@emilgroup/account-sdk 1.0.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.openapi-generator/FILES +1 -1
- package/README.md +11 -11
- package/api/accounts-api.ts +54 -44
- package/api.ts +0 -9
- package/base.ts +124 -65
- package/common.ts +61 -2
- package/configuration.ts +0 -8
- package/dist/api/accounts-api.d.ts +54 -45
- package/dist/api/accounts-api.js +76 -80
- package/dist/api.d.ts +0 -4
- package/dist/api.js +4 -21
- package/dist/base.d.ts +10 -6
- package/dist/base.js +105 -66
- package/dist/common.d.ts +26 -1
- package/dist/common.js +43 -22
- package/dist/configuration.d.ts +0 -7
- package/dist/configuration.js +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -19
- package/dist/models/account-class.d.ts +31 -5
- package/dist/models/account-class.js +6 -0
- package/dist/models/create-account-request-dto.d.ts +40 -10
- package/dist/models/create-account-request-dto.js +10 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +6 -24
- package/dist/models/policy-class.d.ts +30 -0
- package/dist/models/update-account-request-dto.d.ts +41 -17
- package/dist/models/update-account-request-dto.js +10 -1
- package/index.ts +1 -1
- package/models/account-class.ts +34 -5
- package/models/create-account-request-dto.ts +42 -10
- package/models/index.ts +1 -1
- package/models/policy-class.ts +36 -0
- package/models/update-account-request-dto.ts +43 -17
- package/package.json +3 -5
- package/dist/models/get-account-request-dto.d.ts +0 -30
- package/models/get-account-request-dto.ts +0 -36
- /package/dist/models/{get-account-request-dto.js → policy-class.js} +0 -0
package/.openapi-generator/FILES
CHANGED
|
@@ -13,10 +13,10 @@ models/account-class.ts
|
|
|
13
13
|
models/create-account-request-dto.ts
|
|
14
14
|
models/create-account-response-class.ts
|
|
15
15
|
models/delete-request-dto.ts
|
|
16
|
-
models/get-account-request-dto.ts
|
|
17
16
|
models/get-account-response-class.ts
|
|
18
17
|
models/index.ts
|
|
19
18
|
models/list-accounts-response-class.ts
|
|
19
|
+
models/policy-class.ts
|
|
20
20
|
models/register-policy-request-dto.ts
|
|
21
21
|
models/update-account-request-dto.ts
|
|
22
22
|
models/update-account-response-class.ts
|
package/README.md
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# Emil Account SDK
|
|
2
2
|
|
|
3
|
-
This TypeScript/JavaScript client utilizes [axios](https://github.com/axios/axios). The generated
|
|
4
|
-
|
|
5
|
-
Environment
|
|
6
|
-
* Node.js
|
|
7
|
-
* Webpack
|
|
8
|
-
* Browserify
|
|
3
|
+
This TypeScript/JavaScript client utilizes [axios](https://github.com/axios/axios). The generated module can be used with client-based applications (i.e. React).
|
|
9
4
|
|
|
10
5
|
Language level
|
|
11
6
|
* ES5 - you must have a Promises/A+ library installed
|
|
@@ -15,15 +10,20 @@ Module system
|
|
|
15
10
|
* CommonJS
|
|
16
11
|
* ES6 module system
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
Although this package can be used in both TypeScript and JavaScript, it is intended to be used with TypeScript. The definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html)). For more information, you can go to [Emil Api documentation](https://emil.stoplight.io/docs/emil-api/).
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
## Consuming
|
|
21
16
|
|
|
22
|
-
|
|
17
|
+
Navigate to the folder of your consuming project and run one of the following commands:
|
|
23
18
|
|
|
24
19
|
```
|
|
25
|
-
npm install @emilgroup/account-sdk@1.0
|
|
20
|
+
npm install @emilgroup/account-sdk@1.4.0 --save
|
|
21
|
+
```
|
|
22
|
+
or
|
|
26
23
|
```
|
|
24
|
+
yarn add @emilgroup/account-sdk@1.4.0
|
|
25
|
+
```
|
|
26
|
+
|
|
27
27
|
And then you can import `AccountsApi`.
|
|
28
28
|
|
|
29
29
|
```ts
|
package/api/accounts-api.ts
CHANGED
|
@@ -32,10 +32,6 @@ import { ListAccountsResponseClass } from '../models';
|
|
|
32
32
|
import { UpdateAccountRequestDto } from '../models';
|
|
33
33
|
// @ts-ignore
|
|
34
34
|
import { UpdateAccountResponseClass } from '../models';
|
|
35
|
-
// URLSearchParams not necessarily used
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
import { URL, URLSearchParams } from 'url';
|
|
38
|
-
const FormData = require('form-data');
|
|
39
35
|
/**
|
|
40
36
|
* AccountsApi - axios parameter creator
|
|
41
37
|
* @export
|
|
@@ -185,18 +181,19 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
|
|
|
185
181
|
};
|
|
186
182
|
},
|
|
187
183
|
/**
|
|
188
|
-
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest
|
|
184
|
+
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
189
185
|
* @summary List accounts
|
|
190
186
|
* @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
|
|
191
|
-
* @param {
|
|
192
|
-
* @param {
|
|
193
|
-
* @param {
|
|
194
|
-
* @param {
|
|
195
|
-
* @param {
|
|
187
|
+
* @param {any} [pageSize] A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
|
|
188
|
+
* @param {any} [pageToken] A cursor for use in pagination. pageToken is an ID that defines your place in the list. For instance, if you make a list request and receive 100 objects and pageToken=1, your subsequent call can include pageToken=2 in order to fetch the next page of the list.
|
|
189
|
+
* @param {any} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.
|
|
190
|
+
* @param {any} [search] Search the list by any field. For instance, if you want to search by code add code=xxx in order to fetch the result.
|
|
191
|
+
* @param {any} [order] The order parameter determines how the results should be sorted according to a specified field. It functions similarly to an SQL ORDER BY. Sorting can be performed in either ascending (ASC) or descending (DESC) order. Default: ASC.
|
|
192
|
+
* @param {any} [expand] Use this parameter to fetch additional information about the list items. The expand query parameter increases the set of fields that appear in the response in addition to the default ones. Expanding resources can reduce the number of API calls required to accomplish a task. However, use this with parsimony as some expanded fields can drastically increase payload size.
|
|
196
193
|
* @param {*} [options] Override http request option.
|
|
197
194
|
* @throws {RequiredError}
|
|
198
195
|
*/
|
|
199
|
-
listAccounts: async (authorization?: string, pageSize?:
|
|
196
|
+
listAccounts: async (authorization?: string, pageSize?: any, pageToken?: any, filter?: any, search?: any, order?: any, expand?: any, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
|
200
197
|
const localVarPath = `/accountservice/v1/accounts`;
|
|
201
198
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
202
199
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -227,6 +224,10 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
|
|
|
227
224
|
localVarQueryParameter['filter'] = filter;
|
|
228
225
|
}
|
|
229
226
|
|
|
227
|
+
if (search !== undefined) {
|
|
228
|
+
localVarQueryParameter['search'] = search;
|
|
229
|
+
}
|
|
230
|
+
|
|
230
231
|
if (order !== undefined) {
|
|
231
232
|
localVarQueryParameter['order'] = order;
|
|
232
233
|
}
|
|
@@ -349,19 +350,20 @@ export const AccountsApiFp = function(configuration?: Configuration) {
|
|
|
349
350
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
350
351
|
},
|
|
351
352
|
/**
|
|
352
|
-
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest
|
|
353
|
+
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
353
354
|
* @summary List accounts
|
|
354
355
|
* @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
|
|
355
|
-
* @param {
|
|
356
|
-
* @param {
|
|
357
|
-
* @param {
|
|
358
|
-
* @param {
|
|
359
|
-
* @param {
|
|
356
|
+
* @param {any} [pageSize] A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
|
|
357
|
+
* @param {any} [pageToken] A cursor for use in pagination. pageToken is an ID that defines your place in the list. For instance, if you make a list request and receive 100 objects and pageToken=1, your subsequent call can include pageToken=2 in order to fetch the next page of the list.
|
|
358
|
+
* @param {any} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.
|
|
359
|
+
* @param {any} [search] Search the list by any field. For instance, if you want to search by code add code=xxx in order to fetch the result.
|
|
360
|
+
* @param {any} [order] The order parameter determines how the results should be sorted according to a specified field. It functions similarly to an SQL ORDER BY. Sorting can be performed in either ascending (ASC) or descending (DESC) order. Default: ASC.
|
|
361
|
+
* @param {any} [expand] Use this parameter to fetch additional information about the list items. The expand query parameter increases the set of fields that appear in the response in addition to the default ones. Expanding resources can reduce the number of API calls required to accomplish a task. However, use this with parsimony as some expanded fields can drastically increase payload size.
|
|
360
362
|
* @param {*} [options] Override http request option.
|
|
361
363
|
* @throws {RequiredError}
|
|
362
364
|
*/
|
|
363
|
-
async listAccounts(authorization?: string, pageSize?:
|
|
364
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.listAccounts(authorization, pageSize, pageToken, filter, order, expand, options);
|
|
365
|
+
async listAccounts(authorization?: string, pageSize?: any, pageToken?: any, filter?: any, search?: any, order?: any, expand?: any, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ListAccountsResponseClass>> {
|
|
366
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.listAccounts(authorization, pageSize, pageToken, filter, search, order, expand, options);
|
|
365
367
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
366
368
|
},
|
|
367
369
|
/**
|
|
@@ -422,19 +424,20 @@ export const AccountsApiFactory = function (configuration?: Configuration, baseP
|
|
|
422
424
|
return localVarFp.getAccount(code, authorization, expand, options).then((request) => request(axios, basePath));
|
|
423
425
|
},
|
|
424
426
|
/**
|
|
425
|
-
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest
|
|
427
|
+
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
426
428
|
* @summary List accounts
|
|
427
429
|
* @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
|
|
428
|
-
* @param {
|
|
429
|
-
* @param {
|
|
430
|
-
* @param {
|
|
431
|
-
* @param {
|
|
432
|
-
* @param {
|
|
430
|
+
* @param {any} [pageSize] A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
|
|
431
|
+
* @param {any} [pageToken] A cursor for use in pagination. pageToken is an ID that defines your place in the list. For instance, if you make a list request and receive 100 objects and pageToken=1, your subsequent call can include pageToken=2 in order to fetch the next page of the list.
|
|
432
|
+
* @param {any} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.
|
|
433
|
+
* @param {any} [search] Search the list by any field. For instance, if you want to search by code add code=xxx in order to fetch the result.
|
|
434
|
+
* @param {any} [order] The order parameter determines how the results should be sorted according to a specified field. It functions similarly to an SQL ORDER BY. Sorting can be performed in either ascending (ASC) or descending (DESC) order. Default: ASC.
|
|
435
|
+
* @param {any} [expand] Use this parameter to fetch additional information about the list items. The expand query parameter increases the set of fields that appear in the response in addition to the default ones. Expanding resources can reduce the number of API calls required to accomplish a task. However, use this with parsimony as some expanded fields can drastically increase payload size.
|
|
433
436
|
* @param {*} [options] Override http request option.
|
|
434
437
|
* @throws {RequiredError}
|
|
435
438
|
*/
|
|
436
|
-
listAccounts(authorization?: string, pageSize?:
|
|
437
|
-
return localVarFp.listAccounts(authorization, pageSize, pageToken, filter, order, expand, options).then((request) => request(axios, basePath));
|
|
439
|
+
listAccounts(authorization?: string, pageSize?: any, pageToken?: any, filter?: any, search?: any, order?: any, expand?: any, options?: any): AxiosPromise<ListAccountsResponseClass> {
|
|
440
|
+
return localVarFp.listAccounts(authorization, pageSize, pageToken, filter, search, order, expand, options).then((request) => request(axios, basePath));
|
|
438
441
|
},
|
|
439
442
|
/**
|
|
440
443
|
* Updates the specified account by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
|
|
@@ -535,39 +538,46 @@ export interface AccountsApiListAccountsRequest {
|
|
|
535
538
|
readonly authorization?: string
|
|
536
539
|
|
|
537
540
|
/**
|
|
538
|
-
* A limit on the number of objects to be returned.
|
|
539
|
-
* @type {
|
|
541
|
+
* A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
|
|
542
|
+
* @type {any}
|
|
540
543
|
* @memberof AccountsApiListAccounts
|
|
541
544
|
*/
|
|
542
|
-
readonly pageSize?:
|
|
545
|
+
readonly pageSize?: any
|
|
543
546
|
|
|
544
547
|
/**
|
|
545
|
-
* A cursor for use in pagination.
|
|
546
|
-
* @type {
|
|
548
|
+
* A cursor for use in pagination. pageToken is an ID that defines your place in the list. For instance, if you make a list request and receive 100 objects and pageToken=1, your subsequent call can include pageToken=2 in order to fetch the next page of the list.
|
|
549
|
+
* @type {any}
|
|
547
550
|
* @memberof AccountsApiListAccounts
|
|
548
551
|
*/
|
|
549
|
-
readonly pageToken?:
|
|
552
|
+
readonly pageToken?: any
|
|
550
553
|
|
|
551
554
|
/**
|
|
552
|
-
* Filter the response by one or multiple fields.
|
|
553
|
-
* @type {
|
|
555
|
+
* Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.
|
|
556
|
+
* @type {any}
|
|
554
557
|
* @memberof AccountsApiListAccounts
|
|
555
558
|
*/
|
|
556
|
-
readonly filter?:
|
|
559
|
+
readonly filter?: any
|
|
557
560
|
|
|
558
561
|
/**
|
|
559
|
-
*
|
|
560
|
-
* @type {
|
|
562
|
+
* Search the list by any field. For instance, if you want to search by code add code=xxx in order to fetch the result.
|
|
563
|
+
* @type {any}
|
|
561
564
|
* @memberof AccountsApiListAccounts
|
|
562
565
|
*/
|
|
563
|
-
readonly
|
|
566
|
+
readonly search?: any
|
|
564
567
|
|
|
565
568
|
/**
|
|
566
|
-
*
|
|
567
|
-
* @type {
|
|
569
|
+
* The order parameter determines how the results should be sorted according to a specified field. It functions similarly to an SQL ORDER BY. Sorting can be performed in either ascending (ASC) or descending (DESC) order. Default: ASC.
|
|
570
|
+
* @type {any}
|
|
568
571
|
* @memberof AccountsApiListAccounts
|
|
569
572
|
*/
|
|
570
|
-
readonly
|
|
573
|
+
readonly order?: any
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Use this parameter to fetch additional information about the list items. The expand query parameter increases the set of fields that appear in the response in addition to the default ones. Expanding resources can reduce the number of API calls required to accomplish a task. However, use this with parsimony as some expanded fields can drastically increase payload size.
|
|
577
|
+
* @type {any}
|
|
578
|
+
* @memberof AccountsApiListAccounts
|
|
579
|
+
*/
|
|
580
|
+
readonly expand?: any
|
|
571
581
|
}
|
|
572
582
|
|
|
573
583
|
/**
|
|
@@ -642,7 +652,7 @@ export class AccountsApi extends BaseAPI {
|
|
|
642
652
|
}
|
|
643
653
|
|
|
644
654
|
/**
|
|
645
|
-
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest
|
|
655
|
+
* Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation.
|
|
646
656
|
* @summary List accounts
|
|
647
657
|
* @param {AccountsApiListAccountsRequest} requestParameters Request parameters.
|
|
648
658
|
* @param {*} [options] Override http request option.
|
|
@@ -650,7 +660,7 @@ export class AccountsApi extends BaseAPI {
|
|
|
650
660
|
* @memberof AccountsApi
|
|
651
661
|
*/
|
|
652
662
|
public listAccounts(requestParameters: AccountsApiListAccountsRequest = {}, options?: AxiosRequestConfig) {
|
|
653
|
-
return AccountsApiFp(this.configuration).listAccounts(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.order, requestParameters.expand, options).then((request) => request(this.axios, this.basePath));
|
|
663
|
+
return AccountsApiFp(this.configuration).listAccounts(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.search, requestParameters.order, requestParameters.expand, options).then((request) => request(this.axios, this.basePath));
|
|
654
664
|
}
|
|
655
665
|
|
|
656
666
|
/**
|
package/api.ts
CHANGED
|
@@ -15,10 +15,6 @@
|
|
|
15
15
|
|
|
16
16
|
import { Configuration } from './configuration';
|
|
17
17
|
import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
18
|
-
// URLSearchParams not necessarily used
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
import { URL, URLSearchParams } from 'url';
|
|
21
|
-
import FormData from 'form-data'
|
|
22
18
|
// Some imports not used depending on template conditions
|
|
23
19
|
// @ts-ignore
|
|
24
20
|
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
|
|
@@ -29,8 +25,3 @@ import { AccountsApi } from './api';
|
|
|
29
25
|
|
|
30
26
|
export * from './api/accounts-api';
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
export enum Environment {
|
|
34
|
-
Production = 'https://apiv2.emil.de',
|
|
35
|
-
Test = 'https://apiv2-test.emil.de',
|
|
36
|
-
}
|
package/base.ts
CHANGED
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
import { Configuration } from "./configuration";
|
|
17
|
+
import { defaultStorage } from "./common";
|
|
17
18
|
// Some imports not used depending on template conditions
|
|
18
19
|
// @ts-ignore
|
|
19
20
|
import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
20
21
|
|
|
21
|
-
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
|
|
22
22
|
|
|
23
|
+
export const BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
|
|
23
24
|
/**
|
|
24
25
|
*
|
|
25
26
|
* @export
|
|
@@ -34,12 +35,19 @@ export const COLLECTION_FORMATS = {
|
|
|
34
35
|
export interface LoginClass {
|
|
35
36
|
accessToken: string;
|
|
36
37
|
permissions: Array<string>;
|
|
37
|
-
newPasswordRequired: boolean;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export enum Environment {
|
|
41
41
|
Production = 'https://apiv2.emil.de',
|
|
42
42
|
Test = 'https://apiv2-test.emil.de',
|
|
43
|
+
Development = 'https://apiv2-dev.emil.de',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let _retry_count = 0
|
|
47
|
+
let _retry = null
|
|
48
|
+
|
|
49
|
+
export function resetRetry() {
|
|
50
|
+
_retry_count = 0
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
/**
|
|
@@ -52,67 +60,43 @@ export interface RequestArgs {
|
|
|
52
60
|
options: AxiosRequestConfig;
|
|
53
61
|
}
|
|
54
62
|
|
|
63
|
+
interface TokenData {
|
|
64
|
+
accessToken?: string;
|
|
65
|
+
username?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
69
|
+
const TOKEN_DATA = 'APP_TOKEN';
|
|
70
|
+
|
|
55
71
|
/**
|
|
56
72
|
*
|
|
57
73
|
* @export
|
|
58
74
|
* @class BaseAPI
|
|
59
75
|
*/
|
|
60
76
|
export class BaseAPI {
|
|
61
|
-
protected configuration: Configuration;
|
|
77
|
+
protected configuration: Configuration | undefined;
|
|
78
|
+
private tokenData?: TokenData;
|
|
79
|
+
|
|
80
|
+
constructor(configuration?: Configuration,
|
|
81
|
+
protected basePath: string = BASE_PATH,
|
|
82
|
+
protected axios: AxiosInstance = globalAxios) {
|
|
83
|
+
|
|
84
|
+
this.loadTokenData();
|
|
62
85
|
|
|
63
|
-
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
|
|
64
86
|
if (configuration) {
|
|
65
87
|
this.configuration = configuration;
|
|
66
88
|
this.basePath = configuration.basePath || this.basePath;
|
|
67
89
|
} else {
|
|
90
|
+
const { accessToken, username } = this.tokenData;
|
|
91
|
+
|
|
68
92
|
this.configuration = new Configuration({
|
|
69
93
|
basePath: this.basePath,
|
|
94
|
+
accessToken: accessToken ? `Bearer ${accessToken}` : '',
|
|
95
|
+
username,
|
|
70
96
|
});
|
|
71
97
|
}
|
|
72
98
|
|
|
73
|
-
|
|
74
|
-
(res) => {
|
|
75
|
-
return res;
|
|
76
|
-
},
|
|
77
|
-
async (err) => {
|
|
78
|
-
const originalConfig = err.config;
|
|
79
|
-
if (err.response) {
|
|
80
|
-
// Access Token was expired
|
|
81
|
-
if (err.response.status === 401 && !originalConfig._retry) {
|
|
82
|
-
originalConfig._retry = true;
|
|
83
|
-
try {
|
|
84
|
-
const tokenString = await this.refreshToken();
|
|
85
|
-
const accessToken = `Bearer ${tokenString}`;
|
|
86
|
-
|
|
87
|
-
const localVarHeaderParameter = {} as any;
|
|
88
|
-
localVarHeaderParameter['Authorization'] = accessToken;
|
|
89
|
-
|
|
90
|
-
originalConfig.headers = {
|
|
91
|
-
...originalConfig.headers,
|
|
92
|
-
...localVarHeaderParameter,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
this.configuration.accessToken = accessToken;
|
|
96
|
-
|
|
97
|
-
return axios(originalConfig);
|
|
98
|
-
} catch (_error) {
|
|
99
|
-
if (_error.response && _error.response.data) {
|
|
100
|
-
return Promise.reject(_error.response.data);
|
|
101
|
-
}
|
|
102
|
-
return Promise.reject(_error);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (err.response.status === 403 && err.response.data) {
|
|
106
|
-
return Promise.reject(err.response.data);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return Promise.reject(err);
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
getConfiguration(): Configuration {
|
|
115
|
-
return this.configuration;
|
|
99
|
+
this.attachInterceptor(axios);
|
|
116
100
|
}
|
|
117
101
|
|
|
118
102
|
selectEnvironment(env: Environment) {
|
|
@@ -122,40 +106,43 @@ export class BaseAPI {
|
|
|
122
106
|
async authorize(username: string, password: string): Promise<void> {
|
|
123
107
|
const options: AxiosRequestConfig = {
|
|
124
108
|
method: 'POST',
|
|
125
|
-
url: `${
|
|
126
|
-
headers: {'Content-Type': 'application/json'},
|
|
109
|
+
url: `${this.configuration.basePath}/authservice/v1/login`,
|
|
110
|
+
headers: { 'Content-Type': 'application/json' },
|
|
127
111
|
data: {
|
|
128
|
-
username,
|
|
112
|
+
username,
|
|
129
113
|
password,
|
|
130
114
|
},
|
|
131
115
|
withCredentials: true,
|
|
132
116
|
};
|
|
133
117
|
|
|
134
118
|
const response = await globalAxios.request<LoginClass>(options);
|
|
135
|
-
|
|
119
|
+
|
|
136
120
|
const { data: { accessToken } } = response;
|
|
137
|
-
const refreshToken = this.extractRefreshToken(response)
|
|
138
121
|
|
|
139
122
|
this.configuration.username = username;
|
|
140
123
|
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
141
|
-
this.
|
|
124
|
+
this.tokenData.username = username;
|
|
125
|
+
this.tokenData.accessToken = accessToken;
|
|
126
|
+
|
|
127
|
+
this.storeTokenData({
|
|
128
|
+
...this.tokenData
|
|
129
|
+
});
|
|
142
130
|
}
|
|
143
131
|
|
|
144
|
-
async
|
|
145
|
-
const { username
|
|
132
|
+
async refreshTokenInternal(): Promise<string> {
|
|
133
|
+
const { username } = this.configuration;
|
|
146
134
|
|
|
147
|
-
if (!username
|
|
135
|
+
if (!username) {
|
|
148
136
|
return '';
|
|
149
137
|
}
|
|
150
138
|
|
|
151
139
|
const options: AxiosRequestConfig = {
|
|
152
140
|
method: 'POST',
|
|
153
|
-
url: `${
|
|
141
|
+
url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
|
|
154
142
|
headers: {
|
|
155
|
-
'Content-Type': 'application/json',
|
|
156
|
-
Cookie: refreshToken,
|
|
143
|
+
'Content-Type': 'application/json',
|
|
157
144
|
},
|
|
158
|
-
data: {username: username},
|
|
145
|
+
data: { username: username },
|
|
159
146
|
withCredentials: true,
|
|
160
147
|
};
|
|
161
148
|
|
|
@@ -164,14 +151,85 @@ export class BaseAPI {
|
|
|
164
151
|
return accessToken;
|
|
165
152
|
}
|
|
166
153
|
|
|
167
|
-
private
|
|
168
|
-
if (
|
|
169
|
-
|
|
154
|
+
private storeTokenData(tokenData?: TokenData) {
|
|
155
|
+
if (typeof window !== 'undefined') {
|
|
156
|
+
defaultStorage().set<TokenData>(TOKEN_DATA, tokenData);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
170
159
|
|
|
171
|
-
|
|
160
|
+
public loadTokenData() {
|
|
161
|
+
if (typeof window !== 'undefined') {
|
|
162
|
+
this.tokenData = defaultStorage().get<TokenData>(TOKEN_DATA) || {};
|
|
172
163
|
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public cleanTokenData() {
|
|
167
|
+
this.storeTokenData(null);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private attachInterceptor(axios: AxiosInstance) {
|
|
171
|
+
axios.interceptors.response.use(
|
|
172
|
+
(res) => {
|
|
173
|
+
return res;
|
|
174
|
+
},
|
|
175
|
+
async (err) => {
|
|
176
|
+
let originalConfig = err.config;
|
|
177
|
+
if (err.response && !(err.response instanceof XMLHttpRequest)) { // sometimes buggy and is of type request
|
|
178
|
+
// Access Token was expired
|
|
179
|
+
if ((err.response.status === 401 || err.response.status === 403)
|
|
180
|
+
&& !originalConfig._retry) {
|
|
181
|
+
originalConfig._retry = true;
|
|
182
|
+
try {
|
|
183
|
+
let tokenString = await this.refreshTokenInternal();
|
|
184
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
185
|
+
|
|
186
|
+
delete originalConfig.headers['Authorization']
|
|
173
187
|
|
|
174
|
-
|
|
188
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
189
|
+
|
|
190
|
+
this.configuration.accessToken = accessToken;
|
|
191
|
+
this.tokenData.accessToken = tokenString;
|
|
192
|
+
|
|
193
|
+
this.storeTokenData(this.tokenData);
|
|
194
|
+
|
|
195
|
+
return axios(originalConfig);
|
|
196
|
+
} catch (_error) {
|
|
197
|
+
if (_error.response && _error.response.data) {
|
|
198
|
+
return Promise.reject(_error.response.data);
|
|
199
|
+
}
|
|
200
|
+
return Promise.reject(_error);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
} else if (err.message === NETWORK_ERROR_MESSAGE
|
|
204
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
205
|
+
&& _retry_count < 4
|
|
206
|
+
) {
|
|
207
|
+
_retry_count++;
|
|
208
|
+
try {
|
|
209
|
+
let tokenString = await this.refreshTokenInternal();
|
|
210
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
211
|
+
|
|
212
|
+
_retry = true;
|
|
213
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
214
|
+
|
|
215
|
+
this.configuration.accessToken = accessToken;
|
|
216
|
+
this.tokenData.accessToken = tokenString;
|
|
217
|
+
|
|
218
|
+
this.storeTokenData(this.tokenData);
|
|
219
|
+
|
|
220
|
+
return axios.request({
|
|
221
|
+
...originalConfig,
|
|
222
|
+
});
|
|
223
|
+
} catch (_error) {
|
|
224
|
+
if (_error.response && _error.response.data) {
|
|
225
|
+
return Promise.reject(_error.response.data);
|
|
226
|
+
}
|
|
227
|
+
return Promise.reject(_error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return Promise.reject(err);
|
|
231
|
+
}
|
|
232
|
+
);
|
|
175
233
|
}
|
|
176
234
|
};
|
|
177
235
|
|
|
@@ -187,3 +245,4 @@ export class RequiredError extends Error {
|
|
|
187
245
|
super(msg);
|
|
188
246
|
}
|
|
189
247
|
}
|
|
248
|
+
|
package/common.ts
CHANGED
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
import { Configuration } from "./configuration";
|
|
17
17
|
import { RequiredError, RequestArgs } from "./base";
|
|
18
18
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
19
|
-
import { URL, URLSearchParams } from 'url';
|
|
20
|
-
|
|
21
19
|
/**
|
|
22
20
|
*
|
|
23
21
|
* @export
|
|
@@ -137,3 +135,64 @@ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxi
|
|
|
137
135
|
return axios.request<T, R>(axiosRequestArgs);
|
|
138
136
|
};
|
|
139
137
|
}
|
|
138
|
+
|
|
139
|
+
/* tslint:disable */
|
|
140
|
+
/* eslint-disable */
|
|
141
|
+
/**
|
|
142
|
+
* EMIL AccountService
|
|
143
|
+
* The EMIL AccountService API description
|
|
144
|
+
*
|
|
145
|
+
* The version of the OpenAPI document: 1.0
|
|
146
|
+
*
|
|
147
|
+
*
|
|
148
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
149
|
+
* https://openapi-generator.tech
|
|
150
|
+
* Do not edit the class manually.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
export interface IStorageConverter<D, SD> {
|
|
155
|
+
toStorageData( data: D ): SD;
|
|
156
|
+
fromStorageData( storageData: SD ): D;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface IStorage {
|
|
160
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null;
|
|
161
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export class LocalStorage implements IStorage {
|
|
165
|
+
readonly storage: Storage;
|
|
166
|
+
|
|
167
|
+
constructor() {
|
|
168
|
+
this.storage = localStorage;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null {
|
|
172
|
+
const jsonValue = this.storage.getItem( key );
|
|
173
|
+
if ( jsonValue === null ) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const value = JSON.parse( jsonValue );
|
|
177
|
+
if ( converter !== undefined ) {
|
|
178
|
+
return converter.fromStorageData( value );
|
|
179
|
+
} else {
|
|
180
|
+
return value as T;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void {
|
|
185
|
+
let valueToStore: any = value;
|
|
186
|
+
if ( converter !== undefined ) {
|
|
187
|
+
valueToStore = converter.toStorageData( value );
|
|
188
|
+
}
|
|
189
|
+
const jsonValue = JSON.stringify( valueToStore );
|
|
190
|
+
this.storage.setItem( key, jsonValue );
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let _defaultStorage: IStorage = null;
|
|
195
|
+
|
|
196
|
+
export const defaultStorage = (): IStorage => {
|
|
197
|
+
return _defaultStorage || (_defaultStorage = new LocalStorage());
|
|
198
|
+
};
|
package/configuration.ts
CHANGED
|
@@ -74,14 +74,6 @@ export class Configuration {
|
|
|
74
74
|
*/
|
|
75
75
|
formDataCtor?: new () => any;
|
|
76
76
|
|
|
77
|
-
/**
|
|
78
|
-
* parameter for automatically refreshing access token for oauth2 security
|
|
79
|
-
*
|
|
80
|
-
* @type {string}
|
|
81
|
-
* @memberof Configuration
|
|
82
|
-
*/
|
|
83
|
-
refreshToken?: string;
|
|
84
|
-
|
|
85
77
|
constructor(param: ConfigurationParameters = {}) {
|
|
86
78
|
this.apiKey = param.apiKey;
|
|
87
79
|
this.username = param.username;
|