@emilgroup/action-sdk 1.8.1-beta.14 → 1.8.1-beta.17
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 +2 -2
- package/api/action-client-api.ts +84 -48
- package/api/actions-api.ts +63 -36
- package/api/executions-api.ts +21 -12
- package/api/health-api.ts +1 -1
- package/base.ts +72 -9
- package/dist/api/action-client-api.js +130 -89
- package/dist/api/actions-api.js +98 -67
- package/dist/api/executions-api.js +32 -22
- package/dist/api/health-api.js +1 -1
- package/dist/base.d.ts +2 -0
- package/dist/base.js +74 -10
- package/package.json +1 -1
package/api/executions-api.ts
CHANGED
|
@@ -70,9 +70,12 @@ export const ExecutionsApiAxiosParamCreator = function (configuration?: Configur
|
|
|
70
70
|
localVarQueryParameter['correlationId'] = correlationId;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
// Only Authorization falls back to the configured token
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
// Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
|
|
74
|
+
// no token is stored, so a refused call still refreshes; a session call (account header) sends none.
|
|
75
|
+
const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
|
|
76
|
+
const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
|
|
77
|
+
const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
|
|
78
|
+
if (authorizationValue || authorizationKeepEmpty) {
|
|
76
79
|
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
77
80
|
}
|
|
78
81
|
|
|
@@ -148,9 +151,12 @@ export const ExecutionsApiAxiosParamCreator = function (configuration?: Configur
|
|
|
148
151
|
localVarQueryParameter['filters'] = filters;
|
|
149
152
|
}
|
|
150
153
|
|
|
151
|
-
// Only Authorization falls back to the configured token
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
// Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
|
|
155
|
+
// no token is stored, so a refused call still refreshes; a session call (account header) sends none.
|
|
156
|
+
const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
|
|
157
|
+
const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
|
|
158
|
+
const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
|
|
159
|
+
if (authorizationValue || authorizationKeepEmpty) {
|
|
154
160
|
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
155
161
|
}
|
|
156
162
|
|
|
@@ -194,9 +200,12 @@ export const ExecutionsApiAxiosParamCreator = function (configuration?: Configur
|
|
|
194
200
|
// http bearer authentication required
|
|
195
201
|
await setBearerAuthToObject(localVarHeaderParameter, configuration)
|
|
196
202
|
|
|
197
|
-
// Only Authorization falls back to the configured token
|
|
198
|
-
|
|
199
|
-
|
|
203
|
+
// Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
|
|
204
|
+
// no token is stored, so a refused call still refreshes; a session call (account header) sends none.
|
|
205
|
+
const authorizationIsAuth = 'Authorization'.toLowerCase() === 'authorization';
|
|
206
|
+
const authorizationValue = authorizationIsAuth ? (authorization || baseAccessToken) : authorization;
|
|
207
|
+
const authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !baseOptions?.headers?.['X-Emil-Account'];
|
|
208
|
+
if (authorizationValue || authorizationKeepEmpty) {
|
|
200
209
|
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
201
210
|
}
|
|
202
211
|
|
|
@@ -448,7 +457,7 @@ export class ExecutionsApi extends BaseAPI {
|
|
|
448
457
|
* @memberof ExecutionsApi
|
|
449
458
|
*/
|
|
450
459
|
public getActionExecutionStatus(requestParameters: ExecutionsApiGetActionExecutionStatusRequest = {}, options?: AxiosRequestConfig) {
|
|
451
|
-
return ExecutionsApiFp(this.configuration).getActionExecutionStatus(requestParameters.authorization, requestParameters.executionCode, requestParameters.correlationId, options).then((request) => request(this.axios, this.basePath));
|
|
460
|
+
return ExecutionsApiFp(this.configuration).getActionExecutionStatus(requestParameters.authorization, requestParameters.executionCode, requestParameters.correlationId, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
|
|
452
461
|
}
|
|
453
462
|
|
|
454
463
|
/**
|
|
@@ -460,7 +469,7 @@ export class ExecutionsApi extends BaseAPI {
|
|
|
460
469
|
* @memberof ExecutionsApi
|
|
461
470
|
*/
|
|
462
471
|
public listActionExecutions(requestParameters: ExecutionsApiListActionExecutionsRequest = {}, options?: AxiosRequestConfig) {
|
|
463
|
-
return ExecutionsApiFp(this.configuration).listActionExecutions(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.search, requestParameters.order, requestParameters.expand, requestParameters.filters, options).then((request) => request(this.axios, this.basePath));
|
|
472
|
+
return ExecutionsApiFp(this.configuration).listActionExecutions(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));
|
|
464
473
|
}
|
|
465
474
|
|
|
466
475
|
/**
|
|
@@ -472,6 +481,6 @@ export class ExecutionsApi extends BaseAPI {
|
|
|
472
481
|
* @memberof ExecutionsApi
|
|
473
482
|
*/
|
|
474
483
|
public triggerAction(requestParameters: ExecutionsApiTriggerActionRequest, options?: AxiosRequestConfig) {
|
|
475
|
-
return ExecutionsApiFp(this.configuration).triggerAction(requestParameters.triggerActionRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
|
|
484
|
+
return ExecutionsApiFp(this.configuration).triggerAction(requestParameters.triggerActionRequestDto, requestParameters.authorization, this.withOwner(options)).then((request) => request(this.axios, this.basePath));
|
|
476
485
|
}
|
|
477
486
|
}
|
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
|
-
|
|
180
|
-
|
|
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) {
|