@coreframe/dashboard 0.4.0-next.4 → 0.4.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.
Files changed (58) hide show
  1. package/README.md +230 -25
  2. package/dist/package/access.d.ts +7 -0
  3. package/dist/package/access.js +30 -0
  4. package/dist/package/app/client-route.d.ts +7 -0
  5. package/dist/package/app/client-route.js +1 -0
  6. package/dist/package/app/entry.browser.d.ts +1 -0
  7. package/dist/package/app/entry.browser.js +1 -0
  8. package/dist/package/app/not-found.js +1 -1
  9. package/dist/package/app/providers.js +1 -0
  10. package/dist/package/app/root.js +1 -1
  11. package/dist/package/app/sculpted-runtime.js +1 -0
  12. package/dist/package/app/shell.js +1 -1
  13. package/dist/package/app-client.d.ts +5 -4
  14. package/dist/package/app-client.js +1 -1
  15. package/dist/package/build.js +2 -2
  16. package/dist/package/config.d.ts +15 -3
  17. package/dist/package/index.d.ts +3 -3
  18. package/dist/package/node-fetch-adapter.js +1 -1
  19. package/dist/package/server.d.ts +8 -2
  20. package/dist/package/server.js +1 -1
  21. package/dist/package/types.d.ts +1 -17
  22. package/dist/package/web/styled-system/css/conditions.js +1 -1
  23. package/dist/package/web/styled-system/helpers.js +1 -1
  24. package/dist/package/web/styled-system/recipes/dashboard-button.js +1 -1
  25. package/dist/package/web/styled-system/recipes/dashboard-status.js +1 -1
  26. package/dist/package/web/styled-system/recipes/runtime.js +1 -1
  27. package/dist/package/web/ui/index.d.ts +1 -1
  28. package/dist/package/web/ui/styles.js +1 -1
  29. package/dist/package/web-shell/index.d.ts +2 -1
  30. package/dist/package/web-shell/index.js +1 -1
  31. package/dist/package/web-shell/menu.d.ts +19 -0
  32. package/dist/package/web-shell/menu.js +1 -0
  33. package/dist/package/web-shell/shell.d.ts +7 -6
  34. package/dist/package/web-shell/shell.js +6 -1
  35. package/dist/package/worker.d.ts +3 -3
  36. package/dist/package/worker.js +1 -1
  37. package/package.json +16 -33
  38. package/dist/package/plugins/diagnostics/api/contract.d.ts +0 -10
  39. package/dist/package/plugins/diagnostics/api/contract.js +0 -1
  40. package/dist/package/plugins/diagnostics/api/local.d.ts +0 -10
  41. package/dist/package/plugins/diagnostics/api/local.js +0 -1
  42. package/dist/package/plugins/diagnostics/api/worker.d.ts +0 -8
  43. package/dist/package/plugins/diagnostics/api/worker.js +0 -1
  44. package/dist/package/plugins/diagnostics/index.d.ts +0 -30
  45. package/dist/package/plugins/diagnostics/index.js +0 -1
  46. package/dist/package/plugins/diagnostics/web/queries.js +0 -1
  47. package/dist/package/plugins/diagnostics/web.d.ts +0 -4
  48. package/dist/package/plugins/diagnostics/web.js +0 -1
  49. package/dist/package/shell.css +0 -390
  50. package/dist/package/styled-css.js +0 -1
  51. package/dist/package/web/dashboard/dashboard-page.js +0 -1
  52. package/dist/package/web/dashboard/dashboard-section.js +0 -1
  53. package/dist/package/web/dashboard/dashboard.style.js +0 -1
  54. package/dist/package/web/dashboard/deployed-dashboard-page.js +0 -1
  55. package/dist/package/web/dashboard/findings.js +0 -1
  56. package/dist/package/web/dashboard/worker-environment.js +0 -1
  57. package/dist/package/web/root.style.js +0 -1
  58. package/dist/package/web/styled-system/css/css.js +0 -1
package/README.md CHANGED
@@ -15,48 +15,209 @@ assets are merged into `dist/client/__dashboard` and remain mounted at `/__dashb
15
15
 
16
16
  ```ts
17
17
  import { defineConfig } from "@coreframe/dashboard/config"
18
- import { diagnostics } from "@coreframe/dashboard/plugins/diagnostics"
19
18
 
20
19
  export default defineConfig({
21
- plugins: [diagnostics()],
20
+ plugins: [],
22
21
  })
23
22
  ```
24
23
 
25
- Removing `diagnostics()` removes the feature's root navigation entry and its runtime operations.
26
- Plugins are never discovered or installed at runtime.
27
-
28
- Add app-owned routes at `dashboard/pages/<slug>/route.tsx`. An optional adjacent `page.yaml` may
29
- define `title`, `description`, and `layout`. Set `layout: standalone` when a page owns its full
30
- viewport presentation and should render without the dashboard navigation, heading, or shell spacing.
24
+ The default dashboard has no built-in pages or operations. Its landing page introduces page
25
+ creation and customization until an app-owned page exists, then redirects to the first configured
26
+ page. Optional plugins do not suppress the introduction. Plugins are never discovered or installed
27
+ at runtime.
28
+
29
+ Add app-owned routes at `dashboard/pages/<slug>/route.tsx`. An adjacent `page.yaml` must define
30
+ `icon` as a Tabler name (for example, `icon: settings`) and may define `title`, `description`,
31
+ and `layout`. Plugin navigation also requires `icon`. Navigation uses `src/assets/favicon.svg` for
32
+ the logo and omits the project slug. A small logo floats in the top-left corner and links to the
33
+ app’s home page at `/` in the same tab. With multiple pages, hovering the logo opens a navigation
34
+ popover; an adjacent chevron button toggles it on click, touch, or keyboard activation. The button
35
+ also supports ArrowDown and ArrowUp to focus the first or last navigation link, and Escape closes
36
+ the popover. With at most one page, only the home link appears, including in project-placed menus.
37
+ Pages own their headings, layout, and spacing; Coreframe adds no page header or content wrapper.
38
+ Leave room around the floating logo and menu button.
39
+ Icon names are resolved during composition. The browser receives only the selected SVGs and their
40
+ dimensions, rather than the full Tabler catalog.
41
+
42
+ Set `layout: standalone` to omit the floating logo. A standalone page may place `DashboardMenu`
43
+ from `@coreframe/dashboard/web` in its own header or layout; it receives the current application and
44
+ page list automatically:
31
45
 
32
46
  ```yaml
47
+ icon: settings
33
48
  title: Moderation
34
49
  layout: standalone
35
50
  ```
36
51
 
37
- Omitting `layout`, or setting it to `default`, retains the standard shell. Standalone pages remain in
52
+ ```tsx
53
+ import { DashboardMenu } from "@coreframe/dashboard/web"
54
+
55
+ export default function Moderation() {
56
+ return (
57
+ <main>
58
+ <header>
59
+ <DashboardMenu />
60
+ <h1>Moderation</h1>
61
+ </header>
62
+ {/* Page content */}
63
+ </main>
64
+ )
65
+ }
66
+ ```
67
+
68
+ Omitting `layout`, or setting it to `default`, retains the floating logo. Standalone pages remain in
38
69
  the dashboard route, build, authentication, query-client, and error-handling boundaries. Build-time
39
70
  composition validates slugs, metadata, route modules, identifiers, and paths before generating the
40
71
  React Router route graph and navigation manifest.
41
72
 
42
73
  The generated dashboard does not need route adapters, a document root, a query-client module, or an
43
74
  entry file. Keep those defaults in the package unless the dashboard build contract itself must
44
- change. The dashboard is intentionally configured with `ssr: false` and does not prerender pages or
45
- ship an app-owned server entry.
75
+ change. The dashboard is configured with `ssr: false` and does not ship an app-owned server entry.
76
+ Framework Mode still uses Vite's server environment in development and renders the root document
77
+ at build time to generate the SPA's HTML.
46
78
 
47
79
  Projects can opt into app-owned customization without copying the default scaffold:
48
80
 
49
81
  - `dashboard/document.tsx`, referenced as `document` in `dashboard.config.ts`, can provide a custom
50
82
  document `Layout` and optional `links` or `meta` exports;
51
- - `dashboard/styles.css` is loaded after the package stylesheet, while `panda.config.ts` remains the
52
- theme and generated-style override; and
83
+ - `dashboard/panda.config.ts` owns theme and style overrides; an optional `dashboard/styles.css`
84
+ loads after the generated Panda stylesheet for additional project CSS; and
53
85
  - `vite.config.ts` and `react-router.config.ts` remain small tool-level adapters for build changes.
54
86
 
87
+ ## Client routing in development
88
+
89
+ Projects can opt into a browser Data Router during development. This requires the client-compatible
90
+ page contract below; the setting does not automatically migrate Framework route modules.
91
+
92
+ Set `dashboard.devRouter` in `coreframe.config.ts`:
93
+
94
+ ```ts
95
+ export default defineConfig({
96
+ dashboard: { devRouter: "client" },
97
+ })
98
+ ```
99
+
100
+ The generated `dashboard/vite.config.ts` selects `coreframeDashboardClientPlugin` from
101
+ `@coreframe/vite/dashboard-client` when Coreframe starts client development. Existing projects
102
+ must adopt this Vite adapter as well as the setting. The relevant adapter shape is:
103
+
104
+ ```ts
105
+ const clientRouter =
106
+ env.command === "serve" && process.env.COREFRAME_DASHBOARD_DEV_ROUTER === "client"
107
+
108
+ const routerPlugins = clientRouter
109
+ ? [coreframeDashboardClientPlugin({ projectRoot })]
110
+ : [coreframeDashboardAppPlugin({ projectRoot }), reactRouter()]
111
+ ```
112
+
113
+ Spread `routerPlugins` into the existing plugins array, preserving Panda and other project
114
+ transforms. Import both dashboard adapters and `reactRouter` in this config.
115
+
116
+ Run the ordinary `pnpm dev` or `pnpm exec coreframe dashboard dev --port 5174` command. Coreframe
117
+ starts plain Vite for the dashboard UI, generates its browser route list from the same pages and
118
+ plugins as Framework Mode, and runs Framework type generation initially and after changes under
119
+ `dashboard/pages/` or to `dashboard/dashboard.config.ts`. Generation failures stop dashboard
120
+ development with an error. Changes to configuration dependencies outside these paths may require
121
+ restarting development. The setting defaults to `"framework"`.
122
+
123
+ `coreframe typegen` and `coreframe dashboard build` continue to use Framework Mode. Keep
124
+ `react-router.config.ts`, including `ssr: false`. Production builds still evaluate modules in a
125
+ server environment and render the root document at build time, so successful client development
126
+ does not establish production build compatibility. Run the dashboard build before deploying.
127
+
128
+ Client-compatible dashboard pages:
129
+
130
+ - Export a default React component. Use router hooks such as `useLoaderData`, `useActionData`,
131
+ `useParams`, `useMatches`, and `useRouteError`; client routing does not supply Framework
132
+ component or error-boundary props.
133
+ - Use `clientLoader` and `clientAction` for browser data work, calling the app API or dashboard
134
+ plugin APIs directly. These functions receive Data Router arguments; `serverLoader` and
135
+ `serverAction` are unavailable. Data Router revalidation defaults apply in this development mode.
136
+ - May export `ErrorBoundary`, `HydrateFallback`, `handle`, and `shouldRevalidate`.
137
+ - Must keep imports and page code browser-safe. Client development does not strip server exports
138
+ or server-only imports. Exports named `loader`, `action`, `headers`, `meta`, `links`, `middleware`,
139
+ and `clientMiddleware` produce an unsupported-feature error when the page loads.
140
+ - Must avoid Framework-only components and link features such as `Meta`, `Links`, `Scripts`,
141
+ `prefetch`, and `discover`. Use React document metadata elements where needed.
142
+
143
+ For example, a page can use client loading and hooks in both router modes:
144
+
145
+ ```tsx
146
+ import { useLoaderData, type LoaderFunctionArgs } from "react-router"
147
+
148
+ export async function clientLoader({ request }: LoaderFunctionArgs) {
149
+ const response = await fetch("/api/operator-summary", { signal: request.signal })
150
+ if (!response.ok) throw response
151
+ return response.json() as Promise<{ total: number }>
152
+ }
153
+
154
+ export default function Overview() {
155
+ const data = useLoaderData<typeof clientLoader>()
156
+ return <h1>{data.total} items</h1>
157
+ }
158
+ ```
159
+
160
+ Remove any `document` override in `dashboard/dashboard.config.ts` before selecting client routing;
161
+ custom Framework documents are rejected at startup. Move required content and wrappers into page
162
+ components. Coreframe supplies the browser entry, query provider, navigation, default page title,
163
+ favicon, styles, Sculpted runtime, and managed development overlay. The local dashboard API still
164
+ loads Node implementations through Vite's server environment. Its existing app-session admin
165
+ checks and same-origin request rules apply to both router modes.
166
+
167
+ ## Style overrides
168
+
169
+ The dashboard app's Panda build generates all dashboard styles, including the document reset,
170
+ shell, tokens, and UI recipes. `@coreframe/dashboard` does not ship a compiled stylesheet.
171
+ The styles module loads Inter's font stylesheet, then `dashboard/styled-system/styles.css`, then
172
+ an optional `dashboard/styles.css`. Panda controls the layer order; shell and document rules live
173
+ in its `base` layer. Normal unlayered project CSS takes precedence over normal layered rules.
174
+
175
+ The dashboard Panda config includes `coreframeDashboardPreset()` from `@coreframe/panda` and
176
+ statically generates all dashboard recipe variants because package components select variants at
177
+ runtime. Keep that `staticCss.recipes` configuration when customizing the app. The preset installs
178
+ document-wide styles, so use it only in the dedicated dashboard build, not the host app's Panda config.
179
+
180
+ Customize `theme.extend.semanticTokens.colors.dashboard` for shared colors, `theme.extend.tokens.fonts`
181
+ for typography, and `theme.extend.recipes` or `theme.extend.slotRecipes` for reusable UI defaults.
182
+ The color roles are `canvas`, `panel`, `ink`, `muted`, `border`, `accent`, `danger`, `info`,
183
+ `success`, and `warning`. Shell styles consume the same tokens as the UI components.
184
+
185
+ For targeted menu changes, extend the public `.coreframe-dashboard__*` selectors through
186
+ `globalCss.extend` in `dashboard/panda.config.ts`. Using `extend` preserves the other defaults
187
+ for each selector:
188
+
189
+ ```ts
190
+ globalCss: {
191
+ extend: {
192
+ ".coreframe-dashboard__floating-navigation": {
193
+ top: "1.5rem",
194
+ left: "1.5rem",
195
+ },
196
+ '.coreframe-dashboard__navigation-link[aria-current="page"]': {
197
+ fontWeight: "700",
198
+ },
199
+ },
200
+ },
201
+ ```
202
+
203
+ The `.coreframe-dashboard__menu-toggle` button exposes `aria-expanded`; navigation links expose `aria-current="page"` for the
204
+ current page. The reusable UI uses Panda recipe classes
205
+ such as `.dashboard-button` and `.dashboard-section__root`.
206
+
207
+ Sculpted source editing applies to supported project-owned static Panda `css({ ... })` sources;
208
+ it does not redirect package styles into project overrides or edit config recipes. Its current
209
+ root-level development endpoints need to be scoped to the dashboard's Vite base. Wrap the
210
+ dashboard's `sculpted()` plugin with `coreframeDashboardSculptedPlugin` from
211
+ `@coreframe/vite/dashboard-sculpted`; the generated dashboard does this and mounts the runtime in
212
+ development. The wrapper routes requests through `/__dashboard/` to this dashboard's own manifest
213
+ and writeback handlers. A custom document continues to get the runtime when it renders the root's
214
+ children. CSS and Panda overrides work independently of Sculpted.
215
+
55
216
  ## Runtime boundaries
56
217
 
57
218
  The app dashboard uses the same React, React Router framework mode, React Compiler, PandaCSS,
58
- Sculpted, Rouzer, Zod, TanStack Query, and Worker conventions as the main Coreframe application.
59
- Coreframe contributes the responsive navigation shell and default client/query runtime without
219
+ Rouzer, Zod, TanStack Query, and Worker conventions as the main Coreframe application.
220
+ Coreframe contributes the logo navigation and default client/query runtime without
60
221
  imposing a page-content component API.
61
222
 
62
223
  Plugin APIs expose named `queries` and `commands`. Queries are `GET` operations and commands are
@@ -82,9 +243,6 @@ credentials, Worker bindings, environment secrets, and the raw request remain ou
82
243
  contract. Typed operation errors expose safe error codes, and a failed local initialization can be
83
244
  retried without restarting the host.
84
245
 
85
- Each plugin’s `apiModule` must default-export its operation contract. Both the local host and
86
- generated Worker target load that default export.
87
-
88
246
  The compact plugin API uses `api`, `query`, and `command` for the shared contract, then derives a
89
247
  browser client from that contract:
90
248
 
@@ -158,15 +316,27 @@ dashboard credentials, or user IDs.
158
316
 
159
317
  App requests use credentialed same-origin transport. Explicit invalid-token challenges refresh and
160
318
  replay once through the app transport. Other response statuses keep their normal meaning, including
161
- distinct `401` and `403` failures. The dashboard password and plugin `DashboardSuperuser` actor are
162
- separate from app authentication, and the client does not proxy or translate between them.
319
+ distinct `401` and `403` failures. The dashboard host requires the current app session and an
320
+ active user with `role === "admin"`. The plugin `DashboardSuperuser` actor remains a capability
321
+ marker; plugins do not receive the app identity.
163
322
 
164
- ## Built-in diagnostics
323
+ If the route tree contains response codecs such as NDJSON, register their client plugins even when
324
+ the page does not call those routes. Rouzer validates codec registration during client construction.
165
325
 
166
- The diagnostics plugin preserves the full local production-readiness inspection and provides a
167
- reduced deployed view. Its page is a normal module and its browser data uses a typed operation client
168
- with TanStack Query. Local collection may use Node.js through its narrow host data; deployed
169
- collection never receives ambient Worker bindings or raw configuration values.
326
+ ```ts
327
+ import { createDashboardAppClient } from "@coreframe/dashboard/app-client"
328
+ import * as ndjson from "rouzer/ndjson"
329
+
330
+ const { client, session } = createDashboardAppClient(routes, {
331
+ plugins: [ndjson.clientPlugin],
332
+ })
333
+ ```
334
+
335
+ The hosting app must separately register `ndjson.routerPlugin` in its API's `createRouter({ plugins })`
336
+ configuration. Keep its existing authentication middleware, and complete authentication and permission
337
+ checks before returning a stream. NDJSON actions resolve to an `AsyncIterable` of the declared item
338
+ type; the codec does not validate items against a runtime schema. This configuration applies to the
339
+ hosting app's `/api/` routes, independently of the dashboard plugin API.
170
340
 
171
341
  Useful package checks:
172
342
 
@@ -178,3 +348,38 @@ pnpm --dir node/dashboard build
178
348
  ```
179
349
 
180
350
  Design notes live in [`design/`](./design/).
351
+
352
+ ## App navigation and sign-in
353
+
354
+ Apps import browser-safe navigation from `@coreframe/app/dashboard`:
355
+
356
+ ```tsx
357
+ import { dashboard } from "@coreframe/app/dashboard"
358
+
359
+ export function DashboardLinks() {
360
+ return dashboard.pages.map((page) => (
361
+ <a key={page.id} href={page.href}>
362
+ {page.title}
363
+ </a>
364
+ ))
365
+ }
366
+ ```
367
+
368
+ `dashboard` exposes `enabled`, `href`, and ordered `pages` containing `id`, `title`, optional
369
+ `description`, Tabler `icon`, and `href`. Composition uses the same app pages, plugin entries,
370
+ and environment filtering as the dashboard. Disabled dashboards and client-only builds expose
371
+ an empty list. This metadata is public in the app bundle and grants no access. Use browser links
372
+ because the dashboard owns a separate router.
373
+
374
+ The app host resolves the current durable session and database user for every dashboard request.
375
+ Only active users whose role is exactly `admin` may access documents, assets, or plugin APIs.
376
+ Signed-out document navigations receive an email/password sign-in form at the requested URL;
377
+ other unauthorized requests receive JSON `401`. Signed-in non-admins receive `403`, with an
378
+ account-switch action on document navigations. Login and sign-out use the app's existing auth
379
+ endpoints. Reloading after sign-in preserves the path, query, and fragment. Dashboard responses
380
+ are not cached. No dashboard password or alternate authentication mode is used.
381
+
382
+ The template owns the database/session integration in `src/api/worker/dashboard.ts`. Reusable
383
+ Worker handlers require a server-resolved access result; Node hosts fail closed unless an app
384
+ access resolver is supplied. Local development resolves access through the app's fixed origin,
385
+ including direct dashboard-server requests. Preview requires a running app auth boundary.
@@ -0,0 +1,7 @@
1
+ //#region src/access.d.ts
2
+ /** Result of resolving the app's current durable session and database user. */
3
+ type DashboardAccess = "admin" | "unauthenticated" | "forbidden";
4
+ /** Responds before any dashboard assets or operations are served. */
5
+ declare function dashboardAccessResponse(request: Request, access: DashboardAccess): Response | null;
6
+ //#endregion
7
+ export { DashboardAccess, dashboardAccessResponse };
@@ -0,0 +1,30 @@
1
+ function e(e,n){if(n===`admin`)return null;let r=n===`unauthenticated`?401:403,i=new URL(e.url);if(!((e.method===`GET`||e.method===`HEAD`)&&!i.pathname.startsWith(`/__dashboard/api`)&&(e.headers.get(`sec-fetch-dest`)===`document`||e.headers.get(`accept`)?.includes(`text/html`))))return Response.json({error:n},{status:r,headers:{"cache-control":`no-store`}});let a=crypto.randomUUID();return new Response(e.method===`HEAD`?null:t(n,a),{status:r,headers:{"cache-control":`private, no-store`,"content-type":`text/html; charset=utf-8`,"content-security-policy":`default-src 'none'; script-src 'nonce-${a}'; style-src 'nonce-${a}'; connect-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'`,"x-content-type-options":`nosniff`,"referrer-policy":`same-origin`}})}function t(e,t){let n=e===`forbidden`;return`<!doctype html>
2
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
3
+ <title>${n?`Dashboard access denied`:`Sign in to dashboard`}</title>
4
+ <style nonce="${t}">
5
+ body{font:16px system-ui,sans-serif;background:#f7f7f8;color:#202124;margin:0;display:grid;min-height:100svh;place-items:center}main{width:min(24rem,calc(100% - 4rem));padding:2rem}h1{font-size:1.6rem}form,label{display:grid;gap:.5rem}form{gap:1rem}input,button{font:inherit;padding:.75rem;border:1px solid #aaa;border-radius:.4rem}button{cursor:pointer;background:#202124;color:white}button:disabled{opacity:.6}#error{color:#a11919}
6
+ </style></head><body><main><p>Coreframe Dashboard</p>
7
+ <h1>${n?`You don’t have dashboard access`:`Sign in to dashboard`}</h1>
8
+ ${n?`<p>An administrator account is required.</p><button id="switch" type="button">Switch accounts</button>`:`<form id="signin"><label>Email<input name="email" type="email" autocomplete="username" required></label><label>Password<input name="password" type="password" autocomplete="current-password" required></label><button type="submit">Sign in</button></form>`}
9
+ <p id="error" role="alert"></p>
10
+ <script nonce="${t}">
11
+ const error = document.getElementById('error');
12
+ async function submit(path, body, button) {
13
+ button.disabled = true; error.textContent = '';
14
+ try {
15
+ const response = await fetch('/api/auth/' + path, {method:'POST', credentials:'same-origin', headers:{'content-type':'application/json'}, body:JSON.stringify(body)});
16
+ if (!response.ok) { error.textContent = response.status === 429 ? 'Too many attempts. Try again later.' : 'Unable to sign in. Check your details and try again.'; return; }
17
+ try {
18
+ localStorage.removeItem('coreframe.auth-session-observation.v1');
19
+ sessionStorage.setItem('coreframe.auth-session-recheck', 'true');
20
+ } catch {}
21
+ location.reload();
22
+ } catch { error.textContent = 'Unable to connect. Try again.'; }
23
+ finally { button.disabled = false; }
24
+ }
25
+ document.getElementById('signin')?.addEventListener('submit', event => {
26
+ event.preventDefault(); const form = event.currentTarget; const values = new FormData(form);
27
+ void submit('sign-in/email', {email:values.get('email'), password:values.get('password')}, form.querySelector('button'));
28
+ });
29
+ document.getElementById('switch')?.addEventListener('click', event => { void submit('sign-out', {}, event.currentTarget); });
30
+ <\/script></main></body></html>`}export{e as dashboardAccessResponse};
@@ -0,0 +1,7 @@
1
+ import { NonIndexRouteObject } from "react-router";
2
+
3
+ //#region src/app/client-route.d.ts
4
+ /** Adapts the supported browser-only subset of Framework route modules. */
5
+ declare function adaptClientRoute(module: Record<string, unknown>, file: string): Pick<NonIndexRouteObject, "Component" | "loader" | "action" | "ErrorBoundary" | "HydrateFallback" | "handle" | "shouldRevalidate">;
6
+ //#endregion
7
+ export { adaptClientRoute };
@@ -0,0 +1 @@
1
+ function e(e,t){for(let n of[`loader`,`action`,`headers`,`meta`,`links`,`middleware`,`clientMiddleware`])if(n in e)throw Error(`Dashboard client routing does not support the ${n} export in ${t}. Use clientLoader/clientAction, router hooks, and browser-safe page code, or select framework routing.`);return{Component:e.default,loader:e.clientLoader,action:e.clientAction,ErrorBoundary:e.ErrorBoundary,HydrateFallback:e.HydrateFallback,handle:e.handle,shouldRevalidate:e.shouldRevalidate}}export{e as adaptClientRoute};
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ import{DashboardEmptyState as e}from"../web-shell/shell.js";import"./empty.js";import t from"./index-route.js";import n from"./not-found.js";import{DashboardProviders as r}from"./providers.js";import i,{ErrorBoundary as a}from"./shell.js";import{Outlet as o,ScrollRestoration as s,createBrowserRouter as c,useLocation as l}from"react-router";import{StrictMode as u}from"react";import{Fragment as d,jsx as f,jsxs as p}from"react/jsx-runtime";import{createRoot as m}from"react-dom/client";import{RouterProvider as h}from"react-router/dom";import{routes as g}from"virtual:coreframe-internal/dashboard/client-routes";import{dashboardApplication as _,dashboardManifest as v}from"virtual:coreframe-internal/dashboard/manifest";import"virtual:coreframe-internal/dashboard/styles";function y(){let{pathname:e}=l();return p(d,{children:[f(`title`,{children:`${v.find(t=>t.path===e.split(`/`).filter(Boolean)[0])?.title||`Dashboard`} | ${_.name}`}),f(`link`,{rel:`icon`,href:_.favicon}),f(o,{}),f(s,{})]})}const b=c([{id:`root`,Component:y,HydrateFallback:()=>f(`p`,{role:`status`,children:`Loading dashboard…`}),children:[{id:`dashboard-shell`,Component:i,ErrorBoundary:a,children:[{index:!0,Component:v.length?t:e},...g,{path:`*`,Component:n}]}]}],{basename:`/__dashboard/`});m(document.getElementById(`root`)).render(f(u,{children:f(r,{children:f(h,{router:b})})}));export{};
@@ -1 +1 @@
1
- import{Link as e}from"react-router";import{jsx as t,jsxs as n}from"react/jsx-runtime";function r(){return n(`section`,{className:`coreframe-dashboard__state`,"aria-labelledby":`dashboard-not-found-title`,children:[t(`p`,{className:`coreframe-dashboard__eyebrow`,children:`Coreframe Dashboard`}),t(`h1`,{id:`dashboard-not-found-title`,children:`Page not found`}),t(`p`,{children:`The requested dashboard page does not exist.`}),t(e,{className:`coreframe-dashboard__button`,to:`/`,prefetch:`intent`,viewTransition:!0,children:`Go to dashboard`})]})}export{r as default};
1
+ import{Link as e}from"react-router";import{jsx as t,jsxs as n}from"react/jsx-runtime";function r(){return n(`section`,{className:`coreframe-dashboard__state`,"aria-labelledby":`dashboard-not-found-title`,children:[t(`p`,{className:`coreframe-dashboard__eyebrow`,children:`Coreframe Dashboard`}),t(`h1`,{id:`dashboard-not-found-title`,children:`Page not found`}),t(`p`,{children:`The requested dashboard page does not exist.`}),t(e,{className:`coreframe-dashboard__button`,to:`/`,viewTransition:!0,children:`Go to dashboard`})]})}export{r as default};
@@ -0,0 +1 @@
1
+ import{DashboardSculptedRuntime as e}from"./sculpted-runtime.js";import{Suspense as t,lazy as n}from"react";import{jsx as r,jsxs as i}from"react/jsx-runtime";import{QueryClient as a,QueryClientProvider as o}from"@tanstack/react-query";const s=new a({defaultOptions:{queries:{retry:1,staleTime:3e4}}}),c=import.meta.env.VITE_COREFRAME_MANAGED_DEV_OVERLAY_DEBUG===`1`,l=import.meta.env.DEV&&(import.meta.env.COREFRAME_MANAGED_DEV||c),u=import.meta.env.DEV?n(()=>import(`virtual:coreframe-internal/dashboard/managed-dev-overlay`).then(({ManagedDevOverlay:e})=>({default:e}))):null;function d({children:n}){return i(o,{client:s,children:[n,import.meta.env.DEV?r(e,{}):null,u&&l?r(t,{fallback:null,children:r(u,{debug:c})}):null]})}export{d as DashboardProviders};
@@ -1 +1 @@
1
- import{Links as e,Meta as t,Outlet as n,Scripts as r,ScrollRestoration as i}from"react-router";import{jsx as a,jsxs as o}from"react/jsx-runtime";import{QueryClient as s,QueryClientProvider as c}from"@tanstack/react-query";import*as l from"virtual:coreframe-internal/dashboard/document";import"virtual:coreframe-internal/dashboard/styles";const u=new s({defaultOptions:{queries:{retry:1,staleTime:3e4}}});function d({children:n}){let s=l.Layout,d=a(c,{client:u,children:n});return s?a(s,{children:d}):o(`html`,{lang:`en`,children:[o(`head`,{children:[a(`meta`,{charSet:`UTF-8`}),a(`meta`,{name:`viewport`,content:`width=device-width, initial-scale=1`}),a(`title`,{children:`Coreframe Dashboard`}),a(t,{}),a(e,{})]}),o(`body`,{children:[d,a(i,{}),a(r,{})]})]})}const f=l.links,p=l.meta;function m(){let e=l.default;return a(e||n,{})}export{d as Layout,m as default,f as links,p as meta};
1
+ import{DashboardProviders as e}from"./providers.js";import{Links as t,Meta as n,Outlet as r,Scripts as i,ScrollRestoration as a}from"react-router";import{jsx as o,jsxs as s}from"react/jsx-runtime";import{dashboardApplication as c,dashboardManifest as l}from"virtual:coreframe-internal/dashboard/manifest";import"virtual:coreframe-internal/dashboard/styles";import*as u from"virtual:coreframe-internal/dashboard/document";function d({children:r}){let c=u.Layout,l=o(e,{children:r});return c?o(c,{children:l}):s(`html`,{lang:`en`,children:[s(`head`,{children:[o(`meta`,{charSet:`UTF-8`}),o(`meta`,{name:`viewport`,content:`width=device-width, initial-scale=1`}),o(n,{}),o(t,{})]}),s(`body`,{children:[l,o(a,{}),o(i,{})]})]})}const f=({location:e})=>{let t=e.pathname.split(`/`).filter(Boolean)[0];return[{title:`${l.find(e=>e.path===t)?.title||`Dashboard`} | ${c.name}`}]},p=u.links??(()=>[{rel:`icon`,href:c.favicon}]),m=u.meta??f;function h(){let e=u.default;return o(e||r,{})}export{d as Layout,h as default,p as links,m as meta};
@@ -0,0 +1 @@
1
+ import{useEffect as e}from"react";import{enabled as t}from"virtual:coreframe-internal/dashboard/sculpted-availability";function n(){return e(()=>{import.meta.env.DEV&&t&&import(`virtual:coreframe-internal/dashboard/sculpted-runtime`)},[]),null}export{n as DashboardSculptedRuntime};
@@ -1 +1 @@
1
- import{DashboardErrorBoundary as e,DashboardShell as t}from"../web-shell/shell.js";import"../web-shell/index.js";import{jsx as n}from"react/jsx-runtime";import{dashboardManifest as r}from"virtual:coreframe-internal/dashboard/manifest";const i=e;function a(){return n(t,{pages:r})}export{i as ErrorBoundary,a as default};
1
+ import{DashboardErrorBoundary as e,DashboardShell as t}from"../web-shell/shell.js";import"../web-shell/index.js";import{jsx as n}from"react/jsx-runtime";import{dashboardApplication as r,dashboardManifest as i}from"virtual:coreframe-internal/dashboard/manifest";const a=e;function o(){return n(t,{pages:i,application:r})}export{a as ErrorBoundary,o as default};
@@ -1,14 +1,15 @@
1
1
  import { AuthSessionHintStore } from "@coreframe/lib/auth-transport";
2
2
  import { ReactNode } from "react";
3
- import { RouzerClient } from "rouzer";
3
+ import { ClientResponsePlugin, RouzerClient } from "rouzer";
4
4
  import { HttpRouteTree } from "rouzer/http";
5
5
 
6
6
  //#region src/app-client.d.ts
7
7
  /** The authentication states exposed by a dashboard app session. */
8
8
  type DashboardAppSessionStatus = "authenticated" | "checking" | "unauthenticated" | "unknown";
9
- /** The browser-only seams accepted by {@link createDashboardAppClient}. */
9
+ /** Response codecs and browser transport options for {@link createDashboardAppClient}. */
10
10
  type DashboardAppClientOptions = Readonly<{
11
- /** Replaces the browser fetch implementation in focused transport tests. */fetch?: typeof globalThis.fetch; /** Replaces the browser session hint store in focused session tests. */
11
+ /** Replaces the browser fetch implementation in focused transport tests. */fetch?: typeof globalThis.fetch; /** Response codecs required by the route tree, including routes the caller does not invoke. */
12
+ plugins?: readonly ClientResponsePlugin[]; /** Replaces the browser session hint store in focused session tests. */
12
13
  sessionHint?: AuthSessionHintStore;
13
14
  }>;
14
15
  /** The public state of a dashboard app session at one point in time. */
@@ -49,7 +50,7 @@ type DashboardAppClientResult<Routes extends HttpRouteTree> = Readonly<{
49
50
  *
50
51
  * The client always targets the current page origin and `/api/`. It refreshes through the app's
51
52
  * fixed `POST /api/auth/token` endpoint and sends credentialed same-origin requests. Dashboard
52
- * Basic Auth remains owned by the dashboard host and is not part of this client.
53
+ * admin authorization remains owned by the dashboard host and is not part of this client.
53
54
  */
54
55
  declare function createDashboardAppClient<const Routes extends HttpRouteTree>(routes: Routes, options?: DashboardAppClientOptions): DashboardAppClientResult<Routes>;
55
56
  /** The props accepted by {@link DashboardAppSessionBoundary}. */
@@ -1 +1 @@
1
- import{createAuthSessionHintStore as e}from"@coreframe/lib/auth-transport";import{createBrowserAuthSessionHintPersistence as t,createBrowserAuthenticatedFetch as n}from"@coreframe/lib/auth-transport/browser";import{useSyncExternalStore as r}from"react";import{createClient as i}from"rouzer";function a(e,t={}){let r=p(),a=m(t.fetch??((e,t)=>globalThis.fetch(e,t)),r),o=t.sessionHint??f(),s=n({appOrigin:r,fetch:a,refreshAccess:()=>a(new URL(`/api/auth/token`,r),{credentials:`include`,method:`POST`}),sessionHint:o});return{client:i({baseURL:new URL(`/api/`,r).href,fetch:s.fetch,headers:{"content-type":`application/json`},onJsonError:h,routes:e}),session:l(s,o)}}function o(e){return r(e.subscribe,e.get,e.get)}function s({children:e,pending:t,session:n,unauthenticated:r,unknown:i}){switch(o(n).status){case`authenticated`:return e;case`checking`:return g(t,n);case`unauthenticated`:return g(r,n);case`unknown`:return g(i,n)}}var c=class extends Error{status;constructor(e){super(`Request failed with status ${e}.`),this.name=`DashboardAppResponseError`,this.status=e}};function l(e,t){let n=u(t.get()),r,i,a=!1;function o(){return n}function s(e,t){let r=d(e,t);r.status===n.status&&r.expiresAt===n.expiresAt||(n=r,l())}let c=new Set;function l(){for(let e of c)e()}function f(e){return c.add(e),()=>c.delete(e)}function p(){i!==void 0&&(clearTimeout(i),i=void 0)}function m(e){p(),i=setTimeout(()=>{i=void 0,t.get(),h()},Math.max(0,e-Date.now()))}function h(){if(a)return;let e=t.get();if(e.status===`authenticated`){s(`authenticated`,e.validUntil),m(e.validUntil);return}if(e.status===`unauthenticated`){s(`unauthenticated`,null),m(e.validUntil);return}p(),s(`checking`,null),g()}function g(){if(a)return Promise.resolve(n);if(t.get().status!==`unknown`)return h(),Promise.resolve(n);if(s(`checking`,null),r)return r;let i=e.refreshAccessToken().then(r=>{if(a)return n;let i=t.get();return i.status===`authenticated`||i.status===`unauthenticated`?h():r?s(`unknown`,null):(e.setUnauthenticated(),h()),n}).catch(()=>{if(!a){let e=t.get();e.status===`authenticated`||e.status===`unauthenticated`?h():s(`unknown`,null)}return n});return r=i,i.then(()=>{r===i&&(r=void 0)}),i}function _(){return a?Promise.resolve(n):(t.invalidate(),g())}let v=t.subscribe(h),y=()=>t.syncFromPersistence(),b=()=>{n.status===`unknown`&&g()};return globalThis.window!==void 0&&(globalThis.addEventListener(`storage`,y),globalThis.addEventListener(`online`,b)),h(),{get expiresAt(){return n.expiresAt},get isPending(){return n.isPending},get status(){return n.status},dispose(){a||(a=!0,p(),v(),globalThis.window!==void 0&&(globalThis.removeEventListener(`storage`,y),globalThis.removeEventListener(`online`,b)))},get:o,refresh:_,subscribe:f}}function u(e){return e.status===`authenticated`?d(`authenticated`,e.validUntil):e.status===`unauthenticated`?d(`unauthenticated`,null):d(`checking`,null)}function d(e,t){return Object.freeze({expiresAt:t,isPending:e!==`authenticated`&&e!==`unauthenticated`,status:e})}function f(){let n=!1;if(globalThis.window!==void 0)try{n=t({key:`coreframe.auth-session-observation.v1`,storage:globalThis.localStorage})}catch{n=!1}return e({persistence:n,unauthenticatedTtlMs:3e5})}function p(){let e=globalThis.location?.origin;if(!e)throw Error(`createDashboardAppClient() requires a browser location.`);let t;try{t=new URL(e)}catch{throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`)}if(t.protocol!==`http:`&&t.protocol!==`https:`)throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`);return t.origin}function m(e,t){return(n,r)=>{if(new URL(n instanceof Request?n.url:n.toString(),t).origin!==t)throw TypeError(`Dashboard app client only allows same-origin requests.`);return e(n,{...r,credentials:`include`})}}async function h(e){throw new c(e.status)}function g(e,t){return typeof e==`function`?e(t):e??null}export{c as DashboardAppResponseError,s as DashboardAppSessionBoundary,a as createDashboardAppClient,o as useDashboardAppSession};
1
+ import{createAuthSessionHintStore as e}from"@coreframe/lib/auth-transport";import{createBrowserAuthSessionHintPersistence as t,createBrowserAuthenticatedFetch as n}from"@coreframe/lib/auth-transport/browser";import{useSyncExternalStore as r}from"react";import{createClient as i}from"rouzer";function a(e,t={}){let r=p(),a=m(t.fetch??((e,t)=>globalThis.fetch(e,t)),r),o=t.sessionHint??f(),s=n({appOrigin:r,fetch:a,refreshAccess:()=>a(new URL(`/api/auth/token`,r),{credentials:`include`,method:`POST`}),sessionHint:o});return{client:i({baseURL:new URL(`/api/`,r).href,fetch:s.fetch,headers:{"content-type":`application/json`},onJsonError:h,plugins:t.plugins,routes:e}),session:l(s,o)}}function o(e){return r(e.subscribe,e.get,e.get)}function s({children:e,pending:t,session:n,unauthenticated:r,unknown:i}){switch(o(n).status){case`authenticated`:return e;case`checking`:return g(t,n);case`unauthenticated`:return g(r,n);case`unknown`:return g(i,n)}}var c=class extends Error{status;constructor(e){super(`Request failed with status ${e}.`),this.name=`DashboardAppResponseError`,this.status=e}};function l(e,t){let n=u(t.get()),r,i,a=!1;function o(){return n}function s(e,t){let r=d(e,t);r.status===n.status&&r.expiresAt===n.expiresAt||(n=r,l())}let c=new Set;function l(){for(let e of c)e()}function f(e){return c.add(e),()=>c.delete(e)}function p(){i!==void 0&&(clearTimeout(i),i=void 0)}function m(e){p(),i=setTimeout(()=>{i=void 0,t.get(),h()},Math.max(0,e-Date.now()))}function h(){if(a)return;let e=t.get();if(e.status===`authenticated`){s(`authenticated`,e.validUntil),m(e.validUntil);return}if(e.status===`unauthenticated`){s(`unauthenticated`,null),m(e.validUntil);return}p(),s(`checking`,null),g()}function g(){if(a)return Promise.resolve(n);if(t.get().status!==`unknown`)return h(),Promise.resolve(n);if(s(`checking`,null),r)return r;let i=e.refreshAccessToken().then(r=>{if(a)return n;let i=t.get();return i.status===`authenticated`||i.status===`unauthenticated`?h():r?s(`unknown`,null):(e.setUnauthenticated(),h()),n}).catch(()=>{if(!a){let e=t.get();e.status===`authenticated`||e.status===`unauthenticated`?h():s(`unknown`,null)}return n});return r=i,i.then(()=>{r===i&&(r=void 0)}),i}function _(){return a?Promise.resolve(n):(t.invalidate(),g())}let v=t.subscribe(h),y=()=>t.syncFromPersistence(),b=()=>{n.status===`unknown`&&g()};return globalThis.window!==void 0&&(globalThis.addEventListener(`storage`,y),globalThis.addEventListener(`online`,b)),h(),{get expiresAt(){return n.expiresAt},get isPending(){return n.isPending},get status(){return n.status},dispose(){a||(a=!0,p(),v(),globalThis.window!==void 0&&(globalThis.removeEventListener(`storage`,y),globalThis.removeEventListener(`online`,b)))},get:o,refresh:_,subscribe:f}}function u(e){return e.status===`authenticated`?d(`authenticated`,e.validUntil):e.status===`unauthenticated`?d(`unauthenticated`,null):d(`checking`,null)}function d(e,t){return Object.freeze({expiresAt:t,isPending:e!==`authenticated`&&e!==`unauthenticated`,status:e})}function f(){let n=!1;if(globalThis.window!==void 0)try{n=t({key:`coreframe.auth-session-observation.v1`,storage:globalThis.localStorage})}catch{n=!1}return e({persistence:n,unauthenticatedTtlMs:3e5})}function p(){let e=globalThis.location?.origin;if(!e)throw Error(`createDashboardAppClient() requires a browser location.`);let t;try{t=new URL(e)}catch{throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`)}if(t.protocol!==`http:`&&t.protocol!==`https:`)throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`);return t.origin}function m(e,t){return(n,r)=>{if(new URL(n instanceof Request?n.url:n.toString(),t).origin!==t)throw TypeError(`Dashboard app client only allows same-origin requests.`);return e(n,{...r,credentials:`include`})}}async function h(e){throw new c(e.status)}function g(e,t){return typeof e==`function`?e(t):e??null}export{c as DashboardAppResponseError,s as DashboardAppSessionBoundary,a as createDashboardAppClient,o as useDashboardAppSession};
@@ -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(),layout:c.enum([`default`,`standalone`]).optional()}).strict(),d=c.object({id:c.string(),path:c.string(),title:c.string(),description:c.string().optional(),layout:c.enum([`default`,`standalone`]).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}:{},...o?.layout?{layout:o.layout}:{},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(`
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{icons as s}from"@iconify-json/tabler";import{parseDocument as c}from"yaml";import{z as l}from"zod";const u=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u,d=l.string().refine(e=>Object.hasOwn(s.icons,e),`must be a valid Tabler name`),f=l.object({icon:d,title:l.string().trim().min(1,`title must not be empty`).optional(),description:l.string().trim().min(1,`description must not be empty`).optional(),layout:l.enum([`default`,`standalone`]).optional()}).strict(),p=l.object({id:l.string(),path:l.string(),icon:d,title:l.string(),description:l.string().optional(),layout:l.enum([`default`,`standalone`]).optional(),routeModule:l.string(),environments:l.array(l.enum([`local`,`deployed`])).optional()}).strict(),m=l.string().trim().min(1,`module reference must not be empty`),h=l.object({path:l.string(),icon:d,title:l.string(),description:l.string().optional(),environments:l.array(l.enum([`local`,`deployed`])).optional()}).strict(),g=l.object({document:m.optional(),plugins:l.array(l.object({id:l.string(),navigation:h,pageModule:m,api:l.unknown().optional()}).strict()).optional()}).strict();async function _(e={}){let t=a(o(e.dashboardDirectory??a(process.cwd(),`dashboard`)),`pages`),i;try{i=await r(t,{withFileTypes:!0})}catch(e){if(F(e)&&e.code===`ENOENT`)return[];throw new w(t,`could not read the pages directory`,e)}let s=i.filter(e=>e.isDirectory()&&!e.name.startsWith(`.`)).sort((e,t)=>P(e.name,t.name));return Promise.all(s.map(async({name:e})=>{let r=a(t,e);M(e,r,`page directory`);let i=a(r,`route.tsx`);try{await n(i)}catch(e){throw F(e)&&e.code===`ENOENT`?new w(i,`missing required React Router route.tsx`):new w(i,`could not read route.tsx`,e)}let o=await T(a(r,`page.yaml`));return{id:e,path:e,icon:o.icon,title:o?.title??N(e),...o?.description?{description:o.description}:{},...o?.layout?{layout:o.layout}:{},routeModule:`pages/${e}/route.tsx`}}))}function v(e,t,n={}){let r=n.environment??`local`,i=new Set,a=[],o=A(e);for(let e of o.plugins??[]){if(M(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),i.has(e.id))throw new w(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);i.add(e.id);let t=D(e,`plugin`,r);t&&a.push(t)}let s=t.map(e=>({page:e,normalizedPage:E(e,`app`)})).sort((e,t)=>P(e.normalizedPage.path,t.normalizedPage.path));for(let{page:e,normalizedPage:t}of s)k(e,r)&&a.push(t);return O(a),a}function y(e,t){let n=A(e),r=new Set,i=[];for(let e of n.plugins??[]){if(M(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),r.has(e.id))throw new w(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);if(r.add(e.id),!e.api)continue;let n=j(e,`dashboard API`),a=t===`local`?n.localImplementationModule:n.deployedImplementationModule;a&&i.push({pluginId:e.id,apiModule:n.apiModule,implementationModule:a})}return i}function b(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(`
2
2
  `)}\n\nexport const dashboardPlugins = [\n${n.map(e=>` ${e},`).join(`
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}:{},...a.layout?{layout:a.layout}:{},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};
3
+ `)}\n]\n`}function x(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 S(e,t={}){let n=o(t.dashboardDirectory??a(process.cwd(),`dashboard`));return e.map(e=>({...e,routeModule:e.source===`app`?o(n,e.routeModule):C(e.routeModule,t)}))}function C(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 w(e,`could not resolve dashboard module`,t)}}var w=class extends Error{file;constructor(e,t,n){super(`${e}: ${t}`,{cause:n}),this.name=`DashboardCompositionError`,this.file=e}};async function T(e){let t;try{t=await n(e,`utf8`)}catch(t){throw F(t)&&t.code===`ENOENT`?new w(e,`missing required page.yaml with a Tabler icon`):new w(e,`could not read page metadata`,t)}let r=c(t,{prettyErrors:!0,strict:!0,uniqueKeys:!0});if(r.errors.length>0)throw new w(e,r.errors[0]?.message??`invalid YAML`);let i=f.safeParse(r.toJS());if(!i.success)throw new w(e,l.prettifyError(i.error));return i.data}function E(e,t,n){let r=t===`plugin`?`dashboard.config.ts plugin "${n??`unknown`}" page "${e.id}"`:e.routeModule,i=p.safeParse(e);if(!i.success)throw new w(r,l.prettifyError(i.error));let a=i.data;M(a.id,r,`page id`),M(a.path,r,`page path`);let o=a.title.trim();if(!o)throw new w(r,`page title must not be empty`);if(!a.routeModule.trim())throw new w(r,`page routeModule must not be empty`);let c=a.description?.trim();if(a.description!==void 0&&!c)throw new w(r,`page description must not be empty`);let u=s.icons[a.icon];return{id:a.id,path:a.path,title:o,icon:a.icon,iconData:{body:u.body,width:u.width??s.width??16,height:u.height??s.height??16},...c?{description:c}:{},...a.layout?{layout:a.layout}:{},routeModule:a.routeModule,source:t,...n?{pluginId:n}:{}}}function D(e,t,n){let r=`dashboard.config.ts plugin "${e.id}"`,i=h.safeParse(e.navigation);if(!i.success)throw new w(r,l.prettifyError(i.error));let a=i.data;if(M(e.id,r,`plugin id`),M(a.path,r,`navigation path`),!a.title.trim())throw new w(r,`navigation title must not be empty`);if(a.description!==void 0&&!a.description.trim())throw new w(r,`navigation description must not be empty`);if(!e.pageModule.trim())throw new w(r,`pageModule must not be empty`);if(!(a.environments&&!a.environments.includes(n))){if(e.api){let t=j(e,`dashboard API`);if(n===`local`&&!t.localImplementationModule||n===`deployed`&&!t.deployedImplementationModule)return}return E({id:e.id,path:a.path,title:a.title,icon:a.icon,...a.description?{description:a.description}:{},routeModule:e.pageModule,...a.environments?{environments:a.environments}:{}},t,e.id)}}function O(e){let t=new Map,n=new Map;for(let r of e){let e=t.get(r.id);if(e)throw new w(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 w(r.routeModule,`duplicate page path "${r.path}" also contributed by ${i.routeModule}`);n.set(r.path,r)}}function k(e,t){return e.environments?e.environments.includes(t):!0}function A(e){let t=g.safeParse(e);if(!t.success)throw new w(`dashboard.config.ts`,l.prettifyError(t.error));return e}function j(t,n){let r=e(t);if(!r)throw new w(`dashboard.config.ts plugin "${t.id}"`,`${n} is missing its package-owned build descriptor`);if(t.api&&t.api.id!==t.id)throw new w(`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 w(`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 w(`dashboard.config.ts plugin "${t.id}"`,`build descriptor field "deployedImplementationModule" must be a non-empty module reference`);return r}function M(e,t,n){if(!u.test(e))throw new w(t,`${n} "${e}" must contain only lowercase letters, numbers, and single hyphens`)}function N(e){let t=e.split(`-`).join(` `);return`${t.charAt(0).toUpperCase()}${t.slice(1)}`}function P(e,t){return e<t?-1:+(e>t)}function F(e){return e instanceof Error&&`code`in e}export{w as DashboardCompositionError,v as composeDashboardManifest,y as composeDashboardPluginTarget,x as composeDashboardRoutes,_ as discoverDashboardPages,b as renderDashboardPluginTargetModule,C as resolveDashboardModuleReference,S as resolveDashboardRouteModules};
@@ -2,7 +2,7 @@ import { DashboardPluginApi } from "./api/contract.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  type DashboardEnvironment = "local" | "deployed";
5
- /** Presentation supplied around a dashboard page route. */
5
+ /** Whether Coreframe places floating navigation or the page owns navigation placement. */
6
6
  type DashboardPageLayout = "default" | "standalone";
7
7
  interface DashboardPageContribution {
8
8
  /** Stable page identity. It must be a lowercase, URL-safe slug. */
@@ -10,8 +10,10 @@ interface DashboardPageContribution {
10
10
  /** Top-level URL segment below `/__dashboard/`. */
11
11
  path: string;
12
12
  title: string;
13
+ /** Tabler name, for example `settings`. */
14
+ icon: string;
13
15
  description?: string;
14
- /** Presentation supplied around the route. Defaults to the dashboard shell. */
16
+ /** Defaults to floating logo navigation. Standalone pages can place DashboardMenu themselves. */
15
17
  layout?: DashboardPageLayout;
16
18
  /** React Router framework route module, resolved by the dashboard build. */
17
19
  routeModule: string;
@@ -23,6 +25,8 @@ interface DashboardPluginNavigation {
23
25
  /** Top-level URL segment below `/__dashboard/`. */
24
26
  path: string;
25
27
  title: string;
28
+ /** Tabler name, for example `settings`. */
29
+ icon: string;
26
30
  description?: string;
27
31
  /** Environments where the feature is available. Defaults to both. */
28
32
  environments?: readonly DashboardEnvironment[];
@@ -33,7 +37,7 @@ interface DashboardPluginNavigation {
33
37
  * than a public list of target-specific module paths.
34
38
  */
35
39
  interface DashboardPluginBuild {
36
- /** Module exporting the plugin's operation contract as its default export. */
40
+ /** Module exporting the plugin's operation contract as `api`. */
37
41
  apiModule: string;
38
42
  /** Module exporting the local implementation factory as `createImplementation`. */
39
43
  localImplementationModule: string;
@@ -60,6 +64,14 @@ interface DashboardPageManifestEntry {
60
64
  id: string;
61
65
  path: string;
62
66
  title: string;
67
+ /** Tabler name, for example `settings`. */
68
+ icon: string;
69
+ /** Selected SVG data resolved during composition; the browser does not load the icon catalog. */
70
+ iconData: {
71
+ body: string;
72
+ width: number;
73
+ height: number;
74
+ };
63
75
  description?: string;
64
76
  layout?: DashboardPageLayout;
65
77
  routeModule: string;
@@ -1,3 +1,3 @@
1
- import { DashboardPayload, DashboardReleaseIdentity, DeployedDashboardPayload } from "./types.js";
2
- import { DashboardRequestHandler, DashboardServerOptions, createNodeHandler, createNodeServer } from "./server.js";
3
- export { type DashboardPayload, type DashboardReleaseIdentity, type DashboardRequestHandler, type DashboardServerOptions, type DeployedDashboardPayload, createNodeHandler, createNodeServer };
1
+ import { DashboardReleaseIdentity } from "./types.js";
2
+ import { createNodeHandler, createNodeServer } from "./server.js";
3
+ export { type DashboardReleaseIdentity, createNodeHandler, createNodeServer };
@@ -1 +1 @@
1
- import{DashboardRequestError as e}from"./request-error.js";async function t(e,t,r){let i=await r(await n(e)),a={};i.headers.forEach((e,t)=>{a[t]=e}),t.writeHead(i.status,a),t.end(Buffer.from(await i.arrayBuffer()))}async function n(e){let t=e.method??`GET`,n=new Headers;for(let[t,r]of Object.entries(e.headers))Array.isArray(r)?r.forEach(e=>n.append(t,e)):r!==void 0&&n.set(t,r);return new Request(r(e),{method:t,headers:n,body:t===`GET`||t===`HEAD`?void 0:await i(e)})}function r(e){let t=e.headers[`x-forwarded-proto`]===`https`?`https`:`http`;return new URL(e.url??`/`,`${t}://${e.headers.host??`localhost`}`)}async function i(t){let n=[],r=0;for await(let i of t){let t=Buffer.isBuffer(i)?i:Buffer.from(i);if(r+=t.length,r>8192)throw new e(`Dashboard request is too large.`,413);n.push(t)}return Buffer.concat(n).toString(`utf8`)}export{t as handleFetchRequest};
1
+ import{DashboardRequestError as e}from"./request-error.js";async function t(e,t,r){let i=await r(await n(e)),a={};i.headers.forEach((e,t)=>{a[t]=e}),t.writeHead(i.status,a),t.end(Buffer.from(await i.arrayBuffer()))}async function n(e){let t=e.method??`GET`,n=new Headers;for(let[t,r]of Object.entries(e.headers))Array.isArray(r)?r.forEach(e=>n.append(t,e)):r!==void 0&&n.set(t,r);return new Request(r(e),{method:t,headers:n,body:t===`GET`||t===`HEAD`?void 0:await i(e)})}function r(e){let t=String(e.headers[`x-forwarded-proto`]??``).split(`,`)[0]?.trim()===`https`?`https`:`http`;return new URL(e.url??`/`,`${t}://${e.headers.host??`localhost`}`)}async function i(t){let n=[],r=0;for await(let i of t){let t=Buffer.isBuffer(i)?i:Buffer.from(i);if(r+=t.length,r>8192)throw new e(`Dashboard request is too large.`,413);n.push(t)}return Buffer.concat(n).toString(`utf8`)}export{t as handleFetchRequest};
@@ -1,9 +1,12 @@
1
+ import { DashboardAccess } from "./access.js";
1
2
  import { DashboardPluginRegistration } from "./api/contract.js";
2
3
  import { IncomingMessage, Server, ServerResponse } from "node:http";
4
+ import { SecureContextOptions } from "node:tls";
3
5
 
4
6
  //#region src/server.d.ts
5
7
  type DashboardServerOptions = {
6
- /** Built dashboard client directory. Omit when the host only dispatches API requests. */clientDist?: string;
8
+ /** Built dashboard client directory. Omit when the host only dispatches API requests. */clientDist?: string; /** Resolves the current app session through the trusted app host. Fails closed if omitted. */
9
+ getAccess?: (request: IncomingMessage) => Promise<DashboardAccess>;
7
10
  plugins: readonly DashboardPluginRegistration<DashboardLocalHostData>[];
8
11
  projectRoot: string;
9
12
  };
@@ -11,11 +14,14 @@ type DashboardLocalHostData = {
11
14
  /** Root of the application the local dashboard is inspecting. */projectRoot: string;
12
15
  };
13
16
  type DashboardRequestHandler = {
17
+ /** Gates host-served development assets; writes the denied response and returns false on failure. */authorize(request: IncomingMessage, response: ServerResponse): Promise<boolean>;
14
18
  dispose(): Promise<void>;
15
19
  handle(request: IncomingMessage, response: ServerResponse): Promise<void>;
16
20
  };
17
21
  declare function createNodeServer(options: DashboardServerOptions): Server;
18
22
  /** Creates the localhost-only Node handler for the built client and composed plugin operations. */
19
23
  declare function createNodeHandler(options: DashboardServerOptions): DashboardRequestHandler;
24
+ /** Resolves access through a fixed app origin; request Host headers never select the destination. */
25
+ declare function createAppAccessResolver(getOrigin: () => string | undefined, tls?: Pick<SecureContextOptions, "ca">): (request: IncomingMessage) => Promise<DashboardAccess>;
20
26
  //#endregion
21
- export { DashboardLocalHostData, DashboardRequestHandler, DashboardServerOptions, createNodeHandler, createNodeServer };
27
+ export { DashboardLocalHostData, DashboardRequestHandler, DashboardServerOptions, createAppAccessResolver, createNodeHandler, createNodeServer };