Skip to content

Commit fe4af30

Browse files
author
Crhistian Ramirez
committed
💥 Use new auth url
- `baseAuthUrl` no longer exists - `baseApiUrl` is updated to exclude apiVersion - `apiVersion` now exists
1 parent 73ff3ee commit fe4af30

10 files changed

Lines changed: 42 additions & 36 deletions

File tree

codegen/templates/Configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { SdkConfiguration } from './models'
22

33
class Configuration {
44
private config: SdkConfiguration = {
5-
baseApiUrl: 'https://api.ordercloud.io/v1',
6-
baseAuthUrl: 'https://auth.ordercloud.io/oauth/token',
5+
baseApiUrl: 'https://api.ordercloud.io',
6+
apiVersion: 'v1',
77
timeoutInMilliseconds: 60 * 1000, // 60 seconds by default
88
clientID: null,
99
cookieOptions: {

codegen/templates/api/Auth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Auth {
5757
}
5858
const configuration = Configuration.Get()
5959
const response = await axios
60-
.post(configuration.baseAuthUrl, serialize(body), {
60+
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
6161
headers: {
6262
'Content-Type': 'application/x-www-form-urlencoded',
6363
Accept: 'application/json',
@@ -110,7 +110,7 @@ class Auth {
110110
}
111111
const configuration = Configuration.Get()
112112
const response = await axios
113-
.post(configuration.baseAuthUrl, serialize(body), {
113+
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
114114
headers: {
115115
'Content-Type': 'application/x-www-form-urlencoded',
116116
Accept: 'application/json',
@@ -157,7 +157,7 @@ class Auth {
157157
}
158158
const configuration = Configuration.Get()
159159
const response = await axios
160-
.post(configuration.baseAuthUrl, serialize(body), {
160+
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
161161
headers: {
162162
'Content-Type': 'application/x-www-form-urlencoded',
163163
Accept: 'application/json',
@@ -196,7 +196,7 @@ class Auth {
196196
}
197197
const configuration = Configuration.Get()
198198
const response = await axios
199-
.post(configuration.baseAuthUrl, serialize(body), {
199+
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
200200
headers: {
201201
'Content-Type': 'application/x-www-form-urlencoded',
202202
Accept: 'application/json',
@@ -238,7 +238,7 @@ class Auth {
238238
}
239239
const configuration = Configuration.Get()
240240
const response = await axios
241-
.post(configuration.baseAuthUrl, serialize(body), {
241+
.post(`${configuration.baseApiUrl}/oauth/token`, serialize(body), {
242242
headers: {
243243
'Content-Type': 'application/x-www-form-urlencoded',
244244
Accept: 'application/json',

codegen/templates/models/SdkConfiguration.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
export interface SdkConfiguration {
22
/**
3-
* the path that will be used to talk to the ordercloud api.
4-
* It may be useful to change this to interact with different
5-
* environments or different versions of the api. At the time of writing
6-
* there is only one version of the api.
3+
* The apiurl that will be used to talk to the ordercloud API.
4+
* It may be useful to change this to interact with different environments
5+
*
6+
* Defaults to: https://api.ordercloud.io
77
*/
88
baseApiUrl?: string
99

1010
/**
11-
* the path that will be used to authenticate into ordercloud api.
12-
* It may be useful to change this to interact with different
13-
* environments or different versions of the api. At the time of writing
14-
* there is only one version of the api.
11+
* At the time of writing there is only one version of the API
12+
*
13+
* Defaults to: v1
1514
*/
16-
baseAuthUrl?: string
15+
apiVersion?: string
1716

1817
/**
1918
* when set is used to call the refresh token endpoint to obtain a new access

codegen/templates/utils/HttpClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ class HttpClient {
6666
const requestBody = requestConfig.data
6767
delete requestConfig.data
6868
const response = await axios[verb as string](
69-
`${Configuration.Get().baseApiUrl}${path}`,
69+
`${Configuration.Get().baseApiUrl}/${
70+
Configuration.Get().apiVersion
71+
}${path}`,
7072
requestBody,
7173
requestConfig
7274
)
7375
return response.data
7476
} else {
7577
const response = await axios[verb as string](
76-
`${Configuration.Get().baseApiUrl}${path}`,
78+
`${Configuration.Get().baseApiUrl}/${
79+
Configuration.Get().apiVersion
80+
}${path}`,
7781
requestConfig
7882
)
7983
return response.data

readmes/MIGRATION_GUIDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ The objective of this guide is to document the breaking changes and updates requ
2525

2626
```javascript
2727
Configuration.Set({
28-
baseApiUrl: 'https://api.ordercloud.io/v1',
29-
baseAuthUrl: 'https://auth.ordercloud.io/oauth/token'
28+
baseApiUrl: 'https://api.ordercloud.io',
29+
apiVersion: 'v1'
3030
})
3131
3232
Tokens.SetAccessToken('my-token');

src/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { SdkConfiguration } from './models'
22

33
class Configuration {
44
private config: SdkConfiguration = {
5-
baseApiUrl: 'https://api.ordercloud.io/v1',
6-
baseAuthUrl: 'https://auth.ordercloud.io/oauth/token',
5+
baseApiUrl: 'https://api.ordercloud.io',
6+
apiVersion: 'v1',
77
timeoutInMilliseconds: 60 * 1000, // 60 seconds by default
88
clientID: null,
99
cookieOptions: {

src/models/SdkConfiguration.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
export interface SdkConfiguration {
22
/**
3-
* the path that will be used to talk to the ordercloud api.
4-
* It may be useful to change this to interact with different
5-
* environments or different versions of the api. At the time of writing
6-
* there is only one version of the api.
3+
* The apiurl that will be used to talk to the ordercloud API.
4+
* It may be useful to change this to interact with different environments
5+
*
6+
* Defaults to: https://api.ordercloud.io
77
*/
88
baseApiUrl?: string
99

1010
/**
11-
* the path that will be used to authenticate into ordercloud api.
12-
* It may be useful to change this to interact with different
13-
* environments or different versions of the api. At the time of writing
14-
* there is only one version of the api.
11+
* At the time of writing there is only one version of the API
12+
*
13+
* Defaults to: v1
1514
*/
16-
baseAuthUrl?: string
15+
apiVersion?: string
1716

1817
/**
1918
* when set is used to call the refresh token endpoint to obtain a new access

src/utils/HttpClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ class HttpClient {
6666
const requestBody = requestConfig.data
6767
delete requestConfig.data
6868
const response = await axios[verb as string](
69-
`${Configuration.Get().baseApiUrl}${path}`,
69+
`${Configuration.Get().baseApiUrl}/${
70+
Configuration.Get().apiVersion
71+
}${path}`,
7072
requestBody,
7173
requestConfig
7274
)
7375
return response.data
7476
} else {
7577
const response = await axios[verb as string](
76-
`${Configuration.Get().baseApiUrl}${path}`,
78+
`${Configuration.Get().baseApiUrl}/${
79+
Configuration.Get().apiVersion
80+
}${path}`,
7781
requestConfig
7882
)
7983
return response.data

tests/auth.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface TestData {
1414
}
1515
}
1616
const testdata: TestData = {
17-
authUrl: 'https://auth.ordercloud.io/oauth/token',
17+
authUrl: 'https://api.ordercloud.io/oauth/token',
1818
username: '$crhistian', // handles special chars
1919
password: '87awesomesauce#$%^&', // handles special chars
2020
clientSecret: 'my-mock-secret',

tests/invalid-token.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ beforeEach(() => {
2828
Tokens.RemoveRefreshToken()
2929
// reset defaults for configuration
3030
Configuration.Set({
31-
baseApiUrl: 'https://api.ordercloud.io/v1',
32-
baseAuthUrl: 'https://auth.ordercloud.io/oauth/token',
31+
baseApiUrl: 'https://api.ordercloud.io',
32+
apiVersion: 'v1',
3333
timeoutInMilliseconds: 10 * 1000,
3434
clientID: null,
3535
})

0 commit comments

Comments
 (0)