@emilgroup/public-api-sdk 1.40.1-beta.27 → 1.40.1-beta.28
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/address-completions-validations-api.ts +6 -16
- package/api/booking-funnels-api.ts +3 -8
- package/api/documents-api.ts +21 -56
- package/api/health-api.ts +1 -1
- package/api/ibanvalidator-api.ts +3 -8
- package/api/leads-api.ts +24 -64
- package/api/named-ranges-api.ts +3 -8
- package/api/notifications-api.ts +9 -24
- package/api/partners-api.ts +3 -8
- package/api/payments-setup-api.ts +20 -60
- package/api/product-versions-api.ts +12 -32
- package/api/products-api.ts +27 -72
- package/base.ts +54 -310
- package/common.ts +2 -3
- package/configuration.ts +0 -20
- package/dist/api/address-completions-validations-api.d.ts +2 -2
- package/dist/api/address-completions-validations-api.js +14 -22
- package/dist/api/booking-funnels-api.d.ts +1 -1
- package/dist/api/booking-funnels-api.js +7 -11
- package/dist/api/documents-api.d.ts +7 -7
- package/dist/api/documents-api.js +53 -93
- package/dist/api/health-api.d.ts +1 -1
- package/dist/api/health-api.js +1 -1
- package/dist/api/ibanvalidator-api.d.ts +1 -1
- package/dist/api/ibanvalidator-api.js +8 -15
- package/dist/api/leads-api.d.ts +8 -8
- package/dist/api/leads-api.js +64 -120
- package/dist/api/named-ranges-api.d.ts +1 -1
- package/dist/api/named-ranges-api.js +7 -11
- package/dist/api/notifications-api.d.ts +3 -3
- package/dist/api/notifications-api.js +24 -45
- package/dist/api/partners-api.d.ts +1 -1
- package/dist/api/partners-api.js +8 -15
- package/dist/api/payments-setup-api.d.ts +4 -4
- package/dist/api/payments-setup-api.js +40 -80
- package/dist/api/product-versions-api.d.ts +4 -4
- package/dist/api/product-versions-api.js +31 -56
- package/dist/api/products-api.d.ts +9 -9
- package/dist/api/products-api.js +68 -119
- package/dist/base.d.ts +0 -33
- package/dist/base.js +72 -308
- 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
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,20 +106,12 @@ var Environment;
|
|
|
117
106
|
})(Environment = exports.Environment || (exports.Environment = {}));
|
|
118
107
|
var _retry_count = 0;
|
|
119
108
|
var _retry = null;
|
|
120
|
-
// Refreshes in flight per account (BaseAPI.shareRefresh).
|
|
121
|
-
var refreshesInFlight = new Map();
|
|
122
109
|
function resetRetry() {
|
|
123
110
|
_retry_count = 0;
|
|
124
111
|
}
|
|
125
112
|
exports.resetRetry = resetRetry;
|
|
126
113
|
var NETWORK_ERROR_MESSAGE = "Network Error";
|
|
127
114
|
var TOKEN_DATA = 'APP_TOKEN';
|
|
128
|
-
// Sent only to authservice, to ask for a server session.
|
|
129
|
-
var AUTH_MODE_HEADER = 'X-Emil-Auth-Mode';
|
|
130
|
-
// Names the account on every call; one browser session can hold several.
|
|
131
|
-
var ACCOUNT_HEADER = 'X-Emil-Account';
|
|
132
|
-
var SESSION_MODES = ['both', 'session'];
|
|
133
|
-
var RESEND_SAFE_METHODS = ['get', 'head', 'options'];
|
|
134
115
|
/**
|
|
135
116
|
*
|
|
136
117
|
* @export
|
|
@@ -144,30 +125,13 @@ var BaseAPI = /** @class */ (function () {
|
|
|
144
125
|
this.axios = axios;
|
|
145
126
|
this.loadTokenData();
|
|
146
127
|
if (configuration) {
|
|
147
|
-
// Two accounts in one browser share APP_TOKEN: never take the token or session account saved for
|
|
148
|
-
// another account. The mode stays (an app naming its account keeps its session). Saved with the next refresh.
|
|
149
|
-
var ownUser = configuration.username;
|
|
150
|
-
var storedUser = this.tokenData.username;
|
|
151
|
-
if (ownUser && storedUser && ownUser.toLowerCase() !== storedUser.toLowerCase()) {
|
|
152
|
-
delete this.tokenData.accessToken;
|
|
153
|
-
delete this.tokenData.sub;
|
|
154
|
-
this.tokenData.username = ownUser;
|
|
155
|
-
}
|
|
156
128
|
var accessToken = this.tokenData.accessToken;
|
|
157
129
|
this.configuration = configuration;
|
|
158
130
|
this.basePath = configuration.basePath || this.basePath;
|
|
159
|
-
if
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.useSessionAuth();
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
// Use config token if provided, otherwise use tokenData token
|
|
167
|
-
var configToken = this.configuration.accessToken;
|
|
168
|
-
var storedToken = accessToken ? "Bearer ".concat(accessToken) : '';
|
|
169
|
-
this.configuration.accessToken = configToken || storedToken;
|
|
170
|
-
}
|
|
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;
|
|
171
135
|
}
|
|
172
136
|
else {
|
|
173
137
|
var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
|
|
@@ -179,100 +143,6 @@ var BaseAPI = /** @class */ (function () {
|
|
|
179
143
|
}
|
|
180
144
|
this.attachInterceptor(axios);
|
|
181
145
|
}
|
|
182
|
-
// The app's own account wins over APP_TOKEN, which holds whichever tab wrote last.
|
|
183
|
-
BaseAPI.prototype.sessionAccount = function () {
|
|
184
|
-
return this.configuration.account || this.tokenData.sub;
|
|
185
|
-
};
|
|
186
|
-
// Apps may pass the address as the second argument only; authservice is on the same host.
|
|
187
|
-
BaseAPI.prototype.authBasePath = function () {
|
|
188
|
-
return this.configuration.basePath || this.basePath;
|
|
189
|
-
};
|
|
190
|
-
BaseAPI.prototype.usesSession = function () {
|
|
191
|
-
return !!this.configuration.cookieAuth && SESSION_MODES.indexOf(this.tokenData.authMode) !== -1 && !!this.sessionAccount();
|
|
192
|
-
};
|
|
193
|
-
BaseAPI.prototype.useSessionAuth = function () {
|
|
194
|
-
var _a;
|
|
195
|
-
var _b = this.configuration.baseOptions || {}, headers = _b.headers, baseOptions = __rest(_b, ["headers"]);
|
|
196
|
-
this.configuration.accessToken = '';
|
|
197
|
-
this.configuration.baseOptions = __assign(__assign({}, baseOptions), { withCredentials: true, headers: __assign(__assign({}, headers), (_a = {}, _a[ACCOUNT_HEADER] = this.sessionAccount(), _a)) });
|
|
198
|
-
};
|
|
199
|
-
BaseAPI.prototype.useHeaderAuth = function (accessToken, keepSessionData) {
|
|
200
|
-
if (keepSessionData === void 0) { keepSessionData = false; }
|
|
201
|
-
this.configuration.accessToken = accessToken ? "Bearer ".concat(accessToken) : '';
|
|
202
|
-
this.tokenData.accessToken = accessToken;
|
|
203
|
-
// An app without cookieAuth does not own the session fields: its refresh leaves them for the session apps.
|
|
204
|
-
if (!keepSessionData || this.configuration.cookieAuth) {
|
|
205
|
-
delete this.tokenData.authMode;
|
|
206
|
-
delete this.tokenData.sub;
|
|
207
|
-
}
|
|
208
|
-
if (this.configuration.cookieAuth) {
|
|
209
|
-
var _a = this.configuration.baseOptions || {}, withCredentials = _a.withCredentials, headers = _a.headers, baseOptions = __rest(_a, ["withCredentials", "headers"]);
|
|
210
|
-
var _b = headers || {}, _c = ACCOUNT_HEADER, account = _b[_c], otherHeaders = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
211
|
-
this.configuration.baseOptions = __assign(__assign({}, baseOptions), { headers: otherHeaders });
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
BaseAPI.prototype.applyTokenReply = function (_a, fromRefresh) {
|
|
215
|
-
var accessToken = _a.accessToken, authMode = _a.authMode, session = _a.session;
|
|
216
|
-
if (fromRefresh === void 0) { fromRefresh = false; }
|
|
217
|
-
if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && (session === null || session === void 0 ? void 0 : session.sub)) {
|
|
218
|
-
this.tokenData.authMode = authMode;
|
|
219
|
-
this.tokenData.sub = session.sub;
|
|
220
|
-
if (this.configuration.account) {
|
|
221
|
-
// A workspace switch moves the app to another account.
|
|
222
|
-
this.configuration.account = session.sub;
|
|
223
|
-
}
|
|
224
|
-
// Both keeps the token for apps not moved yet; session mode keeps no token at all.
|
|
225
|
-
if (authMode === 'both' && accessToken) {
|
|
226
|
-
this.tokenData.accessToken = accessToken;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
delete this.tokenData.accessToken;
|
|
230
|
-
}
|
|
231
|
-
this.useSessionAuth();
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
this.useHeaderAuth(accessToken, fromRefresh);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
BaseAPI.prototype.sessionHeaders = function () {
|
|
238
|
-
var _a, _b;
|
|
239
|
-
if (!this.configuration.cookieAuth) {
|
|
240
|
-
return {};
|
|
241
|
-
}
|
|
242
|
-
return __assign((_a = {}, _a[AUTH_MODE_HEADER] = 'session', _a), (this.usesSession() && (_b = {}, _b[ACCOUNT_HEADER] = this.sessionAccount(), _b)));
|
|
243
|
-
};
|
|
244
|
-
BaseAPI.prototype.withCurrentAuth = function (config) {
|
|
245
|
-
delete config.headers['Authorization'];
|
|
246
|
-
delete config.headers[ACCOUNT_HEADER];
|
|
247
|
-
if (this.usesSession()) {
|
|
248
|
-
config.headers[ACCOUNT_HEADER] = this.sessionAccount();
|
|
249
|
-
config.withCredentials = true;
|
|
250
|
-
}
|
|
251
|
-
else if (this.configuration.accessToken) {
|
|
252
|
-
config.headers['Authorization'] = this.configuration.accessToken;
|
|
253
|
-
}
|
|
254
|
-
return config;
|
|
255
|
-
};
|
|
256
|
-
// Both keeps the token, so a session call the browser could not complete can be sent again with it.
|
|
257
|
-
BaseAPI.prototype.canRetryWithToken = function (config) {
|
|
258
|
-
var _a;
|
|
259
|
-
return !!config.withCredentials && !!((_a = config.headers) === null || _a === void 0 ? void 0 : _a[ACCOUNT_HEADER])
|
|
260
|
-
&& !!this.tokenData.accessToken && this.tokenData.authMode !== 'session';
|
|
261
|
-
};
|
|
262
|
-
// A network error can come after the server ran the call, so only a call that is safe to repeat is sent again.
|
|
263
|
-
BaseAPI.prototype.canResend = function (config) {
|
|
264
|
-
return RESEND_SAFE_METHODS.indexOf((config.method || 'get').toLowerCase()) !== -1
|
|
265
|
-
|| Object.keys(config.headers || {}).some(function (name) { return name.toLowerCase() === 'idempotency-key'; });
|
|
266
|
-
};
|
|
267
|
-
BaseAPI.prototype.switchToToken = function () {
|
|
268
|
-
this.useHeaderAuth(this.tokenData.accessToken);
|
|
269
|
-
this.storeTokenData(this.tokenData);
|
|
270
|
-
};
|
|
271
|
-
BaseAPI.prototype.retryWithToken = function (axios, config) {
|
|
272
|
-
this.switchToToken();
|
|
273
|
-
config.withCredentials = false;
|
|
274
|
-
return axios(this.withCurrentAuth(config));
|
|
275
|
-
};
|
|
276
146
|
BaseAPI.prototype.selectEnvironment = function (env) {
|
|
277
147
|
this.selectBasePath(env);
|
|
278
148
|
};
|
|
@@ -288,15 +158,14 @@ var BaseAPI = /** @class */ (function () {
|
|
|
288
158
|
};
|
|
289
159
|
BaseAPI.prototype.authorize = function (username, password, targetWorkspace) {
|
|
290
160
|
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
-
var options, response;
|
|
292
|
-
var _a;
|
|
161
|
+
var options, response, _a, accessToken, permissions;
|
|
293
162
|
return __generator(this, function (_b) {
|
|
294
163
|
switch (_b.label) {
|
|
295
164
|
case 0:
|
|
296
165
|
options = {
|
|
297
166
|
method: 'POST',
|
|
298
|
-
url: "".concat(this.
|
|
299
|
-
headers:
|
|
167
|
+
url: "".concat(this.configuration.basePath, "/authservice/v1/login"),
|
|
168
|
+
headers: { 'Content-Type': 'application/json' },
|
|
300
169
|
data: {
|
|
301
170
|
username: username,
|
|
302
171
|
password: password,
|
|
@@ -306,10 +175,12 @@ var BaseAPI = /** @class */ (function () {
|
|
|
306
175
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
307
176
|
case 1:
|
|
308
177
|
response = _b.sent();
|
|
178
|
+
_a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
|
|
309
179
|
this.configuration.username = username;
|
|
180
|
+
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
310
181
|
this.tokenData.username = username;
|
|
311
|
-
this.tokenData.
|
|
312
|
-
this.
|
|
182
|
+
this.tokenData.accessToken = accessToken;
|
|
183
|
+
this.tokenData.permissions = permissions;
|
|
313
184
|
if (!targetWorkspace) return [3 /*break*/, 3];
|
|
314
185
|
return [4 /*yield*/, this.switchWorkspace(targetWorkspace)];
|
|
315
186
|
case 2:
|
|
@@ -328,14 +199,17 @@ var BaseAPI = /** @class */ (function () {
|
|
|
328
199
|
};
|
|
329
200
|
BaseAPI.prototype.switchWorkspace = function (targetWorkspace) {
|
|
330
201
|
return __awaiter(this, void 0, void 0, function () {
|
|
331
|
-
var options, response;
|
|
332
|
-
return __generator(this, function (
|
|
333
|
-
switch (
|
|
202
|
+
var options, response, _a, accessToken, permissions;
|
|
203
|
+
return __generator(this, function (_b) {
|
|
204
|
+
switch (_b.label) {
|
|
334
205
|
case 0:
|
|
335
206
|
options = {
|
|
336
207
|
method: 'POST',
|
|
337
|
-
url: "".concat(this.
|
|
338
|
-
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
|
+
},
|
|
339
213
|
data: {
|
|
340
214
|
username: this.configuration.username,
|
|
341
215
|
targetWorkspace: targetWorkspace,
|
|
@@ -344,9 +218,11 @@ var BaseAPI = /** @class */ (function () {
|
|
|
344
218
|
};
|
|
345
219
|
return [4 /*yield*/, axios_1.default.request(options)];
|
|
346
220
|
case 1:
|
|
347
|
-
response =
|
|
348
|
-
|
|
349
|
-
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;
|
|
350
226
|
this.storeTokenData(__assign({}, this.tokenData));
|
|
351
227
|
return [2 /*return*/];
|
|
352
228
|
}
|
|
@@ -355,55 +231,28 @@ var BaseAPI = /** @class */ (function () {
|
|
|
355
231
|
};
|
|
356
232
|
BaseAPI.prototype.refreshTokenInternal = function () {
|
|
357
233
|
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
-
var username,
|
|
234
|
+
var username, refreshTokenAxios, options, response;
|
|
359
235
|
var _this = this;
|
|
360
236
|
return __generator(this, function (_a) {
|
|
361
237
|
switch (_a.label) {
|
|
362
238
|
case 0:
|
|
363
239
|
username = this.configuration.username;
|
|
364
240
|
if (!username) {
|
|
365
|
-
|
|
366
|
-
cannotRefresh.sessionExpired = true;
|
|
367
|
-
throw cannotRefresh;
|
|
241
|
+
throw new Error('Failed to refresh token.');
|
|
368
242
|
}
|
|
369
243
|
refreshTokenAxios = axios_1.default.create();
|
|
370
244
|
refreshTokenAxios.interceptors.response.use(function (response) {
|
|
371
|
-
var
|
|
372
|
-
var _c = response.data, permissions = _c.permissions, accessToken = _c.accessToken, authMode = _c.authMode;
|
|
373
|
-
// Decided before the merge below: newer session data must not keep the new token from this object.
|
|
374
|
-
var onSession = _this.usesSession();
|
|
375
|
-
// Newer data saved for this account (e.g. the session mode the shell saved later) wins over the copy
|
|
376
|
-
// read when the object was made; data of another account or another workspace (sub) is never taken.
|
|
377
|
-
var latest = ((typeof window !== 'undefined' && (0, common_1.defaultStorage)().get(TOKEN_DATA)) || {});
|
|
378
|
-
var ownSub = _this.sessionAccount();
|
|
379
|
-
if (((_a = latest.username) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === username.toLowerCase()
|
|
380
|
-
&& (!ownSub || !latest.sub || latest.sub === ownSub)) {
|
|
381
|
-
// A bare reset ({username}, an app's account check) keeps this copy's other fields; any fuller record
|
|
382
|
-
// is the truth, so fields it lacks were removed on purpose (e.g. a rollback) and stay removed.
|
|
383
|
-
var bareReset = Object.keys(latest).every(function (key) { return key === 'username'; });
|
|
384
|
-
_this.tokenData = bareReset ? __assign(__assign({}, _this.tokenData), latest) : __assign({}, latest);
|
|
385
|
-
}
|
|
386
|
-
// The reply is for this account: label it, or an SDK object of another account would take the token.
|
|
387
|
-
if (((_b = _this.tokenData.username) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== username.toLowerCase()) {
|
|
388
|
-
_this.tokenData.username = username;
|
|
389
|
-
}
|
|
245
|
+
var permissions = response.data.permissions;
|
|
390
246
|
_this.tokenData.permissions = permissions;
|
|
391
|
-
// Keep the new token for the page's next SDK objects; session data is left as it is.
|
|
392
|
-
if (accessToken && !onSession) {
|
|
393
|
-
_this.tokenData.accessToken = accessToken;
|
|
394
|
-
_this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
395
|
-
}
|
|
396
|
-
else if (accessToken && authMode === 'both') {
|
|
397
|
-
// Both: this app stays on the session; the token is kept for apps not moved yet.
|
|
398
|
-
_this.tokenData.accessToken = accessToken;
|
|
399
|
-
}
|
|
400
247
|
_this.storeTokenData(_this.tokenData);
|
|
401
248
|
return response;
|
|
402
249
|
});
|
|
403
250
|
options = {
|
|
404
251
|
method: 'POST',
|
|
405
|
-
url: "".concat(this.
|
|
406
|
-
headers:
|
|
252
|
+
url: "".concat(this.configuration.basePath, "/authservice/v1/refresh-token"),
|
|
253
|
+
headers: {
|
|
254
|
+
'Content-Type': 'application/json',
|
|
255
|
+
},
|
|
407
256
|
data: { username: username },
|
|
408
257
|
withCredentials: true,
|
|
409
258
|
};
|
|
@@ -431,156 +280,71 @@ var BaseAPI = /** @class */ (function () {
|
|
|
431
280
|
BaseAPI.prototype.cleanTokenData = function () {
|
|
432
281
|
this.storeTokenData(null);
|
|
433
282
|
};
|
|
434
|
-
BaseAPI.prototype.ownAccount = function () {
|
|
435
|
-
return (this.configuration.username || '').toLowerCase();
|
|
436
|
-
};
|
|
437
|
-
BaseAPI.prototype.withOwner = function (options) {
|
|
438
|
-
var _a;
|
|
439
|
-
// An object without a username cannot refresh itself: its requests stay unmarked, as before.
|
|
440
|
-
if (!this.ownAccount()) {
|
|
441
|
-
return __assign({}, options);
|
|
442
|
-
}
|
|
443
|
-
return __assign(__assign({}, options), (_a = {}, _a[BaseAPI.REQUEST_OWNER] = this.ownAccount(), _a));
|
|
444
|
-
};
|
|
445
|
-
// Sent for another account: only that account's SDK objects handle it. Unmarked requests as before.
|
|
446
|
-
BaseAPI.prototype.sentByOtherAccount = function (config) {
|
|
447
|
-
var owner = config === null || config === void 0 ? void 0 : config[BaseAPI.REQUEST_OWNER];
|
|
448
|
-
return owner !== undefined && owner !== this.ownAccount();
|
|
449
|
-
};
|
|
450
|
-
// One refresh per account; an object without a username keeps its own, which fails as before.
|
|
451
|
-
BaseAPI.prototype.sharedRefresh = function () {
|
|
452
|
-
var _this = this;
|
|
453
|
-
var account = this.ownAccount();
|
|
454
|
-
if (!account) {
|
|
455
|
-
return this.refreshTokenInternal();
|
|
456
|
-
}
|
|
457
|
-
return BaseAPI.shareRefresh(refreshesInFlight, account, function () { return _this.refreshTokenInternal(); });
|
|
458
|
-
};
|
|
459
|
-
BaseAPI.prototype.refreshRunning = function () {
|
|
460
|
-
var account = this.ownAccount();
|
|
461
|
-
return !!account && refreshesInFlight.has(account);
|
|
462
|
-
};
|
|
463
|
-
// Joins the refresh already in flight for this key, or starts one: calls refused at the same time wait for
|
|
464
|
-
// one refresh instead of each starting their own (a refresh token may be single-use). The entry is removed
|
|
465
|
-
// when the refresh settles.
|
|
466
|
-
BaseAPI.shareRefresh = function (inFlight, key, start) {
|
|
467
|
-
var running = inFlight.get(key);
|
|
468
|
-
if (running) {
|
|
469
|
-
return running;
|
|
470
|
-
}
|
|
471
|
-
var refresh = start();
|
|
472
|
-
inFlight.set(key, refresh);
|
|
473
|
-
var settled = function () { inFlight.delete(key); };
|
|
474
|
-
refresh.then(settled, settled);
|
|
475
|
-
return refresh;
|
|
476
|
-
};
|
|
477
|
-
// A refused call that joins a refresh already running is not a new try: only started refreshes count toward
|
|
478
|
-
// the limit, so every call refused at the same time is retried.
|
|
479
|
-
BaseAPI.prototype.mayRefreshAfterNetworkError = function () {
|
|
480
|
-
if (this.refreshRunning()) {
|
|
481
|
-
return true;
|
|
482
|
-
}
|
|
483
|
-
if (_retry_count >= 4) {
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
_retry_count++;
|
|
487
|
-
return true;
|
|
488
|
-
};
|
|
489
|
-
// Rejects as before (the refresh's response body, or its error). Marks it as an ended session only when the
|
|
490
|
-
// refresh was refused (401 or 403) or could not run (no username, marked where it is thrown); a server error
|
|
491
|
-
// or a network error says nothing about the session, so an app must not log the user out for it. A body that
|
|
492
|
-
// is not an object cannot carry the mark and is kept as it is.
|
|
493
|
-
BaseAPI.prototype.rejectEndedSession = function (error) {
|
|
494
|
-
var _a, _b;
|
|
495
|
-
var rejection = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error;
|
|
496
|
-
var status = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status;
|
|
497
|
-
if (typeof rejection === 'object' && (status === 401 || status === 403)) {
|
|
498
|
-
rejection.sessionExpired = true;
|
|
499
|
-
}
|
|
500
|
-
return Promise.reject(rejection);
|
|
501
|
-
};
|
|
502
283
|
BaseAPI.prototype.attachInterceptor = function (axios) {
|
|
503
284
|
var _this = this;
|
|
504
285
|
axios.interceptors.response.use(function (res) {
|
|
505
286
|
return res;
|
|
506
287
|
}, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
507
|
-
var originalConfig,
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
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) {
|
|
511
291
|
case 0:
|
|
512
292
|
originalConfig = err.config;
|
|
513
|
-
if (this.sentByOtherAccount(originalConfig)) {
|
|
514
|
-
return [2 /*return*/, Promise.reject(err)];
|
|
515
|
-
}
|
|
516
293
|
if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
|
|
517
294
|
if (!((err.response.status === 401 || err.response.status === 403)
|
|
518
295
|
&& !originalConfig._retry)) return [3 /*break*/, 4];
|
|
519
296
|
originalConfig._retry = true;
|
|
520
|
-
|
|
297
|
+
_c.label = 1;
|
|
521
298
|
case 1:
|
|
522
|
-
|
|
523
|
-
return [4 /*yield*/, this.
|
|
299
|
+
_c.trys.push([1, 3, , 4]);
|
|
300
|
+
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
524
301
|
case 2:
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
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;
|
|
528
309
|
this.storeTokenData(this.tokenData);
|
|
529
|
-
|
|
530
|
-
return [2 /*return*/, axios(this.withCurrentAuth(originalConfig))];
|
|
531
|
-
}
|
|
532
|
-
// Both mode: if the browser does not send the session cookie (another site), use the token.
|
|
533
|
-
return [2 /*return*/, axios(this.withCurrentAuth(originalConfig)).catch(function (retryError) {
|
|
534
|
-
var _a;
|
|
535
|
-
if (((_a = retryError === null || retryError === void 0 ? void 0 : retryError.response) === null || _a === void 0 ? void 0 : _a.status) !== 401 || !_this.tokenData.accessToken) {
|
|
536
|
-
return Promise.reject(retryError);
|
|
537
|
-
}
|
|
538
|
-
return _this.retryWithToken(axios, originalConfig);
|
|
539
|
-
})];
|
|
310
|
+
return [2 /*return*/, axios(originalConfig)];
|
|
540
311
|
case 3:
|
|
541
|
-
_error_1 =
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
case 5:
|
|
545
|
-
if (!(err.message === NETWORK_ERROR_MESSAGE && this.canRetryWithToken(originalConfig))) return [3 /*break*/, 6];
|
|
546
|
-
// Both mode: the browser blocked the session call or hid its reply; later calls use the token.
|
|
547
|
-
if (!this.canResend(originalConfig)) {
|
|
548
|
-
this.switchToToken();
|
|
549
|
-
return [2 /*return*/, Promise.reject(err)];
|
|
312
|
+
_error_1 = _c.sent();
|
|
313
|
+
if (_error_1.response && _error_1.response.data) {
|
|
314
|
+
return [2 /*return*/, Promise.reject(_error_1.response.data)];
|
|
550
315
|
}
|
|
551
|
-
return [2 /*return*/,
|
|
552
|
-
case
|
|
316
|
+
return [2 /*return*/, Promise.reject(_error_1)];
|
|
317
|
+
case 4: return [3 /*break*/, 9];
|
|
318
|
+
case 5:
|
|
553
319
|
if (!(err.message === NETWORK_ERROR_MESSAGE
|
|
554
|
-
&&
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
320
|
+
&& originalConfig.headers.hasOwnProperty('Authorization')
|
|
321
|
+
&& _retry_count < 4)) return [3 /*break*/, 9];
|
|
322
|
+
_retry_count++;
|
|
323
|
+
_c.label = 6;
|
|
324
|
+
case 6:
|
|
325
|
+
_c.trys.push([6, 8, , 9]);
|
|
326
|
+
return [4 /*yield*/, this.refreshTokenInternal()];
|
|
558
327
|
case 7:
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
reply = _a.sent();
|
|
563
|
-
this.tokenData.permissions = reply.permissions;
|
|
328
|
+
_b = _c.sent(), tokenString = _b.accessToken, permissions = _b.permissions;
|
|
329
|
+
accessToken = "Bearer ".concat(tokenString);
|
|
330
|
+
this.tokenData.permissions = permissions;
|
|
564
331
|
_retry = true;
|
|
565
|
-
|
|
332
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
333
|
+
this.configuration.accessToken = accessToken;
|
|
334
|
+
this.tokenData.accessToken = tokenString;
|
|
566
335
|
this.storeTokenData(this.tokenData);
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return [2 /*return*/, this.rejectEndedSession(_error_2)];
|
|
576
|
-
case 10: return [2 /*return*/, Promise.reject(err)];
|
|
336
|
+
return [2 /*return*/, axios.request(__assign({}, originalConfig))];
|
|
337
|
+
case 8:
|
|
338
|
+
_error_2 = _c.sent();
|
|
339
|
+
if (_error_2.response && _error_2.response.data) {
|
|
340
|
+
return [2 /*return*/, Promise.reject(_error_2.response.data)];
|
|
341
|
+
}
|
|
342
|
+
return [2 /*return*/, Promise.reject(_error_2)];
|
|
343
|
+
case 9: return [2 /*return*/, Promise.reject(err)];
|
|
577
344
|
}
|
|
578
345
|
});
|
|
579
346
|
}); });
|
|
580
347
|
};
|
|
581
|
-
// Marks each request with the account (username) of the SDK object that sent it: only SDK objects of that
|
|
582
|
-
// account refresh and resend it, never an object of another account in the same app.
|
|
583
|
-
BaseAPI.REQUEST_OWNER = '_emilSdkOwner';
|
|
584
348
|
return BaseAPI;
|
|
585
349
|
}());
|
|
586
350
|
exports.BaseAPI = BaseAPI;
|
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, {}
|
|
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>;
|
|
66
66
|
/**
|
|
67
67
|
* Emil PublicAPI
|
|
68
68
|
* The Emil Public API description
|
package/dist/common.js
CHANGED
|
@@ -233,7 +233,6 @@ 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.
|
|
237
236
|
return function (axios, basePath) {
|
|
238
237
|
if (axios === void 0) { axios = globalAxios; }
|
|
239
238
|
if (basePath === void 0) { basePath = BASE_PATH; }
|
package/dist/configuration.d.ts
CHANGED
|
@@ -17,8 +17,6 @@ export interface ConfigurationParameters {
|
|
|
17
17
|
basePath?: string;
|
|
18
18
|
baseOptions?: any;
|
|
19
19
|
formDataCtor?: new () => any;
|
|
20
|
-
cookieAuth?: boolean;
|
|
21
|
-
account?: string;
|
|
22
20
|
}
|
|
23
21
|
export declare class Configuration {
|
|
24
22
|
/**
|
|
@@ -70,21 +68,6 @@ export declare class Configuration {
|
|
|
70
68
|
* @type {new () => FormData}
|
|
71
69
|
*/
|
|
72
70
|
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;
|
|
88
71
|
constructor(param?: ConfigurationParameters);
|
|
89
72
|
/**
|
|
90
73
|
* Check if the given MIME is a JSON MIME.
|
package/dist/configuration.js
CHANGED
|
@@ -24,8 +24,6 @@ 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;
|
|
29
27
|
}
|
|
30
28
|
/**
|
|
31
29
|
* Check if the given MIME is a JSON MIME.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emilgroup/public-api-sdk",
|
|
3
|
-
"version": "1.40.1-beta.
|
|
3
|
+
"version": "1.40.1-beta.28",
|
|
4
4
|
"description": "OpenAPI client for @emilgroup/public-api-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.18.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
|