@fayz-ai/core 0.1.6
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/app/render.d.ts +16 -0
- package/dist/app/render.d.ts.map +1 -0
- package/dist/blocks/index.d.ts +25 -0
- package/dist/blocks/index.d.ts.map +1 -0
- package/dist/chunk-2NTHNWEH.cjs +32 -0
- package/dist/chunk-2NTHNWEH.cjs.map +1 -0
- package/dist/chunk-5EAZOMVP.js +1609 -0
- package/dist/chunk-5EAZOMVP.js.map +1 -0
- package/dist/chunk-5TKIZVVJ.cjs +16 -0
- package/dist/chunk-5TKIZVVJ.cjs.map +1 -0
- package/dist/chunk-7RTUHSKY.js +3 -0
- package/dist/chunk-7RTUHSKY.js.map +1 -0
- package/dist/chunk-AXTWKF5X.cjs +38 -0
- package/dist/chunk-AXTWKF5X.cjs.map +1 -0
- package/dist/chunk-EGWWQ7AT.cjs +355 -0
- package/dist/chunk-EGWWQ7AT.cjs.map +1 -0
- package/dist/chunk-KAYQFSR6.js +298 -0
- package/dist/chunk-KAYQFSR6.js.map +1 -0
- package/dist/chunk-LSVBDYFQ.cjs +1639 -0
- package/dist/chunk-LSVBDYFQ.cjs.map +1 -0
- package/dist/chunk-SNQW6TRF.cjs +658 -0
- package/dist/chunk-SNQW6TRF.cjs.map +1 -0
- package/dist/chunk-WKZVSKEU.js +26 -0
- package/dist/chunk-WKZVSKEU.js.map +1 -0
- package/dist/chunk-Y2C2FBQP.js +35 -0
- package/dist/chunk-Y2C2FBQP.js.map +1 -0
- package/dist/chunk-YSBXGHAM.js +643 -0
- package/dist/chunk-YSBXGHAM.js.map +1 -0
- package/dist/data/archetype.d.ts +13 -0
- package/dist/data/archetype.d.ts.map +1 -0
- package/dist/data/cached.d.ts +19 -0
- package/dist/data/cached.d.ts.map +1 -0
- package/dist/data/fayz-api.d.ts +19 -0
- package/dist/data/fayz-api.d.ts.map +1 -0
- package/dist/data/index.cjs +32 -0
- package/dist/data/index.cjs.map +1 -0
- package/dist/data/index.d.ts +9 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +3 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/mock.d.ts +7 -0
- package/dist/data/mock.d.ts.map +1 -0
- package/dist/data/resolve.d.ts +22 -0
- package/dist/data/resolve.d.ts.map +1 -0
- package/dist/data/supabase.d.ts +18 -0
- package/dist/data/supabase.d.ts.map +1 -0
- package/dist/data/types.d.ts +23 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/entity/index.cjs +28 -0
- package/dist/entity/index.cjs.map +1 -0
- package/dist/entity/index.d.ts +3 -0
- package/dist/entity/index.d.ts.map +1 -0
- package/dist/entity/index.js +3 -0
- package/dist/entity/index.js.map +1 -0
- package/dist/entity/registry.d.ts +20 -0
- package/dist/entity/registry.d.ts.map +1 -0
- package/dist/events/index.d.ts +16 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/i18n/index.cjs +44 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.ts +21 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +3 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/shell-translations.d.ts +2 -0
- package/dist/i18n/shell-translations.d.ts.map +1 -0
- package/dist/index.cjs +911 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +596 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cache.d.ts +21 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/csv.d.ts +14 -0
- package/dist/lib/csv.d.ts.map +1 -0
- package/dist/lib/format.d.ts +7 -0
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/manifest/index.d.ts +80 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/plugin/createSafeDataProvider.d.ts +14 -0
- package/dist/plugin/createSafeDataProvider.d.ts.map +1 -0
- package/dist/plugin/index.cjs +32 -0
- package/dist/plugin/index.cjs.map +1 -0
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +3 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/runtime.d.ts +31 -0
- package/dist/plugin/runtime.d.ts.map +1 -0
- package/dist/registry/index.d.ts +88 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/router/index.cjs +16 -0
- package/dist/router/index.cjs.map +1 -0
- package/dist/router/index.d.ts +8 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +3 -0
- package/dist/router/index.js.map +1 -0
- package/dist/runtime/index.cjs +16 -0
- package/dist/runtime/index.cjs.map +1 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/oauth.d.ts +96 -0
- package/dist/runtime/oauth.d.ts.map +1 -0
- package/dist/tenant/index.d.ts +3 -0
- package/dist/tenant/index.d.ts.map +1 -0
- package/dist/types/auth.d.ts +27 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/billing.d.ts +17 -0
- package/dist/types/billing.d.ts.map +1 -0
- package/dist/types/crud.d.ts +107 -0
- package/dist/types/crud.d.ts.map +1 -0
- package/dist/types/entities.d.ts +134 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/i18n.d.ts +8 -0
- package/dist/types/i18n.d.ts.map +1 -0
- package/dist/types/index.cjs +4 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/org.d.ts +96 -0
- package/dist/types/org.d.ts.map +1 -0
- package/dist/types/permissions.d.ts +25 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +314 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/theme.d.ts +16 -0
- package/dist/types/theme.d.ts.map +1 -0
- package/package.json +98 -0
- package/src/app/render.tsx +69 -0
- package/src/blocks/index.tsx +68 -0
- package/src/data/archetype.ts +210 -0
- package/src/data/cached.ts +55 -0
- package/src/data/fayz-api.ts +200 -0
- package/src/data/index.ts +8 -0
- package/src/data/mock.ts +84 -0
- package/src/data/resolve.ts +108 -0
- package/src/data/supabase.ts +169 -0
- package/src/data/types.ts +20 -0
- package/src/entity/index.ts +2 -0
- package/src/entity/registry.ts +42 -0
- package/src/events/index.tsx +82 -0
- package/src/i18n/index.ts +250 -0
- package/src/i18n/shell-translations.ts +1391 -0
- package/src/index.ts +132 -0
- package/src/lib/cache.ts +118 -0
- package/src/lib/csv.ts +54 -0
- package/src/lib/format.ts +58 -0
- package/src/manifest/app-manifest.schema.json +103 -0
- package/src/manifest/index.ts +394 -0
- package/src/plugin/createSafeDataProvider.ts +30 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin/runtime.ts +313 -0
- package/src/registry/index.ts +163 -0
- package/src/router/index.ts +29 -0
- package/src/runtime/index.ts +15 -0
- package/src/runtime/oauth.ts +219 -0
- package/src/tenant/index.ts +18 -0
- package/src/types/auth.ts +26 -0
- package/src/types/billing.ts +17 -0
- package/src/types/crud.ts +108 -0
- package/src/types/entities.ts +142 -0
- package/src/types/i18n.ts +7 -0
- package/src/types/index.ts +10 -0
- package/src/types/org.ts +94 -0
- package/src/types/permissions.ts +32 -0
- package/src/types/plugins.ts +363 -0
- package/src/types/theme.ts +17 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
// src/registry/index.ts
|
|
4
|
+
var Registry = class {
|
|
5
|
+
constructor(kind) {
|
|
6
|
+
this.kind = kind;
|
|
7
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
8
|
+
}
|
|
9
|
+
register(id, value, meta = {}) {
|
|
10
|
+
this.entries.set(id, { id, value, meta });
|
|
11
|
+
}
|
|
12
|
+
get(id) {
|
|
13
|
+
return this.entries.get(id)?.value;
|
|
14
|
+
}
|
|
15
|
+
getEntry(id) {
|
|
16
|
+
return this.entries.get(id);
|
|
17
|
+
}
|
|
18
|
+
has(id) {
|
|
19
|
+
return this.entries.has(id);
|
|
20
|
+
}
|
|
21
|
+
list() {
|
|
22
|
+
return Array.from(this.entries.values());
|
|
23
|
+
}
|
|
24
|
+
ids() {
|
|
25
|
+
return Array.from(this.entries.keys());
|
|
26
|
+
}
|
|
27
|
+
clear() {
|
|
28
|
+
this.entries.clear();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function isCustomId(id) {
|
|
32
|
+
return id.startsWith("custom:");
|
|
33
|
+
}
|
|
34
|
+
var componentRegistry = new Registry("component");
|
|
35
|
+
var blockRegistry = new Registry("block");
|
|
36
|
+
var pageRegistry = new Registry("page");
|
|
37
|
+
var scaffoldRegistry = new Registry("scaffold");
|
|
38
|
+
var metricRegistry = new Registry("metric");
|
|
39
|
+
var pluginRegistry = new Registry("plugin");
|
|
40
|
+
var registerComponent = (id, c, meta) => componentRegistry.register(id, c, meta);
|
|
41
|
+
var getComponent = (id) => componentRegistry.get(id);
|
|
42
|
+
var registerBlock = (id, c, meta) => blockRegistry.register(id, c, meta);
|
|
43
|
+
var getBlock = (id) => blockRegistry.get(id);
|
|
44
|
+
var listBlocks = () => blockRegistry.list();
|
|
45
|
+
var registerPage = (id, c, meta) => pageRegistry.register(id, c, meta);
|
|
46
|
+
var getPage = (id) => pageRegistry.get(id);
|
|
47
|
+
var registerScaffold = (id, c, meta) => scaffoldRegistry.register(id, c, meta);
|
|
48
|
+
var getScaffold = (id) => scaffoldRegistry.get(id);
|
|
49
|
+
var registerMetric = (def, meta) => metricRegistry.register(def.id, def, meta);
|
|
50
|
+
var getMetric = (id) => metricRegistry.get(id);
|
|
51
|
+
var listMetrics = () => metricRegistry.list();
|
|
52
|
+
var registerPlugin = (id, manifest, meta) => pluginRegistry.register(id, manifest, meta);
|
|
53
|
+
var getPlugin = (id) => pluginRegistry.get(id);
|
|
54
|
+
var listPlugins = () => pluginRegistry.list();
|
|
55
|
+
var pluginFactoryRegistry = new Registry("plugin-factory");
|
|
56
|
+
var registerPluginFactory = (id, factory, meta) => pluginFactoryRegistry.register(id, factory, meta);
|
|
57
|
+
var getPluginFactory = (id) => pluginFactoryRegistry.get(id);
|
|
58
|
+
var listPluginFactories = () => pluginFactoryRegistry.list();
|
|
59
|
+
var PLUGIN_API_VERSION = 1;
|
|
60
|
+
function resolvePluginComponent(def) {
|
|
61
|
+
if (def.component) return def.component;
|
|
62
|
+
if (def.componentId) return getComponent(def.componentId);
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
var EMPTY_CONTEXT = {
|
|
66
|
+
tenant: null,
|
|
67
|
+
user: null,
|
|
68
|
+
currentPath: "/",
|
|
69
|
+
matchedPath: "/",
|
|
70
|
+
layout: "sidebar"
|
|
71
|
+
};
|
|
72
|
+
function slugify(input) {
|
|
73
|
+
return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
74
|
+
}
|
|
75
|
+
function matchesRoutePattern(pattern, currentPath) {
|
|
76
|
+
if (pattern === currentPath) return true;
|
|
77
|
+
if (pattern.endsWith("/*")) {
|
|
78
|
+
const base = pattern.slice(0, -2);
|
|
79
|
+
return currentPath === base || currentPath.startsWith(`${base}/`);
|
|
80
|
+
}
|
|
81
|
+
if (pattern.endsWith("*")) return currentPath.startsWith(pattern.slice(0, -1));
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
function isWidgetVisible(widget, context) {
|
|
85
|
+
if (widget.permission && context.hasPermission && !context.hasPermission(widget.permission)) return false;
|
|
86
|
+
const visibility = widget.visibility;
|
|
87
|
+
if (!visibility) return true;
|
|
88
|
+
if (visibility.layouts && !visibility.layouts.includes(context.layout)) return false;
|
|
89
|
+
if (visibility.roles && context.user?.role && !visibility.roles.includes(context.user.role)) return false;
|
|
90
|
+
if (visibility.roles && !context.user?.role) return false;
|
|
91
|
+
if (visibility.plans && context.tenant?.plan && !visibility.plans.includes(context.tenant.plan)) return false;
|
|
92
|
+
if (visibility.plans && !context.tenant?.plan) return false;
|
|
93
|
+
if (visibility.routes && !visibility.routes.some((p) => matchesRoutePattern(p, context.currentPath))) return false;
|
|
94
|
+
if (visibility.excludeRoutes?.some((p) => matchesRoutePattern(p, context.currentPath))) return false;
|
|
95
|
+
if (visibility.permissions?.length) {
|
|
96
|
+
if (!context.hasPermission) return false;
|
|
97
|
+
if (!visibility.permissions.every((req) => context.hasPermission?.(req))) return false;
|
|
98
|
+
}
|
|
99
|
+
if (visibility.when && !visibility.when(context)) return false;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
function normalizeSettingsTabs(plugin) {
|
|
103
|
+
return (plugin.settings ?? []).map((entry, index) => ({
|
|
104
|
+
...entry,
|
|
105
|
+
pluginId: entry.pluginId ?? plugin.id,
|
|
106
|
+
order: entry.order ?? index,
|
|
107
|
+
id: entry.id ?? `${plugin.id}-${slugify(entry.label)}`
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
function createEmptyRuntime(context = EMPTY_CONTEXT) {
|
|
111
|
+
return {
|
|
112
|
+
context,
|
|
113
|
+
plugins: [],
|
|
114
|
+
activePlugins: [],
|
|
115
|
+
routes: [],
|
|
116
|
+
navigation: [],
|
|
117
|
+
settingsTabs: [],
|
|
118
|
+
widgets: [],
|
|
119
|
+
dashboardWidgets: [],
|
|
120
|
+
capabilities: [],
|
|
121
|
+
aiTools: [],
|
|
122
|
+
registries: /* @__PURE__ */ new Map(),
|
|
123
|
+
pluginFeatures: [],
|
|
124
|
+
issues: []
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function definePlugin(plugin) {
|
|
128
|
+
return plugin;
|
|
129
|
+
}
|
|
130
|
+
function resolvePluginRuntime({
|
|
131
|
+
plugins = [],
|
|
132
|
+
tenantPlugins = [],
|
|
133
|
+
hasTenantBindings,
|
|
134
|
+
context
|
|
135
|
+
}) {
|
|
136
|
+
if (plugins.length === 0) return createEmptyRuntime(context);
|
|
137
|
+
const issues = [];
|
|
138
|
+
const normalizedPlugins = /* @__PURE__ */ new Map();
|
|
139
|
+
for (const plugin of plugins) {
|
|
140
|
+
if (normalizedPlugins.has(plugin.id)) {
|
|
141
|
+
issues.push({ type: "duplicate_plugin", pluginId: plugin.id, message: `Plugin "${plugin.id}" registered more than once.` });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (plugin.apiVersion != null && plugin.apiVersion > PLUGIN_API_VERSION) {
|
|
145
|
+
issues.push({
|
|
146
|
+
type: "incompatible_api_version",
|
|
147
|
+
pluginId: plugin.id,
|
|
148
|
+
message: `Plugin "${plugin.id}" requires plugin API v${plugin.apiVersion}, but this runtime supports v${PLUGIN_API_VERSION}. Upgrade @fayz-ai/app-runtime.`
|
|
149
|
+
});
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
normalizedPlugins.set(plugin.id, plugin);
|
|
153
|
+
}
|
|
154
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
155
|
+
for (const b of tenantPlugins) bindings.set(b.pluginId, b);
|
|
156
|
+
const bindingsAreManaged = hasTenantBindings ?? tenantPlugins.length > 0;
|
|
157
|
+
const requested = /* @__PURE__ */ new Set();
|
|
158
|
+
const activationReason = /* @__PURE__ */ new Map();
|
|
159
|
+
for (const plugin of normalizedPlugins.values()) {
|
|
160
|
+
const binding = bindings.get(plugin.id);
|
|
161
|
+
if (binding?.status === "active") {
|
|
162
|
+
requested.add(plugin.id);
|
|
163
|
+
activationReason.set(plugin.id, "tenant");
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (plugin.defaultEnabled === true || !bindingsAreManaged && plugin.defaultEnabled !== false) {
|
|
167
|
+
requested.add(plugin.id);
|
|
168
|
+
activationReason.set(plugin.id, "default");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const orderedIds = [];
|
|
172
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
173
|
+
const visited = /* @__PURE__ */ new Set();
|
|
174
|
+
function visit(pluginId, ancestry = []) {
|
|
175
|
+
if (visited.has(pluginId)) return;
|
|
176
|
+
const plugin = normalizedPlugins.get(pluginId);
|
|
177
|
+
if (!plugin) return;
|
|
178
|
+
if (visiting.has(pluginId)) {
|
|
179
|
+
issues.push({ type: "circular_dependency", pluginId, message: `Circular dependency: ${[...ancestry, pluginId].join(" -> ")}.` });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
visiting.add(pluginId);
|
|
183
|
+
for (const depId of plugin.dependencies ?? []) {
|
|
184
|
+
if (!normalizedPlugins.has(depId)) {
|
|
185
|
+
issues.push({ type: "missing_dependency", pluginId, dependencyId: depId, message: `Plugin "${plugin.id}" depends on missing plugin "${depId}".` });
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (requested.has(pluginId) && !requested.has(depId)) {
|
|
189
|
+
requested.add(depId);
|
|
190
|
+
activationReason.set(depId, "dependency");
|
|
191
|
+
}
|
|
192
|
+
visit(depId, [...ancestry, pluginId]);
|
|
193
|
+
}
|
|
194
|
+
visiting.delete(pluginId);
|
|
195
|
+
visited.add(pluginId);
|
|
196
|
+
orderedIds.push(pluginId);
|
|
197
|
+
}
|
|
198
|
+
for (const id of normalizedPlugins.keys()) visit(id);
|
|
199
|
+
const resolvedById = /* @__PURE__ */ new Map();
|
|
200
|
+
for (const pluginId of orderedIds) {
|
|
201
|
+
const plugin = normalizedPlugins.get(pluginId);
|
|
202
|
+
if (!plugin) continue;
|
|
203
|
+
const binding = bindings.get(plugin.id);
|
|
204
|
+
const missing = (plugin.dependencies ?? []).filter((id) => !normalizedPlugins.has(id));
|
|
205
|
+
const compatible = !plugin.verticalId || plugin.verticalId === context.tenant?.verticalId;
|
|
206
|
+
if (!compatible) {
|
|
207
|
+
issues.push({ type: "vertical_mismatch", pluginId: plugin.id, message: `Plugin "${plugin.id}" requires vertical "${plugin.verticalId}".` });
|
|
208
|
+
}
|
|
209
|
+
const reason = activationReason.get(plugin.id) ?? "inactive";
|
|
210
|
+
const depsReady = (plugin.dependencies ?? []).every((id) => resolvedById.get(id)?.isActive);
|
|
211
|
+
const explicitlyDisabled = binding?.status === "disabled" || binding?.status === "removed";
|
|
212
|
+
const shouldActivate = reason === "dependency" ? true : requested.has(plugin.id) && !explicitlyDisabled;
|
|
213
|
+
const isActive = shouldActivate && compatible && missing.length === 0 && depsReady;
|
|
214
|
+
resolvedById.set(plugin.id, {
|
|
215
|
+
...plugin,
|
|
216
|
+
status: isActive ? "active" : binding?.status ?? "disabled",
|
|
217
|
+
isActive,
|
|
218
|
+
activationReason: isActive ? reason : "inactive",
|
|
219
|
+
config: binding?.config ?? {},
|
|
220
|
+
missingDependencies: missing,
|
|
221
|
+
settingsTabs: normalizeSettingsTabs(plugin),
|
|
222
|
+
widgets: plugin.widgets ?? [],
|
|
223
|
+
resolvedRegistries: plugin.registries ?? [],
|
|
224
|
+
resolvedAITools: plugin.aiTools ?? []
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
const resolvedPlugins = orderedIds.map((id) => resolvedById.get(id)).filter((p) => Boolean(p));
|
|
228
|
+
const activePlugins = resolvedPlugins.filter((p) => p.isActive);
|
|
229
|
+
const routes = [];
|
|
230
|
+
const navigation = [];
|
|
231
|
+
const settingsTabs = [];
|
|
232
|
+
const widgets = [];
|
|
233
|
+
const dashboardWidgets = [];
|
|
234
|
+
const capabilities = [];
|
|
235
|
+
const aiTools = [];
|
|
236
|
+
const registries = /* @__PURE__ */ new Map();
|
|
237
|
+
const pluginFeatures = [];
|
|
238
|
+
for (const plugin of activePlugins) {
|
|
239
|
+
routes.push(...plugin.routes.map((r) => ({ ...r, plugin })));
|
|
240
|
+
navigation.push(...plugin.navigation.map((entry, i) => ({
|
|
241
|
+
...entry,
|
|
242
|
+
id: entry.id ?? `${plugin.id}:${entry.route}:${i}`,
|
|
243
|
+
icon: entry.icon ?? plugin.icon
|
|
244
|
+
})));
|
|
245
|
+
settingsTabs.push(...plugin.settingsTabs);
|
|
246
|
+
capabilities.push(...plugin.capabilities ?? []);
|
|
247
|
+
aiTools.push(...plugin.resolvedAITools);
|
|
248
|
+
if (plugin.resolvedRegistries.length > 0) registries.set(plugin.id, plugin.resolvedRegistries);
|
|
249
|
+
if (plugin.declaredFeatures) pluginFeatures.push(...plugin.declaredFeatures);
|
|
250
|
+
widgets.push(...plugin.widgets.map((w, i) => ({
|
|
251
|
+
...w,
|
|
252
|
+
order: w.order ?? i,
|
|
253
|
+
config: { ...plugin.config, ...w.props ?? {} },
|
|
254
|
+
plugin
|
|
255
|
+
})));
|
|
256
|
+
dashboardWidgets.push(...(plugin.dashboardWidgets ?? []).map((w, i) => ({
|
|
257
|
+
...w,
|
|
258
|
+
domain: w.domain ?? plugin.id,
|
|
259
|
+
order: w.defaultOrder ?? i,
|
|
260
|
+
plugin
|
|
261
|
+
})));
|
|
262
|
+
}
|
|
263
|
+
navigation.sort((a, b) => {
|
|
264
|
+
const order = { main: 0, secondary: 1, settings: 2 };
|
|
265
|
+
return (order[a.section] ?? 99) - (order[b.section] ?? 99) || a.position - b.position;
|
|
266
|
+
});
|
|
267
|
+
settingsTabs.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
268
|
+
widgets.sort((a, b) => a.zone !== b.zone ? a.zone.localeCompare(b.zone) : a.order - b.order);
|
|
269
|
+
dashboardWidgets.sort((a, b) => a.order - b.order);
|
|
270
|
+
return { context, plugins: resolvedPlugins, activePlugins, routes, navigation, settingsTabs, widgets, dashboardWidgets, capabilities, aiTools, issues, registries, pluginFeatures };
|
|
271
|
+
}
|
|
272
|
+
function getWidgetsForZone(runtime, zone, contextOverrides) {
|
|
273
|
+
const ctx = { ...runtime.context, ...contextOverrides };
|
|
274
|
+
return runtime.widgets.filter((w) => w.zone === zone && isWidgetVisible(w, ctx));
|
|
275
|
+
}
|
|
276
|
+
function getDashboardWidgets(runtime, options) {
|
|
277
|
+
const ctx = { ...runtime.context, ...options.contextOverrides };
|
|
278
|
+
return runtime.dashboardWidgets.filter((w) => {
|
|
279
|
+
const surfaces = w.surfaces ?? ["home", "plugin-home"];
|
|
280
|
+
if (!surfaces.includes(options.surface)) return false;
|
|
281
|
+
if (options.domain && w.domain !== options.domain) return false;
|
|
282
|
+
if (w.verticalId && ctx.tenant?.verticalId && w.verticalId !== ctx.tenant.verticalId) return false;
|
|
283
|
+
if (w.permission && ctx.hasPermission && !ctx.hasPermission(w.permission)) return false;
|
|
284
|
+
return true;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
var PluginRuntimeContext = React.createContext(null);
|
|
288
|
+
var PluginRuntimeProvider = PluginRuntimeContext.Provider;
|
|
289
|
+
function usePluginRuntime() {
|
|
290
|
+
return React.useContext(PluginRuntimeContext) ?? createEmptyRuntime();
|
|
291
|
+
}
|
|
292
|
+
function usePluginRuntimeOptional() {
|
|
293
|
+
return React.useContext(PluginRuntimeContext);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { PLUGIN_API_VERSION, PluginRuntimeProvider, Registry, blockRegistry, componentRegistry, definePlugin, getBlock, getComponent, getDashboardWidgets, getMetric, getPage, getPlugin, getPluginFactory, getScaffold, getWidgetsForZone, isCustomId, listBlocks, listMetrics, listPluginFactories, listPlugins, metricRegistry, pageRegistry, pluginFactoryRegistry, pluginRegistry, registerBlock, registerComponent, registerMetric, registerPage, registerPlugin, registerPluginFactory, registerScaffold, resolvePluginComponent, resolvePluginRuntime, scaffoldRegistry, usePluginRuntime, usePluginRuntimeOptional };
|
|
297
|
+
//# sourceMappingURL=chunk-KAYQFSR6.js.map
|
|
298
|
+
//# sourceMappingURL=chunk-KAYQFSR6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/registry/index.ts","../src/plugin/runtime.ts"],"names":[],"mappings":";;;AAuCO,IAAM,WA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,CAAE,UAAA,IAAc,GAAA,CAAI,aAAA,IAAiB,CAAC,IAAI,aAAA,CAAc,CAAA,CAAE,UAAU,CAAA,EAAG,OAAO,KAAA;AAClF,IAAA,OAAO,IAAA;AAAA,EACT,CAAC,CAAA;AACH;AAEA,IAAM,oBAAA,GAA6B,oBAAoC,IAAI,CAAA;AACpE,IAAM,wBAAwB,oBAAA,CAAqB;AAEnD,SAAS,gBAAA,GAAkC;AAChD,EAAA,OAAa,KAAA,CAAA,UAAA,CAAW,oBAAoB,CAAA,IAAK,kBAAA,EAAmB;AACtE;AAEO,SAAS,wBAAA,GAAiD;AAC/D,EAAA,OAAa,iBAAW,oBAAoB,CAAA;AAC9C","file":"chunk-KAYQFSR6.js","sourcesContent":["import type { ComponentType } from 'react'\n\n// ---------------------------------------------------------------------------\n// Uniform registry — the indirection layer that lets a pure-data AppManifest\n// reference code by string id. Generalizes the entity registry pattern to\n// components, blocks, pages, metrics, scaffolds and plugins.\n//\n// Naming convention: SDK/plugin artifacts use a namespaced id\n// (`agenda.week-view`, `crud.detail-header`); app-local custom code uses the\n// reserved `custom:` prefix (`custom:tannat.HarvestBoard`). The platform never\n// generates `custom:` ids — they only come from an app's registry.tsx.\n// ---------------------------------------------------------------------------\n\n/** A JSON Schema object (loosely typed; validated by tooling, not at runtime). */\nexport type JsonSchema = Record<string, unknown>\n\nexport type RegistrySource = 'sdk' | 'plugin' | 'app'\n\nexport interface RegistryMeta {\n /** Human label for the platform editor. */\n label?: string\n description?: string\n /** Where this artifact came from (for introspection / conflict reporting). */\n source?: RegistrySource\n /** Owning plugin id, when source is 'plugin'. */\n pluginId?: string\n /** JSON Schema for this artifact's props/config — drives the visual editor\n * and constrains AI generation. Optional but strongly encouraged. */\n propsSchema?: JsonSchema\n}\n\nexport interface RegistryEntry<T> {\n id: string\n value: T\n meta: RegistryMeta\n}\n\n/** A typed, introspectable id→value map. Last registration wins (so an app's\n * registry.tsx can override an SDK artifact by re-registering its id). */\nexport class Registry<T> {\n private readonly entries = new Map<string, RegistryEntry<T>>()\n\n constructor(readonly kind: string) {}\n\n register(id: string, value: T, meta: RegistryMeta = {}): void {\n this.entries.set(id, { id, value, meta })\n }\n\n get(id: string): T | undefined {\n return this.entries.get(id)?.value\n }\n\n getEntry(id: string): RegistryEntry<T> | undefined {\n return this.entries.get(id)\n }\n\n has(id: string): boolean {\n return this.entries.has(id)\n }\n\n list(): RegistryEntry<T>[] {\n return Array.from(this.entries.values())\n }\n\n ids(): string[] {\n return Array.from(this.entries.keys())\n }\n\n clear(): void {\n this.entries.clear()\n }\n}\n\n/** True for app-local custom artifacts (`custom:*`). */\nexport function isCustomId(id: string): boolean {\n return id.startsWith('custom:')\n}\n\n// ---------------------------------------------------------------------------\n// Metric definitions (consumed by dashboard / reports / KPI panels).\n// ---------------------------------------------------------------------------\n\nexport type MetricFormat = 'number' | 'currency' | 'percent' | 'duration' | 'rating'\n\nexport interface MetricContext {\n tenantId?: string\n /** ISO date range the metric should compute over, when applicable. */\n range?: { from: string; to: string }\n [key: string]: unknown\n}\n\nexport interface MetricValue {\n value: number\n previousValue?: number\n trend?: 'up' | 'down' | 'flat'\n}\n\nexport interface MetricDefinition {\n id: string\n label?: string\n category?: string\n format?: MetricFormat\n compute: (ctx: MetricContext) => Promise<MetricValue> | MetricValue\n}\n\n// ---------------------------------------------------------------------------\n// Concrete registries. Components/blocks/pages/scaffolds hold React component\n// types; metrics hold definitions; plugins hold opaque manifests (typed at the\n// plugin layer to avoid a circular import).\n// ---------------------------------------------------------------------------\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyComponent = ComponentType<any>\n\nexport const componentRegistry = new Registry<AnyComponent>('component')\nexport const blockRegistry = new Registry<AnyComponent>('block')\nexport const pageRegistry = new Registry<AnyComponent>('page')\nexport const scaffoldRegistry = new Registry<AnyComponent>('scaffold')\nexport const metricRegistry = new Registry<MetricDefinition>('metric')\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const pluginRegistry = new Registry<any>('plugin')\n\n// Thin functional facade (the public API surface) -----------------------------\n\nexport const registerComponent = (id: string, c: AnyComponent, meta?: RegistryMeta) =>\n componentRegistry.register(id, c, meta)\nexport const getComponent = (id: string) => componentRegistry.get(id)\n\nexport const registerBlock = (id: string, c: AnyComponent, meta?: RegistryMeta) =>\n blockRegistry.register(id, c, meta)\nexport const getBlock = (id: string) => blockRegistry.get(id)\nexport const listBlocks = () => blockRegistry.list()\n\nexport const registerPage = (id: string, c: AnyComponent, meta?: RegistryMeta) =>\n pageRegistry.register(id, c, meta)\nexport const getPage = (id: string) => pageRegistry.get(id)\n\nexport const registerScaffold = (id: string, c: AnyComponent, meta?: RegistryMeta) =>\n scaffoldRegistry.register(id, c, meta)\nexport const getScaffold = (id: string) => scaffoldRegistry.get(id)\n\nexport const registerMetric = (def: MetricDefinition, meta?: RegistryMeta) =>\n metricRegistry.register(def.id, def, meta)\nexport const getMetric = (id: string) => metricRegistry.get(id)\nexport const listMetrics = () => metricRegistry.list()\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const registerPlugin = (id: string, manifest: any, meta?: RegistryMeta) =>\n pluginRegistry.register(id, manifest, meta)\nexport const getPlugin = (id: string) => pluginRegistry.get(id)\nexport const listPlugins = () => pluginRegistry.list()\n\n// Plugin factories — a generated app registers each installed @fayz-ai/plugin-*\n// factory by id (src/plugins.generated.ts), so a scaffold can resolve a\n// manifest's PluginRef (id + JSON config) to a live PluginManifest:\n// getPluginFactory(ref.id)?.(ref.config)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type PluginFactory = (config?: Record<string, unknown>) => any\nexport const pluginFactoryRegistry = new Registry<PluginFactory>('plugin-factory')\nexport const registerPluginFactory = (id: string, factory: PluginFactory, meta?: RegistryMeta) =>\n pluginFactoryRegistry.register(id, factory, meta)\nexport const getPluginFactory = (id: string) => pluginFactoryRegistry.get(id)\nexport const listPluginFactories = () => pluginFactoryRegistry.list()\n","import * as React from 'react'\nimport type {\n PluginManifest,\n PluginRuntime,\n PluginRuntimeContext,\n PluginRuntimeIssue,\n PluginRuntimeRoute,\n PluginSettingsTab,\n PluginWidgetDefinition,\n PluginWidgetZone,\n ResolvedPluginManifest,\n ResolvedPluginWidget,\n TenantPluginBinding,\n PluginRegistryDef,\n PluginAITool,\n PluginNavigationEntry,\n PluginCapability,\n PluginWidgetVisibility,\n ResolvedDashboardWidget,\n DashboardSurface,\n} from '../types/plugins'\nimport type { FeatureDeclaration } from '../types/permissions'\nimport { getComponent } from '../registry'\n\n/** The plugin contract version this runtime understands. A plugin declaring a\n * higher apiVersion is rejected rather than mis-rendered. */\nexport const PLUGIN_API_VERSION = 1\n\n/** Resolve a plugin route/widget/settings/onboarding target to a component,\n * whether it provided the component directly or a registered component id. */\nexport function resolvePluginComponent(\n def: { component?: React.ComponentType<unknown>; componentId?: string },\n): React.ComponentType<unknown> | undefined {\n if (def.component) return def.component\n if (def.componentId) return getComponent(def.componentId) as React.ComponentType<unknown> | undefined\n return undefined\n}\n\ninterface ResolvePluginRuntimeOptions {\n plugins?: PluginManifest[]\n tenantPlugins?: TenantPluginBinding[]\n hasTenantBindings?: boolean\n context: PluginRuntimeContext\n}\n\nconst EMPTY_CONTEXT: PluginRuntimeContext = {\n tenant: null,\n user: null,\n currentPath: '/',\n matchedPath: '/',\n layout: 'sidebar',\n}\n\nfunction slugify(input: string): string {\n return input.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')\n}\n\nfunction matchesRoutePattern(pattern: string, currentPath: string): boolean {\n if (pattern === currentPath) return true\n if (pattern.endsWith('/*')) {\n const base = pattern.slice(0, -2)\n return currentPath === base || currentPath.startsWith(`${base}/`)\n }\n if (pattern.endsWith('*')) return currentPath.startsWith(pattern.slice(0, -1))\n return false\n}\n\nfunction isWidgetVisible(widget: ResolvedPluginWidget, context: PluginRuntimeContext): boolean {\n if (widget.permission && context.hasPermission && !context.hasPermission(widget.permission)) return false\n const visibility: PluginWidgetVisibility | undefined = widget.visibility\n if (!visibility) return true\n\n if (visibility.layouts && !visibility.layouts.includes(context.layout)) return false\n if (visibility.roles && context.user?.role && !visibility.roles.includes(context.user.role)) return false\n if (visibility.roles && !context.user?.role) return false\n if (visibility.plans && context.tenant?.plan && !visibility.plans.includes(context.tenant.plan)) return false\n if (visibility.plans && !context.tenant?.plan) return false\n if (visibility.routes && !visibility.routes.some((p) => matchesRoutePattern(p, context.currentPath))) return false\n if (visibility.excludeRoutes?.some((p) => matchesRoutePattern(p, context.currentPath))) return false\n if (visibility.permissions?.length) {\n if (!context.hasPermission) return false\n if (!visibility.permissions.every((req) => context.hasPermission?.(req))) return false\n }\n if (visibility.when && !visibility.when(context)) return false\n return true\n}\n\nfunction normalizeSettingsTabs(plugin: PluginManifest): PluginSettingsTab[] {\n return (plugin.settings ?? []).map((entry, index) => ({\n ...entry,\n pluginId: entry.pluginId ?? plugin.id,\n order: entry.order ?? index,\n id: entry.id ?? `${plugin.id}-${slugify(entry.label)}`,\n }))\n}\n\nfunction createEmptyRuntime(context: PluginRuntimeContext = EMPTY_CONTEXT): PluginRuntime {\n return {\n context,\n plugins: [],\n activePlugins: [],\n routes: [],\n navigation: [],\n settingsTabs: [],\n widgets: [],\n dashboardWidgets: [],\n capabilities: [],\n aiTools: [],\n registries: new Map(),\n pluginFeatures: [],\n issues: [],\n }\n}\n\nexport function definePlugin<T extends PluginManifest>(plugin: T): T {\n return plugin\n}\n\nexport function resolvePluginRuntime({\n plugins = [],\n tenantPlugins = [],\n hasTenantBindings,\n context,\n}: ResolvePluginRuntimeOptions): PluginRuntime {\n if (plugins.length === 0) return createEmptyRuntime(context)\n\n const issues: PluginRuntimeIssue[] = []\n const normalizedPlugins = new Map<string, PluginManifest>()\n\n for (const plugin of plugins) {\n if (normalizedPlugins.has(plugin.id)) {\n issues.push({ type: 'duplicate_plugin', pluginId: plugin.id, message: `Plugin \"${plugin.id}\" registered more than once.` })\n continue\n }\n if (plugin.apiVersion != null && plugin.apiVersion > PLUGIN_API_VERSION) {\n issues.push({\n type: 'incompatible_api_version',\n pluginId: plugin.id,\n message: `Plugin \"${plugin.id}\" requires plugin API v${plugin.apiVersion}, but this runtime supports v${PLUGIN_API_VERSION}. Upgrade @fayz-ai/app-runtime.`,\n })\n continue\n }\n normalizedPlugins.set(plugin.id, plugin)\n }\n\n const bindings = new Map<string, TenantPluginBinding>()\n for (const b of tenantPlugins) bindings.set(b.pluginId, b)\n const bindingsAreManaged = hasTenantBindings ?? tenantPlugins.length > 0\n\n const requested = new Set<string>()\n const activationReason = new Map<string, ResolvedPluginManifest['activationReason']>()\n\n for (const plugin of normalizedPlugins.values()) {\n const binding = bindings.get(plugin.id)\n if (binding?.status === 'active') {\n requested.add(plugin.id)\n activationReason.set(plugin.id, 'tenant')\n continue\n }\n if (plugin.defaultEnabled === true || (!bindingsAreManaged && plugin.defaultEnabled !== false)) {\n requested.add(plugin.id)\n activationReason.set(plugin.id, 'default')\n }\n }\n\n const orderedIds: string[] = []\n const visiting = new Set<string>()\n const visited = new Set<string>()\n\n function visit(pluginId: string, ancestry: string[] = []): void {\n if (visited.has(pluginId)) return\n const plugin = normalizedPlugins.get(pluginId)\n if (!plugin) return\n if (visiting.has(pluginId)) {\n issues.push({ type: 'circular_dependency', pluginId, message: `Circular dependency: ${[...ancestry, pluginId].join(' -> ')}.` })\n return\n }\n visiting.add(pluginId)\n for (const depId of plugin.dependencies ?? []) {\n if (!normalizedPlugins.has(depId)) {\n issues.push({ type: 'missing_dependency', pluginId, dependencyId: depId, message: `Plugin \"${plugin.id}\" depends on missing plugin \"${depId}\".` })\n continue\n }\n if (requested.has(pluginId) && !requested.has(depId)) {\n requested.add(depId)\n activationReason.set(depId, 'dependency')\n }\n visit(depId, [...ancestry, pluginId])\n }\n visiting.delete(pluginId)\n visited.add(pluginId)\n orderedIds.push(pluginId)\n }\n\n for (const id of normalizedPlugins.keys()) visit(id)\n\n const resolvedById = new Map<string, ResolvedPluginManifest>()\n\n for (const pluginId of orderedIds) {\n const plugin = normalizedPlugins.get(pluginId)\n if (!plugin) continue\n const binding = bindings.get(plugin.id)\n const missing = (plugin.dependencies ?? []).filter((id) => !normalizedPlugins.has(id))\n const compatible = !plugin.verticalId || plugin.verticalId === context.tenant?.verticalId\n if (!compatible) {\n issues.push({ type: 'vertical_mismatch', pluginId: plugin.id, message: `Plugin \"${plugin.id}\" requires vertical \"${plugin.verticalId}\".` })\n }\n const reason = activationReason.get(plugin.id) ?? 'inactive'\n const depsReady = (plugin.dependencies ?? []).every((id) => resolvedById.get(id)?.isActive)\n const explicitlyDisabled = binding?.status === 'disabled' || binding?.status === 'removed'\n const shouldActivate = reason === 'dependency' ? true : requested.has(plugin.id) && !explicitlyDisabled\n const isActive = shouldActivate && compatible && missing.length === 0 && depsReady\n\n resolvedById.set(plugin.id, {\n ...plugin,\n status: isActive ? 'active' : (binding?.status ?? 'disabled'),\n isActive,\n activationReason: isActive ? reason : 'inactive',\n config: binding?.config ?? {},\n missingDependencies: missing,\n settingsTabs: normalizeSettingsTabs(plugin),\n widgets: plugin.widgets ?? [],\n resolvedRegistries: plugin.registries ?? [],\n resolvedAITools: plugin.aiTools ?? [],\n })\n }\n\n const resolvedPlugins = orderedIds\n .map((id) => resolvedById.get(id))\n .filter((p): p is ResolvedPluginManifest => Boolean(p))\n\n const activePlugins = resolvedPlugins.filter((p) => p.isActive)\n const routes: PluginRuntimeRoute[] = []\n const navigation: PluginNavigationEntry[] = []\n const settingsTabs: PluginSettingsTab[] = []\n const widgets: ResolvedPluginWidget[] = []\n const dashboardWidgets: ResolvedDashboardWidget[] = []\n const capabilities: PluginCapability[] = []\n const aiTools: PluginAITool[] = []\n const registries = new Map<string, PluginRegistryDef[]>()\n const pluginFeatures: FeatureDeclaration[] = []\n\n for (const plugin of activePlugins) {\n routes.push(...plugin.routes.map((r) => ({ ...r, plugin })))\n navigation.push(...plugin.navigation.map((entry, i) => ({\n ...entry,\n id: entry.id ?? `${plugin.id}:${entry.route}:${i}`,\n icon: entry.icon ?? plugin.icon,\n })))\n settingsTabs.push(...plugin.settingsTabs)\n capabilities.push(...(plugin.capabilities ?? []))\n aiTools.push(...plugin.resolvedAITools)\n if (plugin.resolvedRegistries.length > 0) registries.set(plugin.id, plugin.resolvedRegistries)\n if (plugin.declaredFeatures) pluginFeatures.push(...plugin.declaredFeatures)\n widgets.push(...plugin.widgets.map((w, i) => ({\n ...w,\n order: w.order ?? i,\n config: { ...plugin.config, ...(w.props ?? {}) },\n plugin,\n })))\n dashboardWidgets.push(...(plugin.dashboardWidgets ?? []).map((w, i) => ({\n ...w,\n domain: w.domain ?? plugin.id,\n order: w.defaultOrder ?? i,\n plugin,\n })))\n }\n\n navigation.sort((a, b) => {\n const order = { main: 0, secondary: 1, settings: 2 }\n return (order[a.section] ?? 99) - (order[b.section] ?? 99) || a.position - b.position\n })\n settingsTabs.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))\n widgets.sort((a, b) => a.zone !== b.zone ? a.zone.localeCompare(b.zone) : a.order - b.order)\n dashboardWidgets.sort((a, b) => a.order - b.order)\n\n return { context, plugins: resolvedPlugins, activePlugins, routes, navigation, settingsTabs, widgets, dashboardWidgets, capabilities, aiTools, issues, registries, pluginFeatures }\n}\n\nexport function getWidgetsForZone(\n runtime: PluginRuntime,\n zone: PluginWidgetZone,\n contextOverrides?: Partial<PluginRuntimeContext>,\n): ResolvedPluginWidget[] {\n const ctx = { ...runtime.context, ...contextOverrides }\n return runtime.widgets.filter((w) => w.zone === zone && isWidgetVisible(w, ctx))\n}\n\nexport function getDashboardWidgets(\n runtime: PluginRuntime,\n options: { surface: DashboardSurface; domain?: string; contextOverrides?: Partial<PluginRuntimeContext> },\n): ResolvedDashboardWidget[] {\n const ctx = { ...runtime.context, ...options.contextOverrides }\n return runtime.dashboardWidgets.filter((w) => {\n const surfaces = w.surfaces ?? ['home', 'plugin-home']\n if (!surfaces.includes(options.surface)) return false\n if (options.domain && w.domain !== options.domain) return false\n if (w.verticalId && ctx.tenant?.verticalId && w.verticalId !== ctx.tenant.verticalId) return false\n if (w.permission && ctx.hasPermission && !ctx.hasPermission(w.permission)) return false\n return true\n })\n}\n\nconst PluginRuntimeContext = React.createContext<PluginRuntime | null>(null)\nexport const PluginRuntimeProvider = PluginRuntimeContext.Provider\n\nexport function usePluginRuntime(): PluginRuntime {\n return React.useContext(PluginRuntimeContext) ?? createEmptyRuntime()\n}\n\nexport function usePluginRuntimeOptional(): PluginRuntime | null {\n return React.useContext(PluginRuntimeContext)\n}\n"]}
|