@emilgroup/account-sdk 1.1.0 → 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.
Files changed (38) hide show
  1. package/.openapi-generator/FILES +1 -1
  2. package/README.md +11 -11
  3. package/api/accounts-api.ts +54 -40
  4. package/api.ts +0 -5
  5. package/base.ts +122 -63
  6. package/common.ts +61 -0
  7. package/configuration.ts +0 -8
  8. package/dist/api/accounts-api.d.ts +54 -45
  9. package/dist/api/accounts-api.js +71 -71
  10. package/dist/api.d.ts +0 -4
  11. package/dist/api.js +4 -21
  12. package/dist/base.d.ts +10 -6
  13. package/dist/base.js +105 -66
  14. package/dist/common.d.ts +26 -0
  15. package/dist/common.js +42 -20
  16. package/dist/configuration.d.ts +0 -7
  17. package/dist/configuration.js +0 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +8 -19
  20. package/dist/models/account-class.d.ts +31 -5
  21. package/dist/models/account-class.js +6 -0
  22. package/dist/models/create-account-request-dto.d.ts +40 -10
  23. package/dist/models/create-account-request-dto.js +10 -1
  24. package/dist/models/index.d.ts +1 -1
  25. package/dist/models/index.js +6 -24
  26. package/dist/models/policy-class.d.ts +30 -0
  27. package/dist/models/update-account-request-dto.d.ts +41 -17
  28. package/dist/models/update-account-request-dto.js +10 -1
  29. package/index.ts +1 -1
  30. package/models/account-class.ts +34 -5
  31. package/models/create-account-request-dto.ts +42 -10
  32. package/models/index.ts +1 -1
  33. package/models/policy-class.ts +36 -0
  34. package/models/update-account-request-dto.ts +43 -17
  35. package/package.json +3 -3
  36. package/dist/models/get-account-request-dto.d.ts +0 -30
  37. package/models/get-account-request-dto.ts +0 -36
  38. /package/dist/models/{get-account-request-dto.js → policy-class.js} +0 -0
@@ -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
- ## @emilgroup/account-sdk@1.1.0
1
+ # Emil Account SDK
2
2
 
3
- This TypeScript/JavaScript client utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
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
- It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
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
- ### Consuming
15
+ ## Consuming
21
16
 
22
- navigate to the folder of your consuming project and run one of the following commands.
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.1.0 --save
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
@@ -181,18 +181,19 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
181
181
  };
182
182
  },
183
183
  /**
184
- * Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest account appearing first. For more information about pagination, read the Pagination documentation.
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.
185
185
  * @summary List accounts
186
186
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
187
- * @param {number} [pageSize] A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
188
- * @param {string} [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 {string} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time. Parameters: **code**, **firstName**, **lastName**, **accountNumber**, **email**, **zipCode**, **birthDate**
190
- * @param {string} [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. Parameters: **firstName**, **lastName**, **accountNumber**, **email**.
191
- * @param {string} [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. Parameters: **policy**.
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.
192
193
  * @param {*} [options] Override http request option.
193
194
  * @throws {RequiredError}
194
195
  */
195
- listAccounts: async (authorization?: string, pageSize?: number, pageToken?: string, filter?: string, order?: string, expand?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
196
+ listAccounts: async (authorization?: string, pageSize?: any, pageToken?: any, filter?: any, search?: any, order?: any, expand?: any, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
196
197
  const localVarPath = `/accountservice/v1/accounts`;
197
198
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
198
199
  const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
@@ -223,6 +224,10 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
223
224
  localVarQueryParameter['filter'] = filter;
224
225
  }
225
226
 
227
+ if (search !== undefined) {
228
+ localVarQueryParameter['search'] = search;
229
+ }
230
+
226
231
  if (order !== undefined) {
227
232
  localVarQueryParameter['order'] = order;
228
233
  }
@@ -345,19 +350,20 @@ export const AccountsApiFp = function(configuration?: Configuration) {
345
350
  return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
346
351
  },
347
352
  /**
348
- * Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest account appearing first. For more information about pagination, read the Pagination documentation.
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.
349
354
  * @summary List accounts
350
355
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
351
- * @param {number} [pageSize] A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
352
- * @param {string} [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&#x3D;1, your subsequent call can include pageToken&#x3D;2 in order to fetch the next page of the list.
353
- * @param {string} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time. Parameters: **code**, **firstName**, **lastName**, **accountNumber**, **email**, **zipCode**, **birthDate**
354
- * @param {string} [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. Parameters: **firstName**, **lastName**, **accountNumber**, **email**.
355
- * @param {string} [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. Parameters: **policy**.
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&#x3D;1, your subsequent call can include pageToken&#x3D;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&#x3D;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.
356
362
  * @param {*} [options] Override http request option.
357
363
  * @throws {RequiredError}
358
364
  */
359
- async listAccounts(authorization?: string, pageSize?: number, pageToken?: string, filter?: string, order?: string, expand?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ListAccountsResponseClass>> {
360
- 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);
361
367
  return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
362
368
  },
363
369
  /**
@@ -418,19 +424,20 @@ export const AccountsApiFactory = function (configuration?: Configuration, baseP
418
424
  return localVarFp.getAccount(code, authorization, expand, options).then((request) => request(axios, basePath));
419
425
  },
420
426
  /**
421
- * Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest account appearing first. For more information about pagination, read the Pagination documentation.
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.
422
428
  * @summary List accounts
423
429
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
424
- * @param {number} [pageSize] A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
425
- * @param {string} [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&#x3D;1, your subsequent call can include pageToken&#x3D;2 in order to fetch the next page of the list.
426
- * @param {string} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time. Parameters: **code**, **firstName**, **lastName**, **accountNumber**, **email**, **zipCode**, **birthDate**
427
- * @param {string} [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. Parameters: **firstName**, **lastName**, **accountNumber**, **email**.
428
- * @param {string} [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. Parameters: **policy**.
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&#x3D;1, your subsequent call can include pageToken&#x3D;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&#x3D;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.
429
436
  * @param {*} [options] Override http request option.
430
437
  * @throws {RequiredError}
431
438
  */
432
- listAccounts(authorization?: string, pageSize?: number, pageToken?: string, filter?: string, order?: string, expand?: string, options?: any): AxiosPromise<ListAccountsResponseClass> {
433
- 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));
434
441
  },
435
442
  /**
436
443
  * Updates the specified account by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
@@ -531,39 +538,46 @@ export interface AccountsApiListAccountsRequest {
531
538
  readonly authorization?: string
532
539
 
533
540
  /**
534
- * A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
535
- * @type {number}
541
+ * A limit on the number of objects to be returned. Limit ranges between 1 and 100. Default: 10.
542
+ * @type {any}
536
543
  * @memberof AccountsApiListAccounts
537
544
  */
538
- readonly pageSize?: number
545
+ readonly pageSize?: any
539
546
 
540
547
  /**
541
- * 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&#x3D;1, your subsequent call can include pageToken&#x3D;2 in order to fetch the next page of the list.
542
- * @type {string}
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&#x3D;1, your subsequent call can include pageToken&#x3D;2 in order to fetch the next page of the list.
549
+ * @type {any}
543
550
  * @memberof AccountsApiListAccounts
544
551
  */
545
- readonly pageToken?: string
552
+ readonly pageToken?: any
546
553
 
547
554
  /**
548
- * Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time. Parameters: **code**, **firstName**, **lastName**, **accountNumber**, **email**, **zipCode**, **birthDate**
549
- * @type {string}
555
+ * Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.
556
+ * @type {any}
550
557
  * @memberof AccountsApiListAccounts
551
558
  */
552
- readonly filter?: string
559
+ readonly filter?: any
553
560
 
554
561
  /**
555
- * 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. Parameters: **firstName**, **lastName**, **accountNumber**, **email**.
556
- * @type {string}
562
+ * Search the list by any field. For instance, if you want to search by code add code&#x3D;xxx in order to fetch the result.
563
+ * @type {any}
557
564
  * @memberof AccountsApiListAccounts
558
565
  */
559
- readonly order?: string
566
+ readonly search?: any
560
567
 
561
568
  /**
562
- * 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. Parameters: **policy**.
563
- * @type {string}
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}
564
571
  * @memberof AccountsApiListAccounts
565
572
  */
566
- readonly expand?: string
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
567
581
  }
568
582
 
569
583
  /**
@@ -638,7 +652,7 @@ export class AccountsApi extends BaseAPI {
638
652
  }
639
653
 
640
654
  /**
641
- * Returns a list of accounts you have previously created. The accounts are returned in sorted order, with the oldest account appearing first. For more information about pagination, read the Pagination documentation.
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.
642
656
  * @summary List accounts
643
657
  * @param {AccountsApiListAccountsRequest} requestParameters Request parameters.
644
658
  * @param {*} [options] Override http request option.
@@ -646,7 +660,7 @@ export class AccountsApi extends BaseAPI {
646
660
  * @memberof AccountsApi
647
661
  */
648
662
  public listAccounts(requestParameters: AccountsApiListAccountsRequest = {}, options?: AxiosRequestConfig) {
649
- 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));
650
664
  }
651
665
 
652
666
  /**
package/api.ts CHANGED
@@ -25,8 +25,3 @@ import { AccountsApi } from './api';
25
25
 
26
26
  export * from './api/accounts-api';
27
27
 
28
-
29
- export enum Environment {
30
- Production = 'https://apiv2.emil.de',
31
- Test = 'https://apiv2-test.emil.de',
32
- }
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
- axios.interceptors.response.use(
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) {
@@ -123,28 +107,32 @@ export class BaseAPI {
123
107
  const options: AxiosRequestConfig = {
124
108
  method: 'POST',
125
109
  url: `${this.configuration.basePath}/authservice/v1/login`,
126
- headers: {'Content-Type': 'application/json'},
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.configuration.refreshToken = refreshToken;
124
+ this.tokenData.username = username;
125
+ this.tokenData.accessToken = accessToken;
126
+
127
+ this.storeTokenData({
128
+ ...this.tokenData
129
+ });
142
130
  }
143
131
 
144
- async refreshToken(): Promise<string> {
145
- const { username, refreshToken } = this.configuration;
132
+ async refreshTokenInternal(): Promise<string> {
133
+ const { username } = this.configuration;
146
134
 
147
- if (!username || !refreshToken) {
135
+ if (!username) {
148
136
  return '';
149
137
  }
150
138
 
@@ -152,10 +140,9 @@ export class BaseAPI {
152
140
  method: 'POST',
153
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 extractRefreshToken(response: AxiosResponse): string {
168
- if (response.headers && response.headers['set-cookie']
169
- && response.headers['set-cookie'].length > 0) {
154
+ private storeTokenData(tokenData?: TokenData) {
155
+ if (typeof window !== 'undefined') {
156
+ defaultStorage().set<TokenData>(TOKEN_DATA, tokenData);
157
+ }
158
+ }
170
159
 
171
- return `${response.headers['set-cookie'][0].split(';')[0]};`;
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
- return '';
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
@@ -135,3 +135,64 @@ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxi
135
135
  return axios.request<T, R>(axiosRequestArgs);
136
136
  };
137
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;