@framework-m/plugin-sdk 0.2.10 → 0.3.0
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +142 -105
- package/dist/index.js.map +1 -1
- package/dist/loader/federation.d.ts +24 -0
- package/dist/loader/federation.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var P=(r,e,t)=>e in r?p(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e,t)=>P(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),a=require("react");class v{constructor(){u(this,"factories",new Map);u(this,"instances",new Map)}register(e,t){this.factories.set(e,t),this.instances.delete(e)}async get(e){if(this.instances.has(e))return this.instances.get(e);const t=this.factories.get(e);if(!t)throw new Error(`Service "${e}" is not registered`);const i=await Promise.resolve(t());return this.instances.set(e,i),i}has(e){return this.factories.has(e)}getAll(){return Array.from(this.factories.keys())}clear(){this.factories.clear(),this.instances.clear()}}const d="0.1.0",f={Sales:"shopping-cart",Inventory:"package",HR:"users",Finance:"dollar-sign",Core:"settings",Other:"folder"};function C(){const r=globalThis.__FRAMEWORK_M_PLUGIN_DEBUG__;if(typeof r=="boolean")return r;if(typeof r=="string")return["1","true","yes","on"].includes(r.toLowerCase());const e=globalThis.process;if(e!=null&&e.env){const t=e.env.FRAMEWORK_M_PLUGIN_DEBUG;if(typeof t=="string")return["1","true","yes","on"].includes(t.toLowerCase())}return!1}const O={debug(r,...e){C()&&console.debug(`[PluginRegistry] ${r}`,...e)}};class w{constructor(){u(this,"plugins",new Map);u(this,"menuCache",null);u(this,"serviceContainer",new v);u(this,"routeOwners",new Map);u(this,"menuNameOwners",new Map);u(this,"menuRouteOwners",new Map);u(this,"serviceOwners",new Map);u(this,"diagnostics",[]);u(this,"permissionChecker",null);u(this,"eventListeners",{"plugin:registered":new Set,"plugin:error":new Set})}async register(e){if(!e.name||!e.version)throw new Error("Plugin must have name and version");const t=this.validateRegistration(e),i=t.filter(o=>o.severity==="error");if(i.length>0){const o=new Error(`Plugin "${e.name}" registration failed: ${i.map(c=>c.message).join("; ")}`);throw this.emit("plugin:error",{plugin:e,error:o}),o}const s=this.plugins.get(e.name);this.plugins.set(e.name,e),this.rebuildIndexesAndServices(),this.menuCache=null;try{e.onInit&&await Promise.resolve(e.onInit())}catch(o){throw s?this.plugins.set(e.name,s):this.plugins.delete(e.name),this.rebuildIndexesAndServices(),this.menuCache=null,this.emit("plugin:error",{plugin:e,error:o}),o}s!=null&&s.onDestroy&&s!==e&&await Promise.resolve(s.onDestroy()),this.emit("plugin:registered",{plugin:e});const n=t.filter(o=>o.severity==="warning");n.length>0&&O.debug(`Registered plugin "${e.name}" with warnings`,n)}getMenu(){if(this.menuCache)return this.menuCache;const e=[];for(const t of this.plugins.values())t.menu&&e.push(...t.menu);return e.length===0?(this.menuCache=[],this.menuCache):(this.menuCache=this.mergeMenus(e),this.menuCache)}getRoutes(){const e=[];for(const t of this.plugins.values())t.routes&&e.push(...t.routes);return e}getPlugin(e){return this.plugins.get(e)}getAllPlugins(){return Array.from(this.plugins.values())}getServiceContainer(){return this.serviceContainer}async unregister(e){const t=this.plugins.get(e);return t?(this.plugins.delete(e),this.rebuildIndexesAndServices(),this.menuCache=null,t.onDestroy&&await Promise.resolve(t.onDestroy()),!0):!1}async getService(e){return this.serviceContainer.get(e)}getWidgets(){const e=[];for(const t of this.plugins.values())t.widgets&&e.push(...t.widgets);return e}setPermissionChecker(e){this.permissionChecker=e}getPermissionChecker(){return this.permissionChecker}on(e,t){return this.eventListeners[e].add(t),()=>{this.eventListeners[e].delete(t)}}getDiagnostics(e){return e?this.diagnostics.filter(t=>t.severity===e):[...this.diagnostics]}clearDiagnostics(){this.diagnostics=[]}checkCompatibility(){const e=[];for(const t of this.plugins.values()){const i={name:t.name,version:t.version,sdkCompatible:!0,missingPeerPlugins:[]};if(t.minSdkVersion&&(i.sdkCompatible=this.checkSemverCompat(d,t.minSdkVersion)),t.peerPlugins)for(const s of t.peerPlugins)this.plugins.has(s)||i.missingPeerPlugins.push(s);e.push(i)}return e}checkSemverCompat(e,t){const i=t.replace(/^>=?/,""),[s,n=0,o=0]=e.split(".").map(Number),[c,l=0,m=0]=i.split(".").map(Number);return s!==c?s>c:n!==l?n>l:o>=m}validateRegistration(e){return[...this.validateSdkCompatibility(e),...this.validateDuplicatePlugin(e),...this.validateRouteCollisions(e),...this.validateMenuCollisions(e),...this.validateServiceCollisions(e)]}validateSdkCompatibility(e){const t=[];return e.minSdkVersion&&(this.checkSemverCompat(d,e.minSdkVersion)||t.push(this.addDiagnostic({code:"SDK_INCOMPATIBLE",severity:"warning",message:`Plugin ${e.name} requires SDK >=${e.minSdkVersion}, current SDK is ${d}. Plugin may not work correctly.`,pluginName:e.name,key:e.minSdkVersion}))),t}validateDuplicatePlugin(e){const t=[];return this.plugins.has(e.name)&&t.push(this.addDiagnostic({code:"PLUGIN_DUPLICATE",severity:"warning",message:`Plugin ${e.name} is already registered and will be replaced`,pluginName:e.name,conflictingPluginName:e.name,key:e.name})),t}validateRouteCollisions(e){const t=[],i=new Set;for(const s of e.routes??[]){if(i.has(s.path)){t.push(this.addDiagnostic({code:"ROUTE_COLLISION",severity:"error",message:`Duplicate route path "${s.path}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:s.path}));continue}i.add(s.path);const n=this.routeOwners.get(s.path);n&&n!==e.name&&t.push(this.addDiagnostic({code:"ROUTE_COLLISION",severity:"error",message:`Route path "${s.path}" from plugin ${e.name} conflicts with plugin ${n}`,pluginName:e.name,conflictingPluginName:n,key:s.path}))}return t}validateMenuCollisions(e){const t=[],i=new Set,s=new Set;for(const n of e.menu??[]){if(i.has(n.name))t.push(this.addDiagnostic({code:"MENU_NAME_COLLISION",severity:"error",message:`Duplicate menu name "${n.name}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:n.name}));else{i.add(n.name);const o=this.menuNameOwners.get(n.name);o&&o!==e.name&&t.push(this.addDiagnostic({code:"MENU_NAME_COLLISION",severity:"error",message:`Menu name "${n.name}" from plugin ${e.name} conflicts with plugin ${o}`,pluginName:e.name,conflictingPluginName:o,key:n.name}))}if(s.has(n.route))t.push(this.addDiagnostic({code:"MENU_ROUTE_COLLISION",severity:"error",message:`Duplicate menu route "${n.route}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:n.route}));else{s.add(n.route);const o=this.menuRouteOwners.get(n.route);o&&o!==e.name&&t.push(this.addDiagnostic({code:"MENU_ROUTE_COLLISION",severity:"error",message:`Menu route "${n.route}" from plugin ${e.name} conflicts with plugin ${o}`,pluginName:e.name,conflictingPluginName:o,key:n.route}))}}return t}validateServiceCollisions(e){const t=[],i=new Set;for(const s of Object.keys(e.services??{})){if(i.has(s)){t.push(this.addDiagnostic({code:"SERVICE_COLLISION",severity:"error",message:`Duplicate service "${s}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:s}));continue}i.add(s);const n=this.serviceOwners.get(s);n&&n!==e.name&&t.push(this.addDiagnostic({code:"SERVICE_COLLISION",severity:"error",message:`Service "${s}" from plugin ${e.name} conflicts with plugin ${n}`,pluginName:e.name,conflictingPluginName:n,key:s}))}return t}addDiagnostic(e){const t={...e,timestamp:new Date().toISOString()};return this.diagnostics.push(t),t}mergeMenus(e){var i;const t=new Map;for(const s of e){const n=s.module||"Other";t.has(n)||t.set(n,{name:n.toLowerCase(),label:n,route:`/${n.toLowerCase()}`,icon:this.getModuleIcon(n),order:s.order,children:[]});const o=t.get(n);if(s.order!==void 0&&(o.order===void 0||s.order<o.order)&&(o.order=s.order),s.category){let c=(i=o.children)==null?void 0:i.find(l=>l.label===s.category);c||(c={name:s.category.toLowerCase(),label:s.category,route:`/${n.toLowerCase()}/${s.category.toLowerCase()}`,children:[]},o.children.push(c)),c.children.push(s)}else o.children.push(s)}return Array.from(t.values()).sort((s,n)=>(s.order??999)-(n.order??999))}getModuleIcon(e){return f[e]||f.Other}rebuildIndexesAndServices(){this.routeOwners.clear(),this.menuNameOwners.clear(),this.menuRouteOwners.clear(),this.serviceOwners.clear(),this.serviceContainer.clear();for(const e of this.plugins.values())this.registerPluginServices(e),this.registerPluginRoutes(e),this.registerPluginMenuItems(e)}registerPluginServices(e){for(const[t,i]of Object.entries(e.services??{}))this.serviceContainer.register(t,i),this.serviceOwners.set(t,e.name)}registerPluginRoutes(e){for(const t of e.routes??[])this.routeOwners.set(t.path,e.name)}registerPluginMenuItems(e){for(const t of e.menu??[])this.menuNameOwners.set(t.name,e.name),this.menuRouteOwners.set(t.route,e.name)}emit(e,t){for(const i of this.eventListeners[e])i(t)}}const g=a.createContext(null);function N({children:r,registry:e}){const[t]=a.useState(()=>e??new w),[i,s]=a.useState(!1);return a.useEffect(()=>{s(!0)},[]),i?S.jsx(g.Provider,{value:t,children:r}):null}async function y(r,e){const t=[];for(const i of r){if(i.hidden||i.permissions&&i.permissions.length>0&&!await Promise.resolve(e(i.permissions)))continue;const s=i.children?await y(i.children,e):void 0;i.children&&((s==null?void 0:s.length)??0)===0||t.push({...i,children:s})}return t}function M(){const r=a.useContext(g),[e,t]=a.useState([]);if(!r)throw new Error("usePluginMenu must be used within PluginRegistryProvider");return a.useEffect(()=>{let i=!1;return(async()=>{const n=r.getMenu(),o=r.getPermissionChecker();if(!o){i||t(n.filter(l=>!l.hidden));return}const c=await y(n,o);i||t(c)})(),()=>{i=!0}},[r]),e}function R(r){const e=a.useContext(g);if(!e)throw new Error("usePlugin must be used within PluginRegistryProvider");return a.useMemo(()=>e.getPlugin(r),[e,r])}function I(r){const e=a.useContext(g);if(!e)throw new Error("useService must be used within PluginRegistryProvider");const[t,i]=a.useState(null),[s,n]=a.useState(!0),[o,c]=a.useState(null),l=a.useMemo(()=>e.getService(r),[e,r]);return a.useEffect(()=>{let m=!1;return n(!0),c(null),l.then(h=>{m||(i(h),n(!1))}).catch(h=>{m||(c(h instanceof Error?h:new Error(String(h))),n(!1))}),()=>{m=!0}},[l]),{service:t,isLoading:s,error:o}}async function E(r,e){const t=[];for(const i of r)i.permissions&&i.permissions.length>0&&!await Promise.resolve(e(i.permissions))||t.push(i);return t}function k(){const r=a.useContext(g),[e,t]=a.useState([]);if(!r)throw new Error("useWidgets must be used within PluginRegistryProvider");return a.useEffect(()=>{let i=!1;return(async()=>{const n=r.getWidgets(),o=r.getPermissionChecker();if(!o){i||t(n);return}const c=await E(n,o);i||t(c)})(),()=>{i=!0}},[r]),e}exports.PluginRegistry=w;exports.PluginRegistryContext=g;exports.PluginRegistryProvider=N;exports.SDK_VERSION=d;exports.ServiceContainer=v;exports.usePlugin=R;exports.usePluginMenu=M;exports.useService=I;exports.useWidgets=k;
|
|
1
|
+
"use strict";var P=Object.defineProperty;var S=(n,e,t)=>e in n?P(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var u=(n,e,t)=>S(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),c=require("react");class v{constructor(){u(this,"factories",new Map);u(this,"instances",new Map)}register(e,t){this.factories.set(e,t),this.instances.delete(e)}async get(e){if(this.instances.has(e))return this.instances.get(e);const t=this.factories.get(e);if(!t)throw new Error(`Service "${e}" is not registered`);const i=await Promise.resolve(t());return this.instances.set(e,i),i}has(e){return this.factories.has(e)}getAll(){return Array.from(this.factories.keys())}clear(){this.factories.clear(),this.instances.clear()}}const d="0.1.0",f={Sales:"shopping-cart",Inventory:"package",HR:"users",Finance:"dollar-sign",Core:"settings",Other:"folder"};function O(){const n=globalThis.__FRAMEWORK_M_PLUGIN_DEBUG__;if(typeof n=="boolean")return n;if(typeof n=="string")return["1","true","yes","on"].includes(n.toLowerCase());const e=globalThis.process;if(e!=null&&e.env){const t=e.env.FRAMEWORK_M_PLUGIN_DEBUG;if(typeof t=="string")return["1","true","yes","on"].includes(t.toLowerCase())}return!1}const N={debug(n,...e){O()&&console.debug(`[PluginRegistry] ${n}`,...e)}};class w{constructor(){u(this,"plugins",new Map);u(this,"menuCache",null);u(this,"serviceContainer",new v);u(this,"routeOwners",new Map);u(this,"menuNameOwners",new Map);u(this,"menuRouteOwners",new Map);u(this,"serviceOwners",new Map);u(this,"diagnostics",[]);u(this,"permissionChecker",null);u(this,"eventListeners",{"plugin:registered":new Set,"plugin:error":new Set})}async register(e){if(!e.name||!e.version)throw new Error("Plugin must have name and version");const t=this.validateRegistration(e),i=t.filter(o=>o.severity==="error");if(i.length>0){const o=new Error(`Plugin "${e.name}" registration failed: ${i.map(a=>a.message).join("; ")}`);throw this.emit("plugin:error",{plugin:e,error:o}),o}const s=this.plugins.get(e.name);this.plugins.set(e.name,e),this.rebuildIndexesAndServices(),this.menuCache=null;try{e.onInit&&await Promise.resolve(e.onInit())}catch(o){throw s?this.plugins.set(e.name,s):this.plugins.delete(e.name),this.rebuildIndexesAndServices(),this.menuCache=null,this.emit("plugin:error",{plugin:e,error:o}),o}s!=null&&s.onDestroy&&s!==e&&await Promise.resolve(s.onDestroy()),this.emit("plugin:registered",{plugin:e});const r=t.filter(o=>o.severity==="warning");r.length>0&&N.debug(`Registered plugin "${e.name}" with warnings`,r)}getMenu(){if(this.menuCache)return this.menuCache;const e=[];for(const t of this.plugins.values())t.menu&&e.push(...t.menu);return e.length===0?(this.menuCache=[],this.menuCache):(this.menuCache=this.mergeMenus(e),this.menuCache)}getRoutes(){const e=[];for(const t of this.plugins.values())t.routes&&e.push(...t.routes);return e}getPlugin(e){return this.plugins.get(e)}getAllPlugins(){return Array.from(this.plugins.values())}getServiceContainer(){return this.serviceContainer}async unregister(e){const t=this.plugins.get(e);return t?(this.plugins.delete(e),this.rebuildIndexesAndServices(),this.menuCache=null,t.onDestroy&&await Promise.resolve(t.onDestroy()),!0):!1}async getService(e){return this.serviceContainer.get(e)}getWidgets(){const e=[];for(const t of this.plugins.values())t.widgets&&e.push(...t.widgets);return e}setPermissionChecker(e){this.permissionChecker=e}getPermissionChecker(){return this.permissionChecker}on(e,t){return this.eventListeners[e].add(t),()=>{this.eventListeners[e].delete(t)}}getDiagnostics(e){return e?this.diagnostics.filter(t=>t.severity===e):[...this.diagnostics]}clearDiagnostics(){this.diagnostics=[]}checkCompatibility(){const e=[];for(const t of this.plugins.values()){const i={name:t.name,version:t.version,sdkCompatible:!0,missingPeerPlugins:[]};if(t.minSdkVersion&&(i.sdkCompatible=this.checkSemverCompat(d,t.minSdkVersion)),t.peerPlugins)for(const s of t.peerPlugins)this.plugins.has(s)||i.missingPeerPlugins.push(s);e.push(i)}return e}checkSemverCompat(e,t){const i=t.replace(/^>=?/,""),[s,r=0,o=0]=e.split(".").map(Number),[a,l=0,h=0]=i.split(".").map(Number);return s!==a?s>a:r!==l?r>l:o>=h}validateRegistration(e){return[...this.validateSdkCompatibility(e),...this.validateDuplicatePlugin(e),...this.validateRouteCollisions(e),...this.validateMenuCollisions(e),...this.validateServiceCollisions(e)]}validateSdkCompatibility(e){const t=[];return e.minSdkVersion&&(this.checkSemverCompat(d,e.minSdkVersion)||t.push(this.addDiagnostic({code:"SDK_INCOMPATIBLE",severity:"warning",message:`Plugin ${e.name} requires SDK >=${e.minSdkVersion}, current SDK is ${d}. Plugin may not work correctly.`,pluginName:e.name,key:e.minSdkVersion}))),t}validateDuplicatePlugin(e){const t=[];return this.plugins.has(e.name)&&t.push(this.addDiagnostic({code:"PLUGIN_DUPLICATE",severity:"warning",message:`Plugin ${e.name} is already registered and will be replaced`,pluginName:e.name,conflictingPluginName:e.name,key:e.name})),t}validateRouteCollisions(e){const t=[],i=new Set;for(const s of e.routes??[]){if(i.has(s.path)){t.push(this.addDiagnostic({code:"ROUTE_COLLISION",severity:"error",message:`Duplicate route path "${s.path}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:s.path}));continue}i.add(s.path);const r=this.routeOwners.get(s.path);r&&r!==e.name&&t.push(this.addDiagnostic({code:"ROUTE_COLLISION",severity:"error",message:`Route path "${s.path}" from plugin ${e.name} conflicts with plugin ${r}`,pluginName:e.name,conflictingPluginName:r,key:s.path}))}return t}validateMenuCollisions(e){const t=[],i=new Set,s=new Set;for(const r of e.menu??[]){if(i.has(r.name))t.push(this.addDiagnostic({code:"MENU_NAME_COLLISION",severity:"error",message:`Duplicate menu name "${r.name}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:r.name}));else{i.add(r.name);const o=this.menuNameOwners.get(r.name);o&&o!==e.name&&t.push(this.addDiagnostic({code:"MENU_NAME_COLLISION",severity:"error",message:`Menu name "${r.name}" from plugin ${e.name} conflicts with plugin ${o}`,pluginName:e.name,conflictingPluginName:o,key:r.name}))}if(s.has(r.route))t.push(this.addDiagnostic({code:"MENU_ROUTE_COLLISION",severity:"error",message:`Duplicate menu route "${r.route}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:r.route}));else{s.add(r.route);const o=this.menuRouteOwners.get(r.route);o&&o!==e.name&&t.push(this.addDiagnostic({code:"MENU_ROUTE_COLLISION",severity:"error",message:`Menu route "${r.route}" from plugin ${e.name} conflicts with plugin ${o}`,pluginName:e.name,conflictingPluginName:o,key:r.route}))}}return t}validateServiceCollisions(e){const t=[],i=new Set;for(const s of Object.keys(e.services??{})){if(i.has(s)){t.push(this.addDiagnostic({code:"SERVICE_COLLISION",severity:"error",message:`Duplicate service "${s}" inside plugin ${e.name}`,pluginName:e.name,conflictingPluginName:e.name,key:s}));continue}i.add(s);const r=this.serviceOwners.get(s);r&&r!==e.name&&t.push(this.addDiagnostic({code:"SERVICE_COLLISION",severity:"error",message:`Service "${s}" from plugin ${e.name} conflicts with plugin ${r}`,pluginName:e.name,conflictingPluginName:r,key:s}))}return t}addDiagnostic(e){const t={...e,timestamp:new Date().toISOString()};return this.diagnostics.push(t),t}mergeMenus(e){var i;const t=new Map;for(const s of e){const r=s.module||"Other";t.has(r)||t.set(r,{name:r.toLowerCase(),label:r,route:`/${r.toLowerCase()}`,icon:this.getModuleIcon(r),order:s.order,children:[]});const o=t.get(r);if(s.order!==void 0&&(o.order===void 0||s.order<o.order)&&(o.order=s.order),s.category){let a=(i=o.children)==null?void 0:i.find(l=>l.label===s.category);a||(a={name:s.category.toLowerCase(),label:s.category,route:`/${r.toLowerCase()}/${s.category.toLowerCase()}`,children:[]},o.children.push(a)),a.children.push(s)}else o.children.push(s)}return Array.from(t.values()).sort((s,r)=>(s.order??999)-(r.order??999))}getModuleIcon(e){return f[e]||f.Other}rebuildIndexesAndServices(){this.routeOwners.clear(),this.menuNameOwners.clear(),this.menuRouteOwners.clear(),this.serviceOwners.clear(),this.serviceContainer.clear();for(const e of this.plugins.values())this.registerPluginServices(e),this.registerPluginRoutes(e),this.registerPluginMenuItems(e)}registerPluginServices(e){for(const[t,i]of Object.entries(e.services??{}))this.serviceContainer.register(t,i),this.serviceOwners.set(t,e.name)}registerPluginRoutes(e){for(const t of e.routes??[])this.routeOwners.set(t.path,e.name)}registerPluginMenuItems(e){for(const t of e.menu??[])this.menuNameOwners.set(t.name,e.name),this.menuRouteOwners.set(t.route,e.name)}emit(e,t){for(const i of this.eventListeners[e])i(t)}}const m=c.createContext(null);function R({children:n,registry:e}){const[t]=c.useState(()=>e??new w),[i,s]=c.useState(!1);return c.useEffect(()=>{s(!0)},[]),i?C.jsx(m.Provider,{value:t,children:n}):null}async function y(n,e){const t=[];for(const i of n){if(i.hidden||i.permissions&&i.permissions.length>0&&!await Promise.resolve(e(i.permissions)))continue;const s=i.children?await y(i.children,e):void 0;i.children&&((s==null?void 0:s.length)??0)===0||t.push({...i,children:s})}return t}function M(){const n=c.useContext(m),[e,t]=c.useState([]);if(!n)throw new Error("usePluginMenu must be used within PluginRegistryProvider");return c.useEffect(()=>{let i=!1;return(async()=>{const r=n.getMenu(),o=n.getPermissionChecker();if(!o){i||t(r.filter(l=>!l.hidden));return}const a=await y(r,o);i||t(a)})(),()=>{i=!0}},[n]),e}function I(n){const e=c.useContext(m);if(!e)throw new Error("usePlugin must be used within PluginRegistryProvider");return c.useMemo(()=>e.getPlugin(n),[e,n])}function E(n){const e=c.useContext(m);if(!e)throw new Error("useService must be used within PluginRegistryProvider");const[t,i]=c.useState(null),[s,r]=c.useState(!0),[o,a]=c.useState(null),l=c.useMemo(()=>e.getService(n),[e,n]);return c.useEffect(()=>{let h=!1;return r(!0),a(null),l.then(g=>{h||(i(g),r(!1))}).catch(g=>{h||(a(g instanceof Error?g:new Error(String(g))),r(!1))}),()=>{h=!0}},[l]),{service:t,isLoading:s,error:o}}async function k(n,e){const t=[];for(const i of n)i.permissions&&i.permissions.length>0&&!await Promise.resolve(e(i.permissions))||t.push(i);return t}function L(){const n=c.useContext(m),[e,t]=c.useState([]);if(!n)throw new Error("useWidgets must be used within PluginRegistryProvider");return c.useEffect(()=>{let i=!1;return(async()=>{const r=n.getWidgets(),o=n.getPermissionChecker();if(!o){i||t(r);return}const a=await k(r,o);i||t(a)})(),()=>{i=!0}},[n]),e}const p={apiUrl:"/api/v1/frontend/remotes",shareScope:"default"},D=async n=>{const e=(n==null?void 0:n.apiUrl)??p.apiUrl;try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch remotes: ${t.status}`);return await t.json()}catch(t){throw console.error("Error fetching remotes:",t),t}},b=n=>{const e=document.createElement("script");e.src=n,e.async=!0,document.body.appendChild(e)},$=async(n,e)=>{const t=(e==null?void 0:e.shareScope)??p.shareScope;return new Promise((i,s)=>{const r=setInterval(()=>{const o=window;if(o[n]){clearInterval(r);try{o[n].init({shareScope:t}),i()}catch(a){console.error(`Failed to initialize remote module ${n}:`,a),s(a)}}},50)})};exports.PluginRegistry=w;exports.PluginRegistryContext=m;exports.PluginRegistryProvider=R;exports.SDK_VERSION=d;exports.ServiceContainer=v;exports.fetchRemotes=D;exports.initializeRemote=$;exports.loadRemoteScript=b;exports.usePlugin=I;exports.usePluginMenu=M;exports.useService=E;exports.useWidgets=L;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/core/ServiceContainer.ts","../src/core/PluginRegistry.ts","../src/context/PluginRegistryContext.tsx","../src/hooks/usePluginMenu.ts","../src/hooks/usePlugin.ts","../src/hooks/useService.ts","../src/hooks/useWidgets.ts"],"sourcesContent":["/**\n * ServiceContainer — Simple dependency injection for plugin services.\n *\n * Services are registered as factories and lazily instantiated as singletons\n * on first `get()` call. Supports both sync and async factories.\n *\n * @example\n * ```ts\n * const container = new ServiceContainer();\n * container.register(\"warehouseService\", () => new WarehouseService());\n * const svc = await container.get<WarehouseService>(\"warehouseService\");\n * ```\n */\n\nimport type { ServiceFactory } from \"../types/plugin\";\n\nexport class ServiceContainer {\n private readonly factories = new Map<string, ServiceFactory>();\n private readonly instances = new Map<string, unknown>();\n\n /**\n * Register a service factory.\n *\n * @param name — unique service name\n * @param factory — factory function (sync or async)\n */\n register<T>(name: string, factory: ServiceFactory<T>): void {\n this.factories.set(name, factory as ServiceFactory);\n // Clear cached instance if re-registering\n this.instances.delete(name);\n }\n\n /**\n * Get a service by name. Lazily instantiates on first call (singleton).\n *\n * @throws Error if service is not registered\n */\n async get<T = unknown>(name: string): Promise<T> {\n // Return cached singleton\n if (this.instances.has(name)) {\n return this.instances.get(name) as T;\n }\n\n const factory = this.factories.get(name);\n if (!factory) {\n throw new Error(`Service \"${name}\" is not registered`);\n }\n\n // Create instance (may be async)\n const instance = await Promise.resolve(factory());\n this.instances.set(name, instance);\n return instance as T;\n }\n\n /**\n * Check if a service is registered.\n */\n has(name: string): boolean {\n return this.factories.has(name);\n }\n\n /**\n * Get all registered service names.\n */\n getAll(): string[] {\n return Array.from(this.factories.keys());\n }\n\n /**\n * Clear all registered factories and cached instances.\n */\n clear(): void {\n this.factories.clear();\n this.instances.clear();\n }\n}\n","/**\n * PluginRegistry — Central registry for Framework M plugins.\n *\n * Handles plugin registration, menu merging (by module/category),\n * route aggregation, and service container population.\n *\n * Per ADR-0008: this is the core runtime that the shell app bootstraps\n * and provides to all components via React Context.\n */\n\nimport type {\n FrameworkMPlugin,\n MenuItem,\n RouteDefinition,\n CompatibilityReport,\n PluginRegistryDiagnostic,\n PluginRegistryDiagnosticSeverity,\n PermissionChecker,\n Widget,\n} from \"../types/plugin\";\nimport { ServiceContainer } from \"./ServiceContainer\";\n\ntype PluginRegistryEvent = \"plugin:registered\" | \"plugin:error\";\n\ntype PluginRegistryEventPayloadMap = {\n \"plugin:registered\": { plugin: FrameworkMPlugin };\n \"plugin:error\": { plugin: FrameworkMPlugin; error: unknown };\n};\n\ntype PluginRegistryEventHandler<E extends PluginRegistryEvent> = (\n payload: PluginRegistryEventPayloadMap[E],\n) => void;\n\n/**\n * SDK version — used for compatibility checking.\n */\nexport const SDK_VERSION = \"0.1.0\";\n\n/**\n * Default icon mapping for well-known module names.\n */\nconst MODULE_ICONS: Record<string, string> = {\n Sales: \"shopping-cart\",\n Inventory: \"package\",\n HR: \"users\",\n Finance: \"dollar-sign\",\n Core: \"settings\",\n Other: \"folder\",\n};\n\nfunction isDebugEnabled(): boolean {\n const globalFlag = (globalThis as { __FRAMEWORK_M_PLUGIN_DEBUG__?: unknown })\n .__FRAMEWORK_M_PLUGIN_DEBUG__;\n if (typeof globalFlag === \"boolean\") {\n return globalFlag;\n }\n if (typeof globalFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(globalFlag.toLowerCase());\n }\n\n const processRef = (\n globalThis as { process?: { env?: Record<string, string | undefined> } }\n ).process;\n if (processRef?.env) {\n const envFlag = processRef.env.FRAMEWORK_M_PLUGIN_DEBUG;\n if (typeof envFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(envFlag.toLowerCase());\n }\n }\n\n return false;\n}\n\nconst registryLogger = {\n debug(message: string, ...args: unknown[]) {\n if (isDebugEnabled()) {\n console.debug(`[PluginRegistry] ${message}`, ...args);\n }\n },\n};\n\nexport class PluginRegistry {\n private readonly plugins = new Map<string, FrameworkMPlugin>();\n private menuCache: MenuItem[] | null = null;\n private readonly serviceContainer = new ServiceContainer();\n private readonly routeOwners = new Map<string, string>();\n private readonly menuNameOwners = new Map<string, string>();\n private readonly menuRouteOwners = new Map<string, string>();\n private readonly serviceOwners = new Map<string, string>();\n private diagnostics: PluginRegistryDiagnostic[] = [];\n private permissionChecker: PermissionChecker | null = null;\n private readonly eventListeners: {\n [E in PluginRegistryEvent]: Set<PluginRegistryEventHandler<E>>;\n } = {\n \"plugin:registered\": new Set(),\n \"plugin:error\": new Set(),\n };\n\n /**\n * Register a plugin with the registry.\n *\n * validates that the plugin has name and version, checks collisions,\n * stores it, registers any services into the ServiceContainer,\n * and invalidates the menu cache.\n *\n * @throws Error if plugin has no name or version\n */\n async register(plugin: FrameworkMPlugin): Promise<void> {\n if (!plugin.name || !plugin.version) {\n throw new Error(\"Plugin must have name and version\");\n }\n\n const diagnostics = this.validateRegistration(plugin);\n const errors = diagnostics.filter(d => d.severity === \"error\");\n\n if (errors.length > 0) {\n const error = new Error(\n `Plugin \"${plugin.name}\" registration failed: ${errors.map(d => d.message).join(\"; \")}`,\n );\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n const previous = this.plugins.get(plugin.name);\n this.plugins.set(plugin.name, plugin);\n this.rebuildIndexesAndServices();\n\n // Invalidate menu cache\n this.menuCache = null;\n\n try {\n if (plugin.onInit) {\n await Promise.resolve(plugin.onInit());\n }\n } catch (error) {\n if (previous) {\n this.plugins.set(plugin.name, previous);\n } else {\n this.plugins.delete(plugin.name);\n }\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n if (previous?.onDestroy && previous !== plugin) {\n await Promise.resolve(previous.onDestroy());\n }\n\n this.emit(\"plugin:registered\", { plugin });\n\n const warnings = diagnostics.filter(d => d.severity === \"warning\");\n if (warnings.length > 0) {\n registryLogger.debug(\n `Registered plugin \"${plugin.name}\" with warnings`,\n warnings,\n );\n }\n }\n\n /**\n * Get merged menu tree from all plugins.\n *\n * Collects all MenuItem entries, groups them by `module` (default: \"Other\"),\n * optionally sub-groups by `category`, and sorts by `order`.\n * Result is cached until a new plugin is registered.\n */\n getMenu(): MenuItem[] {\n if (this.menuCache) return this.menuCache;\n\n const allMenus: MenuItem[] = [];\n\n for (const plugin of this.plugins.values()) {\n if (plugin.menu) {\n allMenus.push(...plugin.menu);\n }\n }\n\n if (allMenus.length === 0) {\n this.menuCache = [];\n return this.menuCache;\n }\n\n this.menuCache = this.mergeMenus(allMenus);\n return this.menuCache;\n }\n\n /**\n * Get aggregated routes from all plugins.\n */\n getRoutes(): RouteDefinition[] {\n const routes: RouteDefinition[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.routes) {\n routes.push(...plugin.routes);\n }\n }\n return routes;\n }\n\n /**\n * Get a specific plugin by name.\n */\n getPlugin(name: string): FrameworkMPlugin | undefined {\n return this.plugins.get(name);\n }\n\n /**\n * Get all registered plugins.\n */\n getAllPlugins(): FrameworkMPlugin[] {\n return Array.from(this.plugins.values());\n }\n\n /**\n * Get the service container for DI.\n */\n getServiceContainer(): ServiceContainer {\n return this.serviceContainer;\n }\n\n /**\n * Unregister a plugin by name and run cleanup lifecycle if provided.\n */\n async unregister(pluginName: string): Promise<boolean> {\n const plugin = this.plugins.get(pluginName);\n if (!plugin) {\n return false;\n }\n\n this.plugins.delete(pluginName);\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n\n if (plugin.onDestroy) {\n await Promise.resolve(plugin.onDestroy());\n }\n\n return true;\n }\n\n /**\n * Resolve a service instance from the registry-level DI container.\n */\n async getService<T = unknown>(name: string): Promise<T> {\n return this.serviceContainer.get<T>(name);\n }\n\n /**\n * Aggregate all widgets contributed by registered plugins.\n */\n getWidgets(): Widget[] {\n const widgets: Widget[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.widgets) {\n widgets.push(...plugin.widgets);\n }\n }\n return widgets;\n }\n\n /**\n * Configure a permission checker used by consumer hooks.\n */\n setPermissionChecker(checker: PermissionChecker | null): void {\n this.permissionChecker = checker;\n }\n\n /**\n * Get the configured permission checker.\n */\n getPermissionChecker(): PermissionChecker | null {\n return this.permissionChecker;\n }\n\n /**\n * Subscribe to plugin lifecycle events.\n */\n on<E extends PluginRegistryEvent>(\n event: E,\n handler: PluginRegistryEventHandler<E>,\n ): () => void {\n this.eventListeners[event].add(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n return () => {\n this.eventListeners[event].delete(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n };\n }\n\n /**\n * Get emitted diagnostics.\n */\n getDiagnostics(\n severity?: PluginRegistryDiagnosticSeverity,\n ): PluginRegistryDiagnostic[] {\n if (!severity) {\n return [...this.diagnostics];\n }\n return this.diagnostics.filter(d => d.severity === severity);\n }\n\n /**\n * Clear diagnostics.\n */\n clearDiagnostics(): void {\n this.diagnostics = [];\n }\n\n // -------------------------------------------------------------------------\n // Version Compatibility\n // -------------------------------------------------------------------------\n\n /**\n * Check compatibility of all registered plugins.\n *\n * Returns a report of all plugins with their compatibility status:\n * - SDK version compatibility\n * - Peer plugin dependency satisfaction\n */\n checkCompatibility(): CompatibilityReport[] {\n const reports: CompatibilityReport[] = [];\n\n for (const plugin of this.plugins.values()) {\n const report: CompatibilityReport = {\n name: plugin.name,\n version: plugin.version,\n sdkCompatible: true,\n missingPeerPlugins: [],\n };\n\n // Check SDK version\n if (plugin.minSdkVersion) {\n report.sdkCompatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n }\n\n // Check peer plugins\n if (plugin.peerPlugins) {\n for (const peerName of plugin.peerPlugins) {\n if (!this.plugins.has(peerName)) {\n report.missingPeerPlugins.push(peerName);\n }\n }\n }\n\n reports.push(report);\n }\n\n return reports;\n }\n\n // -------------------------------------------------------------------------\n // Private helpers\n // -------------------------------------------------------------------------\n\n /**\n * Simple semver compatibility check.\n * Checks if `current` satisfies `>=required`.\n */\n private checkSemverCompat(current: string, required: string): boolean {\n const clean = required.replace(/^>=?/, \"\");\n const [cMajor, cMinor = 0, cPatch = 0] = current.split(\".\").map(Number);\n const [rMajor, rMinor = 0, rPatch = 0] = clean.split(\".\").map(Number);\n\n if (cMajor !== rMajor) return cMajor > rMajor;\n if (cMinor !== rMinor) return cMinor > rMinor;\n return cPatch >= rPatch;\n }\n\n private validateRegistration(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n return [\n ...this.validateSdkCompatibility(plugin),\n ...this.validateDuplicatePlugin(plugin),\n ...this.validateRouteCollisions(plugin),\n ...this.validateMenuCollisions(plugin),\n ...this.validateServiceCollisions(plugin),\n ];\n }\n\n private validateSdkCompatibility(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (plugin.minSdkVersion) {\n const compatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n if (!compatible) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SDK_INCOMPATIBLE\",\n severity: \"warning\",\n message:\n `Plugin ${plugin.name} requires SDK >=${plugin.minSdkVersion}, ` +\n `current SDK is ${SDK_VERSION}. Plugin may not work correctly.`,\n pluginName: plugin.name,\n key: plugin.minSdkVersion,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateDuplicatePlugin(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (this.plugins.has(plugin.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"PLUGIN_DUPLICATE\",\n severity: \"warning\",\n message: `Plugin ${plugin.name} is already registered and will be replaced`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: plugin.name,\n }),\n );\n }\n\n return diagnostics;\n }\n\n private validateRouteCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenRoutePaths = new Set<string>();\n for (const route of plugin.routes ?? []) {\n if (seenRoutePaths.has(route.path)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate route path \"${route.path}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: route.path,\n }),\n );\n continue;\n }\n\n seenRoutePaths.add(route.path);\n const existingRouteOwner = this.routeOwners.get(route.path);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Route path \"${route.path}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: route.path,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateMenuCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenMenuNames = new Set<string>();\n const seenMenuRoutes = new Set<string>();\n for (const item of plugin.menu ?? []) {\n if (seenMenuNames.has(item.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu name \"${item.name}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.name,\n }),\n );\n } else {\n seenMenuNames.add(item.name);\n const existingNameOwner = this.menuNameOwners.get(item.name);\n if (existingNameOwner && existingNameOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message:\n `Menu name \"${item.name}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingNameOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingNameOwner,\n key: item.name,\n }),\n );\n }\n }\n\n if (seenMenuRoutes.has(item.route)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu route \"${item.route}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.route,\n }),\n );\n } else {\n seenMenuRoutes.add(item.route);\n const existingRouteOwner = this.menuRouteOwners.get(item.route);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Menu route \"${item.route}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: item.route,\n }),\n );\n }\n }\n }\n\n return diagnostics;\n }\n\n private validateServiceCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenServiceNames = new Set<string>();\n for (const serviceName of Object.keys(plugin.services ?? {})) {\n if (seenServiceNames.has(serviceName)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message: `Duplicate service \"${serviceName}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: serviceName,\n }),\n );\n continue;\n }\n\n seenServiceNames.add(serviceName);\n const existingServiceOwner = this.serviceOwners.get(serviceName);\n if (existingServiceOwner && existingServiceOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message:\n `Service \"${serviceName}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingServiceOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingServiceOwner,\n key: serviceName,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private addDiagnostic(\n diagnostic: Omit<PluginRegistryDiagnostic, \"timestamp\">,\n ): PluginRegistryDiagnostic {\n const fullDiagnostic: PluginRegistryDiagnostic = {\n ...diagnostic,\n timestamp: new Date().toISOString(),\n };\n this.diagnostics.push(fullDiagnostic);\n return fullDiagnostic;\n }\n\n /**\n * Merge flat menu items into a grouped tree:\n * Module → (optional) Category → Items\n *\n * Items without a `module` are placed under \"Other\".\n */\n private mergeMenus(items: MenuItem[]): MenuItem[] {\n const moduleMap = new Map<string, MenuItem>();\n\n for (const item of items) {\n const moduleName = item.module || \"Other\";\n\n if (!moduleMap.has(moduleName)) {\n moduleMap.set(moduleName, {\n name: moduleName.toLowerCase(),\n label: moduleName,\n route: `/${moduleName.toLowerCase()}`,\n icon: this.getModuleIcon(moduleName),\n order: item.order,\n children: [],\n });\n }\n\n const moduleGroup = moduleMap.get(moduleName)!;\n\n // Track lowest order value for module-level sorting\n if (item.order !== undefined) {\n if (moduleGroup.order === undefined || item.order < moduleGroup.order) {\n moduleGroup.order = item.order;\n }\n }\n\n if (item.category) {\n // Find or create category sub-group\n let categoryGroup = moduleGroup.children?.find(\n c => c.label === item.category,\n );\n\n if (!categoryGroup) {\n categoryGroup = {\n name: item.category.toLowerCase(),\n label: item.category,\n route: `/${moduleName.toLowerCase()}/${item.category.toLowerCase()}`,\n children: [],\n };\n moduleGroup.children!.push(categoryGroup);\n }\n\n categoryGroup.children!.push(item);\n } else {\n // No category — add directly to module\n moduleGroup.children!.push(item);\n }\n }\n\n // Sort module groups by order (lower first, undefined last)\n return Array.from(moduleMap.values()).sort(\n (a, b) => (a.order ?? 999) - (b.order ?? 999),\n );\n }\n\n private getModuleIcon(moduleName: string): string {\n return MODULE_ICONS[moduleName] || MODULE_ICONS.Other;\n }\n\n private rebuildIndexesAndServices(): void {\n this.routeOwners.clear();\n this.menuNameOwners.clear();\n this.menuRouteOwners.clear();\n this.serviceOwners.clear();\n this.serviceContainer.clear();\n\n for (const plugin of this.plugins.values()) {\n this.registerPluginServices(plugin);\n this.registerPluginRoutes(plugin);\n this.registerPluginMenuItems(plugin);\n }\n }\n\n private registerPluginServices(plugin: FrameworkMPlugin): void {\n for (const [name, factory] of Object.entries(plugin.services ?? {})) {\n this.serviceContainer.register(name, factory);\n this.serviceOwners.set(name, plugin.name);\n }\n }\n\n private registerPluginRoutes(plugin: FrameworkMPlugin): void {\n for (const route of plugin.routes ?? []) {\n this.routeOwners.set(route.path, plugin.name);\n }\n }\n\n private registerPluginMenuItems(plugin: FrameworkMPlugin): void {\n for (const item of plugin.menu ?? []) {\n this.menuNameOwners.set(item.name, plugin.name);\n this.menuRouteOwners.set(item.route, plugin.name);\n }\n }\n\n private emit<E extends PluginRegistryEvent>(\n event: E,\n payload: PluginRegistryEventPayloadMap[E],\n ): void {\n for (const handler of this.eventListeners[event]) {\n handler(payload as never);\n }\n }\n}\n","/**\n * PluginRegistryContext — React context for the PluginRegistry.\n *\n * Provides the PluginRegistry to all child components via React Context.\n * Must wrap any component that uses usePluginMenu(), usePlugin(), or useService().\n */\n\nimport { createContext, useEffect, useState, type ReactNode } from \"react\";\nimport { PluginRegistry } from \"../core/PluginRegistry\";\n\nexport const PluginRegistryContext = createContext<PluginRegistry | null>(null);\n\nexport interface PluginRegistryProviderProps {\n readonly children: ReactNode;\n /** Optional pre-configured PluginRegistry instance */\n readonly registry?: PluginRegistry;\n}\n\n/**\n * Provider component that makes the PluginRegistry available to child components.\n *\n * @example\n * ```tsx\n * const registry = new PluginRegistry();\n * await registry.register(wmsPlugin);\n *\n * <PluginRegistryProvider registry={registry}>\n * <App />\n * </PluginRegistryProvider>\n * ```\n */\nexport function PluginRegistryProvider({\n children,\n registry,\n}: PluginRegistryProviderProps) {\n const [registryInstance] = useState<PluginRegistry>(\n () => registry ?? new PluginRegistry(),\n );\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n setIsReady(true);\n }, []);\n\n if (!isReady) {\n return null;\n }\n\n return (\n <PluginRegistryContext.Provider value={registryInstance}>\n {children}\n </PluginRegistryContext.Provider>\n );\n}\n","/**\n * usePluginMenu — React hook for accessing the merged menu tree.\n *\n * Returns the merged MenuItem[] from all registered plugins.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function Sidebar() {\n * const menu = usePluginMenu();\n * return <nav>{menu.map(m => <ModuleGroup key={m.name} {...m} />)}</nav>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { MenuItem } from \"../types/plugin\";\n\nasync function filterMenuByPermissions(\n items: MenuItem[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<MenuItem[]> {\n const filtered: MenuItem[] = [];\n\n for (const item of items) {\n if (item.hidden) {\n continue;\n }\n\n if (item.permissions && item.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(item.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n const children = item.children\n ? await filterMenuByPermissions(item.children, checker)\n : undefined;\n\n if (item.children && (children?.length ?? 0) === 0) {\n continue;\n }\n\n filtered.push({ ...item, children });\n }\n\n return filtered;\n}\n\nexport function usePluginMenu(): MenuItem[] {\n const registry = useContext(PluginRegistryContext);\n const [menu, setMenu] = useState<MenuItem[]>([]);\n\n if (!registry) {\n throw new Error(\"usePluginMenu must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getMenu();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setMenu(source.filter(item => !item.hidden));\n }\n return;\n }\n\n const filtered = await filterMenuByPermissions(source, checker);\n if (!cancelled) {\n setMenu(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return menu;\n}\n","/**\n * usePlugin — React hook for accessing a specific plugin by name.\n *\n * Returns the FrameworkMPlugin or undefined if not found.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WMSStatus() {\n * const wms = usePlugin(\"wms\");\n * if (!wms) return <p>WMS not installed</p>;\n * return <p>WMS v{wms.version}</p>;\n * }\n * ```\n */\n\nimport { useContext, useMemo } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { FrameworkMPlugin } from \"../types/plugin\";\n\nexport function usePlugin(name: string): FrameworkMPlugin | undefined {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"usePlugin must be used within PluginRegistryProvider\");\n }\n\n return useMemo(() => registry.getPlugin(name), [registry, name]);\n}\n","/**\n * useService — React hook for accessing a service from the ServiceContainer.\n *\n * Returns the service instance (lazily loaded), loading state, and error.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WarehouseDashboard() {\n * const { service, isLoading, error } = useService<WarehouseService>(\"warehouseService\");\n * if (isLoading) return <Spinner />;\n * if (error) return <Error message={error.message} />;\n * return <div>{service.getWarehouses()}</div>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useMemo, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\n\ninterface UseServiceResult<T> {\n service: T | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport function useService<T = unknown>(name: string): UseServiceResult<T> {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"useService must be used within PluginRegistryProvider\");\n }\n\n const [service, setService] = useState<T | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const servicePromise = useMemo(\n () => registry.getService<T>(name),\n [registry, name],\n );\n\n useEffect(() => {\n let cancelled = false;\n setIsLoading(true);\n setError(null);\n\n servicePromise\n .then(instance => {\n if (!cancelled) {\n setService(instance);\n setIsLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsLoading(false);\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [servicePromise]);\n\n return { service, isLoading, error };\n}\n","/**\n * useWidgets — React hook for accessing plugin-provided dashboard widgets.\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { Widget } from \"../types/plugin\";\n\nasync function filterWidgetsByPermissions(\n widgets: Widget[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<Widget[]> {\n const filtered: Widget[] = [];\n\n for (const widget of widgets) {\n if (widget.permissions && widget.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(widget.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n filtered.push(widget);\n }\n\n return filtered;\n}\n\nexport function useWidgets(): Widget[] {\n const registry = useContext(PluginRegistryContext);\n const [widgets, setWidgets] = useState<Widget[]>([]);\n\n if (!registry) {\n throw new Error(\"useWidgets must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getWidgets();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setWidgets(source);\n }\n return;\n }\n\n const filtered = await filterWidgetsByPermissions(source, checker);\n if (!cancelled) {\n setWidgets(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return widgets;\n}\n"],"names":["ServiceContainer","__publicField","name","factory","instance","SDK_VERSION","MODULE_ICONS","isDebugEnabled","globalFlag","processRef","envFlag","registryLogger","message","args","PluginRegistry","plugin","diagnostics","errors","d","error","previous","warnings","allMenus","routes","pluginName","widgets","checker","event","handler","severity","reports","report","peerName","current","required","clean","cMajor","cMinor","cPatch","rMajor","rMinor","rPatch","seenRoutePaths","route","existingRouteOwner","seenMenuNames","seenMenuRoutes","item","existingNameOwner","seenServiceNames","serviceName","existingServiceOwner","diagnostic","fullDiagnostic","items","moduleMap","moduleName","moduleGroup","categoryGroup","_a","c","a","b","payload","PluginRegistryContext","createContext","PluginRegistryProvider","children","registry","registryInstance","useState","isReady","setIsReady","useEffect","filterMenuByPermissions","filtered","usePluginMenu","useContext","menu","setMenu","cancelled","source","usePlugin","useMemo","useService","service","setService","isLoading","setIsLoading","setError","servicePromise","err","filterWidgetsByPermissions","widget","useWidgets","setWidgets"],"mappings":"4SAgBO,MAAMA,CAAiB,CAAvB,cACYC,EAAA,qBAAgB,KAChBA,EAAA,qBAAgB,KAQjC,SAAYC,EAAcC,EAAkC,CAC1D,KAAK,UAAU,IAAID,EAAMC,CAAyB,EAElD,KAAK,UAAU,OAAOD,CAAI,CAC5B,CAOA,MAAM,IAAiBA,EAA0B,CAE/C,GAAI,KAAK,UAAU,IAAIA,CAAI,EACzB,OAAO,KAAK,UAAU,IAAIA,CAAI,EAGhC,MAAMC,EAAU,KAAK,UAAU,IAAID,CAAI,EACvC,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,YAAYD,CAAI,qBAAqB,EAIvD,MAAME,EAAW,MAAM,QAAQ,QAAQD,GAAS,EAChD,YAAK,UAAU,IAAID,EAAME,CAAQ,EAC1BA,CACT,CAKA,IAAIF,EAAuB,CACzB,OAAO,KAAK,UAAU,IAAIA,CAAI,CAChC,CAKA,QAAmB,CACjB,OAAO,MAAM,KAAK,KAAK,UAAU,MAAM,CACzC,CAKA,OAAc,CACZ,KAAK,UAAU,MAAA,EACf,KAAK,UAAU,MAAA,CACjB,CACF,CCvCO,MAAMG,EAAc,QAKrBC,EAAuC,CAC3C,MAAO,gBACP,UAAW,UACX,GAAI,QACJ,QAAS,cACT,KAAM,WACN,MAAO,QACT,EAEA,SAASC,GAA0B,CACjC,MAAMC,EAAc,WACjB,6BACH,GAAI,OAAOA,GAAe,UACxB,OAAOA,EAET,GAAI,OAAOA,GAAe,SACxB,MAAO,CAAC,IAAK,OAAQ,MAAO,IAAI,EAAE,SAASA,EAAW,aAAa,EAGrE,MAAMC,EACJ,WACA,QACF,GAAIA,GAAA,MAAAA,EAAY,IAAK,CACnB,MAAMC,EAAUD,EAAW,IAAI,yBAC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WAAA,EAClB1C,EAAU0C,EAAS,qBAAA,EAEzB,GAAI,CAAC1C,EAAS,CACPsD,GACHe,EAAWd,CAAM,EAEnB,MACF,CAEA,MAAMN,EAAW,MAAMiB,EAA2BX,EAAQvD,CAAO,EAC5DsD,GACHe,EAAWpB,CAAQ,CAEvB,GAEK,EAEE,IAAM,CACXK,EAAY,EACd,CACF,EAAG,CAACZ,CAAQ,CAAC,EAEN3C,CACT"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/core/ServiceContainer.ts","../src/core/PluginRegistry.ts","../src/context/PluginRegistryContext.tsx","../src/hooks/usePluginMenu.ts","../src/hooks/usePlugin.ts","../src/hooks/useService.ts","../src/hooks/useWidgets.ts","../src/loader/federation.ts"],"sourcesContent":["/**\n * ServiceContainer — Simple dependency injection for plugin services.\n *\n * Services are registered as factories and lazily instantiated as singletons\n * on first `get()` call. Supports both sync and async factories.\n *\n * @example\n * ```ts\n * const container = new ServiceContainer();\n * container.register(\"warehouseService\", () => new WarehouseService());\n * const svc = await container.get<WarehouseService>(\"warehouseService\");\n * ```\n */\n\nimport type { ServiceFactory } from \"../types/plugin\";\n\nexport class ServiceContainer {\n private readonly factories = new Map<string, ServiceFactory>();\n private readonly instances = new Map<string, unknown>();\n\n /**\n * Register a service factory.\n *\n * @param name — unique service name\n * @param factory — factory function (sync or async)\n */\n register<T>(name: string, factory: ServiceFactory<T>): void {\n this.factories.set(name, factory as ServiceFactory);\n // Clear cached instance if re-registering\n this.instances.delete(name);\n }\n\n /**\n * Get a service by name. Lazily instantiates on first call (singleton).\n *\n * @throws Error if service is not registered\n */\n async get<T = unknown>(name: string): Promise<T> {\n // Return cached singleton\n if (this.instances.has(name)) {\n return this.instances.get(name) as T;\n }\n\n const factory = this.factories.get(name);\n if (!factory) {\n throw new Error(`Service \"${name}\" is not registered`);\n }\n\n // Create instance (may be async)\n const instance = await Promise.resolve(factory());\n this.instances.set(name, instance);\n return instance as T;\n }\n\n /**\n * Check if a service is registered.\n */\n has(name: string): boolean {\n return this.factories.has(name);\n }\n\n /**\n * Get all registered service names.\n */\n getAll(): string[] {\n return Array.from(this.factories.keys());\n }\n\n /**\n * Clear all registered factories and cached instances.\n */\n clear(): void {\n this.factories.clear();\n this.instances.clear();\n }\n}\n","/**\n * PluginRegistry — Central registry for Framework M plugins.\n *\n * Handles plugin registration, menu merging (by module/category),\n * route aggregation, and service container population.\n *\n * Per ADR-0008: this is the core runtime that the shell app bootstraps\n * and provides to all components via React Context.\n */\n\nimport type {\n FrameworkMPlugin,\n MenuItem,\n RouteDefinition,\n CompatibilityReport,\n PluginRegistryDiagnostic,\n PluginRegistryDiagnosticSeverity,\n PermissionChecker,\n Widget,\n} from \"../types/plugin\";\nimport { ServiceContainer } from \"./ServiceContainer\";\n\ntype PluginRegistryEvent = \"plugin:registered\" | \"plugin:error\";\n\ntype PluginRegistryEventPayloadMap = {\n \"plugin:registered\": { plugin: FrameworkMPlugin };\n \"plugin:error\": { plugin: FrameworkMPlugin; error: unknown };\n};\n\ntype PluginRegistryEventHandler<E extends PluginRegistryEvent> = (\n payload: PluginRegistryEventPayloadMap[E],\n) => void;\n\n/**\n * SDK version — used for compatibility checking.\n */\nexport const SDK_VERSION = \"0.1.0\";\n\n/**\n * Default icon mapping for well-known module names.\n */\nconst MODULE_ICONS: Record<string, string> = {\n Sales: \"shopping-cart\",\n Inventory: \"package\",\n HR: \"users\",\n Finance: \"dollar-sign\",\n Core: \"settings\",\n Other: \"folder\",\n};\n\nfunction isDebugEnabled(): boolean {\n const globalFlag = (globalThis as { __FRAMEWORK_M_PLUGIN_DEBUG__?: unknown })\n .__FRAMEWORK_M_PLUGIN_DEBUG__;\n if (typeof globalFlag === \"boolean\") {\n return globalFlag;\n }\n if (typeof globalFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(globalFlag.toLowerCase());\n }\n\n const processRef = (\n globalThis as { process?: { env?: Record<string, string | undefined> } }\n ).process;\n if (processRef?.env) {\n const envFlag = processRef.env.FRAMEWORK_M_PLUGIN_DEBUG;\n if (typeof envFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(envFlag.toLowerCase());\n }\n }\n\n return false;\n}\n\nconst registryLogger = {\n debug(message: string, ...args: unknown[]) {\n if (isDebugEnabled()) {\n console.debug(`[PluginRegistry] ${message}`, ...args);\n }\n },\n};\n\nexport class PluginRegistry {\n private readonly plugins = new Map<string, FrameworkMPlugin>();\n private menuCache: MenuItem[] | null = null;\n private readonly serviceContainer = new ServiceContainer();\n private readonly routeOwners = new Map<string, string>();\n private readonly menuNameOwners = new Map<string, string>();\n private readonly menuRouteOwners = new Map<string, string>();\n private readonly serviceOwners = new Map<string, string>();\n private diagnostics: PluginRegistryDiagnostic[] = [];\n private permissionChecker: PermissionChecker | null = null;\n private readonly eventListeners: {\n [E in PluginRegistryEvent]: Set<PluginRegistryEventHandler<E>>;\n } = {\n \"plugin:registered\": new Set(),\n \"plugin:error\": new Set(),\n };\n\n /**\n * Register a plugin with the registry.\n *\n * validates that the plugin has name and version, checks collisions,\n * stores it, registers any services into the ServiceContainer,\n * and invalidates the menu cache.\n *\n * @throws Error if plugin has no name or version\n */\n async register(plugin: FrameworkMPlugin): Promise<void> {\n if (!plugin.name || !plugin.version) {\n throw new Error(\"Plugin must have name and version\");\n }\n\n const diagnostics = this.validateRegistration(plugin);\n const errors = diagnostics.filter(d => d.severity === \"error\");\n\n if (errors.length > 0) {\n const error = new Error(\n `Plugin \"${plugin.name}\" registration failed: ${errors.map(d => d.message).join(\"; \")}`,\n );\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n const previous = this.plugins.get(plugin.name);\n this.plugins.set(plugin.name, plugin);\n this.rebuildIndexesAndServices();\n\n // Invalidate menu cache\n this.menuCache = null;\n\n try {\n if (plugin.onInit) {\n await Promise.resolve(plugin.onInit());\n }\n } catch (error) {\n if (previous) {\n this.plugins.set(plugin.name, previous);\n } else {\n this.plugins.delete(plugin.name);\n }\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n if (previous?.onDestroy && previous !== plugin) {\n await Promise.resolve(previous.onDestroy());\n }\n\n this.emit(\"plugin:registered\", { plugin });\n\n const warnings = diagnostics.filter(d => d.severity === \"warning\");\n if (warnings.length > 0) {\n registryLogger.debug(\n `Registered plugin \"${plugin.name}\" with warnings`,\n warnings,\n );\n }\n }\n\n /**\n * Get merged menu tree from all plugins.\n *\n * Collects all MenuItem entries, groups them by `module` (default: \"Other\"),\n * optionally sub-groups by `category`, and sorts by `order`.\n * Result is cached until a new plugin is registered.\n */\n getMenu(): MenuItem[] {\n if (this.menuCache) return this.menuCache;\n\n const allMenus: MenuItem[] = [];\n\n for (const plugin of this.plugins.values()) {\n if (plugin.menu) {\n allMenus.push(...plugin.menu);\n }\n }\n\n if (allMenus.length === 0) {\n this.menuCache = [];\n return this.menuCache;\n }\n\n this.menuCache = this.mergeMenus(allMenus);\n return this.menuCache;\n }\n\n /**\n * Get aggregated routes from all plugins.\n */\n getRoutes(): RouteDefinition[] {\n const routes: RouteDefinition[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.routes) {\n routes.push(...plugin.routes);\n }\n }\n return routes;\n }\n\n /**\n * Get a specific plugin by name.\n */\n getPlugin(name: string): FrameworkMPlugin | undefined {\n return this.plugins.get(name);\n }\n\n /**\n * Get all registered plugins.\n */\n getAllPlugins(): FrameworkMPlugin[] {\n return Array.from(this.plugins.values());\n }\n\n /**\n * Get the service container for DI.\n */\n getServiceContainer(): ServiceContainer {\n return this.serviceContainer;\n }\n\n /**\n * Unregister a plugin by name and run cleanup lifecycle if provided.\n */\n async unregister(pluginName: string): Promise<boolean> {\n const plugin = this.plugins.get(pluginName);\n if (!plugin) {\n return false;\n }\n\n this.plugins.delete(pluginName);\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n\n if (plugin.onDestroy) {\n await Promise.resolve(plugin.onDestroy());\n }\n\n return true;\n }\n\n /**\n * Resolve a service instance from the registry-level DI container.\n */\n async getService<T = unknown>(name: string): Promise<T> {\n return this.serviceContainer.get<T>(name);\n }\n\n /**\n * Aggregate all widgets contributed by registered plugins.\n */\n getWidgets(): Widget[] {\n const widgets: Widget[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.widgets) {\n widgets.push(...plugin.widgets);\n }\n }\n return widgets;\n }\n\n /**\n * Configure a permission checker used by consumer hooks.\n */\n setPermissionChecker(checker: PermissionChecker | null): void {\n this.permissionChecker = checker;\n }\n\n /**\n * Get the configured permission checker.\n */\n getPermissionChecker(): PermissionChecker | null {\n return this.permissionChecker;\n }\n\n /**\n * Subscribe to plugin lifecycle events.\n */\n on<E extends PluginRegistryEvent>(\n event: E,\n handler: PluginRegistryEventHandler<E>,\n ): () => void {\n this.eventListeners[event].add(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n return () => {\n this.eventListeners[event].delete(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n };\n }\n\n /**\n * Get emitted diagnostics.\n */\n getDiagnostics(\n severity?: PluginRegistryDiagnosticSeverity,\n ): PluginRegistryDiagnostic[] {\n if (!severity) {\n return [...this.diagnostics];\n }\n return this.diagnostics.filter(d => d.severity === severity);\n }\n\n /**\n * Clear diagnostics.\n */\n clearDiagnostics(): void {\n this.diagnostics = [];\n }\n\n // -------------------------------------------------------------------------\n // Version Compatibility\n // -------------------------------------------------------------------------\n\n /**\n * Check compatibility of all registered plugins.\n *\n * Returns a report of all plugins with their compatibility status:\n * - SDK version compatibility\n * - Peer plugin dependency satisfaction\n */\n checkCompatibility(): CompatibilityReport[] {\n const reports: CompatibilityReport[] = [];\n\n for (const plugin of this.plugins.values()) {\n const report: CompatibilityReport = {\n name: plugin.name,\n version: plugin.version,\n sdkCompatible: true,\n missingPeerPlugins: [],\n };\n\n // Check SDK version\n if (plugin.minSdkVersion) {\n report.sdkCompatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n }\n\n // Check peer plugins\n if (plugin.peerPlugins) {\n for (const peerName of plugin.peerPlugins) {\n if (!this.plugins.has(peerName)) {\n report.missingPeerPlugins.push(peerName);\n }\n }\n }\n\n reports.push(report);\n }\n\n return reports;\n }\n\n // -------------------------------------------------------------------------\n // Private helpers\n // -------------------------------------------------------------------------\n\n /**\n * Simple semver compatibility check.\n * Checks if `current` satisfies `>=required`.\n */\n private checkSemverCompat(current: string, required: string): boolean {\n const clean = required.replace(/^>=?/, \"\");\n const [cMajor, cMinor = 0, cPatch = 0] = current.split(\".\").map(Number);\n const [rMajor, rMinor = 0, rPatch = 0] = clean.split(\".\").map(Number);\n\n if (cMajor !== rMajor) return cMajor > rMajor;\n if (cMinor !== rMinor) return cMinor > rMinor;\n return cPatch >= rPatch;\n }\n\n private validateRegistration(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n return [\n ...this.validateSdkCompatibility(plugin),\n ...this.validateDuplicatePlugin(plugin),\n ...this.validateRouteCollisions(plugin),\n ...this.validateMenuCollisions(plugin),\n ...this.validateServiceCollisions(plugin),\n ];\n }\n\n private validateSdkCompatibility(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (plugin.minSdkVersion) {\n const compatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n if (!compatible) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SDK_INCOMPATIBLE\",\n severity: \"warning\",\n message:\n `Plugin ${plugin.name} requires SDK >=${plugin.minSdkVersion}, ` +\n `current SDK is ${SDK_VERSION}. Plugin may not work correctly.`,\n pluginName: plugin.name,\n key: plugin.minSdkVersion,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateDuplicatePlugin(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (this.plugins.has(plugin.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"PLUGIN_DUPLICATE\",\n severity: \"warning\",\n message: `Plugin ${plugin.name} is already registered and will be replaced`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: plugin.name,\n }),\n );\n }\n\n return diagnostics;\n }\n\n private validateRouteCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenRoutePaths = new Set<string>();\n for (const route of plugin.routes ?? []) {\n if (seenRoutePaths.has(route.path)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate route path \"${route.path}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: route.path,\n }),\n );\n continue;\n }\n\n seenRoutePaths.add(route.path);\n const existingRouteOwner = this.routeOwners.get(route.path);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Route path \"${route.path}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: route.path,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateMenuCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenMenuNames = new Set<string>();\n const seenMenuRoutes = new Set<string>();\n for (const item of plugin.menu ?? []) {\n if (seenMenuNames.has(item.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu name \"${item.name}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.name,\n }),\n );\n } else {\n seenMenuNames.add(item.name);\n const existingNameOwner = this.menuNameOwners.get(item.name);\n if (existingNameOwner && existingNameOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message:\n `Menu name \"${item.name}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingNameOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingNameOwner,\n key: item.name,\n }),\n );\n }\n }\n\n if (seenMenuRoutes.has(item.route)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu route \"${item.route}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.route,\n }),\n );\n } else {\n seenMenuRoutes.add(item.route);\n const existingRouteOwner = this.menuRouteOwners.get(item.route);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Menu route \"${item.route}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: item.route,\n }),\n );\n }\n }\n }\n\n return diagnostics;\n }\n\n private validateServiceCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenServiceNames = new Set<string>();\n for (const serviceName of Object.keys(plugin.services ?? {})) {\n if (seenServiceNames.has(serviceName)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message: `Duplicate service \"${serviceName}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: serviceName,\n }),\n );\n continue;\n }\n\n seenServiceNames.add(serviceName);\n const existingServiceOwner = this.serviceOwners.get(serviceName);\n if (existingServiceOwner && existingServiceOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message:\n `Service \"${serviceName}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingServiceOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingServiceOwner,\n key: serviceName,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private addDiagnostic(\n diagnostic: Omit<PluginRegistryDiagnostic, \"timestamp\">,\n ): PluginRegistryDiagnostic {\n const fullDiagnostic: PluginRegistryDiagnostic = {\n ...diagnostic,\n timestamp: new Date().toISOString(),\n };\n this.diagnostics.push(fullDiagnostic);\n return fullDiagnostic;\n }\n\n /**\n * Merge flat menu items into a grouped tree:\n * Module → (optional) Category → Items\n *\n * Items without a `module` are placed under \"Other\".\n */\n private mergeMenus(items: MenuItem[]): MenuItem[] {\n const moduleMap = new Map<string, MenuItem>();\n\n for (const item of items) {\n const moduleName = item.module || \"Other\";\n\n if (!moduleMap.has(moduleName)) {\n moduleMap.set(moduleName, {\n name: moduleName.toLowerCase(),\n label: moduleName,\n route: `/${moduleName.toLowerCase()}`,\n icon: this.getModuleIcon(moduleName),\n order: item.order,\n children: [],\n });\n }\n\n const moduleGroup = moduleMap.get(moduleName)!;\n\n // Track lowest order value for module-level sorting\n if (item.order !== undefined) {\n if (moduleGroup.order === undefined || item.order < moduleGroup.order) {\n moduleGroup.order = item.order;\n }\n }\n\n if (item.category) {\n // Find or create category sub-group\n let categoryGroup = moduleGroup.children?.find(\n c => c.label === item.category,\n );\n\n if (!categoryGroup) {\n categoryGroup = {\n name: item.category.toLowerCase(),\n label: item.category,\n route: `/${moduleName.toLowerCase()}/${item.category.toLowerCase()}`,\n children: [],\n };\n moduleGroup.children!.push(categoryGroup);\n }\n\n categoryGroup.children!.push(item);\n } else {\n // No category — add directly to module\n moduleGroup.children!.push(item);\n }\n }\n\n // Sort module groups by order (lower first, undefined last)\n return Array.from(moduleMap.values()).sort(\n (a, b) => (a.order ?? 999) - (b.order ?? 999),\n );\n }\n\n private getModuleIcon(moduleName: string): string {\n return MODULE_ICONS[moduleName] || MODULE_ICONS.Other;\n }\n\n private rebuildIndexesAndServices(): void {\n this.routeOwners.clear();\n this.menuNameOwners.clear();\n this.menuRouteOwners.clear();\n this.serviceOwners.clear();\n this.serviceContainer.clear();\n\n for (const plugin of this.plugins.values()) {\n this.registerPluginServices(plugin);\n this.registerPluginRoutes(plugin);\n this.registerPluginMenuItems(plugin);\n }\n }\n\n private registerPluginServices(plugin: FrameworkMPlugin): void {\n for (const [name, factory] of Object.entries(plugin.services ?? {})) {\n this.serviceContainer.register(name, factory);\n this.serviceOwners.set(name, plugin.name);\n }\n }\n\n private registerPluginRoutes(plugin: FrameworkMPlugin): void {\n for (const route of plugin.routes ?? []) {\n this.routeOwners.set(route.path, plugin.name);\n }\n }\n\n private registerPluginMenuItems(plugin: FrameworkMPlugin): void {\n for (const item of plugin.menu ?? []) {\n this.menuNameOwners.set(item.name, plugin.name);\n this.menuRouteOwners.set(item.route, plugin.name);\n }\n }\n\n private emit<E extends PluginRegistryEvent>(\n event: E,\n payload: PluginRegistryEventPayloadMap[E],\n ): void {\n for (const handler of this.eventListeners[event]) {\n handler(payload as never);\n }\n }\n}\n","/**\n * PluginRegistryContext — React context for the PluginRegistry.\n *\n * Provides the PluginRegistry to all child components via React Context.\n * Must wrap any component that uses usePluginMenu(), usePlugin(), or useService().\n */\n\nimport { createContext, useEffect, useState, type ReactNode } from \"react\";\nimport { PluginRegistry } from \"../core/PluginRegistry\";\n\nexport const PluginRegistryContext = createContext<PluginRegistry | null>(null);\n\nexport interface PluginRegistryProviderProps {\n readonly children: ReactNode;\n /** Optional pre-configured PluginRegistry instance */\n readonly registry?: PluginRegistry;\n}\n\n/**\n * Provider component that makes the PluginRegistry available to child components.\n *\n * @example\n * ```tsx\n * const registry = new PluginRegistry();\n * await registry.register(wmsPlugin);\n *\n * <PluginRegistryProvider registry={registry}>\n * <App />\n * </PluginRegistryProvider>\n * ```\n */\nexport function PluginRegistryProvider({\n children,\n registry,\n}: PluginRegistryProviderProps) {\n const [registryInstance] = useState<PluginRegistry>(\n () => registry ?? new PluginRegistry(),\n );\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n setIsReady(true);\n }, []);\n\n if (!isReady) {\n return null;\n }\n\n return (\n <PluginRegistryContext.Provider value={registryInstance}>\n {children}\n </PluginRegistryContext.Provider>\n );\n}\n","/**\n * usePluginMenu — React hook for accessing the merged menu tree.\n *\n * Returns the merged MenuItem[] from all registered plugins.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function Sidebar() {\n * const menu = usePluginMenu();\n * return <nav>{menu.map(m => <ModuleGroup key={m.name} {...m} />)}</nav>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { MenuItem } from \"../types/plugin\";\n\nasync function filterMenuByPermissions(\n items: MenuItem[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<MenuItem[]> {\n const filtered: MenuItem[] = [];\n\n for (const item of items) {\n if (item.hidden) {\n continue;\n }\n\n if (item.permissions && item.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(item.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n const children = item.children\n ? await filterMenuByPermissions(item.children, checker)\n : undefined;\n\n if (item.children && (children?.length ?? 0) === 0) {\n continue;\n }\n\n filtered.push({ ...item, children });\n }\n\n return filtered;\n}\n\nexport function usePluginMenu(): MenuItem[] {\n const registry = useContext(PluginRegistryContext);\n const [menu, setMenu] = useState<MenuItem[]>([]);\n\n if (!registry) {\n throw new Error(\"usePluginMenu must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getMenu();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setMenu(source.filter(item => !item.hidden));\n }\n return;\n }\n\n const filtered = await filterMenuByPermissions(source, checker);\n if (!cancelled) {\n setMenu(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return menu;\n}\n","/**\n * usePlugin — React hook for accessing a specific plugin by name.\n *\n * Returns the FrameworkMPlugin or undefined if not found.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WMSStatus() {\n * const wms = usePlugin(\"wms\");\n * if (!wms) return <p>WMS not installed</p>;\n * return <p>WMS v{wms.version}</p>;\n * }\n * ```\n */\n\nimport { useContext, useMemo } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { FrameworkMPlugin } from \"../types/plugin\";\n\nexport function usePlugin(name: string): FrameworkMPlugin | undefined {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"usePlugin must be used within PluginRegistryProvider\");\n }\n\n return useMemo(() => registry.getPlugin(name), [registry, name]);\n}\n","/**\n * useService — React hook for accessing a service from the ServiceContainer.\n *\n * Returns the service instance (lazily loaded), loading state, and error.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WarehouseDashboard() {\n * const { service, isLoading, error } = useService<WarehouseService>(\"warehouseService\");\n * if (isLoading) return <Spinner />;\n * if (error) return <Error message={error.message} />;\n * return <div>{service.getWarehouses()}</div>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useMemo, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\n\ninterface UseServiceResult<T> {\n service: T | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport function useService<T = unknown>(name: string): UseServiceResult<T> {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"useService must be used within PluginRegistryProvider\");\n }\n\n const [service, setService] = useState<T | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const servicePromise = useMemo(\n () => registry.getService<T>(name),\n [registry, name],\n );\n\n useEffect(() => {\n let cancelled = false;\n setIsLoading(true);\n setError(null);\n\n servicePromise\n .then(instance => {\n if (!cancelled) {\n setService(instance);\n setIsLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsLoading(false);\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [servicePromise]);\n\n return { service, isLoading, error };\n}\n","/**\n * useWidgets — React hook for accessing plugin-provided dashboard widgets.\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { Widget } from \"../types/plugin\";\n\nasync function filterWidgetsByPermissions(\n widgets: Widget[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<Widget[]> {\n const filtered: Widget[] = [];\n\n for (const widget of widgets) {\n if (widget.permissions && widget.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(widget.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n filtered.push(widget);\n }\n\n return filtered;\n}\n\nexport function useWidgets(): Widget[] {\n const registry = useContext(PluginRegistryContext);\n const [widgets, setWidgets] = useState<Widget[]>([]);\n\n if (!registry) {\n throw new Error(\"useWidgets must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getWidgets();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setWidgets(source);\n }\n return;\n }\n\n const filtered = await filterWidgetsByPermissions(source, checker);\n if (!cancelled) {\n setWidgets(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return widgets;\n}\n","export interface RemoteModule {\n init: (args: { shareScope: string }) => void;\n}\n\nexport interface FederationOptions {\n /** Discovery API URL, defaults to /api/v1/frontend/remotes */\n apiUrl?: string;\n /** Share scope for federation, defaults to 'default' */\n shareScope?: string;\n}\n\nconst DEFAULT_OPTIONS: FederationOptions = {\n apiUrl: \"/api/v1/frontend/remotes\",\n shareScope: \"default\",\n};\n\n/**\n * Fetch remote plugin definitions from the backend discovery API.\n */\nexport const fetchRemotes = async (options?: FederationOptions): Promise<Record<string, string>> => {\n const apiUrl = options?.apiUrl ?? DEFAULT_OPTIONS.apiUrl!;\n try {\n const response = await fetch(apiUrl);\n if (!response.ok) {\n throw new Error(`Failed to fetch remotes: ${response.status}`);\n }\n return await response.json();\n } catch (error: unknown) {\n console.error('Error fetching remotes:', error);\n throw error;\n }\n};\n\n/**\n * Dynamically load a remote script into the browser runtime.\n */\nexport const loadRemoteScript = (remoteUrl: string): void => {\n const script = document.createElement('script');\n script.src = remoteUrl;\n script.async = true;\n document.body.appendChild(script);\n};\n\n/**\n * Initialize a federated remote module on the global window scope.\n */\nexport const initializeRemote = async (scope: string, options?: FederationOptions): Promise<void> => {\n const shareScope = options?.shareScope ?? DEFAULT_OPTIONS.shareScope!;\n \n return new Promise((resolve, reject) => {\n interface WindowWithRemote {\n [key: string]: {\n init: (args: { shareScope: string }) => void;\n } | undefined;\n }\n \n const checkInterval = setInterval(() => {\n const w = window as unknown as WindowWithRemote;\n if (w[scope]) {\n clearInterval(checkInterval);\n try {\n w[scope]!.init({\n shareScope,\n });\n resolve();\n } catch (error: unknown) {\n console.error(`Failed to initialize remote module ${scope}:`, error);\n reject(error);\n }\n }\n }, 50);\n });\n};\n"],"names":["ServiceContainer","__publicField","name","factory","instance","SDK_VERSION","MODULE_ICONS","isDebugEnabled","globalFlag","processRef","envFlag","registryLogger","message","args","PluginRegistry","plugin","diagnostics","errors","d","error","previous","warnings","allMenus","routes","pluginName","widgets","checker","event","handler","severity","reports","report","peerName","current","required","clean","cMajor","cMinor","cPatch","rMajor","rMinor","rPatch","seenRoutePaths","route","existingRouteOwner","seenMenuNames","seenMenuRoutes","item","existingNameOwner","seenServiceNames","serviceName","existingServiceOwner","diagnostic","fullDiagnostic","items","moduleMap","moduleName","moduleGroup","categoryGroup","_a","c","a","b","payload","PluginRegistryContext","createContext","PluginRegistryProvider","children","registry","registryInstance","useState","isReady","setIsReady","useEffect","filterMenuByPermissions","filtered","usePluginMenu","useContext","menu","setMenu","cancelled","source","usePlugin","useMemo","useService","service","setService","isLoading","setIsLoading","setError","servicePromise","err","filterWidgetsByPermissions","widget","useWidgets","setWidgets","DEFAULT_OPTIONS","fetchRemotes","options","apiUrl","response","loadRemoteScript","remoteUrl","script","initializeRemote","scope","shareScope","resolve","reject","checkInterval","w"],"mappings":"4SAgBO,MAAMA,CAAiB,CAAvB,cACYC,EAAA,qBAAgB,KAChBA,EAAA,qBAAgB,KAQjC,SAAYC,EAAcC,EAAkC,CAC1D,KAAK,UAAU,IAAID,EAAMC,CAAyB,EAElD,KAAK,UAAU,OAAOD,CAAI,CAC5B,CAOA,MAAM,IAAiBA,EAA0B,CAE/C,GAAI,KAAK,UAAU,IAAIA,CAAI,EACzB,OAAO,KAAK,UAAU,IAAIA,CAAI,EAGhC,MAAMC,EAAU,KAAK,UAAU,IAAID,CAAI,EACvC,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,YAAYD,CAAI,qBAAqB,EAIvD,MAAME,EAAW,MAAM,QAAQ,QAAQD,GAAS,EAChD,YAAK,UAAU,IAAID,EAAME,CAAQ,EAC1BA,CACT,CAKA,IAAIF,EAAuB,CACzB,OAAO,KAAK,UAAU,IAAIA,CAAI,CAChC,CAKA,QAAmB,CACjB,OAAO,MAAM,KAAK,KAAK,UAAU,MAAM,CACzC,CAKA,OAAc,CACZ,KAAK,UAAU,MAAA,EACf,KAAK,UAAU,MAAA,CACjB,CACF,CCvCO,MAAMG,EAAc,QAKrBC,EAAuC,CAC3C,MAAO,gBACP,UAAW,UACX,GAAI,QACJ,QAAS,cACT,KAAM,WACN,MAAO,QACT,EAEA,SAASC,GAA0B,CACjC,MAAMC,EAAc,WACjB,6BACH,GAAI,OAAOA,GAAe,UACxB,OAAOA,EAET,GAAI,OAAOA,GAAe,SACxB,MAAO,CAAC,IAAK,OAAQ,MAAO,IAAI,EAAE,SAASA,EAAW,aAAa,EAGrE,MAAMC,EACJ,WACA,QACF,GAAIA,GAAA,MAAAA,EAAY,IAAK,CACnB,MAAMC,EA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,CACP,CAAC,CACH"}
|
package/dist/index.d.ts
CHANGED
|
@@ -36,4 +36,6 @@ export { usePluginMenu } from './hooks/usePluginMenu';
|
|
|
36
36
|
export { usePlugin } from './hooks/usePlugin';
|
|
37
37
|
export { useService } from './hooks/useService';
|
|
38
38
|
export { useWidgets } from './hooks/useWidgets';
|
|
39
|
+
export { fetchRemotes, loadRemoteScript, initializeRemote, } from './loader/federation';
|
|
40
|
+
export type { RemoteModule, FederationOptions, } from './loader/federation';
|
|
39
41
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,YAAY,EACV,QAAQ,EACR,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAGnF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,YAAY,EACV,QAAQ,EACR,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAGnF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,YAAY,EACZ,iBAAiB,GAClB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var c = (
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { createContext as
|
|
6
|
-
class
|
|
1
|
+
var C = Object.defineProperty;
|
|
2
|
+
var S = (n, e, t) => e in n ? C(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var c = (n, e, t) => S(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { jsx as O } from "react/jsx-runtime";
|
|
5
|
+
import { createContext as N, useState as l, useEffect as g, useContext as f, useMemo as p } from "react";
|
|
6
|
+
class I {
|
|
7
7
|
constructor() {
|
|
8
8
|
c(this, "factories", /* @__PURE__ */ new Map());
|
|
9
9
|
c(this, "instances", /* @__PURE__ */ new Map());
|
|
@@ -50,7 +50,7 @@ class N {
|
|
|
50
50
|
this.factories.clear(), this.instances.clear();
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
const
|
|
53
|
+
const w = "0.1.0", v = {
|
|
54
54
|
Sales: "shopping-cart",
|
|
55
55
|
Inventory: "package",
|
|
56
56
|
HR: "users",
|
|
@@ -59,11 +59,11 @@ const v = "0.1.0", w = {
|
|
|
59
59
|
Other: "folder"
|
|
60
60
|
};
|
|
61
61
|
function M() {
|
|
62
|
-
const
|
|
63
|
-
if (typeof
|
|
64
|
-
return
|
|
65
|
-
if (typeof
|
|
66
|
-
return ["1", "true", "yes", "on"].includes(
|
|
62
|
+
const n = globalThis.__FRAMEWORK_M_PLUGIN_DEBUG__;
|
|
63
|
+
if (typeof n == "boolean")
|
|
64
|
+
return n;
|
|
65
|
+
if (typeof n == "string")
|
|
66
|
+
return ["1", "true", "yes", "on"].includes(n.toLowerCase());
|
|
67
67
|
const e = globalThis.process;
|
|
68
68
|
if (e != null && e.env) {
|
|
69
69
|
const t = e.env.FRAMEWORK_M_PLUGIN_DEBUG;
|
|
@@ -72,16 +72,16 @@ function M() {
|
|
|
72
72
|
}
|
|
73
73
|
return !1;
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
debug(
|
|
77
|
-
M() && console.debug(`[PluginRegistry] ${
|
|
75
|
+
const R = {
|
|
76
|
+
debug(n, ...e) {
|
|
77
|
+
M() && console.debug(`[PluginRegistry] ${n}`, ...e);
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
-
class
|
|
80
|
+
class k {
|
|
81
81
|
constructor() {
|
|
82
82
|
c(this, "plugins", /* @__PURE__ */ new Map());
|
|
83
83
|
c(this, "menuCache", null);
|
|
84
|
-
c(this, "serviceContainer", new
|
|
84
|
+
c(this, "serviceContainer", new I());
|
|
85
85
|
c(this, "routeOwners", /* @__PURE__ */ new Map());
|
|
86
86
|
c(this, "menuNameOwners", /* @__PURE__ */ new Map());
|
|
87
87
|
c(this, "menuRouteOwners", /* @__PURE__ */ new Map());
|
|
@@ -120,10 +120,10 @@ class R {
|
|
|
120
120
|
throw s ? this.plugins.set(e.name, s) : this.plugins.delete(e.name), this.rebuildIndexesAndServices(), this.menuCache = null, this.emit("plugin:error", { plugin: e, error: o }), o;
|
|
121
121
|
}
|
|
122
122
|
s != null && s.onDestroy && s !== e && await Promise.resolve(s.onDestroy()), this.emit("plugin:registered", { plugin: e });
|
|
123
|
-
const
|
|
124
|
-
|
|
123
|
+
const r = t.filter((o) => o.severity === "warning");
|
|
124
|
+
r.length > 0 && R.debug(
|
|
125
125
|
`Registered plugin "${e.name}" with warnings`,
|
|
126
|
-
|
|
126
|
+
r
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
@@ -245,7 +245,7 @@ class R {
|
|
|
245
245
|
missingPeerPlugins: []
|
|
246
246
|
};
|
|
247
247
|
if (t.minSdkVersion && (i.sdkCompatible = this.checkSemverCompat(
|
|
248
|
-
|
|
248
|
+
w,
|
|
249
249
|
t.minSdkVersion
|
|
250
250
|
)), t.peerPlugins)
|
|
251
251
|
for (const s of t.peerPlugins)
|
|
@@ -262,8 +262,8 @@ class R {
|
|
|
262
262
|
* Checks if `current` satisfies `>=required`.
|
|
263
263
|
*/
|
|
264
264
|
checkSemverCompat(e, t) {
|
|
265
|
-
const i = t.replace(/^>=?/, ""), [s,
|
|
266
|
-
return s !== a ? s > a :
|
|
265
|
+
const i = t.replace(/^>=?/, ""), [s, r = 0, o = 0] = e.split(".").map(Number), [a, u = 0, h = 0] = i.split(".").map(Number);
|
|
266
|
+
return s !== a ? s > a : r !== u ? r > u : o >= h;
|
|
267
267
|
}
|
|
268
268
|
validateRegistration(e) {
|
|
269
269
|
return [
|
|
@@ -277,13 +277,13 @@ class R {
|
|
|
277
277
|
validateSdkCompatibility(e) {
|
|
278
278
|
const t = [];
|
|
279
279
|
return e.minSdkVersion && (this.checkSemverCompat(
|
|
280
|
-
|
|
280
|
+
w,
|
|
281
281
|
e.minSdkVersion
|
|
282
282
|
) || t.push(
|
|
283
283
|
this.addDiagnostic({
|
|
284
284
|
code: "SDK_INCOMPATIBLE",
|
|
285
285
|
severity: "warning",
|
|
286
|
-
message: `Plugin ${e.name} requires SDK >=${e.minSdkVersion}, current SDK is ${
|
|
286
|
+
message: `Plugin ${e.name} requires SDK >=${e.minSdkVersion}, current SDK is ${w}. Plugin may not work correctly.`,
|
|
287
287
|
pluginName: e.name,
|
|
288
288
|
key: e.minSdkVersion
|
|
289
289
|
})
|
|
@@ -319,14 +319,14 @@ class R {
|
|
|
319
319
|
continue;
|
|
320
320
|
}
|
|
321
321
|
i.add(s.path);
|
|
322
|
-
const
|
|
323
|
-
|
|
322
|
+
const r = this.routeOwners.get(s.path);
|
|
323
|
+
r && r !== e.name && t.push(
|
|
324
324
|
this.addDiagnostic({
|
|
325
325
|
code: "ROUTE_COLLISION",
|
|
326
326
|
severity: "error",
|
|
327
|
-
message: `Route path "${s.path}" from plugin ${e.name} conflicts with plugin ${
|
|
327
|
+
message: `Route path "${s.path}" from plugin ${e.name} conflicts with plugin ${r}`,
|
|
328
328
|
pluginName: e.name,
|
|
329
|
-
conflictingPluginName:
|
|
329
|
+
conflictingPluginName: r,
|
|
330
330
|
key: s.path
|
|
331
331
|
})
|
|
332
332
|
);
|
|
@@ -335,54 +335,54 @@ class R {
|
|
|
335
335
|
}
|
|
336
336
|
validateMenuCollisions(e) {
|
|
337
337
|
const t = [], i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
|
|
338
|
-
for (const
|
|
339
|
-
if (i.has(
|
|
338
|
+
for (const r of e.menu ?? []) {
|
|
339
|
+
if (i.has(r.name))
|
|
340
340
|
t.push(
|
|
341
341
|
this.addDiagnostic({
|
|
342
342
|
code: "MENU_NAME_COLLISION",
|
|
343
343
|
severity: "error",
|
|
344
|
-
message: `Duplicate menu name "${
|
|
344
|
+
message: `Duplicate menu name "${r.name}" inside plugin ${e.name}`,
|
|
345
345
|
pluginName: e.name,
|
|
346
346
|
conflictingPluginName: e.name,
|
|
347
|
-
key:
|
|
347
|
+
key: r.name
|
|
348
348
|
})
|
|
349
349
|
);
|
|
350
350
|
else {
|
|
351
|
-
i.add(
|
|
352
|
-
const o = this.menuNameOwners.get(
|
|
351
|
+
i.add(r.name);
|
|
352
|
+
const o = this.menuNameOwners.get(r.name);
|
|
353
353
|
o && o !== e.name && t.push(
|
|
354
354
|
this.addDiagnostic({
|
|
355
355
|
code: "MENU_NAME_COLLISION",
|
|
356
356
|
severity: "error",
|
|
357
|
-
message: `Menu name "${
|
|
357
|
+
message: `Menu name "${r.name}" from plugin ${e.name} conflicts with plugin ${o}`,
|
|
358
358
|
pluginName: e.name,
|
|
359
359
|
conflictingPluginName: o,
|
|
360
|
-
key:
|
|
360
|
+
key: r.name
|
|
361
361
|
})
|
|
362
362
|
);
|
|
363
363
|
}
|
|
364
|
-
if (s.has(
|
|
364
|
+
if (s.has(r.route))
|
|
365
365
|
t.push(
|
|
366
366
|
this.addDiagnostic({
|
|
367
367
|
code: "MENU_ROUTE_COLLISION",
|
|
368
368
|
severity: "error",
|
|
369
|
-
message: `Duplicate menu route "${
|
|
369
|
+
message: `Duplicate menu route "${r.route}" inside plugin ${e.name}`,
|
|
370
370
|
pluginName: e.name,
|
|
371
371
|
conflictingPluginName: e.name,
|
|
372
|
-
key:
|
|
372
|
+
key: r.route
|
|
373
373
|
})
|
|
374
374
|
);
|
|
375
375
|
else {
|
|
376
|
-
s.add(
|
|
377
|
-
const o = this.menuRouteOwners.get(
|
|
376
|
+
s.add(r.route);
|
|
377
|
+
const o = this.menuRouteOwners.get(r.route);
|
|
378
378
|
o && o !== e.name && t.push(
|
|
379
379
|
this.addDiagnostic({
|
|
380
380
|
code: "MENU_ROUTE_COLLISION",
|
|
381
381
|
severity: "error",
|
|
382
|
-
message: `Menu route "${
|
|
382
|
+
message: `Menu route "${r.route}" from plugin ${e.name} conflicts with plugin ${o}`,
|
|
383
383
|
pluginName: e.name,
|
|
384
384
|
conflictingPluginName: o,
|
|
385
|
-
key:
|
|
385
|
+
key: r.route
|
|
386
386
|
})
|
|
387
387
|
);
|
|
388
388
|
}
|
|
@@ -406,14 +406,14 @@ class R {
|
|
|
406
406
|
continue;
|
|
407
407
|
}
|
|
408
408
|
i.add(s);
|
|
409
|
-
const
|
|
410
|
-
|
|
409
|
+
const r = this.serviceOwners.get(s);
|
|
410
|
+
r && r !== e.name && t.push(
|
|
411
411
|
this.addDiagnostic({
|
|
412
412
|
code: "SERVICE_COLLISION",
|
|
413
413
|
severity: "error",
|
|
414
|
-
message: `Service "${s}" from plugin ${e.name} conflicts with plugin ${
|
|
414
|
+
message: `Service "${s}" from plugin ${e.name} conflicts with plugin ${r}`,
|
|
415
415
|
pluginName: e.name,
|
|
416
|
-
conflictingPluginName:
|
|
416
|
+
conflictingPluginName: r,
|
|
417
417
|
key: s
|
|
418
418
|
})
|
|
419
419
|
);
|
|
@@ -437,16 +437,16 @@ class R {
|
|
|
437
437
|
var i;
|
|
438
438
|
const t = /* @__PURE__ */ new Map();
|
|
439
439
|
for (const s of e) {
|
|
440
|
-
const
|
|
441
|
-
t.has(
|
|
442
|
-
name:
|
|
443
|
-
label:
|
|
444
|
-
route: `/${
|
|
445
|
-
icon: this.getModuleIcon(
|
|
440
|
+
const r = s.module || "Other";
|
|
441
|
+
t.has(r) || t.set(r, {
|
|
442
|
+
name: r.toLowerCase(),
|
|
443
|
+
label: r,
|
|
444
|
+
route: `/${r.toLowerCase()}`,
|
|
445
|
+
icon: this.getModuleIcon(r),
|
|
446
446
|
order: s.order,
|
|
447
447
|
children: []
|
|
448
448
|
});
|
|
449
|
-
const o = t.get(
|
|
449
|
+
const o = t.get(r);
|
|
450
450
|
if (s.order !== void 0 && (o.order === void 0 || s.order < o.order) && (o.order = s.order), s.category) {
|
|
451
451
|
let a = (i = o.children) == null ? void 0 : i.find(
|
|
452
452
|
(u) => u.label === s.category
|
|
@@ -454,18 +454,18 @@ class R {
|
|
|
454
454
|
a || (a = {
|
|
455
455
|
name: s.category.toLowerCase(),
|
|
456
456
|
label: s.category,
|
|
457
|
-
route: `/${
|
|
457
|
+
route: `/${r.toLowerCase()}/${s.category.toLowerCase()}`,
|
|
458
458
|
children: []
|
|
459
459
|
}, o.children.push(a)), a.children.push(s);
|
|
460
460
|
} else
|
|
461
461
|
o.children.push(s);
|
|
462
462
|
}
|
|
463
463
|
return Array.from(t.values()).sort(
|
|
464
|
-
(s,
|
|
464
|
+
(s, r) => (s.order ?? 999) - (r.order ?? 999)
|
|
465
465
|
);
|
|
466
466
|
}
|
|
467
467
|
getModuleIcon(e) {
|
|
468
|
-
return
|
|
468
|
+
return v[e] || v.Other;
|
|
469
469
|
}
|
|
470
470
|
rebuildIndexesAndServices() {
|
|
471
471
|
this.routeOwners.clear(), this.menuNameOwners.clear(), this.menuRouteOwners.clear(), this.serviceOwners.clear(), this.serviceContainer.clear();
|
|
@@ -489,21 +489,21 @@ class R {
|
|
|
489
489
|
i(t);
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
|
-
const
|
|
492
|
+
const d = N(null);
|
|
493
493
|
function b({
|
|
494
|
-
children:
|
|
494
|
+
children: n,
|
|
495
495
|
registry: e
|
|
496
496
|
}) {
|
|
497
497
|
const [t] = l(
|
|
498
|
-
() => e ?? new
|
|
498
|
+
() => e ?? new k()
|
|
499
499
|
), [i, s] = l(!1);
|
|
500
|
-
return
|
|
500
|
+
return g(() => {
|
|
501
501
|
s(!0);
|
|
502
|
-
}, []), i ? /* @__PURE__ */
|
|
502
|
+
}, []), i ? /* @__PURE__ */ O(d.Provider, { value: t, children: n }) : null;
|
|
503
503
|
}
|
|
504
|
-
async function y(
|
|
504
|
+
async function y(n, e) {
|
|
505
505
|
const t = [];
|
|
506
|
-
for (const i of
|
|
506
|
+
for (const i of n) {
|
|
507
507
|
if (i.hidden || i.permissions && i.permissions.length > 0 && !await Promise.resolve(e(i.permissions)))
|
|
508
508
|
continue;
|
|
509
509
|
const s = i.children ? await y(i.children, e) : void 0;
|
|
@@ -511,84 +511,121 @@ async function y(r, e) {
|
|
|
511
511
|
}
|
|
512
512
|
return t;
|
|
513
513
|
}
|
|
514
|
-
function
|
|
515
|
-
const
|
|
516
|
-
if (!
|
|
514
|
+
function _() {
|
|
515
|
+
const n = f(d), [e, t] = l([]);
|
|
516
|
+
if (!n)
|
|
517
517
|
throw new Error("usePluginMenu must be used within PluginRegistryProvider");
|
|
518
|
-
return
|
|
518
|
+
return g(() => {
|
|
519
519
|
let i = !1;
|
|
520
520
|
return (async () => {
|
|
521
|
-
const
|
|
521
|
+
const r = n.getMenu(), o = n.getPermissionChecker();
|
|
522
522
|
if (!o) {
|
|
523
|
-
i || t(
|
|
523
|
+
i || t(r.filter((u) => !u.hidden));
|
|
524
524
|
return;
|
|
525
525
|
}
|
|
526
|
-
const a = await y(
|
|
526
|
+
const a = await y(r, o);
|
|
527
527
|
i || t(a);
|
|
528
528
|
})(), () => {
|
|
529
529
|
i = !0;
|
|
530
530
|
};
|
|
531
|
-
}, [
|
|
531
|
+
}, [n]), e;
|
|
532
532
|
}
|
|
533
|
-
function
|
|
534
|
-
const e = f(
|
|
533
|
+
function U(n) {
|
|
534
|
+
const e = f(d);
|
|
535
535
|
if (!e)
|
|
536
536
|
throw new Error("usePlugin must be used within PluginRegistryProvider");
|
|
537
|
-
return p(() => e.getPlugin(
|
|
537
|
+
return p(() => e.getPlugin(n), [e, n]);
|
|
538
538
|
}
|
|
539
|
-
function A(
|
|
540
|
-
const e = f(
|
|
539
|
+
function A(n) {
|
|
540
|
+
const e = f(d);
|
|
541
541
|
if (!e)
|
|
542
542
|
throw new Error("useService must be used within PluginRegistryProvider");
|
|
543
|
-
const [t, i] = l(null), [s,
|
|
544
|
-
() => e.getService(
|
|
545
|
-
[e,
|
|
543
|
+
const [t, i] = l(null), [s, r] = l(!0), [o, a] = l(null), u = p(
|
|
544
|
+
() => e.getService(n),
|
|
545
|
+
[e, n]
|
|
546
546
|
);
|
|
547
|
-
return
|
|
548
|
-
let
|
|
549
|
-
return
|
|
550
|
-
|
|
551
|
-
}).catch((
|
|
552
|
-
|
|
547
|
+
return g(() => {
|
|
548
|
+
let h = !1;
|
|
549
|
+
return r(!0), a(null), u.then((m) => {
|
|
550
|
+
h || (i(m), r(!1));
|
|
551
|
+
}).catch((m) => {
|
|
552
|
+
h || (a(m instanceof Error ? m : new Error(String(m))), r(!1));
|
|
553
553
|
}), () => {
|
|
554
|
-
|
|
554
|
+
h = !0;
|
|
555
555
|
};
|
|
556
556
|
}, [u]), { service: t, isLoading: s, error: o };
|
|
557
557
|
}
|
|
558
|
-
async function
|
|
558
|
+
async function E(n, e) {
|
|
559
559
|
const t = [];
|
|
560
|
-
for (const i of
|
|
560
|
+
for (const i of n)
|
|
561
561
|
i.permissions && i.permissions.length > 0 && !await Promise.resolve(e(i.permissions)) || t.push(i);
|
|
562
562
|
return t;
|
|
563
563
|
}
|
|
564
|
-
function
|
|
565
|
-
const
|
|
566
|
-
if (!
|
|
564
|
+
function x() {
|
|
565
|
+
const n = f(d), [e, t] = l([]);
|
|
566
|
+
if (!n)
|
|
567
567
|
throw new Error("useWidgets must be used within PluginRegistryProvider");
|
|
568
|
-
return
|
|
568
|
+
return g(() => {
|
|
569
569
|
let i = !1;
|
|
570
570
|
return (async () => {
|
|
571
|
-
const
|
|
571
|
+
const r = n.getWidgets(), o = n.getPermissionChecker();
|
|
572
572
|
if (!o) {
|
|
573
|
-
i || t(
|
|
573
|
+
i || t(r);
|
|
574
574
|
return;
|
|
575
575
|
}
|
|
576
|
-
const a = await
|
|
576
|
+
const a = await E(r, o);
|
|
577
577
|
i || t(a);
|
|
578
578
|
})(), () => {
|
|
579
579
|
i = !0;
|
|
580
580
|
};
|
|
581
|
-
}, [
|
|
581
|
+
}, [n]), e;
|
|
582
582
|
}
|
|
583
|
+
const P = {
|
|
584
|
+
apiUrl: "/api/v1/frontend/remotes",
|
|
585
|
+
shareScope: "default"
|
|
586
|
+
}, T = async (n) => {
|
|
587
|
+
const e = (n == null ? void 0 : n.apiUrl) ?? P.apiUrl;
|
|
588
|
+
try {
|
|
589
|
+
const t = await fetch(e);
|
|
590
|
+
if (!t.ok)
|
|
591
|
+
throw new Error(`Failed to fetch remotes: ${t.status}`);
|
|
592
|
+
return await t.json();
|
|
593
|
+
} catch (t) {
|
|
594
|
+
throw console.error("Error fetching remotes:", t), t;
|
|
595
|
+
}
|
|
596
|
+
}, V = (n) => {
|
|
597
|
+
const e = document.createElement("script");
|
|
598
|
+
e.src = n, e.async = !0, document.body.appendChild(e);
|
|
599
|
+
}, F = async (n, e) => {
|
|
600
|
+
const t = (e == null ? void 0 : e.shareScope) ?? P.shareScope;
|
|
601
|
+
return new Promise((i, s) => {
|
|
602
|
+
const r = setInterval(() => {
|
|
603
|
+
const o = window;
|
|
604
|
+
if (o[n]) {
|
|
605
|
+
clearInterval(r);
|
|
606
|
+
try {
|
|
607
|
+
o[n].init({
|
|
608
|
+
shareScope: t
|
|
609
|
+
}), i();
|
|
610
|
+
} catch (a) {
|
|
611
|
+
console.error(`Failed to initialize remote module ${n}:`, a), s(a);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}, 50);
|
|
615
|
+
});
|
|
616
|
+
};
|
|
583
617
|
export {
|
|
584
|
-
|
|
585
|
-
|
|
618
|
+
k as PluginRegistry,
|
|
619
|
+
d as PluginRegistryContext,
|
|
586
620
|
b as PluginRegistryProvider,
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
621
|
+
w as SDK_VERSION,
|
|
622
|
+
I as ServiceContainer,
|
|
623
|
+
T as fetchRemotes,
|
|
624
|
+
F as initializeRemote,
|
|
625
|
+
V as loadRemoteScript,
|
|
626
|
+
U as usePlugin,
|
|
627
|
+
_ as usePluginMenu,
|
|
591
628
|
A as useService,
|
|
592
|
-
|
|
629
|
+
x as useWidgets
|
|
593
630
|
};
|
|
594
631
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/core/ServiceContainer.ts","../src/core/PluginRegistry.ts","../src/context/PluginRegistryContext.tsx","../src/hooks/usePluginMenu.ts","../src/hooks/usePlugin.ts","../src/hooks/useService.ts","../src/hooks/useWidgets.ts"],"sourcesContent":["/**\n * ServiceContainer — Simple dependency injection for plugin services.\n *\n * Services are registered as factories and lazily instantiated as singletons\n * on first `get()` call. Supports both sync and async factories.\n *\n * @example\n * ```ts\n * const container = new ServiceContainer();\n * container.register(\"warehouseService\", () => new WarehouseService());\n * const svc = await container.get<WarehouseService>(\"warehouseService\");\n * ```\n */\n\nimport type { ServiceFactory } from \"../types/plugin\";\n\nexport class ServiceContainer {\n private readonly factories = new Map<string, ServiceFactory>();\n private readonly instances = new Map<string, unknown>();\n\n /**\n * Register a service factory.\n *\n * @param name — unique service name\n * @param factory — factory function (sync or async)\n */\n register<T>(name: string, factory: ServiceFactory<T>): void {\n this.factories.set(name, factory as ServiceFactory);\n // Clear cached instance if re-registering\n this.instances.delete(name);\n }\n\n /**\n * Get a service by name. Lazily instantiates on first call (singleton).\n *\n * @throws Error if service is not registered\n */\n async get<T = unknown>(name: string): Promise<T> {\n // Return cached singleton\n if (this.instances.has(name)) {\n return this.instances.get(name) as T;\n }\n\n const factory = this.factories.get(name);\n if (!factory) {\n throw new Error(`Service \"${name}\" is not registered`);\n }\n\n // Create instance (may be async)\n const instance = await Promise.resolve(factory());\n this.instances.set(name, instance);\n return instance as T;\n }\n\n /**\n * Check if a service is registered.\n */\n has(name: string): boolean {\n return this.factories.has(name);\n }\n\n /**\n * Get all registered service names.\n */\n getAll(): string[] {\n return Array.from(this.factories.keys());\n }\n\n /**\n * Clear all registered factories and cached instances.\n */\n clear(): void {\n this.factories.clear();\n this.instances.clear();\n }\n}\n","/**\n * PluginRegistry — Central registry for Framework M plugins.\n *\n * Handles plugin registration, menu merging (by module/category),\n * route aggregation, and service container population.\n *\n * Per ADR-0008: this is the core runtime that the shell app bootstraps\n * and provides to all components via React Context.\n */\n\nimport type {\n FrameworkMPlugin,\n MenuItem,\n RouteDefinition,\n CompatibilityReport,\n PluginRegistryDiagnostic,\n PluginRegistryDiagnosticSeverity,\n PermissionChecker,\n Widget,\n} from \"../types/plugin\";\nimport { ServiceContainer } from \"./ServiceContainer\";\n\ntype PluginRegistryEvent = \"plugin:registered\" | \"plugin:error\";\n\ntype PluginRegistryEventPayloadMap = {\n \"plugin:registered\": { plugin: FrameworkMPlugin };\n \"plugin:error\": { plugin: FrameworkMPlugin; error: unknown };\n};\n\ntype PluginRegistryEventHandler<E extends PluginRegistryEvent> = (\n payload: PluginRegistryEventPayloadMap[E],\n) => void;\n\n/**\n * SDK version — used for compatibility checking.\n */\nexport const SDK_VERSION = \"0.1.0\";\n\n/**\n * Default icon mapping for well-known module names.\n */\nconst MODULE_ICONS: Record<string, string> = {\n Sales: \"shopping-cart\",\n Inventory: \"package\",\n HR: \"users\",\n Finance: \"dollar-sign\",\n Core: \"settings\",\n Other: \"folder\",\n};\n\nfunction isDebugEnabled(): boolean {\n const globalFlag = (globalThis as { __FRAMEWORK_M_PLUGIN_DEBUG__?: unknown })\n .__FRAMEWORK_M_PLUGIN_DEBUG__;\n if (typeof globalFlag === \"boolean\") {\n return globalFlag;\n }\n if (typeof globalFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(globalFlag.toLowerCase());\n }\n\n const processRef = (\n globalThis as { process?: { env?: Record<string, string | undefined> } }\n ).process;\n if (processRef?.env) {\n const envFlag = processRef.env.FRAMEWORK_M_PLUGIN_DEBUG;\n if (typeof envFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(envFlag.toLowerCase());\n }\n }\n\n return false;\n}\n\nconst registryLogger = {\n debug(message: string, ...args: unknown[]) {\n if (isDebugEnabled()) {\n console.debug(`[PluginRegistry] ${message}`, ...args);\n }\n },\n};\n\nexport class PluginRegistry {\n private readonly plugins = new Map<string, FrameworkMPlugin>();\n private menuCache: MenuItem[] | null = null;\n private readonly serviceContainer = new ServiceContainer();\n private readonly routeOwners = new Map<string, string>();\n private readonly menuNameOwners = new Map<string, string>();\n private readonly menuRouteOwners = new Map<string, string>();\n private readonly serviceOwners = new Map<string, string>();\n private diagnostics: PluginRegistryDiagnostic[] = [];\n private permissionChecker: PermissionChecker | null = null;\n private readonly eventListeners: {\n [E in PluginRegistryEvent]: Set<PluginRegistryEventHandler<E>>;\n } = {\n \"plugin:registered\": new Set(),\n \"plugin:error\": new Set(),\n };\n\n /**\n * Register a plugin with the registry.\n *\n * validates that the plugin has name and version, checks collisions,\n * stores it, registers any services into the ServiceContainer,\n * and invalidates the menu cache.\n *\n * @throws Error if plugin has no name or version\n */\n async register(plugin: FrameworkMPlugin): Promise<void> {\n if (!plugin.name || !plugin.version) {\n throw new Error(\"Plugin must have name and version\");\n }\n\n const diagnostics = this.validateRegistration(plugin);\n const errors = diagnostics.filter(d => d.severity === \"error\");\n\n if (errors.length > 0) {\n const error = new Error(\n `Plugin \"${plugin.name}\" registration failed: ${errors.map(d => d.message).join(\"; \")}`,\n );\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n const previous = this.plugins.get(plugin.name);\n this.plugins.set(plugin.name, plugin);\n this.rebuildIndexesAndServices();\n\n // Invalidate menu cache\n this.menuCache = null;\n\n try {\n if (plugin.onInit) {\n await Promise.resolve(plugin.onInit());\n }\n } catch (error) {\n if (previous) {\n this.plugins.set(plugin.name, previous);\n } else {\n this.plugins.delete(plugin.name);\n }\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n if (previous?.onDestroy && previous !== plugin) {\n await Promise.resolve(previous.onDestroy());\n }\n\n this.emit(\"plugin:registered\", { plugin });\n\n const warnings = diagnostics.filter(d => d.severity === \"warning\");\n if (warnings.length > 0) {\n registryLogger.debug(\n `Registered plugin \"${plugin.name}\" with warnings`,\n warnings,\n );\n }\n }\n\n /**\n * Get merged menu tree from all plugins.\n *\n * Collects all MenuItem entries, groups them by `module` (default: \"Other\"),\n * optionally sub-groups by `category`, and sorts by `order`.\n * Result is cached until a new plugin is registered.\n */\n getMenu(): MenuItem[] {\n if (this.menuCache) return this.menuCache;\n\n const allMenus: MenuItem[] = [];\n\n for (const plugin of this.plugins.values()) {\n if (plugin.menu) {\n allMenus.push(...plugin.menu);\n }\n }\n\n if (allMenus.length === 0) {\n this.menuCache = [];\n return this.menuCache;\n }\n\n this.menuCache = this.mergeMenus(allMenus);\n return this.menuCache;\n }\n\n /**\n * Get aggregated routes from all plugins.\n */\n getRoutes(): RouteDefinition[] {\n const routes: RouteDefinition[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.routes) {\n routes.push(...plugin.routes);\n }\n }\n return routes;\n }\n\n /**\n * Get a specific plugin by name.\n */\n getPlugin(name: string): FrameworkMPlugin | undefined {\n return this.plugins.get(name);\n }\n\n /**\n * Get all registered plugins.\n */\n getAllPlugins(): FrameworkMPlugin[] {\n return Array.from(this.plugins.values());\n }\n\n /**\n * Get the service container for DI.\n */\n getServiceContainer(): ServiceContainer {\n return this.serviceContainer;\n }\n\n /**\n * Unregister a plugin by name and run cleanup lifecycle if provided.\n */\n async unregister(pluginName: string): Promise<boolean> {\n const plugin = this.plugins.get(pluginName);\n if (!plugin) {\n return false;\n }\n\n this.plugins.delete(pluginName);\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n\n if (plugin.onDestroy) {\n await Promise.resolve(plugin.onDestroy());\n }\n\n return true;\n }\n\n /**\n * Resolve a service instance from the registry-level DI container.\n */\n async getService<T = unknown>(name: string): Promise<T> {\n return this.serviceContainer.get<T>(name);\n }\n\n /**\n * Aggregate all widgets contributed by registered plugins.\n */\n getWidgets(): Widget[] {\n const widgets: Widget[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.widgets) {\n widgets.push(...plugin.widgets);\n }\n }\n return widgets;\n }\n\n /**\n * Configure a permission checker used by consumer hooks.\n */\n setPermissionChecker(checker: PermissionChecker | null): void {\n this.permissionChecker = checker;\n }\n\n /**\n * Get the configured permission checker.\n */\n getPermissionChecker(): PermissionChecker | null {\n return this.permissionChecker;\n }\n\n /**\n * Subscribe to plugin lifecycle events.\n */\n on<E extends PluginRegistryEvent>(\n event: E,\n handler: PluginRegistryEventHandler<E>,\n ): () => void {\n this.eventListeners[event].add(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n return () => {\n this.eventListeners[event].delete(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n };\n }\n\n /**\n * Get emitted diagnostics.\n */\n getDiagnostics(\n severity?: PluginRegistryDiagnosticSeverity,\n ): PluginRegistryDiagnostic[] {\n if (!severity) {\n return [...this.diagnostics];\n }\n return this.diagnostics.filter(d => d.severity === severity);\n }\n\n /**\n * Clear diagnostics.\n */\n clearDiagnostics(): void {\n this.diagnostics = [];\n }\n\n // -------------------------------------------------------------------------\n // Version Compatibility\n // -------------------------------------------------------------------------\n\n /**\n * Check compatibility of all registered plugins.\n *\n * Returns a report of all plugins with their compatibility status:\n * - SDK version compatibility\n * - Peer plugin dependency satisfaction\n */\n checkCompatibility(): CompatibilityReport[] {\n const reports: CompatibilityReport[] = [];\n\n for (const plugin of this.plugins.values()) {\n const report: CompatibilityReport = {\n name: plugin.name,\n version: plugin.version,\n sdkCompatible: true,\n missingPeerPlugins: [],\n };\n\n // Check SDK version\n if (plugin.minSdkVersion) {\n report.sdkCompatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n }\n\n // Check peer plugins\n if (plugin.peerPlugins) {\n for (const peerName of plugin.peerPlugins) {\n if (!this.plugins.has(peerName)) {\n report.missingPeerPlugins.push(peerName);\n }\n }\n }\n\n reports.push(report);\n }\n\n return reports;\n }\n\n // -------------------------------------------------------------------------\n // Private helpers\n // -------------------------------------------------------------------------\n\n /**\n * Simple semver compatibility check.\n * Checks if `current` satisfies `>=required`.\n */\n private checkSemverCompat(current: string, required: string): boolean {\n const clean = required.replace(/^>=?/, \"\");\n const [cMajor, cMinor = 0, cPatch = 0] = current.split(\".\").map(Number);\n const [rMajor, rMinor = 0, rPatch = 0] = clean.split(\".\").map(Number);\n\n if (cMajor !== rMajor) return cMajor > rMajor;\n if (cMinor !== rMinor) return cMinor > rMinor;\n return cPatch >= rPatch;\n }\n\n private validateRegistration(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n return [\n ...this.validateSdkCompatibility(plugin),\n ...this.validateDuplicatePlugin(plugin),\n ...this.validateRouteCollisions(plugin),\n ...this.validateMenuCollisions(plugin),\n ...this.validateServiceCollisions(plugin),\n ];\n }\n\n private validateSdkCompatibility(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (plugin.minSdkVersion) {\n const compatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n if (!compatible) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SDK_INCOMPATIBLE\",\n severity: \"warning\",\n message:\n `Plugin ${plugin.name} requires SDK >=${plugin.minSdkVersion}, ` +\n `current SDK is ${SDK_VERSION}. Plugin may not work correctly.`,\n pluginName: plugin.name,\n key: plugin.minSdkVersion,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateDuplicatePlugin(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (this.plugins.has(plugin.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"PLUGIN_DUPLICATE\",\n severity: \"warning\",\n message: `Plugin ${plugin.name} is already registered and will be replaced`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: plugin.name,\n }),\n );\n }\n\n return diagnostics;\n }\n\n private validateRouteCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenRoutePaths = new Set<string>();\n for (const route of plugin.routes ?? []) {\n if (seenRoutePaths.has(route.path)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate route path \"${route.path}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: route.path,\n }),\n );\n continue;\n }\n\n seenRoutePaths.add(route.path);\n const existingRouteOwner = this.routeOwners.get(route.path);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Route path \"${route.path}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: route.path,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateMenuCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenMenuNames = new Set<string>();\n const seenMenuRoutes = new Set<string>();\n for (const item of plugin.menu ?? []) {\n if (seenMenuNames.has(item.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu name \"${item.name}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.name,\n }),\n );\n } else {\n seenMenuNames.add(item.name);\n const existingNameOwner = this.menuNameOwners.get(item.name);\n if (existingNameOwner && existingNameOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message:\n `Menu name \"${item.name}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingNameOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingNameOwner,\n key: item.name,\n }),\n );\n }\n }\n\n if (seenMenuRoutes.has(item.route)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu route \"${item.route}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.route,\n }),\n );\n } else {\n seenMenuRoutes.add(item.route);\n const existingRouteOwner = this.menuRouteOwners.get(item.route);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Menu route \"${item.route}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: item.route,\n }),\n );\n }\n }\n }\n\n return diagnostics;\n }\n\n private validateServiceCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenServiceNames = new Set<string>();\n for (const serviceName of Object.keys(plugin.services ?? {})) {\n if (seenServiceNames.has(serviceName)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message: `Duplicate service \"${serviceName}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: serviceName,\n }),\n );\n continue;\n }\n\n seenServiceNames.add(serviceName);\n const existingServiceOwner = this.serviceOwners.get(serviceName);\n if (existingServiceOwner && existingServiceOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message:\n `Service \"${serviceName}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingServiceOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingServiceOwner,\n key: serviceName,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private addDiagnostic(\n diagnostic: Omit<PluginRegistryDiagnostic, \"timestamp\">,\n ): PluginRegistryDiagnostic {\n const fullDiagnostic: PluginRegistryDiagnostic = {\n ...diagnostic,\n timestamp: new Date().toISOString(),\n };\n this.diagnostics.push(fullDiagnostic);\n return fullDiagnostic;\n }\n\n /**\n * Merge flat menu items into a grouped tree:\n * Module → (optional) Category → Items\n *\n * Items without a `module` are placed under \"Other\".\n */\n private mergeMenus(items: MenuItem[]): MenuItem[] {\n const moduleMap = new Map<string, MenuItem>();\n\n for (const item of items) {\n const moduleName = item.module || \"Other\";\n\n if (!moduleMap.has(moduleName)) {\n moduleMap.set(moduleName, {\n name: moduleName.toLowerCase(),\n label: moduleName,\n route: `/${moduleName.toLowerCase()}`,\n icon: this.getModuleIcon(moduleName),\n order: item.order,\n children: [],\n });\n }\n\n const moduleGroup = moduleMap.get(moduleName)!;\n\n // Track lowest order value for module-level sorting\n if (item.order !== undefined) {\n if (moduleGroup.order === undefined || item.order < moduleGroup.order) {\n moduleGroup.order = item.order;\n }\n }\n\n if (item.category) {\n // Find or create category sub-group\n let categoryGroup = moduleGroup.children?.find(\n c => c.label === item.category,\n );\n\n if (!categoryGroup) {\n categoryGroup = {\n name: item.category.toLowerCase(),\n label: item.category,\n route: `/${moduleName.toLowerCase()}/${item.category.toLowerCase()}`,\n children: [],\n };\n moduleGroup.children!.push(categoryGroup);\n }\n\n categoryGroup.children!.push(item);\n } else {\n // No category — add directly to module\n moduleGroup.children!.push(item);\n }\n }\n\n // Sort module groups by order (lower first, undefined last)\n return Array.from(moduleMap.values()).sort(\n (a, b) => (a.order ?? 999) - (b.order ?? 999),\n );\n }\n\n private getModuleIcon(moduleName: string): string {\n return MODULE_ICONS[moduleName] || MODULE_ICONS.Other;\n }\n\n private rebuildIndexesAndServices(): void {\n this.routeOwners.clear();\n this.menuNameOwners.clear();\n this.menuRouteOwners.clear();\n this.serviceOwners.clear();\n this.serviceContainer.clear();\n\n for (const plugin of this.plugins.values()) {\n this.registerPluginServices(plugin);\n this.registerPluginRoutes(plugin);\n this.registerPluginMenuItems(plugin);\n }\n }\n\n private registerPluginServices(plugin: FrameworkMPlugin): void {\n for (const [name, factory] of Object.entries(plugin.services ?? {})) {\n this.serviceContainer.register(name, factory);\n this.serviceOwners.set(name, plugin.name);\n }\n }\n\n private registerPluginRoutes(plugin: FrameworkMPlugin): void {\n for (const route of plugin.routes ?? []) {\n this.routeOwners.set(route.path, plugin.name);\n }\n }\n\n private registerPluginMenuItems(plugin: FrameworkMPlugin): void {\n for (const item of plugin.menu ?? []) {\n this.menuNameOwners.set(item.name, plugin.name);\n this.menuRouteOwners.set(item.route, plugin.name);\n }\n }\n\n private emit<E extends PluginRegistryEvent>(\n event: E,\n payload: PluginRegistryEventPayloadMap[E],\n ): void {\n for (const handler of this.eventListeners[event]) {\n handler(payload as never);\n }\n }\n}\n","/**\n * PluginRegistryContext — React context for the PluginRegistry.\n *\n * Provides the PluginRegistry to all child components via React Context.\n * Must wrap any component that uses usePluginMenu(), usePlugin(), or useService().\n */\n\nimport { createContext, useEffect, useState, type ReactNode } from \"react\";\nimport { PluginRegistry } from \"../core/PluginRegistry\";\n\nexport const PluginRegistryContext = createContext<PluginRegistry | null>(null);\n\nexport interface PluginRegistryProviderProps {\n readonly children: ReactNode;\n /** Optional pre-configured PluginRegistry instance */\n readonly registry?: PluginRegistry;\n}\n\n/**\n * Provider component that makes the PluginRegistry available to child components.\n *\n * @example\n * ```tsx\n * const registry = new PluginRegistry();\n * await registry.register(wmsPlugin);\n *\n * <PluginRegistryProvider registry={registry}>\n * <App />\n * </PluginRegistryProvider>\n * ```\n */\nexport function PluginRegistryProvider({\n children,\n registry,\n}: PluginRegistryProviderProps) {\n const [registryInstance] = useState<PluginRegistry>(\n () => registry ?? new PluginRegistry(),\n );\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n setIsReady(true);\n }, []);\n\n if (!isReady) {\n return null;\n }\n\n return (\n <PluginRegistryContext.Provider value={registryInstance}>\n {children}\n </PluginRegistryContext.Provider>\n );\n}\n","/**\n * usePluginMenu — React hook for accessing the merged menu tree.\n *\n * Returns the merged MenuItem[] from all registered plugins.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function Sidebar() {\n * const menu = usePluginMenu();\n * return <nav>{menu.map(m => <ModuleGroup key={m.name} {...m} />)}</nav>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { MenuItem } from \"../types/plugin\";\n\nasync function filterMenuByPermissions(\n items: MenuItem[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<MenuItem[]> {\n const filtered: MenuItem[] = [];\n\n for (const item of items) {\n if (item.hidden) {\n continue;\n }\n\n if (item.permissions && item.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(item.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n const children = item.children\n ? await filterMenuByPermissions(item.children, checker)\n : undefined;\n\n if (item.children && (children?.length ?? 0) === 0) {\n continue;\n }\n\n filtered.push({ ...item, children });\n }\n\n return filtered;\n}\n\nexport function usePluginMenu(): MenuItem[] {\n const registry = useContext(PluginRegistryContext);\n const [menu, setMenu] = useState<MenuItem[]>([]);\n\n if (!registry) {\n throw new Error(\"usePluginMenu must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getMenu();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setMenu(source.filter(item => !item.hidden));\n }\n return;\n }\n\n const filtered = await filterMenuByPermissions(source, checker);\n if (!cancelled) {\n setMenu(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return menu;\n}\n","/**\n * usePlugin — React hook for accessing a specific plugin by name.\n *\n * Returns the FrameworkMPlugin or undefined if not found.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WMSStatus() {\n * const wms = usePlugin(\"wms\");\n * if (!wms) return <p>WMS not installed</p>;\n * return <p>WMS v{wms.version}</p>;\n * }\n * ```\n */\n\nimport { useContext, useMemo } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { FrameworkMPlugin } from \"../types/plugin\";\n\nexport function usePlugin(name: string): FrameworkMPlugin | undefined {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"usePlugin must be used within PluginRegistryProvider\");\n }\n\n return useMemo(() => registry.getPlugin(name), [registry, name]);\n}\n","/**\n * useService — React hook for accessing a service from the ServiceContainer.\n *\n * Returns the service instance (lazily loaded), loading state, and error.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WarehouseDashboard() {\n * const { service, isLoading, error } = useService<WarehouseService>(\"warehouseService\");\n * if (isLoading) return <Spinner />;\n * if (error) return <Error message={error.message} />;\n * return <div>{service.getWarehouses()}</div>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useMemo, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\n\ninterface UseServiceResult<T> {\n service: T | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport function useService<T = unknown>(name: string): UseServiceResult<T> {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"useService must be used within PluginRegistryProvider\");\n }\n\n const [service, setService] = useState<T | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const servicePromise = useMemo(\n () => registry.getService<T>(name),\n [registry, name],\n );\n\n useEffect(() => {\n let cancelled = false;\n setIsLoading(true);\n setError(null);\n\n servicePromise\n .then(instance => {\n if (!cancelled) {\n setService(instance);\n setIsLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsLoading(false);\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [servicePromise]);\n\n return { service, isLoading, error };\n}\n","/**\n * useWidgets — React hook for accessing plugin-provided dashboard widgets.\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { Widget } from \"../types/plugin\";\n\nasync function filterWidgetsByPermissions(\n widgets: Widget[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<Widget[]> {\n const filtered: Widget[] = [];\n\n for (const widget of widgets) {\n if (widget.permissions && widget.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(widget.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n filtered.push(widget);\n }\n\n return filtered;\n}\n\nexport function useWidgets(): Widget[] {\n const registry = useContext(PluginRegistryContext);\n const [widgets, setWidgets] = useState<Widget[]>([]);\n\n if (!registry) {\n throw new Error(\"useWidgets must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getWidgets();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setWidgets(source);\n }\n return;\n }\n\n const filtered = await filterWidgetsByPermissions(source, checker);\n if (!cancelled) {\n setWidgets(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return widgets;\n}\n"],"names":["ServiceContainer","__publicField","name","factory","instance","SDK_VERSION","MODULE_ICONS","isDebugEnabled","globalFlag","processRef","envFlag","registryLogger","message","args","PluginRegistry","plugin","diagnostics","errors","d","error","previous","warnings","allMenus","routes","pluginName","widgets","checker","event","handler","severity","reports","report","peerName","current","required","clean","cMajor","cMinor","cPatch","rMajor","rMinor","rPatch","seenRoutePaths","route","existingRouteOwner","seenMenuNames","seenMenuRoutes","item","existingNameOwner","seenServiceNames","serviceName","existingServiceOwner","diagnostic","fullDiagnostic","items","moduleMap","moduleName","moduleGroup","categoryGroup","_a","c","a","b","payload","PluginRegistryContext","createContext","PluginRegistryProvider","children","registry","registryInstance","useState","isReady","setIsReady","useEffect","filterMenuByPermissions","filtered","usePluginMenu","useContext","menu","setMenu","cancelled","source","usePlugin","useMemo","useService","service","setService","isLoading","setIsLoading","setError","servicePromise","err","filterWidgetsByPermissions","widget","useWidgets","setWidgets"],"mappings":";;;;;AAgBO,MAAMA,EAAiB;AAAA,EAAvB;AACY,IAAAC,EAAA,uCAAgB,IAAA;AAChB,IAAAA,EAAA,uCAAgB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjC,SAAYC,GAAcC,GAAkC;AAC1D,SAAK,UAAU,IAAID,GAAMC,CAAyB,GAElD,KAAK,UAAU,OAAOD,CAAI;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAiBA,GAA0B;AAE/C,QAAI,KAAK,UAAU,IAAIA,CAAI;AACzB,aAAO,KAAK,UAAU,IAAIA,CAAI;AAGhC,UAAMC,IAAU,KAAK,UAAU,IAAID,CAAI;AACvC,QAAI,CAACC;AACH,YAAM,IAAI,MAAM,YAAYD,CAAI,qBAAqB;AAIvD,UAAME,IAAW,MAAM,QAAQ,QAAQD,GAAS;AAChD,gBAAK,UAAU,IAAID,GAAME,CAAQ,GAC1BA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,IAAIF,GAAuB;AACzB,WAAO,KAAK,UAAU,IAAIA,CAAI;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,SAAmB;AACjB,WAAO,MAAM,KAAK,KAAK,UAAU,MAAM;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,UAAU,MAAA,GACf,KAAK,UAAU,MAAA;AAAA,EACjB;AACF;ACvCO,MAAMG,IAAc,SAKrBC,IAAuC;AAAA,EAC3C,OAAO;AAAA,EACP,WAAW;AAAA,EACX,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACT;AAEA,SAASC,IAA0B;AACjC,QAAMC,IAAc,WACjB;AACH,MAAI,OAAOA,KAAe;AACxB,WAAOA;AAET,MAAI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,GAAQvD,CAAO;AACjE,MAAKsD,KACHe,EAAWpB,CAAQ;AAAA,IAEvB,GAEK,GAEE,MAAM;AACX,MAAAK,IAAY;AAAA,IACd;AAAA,EACF,GAAG,CAACZ,CAAQ,CAAC,GAEN3C;AACT;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/core/ServiceContainer.ts","../src/core/PluginRegistry.ts","../src/context/PluginRegistryContext.tsx","../src/hooks/usePluginMenu.ts","../src/hooks/usePlugin.ts","../src/hooks/useService.ts","../src/hooks/useWidgets.ts","../src/loader/federation.ts"],"sourcesContent":["/**\n * ServiceContainer — Simple dependency injection for plugin services.\n *\n * Services are registered as factories and lazily instantiated as singletons\n * on first `get()` call. Supports both sync and async factories.\n *\n * @example\n * ```ts\n * const container = new ServiceContainer();\n * container.register(\"warehouseService\", () => new WarehouseService());\n * const svc = await container.get<WarehouseService>(\"warehouseService\");\n * ```\n */\n\nimport type { ServiceFactory } from \"../types/plugin\";\n\nexport class ServiceContainer {\n private readonly factories = new Map<string, ServiceFactory>();\n private readonly instances = new Map<string, unknown>();\n\n /**\n * Register a service factory.\n *\n * @param name — unique service name\n * @param factory — factory function (sync or async)\n */\n register<T>(name: string, factory: ServiceFactory<T>): void {\n this.factories.set(name, factory as ServiceFactory);\n // Clear cached instance if re-registering\n this.instances.delete(name);\n }\n\n /**\n * Get a service by name. Lazily instantiates on first call (singleton).\n *\n * @throws Error if service is not registered\n */\n async get<T = unknown>(name: string): Promise<T> {\n // Return cached singleton\n if (this.instances.has(name)) {\n return this.instances.get(name) as T;\n }\n\n const factory = this.factories.get(name);\n if (!factory) {\n throw new Error(`Service \"${name}\" is not registered`);\n }\n\n // Create instance (may be async)\n const instance = await Promise.resolve(factory());\n this.instances.set(name, instance);\n return instance as T;\n }\n\n /**\n * Check if a service is registered.\n */\n has(name: string): boolean {\n return this.factories.has(name);\n }\n\n /**\n * Get all registered service names.\n */\n getAll(): string[] {\n return Array.from(this.factories.keys());\n }\n\n /**\n * Clear all registered factories and cached instances.\n */\n clear(): void {\n this.factories.clear();\n this.instances.clear();\n }\n}\n","/**\n * PluginRegistry — Central registry for Framework M plugins.\n *\n * Handles plugin registration, menu merging (by module/category),\n * route aggregation, and service container population.\n *\n * Per ADR-0008: this is the core runtime that the shell app bootstraps\n * and provides to all components via React Context.\n */\n\nimport type {\n FrameworkMPlugin,\n MenuItem,\n RouteDefinition,\n CompatibilityReport,\n PluginRegistryDiagnostic,\n PluginRegistryDiagnosticSeverity,\n PermissionChecker,\n Widget,\n} from \"../types/plugin\";\nimport { ServiceContainer } from \"./ServiceContainer\";\n\ntype PluginRegistryEvent = \"plugin:registered\" | \"plugin:error\";\n\ntype PluginRegistryEventPayloadMap = {\n \"plugin:registered\": { plugin: FrameworkMPlugin };\n \"plugin:error\": { plugin: FrameworkMPlugin; error: unknown };\n};\n\ntype PluginRegistryEventHandler<E extends PluginRegistryEvent> = (\n payload: PluginRegistryEventPayloadMap[E],\n) => void;\n\n/**\n * SDK version — used for compatibility checking.\n */\nexport const SDK_VERSION = \"0.1.0\";\n\n/**\n * Default icon mapping for well-known module names.\n */\nconst MODULE_ICONS: Record<string, string> = {\n Sales: \"shopping-cart\",\n Inventory: \"package\",\n HR: \"users\",\n Finance: \"dollar-sign\",\n Core: \"settings\",\n Other: \"folder\",\n};\n\nfunction isDebugEnabled(): boolean {\n const globalFlag = (globalThis as { __FRAMEWORK_M_PLUGIN_DEBUG__?: unknown })\n .__FRAMEWORK_M_PLUGIN_DEBUG__;\n if (typeof globalFlag === \"boolean\") {\n return globalFlag;\n }\n if (typeof globalFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(globalFlag.toLowerCase());\n }\n\n const processRef = (\n globalThis as { process?: { env?: Record<string, string | undefined> } }\n ).process;\n if (processRef?.env) {\n const envFlag = processRef.env.FRAMEWORK_M_PLUGIN_DEBUG;\n if (typeof envFlag === \"string\") {\n return [\"1\", \"true\", \"yes\", \"on\"].includes(envFlag.toLowerCase());\n }\n }\n\n return false;\n}\n\nconst registryLogger = {\n debug(message: string, ...args: unknown[]) {\n if (isDebugEnabled()) {\n console.debug(`[PluginRegistry] ${message}`, ...args);\n }\n },\n};\n\nexport class PluginRegistry {\n private readonly plugins = new Map<string, FrameworkMPlugin>();\n private menuCache: MenuItem[] | null = null;\n private readonly serviceContainer = new ServiceContainer();\n private readonly routeOwners = new Map<string, string>();\n private readonly menuNameOwners = new Map<string, string>();\n private readonly menuRouteOwners = new Map<string, string>();\n private readonly serviceOwners = new Map<string, string>();\n private diagnostics: PluginRegistryDiagnostic[] = [];\n private permissionChecker: PermissionChecker | null = null;\n private readonly eventListeners: {\n [E in PluginRegistryEvent]: Set<PluginRegistryEventHandler<E>>;\n } = {\n \"plugin:registered\": new Set(),\n \"plugin:error\": new Set(),\n };\n\n /**\n * Register a plugin with the registry.\n *\n * validates that the plugin has name and version, checks collisions,\n * stores it, registers any services into the ServiceContainer,\n * and invalidates the menu cache.\n *\n * @throws Error if plugin has no name or version\n */\n async register(plugin: FrameworkMPlugin): Promise<void> {\n if (!plugin.name || !plugin.version) {\n throw new Error(\"Plugin must have name and version\");\n }\n\n const diagnostics = this.validateRegistration(plugin);\n const errors = diagnostics.filter(d => d.severity === \"error\");\n\n if (errors.length > 0) {\n const error = new Error(\n `Plugin \"${plugin.name}\" registration failed: ${errors.map(d => d.message).join(\"; \")}`,\n );\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n const previous = this.plugins.get(plugin.name);\n this.plugins.set(plugin.name, plugin);\n this.rebuildIndexesAndServices();\n\n // Invalidate menu cache\n this.menuCache = null;\n\n try {\n if (plugin.onInit) {\n await Promise.resolve(plugin.onInit());\n }\n } catch (error) {\n if (previous) {\n this.plugins.set(plugin.name, previous);\n } else {\n this.plugins.delete(plugin.name);\n }\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n this.emit(\"plugin:error\", { plugin, error });\n throw error;\n }\n\n if (previous?.onDestroy && previous !== plugin) {\n await Promise.resolve(previous.onDestroy());\n }\n\n this.emit(\"plugin:registered\", { plugin });\n\n const warnings = diagnostics.filter(d => d.severity === \"warning\");\n if (warnings.length > 0) {\n registryLogger.debug(\n `Registered plugin \"${plugin.name}\" with warnings`,\n warnings,\n );\n }\n }\n\n /**\n * Get merged menu tree from all plugins.\n *\n * Collects all MenuItem entries, groups them by `module` (default: \"Other\"),\n * optionally sub-groups by `category`, and sorts by `order`.\n * Result is cached until a new plugin is registered.\n */\n getMenu(): MenuItem[] {\n if (this.menuCache) return this.menuCache;\n\n const allMenus: MenuItem[] = [];\n\n for (const plugin of this.plugins.values()) {\n if (plugin.menu) {\n allMenus.push(...plugin.menu);\n }\n }\n\n if (allMenus.length === 0) {\n this.menuCache = [];\n return this.menuCache;\n }\n\n this.menuCache = this.mergeMenus(allMenus);\n return this.menuCache;\n }\n\n /**\n * Get aggregated routes from all plugins.\n */\n getRoutes(): RouteDefinition[] {\n const routes: RouteDefinition[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.routes) {\n routes.push(...plugin.routes);\n }\n }\n return routes;\n }\n\n /**\n * Get a specific plugin by name.\n */\n getPlugin(name: string): FrameworkMPlugin | undefined {\n return this.plugins.get(name);\n }\n\n /**\n * Get all registered plugins.\n */\n getAllPlugins(): FrameworkMPlugin[] {\n return Array.from(this.plugins.values());\n }\n\n /**\n * Get the service container for DI.\n */\n getServiceContainer(): ServiceContainer {\n return this.serviceContainer;\n }\n\n /**\n * Unregister a plugin by name and run cleanup lifecycle if provided.\n */\n async unregister(pluginName: string): Promise<boolean> {\n const plugin = this.plugins.get(pluginName);\n if (!plugin) {\n return false;\n }\n\n this.plugins.delete(pluginName);\n this.rebuildIndexesAndServices();\n this.menuCache = null;\n\n if (plugin.onDestroy) {\n await Promise.resolve(plugin.onDestroy());\n }\n\n return true;\n }\n\n /**\n * Resolve a service instance from the registry-level DI container.\n */\n async getService<T = unknown>(name: string): Promise<T> {\n return this.serviceContainer.get<T>(name);\n }\n\n /**\n * Aggregate all widgets contributed by registered plugins.\n */\n getWidgets(): Widget[] {\n const widgets: Widget[] = [];\n for (const plugin of this.plugins.values()) {\n if (plugin.widgets) {\n widgets.push(...plugin.widgets);\n }\n }\n return widgets;\n }\n\n /**\n * Configure a permission checker used by consumer hooks.\n */\n setPermissionChecker(checker: PermissionChecker | null): void {\n this.permissionChecker = checker;\n }\n\n /**\n * Get the configured permission checker.\n */\n getPermissionChecker(): PermissionChecker | null {\n return this.permissionChecker;\n }\n\n /**\n * Subscribe to plugin lifecycle events.\n */\n on<E extends PluginRegistryEvent>(\n event: E,\n handler: PluginRegistryEventHandler<E>,\n ): () => void {\n this.eventListeners[event].add(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n return () => {\n this.eventListeners[event].delete(\n handler as unknown as PluginRegistryEventHandler<PluginRegistryEvent>,\n );\n };\n }\n\n /**\n * Get emitted diagnostics.\n */\n getDiagnostics(\n severity?: PluginRegistryDiagnosticSeverity,\n ): PluginRegistryDiagnostic[] {\n if (!severity) {\n return [...this.diagnostics];\n }\n return this.diagnostics.filter(d => d.severity === severity);\n }\n\n /**\n * Clear diagnostics.\n */\n clearDiagnostics(): void {\n this.diagnostics = [];\n }\n\n // -------------------------------------------------------------------------\n // Version Compatibility\n // -------------------------------------------------------------------------\n\n /**\n * Check compatibility of all registered plugins.\n *\n * Returns a report of all plugins with their compatibility status:\n * - SDK version compatibility\n * - Peer plugin dependency satisfaction\n */\n checkCompatibility(): CompatibilityReport[] {\n const reports: CompatibilityReport[] = [];\n\n for (const plugin of this.plugins.values()) {\n const report: CompatibilityReport = {\n name: plugin.name,\n version: plugin.version,\n sdkCompatible: true,\n missingPeerPlugins: [],\n };\n\n // Check SDK version\n if (plugin.minSdkVersion) {\n report.sdkCompatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n }\n\n // Check peer plugins\n if (plugin.peerPlugins) {\n for (const peerName of plugin.peerPlugins) {\n if (!this.plugins.has(peerName)) {\n report.missingPeerPlugins.push(peerName);\n }\n }\n }\n\n reports.push(report);\n }\n\n return reports;\n }\n\n // -------------------------------------------------------------------------\n // Private helpers\n // -------------------------------------------------------------------------\n\n /**\n * Simple semver compatibility check.\n * Checks if `current` satisfies `>=required`.\n */\n private checkSemverCompat(current: string, required: string): boolean {\n const clean = required.replace(/^>=?/, \"\");\n const [cMajor, cMinor = 0, cPatch = 0] = current.split(\".\").map(Number);\n const [rMajor, rMinor = 0, rPatch = 0] = clean.split(\".\").map(Number);\n\n if (cMajor !== rMajor) return cMajor > rMajor;\n if (cMinor !== rMinor) return cMinor > rMinor;\n return cPatch >= rPatch;\n }\n\n private validateRegistration(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n return [\n ...this.validateSdkCompatibility(plugin),\n ...this.validateDuplicatePlugin(plugin),\n ...this.validateRouteCollisions(plugin),\n ...this.validateMenuCollisions(plugin),\n ...this.validateServiceCollisions(plugin),\n ];\n }\n\n private validateSdkCompatibility(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (plugin.minSdkVersion) {\n const compatible = this.checkSemverCompat(\n SDK_VERSION,\n plugin.minSdkVersion,\n );\n if (!compatible) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SDK_INCOMPATIBLE\",\n severity: \"warning\",\n message:\n `Plugin ${plugin.name} requires SDK >=${plugin.minSdkVersion}, ` +\n `current SDK is ${SDK_VERSION}. Plugin may not work correctly.`,\n pluginName: plugin.name,\n key: plugin.minSdkVersion,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateDuplicatePlugin(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n if (this.plugins.has(plugin.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"PLUGIN_DUPLICATE\",\n severity: \"warning\",\n message: `Plugin ${plugin.name} is already registered and will be replaced`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: plugin.name,\n }),\n );\n }\n\n return diagnostics;\n }\n\n private validateRouteCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenRoutePaths = new Set<string>();\n for (const route of plugin.routes ?? []) {\n if (seenRoutePaths.has(route.path)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate route path \"${route.path}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: route.path,\n }),\n );\n continue;\n }\n\n seenRoutePaths.add(route.path);\n const existingRouteOwner = this.routeOwners.get(route.path);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Route path \"${route.path}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: route.path,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private validateMenuCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenMenuNames = new Set<string>();\n const seenMenuRoutes = new Set<string>();\n for (const item of plugin.menu ?? []) {\n if (seenMenuNames.has(item.name)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu name \"${item.name}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.name,\n }),\n );\n } else {\n seenMenuNames.add(item.name);\n const existingNameOwner = this.menuNameOwners.get(item.name);\n if (existingNameOwner && existingNameOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_NAME_COLLISION\",\n severity: \"error\",\n message:\n `Menu name \"${item.name}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingNameOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingNameOwner,\n key: item.name,\n }),\n );\n }\n }\n\n if (seenMenuRoutes.has(item.route)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message: `Duplicate menu route \"${item.route}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: item.route,\n }),\n );\n } else {\n seenMenuRoutes.add(item.route);\n const existingRouteOwner = this.menuRouteOwners.get(item.route);\n if (existingRouteOwner && existingRouteOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"MENU_ROUTE_COLLISION\",\n severity: \"error\",\n message:\n `Menu route \"${item.route}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingRouteOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingRouteOwner,\n key: item.route,\n }),\n );\n }\n }\n }\n\n return diagnostics;\n }\n\n private validateServiceCollisions(\n plugin: FrameworkMPlugin,\n ): PluginRegistryDiagnostic[] {\n const diagnostics: PluginRegistryDiagnostic[] = [];\n\n const seenServiceNames = new Set<string>();\n for (const serviceName of Object.keys(plugin.services ?? {})) {\n if (seenServiceNames.has(serviceName)) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message: `Duplicate service \"${serviceName}\" inside plugin ${plugin.name}`,\n pluginName: plugin.name,\n conflictingPluginName: plugin.name,\n key: serviceName,\n }),\n );\n continue;\n }\n\n seenServiceNames.add(serviceName);\n const existingServiceOwner = this.serviceOwners.get(serviceName);\n if (existingServiceOwner && existingServiceOwner !== plugin.name) {\n diagnostics.push(\n this.addDiagnostic({\n code: \"SERVICE_COLLISION\",\n severity: \"error\",\n message:\n `Service \"${serviceName}\" from plugin ${plugin.name} ` +\n `conflicts with plugin ${existingServiceOwner}`,\n pluginName: plugin.name,\n conflictingPluginName: existingServiceOwner,\n key: serviceName,\n }),\n );\n }\n }\n\n return diagnostics;\n }\n\n private addDiagnostic(\n diagnostic: Omit<PluginRegistryDiagnostic, \"timestamp\">,\n ): PluginRegistryDiagnostic {\n const fullDiagnostic: PluginRegistryDiagnostic = {\n ...diagnostic,\n timestamp: new Date().toISOString(),\n };\n this.diagnostics.push(fullDiagnostic);\n return fullDiagnostic;\n }\n\n /**\n * Merge flat menu items into a grouped tree:\n * Module → (optional) Category → Items\n *\n * Items without a `module` are placed under \"Other\".\n */\n private mergeMenus(items: MenuItem[]): MenuItem[] {\n const moduleMap = new Map<string, MenuItem>();\n\n for (const item of items) {\n const moduleName = item.module || \"Other\";\n\n if (!moduleMap.has(moduleName)) {\n moduleMap.set(moduleName, {\n name: moduleName.toLowerCase(),\n label: moduleName,\n route: `/${moduleName.toLowerCase()}`,\n icon: this.getModuleIcon(moduleName),\n order: item.order,\n children: [],\n });\n }\n\n const moduleGroup = moduleMap.get(moduleName)!;\n\n // Track lowest order value for module-level sorting\n if (item.order !== undefined) {\n if (moduleGroup.order === undefined || item.order < moduleGroup.order) {\n moduleGroup.order = item.order;\n }\n }\n\n if (item.category) {\n // Find or create category sub-group\n let categoryGroup = moduleGroup.children?.find(\n c => c.label === item.category,\n );\n\n if (!categoryGroup) {\n categoryGroup = {\n name: item.category.toLowerCase(),\n label: item.category,\n route: `/${moduleName.toLowerCase()}/${item.category.toLowerCase()}`,\n children: [],\n };\n moduleGroup.children!.push(categoryGroup);\n }\n\n categoryGroup.children!.push(item);\n } else {\n // No category — add directly to module\n moduleGroup.children!.push(item);\n }\n }\n\n // Sort module groups by order (lower first, undefined last)\n return Array.from(moduleMap.values()).sort(\n (a, b) => (a.order ?? 999) - (b.order ?? 999),\n );\n }\n\n private getModuleIcon(moduleName: string): string {\n return MODULE_ICONS[moduleName] || MODULE_ICONS.Other;\n }\n\n private rebuildIndexesAndServices(): void {\n this.routeOwners.clear();\n this.menuNameOwners.clear();\n this.menuRouteOwners.clear();\n this.serviceOwners.clear();\n this.serviceContainer.clear();\n\n for (const plugin of this.plugins.values()) {\n this.registerPluginServices(plugin);\n this.registerPluginRoutes(plugin);\n this.registerPluginMenuItems(plugin);\n }\n }\n\n private registerPluginServices(plugin: FrameworkMPlugin): void {\n for (const [name, factory] of Object.entries(plugin.services ?? {})) {\n this.serviceContainer.register(name, factory);\n this.serviceOwners.set(name, plugin.name);\n }\n }\n\n private registerPluginRoutes(plugin: FrameworkMPlugin): void {\n for (const route of plugin.routes ?? []) {\n this.routeOwners.set(route.path, plugin.name);\n }\n }\n\n private registerPluginMenuItems(plugin: FrameworkMPlugin): void {\n for (const item of plugin.menu ?? []) {\n this.menuNameOwners.set(item.name, plugin.name);\n this.menuRouteOwners.set(item.route, plugin.name);\n }\n }\n\n private emit<E extends PluginRegistryEvent>(\n event: E,\n payload: PluginRegistryEventPayloadMap[E],\n ): void {\n for (const handler of this.eventListeners[event]) {\n handler(payload as never);\n }\n }\n}\n","/**\n * PluginRegistryContext — React context for the PluginRegistry.\n *\n * Provides the PluginRegistry to all child components via React Context.\n * Must wrap any component that uses usePluginMenu(), usePlugin(), or useService().\n */\n\nimport { createContext, useEffect, useState, type ReactNode } from \"react\";\nimport { PluginRegistry } from \"../core/PluginRegistry\";\n\nexport const PluginRegistryContext = createContext<PluginRegistry | null>(null);\n\nexport interface PluginRegistryProviderProps {\n readonly children: ReactNode;\n /** Optional pre-configured PluginRegistry instance */\n readonly registry?: PluginRegistry;\n}\n\n/**\n * Provider component that makes the PluginRegistry available to child components.\n *\n * @example\n * ```tsx\n * const registry = new PluginRegistry();\n * await registry.register(wmsPlugin);\n *\n * <PluginRegistryProvider registry={registry}>\n * <App />\n * </PluginRegistryProvider>\n * ```\n */\nexport function PluginRegistryProvider({\n children,\n registry,\n}: PluginRegistryProviderProps) {\n const [registryInstance] = useState<PluginRegistry>(\n () => registry ?? new PluginRegistry(),\n );\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n setIsReady(true);\n }, []);\n\n if (!isReady) {\n return null;\n }\n\n return (\n <PluginRegistryContext.Provider value={registryInstance}>\n {children}\n </PluginRegistryContext.Provider>\n );\n}\n","/**\n * usePluginMenu — React hook for accessing the merged menu tree.\n *\n * Returns the merged MenuItem[] from all registered plugins.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function Sidebar() {\n * const menu = usePluginMenu();\n * return <nav>{menu.map(m => <ModuleGroup key={m.name} {...m} />)}</nav>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { MenuItem } from \"../types/plugin\";\n\nasync function filterMenuByPermissions(\n items: MenuItem[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<MenuItem[]> {\n const filtered: MenuItem[] = [];\n\n for (const item of items) {\n if (item.hidden) {\n continue;\n }\n\n if (item.permissions && item.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(item.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n const children = item.children\n ? await filterMenuByPermissions(item.children, checker)\n : undefined;\n\n if (item.children && (children?.length ?? 0) === 0) {\n continue;\n }\n\n filtered.push({ ...item, children });\n }\n\n return filtered;\n}\n\nexport function usePluginMenu(): MenuItem[] {\n const registry = useContext(PluginRegistryContext);\n const [menu, setMenu] = useState<MenuItem[]>([]);\n\n if (!registry) {\n throw new Error(\"usePluginMenu must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getMenu();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setMenu(source.filter(item => !item.hidden));\n }\n return;\n }\n\n const filtered = await filterMenuByPermissions(source, checker);\n if (!cancelled) {\n setMenu(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return menu;\n}\n","/**\n * usePlugin — React hook for accessing a specific plugin by name.\n *\n * Returns the FrameworkMPlugin or undefined if not found.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WMSStatus() {\n * const wms = usePlugin(\"wms\");\n * if (!wms) return <p>WMS not installed</p>;\n * return <p>WMS v{wms.version}</p>;\n * }\n * ```\n */\n\nimport { useContext, useMemo } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { FrameworkMPlugin } from \"../types/plugin\";\n\nexport function usePlugin(name: string): FrameworkMPlugin | undefined {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"usePlugin must be used within PluginRegistryProvider\");\n }\n\n return useMemo(() => registry.getPlugin(name), [registry, name]);\n}\n","/**\n * useService — React hook for accessing a service from the ServiceContainer.\n *\n * Returns the service instance (lazily loaded), loading state, and error.\n * Must be used within a PluginRegistryProvider.\n *\n * @example\n * ```tsx\n * function WarehouseDashboard() {\n * const { service, isLoading, error } = useService<WarehouseService>(\"warehouseService\");\n * if (isLoading) return <Spinner />;\n * if (error) return <Error message={error.message} />;\n * return <div>{service.getWarehouses()}</div>;\n * }\n * ```\n */\n\nimport { useContext, useEffect, useMemo, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\n\ninterface UseServiceResult<T> {\n service: T | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport function useService<T = unknown>(name: string): UseServiceResult<T> {\n const registry = useContext(PluginRegistryContext);\n\n if (!registry) {\n throw new Error(\"useService must be used within PluginRegistryProvider\");\n }\n\n const [service, setService] = useState<T | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const servicePromise = useMemo(\n () => registry.getService<T>(name),\n [registry, name],\n );\n\n useEffect(() => {\n let cancelled = false;\n setIsLoading(true);\n setError(null);\n\n servicePromise\n .then(instance => {\n if (!cancelled) {\n setService(instance);\n setIsLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsLoading(false);\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [servicePromise]);\n\n return { service, isLoading, error };\n}\n","/**\n * useWidgets — React hook for accessing plugin-provided dashboard widgets.\n */\n\nimport { useContext, useEffect, useState } from \"react\";\nimport { PluginRegistryContext } from \"../context/PluginRegistryContext\";\nimport type { Widget } from \"../types/plugin\";\n\nasync function filterWidgetsByPermissions(\n widgets: Widget[],\n checker: (permissions: string[]) => boolean | Promise<boolean>,\n): Promise<Widget[]> {\n const filtered: Widget[] = [];\n\n for (const widget of widgets) {\n if (widget.permissions && widget.permissions.length > 0) {\n const allowed = await Promise.resolve(checker(widget.permissions));\n if (!allowed) {\n continue;\n }\n }\n\n filtered.push(widget);\n }\n\n return filtered;\n}\n\nexport function useWidgets(): Widget[] {\n const registry = useContext(PluginRegistryContext);\n const [widgets, setWidgets] = useState<Widget[]>([]);\n\n if (!registry) {\n throw new Error(\"useWidgets must be used within PluginRegistryProvider\");\n }\n\n useEffect(() => {\n let cancelled = false;\n\n const load = async () => {\n const source = registry.getWidgets();\n const checker = registry.getPermissionChecker();\n\n if (!checker) {\n if (!cancelled) {\n setWidgets(source);\n }\n return;\n }\n\n const filtered = await filterWidgetsByPermissions(source, checker);\n if (!cancelled) {\n setWidgets(filtered);\n }\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [registry]);\n\n return widgets;\n}\n","export interface RemoteModule {\n init: (args: { shareScope: string }) => void;\n}\n\nexport interface FederationOptions {\n /** Discovery API URL, defaults to /api/v1/frontend/remotes */\n apiUrl?: string;\n /** Share scope for federation, defaults to 'default' */\n shareScope?: string;\n}\n\nconst DEFAULT_OPTIONS: FederationOptions = {\n apiUrl: \"/api/v1/frontend/remotes\",\n shareScope: \"default\",\n};\n\n/**\n * Fetch remote plugin definitions from the backend discovery API.\n */\nexport const fetchRemotes = async (options?: FederationOptions): Promise<Record<string, string>> => {\n const apiUrl = options?.apiUrl ?? DEFAULT_OPTIONS.apiUrl!;\n try {\n const response = await fetch(apiUrl);\n if (!response.ok) {\n throw new Error(`Failed to fetch remotes: ${response.status}`);\n }\n return await response.json();\n } catch (error: unknown) {\n console.error('Error fetching remotes:', error);\n throw error;\n }\n};\n\n/**\n * Dynamically load a remote script into the browser runtime.\n */\nexport const loadRemoteScript = (remoteUrl: string): void => {\n const script = document.createElement('script');\n script.src = remoteUrl;\n script.async = true;\n document.body.appendChild(script);\n};\n\n/**\n * Initialize a federated remote module on the global window scope.\n */\nexport const initializeRemote = async (scope: string, options?: FederationOptions): Promise<void> => {\n const shareScope = options?.shareScope ?? DEFAULT_OPTIONS.shareScope!;\n \n return new Promise((resolve, reject) => {\n interface WindowWithRemote {\n [key: string]: {\n init: (args: { shareScope: string }) => void;\n } | undefined;\n }\n \n const checkInterval = setInterval(() => {\n const w = window as unknown as WindowWithRemote;\n if (w[scope]) {\n clearInterval(checkInterval);\n try {\n w[scope]!.init({\n shareScope,\n });\n resolve();\n } catch (error: unknown) {\n console.error(`Failed to initialize remote module ${scope}:`, error);\n reject(error);\n }\n }\n }, 50);\n });\n};\n"],"names":["ServiceContainer","__publicField","name","factory","instance","SDK_VERSION","MODULE_ICONS","isDebugEnabled","globalFlag","processRef","envFlag","registryLogger","message","args","PluginRegistry","plugin","diagnostics","errors","d","error","previous","warnings","allMenus","routes","pluginName","widgets","checker","event","handler","severity","reports","report","peerName","current","required","clean","cMajor","cMinor","cPatch","rMajor","rMinor","rPatch","seenRoutePaths","route","existingRouteOwner","seenMenuNames","seenMenuRoutes","item","existingNameOwner","seenServiceNames","serviceName","existingServiceOwner","diagnostic","fullDiagnostic","items","moduleMap","moduleName","moduleGroup","categoryGroup","_a","c","a","b","payload","PluginRegistryContext","createContext","PluginRegistryProvider","children","registry","registryInstance","useState","isReady","setIsReady","useEffect","filterMenuByPermissions","filtered","usePluginMenu","useContext","menu","setMenu","cancelled","source","usePlugin","useMemo","useService","service","setService","isLoading","setIsLoading","setError","servicePromise","err","filterWidgetsByPermissions","widget","useWidgets","setWidgets","DEFAULT_OPTIONS","fetchRemotes","options","apiUrl","response","loadRemoteScript","remoteUrl","script","initializeRemote","scope","shareScope","resolve","reject","checkInterval","w"],"mappings":";;;;;AAgBO,MAAMA,EAAiB;AAAA,EAAvB;AACY,IAAAC,EAAA,uCAAgB,IAAA;AAChB,IAAAA,EAAA,uCAAgB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjC,SAAYC,GAAcC,GAAkC;AAC1D,SAAK,UAAU,IAAID,GAAMC,CAAyB,GAElD,KAAK,UAAU,OAAOD,CAAI;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAiBA,GAA0B;AAE/C,QAAI,KAAK,UAAU,IAAIA,CAAI;AACzB,aAAO,KAAK,UAAU,IAAIA,CAAI;AAGhC,UAAMC,IAAU,KAAK,UAAU,IAAID,CAAI;AACvC,QAAI,CAACC;AACH,YAAM,IAAI,MAAM,YAAYD,CAAI,qBAAqB;AAIvD,UAAME,IAAW,MAAM,QAAQ,QAAQD,GAAS;AAChD,gBAAK,UAAU,IAAID,GAAME,CAAQ,GAC1BA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,IAAIF,GAAuB;AACzB,WAAO,KAAK,UAAU,IAAIA,CAAI;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,SAAmB;AACjB,WAAO,MAAM,KAAK,KAAK,UAAU,MAAM;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,UAAU,MAAA,GACf,KAAK,UAAU,MAAA;AAAA,EACjB;AACF;ACvCO,MAAMG,IAAc,SAKrBC,IAAuC;AAAA,EAC3C,OAAO;AAAA,EACP,WAAW;AAAA,EACX,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACT;AAEA,SAASC,IAA0B;AACjC,QAAMC,IAAc,WACjB;AACH,MAAI,OAAOA,KAAe;AACxB,WAAOA;AAET,MAAI,OAAOA,KAAe;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+
export interface RemoteModule {
|
|
2
|
+
init: (args: {
|
|
3
|
+
shareScope: string;
|
|
4
|
+
}) => void;
|
|
5
|
+
}
|
|
6
|
+
export interface FederationOptions {
|
|
7
|
+
/** Discovery API URL, defaults to /api/v1/frontend/remotes */
|
|
8
|
+
apiUrl?: string;
|
|
9
|
+
/** Share scope for federation, defaults to 'default' */
|
|
10
|
+
shareScope?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fetch remote plugin definitions from the backend discovery API.
|
|
14
|
+
*/
|
|
15
|
+
export declare const fetchRemotes: (options?: FederationOptions) => Promise<Record<string, string>>;
|
|
16
|
+
/**
|
|
17
|
+
* Dynamically load a remote script into the browser runtime.
|
|
18
|
+
*/
|
|
19
|
+
export declare const loadRemoteScript: (remoteUrl: string) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize a federated remote module on the global window scope.
|
|
22
|
+
*/
|
|
23
|
+
export declare const initializeRemote: (scope: string, options?: FederationOptions) => Promise<void>;
|
|
24
|
+
//# sourceMappingURL=federation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"federation.d.ts","sourceRoot":"","sources":["../../src/loader/federation.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAOD;;GAEG;AACH,eAAO,MAAM,YAAY,GAAU,UAAU,iBAAiB,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAY9F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,MAAM,KAAG,IAKpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAU,OAAO,MAAM,EAAE,UAAU,iBAAiB,KAAG,OAAO,CAAC,IAAI,CA0B/F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@framework-m/plugin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Plugin infrastructure and runtime for Framework M multi-app composition",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"directory": "libs/framework-m-plugin-sdk"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@framework-m/desk": "^0.6.
|
|
35
|
+
"@framework-m/desk": "^0.6.2",
|
|
36
36
|
"react": "^19.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|