Skip to content

Commit 162bfe4

Browse files
author
Crhistian
committed
💥 update sdk to be compatible with axios ^1.0.0
Breaking change: any version less than 1.0.0 is no longer supported
1 parent b24198c commit 162bfe4

14 files changed

Lines changed: 325 additions & 245 deletions

codegen/templates/api/Auth.ts

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* eslint-disable no-var */
12
import axios, { CancelToken } from 'axios'
23
import { AccessToken } from '../models/AccessToken'
34
import Configuration from '../Configuration'
45
import { ApiRole } from '../models/ApiRole'
5-
import serialize from '../utils/ParamsSerializer'
6+
import paramsSerializer from '../utils/ParamsSerializer'
67
import { RequiredDeep } from '../models/RequiredDeep'
78
import OrderCloudError from '../utils/OrderCloudError'
89

@@ -65,13 +66,17 @@ class Auth {
6566
}
6667
const configuration = Configuration.Get()
6768
const response = await axios
68-
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
69-
headers: {
70-
'Content-Type': 'application/x-www-form-urlencoded',
71-
Accept: 'application/json',
72-
},
73-
...requestOptions,
74-
})
69+
.post(
70+
`${configuration.baseApiUrl}/oauth/token`,
71+
paramsSerializer.serialize(body),
72+
{
73+
headers: {
74+
'Content-Type': 'application/x-www-form-urlencoded',
75+
Accept: 'application/json',
76+
},
77+
...requestOptions,
78+
}
79+
)
7580
.catch(e => {
7681
if (e.response) {
7782
throw new OrderCloudError(e)
@@ -126,13 +131,17 @@ class Auth {
126131
}
127132
const configuration = Configuration.Get()
128133
const response = await axios
129-
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
130-
headers: {
131-
'Content-Type': 'application/x-www-form-urlencoded',
132-
Accept: 'application/json',
133-
},
134-
...requestOptions,
135-
})
134+
.post(
135+
`${configuration.baseApiUrl}/oauth/token`,
136+
paramsSerializer.serialize(body),
137+
{
138+
headers: {
139+
'Content-Type': 'application/x-www-form-urlencoded',
140+
Accept: 'application/json',
141+
},
142+
...requestOptions,
143+
}
144+
)
136145
.catch(e => {
137146
if (e.response) {
138147
throw new OrderCloudError(e)
@@ -181,13 +190,17 @@ class Auth {
181190
}
182191
const configuration = Configuration.Get()
183192
const response = await axios
184-
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
185-
headers: {
186-
'Content-Type': 'application/x-www-form-urlencoded',
187-
Accept: 'application/json',
188-
},
189-
...requestOptions,
190-
})
193+
.post(
194+
`${configuration.baseApiUrl}/oauth/token`,
195+
paramsSerializer.serialize(body),
196+
{
197+
headers: {
198+
'Content-Type': 'application/x-www-form-urlencoded',
199+
Accept: 'application/json',
200+
},
201+
...requestOptions,
202+
}
203+
)
191204
.catch(e => {
192205
if (e.response) {
193206
throw new OrderCloudError(e)
@@ -220,13 +233,17 @@ class Auth {
220233
}
221234
const configuration = Configuration.Get()
222235
const response = await axios
223-
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
224-
headers: {
225-
'Content-Type': 'application/x-www-form-urlencoded',
226-
Accept: 'application/json',
227-
},
228-
...requestOptions,
229-
})
236+
.post(
237+
`${configuration.baseApiUrl}/oauth/token`,
238+
paramsSerializer.serialize(body),
239+
{
240+
headers: {
241+
'Content-Type': 'application/x-www-form-urlencoded',
242+
Accept: 'application/json',
243+
},
244+
...requestOptions,
245+
}
246+
)
230247
.catch(e => {
231248
if (e.response) {
232249
throw new OrderCloudError(e)
@@ -270,13 +287,17 @@ class Auth {
270287
}
271288
const configuration = Configuration.Get()
272289
const response = await axios
273-
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
274-
headers: {
275-
'Content-Type': 'application/x-www-form-urlencoded',
276-
Accept: 'application/json',
277-
},
278-
...requestOptions,
279-
})
290+
.post(
291+
`${configuration.baseApiUrl}/oauth/token`,
292+
paramsSerializer.serialize(body),
293+
{
294+
headers: {
295+
'Content-Type': 'application/x-www-form-urlencoded',
296+
Accept: 'application/json',
297+
},
298+
...requestOptions,
299+
}
300+
)
280301
.catch(e => {
281302
if (e.response) {
282303
throw new OrderCloudError(e)

codegen/templates/models/Filters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* null is not a valid filter prop
33
* Use negative filter "!" combined with wildcard filter "*" to define a filter for the absence of a value
4-
* ex: an order list call with { xp: { hasPaid: '!*' } } would return a list of orders where xp.hasPaid is null or undefined
4+
* ex: an order list call with \{ xp: \{ hasPaid: '!*' \} \} would return a list of orders where xp.hasPaid is null or undefined
55
* https://ordercloud.io/features/advanced-querying#filtering
66
*/
77
type FilterProp = string | string[] | number | boolean | undefined

codegen/templates/utils/HttpClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class HttpClient {
9090
): Promise<OcRequestConfig> {
9191
const token = this._resolveToken(config)
9292
const validToken = await tokenService.GetValidToken(token)
93+
if (!config.headers) {
94+
config.headers = {}
95+
}
9396
config.headers.Authorization = `Bearer ${validToken}`
9497
return config
9598
}

codegen/templates/utils/paramsSerializer.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
* @ignore
33
* not part of public api, don't include in generated docs
44
*/
5-
export default function ParamSerializer(originalParams: {
6-
[key: string]: any
7-
}): string {
5+
export default {
6+
serialize: customSerializer,
7+
}
8+
9+
/**
10+
* @ignore
11+
* not part of public api, don't include in generated docs
12+
*/
13+
function customSerializer(originalParams: { [key: string]: any }): string {
814
const params = JSON.parse(JSON.stringify(originalParams)) // don't mutate original object
915
const valuesArray: string[] = []
1016

@@ -66,7 +72,7 @@ function inspectProp(propVal, propName, result) {
6672
} else {
6773
if (propVal === null) {
6874
throw new Error(
69-
`Null is not a valid filter prop. Use negative filter "!" combined with wildcard filter "*" to define a filter for the absence of a value. \nex: an order list call with { xp: { hasPaid: '!*' } } would return a list of orders where xp.hasPaid is null or undefined\nhttps://ordercloud.io/features/advanced-querying#filtering`
75+
`Null is not a valid filter prop. Use negative filter "!" combined with wildcard filter "*" to define a filter for the absence of a value. \nex: an order list call with \{ xp: \{ hasPaid: '!*' \} \} would return a list of orders where xp.hasPaid is null or undefined\nhttps://ordercloud.io/features/advanced-querying#filtering`
7076
)
7177
}
7278
result[propName] = propVal

codegen/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module": "es2015",
3+
"module": "CommonJS",
44
"moduleResolution": "node",
55
"strict": true,
66
"target": "es5",

0 commit comments

Comments
 (0)