@bytescale/sdk 3.39.0 → 3.41.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 +380 -71
- package/dist/browser/esm/main.mjs +380 -71
- package/dist/types/private/ServiceWorkerUtils.d.ts +7 -2
- package/dist/types/private/model/ServiceWorkerConfig.d.ts +3 -2
- package/dist/types/private/model/ServiceWorkerInitStatus.d.ts +0 -1
- package/package.json +1 -1
package/dist/browser/cjs/main.js
CHANGED
|
@@ -2572,6 +2572,175 @@ function ServiceWorkerUtils_await(value, then, direct) {
|
|
|
2572
2572
|
}
|
|
2573
2573
|
return then ? value.then(then) : value;
|
|
2574
2574
|
}
|
|
2575
|
+
function ServiceWorkerUtils_empty() {}
|
|
2576
|
+
function ServiceWorkerUtils_settle(pact, state, value) {
|
|
2577
|
+
if (!pact.s) {
|
|
2578
|
+
if (value instanceof ServiceWorkerUtils_Pact) {
|
|
2579
|
+
if (value.s) {
|
|
2580
|
+
if (state & 1) {
|
|
2581
|
+
state = value.s;
|
|
2582
|
+
}
|
|
2583
|
+
value = value.v;
|
|
2584
|
+
} else {
|
|
2585
|
+
value.o = ServiceWorkerUtils_settle.bind(null, pact, state);
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
if (value && value.then) {
|
|
2590
|
+
value.then(ServiceWorkerUtils_settle.bind(null, pact, state), ServiceWorkerUtils_settle.bind(null, pact, 2));
|
|
2591
|
+
return;
|
|
2592
|
+
}
|
|
2593
|
+
pact.s = state;
|
|
2594
|
+
pact.v = value;
|
|
2595
|
+
var observer = pact.o;
|
|
2596
|
+
if (observer) {
|
|
2597
|
+
observer(pact);
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
var ServiceWorkerUtils_Pact = /*#__PURE__*/function () {
|
|
2602
|
+
function _Pact() {}
|
|
2603
|
+
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
2604
|
+
var result = new _Pact();
|
|
2605
|
+
var state = this.s;
|
|
2606
|
+
if (state) {
|
|
2607
|
+
var callback = state & 1 ? onFulfilled : onRejected;
|
|
2608
|
+
if (callback) {
|
|
2609
|
+
try {
|
|
2610
|
+
ServiceWorkerUtils_settle(result, 1, callback(this.v));
|
|
2611
|
+
} catch (e) {
|
|
2612
|
+
ServiceWorkerUtils_settle(result, 2, e);
|
|
2613
|
+
}
|
|
2614
|
+
return result;
|
|
2615
|
+
} else {
|
|
2616
|
+
return this;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
this.o = function (_this) {
|
|
2620
|
+
try {
|
|
2621
|
+
var value = _this.v;
|
|
2622
|
+
if (_this.s & 1) {
|
|
2623
|
+
ServiceWorkerUtils_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
2624
|
+
} else if (onRejected) {
|
|
2625
|
+
ServiceWorkerUtils_settle(result, 1, onRejected(value));
|
|
2626
|
+
} else {
|
|
2627
|
+
ServiceWorkerUtils_settle(result, 2, value);
|
|
2628
|
+
}
|
|
2629
|
+
} catch (e) {
|
|
2630
|
+
ServiceWorkerUtils_settle(result, 2, e);
|
|
2631
|
+
}
|
|
2632
|
+
};
|
|
2633
|
+
return result;
|
|
2634
|
+
};
|
|
2635
|
+
return _Pact;
|
|
2636
|
+
}();
|
|
2637
|
+
function _switch(discriminant, cases) {
|
|
2638
|
+
var dispatchIndex = -1;
|
|
2639
|
+
var awaitBody;
|
|
2640
|
+
outer: {
|
|
2641
|
+
for (var i = 0; i < cases.length; i++) {
|
|
2642
|
+
var test = cases[i][0];
|
|
2643
|
+
if (test) {
|
|
2644
|
+
var testValue = test();
|
|
2645
|
+
if (testValue && testValue.then) {
|
|
2646
|
+
break outer;
|
|
2647
|
+
}
|
|
2648
|
+
if (testValue === discriminant) {
|
|
2649
|
+
dispatchIndex = i;
|
|
2650
|
+
break;
|
|
2651
|
+
}
|
|
2652
|
+
} else {
|
|
2653
|
+
// Found the default case, set it as the pending dispatch case
|
|
2654
|
+
dispatchIndex = i;
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
if (dispatchIndex !== -1) {
|
|
2658
|
+
do {
|
|
2659
|
+
var body = cases[dispatchIndex][1];
|
|
2660
|
+
while (!body) {
|
|
2661
|
+
dispatchIndex++;
|
|
2662
|
+
body = cases[dispatchIndex][1];
|
|
2663
|
+
}
|
|
2664
|
+
var result = body();
|
|
2665
|
+
if (result && result.then) {
|
|
2666
|
+
awaitBody = true;
|
|
2667
|
+
break outer;
|
|
2668
|
+
}
|
|
2669
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
2670
|
+
dispatchIndex++;
|
|
2671
|
+
} while (fallthroughCheck && !fallthroughCheck());
|
|
2672
|
+
return result;
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
var pact = new ServiceWorkerUtils_Pact();
|
|
2676
|
+
var reject = ServiceWorkerUtils_settle.bind(null, pact, 2);
|
|
2677
|
+
(awaitBody ? result.then(_resumeAfterBody) : testValue.then(_resumeAfterTest)).then(void 0, reject);
|
|
2678
|
+
return pact;
|
|
2679
|
+
function _resumeAfterTest(value) {
|
|
2680
|
+
for (;;) {
|
|
2681
|
+
if (value === discriminant) {
|
|
2682
|
+
dispatchIndex = i;
|
|
2683
|
+
break;
|
|
2684
|
+
}
|
|
2685
|
+
if (++i === cases.length) {
|
|
2686
|
+
if (dispatchIndex !== -1) {
|
|
2687
|
+
break;
|
|
2688
|
+
} else {
|
|
2689
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
test = cases[i][0];
|
|
2694
|
+
if (test) {
|
|
2695
|
+
value = test();
|
|
2696
|
+
if (value && value.then) {
|
|
2697
|
+
value.then(_resumeAfterTest).then(void 0, reject);
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
} else {
|
|
2701
|
+
dispatchIndex = i;
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
do {
|
|
2705
|
+
var body = cases[dispatchIndex][1];
|
|
2706
|
+
while (!body) {
|
|
2707
|
+
dispatchIndex++;
|
|
2708
|
+
body = cases[dispatchIndex][1];
|
|
2709
|
+
}
|
|
2710
|
+
var result = body();
|
|
2711
|
+
if (result && result.then) {
|
|
2712
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2713
|
+
return;
|
|
2714
|
+
}
|
|
2715
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
2716
|
+
dispatchIndex++;
|
|
2717
|
+
} while (fallthroughCheck && !fallthroughCheck());
|
|
2718
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2719
|
+
}
|
|
2720
|
+
function _resumeAfterBody(result) {
|
|
2721
|
+
for (;;) {
|
|
2722
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
2723
|
+
if (!fallthroughCheck || fallthroughCheck()) {
|
|
2724
|
+
break;
|
|
2725
|
+
}
|
|
2726
|
+
dispatchIndex++;
|
|
2727
|
+
var body = cases[dispatchIndex][1];
|
|
2728
|
+
while (!body) {
|
|
2729
|
+
dispatchIndex++;
|
|
2730
|
+
body = cases[dispatchIndex][1];
|
|
2731
|
+
}
|
|
2732
|
+
result = body();
|
|
2733
|
+
if (result && result.then) {
|
|
2734
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
function ServiceWorkerUtils_continue(value, then) {
|
|
2742
|
+
return value && value.then ? value.then(then) : then(value);
|
|
2743
|
+
}
|
|
2575
2744
|
function ServiceWorkerUtils_catch(body, recover) {
|
|
2576
2745
|
try {
|
|
2577
2746
|
var result = body();
|
|
@@ -2590,16 +2759,117 @@ function ServiceWorkerUtils_invoke(body, then) {
|
|
|
2590
2759
|
}
|
|
2591
2760
|
return then(result);
|
|
2592
2761
|
}
|
|
2762
|
+
function ServiceWorkerUtils_awaitIgnored(value, direct) {
|
|
2763
|
+
if (!direct) {
|
|
2764
|
+
return value && value.then ? value.then(ServiceWorkerUtils_empty) : Promise.resolve();
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
var _iteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator";
|
|
2768
|
+
function ServiceWorkerUtils_isSettledPact(thenable) {
|
|
2769
|
+
return thenable instanceof ServiceWorkerUtils_Pact && thenable.s & 1;
|
|
2770
|
+
}
|
|
2771
|
+
function _forTo(array, body, check) {
|
|
2772
|
+
var i = -1,
|
|
2773
|
+
pact,
|
|
2774
|
+
reject;
|
|
2775
|
+
function _cycle(result) {
|
|
2776
|
+
try {
|
|
2777
|
+
while (++i < array.length && (!check || !check())) {
|
|
2778
|
+
result = body(i);
|
|
2779
|
+
if (result && result.then) {
|
|
2780
|
+
if (ServiceWorkerUtils_isSettledPact(result)) {
|
|
2781
|
+
result = result.v;
|
|
2782
|
+
} else {
|
|
2783
|
+
result.then(_cycle, reject || (reject = ServiceWorkerUtils_settle.bind(null, pact = new ServiceWorkerUtils_Pact(), 2)));
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
if (pact) {
|
|
2789
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2790
|
+
} else {
|
|
2791
|
+
pact = result;
|
|
2792
|
+
}
|
|
2793
|
+
} catch (e) {
|
|
2794
|
+
ServiceWorkerUtils_settle(pact || (pact = new ServiceWorkerUtils_Pact()), 2, e);
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
_cycle();
|
|
2798
|
+
return pact;
|
|
2799
|
+
}
|
|
2800
|
+
function _forOf(target, body, check) {
|
|
2801
|
+
if (typeof target[_iteratorSymbol] === "function") {
|
|
2802
|
+
var _cycle = function _cycle(result) {
|
|
2803
|
+
try {
|
|
2804
|
+
while (!(step = iterator.next()).done && (!check || !check())) {
|
|
2805
|
+
result = body(step.value);
|
|
2806
|
+
if (result && result.then) {
|
|
2807
|
+
if (ServiceWorkerUtils_isSettledPact(result)) {
|
|
2808
|
+
result = result.v;
|
|
2809
|
+
} else {
|
|
2810
|
+
result.then(_cycle, reject || (reject = ServiceWorkerUtils_settle.bind(null, pact = new ServiceWorkerUtils_Pact(), 2)));
|
|
2811
|
+
return;
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
if (pact) {
|
|
2816
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2817
|
+
} else {
|
|
2818
|
+
pact = result;
|
|
2819
|
+
}
|
|
2820
|
+
} catch (e) {
|
|
2821
|
+
ServiceWorkerUtils_settle(pact || (pact = new ServiceWorkerUtils_Pact()), 2, e);
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
var iterator = target[_iteratorSymbol](),
|
|
2825
|
+
step,
|
|
2826
|
+
pact,
|
|
2827
|
+
reject;
|
|
2828
|
+
_cycle();
|
|
2829
|
+
if (iterator["return"]) {
|
|
2830
|
+
var _fixup = function _fixup(value) {
|
|
2831
|
+
try {
|
|
2832
|
+
if (!step.done) {
|
|
2833
|
+
iterator["return"]();
|
|
2834
|
+
}
|
|
2835
|
+
} catch (e) {}
|
|
2836
|
+
return value;
|
|
2837
|
+
};
|
|
2838
|
+
if (pact && pact.then) {
|
|
2839
|
+
return pact.then(_fixup, function (e) {
|
|
2840
|
+
throw _fixup(e);
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
_fixup();
|
|
2844
|
+
}
|
|
2845
|
+
return pact;
|
|
2846
|
+
}
|
|
2847
|
+
// No support for Symbol.iterator
|
|
2848
|
+
if (!("length" in target)) {
|
|
2849
|
+
throw new TypeError("Object is not iterable");
|
|
2850
|
+
}
|
|
2851
|
+
// Handle live collections properly
|
|
2852
|
+
var values = [];
|
|
2853
|
+
for (var i = 0; i < target.length; i++) {
|
|
2854
|
+
values.push(target[i]);
|
|
2855
|
+
}
|
|
2856
|
+
return _forTo(values, function (i) {
|
|
2857
|
+
return body(values[i]);
|
|
2858
|
+
}, check);
|
|
2859
|
+
}
|
|
2860
|
+
function ServiceWorkerUtils_continueIgnored(value) {
|
|
2861
|
+
if (value && value.then) {
|
|
2862
|
+
return value.then(ServiceWorkerUtils_empty);
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2593
2865
|
function ServiceWorkerUtils_typeof(o) { "@babel/helpers - typeof"; return ServiceWorkerUtils_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; }, ServiceWorkerUtils_typeof(o); }
|
|
2594
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = ServiceWorkerUtils_unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
2595
|
-
function ServiceWorkerUtils_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return ServiceWorkerUtils_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return ServiceWorkerUtils_arrayLikeToArray(o, minLen); }
|
|
2596
|
-
function ServiceWorkerUtils_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
2597
2866
|
function ServiceWorkerUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2598
2867
|
function ServiceWorkerUtils_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, ServiceWorkerUtils_toPropertyKey(descriptor.key), descriptor); } }
|
|
2599
2868
|
function ServiceWorkerUtils_createClass(Constructor, protoProps, staticProps) { if (protoProps) ServiceWorkerUtils_defineProperties(Constructor.prototype, protoProps); if (staticProps) ServiceWorkerUtils_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
2600
2869
|
function ServiceWorkerUtils_toPropertyKey(t) { var i = ServiceWorkerUtils_toPrimitive(t, "string"); return "symbol" == ServiceWorkerUtils_typeof(i) ? i : i + ""; }
|
|
2601
2870
|
function ServiceWorkerUtils_toPrimitive(t, r) { if ("object" != ServiceWorkerUtils_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != ServiceWorkerUtils_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
2602
2871
|
|
|
2872
|
+
|
|
2603
2873
|
var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
2604
2874
|
function ServiceWorkerUtils() {
|
|
2605
2875
|
ServiceWorkerUtils_classCallCheck(this, ServiceWorkerUtils);
|
|
@@ -2614,10 +2884,13 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2614
2884
|
value: function sendMessage(message, config, serviceWorkerScriptFieldName) {
|
|
2615
2885
|
try {
|
|
2616
2886
|
var _this = this;
|
|
2617
|
-
return ServiceWorkerUtils_await(
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2887
|
+
return ServiceWorkerUtils_await(_this.ensureActiveServiceWorkerExists(message, config, serviceWorkerScriptFieldName), function (result) {
|
|
2888
|
+
// Message delivery is at least once. We must always assume this as there is only 1 service worker instance and
|
|
2889
|
+
// potentially multiple browser tabs with AuthManager sessions running. As such, even if we ensure exactly-once
|
|
2890
|
+
// delivery within a single tab, there will still be at-least-once delivery across all. As such, we simplfy our
|
|
2891
|
+
// code by using at-least-once delivery here too (hence the following 'postMessage' will already have been called
|
|
2892
|
+
// in the scenario where a new worker is newly installed).
|
|
2893
|
+
result.serviceWorker.postMessage(message);
|
|
2621
2894
|
return result.config;
|
|
2622
2895
|
});
|
|
2623
2896
|
} catch (e) {
|
|
@@ -2625,34 +2898,41 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2625
2898
|
}
|
|
2626
2899
|
}
|
|
2627
2900
|
}, {
|
|
2628
|
-
key: "
|
|
2629
|
-
value: function
|
|
2901
|
+
key: "ensureActiveServiceWorkerExists",
|
|
2902
|
+
value: function ensureActiveServiceWorkerExists(initMessage, config, serviceWorkerScriptFieldName) {
|
|
2630
2903
|
try {
|
|
2904
|
+
var _exit = false,
|
|
2905
|
+
_interrupt = false;
|
|
2631
2906
|
var _this2 = this;
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
}
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2907
|
+
return ServiceWorkerUtils_await(ServiceWorkerUtils_continue(_switch(config.type, [[function () {
|
|
2908
|
+
return "Uninitialized";
|
|
2909
|
+
}, function () {
|
|
2910
|
+
{
|
|
2911
|
+
return ServiceWorkerUtils_await(_this2.unregisterOnHardReload(), function () {
|
|
2912
|
+
_interrupt = true;
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
}], [function () {
|
|
2916
|
+
return "Initialized";
|
|
2917
|
+
}, function () {
|
|
2918
|
+
{
|
|
2919
|
+
return ServiceWorkerUtils_await(_this2.getActiveServiceWorker(config.serviceWorkerScope), function (serviceWorker) {
|
|
2920
|
+
if (serviceWorker !== undefined) {
|
|
2921
|
+
var _serviceWorker$config = {
|
|
2922
|
+
serviceWorker: serviceWorker,
|
|
2923
|
+
config: config
|
|
2924
|
+
};
|
|
2925
|
+
_exit = true;
|
|
2926
|
+
return _serviceWorker$config;
|
|
2927
|
+
}
|
|
2928
|
+
_interrupt = true;
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
}], [void 0, function () {
|
|
2932
|
+
assertUnreachable(config);
|
|
2933
|
+
}, ServiceWorkerUtils_empty]]), function (_result) {
|
|
2934
|
+
return _exit ? _result : ServiceWorkerUtils_await(_this2.registerServiceWorker(config.serviceWorkerScript, initMessage, serviceWorkerScriptFieldName));
|
|
2935
|
+
}));
|
|
2656
2936
|
} catch (e) {
|
|
2657
2937
|
return Promise.reject(e);
|
|
2658
2938
|
}
|
|
@@ -2666,20 +2946,25 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2666
2946
|
*/
|
|
2667
2947
|
}, {
|
|
2668
2948
|
key: "registerServiceWorker",
|
|
2669
|
-
value: function registerServiceWorker(serviceWorkerScript,
|
|
2949
|
+
value: function registerServiceWorker(serviceWorkerScript, initMessage, serviceWorkerScriptFieldName) {
|
|
2670
2950
|
try {
|
|
2671
|
-
var
|
|
2951
|
+
var _this3 = this;
|
|
2952
|
+
if (!serviceWorkerScript.startsWith("/")) {
|
|
2953
|
+
throw new Error("The '".concat(serviceWorkerScriptFieldName, "' field must start with a '/' and reference a script at the root of your website."));
|
|
2954
|
+
}
|
|
2955
|
+
var forwardSlashCount = serviceWorkerScript.split("/").length - 1;
|
|
2956
|
+
if (forwardSlashCount > 1) {
|
|
2957
|
+
ConsoleUtils.warn("The '".concat(serviceWorkerScriptFieldName, "' field should be a root script (e.g. '/script.js'). The Bytescale SDK can only authorize requests originating from webpages that are at the same level as the script or below."));
|
|
2958
|
+
}
|
|
2672
2959
|
return ServiceWorkerUtils_await(ServiceWorkerUtils_catch(function () {
|
|
2673
2960
|
return ServiceWorkerUtils_await(navigator.serviceWorker.register(serviceWorkerScript), function (registration) {
|
|
2674
|
-
return ServiceWorkerUtils_await(
|
|
2675
|
-
var serviceWorker = _ref.serviceWorker,
|
|
2676
|
-
messageSent = _ref.messageSent;
|
|
2961
|
+
return ServiceWorkerUtils_await(_this3.waitForActiveServiceWorker(registration, initMessage), function (_this3$waitForActiveS) {
|
|
2677
2962
|
return {
|
|
2678
|
-
serviceWorker:
|
|
2679
|
-
messageSent: messageSent,
|
|
2963
|
+
serviceWorker: _this3$waitForActiveS,
|
|
2680
2964
|
config: {
|
|
2681
2965
|
serviceWorkerScript: serviceWorkerScript,
|
|
2682
|
-
serviceWorkerScope: registration.scope
|
|
2966
|
+
serviceWorkerScope: registration.scope,
|
|
2967
|
+
type: "Initialized"
|
|
2683
2968
|
}
|
|
2684
2969
|
};
|
|
2685
2970
|
});
|
|
@@ -2693,9 +2978,9 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2693
2978
|
}
|
|
2694
2979
|
}, {
|
|
2695
2980
|
key: "waitForActiveServiceWorker",
|
|
2696
|
-
value: function waitForActiveServiceWorker(registration,
|
|
2981
|
+
value: function waitForActiveServiceWorker(registration, initMessage) {
|
|
2697
2982
|
try {
|
|
2698
|
-
var
|
|
2983
|
+
var _exit2 = false;
|
|
2699
2984
|
// We must check the 'installing' state before the 'active' state (see comment below).
|
|
2700
2985
|
// The state will be 'installing' when the service worker is installed for the first time, or if there have been
|
|
2701
2986
|
// code changes to the service worker, else the state will be 'active'.
|
|
@@ -2707,31 +2992,29 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2707
2992
|
var sw = e.target;
|
|
2708
2993
|
if (sw.state === "activated") {
|
|
2709
2994
|
installing.removeEventListener("statechange", stateChangeHandler);
|
|
2710
|
-
resolve(
|
|
2711
|
-
messageSent: true,
|
|
2712
|
-
serviceWorker: sw
|
|
2713
|
-
});
|
|
2995
|
+
resolve(sw);
|
|
2714
2996
|
}
|
|
2715
2997
|
};
|
|
2716
2998
|
installing.addEventListener("statechange", stateChangeHandler);
|
|
2717
2999
|
});
|
|
2718
|
-
|
|
3000
|
+
// We send the message during the INSTALL phase instead of ACTIVE phase to ensure that when replacing an
|
|
3001
|
+
// existing Service Worker instance, the new instance will be ready to run (with config received from this
|
|
3002
|
+
// 'postMessage' call) prior to it being activated, so that it can immediately start attaching auth headers to
|
|
3003
|
+
// intercepted 'fetch' requests.
|
|
3004
|
+
installing.postMessage(initMessage);
|
|
2719
3005
|
return ServiceWorkerUtils_await(waitForActive, function (_await$waitForActive) {
|
|
2720
|
-
|
|
3006
|
+
_exit2 = true;
|
|
2721
3007
|
return _await$waitForActive;
|
|
2722
3008
|
});
|
|
2723
3009
|
}
|
|
2724
|
-
}, function (
|
|
2725
|
-
if (
|
|
3010
|
+
}, function (_result2) {
|
|
3011
|
+
if (_exit2) return _result2;
|
|
2726
3012
|
// We must check the 'installing' state before the 'active' state, because if we've just installed a new service
|
|
2727
3013
|
// worker, then the new service worker will be in the 'installing' slot whereas the old service worker will be in
|
|
2728
3014
|
// the 'active' slot. So, if we checked this first, we would always return the old service worker, and therefore the
|
|
2729
3015
|
// new service worker would never be initialized.
|
|
2730
3016
|
if (registration.active !== null) {
|
|
2731
|
-
return
|
|
2732
|
-
serviceWorker: registration.active,
|
|
2733
|
-
messageSent: false
|
|
2734
|
-
};
|
|
3017
|
+
return registration.active;
|
|
2735
3018
|
}
|
|
2736
3019
|
// We expect the service worker to use 'skipWaiting', so we don't expect 'waiting' service workers.
|
|
2737
3020
|
throw new Error("Service worker was neither 'installing' or 'active'.");
|
|
@@ -2743,23 +3026,49 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2743
3026
|
}, {
|
|
2744
3027
|
key: "getActiveServiceWorker",
|
|
2745
3028
|
value: function getActiveServiceWorker(serviceWorkerScope) {
|
|
3029
|
+
try {
|
|
3030
|
+
var _this4 = this;
|
|
3031
|
+
var _a, _b;
|
|
3032
|
+
return ServiceWorkerUtils_await(_this4.getActiveRegistrations(), function (_this4$getActiveRegis) {
|
|
3033
|
+
var registrations = _this4$getActiveRegis.filter(function (x) {
|
|
3034
|
+
return x.scope === serviceWorkerScope;
|
|
3035
|
+
});
|
|
3036
|
+
return (_b = (_a = registrations[0]) === null || _a === void 0 ? void 0 : _a.active) !== null && _b !== void 0 ? _b : undefined;
|
|
3037
|
+
});
|
|
3038
|
+
} catch (e) {
|
|
3039
|
+
return Promise.reject(e);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
/**
|
|
3043
|
+
* Existing active Service Workers will not receive 'fetch' events in sessions that start with a hard reload, so
|
|
3044
|
+
* we must unregister them and register a new one. (See: https://github.com/mswjs/msw/issues/98#issuecomment-612118211)
|
|
3045
|
+
*/
|
|
3046
|
+
}, {
|
|
3047
|
+
key: "unregisterOnHardReload",
|
|
3048
|
+
value: function unregisterOnHardReload() {
|
|
3049
|
+
try {
|
|
3050
|
+
var _this5 = this;
|
|
3051
|
+
var isHardReload = navigator.serviceWorker.controller === null;
|
|
3052
|
+
if (!isHardReload) {
|
|
3053
|
+
return ServiceWorkerUtils_await();
|
|
3054
|
+
}
|
|
3055
|
+
return ServiceWorkerUtils_await(_this5.getActiveRegistrations(), function (registrations) {
|
|
3056
|
+
return ServiceWorkerUtils_continueIgnored(_forOf(registrations, function (registration) {
|
|
3057
|
+
return ServiceWorkerUtils_awaitIgnored(registration.unregister());
|
|
3058
|
+
}));
|
|
3059
|
+
});
|
|
3060
|
+
} catch (e) {
|
|
3061
|
+
return Promise.reject(e);
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
}, {
|
|
3065
|
+
key: "getActiveRegistrations",
|
|
3066
|
+
value: function getActiveRegistrations() {
|
|
2746
3067
|
try {
|
|
2747
3068
|
return ServiceWorkerUtils_await(navigator.serviceWorker.getRegistrations(), function (registrations) {
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2752
|
-
var registration = _step.value;
|
|
2753
|
-
if (registration.active !== null && registration.scope === serviceWorkerScope) {
|
|
2754
|
-
return registration.active;
|
|
2755
|
-
}
|
|
2756
|
-
}
|
|
2757
|
-
} catch (err) {
|
|
2758
|
-
_iterator.e(err);
|
|
2759
|
-
} finally {
|
|
2760
|
-
_iterator.f();
|
|
2761
|
-
}
|
|
2762
|
-
return undefined;
|
|
3069
|
+
return registrations.filter(function (registration) {
|
|
3070
|
+
return registration.active !== null;
|
|
3071
|
+
});
|
|
2763
3072
|
});
|
|
2764
3073
|
} catch (e) {
|
|
2765
3074
|
return Promise.reject(e);
|
|
@@ -2886,7 +3195,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2886
3195
|
isActive: true,
|
|
2887
3196
|
authServiceWorker: params.serviceWorkerScript !== undefined && _this.serviceWorkerUtils.canUseServiceWorkers() ? {
|
|
2888
3197
|
serviceWorkerScript: params.serviceWorkerScript,
|
|
2889
|
-
|
|
3198
|
+
type: "Uninitialized"
|
|
2890
3199
|
} : undefined
|
|
2891
3200
|
};
|
|
2892
3201
|
AuthSessionState.setSession(newSession);
|
|
@@ -2557,6 +2557,175 @@ function ServiceWorkerUtils_await(value, then, direct) {
|
|
|
2557
2557
|
}
|
|
2558
2558
|
return then ? value.then(then) : value;
|
|
2559
2559
|
}
|
|
2560
|
+
function ServiceWorkerUtils_empty() {}
|
|
2561
|
+
function ServiceWorkerUtils_settle(pact, state, value) {
|
|
2562
|
+
if (!pact.s) {
|
|
2563
|
+
if (value instanceof ServiceWorkerUtils_Pact) {
|
|
2564
|
+
if (value.s) {
|
|
2565
|
+
if (state & 1) {
|
|
2566
|
+
state = value.s;
|
|
2567
|
+
}
|
|
2568
|
+
value = value.v;
|
|
2569
|
+
} else {
|
|
2570
|
+
value.o = ServiceWorkerUtils_settle.bind(null, pact, state);
|
|
2571
|
+
return;
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
if (value && value.then) {
|
|
2575
|
+
value.then(ServiceWorkerUtils_settle.bind(null, pact, state), ServiceWorkerUtils_settle.bind(null, pact, 2));
|
|
2576
|
+
return;
|
|
2577
|
+
}
|
|
2578
|
+
pact.s = state;
|
|
2579
|
+
pact.v = value;
|
|
2580
|
+
var observer = pact.o;
|
|
2581
|
+
if (observer) {
|
|
2582
|
+
observer(pact);
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
var ServiceWorkerUtils_Pact = /*#__PURE__*/function () {
|
|
2587
|
+
function _Pact() {}
|
|
2588
|
+
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
2589
|
+
var result = new _Pact();
|
|
2590
|
+
var state = this.s;
|
|
2591
|
+
if (state) {
|
|
2592
|
+
var callback = state & 1 ? onFulfilled : onRejected;
|
|
2593
|
+
if (callback) {
|
|
2594
|
+
try {
|
|
2595
|
+
ServiceWorkerUtils_settle(result, 1, callback(this.v));
|
|
2596
|
+
} catch (e) {
|
|
2597
|
+
ServiceWorkerUtils_settle(result, 2, e);
|
|
2598
|
+
}
|
|
2599
|
+
return result;
|
|
2600
|
+
} else {
|
|
2601
|
+
return this;
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
this.o = function (_this) {
|
|
2605
|
+
try {
|
|
2606
|
+
var value = _this.v;
|
|
2607
|
+
if (_this.s & 1) {
|
|
2608
|
+
ServiceWorkerUtils_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
2609
|
+
} else if (onRejected) {
|
|
2610
|
+
ServiceWorkerUtils_settle(result, 1, onRejected(value));
|
|
2611
|
+
} else {
|
|
2612
|
+
ServiceWorkerUtils_settle(result, 2, value);
|
|
2613
|
+
}
|
|
2614
|
+
} catch (e) {
|
|
2615
|
+
ServiceWorkerUtils_settle(result, 2, e);
|
|
2616
|
+
}
|
|
2617
|
+
};
|
|
2618
|
+
return result;
|
|
2619
|
+
};
|
|
2620
|
+
return _Pact;
|
|
2621
|
+
}();
|
|
2622
|
+
function _switch(discriminant, cases) {
|
|
2623
|
+
var dispatchIndex = -1;
|
|
2624
|
+
var awaitBody;
|
|
2625
|
+
outer: {
|
|
2626
|
+
for (var i = 0; i < cases.length; i++) {
|
|
2627
|
+
var test = cases[i][0];
|
|
2628
|
+
if (test) {
|
|
2629
|
+
var testValue = test();
|
|
2630
|
+
if (testValue && testValue.then) {
|
|
2631
|
+
break outer;
|
|
2632
|
+
}
|
|
2633
|
+
if (testValue === discriminant) {
|
|
2634
|
+
dispatchIndex = i;
|
|
2635
|
+
break;
|
|
2636
|
+
}
|
|
2637
|
+
} else {
|
|
2638
|
+
// Found the default case, set it as the pending dispatch case
|
|
2639
|
+
dispatchIndex = i;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
if (dispatchIndex !== -1) {
|
|
2643
|
+
do {
|
|
2644
|
+
var body = cases[dispatchIndex][1];
|
|
2645
|
+
while (!body) {
|
|
2646
|
+
dispatchIndex++;
|
|
2647
|
+
body = cases[dispatchIndex][1];
|
|
2648
|
+
}
|
|
2649
|
+
var result = body();
|
|
2650
|
+
if (result && result.then) {
|
|
2651
|
+
awaitBody = true;
|
|
2652
|
+
break outer;
|
|
2653
|
+
}
|
|
2654
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
2655
|
+
dispatchIndex++;
|
|
2656
|
+
} while (fallthroughCheck && !fallthroughCheck());
|
|
2657
|
+
return result;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
var pact = new ServiceWorkerUtils_Pact();
|
|
2661
|
+
var reject = ServiceWorkerUtils_settle.bind(null, pact, 2);
|
|
2662
|
+
(awaitBody ? result.then(_resumeAfterBody) : testValue.then(_resumeAfterTest)).then(void 0, reject);
|
|
2663
|
+
return pact;
|
|
2664
|
+
function _resumeAfterTest(value) {
|
|
2665
|
+
for (;;) {
|
|
2666
|
+
if (value === discriminant) {
|
|
2667
|
+
dispatchIndex = i;
|
|
2668
|
+
break;
|
|
2669
|
+
}
|
|
2670
|
+
if (++i === cases.length) {
|
|
2671
|
+
if (dispatchIndex !== -1) {
|
|
2672
|
+
break;
|
|
2673
|
+
} else {
|
|
2674
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2675
|
+
return;
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
test = cases[i][0];
|
|
2679
|
+
if (test) {
|
|
2680
|
+
value = test();
|
|
2681
|
+
if (value && value.then) {
|
|
2682
|
+
value.then(_resumeAfterTest).then(void 0, reject);
|
|
2683
|
+
return;
|
|
2684
|
+
}
|
|
2685
|
+
} else {
|
|
2686
|
+
dispatchIndex = i;
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
do {
|
|
2690
|
+
var body = cases[dispatchIndex][1];
|
|
2691
|
+
while (!body) {
|
|
2692
|
+
dispatchIndex++;
|
|
2693
|
+
body = cases[dispatchIndex][1];
|
|
2694
|
+
}
|
|
2695
|
+
var result = body();
|
|
2696
|
+
if (result && result.then) {
|
|
2697
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
2701
|
+
dispatchIndex++;
|
|
2702
|
+
} while (fallthroughCheck && !fallthroughCheck());
|
|
2703
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2704
|
+
}
|
|
2705
|
+
function _resumeAfterBody(result) {
|
|
2706
|
+
for (;;) {
|
|
2707
|
+
var fallthroughCheck = cases[dispatchIndex][2];
|
|
2708
|
+
if (!fallthroughCheck || fallthroughCheck()) {
|
|
2709
|
+
break;
|
|
2710
|
+
}
|
|
2711
|
+
dispatchIndex++;
|
|
2712
|
+
var body = cases[dispatchIndex][1];
|
|
2713
|
+
while (!body) {
|
|
2714
|
+
dispatchIndex++;
|
|
2715
|
+
body = cases[dispatchIndex][1];
|
|
2716
|
+
}
|
|
2717
|
+
result = body();
|
|
2718
|
+
if (result && result.then) {
|
|
2719
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2720
|
+
return;
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
function ServiceWorkerUtils_continue(value, then) {
|
|
2727
|
+
return value && value.then ? value.then(then) : then(value);
|
|
2728
|
+
}
|
|
2560
2729
|
function ServiceWorkerUtils_catch(body, recover) {
|
|
2561
2730
|
try {
|
|
2562
2731
|
var result = body();
|
|
@@ -2575,16 +2744,117 @@ function ServiceWorkerUtils_invoke(body, then) {
|
|
|
2575
2744
|
}
|
|
2576
2745
|
return then(result);
|
|
2577
2746
|
}
|
|
2747
|
+
function ServiceWorkerUtils_awaitIgnored(value, direct) {
|
|
2748
|
+
if (!direct) {
|
|
2749
|
+
return value && value.then ? value.then(ServiceWorkerUtils_empty) : Promise.resolve();
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
var _iteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator";
|
|
2753
|
+
function ServiceWorkerUtils_isSettledPact(thenable) {
|
|
2754
|
+
return thenable instanceof ServiceWorkerUtils_Pact && thenable.s & 1;
|
|
2755
|
+
}
|
|
2756
|
+
function _forTo(array, body, check) {
|
|
2757
|
+
var i = -1,
|
|
2758
|
+
pact,
|
|
2759
|
+
reject;
|
|
2760
|
+
function _cycle(result) {
|
|
2761
|
+
try {
|
|
2762
|
+
while (++i < array.length && (!check || !check())) {
|
|
2763
|
+
result = body(i);
|
|
2764
|
+
if (result && result.then) {
|
|
2765
|
+
if (ServiceWorkerUtils_isSettledPact(result)) {
|
|
2766
|
+
result = result.v;
|
|
2767
|
+
} else {
|
|
2768
|
+
result.then(_cycle, reject || (reject = ServiceWorkerUtils_settle.bind(null, pact = new ServiceWorkerUtils_Pact(), 2)));
|
|
2769
|
+
return;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
if (pact) {
|
|
2774
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2775
|
+
} else {
|
|
2776
|
+
pact = result;
|
|
2777
|
+
}
|
|
2778
|
+
} catch (e) {
|
|
2779
|
+
ServiceWorkerUtils_settle(pact || (pact = new ServiceWorkerUtils_Pact()), 2, e);
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
_cycle();
|
|
2783
|
+
return pact;
|
|
2784
|
+
}
|
|
2785
|
+
function _forOf(target, body, check) {
|
|
2786
|
+
if (typeof target[_iteratorSymbol] === "function") {
|
|
2787
|
+
var _cycle = function _cycle(result) {
|
|
2788
|
+
try {
|
|
2789
|
+
while (!(step = iterator.next()).done && (!check || !check())) {
|
|
2790
|
+
result = body(step.value);
|
|
2791
|
+
if (result && result.then) {
|
|
2792
|
+
if (ServiceWorkerUtils_isSettledPact(result)) {
|
|
2793
|
+
result = result.v;
|
|
2794
|
+
} else {
|
|
2795
|
+
result.then(_cycle, reject || (reject = ServiceWorkerUtils_settle.bind(null, pact = new ServiceWorkerUtils_Pact(), 2)));
|
|
2796
|
+
return;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
if (pact) {
|
|
2801
|
+
ServiceWorkerUtils_settle(pact, 1, result);
|
|
2802
|
+
} else {
|
|
2803
|
+
pact = result;
|
|
2804
|
+
}
|
|
2805
|
+
} catch (e) {
|
|
2806
|
+
ServiceWorkerUtils_settle(pact || (pact = new ServiceWorkerUtils_Pact()), 2, e);
|
|
2807
|
+
}
|
|
2808
|
+
};
|
|
2809
|
+
var iterator = target[_iteratorSymbol](),
|
|
2810
|
+
step,
|
|
2811
|
+
pact,
|
|
2812
|
+
reject;
|
|
2813
|
+
_cycle();
|
|
2814
|
+
if (iterator["return"]) {
|
|
2815
|
+
var _fixup = function _fixup(value) {
|
|
2816
|
+
try {
|
|
2817
|
+
if (!step.done) {
|
|
2818
|
+
iterator["return"]();
|
|
2819
|
+
}
|
|
2820
|
+
} catch (e) {}
|
|
2821
|
+
return value;
|
|
2822
|
+
};
|
|
2823
|
+
if (pact && pact.then) {
|
|
2824
|
+
return pact.then(_fixup, function (e) {
|
|
2825
|
+
throw _fixup(e);
|
|
2826
|
+
});
|
|
2827
|
+
}
|
|
2828
|
+
_fixup();
|
|
2829
|
+
}
|
|
2830
|
+
return pact;
|
|
2831
|
+
}
|
|
2832
|
+
// No support for Symbol.iterator
|
|
2833
|
+
if (!("length" in target)) {
|
|
2834
|
+
throw new TypeError("Object is not iterable");
|
|
2835
|
+
}
|
|
2836
|
+
// Handle live collections properly
|
|
2837
|
+
var values = [];
|
|
2838
|
+
for (var i = 0; i < target.length; i++) {
|
|
2839
|
+
values.push(target[i]);
|
|
2840
|
+
}
|
|
2841
|
+
return _forTo(values, function (i) {
|
|
2842
|
+
return body(values[i]);
|
|
2843
|
+
}, check);
|
|
2844
|
+
}
|
|
2845
|
+
function ServiceWorkerUtils_continueIgnored(value) {
|
|
2846
|
+
if (value && value.then) {
|
|
2847
|
+
return value.then(ServiceWorkerUtils_empty);
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2578
2850
|
function ServiceWorkerUtils_typeof(o) { "@babel/helpers - typeof"; return ServiceWorkerUtils_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; }, ServiceWorkerUtils_typeof(o); }
|
|
2579
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = ServiceWorkerUtils_unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
2580
|
-
function ServiceWorkerUtils_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return ServiceWorkerUtils_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return ServiceWorkerUtils_arrayLikeToArray(o, minLen); }
|
|
2581
|
-
function ServiceWorkerUtils_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
2582
2851
|
function ServiceWorkerUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2583
2852
|
function ServiceWorkerUtils_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, ServiceWorkerUtils_toPropertyKey(descriptor.key), descriptor); } }
|
|
2584
2853
|
function ServiceWorkerUtils_createClass(Constructor, protoProps, staticProps) { if (protoProps) ServiceWorkerUtils_defineProperties(Constructor.prototype, protoProps); if (staticProps) ServiceWorkerUtils_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
2585
2854
|
function ServiceWorkerUtils_toPropertyKey(t) { var i = ServiceWorkerUtils_toPrimitive(t, "string"); return "symbol" == ServiceWorkerUtils_typeof(i) ? i : i + ""; }
|
|
2586
2855
|
function ServiceWorkerUtils_toPrimitive(t, r) { if ("object" != ServiceWorkerUtils_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != ServiceWorkerUtils_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
2587
2856
|
|
|
2857
|
+
|
|
2588
2858
|
var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
2589
2859
|
function ServiceWorkerUtils() {
|
|
2590
2860
|
ServiceWorkerUtils_classCallCheck(this, ServiceWorkerUtils);
|
|
@@ -2599,10 +2869,13 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2599
2869
|
value: function sendMessage(message, config, serviceWorkerScriptFieldName) {
|
|
2600
2870
|
try {
|
|
2601
2871
|
var _this = this;
|
|
2602
|
-
return ServiceWorkerUtils_await(
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2872
|
+
return ServiceWorkerUtils_await(_this.ensureActiveServiceWorkerExists(message, config, serviceWorkerScriptFieldName), function (result) {
|
|
2873
|
+
// Message delivery is at least once. We must always assume this as there is only 1 service worker instance and
|
|
2874
|
+
// potentially multiple browser tabs with AuthManager sessions running. As such, even if we ensure exactly-once
|
|
2875
|
+
// delivery within a single tab, there will still be at-least-once delivery across all. As such, we simplfy our
|
|
2876
|
+
// code by using at-least-once delivery here too (hence the following 'postMessage' will already have been called
|
|
2877
|
+
// in the scenario where a new worker is newly installed).
|
|
2878
|
+
result.serviceWorker.postMessage(message);
|
|
2606
2879
|
return result.config;
|
|
2607
2880
|
});
|
|
2608
2881
|
} catch (e) {
|
|
@@ -2610,34 +2883,41 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2610
2883
|
}
|
|
2611
2884
|
}
|
|
2612
2885
|
}, {
|
|
2613
|
-
key: "
|
|
2614
|
-
value: function
|
|
2886
|
+
key: "ensureActiveServiceWorkerExists",
|
|
2887
|
+
value: function ensureActiveServiceWorkerExists(initMessage, config, serviceWorkerScriptFieldName) {
|
|
2615
2888
|
try {
|
|
2889
|
+
var _exit = false,
|
|
2890
|
+
_interrupt = false;
|
|
2616
2891
|
var _this2 = this;
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
}
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2892
|
+
return ServiceWorkerUtils_await(ServiceWorkerUtils_continue(_switch(config.type, [[function () {
|
|
2893
|
+
return "Uninitialized";
|
|
2894
|
+
}, function () {
|
|
2895
|
+
{
|
|
2896
|
+
return ServiceWorkerUtils_await(_this2.unregisterOnHardReload(), function () {
|
|
2897
|
+
_interrupt = true;
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
}], [function () {
|
|
2901
|
+
return "Initialized";
|
|
2902
|
+
}, function () {
|
|
2903
|
+
{
|
|
2904
|
+
return ServiceWorkerUtils_await(_this2.getActiveServiceWorker(config.serviceWorkerScope), function (serviceWorker) {
|
|
2905
|
+
if (serviceWorker !== undefined) {
|
|
2906
|
+
var _serviceWorker$config = {
|
|
2907
|
+
serviceWorker: serviceWorker,
|
|
2908
|
+
config: config
|
|
2909
|
+
};
|
|
2910
|
+
_exit = true;
|
|
2911
|
+
return _serviceWorker$config;
|
|
2912
|
+
}
|
|
2913
|
+
_interrupt = true;
|
|
2914
|
+
});
|
|
2915
|
+
}
|
|
2916
|
+
}], [void 0, function () {
|
|
2917
|
+
assertUnreachable(config);
|
|
2918
|
+
}, ServiceWorkerUtils_empty]]), function (_result) {
|
|
2919
|
+
return _exit ? _result : ServiceWorkerUtils_await(_this2.registerServiceWorker(config.serviceWorkerScript, initMessage, serviceWorkerScriptFieldName));
|
|
2920
|
+
}));
|
|
2641
2921
|
} catch (e) {
|
|
2642
2922
|
return Promise.reject(e);
|
|
2643
2923
|
}
|
|
@@ -2651,20 +2931,25 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2651
2931
|
*/
|
|
2652
2932
|
}, {
|
|
2653
2933
|
key: "registerServiceWorker",
|
|
2654
|
-
value: function registerServiceWorker(serviceWorkerScript,
|
|
2934
|
+
value: function registerServiceWorker(serviceWorkerScript, initMessage, serviceWorkerScriptFieldName) {
|
|
2655
2935
|
try {
|
|
2656
|
-
var
|
|
2936
|
+
var _this3 = this;
|
|
2937
|
+
if (!serviceWorkerScript.startsWith("/")) {
|
|
2938
|
+
throw new Error("The '".concat(serviceWorkerScriptFieldName, "' field must start with a '/' and reference a script at the root of your website."));
|
|
2939
|
+
}
|
|
2940
|
+
var forwardSlashCount = serviceWorkerScript.split("/").length - 1;
|
|
2941
|
+
if (forwardSlashCount > 1) {
|
|
2942
|
+
ConsoleUtils.warn("The '".concat(serviceWorkerScriptFieldName, "' field should be a root script (e.g. '/script.js'). The Bytescale SDK can only authorize requests originating from webpages that are at the same level as the script or below."));
|
|
2943
|
+
}
|
|
2657
2944
|
return ServiceWorkerUtils_await(ServiceWorkerUtils_catch(function () {
|
|
2658
2945
|
return ServiceWorkerUtils_await(navigator.serviceWorker.register(serviceWorkerScript), function (registration) {
|
|
2659
|
-
return ServiceWorkerUtils_await(
|
|
2660
|
-
var serviceWorker = _ref.serviceWorker,
|
|
2661
|
-
messageSent = _ref.messageSent;
|
|
2946
|
+
return ServiceWorkerUtils_await(_this3.waitForActiveServiceWorker(registration, initMessage), function (_this3$waitForActiveS) {
|
|
2662
2947
|
return {
|
|
2663
|
-
serviceWorker:
|
|
2664
|
-
messageSent: messageSent,
|
|
2948
|
+
serviceWorker: _this3$waitForActiveS,
|
|
2665
2949
|
config: {
|
|
2666
2950
|
serviceWorkerScript: serviceWorkerScript,
|
|
2667
|
-
serviceWorkerScope: registration.scope
|
|
2951
|
+
serviceWorkerScope: registration.scope,
|
|
2952
|
+
type: "Initialized"
|
|
2668
2953
|
}
|
|
2669
2954
|
};
|
|
2670
2955
|
});
|
|
@@ -2678,9 +2963,9 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2678
2963
|
}
|
|
2679
2964
|
}, {
|
|
2680
2965
|
key: "waitForActiveServiceWorker",
|
|
2681
|
-
value: function waitForActiveServiceWorker(registration,
|
|
2966
|
+
value: function waitForActiveServiceWorker(registration, initMessage) {
|
|
2682
2967
|
try {
|
|
2683
|
-
var
|
|
2968
|
+
var _exit2 = false;
|
|
2684
2969
|
// We must check the 'installing' state before the 'active' state (see comment below).
|
|
2685
2970
|
// The state will be 'installing' when the service worker is installed for the first time, or if there have been
|
|
2686
2971
|
// code changes to the service worker, else the state will be 'active'.
|
|
@@ -2692,31 +2977,29 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2692
2977
|
var sw = e.target;
|
|
2693
2978
|
if (sw.state === "activated") {
|
|
2694
2979
|
installing.removeEventListener("statechange", stateChangeHandler);
|
|
2695
|
-
resolve(
|
|
2696
|
-
messageSent: true,
|
|
2697
|
-
serviceWorker: sw
|
|
2698
|
-
});
|
|
2980
|
+
resolve(sw);
|
|
2699
2981
|
}
|
|
2700
2982
|
};
|
|
2701
2983
|
installing.addEventListener("statechange", stateChangeHandler);
|
|
2702
2984
|
});
|
|
2703
|
-
|
|
2985
|
+
// We send the message during the INSTALL phase instead of ACTIVE phase to ensure that when replacing an
|
|
2986
|
+
// existing Service Worker instance, the new instance will be ready to run (with config received from this
|
|
2987
|
+
// 'postMessage' call) prior to it being activated, so that it can immediately start attaching auth headers to
|
|
2988
|
+
// intercepted 'fetch' requests.
|
|
2989
|
+
installing.postMessage(initMessage);
|
|
2704
2990
|
return ServiceWorkerUtils_await(waitForActive, function (_await$waitForActive) {
|
|
2705
|
-
|
|
2991
|
+
_exit2 = true;
|
|
2706
2992
|
return _await$waitForActive;
|
|
2707
2993
|
});
|
|
2708
2994
|
}
|
|
2709
|
-
}, function (
|
|
2710
|
-
if (
|
|
2995
|
+
}, function (_result2) {
|
|
2996
|
+
if (_exit2) return _result2;
|
|
2711
2997
|
// We must check the 'installing' state before the 'active' state, because if we've just installed a new service
|
|
2712
2998
|
// worker, then the new service worker will be in the 'installing' slot whereas the old service worker will be in
|
|
2713
2999
|
// the 'active' slot. So, if we checked this first, we would always return the old service worker, and therefore the
|
|
2714
3000
|
// new service worker would never be initialized.
|
|
2715
3001
|
if (registration.active !== null) {
|
|
2716
|
-
return
|
|
2717
|
-
serviceWorker: registration.active,
|
|
2718
|
-
messageSent: false
|
|
2719
|
-
};
|
|
3002
|
+
return registration.active;
|
|
2720
3003
|
}
|
|
2721
3004
|
// We expect the service worker to use 'skipWaiting', so we don't expect 'waiting' service workers.
|
|
2722
3005
|
throw new Error("Service worker was neither 'installing' or 'active'.");
|
|
@@ -2728,23 +3011,49 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
|
|
|
2728
3011
|
}, {
|
|
2729
3012
|
key: "getActiveServiceWorker",
|
|
2730
3013
|
value: function getActiveServiceWorker(serviceWorkerScope) {
|
|
3014
|
+
try {
|
|
3015
|
+
var _this4 = this;
|
|
3016
|
+
var _a, _b;
|
|
3017
|
+
return ServiceWorkerUtils_await(_this4.getActiveRegistrations(), function (_this4$getActiveRegis) {
|
|
3018
|
+
var registrations = _this4$getActiveRegis.filter(function (x) {
|
|
3019
|
+
return x.scope === serviceWorkerScope;
|
|
3020
|
+
});
|
|
3021
|
+
return (_b = (_a = registrations[0]) === null || _a === void 0 ? void 0 : _a.active) !== null && _b !== void 0 ? _b : undefined;
|
|
3022
|
+
});
|
|
3023
|
+
} catch (e) {
|
|
3024
|
+
return Promise.reject(e);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
/**
|
|
3028
|
+
* Existing active Service Workers will not receive 'fetch' events in sessions that start with a hard reload, so
|
|
3029
|
+
* we must unregister them and register a new one. (See: https://github.com/mswjs/msw/issues/98#issuecomment-612118211)
|
|
3030
|
+
*/
|
|
3031
|
+
}, {
|
|
3032
|
+
key: "unregisterOnHardReload",
|
|
3033
|
+
value: function unregisterOnHardReload() {
|
|
3034
|
+
try {
|
|
3035
|
+
var _this5 = this;
|
|
3036
|
+
var isHardReload = navigator.serviceWorker.controller === null;
|
|
3037
|
+
if (!isHardReload) {
|
|
3038
|
+
return ServiceWorkerUtils_await();
|
|
3039
|
+
}
|
|
3040
|
+
return ServiceWorkerUtils_await(_this5.getActiveRegistrations(), function (registrations) {
|
|
3041
|
+
return ServiceWorkerUtils_continueIgnored(_forOf(registrations, function (registration) {
|
|
3042
|
+
return ServiceWorkerUtils_awaitIgnored(registration.unregister());
|
|
3043
|
+
}));
|
|
3044
|
+
});
|
|
3045
|
+
} catch (e) {
|
|
3046
|
+
return Promise.reject(e);
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
}, {
|
|
3050
|
+
key: "getActiveRegistrations",
|
|
3051
|
+
value: function getActiveRegistrations() {
|
|
2731
3052
|
try {
|
|
2732
3053
|
return ServiceWorkerUtils_await(navigator.serviceWorker.getRegistrations(), function (registrations) {
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2737
|
-
var registration = _step.value;
|
|
2738
|
-
if (registration.active !== null && registration.scope === serviceWorkerScope) {
|
|
2739
|
-
return registration.active;
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
} catch (err) {
|
|
2743
|
-
_iterator.e(err);
|
|
2744
|
-
} finally {
|
|
2745
|
-
_iterator.f();
|
|
2746
|
-
}
|
|
2747
|
-
return undefined;
|
|
3054
|
+
return registrations.filter(function (registration) {
|
|
3055
|
+
return registration.active !== null;
|
|
3056
|
+
});
|
|
2748
3057
|
});
|
|
2749
3058
|
} catch (e) {
|
|
2750
3059
|
return Promise.reject(e);
|
|
@@ -2871,7 +3180,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2871
3180
|
isActive: true,
|
|
2872
3181
|
authServiceWorker: params.serviceWorkerScript !== undefined && _this.serviceWorkerUtils.canUseServiceWorkers() ? {
|
|
2873
3182
|
serviceWorkerScript: params.serviceWorkerScript,
|
|
2874
|
-
|
|
3183
|
+
type: "Uninitialized"
|
|
2875
3184
|
} : undefined
|
|
2876
3185
|
};
|
|
2877
3186
|
AuthSessionState.setSession(newSession);
|
|
@@ -2,8 +2,7 @@ import { ServiceWorkerConfig, ServiceWorkerConfigInitialized } from "./model/Ser
|
|
|
2
2
|
export declare class ServiceWorkerUtils<TMessage> {
|
|
3
3
|
canUseServiceWorkers(): boolean;
|
|
4
4
|
sendMessage(message: TMessage, config: ServiceWorkerConfig, serviceWorkerScriptFieldName: string): Promise<ServiceWorkerConfigInitialized>;
|
|
5
|
-
private
|
|
6
|
-
private getActiveServiceWorkerElseRegister;
|
|
5
|
+
private ensureActiveServiceWorkerExists;
|
|
7
6
|
/**
|
|
8
7
|
* Idempotent.
|
|
9
8
|
*
|
|
@@ -14,4 +13,10 @@ export declare class ServiceWorkerUtils<TMessage> {
|
|
|
14
13
|
private registerServiceWorker;
|
|
15
14
|
private waitForActiveServiceWorker;
|
|
16
15
|
private getActiveServiceWorker;
|
|
16
|
+
/**
|
|
17
|
+
* Existing active Service Workers will not receive 'fetch' events in sessions that start with a hard reload, so
|
|
18
|
+
* we must unregister them and register a new one. (See: https://github.com/mswjs/msw/issues/98#issuecomment-612118211)
|
|
19
|
+
*/
|
|
20
|
+
private unregisterOnHardReload;
|
|
21
|
+
private getActiveRegistrations;
|
|
17
22
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export type ServiceWorkerConfig = ServiceWorkerConfigUninitialized | ServiceWorkerConfigInitialized;
|
|
2
2
|
export interface ServiceWorkerConfigUninitialized {
|
|
3
|
-
serviceWorkerScope: undefined;
|
|
4
3
|
serviceWorkerScript: string;
|
|
4
|
+
type: "Uninitialized";
|
|
5
5
|
}
|
|
6
6
|
export interface ServiceWorkerConfigInitialized {
|
|
7
|
-
serviceWorkerScope: string;
|
|
7
|
+
serviceWorkerScope: string | undefined;
|
|
8
8
|
serviceWorkerScript: string;
|
|
9
|
+
type: "Initialized";
|
|
9
10
|
}
|