@dokebi/template-inertia 0.4.10 → 0.4.12

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/AI.md CHANGED
@@ -175,7 +175,7 @@ A page whose entry script cannot be fetched (a `dokebi dev` restart, a deploy in
175
175
  - The built-in look follows the browser: a dark colour scheme (`prefers-color-scheme: dark`) gets a dark box over the whole window (the page behind it is white without the app's CSS), a light one leaves the page's background; reduced motion (`prefers-reduced-motion: reduce`) stops the spinner. `logo` (a local URL such as `/assets/logo.svg`) shows an image above the spinner and the "could not load" text, decorative (`alt=""`, `[data-dokebi-boot-logo]`, at most 160 × 64 px by default).
176
176
  - Selectors for your stylesheet: `[data-dokebi-boot]` (the box, `role="status"`, `data-dokebi-boot="failed"` once it failed early), `[data-dokebi-boot-loading]`, `[data-dokebi-boot-failed]`. Never set `visibility`, `position` or `animation` on the two lines (their switch is those); animate a pseudo-element instead.
177
177
  - **Your own look: `bootFallback.stylesheet`** (a local URL such as `/assets/boot.css`, a plain CSS file of the app's `public/` that @dokebi/app serves) is linked right after the built-in style, so it applies before any script of the app runs. Do not style the box from the Vite bundle (`main.css`): under `dokebi dev` that CSS comes with the scripts, so the box shows unstyled while they load and stays unstyled when they fail. Keep the file small and self-contained (no Tailwind, no tokens of the bundle: they are not loaded yet).
178
- - CSP: web's default policy allows both inline blocks (`'unsafe-inline'`). A policy without it needs their hashes in `style-src` and `script-src` — the debug records `Inertia error answers` and `Inertia scope created` carry `bootFallback.cspHashes` (fixed per root id and timeout) — or `bootFallback: { enabled: false }`.
178
+ - CSP: web's default policy allows both inline blocks (`'unsafe-inline'`). Under web's nonce policy (`securityHeaders.contentSecurityPolicy.nonce` / `styleNonce`, 0.4.12, D-0247) both carry the page's nonce and nothing else is needed. A policy of your own without `'unsafe-inline'` and without a nonce needs their hashes in `style-src` and `script-src` — the debug records `Inertia error answers` and `Inertia scope created` carry `bootFallback.cspHashes` (fixed per root id and timeout) — or `bootFallback: { enabled: false }`.
179
179
  - A scope (`scope({ bootFallback })`, an app's inertia options) has its own; `false` there turns it off for that scope.
180
180
 
181
181
  ### 3.5 Public pages and head tags (0.4.6, D-0195)
@@ -242,7 +242,7 @@ A module keeps its Vue pages in its own views folder (@dokebi/module AI.md §4a)
242
242
  - The module text is one static import per page file and `export default modulePages({ <module>: { '<template>/<path>': page } })`. Left out: pages of sets the app did not choose (`Pages/<set>/**`), and a page the app overrides in `views/default/Pages/<module>/` (the app's file wins for every template). At most 2000 page files per app (warn `INERTIA_MODULE_PAGES_LIMIT`).
243
243
  - `modulePages(table)` of `@dokebi/template-inertia/pages` (no imports, browser and SSR bundles) gives `{ modules, page(template, name) }`: the module's page of `template`, else of `default`, else undefined. The entries look up the app's own page first: `` pick(`Pages/${name}`) ?? modulePages.page(template, name) ``.
244
244
  - Types: `/// <reference types="@dokebi/template-inertia/module-pages" />` in `src/infra/inertia/page.d.ts` (the generated file has it) declares the virtual module for vue-tsc and `dokebi check`, whose browser program now reads the project's `.d.ts` files too.
245
- - The dev server serves each module's views folder like an app's (§5.2), and reloads the browser when a `.vue` file is added to or removed from a module folder or the app's views, or the app file changes. The dev server reads an app's module pages in a worker thread of its own (0.4.10, D-0230), so the app file and everything it imports — the module list the CLI writes (`registeredModules`, D-0227), the modules' definitions — are read as they are now; a module added with `npx dokebi module add` while `dokebi dev` runs is served (its pages in the table, its folder allowed) once the list or the app file changes, without a restart. A change of the module list file or of a mounted module's `module.ts` reads the app again too.
245
+ - The dev server serves each module's views folder like an app's (§5.2), and reloads the browser when a `.vue` file is added to or removed from a module folder or the app's views, or the app file changes. The dev server reads an app's module pages in a worker thread of its own (0.4.10, D-0230), so the app file and everything it imports — the module list the CLI writes (`registeredModules`, D-0227), the modules' definitions — are read as they are now; a module added with `npx dokebi module add` while `dokebi dev` runs is served (its pages in the table, its folder allowed) once the list or the app file changes, without a restart. A change of the module list file reads the app again too, and so does a change of **any** module's definition (`module.ts`, `.mts` or `.js`) under the app's `src/` — a module that gains `views:` while `dokebi dev` runs has its pages in the table at once, and one that drops them loses them (0.4.11; before, only modules that already had views were watched, and `Unknown page` stayed until a restart).
246
246
  - `vite.ssr.config.ts` needs `dokebiInertia()` too (the SSR build resolves the same import; server rendering still leaves the seal imports to Node). `npx dokebi doctor` names an entry without the import while a module under `src/` has Vue pages (`TEMPLATE_FIX_MISSING`, `module-pages`) and a Vite config without `dokebiInertia()` while an entry imports it (`module-pages-plugin`).
247
247
  - An app package without the sources (before @dokebi/app 0.4.9): no module pages, warn `INERTIA_MODULE_PAGES_UNSUPPORTED`. Failures are coded errors of the build: `MODULE_PAGES_APP_MISSING` (imported outside an app's views folder), `MODULE_PAGES_FAILED` (the app file cannot be imported, exports no definition, or a module folder cannot be read; the cause is kept).
248
248
  - Debug logs: `Inertia module pages gathered` (app, page count per module, skipped sets, ms), `Inertia module pages changed; the browser reloads` (event, path), `Inertia dev file policy allows a module views folder`.
@@ -273,6 +273,7 @@ A module keeps its Vue pages in its own views folder (@dokebi/module AI.md §4a)
273
273
  - When a build marks absolute-path imports as `external`, the dev server prefixes those paths with `<base>`. In the dev server use a Vite plugin that resolves them to real files (see the playground's `vite.config.ts`).
274
274
  - Production (no `DOKEBI_VITE_DEV`) is unaffected. Never set this variable on a production server.
275
275
  - **Content-Security-Policy** (dokebi-web security headers, [D-0149](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0149-security-headers.md)): in development this plugin adds `ws://*:* wss://*:*` to `connect-src` for Vite's HMR socket, which connects to the page's own origin and `<base>` (`ws://localhost:<app port>/build/`, or `wss://<public host>/build/` through a tunnel; §5.1), and `worker-src 'self' blob:` for the `blob:` SharedWorker Vite's client pings a restarted dev host from (without it the page never reconnects); production adds nothing. Pages load their scripts from `'self'` (the page data is JSON, not a script); keep `'unsafe-inline'` in a policy of your own when a Vite framework plugin adds inline scripts in development.
276
+ - **Nonce policy** (0.4.12, [D-0247](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0247-csp-nonce.md); web 0.4.19 `contentSecurityPolicy: { nonce: true, styleNonce?: true }`): the first HTML — plain, sealed or server rendered, built or in development — writes the request's nonce (`web.cspNonce(request)`) on every module script and on the boot fallback's `<style>` and `<script>`, and adds `<meta property="csp-nonce" nonce="…">`, which Vite's client (development `<style>` of imported CSS) and its preload helper read. The page data block (`type="application/json"`) is never run and needs none. What the entry imports or creates is trusted by `'strict-dynamic'`. Inertia's own progress bar and error dialog styles take the nonce from `createInertiaApp({ nonce: document.querySelector('meta[property="csp-nonce"]')?.nonce || undefined })` (the generated `views/app.js` does; add it to an older entry before `styleNonce`). Checked in Chromium: a built Vue app with SSR and navigation (example 24), a seal host with server-rendered public pages and a framed page (example 80), and the Vite dev page with imported CSS, a dynamic import and the HMR client (`tests/dev-files.test.ts`).
276
277
  - The host answers a Vite middleware error with 500 (error log `INERTIA_VITE_HOST_FAILED`); 404 only when Vite has nothing for the URL. A host that does not answer is a 502 with error `INERTIA_VITE_DEV_FAILED` (once per 10 seconds, `repeated`); a host that cannot be reached at start is `VITE_DEV_UNAVAILABLE`.
277
278
  - Debug logs (D-0047): `Inertia settings resolved`, `Vite dev server ready` (ms, `shared`), `Vite dev route registered`, `Vite manifest read`, `Inertia SSR bundle loaded`, `Inertia SSR render deadline` (`timeoutMs`), `Inertia SSR render finished after its deadline` (a cut render that ended later), `Inertia SSR renders the source through Vite` (the source used), `Inertia scope created`, `Vite dev uses the host of dokebi dev`, `Vite dev starts a host in this process`, `Vite dev host connected` / `disconnected`; in the host `Vite dev host listening` (`port`, `hosts`), `Vite dev host started` (ms), `Vite dev host closed` (`connections`), `Vite dev host listens on IPv4 loopback only`, `Vite dev host port is taken on ::1, trying another`, `Vite dev host filters watcher events of unchanged files`, `Vite dev host ignored an event for a file that did not change` (the first and every 100th, `dropped`); `Vite dev host settings read` (`depsRepairIntervalMs`), `Vite dev host recorded itself in the cache folder` (`shared`), `Vite dev host re-optimized its dependencies` (`trigger`, `ms`, `repairs`), and per check only when debug is on `Vite dev host dependency cache matches` (`trigger`, `files`); per real file event, only when debug is on, `Vite dev host passes a file change`. A file whose state cannot be read is warn `INERTIA_VITE_WATCH_STAT_FAILED` (the event goes on). Per request, only when debug is on: `Vite dev route refused a host`, `Vite dev host closed an upgrade that is not Vite`, `Vite dev host refused a request without its key`, `Vite dev request ended by the browser`. Host listener and request failures are error `INERTIA_VITE_HOST_FAILED`.
278
279
 
@@ -34,12 +34,14 @@ export declare function normalizeBootFallback(input: InertiaBootFallback | false
34
34
  * the root's content. The head part depends on the root id and the timeout only, so its hashes are
35
35
  * fixed for a scope (logged at debug for a CSP that lists hashes).
36
36
  */
37
- export declare function bootMarkup(settings: NormalizedBootFallback, rootId: string, language: string | undefined): {
37
+ export declare function bootMarkup(settings: NormalizedBootFallback, rootId: string, language: string | undefined,
38
+ /** D-0247: the page's CSP nonce, written on the style and the script. */
39
+ nonce?: string): {
38
40
  readonly head: string;
39
41
  readonly root: string;
40
42
  };
41
- /** The style and the script of the head (fixed per root id and timeout). */
42
- export declare function bootHead(rootId: string, timeoutMs: number): string;
43
+ /** The style and the script of the head (fixed per root id and timeout; D-0247: with the page's nonce). */
44
+ export declare function bootHead(rootId: string, timeoutMs: number, nonce?: string): string;
43
45
  /**
44
46
  * "Loading" turns to "could not load" after the delay, or at once once the script marks it. The
45
47
  * look: the box fills the window and centers its line; "loading" is a spinner (its text, at size 0,
@@ -95,19 +95,22 @@ function textsFor(settings, language) {
95
95
  * the root's content. The head part depends on the root id and the timeout only, so its hashes are
96
96
  * fixed for a scope (logged at debug for a CSP that lists hashes).
97
97
  */
98
- export function bootMarkup(settings, rootId, language) {
98
+ export function bootMarkup(settings, rootId, language,
99
+ /** D-0247: the page's CSP nonce, written on the style and the script. */
100
+ nonce) {
99
101
  const texts = textsFor(settings, language);
100
102
  return {
101
- head: bootHead(rootId, settings.timeoutMs) +
103
+ head: bootHead(rootId, settings.timeoutMs, nonce) +
102
104
  (settings.stylesheet
103
105
  ? `<link rel="stylesheet" href="${escapeHtml(settings.stylesheet)}">`
104
106
  : ''),
105
107
  root: `<div data-dokebi-boot role="status" aria-live="polite">${settings.logo ? `<img data-dokebi-boot-logo src="${escapeHtml(settings.logo)}" alt="">` : ''}<p data-dokebi-boot-loading>${escapeHtml(texts.loading)}</p><p data-dokebi-boot-failed>${escapeHtml(texts.failed)} <a href="">${escapeHtml(texts.reload)}</a></p></div>`,
106
108
  };
107
109
  }
108
- /** The style and the script of the head (fixed per root id and timeout). */
109
- export function bootHead(rootId, timeoutMs) {
110
- return `<style>${bootStyle(timeoutMs)}</style><script>${bootScript(rootId)}</script>`;
110
+ /** The style and the script of the head (fixed per root id and timeout; D-0247: with the page's nonce). */
111
+ export function bootHead(rootId, timeoutMs, nonce) {
112
+ const attribute = nonce === undefined ? '' : ` nonce="${escapeHtml(nonce)}"`;
113
+ return `<style${attribute}>${bootStyle(timeoutMs)}</style><script${attribute}>${bootScript(rootId)}</script>`;
111
114
  }
112
115
  /**
113
116
  * "Loading" turns to "could not load" after the delay, or at once once the script marks it. The
package/dist/index.js CHANGED
@@ -292,7 +292,7 @@ function hasCookie(header, name) {
292
292
  */
293
293
  const web = providerDependency({
294
294
  name: 'dokebi-web',
295
- version: '^0.4.3',
295
+ version: '^0.4.19',
296
296
  packageName: '@dokebi/web',
297
297
  load: () => import('@dokebi/web'),
298
298
  });
@@ -439,6 +439,7 @@ class InertiaRuntime {
439
439
  const resets = new WeakMap();
440
440
  const hooks = Object.freeze({
441
441
  sealOf: (request) => server.sealOf(request),
442
+ cspNonce: (request) => server.cspNonce(request),
442
443
  ...(sessions
443
444
  ? {
444
445
  historyReset: async (request) => {
@@ -1036,7 +1037,7 @@ class InertiaRuntime {
1036
1037
  }
1037
1038
  export const createPlugin = definePlugin({
1038
1039
  name: 'dokebi-template-inertia',
1039
- version: '0.4.10',
1040
+ version: '0.4.12',
1040
1041
  core: '^0.4.2',
1041
1042
  options,
1042
1043
  entry: parseEntry,
@@ -86,6 +86,8 @@ async function readHere(app) {
86
86
  return { kind: 'unsupported' };
87
87
  return { kind: 'sources', sources: list() };
88
88
  }
89
+ /** A module's definition file (D-0227: `module.ts` at the module's root). */
90
+ const DEFINITION = /^module\.(?:ts|mts|js)$/;
89
91
  /** How long the dev server waits for a worker to read an app's module page sources. */
90
92
  const WORKER_TIMEOUT_MS = 30_000;
91
93
  const WORKER = new URL('./module-pages-worker.js', import.meta.url);
@@ -238,7 +240,11 @@ export class ModulePagesSource {
238
240
  const page = event !== 'change' &&
239
241
  path.endsWith('.vue') &&
240
242
  watched.folders.some((folder) => within(path, folder));
241
- if (!page && path !== watched.app && !watched.files.includes(path))
243
+ // Any module definition under the app's sources (src/): a module the app mounts that
244
+ // gains, changes or drops `views` changes the table, and a module without views is not
245
+ // in the sources to watch by name (shop: gameplus/member/Favorites unknown until a restart).
246
+ const definition = DEFINITION.test(basename(path)) && within(path, watched.sources);
247
+ if (!page && !definition && path !== watched.app && !watched.files.includes(path))
242
248
  continue;
243
249
  this.#invalidate(id, event, path);
244
250
  }
@@ -257,12 +263,20 @@ export class ModulePagesSource {
257
263
  ...['ts', 'js'].map((ext) => join(dirname(app), '..', '..', `dokebi.modules.generated.${ext}`)),
258
264
  ...sources.flatMap((source) => ['module.ts', 'module.mts', 'module.js'].map((name) => join(dirname(source.folder), name))),
259
265
  ];
260
- this.#watched.set(id, { app, folders, files });
266
+ const root = join(dirname(app), '..', '..');
267
+ this.#watched.set(id, { app, folders, files, sources: root });
261
268
  if (!this.#serve)
262
269
  return;
263
270
  for (const source of sources)
264
271
  this.#allow(source.folder);
265
- this.#server?.watcher?.add([app, ...folders, ...files.filter((file) => existsSync(file))]);
272
+ // The source tree too, so a definition file is seen wherever its module lives (Vite watches
273
+ // its root; this covers a host whose root is elsewhere).
274
+ this.#server?.watcher?.add([
275
+ app,
276
+ root,
277
+ ...folders,
278
+ ...files.filter((file) => existsSync(file)),
279
+ ]);
266
280
  }
267
281
  #invalidate(id, event, path) {
268
282
  const server = this.#server;
@@ -91,6 +91,8 @@ export interface InertiaHooks {
91
91
  readonly sealOf?: (request: FastifyRequest) => {
92
92
  encode(text: string): string;
93
93
  } | undefined;
94
+ /** D-0247: the request's CSP nonce (dokebi-web `cspNonce`), undefined when no policy asks for one. */
95
+ readonly cspNonce?: (request: FastifyRequest) => string | undefined;
94
96
  readonly historyReset?: (request: FastifyRequest) => Promise<boolean>;
95
97
  /**
96
98
  * The validation redirect of an Inertia request (D-0074 §3): flashes `errors` (and `old`) in
package/dist/responder.js CHANGED
@@ -479,9 +479,17 @@ export class InertiaResponder {
479
479
  const htmlLanguage = typeof language === 'string' && /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(language)
480
480
  ? ` lang="${escapeHtml(language)}"`
481
481
  : '';
482
+ // D-0247: under a nonce policy every script of the page carries the nonce, and the meta tag
483
+ // hands it to Vite's client and preload helper for the styles and preloads they add.
484
+ const cspNonce = this.hooks.cspNonce?.(request);
485
+ const nonce = cspNonce === undefined ? '' : ` nonce="${escapeHtml(cspNonce)}"`;
486
+ const nonceMeta = cspNonce === undefined ? '' : `<meta property="csp-nonce"${nonce}>`;
487
+ const moduleScripts = scripts
488
+ .map((url) => `<script type="module"${nonce} src="${escapeHtml(url)}"></script>`)
489
+ .join('');
482
490
  // Studio v2: "loading", then "could not load — reload", while the app has not mounted.
483
491
  const boot = this.options.bootFallback.enabled
484
- ? bootMarkup(this.options.bootFallback, rootId, typeof language === 'string' ? language : undefined)
492
+ ? bootMarkup(this.options.bootFallback, rootId, typeof language === 'string' ? language : undefined, cspNonce)
485
493
  : undefined;
486
494
  if (sealer && !publicHtml) {
487
495
  // `E:<ts>:<base64>` holds no HTML specials; the client opens it before Inertia starts
@@ -490,7 +498,7 @@ export class InertiaResponder {
490
498
  const frame = sealer.encode(json);
491
499
  return reply
492
500
  .type('text/html; charset=utf-8')
493
- .send(`<!doctype html><html${htmlLanguage}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(title)}</title>${head?.tags ?? ''}${styles.map((url) => `<link rel="stylesheet" href="${escapeHtml(url)}">`).join('')}${boot?.head ?? ''}${scripts.map((url) => `<script type="module" src="${escapeHtml(url)}"></script>`).join('')}</head><body><script data-page="${rootId}" type="application/json" data-sealed="true">${escapeHtml(frame)}</script><div id="${rootId}">${boot?.root ?? ''}</div></body></html>`);
501
+ .send(`<!doctype html><html${htmlLanguage}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(title)}</title>${nonceMeta}${head?.tags ?? ''}${styles.map((url) => `<link rel="stylesheet" href="${escapeHtml(url)}">`).join('')}${boot?.head ?? ''}${moduleScripts}</head><body><script data-page="${rootId}" type="application/json" data-sealed="true">${escapeHtml(frame)}</script><div id="${rootId}">${boot?.root ?? ''}</div></body></html>`);
494
502
  }
495
503
  // Only the first HTML is server rendered; Inertia visits above stay JSON.
496
504
  const rendered = this.ssr ? await this.#serverRender(JSON.parse(json), rootId) : undefined;
@@ -523,7 +531,7 @@ export class InertiaResponder {
523
531
  const sealHost = sealer ? SEAL_HOST_META : '';
524
532
  return reply
525
533
  .type('text/html; charset=utf-8')
526
- .send(`<!doctype html><html${htmlLanguage}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">${sealHost}${titled ? '' : `<title>${escapeHtml(title)}</title>`}${head?.tags ?? ''}${styles.map((url) => `<link rel="stylesheet" href="${escapeHtml(url)}">`).join('')}${rendered ? '' : (boot?.head ?? '')}${scripts.map((url) => `<script type="module" src="${escapeHtml(url)}"></script>`).join('')}${ssrHead.join('')}</head><body>${rendered?.body ?? `<script data-page="${rootId}" type="application/json">${safeJson}</script><div id="${rootId}">${boot?.root ?? ''}</div>`}</body></html>`);
534
+ .send(`<!doctype html><html${htmlLanguage}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">${sealHost}${titled ? '' : `<title>${escapeHtml(title)}</title>`}${nonceMeta}${head?.tags ?? ''}${styles.map((url) => `<link rel="stylesheet" href="${escapeHtml(url)}">`).join('')}${rendered ? '' : (boot?.head ?? '')}${moduleScripts}${ssrHead.join('')}</head><body>${rendered?.body ?? `<script data-page="${rootId}" type="application/json">${safeJson}</script><div id="${rootId}">${boot?.root ?? ''}</div>`}</body></html>`);
527
535
  }
528
536
  /**
529
537
  * The value of one selected prop. A function runs here; a rescued deferred prop that throws is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/template-inertia",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "Inertia v3 server adapter for Dokebi: page JSON, Vite manifest assets and optional server-side rendering.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@dokebi/core": "^0.4.2",
64
- "@dokebi/web": "^0.4.3",
64
+ "@dokebi/web": "^0.4.19",
65
65
  "fastify": "^5.12.7",
66
66
  "vue": "^3.5.0"
67
67
  },
@@ -77,7 +77,7 @@
77
77
  "dependencies": [
78
78
  {
79
79
  "name": "dokebi-web",
80
- "version": "^0.4.3"
80
+ "version": "^0.4.19"
81
81
  },
82
82
  {
83
83
  "name": "dokebi-session",
@@ -143,11 +143,11 @@
143
143
  ]
144
144
  },
145
145
  "devDependencies": {
146
- "@dokebi/i18n": "0.2.5",
147
- "@dokebi/session": "0.4.8",
148
- "@dokebi/web": "0.4.12",
149
- "@dokebi/websocket": "0.4.5",
150
- "@dokebi/websocket-hub": "0.4.3",
146
+ "@dokebi/i18n": "0.2.8",
147
+ "@dokebi/session": "0.4.9",
148
+ "@dokebi/web": "0.4.19",
149
+ "@dokebi/websocket": "0.4.9",
150
+ "@dokebi/websocket-hub": "0.4.5",
151
151
  "@inertiajs/vue3": "3.9.1",
152
152
  "vue": "3.5.44"
153
153
  },