@squide/firefly 13.3.0 → 14.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 +64 -0
- package/dist/AppRouterReducer.d.ts +4 -2
- package/dist/AppRouterReducer.js +63 -45
- package/dist/AppRouterReducer.js.map +1 -1
- package/dist/AppRouterStore.d.ts +3 -3
- package/dist/AppRouterStore.js.map +1 -1
- package/dist/FireflyRuntime.d.ts +22 -5
- package/dist/FireflyRuntime.js +34 -11
- package/dist/FireflyRuntime.js.map +1 -1
- package/dist/honeycomb/activeSpan.d.ts +2 -2
- package/dist/honeycomb/activeSpan.js.map +1 -1
- package/dist/honeycomb/registerHoneycombInstrumentation.js +20 -5
- package/dist/honeycomb/registerHoneycombInstrumentation.js.map +1 -1
- package/package.json +17 -17
- package/src/AppRouterReducer.ts +52 -53
- package/src/AppRouterStore.ts +4 -4
- package/src/FireflyRuntime.tsx +50 -12
- package/src/honeycomb/activeSpan.ts +2 -2
- package/src/honeycomb/registerHoneycombInstrumentation.ts +22 -6
package/src/FireflyRuntime.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { RegisterRouteOptions, RuntimeOptions } from "@squide/core";
|
|
1
|
+
import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from "@squide/core";
|
|
2
2
|
import { MswPlugin, MswPluginName } from "@squide/msw";
|
|
3
|
-
import { ReactRouterRuntime, type Route } from "@squide/react-router";
|
|
3
|
+
import { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from "@squide/react-router";
|
|
4
|
+
import type { Logger } from "@workleap/logging";
|
|
4
5
|
import type { RequestHandler } from "msw";
|
|
5
6
|
import { getAreModulesRegistered } from "./AppRouterReducer.ts";
|
|
6
7
|
import { type AppRouterStore, createAppRouterStore } from "./AppRouterStore.ts";
|
|
@@ -9,9 +10,18 @@ export interface FireflyRuntimeOptions extends RuntimeOptions {
|
|
|
9
10
|
useMsw?: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
export interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}
|
|
14
|
+
|
|
15
|
+
export interface IFireflyRuntime extends IReactRouterRuntime {
|
|
16
|
+
registerRequestHandlers: (handlers: RequestHandler[]) => void;
|
|
17
|
+
get requestHandlers(): RequestHandler[];
|
|
18
|
+
get appRouterStore(): AppRouterStore;
|
|
19
|
+
get isMswEnabled(): boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class FireflyRuntime extends ReactRouterRuntime implements IFireflyRuntime {
|
|
23
|
+
protected _appRouterStore: AppRouterStore;
|
|
24
|
+
protected _useMsw: boolean;
|
|
15
25
|
|
|
16
26
|
constructor({ plugins, useMsw, ...options }: FireflyRuntimeOptions = {}) {
|
|
17
27
|
if (useMsw) {
|
|
@@ -23,20 +33,21 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
23
33
|
...options
|
|
24
34
|
});
|
|
25
35
|
|
|
26
|
-
this
|
|
36
|
+
this._useMsw = true;
|
|
27
37
|
} else {
|
|
28
38
|
super({
|
|
29
39
|
plugins,
|
|
30
40
|
...options
|
|
31
41
|
});
|
|
32
42
|
|
|
33
|
-
this
|
|
43
|
+
this._useMsw = false;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
|
-
this
|
|
46
|
+
this._appRouterStore = createAppRouterStore(this._logger);
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
registerRequestHandlers(handlers: RequestHandler[]) {
|
|
49
|
+
registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {
|
|
50
|
+
const logger = this._getLogger(options);
|
|
40
51
|
const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;
|
|
41
52
|
|
|
42
53
|
if (!mswPlugin) {
|
|
@@ -47,7 +58,9 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
47
58
|
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.");
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
mswPlugin.registerRequestHandlers(handlers
|
|
61
|
+
mswPlugin.registerRequestHandlers(handlers, {
|
|
62
|
+
logger
|
|
63
|
+
});
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
// Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
|
|
@@ -70,10 +83,35 @@ export class FireflyRuntime extends ReactRouterRuntime {
|
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
get appRouterStore() {
|
|
73
|
-
return this
|
|
86
|
+
return this._appRouterStore;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get isMswEnabled() {
|
|
90
|
+
return this._useMsw;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
startScope(logger: Logger): FireflyRuntime {
|
|
94
|
+
return (new FireflyRuntimeScope(this, logger) as unknown) as FireflyRuntime;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {
|
|
99
|
+
registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {
|
|
100
|
+
this._runtime.registerRequestHandlers(handlers, {
|
|
101
|
+
...options,
|
|
102
|
+
logger: this._getLogger(options)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get requestHandlers(): RequestHandler[] {
|
|
107
|
+
return this._runtime.requestHandlers;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get appRouterStore() {
|
|
111
|
+
return this._runtime.appRouterStore;
|
|
74
112
|
}
|
|
75
113
|
|
|
76
114
|
get isMswEnabled() {
|
|
77
|
-
return this
|
|
115
|
+
return this._runtime.isMswEnabled;
|
|
78
116
|
}
|
|
79
117
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Span } from "@opentelemetry/api";
|
|
2
2
|
import { isPlainObject } from "@squide/core";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Logger } from "@workleap/logging";
|
|
4
4
|
import { v4 as uuidv4 } from "uuid";
|
|
5
5
|
import { createTraceContextId } from "./createTraceContextId.ts";
|
|
6
6
|
|
|
@@ -97,7 +97,7 @@ export function popActiveSpan(span: ActiveSpan) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export function createOverrideFetchRequestSpanWithActiveSpanContext(logger:
|
|
100
|
+
export function createOverrideFetchRequestSpanWithActiveSpanContext(logger: Logger) {
|
|
101
101
|
return (span: Span, request: Request | RequestInit) => {
|
|
102
102
|
const activeSpan = getActiveSpan();
|
|
103
103
|
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
RemoteModulesRegistrationStartedEvent,
|
|
38
38
|
type RemoteModulesRegistrationStartedEventPayload
|
|
39
39
|
} from "@squide/module-federation";
|
|
40
|
-
import { ApplicationBoostrappedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from "../AppRouterReducer.ts";
|
|
40
|
+
import { ApplicationBoostrappedEvent, type AppRouterWaitState, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, PublicDataReadyEvent } from "../AppRouterReducer.ts";
|
|
41
41
|
import type { FireflyRuntime } from "../FireflyRuntime.tsx";
|
|
42
42
|
import { ApplicationBootstrappingStartedEvent } from "../initializeFirefly.ts";
|
|
43
43
|
import { ProtectedDataFetchFailedEvent, ProtectedDataFetchStartedEvent } from "../useProtectedDataQueries.ts";
|
|
@@ -72,11 +72,16 @@ export function reduceDataFetchEvents(
|
|
|
72
72
|
onPublicDataFetchStarted();
|
|
73
73
|
}, { once: true });
|
|
74
74
|
|
|
75
|
-
runtime.eventBus.addListener(PublicDataReadyEvent,
|
|
75
|
+
runtime.eventBus.addListener(PublicDataReadyEvent, payload => {
|
|
76
76
|
onPublicDataReady();
|
|
77
77
|
|
|
78
78
|
if (dataFetchState === "fetching-data") {
|
|
79
|
-
|
|
79
|
+
if (payload && !(payload as AppRouterWaitState).waitForProtectedData) {
|
|
80
|
+
dataFetchState = "data-ready";
|
|
81
|
+
onDataReady();
|
|
82
|
+
} else {
|
|
83
|
+
dataFetchState = "public-data-ready";
|
|
84
|
+
}
|
|
80
85
|
} else if (dataFetchState === "protected-data-ready") {
|
|
81
86
|
dataFetchState = "data-ready";
|
|
82
87
|
onDataReady();
|
|
@@ -92,11 +97,16 @@ export function reduceDataFetchEvents(
|
|
|
92
97
|
onProtectedDataFetchStarted();
|
|
93
98
|
}, { once: true });
|
|
94
99
|
|
|
95
|
-
runtime.eventBus.addListener(ProtectedDataReadyEvent,
|
|
100
|
+
runtime.eventBus.addListener(ProtectedDataReadyEvent, payload => {
|
|
96
101
|
onProtectedDataReady();
|
|
97
102
|
|
|
98
103
|
if (dataFetchState === "fetching-data") {
|
|
99
|
-
|
|
104
|
+
if (payload && !(payload as AppRouterWaitState).waitForPublicData) {
|
|
105
|
+
dataFetchState = "data-ready";
|
|
106
|
+
onDataReady();
|
|
107
|
+
} else {
|
|
108
|
+
dataFetchState = "protected-data-ready";
|
|
109
|
+
}
|
|
100
110
|
} else if (dataFetchState === "public-data-ready") {
|
|
101
111
|
dataFetchState = "data-ready";
|
|
102
112
|
onDataReady();
|
|
@@ -330,7 +340,13 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
|
|
|
330
340
|
traceError(dataFetchSpan.instance, x);
|
|
331
341
|
});
|
|
332
342
|
|
|
333
|
-
dataFetchSpan
|
|
343
|
+
endActiveSpan(dataFetchSpan);
|
|
344
|
+
|
|
345
|
+
// Global data fetch errors are unmanaged, which mean the host application bootstrapping flow
|
|
346
|
+
// will be aborted and a react-router error boundary will be rendered.
|
|
347
|
+
if (bootstrappingSpan) {
|
|
348
|
+
bootstrappingSpan.end();
|
|
349
|
+
}
|
|
334
350
|
}
|
|
335
351
|
};
|
|
336
352
|
|