@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
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { g as UnsubscribeFn, h as SubscribeFn, r as SPAGuardEvent, t as EmitOptions } from "./types-DrN8pgyc.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/common/constants.d.ts
|
|
4
|
+
declare const optionsWindowKey = "__SPA_GUARD_OPTIONS__";
|
|
5
|
+
declare const debugSyncErrorEventType = "spa-guard:debug-sync-error";
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/common/logger.d.ts
|
|
8
|
+
interface Logger {
|
|
9
|
+
beaconSendFailed(error: unknown): void;
|
|
10
|
+
capturedError(type: string, ...args: unknown[]): void;
|
|
11
|
+
error(msg: string, ...args: unknown[]): void;
|
|
12
|
+
fallbackAlreadyShown(error: unknown): void;
|
|
13
|
+
fallbackInjectFailed(error: unknown): void;
|
|
14
|
+
fallbackTargetNotFound(selector: string): void;
|
|
15
|
+
log(msg: string, ...args: unknown[]): void;
|
|
16
|
+
logEvent(event: SPAGuardEvent): void;
|
|
17
|
+
noBeaconEndpoint(): void;
|
|
18
|
+
noFallbackConfigured(): void;
|
|
19
|
+
reloadAlreadyScheduled(error: unknown): void;
|
|
20
|
+
retryCycleStarting(retryId: string, fromAttempt: number): void;
|
|
21
|
+
retrySchedulingReload(retryId: string, attempt: number, delay: number): void;
|
|
22
|
+
versionChangeDetected(oldVersion: null | string, latestVersion: string): void;
|
|
23
|
+
versionCheckAlreadyRunning(): void;
|
|
24
|
+
versionCheckDisabled(): void;
|
|
25
|
+
versionCheckFailed(error: unknown): void;
|
|
26
|
+
versionCheckHttpError(status: number): void;
|
|
27
|
+
versionCheckParseError(): void;
|
|
28
|
+
versionCheckPaused(): void;
|
|
29
|
+
versionCheckRequiresEndpoint(): void;
|
|
30
|
+
versionCheckResumed(): void;
|
|
31
|
+
versionCheckResumedImmediate(): void;
|
|
32
|
+
versionCheckStarted(mode: string, interval: number, version: string): void;
|
|
33
|
+
versionCheckStopped(): void;
|
|
34
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
35
|
+
}
|
|
36
|
+
declare const createLogger: () => Logger;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/common/events/internal.d.ts
|
|
39
|
+
declare const emitEvent: (event: SPAGuardEvent, options?: EmitOptions) => void;
|
|
40
|
+
declare const subscribe: (cb: SubscribeFn) => UnsubscribeFn;
|
|
41
|
+
declare const disableDefaultRetry: () => void;
|
|
42
|
+
declare const enableDefaultRetry: () => void;
|
|
43
|
+
declare const isDefaultRetryEnabled: () => boolean;
|
|
44
|
+
declare namespace options_d_exports {
|
|
45
|
+
export { Options, getOptions, optionsWindowKey };
|
|
46
|
+
}
|
|
47
|
+
interface Options {
|
|
48
|
+
/**
|
|
49
|
+
* Application name for beacon source identification.
|
|
50
|
+
* Useful in monorepo setups to identify which app sent the beacon.
|
|
51
|
+
*/
|
|
52
|
+
appName?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Configuration for proactive version checking to detect new deployments.
|
|
55
|
+
* When configured with a `version`, periodically polls to detect version changes
|
|
56
|
+
* and dispatches a `spa-guard:version-change` CustomEvent on the window.
|
|
57
|
+
*/
|
|
58
|
+
checkVersion?: {
|
|
59
|
+
/**
|
|
60
|
+
* Cache mode for the fetch request used to check the version.
|
|
61
|
+
* - "no-store": Bypass the HTTP cache entirely (default).
|
|
62
|
+
* - "no-cache": Revalidate with the server before using cached response.
|
|
63
|
+
* @default "no-store"
|
|
64
|
+
*/
|
|
65
|
+
cache?: "no-cache" | "no-store";
|
|
66
|
+
/**
|
|
67
|
+
* Endpoint URL for JSON mode version checking.
|
|
68
|
+
* Required when mode is "json".
|
|
69
|
+
*/
|
|
70
|
+
endpoint?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Polling interval in milliseconds.
|
|
73
|
+
* @default 300000
|
|
74
|
+
*/
|
|
75
|
+
interval?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Detection mode.
|
|
78
|
+
* - "html": Re-fetches the current page and parses the injected version from the HTML.
|
|
79
|
+
* - "json": Fetches a dedicated JSON endpoint.
|
|
80
|
+
* @default "html"
|
|
81
|
+
*/
|
|
82
|
+
mode?: "html" | "json";
|
|
83
|
+
/**
|
|
84
|
+
* Behavior when a version change is detected.
|
|
85
|
+
* - "reload": Automatically calls location.reload() after dispatching the event.
|
|
86
|
+
* - "event": Only dispatches the spa-guard:version-change CustomEvent (no reload).
|
|
87
|
+
* @default "reload"
|
|
88
|
+
*/
|
|
89
|
+
onUpdate?: "event" | "reload";
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Enable automatic retry cycle reset when enough time has passed
|
|
93
|
+
* since the last reload. When true, if the user stays on a page longer
|
|
94
|
+
* than the retry delay, the next error will start a fresh retry cycle.
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
enableRetryReset?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Error filtering and retry configuration.
|
|
100
|
+
*/
|
|
101
|
+
errors?: {
|
|
102
|
+
/**
|
|
103
|
+
* List of error message substrings that should trigger the retry/reload process,
|
|
104
|
+
* same as chunk load errors. Useful for custom errors that indicate a stale deployment.
|
|
105
|
+
* @default []
|
|
106
|
+
*/
|
|
107
|
+
forceRetry?: string[];
|
|
108
|
+
/**
|
|
109
|
+
* List of error message substrings to ignore and not report.
|
|
110
|
+
* If error message contains any of these strings, it will be filtered out.
|
|
111
|
+
* @default []
|
|
112
|
+
*/
|
|
113
|
+
ignore?: string[];
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Controls behavior for regular unhandled promise rejections
|
|
117
|
+
* (those that are not chunk errors or ForceRetry errors).
|
|
118
|
+
* @default { retry: false, sendBeacon: true }
|
|
119
|
+
*/
|
|
120
|
+
handleUnhandledRejections?: {
|
|
121
|
+
/**
|
|
122
|
+
* Whether to attempt a page reload on unhandled rejections.
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
retry?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Whether to send a beacon report on unhandled rejections.
|
|
128
|
+
* @default true
|
|
129
|
+
*/
|
|
130
|
+
sendBeacon?: boolean;
|
|
131
|
+
};
|
|
132
|
+
html?: {
|
|
133
|
+
fallback?: {
|
|
134
|
+
/** Custom HTML to display when all reload attempts are exhausted */content?: string; /** CSS selector where the fallback HTML should be injected @default "body" */
|
|
135
|
+
selector?: string;
|
|
136
|
+
};
|
|
137
|
+
loading?: {
|
|
138
|
+
/** Custom HTML to display during the loading/retrying state */content?: string;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Spinner overlay configuration.
|
|
142
|
+
* Controls the full-page loading spinner injected by the Vite plugin
|
|
143
|
+
* and available via `showSpinner()`/`dismissSpinner()` at runtime.
|
|
144
|
+
*/
|
|
145
|
+
spinner?: {
|
|
146
|
+
/**
|
|
147
|
+
* Overlay background color.
|
|
148
|
+
* Used as CSS variable fallback: var(--spa-guard-spinner-bg, <this value>).
|
|
149
|
+
* @default '#fff'
|
|
150
|
+
*/
|
|
151
|
+
background?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Custom spinner HTML (the spinner element only, no container/overlay).
|
|
154
|
+
* If not provided, uses the default SVG spinner.
|
|
155
|
+
*/
|
|
156
|
+
content?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Disable spinner entirely.
|
|
159
|
+
* No injection into body, showSpinner() is a no-op, Spinner returns null.
|
|
160
|
+
* @default false
|
|
161
|
+
*/
|
|
162
|
+
disabled?: boolean;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Options for the lazyWithRetry module-level retry logic.
|
|
167
|
+
* Controls retry behaviour for dynamic imports before falling back to a full page reload.
|
|
168
|
+
*/
|
|
169
|
+
lazyRetry?: {
|
|
170
|
+
/**
|
|
171
|
+
* Call triggerRetry() after all retry attempts for dynamic imports are exhausted.
|
|
172
|
+
* If true, triggers page reload logic after all retryDelays fail.
|
|
173
|
+
* If false, only throws the error to the error boundary without a reload.
|
|
174
|
+
* @default true
|
|
175
|
+
*/
|
|
176
|
+
callReloadOnFailure?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Array of delays in milliseconds for dynamic import retry attempts.
|
|
179
|
+
* Each element represents one retry attempt with the given delay.
|
|
180
|
+
* The number of elements determines the total number of retry attempts.
|
|
181
|
+
* @default [1000, 2000]
|
|
182
|
+
* @example [500, 1500, 3000] // 3 attempts: 500ms, 1.5s, 3s
|
|
183
|
+
*/
|
|
184
|
+
retryDelays?: number[];
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Minimum time in milliseconds between retry cycle resets.
|
|
188
|
+
* Prevents infinite reset loops by ensuring a reset can only happen
|
|
189
|
+
* if the previous reset was at least this many milliseconds ago.
|
|
190
|
+
* @default 5000 (5 seconds)
|
|
191
|
+
*/
|
|
192
|
+
minTimeBetweenResets?: number;
|
|
193
|
+
/** @default [1000, 2000, 5000] */
|
|
194
|
+
reloadDelays?: number[];
|
|
195
|
+
reportBeacon?: {
|
|
196
|
+
endpoint?: string;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Configuration for automatic recovery from static asset 404 errors
|
|
200
|
+
* caused by deployment version mismatches.
|
|
201
|
+
*/
|
|
202
|
+
staticAssets?: {
|
|
203
|
+
/**
|
|
204
|
+
* Automatically trigger a cache-busting reload when a hashed static asset
|
|
205
|
+
* fails to load and the page has been open long enough to suggest a stale deployment.
|
|
206
|
+
* @default true
|
|
207
|
+
*/
|
|
208
|
+
autoRecover?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Milliseconds to wait after the first failed asset before triggering the reload.
|
|
211
|
+
* Allows collecting multiple concurrent failures into a single reload.
|
|
212
|
+
* @default 500
|
|
213
|
+
*/
|
|
214
|
+
recoveryDelay?: number;
|
|
215
|
+
};
|
|
216
|
+
/** @default true */
|
|
217
|
+
useRetryId?: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Current application version. Used by the version checker to detect new deployments.
|
|
220
|
+
* Automatically generated by the Vite plugin using `crypto.randomUUID()` if not explicitly provided.
|
|
221
|
+
*/
|
|
222
|
+
version?: string;
|
|
223
|
+
}
|
|
224
|
+
declare const getOptions: () => Options;
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/common/retryOrchestrator.d.ts
|
|
227
|
+
type RetryPhase = "fallback" | "idle" | "scheduled";
|
|
228
|
+
interface RetrySnapshot {
|
|
229
|
+
attempt: number;
|
|
230
|
+
lastSource?: string;
|
|
231
|
+
lastTriggerTime?: number;
|
|
232
|
+
phase: RetryPhase;
|
|
233
|
+
retryId: null | string;
|
|
234
|
+
}
|
|
235
|
+
interface TriggerInput {
|
|
236
|
+
cacheBust?: boolean;
|
|
237
|
+
error?: unknown;
|
|
238
|
+
source?: string;
|
|
239
|
+
}
|
|
240
|
+
type TriggerResult = {
|
|
241
|
+
reason: string;
|
|
242
|
+
status: "deduped";
|
|
243
|
+
} | {
|
|
244
|
+
status: "accepted";
|
|
245
|
+
} | {
|
|
246
|
+
status: "fallback";
|
|
247
|
+
} | {
|
|
248
|
+
status: "internal-error";
|
|
249
|
+
} | {
|
|
250
|
+
status: "retry-disabled";
|
|
251
|
+
};
|
|
252
|
+
declare const triggerRetry: (input?: TriggerInput) => TriggerResult;
|
|
253
|
+
declare const markRetryHealthyBoot: () => void;
|
|
254
|
+
declare const getRetrySnapshot: () => RetrySnapshot;
|
|
255
|
+
declare const resetRetryOrchestratorForTests: () => void;
|
|
256
|
+
//#endregion
|
|
257
|
+
export { Logger as _, getRetrySnapshot as a, optionsWindowKey as b, triggerRetry as c, options_d_exports as d, disableDefaultRetry as f, subscribe as g, isDefaultRetryEnabled as h, TriggerResult as i, Options as l, enableDefaultRetry as m, RetrySnapshot as n, markRetryHealthyBoot as o, emitEvent as p, TriggerInput as r, resetRetryOrchestratorForTests as s, RetryPhase as t, getOptions as u, createLogger as v, debugSyncErrorEventType as y };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/runtime/debug/index.d.ts
|
|
1
2
|
type Position = "bottom-left" | "bottom-right" | "top-left" | "top-right";
|
|
2
3
|
/**
|
|
3
4
|
* Creates a debug panel for spa-guard that displays state, events,
|
|
@@ -5,8 +6,9 @@ type Position = "bottom-left" | "bottom-right" | "top-left" | "top-right";
|
|
|
5
6
|
*
|
|
6
7
|
* Returns a cleanup function that removes the panel and unsubscribes all listeners.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
declare function createDebugger(options?: {
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
position?: Position;
|
|
11
12
|
}): () => void;
|
|
12
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
export { createDebugger };
|