@ovineko/spa-guard 0.0.2-alpha-1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -173
- package/dist/ForceRetryError-BWLv3UVK.d.mts +6 -0
- package/dist/_internal.d.ts +149 -20
- package/dist/_internal.js +113 -170
- package/dist/chunk-CfYAbeIz.mjs +13 -0
- package/dist/common/index.d.ts +29 -9
- package/dist/common/index.js +47 -83
- package/dist/errorDispatchers-Cl_pa0DT.mjs +105 -0
- package/dist/i18n/index.d.ts +2 -21
- package/dist/i18n/index.js +344 -341
- package/dist/index-DL8CfPXg.d.mts +26 -0
- package/dist/index-rPxPv6iu.d.mts +16 -0
- package/dist/logger-Cp1Eyk6S.mjs +534 -0
- package/dist/retryOrchestrator-DNGIHV2M.mjs +758 -0
- package/dist/retryOrchestrator-mn9XcIVu.d.mts +257 -0
- package/dist/runtime/debug/index.d.ts +6 -4
- package/dist/runtime/debug/index.js +218 -238
- package/dist/runtime/index.d.ts +66 -8
- package/dist/runtime/index.js +279 -367
- package/dist/schema/index.d.ts +2 -13
- package/dist/schema/index.js +1 -0
- package/dist/schema/parse.d.ts +6 -2
- package/dist/schema/parse.js +29 -44
- package/dist/spinner-BbZVKZ-6.mjs +60 -0
- package/dist/spinner-X23gI09z.d.mts +37 -0
- package/dist/state-I20jENMD.mjs +93 -0
- package/dist/types-DrN8pgyc.d.mts +107 -0
- package/package.json +1 -4
- package/dist/chunk-3UJ67DPX.js +0 -98
- package/dist/chunk-GE63YJOT.js +0 -865
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-PERG4557.js +0 -74
- package/dist/chunk-VZ2DLGXX.js +0 -111
- package/dist/chunk-XIFXSNSD.js +0 -678
- package/dist/common/checkVersion.d.ts +0 -5
- package/dist/common/constants.d.ts +0 -14
- package/dist/common/errors/BeaconError.d.ts +0 -12
- package/dist/common/errors/ForceRetryError.d.ts +0 -5
- package/dist/common/events/index.d.ts +0 -2
- package/dist/common/events/internal.d.ts +0 -13
- package/dist/common/events/types.d.ts +0 -104
- package/dist/common/fallbackRendering.d.ts +0 -23
- package/dist/common/fallbackState.d.ts +0 -3
- package/dist/common/handleErrorWithSpaGuard.d.ts +0 -18
- package/dist/common/html.generated.d.ts +0 -3
- package/dist/common/i18n.d.ts +0 -23
- package/dist/common/isChunkError.d.ts +0 -1
- package/dist/common/isStaticAssetError.d.ts +0 -3
- package/dist/common/lastReloadTime.d.ts +0 -17
- package/dist/common/listen/index.d.ts +0 -1
- package/dist/common/listen/internal.d.ts +0 -2
- package/dist/common/log.d.ts +0 -1
- package/dist/common/logger.d.ts +0 -30
- package/dist/common/options.d.ts +0 -182
- package/dist/common/parseVersion.d.ts +0 -9
- package/dist/common/retryImport.d.ts +0 -43
- package/dist/common/retryOrchestrator.d.ts +0 -35
- package/dist/common/retryState.d.ts +0 -11
- package/dist/common/sendBeacon.d.ts +0 -2
- package/dist/common/serializeError.d.ts +0 -1
- package/dist/common/shouldIgnore.d.ts +0 -13
- package/dist/common/spinner.d.ts +0 -8
- package/dist/common/staticAssetRecovery.d.ts +0 -2
- package/dist/i18n/translations.d.ts +0 -2
- package/dist/runtime/debug/errorDispatchers.d.ts +0 -63
- package/dist/runtime/recommendedSetup.d.ts +0 -36
- package/dist/runtime/state.d.ts +0 -20
package/dist/runtime/index.js
CHANGED
|
@@ -1,386 +1,298 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
getRetryAttemptFromUrl,
|
|
16
|
-
getRetrySnapshot,
|
|
17
|
-
markRetryHealthyBoot,
|
|
18
|
-
setTranslations,
|
|
19
|
-
versionCheckStateWindowKey
|
|
20
|
-
} from "../chunk-GE63YJOT.js";
|
|
21
|
-
import "../chunk-MLKGABMK.js";
|
|
22
|
-
|
|
23
|
-
// src/common/checkVersion.ts
|
|
24
|
-
var createInitialState = () => ({
|
|
25
|
-
blurHandler: null,
|
|
26
|
-
checkInProgress: false,
|
|
27
|
-
focusHandler: null,
|
|
28
|
-
lastCheckTimestamp: null,
|
|
29
|
-
lastKnownVersion: null,
|
|
30
|
-
runEpoch: 0,
|
|
31
|
-
versionCheckInterval: null,
|
|
32
|
-
versionCheckTimeout: null,
|
|
33
|
-
visibilityHandler: null
|
|
1
|
+
import { C as setTranslations, D as getLogger, L as versionCheckStateWindowKey, g as getOptions, l as ForceRetryError, n as markRetryHealthyBoot, p as getRetryAttemptFromUrl, t as getRetrySnapshot } from "../retryOrchestrator-DNGIHV2M.mjs";
|
|
2
|
+
import { i as getSpinnerHtml, o as showSpinner, r as dismissSpinner, s as extractVersionFromHtml } from "../spinner-BbZVKZ-6.mjs";
|
|
3
|
+
import { n as subscribeToState, t as getState } from "../state-I20jENMD.mjs";
|
|
4
|
+
//#region src/common/checkVersion.ts
|
|
5
|
+
const createInitialState = () => ({
|
|
6
|
+
blurHandler: null,
|
|
7
|
+
checkInProgress: false,
|
|
8
|
+
focusHandler: null,
|
|
9
|
+
lastCheckTimestamp: null,
|
|
10
|
+
lastKnownVersion: null,
|
|
11
|
+
runEpoch: 0,
|
|
12
|
+
versionCheckInterval: null,
|
|
13
|
+
versionCheckTimeout: null,
|
|
14
|
+
visibilityHandler: null
|
|
34
15
|
});
|
|
35
|
-
if (globalThis.window && !globalThis.window[versionCheckStateWindowKey])
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (globalThis.window === void 0) {
|
|
40
|
-
return createInitialState();
|
|
41
|
-
}
|
|
42
|
-
return globalThis.window[versionCheckStateWindowKey] ?? (globalThis.window[versionCheckStateWindowKey] = createInitialState());
|
|
16
|
+
if (globalThis.window && !globalThis.window[versionCheckStateWindowKey]) globalThis.window[versionCheckStateWindowKey] = createInitialState();
|
|
17
|
+
const getState$2 = () => {
|
|
18
|
+
if (globalThis.window === void 0) return createInitialState();
|
|
19
|
+
return globalThis.window[versionCheckStateWindowKey] ?? (globalThis.window[versionCheckStateWindowKey] = createInitialState());
|
|
43
20
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
clearTimeout(timeoutId);
|
|
70
|
-
}
|
|
21
|
+
const FETCH_TIMEOUT_MS = 3e4;
|
|
22
|
+
const fetchJsonVersion = async () => {
|
|
23
|
+
const endpoint = getOptions().checkVersion?.endpoint;
|
|
24
|
+
if (!endpoint) {
|
|
25
|
+
getLogger()?.versionCheckRequiresEndpoint();
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(endpoint, {
|
|
32
|
+
cache: getOptions().checkVersion?.cache ?? "no-store",
|
|
33
|
+
headers: { Accept: "application/json" },
|
|
34
|
+
signal: controller.signal
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
getLogger()?.versionCheckHttpError(response.status);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
if (typeof data !== "object" || data === null) return null;
|
|
42
|
+
return "version" in data && typeof data.version === "string" ? data.version : null;
|
|
43
|
+
} finally {
|
|
44
|
+
clearTimeout(timeoutId);
|
|
45
|
+
}
|
|
71
46
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
47
|
+
const fetchHtmlVersion = async () => {
|
|
48
|
+
const url = new URL(globalThis.location.href);
|
|
49
|
+
url.search = "";
|
|
50
|
+
url.hash = "";
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
53
|
+
try {
|
|
54
|
+
const response = await fetch(url.toString(), {
|
|
55
|
+
cache: getOptions().checkVersion?.cache ?? "no-store",
|
|
56
|
+
headers: { Accept: "text/html" },
|
|
57
|
+
signal: controller.signal
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
getLogger()?.versionCheckHttpError(response.status);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const version = extractVersionFromHtml(await response.text());
|
|
64
|
+
if (!version) {
|
|
65
|
+
getLogger()?.versionCheckParseError();
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return version;
|
|
69
|
+
} finally {
|
|
70
|
+
clearTimeout(timeoutId);
|
|
71
|
+
}
|
|
98
72
|
};
|
|
99
|
-
|
|
100
|
-
|
|
73
|
+
const fetchRemoteVersion = async (mode) => {
|
|
74
|
+
return mode === "json" ? fetchJsonVersion() : fetchHtmlVersion();
|
|
101
75
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
getLogger()?.versionChangeDetected(oldVersion, latestVersion);
|
|
111
|
-
if (getOptions().checkVersion?.onUpdate !== "event") {
|
|
112
|
-
globalThis.location.reload();
|
|
113
|
-
}
|
|
76
|
+
const onVersionChange = (oldVersion, latestVersion) => {
|
|
77
|
+
if (globalThis.window !== void 0) globalThis.dispatchEvent(new CustomEvent("spa-guard:version-change", { detail: {
|
|
78
|
+
latestVersion,
|
|
79
|
+
oldVersion
|
|
80
|
+
} }));
|
|
81
|
+
getLogger()?.versionChangeDetected(oldVersion, latestVersion);
|
|
82
|
+
if (getOptions().checkVersion?.onUpdate !== "event") globalThis.location.reload();
|
|
114
83
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
getLogger()?.versionCheckFailed(error);
|
|
134
|
-
} finally {
|
|
135
|
-
if (epochAtStart === s.runEpoch) {
|
|
136
|
-
s.checkInProgress = false;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
84
|
+
const checkVersionOnce = async (mode) => {
|
|
85
|
+
const s = getState$2();
|
|
86
|
+
if (s.checkInProgress) return;
|
|
87
|
+
s.checkInProgress = true;
|
|
88
|
+
const epochAtStart = s.runEpoch;
|
|
89
|
+
try {
|
|
90
|
+
const remoteVersion = await fetchRemoteVersion(mode);
|
|
91
|
+
if (epochAtStart !== s.runEpoch) return;
|
|
92
|
+
if (remoteVersion && remoteVersion !== s.lastKnownVersion) {
|
|
93
|
+
const oldVersion = s.lastKnownVersion;
|
|
94
|
+
s.lastKnownVersion = remoteVersion;
|
|
95
|
+
onVersionChange(oldVersion, remoteVersion);
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {
|
|
98
|
+
getLogger()?.versionCheckFailed(error);
|
|
99
|
+
} finally {
|
|
100
|
+
if (epochAtStart === s.runEpoch) s.checkInProgress = false;
|
|
101
|
+
}
|
|
139
102
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
103
|
+
const startPolling = (mode, interval) => {
|
|
104
|
+
const s = getState$2();
|
|
105
|
+
clearTimers();
|
|
106
|
+
s.versionCheckInterval = setInterval(async () => {
|
|
107
|
+
s.lastCheckTimestamp = Date.now();
|
|
108
|
+
await checkVersionOnce(mode);
|
|
109
|
+
}, interval);
|
|
147
110
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
111
|
+
const clearTimers = () => {
|
|
112
|
+
const s = getState$2();
|
|
113
|
+
if (s.versionCheckInterval !== null) {
|
|
114
|
+
clearInterval(s.versionCheckInterval);
|
|
115
|
+
s.versionCheckInterval = null;
|
|
116
|
+
}
|
|
117
|
+
if (s.versionCheckTimeout !== null) {
|
|
118
|
+
clearTimeout(s.versionCheckTimeout);
|
|
119
|
+
s.versionCheckTimeout = null;
|
|
120
|
+
}
|
|
158
121
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
122
|
+
const handleVisibilityHidden = () => {
|
|
123
|
+
clearTimers();
|
|
124
|
+
getLogger()?.versionCheckPaused();
|
|
162
125
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
s.lastCheckTimestamp = Date.now();
|
|
184
|
-
void checkVersionOnce(mode);
|
|
185
|
-
startPolling(mode, interval);
|
|
186
|
-
}, remaining);
|
|
126
|
+
const handleResume = (mode, interval) => {
|
|
127
|
+
if (document.visibilityState !== "visible" || !document.hasFocus()) return;
|
|
128
|
+
const s = getState$2();
|
|
129
|
+
if (s.versionCheckInterval !== null || s.versionCheckTimeout !== null) return;
|
|
130
|
+
const elapsed = Date.now() - (s.lastCheckTimestamp ?? 0);
|
|
131
|
+
if (elapsed >= interval) {
|
|
132
|
+
getLogger()?.versionCheckResumedImmediate();
|
|
133
|
+
s.lastCheckTimestamp = Date.now();
|
|
134
|
+
checkVersionOnce(mode);
|
|
135
|
+
startPolling(mode, interval);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
getLogger()?.versionCheckResumed();
|
|
139
|
+
const remaining = interval - elapsed;
|
|
140
|
+
s.versionCheckTimeout = setTimeout(() => {
|
|
141
|
+
s.versionCheckTimeout = null;
|
|
142
|
+
s.lastCheckTimestamp = Date.now();
|
|
143
|
+
checkVersionOnce(mode);
|
|
144
|
+
startPolling(mode, interval);
|
|
145
|
+
}, remaining);
|
|
187
146
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
handleVisibilityHidden();
|
|
228
|
-
};
|
|
229
|
-
document.addEventListener("visibilitychange", s.visibilityHandler);
|
|
230
|
-
globalThis.addEventListener("focus", s.focusHandler);
|
|
231
|
-
globalThis.addEventListener("blur", s.blurHandler);
|
|
147
|
+
const startVersionCheck = () => {
|
|
148
|
+
if (globalThis.window === void 0) return;
|
|
149
|
+
const options = getOptions();
|
|
150
|
+
if (!options.version) {
|
|
151
|
+
getLogger()?.versionCheckDisabled();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const s = getState$2();
|
|
155
|
+
if (s.versionCheckInterval !== null || s.visibilityHandler !== null) {
|
|
156
|
+
getLogger()?.versionCheckAlreadyRunning();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
s.runEpoch++;
|
|
160
|
+
s.lastKnownVersion = options.version;
|
|
161
|
+
const interval = options.checkVersion?.interval ?? 3e5;
|
|
162
|
+
const mode = options.checkVersion?.mode ?? "html";
|
|
163
|
+
getLogger()?.versionCheckStarted(mode, interval, s.lastKnownVersion);
|
|
164
|
+
const isTabVisible = document.visibilityState === "visible";
|
|
165
|
+
const isWindowFocused = document.hasFocus();
|
|
166
|
+
if (isTabVisible && isWindowFocused) {
|
|
167
|
+
s.lastCheckTimestamp = Date.now();
|
|
168
|
+
startPolling(mode, interval);
|
|
169
|
+
} else {
|
|
170
|
+
s.lastCheckTimestamp = 0;
|
|
171
|
+
getLogger()?.versionCheckPaused();
|
|
172
|
+
}
|
|
173
|
+
s.visibilityHandler = () => {
|
|
174
|
+
if (document.visibilityState === "hidden") handleVisibilityHidden();
|
|
175
|
+
else handleResume(mode, interval);
|
|
176
|
+
};
|
|
177
|
+
s.focusHandler = () => {
|
|
178
|
+
handleResume(mode, interval);
|
|
179
|
+
};
|
|
180
|
+
s.blurHandler = () => {
|
|
181
|
+
handleVisibilityHidden();
|
|
182
|
+
};
|
|
183
|
+
document.addEventListener("visibilitychange", s.visibilityHandler);
|
|
184
|
+
globalThis.addEventListener("focus", s.focusHandler);
|
|
185
|
+
globalThis.addEventListener("blur", s.blurHandler);
|
|
232
186
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
if (wasRunning) {
|
|
255
|
-
getLogger()?.versionCheckStopped();
|
|
256
|
-
}
|
|
187
|
+
const stopVersionCheck = () => {
|
|
188
|
+
if (globalThis.window === void 0) return;
|
|
189
|
+
const s = getState$2();
|
|
190
|
+
s.runEpoch++;
|
|
191
|
+
s.checkInProgress = false;
|
|
192
|
+
const wasRunning = s.versionCheckInterval !== null || s.versionCheckTimeout !== null || s.visibilityHandler !== null;
|
|
193
|
+
clearTimers();
|
|
194
|
+
if (s.visibilityHandler !== null) {
|
|
195
|
+
document.removeEventListener("visibilitychange", s.visibilityHandler);
|
|
196
|
+
s.visibilityHandler = null;
|
|
197
|
+
}
|
|
198
|
+
if (s.focusHandler !== null) {
|
|
199
|
+
globalThis.removeEventListener("focus", s.focusHandler);
|
|
200
|
+
s.focusHandler = null;
|
|
201
|
+
}
|
|
202
|
+
if (s.blurHandler !== null) {
|
|
203
|
+
globalThis.removeEventListener("blur", s.blurHandler);
|
|
204
|
+
s.blurHandler = null;
|
|
205
|
+
}
|
|
206
|
+
if (wasRunning) getLogger()?.versionCheckStopped();
|
|
257
207
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
versionCheckEnabled: false
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/runtime/recommendedSetup.ts
|
|
210
|
+
const AUTO_HEALTHY_BOOT_BUFFER_MS = 1e3;
|
|
211
|
+
const MIN_HEALTHY_BOOT_GRACE_MS = 5e3;
|
|
212
|
+
const setupStateWindowKey = "__spa_guard_runtime_recommended_setup_state__";
|
|
213
|
+
const createFreshState = () => ({
|
|
214
|
+
cleanup: () => {},
|
|
215
|
+
initialized: false,
|
|
216
|
+
timer: null,
|
|
217
|
+
versionCheckEnabled: false
|
|
269
218
|
});
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (!w[setupStateWindowKey]) {
|
|
276
|
-
w[setupStateWindowKey] = createFreshState();
|
|
277
|
-
}
|
|
278
|
-
return w[setupStateWindowKey];
|
|
219
|
+
const getState$1 = () => {
|
|
220
|
+
if (globalThis.window === void 0) return createFreshState();
|
|
221
|
+
const w = globalThis.window;
|
|
222
|
+
if (!w[setupStateWindowKey]) w[setupStateWindowKey] = createFreshState();
|
|
223
|
+
return w[setupStateWindowKey];
|
|
279
224
|
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
return {
|
|
306
|
-
healthyBootGraceMs: computedGraceMs,
|
|
307
|
-
healthyBootMode: "auto",
|
|
308
|
-
versionCheck
|
|
309
|
-
};
|
|
225
|
+
const resolveOptions = (overrides) => {
|
|
226
|
+
const healthyBoot = overrides?.healthyBoot;
|
|
227
|
+
const versionCheck = overrides?.versionCheck ?? true;
|
|
228
|
+
const computedGraceMs = computeAutoHealthyBootGraceMs();
|
|
229
|
+
if (healthyBoot === false || healthyBoot === "off") return {
|
|
230
|
+
healthyBootGraceMs: computedGraceMs,
|
|
231
|
+
healthyBootMode: "off",
|
|
232
|
+
versionCheck
|
|
233
|
+
};
|
|
234
|
+
if (healthyBoot === "manual") return {
|
|
235
|
+
healthyBootGraceMs: computedGraceMs,
|
|
236
|
+
healthyBootMode: "manual",
|
|
237
|
+
versionCheck
|
|
238
|
+
};
|
|
239
|
+
if (healthyBoot && typeof healthyBoot === "object") return {
|
|
240
|
+
healthyBootGraceMs: Math.max(computedGraceMs, healthyBoot.graceMs ?? computedGraceMs),
|
|
241
|
+
healthyBootMode: "auto",
|
|
242
|
+
versionCheck
|
|
243
|
+
};
|
|
244
|
+
return {
|
|
245
|
+
healthyBootGraceMs: computedGraceMs,
|
|
246
|
+
healthyBootMode: "auto",
|
|
247
|
+
versionCheck
|
|
248
|
+
};
|
|
310
249
|
};
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
250
|
+
const computeAutoHealthyBootGraceMs = () => {
|
|
251
|
+
const options = getOptions();
|
|
252
|
+
const reloadDelays = options.reloadDelays ?? [
|
|
253
|
+
1e3,
|
|
254
|
+
2e3,
|
|
255
|
+
5e3
|
|
256
|
+
];
|
|
257
|
+
const lazyRetryDelays = options.lazyRetry?.retryDelays ?? [1e3, 2e3];
|
|
258
|
+
const maxReloadDelay = Math.max(...reloadDelays, 0);
|
|
259
|
+
const lazyRetryTotalDelay = lazyRetryDelays.reduce((acc, delay) => acc + delay, 0);
|
|
260
|
+
return Math.max(MIN_HEALTHY_BOOT_GRACE_MS, maxReloadDelay + AUTO_HEALTHY_BOOT_BUFFER_MS, lazyRetryTotalDelay + AUTO_HEALTHY_BOOT_BUFFER_MS);
|
|
322
261
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (getRetryAttemptFromUrl() === null) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
const snapshot = getRetrySnapshot();
|
|
335
|
-
if (snapshot.phase !== "idle") {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
markRetryHealthyBoot();
|
|
339
|
-
}, graceMs);
|
|
262
|
+
const scheduleAutoHealthyBoot = (graceMs) => {
|
|
263
|
+
if (globalThis.window === void 0) return null;
|
|
264
|
+
if (getRetryAttemptFromUrl() === null) return null;
|
|
265
|
+
return setTimeout(() => {
|
|
266
|
+
if (getRetryAttemptFromUrl() === null) return;
|
|
267
|
+
if (getRetrySnapshot().phase !== "idle") return;
|
|
268
|
+
markRetryHealthyBoot();
|
|
269
|
+
}, graceMs);
|
|
340
270
|
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
};
|
|
367
|
-
Object.assign(state, {
|
|
368
|
-
cleanup,
|
|
369
|
-
initialized: true,
|
|
370
|
-
timer,
|
|
371
|
-
versionCheckEnabled: options.versionCheck
|
|
372
|
-
});
|
|
373
|
-
return cleanup;
|
|
374
|
-
};
|
|
375
|
-
export {
|
|
376
|
-
ForceRetryError,
|
|
377
|
-
dismissSpinner,
|
|
378
|
-
getSpinnerHtml,
|
|
379
|
-
getState,
|
|
380
|
-
recommendedSetup,
|
|
381
|
-
setTranslations,
|
|
382
|
-
showSpinner,
|
|
383
|
-
startVersionCheck,
|
|
384
|
-
stopVersionCheck,
|
|
385
|
-
subscribeToState
|
|
271
|
+
/**
|
|
272
|
+
* Enable recommended runtime features with sensible defaults.
|
|
273
|
+
* Returns a cleanup function that tears down all started features.
|
|
274
|
+
*/
|
|
275
|
+
const recommendedSetup = (overrides) => {
|
|
276
|
+
const state = getState$1();
|
|
277
|
+
if (state.initialized) return state.cleanup;
|
|
278
|
+
dismissSpinner();
|
|
279
|
+
const options = resolveOptions(overrides);
|
|
280
|
+
if (options.versionCheck) startVersionCheck();
|
|
281
|
+
const timer = options.healthyBootMode === "auto" ? scheduleAutoHealthyBoot(options.healthyBootGraceMs) : null;
|
|
282
|
+
const cleanup = () => {
|
|
283
|
+
const currentState = getState$1();
|
|
284
|
+
if (!currentState.initialized) return;
|
|
285
|
+
if (currentState.timer !== null) clearTimeout(currentState.timer);
|
|
286
|
+
if (currentState.versionCheckEnabled) stopVersionCheck();
|
|
287
|
+
if (globalThis.window !== void 0) globalThis.window[setupStateWindowKey] = createFreshState();
|
|
288
|
+
};
|
|
289
|
+
Object.assign(state, {
|
|
290
|
+
cleanup,
|
|
291
|
+
initialized: true,
|
|
292
|
+
timer,
|
|
293
|
+
versionCheckEnabled: options.versionCheck
|
|
294
|
+
});
|
|
295
|
+
return cleanup;
|
|
386
296
|
};
|
|
297
|
+
//#endregion
|
|
298
|
+
export { ForceRetryError, dismissSpinner, getSpinnerHtml, getState, recommendedSetup, setTranslations, showSpinner, startVersionCheck, stopVersionCheck, subscribeToState };
|