diff --git a/src/common/interfaces/workos-options.interface.ts b/src/common/interfaces/workos-options.interface.ts index a26909a72..7ada5392e 100644 --- a/src/common/interfaces/workos-options.interface.ts +++ b/src/common/interfaces/workos-options.interface.ts @@ -1,5 +1,8 @@ +import { AxiosRequestConfig } from 'axios'; + export interface WorkOSOptions { apiHostname?: string; https?: boolean; port?: number; + axios?: Omit; } diff --git a/src/workos.spec.ts b/src/workos.spec.ts index fddf8b4bc..51115a9fd 100644 --- a/src/workos.spec.ts +++ b/src/workos.spec.ts @@ -69,6 +69,26 @@ describe('WorkOS', () => { expect(workos.baseURL).toEqual('https://localhost:4000'); }); }); + + describe('when the `axios` option is provided', () => { + it('applies the configuration to the Axios client', async () => { + mock.onPost().reply(200, 'OK', { 'X-Request-ID': 'a-request-id' }); + + const workos = new WorkOS('sk_test', { + axios: { + headers: { + 'X-My-Custom-Header': 'Hey there!', + }, + }, + }); + + await workos.post('/somewhere', {}); + + expect(mock.history.post[0].headers).toMatchObject({ + 'X-My-Custom-Header': 'Hey there!', + }); + }); + }); }); describe('post', () => { diff --git a/src/workos.ts b/src/workos.ts index b54caf6bf..f0135005a 100644 --- a/src/workos.ts +++ b/src/workos.ts @@ -65,8 +65,10 @@ export class WorkOS { } this.client = axios.create({ + ...options.axios, baseURL: this.baseURL, headers: { + ...options.axios?.headers, Authorization: `Bearer ${this.key}`, 'User-Agent': `workos-node/${VERSION}`, },