Skip to content

Commit

Permalink
feat: Make requestTimeout configurable
Browse files Browse the repository at this point in the history
Co-authored-by: Alois Klink <[email protected]>
  • Loading branch information
sidharthv96 and aloisklink committed Aug 23, 2024
1 parent 1e0f33c commit c5a6c97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { URLS } from './urls.js';

const defaultBaseURL = 'https://www.mermaidchart.com'; // "http://127.0.0.1:5174"
const authorizationURLTimeout = 60_000;
const requestTimeout = 30_000;

export class MermaidChart {
private clientID: string;
Expand All @@ -26,13 +25,17 @@ export class MermaidChart {
private pendingStates: Record<string, AuthState> = {};
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) {
Expand All @@ -53,7 +56,7 @@ export class MermaidChart {
});
this.axios = defaultAxios.create({
baseURL: this.#baseURL,
timeout: requestTimeout,
timeout: this.requestTimeout,
});

this.axios.interceptors.response.use((res: AxiosResponse) => {
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface InitParams {
clientID: string;
redirectURI?: string;
baseURL?: string;
requestTimeout?: number;
}

export interface OAuthAuthorizationParams {
Expand Down

0 comments on commit c5a6c97

Please sign in to comment.