@emilgroup/customer-sdk-node 1.3.0 → 1.6.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 +15 -1
- package/README.md +2 -2
- package/api/customers-api.ts +798 -82
- package/base.ts +56 -13
- package/dist/api/customers-api.d.ts +456 -36
- package/dist/api/customers-api.js +579 -40
- package/dist/base.d.ts +1 -0
- package/dist/base.js +46 -8
- package/dist/models/account-class.d.ts +132 -0
- package/dist/models/account-class.js +15 -0
- package/dist/models/create-customer-request-dto.d.ts +0 -7
- package/dist/models/create-customer-response-class.d.ts +3 -2
- package/dist/models/customer-class.d.ts +67 -0
- package/dist/models/customer-class.js +15 -0
- package/dist/models/customer-document-class.d.ts +99 -0
- package/dist/models/customer-document-class.js +36 -0
- package/dist/models/get-customer-document-download-url-response-class.d.ts +24 -0
- package/dist/models/get-customer-document-download-url-response-class.js +15 -0
- package/dist/models/get-customer-response-class.d.ts +25 -0
- package/dist/models/get-customer-response-class.js +15 -0
- package/dist/models/index.d.ts +15 -1
- package/dist/models/index.js +15 -1
- package/dist/models/invoice-class.d.ts +135 -0
- package/dist/models/invoice-class.js +28 -0
- package/dist/models/list-documents-response-class.d.ts +31 -0
- package/dist/models/list-documents-response-class.js +15 -0
- package/dist/models/list-invoices-response-class.d.ts +3 -2
- package/dist/models/request-policy-update-request-dto.d.ts +42 -0
- package/dist/models/request-policy-update-request-dto.js +15 -0
- package/dist/models/reset-password-by-customer-request-dto.d.ts +1 -1
- package/dist/models/shared-invoice-item-class.d.ts +102 -0
- package/dist/models/shared-invoice-item-class.js +15 -0
- package/dist/models/terminate-customer-policy-request-dto.d.ts +24 -0
- package/dist/models/terminate-customer-policy-request-dto.js +15 -0
- package/dist/models/terminate-customer-policy-response-class.d.ts +25 -0
- package/dist/models/terminate-customer-policy-response-class.js +15 -0
- package/dist/models/{create-account-request-dto.d.ts → update-account-request-dto.d.ts} +26 -32
- package/dist/models/{create-account-request-dto.js → update-account-request-dto.js} +2 -2
- package/dist/models/update-customer-request-dto.d.ts +31 -0
- package/dist/models/update-customer-request-dto.js +15 -0
- package/dist/models/update-customer-response-class.d.ts +25 -0
- package/dist/models/update-customer-response-class.js +15 -0
- package/dist/models/withdraw-customer-policy-response-class.d.ts +25 -0
- package/dist/models/withdraw-customer-policy-response-class.js +15 -0
- package/models/account-class.ts +138 -0
- package/models/create-customer-request-dto.ts +0 -7
- package/models/create-customer-response-class.ts +3 -2
- package/models/customer-class.ts +73 -0
- package/models/customer-document-class.ts +108 -0
- package/models/get-customer-document-download-url-response-class.ts +30 -0
- package/models/get-customer-response-class.ts +31 -0
- package/models/index.ts +15 -1
- package/models/invoice-class.ts +145 -0
- package/models/list-documents-response-class.ts +37 -0
- package/models/list-invoices-response-class.ts +3 -2
- package/models/request-policy-update-request-dto.ts +48 -0
- package/models/reset-password-by-customer-request-dto.ts +1 -1
- package/models/shared-invoice-item-class.ts +108 -0
- package/models/terminate-customer-policy-request-dto.ts +30 -0
- package/models/terminate-customer-policy-response-class.ts +31 -0
- package/models/{create-account-request-dto.ts → update-account-request-dto.ts} +26 -32
- package/models/update-customer-request-dto.ts +37 -0
- package/models/update-customer-response-class.ts +31 -0
- package/models/withdraw-customer-policy-response-class.ts +31 -0
- package/package.json +1 -1
package/base.ts
CHANGED
|
@@ -61,6 +61,8 @@ export interface RequestArgs {
|
|
|
61
61
|
options: AxiosRequestConfig;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
const NETWORK_ERROR_MESSAGE = "Network Error";
|
|
65
|
+
|
|
64
66
|
/**
|
|
65
67
|
*
|
|
66
68
|
* @export
|
|
@@ -68,6 +70,7 @@ export interface RequestArgs {
|
|
|
68
70
|
*/
|
|
69
71
|
export class BaseAPI {
|
|
70
72
|
protected configuration: Configuration | undefined;
|
|
73
|
+
private lastRequestConfig?: AxiosRequestConfig;
|
|
71
74
|
private username?: string;
|
|
72
75
|
private password?: string;
|
|
73
76
|
private isCustomerToken = false;
|
|
@@ -156,10 +159,10 @@ export class BaseAPI {
|
|
|
156
159
|
const response = await globalAxios.request<LoginClass>(options);
|
|
157
160
|
|
|
158
161
|
const { data: { accessToken } } = response;
|
|
159
|
-
const refreshToken = this.extractRefreshToken(response)
|
|
160
|
-
|
|
161
162
|
this.configuration.username = username;
|
|
162
163
|
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
164
|
+
|
|
165
|
+
const refreshToken = this.extractRefreshToken(response);
|
|
163
166
|
this.configuration.refreshToken = refreshToken;
|
|
164
167
|
}
|
|
165
168
|
|
|
@@ -184,14 +187,14 @@ export class BaseAPI {
|
|
|
184
187
|
|
|
185
188
|
if (response.data.authenticationResult) {
|
|
186
189
|
const { accessToken } = response.data.authenticationResult;
|
|
187
|
-
const refreshToken = this.extractRefreshToken(response)
|
|
188
190
|
|
|
189
191
|
this.configuration.username = username;
|
|
190
192
|
this.configuration.tenantSlug = tenantSlug;
|
|
191
193
|
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
192
|
-
this.configuration.refreshToken = refreshToken;
|
|
193
|
-
|
|
194
194
|
this.isCustomerToken = true;
|
|
195
|
+
|
|
196
|
+
const refreshToken = this.extractRefreshToken(response);
|
|
197
|
+
this.configuration.refreshToken = refreshToken;
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
return response;
|
|
@@ -213,12 +216,12 @@ export class BaseAPI {
|
|
|
213
216
|
|
|
214
217
|
if (response.data.authenticationResult) {
|
|
215
218
|
const { accessToken } = response.data.authenticationResult;
|
|
216
|
-
const refreshToken = this.extractRefreshToken(response)
|
|
217
219
|
|
|
218
220
|
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
219
|
-
this.configuration.refreshToken = refreshToken;
|
|
220
|
-
|
|
221
221
|
this.isCustomerToken = true;
|
|
222
|
+
|
|
223
|
+
const refreshToken = this.extractRefreshToken(response);
|
|
224
|
+
this.configuration.refreshToken = refreshToken;
|
|
222
225
|
}
|
|
223
226
|
|
|
224
227
|
return response;
|
|
@@ -226,6 +229,7 @@ export class BaseAPI {
|
|
|
226
229
|
|
|
227
230
|
async refreshTokenTenant(): Promise<string> {
|
|
228
231
|
const { username, refreshToken } = this.configuration;
|
|
232
|
+
|
|
229
233
|
|
|
230
234
|
if (!username || !refreshToken) {
|
|
231
235
|
return '';
|
|
@@ -241,7 +245,6 @@ export class BaseAPI {
|
|
|
241
245
|
data: { username: username },
|
|
242
246
|
withCredentials: true,
|
|
243
247
|
};
|
|
244
|
-
|
|
245
248
|
const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
|
|
246
249
|
|
|
247
250
|
return accessToken;
|
|
@@ -265,14 +268,14 @@ export class BaseAPI {
|
|
|
265
268
|
withCredentials: true,
|
|
266
269
|
};
|
|
267
270
|
|
|
268
|
-
|
|
271
|
+
const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
|
|
269
272
|
|
|
270
273
|
return accessToken;
|
|
271
274
|
}
|
|
272
275
|
|
|
273
276
|
private extractRefreshToken(response: AxiosResponse): string {
|
|
274
|
-
if (response.headers && response.headers['set-cookie']
|
|
275
|
-
|
|
277
|
+
if (response.headers && response.headers['set-cookie']
|
|
278
|
+
&& response.headers['set-cookie'].length > 0) {
|
|
276
279
|
|
|
277
280
|
return `${response.headers['set-cookie'][0].split(';')[0]};`;
|
|
278
281
|
}
|
|
@@ -281,12 +284,19 @@ export class BaseAPI {
|
|
|
281
284
|
}
|
|
282
285
|
|
|
283
286
|
private attachInterceptor(axios: AxiosInstance) {
|
|
287
|
+
axios.interceptors.request.use((config) => {
|
|
288
|
+
if (config.url?.indexOf('refresh-token') === -1) {
|
|
289
|
+
this.lastRequestConfig = config;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return config;
|
|
293
|
+
});
|
|
284
294
|
axios.interceptors.response.use(
|
|
285
295
|
(res) => {
|
|
286
296
|
return res;
|
|
287
297
|
},
|
|
288
298
|
async (err) => {
|
|
289
|
-
|
|
299
|
+
let originalConfig = err.config;
|
|
290
300
|
if (err.response) {
|
|
291
301
|
// Access Token was expired
|
|
292
302
|
if (err.response.status === 401 && !originalConfig._retry) {
|
|
@@ -321,6 +331,39 @@ export class BaseAPI {
|
|
|
321
331
|
if (err.response.status === 403 && err.response.data) {
|
|
322
332
|
return Promise.reject(err.response.data);
|
|
323
333
|
}
|
|
334
|
+
} else if (err.message === NETWORK_ERROR_MESSAGE && !originalConfig._retry) {
|
|
335
|
+
try {
|
|
336
|
+
let tokenString: string;
|
|
337
|
+
if (this.isCustomerToken) {
|
|
338
|
+
tokenString = await this.refreshTokenCustomer();
|
|
339
|
+
} else {
|
|
340
|
+
tokenString = await this.refreshTokenTenant();
|
|
341
|
+
}
|
|
342
|
+
const accessToken = `Bearer ${tokenString}`;
|
|
343
|
+
|
|
344
|
+
const localVarHeaderParameter = {} as any;
|
|
345
|
+
localVarHeaderParameter['Authorization'] = accessToken;
|
|
346
|
+
|
|
347
|
+
this.lastRequestConfig.headers = {
|
|
348
|
+
...originalConfig.headers,
|
|
349
|
+
...localVarHeaderParameter,
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
originalConfig = {
|
|
353
|
+
...this.lastRequestConfig,
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
originalConfig._retry = true;
|
|
357
|
+
|
|
358
|
+
this.configuration.accessToken = accessToken;
|
|
359
|
+
|
|
360
|
+
return axios(originalConfig);
|
|
361
|
+
} catch (_error) {
|
|
362
|
+
if (_error.response && _error.response.data) {
|
|
363
|
+
return Promise.reject(_error.response.data);
|
|
364
|
+
}
|
|
365
|
+
return Promise.reject(_error);
|
|
366
|
+
}
|
|
324
367
|
}
|
|
325
368
|
return Promise.reject(err);
|
|
326
369
|
}
|