@emilgroup/action-sdk 1.8.1-beta.19 → 1.8.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 +2 -2
- package/api/action-client-api.ts +36 -96
- package/api/actions-api.ts +27 -72
- package/api/executions-api.ts +9 -24
- package/api/health-api.ts +1 -1
- package/base.ts +43 -239
- package/common.ts +2 -3
- package/configuration.ts +0 -20
- package/dist/api/action-client-api.d.ts +12 -12
- package/dist/api/action-client-api.js +89 -152
- package/dist/api/actions-api.d.ts +9 -9
- package/dist/api/actions-api.js +67 -115
- package/dist/api/executions-api.d.ts +3 -3
- package/dist/api/executions-api.js +22 -37
- package/dist/api/health-api.d.ts +1 -1
- package/dist/api/health-api.js +1 -1
- package/dist/base.d.ts +0 -26
- package/dist/base.js +60 -243
- package/dist/common.d.ts +1 -1
- package/dist/common.js +0 -1
- package/dist/configuration.d.ts +0 -17
- package/dist/configuration.js +0 -2
- package/package.json +2 -2
|
@@ -104,10 +104,9 @@ var ExecutionsApiAxiosParamCreator = function (configuration) {
|
|
|
104
104
|
getActionExecutionStatus: function (authorization, executionCode, correlationId, options) {
|
|
105
105
|
if (options === void 0) { options = {}; }
|
|
106
106
|
return __awaiter(_this, void 0, void 0, function () {
|
|
107
|
-
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
switch (_b.label) {
|
|
107
|
+
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
switch (_a.label) {
|
|
111
110
|
case 0:
|
|
112
111
|
localVarPath = "/actionservice/v1/actions/executions/status";
|
|
113
112
|
localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
|
|
@@ -124,18 +123,15 @@ var ExecutionsApiAxiosParamCreator = function (configuration) {
|
|
|
124
123
|
case 1:
|
|
125
124
|
// authentication bearer required
|
|
126
125
|
// http bearer authentication required
|
|
127
|
-
|
|
126
|
+
_a.sent();
|
|
128
127
|
if (executionCode !== undefined) {
|
|
129
128
|
localVarQueryParameter['executionCode'] = executionCode;
|
|
130
129
|
}
|
|
131
130
|
if (correlationId !== undefined) {
|
|
132
131
|
localVarQueryParameter['correlationId'] = correlationId;
|
|
133
132
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
|
|
137
|
-
if (authorizationValue || authorizationKeepEmpty) {
|
|
138
|
-
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
133
|
+
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
134
|
+
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
139
135
|
}
|
|
140
136
|
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
141
137
|
headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
@@ -165,10 +161,9 @@ var ExecutionsApiAxiosParamCreator = function (configuration) {
|
|
|
165
161
|
listActionExecutions: function (authorization, pageSize, pageToken, filter, search, order, expand, filters, options) {
|
|
166
162
|
if (options === void 0) { options = {}; }
|
|
167
163
|
return __awaiter(_this, void 0, void 0, function () {
|
|
168
|
-
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
switch (_b.label) {
|
|
164
|
+
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
switch (_a.label) {
|
|
172
167
|
case 0:
|
|
173
168
|
localVarPath = "/actionservice/v1/actions/executions";
|
|
174
169
|
localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
|
|
@@ -185,7 +180,7 @@ var ExecutionsApiAxiosParamCreator = function (configuration) {
|
|
|
185
180
|
case 1:
|
|
186
181
|
// authentication bearer required
|
|
187
182
|
// http bearer authentication required
|
|
188
|
-
|
|
183
|
+
_a.sent();
|
|
189
184
|
if (pageSize !== undefined) {
|
|
190
185
|
localVarQueryParameter['pageSize'] = pageSize;
|
|
191
186
|
}
|
|
@@ -207,11 +202,8 @@ var ExecutionsApiAxiosParamCreator = function (configuration) {
|
|
|
207
202
|
if (filters !== undefined) {
|
|
208
203
|
localVarQueryParameter['filters'] = filters;
|
|
209
204
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
|
|
213
|
-
if (authorizationValue || authorizationKeepEmpty) {
|
|
214
|
-
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
205
|
+
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
206
|
+
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
215
207
|
}
|
|
216
208
|
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
217
209
|
headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
@@ -235,10 +227,9 @@ var ExecutionsApiAxiosParamCreator = function (configuration) {
|
|
|
235
227
|
triggerAction: function (triggerActionRequestDto, authorization, options) {
|
|
236
228
|
if (options === void 0) { options = {}; }
|
|
237
229
|
return __awaiter(_this, void 0, void 0, function () {
|
|
238
|
-
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
switch (_b.label) {
|
|
230
|
+
var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
231
|
+
return __generator(this, function (_a) {
|
|
232
|
+
switch (_a.label) {
|
|
242
233
|
case 0:
|
|
243
234
|
// verify required parameter 'triggerActionRequestDto' is not null or undefined
|
|
244
235
|
(0, common_1.assertParamExists)('triggerAction', 'triggerActionRequestDto', triggerActionRequestDto);
|
|
@@ -253,19 +244,13 @@ var ExecutionsApiAxiosParamCreator = function (configuration) {
|
|
|
253
244
|
localVarQueryParameter = {};
|
|
254
245
|
// authentication bearer required
|
|
255
246
|
// http bearer authentication required
|
|
256
|
-
return [4 /*yield*/, (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration)
|
|
257
|
-
// Only Authorization falls back to the configured token. Without a session it is sent as before, empty when
|
|
258
|
-
// no token is stored, so a refused call still refreshes; a session call (account header) sends none.
|
|
259
|
-
];
|
|
247
|
+
return [4 /*yield*/, (0, common_1.setBearerAuthToObject)(localVarHeaderParameter, configuration)];
|
|
260
248
|
case 1:
|
|
261
249
|
// authentication bearer required
|
|
262
250
|
// http bearer authentication required
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
authorizationKeepEmpty = authorizationIsAuth && authorizationValue === '' && !((_a = baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.headers) === null || _a === void 0 ? void 0 : _a['X-Emil-Account']);
|
|
267
|
-
if (authorizationValue || authorizationKeepEmpty) {
|
|
268
|
-
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
251
|
+
_a.sent();
|
|
252
|
+
if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
|
|
253
|
+
localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
|
|
269
254
|
}
|
|
270
255
|
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
271
256
|
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
@@ -435,7 +420,7 @@ var ExecutionsApi = /** @class */ (function (_super) {
|
|
|
435
420
|
ExecutionsApi.prototype.getActionExecutionStatus = function (requestParameters, options) {
|
|
436
421
|
var _this = this;
|
|
437
422
|
if (requestParameters === void 0) { requestParameters = {}; }
|
|
438
|
-
return (0, exports.ExecutionsApiFp)(this.configuration).getActionExecutionStatus(requestParameters.authorization, requestParameters.executionCode, requestParameters.correlationId,
|
|
423
|
+
return (0, exports.ExecutionsApiFp)(this.configuration).getActionExecutionStatus(requestParameters.authorization, requestParameters.executionCode, requestParameters.correlationId, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
439
424
|
};
|
|
440
425
|
/**
|
|
441
426
|
* Lists action executions (latest status per execution only) with optional filters **Required Permissions** \"action-management.actions.view\"
|
|
@@ -448,7 +433,7 @@ var ExecutionsApi = /** @class */ (function (_super) {
|
|
|
448
433
|
ExecutionsApi.prototype.listActionExecutions = function (requestParameters, options) {
|
|
449
434
|
var _this = this;
|
|
450
435
|
if (requestParameters === void 0) { requestParameters = {}; }
|
|
451
|
-
return (0, exports.ExecutionsApiFp)(this.configuration).listActionExecutions(requestParameters.authorization, requestParameters.pageSize, requestParameters.pageToken, requestParameters.filter, requestParameters.search, requestParameters.order, requestParameters.expand, requestParameters.filters,
|
|
436
|
+
return (0, exports.ExecutionsApiFp)(this.configuration).listActionExecutions(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); });
|
|
452
437
|
};
|
|
453
438
|
/**
|
|
454
439
|
* Triggers an action execution. When the action has an input_validation_schema, the input payload is validated against it; invalid payloads return HTTP 400 with a body containing message and errors (JSON Schema validation errors). **Required Permissions** \"action-management.actions.run\"
|
|
@@ -460,7 +445,7 @@ var ExecutionsApi = /** @class */ (function (_super) {
|
|
|
460
445
|
*/
|
|
461
446
|
ExecutionsApi.prototype.triggerAction = function (requestParameters, options) {
|
|
462
447
|
var _this = this;
|
|
463
|
-
return (0, exports.ExecutionsApiFp)(this.configuration).triggerAction(requestParameters.triggerActionRequestDto, requestParameters.authorization,
|
|
448
|
+
return (0, exports.ExecutionsApiFp)(this.configuration).triggerAction(requestParameters.triggerActionRequestDto, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
464
449
|
};
|
|
465
450
|
return ExecutionsApi;
|
|
466
451
|
}(base_1.BaseAPI));
|
package/dist/api/health-api.d.ts
CHANGED
|
@@ -66,5 +66,5 @@ export declare class HealthApi extends BaseAPI {
|
|
|
66
66
|
* @throws {RequiredError}
|
|
67
67
|
* @memberof HealthApi
|
|
68
68
|
*/
|
|
69
|
-
check(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<InlineResponse200, any, {}
|
|
69
|
+
check(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<InlineResponse200, any, {}>>;
|
|
70
70
|
}
|
package/dist/api/health-api.js
CHANGED
|
@@ -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(
|
|
196
|
+
return (0, exports.HealthApiFp)(this.configuration).check(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
|
@@ -22,19 +22,9 @@ export declare const COLLECTION_FORMATS: {
|
|
|
22
22
|
tsv: string;
|
|
23
23
|
pipes: string;
|
|
24
24
|
};
|
|
25
|
-
export interface SessionClass {
|
|
26
|
-
sub: string;
|
|
27
|
-
username?: string;
|
|
28
|
-
email?: string;
|
|
29
|
-
tenantSlug?: string;
|
|
30
|
-
permissions?: string;
|
|
31
|
-
expiresAt?: number;
|
|
32
|
-
}
|
|
33
25
|
export interface LoginClass {
|
|
34
26
|
accessToken: string;
|
|
35
27
|
permissions: string;
|
|
36
|
-
authMode?: string;
|
|
37
|
-
session?: SessionClass;
|
|
38
28
|
}
|
|
39
29
|
export interface SwitchWorkspaceRequest {
|
|
40
30
|
username: string;
|
|
@@ -43,8 +33,6 @@ export interface SwitchWorkspaceRequest {
|
|
|
43
33
|
export interface SwitchWorkspaceResponseClass {
|
|
44
34
|
accessToken: string;
|
|
45
35
|
permissions: string;
|
|
46
|
-
authMode?: string;
|
|
47
|
-
session?: SessionClass;
|
|
48
36
|
}
|
|
49
37
|
export declare enum Environment {
|
|
50
38
|
Production = "https://apiv2.emil.de",
|
|
@@ -75,18 +63,6 @@ export declare class BaseAPI {
|
|
|
75
63
|
protected configuration: Configuration | undefined;
|
|
76
64
|
private tokenData?;
|
|
77
65
|
constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
|
|
78
|
-
private sessionAccount;
|
|
79
|
-
private authBasePath;
|
|
80
|
-
private usesSession;
|
|
81
|
-
private useSessionAuth;
|
|
82
|
-
private useHeaderAuth;
|
|
83
|
-
private applyTokenReply;
|
|
84
|
-
private sessionHeaders;
|
|
85
|
-
private withCurrentAuth;
|
|
86
|
-
private canRetryWithToken;
|
|
87
|
-
private canResend;
|
|
88
|
-
private switchToToken;
|
|
89
|
-
private retryWithToken;
|
|
90
66
|
selectEnvironment(env: Environment): void;
|
|
91
67
|
selectBasePath(path: string): void;
|
|
92
68
|
getPermissions(): Array<string>;
|
|
@@ -96,8 +72,6 @@ export declare class BaseAPI {
|
|
|
96
72
|
private storeTokenData;
|
|
97
73
|
loadTokenData(): void;
|
|
98
74
|
cleanTokenData(): void;
|
|
99
|
-
private ownAccount;
|
|
100
|
-
protected withOwner(options?: AxiosRequestConfig): AxiosRequestConfig;
|
|
101
75
|
private attachInterceptor;
|
|
102
76
|
}
|
|
103
77
|
/**
|
package/dist/base.js
CHANGED
|
@@ -74,17 +74,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
74
74
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
78
|
-
var t = {};
|
|
79
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
80
|
-
t[p] = s[p];
|
|
81
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
82
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
83
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
84
|
-
t[p[i]] = s[p[i]];
|
|
85
|
-
}
|
|
86
|
-
return t;
|
|
87
|
-
};
|
|
88
77
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
89
78
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
90
79
|
};
|
|
@@ -117,21 +106,12 @@ var Environment;
|
|
|
117
106
|
})(Environment = exports.Environment || (exports.Environment = {}));
|
|
118
107
|
var _retry_count = 0;
|
|
119
108
|
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';
|
|
123
109
|
function resetRetry() {
|
|
124
110
|
_retry_count = 0;
|
|
125
111
|
}
|
|
126
112
|
exports.resetRetry = resetRetry;
|
|
127
113
|
var NETWORK_ERROR_MESSAGE = "Network Error";
|
|
128
114
|
var TOKEN_DATA = 'APP_TOKEN';
|
|
129
|
-
// Sent only to authservice, to ask for a server session.
|
|
130
|
-
var AUTH_MODE_HEADER = 'X-Emil-Auth-Mode';
|
|
131
|
-
// Names the account on every call; one browser session can hold several.
|
|
132
|
-
var ACCOUNT_HEADER = 'X-Emil-Account';
|
|
133
|
-
var SESSION_MODES = ['both', 'session'];
|
|
134
|
-
var RESEND_SAFE_METHODS = ['get', 'head', 'options'];
|
|
135
115
|
/**
|
|
136
116
|
*
|
|
137
117
|
* @export
|
|
@@ -145,30 +125,13 @@ var BaseAPI = /** @class */ (function () {
|
|
|
145
125
|
this.axios = axios;
|
|
146
126
|
this.loadTokenData();
|
|
147
127
|
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
|
-
}
|
|
157
128
|
var accessToken = this.tokenData.accessToken;
|
|
158
129
|
this.configuration = configuration;
|
|
159
130
|
this.basePath = configuration.basePath || this.basePath;
|
|
160
|
-
if
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.useSessionAuth();
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
// Use config token if provided, otherwise use tokenData token
|
|
168
|
-
var configToken = this.configuration.accessToken;
|
|
169
|
-
var storedToken = accessToken ? "Bearer ".concat(accessToken) : '';
|
|
170
|
-
this.configuration.accessToken = configToken || storedToken;
|
|
171
|
-
}
|
|
131
|
+
// Use config token if provided, otherwise use tokenData token
|
|
132
|
+
var configToken = this.configuration.accessToken;
|
|
133
|
+
var storedToken = accessToken ? "Bearer ".concat(accessToken) : '';
|
|
134
|
+
this.configuration.accessToken = configToken || storedToken;
|
|
172
135
|
}
|
|
173
136
|
else {
|
|
174
137
|
var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
|
|
@@ -180,100 +143,6 @@ var BaseAPI = /** @class */ (function () {
|
|
|
180
143
|
}
|
|
181
144
|
this.attachInterceptor(axios);
|
|
182
145
|
}
|
|
183
|
-
// The app's own account wins over APP_TOKEN, which holds whichever tab wrote last.
|
|
184
|
-
BaseAPI.prototype.sessionAccount = function () {
|
|
185
|
-
return this.configuration.account || this.tokenData.sub;
|
|
186
|
-
};
|
|
187
|
-
// Apps may pass the address as the second argument only; authservice is on the same host.
|
|
188
|
-
BaseAPI.prototype.authBasePath = function () {
|
|
189
|
-
return this.configuration.basePath || this.basePath;
|
|
190
|
-
};
|
|
191
|
-
BaseAPI.prototype.usesSession = function () {
|
|
192
|
-
return !!this.configuration.cookieAuth && SESSION_MODES.indexOf(this.tokenData.authMode) !== -1 && !!this.sessionAccount();
|
|
193
|
-
};
|
|
194
|
-
BaseAPI.prototype.useSessionAuth = function () {
|
|
195
|
-
var _a;
|
|
196
|
-
var _b = this.configuration.baseOptions || {}, headers = _b.headers, baseOptions = __rest(_b, ["headers"]);
|
|
197
|
-
this.configuration.accessToken = '';
|
|
198
|
-
this.configuration.baseOptions = __assign(__assign({}, baseOptions), { withCredentials: true, headers: __assign(__assign({}, headers), (_a = {}, _a[ACCOUNT_HEADER] = this.sessionAccount(), _a)) });
|
|
199
|
-
};
|
|
200
|
-
BaseAPI.prototype.useHeaderAuth = function (accessToken, keepSessionData) {
|
|
201
|
-
if (keepSessionData === void 0) { keepSessionData = false; }
|
|
202
|
-
this.configuration.accessToken = accessToken ? "Bearer ".concat(accessToken) : '';
|
|
203
|
-
this.tokenData.accessToken = accessToken;
|
|
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
|
-
}
|
|
209
|
-
if (this.configuration.cookieAuth) {
|
|
210
|
-
var _a = this.configuration.baseOptions || {}, withCredentials = _a.withCredentials, headers = _a.headers, baseOptions = __rest(_a, ["withCredentials", "headers"]);
|
|
211
|
-
var _b = headers || {}, _c = ACCOUNT_HEADER, account = _b[_c], otherHeaders = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
212
|
-
this.configuration.baseOptions = __assign(__assign({}, baseOptions), { headers: otherHeaders });
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
BaseAPI.prototype.applyTokenReply = function (_a, fromRefresh) {
|
|
216
|
-
var accessToken = _a.accessToken, authMode = _a.authMode, session = _a.session;
|
|
217
|
-
if (fromRefresh === void 0) { fromRefresh = false; }
|
|
218
|
-
if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && (session === null || session === void 0 ? void 0 : session.sub)) {
|
|
219
|
-
this.tokenData.authMode = authMode;
|
|
220
|
-
this.tokenData.sub = session.sub;
|
|
221
|
-
if (this.configuration.account) {
|
|
222
|
-
// A workspace switch moves the app to another account.
|
|
223
|
-
this.configuration.account = session.sub;
|
|
224
|
-
}
|
|
225
|
-
// Both keeps the token for apps not moved yet; session mode keeps no token at all.
|
|
226
|
-
if (authMode === 'both' && accessToken) {
|
|
227
|
-
this.tokenData.accessToken = accessToken;
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
delete this.tokenData.accessToken;
|
|
231
|
-
}
|
|
232
|
-
this.useSessionAuth();
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
this.useHeaderAuth(accessToken, fromRefresh);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
BaseAPI.prototype.sessionHeaders = function () {
|
|
239
|
-
var _a, _b;
|
|
240
|
-
if (!this.configuration.cookieAuth) {
|
|
241
|
-
return {};
|
|
242
|
-
}
|
|
243
|
-
return __assign((_a = {}, _a[AUTH_MODE_HEADER] = 'session', _a), (this.usesSession() && (_b = {}, _b[ACCOUNT_HEADER] = this.sessionAccount(), _b)));
|
|
244
|
-
};
|
|
245
|
-
BaseAPI.prototype.withCurrentAuth = function (config) {
|
|
246
|
-
delete config.headers['Authorization'];
|
|
247
|
-
delete config.headers[ACCOUNT_HEADER];
|
|
248
|
-
if (this.usesSession()) {
|
|
249
|
-
config.headers[ACCOUNT_HEADER] = this.sessionAccount();
|
|
250
|
-
config.withCredentials = true;
|
|
251
|
-
}
|
|
252
|
-
else if (this.configuration.accessToken) {
|
|
253
|
-
config.headers['Authorization'] = this.configuration.accessToken;
|
|
254
|
-
}
|
|
255
|
-
return config;
|
|
256
|
-
};
|
|
257
|
-
// Both keeps the token, so a session call the browser could not complete can be sent again with it.
|
|
258
|
-
BaseAPI.prototype.canRetryWithToken = function (config) {
|
|
259
|
-
var _a;
|
|
260
|
-
return !!config.withCredentials && !!((_a = config.headers) === null || _a === void 0 ? void 0 : _a[ACCOUNT_HEADER])
|
|
261
|
-
&& !!this.tokenData.accessToken && this.tokenData.authMode !== 'session';
|
|
262
|
-
};
|
|
263
|
-
// A network error can come after the server ran the call, so only a call that is safe to repeat is sent again.
|
|
264
|
-
BaseAPI.prototype.canResend = function (config) {
|
|
265
|
-
return RESEND_SAFE_METHODS.indexOf((config.method || 'get').toLowerCase()) !== -1
|
|
266
|
-
|| Object.keys(config.headers || {}).some(function (name) { return name.toLowerCase() === 'idempotency-key'; });
|
|
267
|
-
};
|
|
268
|
-
BaseAPI.prototype.switchToToken = function () {
|
|
269
|
-
this.useHeaderAuth(this.tokenData.accessToken);
|
|
270
|
-
this.storeTokenData(this.tokenData);
|
|
271
|
-
};
|
|
272
|
-
BaseAPI.prototype.retryWithToken = function (axios, config) {
|
|
273
|
-
this.switchToToken();
|
|
274
|
-
config.withCredentials = false;
|
|
275
|
-
return axios(this.withCurrentAuth(config));
|
|
276
|
-
};
|
|
277
146
|
BaseAPI.prototype.selectEnvironment = function (env) {
|
|
278
147
|
this.selectBasePath(env);
|
|
279
148
|
};
|
|
@@ -289,15 +158,14 @@ var BaseAPI = /** @class */ (function () {
|
|
|
289
158
|
};
|
|
290
159
|
BaseAPI.prototype.authorize = function (username, password, targetWorkspace) {
|
|
291
160
|
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
-
var options, response;
|
|
293
|
-
var _a;
|
|
161
|
+
var options, response, _a, accessToken, permissions;
|
|
294
162
|
return __generator(this, function (_b) {
|
|
295
163
|
switch (_b.label) {
|
|
296
164
|
case 0:
|
|
297
165
|
options = {
|
|
298
166
|
method: 'POST',
|
|
299
|
-
url: "".concat(this.
|
|
300
|
-
headers:
|
|
167
|
+
url: "".concat(this.configuration.basePath, "/authservice/v1/login"),
|
|
168
|
+
headers: { 'Content-Type': 'application/json' },
|
|
301
169
|
data: {
|
|
302
170
|
username: username,
|
|
303
171
|
password: password,
|
|
@@ -307,10 +175,12 @@ var BaseAPI = /** @class */ (function () {
|
|
|
307
175
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
308
176
|
case 1:
|
|
309
177
|
response = _b.sent();
|
|
178
|
+
_a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
|
|
310
179
|
this.configuration.username = username;
|
|
180
|
+
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
311
181
|
this.tokenData.username = username;
|
|
312
|
-
this.tokenData.
|
|
313
|
-
this.
|
|
182
|
+
this.tokenData.accessToken = accessToken;
|
|
183
|
+
this.tokenData.permissions = permissions;
|
|
314
184
|
if (!targetWorkspace) return [3 /*break*/, 3];
|
|
315
185
|
return [4 /*yield*/, this.switchWorkspace(targetWorkspace)];
|
|
316
186
|
case 2:
|
|
@@ -329,14 +199,17 @@ var BaseAPI = /** @class */ (function () {
|
|
|
329
199
|
};
|
|
330
200
|
BaseAPI.prototype.switchWorkspace = function (targetWorkspace) {
|
|
331
201
|
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
-
var options, response;
|
|
333
|
-
return __generator(this, function (
|
|
334
|
-
switch (
|
|
202
|
+
var options, response, _a, accessToken, permissions;
|
|
203
|
+
return __generator(this, function (_b) {
|
|
204
|
+
switch (_b.label) {
|
|
335
205
|
case 0:
|
|
336
206
|
options = {
|
|
337
207
|
method: 'POST',
|
|
338
|
-
url: "".concat(this.
|
|
339
|
-
headers:
|
|
208
|
+
url: "".concat(this.configuration.basePath, "/authservice/v1/workspaces/switch"),
|
|
209
|
+
headers: {
|
|
210
|
+
'Content-Type': 'application/json',
|
|
211
|
+
'Authorization': "Bearer ".concat(this.configuration.accessToken),
|
|
212
|
+
},
|
|
340
213
|
data: {
|
|
341
214
|
username: this.configuration.username,
|
|
342
215
|
targetWorkspace: targetWorkspace,
|
|
@@ -345,9 +218,11 @@ var BaseAPI = /** @class */ (function () {
|
|
|
345
218
|
};
|
|
346
219
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
347
220
|
case 1:
|
|
348
|
-
response =
|
|
349
|
-
|
|
350
|
-
this.
|
|
221
|
+
response = _b.sent();
|
|
222
|
+
_a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
|
|
223
|
+
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
224
|
+
this.tokenData.accessToken = accessToken;
|
|
225
|
+
this.tokenData.permissions = permissions;
|
|
351
226
|
this.storeTokenData(__assign({}, this.tokenData));
|
|
352
227
|
return [2 /*return*/];
|
|
353
228
|
}
|
|
@@ -367,42 +242,17 @@ var BaseAPI = /** @class */ (function () {
|
|
|
367
242
|
}
|
|
368
243
|
refreshTokenAxios = axios_1.default.create();
|
|
369
244
|
refreshTokenAxios.interceptors.response.use(function (response) {
|
|
370
|
-
var
|
|
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
|
-
}
|
|
245
|
+
var permissions = response.data.permissions;
|
|
389
246
|
_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
|
-
}
|
|
399
247
|
_this.storeTokenData(_this.tokenData);
|
|
400
248
|
return response;
|
|
401
249
|
});
|
|
402
250
|
options = {
|
|
403
251
|
method: 'POST',
|
|
404
|
-
url: "".concat(this.
|
|
405
|
-
headers:
|
|
252
|
+
url: "".concat(this.configuration.basePath, "/authservice/v1/refresh-token"),
|
|
253
|
+
headers: {
|
|
254
|
+
'Content-Type': 'application/json',
|
|
255
|
+
},
|
|
406
256
|
data: { username: username },
|
|
407
257
|
withCredentials: true,
|
|
408
258
|
};
|
|
@@ -430,100 +280,67 @@ var BaseAPI = /** @class */ (function () {
|
|
|
430
280
|
BaseAPI.prototype.cleanTokenData = function () {
|
|
431
281
|
this.storeTokenData(null);
|
|
432
282
|
};
|
|
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
|
-
};
|
|
444
283
|
BaseAPI.prototype.attachInterceptor = function (axios) {
|
|
445
284
|
var _this = this;
|
|
446
285
|
axios.interceptors.response.use(function (res) {
|
|
447
286
|
return res;
|
|
448
287
|
}, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
449
|
-
var originalConfig,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
switch (_a.label) {
|
|
288
|
+
var originalConfig, _a, tokenString, permissions, accessToken, _error_1, _b, tokenString, permissions, accessToken, _error_2;
|
|
289
|
+
return __generator(this, function (_c) {
|
|
290
|
+
switch (_c.label) {
|
|
453
291
|
case 0:
|
|
454
292
|
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
|
-
}
|
|
459
293
|
if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
|
|
460
294
|
if (!((err.response.status === 401 || err.response.status === 403)
|
|
461
295
|
&& !originalConfig._retry)) return [3 /*break*/, 4];
|
|
462
296
|
originalConfig._retry = true;
|
|
463
|
-
|
|
297
|
+
_c.label = 1;
|
|
464
298
|
case 1:
|
|
465
|
-
|
|
299
|
+
_c.trys.push([1, 3, , 4]);
|
|
466
300
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
467
301
|
case 2:
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
this.
|
|
302
|
+
_a = _c.sent(), tokenString = _a.accessToken, permissions = _a.permissions;
|
|
303
|
+
accessToken = "Bearer ".concat(tokenString);
|
|
304
|
+
this.tokenData.permissions = permissions;
|
|
305
|
+
delete originalConfig.headers['Authorization'];
|
|
306
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
307
|
+
this.configuration.accessToken = accessToken;
|
|
308
|
+
this.tokenData.accessToken = tokenString;
|
|
471
309
|
this.storeTokenData(this.tokenData);
|
|
472
|
-
|
|
473
|
-
return [2 /*return*/, axios(this.withCurrentAuth(originalConfig))];
|
|
474
|
-
}
|
|
475
|
-
// Both mode: if the browser does not send the session cookie (another site), use the token.
|
|
476
|
-
return [2 /*return*/, axios(this.withCurrentAuth(originalConfig)).catch(function (retryError) {
|
|
477
|
-
var _a;
|
|
478
|
-
if (((_a = retryError === null || retryError === void 0 ? void 0 : retryError.response) === null || _a === void 0 ? void 0 : _a.status) !== 401 || !_this.tokenData.accessToken) {
|
|
479
|
-
return Promise.reject(retryError);
|
|
480
|
-
}
|
|
481
|
-
return _this.retryWithToken(axios, originalConfig);
|
|
482
|
-
})];
|
|
310
|
+
return [2 /*return*/, axios(originalConfig)];
|
|
483
311
|
case 3:
|
|
484
|
-
_error_1 =
|
|
312
|
+
_error_1 = _c.sent();
|
|
485
313
|
if (_error_1.response && _error_1.response.data) {
|
|
486
314
|
return [2 /*return*/, Promise.reject(_error_1.response.data)];
|
|
487
315
|
}
|
|
488
316
|
return [2 /*return*/, Promise.reject(_error_1)];
|
|
489
|
-
case 4: return [3 /*break*/,
|
|
317
|
+
case 4: return [3 /*break*/, 9];
|
|
490
318
|
case 5:
|
|
491
|
-
if (!(err.message === NETWORK_ERROR_MESSAGE && this.canRetryWithToken(originalConfig))) return [3 /*break*/, 6];
|
|
492
|
-
// Both mode: the browser blocked the session call or hid its reply; later calls use the token.
|
|
493
|
-
if (!this.canResend(originalConfig)) {
|
|
494
|
-
this.switchToToken();
|
|
495
|
-
return [2 /*return*/, Promise.reject(err)];
|
|
496
|
-
}
|
|
497
|
-
return [2 /*return*/, this.retryWithToken(axios, originalConfig)];
|
|
498
|
-
case 6:
|
|
499
319
|
if (!(err.message === NETWORK_ERROR_MESSAGE
|
|
500
|
-
&&
|
|
501
|
-
|
|
502
|
-
&& _retry_count < 4)) return [3 /*break*/, 10];
|
|
320
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
321
|
+
&& _retry_count < 4)) return [3 /*break*/, 9];
|
|
503
322
|
_retry_count++;
|
|
504
|
-
|
|
505
|
-
case
|
|
506
|
-
|
|
323
|
+
_c.label = 6;
|
|
324
|
+
case 6:
|
|
325
|
+
_c.trys.push([6, 8, , 9]);
|
|
507
326
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
508
|
-
case
|
|
509
|
-
|
|
510
|
-
|
|
327
|
+
case 7:
|
|
328
|
+
_b = _c.sent(), tokenString = _b.accessToken, permissions = _b.permissions;
|
|
329
|
+
accessToken = "Bearer ".concat(tokenString);
|
|
330
|
+
this.tokenData.permissions = permissions;
|
|
511
331
|
_retry = true;
|
|
512
|
-
|
|
332
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
333
|
+
this.configuration.accessToken = accessToken;
|
|
334
|
+
this.tokenData.accessToken = tokenString;
|
|
513
335
|
this.storeTokenData(this.tokenData);
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
_retry_count = 0;
|
|
518
|
-
return retried;
|
|
519
|
-
})];
|
|
520
|
-
case 9:
|
|
521
|
-
_error_2 = _a.sent();
|
|
336
|
+
return [2 /*return*/, axios.request(__assign({}, originalConfig))];
|
|
337
|
+
case 8:
|
|
338
|
+
_error_2 = _c.sent();
|
|
522
339
|
if (_error_2.response && _error_2.response.data) {
|
|
523
340
|
return [2 /*return*/, Promise.reject(_error_2.response.data)];
|
|
524
341
|
}
|
|
525
342
|
return [2 /*return*/, Promise.reject(_error_2)];
|
|
526
|
-
case
|
|
343
|
+
case 9: return [2 /*return*/, Promise.reject(err)];
|
|
527
344
|
}
|
|
528
345
|
});
|
|
529
346
|
}); });
|