@arch-cadre/modules 0.0.49 → 0.0.52
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/dist/client/extension-point-client.cjs +33 -26
- package/dist/client/extension-point-client.d.ts +10 -0
- package/dist/client/extension-point-client.mjs +19 -23
- package/dist/client/extension-point.cjs +25 -18
- package/dist/client/extension-point.d.ts +9 -0
- package/dist/client/extension-point.mjs +14 -17
- package/dist/client/index.cjs +38 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.mjs +3 -0
- package/dist/client/widget-area.cjs +29 -22
- package/dist/client/widget-area.d.ts +9 -0
- package/dist/client/widget-area.mjs +16 -20
- package/dist/index.cjs +42 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +4 -6
- package/dist/server/lifecycle.cjs +204 -180
- package/dist/server/lifecycle.d.ts +5 -0
- package/dist/server/lifecycle.mjs +223 -173
- package/dist/server/manage.cjs +124 -110
- package/dist/server/manage.d.ts +12 -0
- package/dist/server/manage.mjs +113 -104
- package/dist/server/registry.cjs +90 -82
- package/dist/server/registry.d.ts +1 -0
- package/dist/server/registry.mjs +94 -80
- package/dist/server/ui.cjs +197 -155
- package/dist/server/ui.d.ts +12 -0
- package/dist/server/ui.mjs +203 -154
- package/dist/server.cjs +59 -29
- package/dist/server.d.ts +5 -0
- package/dist/server.mjs +5 -7
- package/dist/types.cjs +18 -17
- package/dist/types.d.ts +113 -0
- package/dist/types.mjs +12 -16
- package/package.json +20 -6
- package/dist/_virtual/_rolldown/runtime.cjs +0 -29
package/dist/server/ui.cjs
CHANGED
|
@@ -1,180 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
"use server";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getApiModuleRoutes = getApiModuleRoutes;
|
|
8
|
+
exports.getExtensions = getExtensions;
|
|
9
|
+
exports.getKryoModuleNavigationGrouped = getKryoModuleNavigationGrouped;
|
|
10
|
+
exports.getKryoModuleRoutes = getKryoModuleRoutes;
|
|
11
|
+
exports.getKryoPathPrefix = getKryoPathPrefix;
|
|
12
|
+
exports.getModuleNavigation = getModuleNavigation;
|
|
13
|
+
exports.getModuleNavigationGrouped = getModuleNavigationGrouped;
|
|
14
|
+
exports.getModuleWidgets = getModuleWidgets;
|
|
15
|
+
exports.getPrivateModuleRoutes = getPrivateModuleRoutes;
|
|
16
|
+
exports.getPublicModuleRoutes = getPublicModuleRoutes;
|
|
17
|
+
exports.hasExtension = hasExtension;
|
|
18
|
+
var _server = require("@arch-cadre/core/server");
|
|
19
|
+
var _manage = require("./manage.js");
|
|
12
20
|
function filterNavItem(item, userRoles, userPermissions) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
if (item.roles && item.roles.length > 0) {
|
|
22
|
+
if (!item.roles.some(role => userRoles.includes(role))) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (item.permissions && item.permissions.length > 0) {
|
|
27
|
+
if (!item.permissions.every(perm => userPermissions.includes(perm))) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (item.items && item.items.length > 0) {
|
|
32
|
+
const filteredSubItems = item.items.map(subItem => filterNavItem(subItem, userRoles, userPermissions)).filter(subItem => subItem !== null);
|
|
33
|
+
return {
|
|
34
|
+
...item,
|
|
35
|
+
items: filteredSubItems
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return item;
|
|
27
39
|
}
|
|
28
40
|
async function getModuleNavigationGrouped(type) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const {
|
|
42
|
+
user
|
|
43
|
+
} = await (0, _server.getCurrentSession)();
|
|
44
|
+
const userRoles = user?.roles || [];
|
|
45
|
+
const userPermissions = user?.permissions || [];
|
|
46
|
+
const modules = await (0, _manage.getModules)();
|
|
47
|
+
const active = modules.filter(m => m.enabled);
|
|
48
|
+
const groups = {};
|
|
49
|
+
for (const mod of active) {
|
|
50
|
+
try {
|
|
51
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
52
|
+
const instanceNav = instance?.navigation?.[type];
|
|
53
|
+
if (instanceNav) {
|
|
54
|
+
for (const [groupName, items] of Object.entries(instanceNav)) {
|
|
55
|
+
if (!groups[groupName]) groups[groupName] = [];
|
|
56
|
+
for (const rawItem of items) {
|
|
57
|
+
const item = filterNavItem(rawItem, userRoles, userPermissions);
|
|
58
|
+
if (item && !groups[groupName].some(existing => existing.url === item.url)) {
|
|
59
|
+
groups[groupName].push(item);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (_e) {
|
|
65
|
+
console.warn(`[Kernel:UI] Failed to load navigation for module ${mod.id}:`, _e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return groups;
|
|
47
69
|
}
|
|
48
70
|
async function getKryoPathPrefix() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
71
|
+
try {
|
|
72
|
+
const config = await (0, _manage.getModuleConfig)("kryo-panel");
|
|
73
|
+
return config?.pathPrefix ?? "/kryo";
|
|
74
|
+
} catch (_e) {
|
|
75
|
+
return "/kryo";
|
|
76
|
+
}
|
|
54
77
|
}
|
|
55
78
|
async function getKryoModuleNavigationGrouped(type) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
const groups = await getModuleNavigationGrouped(type);
|
|
80
|
+
const prefix = await getKryoPathPrefix();
|
|
81
|
+
const prefixUrl = url => {
|
|
82
|
+
if (url.startsWith(prefix)) return url;
|
|
83
|
+
return url === "/" ? prefix : `${prefix}${url}`;
|
|
84
|
+
};
|
|
85
|
+
const processItems = items => {
|
|
86
|
+
return items.map(item => ({
|
|
87
|
+
...item,
|
|
88
|
+
url: prefixUrl(item.url),
|
|
89
|
+
items: item.items ? processItems(item.items) : void 0
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
const transformedGroups = {};
|
|
93
|
+
for (const [group, items] of Object.entries(groups)) {
|
|
94
|
+
transformedGroups[group] = processItems(items);
|
|
95
|
+
}
|
|
96
|
+
return transformedGroups;
|
|
72
97
|
}
|
|
73
98
|
async function getModuleNavigation(type) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
const {
|
|
100
|
+
user
|
|
101
|
+
} = await (0, _server.getCurrentSession)();
|
|
102
|
+
const userRoles = user?.roles || [];
|
|
103
|
+
const userPermissions = user?.permissions || [];
|
|
104
|
+
const modules = await (0, _manage.getModules)();
|
|
105
|
+
const active = modules.filter(m => m.enabled);
|
|
106
|
+
const all = [];
|
|
107
|
+
for (const mod of active) {
|
|
108
|
+
try {
|
|
109
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
110
|
+
if (instance?.navigation?.[type]) {
|
|
111
|
+
const items = instance.navigation[type];
|
|
112
|
+
for (const rawItem of items) {
|
|
113
|
+
const item = filterNavItem(rawItem, userRoles, userPermissions);
|
|
114
|
+
if (item) all.push(item);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch {}
|
|
118
|
+
}
|
|
119
|
+
return all;
|
|
90
120
|
}
|
|
91
121
|
async function getPublicModuleRoutes() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
122
|
+
const modules = await (0, _manage.getModules)();
|
|
123
|
+
const active = modules.filter(m => m.enabled);
|
|
124
|
+
const allRoutes = [];
|
|
125
|
+
for (const mod of active) {
|
|
126
|
+
try {
|
|
127
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
128
|
+
if (instance?.routes?.public) {
|
|
129
|
+
allRoutes.push(...instance.routes.public);
|
|
130
|
+
}
|
|
131
|
+
} catch {}
|
|
132
|
+
}
|
|
133
|
+
return allRoutes;
|
|
99
134
|
}
|
|
100
135
|
async function getPrivateModuleRoutes() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
136
|
+
const modules = await (0, _manage.getModules)();
|
|
137
|
+
const active = modules.filter(m => m.enabled);
|
|
138
|
+
const allRoutes = [];
|
|
139
|
+
for (const mod of active) {
|
|
140
|
+
try {
|
|
141
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
142
|
+
if (instance?.routes?.private) {
|
|
143
|
+
allRoutes.push(...instance.routes.private);
|
|
144
|
+
}
|
|
145
|
+
} catch {}
|
|
146
|
+
}
|
|
147
|
+
return allRoutes;
|
|
108
148
|
}
|
|
109
149
|
async function getKryoModuleRoutes() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
150
|
+
const routes = await getPrivateModuleRoutes();
|
|
151
|
+
const prefix = await getKryoPathPrefix();
|
|
152
|
+
return routes.map(route => ({
|
|
153
|
+
...route,
|
|
154
|
+
path: route.path === "/" ? prefix : `${prefix}${route.path}`
|
|
155
|
+
}));
|
|
116
156
|
}
|
|
117
157
|
async function getApiModuleRoutes() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
158
|
+
const modules = await (0, _manage.getModules)();
|
|
159
|
+
const active = modules.filter(m => m.enabled);
|
|
160
|
+
const allRoutes = [];
|
|
161
|
+
for (const mod of active) {
|
|
162
|
+
try {
|
|
163
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
164
|
+
if (instance?.routes?.api) {
|
|
165
|
+
allRoutes.push(...instance.routes.api);
|
|
166
|
+
}
|
|
167
|
+
} catch {}
|
|
168
|
+
}
|
|
169
|
+
return allRoutes;
|
|
125
170
|
}
|
|
126
171
|
async function getModuleWidgets(area) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
172
|
+
const modules = await (0, _manage.getModules)();
|
|
173
|
+
const active = modules.filter(m => m.enabled);
|
|
174
|
+
const widgets = [];
|
|
175
|
+
for (const mod of active) {
|
|
176
|
+
try {
|
|
177
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
178
|
+
if (instance?.widgets) {
|
|
179
|
+
const matching = instance.widgets.filter(w => w.area === area);
|
|
180
|
+
widgets.push(...matching);
|
|
181
|
+
}
|
|
182
|
+
} catch (_e) {}
|
|
183
|
+
}
|
|
184
|
+
return widgets.sort((a, b) => (a.priority || 0) - (b.priority || 0));
|
|
137
185
|
}
|
|
138
186
|
async function getExtensions(targetModule, point) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
187
|
+
const modules = await (0, _manage.getModules)();
|
|
188
|
+
const active = modules.filter(m => m.enabled);
|
|
189
|
+
const extensions = [];
|
|
190
|
+
for (const mod of active) {
|
|
191
|
+
try {
|
|
192
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
193
|
+
if (instance?.extensions) {
|
|
194
|
+
const matching = instance.extensions.filter(ext => {
|
|
195
|
+
const isTarget = ext.targetModule === targetModule;
|
|
196
|
+
const isPoint = point ? ext.point === point : true;
|
|
197
|
+
return isTarget && isPoint;
|
|
198
|
+
});
|
|
199
|
+
extensions.push(...matching);
|
|
200
|
+
}
|
|
201
|
+
} catch (_e) {}
|
|
202
|
+
}
|
|
203
|
+
return extensions.sort((a, b) => (a.priority || 0) - (b.priority || 0));
|
|
153
204
|
}
|
|
154
205
|
async function hasExtension(targetModule, point) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
exports.getKryoModuleNavigationGrouped = getKryoModuleNavigationGrouped;
|
|
173
|
-
exports.getKryoModuleRoutes = getKryoModuleRoutes;
|
|
174
|
-
exports.getKryoPathPrefix = getKryoPathPrefix;
|
|
175
|
-
exports.getModuleNavigation = getModuleNavigation;
|
|
176
|
-
exports.getModuleNavigationGrouped = getModuleNavigationGrouped;
|
|
177
|
-
exports.getModuleWidgets = getModuleWidgets;
|
|
178
|
-
exports.getPrivateModuleRoutes = getPrivateModuleRoutes;
|
|
179
|
-
exports.getPublicModuleRoutes = getPublicModuleRoutes;
|
|
180
|
-
exports.hasExtension = hasExtension;
|
|
206
|
+
const modules = await (0, _manage.getModules)();
|
|
207
|
+
const active = modules.filter(m => m.enabled);
|
|
208
|
+
for (const mod of active) {
|
|
209
|
+
try {
|
|
210
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
211
|
+
if (instance?.extensions) {
|
|
212
|
+
const matching = instance.extensions.filter(ext => {
|
|
213
|
+
const isTarget = ext.targetModule === targetModule;
|
|
214
|
+
const isPoint = point ? ext.point === point : true;
|
|
215
|
+
return isTarget && isPoint;
|
|
216
|
+
});
|
|
217
|
+
if (matching.length > 0) return true;
|
|
218
|
+
}
|
|
219
|
+
} catch (_e) {}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ApiRouteDefinition, ModuleExtension, ModuleNavElement, ModuleWidget, PrivateRouteDefinition, PublicRouteDefinition } from "../types.js";
|
|
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>;
|