Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing Axios client #657

Merged
merged 1 commit into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions 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<AxiosRequestConfig, 'baseURL'>;
}
20 changes: 20 additions & 0 deletions src/workos.spec.ts
Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/workos.ts
Expand Up @@ -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}`,
},
Expand Down