@squide/firefly 11.0.0 → 12.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,25 @@
1
1
  import { useAppRouterState } from "./AppRouterContext.ts";
2
+ import type { ActiveRouteVisiblity } from "./AppRouterReducer.ts";
3
+
4
+ // This function is exported for external integration, like the integration
5
+ // with the Platform Widgets. Do not remove.
6
+ export function canFetchProtectedData(
7
+ waitForMsw: boolean,
8
+ areModulesRegistered: boolean,
9
+ areModulesReady: boolean,
10
+ activeRouteVisibility: ActiveRouteVisiblity,
11
+ isMswReady: boolean
12
+ ) {
13
+ return (
14
+ // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
15
+ // depends on the protected data.
16
+ (areModulesRegistered || areModulesReady)
17
+ // Only fetch the protected data for protected routes, aka do not fetch the protected data for public routes.
18
+ && activeRouteVisibility === "protected"
19
+ // Wait for MSW since the endpoints for the protected data might be an MSW endpoint when in development.
20
+ && (!waitForMsw || isMswReady)
21
+ );
22
+ }
2
23
 
3
24
  export function useCanFetchProtectedData() {
4
25
  const {
@@ -10,17 +31,12 @@ export function useCanFetchProtectedData() {
10
31
  activeRouteVisibility
11
32
  } = useAppRouterState();
12
33
 
13
- return (
14
- // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
15
- isProtectedDataReady
16
- || (
17
- // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
18
- // depends on the protected data.
19
- (areModulesRegistered || areModulesReady)
20
- // Only fetch the protected data for protected routes, aka do not fetch the protected data for public routes.
21
- && activeRouteVisibility === "protected"
22
- // Wait for MSW since the endpoints for the protected data might be an MSW endpoint when in development.
23
- && (!waitForMsw || isMswReady)
24
- )
34
+ // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
35
+ return isProtectedDataReady || canFetchProtectedData(
36
+ waitForMsw,
37
+ areModulesRegistered,
38
+ areModulesReady,
39
+ activeRouteVisibility,
40
+ isMswReady
25
41
  );
26
42
  }
@@ -1,14 +0,0 @@
1
- import { type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
2
- import { type RemoteDefinition } from "@squide/module-federation";
3
- import type { FireflyRuntime } from "./FireflyRuntime.tsx";
4
- export declare const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
5
- export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
6
- export type OnBootstrapErrorFunction = (error: unknown) => void;
7
- export interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {
8
- localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
9
- remotes?: RemoteDefinition[];
10
- startMsw?: StartMswFunction<TRuntime>;
11
- onError?: OnBootstrapErrorFunction;
12
- }
13
- export declare function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options?: BootstrapAppOptions<TRuntime, TContext, TData>): void;
14
- export declare function __resetHasExecuteGuard(): void;
@@ -1 +0,0 @@
1
- {"version":3,"file":"boostrap.js","sources":["webpack://@squide/firefly/./src/boostrap.ts"],"sourcesContent":["import { isFunction, registerLocalModules, type ModuleRegisterFunction, type RegisterModulesOptions } from \"@squide/core\";\nimport { registerRemoteModules, type RemoteDefinition } from \"@squide/module-federation\";\nimport { setMswAsReady } from \"@squide/msw\";\nimport type { FireflyRuntime } from \"./FireflyRuntime.tsx\";\n\nexport const ApplicationBootstrappingStartedEvent = \"squide-app-bootstrapping-started\";\n\nexport type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;\n\nexport type OnBootstrapErrorFunction = (error: unknown) => void;\n\nexport interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {\n localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];\n remotes?: RemoteDefinition[];\n startMsw?: StartMswFunction<TRuntime>;\n onError?: OnBootstrapErrorFunction;\n}\n\nfunction propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError: OnBootstrapErrorFunction) {\n if (results) {\n if (results.status === \"fulfilled\") {\n results.value.forEach(x => {\n onError(x);\n });\n }\n }\n}\n\nlet hasExecuted = false;\n\nexport function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: BootstrapAppOptions<TRuntime, TContext, TData> = {}) {\n const {\n localModules = [],\n remotes = [],\n context,\n startMsw,\n onError\n } = options;\n\n if (hasExecuted) {\n throw new Error(\"[squide] A squide application can only be bootstrapped once. Did you call the \\\"bootstrap\\\" function twice?\");\n }\n\n hasExecuted = true;\n\n runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);\n\n Promise.allSettled([\n registerLocalModules<TRuntime, TContext, TData>(localModules, runtime, { context }),\n registerRemoteModules(remotes, runtime, { 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 setMswAsReady();\n })\n .catch((error: unknown) => {\n runtime.logger.debug(\"[squide] An error occured while starting MSW.\", error);\n });\n }\n\n if (onError) {\n propagateRegistrationErrors(results[0], onError);\n propagateRegistrationErrors(results[1], onError);\n }\n });\n}\n\nexport function __resetHasExecuteGuard() {\n hasExecuted = false;\n}\n"],"names":["isFunction","registerLocalModules","registerRemoteModules","setMswAsReady","ApplicationBootstrappingStartedEvent","propagateRegistrationErrors","results","onError","x","hasExecuted","bootstrap","runtime","options","localModules","remotes","context","startMsw","Error","Promise","error","__resetHasExecuteGuard"],"mappings":";;;;;;;;;;;AAA0H;AACjC;AAC7C;AAGrC,MAAMI,uCAAuC,mCAAmC;AAavF,SAASC,4BAA4BC,OAAwC,EAAEC,OAAiC;IAC5G,IAAID,SAAS;QACT,IAAIA,QAAQ,MAAM,KAAK,aAAa;YAChCA,QAAQ,KAAK,CAAC,OAAO,CAACE,CAAAA;gBAClBD,QAAQC;YACZ;QACJ;IACJ;AACJ;AAEA,IAAIC,cAAc;AAEX,SAASC,UAAiGC,OAAiB,EAAEC,UAA0D,CAAC,CAAC;IAC5L,MAAM,EACFC,eAAe,EAAE,EACjBC,UAAU,EAAE,EACZC,OAAO,EACPC,QAAQ,EACRT,OAAO,EACV,GAAGK;IAEJ,IAAIH,aAAa;QACb,MAAM,IAAIQ,MAAM;IACpB;IAEAR,cAAc;IAEdE,QAAQ,QAAQ,CAAC,QAAQ,CAACP;IAE1Bc,QAAQ,UAAU,CAAC;QACfjB,0EAAoBA,CAA4BY,cAAcF,SAAS;YAAEI;QAAQ;QACjFb,wFAAqBA,CAACY,SAASH,SAAS;YAAEI;QAAQ;KACrD,EAAE,IAAI,CAACT,CAAAA;QACJ,IAAIK,QAAQ,YAAY,EAAE;YACtB,IAAI,CAACX,gEAAUA,CAACgB,WAAW;gBACvB,MAAM,IAAIC,MAAM;YACpB;YAEAD,SAASL,SACJ,IAAI,CAAC;gBACFR,kEAAaA;YACjB,GACC,KAAK,CAAC,CAACgB;gBACJR,QAAQ,MAAM,CAAC,KAAK,CAAC,iDAAiDQ;YAC1E;QACR;QAEA,IAAIZ,SAAS;YACTF,4BAA4BC,OAAO,CAAC,EAAE,EAAEC;YACxCF,4BAA4BC,OAAO,CAAC,EAAE,EAAEC;QAC5C;IACJ;AACJ;AAEO,SAASa;IACZX,cAAc;AAClB"}