Skip to content

Commit acdd681

Browse files
authored
fix: remove request id when calling the sync api (#258)
1 parent 6c9c0e7 commit acdd681

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/consts/endpoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const BASE_URI = 'https://api.todoist.com'
22
const API_REST_BASE_URI = '/rest/v2/'
3-
const API_SYNC_BASE_URI = '/sync/v9/'
3+
export const API_SYNC_BASE_URI = '/sync/v9/'
44
const TODOIST_URI = 'https://todoist.com'
55
const API_AUTHORIZATION_BASE_URI = '/oauth/'
66

src/restClient.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TodoistRequestError } from './types/errors'
55
import * as caseConverter from 'axios-case-converter'
66
import { assertInstance } from './testUtils/asserts'
77
import { DEFAULT_REQUEST_ID } from './testUtils/testDefaults'
8+
import { API_SYNC_BASE_URI } from './consts/endpoints'
89

910
const RANDOM_ID = 'SomethingRandom'
1011

@@ -193,6 +194,16 @@ describe('restClient', () => {
193194
})
194195
})
195196

197+
test('random request ID is not created if none provided for POST request on the sync endpoint', async () => {
198+
const syncUrl = new URL(API_SYNC_BASE_URI, DEFAULT_BASE_URI).toString()
199+
await request('POST', syncUrl, DEFAULT_ENDPOINT, DEFAULT_AUTH_TOKEN, DEFAULT_PAYLOAD)
200+
201+
expect(axiosMock.create).toBeCalledWith({
202+
baseURL: syncUrl,
203+
headers: { ...AUTHORIZATION_HEADERS },
204+
})
205+
})
206+
196207
test('delete calls axios with expected endpoint', async () => {
197208
await request('DELETE', DEFAULT_BASE_URI, DEFAULT_ENDPOINT, DEFAULT_AUTH_TOKEN)
198209

src/restClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TodoistRequestError } from './types/errors'
55
import { HttpMethod } from './types/http'
66
import { v4 as uuidv4 } from 'uuid'
77
import axiosRetry from 'axios-retry'
8+
import { API_SYNC_BASE_URI } from './consts/endpoints'
89

910
export function paramsSerializer(params: Record<string, unknown>) {
1011
const qs = new URLSearchParams()
@@ -96,7 +97,8 @@ export async function request<T>(
9697
const originalStack = new Error()
9798

9899
try {
99-
if (httpMethod === 'POST' && !requestId) {
100+
// Sync api don't allow a request id in the CORS
101+
if (httpMethod === 'POST' && !requestId && !baseUri.includes(API_SYNC_BASE_URI)) {
100102
requestId = uuidv4()
101103
}
102104

0 commit comments

Comments
 (0)