@squide/firefly 13.3.1 → 14.0.0
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 +58 -0
- package/dist/AppRouterReducer.js +6 -15
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/AppRouterStore.d.ts +3 -3
- package/dist/AppRouterStore.js.map +1 -1
- package/dist/FireflyRuntime.d.ts +22 -5
- package/dist/FireflyRuntime.js +34 -11
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/honeycomb/activeSpan.d.ts +2 -2
- package/dist/honeycomb/activeSpan.js.map +1 -1
- package/package.json +17 -17
- package/src/AppRouterReducer.ts +6 -21
- package/src/AppRouterStore.ts +4 -4
- package/src/FireflyRuntime.tsx +50 -12
- package/src/honeycomb/activeSpan.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
# @squide/firefly
|
|
2
2
|
|
|
3
|
+
## 14.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#311](https://github.com/workleap/wl-squide/pull/311) [`cc52e8b`](https://github.com/workleap/wl-squide/commit/cc52e8bfbe9d3d215f51d12755743f17c0c69772) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Deferred registration functions now receives a runtime instance as the first argument. This new scope runtime instance should used whenever runtime access is required within a deferred registration function scope.
|
|
8
|
+
|
|
9
|
+
Before:
|
|
10
|
+
|
|
11
|
+
The `runtime` argument of the registration function is used to register the navigation item.
|
|
12
|
+
|
|
13
|
+
```ts !#1,2,4
|
|
14
|
+
export const register: ModuleRegisterFunction<
|
|
15
|
+
FireflyRuntime,
|
|
16
|
+
unknown,
|
|
17
|
+
DeferredRegistrationData
|
|
18
|
+
> = (runtime) => {
|
|
19
|
+
return ({ featureFlags }, operation) => {
|
|
20
|
+
if (featureFlags.featureA) {
|
|
21
|
+
runtime.registerNavigationItem({
|
|
22
|
+
$id: "feature-a",
|
|
23
|
+
$label: operation === "register" ? "Feature A" : "Feature A updated",
|
|
24
|
+
to: "/feature-a",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
After:
|
|
32
|
+
|
|
33
|
+
The `deferredRuntime` argument of the **deferred** registration function is used to register the navigation item.
|
|
34
|
+
|
|
35
|
+
```ts !#2,4
|
|
36
|
+
export const register: ModuleRegisterFunction<
|
|
37
|
+
FireflyRuntime,
|
|
38
|
+
unknown,
|
|
39
|
+
DeferredRegistrationData
|
|
40
|
+
> = (runtime) => {
|
|
41
|
+
return (deferredRuntime, { featureFlags }, operation) => {
|
|
42
|
+
if (featureFlags.featureA) {
|
|
43
|
+
deferredRuntime.registerNavigationItem({
|
|
44
|
+
$id: "feature-a",
|
|
45
|
+
$label: operation === "register" ? "Feature A" : "Feature A updated",
|
|
46
|
+
to: "/feature-a",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- Updated dependencies [[`cc52e8b`](https://github.com/workleap/wl-squide/commit/cc52e8bfbe9d3d215f51d12755743f17c0c69772)]:
|
|
56
|
+
- @squide/module-federation@7.0.0
|
|
57
|
+
- @squide/react-router@8.0.0
|
|
58
|
+
- @squide/core@6.0.0
|
|
59
|
+
- @squide/msw@4.0.0
|
|
60
|
+
|
|
3
61
|
## 13.3.1
|
|
4
62
|
|
|
5
63
|
### Patch Changes
|
package/dist/AppRouterReducer.js
CHANGED
|
@@ -160,13 +160,10 @@ function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areMod
|
|
|
160
160
|
dispatch({
|
|
161
161
|
type: "modules-registered"
|
|
162
162
|
});
|
|
163
|
-
logger.withText("[squide]
|
|
163
|
+
logger.withText("[squide] Modules are registered.", {
|
|
164
164
|
style: {
|
|
165
|
-
color: "
|
|
166
|
-
backgroundColor: "green"
|
|
165
|
+
color: "green"
|
|
167
166
|
}
|
|
168
|
-
}).withText(".", {
|
|
169
|
-
leadingSpace: false
|
|
170
167
|
}).information();
|
|
171
168
|
return true;
|
|
172
169
|
}
|
|
@@ -180,13 +177,10 @@ function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areMod
|
|
|
180
177
|
dispatch({
|
|
181
178
|
type: "modules-ready"
|
|
182
179
|
});
|
|
183
|
-
logger.withText("[squide]
|
|
180
|
+
logger.withText("[squide] Modules are ready.", {
|
|
184
181
|
style: {
|
|
185
|
-
color: "
|
|
186
|
-
backgroundColor: "green"
|
|
182
|
+
color: "green"
|
|
187
183
|
}
|
|
188
|
-
}).withText(".", {
|
|
189
|
-
leadingSpace: false
|
|
190
184
|
}).information();
|
|
191
185
|
return true;
|
|
192
186
|
}
|
|
@@ -224,13 +218,10 @@ function useMswStatusDispatcher(isMswReadyValue, dispatch) {
|
|
|
224
218
|
dispatch({
|
|
225
219
|
type: "msw-ready"
|
|
226
220
|
});
|
|
227
|
-
logger.withText("[squide]
|
|
221
|
+
logger.withText("[squide] MSW is ready.", {
|
|
228
222
|
style: {
|
|
229
|
-
color: "
|
|
230
|
-
backgroundColor: "green"
|
|
223
|
+
color: "green"
|
|
231
224
|
}
|
|
232
|
-
}).withText(".", {
|
|
233
|
-
leadingSpace: false
|
|
234
225
|
}).information();
|
|
235
226
|
return true;
|
|
236
227
|
}
|
|
@@ -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 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;AAClE,MAAMC,oCAAoC,wCAAwC;AAClF,MAAMC,8BAA8B,yBAAyB;AASpE,SAASC,QAAQC,KAAqB,EAAEC,MAAuB;IAC3D,IAAIC,WAAWF;IAEf,OAAQC,OAAO,IAAI;QACf,KAAK;YAAsB;gBACvBC,WAAW;oBACP,GAAGA,QAAQ;oBACX,sBAAsB;gBAC1B;gBAEA;YACJ;QACA,KAAK;YAA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gBAAE,MAAM;gBAAsB,SAASZ;YAAU;YACzEC,SAAS,QAAQ,CAACjC,wBAAwBgC;QAC9C;QAEA,OAAO;IACX,GAAG;QAACkB;QAA+BN;QAAgBX;QAAUD;KAAU,GAAG;IAE1E,2IAA2I;IAC3I,6HAA6H;IAC7HlC,cAAcA,CAACL,WAAWA,CAAC;QACvB,IAAI0D,0BAA0B;YAC1BP,eAAe,QAAQ,CAAC;gBAAE,MAAM;gBAAiB,SAASZ;YAAU;YACpEC,SAAS,QAAQ,CAAChC,mBAAmB+B;QACzC;QAEA,OAAO;IACX,GAAG;QAACmB;QAA0BP;QAAgBX;QAAUD;KAAU,GAAG;IAErE,2IAA2I;IAC3I,6HAA6H;IAC7HlC,cAAcA,CAACL,WAAWA,CAAC;QACvB,IAAI2D,qBAAqB;YACrBR,eAAe,QAAQ,CAAC;gBAAE,MAAM;gBAAa,SAASZ;YAAU;YAChEC,SAAS,QAAQ,CAAC/B,eAAe8B;QACrC;QAEA,OAAO;IACX,GAAG;QAACoB;QAAqBR;QAAgBX;QAAUD;KAAU,GAAG;IAEhE,MAAM,CAACpB,OAAO6B,cAAc,GAAG7C,UAAUA,CAACe,SAAS0C;IAEnD,MAAM,EACF,sBAAsB/B,yBAAyB,EAC/C,iBAAiBC,oBAAoB,EACrC,YAAYM,eAAe,EAC9B,GAAGjB;IAEJ,iHAAiH;IACjH,sCAAsC;IACtC,MAAM0C,gBAAgBd,wBAAwBC;IAC9C,MAAMjB,WAAWkB,2BAA2BV,WAAWsB;IAEvDjC,sCAAsCC,2BAA2BC,sBAAsBC;IACvFI,uBAAuBC,iBAAiBL;IACxCO,oCAAoCC,WAAWpB;IAE/C,OAAO;QAACA;QAAOY;KAAS;AAC5B"}
|
|
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 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] Modules are registered.\", {\n style: {\n color: \"green\"\n }\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] Modules are ready.\", {\n style: {\n color: \"green\"\n }\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] MSW is ready.\", {\n style: {\n color: \"green\"\n }\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;AAClE,MAAMC,oCAAoC,wCAAwC;AAClF,MAAMC,8BAA8B,yBAAyB;AASpE,SAASC,QAAQC,KAAqB,EAAEC,MAAuB;IAC3D,IAAIC,WAAWF;IAEf,OAAQC,OAAO,IAAI;QACf,KAAK;YAAsB;gBACvBC,WAAW;oBACP,GAAGA,QAAQ;oBACX,sBAAsB;gBAC1B;gBAEA;YACJ;QACA,KAAK;YAAiB;gBAClBA,WAAW;oBACP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,QAAQ,CAAC;gBAAE,MAAM;gBAAiB,SAASZ;YAAU;YACpEC,SAAS,QAAQ,CAAChC,mBAAmB+B;QACzC;QAEA,OAAO;IACX,GAAG;QAACmB;QAA0BP;QAAgBX;QAAUD;KAAU,GAAG;IAErE,2IAA2I;IAC3I,6HAA6H;IAC7HlC,cAAcA,CAACL,WAAWA,CAAC;QACvB,IAAI2D,qBAAqB;YACrBR,eAAe,QAAQ,CAAC;gBAAE,MAAM;gBAAa,SAASZ;YAAU;YAChEC,SAAS,QAAQ,CAAC/B,eAAe8B;QACrC;QAEA,OAAO;IACX,GAAG;QAACoB;QAAqBR;QAAgBX;QAAUD;KAAU,GAAG;IAEhE,MAAM,CAACpB,OAAO6B,cAAc,GAAG7C,UAAUA,CAACe,SAAS0C;IAEnD,MAAM,EACF,sBAAsB/B,yBAAyB,EAC/C,iBAAiBC,oBAAoB,EACrC,YAAYM,eAAe,EAC9B,GAAGjB;IAEJ,iHAAiH;IACjH,sCAAsC;IACtC,MAAM0C,gBAAgBd,wBAAwBC;IAC9C,MAAMjB,WAAWkB,2BAA2BV,WAAWsB;IAEvDjC,sCAAsCC,2BAA2BC,sBAAsBC;IACvFI,uBAAuBC,iBAAiBL;IACxCO,oCAAoCC,WAAWpB;IAE/C,OAAO;QAACA;QAAOY;KAAS;AAC5B"}
|
package/dist/AppRouterStore.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Logger } from "@workleap/logging";
|
|
2
2
|
import type { AppRouterAction, AppRouterState } from "./AppRouterReducer.ts";
|
|
3
3
|
export type AppRouterStoreState = Omit<AppRouterState, "waitForMsw" | "waitForPublicData" | "waitForProtectedData">;
|
|
4
4
|
export type AppRouterStoreListenerFunction = (store: AppRouterStore, unsuscribe: () => void) => void;
|
|
5
5
|
export declare class AppRouterStore {
|
|
6
6
|
#private;
|
|
7
|
-
constructor(initialialState: AppRouterStoreState, logger:
|
|
7
|
+
constructor(initialialState: AppRouterStoreState, logger: Logger);
|
|
8
8
|
subscribe(listener: AppRouterStoreListenerFunction): () => void;
|
|
9
9
|
unsuscribe(listener: AppRouterStoreListenerFunction): void;
|
|
10
10
|
dispatch(action: AppRouterAction): void;
|
|
11
11
|
get state(): AppRouterStoreState;
|
|
12
12
|
}
|
|
13
|
-
export declare function createAppRouterStore(logger:
|
|
13
|
+
export declare function createAppRouterStore(logger: Logger): AppRouterStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouterStore.js","sources":["webpack://@squide/firefly/./src/AppRouterStore.ts"],"sourcesContent":["// This file is a low cost port of the AppRouterReducer to a non-React store. It allows, non-React parts of the library to get\n// access to the state and ease the integration with third-party libraries such as the Platform Widgets.\n// Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.\n\nimport type {
|
|
1
|
+
{"version":3,"file":"AppRouterStore.js","sources":["webpack://@squide/firefly/./src/AppRouterStore.ts"],"sourcesContent":["// This file is a low cost port of the AppRouterReducer to a non-React store. It allows, non-React parts of the library to get\n// access to the state and ease the integration with third-party libraries such as the Platform Widgets.\n// Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.\n\nimport type { Logger } from \"@workleap/logging\";\nimport type { AppRouterAction, AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport type AppRouterStoreState = Omit<AppRouterState, \"waitForMsw\" | \"waitForPublicData\" | \"waitForProtectedData\">;\n\nexport type AppRouterStoreListenerFunction = (store: AppRouterStore, unsuscribe: () => void) => void;\n\nexport class AppRouterStore {\n #state: AppRouterStoreState;\n\n readonly #listeners = new Set<AppRouterStoreListenerFunction>();\n readonly #logger: Logger;\n\n constructor(initialialState: AppRouterStoreState, logger: Logger) {\n this.#state = initialialState;\n this.#logger = logger;\n }\n\n subscribe(listener: AppRouterStoreListenerFunction) {\n this.#listeners.add(listener);\n\n return () => {\n this.unsuscribe(listener);\n };\n }\n\n unsuscribe(listener: AppRouterStoreListenerFunction) {\n this.#listeners.delete(listener);\n }\n\n dispatch(action: AppRouterAction) {\n const newState = this.#reducer({ ...this.#state }, action);\n\n this.#logger\n .withText(\"[squide] The AppRouterStore state has been updated to:\")\n .withObject(newState)\n .debug();\n\n this.#state = newState;\n\n // Creating a copy of the listeners in case some are removed during the looping.\n // To be honest, it might not be necessary, I simply don't know.\n new Set(this.#listeners).forEach(x => {\n x(this, () => {\n this.unsuscribe(x);\n });\n });\n }\n\n #reducer(state: AppRouterStoreState, 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 AppRouterStore state reducer doesn't support action type \"${action.type}\".`);\n }\n }\n\n return newState;\n }\n\n get state() {\n return this.#state;\n }\n}\n\nexport function createAppRouterStore(logger: Logger) {\n const initialState: AppRouterStoreState = {\n areModulesRegistered: false,\n areModulesReady: false,\n isMswReady: false,\n isPublicDataReady: false,\n isProtectedDataReady: false,\n activeRouteVisibility: \"unknown\",\n isUnauthorized: false\n };\n\n return new AppRouterStore(initialState, logger);\n}\n"],"names":["AppRouterStore","Set","initialialState","logger","listener","action","newState","x","state","Date","Error","createAppRouterStore","initialState"],"mappings":";;AAAA,8HAA8H;AAC9H,wGAAwG;AACxG,yFAAyF;AASlF,MAAMA;IACT,MAAM,CAAsB;IAEnB,UAAU,GAAG,IAAIC,MAAsC;IACvD,OAAO,CAAS;IAEzB,YAAYC,eAAoC,EAAEC,MAAc,CAAE;QAC9D,IAAI,CAAC,MAAM,GAAGD;QACd,IAAI,CAAC,OAAO,GAAGC;IACnB;IAEA,UAAUC,QAAwC,EAAE;QAChD,IAAI,CAAC,UAAU,CAAC,GAAG,CAACA;QAEpB,OAAO;YACH,IAAI,CAAC,UAAU,CAACA;QACpB;IACJ;IAEA,WAAWA,QAAwC,EAAE;QACjD,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;IAC3B;IAEA,SAASC,MAAuB,EAAE;QAC9B,MAAMC,WAAW,IAAI,CAAC,QAAQ,CAAC;YAAE,GAAG,IAAI,CAAC,MAAM;QAAC,GAAGD;QAEnD,IAAI,CAAC,OAAO,CACP,QAAQ,CAAC,0DACT,UAAU,CAACC,UACX,KAAK;QAEV,IAAI,CAAC,MAAM,GAAGA;QAEd,gFAAgF;QAChF,gEAAgE;QAChE,IAAIL,IAAI,IAAI,CAAC,UAAU,EAAE,OAAO,CAACM,CAAAA;YAC7BA,EAAE,IAAI,EAAE;gBACJ,IAAI,CAAC,UAAU,CAACA;YACpB;QACJ;IACJ;IAEA,QAAQ,CAACC,KAA0B,EAAEH,MAAuB;QACxD,IAAIC,WAAWE;QAEf,OAAQH,OAAO,IAAI;YACf,KAAK;gBAAsB;oBACvBC,WAAW;wB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AI,QAAQ;QACR,OAAO,IAAI,CAAC,MAAM;IACtB;AACJ;AAEO,SAASK,qBAAqBR,MAAc;IAC/C,MAAMS,eAAoC;QACtC,sBAAsB;QACtB,iBAAiB;QACjB,YAAY;QACZ,mBAAmB;QACnB,sBAAsB;QACtB,uBAAuB;QACvB,gBAAgB;IACpB;IAEA,OAAO,IAAIZ,eAAeY,cAAcT;AAC5C"}
|
package/dist/FireflyRuntime.d.ts
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import type { RegisterRouteOptions, RuntimeOptions } from "@squide/core";
|
|
2
|
-
import { ReactRouterRuntime, type Route } from "@squide/react-router";
|
|
1
|
+
import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from "@squide/core";
|
|
2
|
+
import { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from "@squide/react-router";
|
|
3
|
+
import type { Logger } from "@workleap/logging";
|
|
3
4
|
import type { RequestHandler } from "msw";
|
|
4
5
|
import { type AppRouterStore } from "./AppRouterStore.ts";
|
|
5
6
|
export interface FireflyRuntimeOptions extends RuntimeOptions {
|
|
6
7
|
useMsw?: boolean;
|
|
7
8
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
9
|
+
export interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {
|
|
10
|
+
}
|
|
11
|
+
export interface IFireflyRuntime extends IReactRouterRuntime {
|
|
12
|
+
registerRequestHandlers: (handlers: RequestHandler[]) => void;
|
|
13
|
+
get requestHandlers(): RequestHandler[];
|
|
14
|
+
get appRouterStore(): AppRouterStore;
|
|
15
|
+
get isMswEnabled(): boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class FireflyRuntime extends ReactRouterRuntime implements IFireflyRuntime {
|
|
18
|
+
protected _appRouterStore: AppRouterStore;
|
|
19
|
+
protected _useMsw: boolean;
|
|
10
20
|
constructor({ plugins, useMsw, ...options }?: FireflyRuntimeOptions);
|
|
11
|
-
registerRequestHandlers(handlers: RequestHandler[]): void;
|
|
21
|
+
registerRequestHandlers(handlers: RequestHandler[], options?: RegisterRequestHandlersOptions): void;
|
|
12
22
|
get requestHandlers(): RequestHandler[];
|
|
13
23
|
registerRoute(route: Route, options?: RegisterRouteOptions): void;
|
|
14
24
|
get appRouterStore(): AppRouterStore;
|
|
15
25
|
get isMswEnabled(): boolean;
|
|
26
|
+
startScope(logger: Logger): FireflyRuntime;
|
|
27
|
+
}
|
|
28
|
+
export declare class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {
|
|
29
|
+
registerRequestHandlers(handlers: RequestHandler[], options?: RegisterRequestHandlersOptions): void;
|
|
30
|
+
get requestHandlers(): RequestHandler[];
|
|
31
|
+
get appRouterStore(): AppRouterStore;
|
|
32
|
+
get isMswEnabled(): boolean;
|
|
16
33
|
}
|
package/dist/FireflyRuntime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MswPlugin, MswPluginName } from "@squide/msw";
|
|
2
|
-
import { ReactRouterRuntime } from "@squide/react-router";
|
|
2
|
+
import { ReactRouterRuntime, ReactRouterRuntimeScope } from "@squide/react-router";
|
|
3
3
|
import { getAreModulesRegistered } from "./AppRouterReducer.js";
|
|
4
4
|
import { createAppRouterStore } from "./AppRouterStore.js";
|
|
5
5
|
|
|
@@ -17,8 +17,8 @@ import { createAppRouterStore } from "./AppRouterStore.js";
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class FireflyRuntime extends ReactRouterRuntime {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
_appRouterStore;
|
|
21
|
+
_useMsw;
|
|
22
22
|
constructor({ plugins, useMsw, ...options } = {}){
|
|
23
23
|
if (useMsw) {
|
|
24
24
|
super({
|
|
@@ -28,17 +28,18 @@ class FireflyRuntime extends ReactRouterRuntime {
|
|
|
28
28
|
],
|
|
29
29
|
...options
|
|
30
30
|
});
|
|
31
|
-
this
|
|
31
|
+
this._useMsw = true;
|
|
32
32
|
} else {
|
|
33
33
|
super({
|
|
34
34
|
plugins,
|
|
35
35
|
...options
|
|
36
36
|
});
|
|
37
|
-
this
|
|
37
|
+
this._useMsw = false;
|
|
38
38
|
}
|
|
39
|
-
this
|
|
39
|
+
this._appRouterStore = createAppRouterStore(this._logger);
|
|
40
40
|
}
|
|
41
|
-
registerRequestHandlers(handlers) {
|
|
41
|
+
registerRequestHandlers(handlers, options = {}) {
|
|
42
|
+
const logger = this._getLogger(options);
|
|
42
43
|
const mswPlugin = this.getPlugin(MswPluginName);
|
|
43
44
|
if (!mswPlugin) {
|
|
44
45
|
throw new Error("[squide] Cannot register the provided MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \"useMsw\" option?");
|
|
@@ -46,7 +47,9 @@ class FireflyRuntime extends ReactRouterRuntime {
|
|
|
46
47
|
if (getAreModulesRegistered()) {
|
|
47
48
|
throw new Error("[squide] Cannot register an MSW request handlers once the modules are registered. Are you trying to register an MSW request handler in a deferred registration function? Only navigation items can be registered in a deferred registration function.");
|
|
48
49
|
}
|
|
49
|
-
mswPlugin.registerRequestHandlers(handlers
|
|
50
|
+
mswPlugin.registerRequestHandlers(handlers, {
|
|
51
|
+
logger
|
|
52
|
+
});
|
|
50
53
|
}
|
|
51
54
|
// Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
|
|
52
55
|
get requestHandlers() {
|
|
@@ -63,13 +66,33 @@ class FireflyRuntime extends ReactRouterRuntime {
|
|
|
63
66
|
super.registerRoute(route, options);
|
|
64
67
|
}
|
|
65
68
|
get appRouterStore() {
|
|
66
|
-
return this
|
|
69
|
+
return this._appRouterStore;
|
|
67
70
|
}
|
|
68
71
|
get isMswEnabled() {
|
|
69
|
-
return this
|
|
72
|
+
return this._useMsw;
|
|
73
|
+
}
|
|
74
|
+
startScope(logger) {
|
|
75
|
+
return new FireflyRuntimeScope(this, logger);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class FireflyRuntimeScope extends ReactRouterRuntimeScope {
|
|
79
|
+
registerRequestHandlers(handlers, options = {}) {
|
|
80
|
+
this._runtime.registerRequestHandlers(handlers, {
|
|
81
|
+
...options,
|
|
82
|
+
logger: this._getLogger(options)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
get requestHandlers() {
|
|
86
|
+
return this._runtime.requestHandlers;
|
|
87
|
+
}
|
|
88
|
+
get appRouterStore() {
|
|
89
|
+
return this._runtime.appRouterStore;
|
|
90
|
+
}
|
|
91
|
+
get isMswEnabled() {
|
|
92
|
+
return this._runtime.isMswEnabled;
|
|
70
93
|
}
|
|
71
94
|
}
|
|
72
95
|
|
|
73
|
-
export { FireflyRuntime };
|
|
96
|
+
export { FireflyRuntime, FireflyRuntimeScope };
|
|
74
97
|
|
|
75
98
|
//# sourceMappingURL=FireflyRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FireflyRuntime.js","sources":["webpack://@squide/firefly/./src/FireflyRuntime.tsx"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeOptions } from \"@squide/core\";\nimport { MswPlugin, MswPluginName } from \"@squide/msw\";\nimport { ReactRouterRuntime, type Route } from \"@squide/react-router\";\nimport type { RequestHandler } from \"msw\";\nimport { getAreModulesRegistered } from \"./AppRouterReducer.ts\";\nimport { type AppRouterStore, createAppRouterStore } from \"./AppRouterStore.ts\";\n\nexport interface FireflyRuntimeOptions extends RuntimeOptions {\n useMsw?: boolean;\n}\n\nexport class FireflyRuntime extends ReactRouterRuntime {\n
|
|
1
|
+
{"version":3,"file":"FireflyRuntime.js","sources":["webpack://@squide/firefly/./src/FireflyRuntime.tsx"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from \"@squide/core\";\nimport { MswPlugin, MswPluginName } from \"@squide/msw\";\nimport { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from \"@squide/react-router\";\nimport type { Logger } from \"@workleap/logging\";\nimport type { RequestHandler } from \"msw\";\nimport { getAreModulesRegistered } from \"./AppRouterReducer.ts\";\nimport { type AppRouterStore, createAppRouterStore } from \"./AppRouterStore.ts\";\n\nexport interface FireflyRuntimeOptions extends RuntimeOptions {\n useMsw?: boolean;\n}\n\nexport interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}\n\nexport interface IFireflyRuntime extends IReactRouterRuntime {\n registerRequestHandlers: (handlers: RequestHandler[]) => void;\n get requestHandlers(): RequestHandler[];\n get appRouterStore(): AppRouterStore;\n get isMswEnabled(): boolean;\n}\n\nexport class FireflyRuntime extends ReactRouterRuntime implements IFireflyRuntime {\n protected _appRouterStore: AppRouterStore;\n protected _useMsw: boolean;\n\n constructor({ plugins, useMsw, ...options }: FireflyRuntimeOptions = {}) {\n if (useMsw) {\n super({\n plugins: [\n ...(plugins ?? []),\n runtime => new MswPlugin(runtime)\n ],\n ...options\n });\n\n this._useMsw = true;\n } else {\n super({\n plugins,\n ...options\n });\n\n this._useMsw = false;\n }\n\n this._appRouterStore = createAppRouterStore(this._logger);\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n const logger = this._getLogger(options);\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n throw new Error(\"[squide] Cannot register the provided MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \\\"useMsw\\\" option?\");\n }\n\n if (getAreModulesRegistered()) {\n throw new Error(\"[squide] Cannot register an MSW request handlers once the modules are registered. Are you trying to register an MSW request handler in a deferred registration function? Only navigation items can be registered in a deferred registration function.\");\n }\n\n mswPlugin.registerRequestHandlers(handlers, {\n logger\n });\n }\n\n // Must define a return type otherwise we get an \"error TS2742: The inferred type of 'requestHandlers' cannot be named\" error.\n get requestHandlers(): RequestHandler[] {\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n throw new Error(\"[squide] Cannot retrieve MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \\\"useMsw\\\" option?\");\n }\n\n return mswPlugin.requestHandlers;\n }\n\n registerRoute(route: Route, options: RegisterRouteOptions = {}) {\n if (getAreModulesRegistered()) {\n throw new Error(\"[squide] Cannot register a route once the modules are registered. Are you trying to register a route in a deferred registration function? Only navigation items can be registered in a deferred registration function.\");\n }\n\n super.registerRoute(route, options);\n }\n\n get appRouterStore() {\n return this._appRouterStore;\n }\n\n get isMswEnabled() {\n return this._useMsw;\n }\n\n startScope(logger: Logger): FireflyRuntime {\n return (new FireflyRuntimeScope(this, logger) as unknown) as FireflyRuntime;\n }\n}\n\nexport class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n this._runtime.registerRequestHandlers(handlers, {\n ...options,\n logger: this._getLogger(options)\n });\n }\n\n get requestHandlers(): RequestHandler[] {\n return this._runtime.requestHandlers;\n }\n\n get appRouterStore() {\n return this._runtime.appRouterStore;\n }\n\n get isMswEnabled() {\n return this._runtime.isMswEnabled;\n }\n}\n"],"names":["MswPlugin","MswPluginName","ReactRouterRuntime","ReactRouterRuntimeScope","getAreModulesRegistered","createAppRouterStore","FireflyRuntime","plugins","useMsw","options","runtime","handlers","logger","mswPlugin","Error","route","FireflyRuntimeScope"],"mappings":";;;;;;;;;;;;;;AACuD;AACkE;AAGzD;AACgB;AAezE,MAAMM,uBAAuBJ,kBAAkBA;IACxC,gBAAgC;IAChC,QAAiB;IAE3B,YAAY,EAAEK,OAAO,EAAEC,MAAM,EAAE,GAAGC,SAAgC,GAAG,CAAC,CAAC,CAAE;QACrE,IAAID,QAAQ;YACR,KAAK,CAAC;gBACF,SAAS;uBACDD,WAAW,EAAE;oBACjBG,CAAAA,UAAW,IAAIV,SAASA,CAACU;iB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,OAAO;YACV,QAAQ,IAAI,CAAC,UAAU,CAACA;QAC5B;IACJ;IAEA,IAAI,kBAAoC;QACpC,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe;IACxC;IAEA,IAAI,iBAAiB;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc;IACvC;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY;IACrC;AACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Span } from "@opentelemetry/api";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Logger } from "@workleap/logging";
|
|
3
3
|
export type ActiveSpanId = string;
|
|
4
4
|
export interface ActiveSpan {
|
|
5
5
|
id: ActiveSpanId;
|
|
@@ -9,4 +9,4 @@ export interface ActiveSpan {
|
|
|
9
9
|
export declare function registerActiveSpanStack(): void;
|
|
10
10
|
export declare function setActiveSpan(name: string, span: Span): ActiveSpan;
|
|
11
11
|
export declare function popActiveSpan(span: ActiveSpan): void;
|
|
12
|
-
export declare function createOverrideFetchRequestSpanWithActiveSpanContext(logger:
|
|
12
|
+
export declare function createOverrideFetchRequestSpanWithActiveSpanContext(logger: Logger): (span: Span, request: Request | RequestInit) => true | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"honeycomb/activeSpan.js","sources":["webpack://@squide/firefly/./src/honeycomb/activeSpan.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport { isPlainObject } from \"@squide/core\";\nimport type {
|
|
1
|
+
{"version":3,"file":"honeycomb/activeSpan.js","sources":["webpack://@squide/firefly/./src/honeycomb/activeSpan.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport { isPlainObject } from \"@squide/core\";\nimport type { Logger } from \"@workleap/logging\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { createTraceContextId } from \"./createTraceContextId.ts\";\n\nexport type ActiveSpanId = string;\n\nexport interface ActiveSpan {\n id: ActiveSpanId;\n name: string;\n instance: Span;\n}\n\n// Using a stack because we want a Last In First Out implementation for this.\n// https://github.com/open-telemetry/opentelemetry-js/issues/5084\n// https://github.com/open-telemetry/opentelemetry-js/issues/3558#issuecomment-1760680244\nclass ActiveSpanStack {\n readonly #stack: ActiveSpan[] = [];\n\n push(span: ActiveSpan) {\n this.#stack.push(span);\n }\n\n pop(span: ActiveSpan) {\n const head = this.#stack.pop();\n\n if (!head) {\n throw new Error(\"[squide] Unexpected pop, the active Honeycomb span stack is empty.\");\n }\n\n if (head.id !== span.id) {\n throw new Error(`[squide] The active Honeycomb span is not the expected span. Expected to pop span with name and id \"${span.name} / ${span.id}\" but found \"${head.name} / ${head.id}\". Did you forget to end an active span?`);\n }\n\n return head;\n }\n\n peek() {\n if (this.#stack.length === 0) {\n return undefined;\n }\n\n return this.#stack[this.#stack.length - 1];\n }\n}\n\nconst GlobalActiveSpanStackVariableName = \"__SQUIDE_HONEYCOMB_ACTIVE_SPAN_STACK__\";\n\nexport function registerActiveSpanStack() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (globalThis[GlobalActiveSpanStackVariableName]) {\n throw new Error(`[squide] An ActiveSpanStack instance has already been registered to globalThis.${GlobalActiveSpanStackVariableName}. Did you register the Honeycomb instrumentation twice?`);\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n globalThis[GlobalActiveSpanStackVariableName] = new ActiveSpanStack();\n}\n\nfunction getActiveSpanStack() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return globalThis[GlobalActiveSpanStackVariableName] as ActiveSpanStack;\n}\n\nfunction getActiveSpan() {\n const stack = getActiveSpanStack();\n\n if (stack) {\n return stack.peek();\n }\n}\n\nexport function setActiveSpan(name: string, span: Span) {\n const activeSpan: ActiveSpan = {\n id: uuidv4(),\n name: name,\n instance: span\n };\n\n const stack = getActiveSpanStack();\n\n if (stack) {\n stack.push(activeSpan);\n }\n\n return activeSpan;\n}\n\nexport function popActiveSpan(span: ActiveSpan) {\n const stack = getActiveSpanStack();\n\n if (stack) {\n stack.pop(span);\n }\n}\n\nexport function createOverrideFetchRequestSpanWithActiveSpanContext(logger: Logger) {\n return (span: Span, request: Request | RequestInit) => {\n const activeSpan = getActiveSpan();\n\n if (activeSpan) {\n const activeSpanContext = activeSpan.instance.spanContext();\n const requestSpanContext = span.spanContext();\n\n if (activeSpanContext) {\n logger\n .withText(\"[squide] Found a Honeycomb active context to apply to the following fetch request:\")\n .withLineChange()\n .withText(\"Request span context:\")\n .withObject(requestSpanContext)\n .withLineChange()\n .withText(\"Active span context:\")\n .withObject(activeSpanContext)\n .withLineChange()\n .withText(\"Request:\")\n .withObject(request)\n .debug();\n\n span.setAttribute(\"trace.trace_id\", activeSpanContext.traceId);\n span.setAttribute(\"trace.parent_id\", activeSpanContext.spanId);\n\n const traceParent = createTraceContextId(activeSpanContext.traceId, requestSpanContext.spanId, requestSpanContext.traceFlags);\n\n if (request instanceof Request) {\n request.headers.set(\"traceparent\", traceParent);\n } else if (isPlainObject(request.headers)) {\n request.headers[\"traceparent\"] = traceParent;\n }\n\n // Indicates to not propagate the requests to the subsequent hooks.\n return true;\n }\n }\n };\n}\n"],"names":["isPlainObject","v4","uuidv4","createTraceContextId","ActiveSpanStack","span","head","Error","undefined","GlobalActiveSpanStackVariableName","registerActiveSpanStack","globalThis","getActiveSpanStack","getActiveSpan","stack","setActiveSpan","name","activeSpan","popActiveSpan","createOverrideFetchRequestSpanWithActiveSpanContext","logger","request","activeSpanContext","requestSpanContext","traceParent","Request"],"mappings":";;;;;;;;;;;AAC6C;AAET;AAC6B;AAUjE,6EAA6E;AAC7E,iEAAiE;AACjE,yFAAyF;AACzF,MAAMI;IACO,MAAM,GAAiB,EAAE,CAAC;IAEnC,KAAKC,IAAgB,EAAE;QACnB,IAAI,CAAC,MAAM,CAAC,IAAI,CAACA;IACrB;IAEA,IAAIA,IAAgB,EAAE;QAClB,MAAMC,OAAO,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c,oDAAoDC,MAAc;IAC9E,OAAO,CAACf,MAAYgB;QAChB,MAAMJ,aAAaJ;QAEnB,IAAII,YAAY;YACZ,MAAMK,oBAAoBL,WAAW,QAAQ,CAAC,WAAW;YACzD,MAAMM,qBAAqBlB,KAAK,WAAW;YAE3C,IAAIiB,mBAAmB;gBACnBF,OACK,QAAQ,CAAC,sFACT,cAAc,GACd,QAAQ,CAAC,yBACT,UAAU,CAACG,oBACX,cAAc,GACd,QAAQ,CAAC,wBACT,UAAU,CAACD,mBACX,cAAc,GACd,QAAQ,CAAC,YACT,UAAU,CAACD,SACX,KAAK;gBAEVhB,KAAK,YAAY,CAAC,kBAAkBiB,kBAAkB,OAAO;gBAC7DjB,KAAK,YAAY,CAAC,mBAAmBiB,kBAAkB,MAAM;gBAE7D,MAAME,cAAcrB,oBAAoBA,CAACmB,kBAAkB,OAAO,EAAEC,mBAAmB,MAAM,EAAEA,mBAAmB,UAAU;gBAE5H,IAAIF,mBAAmBI,SAAS;oBAC5BJ,QAAQ,OAAO,CAAC,GAAG,CAAC,eAAeG;gBACvC,OAAO,IAAIxB,aAAaA,CAACqB,QAAQ,OAAO,GAAG;oBACvCA,QAAQ,OAAO,CAAC,cAAc,GAAGG;gBACrC;gBAEA,mEAAmE;gBACnE,OAAO;YACX;QACJ;IACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squide/firefly",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "14.0.0",
|
|
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": {
|
|
@@ -29,34 +29,34 @@
|
|
|
29
29
|
],
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@opentelemetry/api": "^1.9.0",
|
|
32
|
-
"@tanstack/react-query": "^5.
|
|
33
|
-
"msw": "^2.
|
|
32
|
+
"@tanstack/react-query": "^5.87.1",
|
|
33
|
+
"msw": "^2.11.1",
|
|
34
34
|
"react": "^18.0.0 || ^19.0.0",
|
|
35
35
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
36
|
-
"react-router": "^7.
|
|
36
|
+
"react-router": "^7.8.2"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@workleap/logging": "^1.
|
|
40
|
-
"uuid": "^
|
|
41
|
-
"@squide/core": "
|
|
42
|
-
"@squide/module-federation": "
|
|
43
|
-
"@squide/
|
|
44
|
-
"@squide/
|
|
39
|
+
"@workleap/logging": "^1.3.0",
|
|
40
|
+
"uuid": "^12.0.0",
|
|
41
|
+
"@squide/core": "6.0.0",
|
|
42
|
+
"@squide/module-federation": "7.0.0",
|
|
43
|
+
"@squide/msw": "4.0.0",
|
|
44
|
+
"@squide/react-router": "8.0.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@rsbuild/core": "1.4
|
|
48
|
-
"@rslib/core": "0.
|
|
47
|
+
"@rsbuild/core": "1.5.4",
|
|
48
|
+
"@rslib/core": "0.12.4",
|
|
49
49
|
"@testing-library/react": "16.3.0",
|
|
50
|
-
"@types/react": "19.1.
|
|
51
|
-
"@types/react-dom": "19.1.
|
|
52
|
-
"@typescript-eslint/parser": "8.
|
|
53
|
-
"@vitejs/plugin-react": "
|
|
50
|
+
"@types/react": "19.1.12",
|
|
51
|
+
"@types/react-dom": "19.1.9",
|
|
52
|
+
"@typescript-eslint/parser": "8.42.0",
|
|
53
|
+
"@vitejs/plugin-react": "5.0.2",
|
|
54
54
|
"@workleap/eslint-plugin": "3.5.0",
|
|
55
55
|
"@workleap/rslib-configs": "1.1.0",
|
|
56
56
|
"@workleap/typescript-configs": "3.0.4",
|
|
57
57
|
"eslint": "8.57.0",
|
|
58
58
|
"happy-dom": "18.0.1",
|
|
59
|
-
"typescript": "5.
|
|
59
|
+
"typescript": "5.9.2",
|
|
60
60
|
"vitest": "3.2.4"
|
|
61
61
|
},
|
|
62
62
|
"sideEffects": false,
|
package/src/AppRouterReducer.ts
CHANGED
|
@@ -188,16 +188,11 @@ export function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue:
|
|
|
188
188
|
dispatch({ type: "modules-registered" });
|
|
189
189
|
|
|
190
190
|
logger
|
|
191
|
-
.withText("[squide]"
|
|
192
|
-
.withText("Modules are registered", {
|
|
191
|
+
.withText("[squide] Modules are registered.", {
|
|
193
192
|
style: {
|
|
194
|
-
color: "
|
|
195
|
-
backgroundColor: "green"
|
|
193
|
+
color: "green"
|
|
196
194
|
}
|
|
197
195
|
})
|
|
198
|
-
.withText(".", {
|
|
199
|
-
leadingSpace: false
|
|
200
|
-
})
|
|
201
196
|
.information();
|
|
202
197
|
|
|
203
198
|
return true;
|
|
@@ -211,16 +206,11 @@ export function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue:
|
|
|
211
206
|
dispatch({ type: "modules-ready" });
|
|
212
207
|
|
|
213
208
|
logger
|
|
214
|
-
.withText("[squide]"
|
|
215
|
-
.withText("Modules are ready", {
|
|
209
|
+
.withText("[squide] Modules are ready.", {
|
|
216
210
|
style: {
|
|
217
|
-
color: "
|
|
218
|
-
backgroundColor: "green"
|
|
211
|
+
color: "green"
|
|
219
212
|
}
|
|
220
213
|
})
|
|
221
|
-
.withText(".", {
|
|
222
|
-
leadingSpace: false
|
|
223
|
-
})
|
|
224
214
|
.information();
|
|
225
215
|
|
|
226
216
|
return true;
|
|
@@ -258,16 +248,11 @@ export function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRo
|
|
|
258
248
|
dispatch({ type: "msw-ready" });
|
|
259
249
|
|
|
260
250
|
logger
|
|
261
|
-
.withText("[squide]"
|
|
262
|
-
.withText("MSW is ready", {
|
|
251
|
+
.withText("[squide] MSW is ready.", {
|
|
263
252
|
style: {
|
|
264
|
-
color: "
|
|
265
|
-
backgroundColor: "green"
|
|
253
|
+
color: "green"
|
|
266
254
|
}
|
|
267
255
|
})
|
|
268
|
-
.withText(".", {
|
|
269
|
-
leadingSpace: false
|
|
270
|
-
})
|
|
271
256
|
.information();
|
|
272
257
|
|
|
273
258
|
return true;
|
package/src/AppRouterStore.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// access to the state and ease the integration with third-party libraries such as the Platform Widgets.
|
|
3
3
|
// Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { Logger } from "@workleap/logging";
|
|
6
6
|
import type { AppRouterAction, AppRouterState } from "./AppRouterReducer.ts";
|
|
7
7
|
|
|
8
8
|
export type AppRouterStoreState = Omit<AppRouterState, "waitForMsw" | "waitForPublicData" | "waitForProtectedData">;
|
|
@@ -13,9 +13,9 @@ export class AppRouterStore {
|
|
|
13
13
|
#state: AppRouterStoreState;
|
|
14
14
|
|
|
15
15
|
readonly #listeners = new Set<AppRouterStoreListenerFunction>();
|
|
16
|
-
readonly #logger:
|
|
16
|
+
readonly #logger: Logger;
|
|
17
17
|
|
|
18
|
-
constructor(initialialState: AppRouterStoreState, logger:
|
|
18
|
+
constructor(initialialState: AppRouterStoreState, logger: Logger) {
|
|
19
19
|
this.#state = initialialState;
|
|
20
20
|
this.#logger = logger;
|
|
21
21
|
}
|
|
@@ -160,7 +160,7 @@ export class AppRouterStore {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
export function createAppRouterStore(logger:
|
|
163
|
+
export function createAppRouterStore(logger: Logger) {
|
|
164
164
|
const initialState: AppRouterStoreState = {
|
|
165
165
|
areModulesRegistered: false,
|
|
166
166
|
areModulesReady: false,
|
package/src/FireflyRuntime.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { RegisterRouteOptions, RuntimeOptions } from "@squide/core";
|
|
1
|
+
import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from "@squide/core";
|
|
2
2
|
import { MswPlugin, MswPluginName } from "@squide/msw";
|
|
3
|
-
import { ReactRouterRuntime, type Route } from "@squide/react-router";
|
|
3
|
+
import { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from "@squide/react-router";
|
|
4
|
+
import type { Logger } from "@workleap/logging";
|
|
4
5
|
import type { RequestHandler } from "msw";
|
|
5
6
|
import { getAreModulesRegistered } from "./AppRouterReducer.ts";
|
|
6
7
|
import { type AppRouterStore, createAppRouterStore } from "./AppRouterStore.ts";
|
|
@@ -9,9 +10,18 @@ export interface FireflyRuntimeOptions extends RuntimeOptions {
|
|
|
9
10
|
useMsw?: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
export interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}
|
|
14
|
+
|
|
15
|
+
export interface IFireflyRuntime extends IReactRouterRuntime {
|
|
16
|
+
registerRequestHandlers: (handlers: RequestHandler[]) => void;
|
|
17
|
+
get requestHandlers(): RequestHandler[];
|
|
18
|
+
get appRouterStore(): AppRouterStore;
|
|
19
|
+
get isMswEnabled(): boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class FireflyRuntime extends ReactRouterRuntime implements IFireflyRuntime {
|
|
23
|
+
protected _appRouterStore: AppRouterStore;
|
|
24
|
+
protected _useMsw: boolean;
|
|
15
25
|
|
|
16
26
|
constructor({ plugins, useMsw, ...options }: FireflyRuntimeOptions = {}) {
|
|
17
27
|
if (useMsw) {
|
|
@@ -23,20 +33,21 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
23
33
|
...options
|
|
24
34
|
});
|
|
25
35
|
|
|
26
|
-
this
|
|
36
|
+
this._useMsw = true;
|
|
27
37
|
} else {
|
|
28
38
|
super({
|
|
29
39
|
plugins,
|
|
30
40
|
...options
|
|
31
41
|
});
|
|
32
42
|
|
|
33
|
-
this
|
|
43
|
+
this._useMsw = false;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
|
-
this
|
|
46
|
+
this._appRouterStore = createAppRouterStore(this._logger);
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
registerRequestHandlers(handlers: RequestHandler[]) {
|
|
49
|
+
registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {
|
|
50
|
+
const logger = this._getLogger(options);
|
|
40
51
|
const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;
|
|
41
52
|
|
|
42
53
|
if (!mswPlugin) {
|
|
@@ -47,7 +58,9 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
47
58
|
throw new Error("[squide] Cannot register an MSW request handlers once the modules are registered. Are you trying to register an MSW request handler in a deferred registration function? Only navigation items can be registered in a deferred registration function.");
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
mswPlugin.registerRequestHandlers(handlers
|
|
61
|
+
mswPlugin.registerRequestHandlers(handlers, {
|
|
62
|
+
logger
|
|
63
|
+
});
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
// Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
|
|
@@ -70,10 +83,35 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
get appRouterStore() {
|
|
73
|
-
return this
|
|
86
|
+
return this._appRouterStore;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get isMswEnabled() {
|
|
90
|
+
return this._useMsw;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
startScope(logger: Logger): FireflyRuntime {
|
|
94
|
+
return (new FireflyRuntimeScope(this, logger) as unknown) as FireflyRuntime;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {
|
|
99
|
+
registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {
|
|
100
|
+
this._runtime.registerRequestHandlers(handlers, {
|
|
101
|
+
...options,
|
|
102
|
+
logger: this._getLogger(options)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get requestHandlers(): RequestHandler[] {
|
|
107
|
+
return this._runtime.requestHandlers;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get appRouterStore() {
|
|
111
|
+
return this._runtime.appRouterStore;
|
|
74
112
|
}
|
|
75
113
|
|
|
76
114
|
get isMswEnabled() {
|
|
77
|
-
return this
|
|
115
|
+
return this._runtime.isMswEnabled;
|
|
78
116
|
}
|
|
79
117
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Span } from "@opentelemetry/api";
|
|
2
2
|
import { isPlainObject } from "@squide/core";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Logger } from "@workleap/logging";
|
|
4
4
|
import { v4 as uuidv4 } from "uuid";
|
|
5
5
|
import { createTraceContextId } from "./createTraceContextId.ts";
|
|
6
6
|
|
|
@@ -97,7 +97,7 @@ export function popActiveSpan(span: ActiveSpan) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export function createOverrideFetchRequestSpanWithActiveSpanContext(logger:
|
|
100
|
+
export function createOverrideFetchRequestSpanWithActiveSpanContext(logger: Logger) {
|
|
101
101
|
return (span: Span, request: Request | RequestInit) => {
|
|
102
102
|
const activeSpan = getActiveSpan();
|
|
103
103
|
|