@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.
Files changed (67) hide show
  1. package/README.md +22 -173
  2. package/dist/ForceRetryError-BWLv3UVK.d.mts +6 -0
  3. package/dist/_internal.d.ts +149 -20
  4. package/dist/_internal.js +113 -170
  5. package/dist/chunk-CfYAbeIz.mjs +13 -0
  6. package/dist/common/index.d.ts +29 -9
  7. package/dist/common/index.js +47 -83
  8. package/dist/errorDispatchers-Cl_pa0DT.mjs +105 -0
  9. package/dist/i18n/index.d.ts +2 -21
  10. package/dist/i18n/index.js +344 -341
  11. package/dist/index-DL8CfPXg.d.mts +26 -0
  12. package/dist/index-rPxPv6iu.d.mts +16 -0
  13. package/dist/logger-Cp1Eyk6S.mjs +534 -0
  14. package/dist/retryOrchestrator-DNGIHV2M.mjs +758 -0
  15. package/dist/retryOrchestrator-mn9XcIVu.d.mts +257 -0
  16. package/dist/runtime/debug/index.d.ts +6 -4
  17. package/dist/runtime/debug/index.js +218 -238
  18. package/dist/runtime/index.d.ts +66 -8
  19. package/dist/runtime/index.js +279 -367
  20. package/dist/schema/index.d.ts +2 -13
  21. package/dist/schema/index.js +1 -0
  22. package/dist/schema/parse.d.ts +6 -2
  23. package/dist/schema/parse.js +29 -44
  24. package/dist/spinner-BbZVKZ-6.mjs +60 -0
  25. package/dist/spinner-X23gI09z.d.mts +37 -0
  26. package/dist/state-I20jENMD.mjs +93 -0
  27. package/dist/types-DrN8pgyc.d.mts +107 -0
  28. package/package.json +1 -4
  29. package/dist/chunk-3UJ67DPX.js +0 -98
  30. package/dist/chunk-GE63YJOT.js +0 -865
  31. package/dist/chunk-MLKGABMK.js +0 -9
  32. package/dist/chunk-PERG4557.js +0 -74
  33. package/dist/chunk-VZ2DLGXX.js +0 -111
  34. package/dist/chunk-XIFXSNSD.js +0 -678
  35. package/dist/common/checkVersion.d.ts +0 -5
  36. package/dist/common/constants.d.ts +0 -14
  37. package/dist/common/errors/BeaconError.d.ts +0 -12
  38. package/dist/common/errors/ForceRetryError.d.ts +0 -5
  39. package/dist/common/events/index.d.ts +0 -2
  40. package/dist/common/events/internal.d.ts +0 -13
  41. package/dist/common/events/types.d.ts +0 -104
  42. package/dist/common/fallbackRendering.d.ts +0 -23
  43. package/dist/common/fallbackState.d.ts +0 -3
  44. package/dist/common/handleErrorWithSpaGuard.d.ts +0 -18
  45. package/dist/common/html.generated.d.ts +0 -3
  46. package/dist/common/i18n.d.ts +0 -23
  47. package/dist/common/isChunkError.d.ts +0 -1
  48. package/dist/common/isStaticAssetError.d.ts +0 -3
  49. package/dist/common/lastReloadTime.d.ts +0 -17
  50. package/dist/common/listen/index.d.ts +0 -1
  51. package/dist/common/listen/internal.d.ts +0 -2
  52. package/dist/common/log.d.ts +0 -1
  53. package/dist/common/logger.d.ts +0 -30
  54. package/dist/common/options.d.ts +0 -182
  55. package/dist/common/parseVersion.d.ts +0 -9
  56. package/dist/common/retryImport.d.ts +0 -43
  57. package/dist/common/retryOrchestrator.d.ts +0 -35
  58. package/dist/common/retryState.d.ts +0 -11
  59. package/dist/common/sendBeacon.d.ts +0 -2
  60. package/dist/common/serializeError.d.ts +0 -1
  61. package/dist/common/shouldIgnore.d.ts +0 -13
  62. package/dist/common/spinner.d.ts +0 -8
  63. package/dist/common/staticAssetRecovery.d.ts +0 -2
  64. package/dist/i18n/translations.d.ts +0 -2
  65. package/dist/runtime/debug/errorDispatchers.d.ts +0 -63
  66. package/dist/runtime/recommendedSetup.d.ts +0 -36
  67. package/dist/runtime/state.d.ts +0 -20
@@ -1,9 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- export {
8
- __export
9
- };
@@ -1,74 +0,0 @@
1
- import {
2
- ForceRetryError,
3
- debugSyncErrorEventType,
4
- emitEvent,
5
- getOptions,
6
- setFallbackStateForDebug
7
- } from "./chunk-GE63YJOT.js";
8
-
9
- // src/runtime/debug/errorDispatchers.ts
10
- function dispatchAsyncRuntimeError() {
11
- setTimeout(() => {
12
- throw new Error("Simulated runtime error from spa-guard debug panel");
13
- }, 0);
14
- }
15
- function dispatchChunkLoadError() {
16
- const error = new Error(
17
- "Failed to fetch dynamically imported module: /nonexistent-chunk-" + Date.now() + ".js"
18
- );
19
- error.name = "ChunkLoadError";
20
- void Promise.reject(error);
21
- }
22
- function dispatchFinallyError() {
23
- void Promise.resolve().finally(() => {
24
- throw new Error("Failed to fetch dynamically imported module: /finally-error-chunk.js");
25
- });
26
- }
27
- function dispatchForceRetryError() {
28
- void Promise.reject(new ForceRetryError("Simulated force-retry from spa-guard debug panel"));
29
- }
30
- function dispatchNetworkTimeout(delayMs = 3e3) {
31
- setTimeout(() => {
32
- void Promise.reject(new TypeError("NetworkError: request timed out"));
33
- }, delayMs);
34
- }
35
- function dispatchRetryExhausted() {
36
- const options = getOptions();
37
- const reloadDelays = options.reloadDelays ?? [];
38
- emitEvent({
39
- finalAttempt: reloadDelays.length,
40
- name: "retry-exhausted",
41
- retryId: ""
42
- });
43
- setFallbackStateForDebug();
44
- }
45
- function dispatchStaticAsset404() {
46
- const hash = crypto.randomUUID().slice(0, 8);
47
- const script = document.createElement("script");
48
- script.src = `/assets/index-${hash}.js`;
49
- script.addEventListener("error", () => {
50
- script.remove();
51
- });
52
- document.head.append(script);
53
- }
54
- function dispatchSyncRuntimeError() {
55
- const error = new Error("Simulated sync runtime error from spa-guard debug panel");
56
- globalThis.dispatchEvent(new CustomEvent(debugSyncErrorEventType, { detail: { error } }));
57
- }
58
- function dispatchUnhandledRejection() {
59
- void Promise.reject(
60
- new Error("Simulated unhandled promise rejection from spa-guard debug panel")
61
- );
62
- }
63
-
64
- export {
65
- dispatchAsyncRuntimeError,
66
- dispatchChunkLoadError,
67
- dispatchFinallyError,
68
- dispatchForceRetryError,
69
- dispatchNetworkTimeout,
70
- dispatchRetryExhausted,
71
- dispatchStaticAsset404,
72
- dispatchSyncRuntimeError,
73
- dispatchUnhandledRejection
74
- };
@@ -1,111 +0,0 @@
1
- import {
2
- getLastRetryResetInfo,
3
- getRetryAttemptFromUrl,
4
- getRetryStateFromUrl,
5
- subscribe
6
- } from "./chunk-GE63YJOT.js";
7
-
8
- // src/runtime/state.ts
9
- var getInitialStateFromUrl = () => {
10
- const resetInfo = getLastRetryResetInfo();
11
- if (globalThis.window === void 0) {
12
- return {
13
- currentAttempt: 0,
14
- isFallbackShown: false,
15
- isWaiting: false,
16
- lastResetRetryId: resetInfo?.previousRetryId,
17
- lastRetryResetTime: resetInfo?.timestamp
18
- };
19
- }
20
- const retryState = getRetryStateFromUrl();
21
- if (!retryState) {
22
- const attempt = getRetryAttemptFromUrl();
23
- if (attempt !== null) {
24
- return {
25
- currentAttempt: attempt,
26
- isFallbackShown: false,
27
- isWaiting: false,
28
- lastResetRetryId: resetInfo?.previousRetryId,
29
- lastRetryResetTime: resetInfo?.timestamp
30
- };
31
- }
32
- return {
33
- currentAttempt: 0,
34
- isFallbackShown: false,
35
- isWaiting: false,
36
- lastResetRetryId: resetInfo?.previousRetryId,
37
- lastRetryResetTime: resetInfo?.timestamp
38
- };
39
- }
40
- return {
41
- currentAttempt: retryState.retryAttempt,
42
- isFallbackShown: false,
43
- isWaiting: false,
44
- lastResetRetryId: resetInfo?.previousRetryId,
45
- lastRetryResetTime: resetInfo?.timestamp
46
- };
47
- };
48
- var currentState = getInitialStateFromUrl();
49
- var stateSubscribers = /* @__PURE__ */ new Set();
50
- var updateState = (nextState) => {
51
- currentState = nextState;
52
- stateSubscribers.forEach((cb) => {
53
- try {
54
- cb(currentState);
55
- } catch {
56
- }
57
- });
58
- };
59
- subscribe((event) => {
60
- switch (event.name) {
61
- case "fallback-ui-shown": {
62
- updateState({
63
- ...currentState,
64
- isFallbackShown: true
65
- });
66
- break;
67
- }
68
- case "retry-attempt": {
69
- updateState({
70
- ...currentState,
71
- currentAttempt: event.attempt,
72
- isFallbackShown: false,
73
- isWaiting: true
74
- });
75
- break;
76
- }
77
- case "retry-exhausted": {
78
- updateState({
79
- ...currentState,
80
- currentAttempt: event.finalAttempt,
81
- isFallbackShown: false,
82
- isWaiting: false
83
- });
84
- break;
85
- }
86
- case "retry-reset": {
87
- updateState({
88
- ...currentState,
89
- currentAttempt: 0,
90
- isFallbackShown: false,
91
- isWaiting: false,
92
- lastResetRetryId: event.previousRetryId,
93
- lastRetryResetTime: Date.now()
94
- });
95
- break;
96
- }
97
- }
98
- });
99
- var getState = () => currentState;
100
- var subscribeToState = (cb) => {
101
- cb(currentState);
102
- stateSubscribers.add(cb);
103
- return () => {
104
- stateSubscribers.delete(cb);
105
- };
106
- };
107
-
108
- export {
109
- getState,
110
- subscribeToState
111
- };