diff --git a/javascript/src/index.ts b/javascript/src/index.ts index 0dfa882bd..877e6cbf4 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -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 = [ @@ -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(baseUrl, {}), diff --git a/javascript/src/request.ts b/javascript/src/request.ts index 2cb9b1885..8fcab139a 100644 --- a/javascript/src/request.ts +++ b/javascript/src/request.ts @@ -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; @@ -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();