@squide/firefly 16.2.1 → 17.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/AppRouter.js +0 -9
  3. package/dist/AppRouter.js.map +1 -1
  4. package/dist/AppRouterContext.js +0 -3
  5. package/dist/AppRouterContext.js.map +1 -1
  6. package/dist/AppRouterReducer.d.ts +17 -0
  7. package/dist/AppRouterReducer.js +0 -6
  8. package/dist/AppRouterReducer.js.map +1 -1
  9. package/dist/AppRouterStore.js +0 -2
  10. package/dist/AppRouterStore.js.map +1 -1
  11. package/dist/FireflyPlugin.js +0 -2
  12. package/dist/FireflyPlugin.js.map +1 -1
  13. package/dist/FireflyProvider.js +0 -3
  14. package/dist/FireflyProvider.js.map +1 -1
  15. package/dist/FireflyRuntime.js +0 -6
  16. package/dist/FireflyRuntime.js.map +1 -1
  17. package/dist/GlobalDataQueriesError.js +0 -2
  18. package/dist/GlobalDataQueriesError.js.map +1 -1
  19. package/dist/RootRoute.js +0 -6
  20. package/dist/RootRoute.js.map +1 -1
  21. package/dist/honeycomb/activeSpan.js +0 -4
  22. package/dist/honeycomb/activeSpan.js.map +1 -1
  23. package/dist/honeycomb/createTraceContextId.js +0 -2
  24. package/dist/honeycomb/createTraceContextId.js.map +1 -1
  25. package/dist/honeycomb/initializeHoneycomb.js +0 -2
  26. package/dist/honeycomb/initializeHoneycomb.js.map +1 -1
  27. package/dist/honeycomb/registerHoneycombInstrumentation.d.ts +2 -2
  28. package/dist/honeycomb/registerHoneycombInstrumentation.js +13 -26
  29. package/dist/honeycomb/registerHoneycombInstrumentation.js.map +1 -1
  30. package/dist/honeycomb/tracer.js +0 -2
  31. package/dist/honeycomb/tracer.js.map +1 -1
  32. package/dist/honeycomb/utils.js +0 -3
  33. package/dist/honeycomb/utils.js.map +1 -1
  34. package/dist/index.js +4 -11
  35. package/dist/index.js.map +1 -1
  36. package/dist/initializeFirefly.d.ts +5 -0
  37. package/dist/initializeFirefly.js +0 -8
  38. package/dist/initializeFirefly.js.map +1 -1
  39. package/dist/internal.js +5 -13
  40. package/dist/internal.js.map +1 -1
  41. package/dist/useAppRouterStore.js +0 -2
  42. package/dist/useAppRouterStore.js.map +1 -1
  43. package/dist/useCanFetchProtectedData.js +0 -2
  44. package/dist/useCanFetchProtectedData.js.map +1 -1
  45. package/dist/useCanFetchPublicData.js +0 -2
  46. package/dist/useCanFetchPublicData.js.map +1 -1
  47. package/dist/useCanRegisterDeferredRegistrations.js +0 -2
  48. package/dist/useCanRegisterDeferredRegistrations.js.map +1 -1
  49. package/dist/useCanUpdateDeferredRegistrations.js +0 -2
  50. package/dist/useCanUpdateDeferredRegistrations.js.map +1 -1
  51. package/dist/useDeferredRegistrations.js +0 -7
  52. package/dist/useDeferredRegistrations.js.map +1 -1
  53. package/dist/useExecuteOnce.js +0 -2
  54. package/dist/useExecuteOnce.js.map +1 -1
  55. package/dist/useIsActiveRouteProtected.js +0 -3
  56. package/dist/useIsActiveRouteProtected.js.map +1 -1
  57. package/dist/useIsBootstrapping.js +0 -2
  58. package/dist/useIsBootstrapping.js.map +1 -1
  59. package/dist/useNavigationItems.js +0 -3
  60. package/dist/useNavigationItems.js.map +1 -1
  61. package/dist/useProtectedDataHandler.js +0 -3
  62. package/dist/useProtectedDataHandler.js.map +1 -1
  63. package/dist/useProtectedDataQueries.d.ts +6 -0
  64. package/dist/useProtectedDataQueries.js +0 -8
  65. package/dist/useProtectedDataQueries.js.map +1 -1
  66. package/dist/usePublicDataHandler.js +0 -3
  67. package/dist/usePublicDataHandler.js.map +1 -1
  68. package/dist/usePublicDataQueries.d.ts +6 -0
  69. package/dist/usePublicDataQueries.js +0 -8
  70. package/dist/usePublicDataQueries.js.map +1 -1
  71. package/dist/useRegisterDeferredRegistrations.js +0 -3
  72. package/dist/useRegisterDeferredRegistrations.js.map +1 -1
  73. package/dist/useStrictRegistrationMode.js +0 -3
  74. package/dist/useStrictRegistrationMode.js.map +1 -1
  75. package/dist/useUpdateDeferredRegistrations.d.ts +6 -0
  76. package/dist/useUpdateDeferredRegistrations.js +0 -4
  77. package/dist/useUpdateDeferredRegistrations.js.map +1 -1
  78. package/package.json +24 -23
  79. package/src/AppRouterReducer.ts +18 -0
  80. package/src/honeycomb/registerHoneycombInstrumentation.ts +30 -42
  81. package/src/initializeFirefly.ts +6 -0
  82. package/src/useProtectedDataQueries.ts +7 -0
  83. package/src/usePublicDataQueries.ts +7 -0
  84. package/src/useUpdateDeferredRegistrations.ts +7 -0
@@ -2,25 +2,19 @@ import type { Span } from "@opentelemetry/api";
2
2
  import {
3
3
  type AddListenerOptions,
4
4
  type EventCallbackFunction,
5
- type EventName,
5
+ type EventMap,
6
+ type EventMapKey,
6
7
  LocalModuleDeferredRegistrationFailedEvent,
7
8
  LocalModuleDeferredRegistrationUpdateFailedEvent,
8
9
  LocalModuleRegistrationFailedEvent,
9
10
  LocalModulesDeferredRegistrationCompletedEvent,
10
- type LocalModulesDeferredRegistrationCompletedEventPayload,
11
11
  LocalModulesDeferredRegistrationStartedEvent,
12
- type LocalModulesDeferredRegistrationStartedEventPayload,
13
12
  LocalModulesDeferredRegistrationsUpdateCompletedEvent,
14
- type LocalModulesDeferredRegistrationsUpdateCompletedEventPayload,
15
13
  LocalModulesDeferredRegistrationsUpdateStartedEvent,
16
- type LocalModulesDeferredRegistrationsUpdateStartedEventPayload,
17
14
  LocalModulesRegistrationCompletedEvent,
18
- type LocalModulesRegistrationCompletedEventPayload,
19
- LocalModulesRegistrationStartedEvent,
20
- type LocalModulesRegistrationStartedEventPayload,
21
- type ModuleRegistrationError
15
+ LocalModulesRegistrationStartedEvent
22
16
  } from "@squide/core";
23
- import { ApplicationBoostrappedEvent, type AppRouterWaitState, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from "../AppRouterReducer.ts";
17
+ import { ApplicationBoostrappedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from "../AppRouterReducer.ts";
24
18
  import { FireflyPlugin } from "../FireflyPlugin.ts";
25
19
  import type { FireflyRuntime } from "../FireflyRuntime.tsx";
26
20
  import { ApplicationBootstrappingStartedEvent } from "../initializeFirefly.ts";
@@ -40,13 +34,13 @@ export interface AddProtectedListenerOptions extends AddListenerOptions {
40
34
  onError?: (error: unknown) => void;
41
35
  }
42
36
 
43
- export function addProtectedListener(runtime: FireflyRuntime, eventName: EventName, callback: EventCallbackFunction, options?: AddProtectedListenerOptions) {
44
- const protectedCallback = (...args: unknown[]) => {
37
+ export function addProtectedListener<K extends EventMapKey>(runtime: FireflyRuntime, eventName: K, callback: EventCallbackFunction<EventMap[K]>, options?: AddProtectedListenerOptions) {
38
+ const protectedCallback: EventCallbackFunction<EventMap[K]> = data => {
45
39
  try {
46
- callback(...args);
40
+ callback(data);
47
41
  } catch (error: unknown) {
48
42
  runtime.logger
49
- .withText(`[squide] An unmanaged error occurred while handling event "${eventName.toString()}" for Honeycomb instrumentation:`)
43
+ .withText(`[squide] An unmanaged error occurred while handling event "${String(eventName)}" for Honeycomb instrumentation:`)
50
44
  .withError(error as Error)
51
45
  .error();
52
46
  }
@@ -89,7 +83,7 @@ export function reduceDataFetchEvents(
89
83
  onPublicDataReady();
90
84
 
91
85
  if (dataFetchState === "fetching-data") {
92
- if (payload && !(payload as AppRouterWaitState).waitForProtectedData) {
86
+ if (payload && !payload.waitForProtectedData) {
93
87
  dataFetchState = "data-ready";
94
88
  onDataReady();
95
89
  } else {
@@ -120,7 +114,7 @@ export function reduceDataFetchEvents(
120
114
  onProtectedDataReady();
121
115
 
122
116
  if (dataFetchState === "fetching-data") {
123
- if (payload && !(payload as AppRouterWaitState).waitForPublicData) {
117
+ if (payload && !payload.waitForPublicData) {
124
118
  dataFetchState = "data-ready";
125
119
  onDataReady();
126
120
  } else {
@@ -135,11 +129,11 @@ export function reduceDataFetchEvents(
135
129
  onError: onUnmanagedError
136
130
  });
137
131
 
138
- const handleDataFetchFailed = (payload: unknown) => {
132
+ const handleDataFetchFailed: EventCallbackFunction<Error[]> = payload => {
139
133
  if (dataFetchState !== "data-fetch-failed") {
140
134
  dataFetchState = "data-fetch-failed";
141
135
 
142
- onDataFetchFailed(payload as Error[]);
136
+ onDataFetchFailed(payload ?? []);
143
137
  }
144
138
  };
145
139
 
@@ -224,9 +218,9 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
224
218
  onError: handleUnmanagedError
225
219
  });
226
220
 
227
- addProtectedListener(runtime, LocalModulesRegistrationStartedEvent, (payload: unknown) => {
221
+ addProtectedListener(runtime, LocalModulesRegistrationStartedEvent, payload => {
228
222
  const attributes = {
229
- "app.squide.module_count": (payload as LocalModulesRegistrationStartedEventPayload).moduleCount
223
+ "app.squide.module_count": payload?.moduleCount
230
224
  };
231
225
 
232
226
  if (bootstrappingSpan) {
@@ -241,10 +235,10 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
241
235
  onError: handleUnmanagedError
242
236
  });
243
237
 
244
- addProtectedListener(runtime, LocalModulesRegistrationCompletedEvent, (payload: unknown) => {
238
+ addProtectedListener(runtime, LocalModulesRegistrationCompletedEvent, payload => {
245
239
  if (bootstrappingSpan) {
246
240
  bootstrappingSpan.addEvent("local-module-registration-completed", {
247
- "app.squide.module_count": (payload as LocalModulesRegistrationCompletedEventPayload).moduleCount
241
+ "app.squide.module_count": payload?.moduleCount
248
242
  });
249
243
  }
250
244
 
@@ -257,19 +251,17 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
257
251
  });
258
252
 
259
253
  // Can occur multiple times.
260
- addProtectedListener(runtime, LocalModuleRegistrationFailedEvent, (payload: unknown) => {
261
- const registrationError = payload as ModuleRegistrationError;
262
-
254
+ addProtectedListener(runtime, LocalModuleRegistrationFailedEvent, payload => {
263
255
  if (localModuleRegistrationSpan) {
264
- traceError(localModuleRegistrationSpan, registrationError);
256
+ traceError(localModuleRegistrationSpan, payload as Error);
265
257
  }
266
258
  }, {
267
259
  onError: handleUnmanagedError
268
260
  });
269
261
 
270
- addProtectedListener(runtime, LocalModulesDeferredRegistrationStartedEvent, (payload: unknown) => {
262
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationStartedEvent, payload => {
271
263
  const attributes = {
272
- "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationStartedEventPayload).registrationCount
264
+ "app.squide.registration_count": payload?.registrationCount
273
265
  };
274
266
 
275
267
  if (bootstrappingSpan) {
@@ -284,10 +276,10 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
284
276
  onError: handleUnmanagedError
285
277
  });
286
278
 
287
- addProtectedListener(runtime, LocalModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {
279
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationCompletedEvent, payload => {
288
280
  if (bootstrappingSpan) {
289
281
  bootstrappingSpan.addEvent("local-module-deferred-registration-completed", {
290
- "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationCompletedEventPayload).registrationCount
282
+ "app.squide.registration_count": payload?.registrationCount
291
283
  });
292
284
  }
293
285
 
@@ -300,11 +292,9 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
300
292
  });
301
293
 
302
294
  // Can occur multiple times.
303
- addProtectedListener(runtime, LocalModuleDeferredRegistrationFailedEvent, (payload: unknown) => {
304
- const registrationError = payload as ModuleRegistrationError;
305
-
295
+ addProtectedListener(runtime, LocalModuleDeferredRegistrationFailedEvent, payload => {
306
296
  if (localModuleDeferredRegistrationSpan) {
307
- traceError(localModuleRegistrationSpan, registrationError);
297
+ traceError(localModuleRegistrationSpan, payload as Error);
308
298
  }
309
299
  }, {
310
300
  onError: handleUnmanagedError
@@ -416,9 +406,9 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
416
406
  });
417
407
 
418
408
  // Can occur multiple times.
419
- addProtectedListener(runtime, LocalModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {
409
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationsUpdateStartedEvent, payload => {
420
410
  const attributes = {
421
- "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount
411
+ "app.squide.registration_count": payload?.registrationCount
422
412
  };
423
413
 
424
414
  if (deferredRegistrationsUpdateSpan) {
@@ -443,10 +433,10 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
443
433
  });
444
434
 
445
435
  // Can occur multiple times.
446
- addProtectedListener(runtime, LocalModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {
436
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationsUpdateCompletedEvent, payload => {
447
437
  if (deferredRegistrationsUpdateSpan) {
448
438
  deferredRegistrationsUpdateSpan.addEvent("local-module-deferred-registrations-update-completed", {
449
- "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount
439
+ "app.squide.registration_count": payload?.registrationCount
450
440
  });
451
441
  }
452
442
 
@@ -458,11 +448,9 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
458
448
  });
459
449
 
460
450
  // Can occur multiple times.
461
- addProtectedListener(runtime, LocalModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {
462
- const registrationError = payload as ModuleRegistrationError;
463
-
451
+ addProtectedListener(runtime, LocalModuleDeferredRegistrationUpdateFailedEvent, payload => {
464
452
  if (localModuleDeferredRegistrationsUpdateSpan) {
465
- traceError(localModuleDeferredRegistrationsUpdateSpan.instance, registrationError);
453
+ traceError(localModuleDeferredRegistrationsUpdateSpan.instance, payload as Error);
466
454
  }
467
455
  }, {
468
456
  onError: handleUnmanagedError
@@ -11,6 +11,12 @@ import { initializeHoneycomb } from "./honeycomb/initializeHoneycomb.ts";
11
11
 
12
12
  export const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
13
13
 
14
+ declare module "@squide/core" {
15
+ interface EventMap {
16
+ "squide-app-bootstrapping-started": void;
17
+ }
18
+ }
19
+
14
20
  export type OnInitializationErrorFunction = (error: unknown) => void;
15
21
 
16
22
  export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
@@ -9,6 +9,13 @@ import { useExecuteOnce } from "./useExecuteOnce.ts";
9
9
  export const ProtectedDataFetchStartedEvent = "squide-protected-data-fetch-started";
10
10
  export const ProtectedDataFetchFailedEvent = "squide-protected-data-fetch-failed";
11
11
 
12
+ declare module "@squide/core" {
13
+ interface EventMap {
14
+ "squide-protected-data-fetch-started": void;
15
+ "squide-protected-data-fetch-failed": Error[];
16
+ }
17
+ }
18
+
12
19
  export type IsUnauthorizedErrorCallback = (error: unknown) => boolean;
13
20
 
14
21
  // This converts an array of UseQueryResult to an array of the data type of each query result.
@@ -9,6 +9,13 @@ import { useExecuteOnce } from "./useExecuteOnce.ts";
9
9
  export const PublicDataFetchStartedEvent = "squide-public-data-fetch-started";
10
10
  export const PublicDataFetchFailedEvent = "squide-public-data-fetch-failed";
11
11
 
12
+ declare module "@squide/core" {
13
+ interface EventMap {
14
+ "squide-public-data-fetch-started": void;
15
+ "squide-public-data-fetch-failed": Error[];
16
+ }
17
+ }
18
+
12
19
  // This converts an array of UseQueryResult to an array of the data type of each query result.
13
20
  // For more information, view: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html#mapped-types-on-tuples-and-arrays.
14
21
  type MapUseQueryResultToData<T> = { [K in keyof T]: T[K] extends UseQueryResult<infer U> ? U : never };
@@ -5,6 +5,13 @@ import { useAppRouterDispatcher } from "./AppRouterContext.ts";
5
5
  export const DeferredRegistrationsUpdateStartedEvent = "squide-deferred-registrations-update-started";
6
6
  export const DeferredRegistrationsUpdateCompletedEvent = "squide-deferred-registrations-update-completed-started";
7
7
 
8
+ declare module "@squide/core" {
9
+ interface EventMap {
10
+ "squide-deferred-registrations-update-started": void;
11
+ "squide-deferred-registrations-update-completed-started": void;
12
+ }
13
+ }
14
+
8
15
  export function useUpdateDeferredRegistrations() {
9
16
  const runtime = useRuntime();
10
17
  const dispatch = useAppRouterDispatcher();