@emilgroup/customer-sdk-node 1.1.1 → 1.3.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.
@@ -30,6 +30,7 @@ models/policy-premium-class.ts
30
30
  models/policy-premium-item-class.ts
31
31
  models/policy-version-class.ts
32
32
  models/refresh-token-dto.ts
33
+ models/request-policy-update-response-class.ts
33
34
  models/reset-password-by-customer-request-dto.ts
34
35
  models/respond-to-auth-challenge-class.ts
35
36
  models/respond-to-auth-challenge-request-dto.ts
package/README.md CHANGED
@@ -17,29 +17,46 @@ 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/customer-sdk-node@1.1.1 --save
20
+ npm install @emilgroup/customer-sdk-node@1.3.0 --save
21
21
  ```
22
22
  or
23
23
  ```
24
- yarn add @emilgroup/customer-sdk-node@1.1.1
24
+ yarn add @emilgroup/customer-sdk-node@1.3.0
25
25
  ```
26
26
 
27
27
  And then you can import `CustomersApi`.
28
28
 
29
29
  ```ts
30
- import { CustomersApi } from '@emilgroup/customer-sdk'
30
+ import { CustomersApi } from '@emilgroup/customer-sdk-node'
31
31
 
32
32
  const customersApi = new CustomersApi();
33
33
  ```
34
+ ## Credentials
34
35
 
35
- To use authentication protected endpoints, you have to first authorize. To do so, use the `authorize` function in `CustomersApi`:
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:
36
53
 
37
54
  ```ts
38
55
  async function listCustomers(): Promise<Void> {
39
56
  try {
40
57
  const customersApi = new CustomersApi();
41
58
 
42
- await customersApi.authorize('username', 'password');
59
+ await customersApi.initialize(); // should be called only once per Api.
43
60
 
44
61
  const { data: { items } } = await customersApi.listCustomers();
45
62
 
@@ -45,6 +45,8 @@ import { ListPoliciesResponseClass } from '../models';
45
45
  // @ts-ignore
46
46
  import { RefreshTokenDto } from '../models';
47
47
  // @ts-ignore
48
+ import { RequestPolicyUpdateResponseClass } from '../models';
49
+ // @ts-ignore
48
50
  import { ResetPasswordByCustomerRequestDto } from '../models';
49
51
  // @ts-ignore
50
52
  import { RespondToAuthChallengeClass } from '../models';
@@ -228,7 +230,7 @@ export const CustomersApiAxiosParamCreator = function (configuration?: Configura
228
230
  },
229
231
  /**
230
232
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
231
- * @summary Invite by customer
233
+ * @summary Invite a customer by self
232
234
  * @param {InviteByCustomerRequestDto} inviteByCustomerRequestDto
233
235
  * @param {string} [authorization] Bearer Token: provided by the Emil Insurance Suite\&#39;s Auth login endpoint under the name accessToken
234
236
  * @param {*} [options] Override http request option.
@@ -271,7 +273,7 @@ export const CustomersApiAxiosParamCreator = function (configuration?: Configura
271
273
  },
272
274
  /**
273
275
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
274
- * @summary Invite by tenant
276
+ * @summary Invite a customer by tenant
275
277
  * @param {InviteByCustomerRequestDto} inviteByCustomerRequestDto
276
278
  * @param {string} [authorization] Bearer Token: provided by the Emil Insurance Suite\&#39;s Auth login endpoint under the name accessToken
277
279
  * @param {*} [options] Override http request option.
@@ -497,6 +499,81 @@ export const CustomersApiAxiosParamCreator = function (configuration?: Configura
497
499
  options: localVarRequestOptions,
498
500
  };
499
501
  },
502
+ /**
503
+ * Request to update an existing policy by customer
504
+ * @summary Request policy update by customer
505
+ * @param {string} policyCode The policy code
506
+ * @param {string} customerCode The customer code or \&quot;me\&quot; for the currently logged in customer
507
+ * @param {string} code Policy code
508
+ * @param {Array<string>} policyObjects Policy objects
509
+ * @param {string} from Update from
510
+ * @param {string} [to] Update to
511
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
512
+ * @param {*} [options] Override http request option.
513
+ * @throws {RequiredError}
514
+ */
515
+ requestPolicyUpdate: async (policyCode: string, customerCode: string, code: string, policyObjects: Array<string>, from: string, to?: string, authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
516
+ // verify required parameter 'policyCode' is not null or undefined
517
+ assertParamExists('requestPolicyUpdate', 'policyCode', policyCode)
518
+ // verify required parameter 'customerCode' is not null or undefined
519
+ assertParamExists('requestPolicyUpdate', 'customerCode', customerCode)
520
+ // verify required parameter 'code' is not null or undefined
521
+ assertParamExists('requestPolicyUpdate', 'code', code)
522
+ // verify required parameter 'policyObjects' is not null or undefined
523
+ assertParamExists('requestPolicyUpdate', 'policyObjects', policyObjects)
524
+ // verify required parameter 'from' is not null or undefined
525
+ assertParamExists('requestPolicyUpdate', 'from', from)
526
+ const localVarPath = `/v1/customers/{customerCode}/policies/{policyCode}/request-update`
527
+ .replace(`{${"policyCode"}}`, encodeURIComponent(String(policyCode)))
528
+ .replace(`{${"customerCode"}}`, encodeURIComponent(String(customerCode)));
529
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
530
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
531
+ let baseOptions;
532
+ let baseAccessToken;
533
+ if (configuration) {
534
+ baseOptions = configuration.baseOptions;
535
+ baseAccessToken = configuration.accessToken;
536
+ }
537
+
538
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
539
+ const localVarHeaderParameter = {} as any;
540
+ const localVarQueryParameter = {} as any;
541
+
542
+ if (code !== undefined) {
543
+ localVarQueryParameter['code'] = code;
544
+ }
545
+
546
+ if (policyObjects) {
547
+ localVarQueryParameter['policyObjects'] = policyObjects;
548
+ }
549
+
550
+ if (from !== undefined) {
551
+ localVarQueryParameter['from'] = (from as any instanceof Date) ?
552
+ (from as any).toISOString() :
553
+ from;
554
+ }
555
+
556
+ if (to !== undefined) {
557
+ localVarQueryParameter['to'] = (to as any instanceof Date) ?
558
+ (to as any).toISOString() :
559
+ to;
560
+ }
561
+
562
+ if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
563
+ localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
564
+ }
565
+
566
+
567
+
568
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
569
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
570
+ localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
571
+
572
+ return {
573
+ url: toPathString(localVarUrlObj),
574
+ options: localVarRequestOptions,
575
+ };
576
+ },
500
577
  /**
501
578
  * Change customer\'s password using the token provided by the reset password endpoint.
502
579
  * @summary Change password by customer
@@ -710,7 +787,7 @@ export const CustomersApiFp = function(configuration?: Configuration) {
710
787
  },
711
788
  /**
712
789
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
713
- * @summary Invite by customer
790
+ * @summary Invite a customer by self
714
791
  * @param {InviteByCustomerRequestDto} inviteByCustomerRequestDto
715
792
  * @param {string} [authorization] Bearer Token: provided by the Emil Insurance Suite\&#39;s Auth login endpoint under the name accessToken
716
793
  * @param {*} [options] Override http request option.
@@ -722,7 +799,7 @@ export const CustomersApiFp = function(configuration?: Configuration) {
722
799
  },
723
800
  /**
724
801
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
725
- * @summary Invite by tenant
802
+ * @summary Invite a customer by tenant
726
803
  * @param {InviteByCustomerRequestDto} inviteByCustomerRequestDto
727
804
  * @param {string} [authorization] Bearer Token: provided by the Emil Insurance Suite\&#39;s Auth login endpoint under the name accessToken
728
805
  * @param {*} [options] Override http request option.
@@ -780,6 +857,23 @@ export const CustomersApiFp = function(configuration?: Configuration) {
780
857
  const localVarAxiosArgs = await localVarAxiosParamCreator.refreshToken(refreshTokenDto, cookie, options);
781
858
  return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
782
859
  },
860
+ /**
861
+ * Request to update an existing policy by customer
862
+ * @summary Request policy update by customer
863
+ * @param {string} policyCode The policy code
864
+ * @param {string} customerCode The customer code or \&quot;me\&quot; for the currently logged in customer
865
+ * @param {string} code Policy code
866
+ * @param {Array<string>} policyObjects Policy objects
867
+ * @param {string} from Update from
868
+ * @param {string} [to] Update to
869
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
870
+ * @param {*} [options] Override http request option.
871
+ * @throws {RequiredError}
872
+ */
873
+ async requestPolicyUpdate(policyCode: string, customerCode: string, code: string, policyObjects: Array<string>, from: string, to?: string, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RequestPolicyUpdateResponseClass>> {
874
+ const localVarAxiosArgs = await localVarAxiosParamCreator.requestPolicyUpdate(policyCode, customerCode, code, policyObjects, from, to, authorization, options);
875
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
876
+ },
783
877
  /**
784
878
  * Change customer\'s password using the token provided by the reset password endpoint.
785
879
  * @summary Change password by customer
@@ -879,7 +973,7 @@ export const CustomersApiFactory = function (configuration?: Configuration, base
879
973
  },
880
974
  /**
881
975
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
882
- * @summary Invite by customer
976
+ * @summary Invite a customer by self
883
977
  * @param {InviteByCustomerRequestDto} inviteByCustomerRequestDto
884
978
  * @param {string} [authorization] Bearer Token: provided by the Emil Insurance Suite\&#39;s Auth login endpoint under the name accessToken
885
979
  * @param {*} [options] Override http request option.
@@ -890,7 +984,7 @@ export const CustomersApiFactory = function (configuration?: Configuration, base
890
984
  },
891
985
  /**
892
986
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
893
- * @summary Invite by tenant
987
+ * @summary Invite a customer by tenant
894
988
  * @param {InviteByCustomerRequestDto} inviteByCustomerRequestDto
895
989
  * @param {string} [authorization] Bearer Token: provided by the Emil Insurance Suite\&#39;s Auth login endpoint under the name accessToken
896
990
  * @param {*} [options] Override http request option.
@@ -944,6 +1038,22 @@ export const CustomersApiFactory = function (configuration?: Configuration, base
944
1038
  refreshToken(refreshTokenDto: RefreshTokenDto, cookie?: string, options?: any): AxiosPromise<void> {
945
1039
  return localVarFp.refreshToken(refreshTokenDto, cookie, options).then((request) => request(axios, basePath));
946
1040
  },
1041
+ /**
1042
+ * Request to update an existing policy by customer
1043
+ * @summary Request policy update by customer
1044
+ * @param {string} policyCode The policy code
1045
+ * @param {string} customerCode The customer code or \&quot;me\&quot; for the currently logged in customer
1046
+ * @param {string} code Policy code
1047
+ * @param {Array<string>} policyObjects Policy objects
1048
+ * @param {string} from Update from
1049
+ * @param {string} [to] Update to
1050
+ * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
1051
+ * @param {*} [options] Override http request option.
1052
+ * @throws {RequiredError}
1053
+ */
1054
+ requestPolicyUpdate(policyCode: string, customerCode: string, code: string, policyObjects: Array<string>, from: string, to?: string, authorization?: string, options?: any): AxiosPromise<RequestPolicyUpdateResponseClass> {
1055
+ return localVarFp.requestPolicyUpdate(policyCode, customerCode, code, policyObjects, from, to, authorization, options).then((request) => request(axios, basePath));
1056
+ },
947
1057
  /**
948
1058
  * Change customer\'s password using the token provided by the reset password endpoint.
949
1059
  * @summary Change password by customer
@@ -1253,6 +1363,62 @@ export interface CustomersApiRefreshTokenRequest {
1253
1363
  readonly cookie?: string
1254
1364
  }
1255
1365
 
1366
+ /**
1367
+ * Request parameters for requestPolicyUpdate operation in CustomersApi.
1368
+ * @export
1369
+ * @interface CustomersApiRequestPolicyUpdateRequest
1370
+ */
1371
+ export interface CustomersApiRequestPolicyUpdateRequest {
1372
+ /**
1373
+ * The policy code
1374
+ * @type {string}
1375
+ * @memberof CustomersApiRequestPolicyUpdate
1376
+ */
1377
+ readonly policyCode: string
1378
+
1379
+ /**
1380
+ * The customer code or \&quot;me\&quot; for the currently logged in customer
1381
+ * @type {string}
1382
+ * @memberof CustomersApiRequestPolicyUpdate
1383
+ */
1384
+ readonly customerCode: string
1385
+
1386
+ /**
1387
+ * Policy code
1388
+ * @type {string}
1389
+ * @memberof CustomersApiRequestPolicyUpdate
1390
+ */
1391
+ readonly code: string
1392
+
1393
+ /**
1394
+ * Policy objects
1395
+ * @type {Array<string>}
1396
+ * @memberof CustomersApiRequestPolicyUpdate
1397
+ */
1398
+ readonly policyObjects: Array<string>
1399
+
1400
+ /**
1401
+ * Update from
1402
+ * @type {string}
1403
+ * @memberof CustomersApiRequestPolicyUpdate
1404
+ */
1405
+ readonly from: string
1406
+
1407
+ /**
1408
+ * Update to
1409
+ * @type {string}
1410
+ * @memberof CustomersApiRequestPolicyUpdate
1411
+ */
1412
+ readonly to?: string
1413
+
1414
+ /**
1415
+ * Bearer Token: provided by the login endpoint under the name accessToken.
1416
+ * @type {string}
1417
+ * @memberof CustomersApiRequestPolicyUpdate
1418
+ */
1419
+ readonly authorization?: string
1420
+ }
1421
+
1256
1422
  /**
1257
1423
  * Request parameters for resetPassword operation in CustomersApi.
1258
1424
  * @export
@@ -1366,7 +1532,7 @@ export class CustomersApi extends BaseAPI {
1366
1532
 
1367
1533
  /**
1368
1534
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
1369
- * @summary Invite by customer
1535
+ * @summary Invite a customer by self
1370
1536
  * @param {CustomersApiInviteByCustomerRequest} requestParameters Request parameters.
1371
1537
  * @param {*} [options] Override http request option.
1372
1538
  * @throws {RequiredError}
@@ -1378,7 +1544,7 @@ export class CustomersApi extends BaseAPI {
1378
1544
 
1379
1545
  /**
1380
1546
  * Send a customer an invite via email to register. An account should have been created before inviting the customer. To invite users without accounts and policies is not yet supported.
1381
- * @summary Invite by tenant
1547
+ * @summary Invite a customer by tenant
1382
1548
  * @param {CustomersApiInviteByTenantRequest} requestParameters Request parameters.
1383
1549
  * @param {*} [options] Override http request option.
1384
1550
  * @throws {RequiredError}
@@ -1424,6 +1590,18 @@ export class CustomersApi extends BaseAPI {
1424
1590
  return CustomersApiFp(this.configuration).refreshToken(requestParameters.refreshTokenDto, requestParameters.cookie, options).then((request) => request(this.axios, this.basePath));
1425
1591
  }
1426
1592
 
1593
+ /**
1594
+ * Request to update an existing policy by customer
1595
+ * @summary Request policy update by customer
1596
+ * @param {CustomersApiRequestPolicyUpdateRequest} requestParameters Request parameters.
1597
+ * @param {*} [options] Override http request option.
1598
+ * @throws {RequiredError}
1599
+ * @memberof CustomersApi
1600
+ */
1601
+ public requestPolicyUpdate(requestParameters: CustomersApiRequestPolicyUpdateRequest, options?: AxiosRequestConfig) {
1602
+ return CustomersApiFp(this.configuration).requestPolicyUpdate(requestParameters.policyCode, requestParameters.customerCode, requestParameters.code, requestParameters.policyObjects, requestParameters.from, requestParameters.to, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
1603
+ }
1604
+
1427
1605
  /**
1428
1606
  * Change customer\'s password using the token provided by the reset password endpoint.
1429
1607
  * @summary Change password by customer
package/base.ts CHANGED
@@ -17,6 +17,7 @@ import { Configuration } from "./configuration";
17
17
  // Some imports not used depending on template conditions
18
18
  // @ts-ignore
19
19
  import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
20
+ import { InitiateAuthResponseClass, RespondToAuthChallengeClass, RespondToAuthChallengeRequestDto } from "./models";
20
21
  import * as fs from 'fs';
21
22
  import * as path from 'path';
22
23
  import * as os from 'os';
@@ -69,6 +70,7 @@ export class BaseAPI {
69
70
  protected configuration: Configuration | undefined;
70
71
  private username?: string;
71
72
  private password?: string;
73
+ private isCustomerToken = false;
72
74
 
73
75
  constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
74
76
  if (configuration) {
@@ -83,35 +85,169 @@ export class BaseAPI {
83
85
  this.attachInterceptor(axios);
84
86
  }
85
87
 
88
+ async initialize(env: Environment = Environment.Production) {
89
+ this.configuration.basePath = env;
90
+
91
+ await this.loadCredentials();
92
+
93
+ if (this.username) {
94
+ await this.authorize(this.username, this.password);
95
+ this.password = null; // to avoid keeping password loaded in memory.
96
+ }
97
+ }
98
+
99
+ private async loadCredentials() {
100
+ try {
101
+ await this.readConfigFile();
102
+ } catch (error) {
103
+ console.warn(`No credentials file found. Check that ${filePath} exists.`);
104
+ }
105
+
106
+ this.readEnvVariables();
107
+
108
+ if (!this.username) {
109
+ console.info(`No credentials found in credentials file or environment variables. Either provide some or use
110
+ authorize() function.`);
111
+ }
112
+ }
113
+
114
+ private async readConfigFile() {
115
+ const file = await fs.promises.readFile(filePath, 'utf-8');
116
+
117
+ const lines = file.split(os.EOL)
118
+ .filter(Boolean);
119
+
120
+ lines.forEach((line: string) => {
121
+ if (line.startsWith(KEY_USERNAME)) {
122
+ this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
123
+ } else if (line.startsWith(KEY_PASSWORD)) {
124
+ this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
125
+ }
126
+ });
127
+ }
128
+
129
+ private readEnvVariables(): boolean {
130
+ if (process.env.EMIL_USERNAME) {
131
+ this.username = process.env.EMIL_USERNAME;
132
+ this.password = process.env.EMIL_PASSWORD || '';
133
+
134
+ return true;
135
+ }
136
+
137
+ return false;
138
+ }
139
+
86
140
  selectEnvironment(env: Environment) {
87
141
  this.configuration.basePath = env;
88
142
  }
89
143
 
90
- async authorize(username: string, password: string, tenantSlug: string): Promise<void> {
144
+ async authorize(username: string, password: string): Promise<void> {
91
145
  const options: AxiosRequestConfig = {
92
146
  method: 'POST',
93
- url: `${this.configuration.basePath}/v1/customers/login`,
94
- headers: {'Content-Type': 'application/json'},
147
+ url: `${this.configuration.basePath}/authservice/v1/login`,
148
+ headers: { 'Content-Type': 'application/json' },
95
149
  data: {
96
- username,
150
+ username,
97
151
  password,
98
- tenantSlug,
99
152
  },
100
153
  withCredentials: true,
101
154
  };
102
155
 
103
156
  const response = await globalAxios.request<LoginClass>(options);
104
-
157
+
105
158
  const { data: { accessToken } } = response;
106
159
  const refreshToken = this.extractRefreshToken(response)
107
160
 
108
161
  this.configuration.username = username;
109
- this.configuration.tenantSlug = tenantSlug;
110
162
  this.configuration.accessToken = `Bearer ${accessToken}`;
111
163
  this.configuration.refreshToken = refreshToken;
112
164
  }
113
165
 
114
- async refreshTokenInternal(): Promise<string> {
166
+ async initiateAuthorization(username: string, password: string, tenantSlug: string):
167
+ Promise<AxiosResponse<InitiateAuthResponseClass>> {
168
+ const options: AxiosRequestConfig = {
169
+ method: 'POST',
170
+ url: `${this.configuration.basePath}/v1/customers/auth/initiate`,
171
+ headers: { 'Content-Type': 'application/json' },
172
+ data: {
173
+ authFlow: "USER_PASSWORD_AUTH",
174
+ authParameters: {
175
+ "USERNAME": username,
176
+ "PASSWORD": password,
177
+ },
178
+ tenantSlug,
179
+ },
180
+ withCredentials: true,
181
+ };
182
+
183
+ const response = await globalAxios.request<InitiateAuthResponseClass>(options);
184
+
185
+ if (response.data.authenticationResult) {
186
+ const { accessToken } = response.data.authenticationResult;
187
+ const refreshToken = this.extractRefreshToken(response)
188
+
189
+ this.configuration.username = username;
190
+ this.configuration.tenantSlug = tenantSlug;
191
+ this.configuration.accessToken = `Bearer ${accessToken}`;
192
+ this.configuration.refreshToken = refreshToken;
193
+
194
+ this.isCustomerToken = true;
195
+ }
196
+
197
+ return response;
198
+ }
199
+
200
+ async respondToAuthorizationChallenge(respondToAuthChallengeRequestDto: RespondToAuthChallengeRequestDto):
201
+ Promise<AxiosResponse<RespondToAuthChallengeClass>> {
202
+ const options: AxiosRequestConfig = {
203
+ method: 'POST',
204
+ url: `${this.configuration.basePath}/v1/customers/auth/respond`,
205
+ headers: { 'Content-Type': 'application/json' },
206
+ data: {
207
+ ...respondToAuthChallengeRequestDto,
208
+ },
209
+ withCredentials: true,
210
+ };
211
+
212
+ const response = await globalAxios.request<RespondToAuthChallengeClass>(options);
213
+
214
+ if (response.data.authenticationResult) {
215
+ const { accessToken } = response.data.authenticationResult;
216
+ const refreshToken = this.extractRefreshToken(response)
217
+
218
+ this.configuration.accessToken = `Bearer ${accessToken}`;
219
+ this.configuration.refreshToken = refreshToken;
220
+
221
+ this.isCustomerToken = true;
222
+ }
223
+
224
+ return response;
225
+ }
226
+
227
+ async refreshTokenTenant(): Promise<string> {
228
+ const { username, refreshToken } = this.configuration;
229
+
230
+ if (!username || !refreshToken) {
231
+ return '';
232
+ }
233
+
234
+ const options: AxiosRequestConfig = {
235
+ method: 'POST',
236
+ url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
237
+ headers: {
238
+ 'Content-Type': 'application/json',
239
+ Cookie: refreshToken,
240
+ },
241
+ data: { username: username },
242
+ withCredentials: true,
243
+ };
244
+
245
+ const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
246
+
247
+ return accessToken;
248
+ }
249
+
250
+ async refreshTokenCustomer(): Promise<string> {
115
251
  const { username, refreshToken, tenantSlug } = this.configuration;
116
252
 
117
253
  if (!username || !refreshToken) {
@@ -156,7 +292,12 @@ export class BaseAPI {
156
292
  if (err.response.status === 401 && !originalConfig._retry) {
157
293
  originalConfig._retry = true;
158
294
  try {
159
- const tokenString = await this.refreshTokenInternal();
295
+ let tokenString: string;
296
+ if (this.isCustomerToken) {
297
+ tokenString = await this.refreshTokenCustomer();
298
+ } else {
299
+ tokenString = await this.refreshTokenTenant();
300
+ }
160
301
  const accessToken = `Bearer ${tokenString}`;
161
302
 
162
303
  const localVarHeaderParameter = {} as any;