Skip to content

Commit

Permalink
js: Support setting a request timeout (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte authored Feb 4, 2025
2 parents 9b4decf + 11e25ee commit c0fdb39
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit c0fdb39

Please sign in to comment.