Skip to content

Commit 377b4e3

Browse files
author
Crhistian Ramirez
committed
✨ add requestType to requestOptions
Provide a value that can be used to identify the type of request. Useful for error logs.
1 parent c7fdec0 commit 377b4e3

48 files changed

Lines changed: 512 additions & 53 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codegen/templates/api/Auth.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ class Auth {
3535
* @param password of the user logging in
3636
* @param client_id of the application the user is logging into
3737
* @param scope roles being requested - space delimited string or array
38+
* @param requestOptions.cancelToken Provide an [axios cancelToken](https://github.com/axios/axios#cancellation) that can be used to cancel the request.
39+
* @param requestOptions.requestType Provide a value that can be used to identify the type of request. Useful for error logs.
3840
*/
3941
public async Login(
4042
username: string,
4143
password: string,
4244
clientID: string,
4345
scope: ApiRole[],
44-
options: {
46+
requestOptions: {
4547
cancelToken?: CancelToken
48+
requestType?: string
4649
} = {}
4750
): Promise<RequiredDeep<AccessToken>> {
4851
if (!Array.isArray(scope)) {
@@ -62,7 +65,7 @@ class Auth {
6265
'Content-Type': 'application/x-www-form-urlencoded',
6366
Accept: 'application/json',
6467
},
65-
...options,
68+
...requestOptions,
6669
})
6770
.catch(e => {
6871
if (e.response) {
@@ -83,15 +86,18 @@ class Auth {
8386
* @param scope roles being requested - space delimited string or array
8487
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
8588
* @param reportProgress flag to report request and response progress.
89+
* @param requestOptions.cancelToken Provide an [axios cancelToken](https://github.com/axios/axios#cancellation) that can be used to cancel the request.
90+
* @param requestOptions.requestType Provide a value that can be used to identify the type of request. Useful for error logs.
8691
*/
8792
public async ElevatedLogin(
8893
clientSecret: string,
8994
username: string,
9095
password: string,
9196
clientID: string,
9297
scope: ApiRole[],
93-
options: {
98+
requestOptions: {
9499
cancelToken?: CancelToken
100+
requestType?: string
95101
} = {}
96102
): Promise<RequiredDeep<AccessToken>> {
97103
if (!Array.isArray(scope)) {
@@ -112,7 +118,7 @@ class Auth {
112118
'Content-Type': 'application/x-www-form-urlencoded',
113119
Accept: 'application/json',
114120
},
115-
...options,
121+
...requestOptions,
116122
})
117123
.catch(e => {
118124
if (e.response) {
@@ -131,13 +137,16 @@ class Auth {
131137
* @param scope roles being requested - space delimited string or array
132138
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
133139
* @param reportProgress flag to report request and response progress.
140+
* @param requestOptions.cancelToken Provide an [axios cancelToken](https://github.com/axios/axios#cancellation) that can be used to cancel the request.
141+
* @param requestOptions.requestType Provide a value that can be used to identify the type of request. Useful for error logs.
134142
*/
135143
public async ClientCredentials(
136144
clientSecret: string,
137145
clientID: string,
138146
scope: ApiRole[],
139-
options: {
147+
requestOptions: {
140148
cancelToken?: CancelToken
149+
requestType?: string
141150
} = {}
142151
): Promise<RequiredDeep<AccessToken>> {
143152
if (!Array.isArray(scope)) {
@@ -156,7 +165,7 @@ class Auth {
156165
'Content-Type': 'application/x-www-form-urlencoded',
157166
Accept: 'application/json',
158167
},
159-
...options,
168+
...requestOptions,
160169
})
161170
.catch(e => {
162171
if (e.response) {
@@ -172,14 +181,15 @@ class Auth {
172181
*
173182
* @param refreshToken of the application
174183
* @param clientID of the application the user is logging into
175-
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
176-
* @param reportProgress flag to report request and response progress.
184+
* @param requestOptions.cancelToken Provide an [axios cancelToken](https://github.com/axios/axios#cancellation) that can be used to cancel the request.
185+
* @param requestOptions.requestType Provide a value that can be used to identify the type of request. Useful for error logs.
177186
*/
178187
public async RefreshToken(
179188
refreshToken: string,
180189
clientID: string,
181-
options: {
190+
requestOptions: {
182191
cancelToken?: CancelToken
192+
requestType?: string
183193
} = {}
184194
): Promise<RequiredDeep<AccessToken>> {
185195
const body = {
@@ -194,7 +204,7 @@ class Auth {
194204
'Content-Type': 'application/x-www-form-urlencoded',
195205
Accept: 'application/json',
196206
},
197-
...options,
207+
...requestOptions,
198208
})
199209
.catch(e => {
200210
if (e.response) {
@@ -210,14 +220,15 @@ class Auth {
210220
*
211221
* @param clientID of the application the user is logging into
212222
* @param scope roles being requested - space delimited string or array
213-
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
214-
* @param reportProgress flag to report request and response progress.
223+
* @param requestOptions.cancelToken Provide an [axios cancelToken](https://github.com/axios/axios#cancellation) that can be used to cancel the request.
224+
* @param requestOptions.requestType Provide a value that can be used to identify the type of request. Useful for error logs.
215225
*/
216226
public async Anonymous(
217227
clientID: string,
218228
scope: ApiRole[],
219-
options: {
229+
requestOptions: {
220230
cancelToken?: CancelToken
231+
requestType?: string
221232
} = {}
222233
): Promise<RequiredDeep<AccessToken>> {
223234
if (!Array.isArray(scope)) {
@@ -235,7 +246,7 @@ class Auth {
235246
'Content-Type': 'application/x-www-form-urlencoded',
236247
Accept: 'application/json',
237248
},
238-
...options,
249+
...requestOptions,
239250
})
240251
.catch(e => {
241252
if (e.response) {

codegen/templates/api/_RESOURCE_.ts.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class {{resource.id}} {
2929
* @param {{#if isQueryParam}}listOptions.{{name}} {{description}}{{else}}{{name}} {{description}}{{#if isBodyParam}}{{#if hasRequiredFields}}Required fields: {{commaSeparate requiredFields}}{{/if}}{{/if}}{{/if}}{{/allParams}}
3030
* @param requestOptions.accessToken Provide an alternative token to the one stored in the sdk instance (useful for impersonation).
3131
* @param requestOptions.cancelToken Provide an [axios cancelToken](https://github.com/axios/axios#cancellation) that can be used to cancel the request.
32+
* @param requestOptions.requestType Provide a value that can be used to identify the type of request. Useful for error logs.
3233
*/
3334
public async {{name}}({{#allParams}}{{#unless isQueryParam}}{{#if isBodyParam}}{{#if ../isPatch}}{{name}}: PartialDeep<{{typescriptType}}>, {{else}}{{name}}: {{typescriptType}},{{/if}}{{else}}{{name}}: {{typescriptType}}, {{/if}}{{/unless}}{{/allParams}}{{#if hasQueryParams}}listOptions?: { {{#queryParams}}{{#unless isFilter}}{{name}}?: {{typescriptType}}{{/unless}}{{#if isFilter}}filters?: Filters<Required<{{../returnType}}>>{{/if}}{{#unless @last}}, {{/unless}}{{/queryParams}} }, {{/if}}requestOptions?: RequestOptions ): Promise<{{#if hasReturnType}}RequiredDeep<{{#if isList}}{{#if isFacetList}}ListPageWithFacets<{{returnType}}>{{else}}ListPage<{{returnType}}>{{/if}}{{else}}{{returnType}}{{/if}}>{{else}}void{{/if}}>;
3435
public async {{name}}{{#if hasReturnType}}{{#if isList}}<T{{returnType}} extends {{returnType}}>{{else}}<T{{returnType}} extends {{returnType}}>{{/if}}{{/if}}({{#allParams}}{{#unless isQueryParam}}{{#if isBodyParam}}{{#if ../isPatch}}{{name}}: PartialDeep<{{typescriptType}}>, {{else}}{{name}}: {{typescriptType}},{{/if}}{{else}}{{name}}: {{typescriptType}}, {{/if}}{{/unless}}{{/allParams}}{{#if hasQueryParams}}listOptions?: { {{#queryParams}}{{#unless isFilter}}{{name}}?: {{typescriptType}}{{/unless}}{{#if isFilter}}filters?: Filters<Required<T{{../returnType}}>>{{/if}}{{#unless @last}}, {{/unless}}{{/queryParams}} }, {{/if}}requestOptions?: RequestOptions ): Promise<{{#if hasReturnType}}RequiredDeep<{{#if isList}}{{#if isFacetList}}ListPageWithFacets<T{{returnType}}>{{else}}ListPage<T{{returnType}}>{{/if}}{{else}}T{{returnType}}{{/if}}>{{else}}void{{/if}}>;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { CancelToken } from 'axios'
22

33
export interface RequestOptions {
4+
/**
5+
* Alternative token to the one stored in the sdk instance (useful for impersonation).
6+
*/
47
accessToken?: string
8+
9+
/**
10+
* [Axios cancelToken](https://github.com/axios/axios#cancellation) that can be used to cancel the request.
11+
*/
512
cancelToken?: CancelToken
13+
14+
/**
15+
* Identify the type of request. Useful for error logs.
16+
*/
17+
requestType?: string
618
}

docs/assets/js/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)