@squide/firefly 16.0.3 → 16.1.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 +15 -0
- package/dist/AppRouter.js +1 -1
- package/dist/AppRouter.js.map +1 -1
- package/dist/AppRouterContext.js +2 -2
- package/dist/AppRouterContext.js.map +1 -1
- package/dist/AppRouterReducer.d.ts +3 -1
- package/dist/AppRouterReducer.js +35 -4
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/AppRouterStore.js +8 -0
- package/dist/AppRouterStore.js.map +1 -1
- package/dist/FireflyRuntime.d.ts +32 -16
- package/dist/FireflyRuntime.js +61 -19
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/honeycomb/activeSpan.js +2 -2
- package/dist/honeycomb/activeSpan.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/initializeFirefly.d.ts +4 -2
- package/dist/initializeFirefly.js +15 -4
- package/dist/initializeFirefly.js.map +1 -1
- package/dist/useCanUpdateDeferredRegistrations.js +2 -2
- package/dist/useCanUpdateDeferredRegistrations.js.map +1 -1
- package/dist/useDeferredRegistrations.d.ts +1 -1
- package/dist/useDeferredRegistrations.js +6 -5
- package/dist/useDeferredRegistrations.js.map +1 -1
- package/dist/useRegisterDeferredRegistrations.d.ts +1 -2
- package/dist/useRegisterDeferredRegistrations.js +9 -2
- package/dist/useRegisterDeferredRegistrations.js.map +1 -1
- package/dist/useStrictRegistrationMode.js +10 -8
- package/dist/useStrictRegistrationMode.js.map +1 -1
- package/dist/useUpdateDeferredRegistrations.d.ts +1 -2
- package/dist/useUpdateDeferredRegistrations.js +7 -1
- package/dist/useUpdateDeferredRegistrations.js.map +1 -1
- package/package.json +19 -17
- package/src/AppRouter.tsx +1 -1
- package/src/AppRouterContext.ts +1 -1
- package/src/AppRouterReducer.ts +38 -3
- package/src/AppRouterStore.ts +8 -0
- package/src/FireflyRuntime.tsx +85 -30
- package/src/honeycomb/activeSpan.ts +1 -1
- package/src/index.ts +18 -2
- package/src/initializeFirefly.ts +38 -27
- package/src/useCanUpdateDeferredRegistrations.ts +3 -1
- package/src/useDeferredRegistrations.ts +15 -6
- package/src/useRegisterDeferredRegistrations.ts +5 -3
- package/src/useStrictRegistrationMode.ts +11 -11
- package/src/useUpdateDeferredRegistrations.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @squide/firefly
|
|
2
2
|
|
|
3
|
+
## 16.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#352](https://github.com/workleap/wl-squide/pull/352) [`7bd7af5`](https://github.com/workleap/wl-squide/commit/7bd7af5a757912309704b9e93bf8ecf1388e6787) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added support for LaunchDarkly feature flags.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`7bd7af5`](https://github.com/workleap/wl-squide/commit/7bd7af5a757912309704b9e93bf8ecf1388e6787), [`7bd7af5`](https://github.com/workleap/wl-squide/commit/7bd7af5a757912309704b9e93bf8ecf1388e6787)]:
|
|
12
|
+
- @squide/react-router@8.1.7
|
|
13
|
+
- @squide/env-vars@1.4.10
|
|
14
|
+
- @squide/core@6.1.7
|
|
15
|
+
- @squide/msw@4.0.8
|
|
16
|
+
- @squide/launch-darkly@1.0.0
|
|
17
|
+
|
|
3
18
|
## 16.0.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/AppRouter.js
CHANGED
|
@@ -68,7 +68,7 @@ function AppRouter(props) {
|
|
|
68
68
|
isEnabled: strictMode
|
|
69
69
|
});
|
|
70
70
|
useEffect(()=>{
|
|
71
|
-
logger.withText("[squide] AppRouter state updated:").withObject(state).debug();
|
|
71
|
+
logger.withText("[squide] AppRouter state has been updated to:").withObject(state).debug();
|
|
72
72
|
}, [
|
|
73
73
|
state,
|
|
74
74
|
logger
|
package/dist/AppRouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouter.js","sources":["../src/AppRouter.tsx"],"sourcesContent":["import { useLogger } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { RootRoute } from \"./RootRoute.tsx\";\nimport { useStrictRegistrationMode } from \"./useStrictRegistrationMode.ts\";\n\nexport interface AppRouterRenderFunctionArgs {\n routes: Route[];\n}\n\nexport interface RenderRouterProviderFunctionArgs {\n rootRoute: ReactElement;\n registeredRoutes: Route[];\n routerProviderProps: Omit<RouterProviderProps, \"router\">;\n}\n\nexport type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;\n\nexport function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState) {\n return (\n // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably\n // depends on the protected data.\n (areModulesRegistered || areModulesReadyValue)\n );\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction, strictMode: boolean) {\n const routes = useRoutes();\n\n // The value is computed outside of the router provider memo to prevent\n // rendering a new router provider everytime the app router state change.\n const canRenderRouter = useCanRenderRouter(state);\n\n return useMemo(() => {\n if (canRenderRouter) {\n return renderRouterProvider({\n rootRoute: <RootRoute strictMode={strictMode} />,\n registeredRoutes: routes,\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [canRenderRouter, routes, renderRouterProvider, strictMode]);\n}\n\nexport interface AppRouterProps {\n waitForPublicData?: boolean;\n waitForProtectedData?: boolean;\n strictMode?: boolean;\n children: RenderRouterProviderFunction;\n}\n\nexport function AppRouter(props: AppRouterProps) {\n const {\n waitForPublicData = false,\n waitForProtectedData = false,\n strictMode = true,\n children: renderRouterProvider\n } = props;\n const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);\n\n const logger = useLogger();\n\n useStrictRegistrationMode({\n isEnabled: strictMode\n });\n\n useEffect(() => {\n logger\n .withText(\"[squide] AppRouter state updated:\")\n .withObject(state)\n .debug();\n }, [state, logger]);\n\n const routerProvider = useRenderRouterProvider(state, renderRouterProvider, strictMode);\n\n return (\n <AppRouterDispatcherContext.Provider value={dispatch}>\n <AppRouterStateContext.Provider value={state}>\n {routerProvider}\n </AppRouterStateContext.Provider>\n </AppRouterDispatcherContext.Provider>\n );\n}\n"],"names":["useLogger","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","useRenderRouterProvider","state","renderRouterProvider","strictMode","routes","canRenderRouter","AppRouter","props","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAyC;AACoB;AACC;AAE4B;AACT;AACrC;AAC+B;AAcpE,SAASS,mBAAmB,EAAEC,oBAAoB,EAAE,iBAAiBC,oBAAoB,EAAkB;IAC9G,OACI,qIAAqI;IACrI,iCAAiC;IAChCD,wBAAwBC;AAEjC;AAEA,SAASC,wBAAwBC,KAAqB,EAAEC,oBAAkD,EAAEC,UAAmB;IAC3H,MAAMC,SAASf,SAASA;IAExB,uEAAuE;IACvE,yEAAyE;IACzE,MAAMgB,kBAAkBR,mBAAmBI;IAE3C,OAAOV,OAAOA,CAAC;QACX,IAAIc,iBAAiB;YACjB,OAAOH,qBAAqB;gBACxB,yBAAW,IAACP,SAASA;oBAAC,YAAYQ;;gBAClC,kBAAkBC;gBAClB,qBAAqB,CAAC;YAC1B;QACJ;QAEA,OAAO;IACX,GAAG;QAACC;QAAiBD;QAAQF;QAAsBC;KAAW;AAClE;AASO,SAASG,UAAUC,KAAqB;IAC3C,MAAM,EACFC,oBAAoB,KAAK,EACzBC,uBAAuB,KAAK,EAC5BN,aAAa,IAAI,EACjB,UAAUD,oBAAoB,EACjC,GAAGK;IACJ,MAAM,CAACN,OAAOS,SAAS,GAAGhB,mBAAmBA,CAACc,mBAAmBC;IAEjE,MAAME,SAASvB,SAASA;IAExBQ,yBAAyBA,CAAC;QACtB,WAAWO;IACf;IAEAb,SAASA,CAAC;QACNqB,OACK,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"AppRouter.js","sources":["../src/AppRouter.tsx"],"sourcesContent":["import { useLogger } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { RootRoute } from \"./RootRoute.tsx\";\nimport { useStrictRegistrationMode } from \"./useStrictRegistrationMode.ts\";\n\nexport interface AppRouterRenderFunctionArgs {\n routes: Route[];\n}\n\nexport interface RenderRouterProviderFunctionArgs {\n rootRoute: ReactElement;\n registeredRoutes: Route[];\n routerProviderProps: Omit<RouterProviderProps, \"router\">;\n}\n\nexport type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;\n\nexport function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState) {\n return (\n // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably\n // depends on the protected data.\n (areModulesRegistered || areModulesReadyValue)\n );\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction, strictMode: boolean) {\n const routes = useRoutes();\n\n // The value is computed outside of the router provider memo to prevent\n // rendering a new router provider everytime the app router state change.\n const canRenderRouter = useCanRenderRouter(state);\n\n return useMemo(() => {\n if (canRenderRouter) {\n return renderRouterProvider({\n rootRoute: <RootRoute strictMode={strictMode} />,\n registeredRoutes: routes,\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [canRenderRouter, routes, renderRouterProvider, strictMode]);\n}\n\nexport interface AppRouterProps {\n waitForPublicData?: boolean;\n waitForProtectedData?: boolean;\n strictMode?: boolean;\n children: RenderRouterProviderFunction;\n}\n\nexport function AppRouter(props: AppRouterProps) {\n const {\n waitForPublicData = false,\n waitForProtectedData = false,\n strictMode = true,\n children: renderRouterProvider\n } = props;\n const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);\n\n const logger = useLogger();\n\n useStrictRegistrationMode({\n isEnabled: strictMode\n });\n\n useEffect(() => {\n logger\n .withText(\"[squide] AppRouter state has been updated to:\")\n .withObject(state)\n .debug();\n }, [state, logger]);\n\n const routerProvider = useRenderRouterProvider(state, renderRouterProvider, strictMode);\n\n return (\n <AppRouterDispatcherContext.Provider value={dispatch}>\n <AppRouterStateContext.Provider value={state}>\n {routerProvider}\n </AppRouterStateContext.Provider>\n </AppRouterDispatcherContext.Provider>\n );\n}\n"],"names":["useLogger","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","useRenderRouterProvider","state","renderRouterProvider","strictMode","routes","canRenderRouter","AppRouter","props","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAyC;AACoB;AACC;AAE4B;AACT;AACrC;AAC+B;AAcpE,SAASS,mBAAmB,EAAEC,oBAAoB,EAAE,iBAAiBC,oBAAoB,EAAkB;IAC9G,OACI,qIAAqI;IACrI,iCAAiC;IAChCD,wBAAwBC;AAEjC;AAEA,SAASC,wBAAwBC,KAAqB,EAAEC,oBAAkD,EAAEC,UAAmB;IAC3H,MAAMC,SAASf,SAASA;IAExB,uEAAuE;IACvE,yEAAyE;IACzE,MAAMgB,kBAAkBR,mBAAmBI;IAE3C,OAAOV,OAAOA,CAAC;QACX,IAAIc,iBAAiB;YACjB,OAAOH,qBAAqB;gBACxB,yBAAW,IAACP,SAASA;oBAAC,YAAYQ;;gBAClC,kBAAkBC;gBAClB,qBAAqB,CAAC;YAC1B;QACJ;QAEA,OAAO;IACX,GAAG;QAACC;QAAiBD;QAAQF;QAAsBC;KAAW;AAClE;AASO,SAASG,UAAUC,KAAqB;IAC3C,MAAM,EACFC,oBAAoB,KAAK,EACzBC,uBAAuB,KAAK,EAC5BN,aAAa,IAAI,EACjB,UAAUD,oBAAoB,EACjC,GAAGK;IACJ,MAAM,CAACN,OAAOS,SAAS,GAAGhB,mBAAmBA,CAACc,mBAAmBC;IAEjE,MAAME,SAASvB,SAASA;IAExBQ,yBAAyBA,CAAC;QACtB,WAAWO;IACf;IAEAb,SAASA,CAAC;QACNqB,OACK,QAAQ,CAAC,iDACT,UAAU,CAACV,OACX,KAAK;IACd,GAAG;QAACA;QAAOU;KAAO;IAElB,MAAMC,iBAAiBZ,wBAAwBC,OAAOC,sBAAsBC;IAE5E,qBACI,IAACX,mCAAmC;QAAC,OAAOkB;kBACxC,kBAACjB,8BAA8B;YAAC,OAAOQ;sBAClCW;;;AAIjB"}
|
package/dist/AppRouterContext.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isNil } from "@squide/core";
|
|
1
|
+
import { isNil } from "@squide/core/internal";
|
|
2
2
|
import { createContext, useContext } from "react";
|
|
3
3
|
|
|
4
|
-
;// CONCATENATED MODULE: external "@squide/core"
|
|
4
|
+
;// CONCATENATED MODULE: external "@squide/core/internal"
|
|
5
5
|
|
|
6
6
|
;// CONCATENATED MODULE: external "react"
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouterContext.js","sources":["../src/AppRouterContext.ts"],"sourcesContent":["import { isNil } from \"@squide/core\";\nimport { createContext, useContext } from \"react\";\nimport type { AppRouterDispatch, AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport const AppRouterStateContext = createContext<AppRouterState | undefined>(undefined);\n\nexport function useAppRouterState() {\n const state = useContext(AppRouterStateContext);\n\n if (isNil(state)) {\n throw new Error(\"[squide] The useAppRouterState hook must be called by a children of the AppRouter component.\");\n }\n\n return state;\n}\n\nexport const AppRouterDispatcherContext = createContext<AppRouterDispatch | undefined>(undefined);\n\nexport function useAppRouterDispatcher() {\n const dispatch = useContext(AppRouterDispatcherContext);\n\n if (isNil(dispatch)) {\n throw new Error(\"[squide] The useAppRouterDispatcher hook must be called by a children of the AppRouter component.\");\n }\n\n return dispatch;\n}\n"],"names":["isNil","createContext","useContext","AppRouterStateContext","undefined","useAppRouterState","state","Error","AppRouterDispatcherContext","useAppRouterDispatcher","dispatch"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"AppRouterContext.js","sources":["../src/AppRouterContext.ts"],"sourcesContent":["import { isNil } from \"@squide/core/internal\";\nimport { createContext, useContext } from \"react\";\nimport type { AppRouterDispatch, AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport const AppRouterStateContext = createContext<AppRouterState | undefined>(undefined);\n\nexport function useAppRouterState() {\n const state = useContext(AppRouterStateContext);\n\n if (isNil(state)) {\n throw new Error(\"[squide] The useAppRouterState hook must be called by a children of the AppRouter component.\");\n }\n\n return state;\n}\n\nexport const AppRouterDispatcherContext = createContext<AppRouterDispatch | undefined>(undefined);\n\nexport function useAppRouterDispatcher() {\n const dispatch = useContext(AppRouterDispatcherContext);\n\n if (isNil(dispatch)) {\n throw new Error(\"[squide] The useAppRouterDispatcher hook must be called by a children of the AppRouter component.\");\n }\n\n return dispatch;\n}\n"],"names":["isNil","createContext","useContext","AppRouterStateContext","undefined","useAppRouterState","state","Error","AppRouterDispatcherContext","useAppRouterDispatcher","dispatch"],"mappings":";;;;;;;;AAA8C;AACI;AAG3C,MAAMG,wBAAwBF,aAAaA,CAA6BG,WAAW;AAEnF,SAASC;IACZ,MAAMC,QAAQJ,UAAUA,CAACC;IAEzB,IAAIH,KAAKA,CAACM,QAAQ;QACd,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX;AAEO,MAAME,6BAA6BP,aAAaA,CAAgCG,WAAW;AAE3F,SAASK;IACZ,MAAMC,WAAWR,UAAUA,CAACM;IAE5B,IAAIR,KAAKA,CAACU,WAAW;QACjB,MAAM,IAAIH,MAAM;IACpB;IAEA,OAAOG;AACX"}
|
|
@@ -14,11 +14,12 @@ export interface AppRouterState extends AppRouterWaitState {
|
|
|
14
14
|
isProtectedDataReady: boolean;
|
|
15
15
|
publicDataUpdatedAt?: number;
|
|
16
16
|
protectedDataUpdatedAt?: number;
|
|
17
|
+
featureFlagsUpdatedAt?: number;
|
|
17
18
|
deferredRegistrationsUpdatedAt?: number;
|
|
18
19
|
activeRouteVisibility: ActiveRouteVisiblity;
|
|
19
20
|
isUnauthorized: boolean;
|
|
20
21
|
}
|
|
21
|
-
export type AppRouterActionType = "modules-registered" | "modules-ready" | "msw-ready" | "public-data-ready" | "protected-data-ready" | "public-data-updated" | "protected-data-updated" | "deferred-registrations-updated" | "active-route-is-public" | "active-route-is-protected" | "is-unauthorized";
|
|
22
|
+
export type AppRouterActionType = "modules-registered" | "modules-ready" | "msw-ready" | "public-data-ready" | "protected-data-ready" | "public-data-updated" | "protected-data-updated" | "feature-flags-updated" | "deferred-registrations-updated" | "active-route-is-public" | "active-route-is-protected" | "is-unauthorized";
|
|
22
23
|
export declare const ModulesRegisteredEvent = "squide-modules-registered";
|
|
23
24
|
export declare const ModulesReadyEvent = "squide-modules-ready";
|
|
24
25
|
export declare const MswReadyEvent = "squide-msw-ready";
|
|
@@ -37,6 +38,7 @@ export interface AppRouterAction {
|
|
|
37
38
|
export type AppRouterDispatch = Dispatch<AppRouterAction>;
|
|
38
39
|
export declare function useModuleRegistrationStatusDispatcher(runtime: FireflyRuntime, areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch): void;
|
|
39
40
|
export declare function useMswStatusDispatcher(runtime: FireflyRuntime, isMswReadyValue: boolean, dispatch: AppRouterDispatch): void;
|
|
41
|
+
export declare function useFeatureFlagsUpdatedDispatcher(runtime: FireflyRuntime, dispatch: AppRouterDispatch): void;
|
|
40
42
|
export declare function __setAppReducerDispatchProxyFactory(factory: (reactDispatch: AppRouterDispatch) => AppRouterDispatch): void;
|
|
41
43
|
export declare function __clearAppReducerDispatchProxy(): void;
|
|
42
44
|
export declare function useAppRouterReducer(waitForPublicData: boolean, waitForProtectedData: boolean): [AppRouterState, AppRouterDispatch];
|
package/dist/AppRouterReducer.js
CHANGED
|
@@ -96,6 +96,14 @@ function reducer(state, action) {
|
|
|
96
96
|
};
|
|
97
97
|
break;
|
|
98
98
|
}
|
|
99
|
+
case "feature-flags-updated":
|
|
100
|
+
{
|
|
101
|
+
newState = {
|
|
102
|
+
...newState,
|
|
103
|
+
featureFlagsUpdatedAt: Date.now()
|
|
104
|
+
};
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
99
107
|
case "deferred-registrations-updated":
|
|
100
108
|
{
|
|
101
109
|
newState = {
|
|
@@ -199,10 +207,10 @@ function useMswStatusDispatcher(runtime, isMswReadyValue, dispatch) {
|
|
|
199
207
|
useEffect(()=>{
|
|
200
208
|
if (runtime.isMswEnabled) {
|
|
201
209
|
if (!isMswReadyValue) {
|
|
202
|
-
runtime.
|
|
210
|
+
runtime.mswState.addMswReadyListener(dispatchMswReady);
|
|
203
211
|
}
|
|
204
212
|
return ()=>{
|
|
205
|
-
runtime.
|
|
213
|
+
runtime.mswState.removeMswReadyListener(dispatchMswReady);
|
|
206
214
|
};
|
|
207
215
|
}
|
|
208
216
|
}, [
|
|
@@ -211,6 +219,28 @@ function useMswStatusDispatcher(runtime, isMswReadyValue, dispatch) {
|
|
|
211
219
|
dispatchMswReady
|
|
212
220
|
]);
|
|
213
221
|
}
|
|
222
|
+
function useFeatureFlagsUpdatedDispatcher(runtime, dispatch) {
|
|
223
|
+
const logger = useLogger();
|
|
224
|
+
const dispatchFeatureFlagsUpdated = useCallback((changes)=>{
|
|
225
|
+
dispatch({
|
|
226
|
+
type: "feature-flags-updated"
|
|
227
|
+
});
|
|
228
|
+
logger.withText("[squide] Feature flags has been updated to:").withObject(changes).debug();
|
|
229
|
+
}, [
|
|
230
|
+
dispatch,
|
|
231
|
+
logger
|
|
232
|
+
]);
|
|
233
|
+
useEffect(()=>{
|
|
234
|
+
if (runtime.isLaunchDarklyEnabled) {
|
|
235
|
+
runtime.featureFlagSetSnapshot.addSnapshotChangedListener(dispatchFeatureFlagsUpdated);
|
|
236
|
+
return ()=>{
|
|
237
|
+
runtime.featureFlagSetSnapshot.removeSnapshotChangedListener(dispatchFeatureFlagsUpdated);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}, [
|
|
241
|
+
runtime
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
214
244
|
function useBootstrappingCompletedDispatcher(waitState, state) {
|
|
215
245
|
const eventBus = useEventBus();
|
|
216
246
|
const areModulesRegisteredValue = state.areModulesRegistered;
|
|
@@ -271,7 +301,7 @@ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
|
271
301
|
const isMswEnabled = runtime.isMswEnabled;
|
|
272
302
|
const areModulesInitiallyRegistered = runtime.moduleManager.getAreModulesRegistered();
|
|
273
303
|
const areModulesInitiallyReady = runtime.moduleManager.getAreModulesReady();
|
|
274
|
-
const isMswInitiallyReady = runtime.isMswEnabled ? runtime.
|
|
304
|
+
const isMswInitiallyReady = runtime.isMswEnabled ? runtime.mswState.isReady : false;
|
|
275
305
|
const waitState = useMemo(()=>({
|
|
276
306
|
waitForMsw: isMswEnabled,
|
|
277
307
|
waitForPublicData,
|
|
@@ -358,6 +388,7 @@ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
|
358
388
|
const dispatch = useEnhancedReducerDispatch(waitState, dispatchProxy);
|
|
359
389
|
useModuleRegistrationStatusDispatcher(runtime, areModulesRegisteredValue, areModulesReadyValue, dispatch);
|
|
360
390
|
useMswStatusDispatcher(runtime, isMswReadyValue, dispatch);
|
|
391
|
+
useFeatureFlagsUpdatedDispatcher(runtime, dispatch);
|
|
361
392
|
useBootstrappingCompletedDispatcher(waitState, state);
|
|
362
393
|
return [
|
|
363
394
|
state,
|
|
@@ -365,6 +396,6 @@ function useAppRouterReducer(waitForPublicData, waitForProtectedData) {
|
|
|
365
396
|
];
|
|
366
397
|
}
|
|
367
398
|
|
|
368
|
-
export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, useAppRouterReducer, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
|
|
399
|
+
export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, useAppRouterReducer, useFeatureFlagsUpdatedDispatcher, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
|
|
369
400
|
|
|
370
401
|
//# sourceMappingURL=AppRouterReducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouterReducer.js","sources":["../src/AppRouterReducer.ts"],"sourcesContent":["import { useEventBus, useLogger, useRuntime } from \"@squide/core\";\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 useModuleRegistrationStatusDispatcher(runtime: FireflyRuntime, areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchModulesRegistered = useCallback(() => {\n dispatch({ type: \"modules-registered\" });\n\n logger\n .withText(\"[squide] Modules are registered.\", {\n style: {\n color: \"green\"\n }\n })\n .information();\n }, [dispatch, logger]);\n\n const dispatchModulesReady = useCallback(() => {\n dispatch({ type: \"modules-ready\" });\n\n logger\n .withText(\"[squide] Modules are ready.\", {\n style: {\n color: \"green\"\n }\n })\n .information();\n }, [dispatch, logger]);\n\n return useEffect(() => {\n if (!areModulesRegisteredValue) {\n runtime.moduleManager.registerModulesRegisteredListener(dispatchModulesRegistered);\n }\n\n if (!areModulesReadyValue) {\n runtime.moduleManager.registerModulesReadyListener(dispatchModulesReady);\n }\n\n return () => {\n runtime.moduleManager.removeModulesRegisteredListener(dispatchModulesRegistered);\n runtime.moduleManager.removeModulesReadyListener(dispatchModulesReady);\n };\n }, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);\n}\n\nexport function useMswStatusDispatcher(runtime: FireflyRuntime, isMswReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchMswReady = useCallback(() => {\n dispatch({ type: \"msw-ready\" });\n\n logger\n .withText(\"[squide] MSW is ready.\", {\n style: {\n color: \"green\"\n }\n })\n .information();\n }, [dispatch, logger]);\n\n useEffect(() => {\n if (runtime.isMswEnabled) {\n if (!isMswReadyValue) {\n runtime.getMswState().addMswReadyListener(dispatchMswReady);\n }\n\n return () => {\n runtime.getMswState().removeMswReadyListener(dispatchMswReady);\n };\n }\n }, [runtime, 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 const areModulesInitiallyRegistered = runtime.moduleManager.getAreModulesRegistered();\n const areModulesInitiallyReady = runtime.moduleManager.getAreModulesReady();\n const isMswInitiallyReady = runtime.isMswEnabled ? runtime.getMswState().isReady : false;\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(runtime, areModulesRegisteredValue, areModulesReadyValue, dispatch);\n useMswStatusDispatcher(runtime, isMswReadyValue, dispatch);\n useBootstrappingCompletedDispatcher(waitState, state);\n\n return [state, dispatch];\n}\n"],"names":["useEventBus","useLogger","useRuntime","useCallback","useEffect","useMemo","useReducer","useAppRouterStore","useExecuteOnce","isBootstrapping","ModulesRegisteredEvent","ModulesReadyEvent","MswReadyEvent","ActiveRouteIsPublicEvent","ActiveRouteIsProtectedEvent","PublicDataReadyEvent","ProtectedDataReadyEvent","PublicDataUpdatedEvent","ProtectedDataUpdatedEvent","DeferredRegistrationsUpdatedEvent","ApplicationBoostrappedEvent","reducer","state","action","newState","Date","Error","useModuleRegistrationStatusDispatcher","runtime","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","isMswEnabled","areModulesInitiallyRegistered","areModulesInitiallyReady","isMswInitiallyReady","initialState","dispatchProxy"],"mappings":";;;;;;;;;;;;;;;;;AAAkE;AACiB;AAExB;AACN;AACK;AAoC1D,wFAAwF;AACxF,8DAA8D;AACvD,MAAMU,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,SA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C;QAEA,OAAO;IACX,GAAG;QAACkB;QAA0BN;QAAgBX;QAAUD;KAAU,GAAG;IAErE,2IAA2I;IAC3I,6HAA6H;IAC7H/B,cAAcA,CAACL,WAAWA,CAAC;QACvB,IAAIuD,qBAAqB;YACrBP,eAAe,QAAQ,CAAC;gBAAE,MAAM;gBAAa,SAASZ;YAAU;YAChEC,SAAS,QAAQ,CAAC5B,eAAe2B;QACrC;QAEA,OAAO;IACX,GAAG;QAACmB;QAAqBP;QAAgBX;QAAUD;KAAU,GAAG;IAEhE,MAAM,CAACjB,OAAO0B,cAAc,GAAG1C,UAAUA,CAACe,SAASsC;IAEnD,MAAM,EACF,sBAAsB9B,yBAAyB,EAC/C,iBAAiBC,oBAAoB,EACrC,YAAYM,eAAe,EAC9B,GAAGd;IAEJ,iHAAiH;IACjH,sCAAsC;IACtC,MAAMsC,gBAAgBb,wBAAwBC;IAC9C,MAAMjB,WAAWkB,2BAA2BV,WAAWqB;IAEvDjC,sCAAsCC,SAASC,2BAA2BC,sBAAsBC;IAChGI,uBAAuBP,SAASQ,iBAAiBL;IACjDO,oCAAoCC,WAAWjB;IAE/C,OAAO;QAACA;QAAOS;KAAS;AAC5B"}
|
|
1
|
+
{"version":3,"file":"AppRouterReducer.js","sources":["../src/AppRouterReducer.ts"],"sourcesContent":["import { useEventBus, useLogger, useRuntime } from \"@squide/core\";\nimport type { FeatureFlagSetSnapshotChangedListener } from \"@squide/launch-darkly\";\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 featureFlagsUpdatedAt?: 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 | \"feature-flags-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 \"feature-flags-updated\": {\n newState = {\n ...newState,\n featureFlagsUpdatedAt: 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 useModuleRegistrationStatusDispatcher(runtime: FireflyRuntime, areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchModulesRegistered = useCallback(() => {\n dispatch({ type: \"modules-registered\" });\n\n logger\n .withText(\"[squide] Modules are registered.\", {\n style: {\n color: \"green\"\n }\n })\n .information();\n }, [dispatch, logger]);\n\n const dispatchModulesReady = useCallback(() => {\n dispatch({ type: \"modules-ready\" });\n\n logger\n .withText(\"[squide] Modules are ready.\", {\n style: {\n color: \"green\"\n }\n })\n .information();\n }, [dispatch, logger]);\n\n return useEffect(() => {\n if (!areModulesRegisteredValue) {\n runtime.moduleManager.registerModulesRegisteredListener(dispatchModulesRegistered);\n }\n\n if (!areModulesReadyValue) {\n runtime.moduleManager.registerModulesReadyListener(dispatchModulesReady);\n }\n\n return () => {\n runtime.moduleManager.removeModulesRegisteredListener(dispatchModulesRegistered);\n runtime.moduleManager.removeModulesReadyListener(dispatchModulesReady);\n };\n }, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);\n}\n\nexport function useMswStatusDispatcher(runtime: FireflyRuntime, isMswReadyValue: boolean, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchMswReady = useCallback(() => {\n dispatch({ type: \"msw-ready\" });\n\n logger\n .withText(\"[squide] MSW is ready.\", {\n style: {\n color: \"green\"\n }\n })\n .information();\n }, [dispatch, logger]);\n\n useEffect(() => {\n if (runtime.isMswEnabled) {\n if (!isMswReadyValue) {\n runtime.mswState.addMswReadyListener(dispatchMswReady);\n }\n\n return () => {\n runtime.mswState.removeMswReadyListener(dispatchMswReady);\n };\n }\n }, [runtime, isMswReadyValue, dispatchMswReady]);\n}\n\nexport function useFeatureFlagsUpdatedDispatcher(runtime: FireflyRuntime, dispatch: AppRouterDispatch) {\n const logger = useLogger();\n\n const dispatchFeatureFlagsUpdated = useCallback((changes => {\n dispatch({ type: \"feature-flags-updated\" });\n\n logger\n .withText(\"[squide] Feature flags has been updated to:\")\n .withObject(changes)\n .debug();\n }) satisfies FeatureFlagSetSnapshotChangedListener, [dispatch, logger]);\n\n useEffect(() => {\n if (runtime.isLaunchDarklyEnabled) {\n runtime.featureFlagSetSnapshot.addSnapshotChangedListener(dispatchFeatureFlagsUpdated);\n\n return () => {\n runtime.featureFlagSetSnapshot.removeSnapshotChangedListener(dispatchFeatureFlagsUpdated);\n };\n }\n }, [runtime]);\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 const areModulesInitiallyRegistered = runtime.moduleManager.getAreModulesRegistered();\n const areModulesInitiallyReady = runtime.moduleManager.getAreModulesReady();\n const isMswInitiallyReady = runtime.isMswEnabled ? runtime.mswState.isReady : false;\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(runtime, areModulesRegisteredValue, areModulesReadyValue, dispatch);\n useMswStatusDispatcher(runtime, isMswReadyValue, dispatch);\n useFeatureFlagsUpdatedDispatcher(runtime, dispatch);\n useBootstrappingCompletedDispatcher(waitState, state);\n\n return [state, dispatch];\n}\n"],"names":["useEventBus","useLogger","useRuntime","useCallback","useEffect","useMemo","useReducer","useAppRouterStore","useExecuteOnce","isBootstrapping","ModulesRegisteredEvent","ModulesReadyEvent","MswReadyEvent","ActiveRouteIsPublicEvent","ActiveRouteIsProtectedEvent","PublicDataReadyEvent","ProtectedDataReadyEvent","PublicDataUpdatedEvent","ProtectedDataUpdatedEvent","DeferredRegistrationsUpdatedEvent","ApplicationBoostrappedEvent","reducer","state","action","newState","Date","Error","useModuleRegistrationStatusDispatcher","runtime","areModulesRegisteredValue","areModulesReadyValue","dispatch","logger","dispatchModulesRegistered","dispatchModulesReady","useMswStatusDispatcher","isMswReadyValue","dispatchMswReady","useFeatureFlagsUpdatedDispatcher","dispatchFeatureFlagsUpdated","changes","useBootstrappingCompletedDispatcher","waitState","eventBus","isBoostrapping","dispatchProxyFactory","__setAppReducerDispatchProxyFactory","factory","__clearAppReducerDispatchProxy","undefined","useReducerDispatchProxy","reactDispatch","useEnhancedReducerDispatch","reducerDispatch","appRouterStore","useAppRouterReducer","waitForPublicData","waitForProtectedData","isMswEnabled","areModulesInitiallyRegistered","areModulesInitiallyReady","isMswInitiallyReady","initialState","dispatchProxy"],"mappings":";;;;;;;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O;IACX,GAAG;QAACmB;QAAqBP;QAAgBX;QAAUD;KAAU,GAAG;IAEhE,MAAM,CAACpB,OAAO6B,cAAc,GAAG7C,UAAUA,CAACe,SAASyC;IAEnD,MAAM,EACF,sBAAsBjC,yBAAyB,EAC/C,iBAAiBC,oBAAoB,EACrC,YAAYM,eAAe,EAC9B,GAAGd;IAEJ,iHAAiH;IACjH,sCAAsC;IACtC,MAAMyC,gBAAgBb,wBAAwBC;IAC9C,MAAMpB,WAAWqB,2BAA2BV,WAAWqB;IAEvDpC,sCAAsCC,SAASC,2BAA2BC,sBAAsBC;IAChGI,uBAAuBP,SAASQ,iBAAiBL;IACjDO,iCAAiCV,SAASG;IAC1CU,oCAAoCC,WAAWpB;IAE/C,OAAO;QAACA;QAAOS;KAAS;AAC5B"}
|
package/dist/AppRouterStore.js
CHANGED
|
@@ -97,6 +97,14 @@ class AppRouterStore {
|
|
|
97
97
|
};
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
|
+
case "feature-flags-updated":
|
|
101
|
+
{
|
|
102
|
+
newState = {
|
|
103
|
+
...newState,
|
|
104
|
+
featureFlagsUpdatedAt: Date.now()
|
|
105
|
+
};
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
100
108
|
case "deferred-registrations-updated":
|
|
101
109
|
{
|
|
102
110
|
newState = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouterStore.js","sources":["../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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ACJ;YACA,KAAK;gBAA6B;oBAC9BA,WAAW;wBACP,GAAGA,QAAQ;wBACX,uBAAuB;oBAC3B;oBAEA;gBACJ;YACA,KAAK;gBAAmB;oBACpBA,WAAW;wBACP,GAAGA,QAAQ;wBACX,gBAAgB;oBACpB;oBAEA;gBACJ;YACA;gBAAS;oBACL,MAAM,IAAII,MAAM,CAAC,uEAAuE,EAAEL,OAAO,IAAI,CAAC,EAAE,CAAC;gBAC7G;QACJ;QAEA,OAAOC;IACX;IAEA,IAAI,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"}
|
|
1
|
+
{"version":3,"file":"AppRouterStore.js","sources":["../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 \"feature-flags-updated\": {\n newState = {\n ...newState,\n featureFlagsUpdatedAt: 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,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;YACA,KAAK;gBAAmB;oBACpBA,WAAW;wBACP,GAAGA,QAAQ;wBACX,gBAAgB;oBACpB;oBAEA;gBACJ;YACA;gBAAS;oBACL,MAAM,IAAII,MAAM,CAAC,uEAAuE,EAAEL,OAAO,IAAI,CAAC,EAAE,CAAC;gBAC7G;QACJ;QAEA,OAAOC;IACX;IAEA,IAAI,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,9 +1,11 @@
|
|
|
1
1
|
import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from "@squide/core";
|
|
2
|
-
import { EnvironmentVariableKey, EnvironmentVariables
|
|
2
|
+
import { EnvironmentVariableKey, EnvironmentVariables } from "@squide/env-vars";
|
|
3
|
+
import { FeatureFlagKey, FeatureFlags, FeatureFlagSetSnapshot } from "@squide/launch-darkly";
|
|
3
4
|
import { MswState } from "@squide/msw";
|
|
4
5
|
import { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from "@squide/react-router";
|
|
5
6
|
import type { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
|
|
6
7
|
import type { Logger } from "@workleap/logging";
|
|
8
|
+
import { LDClient } from "launchdarkly-js-client-sdk";
|
|
7
9
|
import type { RequestHandler } from "msw";
|
|
8
10
|
import { type AppRouterStore } from "./AppRouterStore.ts";
|
|
9
11
|
export interface FireflyRuntimeOptions<TRuntime extends FireflyRuntime = FireflyRuntime> extends RuntimeOptions<TRuntime> {
|
|
@@ -12,43 +14,57 @@ export interface FireflyRuntimeOptions<TRuntime extends FireflyRuntime = Firefly
|
|
|
12
14
|
export interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {
|
|
13
15
|
}
|
|
14
16
|
export interface IFireflyRuntime extends IReactRouterRuntime {
|
|
15
|
-
|
|
17
|
+
get isMswEnabled(): boolean;
|
|
18
|
+
get mswState(): MswState;
|
|
16
19
|
registerRequestHandlers: (handlers: RequestHandler[]) => void;
|
|
17
20
|
get requestHandlers(): RequestHandler[];
|
|
18
|
-
|
|
19
|
-
registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
|
|
21
|
+
registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]): void;
|
|
20
22
|
registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;
|
|
21
|
-
getEnvironmentVariable(key:
|
|
22
|
-
|
|
23
|
+
getEnvironmentVariable<T extends EnvironmentVariableKey>(key: T): EnvironmentVariables[T];
|
|
24
|
+
get environmentVariables(): EnvironmentVariables;
|
|
23
25
|
get appRouterStore(): AppRouterStore;
|
|
24
26
|
get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;
|
|
27
|
+
get isLaunchDarklyEnabled(): boolean;
|
|
28
|
+
get launchDarklyClient(): LDClient;
|
|
29
|
+
get featureFlags(): FeatureFlags;
|
|
30
|
+
getFeatureFlag(key: string, defaultValue?: unknown): unknown;
|
|
31
|
+
get featureFlagSetSnapshot(): FeatureFlagSetSnapshot;
|
|
25
32
|
}
|
|
26
33
|
export declare class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends ReactRouterRuntime<TRuntime> implements IFireflyRuntime {
|
|
27
|
-
|
|
28
|
-
protected _honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;
|
|
34
|
+
#private;
|
|
29
35
|
constructor(options?: FireflyRuntimeOptions);
|
|
30
36
|
registerRoute(route: Route, options?: RegisterRouteOptions): void;
|
|
31
|
-
|
|
37
|
+
get isMswEnabled(): boolean;
|
|
38
|
+
get mswState(): MswState;
|
|
32
39
|
registerRequestHandlers(handlers: RequestHandler[], options?: RegisterRequestHandlersOptions): void;
|
|
33
40
|
get requestHandlers(): RequestHandler[];
|
|
34
|
-
get isMswEnabled(): boolean;
|
|
35
41
|
getEnvironmentVariable(key: EnvironmentVariableKey): never;
|
|
36
|
-
|
|
37
|
-
registerEnvironmentVariable(key:
|
|
42
|
+
get environmentVariables(): EnvironmentVariables;
|
|
43
|
+
registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]): void;
|
|
38
44
|
registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;
|
|
39
45
|
get appRouterStore(): AppRouterStore;
|
|
40
46
|
get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;
|
|
47
|
+
get isLaunchDarklyEnabled(): boolean;
|
|
48
|
+
get launchDarklyClient(): LDClient;
|
|
49
|
+
get featureFlags(): FeatureFlags;
|
|
50
|
+
getFeatureFlag<T extends FeatureFlagKey>(key: T, defaultValue?: FeatureFlags[T]): FeatureFlags[T];
|
|
51
|
+
get featureFlagSetSnapshot(): FeatureFlagSetSnapshot;
|
|
41
52
|
startScope(logger: Logger): TRuntime;
|
|
42
53
|
}
|
|
43
54
|
export declare class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {
|
|
44
|
-
|
|
55
|
+
get isMswEnabled(): boolean;
|
|
56
|
+
get mswState(): MswState;
|
|
45
57
|
registerRequestHandlers(handlers: RequestHandler[], options?: RegisterRequestHandlersOptions): void;
|
|
46
58
|
get requestHandlers(): RequestHandler[];
|
|
47
|
-
get isMswEnabled(): boolean;
|
|
48
|
-
getEnvironmentVariables(): EnvironmentVariables;
|
|
49
59
|
getEnvironmentVariable(key: EnvironmentVariableKey): never;
|
|
50
|
-
|
|
60
|
+
get environmentVariables(): EnvironmentVariables;
|
|
61
|
+
registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]): void;
|
|
51
62
|
registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;
|
|
52
63
|
get appRouterStore(): AppRouterStore;
|
|
53
64
|
get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient;
|
|
65
|
+
get isLaunchDarklyEnabled(): boolean;
|
|
66
|
+
get launchDarklyClient(): LDClient;
|
|
67
|
+
get featureFlags(): FeatureFlags;
|
|
68
|
+
getFeatureFlag<T extends FeatureFlagKey>(key: T, defaultValue?: FeatureFlags[T]): FeatureFlags[T];
|
|
69
|
+
get featureFlagSetSnapshot(): FeatureFlagSetSnapshot;
|
|
54
70
|
}
|
package/dist/FireflyRuntime.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { getEnvironmentVariablesPlugin } from "@squide/env-vars";
|
|
2
|
+
import { LaunchDarklyPluginName, getLaunchDarklyPlugin } from "@squide/launch-darkly";
|
|
2
3
|
import { MswPluginName, getMswPlugin } from "@squide/msw";
|
|
3
4
|
import { ReactRouterRuntime, ReactRouterRuntimeScope } from "@squide/react-router";
|
|
4
5
|
import { createAppRouterStore } from "./AppRouterStore.js";
|
|
5
6
|
|
|
6
7
|
;// CONCATENATED MODULE: external "@squide/env-vars"
|
|
7
8
|
|
|
9
|
+
;// CONCATENATED MODULE: external "@squide/launch-darkly"
|
|
10
|
+
|
|
8
11
|
;// CONCATENATED MODULE: external "@squide/msw"
|
|
9
12
|
|
|
10
13
|
;// CONCATENATED MODULE: external "@squide/react-router"
|
|
@@ -16,15 +19,20 @@ import { createAppRouterStore } from "./AppRouterStore.js";
|
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
|
|
22
|
+
|
|
19
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
24
|
class FireflyRuntime extends ReactRouterRuntime {
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
#appRouterStore;
|
|
26
|
+
#honeycombInstrumentationClient;
|
|
27
|
+
#isMswEnabled;
|
|
28
|
+
#isLaunchDarklyEnabled;
|
|
23
29
|
constructor(options = {}){
|
|
24
30
|
const { honeycombInstrumentationClient } = options;
|
|
25
31
|
super(options);
|
|
26
|
-
this
|
|
27
|
-
this
|
|
32
|
+
this.#appRouterStore = createAppRouterStore(this._logger);
|
|
33
|
+
this.#honeycombInstrumentationClient = honeycombInstrumentationClient;
|
|
34
|
+
this.#isMswEnabled = this._plugins.some((x)=>x.name === MswPluginName);
|
|
35
|
+
this.#isLaunchDarklyEnabled = this._plugins.some((x)=>x.name === LaunchDarklyPluginName);
|
|
28
36
|
}
|
|
29
37
|
registerRoute(route, options = {}) {
|
|
30
38
|
if (this.moduleManager.getAreModulesRegistered()) {
|
|
@@ -32,7 +40,10 @@ class FireflyRuntime extends ReactRouterRuntime {
|
|
|
32
40
|
}
|
|
33
41
|
super.registerRoute(route, options);
|
|
34
42
|
}
|
|
35
|
-
|
|
43
|
+
get isMswEnabled() {
|
|
44
|
+
return this.#isMswEnabled;
|
|
45
|
+
}
|
|
46
|
+
get mswState() {
|
|
36
47
|
const plugin = getMswPlugin(this);
|
|
37
48
|
return plugin.mswState;
|
|
38
49
|
}
|
|
@@ -51,14 +62,11 @@ class FireflyRuntime extends ReactRouterRuntime {
|
|
|
51
62
|
const plugin = getMswPlugin(this);
|
|
52
63
|
return plugin.requestHandlers;
|
|
53
64
|
}
|
|
54
|
-
get isMswEnabled() {
|
|
55
|
-
return this._plugins.some((x)=>x.name === MswPluginName);
|
|
56
|
-
}
|
|
57
65
|
getEnvironmentVariable(key) {
|
|
58
66
|
const plugin = getEnvironmentVariablesPlugin(this);
|
|
59
67
|
return plugin.getVariable(key);
|
|
60
68
|
}
|
|
61
|
-
|
|
69
|
+
get environmentVariables() {
|
|
62
70
|
const plugin = getEnvironmentVariablesPlugin(this);
|
|
63
71
|
return plugin.getVariables();
|
|
64
72
|
}
|
|
@@ -71,18 +79,36 @@ class FireflyRuntime extends ReactRouterRuntime {
|
|
|
71
79
|
return plugin.registerVariables(variables);
|
|
72
80
|
}
|
|
73
81
|
get appRouterStore() {
|
|
74
|
-
return this
|
|
82
|
+
return this.#appRouterStore;
|
|
75
83
|
}
|
|
76
84
|
get honeycombInstrumentationClient() {
|
|
77
|
-
return this
|
|
85
|
+
return this.#honeycombInstrumentationClient;
|
|
86
|
+
}
|
|
87
|
+
get isLaunchDarklyEnabled() {
|
|
88
|
+
return this.#isLaunchDarklyEnabled;
|
|
89
|
+
}
|
|
90
|
+
get launchDarklyClient() {
|
|
91
|
+
return getLaunchDarklyPlugin(this).client;
|
|
92
|
+
}
|
|
93
|
+
get featureFlags() {
|
|
94
|
+
return this.featureFlagSetSnapshot.value;
|
|
95
|
+
}
|
|
96
|
+
getFeatureFlag(key, defaultValue) {
|
|
97
|
+
return getLaunchDarklyPlugin(this).getFeatureFlag(key, defaultValue);
|
|
98
|
+
}
|
|
99
|
+
get featureFlagSetSnapshot() {
|
|
100
|
+
return getLaunchDarklyPlugin(this).featureFlagSetSnapshot;
|
|
78
101
|
}
|
|
79
102
|
startScope(logger) {
|
|
80
103
|
return new FireflyRuntimeScope(this, logger);
|
|
81
104
|
}
|
|
82
105
|
}
|
|
83
106
|
class FireflyRuntimeScope extends ReactRouterRuntimeScope {
|
|
84
|
-
|
|
85
|
-
return this._runtime.
|
|
107
|
+
get isMswEnabled() {
|
|
108
|
+
return this._runtime.isMswEnabled;
|
|
109
|
+
}
|
|
110
|
+
get mswState() {
|
|
111
|
+
return this._runtime.mswState;
|
|
86
112
|
}
|
|
87
113
|
registerRequestHandlers(handlers, options = {}) {
|
|
88
114
|
this._runtime.registerRequestHandlers(handlers, {
|
|
@@ -94,15 +120,12 @@ class FireflyRuntimeScope extends ReactRouterRuntimeScope {
|
|
|
94
120
|
get requestHandlers() {
|
|
95
121
|
return this._runtime.requestHandlers;
|
|
96
122
|
}
|
|
97
|
-
get isMswEnabled() {
|
|
98
|
-
return this._runtime.isMswEnabled;
|
|
99
|
-
}
|
|
100
|
-
getEnvironmentVariables() {
|
|
101
|
-
return this._runtime.getEnvironmentVariables();
|
|
102
|
-
}
|
|
103
123
|
getEnvironmentVariable(key) {
|
|
104
124
|
return this._runtime.getEnvironmentVariable(key);
|
|
105
125
|
}
|
|
126
|
+
get environmentVariables() {
|
|
127
|
+
return this._runtime.environmentVariables;
|
|
128
|
+
}
|
|
106
129
|
registerEnvironmentVariable(key, value) {
|
|
107
130
|
this._runtime.registerEnvironmentVariable(key, value);
|
|
108
131
|
}
|
|
@@ -115,6 +138,25 @@ class FireflyRuntimeScope extends ReactRouterRuntimeScope {
|
|
|
115
138
|
get honeycombInstrumentationClient() {
|
|
116
139
|
throw new Error("[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.");
|
|
117
140
|
}
|
|
141
|
+
get isLaunchDarklyEnabled() {
|
|
142
|
+
return this._runtime.isLaunchDarklyEnabled;
|
|
143
|
+
}
|
|
144
|
+
get launchDarklyClient() {
|
|
145
|
+
return this._runtime.launchDarklyClient;
|
|
146
|
+
}
|
|
147
|
+
get featureFlags() {
|
|
148
|
+
return this._runtime.featureFlags;
|
|
149
|
+
}
|
|
150
|
+
getFeatureFlag(key, defaultValue) {
|
|
151
|
+
// The error is because the FeatureFlags interface is empty as it is expected to be augmented by the
|
|
152
|
+
// consumer application.
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
return this._runtime.getFeatureFlag(key, defaultValue);
|
|
156
|
+
}
|
|
157
|
+
get featureFlagSetSnapshot() {
|
|
158
|
+
return this._runtime.featureFlagSetSnapshot;
|
|
159
|
+
}
|
|
118
160
|
}
|
|
119
161
|
|
|
120
162
|
export { FireflyRuntime, FireflyRuntimeScope };
|