@squide/firefly 15.0.5 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -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 +9 -7
- package/dist/FireflyRuntime.js +20 -28
- 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 +2 -3
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/initializeFirefly.d.ts +6 -6
- package/dist/initializeFirefly.js +26 -35
- 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 +27 -23
- package/src/AppRouterReducer.ts +51 -89
- package/src/FireflyPlugin.ts +11 -0
- package/src/FireflyRuntime.tsx +31 -34
- package/src/honeycomb/registerHoneycombInstrumentation.ts +30 -169
- package/src/index.ts +14 -3
- package/src/initializeFirefly.ts +51 -48
- 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,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.0",
|
|
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,42 @@
|
|
|
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"
|
|
36
41
|
},
|
|
37
42
|
"dependencies": {
|
|
38
|
-
"@workleap-telemetry/core": "^1.0.
|
|
39
|
-
"@workleap/logging": "^1.3.
|
|
43
|
+
"@workleap-telemetry/core": "^1.0.4",
|
|
44
|
+
"@workleap/logging": "^1.3.2",
|
|
40
45
|
"uuid": "^13.0.0",
|
|
41
|
-
"@squide/core": "6.1.
|
|
42
|
-
"@squide/
|
|
43
|
-
"@squide/
|
|
44
|
-
"@squide/react-router": "8.1.3"
|
|
46
|
+
"@squide/core": "6.1.4",
|
|
47
|
+
"@squide/msw": "4.0.5",
|
|
48
|
+
"@squide/react-router": "8.1.4"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
47
|
-
"@eslint/js": "9.
|
|
48
|
-
"@rsbuild/core": "1.
|
|
49
|
-
"@rslib/core": "0.
|
|
51
|
+
"@eslint/js": "9.39.1",
|
|
52
|
+
"@rsbuild/core": "1.6.7",
|
|
53
|
+
"@rslib/core": "0.18.0",
|
|
50
54
|
"@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": "
|
|
55
|
+
"@types/react": "19.2.6",
|
|
56
|
+
"@types/react-dom": "19.2.3",
|
|
57
|
+
"@typescript-eslint/parser": "8.47.0",
|
|
58
|
+
"@vitejs/plugin-react": "5.1.1",
|
|
59
|
+
"@workleap/eslint-configs": "1.1.5",
|
|
56
60
|
"@workleap/rslib-configs": "1.1.3",
|
|
57
61
|
"@workleap/typescript-configs": "3.0.7",
|
|
58
|
-
"eslint": "9.
|
|
59
|
-
"happy-dom": "20.0.
|
|
62
|
+
"eslint": "9.39.1",
|
|
63
|
+
"happy-dom": "20.0.10",
|
|
60
64
|
"typescript": "5.9.3",
|
|
61
|
-
"typescript-eslint": "8.
|
|
62
|
-
"vitest": "4.0.
|
|
65
|
+
"typescript-eslint": "8.47.0",
|
|
66
|
+
"vitest": "4.0.10"
|
|
63
67
|
},
|
|
64
68
|
"sideEffects": false,
|
|
65
69
|
"scripts": {
|
|
66
70
|
"build": "rslib build --config ./rslib.build.ts",
|
|
67
|
-
"eslint": "eslint . --max-warnings
|
|
71
|
+
"eslint": "eslint . --max-warnings=0 --cache --cache-location node_modules/.cache/eslint",
|
|
68
72
|
"typecheck": "tsc",
|
|
69
73
|
"test": "vitest --config vitest.config.ts --no-watch"
|
|
70
74
|
}
|
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
|
+
}
|
package/src/FireflyRuntime.tsx
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from "@squide/core";
|
|
2
|
-
import { MswPlugin, MswPluginName } from "@squide/msw";
|
|
2
|
+
import { MswPlugin, MswPluginName, MswState } from "@squide/msw";
|
|
3
3
|
import { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from "@squide/react-router";
|
|
4
4
|
import type { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
|
|
5
5
|
import type { Logger } from "@workleap/logging";
|
|
6
6
|
import type { RequestHandler } from "msw";
|
|
7
|
-
import { getAreModulesRegistered } from "./AppRouterReducer.ts";
|
|
8
7
|
import { type AppRouterStore, createAppRouterStore } from "./AppRouterStore.ts";
|
|
9
8
|
|
|
10
|
-
export interface FireflyRuntimeOptions extends RuntimeOptions {
|
|
11
|
-
useMsw?: boolean;
|
|
9
|
+
export interface FireflyRuntimeOptions<TRuntime extends FireflyRuntime = FireflyRuntime> extends RuntimeOptions<TRuntime> {
|
|
12
10
|
honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}
|
|
16
14
|
|
|
17
15
|
export interface IFireflyRuntime extends IReactRouterRuntime {
|
|
16
|
+
getMswState(): MswState;
|
|
18
17
|
registerRequestHandlers: (handlers: RequestHandler[]) => void;
|
|
19
18
|
get requestHandlers(): RequestHandler[];
|
|
20
19
|
get appRouterStore(): AppRouterStore;
|
|
@@ -22,35 +21,28 @@ export interface IFireflyRuntime extends IReactRouterRuntime {
|
|
|
22
21
|
get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
export class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends ReactRouterRuntime<TRuntime> implements IFireflyRuntime {
|
|
26
26
|
protected _appRouterStore: AppRouterStore;
|
|
27
|
-
protected _useMsw: boolean;
|
|
28
27
|
protected _honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;
|
|
29
28
|
|
|
30
|
-
constructor({
|
|
31
|
-
|
|
32
|
-
super({
|
|
33
|
-
plugins: [
|
|
34
|
-
...(plugins ?? []),
|
|
35
|
-
runtime => new MswPlugin(runtime)
|
|
36
|
-
],
|
|
37
|
-
...options
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
this._useMsw = true;
|
|
41
|
-
} else {
|
|
42
|
-
super({
|
|
43
|
-
plugins,
|
|
44
|
-
...options
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
this._useMsw = false;
|
|
48
|
-
}
|
|
29
|
+
constructor({ honeycombInstrumentationClient, ...options }: FireflyRuntimeOptions = {}) {
|
|
30
|
+
super(options);
|
|
49
31
|
|
|
50
32
|
this._appRouterStore = createAppRouterStore(this._logger);
|
|
51
33
|
this._honeycombInstrumentationClient = honeycombInstrumentationClient;
|
|
52
34
|
}
|
|
53
35
|
|
|
36
|
+
getMswState() {
|
|
37
|
+
const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;
|
|
38
|
+
|
|
39
|
+
if (!mswPlugin) {
|
|
40
|
+
throw new Error("[squide] Cannot register the provided MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \"useMsw\" option?");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return mswPlugin.mswState;
|
|
44
|
+
}
|
|
45
|
+
|
|
54
46
|
registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {
|
|
55
47
|
const logger = this._getLogger(options);
|
|
56
48
|
const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;
|
|
@@ -59,7 +51,7 @@ export class FireflyRuntime extends ReactRouterRuntime implements IFireflyRuntim
|
|
|
59
51
|
throw new Error("[squide] Cannot register the provided MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \"useMsw\" option?");
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
if (getAreModulesRegistered()) {
|
|
54
|
+
if (this.moduleManager.getAreModulesRegistered()) {
|
|
63
55
|
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.");
|
|
64
56
|
}
|
|
65
57
|
|
|
@@ -80,7 +72,7 @@ export class FireflyRuntime extends ReactRouterRuntime implements IFireflyRuntim
|
|
|
80
72
|
}
|
|
81
73
|
|
|
82
74
|
registerRoute(route: Route, options: RegisterRouteOptions = {}) {
|
|
83
|
-
if (getAreModulesRegistered()) {
|
|
75
|
+
if (this.moduleManager.getAreModulesRegistered()) {
|
|
84
76
|
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.");
|
|
85
77
|
}
|
|
86
78
|
|
|
@@ -92,19 +84,23 @@ export class FireflyRuntime extends ReactRouterRuntime implements IFireflyRuntim
|
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
get isMswEnabled() {
|
|
95
|
-
return this.
|
|
87
|
+
return this._plugins.some(x => x.name === MswPluginName);
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
get honeycombInstrumentationClient() {
|
|
99
91
|
return this._honeycombInstrumentationClient;
|
|
100
92
|
}
|
|
101
93
|
|
|
102
|
-
startScope(logger: Logger):
|
|
103
|
-
return (new FireflyRuntimeScope(this, logger) as unknown) as
|
|
94
|
+
startScope(logger: Logger): TRuntime {
|
|
95
|
+
return (new FireflyRuntimeScope(this, logger) as unknown) as TRuntime;
|
|
104
96
|
}
|
|
105
97
|
}
|
|
106
98
|
|
|
107
99
|
export class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {
|
|
100
|
+
getMswState() {
|
|
101
|
+
return this._runtime.getMswState();
|
|
102
|
+
}
|
|
103
|
+
|
|
108
104
|
registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {
|
|
109
105
|
this._runtime.registerRequestHandlers(handlers, {
|
|
110
106
|
...options,
|
|
@@ -112,19 +108,20 @@ export class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntim
|
|
|
112
108
|
});
|
|
113
109
|
}
|
|
114
110
|
|
|
111
|
+
// Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
|
|
115
112
|
get requestHandlers(): RequestHandler[] {
|
|
116
113
|
return this._runtime.requestHandlers;
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
get appRouterStore() {
|
|
120
|
-
|
|
116
|
+
get appRouterStore(): AppRouterStore {
|
|
117
|
+
throw new Error("[squide] Cannot retrieve the app router store from a runtime scope instance.");
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
get isMswEnabled() {
|
|
124
121
|
return this._runtime.isMswEnabled;
|
|
125
122
|
}
|
|
126
123
|
|
|
127
|
-
get honeycombInstrumentationClient() {
|
|
128
|
-
|
|
124
|
+
get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient {
|
|
125
|
+
throw new Error("[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.");
|
|
129
126
|
}
|
|
130
127
|
}
|