@squide/firefly 15.0.5 → 16.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/AppRouter.js.map +1 -1
- package/dist/AppRouterContext.js.map +1 -1
- package/dist/AppRouterReducer.d.ts +3 -4
- package/dist/AppRouterReducer.js +51 -82
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/AppRouterStore.js.map +1 -1
- package/dist/FireflyPlugin.d.ts +6 -0
- package/dist/FireflyPlugin.js +6 -0
- package/dist/FireflyPlugin.js.map +1 -0
- package/dist/FireflyProvider.js.map +1 -1
- package/dist/FireflyRuntime.d.ts +26 -11
- package/dist/FireflyRuntime.js +61 -45
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/GlobalDataQueriesError.js.map +1 -1
- package/dist/RootRoute.js.map +1 -1
- package/dist/honeycomb/activeSpan.js.map +1 -1
- package/dist/honeycomb/createTraceContextId.js.map +1 -1
- package/dist/honeycomb/initializeHoneycomb.js.map +1 -1
- package/dist/honeycomb/registerHoneycombInstrumentation.d.ts +8 -0
- package/dist/honeycomb/registerHoneycombInstrumentation.js +19 -136
- package/dist/honeycomb/registerHoneycombInstrumentation.js.map +1 -1
- package/dist/honeycomb/tracer.js.map +1 -1
- package/dist/honeycomb/utils.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/initializeFirefly.d.ts +8 -6
- package/dist/initializeFirefly.js +34 -34
- package/dist/initializeFirefly.js.map +1 -1
- package/dist/internal.d.ts +6 -0
- package/dist/internal.js +26 -0
- package/dist/internal.js.map +1 -0
- package/dist/useAppRouterStore.js.map +1 -1
- package/dist/useCanFetchProtectedData.js.map +1 -1
- package/dist/useCanFetchPublicData.js.map +1 -1
- package/dist/useCanRegisterDeferredRegistrations.js.map +1 -1
- package/dist/useCanUpdateDeferredRegistrations.js.map +1 -1
- package/dist/useDeferredRegistrations.d.ts +1 -5
- package/dist/useDeferredRegistrations.js +2 -5
- package/dist/useDeferredRegistrations.js.map +1 -1
- package/dist/useExecuteOnce.js.map +1 -1
- package/dist/useIsActiveRouteProtected.js.map +1 -1
- package/dist/useIsBootstrapping.js.map +1 -1
- package/dist/useNavigationItems.js.map +1 -1
- package/dist/useProtectedDataHandler.js.map +1 -1
- package/dist/useProtectedDataQueries.js.map +1 -1
- package/dist/usePublicDataHandler.js.map +1 -1
- package/dist/usePublicDataQueries.js.map +1 -1
- package/dist/useRegisterDeferredRegistrations.d.ts +1 -4
- package/dist/useRegisterDeferredRegistrations.js +1 -5
- package/dist/useRegisterDeferredRegistrations.js.map +1 -1
- package/dist/useStrictRegistrationMode.js +10 -17
- package/dist/useStrictRegistrationMode.js.map +1 -1
- package/dist/useUpdateDeferredRegistrations.d.ts +3 -4
- package/dist/useUpdateDeferredRegistrations.js +6 -6
- package/dist/useUpdateDeferredRegistrations.js.map +1 -1
- package/package.json +33 -23
- package/src/AppRouterReducer.ts +51 -89
- package/src/FireflyPlugin.ts +11 -0
- package/src/FireflyRuntime.tsx +89 -55
- package/src/honeycomb/registerHoneycombInstrumentation.ts +30 -169
- package/src/index.ts +31 -4
- package/src/initializeFirefly.ts +60 -49
- package/src/internal.ts +22 -0
- package/src/useDeferredRegistrations.ts +3 -12
- package/src/useRegisterDeferredRegistrations.ts +1 -2
- package/src/useStrictRegistrationMode.ts +10 -15
- package/src/useUpdateDeferredRegistrations.ts +8 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeferredRegistrations.js","sources":["
|
|
1
|
+
{"version":3,"file":"useDeferredRegistrations.js","sources":["../src/useDeferredRegistrations.ts"],"sourcesContent":["import { useRuntime, type ModuleRegistrationError } from \"@squide/core\";\nimport { useEffect } from \"react\";\nimport { useCanRegisterDeferredRegistrations } from \"./useCanRegisterDeferredRegistrations.ts\";\nimport { useCanUpdateDeferredRegistrations } from \"./useCanUpdateDeferredRegistrations.ts\";\nimport { useRegisterDeferredRegistrations } from \"./useRegisterDeferredRegistrations.ts\";\nimport { useUpdateDeferredRegistrations } from \"./useUpdateDeferredRegistrations.ts\";\n\nexport type DeferredRegistrationsErrorCallback = (errors: ModuleRegistrationError[]) => void;\n\nexport interface UseDeferredRegistrationsOptions {\n onError?: DeferredRegistrationsErrorCallback;\n}\n\nexport function useDeferredRegistrations(data: unknown, { onError }: UseDeferredRegistrationsOptions = {}) {\n const runtime = useRuntime();\n\n const canRegisterDeferredRegistrations = useCanRegisterDeferredRegistrations();\n const canUpdateDeferredRegistrations = useCanUpdateDeferredRegistrations();\n\n const registerDeferredRegistrations = useRegisterDeferredRegistrations();\n const updateDeferredRegistrations = useUpdateDeferredRegistrations();\n\n useEffect(() => {\n if (canRegisterDeferredRegistrations) {\n const register = async () => {\n const errors = await registerDeferredRegistrations(data, runtime);\n\n if (errors.length > 0 && onError) {\n onError(errors);\n }\n };\n\n register();\n }\n }, [canRegisterDeferredRegistrations, registerDeferredRegistrations, data, onError, runtime]);\n\n useEffect(() => {\n if (canUpdateDeferredRegistrations) {\n const update = async () => {\n const errors = await updateDeferredRegistrations(data, runtime);\n\n if (errors.length > 0 && onError) {\n onError(errors);\n }\n };\n\n update();\n }\n }, [canUpdateDeferredRegistrations, updateDeferredRegistrations, data, onError, runtime]);\n}\n"],"names":["useRuntime","useEffect","useCanRegisterDeferredRegistrations","useCanUpdateDeferredRegistrations","useRegisterDeferredRegistrations","useUpdateDeferredRegistrations","useDeferredRegistrations","data","onError","runtime","canRegisterDeferredRegistrations","canUpdateDeferredRegistrations","registerDeferredRegistrations","updateDeferredRegistrations","register","errors","update"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAwE;AACtC;AAC6D;AACJ;AACF;AACJ;AAQ9E,SAASM,yBAAyBC,IAAa,EAAE,EAAEC,OAAO,EAAmC,GAAG,CAAC,CAAC;IACrG,MAAMC,UAAUT,UAAUA;IAE1B,MAAMU,mCAAmCR,mCAAmCA;IAC5E,MAAMS,iCAAiCR,iCAAiCA;IAExE,MAAMS,gCAAgCR,gCAAgCA;IACtE,MAAMS,8BAA8BR,8BAA8BA;IAElEJ,SAASA,CAAC;QACN,IAAIS,kCAAkC;YAClC,MAAMI,WAAW;gBACb,MAAMC,SAAS,MAAMH,8BAA8BL,MAAME;gBAEzD,IAAIM,OAAO,MAAM,GAAG,KAAKP,SAAS;oBAC9BA,QAAQO;gBACZ;YACJ;YAEAD;QACJ;IACJ,GAAG;QAACJ;QAAkCE;QAA+BL;QAAMC;QAASC;KAAQ;IAE5FR,SAASA,CAAC;QACN,IAAIU,gCAAgC;YAChC,MAAMK,SAAS;gBACX,MAAMD,SAAS,MAAMF,4BAA4BN,MAAME;gBAEvD,IAAIM,OAAO,MAAM,GAAG,KAAKP,SAAS;oBAC9BA,QAAQO;gBACZ;YACJ;YAEAC;QACJ;IACJ,GAAG;QAACL;QAAgCE;QAA6BN;QAAMC;QAASC;KAAQ;AAC5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExecuteOnce.js","sources":["
|
|
1
|
+
{"version":3,"file":"useExecuteOnce.js","sources":["../src/useExecuteOnce.ts"],"sourcesContent":["import { useCallback, useRef } from \"react\";\n\n// Not using useEffect or useLayoutEffect because this utility hook is often used to dispatch events\n// and it messed with the events dispatch order.\nexport function useExecuteOnce(fct: () => boolean, inline: boolean = false) {\n const triggered = useRef(false);\n\n const onceFct = useCallback(() => {\n if (!triggered.current) {\n const result = fct();\n\n if (result) {\n triggered.current = true;\n }\n }\n }, [fct]);\n\n if (inline) {\n onceFct();\n }\n\n return onceFct;\n}\n"],"names":["useCallback","useRef","useExecuteOnce","fct","inline","triggered","onceFct","result"],"mappings":";;;;;AAA4C;AAE5C,oGAAoG;AACpG,gDAAgD;AACzC,SAASE,eAAeC,GAAkB,EAAEC,SAAkB,KAAK;IACtE,MAAMC,YAAYJ,MAAMA,CAAC;IAEzB,MAAMK,UAAUN,WAAWA,CAAC;QACxB,IAAI,CAACK,UAAU,OAAO,EAAE;YACpB,MAAME,SAASJ;YAEf,IAAII,QAAQ;gBACRF,UAAU,OAAO,GAAG;YACxB;QACJ;IACJ,GAAG;QAACF;KAAI;IAER,IAAIC,QAAQ;QACRE;IACJ;IAEA,OAAOA;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsActiveRouteProtected.js","sources":["
|
|
1
|
+
{"version":3,"file":"useIsActiveRouteProtected.js","sources":["../src/useIsActiveRouteProtected.ts"],"sourcesContent":["import { useIsRouteProtected, useRouteMatch } from \"@squide/react-router\";\nimport { useLocation } from \"react-router\";\n\nexport function useIsActiveRouteProtected(areModulesReady: boolean) {\n // Using this hook instead of window.location to retrieve the current location because it triggers a re-render everytime the browser location change.\n const location = useLocation();\n\n // Only throw when there's no match if the modules are ready, otherwise it's expected that no route will be found since they are not all registered yet.\n const activeRoute = useRouteMatch(location, { throwWhenThereIsNoMatch: areModulesReady });\n\n return useIsRouteProtected(activeRoute);\n}\n"],"names":["useIsRouteProtected","useRouteMatch","useLocation","useIsActiveRouteProtected","areModulesReady","location","activeRoute"],"mappings":";;;;;;;;AAA0E;AAC/B;AAEpC,SAASG,0BAA0BC,eAAwB;IAC9D,qJAAqJ;IACrJ,MAAMC,WAAWH,WAAWA;IAE5B,wJAAwJ;IACxJ,MAAMI,cAAcL,aAAaA,CAACI,UAAU;QAAE,yBAAyBD;IAAgB;IAEvF,OAAOJ,mBAAmBA,CAACM;AAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsBootstrapping.js","sources":["
|
|
1
|
+
{"version":3,"file":"useIsBootstrapping.js","sources":["../src/useIsBootstrapping.ts"],"sourcesContent":["import { useAppRouterState } from \"./AppRouterContext.ts\";\nimport type { AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport function useIsBootstrapping() {\n const state = useAppRouterState();\n\n return isBootstrapping(state);\n}\n\nexport function isBootstrapping(state: AppRouterState) {\n const {\n waitForMsw,\n waitForPublicData,\n waitForProtectedData,\n areModulesReady,\n isMswReady,\n isPublicDataReady,\n isProtectedDataReady,\n activeRouteVisibility,\n isUnauthorized\n } = state;\n\n const isAppReady = (\n !isUnauthorized\n // Wait until the modules has been registered and the deferred registrations has been registered if any.\n && areModulesReady\n // Not required but can sometimes prevent a re-render when the state value is somehow updated after the initial data is ready.\n && (!waitForMsw || isMswReady)\n // Wait for the initial data to be ready.\n && (!waitForPublicData || isPublicDataReady)\n && (!waitForProtectedData || activeRouteVisibility === \"public\" || isProtectedDataReady)\n );\n\n // When an API request returns a 401, the bootstrapping should be bypassed to render the login page.\n const flush = (\n // Only applicable when there's a unauthorized request while fetching the initial data.\n isUnauthorized\n // Not required but can sometimes prevent a re-render when the state value is somehow updated after the public data is ready.\n && (!waitForMsw || isMswReady)\n // If the application is loading public data, we want to wait for this data to be ready to prevent a re-render.\n && (!waitForPublicData || isPublicDataReady)\n );\n\n return !isAppReady && !flush;\n}\n"],"names":["useAppRouterState","useIsBootstrapping","state","isBootstrapping","waitForMsw","waitForPublicData","waitForProtectedData","areModulesReady","isMswReady","isPublicDataReady","isProtectedDataReady","activeRouteVisibility","isUnauthorized","isAppReady","flush"],"mappings":";;;;;AAA0D;AAGnD,SAASC;IACZ,MAAMC,QAAQF,iBAAiBA;IAE/B,OAAOG,gBAAgBD;AAC3B;AAEO,SAASC,gBAAgBD,KAAqB;IACjD,MAAM,EACFE,UAAU,EACVC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,UAAU,EACVC,iBAAiB,EACjBC,oBAAoB,EACpBC,qBAAqB,EACrBC,cAAc,EACjB,GAAGV;IAEJ,MAAMW,aACF,CAACD,kBAEEL,mBAEC,EAACH,cAAcI,UAAS,KAExB,EAACH,qBAAqBI,iBAAgB,KACtC,EAACH,wBAAwBK,0BAA0B,YAAYD,oBAAmB;IAG1F,oGAAoG;IACpG,MAAMI,QACF,uFAAuF;IACvFF,kBAEI,EAACR,cAAcI,UAAS,KAExB,EAACH,qBAAqBI,iBAAgB;IAG9C,OAAO,CAACI,cAAc,CAACC;AAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigationItems.js","sources":["
|
|
1
|
+
{"version":3,"file":"useNavigationItems.js","sources":["../src/useNavigationItems.ts"],"sourcesContent":["import { useRuntimeNavigationItems, type UseRuntimeNavigationItemsOptions } from \"@squide/react-router\";\nimport { useAppRouterState } from \"./AppRouterContext.ts\";\n\nexport type UseNavigationItemsOptions = UseRuntimeNavigationItemsOptions;\n\nexport function useNavigationItems(options?: UseNavigationItemsOptions) {\n // This is not the most sophisticated strategy but it seems to be good enough for now.\n // The idea is that when deferred registrations are used by the consumer applications, the deferred registrations could\n // be updated when the global data is updated. If the deferred registrations are updated, it means that the registered\n // navigation items might have been updated and a re-render must happens to display the new navigation items.\n // Since the \"deferredRegistrationsUpdatedAt\" state value of the AppRouterReducer is updated everytime the deferred registrations\n // are updated, subscribing to the state with useAppRouterState ensure that the navigation items will be re-rendered.\n // A more sophisticated strategy could be implemented later on if needed, something involving a subscription to the \"runtime\" changes, or\n // even introducing new module states.\n useAppRouterState();\n\n return useRuntimeNavigationItems(options);\n}\n"],"names":["useRuntimeNavigationItems","useAppRouterState","useNavigationItems","options"],"mappings":";;;;;;;;AAAwG;AAC9C;AAInD,SAASE,mBAAmBC,OAAmC;IAClE,sFAAsF;IACtF,uHAAuH;IACvH,sHAAsH;IACtH,6GAA6G;IAC7G,iIAAiI;IACjI,qHAAqH;IACrH,yIAAyI;IACzI,sCAAsC;IACtCF,iBAAiBA;IAEjB,OAAOD,yBAAyBA,CAACG;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProtectedDataHandler.js","sources":["
|
|
1
|
+
{"version":3,"file":"useProtectedDataHandler.js","sources":["../src/useProtectedDataHandler.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useCanFetchProtectedData } from \"./useCanFetchProtectedData.ts\";\n\nexport function useProtectedDataHandler(handler: () => void) {\n const canFetchProtectedData = useCanFetchProtectedData();\n\n useEffect(() => {\n if (canFetchProtectedData) {\n handler();\n }\n }, [canFetchProtectedData, handler]);\n}\n"],"names":["useEffect","useCanFetchProtectedData","useProtectedDataHandler","handler","canFetchProtectedData"],"mappings":";;;;;;;;AAAkC;AACuC;AAElE,SAASE,wBAAwBC,OAAmB;IACvD,MAAMC,wBAAwBH,wBAAwBA;IAEtDD,SAASA,CAAC;QACN,IAAII,uBAAuB;YACvBD;QACJ;IACJ,GAAG;QAACC;QAAuBD;KAAQ;AACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProtectedDataQueries.js","sources":["
|
|
1
|
+
{"version":3,"file":"useProtectedDataQueries.js","sources":["../src/useProtectedDataQueries.ts"],"sourcesContent":["import { useEventBus } from \"@squide/core\";\nimport { useQueries, type QueriesOptions, type QueriesResults, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport { useAppRouterDispatcher, useAppRouterState } from \"./AppRouterContext.ts\";\nimport { GlobalDataQueriesError } from \"./GlobalDataQueriesError.ts\";\nimport { useCanFetchProtectedData } from \"./useCanFetchProtectedData.ts\";\nimport { useExecuteOnce } from \"./useExecuteOnce.ts\";\n\nexport const ProtectedDataFetchStartedEvent = \"squide-protected-data-fetch-started\";\nexport const ProtectedDataFetchFailedEvent = \"squide-protected-data-fetch-failed\";\n\nexport type IsUnauthorizedErrorCallback = (error: unknown) => boolean;\n\n// This converts an array of UseQueryResult to an array of the data type of each query result.\n// For more information, view: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html#mapped-types-on-tuples-and-arrays.\ntype MapUseQueryResultToData<T> = { [K in keyof T]: T[K] extends UseQueryResult<infer U> ? U : never };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useProtectedDataQueries<T extends Array<any>>(queries: QueriesOptions<T>, isUnauthorizedError: IsUnauthorizedErrorCallback): MapUseQueryResultToData<QueriesResults<T>> {\n const canFetchProtectedData = useCanFetchProtectedData();\n const eventBus = useEventBus();\n\n const dispatch = useAppRouterDispatcher();\n\n const combineResults = useCallback((results: UseQueryResult<unknown, unknown>[]) => {\n const errors = results.filter(x => x.error).map(x => x.error) as Error[];\n const hasErrors = errors.length > 0;\n\n return {\n data: results.map(x => x.data) as MapUseQueryResultToData<QueriesResults<T>>,\n errors,\n hasErrors,\n isReady: !hasErrors && !results.some(x => x.isPending)\n };\n }, []);\n\n const { data, errors: queriesErrors, hasErrors, isReady } = useQueries({\n queries: queries.map(x => ({\n enabled: canFetchProtectedData,\n ...x\n })),\n combine: combineResults\n });\n\n const { isProtectedDataReady, isUnauthorized } = useAppRouterState();\n\n useExecuteOnce(useCallback(() => {\n if (canFetchProtectedData) {\n eventBus.dispatch(ProtectedDataFetchStartedEvent);\n\n return true;\n }\n\n return false;\n }, [canFetchProtectedData, eventBus]), true);\n\n // Using a ref seems to be the only way to prevent starting two deferred registrations scope.\n const isReadyRef = useRef(false);\n\n const dispatchReady = useExecuteOnce(useCallback(() => {\n if (isReady) {\n isReadyRef.current = true;\n\n dispatch({ type: \"protected-data-ready\" });\n\n return true;\n }\n\n return false;\n }, [isReady, dispatch]));\n\n useEffect(() => {\n // State update must be executed in useEffect.\n dispatchReady();\n }, [dispatchReady]);\n\n useEffect(() => {\n if (isReadyRef.current && data) {\n dispatch({ type: \"protected-data-updated\" });\n }\n }, [data, dispatch]);\n\n useEffect(() => {\n if (hasErrors) {\n if (!isProtectedDataReady && !isUnauthorized && queriesErrors.some(x => isUnauthorizedError(x))) {\n // Will transition the state to allow the routes to render even if the bootstrapping is not complete, because otherwise\n // a login page for example could not be rendered.\n dispatch({ type: \"is-unauthorized\" });\n }\n\n // Otherwise, when a user is logged off, a refetch might throws a 401.\n if (!queriesErrors.every(x => isUnauthorizedError(x))) {\n eventBus.dispatch(ProtectedDataFetchFailedEvent, queriesErrors);\n\n throw new GlobalDataQueriesError(\"[squide] Global protected data queries failed.\", queriesErrors);\n }\n }\n }, [hasErrors, queriesErrors, isProtectedDataReady, isUnauthorized, isUnauthorizedError, dispatch, eventBus]);\n\n return data;\n}\n"],"names":["useEventBus","useQueries","useCallback","useEffect","useRef","useAppRouterDispatcher","useAppRouterState","GlobalDataQueriesError","useCanFetchProtectedData","useExecuteOnce","ProtectedDataFetchStartedEvent","ProtectedDataFetchFailedEvent","useProtectedDataQueries","queries","isUnauthorizedError","canFetchProtectedData","eventBus","dispatch","combineResults","results","errors","x","hasErrors","data","queriesErrors","isReady","isProtectedDataReady","isUnauthorized","isReadyRef","dispatchReady"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAA2C;AACuE;AAC3D;AAC2B;AACb;AACI;AACpB;AAE9C,MAAMU,iCAAiC,sCAAsC;AAC7E,MAAMC,gCAAgC,qCAAqC;AAQlF,8DAA8D;AACvD,SAASC,wBAA8CC,OAA0B,EAAEC,mBAAgD;IACtI,MAAMC,wBAAwBP,wBAAwBA;IACtD,MAAMQ,WAAWhB,WAAWA;IAE5B,MAAMiB,WAAWZ,sBAAsBA;IAEvC,MAAMa,iBAAiBhB,WAAWA,CAAC,CAACiB;QAChC,MAAMC,SAASD,QAAQ,MAAM,CAACE,CAAAA,IAAKA,EAAE,KAAK,EAAE,GAAG,CAACA,CAAAA,IAAKA,EAAE,KAAK;QAC5D,MAAMC,YAAYF,OAAO,MAAM,GAAG;QAElC,OAAO;YACH,MAAMD,QAAQ,GAAG,CAACE,CAAAA,IAAKA,EAAE,IAAI;YAC7BD;YACAE;YACA,SAAS,CAACA,aAAa,CAACH,QAAQ,IAAI,CAACE,CAAAA,IAAKA,EAAE,SAAS;QACzD;IACJ,GAAG,EAAE;IAEL,MAAM,EAAEE,IAAI,EAAE,QAAQC,aAAa,EAAEF,SAAS,EAAEG,OAAO,EAAE,GAAGxB,UAAUA,CAAC;QACnE,SAASY,QAAQ,GAAG,CAACQ,CAAAA,IAAM;gBACvB,SAASN;gBACT,GAAGM,CAAC;YACR;QACA,SAASH;IACb;IAEA,MAAM,EAAEQ,oBAAoB,EAAEC,cAAc,EAAE,GAAGrB,iBAAiBA;IAElEG,cAAcA,CAACP,WAAWA,CAAC;QACvB,IAAIa,uBAAuB;YACvBC,SAAS,QAAQ,CAACN;YAElB,OAAO;QACX;QAEA,OAAO;IACX,GAAG;QAACK;QAAuBC;KAAS,GAAG;IAEvC,6FAA6F;IAC7F,MAAMY,aAAaxB,MAAMA,CAAC;IAE1B,MAAMyB,gBAAgBpB,cAAcA,CAACP,WAAWA,CAAC;QAC7C,IAAIuB,SAAS;YACTG,WAAW,OAAO,GAAG;YAErBX,SAAS;gBAAE,MAAM;YAAuB;YAExC,OAAO;QACX;QAEA,OAAO;IACX,GAAG;QAACQ;QAASR;KAAS;IAEtBd,SAASA,CAAC;QACN,8CAA8C;QAC9C0B;IACJ,GAAG;QAACA;KAAc;IAElB1B,SAASA,CAAC;QACN,IAAIyB,WAAW,OAAO,IAAIL,MAAM;YAC5BN,SAAS;gBAAE,MAAM;YAAyB;QAC9C;IACJ,GAAG;QAACM;QAAMN;KAAS;IAEnBd,SAASA,CAAC;QACN,IAAImB,WAAW;YACX,IAAI,CAACI,wBAAwB,CAACC,kBAAkBH,cAAc,IAAI,CAACH,CAAAA,IAAKP,oBAAoBO,KAAK;gBAC7F,uHAAuH;gBACvH,kDAAkD;gBAClDJ,SAAS;oBAAE,MAAM;gBAAkB;YACvC;YAEA,sEAAsE;YACtE,IAAI,CAACO,cAAc,KAAK,CAACH,CAAAA,IAAKP,oBAAoBO,KAAK;gBACnDL,SAAS,QAAQ,CAACL,+BAA+Ba;gBAEjD,MAAM,IAAIjB,sBAAsBA,CAAC,kDAAkDiB;YACvF;QACJ;IACJ,GAAG;QAACF;QAAWE;QAAeE;QAAsBC;QAAgBb;QAAqBG;QAAUD;KAAS;IAE5G,OAAOO;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePublicDataHandler.js","sources":["
|
|
1
|
+
{"version":3,"file":"usePublicDataHandler.js","sources":["../src/usePublicDataHandler.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useCanFetchPublicData } from \"./useCanFetchPublicData.ts\";\n\nexport function usePublicDataHandler(handler: () => void) {\n const canFetchPublicData = useCanFetchPublicData();\n\n useEffect(() => {\n if (canFetchPublicData) {\n handler();\n }\n }, [canFetchPublicData, handler]);\n}\n"],"names":["useEffect","useCanFetchPublicData","usePublicDataHandler","handler","canFetchPublicData"],"mappings":";;;;;;;;AAAkC;AACiC;AAE5D,SAASE,qBAAqBC,OAAmB;IACpD,MAAMC,qBAAqBH,qBAAqBA;IAEhDD,SAASA,CAAC;QACN,IAAII,oBAAoB;YACpBD;QACJ;IACJ,GAAG;QAACC;QAAoBD;KAAQ;AACpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePublicDataQueries.js","sources":["
|
|
1
|
+
{"version":3,"file":"usePublicDataQueries.js","sources":["../src/usePublicDataQueries.ts"],"sourcesContent":["import { useEventBus } from \"@squide/core\";\nimport { useQueries, type QueriesOptions, type QueriesResults, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport { useAppRouterDispatcher } from \"./AppRouterContext.ts\";\nimport { GlobalDataQueriesError } from \"./GlobalDataQueriesError.ts\";\nimport { useCanFetchPublicData } from \"./useCanFetchPublicData.ts\";\nimport { useExecuteOnce } from \"./useExecuteOnce.ts\";\n\nexport const PublicDataFetchStartedEvent = \"squide-public-data-fetch-started\";\nexport const PublicDataFetchFailedEvent = \"squide-public-data-fetch-failed\";\n\n// This converts an array of UseQueryResult to an array of the data type of each query result.\n// For more information, view: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html#mapped-types-on-tuples-and-arrays.\ntype MapUseQueryResultToData<T> = { [K in keyof T]: T[K] extends UseQueryResult<infer U> ? U : never };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function usePublicDataQueries<T extends Array<any>>(queries: QueriesOptions<T>): MapUseQueryResultToData<QueriesResults<T>> {\n const canFetchPublicData = useCanFetchPublicData();\n const eventBus = useEventBus();\n\n const dispatch = useAppRouterDispatcher();\n\n const combineResults = useCallback((results: UseQueryResult<unknown, unknown>[]) => {\n const errors = results.filter(x => x.error).map(x => x.error) as Error[];\n const hasErrors = errors.length > 0;\n\n return {\n data: results.map(x => x.data) as MapUseQueryResultToData<QueriesResults<T>>,\n errors,\n hasErrors,\n isReady: !hasErrors && !results.some(x => x.isPending)\n };\n }, []);\n\n const { data, errors: queriesErrors, hasErrors, isReady } = useQueries({\n queries: queries.map(x => ({\n enabled: canFetchPublicData,\n ...x\n })),\n combine: combineResults\n });\n\n useExecuteOnce(useCallback(() => {\n if (canFetchPublicData) {\n eventBus.dispatch(PublicDataFetchStartedEvent);\n\n return true;\n }\n\n return false;\n }, [canFetchPublicData, eventBus]), true);\n\n // Using a ref seems to be the only way to prevent starting two deferred registrations scope.\n const isReadyRef = useRef(false);\n\n const dispatchReady = useExecuteOnce(useCallback(() => {\n if (isReady) {\n isReadyRef.current = true;\n\n dispatch({ type: \"public-data-ready\" });\n\n return true;\n }\n\n return false;\n }, [isReady, dispatch]));\n\n useEffect(() => {\n // State update must be executed in useEffect.\n dispatchReady();\n }, [dispatchReady]);\n\n useEffect(() => {\n if (isReadyRef.current && data) {\n dispatch({ type: \"public-data-updated\" });\n }\n }, [data, dispatch]);\n\n useEffect(() => {\n if (hasErrors) {\n eventBus.dispatch(PublicDataFetchFailedEvent, queriesErrors);\n\n throw new GlobalDataQueriesError(\"[squide] Global public data queries failed.\", queriesErrors);\n }\n }, [hasErrors, queriesErrors, eventBus]);\n\n return data;\n}\n"],"names":["useEventBus","useQueries","useCallback","useEffect","useRef","useAppRouterDispatcher","GlobalDataQueriesError","useCanFetchPublicData","useExecuteOnce","PublicDataFetchStartedEvent","PublicDataFetchFailedEvent","usePublicDataQueries","queries","canFetchPublicData","eventBus","dispatch","combineResults","results","errors","x","hasErrors","data","queriesErrors","isReady","isReadyRef","dispatchReady"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAA2C;AACuE;AAC3D;AACQ;AACM;AACF;AACd;AAE9C,MAAMS,8BAA8B,mCAAmC;AACvE,MAAMC,6BAA6B,kCAAkC;AAM5E,8DAA8D;AACvD,SAASC,qBAA2CC,OAA0B;IACjF,MAAMC,qBAAqBN,qBAAqBA;IAChD,MAAMO,WAAWd,WAAWA;IAE5B,MAAMe,WAAWV,sBAAsBA;IAEvC,MAAMW,iBAAiBd,WAAWA,CAAC,CAACe;QAChC,MAAMC,SAASD,QAAQ,MAAM,CAACE,CAAAA,IAAKA,EAAE,KAAK,EAAE,GAAG,CAACA,CAAAA,IAAKA,EAAE,KAAK;QAC5D,MAAMC,YAAYF,OAAO,MAAM,GAAG;QAElC,OAAO;YACH,MAAMD,QAAQ,GAAG,CAACE,CAAAA,IAAKA,EAAE,IAAI;YAC7BD;YACAE;YACA,SAAS,CAACA,aAAa,CAACH,QAAQ,IAAI,CAACE,CAAAA,IAAKA,EAAE,SAAS;QACzD;IACJ,GAAG,EAAE;IAEL,MAAM,EAAEE,IAAI,EAAE,QAAQC,aAAa,EAAEF,SAAS,EAAEG,OAAO,EAAE,GAAGtB,UAAUA,CAAC;QACnE,SAASW,QAAQ,GAAG,CAACO,CAAAA,IAAM;gBACvB,SAASN;gBACT,GAAGM,CAAC;YACR;QACA,SAASH;IACb;IAEAR,cAAcA,CAACN,WAAWA,CAAC;QACvB,IAAIW,oBAAoB;YACpBC,SAAS,QAAQ,CAACL;YAElB,OAAO;QACX;QAEA,OAAO;IACX,GAAG;QAACI;QAAoBC;KAAS,GAAG;IAEpC,6FAA6F;IAC7F,MAAMU,aAAapB,MAAMA,CAAC;IAE1B,MAAMqB,gBAAgBjB,cAAcA,CAACN,WAAWA,CAAC;QAC7C,IAAIqB,SAAS;YACTC,WAAW,OAAO,GAAG;YAErBT,SAAS;gBAAE,MAAM;YAAoB;YAErC,OAAO;QACX;QAEA,OAAO;IACX,GAAG;QAACQ;QAASR;KAAS;IAEtBZ,SAASA,CAAC;QACN,8CAA8C;QAC9CsB;IACJ,GAAG;QAACA;KAAc;IAElBtB,SAASA,CAAC;QACN,IAAIqB,WAAW,OAAO,IAAIH,MAAM;YAC5BN,SAAS;gBAAE,MAAM;YAAsB;QAC3C;IACJ,GAAG;QAACM;QAAMN;KAAS;IAEnBZ,SAASA,CAAC;QACN,IAAIiB,WAAW;YACXN,SAAS,QAAQ,CAACJ,4BAA4BY;YAE9C,MAAM,IAAIhB,sBAAsBA,CAAC,+CAA+CgB;QACpF;IACJ,GAAG;QAACF;QAAWE;QAAeR;KAAS;IAEvC,OAAOO;AACX"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
import type { Runtime } from "@squide/core";
|
|
2
|
-
export declare function useRegisterDeferredRegistrations(): <TData = unknown, TRuntime extends Runtime = Runtime<unknown, unknown>>(data: TData, runtime: TRuntime) => Promise<
|
|
3
|
-
localModuleErrors: import("@squide/core").ModuleRegistrationError[];
|
|
4
|
-
remoteModuleErrors: import("@squide/module-federation").RemoteModuleRegistrationError[];
|
|
5
|
-
}>;
|
|
2
|
+
export declare function useRegisterDeferredRegistrations(): <TData = unknown, TRuntime extends Runtime = Runtime<unknown, unknown, any>>(data: TData, runtime: TRuntime) => Promise<import("@squide/core").ModuleRegistrationError[]>;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { registerDeferredRegistrations } from "@squide/module-federation";
|
|
2
1
|
import { useCallback } from "react";
|
|
3
2
|
|
|
4
|
-
;// CONCATENATED MODULE: external "@squide/module-federation"
|
|
5
|
-
|
|
6
3
|
;// CONCATENATED MODULE: external "react"
|
|
7
4
|
|
|
8
5
|
;// CONCATENATED MODULE: ./src/useRegisterDeferredRegistrations.ts
|
|
9
6
|
|
|
10
|
-
|
|
11
7
|
function useRegisterDeferredRegistrations() {
|
|
12
8
|
return useCallback((data, runtime)=>{
|
|
13
|
-
return registerDeferredRegistrations(data
|
|
9
|
+
return runtime.moduleManager.registerDeferredRegistrations(data);
|
|
14
10
|
}, []);
|
|
15
11
|
}
|
|
16
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRegisterDeferredRegistrations.js","sources":["
|
|
1
|
+
{"version":3,"file":"useRegisterDeferredRegistrations.js","sources":["../src/useRegisterDeferredRegistrations.ts"],"sourcesContent":["import type { Runtime } from \"@squide/core\";\nimport { useCallback } from \"react\";\n\nexport function useRegisterDeferredRegistrations() {\n return useCallback(<TData = unknown, TRuntime extends Runtime = Runtime>(data: TData, runtime: TRuntime) => {\n return runtime.moduleManager.registerDeferredRegistrations(data);\n }, []);\n}\n"],"names":["useCallback","useRegisterDeferredRegistrations","data","runtime"],"mappings":";;;;;AACoC;AAE7B,SAASC;IACZ,OAAOD,WAAWA,CAAC,CAAsDE,MAAaC;QAClF,OAAOA,QAAQ,aAAa,CAAC,6BAA6B,CAACD;IAC/D,GAAG,EAAE;AACT"}
|
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from "@squide/module-federation";
|
|
1
|
+
import { useRuntime } from "@squide/core";
|
|
3
2
|
import { useEffect, useSyncExternalStore } from "react";
|
|
4
3
|
|
|
5
4
|
;// CONCATENATED MODULE: external "@squide/core"
|
|
6
5
|
|
|
7
|
-
;// CONCATENATED MODULE: external "@squide/module-federation"
|
|
8
|
-
|
|
9
6
|
;// CONCATENATED MODULE: external "react"
|
|
10
7
|
|
|
11
8
|
;// CONCATENATED MODULE: ./src/useStrictRegistrationMode.ts
|
|
12
9
|
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
function subscribeToRemoteModuleRegistrationStatusChanged(callback) {
|
|
20
|
-
addRemoteModuleRegistrationStatusChangedListener(callback);
|
|
21
|
-
return ()=>removeRemoteModuleRegistrationStatusChangedListener(callback);
|
|
11
|
+
function subscribeToModulesReady(runtime) {
|
|
12
|
+
return (callback)=>{
|
|
13
|
+
runtime.moduleManager.registerModulesReadyListener(callback);
|
|
14
|
+
return ()=>runtime.moduleManager.removeModulesReadyListener(callback);
|
|
15
|
+
};
|
|
22
16
|
}
|
|
23
17
|
function useStrictRegistrationMode() {
|
|
24
18
|
const runtime = useRuntime();
|
|
25
|
-
|
|
26
|
-
const
|
|
19
|
+
// This listener is only executed if the modules are ready.
|
|
20
|
+
const areModulesReady = useSyncExternalStore(subscribeToModulesReady(runtime), ()=>runtime.moduleManager.getAreModulesReady());
|
|
27
21
|
useEffect(()=>{
|
|
28
|
-
if (areModulesReady
|
|
22
|
+
if (areModulesReady) {
|
|
29
23
|
runtime._validateRegistrations();
|
|
30
24
|
}
|
|
31
25
|
}, [
|
|
32
26
|
runtime,
|
|
33
|
-
|
|
34
|
-
remoteModuleStatus
|
|
27
|
+
areModulesReady
|
|
35
28
|
]);
|
|
36
29
|
}
|
|
37
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStrictRegistrationMode.js","sources":["
|
|
1
|
+
{"version":3,"file":"useStrictRegistrationMode.js","sources":["../src/useStrictRegistrationMode.ts"],"sourcesContent":["import { Runtime, useRuntime } from \"@squide/core\";\nimport { useEffect, useSyncExternalStore } from \"react\";\n\nfunction subscribeToModulesReady(runtime: Runtime) {\n return (callback: () => void) => {\n runtime.moduleManager.registerModulesReadyListener(callback);\n\n return () => runtime.moduleManager.removeModulesReadyListener(callback);\n };\n}\n\nexport function useStrictRegistrationMode() {\n const runtime = useRuntime();\n\n // This listener is only executed if the modules are ready.\n const areModulesReady = useSyncExternalStore(subscribeToModulesReady(runtime), () => runtime.moduleManager.getAreModulesReady());\n\n useEffect(() => {\n if (areModulesReady) {\n runtime._validateRegistrations();\n }\n }, [runtime, areModulesReady]);\n}\n"],"names":["useRuntime","useEffect","useSyncExternalStore","subscribeToModulesReady","runtime","callback","useStrictRegistrationMode","areModulesReady"],"mappings":";;;;;;;;AAAmD;AACK;AAExD,SAASG,wBAAwBC,OAAgB;IAC7C,OAAO,CAACC;QACJD,QAAQ,aAAa,CAAC,4BAA4B,CAACC;QAEnD,OAAO,IAAMD,QAAQ,aAAa,CAAC,0BAA0B,CAACC;IAClE;AACJ;AAEO,SAASC;IACZ,MAAMF,UAAUJ,UAAUA;IAE1B,2DAA2D;IAC3D,MAAMO,kBAAkBL,oBAAoBA,CAACC,wBAAwBC,UAAU,IAAMA,QAAQ,aAAa,CAAC,kBAAkB;IAE7HH,SAASA,CAAC;QACN,IAAIM,iBAAiB;YACjBH,QAAQ,sBAAsB;QAClC;IACJ,GAAG;QAACA;QAASG;KAAgB;AACjC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Runtime } from "@squide/core";
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}>;
|
|
2
|
+
export declare const DeferredRegistrationsUpdateStartedEvent = "squide-deferred-registrations-update-started";
|
|
3
|
+
export declare const DeferredRegistrationsUpdateCompletedEvent = "squide-deferred-registrations-update-completed-started";
|
|
4
|
+
export declare function useUpdateDeferredRegistrations(): <TData = unknown, TRuntime extends Runtime = Runtime<unknown, unknown, any>>(data: TData, runtime: TRuntime) => Promise<import("@squide/core").ModuleRegistrationError[]>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { updateDeferredRegistrations } from "@squide/module-federation";
|
|
2
1
|
import { useCallback } from "react";
|
|
3
2
|
import { useAppRouterDispatcher } from "./AppRouterContext.js";
|
|
4
3
|
|
|
5
|
-
;// CONCATENATED MODULE: external "@squide/module-federation"
|
|
6
|
-
|
|
7
4
|
;// CONCATENATED MODULE: external "react"
|
|
8
5
|
|
|
9
6
|
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
@@ -11,20 +8,23 @@ import { useAppRouterDispatcher } from "./AppRouterContext.js";
|
|
|
11
8
|
;// CONCATENATED MODULE: ./src/useUpdateDeferredRegistrations.ts
|
|
12
9
|
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
const DeferredRegistrationsUpdateStartedEvent = "squide-deferred-registrations-update-started";
|
|
12
|
+
const DeferredRegistrationsUpdateCompletedEvent = "squide-deferred-registrations-update-completed-started";
|
|
15
13
|
function useUpdateDeferredRegistrations() {
|
|
16
14
|
const dispatch = useAppRouterDispatcher();
|
|
17
15
|
return useCallback(async (data, runtime)=>{
|
|
18
|
-
|
|
16
|
+
runtime.eventBus.dispatch(DeferredRegistrationsUpdateStartedEvent);
|
|
17
|
+
const errors = await runtime.moduleManager.updateDeferredRegistrations(data);
|
|
19
18
|
dispatch({
|
|
20
19
|
type: "deferred-registrations-updated"
|
|
21
20
|
});
|
|
21
|
+
runtime.eventBus.dispatch(DeferredRegistrationsUpdateCompletedEvent);
|
|
22
22
|
return errors;
|
|
23
23
|
}, [
|
|
24
24
|
dispatch
|
|
25
25
|
]);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export { useUpdateDeferredRegistrations };
|
|
28
|
+
export { DeferredRegistrationsUpdateCompletedEvent, DeferredRegistrationsUpdateStartedEvent, useUpdateDeferredRegistrations };
|
|
29
29
|
|
|
30
30
|
//# sourceMappingURL=useUpdateDeferredRegistrations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpdateDeferredRegistrations.js","sources":["
|
|
1
|
+
{"version":3,"file":"useUpdateDeferredRegistrations.js","sources":["../src/useUpdateDeferredRegistrations.ts"],"sourcesContent":["import type { Runtime } from \"@squide/core\";\nimport { useCallback } from \"react\";\nimport { useAppRouterDispatcher } from \"./AppRouterContext.ts\";\n\nexport const DeferredRegistrationsUpdateStartedEvent = \"squide-deferred-registrations-update-started\";\nexport const DeferredRegistrationsUpdateCompletedEvent = \"squide-deferred-registrations-update-completed-started\";\n\nexport function useUpdateDeferredRegistrations() {\n const dispatch = useAppRouterDispatcher();\n\n return useCallback(async <TData = unknown, TRuntime extends Runtime = Runtime>(data: TData, runtime: TRuntime) => {\n runtime.eventBus.dispatch(DeferredRegistrationsUpdateStartedEvent);\n\n const errors = await runtime.moduleManager.updateDeferredRegistrations(data);\n\n dispatch({ type: \"deferred-registrations-updated\" });\n\n runtime.eventBus.dispatch(DeferredRegistrationsUpdateCompletedEvent);\n\n return errors;\n }, [dispatch]);\n}\n"],"names":["useCallback","useAppRouterDispatcher","DeferredRegistrationsUpdateStartedEvent","DeferredRegistrationsUpdateCompletedEvent","useUpdateDeferredRegistrations","dispatch","data","runtime","errors"],"mappings":";;;;;;;;AACoC;AAC2B;AAExD,MAAME,0CAA0C,+CAA+C;AAC/F,MAAMC,4CAA4C,yDAAyD;AAE3G,SAASC;IACZ,MAAMC,WAAWJ,sBAAsBA;IAEvC,OAAOD,WAAWA,CAAC,OAA4DM,MAAaC;QACxFA,QAAQ,QAAQ,CAAC,QAAQ,CAACL;QAE1B,MAAMM,SAAS,MAAMD,QAAQ,aAAa,CAAC,2BAA2B,CAACD;QAEvED,SAAS;YAAE,MAAM;QAAiC;QAElDE,QAAQ,QAAQ,CAAC,QAAQ,CAACJ;QAE1B,OAAOK;IACX,GAAG;QAACH;KAAS;AACjB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squide/firefly",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "16.0.1",
|
|
5
5
|
"description": "Helpers to facilitate the creation of an application with the Squide firefly technology stack.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"import": "./dist/index.js",
|
|
21
21
|
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./internal": {
|
|
24
|
+
"types": "./dist/internal.d.ts",
|
|
25
|
+
"import": "./dist/internal.js",
|
|
26
|
+
"default": "./dist/internal.js"
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
"files": [
|
|
@@ -28,43 +33,48 @@
|
|
|
28
33
|
],
|
|
29
34
|
"peerDependencies": {
|
|
30
35
|
"@opentelemetry/api": "^1.9.0",
|
|
31
|
-
"@tanstack/react-query": "^5.90.
|
|
32
|
-
"msw": "^2.
|
|
36
|
+
"@tanstack/react-query": "^5.90.10",
|
|
37
|
+
"msw": "^2.12.2",
|
|
33
38
|
"react": "^18.0.0 || ^19.0.0",
|
|
34
39
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
35
|
-
"react-router": "^7.9.
|
|
40
|
+
"react-router": "^7.9.6"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@opentelemetry/api": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
36
46
|
},
|
|
37
47
|
"dependencies": {
|
|
38
|
-
"@workleap-telemetry/core": "^1.0.
|
|
39
|
-
"@workleap/logging": "^1.3.
|
|
48
|
+
"@workleap-telemetry/core": "^1.0.4",
|
|
49
|
+
"@workleap/logging": "^1.3.2",
|
|
40
50
|
"uuid": "^13.0.0",
|
|
41
|
-
"@squide/
|
|
42
|
-
"@squide/
|
|
43
|
-
"@squide/
|
|
44
|
-
"@squide/
|
|
51
|
+
"@squide/env-vars": "1.4.8",
|
|
52
|
+
"@squide/msw": "4.0.6",
|
|
53
|
+
"@squide/react-router": "8.1.5",
|
|
54
|
+
"@squide/core": "6.1.5"
|
|
45
55
|
},
|
|
46
56
|
"devDependencies": {
|
|
47
|
-
"@eslint/js": "9.
|
|
48
|
-
"@rsbuild/core": "1.
|
|
49
|
-
"@rslib/core": "0.
|
|
57
|
+
"@eslint/js": "9.39.1",
|
|
58
|
+
"@rsbuild/core": "1.6.7",
|
|
59
|
+
"@rslib/core": "0.18.0",
|
|
50
60
|
"@testing-library/react": "16.3.0",
|
|
51
|
-
"@types/react": "19.2.
|
|
52
|
-
"@types/react-dom": "19.2.
|
|
53
|
-
"@typescript-eslint/parser": "8.
|
|
54
|
-
"@vitejs/plugin-react": "5.
|
|
55
|
-
"@workleap/eslint-configs": "
|
|
61
|
+
"@types/react": "19.2.6",
|
|
62
|
+
"@types/react-dom": "19.2.3",
|
|
63
|
+
"@typescript-eslint/parser": "8.47.0",
|
|
64
|
+
"@vitejs/plugin-react": "5.1.1",
|
|
65
|
+
"@workleap/eslint-configs": "1.1.5",
|
|
56
66
|
"@workleap/rslib-configs": "1.1.3",
|
|
57
67
|
"@workleap/typescript-configs": "3.0.7",
|
|
58
|
-
"eslint": "9.
|
|
59
|
-
"happy-dom": "20.0.
|
|
68
|
+
"eslint": "9.39.1",
|
|
69
|
+
"happy-dom": "20.0.10",
|
|
60
70
|
"typescript": "5.9.3",
|
|
61
|
-
"typescript-eslint": "8.
|
|
62
|
-
"vitest": "4.0.
|
|
71
|
+
"typescript-eslint": "8.47.0",
|
|
72
|
+
"vitest": "4.0.10"
|
|
63
73
|
},
|
|
64
74
|
"sideEffects": false,
|
|
65
75
|
"scripts": {
|
|
66
76
|
"build": "rslib build --config ./rslib.build.ts",
|
|
67
|
-
"eslint": "eslint . --max-warnings
|
|
77
|
+
"eslint": "eslint . --max-warnings=0 --cache --cache-location node_modules/.cache/eslint",
|
|
68
78
|
"typecheck": "tsc",
|
|
69
79
|
"test": "vitest --config vitest.config.ts --no-watch"
|
|
70
80
|
}
|
package/src/AppRouterReducer.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, areModulesRegistered, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from "@squide/module-federation";
|
|
3
|
-
import { addMswStateChangedListener, isMswReady, removeMswStateChangedListener } from "@squide/msw";
|
|
1
|
+
import { useEventBus, useLogger, useRuntime } from "@squide/core";
|
|
4
2
|
import { useCallback, useEffect, useMemo, useReducer, type Dispatch } from "react";
|
|
5
3
|
import type { FireflyRuntime } from "./FireflyRuntime.tsx";
|
|
6
4
|
import { useAppRouterStore } from "./useAppRouterStore.ts";
|
|
@@ -166,110 +164,75 @@ function reducer(state: AppRouterState, action: AppRouterAction) {
|
|
|
166
164
|
return newState;
|
|
167
165
|
}
|
|
168
166
|
|
|
169
|
-
export function
|
|
170
|
-
const localModuleStatus = getLocalModuleRegistrationStatus();
|
|
171
|
-
const remoteModuleStatus = getRemoteModuleRegistrationStatus();
|
|
172
|
-
|
|
173
|
-
return areModulesRegistered(localModuleStatus, remoteModuleStatus);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function getAreModulesReady() {
|
|
177
|
-
const localModuleStatus = getLocalModuleRegistrationStatus();
|
|
178
|
-
const remoteModuleStatus = getRemoteModuleRegistrationStatus();
|
|
179
|
-
|
|
180
|
-
return areModulesReady(localModuleStatus, remoteModuleStatus);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {
|
|
167
|
+
export function useModuleRegistrationStatusDispatcher(runtime: FireflyRuntime, areModulesRegisteredValue: boolean, areModulesReadyValue: boolean, dispatch: AppRouterDispatch) {
|
|
184
168
|
const logger = useLogger();
|
|
185
169
|
|
|
186
|
-
const dispatchModulesRegistered =
|
|
187
|
-
|
|
188
|
-
dispatch({ type: "modules-registered" });
|
|
189
|
-
|
|
190
|
-
logger
|
|
191
|
-
.withText("[squide] Modules are registered.", {
|
|
192
|
-
style: {
|
|
193
|
-
color: "green"
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
.information();
|
|
197
|
-
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return false;
|
|
202
|
-
}, [dispatch, logger]));
|
|
170
|
+
const dispatchModulesRegistered = useCallback(() => {
|
|
171
|
+
dispatch({ type: "modules-registered" });
|
|
203
172
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
})
|
|
214
|
-
.information();
|
|
173
|
+
logger
|
|
174
|
+
.withText("[squide] Modules are registered.", {
|
|
175
|
+
style: {
|
|
176
|
+
color: "green"
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
.information();
|
|
180
|
+
}, [dispatch, logger]);
|
|
215
181
|
|
|
216
|
-
|
|
217
|
-
}
|
|
182
|
+
const dispatchModulesReady = useCallback(() => {
|
|
183
|
+
dispatch({ type: "modules-ready" });
|
|
218
184
|
|
|
219
|
-
|
|
220
|
-
|
|
185
|
+
logger
|
|
186
|
+
.withText("[squide] Modules are ready.", {
|
|
187
|
+
style: {
|
|
188
|
+
color: "green"
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
.information();
|
|
192
|
+
}, [dispatch, logger]);
|
|
221
193
|
|
|
222
194
|
return useEffect(() => {
|
|
223
195
|
if (!areModulesRegisteredValue) {
|
|
224
|
-
|
|
225
|
-
addRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
196
|
+
runtime.moduleManager.registerModulesRegisteredListener(dispatchModulesRegistered);
|
|
226
197
|
}
|
|
227
198
|
|
|
228
199
|
if (!areModulesReadyValue) {
|
|
229
|
-
|
|
230
|
-
addRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
200
|
+
runtime.moduleManager.registerModulesReadyListener(dispatchModulesReady);
|
|
231
201
|
}
|
|
232
202
|
|
|
233
203
|
return () => {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
removeLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
238
|
-
removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
204
|
+
runtime.moduleManager.removeModulesRegisteredListener(dispatchModulesRegistered);
|
|
205
|
+
runtime.moduleManager.removeModulesReadyListener(dispatchModulesReady);
|
|
239
206
|
};
|
|
240
207
|
}, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);
|
|
241
208
|
}
|
|
242
209
|
|
|
243
|
-
export function useMswStatusDispatcher(isMswReadyValue: boolean, dispatch: AppRouterDispatch) {
|
|
210
|
+
export function useMswStatusDispatcher(runtime: FireflyRuntime, isMswReadyValue: boolean, dispatch: AppRouterDispatch) {
|
|
244
211
|
const logger = useLogger();
|
|
245
212
|
|
|
246
|
-
const dispatchMswReady =
|
|
247
|
-
|
|
248
|
-
dispatch({ type: "msw-ready" });
|
|
249
|
-
|
|
250
|
-
logger
|
|
251
|
-
.withText("[squide] MSW is ready.", {
|
|
252
|
-
style: {
|
|
253
|
-
color: "green"
|
|
254
|
-
}
|
|
255
|
-
})
|
|
256
|
-
.information();
|
|
213
|
+
const dispatchMswReady = useCallback(() => {
|
|
214
|
+
dispatch({ type: "msw-ready" });
|
|
257
215
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
216
|
+
logger
|
|
217
|
+
.withText("[squide] MSW is ready.", {
|
|
218
|
+
style: {
|
|
219
|
+
color: "green"
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
.information();
|
|
223
|
+
}, [dispatch, logger]);
|
|
263
224
|
|
|
264
225
|
useEffect(() => {
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
226
|
+
if (runtime.isMswEnabled) {
|
|
227
|
+
if (!isMswReadyValue) {
|
|
228
|
+
runtime.getMswState().addMswReadyListener(dispatchMswReady);
|
|
229
|
+
}
|
|
268
230
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
231
|
+
return () => {
|
|
232
|
+
runtime.getMswState().removeMswReadyListener(dispatchMswReady);
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}, [runtime, isMswReadyValue, dispatchMswReady]);
|
|
273
236
|
}
|
|
274
237
|
|
|
275
238
|
function useBootstrappingCompletedDispatcher(waitState: AppRouterWaitState, state: AppRouterState) {
|
|
@@ -331,10 +294,9 @@ export function useAppRouterReducer(waitForPublicData: boolean, waitForProtected
|
|
|
331
294
|
const appRouterStore = useAppRouterStore();
|
|
332
295
|
|
|
333
296
|
const isMswEnabled = runtime.isMswEnabled;
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const isMswInitiallyReady = isMswReady();
|
|
297
|
+
const areModulesInitiallyRegistered = runtime.moduleManager.getAreModulesRegistered();
|
|
298
|
+
const areModulesInitiallyReady = runtime.moduleManager.getAreModulesReady();
|
|
299
|
+
const isMswInitiallyReady = runtime.isMswEnabled ? runtime.getMswState().isReady : false;
|
|
338
300
|
|
|
339
301
|
const waitState = useMemo(() => ({
|
|
340
302
|
waitForMsw: isMswEnabled,
|
|
@@ -402,8 +364,8 @@ export function useAppRouterReducer(waitForPublicData: boolean, waitForProtected
|
|
|
402
364
|
const dispatchProxy = useReducerDispatchProxy(reactDispatch);
|
|
403
365
|
const dispatch = useEnhancedReducerDispatch(waitState, dispatchProxy);
|
|
404
366
|
|
|
405
|
-
useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);
|
|
406
|
-
useMswStatusDispatcher(isMswReadyValue, dispatch);
|
|
367
|
+
useModuleRegistrationStatusDispatcher(runtime, areModulesRegisteredValue, areModulesReadyValue, dispatch);
|
|
368
|
+
useMswStatusDispatcher(runtime, isMswReadyValue, dispatch);
|
|
407
369
|
useBootstrappingCompletedDispatcher(waitState, state);
|
|
408
370
|
|
|
409
371
|
return [state, dispatch];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from "@squide/core";
|
|
2
|
+
import { FireflyRuntime } from "./FireflyRuntime.tsx";
|
|
3
|
+
import { GetSpanFunction, HoneycombTrackingUnmanagedErrorHandler } from "./honeycomb/registerHoneycombInstrumentation.ts";
|
|
4
|
+
|
|
5
|
+
export interface FireflyPlugin extends Plugin<FireflyRuntime> {
|
|
6
|
+
registerHoneycombTrackingListeners?: (
|
|
7
|
+
getBootstrappingSpan: GetSpanFunction,
|
|
8
|
+
getDeferredRegistrationsUpdateSpan: GetSpanFunction,
|
|
9
|
+
onUnmanagedError: HoneycombTrackingUnmanagedErrorHandler
|
|
10
|
+
) => HoneycombTrackingUnmanagedErrorHandler;
|
|
11
|
+
}
|