@arch-cadre/modules 0.0.62 → 0.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/client/extension-point-client.d.ts +8 -17
  2. package/dist/client/extension-point-client.d.ts.map +1 -1
  3. package/dist/client/extension-point-client.js +19 -0
  4. package/dist/client/extension-point.d.ts +8 -19
  5. package/dist/client/extension-point.d.ts.map +1 -1
  6. package/dist/client/extension-point.js +12 -0
  7. package/dist/client/index.d.ts +4 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +3 -0
  10. package/dist/client/widget-area.d.ts +7 -16
  11. package/dist/client/widget-area.d.ts.map +1 -1
  12. package/dist/client/widget-area.js +12 -0
  13. package/dist/index.d.ts +5 -5
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +6 -0
  16. package/dist/server/lifecycle.d.ts +5 -8
  17. package/dist/server/lifecycle.d.ts.map +1 -1
  18. package/dist/server/lifecycle.js +250 -0
  19. package/dist/server/manage.d.ts +25 -29
  20. package/dist/server/manage.d.ts.map +1 -1
  21. package/dist/server/manage.js +143 -0
  22. package/dist/server/registry.d.ts +2 -5
  23. package/dist/server/registry.d.ts.map +1 -1
  24. package/dist/server/registry.js +118 -0
  25. package/dist/server/ui.d.ts +13 -17
  26. package/dist/server/ui.d.ts.map +1 -1
  27. package/dist/server/ui.js +235 -0
  28. package/dist/server.d.ts +6 -6
  29. package/dist/server.d.ts.map +1 -0
  30. package/dist/server.js +8 -0
  31. package/dist/types.d.ts +91 -94
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/types.js +13 -0
  34. package/package.json +17 -13
  35. package/dist/client/extension-point-client.mjs +0 -2
  36. package/dist/client/extension-point-client.mjs.map +0 -1
  37. package/dist/client/extension-point.mjs +0 -2
  38. package/dist/client/extension-point.mjs.map +0 -1
  39. package/dist/client/widget-area.mjs +0 -2
  40. package/dist/client/widget-area.mjs.map +0 -1
  41. package/dist/index.mjs +0 -1
  42. package/dist/server/lifecycle.mjs +0 -2
  43. package/dist/server/lifecycle.mjs.map +0 -1
  44. package/dist/server/manage.mjs +0 -2
  45. package/dist/server/manage.mjs.map +0 -1
  46. package/dist/server/registry.mjs +0 -2
  47. package/dist/server/registry.mjs.map +0 -1
  48. package/dist/server/ui.mjs +0 -2
  49. package/dist/server/ui.mjs.map +0 -1
  50. package/dist/server.mjs +0 -1
  51. package/dist/types.mjs +0 -2
  52. package/dist/types.mjs.map +0 -1
@@ -0,0 +1,143 @@
1
+ "use server";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { systemModulesTable } from "@arch-cadre/core";
5
+ import { db, getModulesDir } from "@arch-cadre/core/server";
6
+ import { eq } from "drizzle-orm";
7
+ import { ModuleManifestSchema } from "../types";
8
+ const globalForModules = globalThis;
9
+ if (!globalForModules.__KRYO_REGISTERED_MODULES__) {
10
+ globalForModules.__KRYO_REGISTERED_MODULES__ = new Map();
11
+ }
12
+ export async function registerModules(modules) {
13
+ var _a;
14
+ const store = globalForModules.__KRYO_REGISTERED_MODULES__;
15
+ for (const mod of modules) {
16
+ if ((_a = mod.manifest) === null || _a === void 0 ? void 0 : _a.id) {
17
+ store.set(mod.manifest.id, mod);
18
+ }
19
+ }
20
+ }
21
+ export async function getModules() {
22
+ try {
23
+ const modulesDir = await getModulesDir();
24
+ const manifests = [];
25
+ const entries = await fs.readdir(modulesDir).catch(() => []);
26
+ for (const dir of entries) {
27
+ if (dir.startsWith("."))
28
+ continue;
29
+ try {
30
+ const content = await fs.readFile(path.join(modulesDir, dir, "manifeston"), "utf-8");
31
+ const manifest = ModuleManifestSchema.parse(JSON.parse(content));
32
+ manifests.push({ ...manifest, hasDocs: false });
33
+ }
34
+ catch { }
35
+ }
36
+ const store = globalForModules.__KRYO_REGISTERED_MODULES__;
37
+ for (const mod of store.values()) {
38
+ if (!manifests.some((m) => m.id === mod.manifest.id)) {
39
+ manifests.push({ ...mod.manifest, hasDocs: false });
40
+ }
41
+ }
42
+ const dbModules = await db
43
+ .select()
44
+ .from(systemModulesTable)
45
+ .catch(() => []);
46
+ const dbMap = new Map(dbModules.map((m) => [m.id, m]));
47
+ return manifests.map((mod) => {
48
+ var _a, _b;
49
+ const dbEntry = dbMap.get(mod.id);
50
+ return {
51
+ ...mod,
52
+ enabled: mod.system ? true : ((_a = dbEntry === null || dbEntry === void 0 ? void 0 : dbEntry.enabled) !== null && _a !== void 0 ? _a : false),
53
+ installed: mod.system ? true : ((_b = dbEntry === null || dbEntry === void 0 ? void 0 : dbEntry.installed) !== null && _b !== void 0 ? _b : false),
54
+ lastStep: dbEntry === null || dbEntry === void 0 ? void 0 : dbEntry.lastStep,
55
+ hasDocs: mod.hasDocs,
56
+ };
57
+ });
58
+ }
59
+ catch {
60
+ return [];
61
+ }
62
+ }
63
+ export async function getModuleStatus(moduleId) {
64
+ try {
65
+ const [mod] = await db
66
+ .select()
67
+ .from(systemModulesTable)
68
+ .where(eq(systemModulesTable.id, moduleId));
69
+ return {
70
+ enabled: mod === null || mod === void 0 ? void 0 : mod.enabled,
71
+ installed: mod === null || mod === void 0 ? void 0 : mod.installed,
72
+ lastStep: mod === null || mod === void 0 ? void 0 : mod.lastStep,
73
+ };
74
+ }
75
+ catch {
76
+ return { enabled: false, installed: false, lastStep: null };
77
+ }
78
+ }
79
+ export async function isModuleEnabled(moduleId) {
80
+ try {
81
+ const [mod] = await db
82
+ .select()
83
+ .from(systemModulesTable)
84
+ .where(eq(systemModulesTable.id, moduleId));
85
+ return !!(mod === null || mod === void 0 ? void 0 : mod.enabled) || !!(mod === null || mod === void 0 ? void 0 : mod.system);
86
+ }
87
+ catch {
88
+ return false;
89
+ }
90
+ }
91
+ export async function getModuleInstance(moduleId) {
92
+ try {
93
+ const store = globalForModules.__KRYO_REGISTERED_MODULES__;
94
+ // 1. Check if module is already registered in the global store
95
+ if (store.has(moduleId)) {
96
+ console.log(`[Kernel:Manage] Module "${moduleId}" found in registry.`);
97
+ return store.get(moduleId) || null;
98
+ }
99
+ console.log(`[Kernel:Manage] Module "${moduleId}" not in registry. Registry size: ${store.size}. Keys: ${Array.from(store.keys()).join(", ")}`);
100
+ // 2. Try to load as an NPM package (for modules installed via npm/pnpm)
101
+ // We only try this if it doesn't look like a local module path
102
+ if (!moduleId.startsWith(".") && !moduleId.startsWith("/")) {
103
+ try {
104
+ const mod = await import(`@arch-cadre/${moduleId}`);
105
+ console.log(`[Kernel:Manage] Module "${moduleId}" loaded via import().`);
106
+ return mod.default || mod || null;
107
+ }
108
+ catch (e) {
109
+ console.warn(`[Kernel:Manage] Failed to import module "${moduleId} via import().": ${e.message}`);
110
+ }
111
+ }
112
+ return null;
113
+ }
114
+ catch (error) {
115
+ console.error(`[Kernel:Manage] Error in getModuleInstance for "${moduleId}":`, error);
116
+ return null;
117
+ }
118
+ }
119
+ export async function getModuleConfig(moduleId) {
120
+ try {
121
+ const [mod] = await db
122
+ .select({ config: systemModulesTable.config })
123
+ .from(systemModulesTable)
124
+ .where(eq(systemModulesTable.id, moduleId));
125
+ if (!(mod === null || mod === void 0 ? void 0 : mod.config))
126
+ return null;
127
+ return JSON.parse(mod.config);
128
+ }
129
+ catch {
130
+ return null;
131
+ }
132
+ }
133
+ export async function updateModuleConfig(moduleId, config) {
134
+ try {
135
+ await db
136
+ .update(systemModulesTable)
137
+ .set({ config: JSON.stringify(config) })
138
+ .where(eq(systemModulesTable.id, moduleId));
139
+ }
140
+ catch (e) {
141
+ console.warn(`[Kernel:Manage] Failed to update config for ${moduleId}:`, e);
142
+ }
143
+ }
@@ -1,5 +1,2 @@
1
- //#region src/server/registry.d.ts
2
- declare function initModules(force?: boolean): Promise<void>;
3
- //#endregion
4
- export { initModules };
5
- //# sourceMappingURL=registry.d.mts.map
1
+ export declare function initModules(force?: boolean): Promise<void>;
2
+ //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.mts","names":[],"sources":["../../src/server/registry.ts"],"mappings":";iBAWsB,WAAA,CAAY,KAAA,aAAa,OAAA"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/server/registry.ts"],"names":[],"mappings":"AAWA,wBAAsB,WAAW,CAAC,KAAK,UAAQ,iBAwI9C"}
@@ -0,0 +1,118 @@
1
+ "use server";
2
+ import { eventBus, systemModulesTable } from "@arch-cadre/core";
3
+ import { db } from "@arch-cadre/core/server";
4
+ import { eq } from "drizzle-orm";
5
+ import { getModuleInstance, getModules, isModuleEnabled } from "./manage";
6
+ const globalForRegistry = globalThis;
7
+ export async function initModules(force = false) {
8
+ var _a, _b, _c;
9
+ if (globalForRegistry.__KRYO_MODULES_INITIALIZED__ && !force)
10
+ return;
11
+ if (force) {
12
+ console.log("[Kernel:Registry] Forcing re-initialization...");
13
+ eventBus.clearAll();
14
+ }
15
+ console.log("[Kernel:Registry] Synchronizing module listeners...");
16
+ globalForRegistry.__KRYO_MODULES_INITIALIZED__ = true;
17
+ await eventBus.publish("system:modules:init:start", {
18
+ timestamp: Date.now(),
19
+ });
20
+ const processedModuleIds = new Set();
21
+ let hasNewModules = true;
22
+ let iterations = 0;
23
+ const MAX_ITERATIONS = 10; // Bezpiecznik przed nieskończoną pętlą
24
+ while (hasNewModules && iterations < MAX_ITERATIONS) {
25
+ hasNewModules = false;
26
+ iterations++;
27
+ // 1. Get ALL currently registered modules (including newly added ones)
28
+ const currentModules = await getModules();
29
+ // 2. Filter out modules that are already processed
30
+ const pendingModules = currentModules.filter((mod) => !processedModuleIds.has(mod.id));
31
+ if (pendingModules.length === 0) {
32
+ break;
33
+ }
34
+ // 3. Synchronize new modules with database
35
+ for (const mod of pendingModules) {
36
+ try {
37
+ await db
38
+ .insert(systemModulesTable)
39
+ .values({
40
+ id: mod.id,
41
+ enabled: (_a = mod.system) !== null && _a !== void 0 ? _a : false,
42
+ installed: (_b = mod.system) !== null && _b !== void 0 ? _b : false,
43
+ system: (_c = mod.system) !== null && _c !== void 0 ? _c : false,
44
+ })
45
+ .onConflictDoNothing();
46
+ }
47
+ catch (_e) {
48
+ // Table might not exist yet
49
+ }
50
+ }
51
+ // 4. Sort pending modules: system modules first
52
+ const sortedPending = [...pendingModules].sort((a, b) => a.system === b.system ? 0 : a.system ? -1 : 1);
53
+ // 5. Initialize modules
54
+ for (const mod of sortedPending) {
55
+ // Mark as processed immediately to avoid cycles
56
+ processedModuleIds.add(mod.id);
57
+ hasNewModules = true; // We processed something, so we should check again in case it added more
58
+ try {
59
+ const enabled = await isModuleEnabled(mod.id);
60
+ if (!enabled)
61
+ continue;
62
+ const instance = await getModuleInstance(mod.id);
63
+ if (!instance) {
64
+ console.warn(`[Kernel:Registry] No instance found for module ${mod.id}. Ensure it is registered correctly.`);
65
+ continue;
66
+ }
67
+ let dbMod = null;
68
+ try {
69
+ [dbMod] = await db
70
+ .select()
71
+ .from(systemModulesTable)
72
+ .where(eq(systemModulesTable.id, mod.id));
73
+ }
74
+ catch (_e) {
75
+ // Ignore missing table
76
+ }
77
+ // onEnable lifecycle
78
+ if (enabled && (!dbMod || !dbMod.installed)) {
79
+ console.log(`[Kernel:Registry] Installing module ${mod.id}...`);
80
+ // 1. Run migrations first
81
+ if (instance.onMigrate) {
82
+ console.log(`[Kernel:Registry] Running onMigrate for ${mod.id}...`);
83
+ await instance.onMigrate();
84
+ }
85
+ // 2. Run enable hook
86
+ console.log(`[Kernel:Registry] Running onEnable for ${mod.id}...`);
87
+ if (instance.onEnable)
88
+ await instance.onEnable();
89
+ try {
90
+ await db
91
+ .update(systemModulesTable)
92
+ .set({ installed: true, lastStep: null })
93
+ .where(eq(systemModulesTable.id, mod.id));
94
+ }
95
+ catch (_e) {
96
+ // Ignore missing table
97
+ }
98
+ }
99
+ // Operational init
100
+ if (instance.init) {
101
+ console.log(`[Kernel:Registry] Initializing ${mod.id}...`);
102
+ await instance.init();
103
+ console.log(`[Kernel:Registry] Module ${mod.id} is active.`);
104
+ }
105
+ }
106
+ catch (error) {
107
+ console.error(`[Kernel:Registry] Critical failure for ${mod.id}:`, error);
108
+ }
109
+ }
110
+ }
111
+ if (iterations >= MAX_ITERATIONS) {
112
+ console.warn("[Kernel:Registry] Max init iterations reached. Check for circular module registrations.");
113
+ }
114
+ await eventBus.publish("system:modules:init:end", {
115
+ timestamp: Date.now(),
116
+ moduleCount: processedModuleIds.size,
117
+ });
118
+ }
@@ -1,17 +1,13 @@
1
- import { ApiRouteDefinition, ModuleExtension, ModuleNavElement, ModuleWidget, PrivateRouteDefinition, PublicRouteDefinition } from "../types.mjs";
2
-
3
- //#region src/server/ui.d.ts
4
- declare function getModuleNavigationGrouped(type: "admin" | "settings"): Promise<Record<string, ModuleNavElement[]>>;
5
- declare function getKryoPathPrefix(): Promise<string>;
6
- declare function getKryoModuleNavigationGrouped(type: "admin" | "settings"): Promise<Record<string, ModuleNavElement[]>>;
7
- declare function getModuleNavigation(type: "public"): Promise<ModuleNavElement[]>;
8
- declare function getPublicModuleRoutes(): Promise<PublicRouteDefinition[]>;
9
- declare function getPrivateModuleRoutes(): Promise<PrivateRouteDefinition[]>;
10
- declare function getKryoModuleRoutes(): Promise<PrivateRouteDefinition[]>;
11
- declare function getApiModuleRoutes(): Promise<ApiRouteDefinition[]>;
12
- declare function getModuleWidgets(area: string): Promise<ModuleWidget[]>;
13
- declare function getExtensions(targetModule: string, point?: string): Promise<ModuleExtension[]>;
14
- declare function hasExtension(targetModule: string, point?: string): Promise<boolean>;
15
- //#endregion
16
- export { getApiModuleRoutes, getExtensions, getKryoModuleNavigationGrouped, getKryoModuleRoutes, getKryoPathPrefix, getModuleNavigation, getModuleNavigationGrouped, getModuleWidgets, getPrivateModuleRoutes, getPublicModuleRoutes, hasExtension };
17
- //# sourceMappingURL=ui.d.mts.map
1
+ import type { ApiRouteDefinition, ModuleExtension, ModuleNavElement, ModuleWidget, PrivateRouteDefinition, PublicRouteDefinition } from "../types";
2
+ export declare function getModuleNavigationGrouped(type: "admin" | "settings"): Promise<Record<string, ModuleNavElement[]>>;
3
+ export declare function getKryoPathPrefix(): Promise<string>;
4
+ export declare function getKryoModuleNavigationGrouped(type: "admin" | "settings"): Promise<Record<string, ModuleNavElement[]>>;
5
+ export declare function getModuleNavigation(type: "public"): Promise<ModuleNavElement[]>;
6
+ export declare function getPublicModuleRoutes(): Promise<PublicRouteDefinition[]>;
7
+ export declare function getPrivateModuleRoutes(): Promise<PrivateRouteDefinition[]>;
8
+ export declare function getKryoModuleRoutes(): Promise<PrivateRouteDefinition[]>;
9
+ export declare function getApiModuleRoutes(): Promise<ApiRouteDefinition[]>;
10
+ export declare function getModuleWidgets(area: string): Promise<ModuleWidget[]>;
11
+ export declare function getExtensions(targetModule: string, point?: string): Promise<ModuleExtension[]>;
12
+ export declare function hasExtension(targetModule: string, point?: string): Promise<boolean>;
13
+ //# sourceMappingURL=ui.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ui.d.mts","names":[],"sources":["../../src/server/ui.ts"],"mappings":";;;iBAqDsB,0BAAA,CAA2B,IAAA,yBAA0B,OAAA,CAAA,MAAA,SAAA,gBAAA;AAAA,iBAyCrD,iBAAA,CAAA,GAAqB,OAAA;AAAA,iBASrB,8BAAA,CACpB,IAAA,yBAA0B,OAAA,CAAA,MAAA,SAAA,gBAAA;AAAA,iBA4BN,mBAAA,CACpB,IAAA,aACC,OAAA,CAAQ,gBAAA;AAAA,iBAwBW,qBAAA,CAAA,GAAyB,OAAA,CAC7C,qBAAA;AAAA,iBAmBoB,sBAAA,CAAA,GAA0B,OAAA,CAC9C,sBAAA;AAAA,iBAmBoB,mBAAA,CAAA,GAAuB,OAAA,CAAQ,sBAAA;AAAA,iBAU/B,kBAAA,CAAA,GAAsB,OAAA,CAAQ,kBAAA;AAAA,iBAgB9B,gBAAA,CAAiB,IAAA,WAAY,OAAA,CAAA,YAAA;AAAA,iBAqB7B,aAAA,CAAc,YAAA,UAAsB,KAAA,YAAc,OAAA,CAAA,eAAA;AAAA,iBAuBlD,YAAA,CAAa,YAAA,UAAsB,KAAA,YAAc,OAAA"}
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../src/server/ui.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAEhB,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,UAAU,CAAC;AA0ClB,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,+CAuC1E;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAOzD;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,OAAO,GAAG,UAAU,+CA0B3B;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAsB7B;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CACpD,qBAAqB,EAAE,CACxB,CAgBA;AAED,wBAAsB,sBAAsB,IAAI,OAAO,CACrD,sBAAsB,EAAE,CACzB,CAgBA;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAQ7E;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAcxE;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,2BAmBlD;AAED,wBAAsB,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,8BAqBvE;AAED,wBAAsB,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,oBAoBtE"}
@@ -0,0 +1,235 @@
1
+ "use server";
2
+ import { getCurrentSession } from "@arch-cadre/core/server";
3
+ import { getModuleConfig, getModuleInstance, getModules } from "./manage";
4
+ /**
5
+ * Helper to check and filter a navigation item based on roles and permissions.
6
+ * Returns the item (potentially with filtered sub-items) or null if access is denied.
7
+ */
8
+ function filterNavItem(item, userRoles, userPermissions) {
9
+ // 1. Check access for the item itself
10
+ if (item.roles && item.roles.length > 0) {
11
+ if (!item.roles.some((role) => userRoles.includes(role))) {
12
+ return null;
13
+ }
14
+ }
15
+ if (item.permissions && item.permissions.length > 0) {
16
+ if (!item.permissions.every((perm) => userPermissions.includes(perm))) {
17
+ return null;
18
+ }
19
+ }
20
+ // 2. Recursively filter sub-items if they exist
21
+ if (item.items && item.items.length > 0) {
22
+ const filteredSubItems = item.items
23
+ .map((subItem) => filterNavItem(subItem, userRoles, userPermissions))
24
+ .filter((subItem) => subItem !== null);
25
+ return {
26
+ ...item,
27
+ items: filteredSubItems,
28
+ };
29
+ }
30
+ return item;
31
+ }
32
+ export async function getModuleNavigationGrouped(type) {
33
+ var _a;
34
+ const { user } = await getCurrentSession();
35
+ const userRoles = (user === null || user === void 0 ? void 0 : user.roles) || [];
36
+ const userPermissions = (user === null || user === void 0 ? void 0 : user.permissions) || [];
37
+ const modules = await getModules();
38
+ const active = modules.filter((m) => m.enabled);
39
+ const groups = {};
40
+ for (const mod of active) {
41
+ try {
42
+ const instance = await getModuleInstance(mod.id);
43
+ // 1. From instance
44
+ const instanceNav = (_a = instance === null || instance === void 0 ? void 0 : instance.navigation) === null || _a === void 0 ? void 0 : _a[type];
45
+ if (instanceNav) {
46
+ for (const [groupName, items] of Object.entries(instanceNav)) {
47
+ if (!groups[groupName])
48
+ groups[groupName] = [];
49
+ for (const rawItem of items) {
50
+ const item = filterNavItem(rawItem, userRoles, userPermissions);
51
+ if (item &&
52
+ !groups[groupName].some((existing) => existing.url === item.url)) {
53
+ groups[groupName].push(item);
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ catch (_e) {
60
+ console.warn(`[Kernel:UI] Failed to load navigation for module ${mod.id}:`, _e);
61
+ }
62
+ }
63
+ return groups;
64
+ }
65
+ export async function getKryoPathPrefix() {
66
+ var _a;
67
+ try {
68
+ const config = await getModuleConfig("kryo-panel");
69
+ return (_a = config === null || config === void 0 ? void 0 : config.pathPrefix) !== null && _a !== void 0 ? _a : "/kryo";
70
+ }
71
+ catch (_e) {
72
+ return "/kryo";
73
+ }
74
+ }
75
+ export async function getKryoModuleNavigationGrouped(type) {
76
+ const groups = await getModuleNavigationGrouped(type);
77
+ const prefix = await getKryoPathPrefix();
78
+ const prefixUrl = (url) => {
79
+ if (url.startsWith(prefix))
80
+ return url;
81
+ return url === "/" ? prefix : `${prefix}${url}`;
82
+ };
83
+ const processItems = (items) => {
84
+ return items.map((item) => ({
85
+ ...item,
86
+ url: prefixUrl(item.url),
87
+ items: item.items
88
+ ? processItems(item.items)
89
+ : undefined,
90
+ }));
91
+ };
92
+ const transformedGroups = {};
93
+ for (const [group, items] of Object.entries(groups)) {
94
+ transformedGroups[group] = processItems(items);
95
+ }
96
+ return transformedGroups;
97
+ }
98
+ export async function getModuleNavigation(type) {
99
+ var _a;
100
+ const { user } = await getCurrentSession();
101
+ const userRoles = (user === null || user === void 0 ? void 0 : user.roles) || [];
102
+ const userPermissions = (user === null || user === void 0 ? void 0 : user.permissions) || [];
103
+ const modules = await getModules();
104
+ const active = modules.filter((m) => m.enabled);
105
+ const all = [];
106
+ for (const mod of active) {
107
+ try {
108
+ const instance = await getModuleInstance(mod.id);
109
+ if ((_a = instance === null || instance === void 0 ? void 0 : instance.navigation) === null || _a === void 0 ? void 0 : _a[type]) {
110
+ const items = instance.navigation[type];
111
+ for (const rawItem of items) {
112
+ const item = filterNavItem(rawItem, userRoles, userPermissions);
113
+ if (item)
114
+ all.push(item);
115
+ }
116
+ }
117
+ }
118
+ catch { }
119
+ }
120
+ return all;
121
+ }
122
+ export async function getPublicModuleRoutes() {
123
+ var _a;
124
+ const modules = await getModules();
125
+ const active = modules.filter((m) => m.enabled);
126
+ const allRoutes = [];
127
+ for (const mod of active) {
128
+ try {
129
+ const instance = await getModuleInstance(mod.id);
130
+ // 1. Try from instance (if pre-defined)
131
+ if ((_a = instance === null || instance === void 0 ? void 0 : instance.routes) === null || _a === void 0 ? void 0 : _a.public) {
132
+ allRoutes.push(...instance.routes.public);
133
+ }
134
+ }
135
+ catch { }
136
+ }
137
+ return allRoutes;
138
+ }
139
+ export async function getPrivateModuleRoutes() {
140
+ var _a;
141
+ const modules = await getModules();
142
+ const active = modules.filter((m) => m.enabled);
143
+ const allRoutes = [];
144
+ for (const mod of active) {
145
+ try {
146
+ const instance = await getModuleInstance(mod.id);
147
+ // 1. Try from instance
148
+ if ((_a = instance === null || instance === void 0 ? void 0 : instance.routes) === null || _a === void 0 ? void 0 : _a.private) {
149
+ allRoutes.push(...instance.routes.private);
150
+ }
151
+ }
152
+ catch { }
153
+ }
154
+ return allRoutes;
155
+ }
156
+ export async function getKryoModuleRoutes() {
157
+ const routes = await getPrivateModuleRoutes();
158
+ const prefix = await getKryoPathPrefix();
159
+ return routes.map((route) => ({
160
+ ...route,
161
+ path: route.path === "/" ? prefix : `${prefix}${route.path}`,
162
+ }));
163
+ }
164
+ export async function getApiModuleRoutes() {
165
+ var _a;
166
+ const modules = await getModules();
167
+ const active = modules.filter((m) => m.enabled);
168
+ const allRoutes = [];
169
+ for (const mod of active) {
170
+ try {
171
+ const instance = await getModuleInstance(mod.id);
172
+ if ((_a = instance === null || instance === void 0 ? void 0 : instance.routes) === null || _a === void 0 ? void 0 : _a.api) {
173
+ allRoutes.push(...instance.routes.api);
174
+ }
175
+ }
176
+ catch { }
177
+ }
178
+ return allRoutes;
179
+ }
180
+ export async function getModuleWidgets(area) {
181
+ const modules = await getModules();
182
+ const active = modules.filter((m) => m.enabled);
183
+ const widgets = [];
184
+ for (const mod of active) {
185
+ try {
186
+ const instance = await getModuleInstance(mod.id);
187
+ if (instance === null || instance === void 0 ? void 0 : instance.widgets) {
188
+ const matching = instance.widgets.filter((w) => w.area === area);
189
+ widgets.push(...matching);
190
+ }
191
+ }
192
+ catch (_e) { }
193
+ }
194
+ return widgets.sort((a, b) => (a.priority || 0) - (b.priority || 0));
195
+ }
196
+ export async function getExtensions(targetModule, point) {
197
+ const modules = await getModules();
198
+ const active = modules.filter((m) => m.enabled);
199
+ const extensions = [];
200
+ for (const mod of active) {
201
+ try {
202
+ const instance = await getModuleInstance(mod.id);
203
+ if (instance === null || instance === void 0 ? void 0 : instance.extensions) {
204
+ const matching = instance.extensions.filter((ext) => {
205
+ const isTarget = ext.targetModule === targetModule;
206
+ const isPoint = point ? ext.point === point : true;
207
+ return isTarget && isPoint;
208
+ });
209
+ extensions.push(...matching);
210
+ }
211
+ }
212
+ catch (_e) { }
213
+ }
214
+ return extensions.sort((a, b) => (a.priority || 0) - (b.priority || 0));
215
+ }
216
+ export async function hasExtension(targetModule, point) {
217
+ const modules = await getModules();
218
+ const active = modules.filter((m) => m.enabled);
219
+ for (const mod of active) {
220
+ try {
221
+ const instance = await getModuleInstance(mod.id);
222
+ if (instance === null || instance === void 0 ? void 0 : instance.extensions) {
223
+ const matching = instance.extensions.filter((ext) => {
224
+ const isTarget = ext.targetModule === targetModule;
225
+ const isPoint = point ? ext.point === point : true;
226
+ return isTarget && isPoint;
227
+ });
228
+ if (matching.length > 0)
229
+ return true;
230
+ }
231
+ }
232
+ catch (_e) { }
233
+ }
234
+ return false;
235
+ }
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { ApiRouteDefinition, IModule, ModuleExtension, ModuleManifest, ModuleManifestSchema, ModuleNavElement, ModuleNavigation, ModuleNavigationGroupMap, ModulePageProps, ModuleRouteDefinition, ModuleWidget, PrivateRouteDefinition, PublicRouteDefinition, SidebarGroupType, SidebarMenuItemType, SidebarMenuType, SystemEvent } from "./types.mjs";
2
- import { initOperationalModules, pushModuleSchema, toggleModuleState } from "./server/lifecycle.mjs";
3
- import { getModuleConfig, getModuleInstance, getModuleStatus, getModules, isModuleEnabled, registerModules, updateModuleConfig } from "./server/manage.mjs";
4
- import { initModules } from "./server/registry.mjs";
5
- import { getApiModuleRoutes, getExtensions, getKryoModuleNavigationGrouped, getKryoModuleRoutes, getKryoPathPrefix, getModuleNavigation, getModuleNavigationGrouped, getModuleWidgets, getPrivateModuleRoutes, getPublicModuleRoutes, hasExtension } from "./server/ui.mjs";
6
- export { ApiRouteDefinition, IModule, ModuleExtension, ModuleManifest, ModuleManifestSchema, ModuleNavElement, ModuleNavigation, ModuleNavigationGroupMap, ModulePageProps, ModuleRouteDefinition, ModuleWidget, PrivateRouteDefinition, PublicRouteDefinition, SidebarGroupType, SidebarMenuItemType, SidebarMenuType, SystemEvent, getApiModuleRoutes, getExtensions, getKryoModuleNavigationGrouped, getKryoModuleRoutes, getKryoPathPrefix, getModuleConfig, getModuleInstance, getModuleNavigation, getModuleNavigationGrouped, getModuleStatus, getModuleWidgets, getModules, getPrivateModuleRoutes, getPublicModuleRoutes, hasExtension, initModules, initOperationalModules, isModuleEnabled, pushModuleSchema, registerModules, toggleModuleState, updateModuleConfig };
1
+ export * from "./server/lifecycle";
2
+ export * from "./server/manage";
3
+ export * from "./server/registry";
4
+ export * from "./server/ui";
5
+ export * from "./types";
6
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAG5B,cAAc,SAAS,CAAC"}
package/dist/server.js ADDED
@@ -0,0 +1,8 @@
1
+ // export { ExtensionPoint } from "./client/extension-point";
2
+ // Server-side Logic
3
+ export * from "./server/lifecycle";
4
+ export * from "./server/manage";
5
+ export * from "./server/registry";
6
+ export * from "./server/ui";
7
+ // Shared exports (from types/common logic)
8
+ export * from "./types";