@coreframe/dashboard 0.3.15 → 0.3.17
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 +27 -2
- package/dist/package/api/client.d.ts +2 -2
- package/dist/package/api/client.js +1 -1
- package/dist/package/api/contract.d.ts +7 -7
- package/dist/package/api/contract.js +1 -1
- package/dist/package/app-worker.js +1 -1
- package/dist/package/config.d.ts +4 -4
- package/dist/package/config.js +1 -1
- package/dist/package/index.d.ts +2 -2
- package/dist/package/index.js +1 -1
- package/dist/package/plugin-api.d.ts +3 -3
- package/dist/package/plugin-api.js +1 -1
- package/dist/package/plugins/diagnostics/api/contract.js +1 -1
- package/dist/package/plugins/diagnostics/api/local.js +1 -1
- package/dist/package/plugins/diagnostics/api/worker.js +1 -1
- package/dist/package/plugins/diagnostics/index.js +1 -1
- package/dist/package/plugins/diagnostics/web/queries.js +1 -1
- package/dist/package/server.d.ts +4 -4
- package/dist/package/server.js +1 -1
- package/dist/package/worker.d.ts +2 -2
- package/dist/package/worker.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,10 +14,10 @@ assets are merged into `dist/client/__dashboard` and remain mounted at `/__dashb
|
|
|
14
14
|
`dashboard/dashboard.config.ts` explicitly registers trusted build-time plugins:
|
|
15
15
|
|
|
16
16
|
```ts
|
|
17
|
-
import {
|
|
17
|
+
import { defineConfig } from "@coreframe/dashboard/config"
|
|
18
18
|
import { diagnostics } from "@coreframe/dashboard/plugins/diagnostics"
|
|
19
19
|
|
|
20
|
-
export default
|
|
20
|
+
export default defineConfig({
|
|
21
21
|
plugins: [diagnostics()],
|
|
22
22
|
})
|
|
23
23
|
```
|
|
@@ -72,6 +72,31 @@ 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
|
+
The compact plugin API uses `api`, `query`, and `command` for the shared contract, then derives a
|
|
76
|
+
browser client from that contract:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { z } from "zod"
|
|
80
|
+
|
|
81
|
+
import { api, command, createClient, query } from "@coreframe/dashboard/api"
|
|
82
|
+
|
|
83
|
+
const contract = api({
|
|
84
|
+
id: "release-tools",
|
|
85
|
+
queries: {
|
|
86
|
+
status: query({ output: z.object({ releaseName: z.string().optional() }) }),
|
|
87
|
+
},
|
|
88
|
+
commands: {
|
|
89
|
+
refresh: command({
|
|
90
|
+
input: z.object({ force: z.boolean() }),
|
|
91
|
+
output: z.object({ accepted: z.boolean() }),
|
|
92
|
+
}),
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const client = createClient(contract)
|
|
97
|
+
const status = await client.queries.status()
|
|
98
|
+
```
|
|
99
|
+
|
|
75
100
|
## App API client
|
|
76
101
|
|
|
77
102
|
App-owned dashboard pages can call the hosting app's API with the signed-in app user's session. The
|
|
@@ -8,9 +8,9 @@ type DashboardPluginClient<Api extends DashboardPluginApi> = {
|
|
|
8
8
|
readonly commands: { [Key in keyof Api["commands"]]: DashboardClientOperation<Api["commands"][Key]> };
|
|
9
9
|
};
|
|
10
10
|
/** Creates the typed client for one plugin without a browser registry or hand-built API URL. */
|
|
11
|
-
declare function
|
|
11
|
+
declare function createClient<Api extends DashboardPluginApi>(api: Api, options?: {
|
|
12
12
|
baseURL?: string;
|
|
13
13
|
fetch?: typeof fetch;
|
|
14
14
|
}): DashboardPluginClient<Api>;
|
|
15
15
|
//#endregion
|
|
16
|
-
export { DashboardClientRequestOptions, DashboardPluginClient,
|
|
16
|
+
export { DashboardClientRequestOptions, DashboardPluginClient, createClient };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{throwDashboardResponseError as e}from"./error-mapping.js";import{getDefaultPluginApiURL as t}from"./paths.js";import{createRouzerRoutes as n}from"./rouzer.js";import{createClient as r}from"rouzer";function i(i,o={}){return a(i,r({baseURL:o.baseURL??t(i.id),headers:{"content-type":`application/json`},onJsonError:e,routes:n(i),fetch:o.fetch}))}function a(e,t){let n=t;return{queries:Object.fromEntries(Object.entries(e.queries).map(([e,t])=>[e,t.input===void 0?t=>n.queries[e](void 0,t):(t,r)=>n.queries[e](t,r)])),commands:Object.fromEntries(Object.entries(e.commands).map(([e,t])=>[e,t.input===void 0?t=>n.commands[e](void 0,t):(t,r)=>n.commands[e](t,r)]))}}export{i as
|
|
1
|
+
import{throwDashboardResponseError as e}from"./error-mapping.js";import{getDefaultPluginApiURL as t}from"./paths.js";import{createRouzerRoutes as n}from"./rouzer.js";import{createClient as r}from"rouzer";function i(i,o={}){return a(i,r({baseURL:o.baseURL??t(i.id),headers:{"content-type":`application/json`},onJsonError:e,routes:n(i),fetch:o.fetch}))}function a(e,t){let n=t;return{queries:Object.fromEntries(Object.entries(e.queries).map(([e,t])=>[e,t.input===void 0?t=>n.queries[e](void 0,t):(t,r)=>n.queries[e](t,r)])),commands:Object.fromEntries(Object.entries(e.commands).map(([e,t])=>[e,t.input===void 0?t=>n.commands[e](void 0,t):(t,r)=>n.commands[e](t,r)]))}}export{i as createClient};
|
|
@@ -23,18 +23,18 @@ interface DashboardOperationDefinitionOptions<Input, Output> {
|
|
|
23
23
|
output?: z.ZodType<Output>;
|
|
24
24
|
}
|
|
25
25
|
/** Defines a query descriptor without exposing Rouzer to plugin implementations. */
|
|
26
|
-
declare function
|
|
27
|
-
declare function
|
|
26
|
+
declare function query<Output = unknown>(options?: DashboardOperationDefinitionOptions<undefined, Output>): DashboardQuery<undefined, Output>;
|
|
27
|
+
declare function query<Input, Output>(options: DashboardOperationDefinitionOptions<Input, Output>): DashboardQuery<Input, Output>;
|
|
28
28
|
/** Defines a command descriptor without exposing Rouzer to plugin implementations. */
|
|
29
|
-
declare function
|
|
30
|
-
declare function
|
|
29
|
+
declare function command<Output = unknown>(options?: DashboardOperationDefinitionOptions<undefined, Output>): DashboardCommand<undefined, Output>;
|
|
30
|
+
declare function command<Input, Output>(options: DashboardOperationDefinitionOptions<Input, Output>): DashboardCommand<Input, Output>;
|
|
31
31
|
interface DashboardPluginApi<Id extends string = string, Queries extends DashboardQueryMap = DashboardQueryMap, Commands extends DashboardCommandMap = DashboardCommandMap> {
|
|
32
32
|
readonly id: Id;
|
|
33
33
|
readonly queries: Queries;
|
|
34
34
|
readonly commands: Commands;
|
|
35
35
|
}
|
|
36
36
|
/** Defines the operation contract shared by a plugin page and its runtime targets. */
|
|
37
|
-
declare function
|
|
37
|
+
declare function api<const Id extends string, const Queries extends DashboardQueryMap, const Commands extends DashboardCommandMap>(definition: {
|
|
38
38
|
id: Id;
|
|
39
39
|
queries: Queries;
|
|
40
40
|
commands: Commands;
|
|
@@ -64,11 +64,11 @@ type DashboardPluginImplementation<Api extends DashboardPluginApi, HostData exte
|
|
|
64
64
|
};
|
|
65
65
|
type DashboardPluginImplementationFactory<Api extends DashboardPluginApi, HostData extends object> = (context: DashboardInitializationContext<HostData>) => DashboardPluginImplementation<Api, HostData> | PromiseLike<DashboardPluginImplementation<Api, HostData>>;
|
|
66
66
|
/** Keeps implementation functions checked against the operation contract. */
|
|
67
|
-
declare function
|
|
67
|
+
declare function defineImplementation<Api extends DashboardPluginApi, HostData extends object>(api: Api, implementation: DashboardPluginImplementation<Api, HostData>): DashboardPluginImplementation<Api, HostData>;
|
|
68
68
|
/** The generated runtime registration for one plugin operation contract. */
|
|
69
69
|
interface DashboardPluginRegistration<HostData extends object, Api extends DashboardPluginApi = DashboardPluginApi> {
|
|
70
70
|
readonly api: Api;
|
|
71
71
|
readonly createImplementation: DashboardPluginImplementationFactory<Api, HostData>;
|
|
72
72
|
}
|
|
73
73
|
//#endregion
|
|
74
|
-
export { DashboardCommand, DashboardCommandMap, DashboardInitializationContext, DashboardOperationDefinitionOptions, DashboardOperationInput, DashboardOperationKind, DashboardOperationOutput, DashboardPluginApi, DashboardPluginImplementation, DashboardPluginImplementationFactory, DashboardPluginRegistration, DashboardQuery, DashboardQueryMap, DashboardRequestContext, DashboardSuperuser,
|
|
74
|
+
export { DashboardCommand, DashboardCommandMap, DashboardInitializationContext, DashboardOperationDefinitionOptions, DashboardOperationInput, DashboardOperationKind, DashboardOperationOutput, DashboardPluginApi, DashboardPluginImplementation, DashboardPluginImplementationFactory, DashboardPluginRegistration, DashboardQuery, DashboardQueryMap, DashboardRequestContext, DashboardSuperuser, api, command, defineImplementation, query };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{assertDashboardPluginApi as e,assertDashboardPluginImplementation as t}from"./validation.js";function n(e={}){return{kind:`query`,...e}}function r(e={}){return{kind:`command`,...e}}function i(t){return e(t),t}function a(e,n){return t(e,n),n}export{i as
|
|
1
|
+
import{assertDashboardPluginApi as e,assertDashboardPluginImplementation as t}from"./validation.js";function n(e={}){return{kind:`query`,...e}}function r(e={}){return{kind:`command`,...e}}function i(t){return e(t),t}function a(e,n){return t(e,n),n}export{i as api,r as command,a as defineImplementation,n as query};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createWorkerHandler as e}from"./worker.js";import{dashboardPlugins as t}from"virtual:coreframe-internal/dashboard/worker-plugins";const n=e({plugins:t});export{n as dashboardWorkerHandler};
|
package/dist/package/config.d.ts
CHANGED
|
@@ -62,14 +62,14 @@ interface DashboardPageManifestEntry {
|
|
|
62
62
|
pluginId?: string;
|
|
63
63
|
}
|
|
64
64
|
/** Defines trusted dashboard composition evaluated by Coreframe at development and build time. */
|
|
65
|
-
declare function
|
|
65
|
+
declare function defineConfig<const Config extends DashboardConfig>(config: Config): Config;
|
|
66
66
|
/**
|
|
67
67
|
* Defines a reusable dashboard feature. The optional build descriptor is package-owned and is not
|
|
68
68
|
* enumerable from application configuration, while Vite can still select one target at a time.
|
|
69
69
|
*/
|
|
70
|
-
declare function
|
|
71
|
-
declare function
|
|
70
|
+
declare function definePlugin<const Plugin extends DashboardPlugin, const Build extends DashboardPluginBuild>(plugin: Plugin, build: Build): Plugin;
|
|
71
|
+
declare function definePlugin<const Plugin extends DashboardPlugin>(plugin: Plugin): Plugin;
|
|
72
72
|
/** @internal Used by the dashboard build composer to read package-owned target metadata. */
|
|
73
73
|
declare function getDashboardPluginBuild(plugin: DashboardPlugin): DashboardPluginBuild | undefined;
|
|
74
74
|
//#endregion
|
|
75
|
-
export { DashboardConfig, DashboardEnvironment, DashboardPageContribution, DashboardPageManifestEntry, DashboardPlugin, DashboardPluginBuild, DashboardPluginNavigation,
|
|
75
|
+
export { DashboardConfig, DashboardEnvironment, DashboardPageContribution, DashboardPageManifestEntry, DashboardPlugin, DashboardPluginBuild, DashboardPluginNavigation, defineConfig, definePlugin, getDashboardPluginBuild };
|
package/dist/package/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=Symbol.for(`coreframe.dashboard.plugin-build`);function t(e){return e}function n(t,n){return n&&Object.defineProperty(t,e,{configurable:!1,enumerable:!1,value:Object.freeze({...n}),writable:!1}),t}function r(t){return t[e]}export{t as
|
|
1
|
+
const e=Symbol.for(`coreframe.dashboard.plugin-build`);function t(e){return e}function n(t,n){return n&&Object.defineProperty(t,e,{configurable:!1,enumerable:!1,value:Object.freeze({...n}),writable:!1}),t}function r(t){return t[e]}export{t as defineConfig,n as definePlugin,r as getDashboardPluginBuild};
|
package/dist/package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DashboardPayload, DashboardReleaseIdentity, DeployedDashboardPayload } from "./types.js";
|
|
2
|
-
import { DashboardRequestHandler, DashboardServerOptions,
|
|
3
|
-
export { type DashboardPayload, type DashboardReleaseIdentity, type DashboardRequestHandler, type DashboardServerOptions, type DeployedDashboardPayload,
|
|
2
|
+
import { DashboardRequestHandler, DashboardServerOptions, createNodeHandler, createNodeServer } from "./server.js";
|
|
3
|
+
export { type DashboardPayload, type DashboardReleaseIdentity, type DashboardRequestHandler, type DashboardServerOptions, type DeployedDashboardPayload, createNodeHandler, createNodeServer };
|
package/dist/package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createNodeHandler as e,createNodeServer as t}from"./server.js";export{e as createNodeHandler,t as createNodeServer};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DashboardCommand, DashboardCommandMap, DashboardInitializationContext, DashboardOperationDefinitionOptions, DashboardOperationInput, DashboardOperationKind, DashboardOperationOutput, DashboardPluginApi, DashboardPluginImplementation, DashboardPluginImplementationFactory, DashboardPluginRegistration, DashboardQuery, DashboardQueryMap, DashboardRequestContext, DashboardSuperuser,
|
|
2
|
-
import { DashboardClientRequestOptions, DashboardPluginClient,
|
|
1
|
+
import { DashboardCommand, DashboardCommandMap, DashboardInitializationContext, DashboardOperationDefinitionOptions, DashboardOperationInput, DashboardOperationKind, DashboardOperationOutput, DashboardPluginApi, DashboardPluginImplementation, DashboardPluginImplementationFactory, DashboardPluginRegistration, DashboardQuery, DashboardQueryMap, DashboardRequestContext, DashboardSuperuser, api, command, defineImplementation, query } from "./api/contract.js";
|
|
2
|
+
import { DashboardClientRequestOptions, DashboardPluginClient, createClient } from "./api/client.js";
|
|
3
3
|
import { DashboardOperationError, DashboardOperationErrorBody, DashboardOperationErrorCode, dashboardOperationError } from "./api/errors.js";
|
|
4
|
-
export { DashboardClientRequestOptions, DashboardCommand, DashboardCommandMap, DashboardInitializationContext, DashboardOperationDefinitionOptions, DashboardOperationError, type DashboardOperationErrorBody, type DashboardOperationErrorCode, DashboardOperationInput, DashboardOperationKind, DashboardOperationOutput, DashboardPluginApi, DashboardPluginClient, DashboardPluginImplementation, DashboardPluginImplementationFactory, DashboardPluginRegistration, DashboardQuery, DashboardQueryMap, DashboardRequestContext, DashboardSuperuser,
|
|
4
|
+
export { DashboardClientRequestOptions, DashboardCommand, DashboardCommandMap, DashboardInitializationContext, DashboardOperationDefinitionOptions, DashboardOperationError, type DashboardOperationErrorBody, type DashboardOperationErrorCode, DashboardOperationInput, DashboardOperationKind, DashboardOperationOutput, DashboardPluginApi, DashboardPluginClient, DashboardPluginImplementation, DashboardPluginImplementationFactory, DashboardPluginRegistration, DashboardQuery, DashboardQueryMap, DashboardRequestContext, DashboardSuperuser, api, command, createClient, dashboardOperationError, defineImplementation, query };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DashboardOperationError as e,dashboardOperationError as t}from"./api/errors.js";import{
|
|
1
|
+
import{DashboardOperationError as e,dashboardOperationError as t}from"./api/errors.js";import{api as n,command as r,defineImplementation as i,query as a}from"./api/contract.js";import{createClient as o}from"./api/client.js";export{e as DashboardOperationError,n as api,r as command,o as createClient,t as dashboardOperationError,i as defineImplementation,a as query};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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 +1 @@
|
|
|
1
|
-
import{
|
|
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 +1 @@
|
|
|
1
|
-
import{
|
|
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 +1 @@
|
|
|
1
|
-
import{
|
|
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 +1 @@
|
|
|
1
|
-
import{
|
|
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};
|
package/dist/package/server.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ type DashboardRequestHandler = {
|
|
|
14
14
|
dispose(): Promise<void>;
|
|
15
15
|
handle(request: IncomingMessage, response: ServerResponse): Promise<void>;
|
|
16
16
|
};
|
|
17
|
-
declare function
|
|
18
|
-
/** Creates the localhost-only Node
|
|
19
|
-
declare function
|
|
17
|
+
declare function createNodeServer(options: DashboardServerOptions): Server;
|
|
18
|
+
/** Creates the localhost-only Node handler for the built client and composed plugin operations. */
|
|
19
|
+
declare function createNodeHandler(options: DashboardServerOptions): DashboardRequestHandler;
|
|
20
20
|
//#endregion
|
|
21
|
-
export { DashboardLocalHostData, DashboardRequestHandler, DashboardServerOptions,
|
|
21
|
+
export { DashboardLocalHostData, DashboardRequestHandler, DashboardServerOptions, createNodeHandler, createNodeServer };
|
package/dist/package/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDashboardPluginDispatcher as e}from"./api/dispatcher.js";import{DashboardRequestError as t}from"./request-error.js";import{assertDashboardApiRequestOrigin as n,assertLocalDashboardHost as r,getDashboardRequestId as i}from"./host-policy.js";import{handleFetchRequest as a}from"./node-fetch-adapter.js";import{readFile as o,stat as s}from"node:fs/promises";import{extname as c,isAbsolute as l,join as u,relative as d,resolve as f,sep as p}from"node:path";import{createServer as m}from"node:http";function h(e){let t=g(e),n=m(async(e,n)=>{await t.handle(e,n)});return n.on(`close`,()=>{t.dispose()}),n}function g(o){let s=e(o.plugins,{host:Object.freeze({projectRoot:o.projectRoot}),getRequestId:i});return{dispose:async()=>void 0,async handle(e,i){try{r(e);let t=e.headers[`x-forwarded-proto`]===`https`?`https`:`http`,c=new URL(e.url??`/`,`${t}://${e.headers.host??`127.0.0.1`}`);if(c.pathname.startsWith(`/__dashboard/api/plugins/`)){n(e,c),await a(e,i,s);return}if(c.pathname===`/__dashboard/api`||c.pathname.startsWith(`/__dashboard/api/`)){v(i,404,{error:`Not found`});return}if(!o.clientDist){v(i,404,{error:`Not found`});return}if(c.pathname===`/__dashboard`){i.writeHead(302,{location:`/__dashboard/`}),i.end();return}if(c.pathname.startsWith(`/__dashboard/`)){if(e.method!==`GET`&&e.method!==`HEAD`){v(i,405,{error:`Method not allowed`});return}await _(e,i,c.pathname.slice(12)||`/`,o.clientDist);return}v(i,404,{error:`Not found`})}catch(e){v(i,e instanceof t?e.status:500,{error:e instanceof Error?e.message:String(e)})}}}}async function _(e,t,n,r){let i=y(r,n);if(!i){v(t,404,{error:`Client asset not found`});return}let a=await b(i),o=!a&&c(n)===``,s=u(r,`index.html`),l=o?await b(s):void 0,d=a?i:s,f=a??l;if(!f){v(t,404,{error:`Client asset not found`});return}t.writeHead(200,{"content-type":x(d),"cache-control":d.endsWith(`index.html`)?`no-store`:`public, max-age=31536000, immutable`}),t.end(e.method===`HEAD`?void 0:f)}function v(e,t,n){e.writeHead(t,{"content-type":`application/json; charset=utf-8`,"cache-control":`no-store`}),e.end(JSON.stringify(n))}function y(e,n){let r;try{r=decodeURIComponent(n)}catch{throw new t(`Dashboard request path is invalid.`,400)}if(r.includes(`\0`))throw new t(`Dashboard request path is invalid.`,400);let i=f(e,r===`/`?`index.html`:r.slice(1)),a=d(e,i);if(!(a===``||a===`..`||a.startsWith(`..${p}`)||l(a)))return i}async function b(e){try{return(await s(e)).isFile()?await o(e):void 0}catch(e){if(S(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return;throw e}}function x(e){switch(c(e)){case`.css`:return`text/css; charset=utf-8`;case`.html`:return`text/html; charset=utf-8`;case`.ico`:return`image/x-icon`;case`.jpeg`:case`.jpg`:return`image/jpeg`;case`.js`:case`.mjs`:return`text/javascript; charset=utf-8`;case`.json`:case`.map`:return`application/json; charset=utf-8`;case`.png`:return`image/png`;case`.svg`:return`image/svg+xml`;case`.ttf`:return`font/ttf`;case`.wasm`:return`application/wasm`;case`.webp`:return`image/webp`;case`.woff`:return`font/woff`;case`.woff2`:return`font/woff2`;default:return`application/octet-stream`}}function S(e){return e instanceof Error&&`code`in e}export{g as
|
|
1
|
+
import{createDashboardPluginDispatcher as e}from"./api/dispatcher.js";import{DashboardRequestError as t}from"./request-error.js";import{assertDashboardApiRequestOrigin as n,assertLocalDashboardHost as r,getDashboardRequestId as i}from"./host-policy.js";import{handleFetchRequest as a}from"./node-fetch-adapter.js";import{readFile as o,stat as s}from"node:fs/promises";import{extname as c,isAbsolute as l,join as u,relative as d,resolve as f,sep as p}from"node:path";import{createServer as m}from"node:http";function h(e){let t=g(e),n=m(async(e,n)=>{await t.handle(e,n)});return n.on(`close`,()=>{t.dispose()}),n}function g(o){let s=e(o.plugins,{host:Object.freeze({projectRoot:o.projectRoot}),getRequestId:i});return{dispose:async()=>void 0,async handle(e,i){try{r(e);let t=e.headers[`x-forwarded-proto`]===`https`?`https`:`http`,c=new URL(e.url??`/`,`${t}://${e.headers.host??`127.0.0.1`}`);if(c.pathname.startsWith(`/__dashboard/api/plugins/`)){n(e,c),await a(e,i,s);return}if(c.pathname===`/__dashboard/api`||c.pathname.startsWith(`/__dashboard/api/`)){v(i,404,{error:`Not found`});return}if(!o.clientDist){v(i,404,{error:`Not found`});return}if(c.pathname===`/__dashboard`){i.writeHead(302,{location:`/__dashboard/`}),i.end();return}if(c.pathname.startsWith(`/__dashboard/`)){if(e.method!==`GET`&&e.method!==`HEAD`){v(i,405,{error:`Method not allowed`});return}await _(e,i,c.pathname.slice(12)||`/`,o.clientDist);return}v(i,404,{error:`Not found`})}catch(e){v(i,e instanceof t?e.status:500,{error:e instanceof Error?e.message:String(e)})}}}}async function _(e,t,n,r){let i=y(r,n);if(!i){v(t,404,{error:`Client asset not found`});return}let a=await b(i),o=!a&&c(n)===``,s=u(r,`index.html`),l=o?await b(s):void 0,d=a?i:s,f=a??l;if(!f){v(t,404,{error:`Client asset not found`});return}t.writeHead(200,{"content-type":x(d),"cache-control":d.endsWith(`index.html`)?`no-store`:`public, max-age=31536000, immutable`}),t.end(e.method===`HEAD`?void 0:f)}function v(e,t,n){e.writeHead(t,{"content-type":`application/json; charset=utf-8`,"cache-control":`no-store`}),e.end(JSON.stringify(n))}function y(e,n){let r;try{r=decodeURIComponent(n)}catch{throw new t(`Dashboard request path is invalid.`,400)}if(r.includes(`\0`))throw new t(`Dashboard request path is invalid.`,400);let i=f(e,r===`/`?`index.html`:r.slice(1)),a=d(e,i);if(!(a===``||a===`..`||a.startsWith(`..${p}`)||l(a)))return i}async function b(e){try{return(await s(e)).isFile()?await o(e):void 0}catch(e){if(S(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return;throw e}}function x(e){switch(c(e)){case`.css`:return`text/css; charset=utf-8`;case`.html`:return`text/html; charset=utf-8`;case`.ico`:return`image/x-icon`;case`.jpeg`:case`.jpg`:return`image/jpeg`;case`.js`:case`.mjs`:return`text/javascript; charset=utf-8`;case`.json`:case`.map`:return`application/json; charset=utf-8`;case`.png`:return`image/png`;case`.svg`:return`image/svg+xml`;case`.ttf`:return`font/ttf`;case`.wasm`:return`application/wasm`;case`.webp`:return`image/webp`;case`.woff`:return`font/woff`;case`.woff2`:return`font/woff2`;default:return`application/octet-stream`}}function S(e){return e instanceof Error&&`code`in e}export{g as createNodeHandler,h as createNodeServer};
|
package/dist/package/worker.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ type DashboardWorkerHostData = {
|
|
|
38
38
|
configuration: readonly DeployedConfigurationEntry[];
|
|
39
39
|
links: readonly DashboardLink[];
|
|
40
40
|
};
|
|
41
|
-
declare function
|
|
41
|
+
declare function createWorkerHandler(options: DashboardWorkerOptions): DashboardWorkerHandler;
|
|
42
42
|
declare function handleDashboardRequest<Env extends DashboardWorkerEnv>(request: Request, env: Env, options: DashboardWorkerOptions): Promise<Response> | null;
|
|
43
43
|
//#endregion
|
|
44
|
-
export { DashboardBuildMetadata, DashboardWorkerEnv, DashboardWorkerHandler, DashboardWorkerHostData, DashboardWorkerOptions,
|
|
44
|
+
export { DashboardBuildMetadata, DashboardWorkerEnv, DashboardWorkerHandler, DashboardWorkerHostData, DashboardWorkerOptions, createWorkerHandler, handleDashboardRequest };
|
package/dist/package/worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDashboardPluginDispatcher as e}from"./api/dispatcher.js";import{getDashboardRequestId as t,isSameOriginDashboardMutation as n}from"./host-policy.js";const r=`/__dashboard`,i=`${r}/api`,a=new WeakMap;function o(n){let r=e(n.plugins,{getRequestId:t});return(e,t)=>{let n=new URL(e.url);return!d(n.pathname)||!t.DEPLOY_ENV?null:c(e,t,n,t.DEPLOY_ENV,r)}}function s(e,t,n){if(!d(new URL(e.url).pathname)||!t.DEPLOY_ENV)return null;let r=n.plugins,i=a.get(r);return i||(i=o(n),a.set(r,i)),i(e,t)}async function c(e,t,a,o,s){if(!t.DASHBOARD_PASSWORD)return new Response(`Dashboard unavailable`,{headers:{"cache-control":`no-store`},status:503});let c=m(e.headers.get(`authorization`));if(!c||!await h(c,t.DASHBOARD_PASSWORD))return new Response(`Authentication required`,{headers:{"cache-control":`no-store`,"www-authenticate":`Basic realm="Coreframe dashboard", charset="UTF-8"`},status:401});if(a.pathname.startsWith(`${i}/plugins/`))return n(e.method,e.headers.get(`origin`),a.origin)?s(e,l(e,t,o)):p({error:{code:`invalid_input`}},403);if(a.pathname===i||a.pathname.startsWith(`${i}/`))return p({error:`Not found`},404);if(a.pathname===r)return a.pathname=`${r}/`,Response.redirect(a,302);if(e.method!==`GET`&&e.method!==`HEAD`)return new Response(`Method not allowed`,{headers:{"cache-control":`no-store`},status:405});if(!t.ASSETS)return new Response(`Dashboard unavailable`,{headers:{"cache-control":`no-store`},status:503});(a.pathname===`${r}/`||!a.pathname.slice(13).includes(`.`))&&(a.pathname=`${r}/index.html`);let u=await t.ASSETS.fetch(new Request(a,e)),d=new Headers(u.headers);return d.set(`cache-control`,a.pathname.endsWith(`/index.html`)?`no-store`:`public, max-age=31536000, immutable`),new Response(e.method===`HEAD`?null:u.body,{headers:d,status:u.status,statusText:u.statusText})}function l(e,t,n){let r=u(),i=t,a=r.configuration.filter(e=>e.requiredIn.includes(n)).map(e=>({description:e.description,kind:e.kind,name:e.name,status:f(i[e.name])?`configured`:`missing`})),o=[],s=r.deployUrls[n];return s?o.push({href:s,id:`application`,label:`Application`}):o.push({href:new URL(`/`,e.url).href,id:`application`,label:`Application`}),{environment:n,release:{applicationName:r.applicationName,applicationVersion:r.applicationVersion,cloudflareVersionId:t.CF_VERSION_METADATA?.id,cloudflareVersionTag:t.CF_VERSION_METADATA?.tag,cloudflareVersionTimestamp:t.CF_VERSION_METADATA?.timestamp,commit:r.commit,coreframeVersion:r.coreframeVersion,releaseName:t.POSTHOG_RELEASE},configuration:a,links:o}}function u(){return typeof __COREFRAME_DASHBOARD_BUILD__<`u`?__COREFRAME_DASHBOARD_BUILD__:{applicationName:`Coreframe application`,configuration:[],deployUrls:{}}}function d(e){return e===r||e.startsWith(`${r}/`)}function f(e){return typeof e==`string`?e.trim().length>0:e!=null}function p(e,t=200){return Response.json(e,{headers:{"cache-control":`no-store`},status:t})}function m(e){if(e?.startsWith(`Basic `))try{let t=Uint8Array.from(atob(e.slice(6)),e=>e.charCodeAt(0)),n=new TextDecoder().decode(t),r=n.indexOf(`:`);return r===-1||n.slice(0,r)!==`coreframe`?void 0:n.slice(r+1)}catch{return}}async function h(e,t){let n=new TextEncoder,[r,i]=await Promise.all([crypto.subtle.digest(`SHA-256`,n.encode(e)),crypto.subtle.digest(`SHA-256`,n.encode(t))]),a=new Uint8Array(r),o=new Uint8Array(i),s=0;for(let e=0;e<a.length;e+=1)s|=a[e]^o[e];return s===0}export{o as
|
|
1
|
+
import{createDashboardPluginDispatcher as e}from"./api/dispatcher.js";import{getDashboardRequestId as t,isSameOriginDashboardMutation as n}from"./host-policy.js";const r=`/__dashboard`,i=`${r}/api`,a=new WeakMap;function o(n){let r=e(n.plugins,{getRequestId:t});return(e,t)=>{let n=new URL(e.url);return!d(n.pathname)||!t.DEPLOY_ENV?null:c(e,t,n,t.DEPLOY_ENV,r)}}function s(e,t,n){if(!d(new URL(e.url).pathname)||!t.DEPLOY_ENV)return null;let r=n.plugins,i=a.get(r);return i||(i=o(n),a.set(r,i)),i(e,t)}async function c(e,t,a,o,s){if(!t.DASHBOARD_PASSWORD)return new Response(`Dashboard unavailable`,{headers:{"cache-control":`no-store`},status:503});let c=m(e.headers.get(`authorization`));if(!c||!await h(c,t.DASHBOARD_PASSWORD))return new Response(`Authentication required`,{headers:{"cache-control":`no-store`,"www-authenticate":`Basic realm="Coreframe dashboard", charset="UTF-8"`},status:401});if(a.pathname.startsWith(`${i}/plugins/`))return n(e.method,e.headers.get(`origin`),a.origin)?s(e,l(e,t,o)):p({error:{code:`invalid_input`}},403);if(a.pathname===i||a.pathname.startsWith(`${i}/`))return p({error:`Not found`},404);if(a.pathname===r)return a.pathname=`${r}/`,Response.redirect(a,302);if(e.method!==`GET`&&e.method!==`HEAD`)return new Response(`Method not allowed`,{headers:{"cache-control":`no-store`},status:405});if(!t.ASSETS)return new Response(`Dashboard unavailable`,{headers:{"cache-control":`no-store`},status:503});(a.pathname===`${r}/`||!a.pathname.slice(13).includes(`.`))&&(a.pathname=`${r}/index.html`);let u=await t.ASSETS.fetch(new Request(a,e)),d=new Headers(u.headers);return d.set(`cache-control`,a.pathname.endsWith(`/index.html`)?`no-store`:`public, max-age=31536000, immutable`),new Response(e.method===`HEAD`?null:u.body,{headers:d,status:u.status,statusText:u.statusText})}function l(e,t,n){let r=u(),i=t,a=r.configuration.filter(e=>e.requiredIn.includes(n)).map(e=>({description:e.description,kind:e.kind,name:e.name,status:f(i[e.name])?`configured`:`missing`})),o=[],s=r.deployUrls[n];return s?o.push({href:s,id:`application`,label:`Application`}):o.push({href:new URL(`/`,e.url).href,id:`application`,label:`Application`}),{environment:n,release:{applicationName:r.applicationName,applicationVersion:r.applicationVersion,cloudflareVersionId:t.CF_VERSION_METADATA?.id,cloudflareVersionTag:t.CF_VERSION_METADATA?.tag,cloudflareVersionTimestamp:t.CF_VERSION_METADATA?.timestamp,commit:r.commit,coreframeVersion:r.coreframeVersion,releaseName:t.POSTHOG_RELEASE},configuration:a,links:o}}function u(){return typeof __COREFRAME_DASHBOARD_BUILD__<`u`?__COREFRAME_DASHBOARD_BUILD__:{applicationName:`Coreframe application`,configuration:[],deployUrls:{}}}function d(e){return e===r||e.startsWith(`${r}/`)}function f(e){return typeof e==`string`?e.trim().length>0:e!=null}function p(e,t=200){return Response.json(e,{headers:{"cache-control":`no-store`},status:t})}function m(e){if(e?.startsWith(`Basic `))try{let t=Uint8Array.from(atob(e.slice(6)),e=>e.charCodeAt(0)),n=new TextDecoder().decode(t),r=n.indexOf(`:`);return r===-1||n.slice(0,r)!==`coreframe`?void 0:n.slice(r+1)}catch{return}}async function h(e,t){let n=new TextEncoder,[r,i]=await Promise.all([crypto.subtle.digest(`SHA-256`,n.encode(e)),crypto.subtle.digest(`SHA-256`,n.encode(t))]),a=new Uint8Array(r),o=new Uint8Array(i),s=0;for(let e=0;e<a.length;e+=1)s|=a[e]^o[e];return s===0}export{o as createWorkerHandler,s as handleDashboardRequest};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/dashboard",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"description": "Reusable dashboard composition, shell, plugin, and authenticated runtime for Coreframe apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"rouzer": "^6.0.1",
|
|
88
88
|
"yaml": "^2.9.0",
|
|
89
89
|
"zod": "^4.4.3",
|
|
90
|
-
"@coreframe/deploy": "0.1.12",
|
|
91
90
|
"@coreframe/diagnostics": "0.2.3",
|
|
91
|
+
"@coreframe/deploy": "0.1.13",
|
|
92
92
|
"@coreframe/lib": "^0.2.15"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
@@ -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.
|
|
106
|
+
"@coreframe/panda": "0.1.9"
|
|
107
107
|
},
|
|
108
108
|
"scripts": {
|
|
109
109
|
"build": "pnpm --dir ../diagnostics build && pnpm build:server",
|