Skip to content

Commit 0798d93

Browse files
committed
fix: workaround axios bug
1 parent 4e45523 commit 0798d93

File tree

7 files changed

+40
-29
lines changed

7 files changed

+40
-29
lines changed

.changeset/shiny-swans-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smartthings/core-sdk": patch
3+
---
4+
5+
work around bug in axios 0.28.1

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ a work in progress. Changes may still be made that are not backwardly compatible
1212
npm install @smartthings/core-sdk
1313
```
1414

15+
:warning: Note that if you use axios in your project, you must use version 0.28.1 or later.
16+
1517
## Importing
1618

1719
`NodeJS`:

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"dependencies": {
2222
"async-mutex": "^0.4.0",
23-
"axios": "^0.28",
23+
"axios": "^0.28.1",
2424
"http-signature": "^1.3.6",
2525
"lodash.isdate": "^4.0.1",
2626
"lodash.isstring": "^4.0.1",

src/endpoint-client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export interface EndpointClientRequestOptions <T> {
7373
* Meant to be used before logging the request
7474
*/
7575
function scrubConfig(config: AxiosRequestConfig): string {
76-
const message = JSON.stringify(config)
76+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
77+
const { paramsSerializer: _unused, ...cleanerConfig } = config
78+
const message = JSON.stringify(cleanerConfig)
7779
const bearerRegex = /"(Bearer [0-9a-f]{8})[0-9a-f-]{28}"/i
7880

7981
if (bearerRegex.test(message)) {
@@ -180,7 +182,9 @@ export class EndpointClient {
180182
headers: options?.headerOverrides ? { ...headers, ...options.headerOverrides } : headers,
181183
params,
182184
data,
183-
paramsSerializer: params => qs.stringify(params, { indices: false }),
185+
paramsSerializer: {
186+
serialize: params => qs.stringify(params, { indices: false }),
187+
},
184188
}
185189

186190
const authHeaders = await this.config.authenticator.authenticate()

test/unit/endpoint-client.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Mutex } from 'async-mutex'
2-
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'
2+
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, ParamsSerializerOptions } from 'axios'
33
import qs from 'qs'
44

55
import { AuthData, Authenticator, BearerTokenAuthenticator, NoOpAuthenticator, RefreshData,
@@ -150,17 +150,17 @@ describe('EndpointClient', () => {
150150
},
151151
data: undefined,
152152
params: undefined,
153-
paramsSerializer: expect.any(Function),
153+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
154154
})
155155
expect(response.status).toBe('ok')
156156

157157
const stringifyMock = (qs.stringify as jest.Mock<string, [unknown]>)
158158
.mockReturnValue('stringified parameters')
159159
// eslint-disable-next-line @typescript-eslint/no-explicit-any
160-
const paramsSerializer = mockRequest.mock.calls[0][0].paramsSerializer as (params: any) => string
160+
const paramsSerializer = mockRequest.mock.calls[0][0].paramsSerializer as ParamsSerializerOptions
161161

162162
expect(paramsSerializer).toBeDefined()
163-
expect(paramsSerializer({ param: 'value' })).toBe('stringified parameters')
163+
expect(paramsSerializer.serialize?.({ param: 'value' })).toBe('stringified parameters')
164164

165165
expect(stringifyMock).toHaveBeenCalledTimes(1)
166166
expect(stringifyMock).toHaveBeenCalledWith({ param: 'value' }, { indices: false })
@@ -184,7 +184,7 @@ describe('EndpointClient', () => {
184184
},
185185
data: undefined,
186186
params: undefined,
187-
paramsSerializer: expect.any(Function),
187+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
188188
})
189189
expect(response.status).toBe('ok')
190190
})
@@ -203,7 +203,7 @@ describe('EndpointClient', () => {
203203
},
204204
data: undefined,
205205
params: undefined,
206-
paramsSerializer: expect.any(Function),
206+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
207207
})
208208
expect(response.status).toBe('ok')
209209
})
@@ -226,7 +226,7 @@ describe('EndpointClient', () => {
226226
},
227227
data: { name: 'Bob' },
228228
params: undefined,
229-
paramsSerializer: expect.any(Function),
229+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
230230
})
231231
expect(response.status).toBe('ok')
232232
})
@@ -244,7 +244,7 @@ describe('EndpointClient', () => {
244244
},
245245
data: undefined,
246246
params: undefined,
247-
paramsSerializer: expect.any(Function),
247+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
248248
})
249249
expect(response.status).toBe('ok')
250250
})
@@ -267,7 +267,7 @@ describe('EndpointClient', () => {
267267
},
268268
data: undefined,
269269
params: undefined,
270-
paramsSerializer: expect.any(Function),
270+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
271271
})
272272
expect(response.status).toBe('ok')
273273

@@ -424,7 +424,7 @@ describe('EndpointClient', () => {
424424
},
425425
data: undefined,
426426
params: undefined,
427-
paramsSerializer: expect.any(Function),
427+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
428428
})
429429
expect(response.status).toBe('ok')
430430
})
@@ -443,7 +443,7 @@ describe('EndpointClient', () => {
443443
params: {
444444
locationId: 'XXX',
445445
},
446-
paramsSerializer: expect.any(Function),
446+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
447447
})
448448
expect(response.status).toBe('ok')
449449
})
@@ -460,7 +460,7 @@ describe('EndpointClient', () => {
460460
},
461461
data: undefined,
462462
params: undefined,
463-
paramsSerializer: expect.any(Function),
463+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
464464
})
465465
expect(response.status).toBe('ok')
466466
})
@@ -477,7 +477,7 @@ describe('EndpointClient', () => {
477477
},
478478
data: undefined,
479479
params: undefined,
480-
paramsSerializer: expect.any(Function),
480+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
481481
})
482482
expect(response.status).toBe('ok')
483483
})
@@ -497,7 +497,7 @@ describe('EndpointClient', () => {
497497
name: 'Bill',
498498
},
499499
params: undefined,
500-
paramsSerializer: expect.any(Function),
500+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
501501
})
502502
expect(response.status).toBe('ok')
503503
})
@@ -516,7 +516,7 @@ describe('EndpointClient', () => {
516516
name: 'Bill',
517517
},
518518
params: undefined,
519-
paramsSerializer: expect.any(Function),
519+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
520520
})
521521
expect(response.status).toBe('ok')
522522
})
@@ -535,7 +535,7 @@ describe('EndpointClient', () => {
535535
name: 'Joe',
536536
},
537537
params: undefined,
538-
paramsSerializer: expect.any(Function),
538+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
539539
})
540540
expect(response.status).toBe('ok')
541541
})
@@ -552,7 +552,7 @@ describe('EndpointClient', () => {
552552
},
553553
data: undefined,
554554
params: undefined,
555-
paramsSerializer: expect.any(Function),
555+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
556556
})
557557
expect(response.status).toBe('ok')
558558
})

test/unit/helpers/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function expectedRequest(config: any): any {
44
data: undefined,
55
params: undefined,
66
...config,
7-
paramsSerializer: expect.any(Function),
7+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
88
}
99
}
1010

@@ -19,6 +19,6 @@ export function buildRequest(path?: string, params?: any, data?: any, method = '
1919
},
2020
data: data,
2121
params: params,
22-
paramsSerializer: expect.any(Function),
22+
paramsSerializer: expect.objectContaining({ serialize: expect.any(Function) }),
2323
}
2424
}

0 commit comments

Comments
 (0)