@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/_internal.js
CHANGED
|
@@ -1,173 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
getRetrySnapshot,
|
|
34
|
-
isDefaultRetryEnabled,
|
|
35
|
-
markRetryHealthyBoot,
|
|
36
|
-
optionsWindowKey,
|
|
37
|
-
resetRetryOrchestratorForTests,
|
|
38
|
-
sendBeacon,
|
|
39
|
-
shouldForceRetry,
|
|
40
|
-
shouldIgnoreMessages,
|
|
41
|
-
subscribe,
|
|
42
|
-
triggerRetry
|
|
43
|
-
} from "./chunk-GE63YJOT.js";
|
|
44
|
-
import "./chunk-MLKGABMK.js";
|
|
45
|
-
|
|
46
|
-
// src/common/handleErrorWithSpaGuard.ts
|
|
47
|
-
var handleErrorWithSpaGuard = (error, options) => {
|
|
48
|
-
const {
|
|
49
|
-
autoRetryChunkErrors = true,
|
|
50
|
-
errorInfo,
|
|
51
|
-
eventName,
|
|
52
|
-
onError,
|
|
53
|
-
sendBeaconOnError = true
|
|
54
|
-
} = options;
|
|
55
|
-
try {
|
|
56
|
-
onError?.(error);
|
|
57
|
-
} catch {
|
|
58
|
-
}
|
|
59
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
60
|
-
if (shouldIgnoreMessages([errorMessage])) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const isChunk = isChunkError(error);
|
|
64
|
-
const isForceRetry = shouldForceRetry([errorMessage]);
|
|
65
|
-
if ((isChunk || isForceRetry) && autoRetryChunkErrors) {
|
|
66
|
-
triggerRetry({ error, source: "error-boundary" });
|
|
67
|
-
} else if (sendBeaconOnError) {
|
|
68
|
-
sendBeacon({
|
|
69
|
-
errorMessage: error instanceof Error ? error.message : String(error),
|
|
70
|
-
eventName,
|
|
71
|
-
serialized: serializeError(errorInfo ? { error, errorInfo } : error),
|
|
72
|
-
...getRetryInfoForBeacon()
|
|
73
|
-
});
|
|
74
|
-
}
|
|
1
|
+
import { E as enableDefaultRetry, M as subscribe, N as debugSyncErrorEventType, O as isDefaultRetryEnabled, P as optionsWindowKey, S as getI18n, T as emitEvent, a as triggerRetry, c as shouldIgnoreMessages, g as getOptions, m as getRetryInfoForBeacon, n as markRetryHealthyBoot, o as sendBeacon, r as resetRetryOrchestratorForTests, s as shouldForceRetry, t as getRetrySnapshot, v as defaultErrorFallbackHtml, w as disableDefaultRetry, x as applyI18n, y as defaultLoadingFallbackHtml } from "./retryOrchestrator-DNGIHV2M.mjs";
|
|
2
|
+
import { i as isChunkError, n as listenInternal, r as serializeError, t as createLogger } from "./logger-Cp1Eyk6S.mjs";
|
|
3
|
+
import { a as sanitizeCssValue, n as defaultSpinnerSvg, s as extractVersionFromHtml, t as SPINNER_ID } from "./spinner-BbZVKZ-6.mjs";
|
|
4
|
+
import { a as dispatchNetworkTimeout, c as dispatchSyncRuntimeError, i as dispatchForceRetryError, l as dispatchUnhandledRejection, n as dispatchChunkLoadError, r as dispatchFinallyError, t as dispatchAsyncRuntimeError } from "./errorDispatchers-Cl_pa0DT.mjs";
|
|
5
|
+
//#region src/common/handleErrorWithSpaGuard.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shared error handling logic with spa-guard integration.
|
|
8
|
+
*
|
|
9
|
+
* Detects chunk errors and automatically retries, or sends beacon for non-chunk errors.
|
|
10
|
+
*/
|
|
11
|
+
const handleErrorWithSpaGuard = (error, options) => {
|
|
12
|
+
const { autoRetryChunkErrors = true, errorInfo, eventName, onError, sendBeaconOnError = true } = options;
|
|
13
|
+
try {
|
|
14
|
+
onError?.(error);
|
|
15
|
+
} catch {}
|
|
16
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
17
|
+
if (shouldIgnoreMessages([errorMessage])) return;
|
|
18
|
+
const isChunk = isChunkError(error);
|
|
19
|
+
const isForceRetry = shouldForceRetry([errorMessage]);
|
|
20
|
+
if ((isChunk || isForceRetry) && autoRetryChunkErrors) triggerRetry({
|
|
21
|
+
error,
|
|
22
|
+
source: "error-boundary"
|
|
23
|
+
});
|
|
24
|
+
else if (sendBeaconOnError) sendBeacon({
|
|
25
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
26
|
+
eventName,
|
|
27
|
+
serialized: serializeError(errorInfo ? {
|
|
28
|
+
error,
|
|
29
|
+
errorInfo
|
|
30
|
+
} : error),
|
|
31
|
+
...getRetryInfoForBeacon()
|
|
32
|
+
});
|
|
75
33
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/common/log.ts
|
|
36
|
+
const logMessage = (msg) => `[spa-guard] ${msg}`;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/common/retryImport.ts
|
|
39
|
+
const wait = (ms, signal) => new Promise((resolve, reject) => {
|
|
40
|
+
if (signal?.aborted) {
|
|
41
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const onAbort = () => {
|
|
45
|
+
clearTimeout(timeoutId);
|
|
46
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
47
|
+
};
|
|
48
|
+
const timeoutId = setTimeout(() => {
|
|
49
|
+
signal?.removeEventListener("abort", onAbort);
|
|
50
|
+
resolve();
|
|
51
|
+
}, ms);
|
|
52
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
95
53
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
extractVersionFromHtml,
|
|
157
|
-
getI18n,
|
|
158
|
-
getOptions,
|
|
159
|
-
getRetrySnapshot,
|
|
160
|
-
handleErrorWithSpaGuard,
|
|
161
|
-
isChunkError,
|
|
162
|
-
isDefaultRetryEnabled,
|
|
163
|
-
listenInternal,
|
|
164
|
-
logMessage,
|
|
165
|
-
markRetryHealthyBoot,
|
|
166
|
-
optionsWindowKey,
|
|
167
|
-
resetRetryOrchestratorForTests,
|
|
168
|
-
retryImport,
|
|
169
|
-
sanitizeCssValue,
|
|
170
|
-
serializeError,
|
|
171
|
-
subscribe,
|
|
172
|
-
triggerRetry
|
|
54
|
+
/**
|
|
55
|
+
* Retries an import function with configurable delays between attempts.
|
|
56
|
+
*
|
|
57
|
+
* @param importFn - The function that performs the dynamic import
|
|
58
|
+
* @param delays - Array of delays in milliseconds. Each entry represents one retry attempt.
|
|
59
|
+
* @param options - Optional configuration for retry behaviour
|
|
60
|
+
* @returns Promise that resolves with the import result or rejects after all attempts are exhausted
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* retryImport(() => import('./MyModule'), [1000, 2000])
|
|
64
|
+
* retryImport(() => import('./MyModule'), [500, 1500], {
|
|
65
|
+
* onRetry: (attempt, delayMs) => console.log(`Retry ${attempt} after ${delayMs}ms`),
|
|
66
|
+
* })
|
|
67
|
+
*/
|
|
68
|
+
const retryImport = async (importFn, delays, options) => {
|
|
69
|
+
const { callReloadOnFailure, onRetry, signal } = options ?? {};
|
|
70
|
+
let lastError = /* @__PURE__ */ new Error("Import failed after all retry attempts");
|
|
71
|
+
const totalAttempts = delays.length + 1;
|
|
72
|
+
const startTime = Date.now();
|
|
73
|
+
if (delays.length > 0) emitEvent({
|
|
74
|
+
name: "lazy-retry-start",
|
|
75
|
+
totalAttempts
|
|
76
|
+
});
|
|
77
|
+
for (let attempt = 0; attempt < totalAttempts; attempt++) {
|
|
78
|
+
if (signal?.aborted) throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
79
|
+
try {
|
|
80
|
+
const result = await importFn();
|
|
81
|
+
if (attempt > 0) emitEvent({
|
|
82
|
+
attempt,
|
|
83
|
+
name: "lazy-retry-success",
|
|
84
|
+
totalTime: Date.now() - startTime
|
|
85
|
+
});
|
|
86
|
+
return result;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
89
|
+
const currentDelay = delays[attempt];
|
|
90
|
+
if (currentDelay === void 0) break;
|
|
91
|
+
onRetry?.(attempt + 1, currentDelay);
|
|
92
|
+
emitEvent({
|
|
93
|
+
attempt: attempt + 1,
|
|
94
|
+
delay: currentDelay,
|
|
95
|
+
error: lastError,
|
|
96
|
+
name: "lazy-retry-attempt",
|
|
97
|
+
totalAttempts
|
|
98
|
+
});
|
|
99
|
+
await wait(currentDelay, signal);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const willReload = callReloadOnFailure === true && isChunkError(lastError) && isDefaultRetryEnabled();
|
|
103
|
+
emitEvent({
|
|
104
|
+
error: lastError,
|
|
105
|
+
name: "lazy-retry-exhausted",
|
|
106
|
+
totalAttempts,
|
|
107
|
+
willReload
|
|
108
|
+
});
|
|
109
|
+
if (willReload) triggerRetry({
|
|
110
|
+
error: lastError,
|
|
111
|
+
source: "lazy-import-failure"
|
|
112
|
+
});
|
|
113
|
+
throw lastError;
|
|
173
114
|
};
|
|
115
|
+
//#endregion
|
|
116
|
+
export { SPINNER_ID, applyI18n, createLogger, debugSyncErrorEventType, defaultErrorFallbackHtml, defaultLoadingFallbackHtml, defaultSpinnerSvg, disableDefaultRetry, dispatchAsyncRuntimeError, dispatchChunkLoadError, dispatchFinallyError, dispatchForceRetryError, dispatchNetworkTimeout, dispatchSyncRuntimeError, dispatchUnhandledRejection, emitEvent, enableDefaultRetry, extractVersionFromHtml, getI18n, getOptions, getRetrySnapshot, handleErrorWithSpaGuard, isChunkError, isDefaultRetryEnabled, listenInternal, logMessage, markRetryHealthyBoot, optionsWindowKey, resetRetryOrchestratorForTests, retryImport, sanitizeCssValue, serializeError, subscribe, triggerRetry };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll as t };
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { a as getRetrySnapshot, c as triggerRetry, d as options_d_exports, f as disableDefaultRetry, g as subscribe, h as isDefaultRetryEnabled, i as TriggerResult, m as enableDefaultRetry, n as RetrySnapshot, o as markRetryHealthyBoot, p as emitEvent, r as TriggerInput, t as RetryPhase } from "../retryOrchestrator-mn9XcIVu.mjs";
|
|
2
|
+
import { a as SPAGuardEventFallbackUINotRendered, c as SPAGuardEventLazyRetryExhausted, d as SPAGuardEventRetryAttempt, f as SPAGuardEventRetryExhausted, g as UnsubscribeFn, h as SubscribeFn, i as SPAGuardEventChunkError, l as SPAGuardEventLazyRetryStart, m as SPAGuardEventStaticAssetLoadFailed, n as InternalConfig, o as SPAGuardEventFallbackUIShown, p as SPAGuardEventRetryReset, r as SPAGuardEvent, s as SPAGuardEventLazyRetryAttempt, t as EmitOptions, u as SPAGuardEventLazyRetrySuccess } from "../types-DrN8pgyc.mjs";
|
|
3
|
+
import { t as BeaconSchema } from "../index-rPxPv6iu.mjs";
|
|
4
|
+
import { t as ForceRetryError } from "../ForceRetryError-BWLv3UVK.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/common/errors/BeaconError.d.ts
|
|
7
|
+
declare class BeaconError extends Error {
|
|
8
|
+
readonly appName: string | undefined;
|
|
9
|
+
readonly errorMessage: string | undefined;
|
|
10
|
+
readonly eventMessage: string | undefined;
|
|
11
|
+
readonly eventName: string | undefined;
|
|
12
|
+
readonly retryAttempt: number | undefined;
|
|
13
|
+
readonly retryId: string | undefined;
|
|
14
|
+
readonly serialized: string | undefined;
|
|
15
|
+
constructor(beacon: BeaconSchema);
|
|
16
|
+
toJSON(): Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
declare namespace index_d_exports {
|
|
19
|
+
export { EmitOptions, InternalConfig, SPAGuardEvent, SPAGuardEventChunkError, SPAGuardEventFallbackUINotRendered, SPAGuardEventFallbackUIShown, SPAGuardEventLazyRetryAttempt, SPAGuardEventLazyRetryExhausted, SPAGuardEventLazyRetryStart, SPAGuardEventLazyRetrySuccess, SPAGuardEventRetryAttempt, SPAGuardEventRetryExhausted, SPAGuardEventRetryReset, SPAGuardEventStaticAssetLoadFailed, SubscribeFn, UnsubscribeFn, emitEvent, subscribe };
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/common/fallbackState.d.ts
|
|
23
|
+
declare const isInFallbackMode: () => boolean;
|
|
24
|
+
declare const resetFallbackMode: () => void;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/common/listen/index.d.ts
|
|
27
|
+
declare const listen: () => void;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { BeaconError, ForceRetryError, type RetryPhase, type RetrySnapshot, type TriggerInput, type TriggerResult, disableDefaultRetry, enableDefaultRetry, index_d_exports as events, getRetrySnapshot, isDefaultRetryEnabled, isInFallbackMode, listen, markRetryHealthyBoot, options_d_exports as options, resetFallbackMode, triggerRetry };
|
package/dist/common/index.js
CHANGED
|
@@ -1,87 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "../chunk-XIFXSNSD.js";
|
|
6
|
-
import {
|
|
7
|
-
ForceRetryError,
|
|
8
|
-
disableDefaultRetry,
|
|
9
|
-
emitEvent,
|
|
10
|
-
enableDefaultRetry,
|
|
11
|
-
getRetrySnapshot,
|
|
12
|
-
isDefaultRetryEnabled,
|
|
13
|
-
isInFallbackMode,
|
|
14
|
-
markRetryHealthyBoot,
|
|
15
|
-
options_exports,
|
|
16
|
-
resetFallbackMode,
|
|
17
|
-
subscribe,
|
|
18
|
-
triggerRetry
|
|
19
|
-
} from "../chunk-GE63YJOT.js";
|
|
20
|
-
import {
|
|
21
|
-
__export
|
|
22
|
-
} from "../chunk-MLKGABMK.js";
|
|
23
|
-
|
|
24
|
-
// src/common/errors/BeaconError.ts
|
|
1
|
+
import { t as __exportAll } from "../chunk-CfYAbeIz.mjs";
|
|
2
|
+
import { E as enableDefaultRetry, M as subscribe, O as isDefaultRetryEnabled, T as emitEvent, _ as options_exports, a as triggerRetry, d as isInFallbackMode, f as resetFallbackMode, l as ForceRetryError, n as markRetryHealthyBoot, t as getRetrySnapshot, w as disableDefaultRetry } from "../retryOrchestrator-DNGIHV2M.mjs";
|
|
3
|
+
import { n as listenInternal, r as serializeError, t as createLogger } from "../logger-Cp1Eyk6S.mjs";
|
|
4
|
+
//#region src/common/errors/BeaconError.ts
|
|
25
5
|
var BeaconError = class extends Error {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
6
|
+
appName;
|
|
7
|
+
errorMessage;
|
|
8
|
+
eventMessage;
|
|
9
|
+
eventName;
|
|
10
|
+
retryAttempt;
|
|
11
|
+
retryId;
|
|
12
|
+
serialized;
|
|
13
|
+
constructor(beacon) {
|
|
14
|
+
super(beacon.errorMessage ?? beacon.eventMessage ?? "Unknown beacon error");
|
|
15
|
+
this.name = "BeaconError";
|
|
16
|
+
this.appName = beacon.appName;
|
|
17
|
+
this.errorMessage = beacon.errorMessage;
|
|
18
|
+
this.eventMessage = beacon.eventMessage;
|
|
19
|
+
this.eventName = beacon.eventName;
|
|
20
|
+
this.retryAttempt = beacon.retryAttempt;
|
|
21
|
+
this.retryId = beacon.retryId;
|
|
22
|
+
this.serialized = beacon.serialized;
|
|
23
|
+
}
|
|
24
|
+
toJSON() {
|
|
25
|
+
return {
|
|
26
|
+
appName: this.appName,
|
|
27
|
+
errorMessage: this.errorMessage,
|
|
28
|
+
eventMessage: this.eventMessage,
|
|
29
|
+
eventName: this.eventName,
|
|
30
|
+
message: this.message,
|
|
31
|
+
name: this.name,
|
|
32
|
+
retryAttempt: this.retryAttempt,
|
|
33
|
+
retryId: this.retryId,
|
|
34
|
+
serialized: this.serialized
|
|
35
|
+
};
|
|
36
|
+
}
|
|
57
37
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var events_exports = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
subscribe: () => subscribe
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/common/events/index.ts
|
|
40
|
+
var events_exports = /* @__PURE__ */ __exportAll({
|
|
41
|
+
emitEvent: () => emitEvent,
|
|
42
|
+
subscribe: () => subscribe
|
|
64
43
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
listenInternal(serializeError, createLogger());
|
|
72
|
-
};
|
|
73
|
-
export {
|
|
74
|
-
BeaconError,
|
|
75
|
-
ForceRetryError,
|
|
76
|
-
disableDefaultRetry,
|
|
77
|
-
enableDefaultRetry,
|
|
78
|
-
events_exports as events,
|
|
79
|
-
getRetrySnapshot,
|
|
80
|
-
isDefaultRetryEnabled,
|
|
81
|
-
isInFallbackMode,
|
|
82
|
-
listen,
|
|
83
|
-
markRetryHealthyBoot,
|
|
84
|
-
options_exports as options,
|
|
85
|
-
resetFallbackMode,
|
|
86
|
-
triggerRetry
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/common/listen/index.ts
|
|
46
|
+
const listen = () => {
|
|
47
|
+
if (!globalThis.window) return;
|
|
48
|
+
listenInternal(serializeError, createLogger());
|
|
87
49
|
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { BeaconError, ForceRetryError, disableDefaultRetry, enableDefaultRetry, events_exports as events, getRetrySnapshot, isDefaultRetryEnabled, isInFallbackMode, listen, markRetryHealthyBoot, options_exports as options, resetFallbackMode, triggerRetry };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { N as debugSyncErrorEventType, T as emitEvent, g as getOptions, i as setFallbackStateForDebug, l as ForceRetryError } from "./retryOrchestrator-DNGIHV2M.mjs";
|
|
2
|
+
//#region src/runtime/debug/errorDispatchers.ts
|
|
3
|
+
/**
|
|
4
|
+
* Error dispatchers for the debug panel.
|
|
5
|
+
*
|
|
6
|
+
* Unlike the old errorSimulators (which returned promises that callers could catch),
|
|
7
|
+
* these functions return void. Errors are "fire and forget" — they escape to
|
|
8
|
+
* window event listeners (window.error, window.unhandledrejection) where
|
|
9
|
+
* spa-guard's listenInternal() picks them up.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Dispatches an async runtime error via setTimeout.
|
|
13
|
+
* Triggers the window "error" event because the throw happens outside
|
|
14
|
+
* any call stack that could catch it.
|
|
15
|
+
*/
|
|
16
|
+
function dispatchAsyncRuntimeError() {
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
throw new Error("Simulated runtime error from spa-guard debug panel");
|
|
19
|
+
}, 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Dispatches an unhandled chunk load error via void Promise.reject().
|
|
23
|
+
* Triggers window "unhandledrejection" with an error matching spa-guard's
|
|
24
|
+
* chunk error detection patterns.
|
|
25
|
+
*/
|
|
26
|
+
function dispatchChunkLoadError() {
|
|
27
|
+
const error = /* @__PURE__ */ new Error("Failed to fetch dynamically imported module: /nonexistent-chunk-" + Date.now() + ".js");
|
|
28
|
+
error.name = "ChunkLoadError";
|
|
29
|
+
Promise.reject(error);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Dispatches an unhandled chunk error via Promise.finally().
|
|
33
|
+
* The throw inside .finally() with no surrounding catch produces
|
|
34
|
+
* a window "unhandledrejection" event.
|
|
35
|
+
*/
|
|
36
|
+
function dispatchFinallyError() {
|
|
37
|
+
Promise.resolve().finally(() => {
|
|
38
|
+
throw new Error("Failed to fetch dynamically imported module: /finally-error-chunk.js");
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Dispatches a ForceRetryError via void Promise.reject().
|
|
43
|
+
* Triggers window "unhandledrejection" with a ForceRetryError whose message
|
|
44
|
+
* contains the FORCE_RETRY_MAGIC prefix, exercising the forceRetry path.
|
|
45
|
+
*/
|
|
46
|
+
function dispatchForceRetryError() {
|
|
47
|
+
Promise.reject(new ForceRetryError("Simulated force-retry from spa-guard debug panel"));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Dispatches an unhandled network timeout error after a delay.
|
|
51
|
+
* Uses setTimeout + void Promise.reject() to trigger window "unhandledrejection".
|
|
52
|
+
*/
|
|
53
|
+
function dispatchNetworkTimeout(delayMs = 3e3) {
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
Promise.reject(/* @__PURE__ */ new TypeError("NetworkError: request timed out"));
|
|
56
|
+
}, delayMs);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Simulates the retry-exhausted state by emitting the "retry-exhausted" event
|
|
60
|
+
* with finalAttempt equal to the configured reloadDelays length, then renders
|
|
61
|
+
* the fallback UI into the DOM.
|
|
62
|
+
*/
|
|
63
|
+
function dispatchRetryExhausted() {
|
|
64
|
+
emitEvent({
|
|
65
|
+
finalAttempt: (getOptions().reloadDelays ?? []).length,
|
|
66
|
+
name: "retry-exhausted",
|
|
67
|
+
retryId: ""
|
|
68
|
+
});
|
|
69
|
+
setFallbackStateForDebug();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Simulates a static asset 404 by appending a <script> element with a
|
|
73
|
+
* nonexistent hashed URL to document.head. The browser fires an "error"
|
|
74
|
+
* event on the element, which spa-guard's listenInternal() detects via
|
|
75
|
+
* the Resource Timing API-based isLikely404 check.
|
|
76
|
+
*/
|
|
77
|
+
function dispatchStaticAsset404() {
|
|
78
|
+
const hash = crypto.randomUUID().slice(0, 8);
|
|
79
|
+
const script = document.createElement("script");
|
|
80
|
+
script.src = `/assets/index-${hash}.js`;
|
|
81
|
+
script.addEventListener("error", () => {
|
|
82
|
+
script.remove();
|
|
83
|
+
});
|
|
84
|
+
document.head.append(script);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Dispatches a sync runtime error via CustomEvent.
|
|
88
|
+
* DebugSyncErrorTrigger (a React component) listens for this event,
|
|
89
|
+
* stores the error in state, and throws it during render so that
|
|
90
|
+
* React Error Boundary can catch it.
|
|
91
|
+
*/
|
|
92
|
+
function dispatchSyncRuntimeError() {
|
|
93
|
+
const error = /* @__PURE__ */ new Error("Simulated sync runtime error from spa-guard debug panel");
|
|
94
|
+
globalThis.dispatchEvent(new CustomEvent(debugSyncErrorEventType, { detail: { error } }));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Dispatches a plain unhandled promise rejection via void Promise.reject().
|
|
98
|
+
* This is NOT a chunk error and NOT a ForceRetry — it exercises the
|
|
99
|
+
* handleUnhandledRejections config path for generic rejections.
|
|
100
|
+
*/
|
|
101
|
+
function dispatchUnhandledRejection() {
|
|
102
|
+
Promise.reject(/* @__PURE__ */ new Error("Simulated unhandled promise rejection from spa-guard debug panel"));
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { dispatchNetworkTimeout as a, dispatchSyncRuntimeError as c, dispatchForceRetryError as i, dispatchUnhandledRejection as l, dispatchChunkLoadError as n, dispatchRetryExhausted as o, dispatchFinallyError as r, dispatchStaticAsset404 as s, dispatchAsyncRuntimeError as t };
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
loading: string;
|
|
4
|
-
message: string;
|
|
5
|
-
reload: string;
|
|
6
|
-
retrying: string;
|
|
7
|
-
rtl?: boolean;
|
|
8
|
-
tryAgain: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Match a language code or Accept-Language header against available translations.
|
|
12
|
-
*
|
|
13
|
-
* - If `input` is undefined, returns `"en"`.
|
|
14
|
-
* - If `input` contains `,` or `;q=`, it's parsed as an Accept-Language header
|
|
15
|
-
* with quality values sorted descending.
|
|
16
|
-
* - Otherwise it's treated as a direct language code.
|
|
17
|
-
*
|
|
18
|
-
* Resolution: exact match → prefix match → `"en"` (or first available if `"en"` not in list).
|
|
19
|
-
*/
|
|
20
|
-
export declare function matchLang(input: string | undefined, available?: string[]): string;
|
|
21
|
-
export { translations } from "./translations";
|
|
1
|
+
import { n as matchLang, r as translations, t as SpaGuardTranslations } from "../index-DL8CfPXg.mjs";
|
|
2
|
+
export { SpaGuardTranslations, matchLang, translations };
|