@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.
Files changed (69) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/AppRouter.js.map +1 -1
  3. package/dist/AppRouterContext.js.map +1 -1
  4. package/dist/AppRouterReducer.d.ts +3 -4
  5. package/dist/AppRouterReducer.js +51 -82
  6. package/dist/AppRouterReducer.js.map +1 -1
  7. package/dist/AppRouterStore.js.map +1 -1
  8. package/dist/FireflyPlugin.d.ts +6 -0
  9. package/dist/FireflyPlugin.js +6 -0
  10. package/dist/FireflyPlugin.js.map +1 -0
  11. package/dist/FireflyProvider.js.map +1 -1
  12. package/dist/FireflyRuntime.d.ts +26 -11
  13. package/dist/FireflyRuntime.js +61 -45
  14. package/dist/FireflyRuntime.js.map +1 -1
  15. package/dist/GlobalDataQueriesError.js.map +1 -1
  16. package/dist/RootRoute.js.map +1 -1
  17. package/dist/honeycomb/activeSpan.js.map +1 -1
  18. package/dist/honeycomb/createTraceContextId.js.map +1 -1
  19. package/dist/honeycomb/initializeHoneycomb.js.map +1 -1
  20. package/dist/honeycomb/registerHoneycombInstrumentation.d.ts +8 -0
  21. package/dist/honeycomb/registerHoneycombInstrumentation.js +19 -136
  22. package/dist/honeycomb/registerHoneycombInstrumentation.js.map +1 -1
  23. package/dist/honeycomb/tracer.js.map +1 -1
  24. package/dist/honeycomb/utils.js.map +1 -1
  25. package/dist/index.d.ts +4 -4
  26. package/dist/index.js +10 -5
  27. package/dist/index.js.map +1 -1
  28. package/dist/initializeFirefly.d.ts +8 -6
  29. package/dist/initializeFirefly.js +34 -34
  30. package/dist/initializeFirefly.js.map +1 -1
  31. package/dist/internal.d.ts +6 -0
  32. package/dist/internal.js +26 -0
  33. package/dist/internal.js.map +1 -0
  34. package/dist/useAppRouterStore.js.map +1 -1
  35. package/dist/useCanFetchProtectedData.js.map +1 -1
  36. package/dist/useCanFetchPublicData.js.map +1 -1
  37. package/dist/useCanRegisterDeferredRegistrations.js.map +1 -1
  38. package/dist/useCanUpdateDeferredRegistrations.js.map +1 -1
  39. package/dist/useDeferredRegistrations.d.ts +1 -5
  40. package/dist/useDeferredRegistrations.js +2 -5
  41. package/dist/useDeferredRegistrations.js.map +1 -1
  42. package/dist/useExecuteOnce.js.map +1 -1
  43. package/dist/useIsActiveRouteProtected.js.map +1 -1
  44. package/dist/useIsBootstrapping.js.map +1 -1
  45. package/dist/useNavigationItems.js.map +1 -1
  46. package/dist/useProtectedDataHandler.js.map +1 -1
  47. package/dist/useProtectedDataQueries.js.map +1 -1
  48. package/dist/usePublicDataHandler.js.map +1 -1
  49. package/dist/usePublicDataQueries.js.map +1 -1
  50. package/dist/useRegisterDeferredRegistrations.d.ts +1 -4
  51. package/dist/useRegisterDeferredRegistrations.js +1 -5
  52. package/dist/useRegisterDeferredRegistrations.js.map +1 -1
  53. package/dist/useStrictRegistrationMode.js +10 -17
  54. package/dist/useStrictRegistrationMode.js.map +1 -1
  55. package/dist/useUpdateDeferredRegistrations.d.ts +3 -4
  56. package/dist/useUpdateDeferredRegistrations.js +6 -6
  57. package/dist/useUpdateDeferredRegistrations.js.map +1 -1
  58. package/package.json +33 -23
  59. package/src/AppRouterReducer.ts +51 -89
  60. package/src/FireflyPlugin.ts +11 -0
  61. package/src/FireflyRuntime.tsx +89 -55
  62. package/src/honeycomb/registerHoneycombInstrumentation.ts +30 -169
  63. package/src/index.ts +31 -4
  64. package/src/initializeFirefly.ts +60 -49
  65. package/src/internal.ts +22 -0
  66. package/src/useDeferredRegistrations.ts +3 -12
  67. package/src/useRegisterDeferredRegistrations.ts +1 -2
  68. package/src/useStrictRegistrationMode.ts +10 -15
  69. package/src/useUpdateDeferredRegistrations.ts +8 -2
@@ -1,6 +1,6 @@
1
- import { isFunction, registerLocalModules, type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
2
- import { registerRemoteModules, type RemoteDefinition } from "@squide/module-federation";
3
- import { setMswAsReady } from "@squide/msw";
1
+ import { isFunction, ModuleDefinition, toLocalModuleDefinitions, type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
2
+ import { EnvironmentVariables, EnvironmentVariablesPlugin } from "@squide/env-vars";
3
+ import { MswPlugin } from "@squide/msw";
4
4
  import type { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
5
5
  import { FireflyRuntime, type FireflyRuntimeOptions } from "./FireflyRuntime.tsx";
6
6
  import { initializeHoneycomb } from "./honeycomb/initializeHoneycomb.ts";
@@ -13,26 +13,20 @@ export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) =>
13
13
 
14
14
  export interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext>, FireflyRuntimeOptions {
15
15
  localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
16
- remotes?: RemoteDefinition[];
16
+ moduleDefinitions?: ModuleDefinition<TRuntime, TContext, TData>[];
17
+ useMsw?: boolean;
18
+ environmentVariables?: Partial<EnvironmentVariables>;
17
19
  honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;
18
20
  startMsw?: StartMswFunction<FireflyRuntime>;
19
21
  onError?: OnInitializationErrorFunction;
20
22
  }
21
23
 
22
- function propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError: OnInitializationErrorFunction) {
23
- if (results) {
24
- if (results.status === "fulfilled") {
25
- results.value.forEach(x => {
26
- onError(x);
27
- });
28
- }
29
- }
30
- }
31
-
32
- export function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: InitializeFireflyOptions<TRuntime, TContext, TData> = {}) {
24
+ export function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(
25
+ runtime: TRuntime,
26
+ modulesDefinitions: ModuleDefinition<TRuntime, TContext, TData>[],
27
+ options: Omit<InitializeFireflyOptions<TRuntime, TContext, TData>, "localModules" | "moduleDefinitions"> = {}
28
+ ) {
33
29
  const {
34
- localModules = [],
35
- remotes = [],
36
30
  startMsw,
37
31
  onError,
38
32
  context
@@ -40,43 +34,52 @@ export function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TCon
40
34
 
41
35
  runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);
42
36
 
43
- Promise.allSettled([
44
- registerLocalModules<TRuntime, TContext, TData>(localModules, runtime, { context }),
45
- registerRemoteModules(remotes, runtime, { context })
46
- ]).then(results => {
47
- if (runtime.isMswEnabled) {
48
- if (!isFunction(startMsw)) {
49
- throw new Error("[squide] When MSW is enabled, the \"startMsw\" function must be provided.");
37
+ runtime.moduleManager.registerModules(modulesDefinitions, { context })
38
+ .then(results => {
39
+ if (runtime.isMswEnabled) {
40
+ if (!isFunction(startMsw)) {
41
+ throw new Error("[squide] When MSW is enabled, the \"startMsw\" function must be provided.");
42
+ }
43
+
44
+ startMsw(runtime)
45
+ .then(() => {
46
+ if (runtime.isMswEnabled) {
47
+ runtime.getMswState().setAsReady();
48
+ }
49
+ })
50
+ .catch((error: unknown) => {
51
+ runtime.logger
52
+ .withText("[squide] An error occured while starting MSW.")
53
+ .withError(error as Error)
54
+ .error();
55
+ });
50
56
  }
51
57
 
52
- startMsw(runtime)
53
- .then(() => {
54
- setMswAsReady();
55
- })
56
- .catch((error: unknown) => {
57
- runtime.logger
58
- .withText("[squide] An error occured while starting MSW.")
59
- .withError(error as Error)
60
- .error();
58
+ if (onError) {
59
+ results.forEach(error => {
60
+ onError(error);
61
61
  });
62
- }
63
-
64
- if (onError) {
65
- propagateRegistrationErrors(results[0], onError);
66
- propagateRegistrationErrors(results[1], onError);
67
- }
68
- });
62
+ }
63
+ });
69
64
  }
70
65
 
71
66
  let hasExecuted = false;
72
67
 
68
+ // Should only be used by tests.
69
+ export function __resetHasExecutedGuard() {
70
+ hasExecuted = false;
71
+ }
72
+
73
73
  export function initializeFirefly<TContext = unknown, TData = unknown>(options: InitializeFireflyOptions<FireflyRuntime, TContext, TData> = {}) {
74
74
  const {
75
75
  mode,
76
+ localModules = [],
77
+ moduleDefinitions = [],
76
78
  useMsw,
77
- loggers,
78
- plugins,
79
+ plugins = [],
80
+ environmentVariables,
79
81
  honeycombInstrumentationClient,
82
+ loggers,
80
83
  onError
81
84
  } = options;
82
85
 
@@ -86,12 +89,20 @@ export function initializeFirefly<TContext = unknown, TData = unknown>(options:
86
89
 
87
90
  hasExecuted = true;
88
91
 
92
+ if (useMsw) {
93
+ plugins.push(x => new MswPlugin(x));
94
+ }
95
+
89
96
  const runtime = new FireflyRuntime({
90
97
  mode,
91
- useMsw,
92
98
  honeycombInstrumentationClient,
93
99
  loggers,
94
- plugins
100
+ plugins: [
101
+ x => new EnvironmentVariablesPlugin(x, {
102
+ variables: environmentVariables
103
+ }),
104
+ ...plugins
105
+ ]
95
106
  });
96
107
 
97
108
  initializeHoneycomb(runtime)
@@ -101,12 +112,12 @@ export function initializeFirefly<TContext = unknown, TData = unknown>(options:
101
112
  }
102
113
  })
103
114
  .finally(() => {
104
- bootstrap(runtime, options);
115
+ bootstrap(
116
+ runtime,
117
+ [...moduleDefinitions, ...toLocalModuleDefinitions(localModules)],
118
+ options
119
+ );
105
120
  });
106
121
 
107
122
  return runtime;
108
123
  }
109
-
110
- export function __resetHasExecuteGuard() {
111
- hasExecuted = false;
112
- }
@@ -0,0 +1,22 @@
1
+ export { AppRouterDispatcherContext, AppRouterStateContext } from "./AppRouterContext.ts";
2
+ export { __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, useAppRouterReducer, type AppRouterDispatch, type AppRouterState } from "./AppRouterReducer.ts";
3
+
4
+ export type { ActiveSpan, ActiveSpanId } from "./honeycomb/activeSpan.ts";
5
+ export { addProtectedListener, type AddProtectedListenerOptions, type GetSpanFunction, type HoneycombTrackingUnmanagedErrorHandler } from "./honeycomb/registerHoneycombInstrumentation.ts";
6
+ export { getTracer } from "./honeycomb/tracer.ts";
7
+ export {
8
+ endActiveSpan,
9
+ startActiveChildSpan,
10
+ startActiveSpan,
11
+ startChildSpan,
12
+ startSpan,
13
+ traceError,
14
+ type StartActiveChildSpanFactory,
15
+ type StartActiveChildSpanFactoryReturn,
16
+ type StartActiveSpanFactory,
17
+ type StartActiveSpanFactoryReturn,
18
+ type StartChildSpanFactory,
19
+ type StartSpanFactory,
20
+ type TraceErrorOptions
21
+ } from "./honeycomb/utils.ts";
22
+
@@ -5,21 +5,12 @@ import { useCanUpdateDeferredRegistrations } from "./useCanUpdateDeferredRegistr
5
5
  import { useRegisterDeferredRegistrations } from "./useRegisterDeferredRegistrations.ts";
6
6
  import { useUpdateDeferredRegistrations } from "./useUpdateDeferredRegistrations.ts";
7
7
 
8
- export interface DeferredRegistrationsErrorsObject {
9
- localModuleErrors: ModuleRegistrationError[];
10
- remoteModuleErrors: ModuleRegistrationError[];
11
- }
12
-
13
- export type DeferredRegistrationsErrorCallback = (errorsObject: DeferredRegistrationsErrorsObject) => void;
8
+ export type DeferredRegistrationsErrorCallback = (errors: ModuleRegistrationError[]) => void;
14
9
 
15
10
  export interface UseDeferredRegistrationsOptions {
16
11
  onError?: DeferredRegistrationsErrorCallback;
17
12
  }
18
13
 
19
- function hasError({ localModuleErrors, remoteModuleErrors }: DeferredRegistrationsErrorsObject) {
20
- return localModuleErrors.length > 0 || remoteModuleErrors.length > 0;
21
- }
22
-
23
14
  export function useDeferredRegistrations(data: unknown, { onError }: UseDeferredRegistrationsOptions = {}) {
24
15
  const runtime = useRuntime();
25
16
 
@@ -34,7 +25,7 @@ export function useDeferredRegistrations(data: unknown, { onError }: UseDeferred
34
25
  const register = async () => {
35
26
  const errors = await registerDeferredRegistrations(data, runtime);
36
27
 
37
- if (hasError(errors) && onError) {
28
+ if (errors.length > 0 && onError) {
38
29
  onError(errors);
39
30
  }
40
31
  };
@@ -48,7 +39,7 @@ export function useDeferredRegistrations(data: unknown, { onError }: UseDeferred
48
39
  const update = async () => {
49
40
  const errors = await updateDeferredRegistrations(data, runtime);
50
41
 
51
- if (hasError(errors) && onError) {
42
+ if (errors.length > 0 && onError) {
52
43
  onError(errors);
53
44
  }
54
45
  };
@@ -1,9 +1,8 @@
1
1
  import type { Runtime } from "@squide/core";
2
- import { registerDeferredRegistrations } from "@squide/module-federation";
3
2
  import { useCallback } from "react";
4
3
 
5
4
  export function useRegisterDeferredRegistrations() {
6
5
  return useCallback(<TData = unknown, TRuntime extends Runtime = Runtime>(data: TData, runtime: TRuntime) => {
7
- return registerDeferredRegistrations(data, runtime);
6
+ return runtime.moduleManager.registerDeferredRegistrations(data);
8
7
  }, []);
9
8
  }
@@ -1,28 +1,23 @@
1
- import { addLocalModuleRegistrationStatusChangedListener, getLocalModuleRegistrationStatus, removeLocalModuleRegistrationStatusChangedListener, useRuntime } from "@squide/core";
2
- import { addRemoteModuleRegistrationStatusChangedListener, areModulesReady, getRemoteModuleRegistrationStatus, removeRemoteModuleRegistrationStatusChangedListener } from "@squide/module-federation";
1
+ import { Runtime, useRuntime } from "@squide/core";
3
2
  import { useEffect, useSyncExternalStore } from "react";
4
3
 
5
- function subscribeToLocalModuleRegistrationStatusChanged(callback: () => void) {
6
- addLocalModuleRegistrationStatusChangedListener(callback);
4
+ function subscribeToModulesReady(runtime: Runtime) {
5
+ return (callback: () => void) => {
6
+ runtime.moduleManager.registerModulesReadyListener(callback);
7
7
 
8
- return () => removeLocalModuleRegistrationStatusChangedListener(callback);
9
- }
10
-
11
- function subscribeToRemoteModuleRegistrationStatusChanged(callback: () => void) {
12
- addRemoteModuleRegistrationStatusChangedListener(callback);
13
-
14
- return () => removeRemoteModuleRegistrationStatusChangedListener(callback);
8
+ return () => runtime.moduleManager.removeModulesReadyListener(callback);
9
+ };
15
10
  }
16
11
 
17
12
  export function useStrictRegistrationMode() {
18
13
  const runtime = useRuntime();
19
14
 
20
- const localModuleStatus = useSyncExternalStore(subscribeToLocalModuleRegistrationStatusChanged, getLocalModuleRegistrationStatus);
21
- const remoteModuleStatus = useSyncExternalStore(subscribeToRemoteModuleRegistrationStatusChanged, getRemoteModuleRegistrationStatus);
15
+ // This listener is only executed if the modules are ready.
16
+ const areModulesReady = useSyncExternalStore(subscribeToModulesReady(runtime), () => runtime.moduleManager.getAreModulesReady());
22
17
 
23
18
  useEffect(() => {
24
- if (areModulesReady(localModuleStatus, remoteModuleStatus)) {
19
+ if (areModulesReady) {
25
20
  runtime._validateRegistrations();
26
21
  }
27
- }, [runtime, localModuleStatus, remoteModuleStatus]);
22
+ }, [runtime, areModulesReady]);
28
23
  }
@@ -1,16 +1,22 @@
1
1
  import type { Runtime } from "@squide/core";
2
- import { updateDeferredRegistrations } from "@squide/module-federation";
3
2
  import { useCallback } from "react";
4
3
  import { useAppRouterDispatcher } from "./AppRouterContext.ts";
5
4
 
5
+ export const DeferredRegistrationsUpdateStartedEvent = "squide-deferred-registrations-update-started";
6
+ export const DeferredRegistrationsUpdateCompletedEvent = "squide-deferred-registrations-update-completed-started";
7
+
6
8
  export function useUpdateDeferredRegistrations() {
7
9
  const dispatch = useAppRouterDispatcher();
8
10
 
9
11
  return useCallback(async <TData = unknown, TRuntime extends Runtime = Runtime>(data: TData, runtime: TRuntime) => {
10
- const errors = await updateDeferredRegistrations(data, runtime);
12
+ runtime.eventBus.dispatch(DeferredRegistrationsUpdateStartedEvent);
13
+
14
+ const errors = await runtime.moduleManager.updateDeferredRegistrations(data);
11
15
 
12
16
  dispatch({ type: "deferred-registrations-updated" });
13
17
 
18
+ runtime.eventBus.dispatch(DeferredRegistrationsUpdateCompletedEvent);
19
+
14
20
  return errors;
15
21
  }, [dispatch]);
16
22
  }