zudoku 0.0.0-z6bcd96da → 0.0.0-z7b86faab

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,15 +1,16 @@
1
- const e = (n) => n, t = (n) => n, i = (n) => "events" in n && typeof n.events == "object", o = (n) => "getProfileMenuItems" in n && typeof n.getProfileMenuItems == "function", s = (n) => "getRoutes" in n && typeof n.getRoutes == "function", c = (n) => "signUp" in n && typeof n.signUp == "function", u = (n) => "renderSearch" in n && typeof n.renderSearch == "function", g = (n) => "initialize" in n && typeof n.initialize == "function", f = (n) => "getHead" in n && typeof n.getHead == "function", r = (n) => "getMdxComponents" in n && typeof n.getMdxComponents == "function", a = (n) => "getIdentities" in n && typeof n.getIdentities == "function";
1
+ const t = (n) => n, i = (n) => n, e = (n) => "events" in n && typeof n.events == "object", o = (n) => "getProfileMenuItems" in n && typeof n.getProfileMenuItems == "function", s = (n) => "getRoutes" in n && typeof n.getRoutes == "function", f = (n) => "signUp" in n && typeof n.signUp == "function", c = (n) => "renderSearch" in n && typeof n.renderSearch == "function", u = (n) => "initialize" in n && typeof n.initialize == "function", g = (n) => "getHead" in n && typeof n.getHead == "function", r = (n) => "getMdxComponents" in n && typeof n.getMdxComponents == "function", a = (n) => "getIdentities" in n && typeof n.getIdentities == "function", l = (n) => "transformConfig" in n && typeof n.transformConfig == "function";
2
2
  export {
3
- e as createApiIdentityPlugin,
4
- t as createProfileMenuPlugin,
5
- f as hasHead,
3
+ t as createApiIdentityPlugin,
4
+ i as createProfileMenuPlugin,
5
+ g as hasHead,
6
6
  a as isApiIdentityPlugin,
7
- c as isAuthenticationPlugin,
8
- i as isEventConsumerPlugin,
7
+ f as isAuthenticationPlugin,
8
+ e as isEventConsumerPlugin,
9
9
  r as isMdxProviderPlugin,
10
10
  s as isNavigationPlugin,
11
11
  o as isProfileMenuPlugin,
12
- u as isSearchPlugin,
13
- g as needsInitialization
12
+ c as isSearchPlugin,
13
+ l as isTransformConfigPlugin,
14
+ u as needsInitialization
14
15
  };
15
16
  //# sourceMappingURL=zudoku.plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"zudoku.plugins.js","sources":["../src/lib/core/plugins.ts"],"sourcesContent":["import type { LucideIcon } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\nimport type { Location, RouteObject } from \"react-router\";\nimport type { Navigation } from \"../../config/validators/NavigationSchema.js\";\nimport type { ProtectedRoutesInput } from \"../../config/validators/ProtectedRoutesSchema.js\";\nimport type { AuthenticationPlugin } from \"../authentication/authentication.js\";\nimport type { MdxComponentsType } from \"../util/MdxComponents.js\";\nimport type {\n ApiIdentity,\n ZudokuContext,\n ZudokuEvents,\n} from \"./ZudokuContext.js\";\n\nexport type ZudokuPlugin =\n | CommonPlugin\n | ProfileMenuPlugin\n | NavigationPlugin\n | ApiIdentityPlugin\n | SearchProviderPlugin\n | EventConsumerPlugin\n | AuthenticationPlugin;\n\nexport type { AuthenticationPlugin, RouteObject };\n\nexport interface NavigationPlugin {\n getRoutes: () => RouteObject[];\n getNavigation?: (path: string, context: ZudokuContext) => Promise<Navigation>;\n getProtectedRoutes?: () => ProtectedRoutesInput;\n}\n\nexport const createApiIdentityPlugin = (\n plugin: ApiIdentityPlugin,\n): ApiIdentityPlugin => plugin;\n\nexport const createProfileMenuPlugin = (\n plugin: ProfileMenuPlugin,\n): ProfileMenuPlugin => plugin;\n\nexport interface ApiIdentityPlugin {\n getIdentities: (context: ZudokuContext) => Promise<ApiIdentity[]>;\n}\n\nexport interface SearchProviderPlugin {\n renderSearch: (o: {\n isOpen: boolean;\n onClose: () => void;\n }) => React.JSX.Element | null;\n}\n\nexport interface ProfileMenuPlugin {\n getProfileMenuItems: (context: ZudokuContext) => ProfileNavigationItem[];\n}\n\nexport type ProfileNavigationItem = {\n label: string;\n path?: string;\n weight?: number;\n category?: \"top\" | \"middle\" | \"bottom\";\n children?: ProfileNavigationItem[];\n icon?: LucideIcon;\n};\n\nexport interface CommonPlugin {\n initialize?: (\n context: ZudokuContext,\n ) => Promise<void | boolean> | void | boolean;\n getHead?: (args: { location: Location }) => ReactNode | undefined;\n getMdxComponents?: () => MdxComponentsType;\n}\n\nexport type EventConsumerPlugin<Event extends ZudokuEvents = ZudokuEvents> = {\n events: { [K in keyof Event]?: Event[K] };\n};\n\nexport const isEventConsumerPlugin = (\n obj: ZudokuPlugin,\n): obj is EventConsumerPlugin =>\n \"events\" in obj && typeof obj.events === \"object\";\n\nexport const isProfileMenuPlugin = (\n obj: ZudokuPlugin,\n): obj is ProfileMenuPlugin =>\n \"getProfileMenuItems\" in obj && typeof obj.getProfileMenuItems === \"function\";\n\nexport const isNavigationPlugin = (\n obj: ZudokuPlugin,\n): obj is NavigationPlugin =>\n \"getRoutes\" in obj && typeof obj.getRoutes === \"function\";\n\nexport const isAuthenticationPlugin = (\n obj: ZudokuPlugin,\n): obj is AuthenticationPlugin =>\n \"signUp\" in obj && typeof obj.signUp === \"function\";\n\nexport const isSearchPlugin = (\n obj: ZudokuPlugin,\n): obj is SearchProviderPlugin =>\n \"renderSearch\" in obj && typeof obj.renderSearch === \"function\";\n\nexport const needsInitialization = (obj: ZudokuPlugin): obj is CommonPlugin =>\n \"initialize\" in obj && typeof obj.initialize === \"function\";\n\nexport const hasHead = (obj: ZudokuPlugin): obj is CommonPlugin =>\n \"getHead\" in obj && typeof obj.getHead === \"function\";\n\nexport const isMdxProviderPlugin = (obj: ZudokuPlugin): obj is CommonPlugin =>\n \"getMdxComponents\" in obj && typeof obj.getMdxComponents === \"function\";\n\nexport const isApiIdentityPlugin = (\n obj: ZudokuPlugin,\n): obj is ApiIdentityPlugin =>\n \"getIdentities\" in obj && typeof obj.getIdentities === \"function\";\n"],"names":["createApiIdentityPlugin","plugin","createProfileMenuPlugin","isEventConsumerPlugin","obj","isProfileMenuPlugin","isNavigationPlugin","isAuthenticationPlugin","isSearchPlugin","needsInitialization","hasHead","isMdxProviderPlugin","isApiIdentityPlugin"],"mappings":"AA8BO,MAAMA,IAA0B,CACrCC,MACsBA,GAEXC,IAA0B,CACrCD,MACsBA,GAsCXE,IAAwB,CACnCC,MAEA,YAAYA,KAAO,OAAOA,EAAI,UAAW,UAE9BC,IAAsB,CACjCD,MAEA,yBAAyBA,KAAO,OAAOA,EAAI,uBAAwB,YAExDE,IAAqB,CAChCF,MAEA,eAAeA,KAAO,OAAOA,EAAI,aAAc,YAEpCG,IAAyB,CACpCH,MAEA,YAAYA,KAAO,OAAOA,EAAI,UAAW,YAE9BI,IAAiB,CAC5BJ,MAEA,kBAAkBA,KAAO,OAAOA,EAAI,gBAAiB,YAE1CK,IAAsB,CAACL,MAClC,gBAAgBA,KAAO,OAAOA,EAAI,cAAe,YAEtCM,IAAU,CAACN,MACtB,aAAaA,KAAO,OAAOA,EAAI,WAAY,YAEhCO,IAAsB,CAACP,MAClC,sBAAsBA,KAAO,OAAOA,EAAI,oBAAqB,YAElDQ,IAAsB,CACjCR,MAEA,mBAAmBA,KAAO,OAAOA,EAAI,iBAAkB;"}
1
+ {"version":3,"file":"zudoku.plugins.js","sources":["../src/lib/core/plugins.ts"],"sourcesContent":["import type { LucideIcon } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\nimport type { Location, RouteObject } from \"react-router\";\nimport type { Navigation } from \"../../config/validators/NavigationSchema.js\";\nimport type { ProtectedRoutesInput } from \"../../config/validators/ProtectedRoutesSchema.js\";\nimport type { ZudokuConfig } from \"../../config/validators/validate.js\";\nimport type { AuthenticationPlugin } from \"../authentication/authentication.js\";\nimport type { MdxComponentsType } from \"../util/MdxComponents.js\";\nimport type {\n ApiIdentity,\n ZudokuContext,\n ZudokuEvents,\n} from \"./ZudokuContext.js\";\n\nexport type ZudokuPlugin =\n | CommonPlugin\n | ProfileMenuPlugin\n | NavigationPlugin\n | ApiIdentityPlugin\n | SearchProviderPlugin\n | EventConsumerPlugin\n | AuthenticationPlugin\n | TransformConfigPlugin;\n\nexport type { AuthenticationPlugin, RouteObject };\n\nexport interface NavigationPlugin {\n getRoutes: () => RouteObject[];\n getNavigation?: (path: string, context: ZudokuContext) => Promise<Navigation>;\n getProtectedRoutes?: () => ProtectedRoutesInput;\n}\n\nexport const createApiIdentityPlugin = (\n plugin: ApiIdentityPlugin,\n): ApiIdentityPlugin => plugin;\n\nexport const createProfileMenuPlugin = (\n plugin: ProfileMenuPlugin,\n): ProfileMenuPlugin => plugin;\n\nexport interface ApiIdentityPlugin {\n getIdentities: (context: ZudokuContext) => Promise<ApiIdentity[]>;\n}\n\nexport interface SearchProviderPlugin {\n renderSearch: (o: {\n isOpen: boolean;\n onClose: () => void;\n }) => React.JSX.Element | null;\n}\n\nexport interface ProfileMenuPlugin {\n getProfileMenuItems: (context: ZudokuContext) => ProfileNavigationItem[];\n}\n\nexport type ProfileNavigationItem = {\n label: string;\n path?: string;\n weight?: number;\n category?: \"top\" | \"middle\" | \"bottom\";\n children?: ProfileNavigationItem[];\n icon?: LucideIcon;\n};\n\nexport interface ConfigHookContext {\n mode: typeof process.env.ZUDOKU_ENV;\n rootDir: string;\n configPath: string;\n}\n\nexport interface TransformConfigPlugin {\n transformConfig?: (\n config: ZudokuConfig,\n ctx: ConfigHookContext,\n ) => Partial<ZudokuConfig> | void | Promise<Partial<ZudokuConfig> | void>;\n}\n\nexport interface CommonPlugin {\n initialize?: (\n context: ZudokuContext,\n ) => Promise<void | boolean> | void | boolean;\n getHead?: (args: { location: Location }) => ReactNode | undefined;\n getMdxComponents?: () => MdxComponentsType;\n}\n\nexport type EventConsumerPlugin<Event extends ZudokuEvents = ZudokuEvents> = {\n events: { [K in keyof Event]?: Event[K] };\n};\n\nexport const isEventConsumerPlugin = (\n obj: ZudokuPlugin,\n): obj is EventConsumerPlugin =>\n \"events\" in obj && typeof obj.events === \"object\";\n\nexport const isProfileMenuPlugin = (\n obj: ZudokuPlugin,\n): obj is ProfileMenuPlugin =>\n \"getProfileMenuItems\" in obj && typeof obj.getProfileMenuItems === \"function\";\n\nexport const isNavigationPlugin = (\n obj: ZudokuPlugin,\n): obj is NavigationPlugin =>\n \"getRoutes\" in obj && typeof obj.getRoutes === \"function\";\n\nexport const isAuthenticationPlugin = (\n obj: ZudokuPlugin,\n): obj is AuthenticationPlugin =>\n \"signUp\" in obj && typeof obj.signUp === \"function\";\n\nexport const isSearchPlugin = (\n obj: ZudokuPlugin,\n): obj is SearchProviderPlugin =>\n \"renderSearch\" in obj && typeof obj.renderSearch === \"function\";\n\nexport const needsInitialization = (obj: ZudokuPlugin): obj is CommonPlugin =>\n \"initialize\" in obj && typeof obj.initialize === \"function\";\n\nexport const hasHead = (obj: ZudokuPlugin): obj is CommonPlugin =>\n \"getHead\" in obj && typeof obj.getHead === \"function\";\n\nexport const isMdxProviderPlugin = (obj: ZudokuPlugin): obj is CommonPlugin =>\n \"getMdxComponents\" in obj && typeof obj.getMdxComponents === \"function\";\n\nexport const isApiIdentityPlugin = (\n obj: ZudokuPlugin,\n): obj is ApiIdentityPlugin =>\n \"getIdentities\" in obj && typeof obj.getIdentities === \"function\";\n\nexport const isTransformConfigPlugin = (\n obj: ZudokuPlugin,\n): obj is TransformConfigPlugin =>\n \"transformConfig\" in obj && typeof obj.transformConfig === \"function\";\n"],"names":["createApiIdentityPlugin","plugin","createProfileMenuPlugin","isEventConsumerPlugin","obj","isProfileMenuPlugin","isNavigationPlugin","isAuthenticationPlugin","isSearchPlugin","needsInitialization","hasHead","isMdxProviderPlugin","isApiIdentityPlugin","isTransformConfigPlugin"],"mappings":"AAgCO,MAAMA,IAA0B,CACrCC,MACsBA,GAEXC,IAA0B,CACrCD,MACsBA,GAmDXE,IAAwB,CACnCC,MAEA,YAAYA,KAAO,OAAOA,EAAI,UAAW,UAE9BC,IAAsB,CACjCD,MAEA,yBAAyBA,KAAO,OAAOA,EAAI,uBAAwB,YAExDE,IAAqB,CAChCF,MAEA,eAAeA,KAAO,OAAOA,EAAI,aAAc,YAEpCG,IAAyB,CACpCH,MAEA,YAAYA,KAAO,OAAOA,EAAI,UAAW,YAE9BI,IAAiB,CAC5BJ,MAEA,kBAAkBA,KAAO,OAAOA,EAAI,gBAAiB,YAE1CK,IAAsB,CAACL,MAClC,gBAAgBA,KAAO,OAAOA,EAAI,cAAe,YAEtCM,IAAU,CAACN,MACtB,aAAaA,KAAO,OAAOA,EAAI,WAAY,YAEhCO,IAAsB,CAACP,MAClC,sBAAsBA,KAAO,OAAOA,EAAI,oBAAqB,YAElDQ,IAAsB,CACjCR,MAEA,mBAAmBA,KAAO,OAAOA,EAAI,iBAAkB,YAE5CS,IAA0B,CACrCT,MAEA,qBAAqBA,KAAO,OAAOA,EAAI,mBAAoB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zudoku",
3
- "version": "0.0.0-z6bcd96da",
3
+ "version": "0.0.0-z7b86faab",
4
4
  "type": "module",
5
5
  "homepage": "https://zudoku.dev",
6
6
  "repository": {
@@ -154,6 +154,7 @@
154
154
  "dependencies": {
155
155
  "@apidevtools/json-schema-ref-parser": "14.1.1",
156
156
  "@envelop/core": "5.3.2",
157
+ "@fastify/deepmerge": "3.1.0",
157
158
  "@graphql-typed-document-node/core": "3.2.0",
158
159
  "@lekoarts/rehype-meta-as-attributes": "3.0.3",
159
160
  "@mdx-js/react": "3.1.1",
@@ -3,6 +3,7 @@ import type { ReactNode } from "react";
3
3
  import type { Location, RouteObject } from "react-router";
4
4
  import type { Navigation } from "../../config/validators/NavigationSchema.js";
5
5
  import type { ProtectedRoutesInput } from "../../config/validators/ProtectedRoutesSchema.js";
6
+ import type { ZudokuConfig } from "../../config/validators/validate.js";
6
7
  import type { AuthenticationPlugin } from "../authentication/authentication.js";
7
8
  import type { MdxComponentsType } from "../util/MdxComponents.js";
8
9
  import type {
@@ -18,7 +19,8 @@ export type ZudokuPlugin =
18
19
  | ApiIdentityPlugin
19
20
  | SearchProviderPlugin
20
21
  | EventConsumerPlugin
21
- | AuthenticationPlugin;
22
+ | AuthenticationPlugin
23
+ | TransformConfigPlugin;
22
24
 
23
25
  export type { AuthenticationPlugin, RouteObject };
24
26
 
@@ -60,6 +62,19 @@ export type ProfileNavigationItem = {
60
62
  icon?: LucideIcon;
61
63
  };
62
64
 
65
+ export interface ConfigHookContext {
66
+ mode: typeof process.env.ZUDOKU_ENV;
67
+ rootDir: string;
68
+ configPath: string;
69
+ }
70
+
71
+ export interface TransformConfigPlugin {
72
+ transformConfig?: (
73
+ config: ZudokuConfig,
74
+ ctx: ConfigHookContext,
75
+ ) => Partial<ZudokuConfig> | void | Promise<Partial<ZudokuConfig> | void>;
76
+ }
77
+
63
78
  export interface CommonPlugin {
64
79
  initialize?: (
65
80
  context: ZudokuContext,
@@ -110,3 +125,8 @@ export const isApiIdentityPlugin = (
110
125
  obj: ZudokuPlugin,
111
126
  ): obj is ApiIdentityPlugin =>
112
127
  "getIdentities" in obj && typeof obj.getIdentities === "function";
128
+
129
+ export const isTransformConfigPlugin = (
130
+ obj: ZudokuPlugin,
131
+ ): obj is TransformConfigPlugin =>
132
+ "transformConfig" in obj && typeof obj.transformConfig === "function";
@@ -0,0 +1,29 @@
1
+ import createDeepmerge from "@fastify/deepmerge";
2
+ import type { ConfigWithMeta } from "../../config/loader.js";
3
+ import { type ConfigHookContext, isTransformConfigPlugin } from "./plugins.js";
4
+
5
+ const mergeConfig = createDeepmerge({
6
+ mergeArray: (opt) => (_, source) => opt.clone(source),
7
+ });
8
+
9
+ export const runTransformConfigHooks = async (
10
+ config: ConfigWithMeta,
11
+ ): Promise<ConfigWithMeta> => {
12
+ const ctx = {
13
+ mode: config.__meta.mode,
14
+ rootDir: config.__meta.rootDir,
15
+ configPath: config.__meta.configPath,
16
+ } satisfies ConfigHookContext;
17
+ const plugins = config.plugins ?? [];
18
+
19
+ let result = config;
20
+
21
+ for (const plugin of plugins.filter(isTransformConfigPlugin)) {
22
+ const partial = await plugin.transformConfig?.(result, ctx);
23
+ if (!partial) continue;
24
+
25
+ result = mergeConfig(result, partial) as ConfigWithMeta;
26
+ }
27
+
28
+ return result;
29
+ };