diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 8063089..b8f67b6 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -3,12 +3,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [UNRELEASED] ### Changes +- Set a 30 second default timeout for all requests - `MermaidChart#resetAccessToken()` no longer returns a `Promise`. +### Added + +- Added `requestTimeout` option to configure timeout. + ## [0.2.0] - 2024-04-11 ### Added diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index ca212ea..ef7ce4a 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -1,18 +1,18 @@ -import { v4 as uuid } from 'uuid'; import { OAuth2Client, generateCodeVerifier } from '@badgateway/oauth2-client'; -import defaultAxios from 'axios'; import type { AxiosInstance, AxiosResponse } from 'axios'; -import { RequiredParameterMissingError, OAuthError } from './errors.js'; -import { URLS } from './urls.js'; +import defaultAxios from 'axios'; +import { v4 as uuid } from 'uuid'; +import { OAuthError, RequiredParameterMissingError } from './errors.js'; import type { AuthState, + AuthorizationData, Document, InitParams, - AuthorizationData, - MCUser, - MCProject, MCDocument, + MCProject, + MCUser, } from './types.js'; +import { URLS } from './urls.js'; const defaultBaseURL = 'https://www.mermaidchart.com'; // "http://127.0.0.1:5174" const authorizationURLTimeout = 60_000; @@ -25,13 +25,17 @@ export class MermaidChart { private pendingStates: Record = {}; private redirectURI!: string; private accessToken?: string; + private requestTimeout = 30_000; - constructor({ clientID, baseURL, redirectURI }: InitParams) { + constructor({ clientID, baseURL, redirectURI, requestTimeout }: InitParams) { this.clientID = clientID; this.setBaseURL(baseURL || defaultBaseURL); if (redirectURI) { this.setRedirectURI(redirectURI); } + if (requestTimeout) { + this.requestTimeout = requestTimeout; + } } public setRedirectURI(redirectURI: string) { @@ -52,6 +56,7 @@ export class MermaidChart { }); this.axios = defaultAxios.create({ baseURL: this.#baseURL, + timeout: this.requestTimeout, }); this.axios.interceptors.response.use((res: AxiosResponse) => { diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 8f487b4..b755b56 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -2,6 +2,7 @@ export interface InitParams { clientID: string; redirectURI?: string; baseURL?: string; + requestTimeout?: number; } export interface OAuthAuthorizationParams {