@squide/firefly 13.2.0 → 13.3.1
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/CHANGELOG.md +20 -0
- package/dist/AppRouterReducer.d.ts +4 -2
- package/dist/AppRouterReducer.js +57 -30
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/honeycomb/registerHoneycombInstrumentation.js +20 -5
- package/dist/honeycomb/registerHoneycombInstrumentation.js.map +1 -1
- package/package.json +5 -5
- package/src/AppRouterReducer.ts +46 -32
- package/src/honeycomb/registerHoneycombInstrumentation.ts +22 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @squide/firefly
|
|
2
2
|
|
|
3
|
+
## 13.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#307](https://github.com/workleap/wl-squide/pull/307) [`4bd0a34`](https://github.com/workleap/wl-squide/commit/4bd0a34b443caeb12f6c65faa5443c4a48784562) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Fix Honeycomb traces for certain usecases, including global data fetch failures.
|
|
8
|
+
|
|
9
|
+
## 13.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#302](https://github.com/workleap/wl-squide/pull/302) [`e55c60b`](https://github.com/workleap/wl-squide/commit/e55c60b8e5a3c258a5a7d667ce990f73021f8e5d) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Improved the logging API.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`e55c60b`](https://github.com/workleap/wl-squide/commit/e55c60b8e5a3c258a5a7d667ce990f73021f8e5d)]:
|
|
18
|
+
- @squide/module-federation@6.5.0
|
|
19
|
+
- @squide/react-router@7.3.0
|
|
20
|
+
- @squide/core@5.7.0
|
|
21
|
+
- @squide/msw@3.5.0
|
|
22
|
+
|
|
3
23
|
## 13.2.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type Dispatch } from "react";
|
|
2
2
|
export type ActiveRouteVisiblity = "unknown" | "public" | "protected";
|
|
3
|
-
export interface
|
|
3
|
+
export interface AppRouterWaitState {
|
|
4
4
|
waitForMsw: boolean;
|
|
5
5
|
waitForPublicData: boolean;
|
|
6
6
|
waitForProtectedData: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface AppRouterState extends AppRouterWaitState {
|
|
7
9
|
areModulesRegistered: boolean;
|
|
8
10
|
areModulesReady: boolean;
|
|
9
11
|
isMswReady: boolean;
|
|
@@ -29,13 +31,13 @@ export declare const DeferredRegistrationsUpdatedEvent = "squide-deferred-regist
|
|
|
29
31
|
export declare const ApplicationBoostrappedEvent = "squide-app-boostrapped";
|
|
30
32
|
export interface AppRouterAction {
|
|
31
33
|
type: AppRouterActionType;
|
|
34
|
+
payload?: unknown;
|
|
32
35
|
}
|
|
33
36
|
export type AppRouterDispatch = Dispatch<AppRouterAction>;
|
|
34
37
|
export declare function getAreModulesRegistered(): boolean;
|
|
35
38
|
export declare function getAreModulesReady(): boolean;
|
|
36
39
|
export declare function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch): void;
|
|
37
40
|
export declare function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRouterDispatch): void;
|
|
38
|
-
export declare function useBootstrappingCompletedDispatcher(state: AppRouterState): void;
|
|
39
41
|
export declare function __setAppReducerDispatchProxyFactory(factory: (reactDispatch: AppRouterDispatch) => AppRouterDispatch): void;
|
|
40
42
|
export declare function __clearAppReducerDispatchProxy(): void;
|
|
41
43
|
export declare function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch];
|
package/dist/AppRouterReducer.js
CHANGED
|
@@ -251,19 +251,20 @@ function useMswStatusDispatcher(isMswReadyValue, dispatch) {
|
|
|
251
251
|
dispatchMswReady
|
|
252
252
|
]);
|
|
253
253
|
}
|
|
254
|
-
function useBootstrappingCompletedDispatcher(state) {
|
|
254
|
+
function useBootstrappingCompletedDispatcher(waitState, state) {
|
|
255
255
|
const eventBus = useEventBus();
|
|
256
256
|
const areModulesRegisteredValue = state.areModulesRegistered;
|
|
257
257
|
const isBoostrapping = isBootstrapping(state);
|
|
258
258
|
useExecuteOnce(useCallback(()=>{
|
|
259
259
|
if (areModulesRegisteredValue && !isBoostrapping) {
|
|
260
|
-
eventBus.dispatch(ApplicationBoostrappedEvent);
|
|
260
|
+
eventBus.dispatch(ApplicationBoostrappedEvent, waitState);
|
|
261
261
|
return true;
|
|
262
262
|
}
|
|
263
263
|
return false;
|
|
264
264
|
}, [
|
|
265
265
|
areModulesRegisteredValue,
|
|
266
266
|
isBoostrapping,
|
|
267
|
+
waitState,
|
|
267
268
|
eventBus
|
|
268
269
|
]), true);
|
|
269
270
|
}
|
|
@@ -283,16 +284,20 @@ function useReducerDispatchProxy(reactDispatch) {
|
|
|
283
284
|
reactDispatch
|
|
284
285
|
]);
|
|
285
286
|
}
|
|
286
|
-
function useEnhancedReducerDispatch(reducerDispatch) {
|
|
287
|
+
function useEnhancedReducerDispatch(waitState, reducerDispatch) {
|
|
287
288
|
const logger = useLogger();
|
|
288
289
|
const appRouterStore = useAppRouterStore();
|
|
289
290
|
const eventBus = useEventBus();
|
|
290
291
|
return useCallback((action)=>{
|
|
291
292
|
logger.withText("[squide] The following action has been dispatched to the AppRouter reducer:").withObject(action).debug();
|
|
292
|
-
appRouterStore.dispatch(
|
|
293
|
-
|
|
293
|
+
appRouterStore.dispatch({
|
|
294
|
+
...action,
|
|
295
|
+
payload: waitState
|
|
296
|
+
});
|
|
297
|
+
eventBus.dispatch(`squide-${action.type}`, waitState);
|
|
294
298
|
reducerDispatch(action);
|
|
295
299
|
}, [
|
|
300
|
+
waitState,
|
|
296
301
|
reducerDispatch,
|
|
297
302
|
logger,
|
|
298
303
|
appRouterStore,
|
|
@@ -303,81 +308,103 @@ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
|
303
308
|
const runtime = useRuntime();
|
|
304
309
|
const eventBus = useEventBus();
|
|
305
310
|
const appRouterStore = useAppRouterStore();
|
|
311
|
+
const isMswEnabled = runtime.isMswEnabled;
|
|
306
312
|
const areModulesInitiallyRegistered = getAreModulesRegistered();
|
|
307
313
|
const areModulesInitiallyReady = getAreModulesReady();
|
|
308
314
|
const isMswInitiallyReady = isMswReady();
|
|
315
|
+
const waitState = useMemo(()=>({
|
|
316
|
+
waitForMsw: isMswEnabled,
|
|
317
|
+
waitForPublicData,
|
|
318
|
+
waitForProtectedData
|
|
319
|
+
}), [
|
|
320
|
+
isMswEnabled,
|
|
321
|
+
waitForPublicData,
|
|
322
|
+
waitForProtectedData
|
|
323
|
+
]);
|
|
324
|
+
const initialState = useMemo(()=>({
|
|
325
|
+
waitForMsw: waitState.waitForMsw,
|
|
326
|
+
waitForPublicData: waitState.waitForPublicData,
|
|
327
|
+
waitForProtectedData: waitState.waitForProtectedData,
|
|
328
|
+
// When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
|
|
329
|
+
areModulesRegistered: areModulesInitiallyRegistered,
|
|
330
|
+
areModulesReady: areModulesInitiallyReady,
|
|
331
|
+
isMswReady: isMswInitiallyReady,
|
|
332
|
+
isPublicDataReady: false,
|
|
333
|
+
isProtectedDataReady: false,
|
|
334
|
+
activeRouteVisibility: "unknown",
|
|
335
|
+
isUnauthorized: false
|
|
336
|
+
}), [
|
|
337
|
+
waitState,
|
|
338
|
+
areModulesInitiallyRegistered,
|
|
339
|
+
areModulesInitiallyReady,
|
|
340
|
+
isMswInitiallyReady
|
|
341
|
+
]);
|
|
309
342
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
310
343
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
311
344
|
useExecuteOnce(useCallback(()=>{
|
|
312
345
|
if (areModulesInitiallyRegistered) {
|
|
313
346
|
appRouterStore.dispatch({
|
|
314
|
-
type: "modules-registered"
|
|
347
|
+
type: "modules-registered",
|
|
348
|
+
payload: waitState
|
|
315
349
|
});
|
|
316
|
-
eventBus.dispatch(ModulesRegisteredEvent);
|
|
350
|
+
eventBus.dispatch(ModulesRegisteredEvent, waitState);
|
|
317
351
|
}
|
|
318
352
|
return true;
|
|
319
353
|
}, [
|
|
320
354
|
areModulesInitiallyRegistered,
|
|
321
355
|
appRouterStore,
|
|
322
|
-
eventBus
|
|
356
|
+
eventBus,
|
|
357
|
+
waitState
|
|
323
358
|
]), true);
|
|
324
359
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
325
360
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
326
361
|
useExecuteOnce(useCallback(()=>{
|
|
327
362
|
if (areModulesInitiallyReady) {
|
|
328
363
|
appRouterStore.dispatch({
|
|
329
|
-
type: "modules-ready"
|
|
364
|
+
type: "modules-ready",
|
|
365
|
+
payload: waitState
|
|
330
366
|
});
|
|
331
|
-
eventBus.dispatch(ModulesReadyEvent);
|
|
367
|
+
eventBus.dispatch(ModulesReadyEvent, waitState);
|
|
332
368
|
}
|
|
333
369
|
return true;
|
|
334
370
|
}, [
|
|
335
371
|
areModulesInitiallyReady,
|
|
336
372
|
appRouterStore,
|
|
337
|
-
eventBus
|
|
373
|
+
eventBus,
|
|
374
|
+
waitState
|
|
338
375
|
]), true);
|
|
339
376
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
340
377
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
341
378
|
useExecuteOnce(useCallback(()=>{
|
|
342
379
|
if (isMswInitiallyReady) {
|
|
343
380
|
appRouterStore.dispatch({
|
|
344
|
-
type: "msw-ready"
|
|
381
|
+
type: "msw-ready",
|
|
382
|
+
payload: waitState
|
|
345
383
|
});
|
|
346
|
-
eventBus.dispatch(MswReadyEvent);
|
|
384
|
+
eventBus.dispatch(MswReadyEvent, waitState);
|
|
347
385
|
}
|
|
348
386
|
return true;
|
|
349
387
|
}, [
|
|
350
388
|
isMswInitiallyReady,
|
|
351
389
|
appRouterStore,
|
|
352
|
-
eventBus
|
|
390
|
+
eventBus,
|
|
391
|
+
waitState
|
|
353
392
|
]), true);
|
|
354
|
-
const [state, reactDispatch] = useReducer(reducer,
|
|
355
|
-
waitForMsw: runtime.isMswEnabled,
|
|
356
|
-
waitForPublicData,
|
|
357
|
-
waitForProtectedData,
|
|
358
|
-
// When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
|
|
359
|
-
areModulesRegistered: areModulesInitiallyRegistered,
|
|
360
|
-
areModulesReady: areModulesInitiallyReady,
|
|
361
|
-
isMswReady: isMswInitiallyReady,
|
|
362
|
-
isPublicDataReady: false,
|
|
363
|
-
isProtectedDataReady: false,
|
|
364
|
-
activeRouteVisibility: "unknown",
|
|
365
|
-
isUnauthorized: false
|
|
366
|
-
});
|
|
393
|
+
const [state, reactDispatch] = useReducer(reducer, initialState);
|
|
367
394
|
const { areModulesRegistered: areModulesRegisteredValue, areModulesReady: areModulesReadyValue, isMswReady: isMswReadyValue } = state;
|
|
368
395
|
// The dispatch proxy is strictly an utility allowing tests to mock the useReducer dispatch function. It's easier
|
|
369
396
|
// than mocking the import from React.
|
|
370
397
|
const dispatchProxy = useReducerDispatchProxy(reactDispatch);
|
|
371
|
-
const dispatch = useEnhancedReducerDispatch(dispatchProxy);
|
|
398
|
+
const dispatch = useEnhancedReducerDispatch(waitState, dispatchProxy);
|
|
372
399
|
useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);
|
|
373
400
|
useMswStatusDispatcher(isMswReadyValue, dispatch);
|
|
374
|
-
useBootstrappingCompletedDispatcher(state);
|
|
401
|
+
useBootstrappingCompletedDispatcher(waitState, state);
|
|
375
402
|
return [
|
|
376
403
|
state,
|
|
377
404
|
dispatch
|
|
378
405
|
];
|
|
379
406
|
}
|
|
380
407
|
|
|
381
|
-
export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, getAreModulesReady, getAreModulesRegistered, useAppRouterReducer,
|
|
408
|
+
export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, getAreModulesReady, getAreModulesRegistered, useAppRouterReducer, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
|
|
382
409
|
|
|
383
410
|
//# sourceMappingURL=AppRouterReducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouterReducer.js","sources":["webpack://@squide/firefly/./src/AppRouterReducer.ts"],"sourcesContent":["import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useEventBus, useLogger, useRuntime } from \"@squide/core\";\nimport { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, areModulesRegistered, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from \"@squide/module-federation\";\nimport { addMswStateChangedListener, isMswReady, removeMswStateChangedListener } from \"@squide/msw\";\nimport { useCallback, useEffect, useMemo, useReducer, type Dispatch } from \"react\";\nimport type { FireflyRuntime } from \"./FireflyRuntime.tsx\";\nimport { useAppRouterStore } from \"./useAppRouterStore.ts\";\nimport { useExecuteOnce } from \"./useExecuteOnce.ts\";\nimport { isBootstrapping } from \"./useIsBootstrapping.ts\";\n\nexport type ActiveRouteVisiblity = \"unknown\" | \"public\" | \"protected\";\n\nexport interface AppRouterState {\n waitForMsw: boolean;\n waitForPublicData: boolean;\n waitForProtectedData: boolean;\n areModulesRegistered: boolean;\n areModulesReady: boolean;\n isMswReady: boolean;\n isPublicDataReady: boolean;\n isProtectedDataReady: boolean;\n publicDataUpdatedAt?: number;\n protectedDataUpdatedAt?: number;\n deferredRegistrationsUpdatedAt?: number;\n activeRouteVisibility: ActiveRouteVisiblity;\n isUnauthorized: boolean;\n}\n\nexport type AppRouterActionType =\n| \"modules-registered\"\n| \"modules-ready\"\n| \"msw-ready\"\n| \"public-data-ready\"\n| \"protected-data-ready\"\n| \"public-data-updated\"\n| \"protected-data-updated\"\n| \"deferred-registrations-updated\"\n| \"active-route-is-public\"\n| \"active-route-is-protected\"\n| \"is-unauthorized\";\n\n// The followings event const are a concatenation of \"squide-\" with AppRouterActionType.\n// They are dispatched by the useEnhancedReducerDispatch hook.\nexport const ModulesRegisteredEvent = \"squide-modules-registered\";\nexport const ModulesReadyEvent = \"squide-modules-ready\";\nexport const MswReadyEvent = \"squide-msw-ready\";\nexport const ActiveRouteIsPublicEvent = \"squide-active-route-is-public\";\nexport const ActiveRouteIsProtectedEvent = \"squide-active-route-is-protected\";\nexport const PublicDataReadyEvent = \"squide-public-data-ready\";\nexport const ProtectedDataReadyEvent = \"squide-protected-data-ready\";\nexport const PublicDataUpdatedEvent = \"squide-public-data-updated\";\nexport const ProtectedDataUpdatedEvent = \"squide-protected-data-updated\";\nexport const DeferredRegistrationsUpdatedEvent = \"squide-deferred-registrations-updated\";\nexport const ApplicationBoostrappedEvent = \"squide-app-boostrapped\";\n\nexport interface AppRouterAction {\n type: AppRouterActionType;\n}\n\nexport type AppRouterDispatch = Dispatch<AppRouterAction>;\n\nfunction reducer(state: AppRouterState, action: AppRouterAction) {\n let newState = state;\n\n switch (action.type) {\n case \"modules-registered\": {\n newState = {\n ...newState,\n areModulesRegistered: true\n };\n\n break;\n }\n case \"modules-ready\": {\n newState = {\n ...newState,\n areModulesReady: true,\n // Will be set even if the app is not using deferred registrations.\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"msw-ready\": {\n newState = {\n ...newState,\n isMswReady: true\n };\n\n break;\n }\n case \"public-data-ready\": {\n newState = {\n ...newState,\n isPublicDataReady: true,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-ready\": {\n newState = {\n ...newState,\n isProtectedDataReady: true,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"public-data-updated\": {\n newState = {\n ...newState,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-updated\": {\n newState = {\n ...newState,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"deferred-registrations-updated\": {\n newState = {\n ...newState,\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"active-route-is-public\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"public\"\n };\n\n break;\n }\n case \"active-route-is-protected\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"protected\"\n };\n\n break;\n }\n case \"is-unauthorized\": {\n newState = {\n ...newState,\n isUnauthorized: true\n };\n\n break;\n }\n default: {\n throw new Error(`[squide] The AppRouter component state reducer doesn't support action type \"${action.type}\".`);\n }\n }\n\n return newState;\n}\n\nexport function getAreModulesRegistered() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesRegistered(localModuleStatus, remoteModuleStatus);\n}\n\nexport function getAreModulesReady() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesReady(localModuleStatus, remoteModuleStatus);\n}\n\nexport function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchModulesRegistered = useExecuteOnce(useCallback(() => {\n if (getAreModulesRegistered()) {\n dispatch({ type: \"modules-registered\" });\n\n logger\n .withText(\"[squide]\")\n .withText(\"Modules are registered\", {\n style: {\n color: \"white\",\n backgroundColor: \"green\"\n }\n })\n .withText(\".\", {\n leadingSpace: false\n })\n .information();\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n const dispatchModulesReady = useExecuteOnce(useCallback(() => {\n if (getAreModulesReady()) {\n dispatch({ type: \"modules-ready\" });\n\n logger\n .withText(\"[squide]\")\n .withText(\"Modules are ready\", {\n style: {\n color: \"white\",\n backgroundColor: \"green\"\n }\n })\n .withText(\".\", {\n leadingSpace: false\n })\n .information();\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n return useEffect(() => {\n if (!areModulesRegisteredValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n }\n\n if (!areModulesReadyValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n }\n\n return () => {\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n };\n }, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);\n}\n\nexport function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchMswReady = useExecuteOnce(useCallback(() => {\n if (isMswReady()) {\n dispatch({ type: \"msw-ready\" });\n\n logger\n .withText(\"[squide]\")\n .withText(\"MSW is ready\", {\n style: {\n color: \"white\",\n backgroundColor: \"green\"\n }\n })\n .withText(\".\", {\n leadingSpace: false\n })\n .information();\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n useEffect(() => {\n if (!isMswReadyValue) {\n addMswStateChangedListener(dispatchMswReady);\n }\n\n return () => {\n removeMswStateChangedListener(dispatchMswReady);\n };\n }, [isMswReadyValue, dispatchMswReady]);\n}\n\nexport function useBootstrappingCompletedDispatcher(state: AppRouterState) {\n const eventBus = useEventBus();\n\n const areModulesRegisteredValue = state.areModulesRegistered;\n const isBoostrapping = isBootstrapping(state);\n\n useExecuteOnce(useCallback(() => {\n if (areModulesRegisteredValue && !isBoostrapping) {\n eventBus.dispatch(ApplicationBoostrappedEvent);\n\n return true;\n }\n\n return false;\n }, [areModulesRegisteredValue, isBoostrapping, eventBus]), true);\n}\n\nlet dispatchProxyFactory: ((reactDispatch: AppRouterDispatch) => AppRouterDispatch) | undefined;\n\n// This function should only be used by tests.\nexport function __setAppReducerDispatchProxyFactory(factory: (reactDispatch: AppRouterDispatch) => AppRouterDispatch) {\n dispatchProxyFactory = factory;\n}\n\n// This function should only be used by tests.\nexport function __clearAppReducerDispatchProxy() {\n dispatchProxyFactory = undefined;\n}\n\nfunction useReducerDispatchProxy(reactDispatch: AppRouterDispatch) {\n return useMemo(() => {\n return dispatchProxyFactory ? dispatchProxyFactory(reactDispatch) : reactDispatch;\n }, [reactDispatch]);\n}\n\nfunction useEnhancedReducerDispatch(reducerDispatch: AppRouterDispatch) {\n const logger = useLogger();\n const appRouterStore = useAppRouterStore();\n const eventBus = useEventBus();\n\n return useCallback((action: AppRouterAction) => {\n logger\n .withText(\"[squide] The following action has been dispatched to the AppRouter reducer:\")\n .withObject(action)\n .debug();\n\n appRouterStore.dispatch(action);\n eventBus.dispatch(`squide-${action.type}`);\n\n reducerDispatch(action);\n }, [reducerDispatch, logger, appRouterStore, eventBus]);\n}\n\nexport function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {\n const runtime = useRuntime() as FireflyRuntime;\n const eventBus = useEventBus();\n const appRouterStore = useAppRouterStore();\n\n const areModulesInitiallyRegistered = getAreModulesRegistered();\n const areModulesInitiallyReady = getAreModulesReady();\n const isMswInitiallyReady = isMswReady();\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyRegistered) {\n appRouterStore.dispatch({ type: \"modules-registered\" });\n eventBus.dispatch(ModulesRegisteredEvent);\n }\n\n return true;\n }, [areModulesInitiallyRegistered, appRouterStore, eventBus]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyReady) {\n appRouterStore.dispatch({ type: \"modules-ready\" });\n eventBus.dispatch(ModulesReadyEvent);\n }\n\n return true;\n }, [areModulesInitiallyReady, appRouterStore, eventBus]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (isMswInitiallyReady) {\n appRouterStore.dispatch({ type: \"msw-ready\" });\n eventBus.dispatch(MswReadyEvent);\n }\n\n return true;\n }, [isMswInitiallyReady, appRouterStore, eventBus]), true);\n\n const [state, reactDispatch] = useReducer(reducer, {\n waitForMsw: runtime.isMswEnabled,\n waitForPublicData,\n waitForProtectedData,\n // When the modules registration functions are awaited, the event listeners are registered after the modules are registered.\n areModulesRegistered: areModulesInitiallyRegistered,\n areModulesReady: areModulesInitiallyReady,\n isMswReady: isMswInitiallyReady,\n isPublicDataReady: false,\n isProtectedDataReady: false,\n activeRouteVisibility: \"unknown\",\n isUnauthorized: false\n });\n\n const {\n areModulesRegistered: areModulesRegisteredValue,\n areModulesReady: areModulesReadyValue,\n isMswReady: isMswReadyValue\n } = state;\n\n // The dispatch proxy is strictly an utility allowing tests to mock the useReducer dispatch function. It's easier\n // than mocking the import from React.\n const dispatchProxy = useReducerDispatchProxy(reactDispatch);\n const dispatch = useEnhancedReducerDispatch(dispatchProxy);\n\n useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);\n useMswStatusDispatcher(isMswReadyValue, dispatch);\n useBootstrappingCompletedDispatcher(state);\n\n return [state, dispatch];\n}\n"],"names":["addLocalModuleRegistrationStatusChangedListener","getLocalModuleRegistrationStatus","removeLocalModuleRegistrationStatusChangedListener","useEventBus","useLogger","useRuntime","addRemoteModuleRegistrationStatusChangedListener","areModulesReady","areModulesRegistered","getRemoteModuleRegistrationStatus","removeRemoteModuleRegistrationStatusChangedListener","addMswStateChangedListener","isMswReady","removeMswStateChangedListener","useCallback","useEffect","useMemo","useReducer","useAppRouterStore","useExecuteOnce","isBootstrapping","ModulesRegisteredEvent","ModulesReadyEvent","MswReadyEvent","ActiveRouteIsPublicEvent","ActiveRouteIsProtectedEvent","PublicDataReadyEvent","ProtectedDataReadyEvent","PublicDataUpdatedEvent","ProtectedDataUpdatedEvent","DeferredRegistrationsUpdatedEvent","ApplicationBoostrappedEvent","reducer","state","action","newState","Date","Error","getAreModulesRegistered","localModuleStatus","remoteModuleStatus","getAreModulesReady","useModuleRegistrationStatusDispatcher","areModulesRegisteredValue","areModulesReadyValue","dispatch","logger","dispatchModulesRegistered","dispatchModulesReady","useMswStatusDispatcher","isMswReadyValue","dispatchMswReady","useBootstrappingCompletedDispatcher","eventBus","isBoostrapping","dispatchProxyFactory","__setAppReducerDispatchProxyFactory","factory","__clearAppReducerDispatchProxy","undefined","useReducerDispatchProxy","reactDispatch","useEnhancedReducerDispatch","reducerDispatch","appRouterStore","useAppRouterReducer","waitForPublicData","waitForProtectedData","runtime","areModulesInitiallyRegistered","areModulesInitiallyReady","isMswInitiallyReady","dispatchProxy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAyM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ppRouterReducer.ts"],"sourcesContent":["import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useEventBus, useLogger, useRuntime } from \"@squide/core\";\nimport { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, areModulesRegistered, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from \"@squide/module-federation\";\nimport { addMswStateChangedListener, isMswReady, removeMswStateChangedListener } from \"@squide/msw\";\nimport { useCallback, useEffect, useMemo, useReducer, type Dispatch } from \"react\";\nimport type { FireflyRuntime } from \"./FireflyRuntime.tsx\";\nimport { useAppRouterStore } from \"./useAppRouterStore.ts\";\nimport { useExecuteOnce } from \"./useExecuteOnce.ts\";\nimport { isBootstrapping } from \"./useIsBootstrapping.ts\";\n\nexport type ActiveRouteVisiblity = \"unknown\" | \"public\" | \"protected\";\n\nexport interface AppRouterWaitState {\n waitForMsw: boolean;\n waitForPublicData: boolean;\n waitForProtectedData: boolean;\n}\n\nexport interface AppRouterState extends AppRouterWaitState {\n areModulesRegistered: boolean;\n areModulesReady: boolean;\n isMswReady: boolean;\n isPublicDataReady: boolean;\n isProtectedDataReady: boolean;\n publicDataUpdatedAt?: number;\n protectedDataUpdatedAt?: number;\n deferredRegistrationsUpdatedAt?: number;\n activeRouteVisibility: ActiveRouteVisiblity;\n isUnauthorized: boolean;\n}\n\nexport type AppRouterActionType =\n| \"modules-registered\"\n| \"modules-ready\"\n| \"msw-ready\"\n| \"public-data-ready\"\n| \"protected-data-ready\"\n| \"public-data-updated\"\n| \"protected-data-updated\"\n| \"deferred-registrations-updated\"\n| \"active-route-is-public\"\n| \"active-route-is-protected\"\n| \"is-unauthorized\";\n\n// The followings event const are a concatenation of \"squide-\" with AppRouterActionType.\n// They are dispatched by the useEnhancedReducerDispatch hook.\nexport const ModulesRegisteredEvent = \"squide-modules-registered\";\nexport const ModulesReadyEvent = \"squide-modules-ready\";\nexport const MswReadyEvent = \"squide-msw-ready\";\nexport const ActiveRouteIsPublicEvent = \"squide-active-route-is-public\";\nexport const ActiveRouteIsProtectedEvent = \"squide-active-route-is-protected\";\nexport const PublicDataReadyEvent = \"squide-public-data-ready\";\nexport const ProtectedDataReadyEvent = \"squide-protected-data-ready\";\nexport const PublicDataUpdatedEvent = \"squide-public-data-updated\";\nexport const ProtectedDataUpdatedEvent = \"squide-protected-data-updated\";\nexport const DeferredRegistrationsUpdatedEvent = \"squide-deferred-registrations-updated\";\nexport const ApplicationBoostrappedEvent = \"squide-app-boostrapped\";\n\nexport interface AppRouterAction {\n type: AppRouterActionType;\n payload?: unknown;\n}\n\nexport type AppRouterDispatch = Dispatch<AppRouterAction>;\n\nfunction reducer(state: AppRouterState, action: AppRouterAction) {\n let newState = state;\n\n switch (action.type) {\n case \"modules-registered\": {\n newState = {\n ...newState,\n areModulesRegistered: true\n };\n\n break;\n }\n case \"modules-ready\": {\n newState = {\n ...newState,\n areModulesReady: true,\n // Will be set even if the app is not using deferred registrations.\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"msw-ready\": {\n newState = {\n ...newState,\n isMswReady: true\n };\n\n break;\n }\n case \"public-data-ready\": {\n newState = {\n ...newState,\n isPublicDataReady: true,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-ready\": {\n newState = {\n ...newState,\n isProtectedDataReady: true,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"public-data-updated\": {\n newState = {\n ...newState,\n publicDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"protected-data-updated\": {\n newState = {\n ...newState,\n protectedDataUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"deferred-registrations-updated\": {\n newState = {\n ...newState,\n deferredRegistrationsUpdatedAt: Date.now()\n };\n\n break;\n }\n case \"active-route-is-public\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"public\"\n };\n\n break;\n }\n case \"active-route-is-protected\": {\n newState = {\n ...newState,\n activeRouteVisibility: \"protected\"\n };\n\n break;\n }\n case \"is-unauthorized\": {\n newState = {\n ...newState,\n isUnauthorized: true\n };\n\n break;\n }\n default: {\n throw new Error(`[squide] The AppRouter component state reducer doesn't support action type \"${action.type}\".`);\n }\n }\n\n return newState;\n}\n\nexport function getAreModulesRegistered() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesRegistered(localModuleStatus, remoteModuleStatus);\n}\n\nexport function getAreModulesReady() {\n const localModuleStatus = getLocalModuleRegistrationStatus();\n const remoteModuleStatus = getRemoteModuleRegistrationStatus();\n\n return areModulesReady(localModuleStatus, remoteModuleStatus);\n}\n\nexport function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchModulesRegistered = useExecuteOnce(useCallback(() => {\n if (getAreModulesRegistered()) {\n dispatch({ type: \"modules-registered\" });\n\n logger\n .withText(\"[squide]\")\n .withText(\"Modules are registered\", {\n style: {\n color: \"white\",\n backgroundColor: \"green\"\n }\n })\n .withText(\".\", {\n leadingSpace: false\n })\n .information();\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n const dispatchModulesReady = useExecuteOnce(useCallback(() => {\n if (getAreModulesReady()) {\n dispatch({ type: \"modules-ready\" });\n\n logger\n .withText(\"[squide]\")\n .withText(\"Modules are ready\", {\n style: {\n color: \"white\",\n backgroundColor: \"green\"\n }\n })\n .withText(\".\", {\n leadingSpace: false\n })\n .information();\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n return useEffect(() => {\n if (!areModulesRegisteredValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n }\n\n if (!areModulesReadyValue) {\n addLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n addRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n }\n\n return () => {\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);\n\n removeLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);\n removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);\n };\n }, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);\n}\n\nexport function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchMswReady = useExecuteOnce(useCallback(() => {\n if (isMswReady()) {\n dispatch({ type: \"msw-ready\" });\n\n logger\n .withText(\"[squide]\")\n .withText(\"MSW is ready\", {\n style: {\n color: \"white\",\n backgroundColor: \"green\"\n }\n })\n .withText(\".\", {\n leadingSpace: false\n })\n .information();\n\n return true;\n }\n\n return false;\n }, [dispatch, logger]));\n\n useEffect(() => {\n if (!isMswReadyValue) {\n addMswStateChangedListener(dispatchMswReady);\n }\n\n return () => {\n removeMswStateChangedListener(dispatchMswReady);\n };\n }, [isMswReadyValue, dispatchMswReady]);\n}\n\nfunction useBootstrappingCompletedDispatcher(waitState: AppRouterWaitState, state: AppRouterState) {\n const eventBus = useEventBus();\n\n const areModulesRegisteredValue = state.areModulesRegistered;\n const isBoostrapping = isBootstrapping(state);\n\n useExecuteOnce(useCallback(() => {\n if (areModulesRegisteredValue && !isBoostrapping) {\n eventBus.dispatch(ApplicationBoostrappedEvent, waitState);\n\n return true;\n }\n\n return false;\n }, [areModulesRegisteredValue, isBoostrapping, waitState, eventBus]), true);\n}\n\nlet dispatchProxyFactory: ((reactDispatch: AppRouterDispatch) => AppRouterDispatch) | undefined;\n\n// This function should only be used by tests.\nexport function __setAppReducerDispatchProxyFactory(factory: (reactDispatch: AppRouterDispatch) => AppRouterDispatch) {\n dispatchProxyFactory = factory;\n}\n\n// This function should only be used by tests.\nexport function __clearAppReducerDispatchProxy() {\n dispatchProxyFactory = undefined;\n}\n\nfunction useReducerDispatchProxy(reactDispatch: AppRouterDispatch) {\n return useMemo(() => {\n return dispatchProxyFactory ? dispatchProxyFactory(reactDispatch) : reactDispatch;\n }, [reactDispatch]);\n}\n\nfunction useEnhancedReducerDispatch(waitState: AppRouterWaitState, reducerDispatch: AppRouterDispatch) {\n const logger = useLogger();\n const appRouterStore = useAppRouterStore();\n const eventBus = useEventBus();\n\n return useCallback((action: AppRouterAction) => {\n logger\n .withText(\"[squide] The following action has been dispatched to the AppRouter reducer:\")\n .withObject(action)\n .debug();\n\n appRouterStore.dispatch({ ...action, payload: waitState });\n eventBus.dispatch(`squide-${action.type}`, waitState);\n\n reducerDispatch(action);\n }, [waitState, reducerDispatch, logger, appRouterStore, eventBus]);\n}\n\nexport function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {\n const runtime = useRuntime() as FireflyRuntime;\n const eventBus = useEventBus();\n const appRouterStore = useAppRouterStore();\n\n const isMswEnabled = runtime.isMswEnabled;\n\n const areModulesInitiallyRegistered = getAreModulesRegistered();\n const areModulesInitiallyReady = getAreModulesReady();\n const isMswInitiallyReady = isMswReady();\n\n const waitState = useMemo(() => ({\n waitForMsw: isMswEnabled,\n waitForPublicData,\n waitForProtectedData\n }), [isMswEnabled, waitForPublicData, waitForProtectedData]);\n\n const initialState = useMemo(() => ({\n waitForMsw: waitState.waitForMsw,\n waitForPublicData: waitState.waitForPublicData,\n waitForProtectedData: waitState.waitForProtectedData,\n // When the modules registration functions are awaited, the event listeners are registered after the modules are registered.\n areModulesRegistered: areModulesInitiallyRegistered,\n areModulesReady: areModulesInitiallyReady,\n isMswReady: isMswInitiallyReady,\n isPublicDataReady: false,\n isProtectedDataReady: false,\n activeRouteVisibility: \"unknown\",\n isUnauthorized: false\n } satisfies AppRouterState), [waitState, areModulesInitiallyRegistered, areModulesInitiallyReady, isMswInitiallyReady]);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyRegistered) {\n appRouterStore.dispatch({ type: \"modules-registered\", payload: waitState });\n eventBus.dispatch(ModulesRegisteredEvent, waitState);\n }\n\n return true;\n }, [areModulesInitiallyRegistered, appRouterStore, eventBus, waitState]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (areModulesInitiallyReady) {\n appRouterStore.dispatch({ type: \"modules-ready\", payload: waitState });\n eventBus.dispatch(ModulesReadyEvent, waitState);\n }\n\n return true;\n }, [areModulesInitiallyReady, appRouterStore, eventBus, waitState]), true);\n\n // When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.\n // To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.\n useExecuteOnce(useCallback(() => {\n if (isMswInitiallyReady) {\n appRouterStore.dispatch({ type: \"msw-ready\", payload: waitState });\n eventBus.dispatch(MswReadyEvent, waitState);\n }\n\n return true;\n }, [isMswInitiallyReady, appRouterStore, eventBus, waitState]), true);\n\n const [state, reactDispatch] = useReducer(reducer, initialState);\n\n const {\n areModulesRegistered: areModulesRegisteredValue,\n areModulesReady: areModulesReadyValue,\n isMswReady: isMswReadyValue\n } = state;\n\n // The dispatch proxy is strictly an utility allowing tests to mock the useReducer dispatch function. It's easier\n // than mocking the import from React.\n const dispatchProxy = useReducerDispatchProxy(reactDispatch);\n const dispatch = useEnhancedReducerDispatch(waitState, dispatchProxy);\n\n useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);\n useMswStatusDispatcher(isMswReadyValue, dispatch);\n useBootstrappingCompletedDispatcher(waitState, state);\n\n return [state, dispatch];\n}\n"],"names":["addLocalModuleRegistrationStatusChangedListener","getLocalModuleRegistrationStatus","removeLocalModuleRegistrationStatusChangedListener","useEventBus","useLogger","useRuntime","addRemoteModuleRegistrationStatusChangedListener","areModulesReady","areModulesRegistered","getRemoteModuleRegistrationStatus","removeRemoteModuleRegistrationStatusChangedListener","addMswStateChangedListener","isMswReady","removeMswStateChangedListener","useCallback","useEffect","useMemo","useReducer","useAppRouterStore","useExecuteOnce","isBootstrapping","ModulesRegisteredEvent","ModulesReadyEvent","MswReadyEvent","ActiveRouteIsPublicEvent","ActiveRouteIsProtectedEvent","PublicDataReadyEvent","ProtectedDataReadyEvent","PublicDataUpdatedEvent","ProtectedDataUpdatedEvent","DeferredRegistrationsUpdatedEvent","ApplicationBoostrappedEvent","reducer","state","action","newState","Date","Error","getAreModulesRegistered","localModuleStatus","remoteModuleStatus","getAreModulesReady","useModuleRegistrationStatusDispatcher","areModulesRegisteredValue","areModulesReadyValue","dispatch","logger","dispatchModulesRegistered","dispatchModulesReady","useMswStatusDispatcher","isMswReadyValue","dispatchMswReady","useBootstrappingCompletedDispatcher","waitState","eventBus","isBoostrapping","dispatchProxyFactory","__setAppReducerDispatchProxyFactory","factory","__clearAppReducerDispatchProxy","undefined","useReducerDispatchProxy","reactDispatch","useEnhancedReducerDispatch","reducerDispatch","appRouterStore","useAppRouterReducer","waitForPublicData","waitForProtectedData","runtime","isMswEnabled","areModulesInitiallyRegistered","areModulesInitiallyReady","isMswInitiallyReady","initialState","dispatchProxy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAyM;AACmB;AACxH;AACjB;AAExB;AACN;AACK;AAoC1D,wFAAwF;AACxF,8DAA8D;AACvD,MAAMqB,yBAAyB,4BAA4B;AAC3D,MAAMC,oBAAoB,uBAAuB;AACjD,MAAMC,gBAAgB,mBAAmB;AACzC,MAAMC,2BAA2B,gCAAgC;AACjE,MAAMC,8BAA8B,mCAAmC;AACvE,MAAMC,uBAAuB,2BAA2B;AACxD,MAAMC,0BAA0B,8BAA8B;AAC9D,MAAMC,yBAAyB,6BAA6B;AAC5D,MAAMC,4BAA4B,gCAAgC;AACl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BAAuBC,iBAAiBL;IACxCO,oCAAoCC,WAAWpB;IAE/C,OAAO;QAACA;QAAOY;KAAS;AAC5B"}
|
|
@@ -47,10 +47,15 @@ function reduceDataFetchEvents(runtime, onDataFetchStarted, onDataReady, onPubli
|
|
|
47
47
|
}, {
|
|
48
48
|
once: true
|
|
49
49
|
});
|
|
50
|
-
runtime.eventBus.addListener(PublicDataReadyEvent, ()=>{
|
|
50
|
+
runtime.eventBus.addListener(PublicDataReadyEvent, (payload)=>{
|
|
51
51
|
onPublicDataReady();
|
|
52
52
|
if (dataFetchState === "fetching-data") {
|
|
53
|
-
|
|
53
|
+
if (payload && !payload.waitForProtectedData) {
|
|
54
|
+
dataFetchState = "data-ready";
|
|
55
|
+
onDataReady();
|
|
56
|
+
} else {
|
|
57
|
+
dataFetchState = "public-data-ready";
|
|
58
|
+
}
|
|
54
59
|
} else if (dataFetchState === "protected-data-ready") {
|
|
55
60
|
dataFetchState = "data-ready";
|
|
56
61
|
onDataReady();
|
|
@@ -67,10 +72,15 @@ function reduceDataFetchEvents(runtime, onDataFetchStarted, onDataReady, onPubli
|
|
|
67
72
|
}, {
|
|
68
73
|
once: true
|
|
69
74
|
});
|
|
70
|
-
runtime.eventBus.addListener(ProtectedDataReadyEvent, ()=>{
|
|
75
|
+
runtime.eventBus.addListener(ProtectedDataReadyEvent, (payload)=>{
|
|
71
76
|
onProtectedDataReady();
|
|
72
77
|
if (dataFetchState === "fetching-data") {
|
|
73
|
-
|
|
78
|
+
if (payload && !payload.waitForPublicData) {
|
|
79
|
+
dataFetchState = "data-ready";
|
|
80
|
+
onDataReady();
|
|
81
|
+
} else {
|
|
82
|
+
dataFetchState = "protected-data-ready";
|
|
83
|
+
}
|
|
74
84
|
} else if (dataFetchState === "public-data-ready") {
|
|
75
85
|
dataFetchState = "data-ready";
|
|
76
86
|
onDataReady();
|
|
@@ -300,7 +310,12 @@ function registerTrackingListeners(runtime) {
|
|
|
300
310
|
queriesErrors.forEach((x)=>{
|
|
301
311
|
traceError(dataFetchSpan.instance, x);
|
|
302
312
|
});
|
|
303
|
-
dataFetchSpan
|
|
313
|
+
endActiveSpan(dataFetchSpan);
|
|
314
|
+
// Global data fetch errors are unmanaged, which mean the host application bootstrapping flow
|
|
315
|
+
// will be aborted and a react-router error boundary will be rendered.
|
|
316
|
+
if (bootstrappingSpan) {
|
|
317
|
+
bootstrappingSpan.end();
|
|
318
|
+
}
|
|
304
319
|
}
|
|
305
320
|
};
|
|
306
321
|
reduceDataFetchEvents(runtime, handleFetchDataStarted, handleDataReady, handlePublicDataFetchStarted, handlePublicDataReady, handleProtectedDataFetchStarted, handleProtectedDataReady, handleDataFetchFailed);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"honeycomb/registerHoneycombInstrumentation.js","sources":["webpack://@squide/firefly/./src/honeycomb/registerHoneycombInstrumentation.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport {\n LocalModuleDeferredRegistrationFailedEvent,\n LocalModuleDeferredRegistrationUpdateFailedEvent,\n LocalModuleRegistrationFailedEvent,\n LocalModulesDeferredRegistrationCompletedEvent,\n type LocalModulesDeferredRegistrationCompletedEventPayload,\n LocalModulesDeferredRegistrationStartedEvent,\n type LocalModulesDeferredRegistrationStartedEventPayload,\n LocalModulesDeferredRegistrationsUpdateCompletedEvent,\n type LocalModulesDeferredRegistrationsUpdateCompletedEventPayload,\n LocalModulesDeferredRegistrationsUpdateStartedEvent,\n type LocalModulesDeferredRegistrationsUpdateStartedEventPayload,\n LocalModulesRegistrationCompletedEvent,\n type LocalModulesRegistrationCompletedEventPayload,\n LocalModulesRegistrationStartedEvent,\n type LocalModulesRegistrationStartedEventPayload,\n type ModuleRegistrationError\n} from \"@squide/core\";\nimport {\n DeferredRegistrationsUpdateCompletedEvent,\n DeferredRegistrationsUpdateStartedEvent,\n RemoteModuleDeferredRegistrationFailedEvent,\n RemoteModuleDeferredRegistrationUpdateFailedEvent,\n type RemoteModuleRegistrationError,\n RemoteModuleRegistrationFailedEvent,\n RemoteModulesDeferredRegistrationCompletedEvent,\n type RemoteModulesDeferredRegistrationCompletedEventPayload,\n RemoteModulesDeferredRegistrationStartedEvent,\n type RemoteModulesDeferredRegistrationStartedEventPayload,\n RemoteModulesDeferredRegistrationsUpdateCompletedEvent,\n type RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload,\n RemoteModulesDeferredRegistrationsUpdateStartedEvent,\n type RemoteModulesDeferredRegistrationsUpdateStartedEventPayload,\n RemoteModulesRegistrationCompletedEvent,\n type RemoteModulesRegistrationCompletedEventPayload,\n RemoteModulesRegistrationStartedEvent,\n type RemoteModulesRegistrationStartedEventPayload\n} from \"@squide/module-federation\";\nimport { ApplicationBoostrappedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from \"../AppRouterReducer.ts\";\nimport type { FireflyRuntime } from \"../FireflyRuntime.tsx\";\nimport { ApplicationBootstrappingStartedEvent } from \"../initializeFirefly.ts\";\nimport { ProtectedDataFetchFailedEvent, ProtectedDataFetchStartedEvent } from \"../useProtectedDataQueries.ts\";\nimport { PublicDataFetchFailedEvent, PublicDataFetchStartedEvent } from \"../usePublicDataQueries.ts\";\nimport { type ActiveSpan, createOverrideFetchRequestSpanWithActiveSpanContext, registerActiveSpanStack } from \"./activeSpan.ts\";\nimport { getTracer } from \"./tracer.ts\";\nimport { endActiveSpan, startActiveChildSpan, startChildSpan, startSpan, traceError } from \"./utils.ts\";\n\n// TIPS:\n// To query those traces in Honeycomb, use the following query filter: \"root.name = squide-bootstrapping\".\n\ntype DataFetchState = \"none\" | \"fetching-data\" | \"public-data-ready\" | \"protected-data-ready\" | \"data-ready\" | \"data-fetch-failed\";\n\nexport function reduceDataFetchEvents(\n runtime: FireflyRuntime,\n onDataFetchStarted: () => void,\n onDataReady: () => void,\n onPublicDataFetchStarted: () => void,\n onPublicDataReady: () => void,\n onProtectedDataFetchStarted: () => void,\n onProtectedDataReady: () => void,\n onDataFetchFailed: (queriesErrors: Error[]) => void\n) {\n let dataFetchState: DataFetchState = \"none\";\n\n runtime.eventBus.addListener(PublicDataFetchStartedEvent, () => {\n if (dataFetchState === \"none\") {\n dataFetchState = \"fetching-data\";\n onDataFetchStarted();\n }\n\n onPublicDataFetchStarted();\n }, { once: true });\n\n runtime.eventBus.addListener(PublicDataReadyEvent, () => {\n onPublicDataReady();\n\n if (dataFetchState === \"fetching-data\") {\n dataFetchState = \"public-data-ready\";\n } else if (dataFetchState === \"protected-data-ready\") {\n dataFetchState = \"data-ready\";\n onDataReady();\n }\n }, { once: true });\n\n runtime.eventBus.addListener(ProtectedDataFetchStartedEvent, () => {\n if (dataFetchState === \"none\") {\n dataFetchState = \"fetching-data\";\n onDataFetchStarted();\n }\n\n onProtectedDataFetchStarted();\n }, { once: true });\n\n runtime.eventBus.addListener(ProtectedDataReadyEvent, () => {\n onProtectedDataReady();\n\n if (dataFetchState === \"fetching-data\") {\n dataFetchState = \"protected-data-ready\";\n } else if (dataFetchState === \"public-data-ready\") {\n dataFetchState = \"data-ready\";\n onDataReady();\n }\n }, { once: true });\n\n const handleDataFetchFailed = (payload: unknown) => {\n if (dataFetchState !== \"data-fetch-failed\") {\n dataFetchState = \"data-fetch-failed\";\n\n onDataFetchFailed(payload as Error[]);\n }\n };\n\n runtime.eventBus.addListener(PublicDataFetchFailedEvent, handleDataFetchFailed, { once: true });\n runtime.eventBus.addListener(ProtectedDataFetchFailedEvent, handleDataFetchFailed, { once: true });\n}\n\nfunction registerTrackingListeners(runtime: FireflyRuntime) {\n let bootstrappingSpan: Span;\n let localModuleRegistrationSpan: Span;\n let localModuleDeferredRegistrationSpan: Span;\n let remoteModuleRegistrationSpan: Span;\n let remoteModuleDeferredRegistrationSpan: Span;\n let dataFetchSpan: ActiveSpan;\n let deferredRegistrationsUpdateSpan: Span;\n let localModuleDeferredRegistrationsUpdateSpan: ActiveSpan;\n let remoteModuleDeferredRegistrationsUpdateSpan: ActiveSpan;\n\n runtime.eventBus.addListener(ApplicationBootstrappingStartedEvent, () => {\n bootstrappingSpan = startSpan((options, context) => getTracer().startSpan(\"squide-bootstrapping\", options, context));\n }, { once: true });\n\n runtime.eventBus.addListener(ApplicationBoostrappedEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.end();\n }\n }, { once: true });\n\n runtime.eventBus.addListener(MswReadyEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"msw-ready\");\n }\n }, { once: true });\n\n runtime.eventBus.addListener(LocalModulesRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.module_count\": (payload as LocalModulesRegistrationStartedEventPayload).moduleCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-registration-started\", attributes);\n }\n\n localModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"local-module-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(LocalModulesRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-registration-completed\", {\n \"app.squide.module_count\": (payload as LocalModulesRegistrationCompletedEventPayload).moduleCount\n });\n }\n\n if (localModuleRegistrationSpan) {\n localModuleRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModuleRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as ModuleRegistrationError;\n\n if (localModuleRegistrationSpan) {\n traceError(localModuleRegistrationSpan, registrationError);\n }\n });\n\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationStartedEventPayload).registrationCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-deferred-registration-started\", attributes);\n }\n\n localModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"local-module-deferred-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-deferred-registration-completed\", {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationCompletedEventPayload).registrationCount\n });\n }\n\n if (localModuleDeferredRegistrationSpan) {\n localModuleDeferredRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModuleDeferredRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as ModuleRegistrationError;\n\n if (localModuleDeferredRegistrationSpan) {\n traceError(localModuleRegistrationSpan, registrationError);\n }\n });\n\n runtime.eventBus.addListener(RemoteModulesRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.remote_count\": (payload as RemoteModulesRegistrationStartedEventPayload).remoteCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-started\", attributes);\n }\n\n remoteModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(RemoteModulesRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-completed\", {\n \"app.squide.remote_count\": (payload as RemoteModulesRegistrationCompletedEventPayload).remoteCount\n });\n }\n\n if (remoteModuleRegistrationSpan) {\n remoteModuleRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModuleRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleRegistrationSpan) {\n traceError(remoteModuleRegistrationSpan, registrationError);\n }\n });\n\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationStartedEventPayload).registrationCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-deferred-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-completed\", {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationCompletedEventPayload).registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationSpan) {\n remoteModuleDeferredRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModuleDeferredRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleDeferredRegistrationSpan) {\n traceError(remoteModuleDeferredRegistrationSpan, registrationError);\n }\n });\n\n const handleFetchDataStarted = () => {\n dataFetchSpan = startActiveChildSpan(bootstrappingSpan, (options, context) => {\n const name = \"data-fetch\";\n const span = getTracer().startSpan(name, options, context);\n\n return {\n name,\n span\n };\n });\n };\n\n const handleDataReady = () => {\n if (dataFetchSpan) {\n endActiveSpan(dataFetchSpan);\n }\n };\n\n const handlePublicDataFetchStarted = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"public-data-fetch-started\");\n }\n };\n\n const handlePublicDataReady = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"public-data-ready\");\n }\n };\n\n const handleProtectedDataFetchStarted = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"protected-data-fetch-started\");\n }\n };\n\n const handleProtectedDataReady = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"protected-data-ready\");\n }\n };\n\n const handleDataFetchFailed = (queriesErrors: Error[]) => {\n if (dataFetchSpan) {\n queriesErrors.forEach(x => {\n traceError(dataFetchSpan.instance, x);\n });\n\n dataFetchSpan.instance.end();\n }\n };\n\n reduceDataFetchEvents(\n runtime,\n handleFetchDataStarted,\n handleDataReady,\n handlePublicDataFetchStarted,\n handlePublicDataReady,\n handleProtectedDataFetchStarted,\n handleProtectedDataReady,\n handleDataFetchFailed\n );\n\n runtime.eventBus.addListener(ModulesRegisteredEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"modules-registered\");\n }\n }, { once: true });\n\n runtime.eventBus.addListener(ModulesReadyEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"modules-ready\");\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(DeferredRegistrationsUpdateStartedEvent, () => {\n deferredRegistrationsUpdateSpan = startSpan((options, context) => getTracer().startSpan(\"squide-deferred-registrations-update\", options, context));\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(DeferredRegistrationsUpdateCompletedEvent, () => {\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.end();\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount\n };\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"local-module-deferred-registrations-update-started\", attributes);\n }\n\n localModuleDeferredRegistrationsUpdateSpan = startActiveChildSpan(deferredRegistrationsUpdateSpan, (options, context) => {\n const name = \"local-module-deferred-registrations-update\";\n\n const span = getTracer().startSpan(name, {\n attributes,\n ...options\n }, context);\n\n return {\n name,\n span\n };\n });\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"local-module-deferred-registrations-update-completed\", {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount\n });\n }\n\n if (localModuleDeferredRegistrationsUpdateSpan) {\n endActiveSpan(localModuleDeferredRegistrationsUpdateSpan);\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {\n const registrationError = payload as ModuleRegistrationError;\n\n if (localModuleDeferredRegistrationsUpdateSpan) {\n traceError(localModuleDeferredRegistrationsUpdateSpan.instance, registrationError);\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount\n };\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationsUpdateSpan = startActiveChildSpan(deferredRegistrationsUpdateSpan, (options, context) => {\n const name = \"remote-module-deferred-registrations-update\";\n\n const span = getTracer().startSpan(name, {\n attributes,\n ...options\n }, context);\n\n return {\n name,\n span\n };\n });\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-completed\", {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n endActiveSpan(remoteModuleDeferredRegistrationsUpdateSpan);\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance, registrationError);\n }\n });\n}\n\nfunction getRegisterFetchRequestHookFunction() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__;\n }\n\n // Fallback to fix an error. Will remove soon.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK;\n}\n\nexport function registerHoneycombInstrumentation(runtime: FireflyRuntime) {\n const registerFetchRequestHookFunction = getRegisterFetchRequestHookFunction();\n\n if (registerFetchRequestHookFunction) {\n registerActiveSpanStack();\n\n const activeSpanOverrideFunction = createOverrideFetchRequestSpanWithActiveSpanContext(runtime.logger);\n\n // Dynamically registering this request hook function to nest the HTTP requests\n // of squide bootstrapping under the appropriate Honeycomb span.\n registerFetchRequestHookFunction(activeSpanOverrideFunction);\n } else {\n runtime.logger.warning(\"[squide] Cannot register Honeycomb fetch request hook because \\\"globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__\\\" is not available. Honeycomb instrumentation is still functional but in degraded mode.\");\n }\n\n registerTrackingListeners(runtime);\n}\n"],"names":["LocalModuleDeferredRegistrationFailedEvent","LocalModuleDeferredRegistrationUpdateFailedEvent","LocalModuleRegistrationFailedEvent","LocalModulesDeferredRegistrationCompletedEvent","LocalModulesDeferredRegistrationStartedEvent","LocalModulesDeferredRegistrationsUpdateCompletedEvent","LocalModulesDeferredRegistrationsUpdateStartedEvent","LocalModulesRegistrationCompletedEvent","LocalModulesRegistrationStartedEvent","DeferredRegistrationsUpdateCompletedEvent","DeferredRegistrationsUpdateStartedEvent","RemoteModuleDeferredRegistrationFailedEvent","RemoteModuleDeferredRegistrationUpdateFailedEvent","RemoteModuleRegistrationFailedEvent","RemoteModulesDeferredRegistrationCompletedEvent","RemoteModulesDeferredRegistrationStartedEvent","RemoteModulesDeferredRegistrationsUpdateCompletedEvent","RemoteModulesDeferredRegistrationsUpdateStartedEvent","RemoteModulesRegistrationCompletedEvent","RemoteModulesRegistrationStartedEvent","ApplicationBoostrappedEvent","ModulesReadyEvent","ModulesRegisteredEvent","MswReadyEvent","ProtectedDataReadyEvent","PublicDataReadyEvent","ApplicationBootstrappingStartedEvent","ProtectedDataFetchFailedEvent","ProtectedDataFetchStartedEvent","PublicDataFetchFailedEvent","PublicDataFetchStartedEvent","createOverrideFetchRequestSpanWithActiveSpanContext","registerActiveSpanStack","getTracer","endActiveSpan","startActiveChildSpan","startChildSpan","startSpan","traceError","reduceDataFetchEvents","runtime","onDataFetchStarted","onDataReady","onPublicDataFetchStarted","onPublicDataReady","onProtectedDataFetchStarted","onProtectedDataReady","onDataFetchFailed","dataFetchState","handleDataFetchFailed","payload","registerTrackingListeners","bootstrappingSpan","localModuleRegistrationSpan","localModuleDeferredRegistrationSpan","remoteModuleRegistrationSpan","remoteModuleDeferredRegistrationSpan","dataFetchSpan","deferredRegistrationsUpdateSpan","localModuleDeferredRegistrationsUpdateSpan","remoteModuleDeferredRegistrationsUpdateSpan","options","context","attributes","registrationError","handleFetchDataStarted","name","span","handleDataReady","handlePublicDataFetchStarted","handlePublicDataReady","handleProtectedDataFetchStarted","handleProtectedDataReady","queriesErrors","x","getRegisterFetchRequestHookFunction","globalThis","registerHoneycombInstrumentation","registerFetchRequestHookFunction","activeSpanOverrideFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBsB;AAoBa;AAC2I;AAE/F;AAC+B;AACT;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,CAAC;IAC3B;IAEAW,0BAA0BX;AAC9B"}
|
|
1
|
+
{"version":3,"file":"honeycomb/registerHoneycombInstrumentation.js","sources":["webpack://@squide/firefly/./src/honeycomb/registerHoneycombInstrumentation.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport {\n LocalModuleDeferredRegistrationFailedEvent,\n LocalModuleDeferredRegistrationUpdateFailedEvent,\n LocalModuleRegistrationFailedEvent,\n LocalModulesDeferredRegistrationCompletedEvent,\n type LocalModulesDeferredRegistrationCompletedEventPayload,\n LocalModulesDeferredRegistrationStartedEvent,\n type LocalModulesDeferredRegistrationStartedEventPayload,\n LocalModulesDeferredRegistrationsUpdateCompletedEvent,\n type LocalModulesDeferredRegistrationsUpdateCompletedEventPayload,\n LocalModulesDeferredRegistrationsUpdateStartedEvent,\n type LocalModulesDeferredRegistrationsUpdateStartedEventPayload,\n LocalModulesRegistrationCompletedEvent,\n type LocalModulesRegistrationCompletedEventPayload,\n LocalModulesRegistrationStartedEvent,\n type LocalModulesRegistrationStartedEventPayload,\n type ModuleRegistrationError\n} from \"@squide/core\";\nimport {\n DeferredRegistrationsUpdateCompletedEvent,\n DeferredRegistrationsUpdateStartedEvent,\n RemoteModuleDeferredRegistrationFailedEvent,\n RemoteModuleDeferredRegistrationUpdateFailedEvent,\n type RemoteModuleRegistrationError,\n RemoteModuleRegistrationFailedEvent,\n RemoteModulesDeferredRegistrationCompletedEvent,\n type RemoteModulesDeferredRegistrationCompletedEventPayload,\n RemoteModulesDeferredRegistrationStartedEvent,\n type RemoteModulesDeferredRegistrationStartedEventPayload,\n RemoteModulesDeferredRegistrationsUpdateCompletedEvent,\n type RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload,\n RemoteModulesDeferredRegistrationsUpdateStartedEvent,\n type RemoteModulesDeferredRegistrationsUpdateStartedEventPayload,\n RemoteModulesRegistrationCompletedEvent,\n type RemoteModulesRegistrationCompletedEventPayload,\n RemoteModulesRegistrationStartedEvent,\n type RemoteModulesRegistrationStartedEventPayload\n} from \"@squide/module-federation\";\nimport { ApplicationBoostrappedEvent, type AppRouterWaitState, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from \"../AppRouterReducer.ts\";\nimport type { FireflyRuntime } from \"../FireflyRuntime.tsx\";\nimport { ApplicationBootstrappingStartedEvent } from \"../initializeFirefly.ts\";\nimport { ProtectedDataFetchFailedEvent, ProtectedDataFetchStartedEvent } from \"../useProtectedDataQueries.ts\";\nimport { PublicDataFetchFailedEvent, PublicDataFetchStartedEvent } from \"../usePublicDataQueries.ts\";\nimport { type ActiveSpan, createOverrideFetchRequestSpanWithActiveSpanContext, registerActiveSpanStack } from \"./activeSpan.ts\";\nimport { getTracer } from \"./tracer.ts\";\nimport { endActiveSpan, startActiveChildSpan, startChildSpan, startSpan, traceError } from \"./utils.ts\";\n\n// TIPS:\n// To query those traces in Honeycomb, use the following query filter: \"root.name = squide-bootstrapping\".\n\ntype DataFetchState = \"none\" | \"fetching-data\" | \"public-data-ready\" | \"protected-data-ready\" | \"data-ready\" | \"data-fetch-failed\";\n\nexport function reduceDataFetchEvents(\n runtime: FireflyRuntime,\n onDataFetchStarted: () => void,\n onDataReady: () => void,\n onPublicDataFetchStarted: () => void,\n onPublicDataReady: () => void,\n onProtectedDataFetchStarted: () => void,\n onProtectedDataReady: () => void,\n onDataFetchFailed: (queriesErrors: Error[]) => void\n) {\n let dataFetchState: DataFetchState = \"none\";\n\n runtime.eventBus.addListener(PublicDataFetchStartedEvent, () => {\n if (dataFetchState === \"none\") {\n dataFetchState = \"fetching-data\";\n onDataFetchStarted();\n }\n\n onPublicDataFetchStarted();\n }, { once: true });\n\n runtime.eventBus.addListener(PublicDataReadyEvent, payload => {\n onPublicDataReady();\n\n if (dataFetchState === \"fetching-data\") {\n if (payload && !(payload as AppRouterWaitState).waitForProtectedData) {\n dataFetchState = \"data-ready\";\n onDataReady();\n } else {\n dataFetchState = \"public-data-ready\";\n }\n } else if (dataFetchState === \"protected-data-ready\") {\n dataFetchState = \"data-ready\";\n onDataReady();\n }\n }, { once: true });\n\n runtime.eventBus.addListener(ProtectedDataFetchStartedEvent, () => {\n if (dataFetchState === \"none\") {\n dataFetchState = \"fetching-data\";\n onDataFetchStarted();\n }\n\n onProtectedDataFetchStarted();\n }, { once: true });\n\n runtime.eventBus.addListener(ProtectedDataReadyEvent, payload => {\n onProtectedDataReady();\n\n if (dataFetchState === \"fetching-data\") {\n if (payload && !(payload as AppRouterWaitState).waitForPublicData) {\n dataFetchState = \"data-ready\";\n onDataReady();\n } else {\n dataFetchState = \"protected-data-ready\";\n }\n } else if (dataFetchState === \"public-data-ready\") {\n dataFetchState = \"data-ready\";\n onDataReady();\n }\n }, { once: true });\n\n const handleDataFetchFailed = (payload: unknown) => {\n if (dataFetchState !== \"data-fetch-failed\") {\n dataFetchState = \"data-fetch-failed\";\n\n onDataFetchFailed(payload as Error[]);\n }\n };\n\n runtime.eventBus.addListener(PublicDataFetchFailedEvent, handleDataFetchFailed, { once: true });\n runtime.eventBus.addListener(ProtectedDataFetchFailedEvent, handleDataFetchFailed, { once: true });\n}\n\nfunction registerTrackingListeners(runtime: FireflyRuntime) {\n let bootstrappingSpan: Span;\n let localModuleRegistrationSpan: Span;\n let localModuleDeferredRegistrationSpan: Span;\n let remoteModuleRegistrationSpan: Span;\n let remoteModuleDeferredRegistrationSpan: Span;\n let dataFetchSpan: ActiveSpan;\n let deferredRegistrationsUpdateSpan: Span;\n let localModuleDeferredRegistrationsUpdateSpan: ActiveSpan;\n let remoteModuleDeferredRegistrationsUpdateSpan: ActiveSpan;\n\n runtime.eventBus.addListener(ApplicationBootstrappingStartedEvent, () => {\n bootstrappingSpan = startSpan((options, context) => getTracer().startSpan(\"squide-bootstrapping\", options, context));\n }, { once: true });\n\n runtime.eventBus.addListener(ApplicationBoostrappedEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.end();\n }\n }, { once: true });\n\n runtime.eventBus.addListener(MswReadyEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"msw-ready\");\n }\n }, { once: true });\n\n runtime.eventBus.addListener(LocalModulesRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.module_count\": (payload as LocalModulesRegistrationStartedEventPayload).moduleCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-registration-started\", attributes);\n }\n\n localModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"local-module-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(LocalModulesRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-registration-completed\", {\n \"app.squide.module_count\": (payload as LocalModulesRegistrationCompletedEventPayload).moduleCount\n });\n }\n\n if (localModuleRegistrationSpan) {\n localModuleRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModuleRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as ModuleRegistrationError;\n\n if (localModuleRegistrationSpan) {\n traceError(localModuleRegistrationSpan, registrationError);\n }\n });\n\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationStartedEventPayload).registrationCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-deferred-registration-started\", attributes);\n }\n\n localModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"local-module-deferred-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"local-module-deferred-registration-completed\", {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationCompletedEventPayload).registrationCount\n });\n }\n\n if (localModuleDeferredRegistrationSpan) {\n localModuleDeferredRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModuleDeferredRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as ModuleRegistrationError;\n\n if (localModuleDeferredRegistrationSpan) {\n traceError(localModuleRegistrationSpan, registrationError);\n }\n });\n\n runtime.eventBus.addListener(RemoteModulesRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.remote_count\": (payload as RemoteModulesRegistrationStartedEventPayload).remoteCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-started\", attributes);\n }\n\n remoteModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(RemoteModulesRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-registration-completed\", {\n \"app.squide.remote_count\": (payload as RemoteModulesRegistrationCompletedEventPayload).remoteCount\n });\n }\n\n if (remoteModuleRegistrationSpan) {\n remoteModuleRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModuleRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleRegistrationSpan) {\n traceError(remoteModuleRegistrationSpan, registrationError);\n }\n });\n\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationStartedEventPayload).registrationCount\n };\n\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {\n return getTracer().startSpan(\"remote-module-deferred-registration\", { ...options, attributes }, context);\n });\n }, { once: true });\n\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"remote-module-deferred-registration-completed\", {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationCompletedEventPayload).registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationSpan) {\n remoteModuleDeferredRegistrationSpan.end();\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModuleDeferredRegistrationFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleDeferredRegistrationSpan) {\n traceError(remoteModuleDeferredRegistrationSpan, registrationError);\n }\n });\n\n const handleFetchDataStarted = () => {\n dataFetchSpan = startActiveChildSpan(bootstrappingSpan, (options, context) => {\n const name = \"data-fetch\";\n const span = getTracer().startSpan(name, options, context);\n\n return {\n name,\n span\n };\n });\n };\n\n const handleDataReady = () => {\n if (dataFetchSpan) {\n endActiveSpan(dataFetchSpan);\n }\n };\n\n const handlePublicDataFetchStarted = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"public-data-fetch-started\");\n }\n };\n\n const handlePublicDataReady = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"public-data-ready\");\n }\n };\n\n const handleProtectedDataFetchStarted = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"protected-data-fetch-started\");\n }\n };\n\n const handleProtectedDataReady = () => {\n if (dataFetchSpan) {\n dataFetchSpan.instance.addEvent(\"protected-data-ready\");\n }\n };\n\n const handleDataFetchFailed = (queriesErrors: Error[]) => {\n if (dataFetchSpan) {\n queriesErrors.forEach(x => {\n traceError(dataFetchSpan.instance, x);\n });\n\n endActiveSpan(dataFetchSpan);\n\n // Global data fetch errors are unmanaged, which mean the host application bootstrapping flow\n // will be aborted and a react-router error boundary will be rendered.\n if (bootstrappingSpan) {\n bootstrappingSpan.end();\n }\n }\n };\n\n reduceDataFetchEvents(\n runtime,\n handleFetchDataStarted,\n handleDataReady,\n handlePublicDataFetchStarted,\n handlePublicDataReady,\n handleProtectedDataFetchStarted,\n handleProtectedDataReady,\n handleDataFetchFailed\n );\n\n runtime.eventBus.addListener(ModulesRegisteredEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"modules-registered\");\n }\n }, { once: true });\n\n runtime.eventBus.addListener(ModulesReadyEvent, () => {\n if (bootstrappingSpan) {\n bootstrappingSpan.addEvent(\"modules-ready\");\n }\n }, { once: true });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(DeferredRegistrationsUpdateStartedEvent, () => {\n deferredRegistrationsUpdateSpan = startSpan((options, context) => getTracer().startSpan(\"squide-deferred-registrations-update\", options, context));\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(DeferredRegistrationsUpdateCompletedEvent, () => {\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.end();\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount\n };\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"local-module-deferred-registrations-update-started\", attributes);\n }\n\n localModuleDeferredRegistrationsUpdateSpan = startActiveChildSpan(deferredRegistrationsUpdateSpan, (options, context) => {\n const name = \"local-module-deferred-registrations-update\";\n\n const span = getTracer().startSpan(name, {\n attributes,\n ...options\n }, context);\n\n return {\n name,\n span\n };\n });\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"local-module-deferred-registrations-update-completed\", {\n \"app.squide.registration_count\": (payload as LocalModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount\n });\n }\n\n if (localModuleDeferredRegistrationsUpdateSpan) {\n endActiveSpan(localModuleDeferredRegistrationsUpdateSpan);\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(LocalModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {\n const registrationError = payload as ModuleRegistrationError;\n\n if (localModuleDeferredRegistrationsUpdateSpan) {\n traceError(localModuleDeferredRegistrationsUpdateSpan.instance, registrationError);\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {\n const attributes = {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount\n };\n\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-started\", attributes);\n }\n\n remoteModuleDeferredRegistrationsUpdateSpan = startActiveChildSpan(deferredRegistrationsUpdateSpan, (options, context) => {\n const name = \"remote-module-deferred-registrations-update\";\n\n const span = getTracer().startSpan(name, {\n attributes,\n ...options\n }, context);\n\n return {\n name,\n span\n };\n });\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {\n if (deferredRegistrationsUpdateSpan) {\n deferredRegistrationsUpdateSpan.addEvent(\"remote-module-deferred-registrations-update-completed\", {\n \"app.squide.registration_count\": (payload as RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount\n });\n }\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n endActiveSpan(remoteModuleDeferredRegistrationsUpdateSpan);\n }\n });\n\n // Can occur multiple times.\n runtime.eventBus.addListener(RemoteModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {\n const registrationError = payload as RemoteModuleRegistrationError;\n\n if (remoteModuleDeferredRegistrationsUpdateSpan) {\n traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance, registrationError);\n }\n });\n}\n\nfunction getRegisterFetchRequestHookFunction() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__;\n }\n\n // Fallback to fix an error. Will remove soon.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK;\n}\n\nexport function registerHoneycombInstrumentation(runtime: FireflyRuntime) {\n const registerFetchRequestHookFunction = getRegisterFetchRequestHookFunction();\n\n if (registerFetchRequestHookFunction) {\n registerActiveSpanStack();\n\n const activeSpanOverrideFunction = createOverrideFetchRequestSpanWithActiveSpanContext(runtime.logger);\n\n // Dynamically registering this request hook function to nest the HTTP requests\n // of squide bootstrapping under the appropriate Honeycomb span.\n registerFetchRequestHookFunction(activeSpanOverrideFunction);\n } else {\n runtime.logger.warning(\"[squide] Cannot register Honeycomb fetch request hook because \\\"globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__\\\" is not available. Honeycomb instrumentation is still functional but in degraded mode.\");\n }\n\n registerTrackingListeners(runtime);\n}\n"],"names":["LocalModuleDeferredRegistrationFailedEvent","LocalModuleDeferredRegistrationUpdateFailedEvent","LocalModuleRegistrationFailedEvent","LocalModulesDeferredRegistrationCompletedEvent","LocalModulesDeferredRegistrationStartedEvent","LocalModulesDeferredRegistrationsUpdateCompletedEvent","LocalModulesDeferredRegistrationsUpdateStartedEvent","LocalModulesRegistrationCompletedEvent","LocalModulesRegistrationStartedEvent","DeferredRegistrationsUpdateCompletedEvent","DeferredRegistrationsUpdateStartedEvent","RemoteModuleDeferredRegistrationFailedEvent","RemoteModuleDeferredRegistrationUpdateFailedEvent","RemoteModuleRegistrationFailedEvent","RemoteModulesDeferredRegistrationCompletedEvent","RemoteModulesDeferredRegistrationStartedEvent","RemoteModulesDeferredRegistrationsUpdateCompletedEvent","RemoteModulesDeferredRegistrationsUpdateStartedEvent","RemoteModulesRegistrationCompletedEvent","RemoteModulesRegistrationStartedEvent","ApplicationBoostrappedEvent","ModulesReadyEvent","ModulesRegisteredEvent","MswReadyEvent","ProtectedDataReadyEvent","PublicDataReadyEvent","ApplicationBootstrappingStartedEvent","ProtectedDataFetchFailedEvent","ProtectedDataFetchStartedEvent","PublicDataFetchFailedEvent","PublicDataFetchStartedEvent","createOverrideFetchRequestSpanWithActiveSpanContext","registerActiveSpanStack","getTracer","endActiveSpan","startActiveChildSpan","startChildSpan","startSpan","traceError","reduceDataFetchEvents","runtime","onDataFetchStarted","onDataReady","onPublicDataFetchStarted","onPublicDataReady","onProtectedDataFetchStarted","onProtectedDataReady","onDataFetchFailed","dataFetchState","payload","handleDataFetchFailed","registerTrackingListeners","bootstrappingSpan","localModuleRegistrationSpan","localModuleDeferredRegistrationSpan","remoteModuleRegistrationSpan","remoteModuleDeferredRegistrationSpan","dataFetchSpan","deferredRegistrationsUpdateSpan","localModuleDeferredRegistrationsUpdateSpan","remoteModuleDeferredRegistrationsUpdateSpan","options","context","attributes","registrationError","handleFetchDataStarted","name","span","handleDataReady","handlePublicDataFetchStarted","handlePublicDataReady","handleProtectedDataFetchStarted","handleProtectedDataReady","queriesErrors","x","getRegisterFetchRequestHookFunction","globalThis","registerHoneycombInstrumentation","registerFetchRequestHookFunction","activeSpanOverrideFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBsB;AAoBa;AACoK;AAExH;AAC+B;AACT;AAC2B;AACxF;AACgE;AAOjG,SAASuC,sBACZC,OAAuB,EACvBC,kBAA8B,EAC9BC,WAAuB,EACvBC,wBAAoC,EACpCC,iBAA6B,EAC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A;QAEvB,MAAM+C,6BAA6BhD,mDAAmDA,CAACS,QAAQ,MAAM;QAErG,+EAA+E;QAC/E,gEAAgE;QAChEsC,iCAAiCC;IACrC,OAAO;QACHvC,QAAQ,MAAM,CAAC,OAAO,CAAC;IAC3B;IAEAW,0BAA0BX;AAC9B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squide/firefly",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "13.
|
|
4
|
+
"version": "13.3.1",
|
|
5
5
|
"description": "Helpers to facilitate the creation of an application with the Squide firefly technology stack.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@workleap/logging": "^1.2.5",
|
|
40
40
|
"uuid": "^11.1.0",
|
|
41
|
-
"@squide/core": "5.
|
|
42
|
-
"@squide/module-federation": "6.
|
|
43
|
-
"@squide/
|
|
44
|
-
"@squide/
|
|
41
|
+
"@squide/core": "5.7.0",
|
|
42
|
+
"@squide/module-federation": "6.5.0",
|
|
43
|
+
"@squide/react-router": "7.3.0",
|
|
44
|
+
"@squide/msw": "3.5.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@rsbuild/core": "1.4.7",
|
package/src/AppRouterReducer.ts
CHANGED
|
@@ -9,10 +9,13 @@ import { isBootstrapping } from "./useIsBootstrapping.ts";
|
|
|
9
9
|
|
|
10
10
|
export type ActiveRouteVisiblity = "unknown" | "public" | "protected";
|
|
11
11
|
|
|
12
|
-
export interface
|
|
12
|
+
export interface AppRouterWaitState {
|
|
13
13
|
waitForMsw: boolean;
|
|
14
14
|
waitForPublicData: boolean;
|
|
15
15
|
waitForProtectedData: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AppRouterState extends AppRouterWaitState {
|
|
16
19
|
areModulesRegistered: boolean;
|
|
17
20
|
areModulesReady: boolean;
|
|
18
21
|
isMswReady: boolean;
|
|
@@ -54,6 +57,7 @@ export const ApplicationBoostrappedEvent = "squide-app-boostrapped";
|
|
|
54
57
|
|
|
55
58
|
export interface AppRouterAction {
|
|
56
59
|
type: AppRouterActionType;
|
|
60
|
+
payload?: unknown;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
export type AppRouterDispatch = Dispatch<AppRouterAction>;
|
|
@@ -283,7 +287,7 @@ export function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRo
|
|
|
283
287
|
}, [isMswReadyValue, dispatchMswReady]);
|
|
284
288
|
}
|
|
285
289
|
|
|
286
|
-
|
|
290
|
+
function useBootstrappingCompletedDispatcher(waitState: AppRouterWaitState, state: AppRouterState) {
|
|
287
291
|
const eventBus = useEventBus();
|
|
288
292
|
|
|
289
293
|
const areModulesRegisteredValue = state.areModulesRegistered;
|
|
@@ -291,13 +295,13 @@ export function useBootstrappingCompletedDispatcher(state: AppRouterState) {
|
|
|
291
295
|
|
|
292
296
|
useExecuteOnce(useCallback(() => {
|
|
293
297
|
if (areModulesRegisteredValue && !isBoostrapping) {
|
|
294
|
-
eventBus.dispatch(ApplicationBoostrappedEvent);
|
|
298
|
+
eventBus.dispatch(ApplicationBoostrappedEvent, waitState);
|
|
295
299
|
|
|
296
300
|
return true;
|
|
297
301
|
}
|
|
298
302
|
|
|
299
303
|
return false;
|
|
300
|
-
}, [areModulesRegisteredValue, isBoostrapping, eventBus]), true);
|
|
304
|
+
}, [areModulesRegisteredValue, isBoostrapping, waitState, eventBus]), true);
|
|
301
305
|
}
|
|
302
306
|
|
|
303
307
|
let dispatchProxyFactory: ((reactDispatch: AppRouterDispatch) => AppRouterDispatch) | undefined;
|
|
@@ -318,7 +322,7 @@ function useReducerDispatchProxy(reactDispatch: AppRouterDispatch) {
|
|
|
318
322
|
}, [reactDispatch]);
|
|
319
323
|
}
|
|
320
324
|
|
|
321
|
-
function useEnhancedReducerDispatch(reducerDispatch: AppRouterDispatch) {
|
|
325
|
+
function useEnhancedReducerDispatch(waitState: AppRouterWaitState, reducerDispatch: AppRouterDispatch) {
|
|
322
326
|
const logger = useLogger();
|
|
323
327
|
const appRouterStore = useAppRouterStore();
|
|
324
328
|
const eventBus = useEventBus();
|
|
@@ -329,11 +333,11 @@ function useEnhancedReducerDispatch(reducerDispatch: AppRouterDispatch) {
|
|
|
329
333
|
.withObject(action)
|
|
330
334
|
.debug();
|
|
331
335
|
|
|
332
|
-
appRouterStore.dispatch(action);
|
|
333
|
-
eventBus.dispatch(`squide-${action.type}
|
|
336
|
+
appRouterStore.dispatch({ ...action, payload: waitState });
|
|
337
|
+
eventBus.dispatch(`squide-${action.type}`, waitState);
|
|
334
338
|
|
|
335
339
|
reducerDispatch(action);
|
|
336
|
-
}, [reducerDispatch, logger, appRouterStore, eventBus]);
|
|
340
|
+
}, [waitState, reducerDispatch, logger, appRouterStore, eventBus]);
|
|
337
341
|
}
|
|
338
342
|
|
|
339
343
|
export function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch] {
|
|
@@ -341,56 +345,66 @@ export function useAppRouterReducer(waitForPublicData: boolean, waitForProtected
|
|
|
341
345
|
const eventBus = useEventBus();
|
|
342
346
|
const appRouterStore = useAppRouterStore();
|
|
343
347
|
|
|
348
|
+
const isMswEnabled = runtime.isMswEnabled;
|
|
349
|
+
|
|
344
350
|
const areModulesInitiallyRegistered = getAreModulesRegistered();
|
|
345
351
|
const areModulesInitiallyReady = getAreModulesReady();
|
|
346
352
|
const isMswInitiallyReady = isMswReady();
|
|
347
353
|
|
|
354
|
+
const waitState = useMemo(() => ({
|
|
355
|
+
waitForMsw: isMswEnabled,
|
|
356
|
+
waitForPublicData,
|
|
357
|
+
waitForProtectedData
|
|
358
|
+
}), [isMswEnabled, waitForPublicData, waitForProtectedData]);
|
|
359
|
+
|
|
360
|
+
const initialState = useMemo(() => ({
|
|
361
|
+
waitForMsw: waitState.waitForMsw,
|
|
362
|
+
waitForPublicData: waitState.waitForPublicData,
|
|
363
|
+
waitForProtectedData: waitState.waitForProtectedData,
|
|
364
|
+
// When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
|
|
365
|
+
areModulesRegistered: areModulesInitiallyRegistered,
|
|
366
|
+
areModulesReady: areModulesInitiallyReady,
|
|
367
|
+
isMswReady: isMswInitiallyReady,
|
|
368
|
+
isPublicDataReady: false,
|
|
369
|
+
isProtectedDataReady: false,
|
|
370
|
+
activeRouteVisibility: "unknown",
|
|
371
|
+
isUnauthorized: false
|
|
372
|
+
} satisfies AppRouterState), [waitState, areModulesInitiallyRegistered, areModulesInitiallyReady, isMswInitiallyReady]);
|
|
373
|
+
|
|
348
374
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
349
375
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
350
376
|
useExecuteOnce(useCallback(() => {
|
|
351
377
|
if (areModulesInitiallyRegistered) {
|
|
352
|
-
appRouterStore.dispatch({ type: "modules-registered" });
|
|
353
|
-
eventBus.dispatch(ModulesRegisteredEvent);
|
|
378
|
+
appRouterStore.dispatch({ type: "modules-registered", payload: waitState });
|
|
379
|
+
eventBus.dispatch(ModulesRegisteredEvent, waitState);
|
|
354
380
|
}
|
|
355
381
|
|
|
356
382
|
return true;
|
|
357
|
-
}, [areModulesInitiallyRegistered, appRouterStore, eventBus]), true);
|
|
383
|
+
}, [areModulesInitiallyRegistered, appRouterStore, eventBus, waitState]), true);
|
|
358
384
|
|
|
359
385
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
360
386
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
361
387
|
useExecuteOnce(useCallback(() => {
|
|
362
388
|
if (areModulesInitiallyReady) {
|
|
363
|
-
appRouterStore.dispatch({ type: "modules-ready" });
|
|
364
|
-
eventBus.dispatch(ModulesReadyEvent);
|
|
389
|
+
appRouterStore.dispatch({ type: "modules-ready", payload: waitState });
|
|
390
|
+
eventBus.dispatch(ModulesReadyEvent, waitState);
|
|
365
391
|
}
|
|
366
392
|
|
|
367
393
|
return true;
|
|
368
|
-
}, [areModulesInitiallyReady, appRouterStore, eventBus]), true);
|
|
394
|
+
}, [areModulesInitiallyReady, appRouterStore, eventBus, waitState]), true);
|
|
369
395
|
|
|
370
396
|
// When modules are initially registered, the reducer action will never be dispatched, therefore the event would not be dispatched as well.
|
|
371
397
|
// To ensure the bootstrapping events sequencing, the event is manually dispatched when the modules are initially registered.
|
|
372
398
|
useExecuteOnce(useCallback(() => {
|
|
373
399
|
if (isMswInitiallyReady) {
|
|
374
|
-
appRouterStore.dispatch({ type: "msw-ready" });
|
|
375
|
-
eventBus.dispatch(MswReadyEvent);
|
|
400
|
+
appRouterStore.dispatch({ type: "msw-ready", payload: waitState });
|
|
401
|
+
eventBus.dispatch(MswReadyEvent, waitState);
|
|
376
402
|
}
|
|
377
403
|
|
|
378
404
|
return true;
|
|
379
|
-
}, [isMswInitiallyReady, appRouterStore, eventBus]), true);
|
|
405
|
+
}, [isMswInitiallyReady, appRouterStore, eventBus, waitState]), true);
|
|
380
406
|
|
|
381
|
-
const [state, reactDispatch] = useReducer(reducer,
|
|
382
|
-
waitForMsw: runtime.isMswEnabled,
|
|
383
|
-
waitForPublicData,
|
|
384
|
-
waitForProtectedData,
|
|
385
|
-
// When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
|
|
386
|
-
areModulesRegistered: areModulesInitiallyRegistered,
|
|
387
|
-
areModulesReady: areModulesInitiallyReady,
|
|
388
|
-
isMswReady: isMswInitiallyReady,
|
|
389
|
-
isPublicDataReady: false,
|
|
390
|
-
isProtectedDataReady: false,
|
|
391
|
-
activeRouteVisibility: "unknown",
|
|
392
|
-
isUnauthorized: false
|
|
393
|
-
});
|
|
407
|
+
const [state, reactDispatch] = useReducer(reducer, initialState);
|
|
394
408
|
|
|
395
409
|
const {
|
|
396
410
|
areModulesRegistered: areModulesRegisteredValue,
|
|
@@ -401,11 +415,11 @@ export function useAppRouterReducer(waitForPublicData: boolean, waitForProtected
|
|
|
401
415
|
// The dispatch proxy is strictly an utility allowing tests to mock the useReducer dispatch function. It's easier
|
|
402
416
|
// than mocking the import from React.
|
|
403
417
|
const dispatchProxy = useReducerDispatchProxy(reactDispatch);
|
|
404
|
-
const dispatch = useEnhancedReducerDispatch(dispatchProxy);
|
|
418
|
+
const dispatch = useEnhancedReducerDispatch(waitState, dispatchProxy);
|
|
405
419
|
|
|
406
420
|
useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);
|
|
407
421
|
useMswStatusDispatcher(isMswReadyValue, dispatch);
|
|
408
|
-
useBootstrappingCompletedDispatcher(state);
|
|
422
|
+
useBootstrappingCompletedDispatcher(waitState, state);
|
|
409
423
|
|
|
410
424
|
return [state, dispatch];
|
|
411
425
|
}
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
RemoteModulesRegistrationStartedEvent,
|
|
38
38
|
type RemoteModulesRegistrationStartedEventPayload
|
|
39
39
|
} from "@squide/module-federation";
|
|
40
|
-
import { ApplicationBoostrappedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from "../AppRouterReducer.ts";
|
|
40
|
+
import { ApplicationBoostrappedEvent, type AppRouterWaitState, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from "../AppRouterReducer.ts";
|
|
41
41
|
import type { FireflyRuntime } from "../FireflyRuntime.tsx";
|
|
42
42
|
import { ApplicationBootstrappingStartedEvent } from "../initializeFirefly.ts";
|
|
43
43
|
import { ProtectedDataFetchFailedEvent, ProtectedDataFetchStartedEvent } from "../useProtectedDataQueries.ts";
|
|
@@ -72,11 +72,16 @@ export function reduceDataFetchEvents(
|
|
|
72
72
|
onPublicDataFetchStarted();
|
|
73
73
|
}, { once: true });
|
|
74
74
|
|
|
75
|
-
runtime.eventBus.addListener(PublicDataReadyEvent,
|
|
75
|
+
runtime.eventBus.addListener(PublicDataReadyEvent, payload => {
|
|
76
76
|
onPublicDataReady();
|
|
77
77
|
|
|
78
78
|
if (dataFetchState === "fetching-data") {
|
|
79
|
-
|
|
79
|
+
if (payload && !(payload as AppRouterWaitState).waitForProtectedData) {
|
|
80
|
+
dataFetchState = "data-ready";
|
|
81
|
+
onDataReady();
|
|
82
|
+
} else {
|
|
83
|
+
dataFetchState = "public-data-ready";
|
|
84
|
+
}
|
|
80
85
|
} else if (dataFetchState === "protected-data-ready") {
|
|
81
86
|
dataFetchState = "data-ready";
|
|
82
87
|
onDataReady();
|
|
@@ -92,11 +97,16 @@ export function reduceDataFetchEvents(
|
|
|
92
97
|
onProtectedDataFetchStarted();
|
|
93
98
|
}, { once: true });
|
|
94
99
|
|
|
95
|
-
runtime.eventBus.addListener(ProtectedDataReadyEvent,
|
|
100
|
+
runtime.eventBus.addListener(ProtectedDataReadyEvent, payload => {
|
|
96
101
|
onProtectedDataReady();
|
|
97
102
|
|
|
98
103
|
if (dataFetchState === "fetching-data") {
|
|
99
|
-
|
|
104
|
+
if (payload && !(payload as AppRouterWaitState).waitForPublicData) {
|
|
105
|
+
dataFetchState = "data-ready";
|
|
106
|
+
onDataReady();
|
|
107
|
+
} else {
|
|
108
|
+
dataFetchState = "protected-data-ready";
|
|
109
|
+
}
|
|
100
110
|
} else if (dataFetchState === "public-data-ready") {
|
|
101
111
|
dataFetchState = "data-ready";
|
|
102
112
|
onDataReady();
|
|
@@ -330,7 +340,13 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
|
|
|
330
340
|
traceError(dataFetchSpan.instance, x);
|
|
331
341
|
});
|
|
332
342
|
|
|
333
|
-
dataFetchSpan
|
|
343
|
+
endActiveSpan(dataFetchSpan);
|
|
344
|
+
|
|
345
|
+
// Global data fetch errors are unmanaged, which mean the host application bootstrapping flow
|
|
346
|
+
// will be aborted and a react-router error boundary will be rendered.
|
|
347
|
+
if (bootstrappingSpan) {
|
|
348
|
+
bootstrappingSpan.end();
|
|
349
|
+
}
|
|
334
350
|
}
|
|
335
351
|
};
|
|
336
352
|
|