@emilgroup/tenant-sdk 1.4.0 → 1.5.1

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 (80) hide show
  1. package/.openapi-generator/FILES +15 -0
  2. package/README.md +5 -22
  3. package/api/custom-schema-api.ts +0 -4
  4. package/api/data-report-api.ts +673 -0
  5. package/api/data-report-executor-api.ts +161 -0
  6. package/api/invite-organizations-api.ts +0 -4
  7. package/api/invite-users-api.ts +0 -4
  8. package/api/list-organization-invitations-api.ts +0 -4
  9. package/api/organizations-api.ts +0 -4
  10. package/api/re-invite-an-organization-api.ts +0 -4
  11. package/api/roles-api.ts +0 -4
  12. package/api/settings-api.ts +0 -4
  13. package/api/users-api.ts +0 -4
  14. package/api.ts +4 -4
  15. package/base.ts +59 -93
  16. package/common.ts +0 -1
  17. package/configuration.ts +0 -8
  18. package/dist/api/custom-schema-api.js +4 -8
  19. package/dist/api/data-report-api.d.ts +380 -0
  20. package/dist/api/data-report-api.js +632 -0
  21. package/dist/api/data-report-executor-api.d.ts +93 -0
  22. package/dist/api/data-report-executor-api.js +220 -0
  23. package/dist/api/invite-organizations-api.js +1 -5
  24. package/dist/api/invite-users-api.js +5 -9
  25. package/dist/api/list-organization-invitations-api.js +1 -5
  26. package/dist/api/organizations-api.js +3 -7
  27. package/dist/api/re-invite-an-organization-api.js +1 -5
  28. package/dist/api/roles-api.js +1 -5
  29. package/dist/api/settings-api.js +1 -5
  30. package/dist/api/users-api.js +9 -13
  31. package/dist/api.d.ts +2 -0
  32. package/dist/api.js +2 -0
  33. package/dist/base.d.ts +5 -9
  34. package/dist/base.js +40 -136
  35. package/dist/common.d.ts +0 -1
  36. package/dist/common.js +1 -2
  37. package/dist/configuration.d.ts +0 -7
  38. package/dist/models/create-data-report-request-dto.d.ts +61 -0
  39. package/dist/models/create-data-report-request-dto.js +15 -0
  40. package/dist/models/create-data-report-response-class.d.ts +25 -0
  41. package/dist/models/create-data-report-response-class.js +15 -0
  42. package/dist/models/data-report-class.d.ts +79 -0
  43. package/dist/models/data-report-class.js +15 -0
  44. package/dist/models/data-report-filter-class.d.ts +72 -0
  45. package/dist/models/data-report-filter-class.js +15 -0
  46. package/dist/models/data-report-filter-dto.d.ts +48 -0
  47. package/dist/models/data-report-filter-dto.js +15 -0
  48. package/dist/models/data-report-filter-single-value-dto.d.ts +42 -0
  49. package/dist/models/data-report-filter-single-value-dto.js +15 -0
  50. package/dist/models/data-report-filter-value-dto.d.ts +31 -0
  51. package/dist/models/data-report-filter-value-dto.js +15 -0
  52. package/dist/models/get-data-report-response-class.d.ts +25 -0
  53. package/dist/models/get-data-report-response-class.js +15 -0
  54. package/dist/models/index.d.ts +13 -0
  55. package/dist/models/index.js +13 -0
  56. package/dist/models/list-data-reports-response-class.d.ts +31 -0
  57. package/dist/models/list-data-reports-response-class.js +15 -0
  58. package/dist/models/run-data-report-request-dto.d.ts +31 -0
  59. package/dist/models/run-data-report-request-dto.js +15 -0
  60. package/dist/models/run-data-report-response-class.d.ts +24 -0
  61. package/dist/models/run-data-report-response-class.js +15 -0
  62. package/dist/models/update-data-report-request-dto.d.ts +61 -0
  63. package/dist/models/update-data-report-request-dto.js +15 -0
  64. package/dist/models/update-data-report-response-class.d.ts +25 -0
  65. package/dist/models/update-data-report-response-class.js +15 -0
  66. package/models/create-data-report-request-dto.ts +67 -0
  67. package/models/create-data-report-response-class.ts +31 -0
  68. package/models/data-report-class.ts +85 -0
  69. package/models/data-report-filter-class.ts +78 -0
  70. package/models/data-report-filter-dto.ts +54 -0
  71. package/models/data-report-filter-single-value-dto.ts +48 -0
  72. package/models/data-report-filter-value-dto.ts +37 -0
  73. package/models/get-data-report-response-class.ts +31 -0
  74. package/models/index.ts +13 -0
  75. package/models/list-data-reports-response-class.ts +37 -0
  76. package/models/run-data-report-request-dto.ts +37 -0
  77. package/models/run-data-report-response-class.ts +30 -0
  78. package/models/update-data-report-request-dto.ts +67 -0
  79. package/models/update-data-report-response-class.ts +31 -0
  80. package/package.json +3 -5
@@ -0,0 +1,161 @@
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 { RunDataReportRequestDto } from '../models';
25
+ // @ts-ignore
26
+ import { RunDataReportResponseClass } from '../models';
27
+ /**
28
+ * DataReportExecutorApi - axios parameter creator
29
+ * @export
30
+ */
31
+ export const DataReportExecutorApiAxiosParamCreator = function (configuration?: Configuration) {
32
+ return {
33
+ /**
34
+ *
35
+ * @param {RunDataReportRequestDto} runDataReportRequestDto
36
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
37
+ * @param {*} [options] Override http request option.
38
+ * @throws {RequiredError}
39
+ */
40
+ runDataReport: async (runDataReportRequestDto: RunDataReportRequestDto, authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
41
+ // verify required parameter 'runDataReportRequestDto' is not null or undefined
42
+ assertParamExists('runDataReport', 'runDataReportRequestDto', runDataReportRequestDto)
43
+ const localVarPath = `/tenantservice/v1/data-report-executor`;
44
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
45
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
46
+ let baseOptions;
47
+ let baseAccessToken;
48
+ if (configuration) {
49
+ baseOptions = configuration.baseOptions;
50
+ baseAccessToken = configuration.accessToken;
51
+ }
52
+
53
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
54
+ const localVarHeaderParameter = {} as any;
55
+ const localVarQueryParameter = {} as any;
56
+
57
+ // authentication bearer required
58
+ // http bearer authentication required
59
+ await setBearerAuthToObject(localVarHeaderParameter, configuration)
60
+
61
+ if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
62
+ localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
63
+ }
64
+
65
+
66
+
67
+ localVarHeaderParameter['Content-Type'] = 'application/json';
68
+
69
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
70
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
71
+ localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
72
+ localVarRequestOptions.data = serializeDataIfNeeded(runDataReportRequestDto, localVarRequestOptions, configuration)
73
+
74
+ return {
75
+ url: toPathString(localVarUrlObj),
76
+ options: localVarRequestOptions,
77
+ };
78
+ },
79
+ }
80
+ };
81
+
82
+ /**
83
+ * DataReportExecutorApi - functional programming interface
84
+ * @export
85
+ */
86
+ export const DataReportExecutorApiFp = function(configuration?: Configuration) {
87
+ const localVarAxiosParamCreator = DataReportExecutorApiAxiosParamCreator(configuration)
88
+ return {
89
+ /**
90
+ *
91
+ * @param {RunDataReportRequestDto} runDataReportRequestDto
92
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
93
+ * @param {*} [options] Override http request option.
94
+ * @throws {RequiredError}
95
+ */
96
+ async runDataReport(runDataReportRequestDto: RunDataReportRequestDto, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RunDataReportResponseClass>> {
97
+ const localVarAxiosArgs = await localVarAxiosParamCreator.runDataReport(runDataReportRequestDto, authorization, options);
98
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
99
+ },
100
+ }
101
+ };
102
+
103
+ /**
104
+ * DataReportExecutorApi - factory interface
105
+ * @export
106
+ */
107
+ export const DataReportExecutorApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
108
+ const localVarFp = DataReportExecutorApiFp(configuration)
109
+ return {
110
+ /**
111
+ *
112
+ * @param {RunDataReportRequestDto} runDataReportRequestDto
113
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
114
+ * @param {*} [options] Override http request option.
115
+ * @throws {RequiredError}
116
+ */
117
+ runDataReport(runDataReportRequestDto: RunDataReportRequestDto, authorization?: string, options?: any): AxiosPromise<RunDataReportResponseClass> {
118
+ return localVarFp.runDataReport(runDataReportRequestDto, authorization, options).then((request) => request(axios, basePath));
119
+ },
120
+ };
121
+ };
122
+
123
+ /**
124
+ * Request parameters for runDataReport operation in DataReportExecutorApi.
125
+ * @export
126
+ * @interface DataReportExecutorApiRunDataReportRequest
127
+ */
128
+ export interface DataReportExecutorApiRunDataReportRequest {
129
+ /**
130
+ *
131
+ * @type {RunDataReportRequestDto}
132
+ * @memberof DataReportExecutorApiRunDataReport
133
+ */
134
+ readonly runDataReportRequestDto: RunDataReportRequestDto
135
+
136
+ /**
137
+ * Bearer Token: provided by the login endpoint under the name accessToken.
138
+ * @type {string}
139
+ * @memberof DataReportExecutorApiRunDataReport
140
+ */
141
+ readonly authorization?: string
142
+ }
143
+
144
+ /**
145
+ * DataReportExecutorApi - object-oriented interface
146
+ * @export
147
+ * @class DataReportExecutorApi
148
+ * @extends {BaseAPI}
149
+ */
150
+ export class DataReportExecutorApi extends BaseAPI {
151
+ /**
152
+ *
153
+ * @param {DataReportExecutorApiRunDataReportRequest} requestParameters Request parameters.
154
+ * @param {*} [options] Override http request option.
155
+ * @throws {RequiredError}
156
+ * @memberof DataReportExecutorApi
157
+ */
158
+ public runDataReport(requestParameters: DataReportExecutorApiRunDataReportRequest, options?: AxiosRequestConfig) {
159
+ return DataReportExecutorApiFp(this.configuration).runDataReport(requestParameters.runDataReportRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
160
+ }
161
+ }
@@ -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,16 +15,14 @@
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';
25
21
  // @ts-ignore
26
22
  import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
27
23
  import { CustomSchemaApi } from './api';
24
+ import { DataReportApi } from './api';
25
+ import { DataReportExecutorApi } from './api';
28
26
  import { InviteOrganizationsApi } from './api';
29
27
  import { InviteUsersApi } from './api';
30
28
  import { ListOrganizationInvitationsApi } from './api';
@@ -36,6 +34,8 @@ import { UsersApi } from './api';
36
34
 
37
35
 
38
36
  export * from './api/custom-schema-api';
37
+ export * from './api/data-report-api';
38
+ export * from './api/data-report-executor-api';
39
39
  export * from './api/invite-organizations-api';
40
40
  export * from './api/invite-users-api';
41
41
  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;
@@ -85,10 +85,6 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
- // URLSearchParams not necessarily used
89
- // @ts-ignore
90
- var url_1 = require("url");
91
- var FormData = require('form-data');
92
88
  /**
93
89
  * CustomSchemaApi - axios parameter creator
94
90
  * @export
@@ -114,7 +110,7 @@ var CustomSchemaApiAxiosParamCreator = function (configuration) {
114
110
  // verify required parameter 'createCustomSchemaRequestDto' is not null or undefined
115
111
  (0, common_1.assertParamExists)('createCustomSchema', 'createCustomSchemaRequestDto', createCustomSchemaRequestDto);
116
112
  localVarPath = "/tenantservice/v1/custom-schemas";
117
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
113
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
118
114
  if (configuration) {
119
115
  baseOptions = configuration.baseOptions;
120
116
  baseAccessToken = configuration.accessToken;
@@ -165,7 +161,7 @@ var CustomSchemaApiAxiosParamCreator = function (configuration) {
165
161
  (0, common_1.assertParamExists)('getCustomSchema', 'code', code);
166
162
  localVarPath = "/tenantservice/v1/custom-schemas/{code}"
167
163
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
168
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
164
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
169
165
  if (configuration) {
170
166
  baseOptions = configuration.baseOptions;
171
167
  baseAccessToken = configuration.accessToken;
@@ -218,7 +214,7 @@ var CustomSchemaApiAxiosParamCreator = function (configuration) {
218
214
  switch (_a.label) {
219
215
  case 0:
220
216
  localVarPath = "/tenantservice/v1/custom-schemas";
221
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
217
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
222
218
  if (configuration) {
223
219
  baseOptions = configuration.baseOptions;
224
220
  baseAccessToken = configuration.accessToken;
@@ -287,7 +283,7 @@ var CustomSchemaApiAxiosParamCreator = function (configuration) {
287
283
  (0, common_1.assertParamExists)('updateCustomSchema', 'updateCustomSchemaRequestDto', updateCustomSchemaRequestDto);
288
284
  localVarPath = "/tenantservice/v1/custom-schemas/{code}"
289
285
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
290
- localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
286
+ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
291
287
  if (configuration) {
292
288
  baseOptions = configuration.baseOptions;
293
289
  baseAccessToken = configuration.accessToken;