@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
package/src/initializeFirefly.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isFunction,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
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
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
.
|
|
54
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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(
|
|
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
|
-
}
|
package/src/internal.ts
ADDED
|
@@ -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
|
|
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 (
|
|
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 (
|
|
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
|
|
6
|
+
return runtime.moduleManager.registerDeferredRegistrations(data);
|
|
8
7
|
}, []);
|
|
9
8
|
}
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import {
|
|
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
|
|
6
|
-
|
|
4
|
+
function subscribeToModulesReady(runtime: Runtime) {
|
|
5
|
+
return (callback: () => void) => {
|
|
6
|
+
runtime.moduleManager.registerModulesReadyListener(callback);
|
|
7
7
|
|
|
8
|
-
|
|
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
|
-
|
|
21
|
-
const
|
|
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
|
|
19
|
+
if (areModulesReady) {
|
|
25
20
|
runtime._validateRegistrations();
|
|
26
21
|
}
|
|
27
|
-
}, [runtime,
|
|
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
|
-
|
|
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
|
}
|