@squide/firefly 16.0.0 → 16.0.2

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @squide/firefly
2
2
 
3
+ ## 16.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#345](https://github.com/workleap/wl-squide/pull/345) [`d05a890`](https://github.com/workleap/wl-squide/commit/d05a890517a1a9d9a0b4946690b36c14ea07aa49) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added a `strictMode` prop to the `AppRouter` component.
8
+
9
+ ## 16.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#342](https://github.com/workleap/wl-squide/pull/342) [`3be4070`](https://github.com/workleap/wl-squide/commit/3be4070d2d647804903b5cc01113e20d5d71cb11) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Minor fine tuning following v16 release.
14
+
15
+ - Updated dependencies [[`3be4070`](https://github.com/workleap/wl-squide/commit/3be4070d2d647804903b5cc01113e20d5d71cb11)]:
16
+ - @squide/env-vars@1.4.8
17
+ - @squide/core@6.1.5
18
+ - @squide/msw@4.0.6
19
+ - @squide/react-router@8.1.5
20
+
3
21
  ## 16.0.0
4
22
 
5
23
  ### Major Changes
@@ -15,6 +15,7 @@ export declare function useCanRenderRouter({ areModulesRegistered, areModulesRea
15
15
  export interface AppRouterProps {
16
16
  waitForPublicData?: boolean;
17
17
  waitForProtectedData?: boolean;
18
+ strictMode?: boolean;
18
19
  children: RenderRouterProviderFunction;
19
20
  }
20
21
  export declare function AppRouter(props: AppRouterProps): import("react/jsx-runtime").JSX.Element;
package/dist/AppRouter.js CHANGED
@@ -37,7 +37,7 @@ function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesR
37
37
  // depends on the protected data.
38
38
  areModulesRegistered || areModulesReadyValue);
39
39
  }
40
- function useRenderRouterProvider(state, renderRouterProvider) {
40
+ function useRenderRouterProvider(state, renderRouterProvider, strictMode) {
41
41
  const routes = useRoutes();
42
42
  // The value is computed outside of the router provider memo to prevent
43
43
  // rendering a new router provider everytime the app router state change.
@@ -45,7 +45,9 @@ function useRenderRouterProvider(state, renderRouterProvider) {
45
45
  return useMemo(()=>{
46
46
  if (canRenderRouter) {
47
47
  return renderRouterProvider({
48
- rootRoute: /*#__PURE__*/ jsx(RootRoute, {}),
48
+ rootRoute: /*#__PURE__*/ jsx(RootRoute, {
49
+ strictMode: strictMode
50
+ }),
49
51
  registeredRoutes: routes,
50
52
  routerProviderProps: {}
51
53
  });
@@ -54,21 +56,24 @@ function useRenderRouterProvider(state, renderRouterProvider) {
54
56
  }, [
55
57
  canRenderRouter,
56
58
  routes,
57
- renderRouterProvider
59
+ renderRouterProvider,
60
+ strictMode
58
61
  ]);
59
62
  }
60
63
  function AppRouter(props) {
61
- const { waitForPublicData = false, waitForProtectedData = false, children: renderRouterProvider } = props;
64
+ const { waitForPublicData = false, waitForProtectedData = false, strictMode = true, children: renderRouterProvider } = props;
62
65
  const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);
63
66
  const logger = useLogger();
64
- useStrictRegistrationMode();
67
+ useStrictRegistrationMode({
68
+ isEnabled: strictMode
69
+ });
65
70
  useEffect(()=>{
66
71
  logger.withText("[squide] AppRouter state updated:").withObject(state).debug();
67
72
  }, [
68
73
  state,
69
74
  logger
70
75
  ]);
71
- const routerProvider = useRenderRouterProvider(state, renderRouterProvider);
76
+ const routerProvider = useRenderRouterProvider(state, renderRouterProvider, strictMode);
72
77
  return /*#__PURE__*/ jsx(AppRouterDispatcherContext.Provider, {
73
78
  value: dispatch,
74
79
  children: /*#__PURE__*/ jsx(AppRouterStateContext.Provider, {
@@ -1 +1 @@
1
- {"version":3,"file":"AppRouter.js","sources":["../src/AppRouter.tsx"],"sourcesContent":["import { useLogger } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { RootRoute } from \"./RootRoute.tsx\";\nimport { useStrictRegistrationMode } from \"./useStrictRegistrationMode.ts\";\n\nexport interface AppRouterRenderFunctionArgs {\n routes: Route[];\n}\n\nexport interface RenderRouterProviderFunctionArgs {\n rootRoute: ReactElement;\n registeredRoutes: Route[];\n routerProviderProps: Omit<RouterProviderProps, \"router\">;\n}\n\nexport type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;\n\nexport function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState) {\n return (\n // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably\n // depends on the protected data.\n (areModulesRegistered || areModulesReadyValue)\n );\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction) {\n const routes = useRoutes();\n\n // The value is computed outside of the router provider memo to prevent\n // rendering a new router provider everytime the app router state change.\n const canRenderRouter = useCanRenderRouter(state);\n\n return useMemo(() => {\n if (canRenderRouter) {\n return renderRouterProvider({\n rootRoute: <RootRoute />,\n registeredRoutes: routes,\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [canRenderRouter, routes, renderRouterProvider]);\n}\n\nexport interface AppRouterProps {\n waitForPublicData?: boolean;\n waitForProtectedData?: boolean;\n children: RenderRouterProviderFunction;\n}\n\nexport function AppRouter(props: AppRouterProps) {\n const {\n waitForPublicData = false,\n waitForProtectedData = false,\n children: renderRouterProvider\n } = props;\n const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);\n\n const logger = useLogger();\n\n useStrictRegistrationMode();\n\n useEffect(() => {\n logger\n .withText(\"[squide] AppRouter state updated:\")\n .withObject(state)\n .debug();\n }, [state, logger]);\n\n const routerProvider = useRenderRouterProvider(state, renderRouterProvider);\n\n return (\n <AppRouterDispatcherContext.Provider value={dispatch}>\n <AppRouterStateContext.Provider value={state}>\n {routerProvider}\n </AppRouterStateContext.Provider>\n </AppRouterDispatcherContext.Provider>\n );\n}\n"],"names":["useLogger","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","useRenderRouterProvider","state","renderRouterProvider","routes","canRenderRouter","AppRouter","props","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAyC;AACoB;AACC;AAE4B;AACT;AACrC;AAC+B;AAcpE,SAASS,mBAAmB,EAAEC,oBAAoB,EAAE,iBAAiBC,oBAAoB,EAAkB;IAC9G,OACI,qIAAqI;IACrI,iCAAiC;IAChCD,wBAAwBC;AAEjC;AAEA,SAASC,wBAAwBC,KAAqB,EAAEC,oBAAkD;IACtG,MAAMC,SAASd,SAASA;IAExB,uEAAuE;IACvE,yEAAyE;IACzE,MAAMe,kBAAkBP,mBAAmBI;IAE3C,OAAOV,OAAOA,CAAC;QACX,IAAIa,iBAAiB;YACjB,OAAOF,qBAAqB;gBACxB,yBAAW,IAACP,SAASA;gBACrB,kBAAkBQ;gBAClB,qBAAqB,CAAC;YAC1B;QACJ;QAEA,OAAO;IACX,GAAG;QAACC;QAAiBD;QAAQD;KAAqB;AACtD;AAQO,SAASG,UAAUC,KAAqB;IAC3C,MAAM,EACFC,oBAAoB,KAAK,EACzBC,uBAAuB,KAAK,EAC5B,UAAUN,oBAAoB,EACjC,GAAGI;IACJ,MAAM,CAACL,OAAOQ,SAAS,GAAGf,mBAAmBA,CAACa,mBAAmBC;IAEjE,MAAME,SAAStB,SAASA;IAExBQ,yBAAyBA;IAEzBN,SAASA,CAAC;QACNoB,OACK,QAAQ,CAAC,qCACT,UAAU,CAACT,OACX,KAAK;IACd,GAAG;QAACA;QAAOS;KAAO;IAElB,MAAMC,iBAAiBX,wBAAwBC,OAAOC;IAEtD,qBACI,IAACV,mCAAmC;QAAC,OAAOiB;kBACxC,kBAAChB,8BAA8B;YAAC,OAAOQ;sBAClCU;;;AAIjB"}
1
+ {"version":3,"file":"AppRouter.js","sources":["../src/AppRouter.tsx"],"sourcesContent":["import { useLogger } from \"@squide/core\";\nimport { useRoutes, type Route } from \"@squide/react-router\";\nimport { useEffect, useMemo, type ReactElement } from \"react\";\nimport type { RouterProviderProps } from \"react-router/dom\";\nimport { AppRouterDispatcherContext, AppRouterStateContext } from \"./AppRouterContext.ts\";\nimport { useAppRouterReducer, type AppRouterState } from \"./AppRouterReducer.ts\";\nimport { RootRoute } from \"./RootRoute.tsx\";\nimport { useStrictRegistrationMode } from \"./useStrictRegistrationMode.ts\";\n\nexport interface AppRouterRenderFunctionArgs {\n routes: Route[];\n}\n\nexport interface RenderRouterProviderFunctionArgs {\n rootRoute: ReactElement;\n registeredRoutes: Route[];\n routerProviderProps: Omit<RouterProviderProps, \"router\">;\n}\n\nexport type RenderRouterProviderFunction = (args: RenderRouterProviderFunctionArgs) => ReactElement;\n\nexport function useCanRenderRouter({ areModulesRegistered, areModulesReady: areModulesReadyValue }: AppRouterState) {\n return (\n // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably\n // depends on the protected data.\n (areModulesRegistered || areModulesReadyValue)\n );\n}\n\nfunction useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction, strictMode: boolean) {\n const routes = useRoutes();\n\n // The value is computed outside of the router provider memo to prevent\n // rendering a new router provider everytime the app router state change.\n const canRenderRouter = useCanRenderRouter(state);\n\n return useMemo(() => {\n if (canRenderRouter) {\n return renderRouterProvider({\n rootRoute: <RootRoute strictMode={strictMode} />,\n registeredRoutes: routes,\n routerProviderProps: {}\n });\n }\n\n return null;\n }, [canRenderRouter, routes, renderRouterProvider, strictMode]);\n}\n\nexport interface AppRouterProps {\n waitForPublicData?: boolean;\n waitForProtectedData?: boolean;\n strictMode?: boolean;\n children: RenderRouterProviderFunction;\n}\n\nexport function AppRouter(props: AppRouterProps) {\n const {\n waitForPublicData = false,\n waitForProtectedData = false,\n strictMode = true,\n children: renderRouterProvider\n } = props;\n const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);\n\n const logger = useLogger();\n\n useStrictRegistrationMode({\n isEnabled: strictMode\n });\n\n useEffect(() => {\n logger\n .withText(\"[squide] AppRouter state updated:\")\n .withObject(state)\n .debug();\n }, [state, logger]);\n\n const routerProvider = useRenderRouterProvider(state, renderRouterProvider, strictMode);\n\n return (\n <AppRouterDispatcherContext.Provider value={dispatch}>\n <AppRouterStateContext.Provider value={state}>\n {routerProvider}\n </AppRouterStateContext.Provider>\n </AppRouterDispatcherContext.Provider>\n );\n}\n"],"names":["useLogger","useRoutes","useEffect","useMemo","AppRouterDispatcherContext","AppRouterStateContext","useAppRouterReducer","RootRoute","useStrictRegistrationMode","useCanRenderRouter","areModulesRegistered","areModulesReadyValue","useRenderRouterProvider","state","renderRouterProvider","strictMode","routes","canRenderRouter","AppRouter","props","waitForPublicData","waitForProtectedData","dispatch","logger","routerProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAyC;AACoB;AACC;AAE4B;AACT;AACrC;AAC+B;AAcpE,SAASS,mBAAmB,EAAEC,oBAAoB,EAAE,iBAAiBC,oBAAoB,EAAkB;IAC9G,OACI,qIAAqI;IACrI,iCAAiC;IAChCD,wBAAwBC;AAEjC;AAEA,SAASC,wBAAwBC,KAAqB,EAAEC,oBAAkD,EAAEC,UAAmB;IAC3H,MAAMC,SAASf,SAASA;IAExB,uEAAuE;IACvE,yEAAyE;IACzE,MAAMgB,kBAAkBR,mBAAmBI;IAE3C,OAAOV,OAAOA,CAAC;QACX,IAAIc,iBAAiB;YACjB,OAAOH,qBAAqB;gBACxB,yBAAW,IAACP,SAASA;oBAAC,YAAYQ;;gBAClC,kBAAkBC;gBAClB,qBAAqB,CAAC;YAC1B;QACJ;QAEA,OAAO;IACX,GAAG;QAACC;QAAiBD;QAAQF;QAAsBC;KAAW;AAClE;AASO,SAASG,UAAUC,KAAqB;IAC3C,MAAM,EACFC,oBAAoB,KAAK,EACzBC,uBAAuB,KAAK,EAC5BN,aAAa,IAAI,EACjB,UAAUD,oBAAoB,EACjC,GAAGK;IACJ,MAAM,CAACN,OAAOS,SAAS,GAAGhB,mBAAmBA,CAACc,mBAAmBC;IAEjE,MAAME,SAASvB,SAASA;IAExBQ,yBAAyBA,CAAC;QACtB,WAAWO;IACf;IAEAb,SAASA,CAAC;QACNqB,OACK,QAAQ,CAAC,qCACT,UAAU,CAACV,OACX,KAAK;IACd,GAAG;QAACA;QAAOU;KAAO;IAElB,MAAMC,iBAAiBZ,wBAAwBC,OAAOC,sBAAsBC;IAE5E,qBACI,IAACX,mCAAmC;QAAC,OAAOkB;kBACxC,kBAACjB,8BAA8B;YAAC,OAAOQ;sBAClCW;;;AAIjB"}
@@ -1,4 +1,5 @@
1
1
  import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from "@squide/core";
2
+ import { EnvironmentVariableKey, EnvironmentVariables, EnvironmentVariableValue } from "@squide/env-vars";
2
3
  import { MswState } from "@squide/msw";
3
4
  import { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from "@squide/react-router";
4
5
  import type { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
@@ -14,20 +15,28 @@ export interface IFireflyRuntime extends IReactRouterRuntime {
14
15
  getMswState(): MswState;
15
16
  registerRequestHandlers: (handlers: RequestHandler[]) => void;
16
17
  get requestHandlers(): RequestHandler[];
17
- get appRouterStore(): AppRouterStore;
18
18
  get isMswEnabled(): boolean;
19
+ registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
20
+ registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;
21
+ getEnvironmentVariable(key: EnvironmentVariableKey): EnvironmentVariableValue;
22
+ getEnvironmentVariables(): EnvironmentVariables;
23
+ get appRouterStore(): AppRouterStore;
19
24
  get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;
20
25
  }
21
26
  export declare class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends ReactRouterRuntime<TRuntime> implements IFireflyRuntime {
22
27
  protected _appRouterStore: AppRouterStore;
23
28
  protected _honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;
24
- constructor({ honeycombInstrumentationClient, ...options }?: FireflyRuntimeOptions);
29
+ constructor(options?: FireflyRuntimeOptions);
30
+ registerRoute(route: Route, options?: RegisterRouteOptions): void;
25
31
  getMswState(): MswState;
26
32
  registerRequestHandlers(handlers: RequestHandler[], options?: RegisterRequestHandlersOptions): void;
27
33
  get requestHandlers(): RequestHandler[];
28
- registerRoute(route: Route, options?: RegisterRouteOptions): void;
29
- get appRouterStore(): AppRouterStore;
30
34
  get isMswEnabled(): boolean;
35
+ getEnvironmentVariable(key: EnvironmentVariableKey): never;
36
+ getEnvironmentVariables(): EnvironmentVariables;
37
+ registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
38
+ registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;
39
+ get appRouterStore(): AppRouterStore;
31
40
  get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;
32
41
  startScope(logger: Logger): TRuntime;
33
42
  }
@@ -35,7 +44,11 @@ export declare class FireflyRuntimeScope<TRuntime extends FireflyRuntime = Firef
35
44
  getMswState(): MswState;
36
45
  registerRequestHandlers(handlers: RequestHandler[], options?: RegisterRequestHandlersOptions): void;
37
46
  get requestHandlers(): RequestHandler[];
38
- get appRouterStore(): AppRouterStore;
39
47
  get isMswEnabled(): boolean;
48
+ getEnvironmentVariables(): EnvironmentVariables;
49
+ getEnvironmentVariable(key: EnvironmentVariableKey): never;
50
+ registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
51
+ registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;
52
+ get appRouterStore(): AppRouterStore;
40
53
  get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient;
41
54
  }
@@ -1,7 +1,10 @@
1
- import { MswPluginName } from "@squide/msw";
1
+ import { getEnvironmentVariablesPlugin } from "@squide/env-vars";
2
+ import { MswPluginName, getMswPlugin } from "@squide/msw";
2
3
  import { ReactRouterRuntime, ReactRouterRuntimeScope } from "@squide/react-router";
3
4
  import { createAppRouterStore } from "./AppRouterStore.js";
4
5
 
6
+ ;// CONCATENATED MODULE: external "@squide/env-vars"
7
+
5
8
  ;// CONCATENATED MODULE: external "@squide/msw"
6
9
 
7
10
  ;// CONCATENATED MODULE: external "@squide/react-router"
@@ -12,55 +15,64 @@ import { createAppRouterStore } from "./AppRouterStore.js";
12
15
 
13
16
 
14
17
 
18
+
15
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
20
  class FireflyRuntime extends ReactRouterRuntime {
17
21
  _appRouterStore;
18
22
  _honeycombInstrumentationClient;
19
- constructor({ honeycombInstrumentationClient, ...options } = {}){
23
+ constructor(options = {}){
24
+ const { honeycombInstrumentationClient } = options;
20
25
  super(options);
21
26
  this._appRouterStore = createAppRouterStore(this._logger);
22
27
  this._honeycombInstrumentationClient = honeycombInstrumentationClient;
23
28
  }
24
- getMswState() {
25
- const mswPlugin = this.getPlugin(MswPluginName);
26
- if (!mswPlugin) {
27
- 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?");
29
+ registerRoute(route, options = {}) {
30
+ if (this.moduleManager.getAreModulesRegistered()) {
31
+ 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.");
28
32
  }
29
- return mswPlugin.mswState;
33
+ super.registerRoute(route, options);
34
+ }
35
+ getMswState() {
36
+ const plugin = getMswPlugin(this);
37
+ return plugin.mswState;
30
38
  }
31
39
  registerRequestHandlers(handlers, options = {}) {
32
40
  const logger = this._getLogger(options);
33
- const mswPlugin = this.getPlugin(MswPluginName);
34
- if (!mswPlugin) {
35
- 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?");
36
- }
41
+ const plugin = getMswPlugin(this);
37
42
  if (this.moduleManager.getAreModulesRegistered()) {
38
43
  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.");
39
44
  }
40
- mswPlugin.registerRequestHandlers(handlers, {
45
+ plugin.registerRequestHandlers(handlers, {
41
46
  logger
42
47
  });
43
48
  }
44
49
  // Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
45
50
  get requestHandlers() {
46
- const mswPlugin = this.getPlugin(MswPluginName);
47
- if (!mswPlugin) {
48
- throw new Error("[squide] Cannot retrieve MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \"useMsw\" option?");
49
- }
50
- return mswPlugin.requestHandlers;
51
+ const plugin = getMswPlugin(this);
52
+ return plugin.requestHandlers;
51
53
  }
52
- registerRoute(route, options = {}) {
53
- if (this.moduleManager.getAreModulesRegistered()) {
54
- 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.");
55
- }
56
- super.registerRoute(route, options);
54
+ get isMswEnabled() {
55
+ return this._plugins.some((x)=>x.name === MswPluginName);
56
+ }
57
+ getEnvironmentVariable(key) {
58
+ const plugin = getEnvironmentVariablesPlugin(this);
59
+ return plugin.getVariable(key);
60
+ }
61
+ getEnvironmentVariables() {
62
+ const plugin = getEnvironmentVariablesPlugin(this);
63
+ return plugin.getVariables();
64
+ }
65
+ registerEnvironmentVariable(key, value) {
66
+ const plugin = getEnvironmentVariablesPlugin(this);
67
+ return plugin.registerVariable(key, value);
68
+ }
69
+ registerEnvironmentVariables(variables) {
70
+ const plugin = getEnvironmentVariablesPlugin(this);
71
+ return plugin.registerVariables(variables);
57
72
  }
58
73
  get appRouterStore() {
59
74
  return this._appRouterStore;
60
75
  }
61
- get isMswEnabled() {
62
- return this._plugins.some((x)=>x.name === MswPluginName);
63
- }
64
76
  get honeycombInstrumentationClient() {
65
77
  return this._honeycombInstrumentationClient;
66
78
  }
@@ -82,12 +94,24 @@ class FireflyRuntimeScope extends ReactRouterRuntimeScope {
82
94
  get requestHandlers() {
83
95
  return this._runtime.requestHandlers;
84
96
  }
85
- get appRouterStore() {
86
- throw new Error("[squide] Cannot retrieve the app router store from a runtime scope instance.");
87
- }
88
97
  get isMswEnabled() {
89
98
  return this._runtime.isMswEnabled;
90
99
  }
100
+ getEnvironmentVariables() {
101
+ return this._runtime.getEnvironmentVariables();
102
+ }
103
+ getEnvironmentVariable(key) {
104
+ return this._runtime.getEnvironmentVariable(key);
105
+ }
106
+ registerEnvironmentVariable(key, value) {
107
+ this._runtime.registerEnvironmentVariable(key, value);
108
+ }
109
+ registerEnvironmentVariables(variables) {
110
+ this._runtime.registerEnvironmentVariables(variables);
111
+ }
112
+ get appRouterStore() {
113
+ throw new Error("[squide] Cannot retrieve the app router store from a runtime scope instance.");
114
+ }
91
115
  get honeycombInstrumentationClient() {
92
116
  throw new Error("[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.");
93
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FireflyRuntime.js","sources":["../src/FireflyRuntime.tsx"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from \"@squide/core\";\nimport { MswPlugin, MswPluginName, MswState } from \"@squide/msw\";\nimport { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from \"@squide/react-router\";\nimport type { HoneycombInstrumentationPartialClient } from \"@workleap-telemetry/core\";\nimport type { Logger } from \"@workleap/logging\";\nimport type { RequestHandler } from \"msw\";\nimport { type AppRouterStore, createAppRouterStore } from \"./AppRouterStore.ts\";\n\nexport interface FireflyRuntimeOptions<TRuntime extends FireflyRuntime = FireflyRuntime> extends RuntimeOptions<TRuntime> {\n honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;\n}\n\nexport interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}\n\nexport interface IFireflyRuntime extends IReactRouterRuntime {\n getMswState(): MswState;\n registerRequestHandlers: (handlers: RequestHandler[]) => void;\n get requestHandlers(): RequestHandler[];\n get appRouterStore(): AppRouterStore;\n get isMswEnabled(): boolean;\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends ReactRouterRuntime<TRuntime> implements IFireflyRuntime {\n protected _appRouterStore: AppRouterStore;\n protected _honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;\n\n constructor({ honeycombInstrumentationClient, ...options }: FireflyRuntimeOptions = {}) {\n super(options);\n\n this._appRouterStore = createAppRouterStore(this._logger);\n this._honeycombInstrumentationClient = honeycombInstrumentationClient;\n }\n\n getMswState() {\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n 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?\");\n }\n\n return mswPlugin.mswState;\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n const logger = this._getLogger(options);\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n 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?\");\n }\n\n if (this.moduleManager.getAreModulesRegistered()) {\n 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.\");\n }\n\n mswPlugin.registerRequestHandlers(handlers, {\n logger\n });\n }\n\n // Must define a return type otherwise we get an \"error TS2742: The inferred type of 'requestHandlers' cannot be named\" error.\n get requestHandlers(): RequestHandler[] {\n const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;\n\n if (!mswPlugin) {\n throw new Error(\"[squide] Cannot retrieve MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \\\"useMsw\\\" option?\");\n }\n\n return mswPlugin.requestHandlers;\n }\n\n registerRoute(route: Route, options: RegisterRouteOptions = {}) {\n if (this.moduleManager.getAreModulesRegistered()) {\n 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.\");\n }\n\n super.registerRoute(route, options);\n }\n\n get appRouterStore() {\n return this._appRouterStore;\n }\n\n get isMswEnabled() {\n return this._plugins.some(x => x.name === MswPluginName);\n }\n\n get honeycombInstrumentationClient() {\n return this._honeycombInstrumentationClient;\n }\n\n startScope(logger: Logger): TRuntime {\n return (new FireflyRuntimeScope(this, logger) as unknown) as TRuntime;\n }\n}\n\nexport class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {\n getMswState() {\n return this._runtime.getMswState();\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n this._runtime.registerRequestHandlers(handlers, {\n ...options,\n logger: this._getLogger(options)\n });\n }\n\n // Must define a return type otherwise we get an \"error TS2742: The inferred type of 'requestHandlers' cannot be named\" error.\n get requestHandlers(): RequestHandler[] {\n return this._runtime.requestHandlers;\n }\n\n get appRouterStore(): AppRouterStore {\n throw new Error(\"[squide] Cannot retrieve the app router store from a runtime scope instance.\");\n }\n\n get isMswEnabled() {\n return this._runtime.isMswEnabled;\n }\n\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient {\n throw new Error(\"[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.\");\n }\n}\n"],"names":["MswPluginName","ReactRouterRuntime","ReactRouterRuntimeScope","createAppRouterStore","FireflyRuntime","honeycombInstrumentationClient","options","mswPlugin","Error","handlers","logger","route","x","FireflyRuntimeScope"],"mappings":";;;;;;;;;;;AACiE;AACwD;AAIzC;AAiBhF,8DAA8D;AACvD,MAAMI,uBAA8DH,kBAAkBA;IAC/E,gBAAgC;IAChC,gCAAmF;IAE7F,YAAY,EAAEI,8BAA8B,EAAE,GAAGC,SAAgC,GAAG,CAAC,CAAC,CAAE;QACpF,KAAK,CAACA;QAEN,IAAI,CAAC,eAAe,GAAGH,oBAAoBA,CAAC,IAAI,CAAC,OAAO;QACxD,IAAI,CAAC,+BAA+B,GAAGE;IAC3C;IAEA,cAAc;QACV,MAAME,YAAY,IAAI,CAAC,SAAS,CAACP,aAAaA;QAE9C,IAAI,CAACO,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAOD,UAAU,QAAQ;IAC7B;IAEA,wBAAwBE,QAA0B,EAAEH,UAA0C,CAAC,CAAC,EAAE;QAC9F,MAAMI,SAAS,IAAI,CAAC,UAAU,CAACJ;QAC/B,MAAMC,YAAY,IAAI,CAAC,SAAS,CAACP,aAAaA;QAE9C,IAAI,CAACO,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,IAAI,IAAI,CAAC,aAAa,CAAC,uBAAuB,IAAI;YAC9C,MAAM,IAAIA,MAAM;QACpB;QAEAD,UAAU,uBAAuB,CAACE,UAAU;YACxCC;QACJ;IACJ;IAEA,8HAA8H;IAC9H,IAAI,kBAAoC;QACpC,MAAMH,YAAY,IAAI,CAAC,SAAS,CAACP,aAAaA;QAE9C,IAAI,CAACO,WAAW;YACZ,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAOD,UAAU,eAAe;IACpC;IAEA,cAAcI,KAAY,EAAEL,UAAgC,CAAC,CAAC,EAAE;QAC5D,IAAI,IAAI,CAAC,aAAa,CAAC,uBAAuB,IAAI;YAC9C,MAAM,IAAIE,MAAM;QACpB;QAEA,KAAK,CAAC,cAAcG,OAAOL;IAC/B;IAEA,IAAI,iBAAiB;QACjB,OAAO,IAAI,CAAC,eAAe;IAC/B;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACM,CAAAA,IAAKA,EAAE,IAAI,KAAKZ,aAAaA;IAC3D;IAEA,IAAI,iCAAiC;QACjC,OAAO,IAAI,CAAC,+BAA+B;IAC/C;IAEA,WAAWU,MAAc,EAAY;QACjC,OAAQ,IAAIG,oBAAoB,IAAI,EAAEH;IAC1C;AACJ;AAEO,MAAMG,4BAA8EX,uBAAuBA;IAC9G,cAAc;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW;IACpC;IAEA,wBAAwBO,QAA0B,EAAEH,UAA0C,CAAC,CAAC,EAAE;QAC9F,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAACG,UAAU;YAC5C,GAAGH,OAAO;YACV,QAAQ,IAAI,CAAC,UAAU,CAACA;QAC5B;IACJ;IAEA,8HAA8H;IAC9H,IAAI,kBAAoC;QACpC,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe;IACxC;IAEA,IAAI,iBAAiC;QACjC,MAAM,IAAIE,MAAM;IACpB;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY;IACrC;IAEA,IAAI,iCAAwE;QACxE,MAAM,IAAIA,MAAM;IACpB;AACJ"}
1
+ {"version":3,"file":"FireflyRuntime.js","sources":["../src/FireflyRuntime.tsx"],"sourcesContent":["import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from \"@squide/core\";\nimport { EnvironmentVariableKey, EnvironmentVariables, EnvironmentVariableValue, getEnvironmentVariablesPlugin } from \"@squide/env-vars\";\nimport { getMswPlugin, MswPluginName, MswState } from \"@squide/msw\";\nimport { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from \"@squide/react-router\";\nimport type { HoneycombInstrumentationPartialClient } from \"@workleap-telemetry/core\";\nimport type { Logger } from \"@workleap/logging\";\nimport type { RequestHandler } from \"msw\";\nimport { type AppRouterStore, createAppRouterStore } from \"./AppRouterStore.ts\";\n\nexport interface FireflyRuntimeOptions<TRuntime extends FireflyRuntime = FireflyRuntime> extends RuntimeOptions<TRuntime> {\n honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;\n}\n\nexport interface RegisterRequestHandlersOptions extends RuntimeMethodOptions {}\n\nexport interface IFireflyRuntime extends IReactRouterRuntime {\n getMswState(): MswState;\n registerRequestHandlers: (handlers: RequestHandler[]) => void;\n get requestHandlers(): RequestHandler[];\n get isMswEnabled(): boolean;\n registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;\n getEnvironmentVariable(key: EnvironmentVariableKey): EnvironmentVariableValue;\n getEnvironmentVariables(): EnvironmentVariables;\n get appRouterStore(): AppRouterStore;\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends ReactRouterRuntime<TRuntime> implements IFireflyRuntime {\n protected _appRouterStore: AppRouterStore;\n protected _honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;\n\n constructor(options: FireflyRuntimeOptions = {}) {\n const {\n honeycombInstrumentationClient\n } = options;\n\n super(options);\n\n this._appRouterStore = createAppRouterStore(this._logger);\n this._honeycombInstrumentationClient = honeycombInstrumentationClient;\n }\n\n registerRoute(route: Route, options: RegisterRouteOptions = {}) {\n if (this.moduleManager.getAreModulesRegistered()) {\n 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.\");\n }\n\n super.registerRoute(route, options);\n }\n\n getMswState() {\n const plugin = getMswPlugin(this);\n\n return plugin.mswState;\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n const logger = this._getLogger(options);\n const plugin = getMswPlugin(this);\n\n if (this.moduleManager.getAreModulesRegistered()) {\n 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.\");\n }\n\n plugin.registerRequestHandlers(handlers, {\n logger\n });\n }\n\n // Must define a return type otherwise we get an \"error TS2742: The inferred type of 'requestHandlers' cannot be named\" error.\n get requestHandlers(): RequestHandler[] {\n const plugin = getMswPlugin(this);\n\n return plugin.requestHandlers;\n }\n\n get isMswEnabled() {\n return this._plugins.some(x => x.name === MswPluginName);\n }\n\n getEnvironmentVariable(key: EnvironmentVariableKey) {\n const plugin = getEnvironmentVariablesPlugin(this);\n\n return plugin.getVariable(key);\n }\n\n getEnvironmentVariables() {\n const plugin = getEnvironmentVariablesPlugin(this);\n\n return plugin.getVariables();\n }\n\n registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {\n const plugin = getEnvironmentVariablesPlugin(this);\n\n return plugin.registerVariable(key, value);\n }\n\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {\n const plugin = getEnvironmentVariablesPlugin(this);\n\n return plugin.registerVariables(variables);\n }\n\n get appRouterStore() {\n return this._appRouterStore;\n }\n\n get honeycombInstrumentationClient() {\n return this._honeycombInstrumentationClient;\n }\n\n startScope(logger: Logger): TRuntime {\n return (new FireflyRuntimeScope(this, logger) as unknown) as TRuntime;\n }\n}\n\nexport class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntime> extends ReactRouterRuntimeScope<TRuntime> implements IFireflyRuntime {\n getMswState() {\n return this._runtime.getMswState();\n }\n\n registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {\n this._runtime.registerRequestHandlers(handlers, {\n ...options,\n logger: this._getLogger(options)\n });\n }\n\n // Must define a return type otherwise we get an \"error TS2742: The inferred type of 'requestHandlers' cannot be named\" error.\n get requestHandlers(): RequestHandler[] {\n return this._runtime.requestHandlers;\n }\n\n get isMswEnabled() {\n return this._runtime.isMswEnabled;\n }\n\n getEnvironmentVariables() {\n return this._runtime.getEnvironmentVariables();\n }\n\n getEnvironmentVariable(key: EnvironmentVariableKey) {\n return this._runtime.getEnvironmentVariable(key);\n }\n\n registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {\n this._runtime.registerEnvironmentVariable(key, value);\n }\n\n registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {\n this._runtime.registerEnvironmentVariables(variables);\n }\n\n get appRouterStore(): AppRouterStore {\n throw new Error(\"[squide] Cannot retrieve the app router store from a runtime scope instance.\");\n }\n\n get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient {\n throw new Error(\"[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.\");\n }\n}\n"],"names":["getEnvironmentVariablesPlugin","getMswPlugin","MswPluginName","ReactRouterRuntime","ReactRouterRuntimeScope","createAppRouterStore","FireflyRuntime","options","honeycombInstrumentationClient","route","Error","plugin","handlers","logger","x","key","value","variables","FireflyRuntimeScope"],"mappings":";;;;;;;;;;;;;;AACyI;AACrE;AACqD;AAIzC;AAqBhF,8DAA8D;AACvD,MAAMM,uBAA8DH,kBAAkBA;IAC/E,gBAAgC;IAChC,gCAAmF;IAE7F,YAAYI,UAAiC,CAAC,CAAC,CAAE;QAC7C,MAAM,EACFC,8BAA8B,EACjC,GAAGD;QAEJ,KAAK,CAACA;QAEN,IAAI,CAAC,eAAe,GAAGF,oBAAoBA,CAAC,IAAI,CAAC,OAAO;QACxD,IAAI,CAAC,+BAA+B,GAAGG;IAC3C;IAEA,cAAcC,KAAY,EAAEF,UAAgC,CAAC,CAAC,EAAE;QAC5D,IAAI,IAAI,CAAC,aAAa,CAAC,uBAAuB,IAAI;YAC9C,MAAM,IAAIG,MAAM;QACpB;QAEA,KAAK,CAAC,cAAcD,OAAOF;IAC/B;IAEA,cAAc;QACV,MAAMI,SAASV,YAAYA,CAAC,IAAI;QAEhC,OAAOU,OAAO,QAAQ;IAC1B;IAEA,wBAAwBC,QAA0B,EAAEL,UAA0C,CAAC,CAAC,EAAE;QAC9F,MAAMM,SAAS,IAAI,CAAC,UAAU,CAACN;QAC/B,MAAMI,SAASV,YAAYA,CAAC,IAAI;QAEhC,IAAI,IAAI,CAAC,aAAa,CAAC,uBAAuB,IAAI;YAC9C,MAAM,IAAIS,MAAM;QACpB;QAEAC,OAAO,uBAAuB,CAACC,UAAU;YACrCC;QACJ;IACJ;IAEA,8HAA8H;IAC9H,IAAI,kBAAoC;QACpC,MAAMF,SAASV,YAAYA,CAAC,IAAI;QAEhC,OAAOU,OAAO,eAAe;IACjC;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACG,CAAAA,IAAKA,EAAE,IAAI,KAAKZ,aAAaA;IAC3D;IAEA,uBAAuBa,GAA2B,EAAE;QAChD,MAAMJ,SAASX,6BAA6BA,CAAC,IAAI;QAEjD,OAAOW,OAAO,WAAW,CAACI;IAC9B;IAEA,0BAA0B;QACtB,MAAMJ,SAASX,6BAA6BA,CAAC,IAAI;QAEjD,OAAOW,OAAO,YAAY;IAC9B;IAEA,4BAA4BI,GAA2B,EAAEC,KAA+B,EAAE;QACtF,MAAML,SAASX,6BAA6BA,CAAC,IAAI;QAEjD,OAAOW,OAAO,gBAAgB,CAACI,KAAKC;IACxC;IAEA,6BAA6BC,SAAwC,EAAE;QACnE,MAAMN,SAASX,6BAA6BA,CAAC,IAAI;QAEjD,OAAOW,OAAO,iBAAiB,CAACM;IACpC;IAEA,IAAI,iBAAiB;QACjB,OAAO,IAAI,CAAC,eAAe;IAC/B;IAEA,IAAI,iCAAiC;QACjC,OAAO,IAAI,CAAC,+BAA+B;IAC/C;IAEA,WAAWJ,MAAc,EAAY;QACjC,OAAQ,IAAIK,oBAAoB,IAAI,EAAEL;IAC1C;AACJ;AAEO,MAAMK,4BAA8Ed,uBAAuBA;IAC9G,cAAc;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW;IACpC;IAEA,wBAAwBQ,QAA0B,EAAEL,UAA0C,CAAC,CAAC,EAAE;QAC9F,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAACK,UAAU;YAC5C,GAAGL,OAAO;YACV,QAAQ,IAAI,CAAC,UAAU,CAACA;QAC5B;IACJ;IAEA,8HAA8H;IAC9H,IAAI,kBAAoC;QACpC,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe;IACxC;IAEA,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY;IACrC;IAEA,0BAA0B;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,uBAAuB;IAChD;IAEA,uBAAuBQ,GAA2B,EAAE;QAChD,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAACA;IAChD;IAEA,4BAA4BA,GAA2B,EAAEC,KAA+B,EAAE;QACtF,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAACD,KAAKC;IACnD;IAEA,6BAA6BC,SAAwC,EAAE;QACnE,IAAI,CAAC,QAAQ,CAAC,4BAA4B,CAACA;IAC/C;IAEA,IAAI,iBAAiC;QACjC,MAAM,IAAIP,MAAM;IACpB;IAEA,IAAI,iCAAwE;QACxE,MAAM,IAAIA,MAAM;IACpB;AACJ"}
@@ -1 +1,4 @@
1
- export declare function RootRoute(): import("react/jsx-runtime").JSX.Element;
1
+ export interface RootRouteProps {
2
+ strictMode?: boolean;
3
+ }
4
+ export declare function RootRoute(props: RootRouteProps): import("react/jsx-runtime").JSX.Element;
package/dist/RootRoute.js CHANGED
@@ -20,9 +20,12 @@ import { useIsActiveRouteProtected } from "./useIsActiveRouteProtected.js";
20
20
 
21
21
 
22
22
 
23
- function RootRoute() {
23
+ function RootRoute(props) {
24
+ const { strictMode = true } = props;
24
25
  const state = useAppRouterState();
25
- const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady);
26
+ const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady, {
27
+ throwWhenThereIsNoMatch: strictMode
28
+ });
26
29
  const dispatch = useAppRouterDispatcher();
27
30
  useEffect(()=>{
28
31
  // Dispatching the active route visibility must be done in a route because React Router's useLocation
@@ -1 +1 @@
1
- {"version":3,"file":"RootRoute.js","sources":["../src/RootRoute.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { Outlet } from \"react-router\";\nimport { useAppRouterDispatcher, useAppRouterState } from \"./AppRouterContext.ts\";\nimport { useIsActiveRouteProtected } from \"./useIsActiveRouteProtected.ts\";\n\nexport function RootRoute() {\n const state = useAppRouterState();\n const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady);\n\n const dispatch = useAppRouterDispatcher();\n\n useEffect(() => {\n // Dispatching the active route visibility must be done in a route because React Router's useLocation\n // hook throws if it's not called from a child of the router component.\n if (isActiveRouteProtected) {\n dispatch({ type: \"active-route-is-protected\" });\n } else {\n dispatch({ type: \"active-route-is-public\" });\n }\n }, [isActiveRouteProtected, dispatch]);\n\n return (\n <Outlet />\n );\n}\n"],"names":["useEffect","Outlet","useAppRouterDispatcher","useAppRouterState","useIsActiveRouteProtected","RootRoute","state","isActiveRouteProtected","dispatch"],"mappings":";;;;;;;;;;;;;;;;;;AAAkC;AACI;AAC4C;AACP;AAEpE,SAASK;IACZ,MAAMC,QAAQH,iBAAiBA;IAC/B,MAAMI,yBAAyBH,yBAAyBA,CAACE,MAAM,eAAe;IAE9E,MAAME,WAAWN,sBAAsBA;IAEvCF,SAASA,CAAC;QACN,qGAAqG;QACrG,uEAAuE;QACvE,IAAIO,wBAAwB;YACxBC,SAAS;gBAAE,MAAM;YAA4B;QACjD,OAAO;YACHA,SAAS;gBAAE,MAAM;YAAyB;QAC9C;IACJ,GAAG;QAACD;QAAwBC;KAAS;IAErC,qBACI,IAACP,MAAMA;AAEf"}
1
+ {"version":3,"file":"RootRoute.js","sources":["../src/RootRoute.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { Outlet } from \"react-router\";\nimport { useAppRouterDispatcher, useAppRouterState } from \"./AppRouterContext.ts\";\nimport { useIsActiveRouteProtected } from \"./useIsActiveRouteProtected.ts\";\n\nexport interface RootRouteProps {\n strictMode?: boolean;\n}\n\nexport function RootRoute(props: RootRouteProps) {\n const {\n strictMode = true\n } = props;\n\n const state = useAppRouterState();\n\n const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady, {\n throwWhenThereIsNoMatch: strictMode\n });\n\n const dispatch = useAppRouterDispatcher();\n\n useEffect(() => {\n // Dispatching the active route visibility must be done in a route because React Router's useLocation\n // hook throws if it's not called from a child of the router component.\n if (isActiveRouteProtected) {\n dispatch({ type: \"active-route-is-protected\" });\n } else {\n dispatch({ type: \"active-route-is-public\" });\n }\n }, [isActiveRouteProtected, dispatch]);\n\n return (\n <Outlet />\n );\n}\n"],"names":["useEffect","Outlet","useAppRouterDispatcher","useAppRouterState","useIsActiveRouteProtected","RootRoute","props","strictMode","state","isActiveRouteProtected","dispatch"],"mappings":";;;;;;;;;;;;;;;;;;AAAkC;AACI;AAC4C;AACP;AAMpE,SAASK,UAAUC,KAAqB;IAC3C,MAAM,EACFC,aAAa,IAAI,EACpB,GAAGD;IAEJ,MAAME,QAAQL,iBAAiBA;IAE/B,MAAMM,yBAAyBL,yBAAyBA,CAACI,MAAM,eAAe,EAAE;QAC5E,yBAAyBD;IAC7B;IAEA,MAAMG,WAAWR,sBAAsBA;IAEvCF,SAASA,CAAC;QACN,qGAAqG;QACrG,uEAAuE;QACvE,IAAIS,wBAAwB;YACxBC,SAAS;gBAAE,MAAM;YAA4B;QACjD,OAAO;YACHA,SAAS;gBAAE,MAAM;YAAyB;QAC9C;IACJ,GAAG;QAACD;QAAwBC;KAAS;IAErC,qBACI,IAACT,MAAMA;AAEf"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "@squide/core";
2
- export * from "@squide/msw";
2
+ export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, useEnvironmentVariable, useEnvironmentVariables, type EnvironmentVariableKey, type EnvironmentVariables, type EnvironmentVariablesPluginOptions, type EnvironmentVariableValue } from "@squide/env-vars";
3
+ export { getMswPlugin, MswPlugin, MswPluginName, MswState, type MswPluginOptions, type MswPluginRegisterRequestHandlersOptions, type MswReadyListener, type MswStateOptions } from "@squide/msw";
3
4
  export * from "@squide/react-router";
4
5
  export type { FireflyPlugin } from "./FireflyPlugin.ts";
5
6
  export * from "./FireflyProvider.tsx";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, useEnvironmentVariable, useEnvironmentVariables } from "@squide/env-vars";
2
+ import { MswPlugin, MswPluginName, MswState, getMswPlugin } from "@squide/msw";
1
3
  import { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent } from "./AppRouterReducer.js";
2
4
  export * from "@squide/core";
3
- export * from "@squide/msw";
4
5
  export * from "@squide/react-router";
5
6
  export * from "./FireflyProvider.js";
6
7
  export * from "./FireflyRuntime.js";
@@ -24,6 +25,10 @@ export * from "./useStrictRegistrationMode.js";
24
25
  export * from "./useUpdateDeferredRegistrations.js";
25
26
  export * from "./initializeFirefly.js";
26
27
 
28
+ ;// CONCATENATED MODULE: external "@squide/env-vars"
29
+
30
+ ;// CONCATENATED MODULE: external "@squide/msw"
31
+
27
32
  ;// CONCATENATED MODULE: external "./AppRouterReducer.js"
28
33
 
29
34
  ;// CONCATENATED MODULE: ./src/index.ts
@@ -53,6 +58,7 @@ export * from "./initializeFirefly.js";
53
58
 
54
59
 
55
60
 
56
- export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent };
61
+
62
+ export { ActiveRouteIsProtectedEvent, ActiveRouteIsPublicEvent, ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, ModulesReadyEvent, ModulesRegisteredEvent, MswPlugin, MswPluginName, MswReadyEvent, MswState, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, getEnvironmentVariablesPlugin, getMswPlugin, useEnvironmentVariable, useEnvironmentVariables };
57
63
 
58
64
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export * from \"@squide/core\";\nexport * from \"@squide/msw\";\nexport * from \"@squide/react-router\";\n\nexport type { FireflyPlugin } from \"./FireflyPlugin.ts\";\nexport * from \"./FireflyProvider.tsx\";\nexport * from \"./FireflyRuntime.tsx\";\n\nexport * from \"./AppRouter.tsx\";\nexport {\n ActiveRouteIsProtectedEvent,\n ActiveRouteIsPublicEvent,\n ApplicationBoostrappedEvent,\n DeferredRegistrationsUpdatedEvent,\n ModulesReadyEvent,\n ModulesRegisteredEvent,\n MswReadyEvent,\n ProtectedDataReadyEvent,\n ProtectedDataUpdatedEvent,\n PublicDataReadyEvent,\n PublicDataUpdatedEvent\n} from \"./AppRouterReducer.ts\";\n\nexport * from \"./AppRouterStore.ts\";\nexport * from \"./GlobalDataQueriesError.ts\";\nexport * from \"./useCanFetchProtectedData.ts\";\nexport * from \"./useCanFetchPublicData.ts\";\nexport * from \"./useCanRegisterDeferredRegistrations.ts\";\nexport * from \"./useCanUpdateDeferredRegistrations.ts\";\nexport * from \"./useDeferredRegistrations.ts\";\nexport * from \"./useIsActiveRouteProtected.ts\";\nexport * from \"./useIsBootstrapping.ts\";\nexport * from \"./useNavigationItems.ts\";\nexport * from \"./useProtectedDataHandler.ts\";\nexport * from \"./useProtectedDataQueries.ts\";\nexport * from \"./usePublicDataHandler.ts\";\nexport * from \"./usePublicDataQueries.ts\";\nexport * from \"./useRegisterDeferredRegistrations.ts\";\nexport * from \"./useStrictRegistrationMode.ts\";\nexport * from \"./useUpdateDeferredRegistrations.ts\";\n\nexport * from \"./initializeFirefly.ts\";\n\n"],"names":["ActiveRouteIsProtectedEvent","ActiveRouteIsPublicEvent","ApplicationBoostrappedEvent","DeferredRegistrationsUpdatedEvent","ModulesReadyEvent","ModulesRegisteredEvent","MswReadyEvent","ProtectedDataReadyEvent","ProtectedDataUpdatedEvent","PublicDataReadyEvent","PublicDataUpdatedEvent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA6B;AACD;AACS;AAGC;AACD;AAEL;AAaD;AAEK;AACQ;AACE;AACH;AACc;AACF;AACT;AACC;AACP;AACA;AACK;AACA;AACH;AACA;AACY;AACP;AACK;AAEb"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export * from \"@squide/core\";\nexport {\n EnvironmentVariablesPlugin,\n EnvironmentVariablesPluginName,\n getEnvironmentVariablesPlugin,\n useEnvironmentVariable,\n useEnvironmentVariables,\n type EnvironmentVariableKey,\n type EnvironmentVariables,\n type EnvironmentVariablesPluginOptions,\n type EnvironmentVariableValue\n} from \"@squide/env-vars\";\nexport {\n getMswPlugin,\n MswPlugin,\n MswPluginName,\n MswState,\n type MswPluginOptions,\n type MswPluginRegisterRequestHandlersOptions,\n type MswReadyListener,\n type MswStateOptions\n} from \"@squide/msw\";\nexport * from \"@squide/react-router\";\n\nexport type { FireflyPlugin } from \"./FireflyPlugin.ts\";\nexport * from \"./FireflyProvider.tsx\";\nexport * from \"./FireflyRuntime.tsx\";\n\nexport * from \"./AppRouter.tsx\";\nexport {\n ActiveRouteIsProtectedEvent,\n ActiveRouteIsPublicEvent,\n ApplicationBoostrappedEvent,\n DeferredRegistrationsUpdatedEvent,\n ModulesReadyEvent,\n ModulesRegisteredEvent,\n MswReadyEvent,\n ProtectedDataReadyEvent,\n ProtectedDataUpdatedEvent,\n PublicDataReadyEvent,\n PublicDataUpdatedEvent\n} from \"./AppRouterReducer.ts\";\n\nexport * from \"./AppRouterStore.ts\";\nexport * from \"./GlobalDataQueriesError.ts\";\nexport * from \"./useCanFetchProtectedData.ts\";\nexport * from \"./useCanFetchPublicData.ts\";\nexport * from \"./useCanRegisterDeferredRegistrations.ts\";\nexport * from \"./useCanUpdateDeferredRegistrations.ts\";\nexport * from \"./useDeferredRegistrations.ts\";\nexport * from \"./useIsActiveRouteProtected.ts\";\nexport * from \"./useIsBootstrapping.ts\";\nexport * from \"./useNavigationItems.ts\";\nexport * from \"./useProtectedDataHandler.ts\";\nexport * from \"./useProtectedDataQueries.ts\";\nexport * from \"./usePublicDataHandler.ts\";\nexport * from \"./usePublicDataQueries.ts\";\nexport * from \"./useRegisterDeferredRegistrations.ts\";\nexport * from \"./useStrictRegistrationMode.ts\";\nexport * from \"./useUpdateDeferredRegistrations.ts\";\n\nexport * from \"./initializeFirefly.ts\";\n\n"],"names":["EnvironmentVariablesPlugin","EnvironmentVariablesPluginName","getEnvironmentVariablesPlugin","useEnvironmentVariable","useEnvironmentVariables","getMswPlugin","MswPlugin","MswPluginName","MswState","ActiveRouteIsProtectedEvent","ActiveRouteIsPublicEvent","ApplicationBoostrappedEvent","DeferredRegistrationsUpdatedEvent","ModulesReadyEvent","ModulesRegisteredEvent","MswReadyEvent","ProtectedDataReadyEvent","ProtectedDataUpdatedEvent","PublicDataReadyEvent","PublicDataUpdatedEvent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA6B;AAWH;AAUL;AACgB;AAGC;AACD;AAEL;AAaD;AAEK;AACQ;AACE;AACH;AACc;AACF;AACT;AACC;AACP;AACA;AACK;AACA;AACH;AACA;AACY;AACP;AACK;AAEb"}
@@ -1,4 +1,5 @@
1
1
  import { ModuleDefinition, type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
2
+ import { EnvironmentVariables } from "@squide/env-vars";
2
3
  import type { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
3
4
  import { FireflyRuntime, type FireflyRuntimeOptions } from "./FireflyRuntime.tsx";
4
5
  export declare const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
@@ -8,6 +9,7 @@ export interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TCont
8
9
  localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
9
10
  moduleDefinitions?: ModuleDefinition<TRuntime, TContext, TData>[];
10
11
  useMsw?: boolean;
12
+ environmentVariables?: Partial<EnvironmentVariables>;
11
13
  honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;
12
14
  startMsw?: StartMswFunction<FireflyRuntime>;
13
15
  onError?: OnInitializationErrorFunction;
@@ -1,10 +1,13 @@
1
1
  import { isFunction, toLocalModuleDefinitions } from "@squide/core";
2
+ import { EnvironmentVariablesPlugin } from "@squide/env-vars";
2
3
  import { MswPlugin } from "@squide/msw";
3
4
  import { FireflyRuntime } from "./FireflyRuntime.js";
4
5
  import { initializeHoneycomb } from "./honeycomb/initializeHoneycomb.js";
5
6
 
6
7
  ;// CONCATENATED MODULE: external "@squide/core"
7
8
 
9
+ ;// CONCATENATED MODULE: external "@squide/env-vars"
10
+
8
11
  ;// CONCATENATED MODULE: external "@squide/msw"
9
12
 
10
13
  ;// CONCATENATED MODULE: external "./FireflyRuntime.js"
@@ -16,6 +19,7 @@ import { initializeHoneycomb } from "./honeycomb/initializeHoneycomb.js";
16
19
 
17
20
 
18
21
 
22
+
19
23
  const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
20
24
  function bootstrap(runtime, modulesDefinitions, options = {}) {
21
25
  const { startMsw, onError, context } = options;
@@ -48,7 +52,7 @@ function __resetHasExecutedGuard() {
48
52
  hasExecuted = false;
49
53
  }
50
54
  function initializeFirefly(options = {}) {
51
- const { mode, localModules = [], moduleDefinitions = [], useMsw, plugins = [], honeycombInstrumentationClient, loggers, onError } = options;
55
+ const { mode, localModules = [], moduleDefinitions = [], useMsw, plugins = [], environmentVariables, honeycombInstrumentationClient, loggers, onError } = options;
52
56
  if (hasExecuted) {
53
57
  throw new Error("[squide] A squide application can only be initialized once. Did you call the \"initializeSquide\" function twice?");
54
58
  }
@@ -60,7 +64,12 @@ function initializeFirefly(options = {}) {
60
64
  mode,
61
65
  honeycombInstrumentationClient,
62
66
  loggers,
63
- plugins
67
+ plugins: [
68
+ (x)=>new EnvironmentVariablesPlugin(x, {
69
+ variables: environmentVariables
70
+ }),
71
+ ...plugins
72
+ ]
64
73
  });
65
74
  initializeHoneycomb(runtime).catch((error)=>{
66
75
  if (onError) {
@@ -1 +1 @@
1
- {"version":3,"file":"initializeFirefly.js","sources":["../src/initializeFirefly.ts"],"sourcesContent":["import { isFunction, ModuleDefinition, toLocalModuleDefinitions, type ModuleRegisterFunction, type RegisterModulesOptions } from \"@squide/core\";\nimport { MswPlugin } from \"@squide/msw\";\nimport type { HoneycombInstrumentationPartialClient } from \"@workleap-telemetry/core\";\nimport { FireflyRuntime, type FireflyRuntimeOptions } from \"./FireflyRuntime.tsx\";\nimport { initializeHoneycomb } from \"./honeycomb/initializeHoneycomb.ts\";\n\nexport const ApplicationBootstrappingStartedEvent = \"squide-app-bootstrapping-started\";\n\nexport type OnInitializationErrorFunction = (error: unknown) => void;\n\nexport type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;\n\nexport interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext>, FireflyRuntimeOptions {\n localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];\n moduleDefinitions?: ModuleDefinition<TRuntime, TContext, TData>[];\n useMsw?: boolean;\n honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;\n startMsw?: StartMswFunction<FireflyRuntime>;\n onError?: OnInitializationErrorFunction;\n}\n\nexport function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(\n runtime: TRuntime,\n modulesDefinitions: ModuleDefinition<TRuntime, TContext, TData>[],\n options: Omit<InitializeFireflyOptions<TRuntime, TContext, TData>, \"localModules\" | \"moduleDefinitions\"> = {}\n) {\n const {\n startMsw,\n onError,\n context\n } = options;\n\n runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);\n\n runtime.moduleManager.registerModules(modulesDefinitions, { context })\n .then(results => {\n if (runtime.isMswEnabled) {\n if (!isFunction(startMsw)) {\n throw new Error(\"[squide] When MSW is enabled, the \\\"startMsw\\\" function must be provided.\");\n }\n\n startMsw(runtime)\n .then(() => {\n if (runtime.isMswEnabled) {\n runtime.getMswState().setAsReady();\n }\n })\n .catch((error: unknown) => {\n runtime.logger\n .withText(\"[squide] An error occured while starting MSW.\")\n .withError(error as Error)\n .error();\n });\n }\n\n if (onError) {\n results.forEach(error => {\n onError(error);\n });\n }\n });\n}\n\nlet hasExecuted = false;\n\n// Should only be used by tests.\nexport function __resetHasExecutedGuard() {\n hasExecuted = false;\n}\n\nexport function initializeFirefly<TContext = unknown, TData = unknown>(options: InitializeFireflyOptions<FireflyRuntime, TContext, TData> = {}) {\n const {\n mode,\n localModules = [],\n moduleDefinitions = [],\n useMsw,\n plugins = [],\n honeycombInstrumentationClient,\n loggers,\n onError\n } = options;\n\n if (hasExecuted) {\n throw new Error(\"[squide] A squide application can only be initialized once. Did you call the \\\"initializeSquide\\\" function twice?\");\n }\n\n hasExecuted = true;\n\n if (useMsw) {\n plugins.push(x => new MswPlugin(x));\n }\n\n const runtime = new FireflyRuntime({\n mode,\n honeycombInstrumentationClient,\n loggers,\n plugins\n });\n\n initializeHoneycomb(runtime)\n .catch((error: unknown) => {\n if (onError) {\n onError(error);\n }\n })\n .finally(() => {\n bootstrap(\n runtime,\n [...moduleDefinitions, ...toLocalModuleDefinitions(localModules)],\n options\n );\n });\n\n return runtime;\n}\n"],"names":["isFunction","toLocalModuleDefinitions","MswPlugin","FireflyRuntime","initializeHoneycomb","ApplicationBootstrappingStartedEvent","bootstrap","runtime","modulesDefinitions","options","startMsw","onError","context","results","Error","error","hasExecuted","__resetHasExecutedGuard","initializeFirefly","mode","localModules","moduleDefinitions","useMsw","plugins","honeycombInstrumentationClient","loggers","x"],"mappings":";;;;;;;;;;;;;;AAAgJ;AACxG;AAE0C;AACT;AAElE,MAAMK,uCAAuC,mCAAmC;AAehF,SAASC,UACZC,OAAiB,EACjBC,kBAAiE,EACjEC,UAA2G,CAAC,CAAC;IAE7G,MAAM,EACFC,QAAQ,EACRC,OAAO,EACPC,OAAO,EACV,GAAGH;IAEJF,QAAQ,QAAQ,CAAC,QAAQ,CAACF;IAE1BE,QAAQ,aAAa,CAAC,eAAe,CAACC,oBAAoB;QAAEI;IAAQ,GAC/D,IAAI,CAACC,CAAAA;QACF,IAAIN,QAAQ,YAAY,EAAE;YACtB,IAAI,CAACP,UAAUA,CAACU,WAAW;gBACvB,MAAM,IAAII,MAAM;YACpB;YAEAJ,SAASH,SACJ,IAAI,CAAC;gBACF,IAAIA,QAAQ,YAAY,EAAE;oBACtBA,QAAQ,WAAW,GAAG,UAAU;gBACpC;YACJ,GACC,KAAK,CAAC,CAACQ;gBACJR,QAAQ,MAAM,CACT,QAAQ,CAAC,iDACT,SAAS,CAACQ,OACV,KAAK;YACd;QACR;QAEA,IAAIJ,SAAS;YACTE,QAAQ,OAAO,CAACE,CAAAA;gBACZJ,QAAQI;YACZ;QACJ;IACJ;AACR;AAEA,IAAIC,cAAc;AAElB,gCAAgC;AACzB,SAASC;IACZD,cAAc;AAClB;AAEO,SAASE,kBAAuDT,UAAqE,CAAC,CAAC;IAC1I,MAAM,EACFU,IAAI,EACJC,eAAe,EAAE,EACjBC,oBAAoB,EAAE,EACtBC,MAAM,EACNC,UAAU,EAAE,EACZC,8BAA8B,EAC9BC,OAAO,EACPd,OAAO,EACV,GAAGF;IAEJ,IAAIO,aAAa;QACb,MAAM,IAAIF,MAAM;IACpB;IAEAE,cAAc;IAEd,IAAIM,QAAQ;QACRC,QAAQ,IAAI,CAACG,CAAAA,IAAK,IAAIxB,SAASA,CAACwB;IACpC;IAEA,MAAMnB,UAAU,IAAIJ,cAAcA,CAAC;QAC/BgB;QACAK;QACAC;QACAF;IACJ;IAEAnB,mBAAmBA,CAACG,SACf,KAAK,CAAC,CAACQ;QACJ,IAAIJ,SAAS;YACTA,QAAQI;QACZ;IACJ,GACC,OAAO,CAAC;QACLT,UACIC,SACA;eAAIc;eAAsBpB,wBAAwBA,CAACmB;SAAc,EACjEX;IAER;IAEJ,OAAOF;AACX"}
1
+ {"version":3,"file":"initializeFirefly.js","sources":["../src/initializeFirefly.ts"],"sourcesContent":["import { isFunction, ModuleDefinition, toLocalModuleDefinitions, type ModuleRegisterFunction, type RegisterModulesOptions } from \"@squide/core\";\nimport { EnvironmentVariables, EnvironmentVariablesPlugin } from \"@squide/env-vars\";\nimport { MswPlugin } from \"@squide/msw\";\nimport type { HoneycombInstrumentationPartialClient } from \"@workleap-telemetry/core\";\nimport { FireflyRuntime, type FireflyRuntimeOptions } from \"./FireflyRuntime.tsx\";\nimport { initializeHoneycomb } from \"./honeycomb/initializeHoneycomb.ts\";\n\nexport const ApplicationBootstrappingStartedEvent = \"squide-app-bootstrapping-started\";\n\nexport type OnInitializationErrorFunction = (error: unknown) => void;\n\nexport type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;\n\nexport interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext>, FireflyRuntimeOptions {\n localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];\n moduleDefinitions?: ModuleDefinition<TRuntime, TContext, TData>[];\n useMsw?: boolean;\n environmentVariables?: Partial<EnvironmentVariables>;\n honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;\n startMsw?: StartMswFunction<FireflyRuntime>;\n onError?: OnInitializationErrorFunction;\n}\n\nexport function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(\n runtime: TRuntime,\n modulesDefinitions: ModuleDefinition<TRuntime, TContext, TData>[],\n options: Omit<InitializeFireflyOptions<TRuntime, TContext, TData>, \"localModules\" | \"moduleDefinitions\"> = {}\n) {\n const {\n startMsw,\n onError,\n context\n } = options;\n\n runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);\n\n runtime.moduleManager.registerModules(modulesDefinitions, { context })\n .then(results => {\n if (runtime.isMswEnabled) {\n if (!isFunction(startMsw)) {\n throw new Error(\"[squide] When MSW is enabled, the \\\"startMsw\\\" function must be provided.\");\n }\n\n startMsw(runtime)\n .then(() => {\n if (runtime.isMswEnabled) {\n runtime.getMswState().setAsReady();\n }\n })\n .catch((error: unknown) => {\n runtime.logger\n .withText(\"[squide] An error occured while starting MSW.\")\n .withError(error as Error)\n .error();\n });\n }\n\n if (onError) {\n results.forEach(error => {\n onError(error);\n });\n }\n });\n}\n\nlet hasExecuted = false;\n\n// Should only be used by tests.\nexport function __resetHasExecutedGuard() {\n hasExecuted = false;\n}\n\nexport function initializeFirefly<TContext = unknown, TData = unknown>(options: InitializeFireflyOptions<FireflyRuntime, TContext, TData> = {}) {\n const {\n mode,\n localModules = [],\n moduleDefinitions = [],\n useMsw,\n plugins = [],\n environmentVariables,\n honeycombInstrumentationClient,\n loggers,\n onError\n } = options;\n\n if (hasExecuted) {\n throw new Error(\"[squide] A squide application can only be initialized once. Did you call the \\\"initializeSquide\\\" function twice?\");\n }\n\n hasExecuted = true;\n\n if (useMsw) {\n plugins.push(x => new MswPlugin(x));\n }\n\n const runtime = new FireflyRuntime({\n mode,\n honeycombInstrumentationClient,\n loggers,\n plugins: [\n x => new EnvironmentVariablesPlugin(x, {\n variables: environmentVariables\n }),\n ...plugins\n ]\n });\n\n initializeHoneycomb(runtime)\n .catch((error: unknown) => {\n if (onError) {\n onError(error);\n }\n })\n .finally(() => {\n bootstrap(\n runtime,\n [...moduleDefinitions, ...toLocalModuleDefinitions(localModules)],\n options\n );\n });\n\n return runtime;\n}\n"],"names":["isFunction","toLocalModuleDefinitions","EnvironmentVariablesPlugin","MswPlugin","FireflyRuntime","initializeHoneycomb","ApplicationBootstrappingStartedEvent","bootstrap","runtime","modulesDefinitions","options","startMsw","onError","context","results","Error","error","hasExecuted","__resetHasExecutedGuard","initializeFirefly","mode","localModules","moduleDefinitions","useMsw","plugins","environmentVariables","honeycombInstrumentationClient","loggers","x"],"mappings":";;;;;;;;;;;;;;;;;AAAgJ;AAC5D;AAC5C;AAE0C;AACT;AAElE,MAAMM,uCAAuC,mCAAmC;AAgBhF,SAASC,UACZC,OAAiB,EACjBC,kBAAiE,EACjEC,UAA2G,CAAC,CAAC;IAE7G,MAAM,EACFC,QAAQ,EACRC,OAAO,EACPC,OAAO,EACV,GAAGH;IAEJF,QAAQ,QAAQ,CAAC,QAAQ,CAACF;IAE1BE,QAAQ,aAAa,CAAC,eAAe,CAACC,oBAAoB;QAAEI;IAAQ,GAC/D,IAAI,CAACC,CAAAA;QACF,IAAIN,QAAQ,YAAY,EAAE;YACtB,IAAI,CAACR,UAAUA,CAACW,WAAW;gBACvB,MAAM,IAAII,MAAM;YACpB;YAEAJ,SAASH,SACJ,IAAI,CAAC;gBACF,IAAIA,QAAQ,YAAY,EAAE;oBACtBA,QAAQ,WAAW,GAAG,UAAU;gBACpC;YACJ,GACC,KAAK,CAAC,CAACQ;gBACJR,QAAQ,MAAM,CACT,QAAQ,CAAC,iDACT,SAAS,CAACQ,OACV,KAAK;YACd;QACR;QAEA,IAAIJ,SAAS;YACTE,QAAQ,OAAO,CAACE,CAAAA;gBACZJ,QAAQI;YACZ;QACJ;IACJ;AACR;AAEA,IAAIC,cAAc;AAElB,gCAAgC;AACzB,SAASC;IACZD,cAAc;AAClB;AAEO,SAASE,kBAAuDT,UAAqE,CAAC,CAAC;IAC1I,MAAM,EACFU,IAAI,EACJC,eAAe,EAAE,EACjBC,oBAAoB,EAAE,EACtBC,MAAM,EACNC,UAAU,EAAE,EACZC,oBAAoB,EACpBC,8BAA8B,EAC9BC,OAAO,EACPf,OAAO,EACV,GAAGF;IAEJ,IAAIO,aAAa;QACb,MAAM,IAAIF,MAAM;IACpB;IAEAE,cAAc;IAEd,IAAIM,QAAQ;QACRC,QAAQ,IAAI,CAACI,CAAAA,IAAK,IAAIzB,SAASA,CAACyB;IACpC;IAEA,MAAMpB,UAAU,IAAIJ,cAAcA,CAAC;QAC/BgB;QACAM;QACAC;QACA,SAAS;YACLC,CAAAA,IAAK,IAAI1B,0BAA0BA,CAAC0B,GAAG;oBACnC,WAAWH;gBACf;eACGD;SACN;IACL;IAEAnB,mBAAmBA,CAACG,SACf,KAAK,CAAC,CAACQ;QACJ,IAAIJ,SAAS;YACTA,QAAQI;QACZ;IACJ,GACC,OAAO,CAAC;QACLT,UACIC,SACA;eAAIc;eAAsBrB,wBAAwBA,CAACoB;SAAc,EACjEX;IAER;IAEJ,OAAOF;AACX"}
@@ -1 +1,4 @@
1
- export declare function useIsActiveRouteProtected(areModulesReady: boolean): boolean;
1
+ export interface UseIsActiveRouteProtectedOptions {
2
+ throwWhenThereIsNoMatch?: boolean;
3
+ }
4
+ export declare function useIsActiveRouteProtected(areModulesReady: boolean, options?: UseIsActiveRouteProtectedOptions): boolean;
@@ -8,12 +8,13 @@ import { useLocation } from "react-router";
8
8
  ;// CONCATENATED MODULE: ./src/useIsActiveRouteProtected.ts
9
9
 
10
10
 
11
- function useIsActiveRouteProtected(areModulesReady) {
11
+ function useIsActiveRouteProtected(areModulesReady, options = {}) {
12
+ const { throwWhenThereIsNoMatch = true } = options;
12
13
  // Using this hook instead of window.location to retrieve the current location because it triggers a re-render everytime the browser location change.
13
14
  const location = useLocation();
14
15
  // Only throw when there's no match if the modules are ready, otherwise it's expected that no route will be found since they are not all registered yet.
15
16
  const activeRoute = useRouteMatch(location, {
16
- throwWhenThereIsNoMatch: areModulesReady
17
+ throwWhenThereIsNoMatch: throwWhenThereIsNoMatch && areModulesReady
17
18
  });
18
19
  return useIsRouteProtected(activeRoute);
19
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useIsActiveRouteProtected.js","sources":["../src/useIsActiveRouteProtected.ts"],"sourcesContent":["import { useIsRouteProtected, useRouteMatch } from \"@squide/react-router\";\nimport { useLocation } from \"react-router\";\n\nexport function useIsActiveRouteProtected(areModulesReady: boolean) {\n // Using this hook instead of window.location to retrieve the current location because it triggers a re-render everytime the browser location change.\n const location = useLocation();\n\n // Only throw when there's no match if the modules are ready, otherwise it's expected that no route will be found since they are not all registered yet.\n const activeRoute = useRouteMatch(location, { throwWhenThereIsNoMatch: areModulesReady });\n\n return useIsRouteProtected(activeRoute);\n}\n"],"names":["useIsRouteProtected","useRouteMatch","useLocation","useIsActiveRouteProtected","areModulesReady","location","activeRoute"],"mappings":";;;;;;;;AAA0E;AAC/B;AAEpC,SAASG,0BAA0BC,eAAwB;IAC9D,qJAAqJ;IACrJ,MAAMC,WAAWH,WAAWA;IAE5B,wJAAwJ;IACxJ,MAAMI,cAAcL,aAAaA,CAACI,UAAU;QAAE,yBAAyBD;IAAgB;IAEvF,OAAOJ,mBAAmBA,CAACM;AAC/B"}
1
+ {"version":3,"file":"useIsActiveRouteProtected.js","sources":["../src/useIsActiveRouteProtected.ts"],"sourcesContent":["import { useIsRouteProtected, useRouteMatch } from \"@squide/react-router\";\nimport { useLocation } from \"react-router\";\n\nexport interface UseIsActiveRouteProtectedOptions {\n throwWhenThereIsNoMatch?: boolean;\n}\n\nexport function useIsActiveRouteProtected(areModulesReady: boolean, options: UseIsActiveRouteProtectedOptions = {}) {\n const {\n throwWhenThereIsNoMatch = true\n } = options;\n\n // Using this hook instead of window.location to retrieve the current location because it triggers a re-render everytime the browser location change.\n const location = useLocation();\n\n // Only throw when there's no match if the modules are ready, otherwise it's expected that no route will be found since they are not all registered yet.\n const activeRoute = useRouteMatch(location, { throwWhenThereIsNoMatch: throwWhenThereIsNoMatch && areModulesReady });\n\n return useIsRouteProtected(activeRoute);\n}\n"],"names":["useIsRouteProtected","useRouteMatch","useLocation","useIsActiveRouteProtected","areModulesReady","options","throwWhenThereIsNoMatch","location","activeRoute"],"mappings":";;;;;;;;AAA0E;AAC/B;AAMpC,SAASG,0BAA0BC,eAAwB,EAAEC,UAA4C,CAAC,CAAC;IAC9G,MAAM,EACFC,0BAA0B,IAAI,EACjC,GAAGD;IAEJ,qJAAqJ;IACrJ,MAAME,WAAWL,WAAWA;IAE5B,wJAAwJ;IACxJ,MAAMM,cAAcP,aAAaA,CAACM,UAAU;QAAE,yBAAyBD,2BAA2BF;IAAgB;IAElH,OAAOJ,mBAAmBA,CAACQ;AAC/B"}
@@ -1 +1,4 @@
1
- export declare function useStrictRegistrationMode(): void;
1
+ export interface UseStrictRegistrationModeOptions {
2
+ isEnabled?: boolean;
3
+ }
4
+ export declare function useStrictRegistrationMode(options?: UseStrictRegistrationModeOptions): void;
@@ -14,17 +14,19 @@ function subscribeToModulesReady(runtime) {
14
14
  return ()=>runtime.moduleManager.removeModulesReadyListener(callback);
15
15
  };
16
16
  }
17
- function useStrictRegistrationMode() {
17
+ function useStrictRegistrationMode(options = {}) {
18
+ const { isEnabled = true } = options;
18
19
  const runtime = useRuntime();
19
20
  // This listener is only executed if the modules are ready.
20
21
  const areModulesReady = useSyncExternalStore(subscribeToModulesReady(runtime), ()=>runtime.moduleManager.getAreModulesReady());
21
22
  useEffect(()=>{
22
- if (areModulesReady) {
23
+ if (areModulesReady && isEnabled) {
23
24
  runtime._validateRegistrations();
24
25
  }
25
26
  }, [
26
27
  runtime,
27
- areModulesReady
28
+ areModulesReady,
29
+ isEnabled
28
30
  ]);
29
31
  }
30
32
 
@@ -1 +1 @@
1
- {"version":3,"file":"useStrictRegistrationMode.js","sources":["../src/useStrictRegistrationMode.ts"],"sourcesContent":["import { Runtime, useRuntime } from \"@squide/core\";\nimport { useEffect, useSyncExternalStore } from \"react\";\n\nfunction subscribeToModulesReady(runtime: Runtime) {\n return (callback: () => void) => {\n runtime.moduleManager.registerModulesReadyListener(callback);\n\n return () => runtime.moduleManager.removeModulesReadyListener(callback);\n };\n}\n\nexport function useStrictRegistrationMode() {\n const runtime = useRuntime();\n\n // This listener is only executed if the modules are ready.\n const areModulesReady = useSyncExternalStore(subscribeToModulesReady(runtime), () => runtime.moduleManager.getAreModulesReady());\n\n useEffect(() => {\n if (areModulesReady) {\n runtime._validateRegistrations();\n }\n }, [runtime, areModulesReady]);\n}\n"],"names":["useRuntime","useEffect","useSyncExternalStore","subscribeToModulesReady","runtime","callback","useStrictRegistrationMode","areModulesReady"],"mappings":";;;;;;;;AAAmD;AACK;AAExD,SAASG,wBAAwBC,OAAgB;IAC7C,OAAO,CAACC;QACJD,QAAQ,aAAa,CAAC,4BAA4B,CAACC;QAEnD,OAAO,IAAMD,QAAQ,aAAa,CAAC,0BAA0B,CAACC;IAClE;AACJ;AAEO,SAASC;IACZ,MAAMF,UAAUJ,UAAUA;IAE1B,2DAA2D;IAC3D,MAAMO,kBAAkBL,oBAAoBA,CAACC,wBAAwBC,UAAU,IAAMA,QAAQ,aAAa,CAAC,kBAAkB;IAE7HH,SAASA,CAAC;QACN,IAAIM,iBAAiB;YACjBH,QAAQ,sBAAsB;QAClC;IACJ,GAAG;QAACA;QAASG;KAAgB;AACjC"}
1
+ {"version":3,"file":"useStrictRegistrationMode.js","sources":["../src/useStrictRegistrationMode.ts"],"sourcesContent":["import { Runtime, useRuntime } from \"@squide/core\";\nimport { useEffect, useSyncExternalStore } from \"react\";\n\nfunction subscribeToModulesReady(runtime: Runtime) {\n return (callback: () => void) => {\n runtime.moduleManager.registerModulesReadyListener(callback);\n\n return () => runtime.moduleManager.removeModulesReadyListener(callback);\n };\n}\n\nexport interface UseStrictRegistrationModeOptions {\n isEnabled?: boolean;\n}\n\nexport function useStrictRegistrationMode(options: UseStrictRegistrationModeOptions = {}) {\n const {\n isEnabled = true\n } = options;\n\n const runtime = useRuntime();\n\n // This listener is only executed if the modules are ready.\n const areModulesReady = useSyncExternalStore(subscribeToModulesReady(runtime), () => runtime.moduleManager.getAreModulesReady());\n\n useEffect(() => {\n if (areModulesReady && isEnabled) {\n runtime._validateRegistrations();\n }\n }, [runtime, areModulesReady, isEnabled]);\n}\n"],"names":["useRuntime","useEffect","useSyncExternalStore","subscribeToModulesReady","runtime","callback","useStrictRegistrationMode","options","isEnabled","areModulesReady"],"mappings":";;;;;;;;AAAmD;AACK;AAExD,SAASG,wBAAwBC,OAAgB;IAC7C,OAAO,CAACC;QACJD,QAAQ,aAAa,CAAC,4BAA4B,CAACC;QAEnD,OAAO,IAAMD,QAAQ,aAAa,CAAC,0BAA0B,CAACC;IAClE;AACJ;AAMO,SAASC,0BAA0BC,UAA4C,CAAC,CAAC;IACpF,MAAM,EACFC,YAAY,IAAI,EACnB,GAAGD;IAEJ,MAAMH,UAAUJ,UAAUA;IAE1B,2DAA2D;IAC3D,MAAMS,kBAAkBP,oBAAoBA,CAACC,wBAAwBC,UAAU,IAAMA,QAAQ,aAAa,CAAC,kBAAkB;IAE7HH,SAASA,CAAC;QACN,IAAIQ,mBAAmBD,WAAW;YAC9BJ,QAAQ,sBAAsB;QAClC;IACJ,GAAG;QAACA;QAASK;QAAiBD;KAAU;AAC5C"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@squide/firefly",
3
3
  "author": "Workleap",
4
- "version": "16.0.0",
5
- "description": "Helpers to facilitate the creation of an application with the Squide firefly technology stack.",
4
+ "version": "16.0.2",
5
+ "description": "Squide bundle for the firefly technology stack.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -39,13 +39,19 @@
39
39
  "react-dom": "^18.0.0 || ^19.0.0",
40
40
  "react-router": "^7.9.6"
41
41
  },
42
+ "peerDependenciesMeta": {
43
+ "@opentelemetry/api": {
44
+ "optional": true
45
+ }
46
+ },
42
47
  "dependencies": {
43
48
  "@workleap-telemetry/core": "^1.0.4",
44
49
  "@workleap/logging": "^1.3.2",
45
50
  "uuid": "^13.0.0",
46
- "@squide/core": "6.1.4",
47
- "@squide/msw": "4.0.5",
48
- "@squide/react-router": "8.1.4"
51
+ "@squide/core": "6.1.5",
52
+ "@squide/env-vars": "1.4.8",
53
+ "@squide/msw": "4.0.6",
54
+ "@squide/react-router": "8.1.5"
49
55
  },
50
56
  "devDependencies": {
51
57
  "@eslint/js": "9.39.1",
package/src/AppRouter.tsx CHANGED
@@ -27,7 +27,7 @@ export function useCanRenderRouter({ areModulesRegistered, areModulesReady: areM
27
27
  );
28
28
  }
29
29
 
30
- function useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction) {
30
+ function useRenderRouterProvider(state: AppRouterState, renderRouterProvider: RenderRouterProviderFunction, strictMode: boolean) {
31
31
  const routes = useRoutes();
32
32
 
33
33
  // The value is computed outside of the router provider memo to prevent
@@ -37,19 +37,20 @@ function useRenderRouterProvider(state: AppRouterState, renderRouterProvider: Re
37
37
  return useMemo(() => {
38
38
  if (canRenderRouter) {
39
39
  return renderRouterProvider({
40
- rootRoute: <RootRoute />,
40
+ rootRoute: <RootRoute strictMode={strictMode} />,
41
41
  registeredRoutes: routes,
42
42
  routerProviderProps: {}
43
43
  });
44
44
  }
45
45
 
46
46
  return null;
47
- }, [canRenderRouter, routes, renderRouterProvider]);
47
+ }, [canRenderRouter, routes, renderRouterProvider, strictMode]);
48
48
  }
49
49
 
50
50
  export interface AppRouterProps {
51
51
  waitForPublicData?: boolean;
52
52
  waitForProtectedData?: boolean;
53
+ strictMode?: boolean;
53
54
  children: RenderRouterProviderFunction;
54
55
  }
55
56
 
@@ -57,13 +58,16 @@ export function AppRouter(props: AppRouterProps) {
57
58
  const {
58
59
  waitForPublicData = false,
59
60
  waitForProtectedData = false,
61
+ strictMode = true,
60
62
  children: renderRouterProvider
61
63
  } = props;
62
64
  const [state, dispatch] = useAppRouterReducer(waitForPublicData, waitForProtectedData);
63
65
 
64
66
  const logger = useLogger();
65
67
 
66
- useStrictRegistrationMode();
68
+ useStrictRegistrationMode({
69
+ isEnabled: strictMode
70
+ });
67
71
 
68
72
  useEffect(() => {
69
73
  logger
@@ -72,7 +76,7 @@ export function AppRouter(props: AppRouterProps) {
72
76
  .debug();
73
77
  }, [state, logger]);
74
78
 
75
- const routerProvider = useRenderRouterProvider(state, renderRouterProvider);
79
+ const routerProvider = useRenderRouterProvider(state, renderRouterProvider, strictMode);
76
80
 
77
81
  return (
78
82
  <AppRouterDispatcherContext.Provider value={dispatch}>
@@ -1,5 +1,6 @@
1
1
  import type { RegisterRouteOptions, RuntimeMethodOptions, RuntimeOptions } from "@squide/core";
2
- import { MswPlugin, MswPluginName, MswState } from "@squide/msw";
2
+ import { EnvironmentVariableKey, EnvironmentVariables, EnvironmentVariableValue, getEnvironmentVariablesPlugin } from "@squide/env-vars";
3
+ import { getMswPlugin, MswPluginName, MswState } from "@squide/msw";
3
4
  import { type IReactRouterRuntime, ReactRouterRuntime, ReactRouterRuntimeScope, type Route } from "@squide/react-router";
4
5
  import type { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
5
6
  import type { Logger } from "@workleap/logging";
@@ -16,8 +17,12 @@ export interface IFireflyRuntime extends IReactRouterRuntime {
16
17
  getMswState(): MswState;
17
18
  registerRequestHandlers: (handlers: RequestHandler[]) => void;
18
19
  get requestHandlers(): RequestHandler[];
19
- get appRouterStore(): AppRouterStore;
20
20
  get isMswEnabled(): boolean;
21
+ registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
22
+ registerEnvironmentVariables(variables: Partial<EnvironmentVariables>): void;
23
+ getEnvironmentVariable(key: EnvironmentVariableKey): EnvironmentVariableValue;
24
+ getEnvironmentVariables(): EnvironmentVariables;
25
+ get appRouterStore(): AppRouterStore;
21
26
  get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient | undefined;
22
27
  }
23
28
 
@@ -26,65 +31,81 @@ export class FireflyRuntime<TRuntime extends FireflyRuntime = any> extends React
26
31
  protected _appRouterStore: AppRouterStore;
27
32
  protected _honeycombInstrumentationClient: HoneycombInstrumentationPartialClient | undefined;
28
33
 
29
- constructor({ honeycombInstrumentationClient, ...options }: FireflyRuntimeOptions = {}) {
34
+ constructor(options: FireflyRuntimeOptions = {}) {
35
+ const {
36
+ honeycombInstrumentationClient
37
+ } = options;
38
+
30
39
  super(options);
31
40
 
32
41
  this._appRouterStore = createAppRouterStore(this._logger);
33
42
  this._honeycombInstrumentationClient = honeycombInstrumentationClient;
34
43
  }
35
44
 
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?");
45
+ registerRoute(route: Route, options: RegisterRouteOptions = {}) {
46
+ if (this.moduleManager.getAreModulesRegistered()) {
47
+ 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.");
41
48
  }
42
49
 
43
- return mswPlugin.mswState;
50
+ super.registerRoute(route, options);
51
+ }
52
+
53
+ getMswState() {
54
+ const plugin = getMswPlugin(this);
55
+
56
+ return plugin.mswState;
44
57
  }
45
58
 
46
59
  registerRequestHandlers(handlers: RequestHandler[], options: RegisterRequestHandlersOptions = {}) {
47
60
  const logger = this._getLogger(options);
48
- const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;
49
-
50
- if (!mswPlugin) {
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?");
52
- }
61
+ const plugin = getMswPlugin(this);
53
62
 
54
63
  if (this.moduleManager.getAreModulesRegistered()) {
55
64
  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.");
56
65
  }
57
66
 
58
- mswPlugin.registerRequestHandlers(handlers, {
67
+ plugin.registerRequestHandlers(handlers, {
59
68
  logger
60
69
  });
61
70
  }
62
71
 
63
72
  // Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
64
73
  get requestHandlers(): RequestHandler[] {
65
- const mswPlugin = this.getPlugin(MswPluginName) as MswPlugin;
74
+ const plugin = getMswPlugin(this);
66
75
 
67
- if (!mswPlugin) {
68
- throw new Error("[squide] Cannot retrieve MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the \"useMsw\" option?");
69
- }
76
+ return plugin.requestHandlers;
77
+ }
70
78
 
71
- return mswPlugin.requestHandlers;
79
+ get isMswEnabled() {
80
+ return this._plugins.some(x => x.name === MswPluginName);
72
81
  }
73
82
 
74
- registerRoute(route: Route, options: RegisterRouteOptions = {}) {
75
- if (this.moduleManager.getAreModulesRegistered()) {
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.");
77
- }
83
+ getEnvironmentVariable(key: EnvironmentVariableKey) {
84
+ const plugin = getEnvironmentVariablesPlugin(this);
78
85
 
79
- super.registerRoute(route, options);
86
+ return plugin.getVariable(key);
80
87
  }
81
88
 
82
- get appRouterStore() {
83
- return this._appRouterStore;
89
+ getEnvironmentVariables() {
90
+ const plugin = getEnvironmentVariablesPlugin(this);
91
+
92
+ return plugin.getVariables();
84
93
  }
85
94
 
86
- get isMswEnabled() {
87
- return this._plugins.some(x => x.name === MswPluginName);
95
+ registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {
96
+ const plugin = getEnvironmentVariablesPlugin(this);
97
+
98
+ return plugin.registerVariable(key, value);
99
+ }
100
+
101
+ registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {
102
+ const plugin = getEnvironmentVariablesPlugin(this);
103
+
104
+ return plugin.registerVariables(variables);
105
+ }
106
+
107
+ get appRouterStore() {
108
+ return this._appRouterStore;
88
109
  }
89
110
 
90
111
  get honeycombInstrumentationClient() {
@@ -113,14 +134,30 @@ export class FireflyRuntimeScope<TRuntime extends FireflyRuntime = FireflyRuntim
113
134
  return this._runtime.requestHandlers;
114
135
  }
115
136
 
116
- get appRouterStore(): AppRouterStore {
117
- throw new Error("[squide] Cannot retrieve the app router store from a runtime scope instance.");
118
- }
119
-
120
137
  get isMswEnabled() {
121
138
  return this._runtime.isMswEnabled;
122
139
  }
123
140
 
141
+ getEnvironmentVariables() {
142
+ return this._runtime.getEnvironmentVariables();
143
+ }
144
+
145
+ getEnvironmentVariable(key: EnvironmentVariableKey) {
146
+ return this._runtime.getEnvironmentVariable(key);
147
+ }
148
+
149
+ registerEnvironmentVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {
150
+ this._runtime.registerEnvironmentVariable(key, value);
151
+ }
152
+
153
+ registerEnvironmentVariables(variables: Partial<EnvironmentVariables>) {
154
+ this._runtime.registerEnvironmentVariables(variables);
155
+ }
156
+
157
+ get appRouterStore(): AppRouterStore {
158
+ throw new Error("[squide] Cannot retrieve the app router store from a runtime scope instance.");
159
+ }
160
+
124
161
  get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient {
125
162
  throw new Error("[squide] Cannot retrieve the Honeycomb instrumentation client from a runtime scope instance.");
126
163
  }
package/src/RootRoute.tsx CHANGED
@@ -3,9 +3,20 @@ import { Outlet } from "react-router";
3
3
  import { useAppRouterDispatcher, useAppRouterState } from "./AppRouterContext.ts";
4
4
  import { useIsActiveRouteProtected } from "./useIsActiveRouteProtected.ts";
5
5
 
6
- export function RootRoute() {
6
+ export interface RootRouteProps {
7
+ strictMode?: boolean;
8
+ }
9
+
10
+ export function RootRoute(props: RootRouteProps) {
11
+ const {
12
+ strictMode = true
13
+ } = props;
14
+
7
15
  const state = useAppRouterState();
8
- const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady);
16
+
17
+ const isActiveRouteProtected = useIsActiveRouteProtected(state.areModulesReady, {
18
+ throwWhenThereIsNoMatch: strictMode
19
+ });
9
20
 
10
21
  const dispatch = useAppRouterDispatcher();
11
22
 
package/src/index.ts CHANGED
@@ -1,5 +1,25 @@
1
1
  export * from "@squide/core";
2
- export * from "@squide/msw";
2
+ export {
3
+ EnvironmentVariablesPlugin,
4
+ EnvironmentVariablesPluginName,
5
+ getEnvironmentVariablesPlugin,
6
+ useEnvironmentVariable,
7
+ useEnvironmentVariables,
8
+ type EnvironmentVariableKey,
9
+ type EnvironmentVariables,
10
+ type EnvironmentVariablesPluginOptions,
11
+ type EnvironmentVariableValue
12
+ } from "@squide/env-vars";
13
+ export {
14
+ getMswPlugin,
15
+ MswPlugin,
16
+ MswPluginName,
17
+ MswState,
18
+ type MswPluginOptions,
19
+ type MswPluginRegisterRequestHandlersOptions,
20
+ type MswReadyListener,
21
+ type MswStateOptions
22
+ } from "@squide/msw";
3
23
  export * from "@squide/react-router";
4
24
 
5
25
  export type { FireflyPlugin } from "./FireflyPlugin.ts";
@@ -1,4 +1,5 @@
1
1
  import { isFunction, ModuleDefinition, toLocalModuleDefinitions, type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
2
+ import { EnvironmentVariables, EnvironmentVariablesPlugin } from "@squide/env-vars";
2
3
  import { MswPlugin } from "@squide/msw";
3
4
  import type { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
4
5
  import { FireflyRuntime, type FireflyRuntimeOptions } from "./FireflyRuntime.tsx";
@@ -14,6 +15,7 @@ export interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TCont
14
15
  localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
15
16
  moduleDefinitions?: ModuleDefinition<TRuntime, TContext, TData>[];
16
17
  useMsw?: boolean;
18
+ environmentVariables?: Partial<EnvironmentVariables>;
17
19
  honeycombInstrumentationClient?: HoneycombInstrumentationPartialClient;
18
20
  startMsw?: StartMswFunction<FireflyRuntime>;
19
21
  onError?: OnInitializationErrorFunction;
@@ -75,6 +77,7 @@ export function initializeFirefly<TContext = unknown, TData = unknown>(options:
75
77
  moduleDefinitions = [],
76
78
  useMsw,
77
79
  plugins = [],
80
+ environmentVariables,
78
81
  honeycombInstrumentationClient,
79
82
  loggers,
80
83
  onError
@@ -94,7 +97,12 @@ export function initializeFirefly<TContext = unknown, TData = unknown>(options:
94
97
  mode,
95
98
  honeycombInstrumentationClient,
96
99
  loggers,
97
- plugins
100
+ plugins: [
101
+ x => new EnvironmentVariablesPlugin(x, {
102
+ variables: environmentVariables
103
+ }),
104
+ ...plugins
105
+ ]
98
106
  });
99
107
 
100
108
  initializeHoneycomb(runtime)
@@ -1,12 +1,20 @@
1
1
  import { useIsRouteProtected, useRouteMatch } from "@squide/react-router";
2
2
  import { useLocation } from "react-router";
3
3
 
4
- export function useIsActiveRouteProtected(areModulesReady: boolean) {
4
+ export interface UseIsActiveRouteProtectedOptions {
5
+ throwWhenThereIsNoMatch?: boolean;
6
+ }
7
+
8
+ export function useIsActiveRouteProtected(areModulesReady: boolean, options: UseIsActiveRouteProtectedOptions = {}) {
9
+ const {
10
+ throwWhenThereIsNoMatch = true
11
+ } = options;
12
+
5
13
  // Using this hook instead of window.location to retrieve the current location because it triggers a re-render everytime the browser location change.
6
14
  const location = useLocation();
7
15
 
8
16
  // Only throw when there's no match if the modules are ready, otherwise it's expected that no route will be found since they are not all registered yet.
9
- const activeRoute = useRouteMatch(location, { throwWhenThereIsNoMatch: areModulesReady });
17
+ const activeRoute = useRouteMatch(location, { throwWhenThereIsNoMatch: throwWhenThereIsNoMatch && areModulesReady });
10
18
 
11
19
  return useIsRouteProtected(activeRoute);
12
20
  }
@@ -9,15 +9,23 @@ function subscribeToModulesReady(runtime: Runtime) {
9
9
  };
10
10
  }
11
11
 
12
- export function useStrictRegistrationMode() {
12
+ export interface UseStrictRegistrationModeOptions {
13
+ isEnabled?: boolean;
14
+ }
15
+
16
+ export function useStrictRegistrationMode(options: UseStrictRegistrationModeOptions = {}) {
17
+ const {
18
+ isEnabled = true
19
+ } = options;
20
+
13
21
  const runtime = useRuntime();
14
22
 
15
23
  // This listener is only executed if the modules are ready.
16
24
  const areModulesReady = useSyncExternalStore(subscribeToModulesReady(runtime), () => runtime.moduleManager.getAreModulesReady());
17
25
 
18
26
  useEffect(() => {
19
- if (areModulesReady) {
27
+ if (areModulesReady && isEnabled) {
20
28
  runtime._validateRegistrations();
21
29
  }
22
- }, [runtime, areModulesReady]);
30
+ }, [runtime, areModulesReady, isEnabled]);
23
31
  }