@emilgroup/account-sdk 1.49.1-beta.20 → 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 +2 -2
- package/api/accounts-api.ts +48 -18
- package/api/health-api.ts +1 -1
- package/base.ts +239 -43
- package/common.ts +3 -2
- package/configuration.ts +20 -0
- package/dist/api/accounts-api.d.ts +6 -6
- package/dist/api/accounts-api.js +78 -45
- package/dist/api/health-api.d.ts +1 -1
- package/dist/api/health-api.js +1 -1
- package/dist/base.d.ts +26 -0
- package/dist/base.js +243 -60
- package/dist/common.d.ts +1 -1
- package/dist/common.js +1 -0
- package/dist/configuration.d.ts +17 -0
- package/dist/configuration.js +2 -0
- package/package.json +2 -2
package/dist/base.js
CHANGED
|
@@ -74,6 +74,17 @@ 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
|
+
};
|
|
77
88
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
78
89
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
79
90
|
};
|
|
@@ -106,12 +117,21 @@ var Environment;
|
|
|
106
117
|
})(Environment = exports.Environment || (exports.Environment = {}));
|
|
107
118
|
var _retry_count = 0;
|
|
108
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';
|
|
109
123
|
function resetRetry() {
|
|
110
124
|
_retry_count = 0;
|
|
111
125
|
}
|
|
112
126
|
exports.resetRetry = resetRetry;
|
|
113
127
|
var NETWORK_ERROR_MESSAGE = "Network Error";
|
|
114
128
|
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'];
|
|
115
135
|
/**
|
|
116
136
|
*
|
|
117
137
|
* @export
|
|
@@ -125,13 +145,30 @@ var BaseAPI = /** @class */ (function () {
|
|
|
125
145
|
this.axios = axios;
|
|
126
146
|
this.loadTokenData();
|
|
127
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
|
+
}
|
|
128
157
|
var accessToken = this.tokenData.accessToken;
|
|
129
158
|
this.configuration = configuration;
|
|
130
159
|
this.basePath = configuration.basePath || this.basePath;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.
|
|
160
|
+
if (configuration.cookieAuth) {
|
|
161
|
+
this.configuration.username = this.configuration.username || this.tokenData.username;
|
|
162
|
+
}
|
|
163
|
+
if (this.usesSession()) {
|
|
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
|
+
}
|
|
135
172
|
}
|
|
136
173
|
else {
|
|
137
174
|
var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
|
|
@@ -143,6 +180,100 @@ var BaseAPI = /** @class */ (function () {
|
|
|
143
180
|
}
|
|
144
181
|
this.attachInterceptor(axios);
|
|
145
182
|
}
|
|
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
|
+
};
|
|
146
277
|
BaseAPI.prototype.selectEnvironment = function (env) {
|
|
147
278
|
this.selectBasePath(env);
|
|
148
279
|
};
|
|
@@ -158,14 +289,15 @@ var BaseAPI = /** @class */ (function () {
|
|
|
158
289
|
};
|
|
159
290
|
BaseAPI.prototype.authorize = function (username, password, targetWorkspace) {
|
|
160
291
|
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
-
var options, response
|
|
292
|
+
var options, response;
|
|
293
|
+
var _a;
|
|
162
294
|
return __generator(this, function (_b) {
|
|
163
295
|
switch (_b.label) {
|
|
164
296
|
case 0:
|
|
165
297
|
options = {
|
|
166
298
|
method: 'POST',
|
|
167
|
-
url: "".concat(this.
|
|
168
|
-
headers: { 'Content-Type': 'application/json' },
|
|
299
|
+
url: "".concat(this.authBasePath(), "/authservice/v1/login"),
|
|
300
|
+
headers: __assign({ 'Content-Type': 'application/json' }, (this.configuration.cookieAuth && (_a = {}, _a[AUTH_MODE_HEADER] = 'session', _a))),
|
|
169
301
|
data: {
|
|
170
302
|
username: username,
|
|
171
303
|
password: password,
|
|
@@ -175,12 +307,10 @@ var BaseAPI = /** @class */ (function () {
|
|
|
175
307
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
176
308
|
case 1:
|
|
177
309
|
response = _b.sent();
|
|
178
|
-
_a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
|
|
179
310
|
this.configuration.username = username;
|
|
180
|
-
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
181
311
|
this.tokenData.username = username;
|
|
182
|
-
this.tokenData.
|
|
183
|
-
this.
|
|
312
|
+
this.tokenData.permissions = response.data.permissions;
|
|
313
|
+
this.applyTokenReply(response.data);
|
|
184
314
|
if (!targetWorkspace) return [3 /*break*/, 3];
|
|
185
315
|
return [4 /*yield*/, this.switchWorkspace(targetWorkspace)];
|
|
186
316
|
case 2:
|
|
@@ -199,17 +329,14 @@ var BaseAPI = /** @class */ (function () {
|
|
|
199
329
|
};
|
|
200
330
|
BaseAPI.prototype.switchWorkspace = function (targetWorkspace) {
|
|
201
331
|
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
-
var options, response
|
|
203
|
-
return __generator(this, function (
|
|
204
|
-
switch (
|
|
332
|
+
var options, response;
|
|
333
|
+
return __generator(this, function (_a) {
|
|
334
|
+
switch (_a.label) {
|
|
205
335
|
case 0:
|
|
206
336
|
options = {
|
|
207
337
|
method: 'POST',
|
|
208
|
-
url: "".concat(this.
|
|
209
|
-
headers: {
|
|
210
|
-
'Content-Type': 'application/json',
|
|
211
|
-
'Authorization': "Bearer ".concat(this.configuration.accessToken),
|
|
212
|
-
},
|
|
338
|
+
url: "".concat(this.authBasePath(), "/authservice/v1/workspaces/switch"),
|
|
339
|
+
headers: __assign(__assign({ 'Content-Type': 'application/json' }, this.sessionHeaders()), (!this.usesSession() && !!this.configuration.accessToken && { 'Authorization': this.configuration.accessToken })),
|
|
213
340
|
data: {
|
|
214
341
|
username: this.configuration.username,
|
|
215
342
|
targetWorkspace: targetWorkspace,
|
|
@@ -218,11 +345,9 @@ var BaseAPI = /** @class */ (function () {
|
|
|
218
345
|
};
|
|
219
346
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
220
347
|
case 1:
|
|
221
|
-
response =
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
this.tokenData.accessToken = accessToken;
|
|
225
|
-
this.tokenData.permissions = permissions;
|
|
348
|
+
response = _a.sent();
|
|
349
|
+
this.tokenData.permissions = response.data.permissions;
|
|
350
|
+
this.applyTokenReply(response.data);
|
|
226
351
|
this.storeTokenData(__assign({}, this.tokenData));
|
|
227
352
|
return [2 /*return*/];
|
|
228
353
|
}
|
|
@@ -242,17 +367,42 @@ var BaseAPI = /** @class */ (function () {
|
|
|
242
367
|
}
|
|
243
368
|
refreshTokenAxios = axios_1.default.create();
|
|
244
369
|
refreshTokenAxios.interceptors.response.use(function (response) {
|
|
245
|
-
var
|
|
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
|
+
}
|
|
246
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
|
+
}
|
|
247
399
|
_this.storeTokenData(_this.tokenData);
|
|
248
400
|
return response;
|
|
249
401
|
});
|
|
250
402
|
options = {
|
|
251
403
|
method: 'POST',
|
|
252
|
-
url: "".concat(this.
|
|
253
|
-
headers: {
|
|
254
|
-
'Content-Type': 'application/json',
|
|
255
|
-
},
|
|
404
|
+
url: "".concat(this.authBasePath(), "/authservice/v1/refresh-token"),
|
|
405
|
+
headers: __assign({ 'Content-Type': 'application/json' }, this.sessionHeaders()),
|
|
256
406
|
data: { username: username },
|
|
257
407
|
withCredentials: true,
|
|
258
408
|
};
|
|
@@ -280,67 +430,100 @@ var BaseAPI = /** @class */ (function () {
|
|
|
280
430
|
BaseAPI.prototype.cleanTokenData = function () {
|
|
281
431
|
this.storeTokenData(null);
|
|
282
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
|
+
};
|
|
283
444
|
BaseAPI.prototype.attachInterceptor = function (axios) {
|
|
284
445
|
var _this = this;
|
|
285
446
|
axios.interceptors.response.use(function (res) {
|
|
286
447
|
return res;
|
|
287
448
|
}, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
288
|
-
var originalConfig,
|
|
289
|
-
|
|
290
|
-
|
|
449
|
+
var originalConfig, owner, reply, _error_1, reply, _error_2;
|
|
450
|
+
var _this = this;
|
|
451
|
+
return __generator(this, function (_a) {
|
|
452
|
+
switch (_a.label) {
|
|
291
453
|
case 0:
|
|
292
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
|
+
}
|
|
293
459
|
if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
|
|
294
460
|
if (!((err.response.status === 401 || err.response.status === 403)
|
|
295
461
|
&& !originalConfig._retry)) return [3 /*break*/, 4];
|
|
296
462
|
originalConfig._retry = true;
|
|
297
|
-
|
|
463
|
+
_a.label = 1;
|
|
298
464
|
case 1:
|
|
299
|
-
|
|
465
|
+
_a.trys.push([1, 3, , 4]);
|
|
300
466
|
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
301
467
|
case 2:
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.
|
|
305
|
-
delete originalConfig.headers['Authorization'];
|
|
306
|
-
originalConfig.headers['Authorization'] = accessToken;
|
|
307
|
-
this.configuration.accessToken = accessToken;
|
|
308
|
-
this.tokenData.accessToken = tokenString;
|
|
468
|
+
reply = _a.sent();
|
|
469
|
+
this.tokenData.permissions = reply.permissions;
|
|
470
|
+
this.applyTokenReply(reply, true);
|
|
309
471
|
this.storeTokenData(this.tokenData);
|
|
310
|
-
|
|
472
|
+
if (!this.usesSession()) {
|
|
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
|
+
})];
|
|
311
483
|
case 3:
|
|
312
|
-
_error_1 =
|
|
484
|
+
_error_1 = _a.sent();
|
|
313
485
|
if (_error_1.response && _error_1.response.data) {
|
|
314
486
|
return [2 /*return*/, Promise.reject(_error_1.response.data)];
|
|
315
487
|
}
|
|
316
488
|
return [2 /*return*/, Promise.reject(_error_1)];
|
|
317
|
-
case 4: return [3 /*break*/,
|
|
489
|
+
case 4: return [3 /*break*/, 10];
|
|
318
490
|
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:
|
|
319
499
|
if (!(err.message === NETWORK_ERROR_MESSAGE
|
|
320
|
-
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
321
|
-
|
|
500
|
+
&& (originalConfig.headers.hasOwnProperty('Authorization')
|
|
501
|
+
|| (this.configuration.cookieAuth && originalConfig.withCredentials && this.canResend(originalConfig)))
|
|
502
|
+
&& _retry_count < 4)) return [3 /*break*/, 10];
|
|
322
503
|
_retry_count++;
|
|
323
|
-
|
|
324
|
-
case 6:
|
|
325
|
-
_c.trys.push([6, 8, , 9]);
|
|
326
|
-
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
504
|
+
_a.label = 7;
|
|
327
505
|
case 7:
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
506
|
+
_a.trys.push([7, 9, , 10]);
|
|
507
|
+
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
508
|
+
case 8:
|
|
509
|
+
reply = _a.sent();
|
|
510
|
+
this.tokenData.permissions = reply.permissions;
|
|
331
511
|
_retry = true;
|
|
332
|
-
|
|
333
|
-
this.configuration.accessToken = accessToken;
|
|
334
|
-
this.tokenData.accessToken = tokenString;
|
|
512
|
+
this.applyTokenReply(reply, true);
|
|
335
513
|
this.storeTokenData(this.tokenData);
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
+
})];
|
|
520
|
+
case 9:
|
|
521
|
+
_error_2 = _a.sent();
|
|
339
522
|
if (_error_2.response && _error_2.response.data) {
|
|
340
523
|
return [2 /*return*/, Promise.reject(_error_2.response.data)];
|
|
341
524
|
}
|
|
342
525
|
return [2 /*return*/, Promise.reject(_error_2)];
|
|
343
|
-
case
|
|
526
|
+
case 10: return [2 /*return*/, Promise.reject(err)];
|
|
344
527
|
}
|
|
345
528
|
});
|
|
346
529
|
}); });
|
package/dist/common.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare const toPathString: (url: URL) => string;
|
|
|
62
62
|
*
|
|
63
63
|
* @export
|
|
64
64
|
*/
|
|
65
|
-
export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) => <T = unknown, R = AxiosResponse<T, any, {}>>(axios?: AxiosInstance, basePath?: string) => Promise<R>;
|
|
65
|
+
export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) => <T = unknown, R = AxiosResponse<T, any, {}, any>>(axios?: AxiosInstance, basePath?: string) => Promise<R>;
|
|
66
66
|
/**
|
|
67
67
|
* EMIL AccountService
|
|
68
68
|
* The EMIL AccountService API description
|
package/dist/common.js
CHANGED
|
@@ -233,6 +233,7 @@ exports.toPathString = toPathString;
|
|
|
233
233
|
* @export
|
|
234
234
|
*/
|
|
235
235
|
var createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) {
|
|
236
|
+
// Typed by hand: since axios 1.20, request() returns an internal axios type that SDK declarations cannot name.
|
|
236
237
|
return function (axios, basePath) {
|
|
237
238
|
if (axios === void 0) { axios = globalAxios; }
|
|
238
239
|
if (basePath === void 0) { basePath = BASE_PATH; }
|
package/dist/configuration.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface ConfigurationParameters {
|
|
|
17
17
|
basePath?: string;
|
|
18
18
|
baseOptions?: any;
|
|
19
19
|
formDataCtor?: new () => any;
|
|
20
|
+
cookieAuth?: boolean;
|
|
21
|
+
account?: string;
|
|
20
22
|
}
|
|
21
23
|
export declare class Configuration {
|
|
22
24
|
/**
|
|
@@ -68,6 +70,21 @@ export declare class Configuration {
|
|
|
68
70
|
* @type {new () => FormData}
|
|
69
71
|
*/
|
|
70
72
|
formDataCtor?: new () => any;
|
|
73
|
+
/**
|
|
74
|
+
* Use a server session when authservice makes one; otherwise the token, as without this option.
|
|
75
|
+
* Set `account` too, so each SDK object keeps its own account.
|
|
76
|
+
*
|
|
77
|
+
* @type {boolean}
|
|
78
|
+
* @memberof Configuration
|
|
79
|
+
*/
|
|
80
|
+
cookieAuth?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The session account (Cognito sub) this app shows, so the SDK never takes another tab's account.
|
|
83
|
+
*
|
|
84
|
+
* @type {string}
|
|
85
|
+
* @memberof Configuration
|
|
86
|
+
*/
|
|
87
|
+
account?: string;
|
|
71
88
|
constructor(param?: ConfigurationParameters);
|
|
72
89
|
/**
|
|
73
90
|
* Check if the given MIME is a JSON MIME.
|
package/dist/configuration.js
CHANGED
|
@@ -24,6 +24,8 @@ var Configuration = /** @class */ (function () {
|
|
|
24
24
|
this.basePath = param.basePath;
|
|
25
25
|
this.baseOptions = param.baseOptions;
|
|
26
26
|
this.formDataCtor = param.formDataCtor;
|
|
27
|
+
this.cookieAuth = param.cookieAuth;
|
|
28
|
+
this.account = param.account;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Check if the given MIME is a JSON MIME.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emilgroup/account-sdk",
|
|
3
|
-
"version": "1.49.1-beta.
|
|
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": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"prepare": "npm run build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"axios": "1.
|
|
21
|
+
"axios": "1.20.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
|