@bytescale/sdk 3.55.0 → 3.57.0
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/dist/browser/cjs/main.js +230 -51
- package/dist/browser/esm/main.mjs +230 -51
- package/dist/types/private/dtos/AuthSwConfigEntryDto.d.ts +4 -0
- package/dist/types/private/model/AuthManagerInterface.d.ts +29 -6
- package/dist/types/private/model/AuthSession.d.ts +6 -1
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +9 -1
- package/dist/types/public/node/AuthManagerNode.d.ts +3 -1
- package/package.json +1 -1
- package/tests/AuthManagerBrowser.test.ts +342 -0
package/dist/browser/cjs/main.js
CHANGED
|
@@ -3196,6 +3196,13 @@ function AuthManagerBrowser_awaitIgnored(value, direct) {
|
|
|
3196
3196
|
return value && value.then ? value.then(AuthManagerBrowser_empty) : Promise.resolve();
|
|
3197
3197
|
}
|
|
3198
3198
|
}
|
|
3199
|
+
function AuthManagerBrowser_invoke(body, then) {
|
|
3200
|
+
var result = body();
|
|
3201
|
+
if (result && result.then) {
|
|
3202
|
+
return result.then(then);
|
|
3203
|
+
}
|
|
3204
|
+
return then(result);
|
|
3205
|
+
}
|
|
3199
3206
|
function AuthManagerBrowser_await(value, then, direct) {
|
|
3200
3207
|
if (direct) {
|
|
3201
3208
|
return then ? then(value) : value;
|
|
@@ -3223,13 +3230,6 @@ function AuthManagerBrowser_invokeIgnored(body) {
|
|
|
3223
3230
|
return result.then(AuthManagerBrowser_empty);
|
|
3224
3231
|
}
|
|
3225
3232
|
}
|
|
3226
|
-
function AuthManagerBrowser_invoke(body, then) {
|
|
3227
|
-
var result = body();
|
|
3228
|
-
if (result && result.then) {
|
|
3229
|
-
return result.then(then);
|
|
3230
|
-
}
|
|
3231
|
-
return then(result);
|
|
3232
|
-
}
|
|
3233
3233
|
function AuthManagerBrowser_catch(body, recover) {
|
|
3234
3234
|
try {
|
|
3235
3235
|
var result = body();
|
|
@@ -3261,8 +3261,29 @@ function AuthManagerBrowser_continueIgnored(value) {
|
|
|
3261
3261
|
return value.then(AuthManagerBrowser_empty);
|
|
3262
3262
|
}
|
|
3263
3263
|
}
|
|
3264
|
-
function
|
|
3264
|
+
function AuthManagerBrowser_call(body, then, direct) {
|
|
3265
|
+
if (direct) {
|
|
3266
|
+
return then ? then(body()) : body();
|
|
3267
|
+
}
|
|
3268
|
+
try {
|
|
3269
|
+
var result = Promise.resolve(body());
|
|
3270
|
+
return then ? result.then(then) : result;
|
|
3271
|
+
} catch (e) {
|
|
3272
|
+
return Promise.reject(e);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
function AuthManagerBrowser_continue(value, then) {
|
|
3276
|
+
return value && value.then ? value.then(then) : then(value);
|
|
3277
|
+
}
|
|
3265
3278
|
function AuthManagerBrowser_defineProperty(e, r, t) { return (r = AuthManagerBrowser_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
3279
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = AuthManagerBrowser_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
3280
|
+
function AuthManagerBrowser_toConsumableArray(r) { return AuthManagerBrowser_arrayWithoutHoles(r) || AuthManagerBrowser_iterableToArray(r) || AuthManagerBrowser_unsupportedIterableToArray(r) || AuthManagerBrowser_nonIterableSpread(); }
|
|
3281
|
+
function AuthManagerBrowser_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3282
|
+
function AuthManagerBrowser_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return AuthManagerBrowser_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? AuthManagerBrowser_arrayLikeToArray(r, a) : void 0; } }
|
|
3283
|
+
function AuthManagerBrowser_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
3284
|
+
function AuthManagerBrowser_arrayWithoutHoles(r) { if (Array.isArray(r)) return AuthManagerBrowser_arrayLikeToArray(r); }
|
|
3285
|
+
function AuthManagerBrowser_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
3286
|
+
function AuthManagerBrowser_typeof(o) { "@babel/helpers - typeof"; return AuthManagerBrowser_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, AuthManagerBrowser_typeof(o); }
|
|
3266
3287
|
function AuthManagerBrowser_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
3267
3288
|
function AuthManagerBrowser_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, AuthManagerBrowser_toPropertyKey(o.key), o); } }
|
|
3268
3289
|
function AuthManagerBrowser_createClass(e, r, t) { return r && AuthManagerBrowser_defineProperties(e.prototype, r), t && AuthManagerBrowser_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -3297,7 +3318,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3297
3318
|
key: "isAuthSessionReady",
|
|
3298
3319
|
value: function isAuthSessionReady() {
|
|
3299
3320
|
var _a;
|
|
3300
|
-
|
|
3321
|
+
var session = AuthSessionState.getSession();
|
|
3322
|
+
return (_a = session === null || session === void 0 ? void 0 : session.isReady) !== null && _a !== void 0 ? _a : (session === null || session === void 0 ? void 0 : session.accessToken) !== undefined;
|
|
3301
3323
|
}
|
|
3302
3324
|
}, {
|
|
3303
3325
|
key: "beginAuthSession",
|
|
@@ -3309,21 +3331,40 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3309
3331
|
if (_this.isAuthSessionActive()) {
|
|
3310
3332
|
throw new Error("Auth session already active. Please call 'await endAuthSession()' and then call 'await beginAuthSession(...)' to start a new auth session.");
|
|
3311
3333
|
}
|
|
3334
|
+
var canUseServiceWorkers = _this.serviceWorkerUtils.canUseServiceWorkers();
|
|
3335
|
+
if (params.serviceWorkerConfig !== undefined) {
|
|
3336
|
+
if (params.serviceWorkerScript === undefined) {
|
|
3337
|
+
throw new Error("The 'serviceWorkerScript' field is required when 'serviceWorkerConfig' is provided.");
|
|
3338
|
+
}
|
|
3339
|
+
if (!canUseServiceWorkers) {
|
|
3340
|
+
throw new Error("The 'serviceWorkerConfig' field requires service workers, but this browser does not support them.");
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3312
3343
|
var newSession = {
|
|
3313
3344
|
accessToken: undefined,
|
|
3314
3345
|
accessTokenRefreshHandle: undefined,
|
|
3315
3346
|
params: params,
|
|
3316
3347
|
isActive: true,
|
|
3317
|
-
|
|
3348
|
+
isReady: false,
|
|
3349
|
+
authServiceWorker: params.serviceWorkerScript !== undefined && canUseServiceWorkers ? {
|
|
3318
3350
|
serviceWorkerScript: params.serviceWorkerScript,
|
|
3319
3351
|
type: "Uninitialized"
|
|
3320
|
-
} : undefined
|
|
3352
|
+
} : undefined,
|
|
3353
|
+
primaryAuthSwConfig: undefined,
|
|
3354
|
+
serviceWorkerConfig: undefined,
|
|
3355
|
+
serviceWorkerConfigRefreshHandle: undefined
|
|
3321
3356
|
};
|
|
3322
3357
|
AuthSessionState.setSession(newSession);
|
|
3323
3358
|
return newSession;
|
|
3324
3359
|
})), function (session) {
|
|
3325
3360
|
// IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
|
|
3326
|
-
return
|
|
3361
|
+
return AuthManagerBrowser_invoke(function () {
|
|
3362
|
+
if (session.params.serviceWorkerConfig !== undefined) {
|
|
3363
|
+
return AuthManagerBrowser_awaitIgnored(_this.refreshServiceWorkerConfig(session, session.params));
|
|
3364
|
+
}
|
|
3365
|
+
}, function () {
|
|
3366
|
+
return AuthManagerBrowser_awaitIgnored(_this.refreshAccessToken(session, session.params));
|
|
3367
|
+
});
|
|
3327
3368
|
});
|
|
3328
3369
|
} catch (e) {
|
|
3329
3370
|
return Promise.reject(e);
|
|
@@ -3344,14 +3385,20 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3344
3385
|
if (session.accessTokenRefreshHandle !== undefined) {
|
|
3345
3386
|
_this2.scheduler.unschedule(session.accessTokenRefreshHandle);
|
|
3346
3387
|
}
|
|
3347
|
-
|
|
3388
|
+
if (session.serviceWorkerConfigRefreshHandle !== undefined) {
|
|
3389
|
+
_this2.scheduler.unschedule(session.serviceWorkerConfigRefreshHandle);
|
|
3390
|
+
}
|
|
3391
|
+
// AuthSessionState is shared between bundled SDK versions. Service-worker-only sessions from 3.56.0 did not
|
|
3392
|
+
// contain an accountId, so allow a newer SDK instance to tear those sessions down without calling this endpoint.
|
|
3393
|
+
return AuthManagerBrowser_invoke(function () {
|
|
3394
|
+
if (typeof session.params.accountId === "string") {
|
|
3395
|
+
return AuthManagerBrowser_awaitIgnored(_this2.deleteAccessToken(session.params));
|
|
3396
|
+
}
|
|
3397
|
+
}, function () {
|
|
3348
3398
|
return AuthManagerBrowser_invokeIgnored(function () {
|
|
3349
3399
|
if (session.authServiceWorker !== undefined) {
|
|
3350
3400
|
// Prevent service worker from authorizing subsequent requests.
|
|
3351
|
-
return AuthManagerBrowser_awaitIgnored(_this2.
|
|
3352
|
-
type: "SET_BYTESCALE_AUTH_CONFIG",
|
|
3353
|
-
config: []
|
|
3354
|
-
}, session.authServiceWorker, _this2.serviceWorkerScriptFieldName));
|
|
3401
|
+
return AuthManagerBrowser_awaitIgnored(_this2.sendServiceWorkerConfig(session, []));
|
|
3355
3402
|
}
|
|
3356
3403
|
});
|
|
3357
3404
|
});
|
|
@@ -3362,7 +3409,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3362
3409
|
}
|
|
3363
3410
|
}, {
|
|
3364
3411
|
key: "refreshAccessToken",
|
|
3365
|
-
value: function refreshAccessToken(session) {
|
|
3412
|
+
value: function refreshAccessToken(session, params) {
|
|
3366
3413
|
try {
|
|
3367
3414
|
var _this3 = this;
|
|
3368
3415
|
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this3.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
@@ -3375,36 +3422,35 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3375
3422
|
var expires = secondsFromNow(_this3.retryAuthAfterErrorSeconds);
|
|
3376
3423
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
|
|
3377
3424
|
return AuthManagerBrowser_catch(function () {
|
|
3378
|
-
var _getAccessToken = _this3.getAccessToken
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
return AuthManagerBrowser_await(_getAccessToken.call(_this3, _session$params, _session$params$authH), function (jwt) {
|
|
3425
|
+
var _getAccessToken = _this3.getAccessToken;
|
|
3426
|
+
return AuthManagerBrowser_await(params.authHeaders(), function (_params$authHeaders) {
|
|
3427
|
+
return AuthManagerBrowser_await(_getAccessToken.call(_this3, params, _params$authHeaders), function (jwt) {
|
|
3382
3428
|
// We don't use cookie-based auth if the browser supports service worker-based auth, as using both will cause
|
|
3383
3429
|
// confusion for us in the future (i.e. we may question "do we need to use both together? was there a reason?").
|
|
3384
3430
|
// Also: if the user has omitted "allowedOrigins" from their JWT, then service worker-based auth is more secure
|
|
3385
3431
|
// than cookie-based auth, which is another reason to prevent these cookies from being set unless required.
|
|
3386
3432
|
var setCookie = session.authServiceWorker === undefined;
|
|
3387
|
-
return AuthManagerBrowser_await(_this3.setAccessToken(
|
|
3433
|
+
return AuthManagerBrowser_await(_this3.setAccessToken(params, jwt, setCookie), function (setTokenResult) {
|
|
3388
3434
|
return AuthManagerBrowser_invoke(function () {
|
|
3389
3435
|
if (session.authServiceWorker !== undefined) {
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3436
|
+
var primaryAuthSwConfig = {
|
|
3437
|
+
headers: [{
|
|
3438
|
+
key: "Authorization",
|
|
3439
|
+
value: "Bearer ".concat(jwt)
|
|
3440
|
+
}],
|
|
3441
|
+
expires: secondsFromNow(setTokenResult.ttlSeconds),
|
|
3442
|
+
urlPrefix: "".concat(_this3.getCdnUrl(params), "/").concat(params.accountId, "/")
|
|
3443
|
+
};
|
|
3444
|
+
// Fail closed until the initial serviceWorkerConfig callback succeeds: without its result, we do not know
|
|
3445
|
+
// the source-page restrictions intended for the primary JWT.
|
|
3446
|
+
return AuthManagerBrowser_invoke(function () {
|
|
3447
|
+
if (params.serviceWorkerConfig === undefined || session.serviceWorkerConfig !== undefined) {
|
|
3448
|
+
return AuthManagerBrowser_await(_this3.sendMergedServiceWorkerConfig(session, primaryAuthSwConfig, session.serviceWorkerConfig), function () {
|
|
3449
|
+
return AuthManagerBrowser_awaitIgnored(_this3.waitForServiceWorker());
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3452
|
+
}, function () {
|
|
3453
|
+
session.primaryAuthSwConfig = primaryAuthSwConfig;
|
|
3408
3454
|
});
|
|
3409
3455
|
}
|
|
3410
3456
|
}, function () {
|
|
@@ -3416,6 +3462,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3416
3462
|
expires = secondsFromNow(actualTtl);
|
|
3417
3463
|
// Set this at the end, as it's also used to signal 'isAuthSessionReady', so must be set after configuring the Service Worker, etc.
|
|
3418
3464
|
session.accessToken = setTokenResult.accessToken;
|
|
3465
|
+
_this3.updateSessionReadiness(session);
|
|
3419
3466
|
});
|
|
3420
3467
|
});
|
|
3421
3468
|
});
|
|
@@ -3428,7 +3475,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3428
3475
|
// 'setTimeout' can be paused (e.g., during hibernation), risking JWT expiration before it triggers. We use a
|
|
3429
3476
|
// scheduler to check wall-clock time every second and execute the callback at the scheduled time (below).
|
|
3430
3477
|
session.accessTokenRefreshHandle = _this3.scheduler.schedule(expires, function () {
|
|
3431
|
-
_this3.refreshAccessToken(session).then(function () {},
|
|
3478
|
+
_this3.refreshAccessToken(session, params).then(function () {},
|
|
3432
3479
|
// Should not occur, as this method shouldn't throw errors.
|
|
3433
3480
|
function (e) {
|
|
3434
3481
|
return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
|
|
@@ -3441,6 +3488,138 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3441
3488
|
return Promise.reject(e);
|
|
3442
3489
|
}
|
|
3443
3490
|
}
|
|
3491
|
+
}, {
|
|
3492
|
+
key: "refreshServiceWorkerConfig",
|
|
3493
|
+
value: function refreshServiceWorkerConfig(session, params) {
|
|
3494
|
+
try {
|
|
3495
|
+
var _this4 = this;
|
|
3496
|
+
var getServiceWorkerConfig = params.serviceWorkerConfig;
|
|
3497
|
+
if (getServiceWorkerConfig === undefined) {
|
|
3498
|
+
return AuthManagerBrowser_await();
|
|
3499
|
+
}
|
|
3500
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this4.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
3501
|
+
var _exit = false;
|
|
3502
|
+
if (!session.isActive) {
|
|
3503
|
+
return;
|
|
3504
|
+
}
|
|
3505
|
+
var refreshAt;
|
|
3506
|
+
return AuthManagerBrowser_continue(AuthManagerBrowser_catch(function () {
|
|
3507
|
+
return AuthManagerBrowser_call(getServiceWorkerConfig, function (result) {
|
|
3508
|
+
if (result === null || AuthManagerBrowser_typeof(result) !== "object" || !Array.isArray(result.additionalConfig)) {
|
|
3509
|
+
throw new Error("The 'serviceWorkerConfig' callback must return an object containing 'additionalConfig'.");
|
|
3510
|
+
}
|
|
3511
|
+
if (result.sourceUrlPrefixes !== undefined && (!Array.isArray(result.sourceUrlPrefixes) || !result.sourceUrlPrefixes.every(function (prefix) {
|
|
3512
|
+
return typeof prefix === "string";
|
|
3513
|
+
}))) {
|
|
3514
|
+
throw new Error("The 'sourceUrlPrefixes' field returned by 'serviceWorkerConfig' must be an array of strings.");
|
|
3515
|
+
}
|
|
3516
|
+
var config = {
|
|
3517
|
+
additionalConfig: result.additionalConfig,
|
|
3518
|
+
sourceUrlPrefixes: result.sourceUrlPrefixes
|
|
3519
|
+
};
|
|
3520
|
+
return AuthManagerBrowser_invoke(function () {
|
|
3521
|
+
if (session.primaryAuthSwConfig !== undefined) {
|
|
3522
|
+
return AuthManagerBrowser_await(_this4.sendMergedServiceWorkerConfig(session, session.primaryAuthSwConfig, config), function () {
|
|
3523
|
+
return AuthManagerBrowser_awaitIgnored(_this4.waitForServiceWorker());
|
|
3524
|
+
});
|
|
3525
|
+
}
|
|
3526
|
+
}, function () {
|
|
3527
|
+
session.serviceWorkerConfig = config;
|
|
3528
|
+
_this4.updateSessionReadiness(session);
|
|
3529
|
+
refreshAt = _this4.getServiceWorkerConfigRefreshEpoch(config.additionalConfig);
|
|
3530
|
+
});
|
|
3531
|
+
});
|
|
3532
|
+
}, function (e) {
|
|
3533
|
+
ConsoleUtils.warn("Unable to refresh service worker auth config: ".concat(e));
|
|
3534
|
+
refreshAt = Date.now() + _this4.retryAuthAfterErrorSeconds * 1000;
|
|
3535
|
+
}), function (_result2) {
|
|
3536
|
+
if (_exit) return _result2;
|
|
3537
|
+
if (refreshAt !== undefined) {
|
|
3538
|
+
session.serviceWorkerConfigRefreshHandle = _this4.scheduler.schedule(refreshAt, function () {
|
|
3539
|
+
_this4.refreshServiceWorkerConfig(session, params).then(function () {}, function (e) {
|
|
3540
|
+
return ConsoleUtils.error("Unexpected error when refreshing service worker auth config: ".concat(e));
|
|
3541
|
+
});
|
|
3542
|
+
});
|
|
3543
|
+
}
|
|
3544
|
+
});
|
|
3545
|
+
}))));
|
|
3546
|
+
} catch (e) {
|
|
3547
|
+
return Promise.reject(e);
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
}, {
|
|
3551
|
+
key: "sendMergedServiceWorkerConfig",
|
|
3552
|
+
value: function sendMergedServiceWorkerConfig(session, primaryConfig, serviceWorkerConfig) {
|
|
3553
|
+
try {
|
|
3554
|
+
var _this5 = this;
|
|
3555
|
+
var _a;
|
|
3556
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this5.sendServiceWorkerConfig(session, [Object.assign(Object.assign({}, primaryConfig), {
|
|
3557
|
+
sourceUrlPrefixes: serviceWorkerConfig === null || serviceWorkerConfig === void 0 ? void 0 : serviceWorkerConfig.sourceUrlPrefixes
|
|
3558
|
+
})].concat(AuthManagerBrowser_toConsumableArray((_a = serviceWorkerConfig === null || serviceWorkerConfig === void 0 ? void 0 : serviceWorkerConfig.additionalConfig) !== null && _a !== void 0 ? _a : [])))));
|
|
3559
|
+
} catch (e) {
|
|
3560
|
+
return Promise.reject(e);
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
}, {
|
|
3564
|
+
key: "getServiceWorkerConfigRefreshEpoch",
|
|
3565
|
+
value: function getServiceWorkerConfigRefreshEpoch(config) {
|
|
3566
|
+
var earliestExpiry;
|
|
3567
|
+
var _iterator = _createForOfIteratorHelper(config),
|
|
3568
|
+
_step;
|
|
3569
|
+
try {
|
|
3570
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
3571
|
+
var entry = _step.value;
|
|
3572
|
+
if (entry.expires !== undefined && (earliestExpiry === undefined || entry.expires < earliestExpiry)) {
|
|
3573
|
+
earliestExpiry = entry.expires;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
} catch (err) {
|
|
3577
|
+
_iterator.e(err);
|
|
3578
|
+
} finally {
|
|
3579
|
+
_iterator.f();
|
|
3580
|
+
}
|
|
3581
|
+
return earliestExpiry === undefined ? undefined : earliestExpiry - this.refreshBeforeExpirySeconds * 1000;
|
|
3582
|
+
}
|
|
3583
|
+
}, {
|
|
3584
|
+
key: "sendServiceWorkerConfig",
|
|
3585
|
+
value: function sendServiceWorkerConfig(session, config) {
|
|
3586
|
+
try {
|
|
3587
|
+
var _this6 = this;
|
|
3588
|
+
if (session.authServiceWorker === undefined) {
|
|
3589
|
+
throw new Error("Service worker configuration cannot be applied because service workers are unavailable.");
|
|
3590
|
+
}
|
|
3591
|
+
return AuthManagerBrowser_await(_this6.serviceWorkerUtils.sendMessage({
|
|
3592
|
+
type: "SET_BYTESCALE_AUTH_CONFIG",
|
|
3593
|
+
config: config.map(function (entry) {
|
|
3594
|
+
return Object.assign(Object.assign({}, entry), {
|
|
3595
|
+
urlPrefix: "".concat(entry.sourceUrlPrefixes === undefined ? "" : _this6.sourceScopedUrlPrefixMarker).concat(entry.urlPrefix)
|
|
3596
|
+
});
|
|
3597
|
+
})
|
|
3598
|
+
}, session.authServiceWorker, _this6.serviceWorkerScriptFieldName), function (_this6$serviceWorkerU) {
|
|
3599
|
+
session.authServiceWorker = _this6$serviceWorkerU;
|
|
3600
|
+
});
|
|
3601
|
+
} catch (e) {
|
|
3602
|
+
return Promise.reject(e);
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
}, {
|
|
3606
|
+
key: "updateSessionReadiness",
|
|
3607
|
+
value: function updateSessionReadiness(session) {
|
|
3608
|
+
session.isReady = session.accessToken !== undefined && (session.params.serviceWorkerConfig === undefined || session.serviceWorkerConfig !== undefined);
|
|
3609
|
+
}
|
|
3610
|
+
}, {
|
|
3611
|
+
key: "waitForServiceWorker",
|
|
3612
|
+
value: function waitForServiceWorker() {
|
|
3613
|
+
try {
|
|
3614
|
+
// Message delivery is asynchronous and has no acknowledgement, so allow the worker time to apply the config before
|
|
3615
|
+
// beginAuthSession reports that authenticated requests are ready.
|
|
3616
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(new Promise(function (resolve) {
|
|
3617
|
+
return setTimeout(resolve, 100);
|
|
3618
|
+
})));
|
|
3619
|
+
} catch (e) {
|
|
3620
|
+
return Promise.reject(e);
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3444
3623
|
}, {
|
|
3445
3624
|
key: "getAccessTokenUrl",
|
|
3446
3625
|
value: function getAccessTokenUrl(params, setCookie) {
|
|
@@ -3456,9 +3635,9 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3456
3635
|
key: "deleteAccessToken",
|
|
3457
3636
|
value: function deleteAccessToken(params) {
|
|
3458
3637
|
try {
|
|
3459
|
-
var
|
|
3638
|
+
var _this7 = this;
|
|
3460
3639
|
var _a;
|
|
3461
|
-
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(
|
|
3640
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this7.getAccessTokenUrl(params, true), {
|
|
3462
3641
|
method: "DELETE",
|
|
3463
3642
|
credentials: "include",
|
|
3464
3643
|
headers: {}
|
|
@@ -3474,15 +3653,15 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3474
3653
|
key: "setAccessToken",
|
|
3475
3654
|
value: function setAccessToken(params, jwt, setCookie) {
|
|
3476
3655
|
try {
|
|
3477
|
-
var
|
|
3656
|
+
var _this8 = this;
|
|
3478
3657
|
var _a;
|
|
3479
3658
|
var request = {
|
|
3480
3659
|
accessToken: jwt
|
|
3481
3660
|
};
|
|
3482
|
-
return AuthManagerBrowser_await(BaseAPI.fetch(
|
|
3661
|
+
return AuthManagerBrowser_await(BaseAPI.fetch(_this8.getAccessTokenUrl(params, setCookie), {
|
|
3483
3662
|
method: "PUT",
|
|
3484
3663
|
credentials: "include",
|
|
3485
|
-
headers: AuthManagerBrowser_defineProperty({},
|
|
3664
|
+
headers: AuthManagerBrowser_defineProperty({}, _this8.contentType, _this8.contentTypeJson),
|
|
3486
3665
|
body: JSON.stringify(request)
|
|
3487
3666
|
}, {
|
|
3488
3667
|
isBytescaleApi: true,
|
|
@@ -3498,10 +3677,10 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3498
3677
|
key: "getAccessToken",
|
|
3499
3678
|
value: function getAccessToken(params, headers) {
|
|
3500
3679
|
try {
|
|
3501
|
-
var
|
|
3680
|
+
var _this9 = this;
|
|
3502
3681
|
var _a, _b;
|
|
3503
3682
|
var endpointName = "Your auth API endpoint";
|
|
3504
|
-
var requiredContentType =
|
|
3683
|
+
var requiredContentType = _this9.contentTypeText;
|
|
3505
3684
|
return AuthManagerBrowser_await(BaseAPI.fetch(params.authUrl, {
|
|
3506
3685
|
method: "GET",
|
|
3507
3686
|
headers: headers
|
|
@@ -3509,10 +3688,10 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3509
3688
|
isBytescaleApi: false,
|
|
3510
3689
|
fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
|
|
3511
3690
|
}), function (result) {
|
|
3512
|
-
var actualContentType = (_b = result.headers.get(
|
|
3691
|
+
var actualContentType = (_b = result.headers.get(_this9.contentType)) !== null && _b !== void 0 ? _b : "";
|
|
3513
3692
|
// Support content types like "text/plain; charset=utf-8" and "text/plain"
|
|
3514
3693
|
if (actualContentType.split(";")[0] !== requiredContentType) {
|
|
3515
|
-
throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(
|
|
3694
|
+
throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this9.contentType, " response header, but the Bytescale SDK requires \"").concat(requiredContentType, "\"."));
|
|
3516
3695
|
}
|
|
3517
3696
|
return AuthManagerBrowser_await(result.text(), function (jwt) {
|
|
3518
3697
|
if (jwt.length === 0) {
|