@bytescale/sdk 3.41.0 → 3.43.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 +101 -13
- package/dist/browser/esm/main.mjs +101 -13
- package/dist/node/cjs/main.js +5 -0
- package/dist/node/esm/main.mjs +5 -0
- package/dist/types/private/Scheduler.d.ts +10 -0
- package/dist/types/private/model/AuthManagerInterface.d.ts +4 -0
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +2 -1
- package/dist/types/public/node/AuthManagerNode.d.ts +1 -0
- package/dist/worker/cjs/main.js +5 -0
- package/dist/worker/esm/main.mjs +5 -0
- package/package.json +1 -1
package/dist/browser/cjs/main.js
CHANGED
|
@@ -3076,6 +3076,77 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
3076
3076
|
}
|
|
3077
3077
|
}]);
|
|
3078
3078
|
}();
|
|
3079
|
+
;// CONCATENATED MODULE: ./src/private/Scheduler.ts
|
|
3080
|
+
function Scheduler_typeof(o) { "@babel/helpers - typeof"; return Scheduler_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; }, Scheduler_typeof(o); }
|
|
3081
|
+
function Scheduler_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3082
|
+
function Scheduler_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, Scheduler_toPropertyKey(descriptor.key), descriptor); } }
|
|
3083
|
+
function Scheduler_createClass(Constructor, protoProps, staticProps) { if (protoProps) Scheduler_defineProperties(Constructor.prototype, protoProps); if (staticProps) Scheduler_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
3084
|
+
function Scheduler_toPropertyKey(t) { var i = Scheduler_toPrimitive(t, "string"); return "symbol" == Scheduler_typeof(i) ? i : i + ""; }
|
|
3085
|
+
function Scheduler_toPrimitive(t, r) { if ("object" != Scheduler_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != Scheduler_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3086
|
+
|
|
3087
|
+
var Scheduler = /*#__PURE__*/function () {
|
|
3088
|
+
function Scheduler() {
|
|
3089
|
+
Scheduler_classCallCheck(this, Scheduler);
|
|
3090
|
+
this.callbacks = {};
|
|
3091
|
+
this.nextId = 0;
|
|
3092
|
+
this.intervalId = undefined;
|
|
3093
|
+
}
|
|
3094
|
+
return Scheduler_createClass(Scheduler, [{
|
|
3095
|
+
key: "schedule",
|
|
3096
|
+
value: function schedule(epoch, callback) {
|
|
3097
|
+
var handle = this.nextId++;
|
|
3098
|
+
this.callbacks[handle] = {
|
|
3099
|
+
epoch: epoch,
|
|
3100
|
+
callback: callback
|
|
3101
|
+
};
|
|
3102
|
+
this.startInterval();
|
|
3103
|
+
return handle;
|
|
3104
|
+
}
|
|
3105
|
+
}, {
|
|
3106
|
+
key: "unschedule",
|
|
3107
|
+
value: function unschedule(handle) {
|
|
3108
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
3109
|
+
delete this.callbacks[handle];
|
|
3110
|
+
if (Object.keys(this.callbacks).length === 0) {
|
|
3111
|
+
this.stopInterval();
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
}, {
|
|
3115
|
+
key: "startInterval",
|
|
3116
|
+
value: function startInterval() {
|
|
3117
|
+
var _this = this;
|
|
3118
|
+
if (this.intervalId === undefined) {
|
|
3119
|
+
this.intervalId = setInterval(function () {
|
|
3120
|
+
return _this.checkCallbacks();
|
|
3121
|
+
}, 1000);
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
}, {
|
|
3125
|
+
key: "stopInterval",
|
|
3126
|
+
value: function stopInterval() {
|
|
3127
|
+
if (this.intervalId !== undefined) {
|
|
3128
|
+
clearInterval(this.intervalId);
|
|
3129
|
+
this.intervalId = undefined;
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}, {
|
|
3133
|
+
key: "checkCallbacks",
|
|
3134
|
+
value: function checkCallbacks() {
|
|
3135
|
+
var now = Date.now();
|
|
3136
|
+
for (var handleStr in this.callbacks) {
|
|
3137
|
+
var handle = parseInt(handleStr);
|
|
3138
|
+
if (this.callbacks[handle].epoch <= now) {
|
|
3139
|
+
try {
|
|
3140
|
+
this.callbacks[handle].callback();
|
|
3141
|
+
} catch (e) {
|
|
3142
|
+
ConsoleUtils.error("Unhandled error from scheduled callback: ".concat(e));
|
|
3143
|
+
}
|
|
3144
|
+
this.unschedule(handle);
|
|
3145
|
+
}
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
}]);
|
|
3149
|
+
}();
|
|
3079
3150
|
;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
|
|
3080
3151
|
function AuthManagerBrowser_empty() {}
|
|
3081
3152
|
function AuthManagerBrowser_awaitIgnored(value, direct) {
|
|
@@ -3159,6 +3230,7 @@ function AuthManagerBrowser_toPrimitive(t, r) { if ("object" != AuthManagerBrows
|
|
|
3159
3230
|
|
|
3160
3231
|
|
|
3161
3232
|
|
|
3233
|
+
|
|
3162
3234
|
var AuthManagerImpl = /*#__PURE__*/function () {
|
|
3163
3235
|
function AuthManagerImpl(serviceWorkerUtils) {
|
|
3164
3236
|
AuthManagerBrowser_classCallCheck(this, AuthManagerImpl);
|
|
@@ -3168,9 +3240,9 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3168
3240
|
this.contentTypeJson = "application/json";
|
|
3169
3241
|
this.contentTypeText = "text/plain";
|
|
3170
3242
|
this.minJwtTtlSeconds = 10;
|
|
3171
|
-
this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
|
|
3172
3243
|
this.retryAuthAfterErrorSeconds = 5;
|
|
3173
3244
|
this.refreshBeforeExpirySeconds = 20;
|
|
3245
|
+
this.scheduler = new Scheduler();
|
|
3174
3246
|
this.authSessionMutex = AuthSessionState.getMutex();
|
|
3175
3247
|
}
|
|
3176
3248
|
return AuthManagerBrowser_createClass(AuthManagerImpl, [{
|
|
@@ -3178,6 +3250,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3178
3250
|
value: function isAuthSessionActive() {
|
|
3179
3251
|
return AuthSessionState.getSession() !== undefined;
|
|
3180
3252
|
}
|
|
3253
|
+
}, {
|
|
3254
|
+
key: "isAuthSessionReady",
|
|
3255
|
+
value: function isAuthSessionReady() {
|
|
3256
|
+
var _a;
|
|
3257
|
+
return ((_a = AuthSessionState.getSession()) === null || _a === void 0 ? void 0 : _a.accessToken) !== undefined;
|
|
3258
|
+
}
|
|
3181
3259
|
}, {
|
|
3182
3260
|
key: "beginAuthSession",
|
|
3183
3261
|
value: function beginAuthSession(params) {
|
|
@@ -3221,7 +3299,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3221
3299
|
AuthSessionState.setSession(undefined);
|
|
3222
3300
|
session.isActive = false;
|
|
3223
3301
|
if (session.accessTokenRefreshHandle !== undefined) {
|
|
3224
|
-
|
|
3302
|
+
_this2.scheduler.unschedule(session.accessTokenRefreshHandle);
|
|
3225
3303
|
}
|
|
3226
3304
|
return AuthManagerBrowser_await(_this2.deleteAccessToken(session.params), function () {
|
|
3227
3305
|
return AuthManagerBrowser_invokeIgnored(function () {
|
|
@@ -3248,7 +3326,10 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3248
3326
|
if (!session.isActive) {
|
|
3249
3327
|
return;
|
|
3250
3328
|
}
|
|
3251
|
-
var
|
|
3329
|
+
var secondsFromNow = function secondsFromNow(seconds) {
|
|
3330
|
+
return Date.now() + seconds * 1000;
|
|
3331
|
+
};
|
|
3332
|
+
var expires = secondsFromNow(_this3.retryAuthAfterErrorSeconds);
|
|
3252
3333
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
|
|
3253
3334
|
return AuthManagerBrowser_catch(function () {
|
|
3254
3335
|
var _getAccessToken = _this3.getAccessToken,
|
|
@@ -3263,26 +3344,33 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3263
3344
|
return AuthManagerBrowser_await(_this3.setAccessToken(session.params, jwt, setCookie), function (setTokenResult) {
|
|
3264
3345
|
return AuthManagerBrowser_invoke(function () {
|
|
3265
3346
|
if (session.authServiceWorker !== undefined) {
|
|
3266
|
-
return
|
|
3347
|
+
return AuthManagerBrowser_await(_this3.serviceWorkerUtils.sendMessage({
|
|
3267
3348
|
type: "SET_BYTESCALE_AUTH_CONFIG",
|
|
3268
3349
|
config: [{
|
|
3269
3350
|
headers: [{
|
|
3270
3351
|
key: "Authorization",
|
|
3271
3352
|
value: "Bearer ".concat(jwt)
|
|
3272
3353
|
}],
|
|
3273
|
-
expires:
|
|
3354
|
+
expires: secondsFromNow(setTokenResult.ttlSeconds),
|
|
3274
3355
|
urlPrefix: "".concat(_this3.getCdnUrl(session.params), "/").concat(session.params.accountId, "/")
|
|
3275
3356
|
}]
|
|
3276
|
-
}, session.authServiceWorker, _this3.serviceWorkerScriptFieldName))
|
|
3357
|
+
}, session.authServiceWorker, _this3.serviceWorkerScriptFieldName), function () {
|
|
3358
|
+
// Allow time for the service worker to receive and process the message. Since this is asynchronous and not
|
|
3359
|
+
// synchronized, we need to wait for a sufficient amount of time to ensure the service worker is ready to
|
|
3360
|
+
// authenticate requests, so that after 'beginAuthSession' completes, users can start making requests.
|
|
3361
|
+
return AuthManagerBrowser_awaitIgnored(new Promise(function (resolve) {
|
|
3362
|
+
return setTimeout(resolve, 100);
|
|
3363
|
+
}));
|
|
3364
|
+
});
|
|
3277
3365
|
}
|
|
3278
3366
|
}, function () {
|
|
3279
3367
|
var desiredTtl = setTokenResult.ttlSeconds - _this3.refreshBeforeExpirySeconds;
|
|
3280
|
-
|
|
3281
|
-
if (desiredTtl !==
|
|
3282
|
-
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(
|
|
3368
|
+
var actualTtl = Math.max(desiredTtl, _this3.minJwtTtlSeconds);
|
|
3369
|
+
if (desiredTtl !== actualTtl) {
|
|
3370
|
+
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(actualTtl, " seconds before refreshing."));
|
|
3283
3371
|
}
|
|
3284
|
-
|
|
3285
|
-
|
|
3372
|
+
expires = secondsFromNow(actualTtl);
|
|
3373
|
+
// Set this at the end, as it's also used to signal 'isAuthSessionReady', so must be set after configuring the Service Worker, etc.
|
|
3286
3374
|
session.accessToken = setTokenResult.accessToken;
|
|
3287
3375
|
});
|
|
3288
3376
|
});
|
|
@@ -3293,13 +3381,13 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3293
3381
|
ConsoleUtils.warn("Unable to refresh JWT access token: ".concat(e));
|
|
3294
3382
|
});
|
|
3295
3383
|
}, function (_wasThrown, _result) {
|
|
3296
|
-
session.accessTokenRefreshHandle =
|
|
3384
|
+
session.accessTokenRefreshHandle = _this3.scheduler.schedule(expires, function () {
|
|
3297
3385
|
_this3.refreshAccessToken(session).then(function () {},
|
|
3298
3386
|
// Should not occur, as this method shouldn't throw errors.
|
|
3299
3387
|
function (e) {
|
|
3300
3388
|
return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
|
|
3301
3389
|
});
|
|
3302
|
-
}
|
|
3390
|
+
});
|
|
3303
3391
|
return AuthManagerBrowser_rethrow(_wasThrown, _result);
|
|
3304
3392
|
}));
|
|
3305
3393
|
}))));
|
|
@@ -3061,6 +3061,77 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
3061
3061
|
}
|
|
3062
3062
|
}]);
|
|
3063
3063
|
}();
|
|
3064
|
+
;// CONCATENATED MODULE: ./src/private/Scheduler.ts
|
|
3065
|
+
function Scheduler_typeof(o) { "@babel/helpers - typeof"; return Scheduler_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; }, Scheduler_typeof(o); }
|
|
3066
|
+
function Scheduler_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3067
|
+
function Scheduler_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, Scheduler_toPropertyKey(descriptor.key), descriptor); } }
|
|
3068
|
+
function Scheduler_createClass(Constructor, protoProps, staticProps) { if (protoProps) Scheduler_defineProperties(Constructor.prototype, protoProps); if (staticProps) Scheduler_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
3069
|
+
function Scheduler_toPropertyKey(t) { var i = Scheduler_toPrimitive(t, "string"); return "symbol" == Scheduler_typeof(i) ? i : i + ""; }
|
|
3070
|
+
function Scheduler_toPrimitive(t, r) { if ("object" != Scheduler_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != Scheduler_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3071
|
+
|
|
3072
|
+
var Scheduler = /*#__PURE__*/function () {
|
|
3073
|
+
function Scheduler() {
|
|
3074
|
+
Scheduler_classCallCheck(this, Scheduler);
|
|
3075
|
+
this.callbacks = {};
|
|
3076
|
+
this.nextId = 0;
|
|
3077
|
+
this.intervalId = undefined;
|
|
3078
|
+
}
|
|
3079
|
+
return Scheduler_createClass(Scheduler, [{
|
|
3080
|
+
key: "schedule",
|
|
3081
|
+
value: function schedule(epoch, callback) {
|
|
3082
|
+
var handle = this.nextId++;
|
|
3083
|
+
this.callbacks[handle] = {
|
|
3084
|
+
epoch: epoch,
|
|
3085
|
+
callback: callback
|
|
3086
|
+
};
|
|
3087
|
+
this.startInterval();
|
|
3088
|
+
return handle;
|
|
3089
|
+
}
|
|
3090
|
+
}, {
|
|
3091
|
+
key: "unschedule",
|
|
3092
|
+
value: function unschedule(handle) {
|
|
3093
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
3094
|
+
delete this.callbacks[handle];
|
|
3095
|
+
if (Object.keys(this.callbacks).length === 0) {
|
|
3096
|
+
this.stopInterval();
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
}, {
|
|
3100
|
+
key: "startInterval",
|
|
3101
|
+
value: function startInterval() {
|
|
3102
|
+
var _this = this;
|
|
3103
|
+
if (this.intervalId === undefined) {
|
|
3104
|
+
this.intervalId = setInterval(function () {
|
|
3105
|
+
return _this.checkCallbacks();
|
|
3106
|
+
}, 1000);
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
}, {
|
|
3110
|
+
key: "stopInterval",
|
|
3111
|
+
value: function stopInterval() {
|
|
3112
|
+
if (this.intervalId !== undefined) {
|
|
3113
|
+
clearInterval(this.intervalId);
|
|
3114
|
+
this.intervalId = undefined;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
}, {
|
|
3118
|
+
key: "checkCallbacks",
|
|
3119
|
+
value: function checkCallbacks() {
|
|
3120
|
+
var now = Date.now();
|
|
3121
|
+
for (var handleStr in this.callbacks) {
|
|
3122
|
+
var handle = parseInt(handleStr);
|
|
3123
|
+
if (this.callbacks[handle].epoch <= now) {
|
|
3124
|
+
try {
|
|
3125
|
+
this.callbacks[handle].callback();
|
|
3126
|
+
} catch (e) {
|
|
3127
|
+
ConsoleUtils.error("Unhandled error from scheduled callback: ".concat(e));
|
|
3128
|
+
}
|
|
3129
|
+
this.unschedule(handle);
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
}]);
|
|
3134
|
+
}();
|
|
3064
3135
|
;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
|
|
3065
3136
|
function AuthManagerBrowser_empty() {}
|
|
3066
3137
|
function AuthManagerBrowser_awaitIgnored(value, direct) {
|
|
@@ -3144,6 +3215,7 @@ function AuthManagerBrowser_toPrimitive(t, r) { if ("object" != AuthManagerBrows
|
|
|
3144
3215
|
|
|
3145
3216
|
|
|
3146
3217
|
|
|
3218
|
+
|
|
3147
3219
|
var AuthManagerImpl = /*#__PURE__*/function () {
|
|
3148
3220
|
function AuthManagerImpl(serviceWorkerUtils) {
|
|
3149
3221
|
AuthManagerBrowser_classCallCheck(this, AuthManagerImpl);
|
|
@@ -3153,9 +3225,9 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3153
3225
|
this.contentTypeJson = "application/json";
|
|
3154
3226
|
this.contentTypeText = "text/plain";
|
|
3155
3227
|
this.minJwtTtlSeconds = 10;
|
|
3156
|
-
this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
|
|
3157
3228
|
this.retryAuthAfterErrorSeconds = 5;
|
|
3158
3229
|
this.refreshBeforeExpirySeconds = 20;
|
|
3230
|
+
this.scheduler = new Scheduler();
|
|
3159
3231
|
this.authSessionMutex = AuthSessionState.getMutex();
|
|
3160
3232
|
}
|
|
3161
3233
|
return AuthManagerBrowser_createClass(AuthManagerImpl, [{
|
|
@@ -3163,6 +3235,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3163
3235
|
value: function isAuthSessionActive() {
|
|
3164
3236
|
return AuthSessionState.getSession() !== undefined;
|
|
3165
3237
|
}
|
|
3238
|
+
}, {
|
|
3239
|
+
key: "isAuthSessionReady",
|
|
3240
|
+
value: function isAuthSessionReady() {
|
|
3241
|
+
var _a;
|
|
3242
|
+
return ((_a = AuthSessionState.getSession()) === null || _a === void 0 ? void 0 : _a.accessToken) !== undefined;
|
|
3243
|
+
}
|
|
3166
3244
|
}, {
|
|
3167
3245
|
key: "beginAuthSession",
|
|
3168
3246
|
value: function beginAuthSession(params) {
|
|
@@ -3206,7 +3284,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3206
3284
|
AuthSessionState.setSession(undefined);
|
|
3207
3285
|
session.isActive = false;
|
|
3208
3286
|
if (session.accessTokenRefreshHandle !== undefined) {
|
|
3209
|
-
|
|
3287
|
+
_this2.scheduler.unschedule(session.accessTokenRefreshHandle);
|
|
3210
3288
|
}
|
|
3211
3289
|
return AuthManagerBrowser_await(_this2.deleteAccessToken(session.params), function () {
|
|
3212
3290
|
return AuthManagerBrowser_invokeIgnored(function () {
|
|
@@ -3233,7 +3311,10 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3233
3311
|
if (!session.isActive) {
|
|
3234
3312
|
return;
|
|
3235
3313
|
}
|
|
3236
|
-
var
|
|
3314
|
+
var secondsFromNow = function secondsFromNow(seconds) {
|
|
3315
|
+
return Date.now() + seconds * 1000;
|
|
3316
|
+
};
|
|
3317
|
+
var expires = secondsFromNow(_this3.retryAuthAfterErrorSeconds);
|
|
3237
3318
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
|
|
3238
3319
|
return AuthManagerBrowser_catch(function () {
|
|
3239
3320
|
var _getAccessToken = _this3.getAccessToken,
|
|
@@ -3248,26 +3329,33 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3248
3329
|
return AuthManagerBrowser_await(_this3.setAccessToken(session.params, jwt, setCookie), function (setTokenResult) {
|
|
3249
3330
|
return AuthManagerBrowser_invoke(function () {
|
|
3250
3331
|
if (session.authServiceWorker !== undefined) {
|
|
3251
|
-
return
|
|
3332
|
+
return AuthManagerBrowser_await(_this3.serviceWorkerUtils.sendMessage({
|
|
3252
3333
|
type: "SET_BYTESCALE_AUTH_CONFIG",
|
|
3253
3334
|
config: [{
|
|
3254
3335
|
headers: [{
|
|
3255
3336
|
key: "Authorization",
|
|
3256
3337
|
value: "Bearer ".concat(jwt)
|
|
3257
3338
|
}],
|
|
3258
|
-
expires:
|
|
3339
|
+
expires: secondsFromNow(setTokenResult.ttlSeconds),
|
|
3259
3340
|
urlPrefix: "".concat(_this3.getCdnUrl(session.params), "/").concat(session.params.accountId, "/")
|
|
3260
3341
|
}]
|
|
3261
|
-
}, session.authServiceWorker, _this3.serviceWorkerScriptFieldName))
|
|
3342
|
+
}, session.authServiceWorker, _this3.serviceWorkerScriptFieldName), function () {
|
|
3343
|
+
// Allow time for the service worker to receive and process the message. Since this is asynchronous and not
|
|
3344
|
+
// synchronized, we need to wait for a sufficient amount of time to ensure the service worker is ready to
|
|
3345
|
+
// authenticate requests, so that after 'beginAuthSession' completes, users can start making requests.
|
|
3346
|
+
return AuthManagerBrowser_awaitIgnored(new Promise(function (resolve) {
|
|
3347
|
+
return setTimeout(resolve, 100);
|
|
3348
|
+
}));
|
|
3349
|
+
});
|
|
3262
3350
|
}
|
|
3263
3351
|
}, function () {
|
|
3264
3352
|
var desiredTtl = setTokenResult.ttlSeconds - _this3.refreshBeforeExpirySeconds;
|
|
3265
|
-
|
|
3266
|
-
if (desiredTtl !==
|
|
3267
|
-
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(
|
|
3353
|
+
var actualTtl = Math.max(desiredTtl, _this3.minJwtTtlSeconds);
|
|
3354
|
+
if (desiredTtl !== actualTtl) {
|
|
3355
|
+
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(actualTtl, " seconds before refreshing."));
|
|
3268
3356
|
}
|
|
3269
|
-
|
|
3270
|
-
|
|
3357
|
+
expires = secondsFromNow(actualTtl);
|
|
3358
|
+
// Set this at the end, as it's also used to signal 'isAuthSessionReady', so must be set after configuring the Service Worker, etc.
|
|
3271
3359
|
session.accessToken = setTokenResult.accessToken;
|
|
3272
3360
|
});
|
|
3273
3361
|
});
|
|
@@ -3278,13 +3366,13 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3278
3366
|
ConsoleUtils.warn("Unable to refresh JWT access token: ".concat(e));
|
|
3279
3367
|
});
|
|
3280
3368
|
}, function (_wasThrown, _result) {
|
|
3281
|
-
session.accessTokenRefreshHandle =
|
|
3369
|
+
session.accessTokenRefreshHandle = _this3.scheduler.schedule(expires, function () {
|
|
3282
3370
|
_this3.refreshAccessToken(session).then(function () {},
|
|
3283
3371
|
// Should not occur, as this method shouldn't throw errors.
|
|
3284
3372
|
function (e) {
|
|
3285
3373
|
return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
|
|
3286
3374
|
});
|
|
3287
|
-
}
|
|
3375
|
+
});
|
|
3288
3376
|
return AuthManagerBrowser_rethrow(_wasThrown, _result);
|
|
3289
3377
|
}));
|
|
3290
3378
|
}))));
|
package/dist/node/cjs/main.js
CHANGED
|
@@ -3092,6 +3092,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3092
3092
|
value: function isAuthSessionActive() {
|
|
3093
3093
|
return false;
|
|
3094
3094
|
}
|
|
3095
|
+
}, {
|
|
3096
|
+
key: "isAuthSessionReady",
|
|
3097
|
+
value: function isAuthSessionReady() {
|
|
3098
|
+
return false;
|
|
3099
|
+
}
|
|
3095
3100
|
}]);
|
|
3096
3101
|
}();
|
|
3097
3102
|
/**
|
package/dist/node/esm/main.mjs
CHANGED
|
@@ -3087,6 +3087,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3087
3087
|
value: function isAuthSessionActive() {
|
|
3088
3088
|
return false;
|
|
3089
3089
|
}
|
|
3090
|
+
}, {
|
|
3091
|
+
key: "isAuthSessionReady",
|
|
3092
|
+
value: function isAuthSessionReady() {
|
|
3093
|
+
return false;
|
|
3094
|
+
}
|
|
3090
3095
|
}]);
|
|
3091
3096
|
}();
|
|
3092
3097
|
/**
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class Scheduler {
|
|
2
|
+
private callbacks;
|
|
3
|
+
private nextId;
|
|
4
|
+
private intervalId;
|
|
5
|
+
schedule(epoch: number, callback: () => void): number;
|
|
6
|
+
unschedule(handle: number): void;
|
|
7
|
+
private startInterval;
|
|
8
|
+
private stopInterval;
|
|
9
|
+
private checkCallbacks;
|
|
10
|
+
}
|
|
@@ -104,4 +104,8 @@ export interface AuthManagerInterface {
|
|
|
104
104
|
* Checks if an authenticated Bytescale API and Bytescale CDN session is active.
|
|
105
105
|
*/
|
|
106
106
|
isAuthSessionActive: () => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Checks if an authenticated Bytescale API and Bytescale CDN session is active and ready to authenticate HTTP requests.
|
|
109
|
+
*/
|
|
110
|
+
isAuthSessionReady: () => boolean;
|
|
107
111
|
}
|
|
@@ -9,11 +9,12 @@ declare class AuthManagerImpl implements AuthManagerInterface {
|
|
|
9
9
|
private readonly contentTypeJson;
|
|
10
10
|
private readonly contentTypeText;
|
|
11
11
|
private readonly minJwtTtlSeconds;
|
|
12
|
-
private readonly maxJwtTtlSeconds;
|
|
13
12
|
private readonly retryAuthAfterErrorSeconds;
|
|
14
13
|
private readonly refreshBeforeExpirySeconds;
|
|
14
|
+
private readonly scheduler;
|
|
15
15
|
constructor(serviceWorkerUtils: ServiceWorkerUtils<AuthSwSetConfigDto>);
|
|
16
16
|
isAuthSessionActive(): boolean;
|
|
17
|
+
isAuthSessionReady(): boolean;
|
|
17
18
|
beginAuthSession(params: BeginAuthSessionParams): Promise<void>;
|
|
18
19
|
endAuthSession(): Promise<void>;
|
|
19
20
|
private refreshAccessToken;
|
|
@@ -3,6 +3,7 @@ declare class AuthManagerImpl implements AuthManagerInterface {
|
|
|
3
3
|
beginAuthSession(_params: BeginAuthSessionParams): Promise<void>;
|
|
4
4
|
endAuthSession(): Promise<void>;
|
|
5
5
|
isAuthSessionActive(): boolean;
|
|
6
|
+
isAuthSessionReady(): boolean;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
package/dist/worker/cjs/main.js
CHANGED
|
@@ -2626,6 +2626,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2626
2626
|
value: function isAuthSessionActive() {
|
|
2627
2627
|
return false;
|
|
2628
2628
|
}
|
|
2629
|
+
}, {
|
|
2630
|
+
key: "isAuthSessionReady",
|
|
2631
|
+
value: function isAuthSessionReady() {
|
|
2632
|
+
return false;
|
|
2633
|
+
}
|
|
2629
2634
|
}]);
|
|
2630
2635
|
}();
|
|
2631
2636
|
/**
|
package/dist/worker/esm/main.mjs
CHANGED
|
@@ -2611,6 +2611,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2611
2611
|
value: function isAuthSessionActive() {
|
|
2612
2612
|
return false;
|
|
2613
2613
|
}
|
|
2614
|
+
}, {
|
|
2615
|
+
key: "isAuthSessionReady",
|
|
2616
|
+
value: function isAuthSessionReady() {
|
|
2617
|
+
return false;
|
|
2618
|
+
}
|
|
2614
2619
|
}]);
|
|
2615
2620
|
}();
|
|
2616
2621
|
/**
|