Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js: Support setting a request timeout #1687

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export { OperationalWebhookEndpointListOptions } from "./api/operational_webhook
export interface SvixOptions {
debug?: boolean;
serverUrl?: string;
/** Time in milliseconds to wait for requests to get a response. */
requestTimeout?: number;
}

const REGIONS = [
Expand Down Expand Up @@ -59,7 +61,7 @@ export class Svix {
const regionalUrl = REGIONS.find((x) => x.region === token.split(".")[1])?.url;
const baseUrl: string = options.serverUrl ?? regionalUrl ?? "https://api.svix.com";

this.requestCtx = { baseUrl, token };
this.requestCtx = { baseUrl, token, timeout: options.requestTimeout };

this._configuration = openapi.createConfiguration({
baseServer: new openapi.ServerConfiguration<any>(baseUrl, {}),
Expand Down
3 changes: 3 additions & 0 deletions javascript/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface SvixRequestContext {
baseUrl: string;
/** The 'bearer' scheme access token */
token: string;
/** Time in milliseconds to wait for requests to get a response. */
timeout?: number;
}

type QueryParameter = string | boolean | number | Date | string[] | null | undefined;
Expand Down Expand Up @@ -122,6 +124,7 @@ export class SvixRequest {
...this.headerParams,
},
credentials: isCredentialsSupported ? "same-origin" : undefined,
signal: ctx.timeout !== undefined ? AbortSignal.timeout(ctx.timeout) : undefined,
});

const responseBody = await response.text();
Expand Down