Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type CreateHttpClientParams = {
adapter?: AxiosRequestConfig['adapter']
/** Axios proxy config */
proxy?: AxiosRequestConfig['proxy']
/** Axios fetch options */
fetchOptions?: AxiosRequestConfig['fetchOptions']

/** Gets called on every request triggered by the SDK, takes the axios request config as an argument */
requestLogger?: DefaultOptions['requestLogger']
Expand Down
17 changes: 17 additions & 0 deletions test/unit/create-http-client-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,20 @@ it('Can change the adapter axios uses', () => {
expect(logHandlerStub).not.toHaveBeenCalled()
expect(instance.httpClientParams.adapter).toEqual(testAdapter)
})

it('Can change to the fetch adapter with fetch options', () => {
const instance = createHttpClient(axios, {
accessToken: 'clientAccessToken',
space: 'clientSpaceId',
defaultHostname: 'defaulthost',
logHandler: logHandlerStub,
adapter: 'fetch',
fetchOptions: { cache: 'no-cache' },
})

const [callConfig] = vi.mocked(axios.create).mock.calls[0]
expect(callConfig?.baseURL).toEqual('https://defaulthost:443/spaces/clientSpaceId/')
expect(logHandlerStub).not.toHaveBeenCalled()
expect(instance.httpClientParams.adapter).toEqual('fetch')
expect(instance.httpClientParams.fetchOptions).toEqual({ cache: 'no-cache' })
})