@coreframe/dashboard 0.3.18 → 0.4.0-next.1

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/README.md CHANGED
@@ -72,6 +72,9 @@ credentials, Worker bindings, environment secrets, and the raw request remain ou
72
72
  contract. Typed operation errors expose safe error codes, and a failed local initialization can be
73
73
  retried without restarting the host.
74
74
 
75
+ Each plugin’s `apiModule` must default-export its operation contract. Both the local host and
76
+ generated Worker target load that default export.
77
+
75
78
  The compact plugin API uses `api`, `query`, and `command` for the shared contract, then derives a
76
79
  browser client from that contract:
77
80
 
@@ -1,3 +1,3 @@
1
- import{getDashboardPluginBuild as e}from"./config.js";import{createRequire as t}from"node:module";import{readFile as n,readdir as r}from"node:fs/promises";import{isAbsolute as i,join as a,resolve as o}from"node:path";import{parseDocument as s}from"yaml";import{z as c}from"zod";const l=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u,u=c.object({title:c.string().trim().min(1,`title must not be empty`).optional(),description:c.string().trim().min(1,`description must not be empty`).optional()}).strict(),d=c.object({id:c.string(),path:c.string(),title:c.string(),description:c.string().optional(),routeModule:c.string(),environments:c.array(c.enum([`local`,`deployed`])).optional()}).strict(),f=c.string().trim().min(1,`module reference must not be empty`),p=c.object({path:c.string(),title:c.string(),description:c.string().optional(),environments:c.array(c.enum([`local`,`deployed`])).optional()}).strict(),m=c.object({document:f.optional(),plugins:c.array(c.object({id:c.string(),navigation:p,pageModule:f,api:c.unknown().optional()}).strict()).optional()}).strict();async function h(e={}){let t=a(o(e.dashboardDirectory??a(process.cwd(),`dashboard`)),`pages`),i;try{i=await r(t,{withFileTypes:!0})}catch(e){if(N(e)&&e.code===`ENOENT`)return[];throw new S(t,`could not read the pages directory`,e)}let s=i.filter(e=>e.isDirectory()&&!e.name.startsWith(`.`)).sort((e,t)=>M(e.name,t.name));return Promise.all(s.map(async({name:e})=>{let r=a(t,e);A(e,r,`page directory`);let i=a(r,`route.tsx`);try{await n(i)}catch(e){throw N(e)&&e.code===`ENOENT`?new S(i,`missing required React Router route.tsx`):new S(i,`could not read route.tsx`,e)}let o=await C(a(r,`page.yaml`));return{id:e,path:e,title:o?.title??j(e),...o?.description?{description:o.description}:{},routeModule:`pages/${e}/route.tsx`}}))}function g(e,t,n={}){let r=n.environment??`local`,i=new Set,a=[],o=O(e);for(let e of o.plugins??[]){if(A(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),i.has(e.id))throw new S(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);i.add(e.id);let t=T(e,`plugin`,r);t&&a.push(t)}let s=t.map(e=>({page:e,normalizedPage:w(e,`app`)})).sort((e,t)=>M(e.normalizedPage.path,t.normalizedPage.path));for(let{page:e,normalizedPage:t}of s)D(e,r)&&a.push(t);return E(a),a}function _(e,t){let n=O(e),r=new Set,i=[];for(let e of n.plugins??[]){if(A(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),r.has(e.id))throw new S(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);if(r.add(e.id),!e.api)continue;let n=k(e,`dashboard API`),a=t===`local`?n.localImplementationModule:n.deployedImplementationModule;a&&i.push({pluginId:e.id,apiModule:n.apiModule,implementationModule:a})}return i}function v(e){let t=[],n=[];for(let[r,i]of e.entries())t.push(`import { api as api${r} } from ${JSON.stringify(i.apiModule)}`,`import { createImplementation as createImplementation${r} } from ${JSON.stringify(i.implementationModule)}`),n.push(`{ api: api${r}, createImplementation: createImplementation${r} }`);return`${t.join(`
1
+ import{getDashboardPluginBuild as e}from"./config.js";import{createRequire as t}from"node:module";import{readFile as n,readdir as r}from"node:fs/promises";import{isAbsolute as i,join as a,resolve as o}from"node:path";import{parseDocument as s}from"yaml";import{z as c}from"zod";const l=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u,u=c.object({title:c.string().trim().min(1,`title must not be empty`).optional(),description:c.string().trim().min(1,`description must not be empty`).optional()}).strict(),d=c.object({id:c.string(),path:c.string(),title:c.string(),description:c.string().optional(),routeModule:c.string(),environments:c.array(c.enum([`local`,`deployed`])).optional()}).strict(),f=c.string().trim().min(1,`module reference must not be empty`),p=c.object({path:c.string(),title:c.string(),description:c.string().optional(),environments:c.array(c.enum([`local`,`deployed`])).optional()}).strict(),m=c.object({document:f.optional(),plugins:c.array(c.object({id:c.string(),navigation:p,pageModule:f,api:c.unknown().optional()}).strict()).optional()}).strict();async function h(e={}){let t=a(o(e.dashboardDirectory??a(process.cwd(),`dashboard`)),`pages`),i;try{i=await r(t,{withFileTypes:!0})}catch(e){if(N(e)&&e.code===`ENOENT`)return[];throw new S(t,`could not read the pages directory`,e)}let s=i.filter(e=>e.isDirectory()&&!e.name.startsWith(`.`)).sort((e,t)=>M(e.name,t.name));return Promise.all(s.map(async({name:e})=>{let r=a(t,e);A(e,r,`page directory`);let i=a(r,`route.tsx`);try{await n(i)}catch(e){throw N(e)&&e.code===`ENOENT`?new S(i,`missing required React Router route.tsx`):new S(i,`could not read route.tsx`,e)}let o=await C(a(r,`page.yaml`));return{id:e,path:e,title:o?.title??j(e),...o?.description?{description:o.description}:{},routeModule:`pages/${e}/route.tsx`}}))}function g(e,t,n={}){let r=n.environment??`local`,i=new Set,a=[],o=O(e);for(let e of o.plugins??[]){if(A(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),i.has(e.id))throw new S(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);i.add(e.id);let t=T(e,`plugin`,r);t&&a.push(t)}let s=t.map(e=>({page:e,normalizedPage:w(e,`app`)})).sort((e,t)=>M(e.normalizedPage.path,t.normalizedPage.path));for(let{page:e,normalizedPage:t}of s)D(e,r)&&a.push(t);return E(a),a}function _(e,t){let n=O(e),r=new Set,i=[];for(let e of n.plugins??[]){if(A(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),r.has(e.id))throw new S(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);if(r.add(e.id),!e.api)continue;let n=k(e,`dashboard API`),a=t===`local`?n.localImplementationModule:n.deployedImplementationModule;a&&i.push({pluginId:e.id,apiModule:n.apiModule,implementationModule:a})}return i}function v(e){let t=[],n=[];for(let[r,i]of e.entries())t.push(`import api${r} from ${JSON.stringify(i.apiModule)}`,`import { createImplementation as createImplementation${r} } from ${JSON.stringify(i.implementationModule)}`),n.push(`{ api: api${r}, createImplementation: createImplementation${r} }`);return`${t.join(`
2
2
  `)}\n\nexport const dashboardPlugins = [\n${n.map(e=>` ${e},`).join(`
3
3
  `)}\n]\n`}function y(e,t){let n=[e.length>0?{index:!0,file:t.indexRoute}:{index:!0,file:t.emptyRoute},...e.map(e=>({id:`dashboard-page-${e.id}`,path:e.path,file:e.routeModule})),...t.notFoundRoute?[{path:`*`,file:t.notFoundRoute}]:[]];return[{id:`dashboard-shell`,file:t.shellRoute,children:n}]}function b(e,t={}){let n=o(t.dashboardDirectory??a(process.cwd(),`dashboard`));return e.map(e=>({...e,routeModule:e.source===`app`?o(n,e.routeModule):x(e.routeModule,t)}))}function x(e,n={}){let r=o(n.dashboardDirectory??a(process.cwd(),`dashboard`)),s=t(a(o(n.projectRoot??a(r,`..`)),`package.json`));if(i(e)||e.startsWith(`.`))return o(r,e);try{return s.resolve(e)}catch(t){throw new S(e,`could not resolve dashboard module`,t)}}var S=class extends Error{file;constructor(e,t,n){super(`${e}: ${t}`,{cause:n}),this.name=`DashboardCompositionError`,this.file=e}};async function C(e){let t;try{t=await n(e,`utf8`)}catch(t){if(N(t)&&t.code===`ENOENT`)return;throw new S(e,`could not read page metadata`,t)}let r=s(t,{prettyErrors:!0,strict:!0,uniqueKeys:!0});if(r.errors.length>0)throw new S(e,r.errors[0]?.message??`invalid YAML`);let i=u.safeParse(r.toJS());if(!i.success)throw new S(e,c.prettifyError(i.error));return i.data}function w(e,t,n){let r=t===`plugin`?`dashboard.config.ts plugin "${n??`unknown`}" page "${e.id}"`:e.routeModule,i=d.safeParse(e);if(!i.success)throw new S(r,c.prettifyError(i.error));let a=i.data;A(a.id,r,`page id`),A(a.path,r,`page path`);let o=a.title.trim();if(!o)throw new S(r,`page title must not be empty`);if(!a.routeModule.trim())throw new S(r,`page routeModule must not be empty`);let s=a.description?.trim();if(a.description!==void 0&&!s)throw new S(r,`page description must not be empty`);return{id:a.id,path:a.path,title:o,...s?{description:s}:{},routeModule:a.routeModule,source:t,...n?{pluginId:n}:{}}}function T(e,t,n){let r=`dashboard.config.ts plugin "${e.id}"`,i=p.safeParse(e.navigation);if(!i.success)throw new S(r,c.prettifyError(i.error));let a=i.data;if(A(e.id,r,`plugin id`),A(a.path,r,`navigation path`),!a.title.trim())throw new S(r,`navigation title must not be empty`);if(a.description!==void 0&&!a.description.trim())throw new S(r,`navigation description must not be empty`);if(!e.pageModule.trim())throw new S(r,`pageModule must not be empty`);if(!(a.environments&&!a.environments.includes(n))){if(e.api){let t=k(e,`dashboard API`);if(n===`local`&&!t.localImplementationModule||n===`deployed`&&!t.deployedImplementationModule)return}return w({id:e.id,path:a.path,title:a.title,...a.description?{description:a.description}:{},routeModule:e.pageModule,...a.environments?{environments:a.environments}:{}},t,e.id)}}function E(e){let t=new Map,n=new Map;for(let r of e){let e=t.get(r.id);if(e)throw new S(r.routeModule,`duplicate page id "${r.id}" also contributed by ${e.routeModule}`);t.set(r.id,r);let i=n.get(r.path);if(i)throw new S(r.routeModule,`duplicate page path "${r.path}" also contributed by ${i.routeModule}`);n.set(r.path,r)}}function D(e,t){return e.environments?e.environments.includes(t):!0}function O(e){let t=m.safeParse(e);if(!t.success)throw new S(`dashboard.config.ts`,c.prettifyError(t.error));return e}function k(t,n){let r=e(t);if(!r)throw new S(`dashboard.config.ts plugin "${t.id}"`,`${n} is missing its package-owned build descriptor`);if(t.api&&t.api.id!==t.id)throw new S(`dashboard.config.ts plugin "${t.id}"`,`API id "${t.api.id}" does not match the plugin id`);for(let e of[`apiModule`,`localImplementationModule`]){let n=r[e];if(typeof n!=`string`||!n.trim())throw new S(`dashboard.config.ts plugin "${t.id}"`,`build descriptor field "${e}" must be a non-empty module reference`)}if(r.deployedImplementationModule!==void 0&&(typeof r.deployedImplementationModule!=`string`||!r.deployedImplementationModule.trim()))throw new S(`dashboard.config.ts plugin "${t.id}"`,`build descriptor field "deployedImplementationModule" must be a non-empty module reference`);return r}function A(e,t,n){if(!l.test(e))throw new S(t,`${n} "${e}" must contain only lowercase letters, numbers, and single hyphens`)}function j(e){let t=e.split(`-`).join(` `);return`${t.charAt(0).toUpperCase()}${t.slice(1)}`}function M(e,t){return e<t?-1:+(e>t)}function N(e){return e instanceof Error&&`code`in e}export{S as DashboardCompositionError,g as composeDashboardManifest,_ as composeDashboardPluginTarget,y as composeDashboardRoutes,h as discoverDashboardPages,v as renderDashboardPluginTargetModule,x as resolveDashboardModuleReference,b as resolveDashboardRouteModules};
@@ -29,7 +29,7 @@ interface DashboardPluginNavigation {
29
29
  * than a public list of target-specific module paths.
30
30
  */
31
31
  interface DashboardPluginBuild {
32
- /** Module exporting the plugin's operation contract as `api`. */
32
+ /** Module exporting the plugin's operation contract as its default export. */
33
33
  apiModule: string;
34
34
  /** Module exporting the local implementation factory as `createImplementation`. */
35
35
  localImplementationModule: string;
@@ -5,9 +5,6 @@ import { DashboardPayload } from "../../../types.js";
5
5
  declare const diagnosticsApi: DashboardPluginApi<"diagnostics", {
6
6
  readonly overview: DashboardQuery<undefined, DashboardPayload>;
7
7
  }, {}>;
8
- declare const api: DashboardPluginApi<"diagnostics", {
9
- readonly overview: DashboardQuery<undefined, DashboardPayload>;
10
- }, {}>;
11
8
  type DiagnosticsApi = typeof diagnosticsApi;
12
9
  //#endregion
13
- export { DiagnosticsApi, api, diagnosticsApi };
10
+ export { DiagnosticsApi, diagnosticsApi as default };
@@ -1 +1 @@
1
- import{api as e,query as t}from"../../../api/contract.js";import{z as n}from"zod";const r=e({id:`diagnostics`,queries:{overview:t({output:n.custom()})},commands:{}}),i=r;export{i as api,r as diagnosticsApi};
1
+ import{api as e,query as t}from"../../../api/contract.js";import{z as n}from"zod";const r=e({id:`diagnostics`,queries:{overview:t({output:n.custom()})},commands:{}});export{r as default};
@@ -1 +1 @@
1
- import{defineImplementation as e}from"../../../api/contract.js";import{diagnosticsApi as t}from"./contract.js";import{inspectWorkerEnvironment as n}from"@coreframe/deploy";import{runDiagnostics as r}from"@coreframe/diagnostics";function i({host:i}){return e(t,{queries:{async overview(){let[e,t]=await Promise.all([r({projectRoot:i.projectRoot,environment:`development`,env:process.env}),n({cwd:i.projectRoot})]);return{mode:`local`,diagnostics:e,workerEnvironment:t}}},commands:{}})}export{i as createImplementation};
1
+ import{defineImplementation as e}from"../../../api/contract.js";import t from"./contract.js";import{inspectWorkerEnvironment as n}from"@coreframe/deploy";import{runDiagnostics as r}from"@coreframe/diagnostics";function i({host:i}){return e(t,{queries:{async overview(){let[e,t]=await Promise.all([r({projectRoot:i.projectRoot,environment:`development`,env:process.env}),n({cwd:i.projectRoot})]);return{mode:`local`,diagnostics:e,workerEnvironment:t}}},commands:{}})}export{i as createImplementation};
@@ -1 +1 @@
1
- import{defineImplementation as e}from"../../../api/contract.js";import{diagnosticsApi as t}from"./contract.js";function n(n){return e(t,{queries:{overview({host:e}){return{mode:`deployed`,environment:e.environment,release:e.release,configuration:[...e.configuration],links:[...e.links]}}},commands:{}})}export{n as createImplementation};
1
+ import{defineImplementation as e}from"../../../api/contract.js";import t from"./contract.js";function n(n){return e(t,{queries:{overview({host:e}){return{mode:`deployed`,environment:e.environment,release:e.release,configuration:[...e.configuration],links:[...e.links]}}},commands:{}})}export{n as createImplementation};
@@ -1 +1 @@
1
- import{definePlugin as e}from"../../config.js";import{diagnosticsApi as t}from"./api/contract.js";const n=e({id:`diagnostics`,navigation:{path:`diagnostics`,title:`Production readiness`,description:`Review launch readiness, deployment configuration, and project health.`},pageModule:`@coreframe/dashboard/plugins/diagnostics/web`,api:t},{apiModule:`@coreframe/dashboard/plugins/diagnostics/api/contract`,localImplementationModule:`@coreframe/dashboard/plugins/diagnostics/api/local`,deployedImplementationModule:`@coreframe/dashboard/plugins/diagnostics/api/worker`});function r(){return n}export{r as diagnostics,n as diagnosticsPlugin};
1
+ import{definePlugin as e}from"../../config.js";import t from"./api/contract.js";const n=e({id:`diagnostics`,navigation:{path:`diagnostics`,title:`Production readiness`,description:`Review launch readiness, deployment configuration, and project health.`},pageModule:`@coreframe/dashboard/plugins/diagnostics/web`,api:t},{apiModule:`@coreframe/dashboard/plugins/diagnostics/api/contract`,localImplementationModule:`@coreframe/dashboard/plugins/diagnostics/api/local`,deployedImplementationModule:`@coreframe/dashboard/plugins/diagnostics/api/worker`});function r(){return n}export{r as diagnostics,n as diagnosticsPlugin};
@@ -1 +1 @@
1
- import{createClient as e}from"../../../api/client.js";import{diagnosticsApi as t}from"../api/contract.js";import{queryOptions as n}from"@tanstack/react-query";const r={overview:()=>n({queryKey:[`dashboard`,`plugins`,`diagnostics`,`overview`],queryFn:()=>e(t).queries.overview()})};export{r as diagnosticsQueries};
1
+ import{createClient as e}from"../../../api/client.js";import t from"../api/contract.js";import{queryOptions as n}from"@tanstack/react-query";const r={overview:()=>n({queryKey:[`dashboard`,`plugins`,`diagnostics`,`overview`],queryFn:()=>e(t).queries.overview()})};export{r as diagnosticsQueries};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreframe/dashboard",
3
- "version": "0.3.18",
3
+ "version": "0.4.0-next.1",
4
4
  "description": "Reusable dashboard composition, shell, plugin, and authenticated runtime for Coreframe apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -87,9 +87,9 @@
87
87
  "rouzer": "^6.0.1",
88
88
  "yaml": "^2.9.0",
89
89
  "zod": "^4.4.3",
90
- "@coreframe/diagnostics": "0.2.3",
91
- "@coreframe/lib": "^0.2.15",
92
- "@coreframe/deploy": "0.1.14"
90
+ "@coreframe/lib": "^0.2.16-next.1",
91
+ "@coreframe/diagnostics": "0.2.4-next.0",
92
+ "@coreframe/deploy": "0.1.15-next.0"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@pandacss/dev": "2.0.0-beta.8",
@@ -103,7 +103,7 @@
103
103
  "typescript": "6.0.3",
104
104
  "vite": "^8.1.4",
105
105
  "vitest": "^4.1.10",
106
- "@coreframe/panda": "0.1.9"
106
+ "@coreframe/panda": "0.1.10-next.1"
107
107
  },
108
108
  "scripts": {
109
109
  "build": "pnpm --dir ../diagnostics build && pnpm build:server",