@emilgroup/account-sdk 1.49.1-beta.19 → 1.49.1-beta.21

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/README.md CHANGED
@@ -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/account-sdk@1.49.1-beta.19 --save
20
+ npm install @emilgroup/account-sdk@1.49.1-beta.21 --save
21
21
  ```
22
22
  or
23
23
  ```
24
- yarn add @emilgroup/account-sdk@1.49.1-beta.19
24
+ yarn add @emilgroup/account-sdk@1.49.1-beta.21
25
25
  ```
26
26
 
27
27
  And then you can import `AccountsApi`.
@@ -67,9 +67,12 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
67
67
  // http bearer authentication required
68
68
  await setBearerAuthToObject(localVarHeaderParameter, configuration)
69
69
 
70
- // Only Authorization falls back to the configured token; an empty value is never sent.
71
- const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
72
- if (authorizationValue) {
70
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
71
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
72
+ const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
73
+ const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
74
+ const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
75
+ if (authorizationValue || authorizationKeepEmpty) {
73
76
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
74
77
  }
75
78
 
@@ -117,9 +120,12 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
117
120
  // http bearer authentication required
118
121
  await setBearerAuthToObject(localVarHeaderParameter, configuration)
119
122
 
120
- // Only Authorization falls back to the configured token; an empty value is never sent.
121
- const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
122
- if (authorizationValue) {
123
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
124
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
125
+ const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
126
+ const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
127
+ const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
128
+ if (authorizationValue || authorizationKeepEmpty) {
123
129
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
124
130
  }
125
131
 
@@ -169,9 +175,12 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
169
175
  localVarQueryParameter['expand'] = expand;
170
176
  }
171
177
 
172
- // Only Authorization falls back to the configured token; an empty value is never sent.
173
- const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
174
- if (authorizationValue) {
178
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
179
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
180
+ const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
181
+ const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
182
+ const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
183
+ if (authorizationValue || authorizationKeepEmpty) {
175
184
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
176
185
  }
177
186
 
@@ -221,9 +230,12 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
221
230
  localVarQueryParameter['expand'] = expand;
222
231
  }
223
232
 
224
- // Only Authorization falls back to the configured token; an empty value is never sent.
225
- const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
226
- if (authorizationValue) {
233
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
234
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
235
+ const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
236
+ const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
237
+ const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
238
+ if (authorizationValue || authorizationKeepEmpty) {
227
239
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
228
240
  }
229
241
 
@@ -299,9 +311,12 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
299
311
  localVarQueryParameter['filters'] = filters;
300
312
  }
301
313
 
302
- // Only Authorization falls back to the configured token; an empty value is never sent.
303
- const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
304
- if (authorizationValue) {
314
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
315
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
316
+ const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
317
+ const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
318
+ const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
319
+ if (authorizationValue || authorizationKeepEmpty) {
305
320
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
306
321
  }
307
322
 
@@ -349,9 +364,12 @@ export const AccountsApiAxiosParamCreator = function (configuration?: Configurat
349
364
  // http bearer authentication required
350
365
  await setBearerAuthToObject(localVarHeaderParameter, configuration)
351
366
 
352
- // Only Authorization falls back to the configured token; an empty value is never sent.
353
- const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
354
- if (authorizationValue) {
367
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
368
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
369
+ const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
370
+ const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
371
+ const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
372
+ if (authorizationValue || authorizationKeepEmpty) {
355
373
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
356
374
  }
357
375
 
@@ -753,7 +771,7 @@ export class AccountsApi extends BaseAPI {
753
771
  * @memberof AccountsApi
754
772
  */
755
773
  public createAccount(requestParameters: AccountsApiCreateAccountRequest, options?: AxiosRequestConfig) {
756
- return AccountsApiFp(this.configuration).createAccount(requestParameters.createAccountRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
774
+ return AccountsApiFp(this.configuration).createAccount(requestParameters.createAccountRequestDto, requestParameters.authorization, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
757
775
  }
758
776
 
759
777
  /**
@@ -765,7 +783,7 @@ export class AccountsApi extends BaseAPI {
765
783
  * @memberof AccountsApi
766
784
  */
767
785
  public deleteAccount(requestParameters: AccountsApiDeleteAccountRequest, options?: AxiosRequestConfig) {
768
- return AccountsApiFp(this.configuration).deleteAccount(requestParameters.code, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
786
+ return AccountsApiFp(this.configuration).deleteAccount(requestParameters.code, requestParameters.authorization, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
769
787
  }
770
788
 
771
789
  /**
@@ -777,7 +795,7 @@ export class AccountsApi extends BaseAPI {
777
795
  * @memberof AccountsApi
778
796
  */
779
797
  public getAccount(requestParameters: AccountsApiGetAccountRequest, options?: AxiosRequestConfig) {
780
- return AccountsApiFp(this.configuration).getAccount(requestParameters.code, requestParameters.authorization, requestParameters.expand, options).then((request) => request(this.axios, this.basePath));
798
+ return AccountsApiFp(this.configuration).getAccount(requestParameters.code, requestParameters.authorization, requestParameters.expand, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
781
799
  }
782
800
 
783
801
  /**
@@ -789,7 +807,7 @@ export class AccountsApi extends BaseAPI {
789
807
  * @memberof AccountsApi
790
808
  */
791
809
  public getAccountByEmail(requestParameters: AccountsApiGetAccountByEmailRequest, options?: AxiosRequestConfig) {
792
- return AccountsApiFp(this.configuration).getAccountByEmail(requestParameters.email, requestParameters.authorization, requestParameters.expand, options).then((request) => request(this.axios, this.basePath));
810
+ return AccountsApiFp(this.configuration).getAccountByEmail(requestParameters.email, requestParameters.authorization, requestParameters.expand, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
793
811
  }
794
812
 
795
813
  /**
@@ -801,7 +819,7 @@ export class AccountsApi extends BaseAPI {
801
819
  * @memberof AccountsApi
802
820
  */
803
821
  public listAccounts(requestParameters: AccountsApiListAccountsRequest = {}, options?: AxiosRequestConfig) {
804
- return AccountsApiFp(this.configuration).listAccounts(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.search, requestParameters.order, requestParameters.expand, requestParameters.filters, options).then((request) => request(this.axios, this.basePath));
822
+ return AccountsApiFp(this.configuration).listAccounts(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.search, requestParameters.order, requestParameters.expand, requestParameters.filters, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
805
823
  }
806
824
 
807
825
  /**
@@ -813,6 +831,6 @@ export class AccountsApi extends BaseAPI {
813
831
  * @memberof AccountsApi
814
832
  */
815
833
  public updateAccount(requestParameters: AccountsApiUpdateAccountRequest, options?: AxiosRequestConfig) {
816
- return AccountsApiFp(this.configuration).updateAccount(requestParameters.code, requestParameters.updateAccountRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
834
+ return AccountsApiFp(this.configuration).updateAccount(requestParameters.code, requestParameters.updateAccountRequestDto, requestParameters.authorization, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
817
835
  }
818
836
  }
package/api/health-api.ts CHANGED
@@ -119,6 +119,6 @@ export class HealthApi extends BaseAPI {
119
119
  * @memberof HealthApi
120
120
  */
121
121
  public check(options?: AxiosRequestConfig) {
122
- return HealthApiFp(this.configuration).check(options).then((request) => request(this.axios, this.basePath));
122
+ return HealthApiFp(this.configuration).check(this.withOwner(options)).then((request) => request(this.axios, this.basePath));
123
123
  }
124
124
  }
package/base.ts CHANGED
@@ -72,6 +72,10 @@ export enum Environment {
72
72
  let _retry_count = 0
73
73
  let _retry = null
74
74
 
75
+ // Marks each request with the account (username) of the SDK object that sent it: only SDK objects of that
76
+ // account refresh and resend it, never an object of another account open in the same browser.
77
+ const REQUEST_OWNER = '_emilSdkOwner';
78
+
75
79
  export function resetRetry() {
76
80
  _retry_count = 0
77
81
  }
@@ -120,6 +124,15 @@ export class BaseAPI {
120
124
  this.loadTokenData();
121
125
 
122
126
  if (configuration) {
127
+ // Two accounts in one browser share APP_TOKEN: never take the token or session account saved for
128
+ // another account. The mode stays (an app naming its account keeps its session). Saved with the next refresh.
129
+ const ownUser = configuration.username;
130
+ const storedUser = this.tokenData.username;
131
+ if (ownUser && storedUser && ownUser.toLowerCase() !== storedUser.toLowerCase()) {
132
+ delete this.tokenData.accessToken;
133
+ delete this.tokenData.sub;
134
+ this.tokenData.username = ownUser;
135
+ }
123
136
  const { accessToken } = this.tokenData;
124
137
  this.configuration = configuration;
125
138
  this.basePath = configuration.basePath || this.basePath;
@@ -173,11 +186,14 @@ export class BaseAPI {
173
186
  };
174
187
  }
175
188
 
176
- private useHeaderAuth(accessToken: string) {
189
+ private useHeaderAuth(accessToken: string, keepSessionData = false) {
177
190
  this.configuration.accessToken = accessToken ? `Bearer ${accessToken}` : '';
178
191
  this.tokenData.accessToken = accessToken;
179
- delete this.tokenData.authMode;
180
- delete this.tokenData.sub;
192
+ // An app without cookieAuth does not own the session fields: its refresh leaves them for the session apps.
193
+ if (!keepSessionData || this.configuration.cookieAuth) {
194
+ delete this.tokenData.authMode;
195
+ delete this.tokenData.sub;
196
+ }
181
197
  if (this.configuration.cookieAuth) {
182
198
  const { withCredentials, headers, ...baseOptions } = this.configuration.baseOptions || {};
183
199
  const { [ACCOUNT_HEADER]: account, ...otherHeaders } = headers || {};
@@ -185,7 +201,7 @@ export class BaseAPI {
185
201
  }
186
202
  }
187
203
 
188
- private applyTokenReply({ accessToken, authMode, session }: LoginClass) {
204
+ private applyTokenReply({ accessToken, authMode, session }: LoginClass, fromRefresh = false) {
189
205
  if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && session?.sub) {
190
206
  this.tokenData.authMode = authMode;
191
207
  this.tokenData.sub = session.sub;
@@ -201,7 +217,7 @@ export class BaseAPI {
201
217
  }
202
218
  this.useSessionAuth();
203
219
  } else {
204
- this.useHeaderAuth(accessToken);
220
+ this.useHeaderAuth(accessToken, fromRefresh);
205
221
  }
206
222
  }
207
223
 
@@ -335,9 +351,34 @@ export class BaseAPI {
335
351
 
336
352
  const refreshTokenAxios = globalAxios.create()
337
353
  refreshTokenAxios.interceptors.response.use(response => {
338
- const { permissions } = response.data;
339
-
354
+ const { permissions, accessToken, authMode } = response.data;
355
+ // Decided before the merge below: newer session data must not keep the new token from this object.
356
+ const onSession = this.usesSession();
357
+
358
+ // Newer data saved for this account (e.g. the session mode the shell saved later) wins over the copy
359
+ // read when the object was made; data of another account or another workspace (sub) is never taken.
360
+ const latest = ((typeof window !== 'undefined' && defaultStorage().get<TokenData>(TOKEN_DATA)) || {}) as TokenData;
361
+ const ownSub = this.sessionAccount();
362
+ if (latest.username?.toLowerCase() === username.toLowerCase()
363
+ && (!ownSub || !latest.sub || latest.sub === ownSub)) {
364
+ // A bare reset ({username}, an app's account check) keeps this copy's other fields; any fuller record
365
+ // is the truth, so fields it lacks were removed on purpose (e.g. a rollback) and stay removed.
366
+ const bareReset = Object.keys(latest).every((key) => key === 'username');
367
+ this.tokenData = bareReset ? { ...this.tokenData, ...latest } : { ...latest };
368
+ }
369
+ // The reply is for this account: label it, or an SDK object of another account would take the token.
370
+ if (this.tokenData.username?.toLowerCase() !== username.toLowerCase()) {
371
+ this.tokenData.username = username;
372
+ }
340
373
  this.tokenData.permissions = permissions;
374
+ // Keep the new token for the page's next SDK objects; session data is left as it is.
375
+ if (accessToken && !onSession) {
376
+ this.tokenData.accessToken = accessToken;
377
+ this.configuration.accessToken = `Bearer ${accessToken}`;
378
+ } else if (accessToken && authMode === 'both') {
379
+ // Both: this app stays on the session; the token is kept for apps not moved yet.
380
+ this.tokenData.accessToken = accessToken;
381
+ }
341
382
  this.storeTokenData(this.tokenData);
342
383
 
343
384
  return response;
@@ -376,6 +417,18 @@ export class BaseAPI {
376
417
  this.storeTokenData(null);
377
418
  }
378
419
 
420
+ private ownAccount(): string {
421
+ return (this.configuration.username || '').toLowerCase();
422
+ }
423
+
424
+ protected withOwner(options?: AxiosRequestConfig): AxiosRequestConfig {
425
+ // An object without a username cannot refresh itself: its requests stay unmarked, as before.
426
+ if (!this.ownAccount()) {
427
+ return { ...options };
428
+ }
429
+ return { ...options, [REQUEST_OWNER]: this.ownAccount() } as AxiosRequestConfig;
430
+ }
431
+
379
432
  private attachInterceptor(axios: AxiosInstance) {
380
433
  axios.interceptors.response.use(
381
434
  (res) => {
@@ -383,6 +436,11 @@ export class BaseAPI {
383
436
  },
384
437
  async (err) => {
385
438
  let originalConfig = err.config;
439
+ // Sent for another account: only that account's SDK objects handle it. Unmarked requests as before.
440
+ const owner = originalConfig?.[REQUEST_OWNER];
441
+ if (owner !== undefined && owner !== this.ownAccount()) {
442
+ return Promise.reject(err);
443
+ }
386
444
  if (err.response && !(err.response instanceof XMLHttpRequest)) { // sometimes buggy and is of type request
387
445
  // Access Token was expired
388
446
  if ((err.response.status === 401 || err.response.status === 403)
@@ -391,7 +449,7 @@ export class BaseAPI {
391
449
  try {
392
450
  const reply = await this.refreshTokenInternal();
393
451
  this.tokenData.permissions = reply.permissions;
394
- this.applyTokenReply(reply);
452
+ this.applyTokenReply(reply, true);
395
453
  this.storeTokenData(this.tokenData);
396
454
 
397
455
  if (!this.usesSession()) {
@@ -431,11 +489,16 @@ export class BaseAPI {
431
489
  this.tokenData.permissions = reply.permissions;
432
490
 
433
491
  _retry = true;
434
- this.applyTokenReply(reply);
492
+ this.applyTokenReply(reply, true);
435
493
  this.storeTokenData(this.tokenData);
436
494
 
495
+ // The limit is for refreshes that do not help; one that worked starts the count again.
496
+ // Not awaited, so a failed retry reaches the app as the same axios error as before.
437
497
  return axios.request({
438
498
  ...this.withCurrentAuth(originalConfig),
499
+ }).then((retried) => {
500
+ _retry_count = 0;
501
+ return retried;
439
502
  });
440
503
  } catch (_error) {
441
504
  if (_error.response && _error.response.data) {
@@ -103,9 +103,10 @@ var AccountsApiAxiosParamCreator = function (configuration) {
103
103
  createAccount: function (createAccountRequestDto, authorization, options) {
104
104
  if (options === void 0) { options = {}; }
105
105
  return __awaiter(_this, void 0, void 0, function () {
106
- var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationValue, headersFromBaseOptions;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
106
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationIsAuth, authorizationValue, authorizationKeepEmpty, headersFromBaseOptions;
107
+ var _a;
108
+ return __generator(this, function (_b) {
109
+ switch (_b.label) {
109
110
  case 0:
110
111
  // verify required parameter 'createAccountRequestDto' is not null or undefined
111
112
  (0, common_1.assertParamExists)('createAccount', 'createAccountRequestDto', createAccountRequestDto);
@@ -121,14 +122,17 @@ var AccountsApiAxiosParamCreator = function (configuration) {
121
122
  // authentication bearer required
122
123
  // http bearer authentication required
123
124
  return [4 /*yield*/, (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration)
124
- // Only Authorization falls back to the configured token; an empty value is never sent.
125
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
126
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
125
127
  ];
126
128
  case 1:
127
129
  // authentication bearer required
128
130
  // http bearer authentication required
129
- _a.sent();
130
- authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
131
- if (authorizationValue) {
131
+ _b.sent();
132
+ authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
133
+ authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
134
+ authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
135
+ if (authorizationValue || authorizationKeepEmpty) {
132
136
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
133
137
  }
134
138
  localVarHeaderParameter['Content-Type'] = 'application/json';
@@ -155,9 +159,10 @@ var AccountsApiAxiosParamCreator = function (configuration) {
155
159
  deleteAccount: function (code, authorization, options) {
156
160
  if (options === void 0) { options = {}; }
157
161
  return __awaiter(_this, void 0, void 0, function () {
158
- var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationValue, headersFromBaseOptions;
159
- return __generator(this, function (_a) {
160
- switch (_a.label) {
162
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationIsAuth, authorizationValue, authorizationKeepEmpty, headersFromBaseOptions;
163
+ var _a;
164
+ return __generator(this, function (_b) {
165
+ switch (_b.label) {
161
166
  case 0:
162
167
  // verify required parameter 'code' is not null or undefined
163
168
  (0, common_1.assertParamExists)('deleteAccount', 'code', code);
@@ -174,14 +179,17 @@ var AccountsApiAxiosParamCreator = function (configuration) {
174
179
  // authentication bearer required
175
180
  // http bearer authentication required
176
181
  return [4 /*yield*/, (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration)
177
- // Only Authorization falls back to the configured token; an empty value is never sent.
182
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
183
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
178
184
  ];
179
185
  case 1:
180
186
  // authentication bearer required
181
187
  // http bearer authentication required
182
- _a.sent();
183
- authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
184
- if (authorizationValue) {
188
+ _b.sent();
189
+ authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
190
+ authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
191
+ authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
192
+ if (authorizationValue || authorizationKeepEmpty) {
185
193
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
186
194
  }
187
195
  (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
@@ -207,9 +215,10 @@ var AccountsApiAxiosParamCreator = function (configuration) {
207
215
  getAccount: function (code, authorization, expand, options) {
208
216
  if (options === void 0) { options = {}; }
209
217
  return __awaiter(_this, void 0, void 0, function () {
210
- var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationValue, headersFromBaseOptions;
211
- return __generator(this, function (_a) {
212
- switch (_a.label) {
218
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationIsAuth, authorizationValue, authorizationKeepEmpty, headersFromBaseOptions;
219
+ var _a;
220
+ return __generator(this, function (_b) {
221
+ switch (_b.label) {
213
222
  case 0:
214
223
  // verify required parameter 'code' is not null or undefined
215
224
  (0, common_1.assertParamExists)('getAccount', 'code', code);
@@ -229,12 +238,14 @@ var AccountsApiAxiosParamCreator = function (configuration) {
229
238
  case 1:
230
239
  // authentication bearer required
231
240
  // http bearer authentication required
232
- _a.sent();
241
+ _b.sent();
233
242
  if (expand !== undefined) {
234
243
  localVarQueryParameter['expand'] = expand;
235
244
  }
236
- authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
237
- if (authorizationValue) {
245
+ authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
246
+ authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
247
+ authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
248
+ if (authorizationValue || authorizationKeepEmpty) {
238
249
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
239
250
  }
240
251
  (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
@@ -260,9 +271,10 @@ var AccountsApiAxiosParamCreator = function (configuration) {
260
271
  getAccountByEmail: function (email, authorization, expand, options) {
261
272
  if (options === void 0) { options = {}; }
262
273
  return __awaiter(_this, void 0, void 0, function () {
263
- var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationValue, headersFromBaseOptions;
264
- return __generator(this, function (_a) {
265
- switch (_a.label) {
274
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationIsAuth, authorizationValue, authorizationKeepEmpty, headersFromBaseOptions;
275
+ var _a;
276
+ return __generator(this, function (_b) {
277
+ switch (_b.label) {
266
278
  case 0:
267
279
  // verify required parameter 'email' is not null or undefined
268
280
  (0, common_1.assertParamExists)('getAccountByEmail', 'email', email);
@@ -282,12 +294,14 @@ var AccountsApiAxiosParamCreator = function (configuration) {
282
294
  case 1:
283
295
  // authentication bearer required
284
296
  // http bearer authentication required
285
- _a.sent();
297
+ _b.sent();
286
298
  if (expand !== undefined) {
287
299
  localVarQueryParameter['expand'] = expand;
288
300
  }
289
- authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
290
- if (authorizationValue) {
301
+ authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
302
+ authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
303
+ authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
304
+ if (authorizationValue || authorizationKeepEmpty) {
291
305
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
292
306
  }
293
307
  (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
@@ -318,9 +332,10 @@ var AccountsApiAxiosParamCreator = function (configuration) {
318
332
  listAccounts: function (authorization, pageSize, pageToken, filter, search, order, expand, filters, options) {
319
333
  if (options === void 0) { options = {}; }
320
334
  return __awaiter(_this, void 0, void 0, function () {
321
- var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationValue, headersFromBaseOptions;
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
335
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationIsAuth, authorizationValue, authorizationKeepEmpty, headersFromBaseOptions;
336
+ var _a;
337
+ return __generator(this, function (_b) {
338
+ switch (_b.label) {
324
339
  case 0:
325
340
  localVarPath = "/accountservice/v1/accounts";
326
341
  localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
@@ -337,7 +352,7 @@ var AccountsApiAxiosParamCreator = function (configuration) {
337
352
  case 1:
338
353
  // authentication bearer required
339
354
  // http bearer authentication required
340
- _a.sent();
355
+ _b.sent();
341
356
  if (pageSize !== undefined) {
342
357
  localVarQueryParameter['pageSize'] = pageSize;
343
358
  }
@@ -359,8 +374,10 @@ var AccountsApiAxiosParamCreator = function (configuration) {
359
374
  if (filters !== undefined) {
360
375
  localVarQueryParameter['filters'] = filters;
361
376
  }
362
- authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
363
- if (authorizationValue) {
377
+ authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
378
+ authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
379
+ authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
380
+ if (authorizationValue || authorizationKeepEmpty) {
364
381
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
365
382
  }
366
383
  (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
@@ -386,9 +403,10 @@ var AccountsApiAxiosParamCreator = function (configuration) {
386
403
  updateAccount: function (code, updateAccountRequestDto, authorization, options) {
387
404
  if (options === void 0) { options = {}; }
388
405
  return __awaiter(_this, void 0, void 0, function () {
389
- var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationValue, headersFromBaseOptions;
390
- return __generator(this, function (_a) {
391
- switch (_a.label) {
406
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, authorizationIsAuth, authorizationValue, authorizationKeepEmpty, headersFromBaseOptions;
407
+ var _a;
408
+ return __generator(this, function (_b) {
409
+ switch (_b.label) {
392
410
  case 0:
393
411
  // verify required parameter 'code' is not null or undefined
394
412
  (0, common_1.assertParamExists)('updateAccount', 'code', code);
@@ -407,14 +425,17 @@ var AccountsApiAxiosParamCreator = function (configuration) {
407
425
  // authentication bearer required
408
426
  // http bearer authentication required
409
427
  return [4 /*yield*/, (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration)
410
- // Only Authorization falls back to the configured token; an empty value is never sent.
428
+ // Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
429
+ // no token is stored, so a refused call still refreshes; a session call (account header) sends none.
411
430
  ];
412
431
  case 1:
413
432
  // authentication bearer required
414
433
  // http bearer authentication required
415
- _a.sent();
416
- authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
417
- if (authorizationValue) {
434
+ _b.sent();
435
+ authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
436
+ authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
437
+ authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
438
+ if (authorizationValue || authorizationKeepEmpty) {
418
439
  localVarHeaderParameter['Authorization'] = String(authorizationValue);
419
440
  }
420
441
  localVarHeaderParameter['Content-Type'] = 'application/json';
@@ -684,7 +705,7 @@ var AccountsApi = /** @class */ (function (_super) {
684
705
  */
685
706
  AccountsApi.prototype.createAccount = function (requestParameters, options) {
686
707
  var _this = this;
687
- return (0, exports.AccountsApiFp)(this.configuration).createAccount(requestParameters.createAccountRequestDto, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
708
+ return (0, exports.AccountsApiFp)(this.configuration).createAccount(requestParameters.createAccountRequestDto, requestParameters.authorization, this.withOwner(options)).then(function (request) { return request(_this.axios, _this.basePath); });
688
709
  };
689
710
  /**
690
711
  * Permanently deletes the account. Supply the unique code that was returned when you created the account and this will delete it. **Required Permissions** \"partner-management.partners.delete\"
@@ -696,7 +717,7 @@ var AccountsApi = /** @class */ (function (_super) {
696
717
  */
697
718
  AccountsApi.prototype.deleteAccount = function (requestParameters, options) {
698
719
  var _this = this;
699
- return (0, exports.AccountsApiFp)(this.configuration).deleteAccount(requestParameters.code, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
720
+ return (0, exports.AccountsApiFp)(this.configuration).deleteAccount(requestParameters.code, requestParameters.authorization, this.withOwner(options)).then(function (request) { return request(_this.axios, _this.basePath); });
700
721
  };
701
722
  /**
702
723
  * Retrieves the details of the account that was previously created. Supply the unique account code that was returned when you created it and Emil Api will return the corresponding account information. **Required Permissions** \"partner-management.partners.view\"
@@ -708,7 +729,7 @@ var AccountsApi = /** @class */ (function (_super) {
708
729
  */
709
730
  AccountsApi.prototype.getAccount = function (requestParameters, options) {
710
731
  var _this = this;
711
- return (0, exports.AccountsApiFp)(this.configuration).getAccount(requestParameters.code, requestParameters.authorization, requestParameters.expand, options).then(function (request) { return request(_this.axios, _this.basePath); });
732
+ return (0, exports.AccountsApiFp)(this.configuration).getAccount(requestParameters.code, requestParameters.authorization, requestParameters.expand, this.withOwner(options)).then(function (request) { return request(_this.axios, _this.basePath); });
712
733
  };
713
734
  /**
714
735
  * Retrieves the details of the account that was previously created. Supply the email that was returned when you created it and Emil Api will return the corresponding account information. Email matching is case-insensitive. **Required Permissions** \"partner-management.partners.view\"
@@ -720,7 +741,7 @@ var AccountsApi = /** @class */ (function (_super) {
720
741
  */
721
742
  AccountsApi.prototype.getAccountByEmail = function (requestParameters, options) {
722
743
  var _this = this;
723
- return (0, exports.AccountsApiFp)(this.configuration).getAccountByEmail(requestParameters.email, requestParameters.authorization, requestParameters.expand, options).then(function (request) { return request(_this.axios, _this.basePath); });
744
+ return (0, exports.AccountsApiFp)(this.configuration).getAccountByEmail(requestParameters.email, requestParameters.authorization, requestParameters.expand, this.withOwner(options)).then(function (request) { return request(_this.axios, _this.basePath); });
724
745
  };
725
746
  /**
726
747
  * 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. **Required Permissions** \"partner-management.partners.view\"
@@ -733,7 +754,7 @@ var AccountsApi = /** @class */ (function (_super) {
733
754
  AccountsApi.prototype.listAccounts = function (requestParameters, options) {
734
755
  var _this = this;
735
756
  if (requestParameters === void 0) { requestParameters = {}; }
736
- return (0, exports.AccountsApiFp)(this.configuration).listAccounts(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.search, requestParameters.order, requestParameters.expand, requestParameters.filters, options).then(function (request) { return request(_this.axios, _this.basePath); });
757
+ return (0, exports.AccountsApiFp)(this.configuration).listAccounts(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.search, requestParameters.order, requestParameters.expand, requestParameters.filters, this.withOwner(options)).then(function (request) { return request(_this.axios, _this.basePath); });
737
758
  };
738
759
  /**
739
760
  * Updates the specified account by setting the values of the parameters passed. Any parameters not provided will be left unchanged. **Required Permissions** \"partner-management.partners.update\"
@@ -745,7 +766,7 @@ var AccountsApi = /** @class */ (function (_super) {
745
766
  */
746
767
  AccountsApi.prototype.updateAccount = function (requestParameters, options) {
747
768
  var _this = this;
748
- return (0, exports.AccountsApiFp)(this.configuration).updateAccount(requestParameters.code, requestParameters.updateAccountRequestDto, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
769
+ return (0, exports.AccountsApiFp)(this.configuration).updateAccount(requestParameters.code, requestParameters.updateAccountRequestDto, requestParameters.authorization, this.withOwner(options)).then(function (request) { return request(_this.axios, _this.basePath); });
749
770
  };
750
771
  return AccountsApi;
751
772
  }(base_1.BaseAPI));
@@ -193,7 +193,7 @@ var HealthApi = /** @class */ (function (_super) {
193
193
  */
194
194
  HealthApi.prototype.check = function (options) {
195
195
  var _this = this;
196
- return (0, exports.HealthApiFp)(this.configuration).check(options).then(function (request) { return request(_this.axios, _this.basePath); });
196
+ return (0, exports.HealthApiFp)(this.configuration).check(this.withOwner(options)).then(function (request) { return request(_this.axios, _this.basePath); });
197
197
  };
198
198
  return HealthApi;
199
199
  }(base_1.BaseAPI));
package/dist/base.d.ts CHANGED
@@ -96,6 +96,8 @@ export declare class BaseAPI {
96
96
  private storeTokenData;
97
97
  loadTokenData(): void;
98
98
  cleanTokenData(): void;
99
+ private ownAccount;
100
+ protected withOwner(options?: AxiosRequestConfig): AxiosRequestConfig;
99
101
  private attachInterceptor;
100
102
  }
101
103
  /**
package/dist/base.js CHANGED
@@ -117,6 +117,9 @@ var Environment;
117
117
  })(Environment = exports.Environment || (exports.Environment = {}));
118
118
  var _retry_count = 0;
119
119
  var _retry = null;
120
+ // Marks each request with the account (username) of the SDK object that sent it: only SDK objects of that
121
+ // account refresh and resend it, never an object of another account open in the same browser.
122
+ var REQUEST_OWNER = '_emilSdkOwner';
120
123
  function resetRetry() {
121
124
  _retry_count = 0;
122
125
  }
@@ -142,6 +145,15 @@ var BaseAPI = /** @class */ (function () {
142
145
  this.axios = axios;
143
146
  this.loadTokenData();
144
147
  if (configuration) {
148
+ // Two accounts in one browser share APP_TOKEN: never take the token or session account saved for
149
+ // another account. The mode stays (an app naming its account keeps its session). Saved with the next refresh.
150
+ var ownUser = configuration.username;
151
+ var storedUser = this.tokenData.username;
152
+ if (ownUser && storedUser && ownUser.toLowerCase() !== storedUser.toLowerCase()) {
153
+ delete this.tokenData.accessToken;
154
+ delete this.tokenData.sub;
155
+ this.tokenData.username = ownUser;
156
+ }
145
157
  var accessToken = this.tokenData.accessToken;
146
158
  this.configuration = configuration;
147
159
  this.basePath = configuration.basePath || this.basePath;
@@ -185,19 +197,24 @@ var BaseAPI = /** @class */ (function () {
185
197
  this.configuration.accessToken = '';
186
198
  this.configuration.baseOptions = __assign(__assign({}, baseOptions), { withCredentials: true, headers: __assign(__assign({}, headers), (_a = {}, _a[ACCOUNT_HEADER] = this.sessionAccount(), _a)) });
187
199
  };
188
- BaseAPI.prototype.useHeaderAuth = function (accessToken) {
200
+ BaseAPI.prototype.useHeaderAuth = function (accessToken, keepSessionData) {
201
+ if (keepSessionData === void 0) { keepSessionData = false; }
189
202
  this.configuration.accessToken = accessToken ? "Bearer ".concat(accessToken) : '';
190
203
  this.tokenData.accessToken = accessToken;
191
- delete this.tokenData.authMode;
192
- delete this.tokenData.sub;
204
+ // An app without cookieAuth does not own the session fields: its refresh leaves them for the session apps.
205
+ if (!keepSessionData || this.configuration.cookieAuth) {
206
+ delete this.tokenData.authMode;
207
+ delete this.tokenData.sub;
208
+ }
193
209
  if (this.configuration.cookieAuth) {
194
210
  var _a = this.configuration.baseOptions || {}, withCredentials = _a.withCredentials, headers = _a.headers, baseOptions = __rest(_a, ["withCredentials", "headers"]);
195
211
  var _b = headers || {}, _c = ACCOUNT_HEADER, account = _b[_c], otherHeaders = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
196
212
  this.configuration.baseOptions = __assign(__assign({}, baseOptions), { headers: otherHeaders });
197
213
  }
198
214
  };
199
- BaseAPI.prototype.applyTokenReply = function (_a) {
215
+ BaseAPI.prototype.applyTokenReply = function (_a, fromRefresh) {
200
216
  var accessToken = _a.accessToken, authMode = _a.authMode, session = _a.session;
217
+ if (fromRefresh === void 0) { fromRefresh = false; }
201
218
  if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && (session === null || session === void 0 ? void 0 : session.sub)) {
202
219
  this.tokenData.authMode = authMode;
203
220
  this.tokenData.sub = session.sub;
@@ -215,7 +232,7 @@ var BaseAPI = /** @class */ (function () {
215
232
  this.useSessionAuth();
216
233
  }
217
234
  else {
218
- this.useHeaderAuth(accessToken);
235
+ this.useHeaderAuth(accessToken, fromRefresh);
219
236
  }
220
237
  };
221
238
  BaseAPI.prototype.sessionHeaders = function () {
@@ -350,8 +367,35 @@ var BaseAPI = /** @class */ (function () {
350
367
  }
351
368
  refreshTokenAxios = axios_1.default.create();
352
369
  refreshTokenAxios.interceptors.response.use(function (response) {
353
- var permissions = response.data.permissions;
370
+ var _a, _b;
371
+ var _c = response.data, permissions = _c.permissions, accessToken = _c.accessToken, authMode = _c.authMode;
372
+ // Decided before the merge below: newer session data must not keep the new token from this object.
373
+ var onSession = _this.usesSession();
374
+ // Newer data saved for this account (e.g. the session mode the shell saved later) wins over the copy
375
+ // read when the object was made; data of another account or another workspace (sub) is never taken.
376
+ var latest = ((typeof window !== 'undefined' && (0, common_1.defaultStorage)().get(TOKEN_DATA)) || {});
377
+ var ownSub = _this.sessionAccount();
378
+ if (((_a = latest.username) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === username.toLowerCase()
379
+ && (!ownSub || !latest.sub || latest.sub === ownSub)) {
380
+ // A bare reset ({username}, an app's account check) keeps this copy's other fields; any fuller record
381
+ // is the truth, so fields it lacks were removed on purpose (e.g. a rollback) and stay removed.
382
+ var bareReset = Object.keys(latest).every(function (key) { return key === 'username'; });
383
+ _this.tokenData = bareReset ? __assign(__assign({}, _this.tokenData), latest) : __assign({}, latest);
384
+ }
385
+ // The reply is for this account: label it, or an SDK object of another account would take the token.
386
+ if (((_b = _this.tokenData.username) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== username.toLowerCase()) {
387
+ _this.tokenData.username = username;
388
+ }
354
389
  _this.tokenData.permissions = permissions;
390
+ // Keep the new token for the page's next SDK objects; session data is left as it is.
391
+ if (accessToken && !onSession) {
392
+ _this.tokenData.accessToken = accessToken;
393
+ _this.configuration.accessToken = "Bearer ".concat(accessToken);
394
+ }
395
+ else if (accessToken && authMode === 'both') {
396
+ // Both: this app stays on the session; the token is kept for apps not moved yet.
397
+ _this.tokenData.accessToken = accessToken;
398
+ }
355
399
  _this.storeTokenData(_this.tokenData);
356
400
  return response;
357
401
  });
@@ -386,17 +430,32 @@ var BaseAPI = /** @class */ (function () {
386
430
  BaseAPI.prototype.cleanTokenData = function () {
387
431
  this.storeTokenData(null);
388
432
  };
433
+ BaseAPI.prototype.ownAccount = function () {
434
+ return (this.configuration.username || '').toLowerCase();
435
+ };
436
+ BaseAPI.prototype.withOwner = function (options) {
437
+ var _a;
438
+ // An object without a username cannot refresh itself: its requests stay unmarked, as before.
439
+ if (!this.ownAccount()) {
440
+ return __assign({}, options);
441
+ }
442
+ return __assign(__assign({}, options), (_a = {}, _a[REQUEST_OWNER] = this.ownAccount(), _a));
443
+ };
389
444
  BaseAPI.prototype.attachInterceptor = function (axios) {
390
445
  var _this = this;
391
446
  axios.interceptors.response.use(function (res) {
392
447
  return res;
393
448
  }, function (err) { return __awaiter(_this, void 0, void 0, function () {
394
- var originalConfig, reply, _error_1, reply, _error_2;
449
+ var originalConfig, owner, reply, _error_1, reply, _error_2;
395
450
  var _this = this;
396
451
  return __generator(this, function (_a) {
397
452
  switch (_a.label) {
398
453
  case 0:
399
454
  originalConfig = err.config;
455
+ owner = originalConfig === null || originalConfig === void 0 ? void 0 : originalConfig[REQUEST_OWNER];
456
+ if (owner !== undefined && owner !== this.ownAccount()) {
457
+ return [2 /*return*/, Promise.reject(err)];
458
+ }
400
459
  if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
401
460
  if (!((err.response.status === 401 || err.response.status === 403)
402
461
  && !originalConfig._retry)) return [3 /*break*/, 4];
@@ -408,7 +467,7 @@ var BaseAPI = /** @class */ (function () {
408
467
  case 2:
409
468
  reply = _a.sent();
410
469
  this.tokenData.permissions = reply.permissions;
411
- this.applyTokenReply(reply);
470
+ this.applyTokenReply(reply, true);
412
471
  this.storeTokenData(this.tokenData);
413
472
  if (!this.usesSession()) {
414
473
  return [2 /*return*/, axios(this.withCurrentAuth(originalConfig))];
@@ -450,9 +509,14 @@ var BaseAPI = /** @class */ (function () {
450
509
  reply = _a.sent();
451
510
  this.tokenData.permissions = reply.permissions;
452
511
  _retry = true;
453
- this.applyTokenReply(reply);
512
+ this.applyTokenReply(reply, true);
454
513
  this.storeTokenData(this.tokenData);
455
- return [2 /*return*/, axios.request(__assign({}, this.withCurrentAuth(originalConfig)))];
514
+ // The limit is for refreshes that do not help; one that worked starts the count again.
515
+ // Not awaited, so a failed retry reaches the app as the same axios error as before.
516
+ return [2 /*return*/, axios.request(__assign({}, this.withCurrentAuth(originalConfig))).then(function (retried) {
517
+ _retry_count = 0;
518
+ return retried;
519
+ })];
456
520
  case 9:
457
521
  _error_2 = _a.sent();
458
522
  if (_error_2.response && _error_2.response.data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emilgroup/account-sdk",
3
- "version": "1.49.1-beta.19",
3
+ "version": "1.49.1-beta.21",
4
4
  "description": "OpenAPI client for @emilgroup/account-sdk",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "keywords": [