UNPKG

@oystehr/sdk

Version:

Oystehr SDK

73 lines (69 loc) 1.83 kB
/** * Configuration for the Oystehr SDK client */ export interface OystehrConfig { /** * Access token for your user, M2M, or developer account. */ accessToken?: string; /** * Optional Oystehr Project ID. Required for developer accessTokens. */ projectId?: string; fhirApiUrl?: string; projectApiUrl?: string; services?: { erxApiUrl?: string; faxApiUrl?: string; fhirApiUrl?: string; labApiUrl?: string; projectApiUrl?: string; terminologyApiUrl?: string; }; /** * Optionally provide a custom fetch implementation. This must conform to the * built-in node.js fetch implementation (undici fetch). * @param req * @returns */ fetch?: (req: Request) => Promise<Response>; /** * Optional configuration for retrying request in case of error. Defaults to * `{ retries: 3 }` if not provided. */ retry?: { /** * Number of retries. */ retries: number; /** * Shift retries by up to this many milliseconds. Defaults to 20 milliseconds. */ jitter?: number; /** * Wait this many milliseconds between retries. Defaults to 100 milliseconds. */ delay?: number; /** * Optional, non-async function to call when a request is retried. * @param attempt * @returns */ onRetry?: (attempt: number) => void; /** * Optional list of additional errors to retry for. The Oystehr SDK will always * retry for status codes 408, 429, 500, 502, 503, and 504. */ retryOn?: number[]; }; } let globalConfig: OystehrConfig; export function getConfig(): OystehrConfig { if (!globalConfig) { throw new Error('Config not set, please initialize the SDK'); } return globalConfig; } export function setConfig(config: OystehrConfig): void { globalConfig = { ...config }; }