@squide/firefly 16.2.1 → 16.2.2
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 +13 -0
- package/dist/AppRouter.js +0 -9
- package/dist/AppRouter.js.map +1 -1
- package/dist/AppRouterContext.js +0 -3
- package/dist/AppRouterContext.js.map +1 -1
- package/dist/AppRouterReducer.js +0 -6
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/AppRouterStore.js +0 -2
- package/dist/AppRouterStore.js.map +1 -1
- package/dist/FireflyPlugin.js +0 -2
- package/dist/FireflyPlugin.js.map +1 -1
- package/dist/FireflyProvider.js +0 -3
- package/dist/FireflyProvider.js.map +1 -1
- package/dist/FireflyRuntime.js +0 -6
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/GlobalDataQueriesError.js +0 -2
- package/dist/GlobalDataQueriesError.js.map +1 -1
- package/dist/RootRoute.js +0 -6
- package/dist/RootRoute.js.map +1 -1
- package/dist/honeycomb/activeSpan.js +0 -4
- package/dist/honeycomb/activeSpan.js.map +1 -1
- package/dist/honeycomb/createTraceContextId.js +0 -2
- package/dist/honeycomb/createTraceContextId.js.map +1 -1
- package/dist/honeycomb/initializeHoneycomb.js +0 -2
- package/dist/honeycomb/initializeHoneycomb.js.map +1 -1
- package/dist/honeycomb/registerHoneycombInstrumentation.js +0 -10
- package/dist/honeycomb/registerHoneycombInstrumentation.js.map +1 -1
- package/dist/honeycomb/tracer.js +0 -2
- package/dist/honeycomb/tracer.js.map +1 -1
- package/dist/honeycomb/utils.js +0 -3
- package/dist/honeycomb/utils.js.map +1 -1
- package/dist/index.js +4 -11
- package/dist/index.js.map +1 -1
- package/dist/initializeFirefly.js +0 -8
- package/dist/initializeFirefly.js.map +1 -1
- package/dist/internal.js +5 -13
- package/dist/internal.js.map +1 -1
- package/dist/useAppRouterStore.js +0 -2
- package/dist/useAppRouterStore.js.map +1 -1
- package/dist/useCanFetchProtectedData.js +0 -2
- package/dist/useCanFetchProtectedData.js.map +1 -1
- package/dist/useCanFetchPublicData.js +0 -2
- package/dist/useCanFetchPublicData.js.map +1 -1
- package/dist/useCanRegisterDeferredRegistrations.js +0 -2
- package/dist/useCanRegisterDeferredRegistrations.js.map +1 -1
- package/dist/useCanUpdateDeferredRegistrations.js +0 -2
- package/dist/useCanUpdateDeferredRegistrations.js.map +1 -1
- package/dist/useDeferredRegistrations.js +0 -7
- package/dist/useDeferredRegistrations.js.map +1 -1
- package/dist/useExecuteOnce.js +0 -2
- package/dist/useExecuteOnce.js.map +1 -1
- package/dist/useIsActiveRouteProtected.js +0 -3
- package/dist/useIsActiveRouteProtected.js.map +1 -1
- package/dist/useIsBootstrapping.js +0 -2
- package/dist/useIsBootstrapping.js.map +1 -1
- package/dist/useNavigationItems.js +0 -3
- package/dist/useNavigationItems.js.map +1 -1
- package/dist/useProtectedDataHandler.js +0 -3
- package/dist/useProtectedDataHandler.js.map +1 -1
- package/dist/useProtectedDataQueries.js +0 -8
- package/dist/useProtectedDataQueries.js.map +1 -1
- package/dist/usePublicDataHandler.js +0 -3
- package/dist/usePublicDataHandler.js.map +1 -1
- package/dist/usePublicDataQueries.js +0 -8
- package/dist/usePublicDataQueries.js.map +1 -1
- package/dist/useRegisterDeferredRegistrations.js +0 -3
- package/dist/useRegisterDeferredRegistrations.js.map +1 -1
- package/dist/useStrictRegistrationMode.js +0 -3
- package/dist/useStrictRegistrationMode.js.map +1 -1
- package/dist/useUpdateDeferredRegistrations.js +0 -4
- package/dist/useUpdateDeferredRegistrations.js.map +1 -1
- package/package.json +24 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @squide/firefly
|
|
2
2
|
|
|
3
|
+
## 16.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#575](https://github.com/workleap/wl-squide/pull/575) [`9c91bd4`](https://github.com/workleap/wl-squide/commit/9c91bd47c5357a2b15b1fb0e984f81687a3b8b53) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Bump dependencies
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`9c91bd4`](https://github.com/workleap/wl-squide/commit/9c91bd47c5357a2b15b1fb0e984f81687a3b8b53)]:
|
|
10
|
+
- @squide/launch-darkly@1.0.11
|
|
11
|
+
- @squide/react-router@8.1.18
|
|
12
|
+
- @squide/env-vars@1.4.20
|
|
13
|
+
- @squide/core@6.1.15
|
|
14
|
+
- @squide/msw@4.0.18
|
|
15
|
+
|
|
3
16
|
## 16.2.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/AppRouter.js
CHANGED
|
@@ -7,23 +7,14 @@ import { useAppRouterReducer } from "./AppRouterReducer.js";
|
|
|
7
7
|
import { RootRoute } from "./RootRoute.js";
|
|
8
8
|
import { useStrictRegistrationMode } from "./useStrictRegistrationMode.js";
|
|
9
9
|
|
|
10
|
-
;// CONCATENATED MODULE: external "react/jsx-runtime"
|
|
11
10
|
|
|
12
|
-
;// CONCATENATED MODULE: external "@squide/core"
|
|
13
11
|
|
|
14
|
-
;// CONCATENATED MODULE: external "@squide/react-router"
|
|
15
12
|
|
|
16
|
-
;// CONCATENATED MODULE: external "react"
|
|
17
13
|
|
|
18
|
-
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
19
14
|
|
|
20
|
-
;// CONCATENATED MODULE: external "./AppRouterReducer.js"
|
|
21
15
|
|
|
22
|
-
;// CONCATENATED MODULE: external "./RootRoute.js"
|
|
23
16
|
|
|
24
|
-
;// CONCATENATED MODULE: external "./useStrictRegistrationMode.js"
|
|
25
17
|
|
|
26
|
-
;// CONCATENATED MODULE: ./src/AppRouter.tsx
|
|
27
18
|
|
|
28
19
|
|
|
29
20
|
|
package/dist/AppRouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRouter.js","sources":["../src/AppRouter.tsx"],"sourcesContent":["import { useLogger, useRuntime } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport { DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyResult, DOMRouterOpts } from \"react-router\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { FireflyRuntime } from \"./FireflyRuntime.tsx\";\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 routerProps: DOMRouterOpts;\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\n// This is a custom React Router data strategy (https://reactrouter.com/api/data-routers/createMemoryRouter#optsdatastrategy)\n// to delay the execution of React Router data browser loaders until MSW is ready.\n// The data strategy implemention is copied from React Router default data strategy: https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/router/router.ts#L5710.\nexport function createWaitForMswDataStrategy(runtime: FireflyRuntime) {\n const strategy: (args: DataStrategyFunctionArgs<unknown>) => ReturnType<DataStrategyFunction<unknown>> = async args => {\n await new Promise(resolve => {\n if (runtime.mswState.isReady) {\n resolve(null);\n } else {\n const handler = () => {\n runtime.mswState.removeMswReadyListener(handler);\n resolve(null);\n };\n\n runtime.mswState.addMswReadyListener(handler);\n }\n });\n\n const matchesToLoad = args.matches.filter(m => m.shouldCallHandler);\n const keyedResults: Record<string, DataStrategyResult> = {};\n const results = await Promise.all(matchesToLoad.map(m => m.resolve()));\n\n results.forEach((result, i) => {\n keyedResults[matchesToLoad[i].route.id] = result;\n });\n\n return keyedResults;\n };\n\n return strategy;\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction, strictMode: boolean) {\n const runtime = useRuntime() as FireflyRuntime;\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 routerProps: {\n dataStrategy: runtime.isMswEnabled ? createWaitForMswDataStrategy(runtime) : undefined\n },\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [runtime, 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","useRuntime","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","createWaitForMswDataStrategy","runtime","strategy","args","Promise","resolve","handler","matchesToLoad","m","keyedResults","results","result","i","useRenderRouterProvider","state","renderRouterProvider","strictMode","routes","canRenderRouter","undefined","AppRouter","props","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AppRouter.js","sources":["../src/AppRouter.tsx"],"sourcesContent":["import { useLogger, useRuntime } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport { DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyResult, DOMRouterOpts } from \"react-router\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { FireflyRuntime } from \"./FireflyRuntime.tsx\";\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 routerProps: DOMRouterOpts;\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\n// This is a custom React Router data strategy (https://reactrouter.com/api/data-routers/createMemoryRouter#optsdatastrategy)\n// to delay the execution of React Router data browser loaders until MSW is ready.\n// The data strategy implemention is copied from React Router default data strategy: https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/router/router.ts#L5710.\nexport function createWaitForMswDataStrategy(runtime: FireflyRuntime) {\n const strategy: (args: DataStrategyFunctionArgs<unknown>) => ReturnType<DataStrategyFunction<unknown>> = async args => {\n await new Promise(resolve => {\n if (runtime.mswState.isReady) {\n resolve(null);\n } else {\n const handler = () => {\n runtime.mswState.removeMswReadyListener(handler);\n resolve(null);\n };\n\n runtime.mswState.addMswReadyListener(handler);\n }\n });\n\n const matchesToLoad = args.matches.filter(m => m.shouldCallHandler);\n const keyedResults: Record<string, DataStrategyResult> = {};\n const results = await Promise.all(matchesToLoad.map(m => m.resolve()));\n\n results.forEach((result, i) => {\n keyedResults[matchesToLoad[i].route.id] = result;\n });\n\n return keyedResults;\n };\n\n return strategy;\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction, strictMode: boolean) {\n const runtime = useRuntime() as FireflyRuntime;\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 routerProps: {\n dataStrategy: runtime.isMswEnabled ? createWaitForMswDataStrategy(runtime) : undefined\n },\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [runtime, 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","useRuntime","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","createWaitForMswDataStrategy","runtime","strategy","args","Promise","resolve","handler","matchesToLoad","m","keyedResults","results","result","i","useRenderRouterProvider","state","renderRouterProvider","strictMode","routes","canRenderRouter","undefined","AppRouter","props","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;AAAqD;AACQ;AACC;AAG4B;AACT;AAErC;AAC+B;AAepE,SAASU,kBAAkBA,CAAC,EAAEC,oBAAoB,EAAE,iBAAiBC,oBAAoB,EAAkB;IAC9G,OACI,qIAAqI;IACrI,iCAAiC;IAChCD,wBAAwBC;AAEjC;AAEA,6HAA6H;AAC7H,kFAAkF;AAClF,0LAA0L;AACnL,SAASC,4BAA4BA,CAACC,OAAuB;IAChE,MAAMC,WAAmG,OAAMC;QAC3G,MAAM,IAAIC,QAAQC,CAAAA;YACd,IAAIJ,QAAQ,QAAQ,CAAC,OAAO,EAAE;gBAC1BI,QAAQ;YACZ,OAAO;gBACH,MAAMC,UAAU;oBACZL,QAAQ,QAAQ,CAAC,sBAAsB,CAACK;oBACxCD,QAAQ;gBACZ;gBAEAJ,QAAQ,QAAQ,CAAC,mBAAmB,CAACK;YACzC;QACJ;QAEA,MAAMC,gBAAgBJ,KAAK,OAAO,CAAC,MAAM,CAACK,CAAAA,IAAKA,EAAE,iBAAiB;QAClE,MAAMC,eAAmD,CAAC;QAC1D,MAAMC,UAAU,MAAMN,QAAQ,GAAG,CAACG,cAAc,GAAG,CAACC,CAAAA,I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
package/dist/AppRouterContext.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { isNil } from "@squide/core/internal";
|
|
2
2
|
import { createContext, useContext } from "react";
|
|
3
3
|
|
|
4
|
-
;// CONCATENATED MODULE: external "@squide/core/internal"
|
|
5
4
|
|
|
6
|
-
;// CONCATENATED MODULE: external "react"
|
|
7
5
|
|
|
8
|
-
;// CONCATENATED MODULE: ./src/AppRouterContext.ts
|
|
9
6
|
|
|
10
7
|
|
|
11
8
|
const AppRouterStateContext = createContext(undefined);
|
|
@@ -1 +1 @@
|
|
|
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":"
|
|
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,qBAAqBA,GAAGF,aAAaA,CAA6BG,WAAW;AAEnF,SAASC,iBAAiBA;IAC7B,MAAMC,QAAQJ,UAAUA,CAACC,qBAAqBA;IAE9C,IAAIH,KAAKA,CAACM,QAAQ;QACd,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX;AAEO,MAAME,0BAA0BA,GAAGP,aAAaA,CAAgCG,WAAW;AAE3F,SAASK,sBAAsBA;IAClC,MAAMC,WAAWR,UAAUA,CAACM,0BAA0BA;IAEtD,IAAIR,KAAKA,CAACU,WAAW;QACjB,MAAM,IAAIH,MAAM;IACpB;IAEA,OAAOG;AACX"}
|
package/dist/AppRouterReducer.js
CHANGED
|
@@ -4,17 +4,11 @@ import { useAppRouterStore } from "./useAppRouterStore.js";
|
|
|
4
4
|
import { useExecuteOnce } from "./useExecuteOnce.js";
|
|
5
5
|
import { isBootstrapping } from "./useIsBootstrapping.js";
|
|
6
6
|
|
|
7
|
-
;// CONCATENATED MODULE: external "@squide/core"
|
|
8
7
|
|
|
9
|
-
;// CONCATENATED MODULE: external "react"
|
|
10
8
|
|
|
11
|
-
;// CONCATENATED MODULE: external "./useAppRouterStore.js"
|
|
12
9
|
|
|
13
|
-
;// CONCATENATED MODULE: external "./useExecuteOnce.js"
|
|
14
10
|
|
|
15
|
-
;// CONCATENATED MODULE: external "./useIsBootstrapping.js"
|
|
16
11
|
|
|
17
|
-
;// CONCATENATED MODULE: ./src/AppRouterReducer.ts
|
|
18
12
|
|
|
19
13
|
|
|
20
14
|
|
|
@@ -1 +1 @@
|
|
|
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 areModulesRegistered: true,\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 }, [runtime, 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<FeatureFlagSetSnapshotChangedListener>(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 }, [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, dispatchFeatureFlagsUpdated]);\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":";;;;;;;;;;;;;;;;;AAAkE;AAEiB;AAExB;AACN;AACK;AAsC1D,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,SAASC,QAAQC,KAAqB,EAAEC,MAAuB;IAC3D,IAAIC,WAAWF;IAEf,OAAQC,OAAO,IAAI;QACf,KAAK;YAAsB;gBACvBC,WAAW;oBACP,GAAGA,QAAQ;oBAC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.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 areModulesRegistered: true,\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 }, [runtime, 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<FeatureFlagSetSnapshotChangedListener>(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 }, [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, dispatchFeatureFlagsUpdated]);\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":";;;;;;;;;;;AAAkE;AAEiB;AAExB;AACN;AACK;AAsC1D,wFAAwF;AACxF,8DAA8D;AACvD,MAAMU,sBAAsBA,GAAG,4BAA4B;AAC3D,MAAMC,iBAAiBA,GAAG,uBAAuB;AACjD,MAAMC,aAAaA,GAAG,mBAAmB;AACzC,MAAMC,wBAAwBA,GAAG,gCAAgC;AACjE,MAAMC,2BAA2BA,GAAG,mCAAmC;AACvE,MAAMC,oBAAoBA,GAAG,2BAA2B;AACxD,MAAMC,uBAAuBA,GAAG,8BAA8B;AAC9D,MAAMC,sBAAsBA,GAAG,6BAA6B;AAC5D,MAAMC,yBAAyBA,GAAG,gCAAgC;AAClE,MAAMC,iCAAiCA,GAAG,wCAAwC;AAClF,MAAMC,2BAA2BA,GAAG,yBAAyB;AASpE,SAASC,OAAOA,CAACC,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,GAAGA,QAAQ;oBACX,sBAAsB;oBACtB,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QAACA;QAAOS;KAAS;AAC5B"}
|
package/dist/AppRouterStore.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
;// CONCATENATED MODULE: ./src/AppRouterStore.ts
|
|
3
1
|
// 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
|
|
4
2
|
// access to the state and ease the integration with third-party libraries such as the Platform Widgets.
|
|
5
3
|
// Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.
|
|
@@ -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 \"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":"
|
|
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":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B;QACtB,uBAAuB;QACvB,gBAAgB;IACpB;IAEA,OAAO,IAAIZ,cAAcA,CAACY,cAAcT;AAC5C"}
|
package/dist/FireflyPlugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FireflyPlugin.js","sources":["../src/FireflyPlugin.ts"],"sourcesContent":["import { Plugin } from \"@squide/core\";\nimport { FireflyRuntime } from \"./FireflyRuntime.tsx\";\nimport { GetSpanFunction, HoneycombTrackingUnmanagedErrorHandler } from \"./honeycomb/registerHoneycombInstrumentation.ts\";\n\nexport interface FireflyPlugin extends Plugin<FireflyRuntime> {\n registerHoneycombTrackingListeners?: (\n getBootstrappingSpan: GetSpanFunction,\n getDeferredRegistrationsUpdateSpan: GetSpanFunction,\n onUnmanagedError: HoneycombTrackingUnmanagedErrorHandler\n ) => HoneycombTrackingUnmanagedErrorHandler;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FireflyPlugin.js","sources":["../src/FireflyPlugin.ts"],"sourcesContent":["import { Plugin } from \"@squide/core\";\nimport { FireflyRuntime } from \"./FireflyRuntime.tsx\";\nimport { GetSpanFunction, HoneycombTrackingUnmanagedErrorHandler } from \"./honeycomb/registerHoneycombInstrumentation.ts\";\n\nexport interface FireflyPlugin extends Plugin<FireflyRuntime> {\n registerHoneycombTrackingListeners?: (\n getBootstrappingSpan: GetSpanFunction,\n getDeferredRegistrationsUpdateSpan: GetSpanFunction,\n onUnmanagedError: HoneycombTrackingUnmanagedErrorHandler\n ) => HoneycombTrackingUnmanagedErrorHandler;\n}\n"],"names":[],"mappings":"AAUC"}
|
package/dist/FireflyProvider.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { RuntimeContext } from "@squide/core";
|
|
3
3
|
|
|
4
|
-
;// CONCATENATED MODULE: external "react/jsx-runtime"
|
|
5
4
|
|
|
6
|
-
;// CONCATENATED MODULE: external "@squide/core"
|
|
7
5
|
|
|
8
|
-
;// CONCATENATED MODULE: ./src/FireflyProvider.tsx
|
|
9
6
|
|
|
10
7
|
|
|
11
8
|
function FireflyProvider(props) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FireflyProvider.js","sources":["../src/FireflyProvider.tsx"],"sourcesContent":["import { RuntimeContext } from \"@squide/core\";\nimport type { PropsWithChildren } from \"react\";\nimport { FireflyRuntime } from \"./FireflyRuntime.tsx\";\n\nexport interface FireflyProviderProps extends PropsWithChildren {\n runtime: FireflyRuntime;\n}\n\nexport function FireflyProvider(props: FireflyProviderProps) {\n const {\n runtime,\n children\n } = props;\n\n return (\n <RuntimeContext.Provider value={runtime}>\n {children}\n </RuntimeContext.Provider>\n );\n}\n"],"names":["RuntimeContext","FireflyProvider","props","runtime","children"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FireflyProvider.js","sources":["../src/FireflyProvider.tsx"],"sourcesContent":["import { RuntimeContext } from \"@squide/core\";\nimport type { PropsWithChildren } from \"react\";\nimport { FireflyRuntime } from \"./FireflyRuntime.tsx\";\n\nexport interface FireflyProviderProps extends PropsWithChildren {\n runtime: FireflyRuntime;\n}\n\nexport function FireflyProvider(props: FireflyProviderProps) {\n const {\n runtime,\n children\n } = props;\n\n return (\n <RuntimeContext.Provider value={runtime}>\n {children}\n </RuntimeContext.Provider>\n );\n}\n"],"names":["RuntimeContext","FireflyProvider","props","runtime","children"],"mappings":";;;;;;AAA8C;AAQvC,SAASC,eAAeA,CAACC,KAA2B;IACvD,MAAM,EACFC,OAAO,EACPC,QAAQ,EACX,GAAGF;IAEJ,qBACI,IAACF,uBAAuB;QAAC,OAAOG;kBAC3BC;;AAGb"}
|
package/dist/FireflyRuntime.js
CHANGED
|
@@ -4,17 +4,11 @@ import { MswPluginName, getMswPlugin } from "@squide/msw";
|
|
|
4
4
|
import { ReactRouterRuntime, ReactRouterRuntimeScope } from "@squide/react-router";
|
|
5
5
|
import { createAppRouterStore } from "./AppRouterStore.js";
|
|
6
6
|
|
|
7
|
-
;// CONCATENATED MODULE: external "@squide/env-vars"
|
|
8
7
|
|
|
9
|
-
;// CONCATENATED MODULE: external "@squide/launch-darkly"
|
|
10
8
|
|
|
11
|
-
;// CONCATENATED MODULE: external "@squide/msw"
|
|
12
9
|
|
|
13
|
-
;// CONCATENATED MODULE: external "@squide/react-router"
|
|
14
10
|
|
|
15
|
-
;// CONCATENATED MODULE: external "./AppRouterStore.js"
|
|
16
11
|
|
|
17
|
-
;// CONCATENATED MODULE: ./src/FireflyRuntime.tsx
|
|
18
12
|
|
|
19
13
|
|
|
20
14
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FireflyRuntime.js","sources":["../src/FireflyRuntime.tsx"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from \"@squide/core\";\nimport { EnvironmentVariableKey, EnvironmentVariables, getEnvironmentVariablesPlugin } from \"@squide/env-vars\";\nimport { FeatureFlagKey, FeatureFlags, FeatureFlagSetSnapshot, getLaunchDarklyPlugin, LaunchDarklyPluginName } from \"@squide/launch-darkly\";\nimport { getMswPlugin, MswPluginName, MswState } from \"@squide/msw\";\nimport { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from \"@squide/react-router\";\nimport type { HoneycombInstrumentationPartialClient } from \"@workleap-telemetry/core\";\nimport type { Logger } from \"@workleap/logging\";\nimport { LDClient } from \"launchdarkly-js-client-sdk\";\nimport type { RequestHandler } from \"msw\";\nimport { type AppRouterStore, createAppRouterStore } from \"./AppRouterStore.ts\";\n\nexport interface FireflyRuntimeOptions<TRuntime extends FireflyRuntime = FireflyRuntime> extends RuntimeOptions<TRuntime> {\n honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;\n}\n\nexport interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}\n\nexport interface IFireflyRuntime extends IReactRouterRuntime {\n get isMswEnabled(): boolean;\n get mswState(): MswState;\n registerRequestHandlers: (handlers: RequestHandler[]) => void;\n get requestHandlers(): RequestHandler[];\n registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]): void;\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;\n getEnvironmentVariable<T extends EnvironmentVariableKey>(key: T): EnvironmentVariables[T];\n get environmentVariables(): EnvironmentVariables;\n get appRouterStore(): AppRouterStore;\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;\n get isLaunchDarklyEnabled(): boolean;\n get launchDarklyClient(): LDClient;\n get featureFlags(): FeatureFlags;\n getFeatureFlag(key: string, defaultValue?: unknown): unknown;\n get featureFlagSetSnapshot(): FeatureFlagSetSnapshot;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends ReactRouterRuntime<TRuntime> implements IFireflyRuntime {\n readonly #appRouterStore: AppRouterStore;\n readonly #honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;\n readonly #isMswEnabled: boolean;\n readonly #isLaunchDarklyEnabled: boolean;\n\n constructor(options: FireflyRuntimeOptions = {}) {\n const {\n honeycombInstrumentationClient\n } = options;\n\n super(options);\n\n this.#appRouterStore = createAppRouterStore(this._logger);\n this.#honeycombInstrumentationClient = honeycombInstrumentationClient;\n this.#isMswEnabled = this._plugins.some(x => x.name === MswPluginName);\n this.#isLaunchDarklyEnabled = this._plugins.some(x => x.name === LaunchDarklyPluginName);\n }\n\n registerRoute(route: Route, options: RegisterRouteOptions = {}) {\n if (this.moduleManager.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 isMswEnabled() {\n return this.#isMswEnabled;\n }\n\n get mswState() {\n return getMswPlugin(this).mswState;\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n const logger = this._getLogger(options);\n const plugin = getMswPlugin(this);\n\n if (this.moduleManager.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 plugin.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 return getMswPlugin(this).requestHandlers;\n }\n\n getEnvironmentVariable(key: EnvironmentVariableKey) {\n return getEnvironmentVariablesPlugin(this).getVariable(key);\n }\n\n get environmentVariables() {\n return getEnvironmentVariablesPlugin(this).getVariables();\n }\n\n registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {\n return getEnvironmentVariablesPlugin(this).registerVariable(key, value);\n }\n\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {\n return getEnvironmentVariablesPlugin(this).registerVariables(variables);\n }\n\n get appRouterStore() {\n return this.#appRouterStore;\n }\n\n get honeycombInstrumentationClient() {\n return this.#honeycombInstrumentationClient;\n }\n\n get isLaunchDarklyEnabled() {\n return this.#isLaunchDarklyEnabled;\n }\n\n get launchDarklyClient() {\n return getLaunchDarklyPlugin(this).client;\n }\n\n get featureFlags() {\n return this.featureFlagSetSnapshot.value;\n }\n\n getFeatureFlag<T extends FeatureFlagKey>(key: T, defaultValue?: FeatureFlags[T]) {\n return getLaunchDarklyPlugin(this).getFeatureFlag(key, defaultValue);\n }\n\n get featureFlagSetSnapshot() {\n return getLaunchDarklyPlugin(this).featureFlagSetSnapshot;\n }\n\n startScope(logger: Logger): TRuntime {\n return (new FireflyRuntimeScope(this, logger) as unknown) as TRuntime;\n }\n}\n\nexport class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {\n get isMswEnabled() {\n return this._runtime.isMswEnabled;\n }\n\n get mswState() {\n return this._runtime.mswState;\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n this._runtime.registerRequestHandlers(handlers, {\n ...options,\n logger: this._getLogger(options)\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 return this._runtime.requestHandlers;\n }\n\n getEnvironmentVariable(key: EnvironmentVariableKey) {\n return this._runtime.getEnvironmentVariable(key);\n }\n\n get environmentVariables() {\n return this._runtime.environmentVariables;\n }\n\n registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {\n this._runtime.registerEnvironmentVariable(key, value);\n }\n\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {\n this._runtime.registerEnvironmentVariables(variables);\n }\n\n get appRouterStore(): AppRouterStore {\n throw new Error(\"[squide] Cannot retrieve the app router store from a runtime scope instance.\");\n }\n\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient {\n throw new Error(\"[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.\");\n }\n\n get isLaunchDarklyEnabled() {\n return this._runtime.isLaunchDarklyEnabled;\n }\n\n get launchDarklyClient() {\n return this._runtime.launchDarklyClient;\n }\n\n get featureFlags() {\n return this._runtime.featureFlags;\n }\n\n getFeatureFlag<T extends FeatureFlagKey>(key: T, defaultValue?: FeatureFlags[T]) {\n // The error is because the FeatureFlags interface is empty as it is expected to be augmented by the\n // consumer application.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return this._runtime.getFeatureFlag(key, defaultValue);\n }\n\n get featureFlagSetSnapshot() {\n return this._runtime.featureFlagSetSnapshot;\n }\n}\n"],"names":["getEnvironmentVariablesPlugin","getLaunchDarklyPlugin","LaunchDarklyPluginName","getMswPlugin","MswPluginName","ReactRouterRuntime","ReactRouterRuntimeScope","createAppRouterStore","FireflyRuntime","options","honeycombInstrumentationClient","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"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from \"@squide/core\";\nimport { EnvironmentVariableKey, EnvironmentVariables, getEnvironmentVariablesPlugin } from \"@squide/env-vars\";\nimport { FeatureFlagKey, FeatureFlags, FeatureFlagSetSnapshot, getLaunchDarklyPlugin, LaunchDarklyPluginName } from \"@squide/launch-darkly\";\nimport { getMswPlugin, MswPluginName, MswState } from \"@squide/msw\";\nimport { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from \"@squide/react-router\";\nimport type { HoneycombInstrumentationPartialClient } from \"@workleap-telemetry/core\";\nimport type { Logger } from \"@workleap/logging\";\nimport { LDClient } from \"launchdarkly-js-client-sdk\";\nimport type { RequestHandler } from \"msw\";\nimport { type AppRouterStore, createAppRouterStore } from \"./AppRouterStore.ts\";\n\nexport interface FireflyRuntimeOptions<TRuntime extends FireflyRuntime = FireflyRuntime> extends RuntimeOptions<TRuntime> {\n honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;\n}\n\nexport interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}\n\nexport interface IFireflyRuntime extends IReactRouterRuntime {\n get isMswEnabled(): boolean;\n get mswState(): MswState;\n registerRequestHandlers: (handlers: RequestHandler[]) => void;\n get requestHandlers(): RequestHandler[];\n registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]): void;\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;\n getEnvironmentVariable<T extends EnvironmentVariableKey>(key: T): EnvironmentVariables[T];\n get environmentVariables(): EnvironmentVariables;\n get appRouterStore(): AppRouterStore;\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;\n get isLaunchDarklyEnabled(): boolean;\n get launchDarklyClient(): LDClient;\n get featureFlags(): FeatureFlags;\n getFeatureFlag(key: string, defaultValue?: unknown): unknown;\n get featureFlagSetSnapshot(): FeatureFlagSetSnapshot;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends ReactRouterRuntime<TRuntime> implements IFireflyRuntime {\n readonly #appRouterStore: AppRouterStore;\n readonly #honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;\n readonly #isMswEnabled: boolean;\n readonly #isLaunchDarklyEnabled: boolean;\n\n constructor(options: FireflyRuntimeOptions = {}) {\n const {\n honeycombInstrumentationClient\n } = options;\n\n super(options);\n\n this.#appRouterStore = createAppRouterStore(this._logger);\n this.#honeycombInstrumentationClient = honeycombInstrumentationClient;\n this.#isMswEnabled = this._plugins.some(x => x.name === MswPluginName);\n this.#isLaunchDarklyEnabled = this._plugins.some(x => x.name === LaunchDarklyPluginName);\n }\n\n registerRoute(route: Route, options: RegisterRouteOptions = {}) {\n if (this.moduleManager.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 isMswEnabled() {\n return this.#isMswEnabled;\n }\n\n get mswState() {\n return getMswPlugin(this).mswState;\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n const logger = this._getLogger(options);\n const plugin = getMswPlugin(this);\n\n if (this.moduleManager.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 plugin.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 return getMswPlugin(this).requestHandlers;\n }\n\n getEnvironmentVariable(key: EnvironmentVariableKey) {\n return getEnvironmentVariablesPlugin(this).getVariable(key);\n }\n\n get environmentVariables() {\n return getEnvironmentVariablesPlugin(this).getVariables();\n }\n\n registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {\n return getEnvironmentVariablesPlugin(this).registerVariable(key, value);\n }\n\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {\n return getEnvironmentVariablesPlugin(this).registerVariables(variables);\n }\n\n get appRouterStore() {\n return this.#appRouterStore;\n }\n\n get honeycombInstrumentationClient() {\n return this.#honeycombInstrumentationClient;\n }\n\n get isLaunchDarklyEnabled() {\n return this.#isLaunchDarklyEnabled;\n }\n\n get launchDarklyClient() {\n return getLaunchDarklyPlugin(this).client;\n }\n\n get featureFlags() {\n return this.featureFlagSetSnapshot.value;\n }\n\n getFeatureFlag<T extends FeatureFlagKey>(key: T, defaultValue?: FeatureFlags[T]) {\n return getLaunchDarklyPlugin(this).getFeatureFlag(key, defaultValue);\n }\n\n get featureFlagSetSnapshot() {\n return getLaunchDarklyPlugin(this).featureFlagSetSnapshot;\n }\n\n startScope(logger: Logger): TRuntime {\n return (new FireflyRuntimeScope(this, logger) as unknown) as TRuntime;\n }\n}\n\nexport class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {\n get isMswEnabled() {\n return this._runtime.isMswEnabled;\n }\n\n get mswState() {\n return this._runtime.mswState;\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n this._runtime.registerRequestHandlers(handlers, {\n ...options,\n logger: this._getLogger(options)\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 return this._runtime.requestHandlers;\n }\n\n getEnvironmentVariable(key: EnvironmentVariableKey) {\n return this._runtime.getEnvironmentVariable(key);\n }\n\n get environmentVariables() {\n return this._runtime.environmentVariables;\n }\n\n registerEnvironmentVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {\n this._runtime.registerEnvironmentVariable(key, value);\n }\n\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {\n this._runtime.registerEnvironmentVariables(variables);\n }\n\n get appRouterStore(): AppRouterStore {\n throw new Error(\"[squide] Cannot retrieve the app router store from a runtime scope instance.\");\n }\n\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient {\n throw new Error(\"[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.\");\n }\n\n get isLaunchDarklyEnabled() {\n return this._runtime.isLaunchDarklyEnabled;\n }\n\n get launchDarklyClient() {\n return this._runtime.launchDarklyClient;\n }\n\n get featureFlags() {\n return this._runtime.featureFlags;\n }\n\n getFeatureFlag<T extends FeatureFlagKey>(key: T, defaultValue?: FeatureFlags[T]) {\n // The error is because the FeatureFlags interface is empty as it is expected to be augmented by the\n // consumer application.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return this._runtime.getFeatureFlag(key, defaultValue);\n }\n\n get featureFlagSetSnapshot() {\n return this._runtime.featureFlagSetSnapshot;\n }\n}\n"],"names":["getEnvironmentVariablesPlugin","getLaunchDarklyPlugin","LaunchDarklyPluginName","getMswPlugin","MswPluginName","ReactRouterRuntime","ReactRouterRuntimeScope","createAppRouterStore","FireflyRuntime","options","honeycombInstrumentationClient","x","route","Error","handlers","logger","plugin","key","value","variables","defaultValue","FireflyRuntimeScope"],"mappings":";;;;;;;;;;;AAC+G;AAC6B;AACxE;AACqD;AAKzC;AA0BhF,8DAA8D;AACvD,MAAMQ,cAAcA,SAAgDH,kBAAkBA;IAChF,eAAe,CAAiB;IAChC,+BAA+B,CAAoD;IACnF,aAAa,CAAU;IACvB,sBAAsB,CAAU;IAEzC,YAAYI,UAAiC,CAAC,CAAC,CAAE;QAC7C,MAAM,EACFC,8BAA8B,EACjC,GAAGD;QAEJ,KAAK,CAACA;QAEN,IAAI,CAAC,eAAe,GAAGF,oBAAoBA,CAAC,IAAI,CAAC,OAAO;QACxD,IAAI,CAAC,+BAA+B,GAAGG;QACvC,IAAI,CAAC,a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AAM,EAAEC,KAA8B,EAAE;QAClG,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAACD,KAAKC;IACnD;IAEA,6BAA6BC,SAAwC,EAAE;QACnE,IAAI,CAAC,QAAQ,CAAC,4BAA4B,CAACA;IAC/C;IAEA,IAAI,iBAAiC;QACjC,MAAM,IAAIN,MAAM;IACpB;IAEA,IAAI,iCAAwE;QACxE,MAAM,IAAIA,MAAM;IACpB;IAEA,IAAI,wBAAwB;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,qBAAqB;IAC9C;IAEA,IAAI,qBAAqB;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,kBAAkB;IAC3C;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY;IACrC;IAEA,eAAyCI,GAAM,EAAEG,YAA8B,EAAE;QAC7E,oGAAoG;QACpG,wBAAwB;QACxB,6DAA6D;QAC7D,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAACH,KAAKG;IAC7C;IAEA,IAAI,yBAAyB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB;IAC/C;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalDataQueriesError.js","sources":["../src/GlobalDataQueriesError.ts"],"sourcesContent":["export class GlobalDataQueriesError extends Error {\n readonly #errors: Error[];\n\n constructor(message: string, errors: Error[]) {\n super(message);\n\n this.#errors = errors;\n }\n\n get errors() {\n return this.#errors;\n }\n}\n\nexport function isGlobalDataQueriesError(error?: unknown): error is GlobalDataQueriesError {\n return error !== undefined && error !== null && error instanceof GlobalDataQueriesError;\n}\n"],"names":["GlobalDataQueriesError","Error","message","errors","isGlobalDataQueriesError","error","undefined"],"mappings":"
|
|
1
|
+
{"version":3,"file":"GlobalDataQueriesError.js","sources":["../src/GlobalDataQueriesError.ts"],"sourcesContent":["export class GlobalDataQueriesError extends Error {\n readonly #errors: Error[];\n\n constructor(message: string, errors: Error[]) {\n super(message);\n\n this.#errors = errors;\n }\n\n get errors() {\n return this.#errors;\n }\n}\n\nexport function isGlobalDataQueriesError(error?: unknown): error is GlobalDataQueriesError {\n return error !== undefined && error !== null && error instanceof GlobalDataQueriesError;\n}\n"],"names":["GlobalDataQueriesError","Error","message","errors","isGlobalDataQueriesError","error","undefined"],"mappings":"AAAO,MAAMA,sBAAsBA,SAASC;IAC/B,OAAO,CAAU;IAE1B,YAAYC,OAAe,EAAEC,MAAe,CAAE;QAC1C,KAAK,CAACD;QAEN,IAAI,CAAC,OAAO,GAAGC;IACnB;IAEA,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,OAAO;IACvB;AACJ;AAEO,SAASC,wBAAwBA,CAACC,KAAe;IACpD,OAAOA,UAAUC,aAAaD,UAAU,QAAQA,iBAAiBL,sBAAsBA;AAC3F"}
|
package/dist/RootRoute.js
CHANGED
|
@@ -4,17 +4,11 @@ import { Outlet } from "react-router";
|
|
|
4
4
|
import { useAppRouterDispatcher, useAppRouterState } from "./AppRouterContext.js";
|
|
5
5
|
import { useIsActiveRouteProtected } from "./useIsActiveRouteProtected.js";
|
|
6
6
|
|
|
7
|
-
;// CONCATENATED MODULE: external "react/jsx-runtime"
|
|
8
7
|
|
|
9
|
-
;// CONCATENATED MODULE: external "react"
|
|
10
8
|
|
|
11
|
-
;// CONCATENATED MODULE: external "react-router"
|
|
12
9
|
|
|
13
|
-
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
14
10
|
|
|
15
|
-
;// CONCATENATED MODULE: external "./useIsActiveRouteProtected.js"
|
|
16
11
|
|
|
17
|
-
;// CONCATENATED MODULE: ./src/RootRoute.tsx
|
|
18
12
|
|
|
19
13
|
|
|
20
14
|
|
package/dist/RootRoute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RootRoute.js","sources":["../src/RootRoute.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { Outlet } from \"react-router\";\nimport { useAppRouterDispatcher, useAppRouterState } from \"./AppRouterContext.ts\";\nimport { useIsActiveRouteProtected } from \"./useIsActiveRouteProtected.ts\";\n\nexport interface RootRouteProps {\n strictMode?: boolean;\n}\n\nexport function RootRoute(props: RootRouteProps) {\n const {\n strictMode = true\n } = props;\n\n const state = useAppRouterState();\n\n const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady, {\n throwWhenThereIsNoMatch: strictMode\n });\n\n const dispatch = useAppRouterDispatcher();\n\n useEffect(() => {\n // Dispatching the active route visibility must be done in a route because React Router's useLocation\n // hook throws if it's not called from a child of the router component.\n if (isActiveRouteProtected) {\n dispatch({ type: \"active-route-is-protected\" });\n } else {\n dispatch({ type: \"active-route-is-public\" });\n }\n }, [isActiveRouteProtected, dispatch]);\n\n return (\n <Outlet />\n );\n}\n"],"names":["useEffect","Outlet","useAppRouterDispatcher","useAppRouterState","useIsActiveRouteProtected","RootRoute","props","strictMode","state","isActiveRouteProtected","dispatch"],"mappings":"
|
|
1
|
+
{"version":3,"file":"RootRoute.js","sources":["../src/RootRoute.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { Outlet } from \"react-router\";\nimport { useAppRouterDispatcher, useAppRouterState } from \"./AppRouterContext.ts\";\nimport { useIsActiveRouteProtected } from \"./useIsActiveRouteProtected.ts\";\n\nexport interface RootRouteProps {\n strictMode?: boolean;\n}\n\nexport function RootRoute(props: RootRouteProps) {\n const {\n strictMode = true\n } = props;\n\n const state = useAppRouterState();\n\n const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady, {\n throwWhenThereIsNoMatch: strictMode\n });\n\n const dispatch = useAppRouterDispatcher();\n\n useEffect(() => {\n // Dispatching the active route visibility must be done in a route because React Router's useLocation\n // hook throws if it's not called from a child of the router component.\n if (isActiveRouteProtected) {\n dispatch({ type: \"active-route-is-protected\" });\n } else {\n dispatch({ type: \"active-route-is-public\" });\n }\n }, [isActiveRouteProtected, dispatch]);\n\n return (\n <Outlet />\n );\n}\n"],"names":["useEffect","Outlet","useAppRouterDispatcher","useAppRouterState","useIsActiveRouteProtected","RootRoute","props","strictMode","state","isActiveRouteProtected","dispatch"],"mappings":";;;;;;;;;;;;AAAkC;AACI;AAC4C;AACP;AAMpE,SAASK,SAASA,CAACC,KAAqB;IAC3C,MAAM,EACFC,aAAa,IAAI,EACpB,GAAGD;IAEJ,MAAME,QAAQL,iBAAiBA;IAE/B,MAAMM,yBAAyBL,yBAAyBA,CAACI,MAAM,eAAe,EAAE;QAC5E,yBAAyBD;IAC7B;IAEA,MAAMG,WAAWR,sBAAsBA;IAEvCF,SAASA,CAAC;QACN,qGAAqG;QACrG,uEAAuE;QACvE,IAAIS,wBAAwB;YACxBC,SAAS;gBAAE,MAAM;YAA4B;QACjD,OAAO;YACHA,SAAS;gBAAE,MAAM;YAAyB;QAC9C;IACJ,GAAG;QAACD;QAAwBC;KAAS;IAErC,qBACI,IAACT,MAAMA;AAEf"}
|
|
@@ -2,13 +2,9 @@ import { isPlainObject } from "@squide/core/internal";
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { createTraceContextId } from "./createTraceContextId.js";
|
|
4
4
|
|
|
5
|
-
;// CONCATENATED MODULE: external "@squide/core/internal"
|
|
6
5
|
|
|
7
|
-
;// CONCATENATED MODULE: external "uuid"
|
|
8
6
|
|
|
9
|
-
;// CONCATENATED MODULE: external "./createTraceContextId.js"
|
|
10
7
|
|
|
11
|
-
;// CONCATENATED MODULE: ./src/honeycomb/activeSpan.ts
|
|
12
8
|
|
|
13
9
|
|
|
14
10
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"honeycomb/activeSpan.js","sources":["../../src/honeycomb/activeSpan.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport { isPlainObject } from \"@squide/core/internal\";\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":"
|
|
1
|
+
{"version":3,"file":"honeycomb/activeSpan.js","sources":["../../src/honeycomb/activeSpan.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport { isPlainObject } from \"@squide/core/internal\";\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":";;;;;;;AACsD;AAElB;AAC6B;AAUjE,6EAA6E;AAC7E,iEAAiE;AACjE,yFAAyF;AACzF,MAAMI,eAAeA;IACR,MAAM,GAAiB,EAAE,CAAC;IAEnC,KAAKC,IAAgB,EAAE;QACnB,IAAI,CAAC,MA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,IAAIE,OAAO;QACPA,MAAM,IAAI,CAACG;IACf;IAEA,OAAOA;AACX;AAEO,SAASC,aAAaA,CAACb,IAAgB;IAC1C,MAAMS,QAAQF,kBAAkBA;IAEhC,IAAIE,OAAO;QACPA,MAAM,GAAG,CAACT;IACd;AACJ;AAEO,SAASc,mDAAmDA,CAACC,MAAc;IAC9E,OAAO,CAACf,MAAYgB;QAChB,MAAMJ,aAAaJ,aAAaA;QAEhC,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"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
;// CONCATENATED MODULE: ./src/honeycomb/createTraceContextId.ts
|
|
3
1
|
// Creates the trace context id based on the following opentelemetry-js implementation: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-core/src/trace/W3CTraceContextPropagator.ts
|
|
4
2
|
const VERSION = "00";
|
|
5
3
|
var createTraceContextId_TraceFlags = /*#__PURE__*/ (/* unused pure expression or super */ null && (function(TraceFlags) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"honeycomb/createTraceContextId.js","sources":["../../src/honeycomb/createTraceContextId.ts"],"sourcesContent":["// Creates the trace context id based on the following opentelemetry-js implementation: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-core/src/trace/W3CTraceContextPropagator.ts\n\nconst VERSION = \"00\";\n\nenum TraceFlags {\n NONE = 0x0,\n SAMPLED = 0x1 << 0\n}\n\nexport function createTraceContextId(traceId: string, spanId: string, traceFlags: number) {\n return `${VERSION}-${traceId}-${spanId}-0${Number(traceFlags || TraceFlags.NONE).toString(16)}`;\n}\n"],"names":["VERSION","TraceFlags","createTraceContextId","traceId","spanId","traceFlags","Number"],"mappings":"
|
|
1
|
+
{"version":3,"file":"honeycomb/createTraceContextId.js","sources":["../../src/honeycomb/createTraceContextId.ts"],"sourcesContent":["// Creates the trace context id based on the following opentelemetry-js implementation: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-core/src/trace/W3CTraceContextPropagator.ts\n\nconst VERSION = \"00\";\n\nenum TraceFlags {\n NONE = 0x0,\n SAMPLED = 0x1 << 0\n}\n\nexport function createTraceContextId(traceId: string, spanId: string, traceFlags: number) {\n return `${VERSION}-${traceId}-${spanId}-0${Number(traceFlags || TraceFlags.NONE).toString(16)}`;\n}\n"],"names":["VERSION","TraceFlags","createTraceContextId","traceId","spanId","traceFlags","Number"],"mappings":"AAAA,uNAAuN;AAEvN,MAAMA,OAAOA,GAAG;AAEhB,IAAKC,+BAAUA,iBAAVA,gDAAAA,SAAAA;;;WAAAA;EAAAA,+BAAUA,OAAVA,EAAAA;AAKE,SAASC,oBAAoBA,CAACC,OAAe,EAAEC,MAAc,EAAEC,UAAkB;IACpF,OAAO,GAAGL,OAAOA,CAAC,CAAC,EAAEG,QAAQ,CAAC,EAAEC,OAAO,EAAE,EAAEE,OAAOD,iBAA+B,QAAQ,CAAC,KAAK;AACnG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"honeycomb/initializeHoneycomb.js","sources":["../../src/honeycomb/initializeHoneycomb.ts"],"sourcesContent":["import type { FireflyRuntime } from \"../FireflyRuntime.tsx\";\n\nexport async function initializeHoneycomb(runtime: FireflyRuntime) {\n if (runtime.honeycombInstrumentationClient) {\n try {\n // Dynamically import the Honeycomb instrumentation to prevent loading all the Honeycomb libraries\n // if Honeycomb instrumentation is not registered by the hosting application.\n const mod = await import(\"./registerHoneycombInstrumentation.ts\");\n\n mod.registerHoneycombInstrumentation(runtime);\n } catch (error: unknown) {\n runtime.logger.error(\"[squide] Failed to register Honeycomb instrumentation. The \\\"./registerHoneycombInstrumentation.ts\\\" file cannot be imported.\");\n\n throw error;\n }\n } else {\n runtime.logger.information(\"[squide] Cannot register Honeycomb instrumentation because the host application hasn't provided a client.\");\n }\n}\n"],"names":["initializeHoneycomb","runtime","mod","error"],"mappings":"
|
|
1
|
+
{"version":3,"file":"honeycomb/initializeHoneycomb.js","sources":["../../src/honeycomb/initializeHoneycomb.ts"],"sourcesContent":["import type { FireflyRuntime } from \"../FireflyRuntime.tsx\";\n\nexport async function initializeHoneycomb(runtime: FireflyRuntime) {\n if (runtime.honeycombInstrumentationClient) {\n try {\n // Dynamically import the Honeycomb instrumentation to prevent loading all the Honeycomb libraries\n // if Honeycomb instrumentation is not registered by the hosting application.\n const mod = await import(\"./registerHoneycombInstrumentation.ts\");\n\n mod.registerHoneycombInstrumentation(runtime);\n } catch (error: unknown) {\n runtime.logger.error(\"[squide] Failed to register Honeycomb instrumentation. The \\\"./registerHoneycombInstrumentation.ts\\\" file cannot be imported.\");\n\n throw error;\n }\n } else {\n runtime.logger.information(\"[squide] Cannot register Honeycomb instrumentation because the host application hasn't provided a client.\");\n }\n}\n"],"names":["initializeHoneycomb","runtime","mod","error"],"mappings":"AAEO,eAAeA,mBAAmBA,CAACC,OAAuB;IAC7D,IAAIA,QAAQ,8BAA8B,EAAE;QACxC,IAAI;YACA,kGAAkG;YAClG,6EAA6E;YAC7E,MAAMC,MAAM,MAAM,+CAA+C;YAEjEA,IAAI,gCAAgC,CAACD;QACzC,EAAE,OAAOE,OAAgB;YACrBF,QAAQ,MAAM,CAAC,KAAK,CAAC;YAErB,MAAME;QACV;IACJ,OAAO;QACHF,QAAQ,MAAM,CAAC,WAAW,CAAC;IAC/B;AACJ"}
|
|
@@ -8,25 +8,15 @@ import { createOverrideFetchRequestSpanWithActiveSpanContext, registerActiveSpan
|
|
|
8
8
|
import { getTracer } from "./tracer.js";
|
|
9
9
|
import { endActiveSpan, startActiveChildSpan, startChildSpan, startSpan, traceError } from "./utils.js";
|
|
10
10
|
|
|
11
|
-
;// CONCATENATED MODULE: external "@squide/core"
|
|
12
11
|
|
|
13
|
-
;// CONCATENATED MODULE: external "../AppRouterReducer.js"
|
|
14
12
|
|
|
15
|
-
;// CONCATENATED MODULE: external "../initializeFirefly.js"
|
|
16
13
|
|
|
17
|
-
;// CONCATENATED MODULE: external "../useProtectedDataQueries.js"
|
|
18
14
|
|
|
19
|
-
;// CONCATENATED MODULE: external "../usePublicDataQueries.js"
|
|
20
15
|
|
|
21
|
-
;// CONCATENATED MODULE: external "../useUpdateDeferredRegistrations.js"
|
|
22
16
|
|
|
23
|
-
;// CONCATENATED MODULE: external "./activeSpan.js"
|
|
24
17
|
|
|
25
|
-
;// CONCATENATED MODULE: external "./tracer.js"
|
|
26
18
|
|
|
27
|
-
;// CONCATENATED MODULE: external "./utils.js"
|
|
28
19
|
|
|
29
|
-
;// CONCATENATED MODULE: ./src/honeycomb/registerHoneycombInstrumentation.ts
|
|
30
20
|
|
|
31
21
|
|
|
32
22
|
|