@emilgroup/tenant-sdk 1.5.0 → 1.7.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 (50) hide show
  1. package/.openapi-generator/FILES +3 -0
  2. package/README.md +5 -22
  3. package/api/custom-schema-api.ts +0 -4
  4. package/api/data-report-api.ts +0 -4
  5. package/api/data-report-executor-api.ts +0 -4
  6. package/api/default-api.ts +120 -0
  7. package/api/invite-organizations-api.ts +0 -4
  8. package/api/invite-users-api.ts +0 -4
  9. package/api/list-organization-invitations-api.ts +0 -4
  10. package/api/organizations-api.ts +0 -4
  11. package/api/re-invite-an-organization-api.ts +0 -4
  12. package/api/roles-api.ts +0 -4
  13. package/api/settings-api.ts +0 -4
  14. package/api/users-api.ts +0 -4
  15. package/api.ts +2 -4
  16. package/base.ts +59 -93
  17. package/common.ts +0 -1
  18. package/configuration.ts +0 -8
  19. package/dist/api/custom-schema-api.js +4 -8
  20. package/dist/api/data-report-api.js +5 -9
  21. package/dist/api/data-report-executor-api.js +1 -5
  22. package/dist/api/default-api.d.ts +66 -0
  23. package/dist/api/default-api.js +196 -0
  24. package/dist/api/invite-organizations-api.js +1 -5
  25. package/dist/api/invite-users-api.js +5 -9
  26. package/dist/api/list-organization-invitations-api.js +1 -5
  27. package/dist/api/organizations-api.js +3 -7
  28. package/dist/api/re-invite-an-organization-api.js +1 -5
  29. package/dist/api/roles-api.js +1 -5
  30. package/dist/api/settings-api.js +1 -5
  31. package/dist/api/users-api.js +9 -13
  32. package/dist/api.d.ts +1 -0
  33. package/dist/api.js +1 -0
  34. package/dist/base.d.ts +5 -9
  35. package/dist/base.js +40 -136
  36. package/dist/common.d.ts +0 -1
  37. package/dist/common.js +1 -2
  38. package/dist/configuration.d.ts +0 -7
  39. package/dist/models/custom-field-dto.d.ts +7 -1
  40. package/dist/models/index.d.ts +2 -0
  41. package/dist/models/index.js +2 -0
  42. package/dist/models/inline-response200.d.ts +54 -0
  43. package/dist/models/inline-response200.js +15 -0
  44. package/dist/models/inline-response503.d.ts +54 -0
  45. package/dist/models/inline-response503.js +15 -0
  46. package/models/custom-field-dto.ts +7 -1
  47. package/models/index.ts +2 -0
  48. package/models/inline-response200.ts +48 -0
  49. package/models/inline-response503.ts +48 -0
  50. package/package.json +3 -5
@@ -6,6 +6,7 @@ api.ts
6
6
  api/custom-schema-api.ts
7
7
  api/data-report-api.ts
8
8
  api/data-report-executor-api.ts
9
+ api/default-api.ts
9
10
  api/invite-organizations-api.ts
10
11
  api/invite-users-api.ts
11
12
  api/list-organization-invitations-api.ts
@@ -51,6 +52,8 @@ models/get-organization-response-class.ts
51
52
  models/get-settings-response-class.ts
52
53
  models/get-user-response-class.ts
53
54
  models/index.ts
55
+ models/inline-response200.ts
56
+ models/inline-response503.ts
54
57
  models/invite-class.ts
55
58
  models/invite-org-request-dto.ts
56
59
  models/invite-user-request-dto.ts
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Emil Tenant SDK
2
2
 
3
- This TypeScript/JavaScript client utilizes [axios](https://github.com/axios/axios). The generated Node module can be used with Nodejs based applications.
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).
4
4
 
5
5
  Language level
6
6
  * ES5 - you must have a Promises/A+ library installed
@@ -17,11 +17,11 @@ Although this package can be used in both TypeScript and JavaScript, it is inten
17
17
  Navigate to the folder of your consuming project and run one of the following commands:
18
18
 
19
19
  ```
20
- npm install @emilgroup/tenant-sdk@1.5.0 --save
20
+ npm install @emilgroup/tenant-sdk@1.7.0 --save
21
21
  ```
22
22
  or
23
23
  ```
24
- yarn add @emilgroup/tenant-sdk@1.5.0
24
+ yarn add @emilgroup/tenant-sdk@1.7.0
25
25
  ```
26
26
 
27
27
  And then you can import `UsersApi`.
@@ -31,32 +31,15 @@ import { UsersApi } from '@emilgroup/tenant-sdk'
31
31
 
32
32
  const usersApi = new UsersApi();
33
33
  ```
34
- ## Credentials
35
34
 
36
- To use authentication protected endpoints, you have to first authorize. To do so, the easiest way is to provide a configuration file under `~/.emil/credentials` with the following content:
37
-
38
- ```shell
39
- emil_username=XXXXX@XXXX.XXX
40
- emil_password=XXXXXXXXXXXXXX
41
- ```
42
-
43
- It is also possible to provide environment variables instead:
44
-
45
- ```shell
46
- export EMIL_USERNAME=XXXXX@XXXX.XXX
47
- export EMIL_PASSWORD=XXXXXXXXXXXXXX
48
- ```
49
-
50
- ## Example
51
-
52
- Here is a basic functionning example:
35
+ To use authentication protected endpoints, you have to first authorize. To do so, use the `authorize` function in `UsersApi`:
53
36
 
54
37
  ```ts
55
38
  async function listUsers(): Promise<Void> {
56
39
  try {
57
40
  const usersApi = new UsersApi();
58
41
 
59
- await usersApi.initialize(); // should be called only once per Api.
42
+ await usersApi.authorize('username', 'password');
60
43
 
61
44
  const { data: { items } } = await usersApi.listUsers();
62
45
 
@@ -32,10 +32,6 @@ import { ListCustomSchemasResponseClass } from '../models';
32
32
  import { UpdateCustomSchemaRequestDto } from '../models';
33
33
  // @ts-ignore
34
34
  import { UpdateCustomSchemaResponseClass } 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
  * CustomSchemaApi - axios parameter creator
41
37
  * @export
@@ -32,10 +32,6 @@ import { ListDataReportsResponseClass } from '../models';
32
32
  import { UpdateDataReportRequestDto } from '../models';
33
33
  // @ts-ignore
34
34
  import { UpdateDataReportResponseClass } 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
  * DataReportApi - axios parameter creator
41
37
  * @export
@@ -24,10 +24,6 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
24
24
  import { RunDataReportRequestDto } from '../models';
25
25
  // @ts-ignore
26
26
  import { RunDataReportResponseClass } from '../models';
27
- // URLSearchParams not necessarily used
28
- // @ts-ignore
29
- import { URL, URLSearchParams } from 'url';
30
- const FormData = require('form-data');
31
27
  /**
32
28
  * DataReportExecutorApi - axios parameter creator
33
29
  * @export
@@ -0,0 +1,120 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL Tenant Service
5
+ * The EMIL TenantService API description
6
+ *
7
+ * The version of the OpenAPI document: 1.0
8
+ * Contact: kontakt@emil.de
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
17
+ import { Configuration } from '../configuration';
18
+ // Some imports not used depending on template conditions
19
+ // @ts-ignore
20
+ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
21
+ // @ts-ignore
22
+ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
23
+ // @ts-ignore
24
+ import { InlineResponse200 } from '../models';
25
+ // @ts-ignore
26
+ import { InlineResponse503 } from '../models';
27
+ /**
28
+ * DefaultApi - axios parameter creator
29
+ * @export
30
+ */
31
+ export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) {
32
+ return {
33
+ /**
34
+ *
35
+ * @param {*} [options] Override http request option.
36
+ * @throws {RequiredError}
37
+ */
38
+ check: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
39
+ const localVarPath = `/tenantservice/health`;
40
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
41
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
42
+ let baseOptions;
43
+ let baseAccessToken;
44
+ if (configuration) {
45
+ baseOptions = configuration.baseOptions;
46
+ baseAccessToken = configuration.accessToken;
47
+ }
48
+
49
+ const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
50
+ const localVarHeaderParameter = {} as any;
51
+ const localVarQueryParameter = {} as any;
52
+
53
+
54
+
55
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
56
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
57
+ localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
58
+
59
+ return {
60
+ url: toPathString(localVarUrlObj),
61
+ options: localVarRequestOptions,
62
+ };
63
+ },
64
+ }
65
+ };
66
+
67
+ /**
68
+ * DefaultApi - functional programming interface
69
+ * @export
70
+ */
71
+ export const DefaultApiFp = function(configuration?: Configuration) {
72
+ const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration)
73
+ return {
74
+ /**
75
+ *
76
+ * @param {*} [options] Override http request option.
77
+ * @throws {RequiredError}
78
+ */
79
+ async check(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse200>> {
80
+ const localVarAxiosArgs = await localVarAxiosParamCreator.check(options);
81
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
82
+ },
83
+ }
84
+ };
85
+
86
+ /**
87
+ * DefaultApi - factory interface
88
+ * @export
89
+ */
90
+ export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
91
+ const localVarFp = DefaultApiFp(configuration)
92
+ return {
93
+ /**
94
+ *
95
+ * @param {*} [options] Override http request option.
96
+ * @throws {RequiredError}
97
+ */
98
+ check(options?: any): AxiosPromise<InlineResponse200> {
99
+ return localVarFp.check(options).then((request) => request(axios, basePath));
100
+ },
101
+ };
102
+ };
103
+
104
+ /**
105
+ * DefaultApi - object-oriented interface
106
+ * @export
107
+ * @class DefaultApi
108
+ * @extends {BaseAPI}
109
+ */
110
+ export class DefaultApi extends BaseAPI {
111
+ /**
112
+ *
113
+ * @param {*} [options] Override http request option.
114
+ * @throws {RequiredError}
115
+ * @memberof DefaultApi
116
+ */
117
+ public check(options?: AxiosRequestConfig) {
118
+ return DefaultApiFp(this.configuration).check(options).then((request) => request(this.axios, this.basePath));
119
+ }
120
+ }
@@ -24,10 +24,6 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
24
24
  import { InviteOrgRequestDto } from '../models';
25
25
  // @ts-ignore
26
26
  import { OrgInvitationResponseClass } from '../models';
27
- // URLSearchParams not necessarily used
28
- // @ts-ignore
29
- import { URL, URLSearchParams } from 'url';
30
- const FormData = require('form-data');
31
27
  /**
32
28
  * InviteOrganizationsApi - axios parameter creator
33
29
  * @export
@@ -36,10 +36,6 @@ import { InviteUsersRequestDto } from '../models';
36
36
  import { InviteUsersResponseClass } from '../models';
37
37
  // @ts-ignore
38
38
  import { ListInvitesResponseClass } from '../models';
39
- // URLSearchParams not necessarily used
40
- // @ts-ignore
41
- import { URL, URLSearchParams } from 'url';
42
- const FormData = require('form-data');
43
39
  /**
44
40
  * InviteUsersApi - axios parameter creator
45
41
  * @export
@@ -22,10 +22,6 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj
22
22
  import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
23
23
  // @ts-ignore
24
24
  import { ListOrgInvitationsResponseClass } from '../models';
25
- // URLSearchParams not necessarily used
26
- // @ts-ignore
27
- import { URL, URLSearchParams } from 'url';
28
- const FormData = require('form-data');
29
25
  /**
30
26
  * ListOrganizationInvitationsApi - axios parameter creator
31
27
  * @export
@@ -28,10 +28,6 @@ import { ListOrganizationsResponseClass } from '../models';
28
28
  import { UpdateOrganizationRequestDtoRest } from '../models';
29
29
  // @ts-ignore
30
30
  import { UpdateOrganizationResponseClass } from '../models';
31
- // URLSearchParams not necessarily used
32
- // @ts-ignore
33
- import { URL, URLSearchParams } from 'url';
34
- const FormData = require('form-data');
35
31
  /**
36
32
  * OrganizationsApi - axios parameter creator
37
33
  * @export
@@ -24,10 +24,6 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
24
24
  import { OrgInvitationResponseClass } from '../models';
25
25
  // @ts-ignore
26
26
  import { ReInviteOrgRequestDto } from '../models';
27
- // URLSearchParams not necessarily used
28
- // @ts-ignore
29
- import { URL, URLSearchParams } from 'url';
30
- const FormData = require('form-data');
31
27
  /**
32
28
  * ReInviteAnOrganizationApi - axios parameter creator
33
29
  * @export
package/api/roles-api.ts CHANGED
@@ -22,10 +22,6 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj
22
22
  import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
23
23
  // @ts-ignore
24
24
  import { ListRolesResponseClass } from '../models';
25
- // URLSearchParams not necessarily used
26
- // @ts-ignore
27
- import { URL, URLSearchParams } from 'url';
28
- const FormData = require('form-data');
29
25
  /**
30
26
  * RolesApi - axios parameter creator
31
27
  * @export
@@ -22,10 +22,6 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj
22
22
  import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
23
23
  // @ts-ignore
24
24
  import { GetSettingsResponseClass } from '../models';
25
- // URLSearchParams not necessarily used
26
- // @ts-ignore
27
- import { URL, URLSearchParams } from 'url';
28
- const FormData = require('form-data');
29
25
  /**
30
26
  * SettingsApi - axios parameter creator
31
27
  * @export
package/api/users-api.ts CHANGED
@@ -46,10 +46,6 @@ import { EnableUsersResponseClass } from '../models';
46
46
  import { GetUserResponseClass } from '../models';
47
47
  // @ts-ignore
48
48
  import { ListUsersResponseClass } from '../models';
49
- // URLSearchParams not necessarily used
50
- // @ts-ignore
51
- import { URL, URLSearchParams } from 'url';
52
- const FormData = require('form-data');
53
49
  /**
54
50
  * UsersApi - axios parameter creator
55
51
  * @export
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';
@@ -27,6 +23,7 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
27
23
  import { CustomSchemaApi } from './api';
28
24
  import { DataReportApi } from './api';
29
25
  import { DataReportExecutorApi } from './api';
26
+ import { DefaultApi } from './api';
30
27
  import { InviteOrganizationsApi } from './api';
31
28
  import { InviteUsersApi } from './api';
32
29
  import { ListOrganizationInvitationsApi } from './api';
@@ -40,6 +37,7 @@ import { UsersApi } from './api';
40
37
  export * from './api/custom-schema-api';
41
38
  export * from './api/data-report-api';
42
39
  export * from './api/data-report-executor-api';
40
+ export * from './api/default-api';
43
41
  export * from './api/invite-organizations-api';
44
42
  export * from './api/invite-users-api';
45
43
  export * from './api/list-organization-invitations-api';
package/base.ts CHANGED
@@ -14,20 +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
- import * as fs from 'fs';
21
- import * as path from 'path';
22
- import * as os from 'os';
23
21
 
24
- export const BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
25
- const CONFIG_DIRECTORY = '.emil';
26
- const CONFIG_FILENAME = 'credentials';
27
- const KEY_USERNAME = 'emil_username';
28
- const KEY_PASSWORD = 'emil_password';
29
22
 
30
- const filePath = os.homedir() + path.sep + CONFIG_DIRECTORY + path.sep + CONFIG_FILENAME;
23
+ export const BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
31
24
  /**
32
25
  *
33
26
  * @export
@@ -67,7 +60,13 @@ export interface RequestArgs {
67
60
  options: AxiosRequestConfig;
68
61
  }
69
62
 
63
+ interface TokenData {
64
+ accessToken?: string;
65
+ username?: string;
66
+ }
67
+
70
68
  const NETWORK_ERROR_MESSAGE = "Network Error";
69
+ const TOKEN_DATA = 'APP_TOKEN';
71
70
 
72
71
  /**
73
72
  *
@@ -75,75 +74,31 @@ const NETWORK_ERROR_MESSAGE = "Network Error";
75
74
  * @class BaseAPI
76
75
  */
77
76
  export class BaseAPI {
78
- protected configuration: Configuration;
79
- private username?: string;
80
- private password?: string;
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();
81
85
 
82
- constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
83
86
  if (configuration) {
84
87
  this.configuration = configuration;
85
88
  this.basePath = configuration.basePath || this.basePath;
86
89
  } else {
90
+ const { accessToken, username } = this.tokenData;
91
+
87
92
  this.configuration = new Configuration({
88
93
  basePath: this.basePath,
94
+ accessToken: accessToken ? `Bearer ${accessToken}` : '',
95
+ username,
89
96
  });
90
97
  }
91
98
 
92
99
  this.attachInterceptor(axios);
93
100
  }
94
101
 
95
- async initialize(env: Environment = Environment.Production) {
96
- this.configuration.basePath = env;
97
-
98
- await this.loadCredentials();
99
-
100
- if (this.username) {
101
- await this.authorize(this.username, this.password);
102
- this.password = null; // to avoid keeping password loaded in memory.
103
- }
104
- }
105
-
106
- private async loadCredentials() {
107
- try {
108
- await this.readConfigFile();
109
- } catch (error) {
110
- console.warn(`No credentials file found. Check that ${filePath} exists.`);
111
- }
112
-
113
- this.readEnvVariables();
114
-
115
- if (!this.username) {
116
- console.info(`No credentials found in credentials file or environment variables. Either provide some or use
117
- authorize() function.`);
118
- }
119
- }
120
-
121
- private async readConfigFile() {
122
- const file = await fs.promises.readFile(filePath, 'utf-8');
123
-
124
- const lines = file.split(os.EOL)
125
- .filter(Boolean);
126
-
127
- lines.forEach((line: string) => {
128
- if (line.startsWith(KEY_USERNAME)) {
129
- this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
130
- } else if (line.startsWith(KEY_PASSWORD)) {
131
- this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
132
- }
133
- });
134
- }
135
-
136
- private readEnvVariables(): boolean {
137
- if (process.env.EMIL_USERNAME) {
138
- this.username = process.env.EMIL_USERNAME;
139
- this.password = process.env.EMIL_PASSWORD || '';
140
-
141
- return true;
142
- }
143
-
144
- return false;
145
- }
146
-
147
102
  selectEnvironment(env: Environment) {
148
103
  this.configuration.basePath = env;
149
104
  }
@@ -163,18 +118,21 @@ export class BaseAPI {
163
118
  const response = await globalAxios.request<LoginClass>(options);
164
119
 
165
120
  const { data: { accessToken } } = response;
121
+
166
122
  this.configuration.username = username;
167
123
  this.configuration.accessToken = `Bearer ${accessToken}`;
124
+ this.tokenData.username = username;
125
+ this.tokenData.accessToken = accessToken;
168
126
 
169
- const refreshToken = this.extractRefreshToken(response)
170
- this.configuration.refreshToken = refreshToken;
127
+ this.storeTokenData({
128
+ ...this.tokenData
129
+ });
171
130
  }
172
131
 
173
132
  async refreshTokenInternal(): Promise<string> {
174
- const { username, refreshToken } = this.configuration;
175
-
133
+ const { username } = this.configuration;
176
134
 
177
- if (!username || !refreshToken) {
135
+ if (!username) {
178
136
  return '';
179
137
  }
180
138
 
@@ -183,7 +141,6 @@ export class BaseAPI {
183
141
  url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
184
142
  headers: {
185
143
  'Content-Type': 'application/json',
186
- Cookie: refreshToken,
187
144
  },
188
145
  data: { username: username },
189
146
  withCredentials: true,
@@ -194,18 +151,22 @@ export class BaseAPI {
194
151
  return accessToken;
195
152
  }
196
153
 
197
- private extractRefreshToken(response: AxiosResponse): string {
198
- if (response.headers && response.headers['set-cookie']
199
- && response.headers['set-cookie'].length > 0) {
200
-
201
- return `${response.headers['set-cookie'][0].split(';')[0]};`;
154
+ private storeTokenData(tokenData?: TokenData) {
155
+ if (typeof window !== 'undefined') {
156
+ defaultStorage().set<TokenData>(TOKEN_DATA, tokenData);
202
157
  }
158
+ }
203
159
 
204
- return '';
160
+ public loadTokenData() {
161
+ if (typeof window !== 'undefined') {
162
+ this.tokenData = defaultStorage().get<TokenData>(TOKEN_DATA) || {};
163
+ } else {
164
+ this.tokenData = {};
165
+ }
205
166
  }
206
167
 
207
- getConfiguration(): Configuration {
208
- return this.configuration;
168
+ public cleanTokenData() {
169
+ this.storeTokenData(null);
209
170
  }
210
171
 
211
172
  private attachInterceptor(axios: AxiosInstance) {
@@ -215,19 +176,25 @@ export class BaseAPI {
215
176
  },
216
177
  async (err) => {
217
178
  let originalConfig = err.config;
218
- if (err.response) {
179
+ if (err.response && !(err.response instanceof XMLHttpRequest)) { // sometimes buggy and is of type request
219
180
  // Access Token was expired
220
- if (err.response.status === 401 && !originalConfig._retry) {
181
+ if ((err.response.status === 401 || err.response.status === 403)
182
+ && !originalConfig._retry) {
221
183
  originalConfig._retry = true;
222
184
  try {
223
- const tokenString = await this.refreshTokenInternal();
185
+ let tokenString = await this.refreshTokenInternal();
224
186
  const accessToken = `Bearer ${tokenString}`;
225
187
 
226
- originalConfig.headers['Authorization'] = `Bearer ${accessToken}`
188
+ delete originalConfig.headers['Authorization']
189
+
190
+ originalConfig.headers['Authorization'] = accessToken;
227
191
 
228
192
  this.configuration.accessToken = accessToken;
193
+ this.tokenData.accessToken = tokenString;
194
+
195
+ this.storeTokenData(this.tokenData);
229
196
 
230
- return axios.request(originalConfig);
197
+ return axios(originalConfig);
231
198
  } catch (_error) {
232
199
  if (_error.response && _error.response.data) {
233
200
  return Promise.reject(_error.response.data);
@@ -235,23 +202,22 @@ export class BaseAPI {
235
202
  return Promise.reject(_error);
236
203
  }
237
204
  }
238
- if (err.response.status === 403 && err.response.data) {
239
- return Promise.reject(err.response.data);
240
- }
241
- } else if(err.message === NETWORK_ERROR_MESSAGE
242
- && err.isAxiosError
205
+ } else if (err.message === NETWORK_ERROR_MESSAGE
243
206
  && originalConfig.headers.hasOwnProperty('Authorization')
244
207
  && _retry_count < 4
245
- ){
208
+ ) {
246
209
  _retry_count++;
247
210
  try {
248
- const tokenString = await this.refreshTokenInternal();
211
+ let tokenString = await this.refreshTokenInternal();
249
212
  const accessToken = `Bearer ${tokenString}`;
250
213
 
251
214
  _retry = true;
252
- originalConfig.headers['Authorization'] = accessToken;
215
+ originalConfig.headers['Authorization'] = accessToken;
253
216
 
254
217
  this.configuration.accessToken = accessToken;
218
+ this.tokenData.accessToken = tokenString;
219
+
220
+ this.storeTokenData(this.tokenData);
255
221
 
256
222
  return axios.request({
257
223
  ...originalConfig,
@@ -261,7 +227,7 @@ export class BaseAPI {
261
227
  return Promise.reject(_error.response.data);
262
228
  }
263
229
  return Promise.reject(_error);
264
- }
230
+ }
265
231
  }
266
232
  return Promise.reject(err);
267
233
  }
package/common.ts CHANGED
@@ -16,7 +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
19
  /**
21
20
  *
22
21
  * @export
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;