@dokebi/template-inertia 0.4.26 → 0.4.27
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 +15 -5
- package/dist/index.js +13 -2
- package/dist/responder.d.ts +2 -0
- package/dist/responder.js +4 -0
- package/dist/template-build.d.ts +23 -0
- package/dist/template-build.js +215 -159
- package/dist/template-bundle.d.ts +21 -0
- package/dist/template-bundle.js +59 -2
- package/dist/template-preview.d.ts +16 -0
- package/dist/template-preview.js +162 -14
- package/dist/template-runtime.d.ts +31 -1
- package/dist/template-runtime.js +83 -3
- package/dist/template.d.ts +3 -3
- package/dist/template.js +3 -3
- package/package.json +4 -4
- package/templates/shared.ts +2 -1
package/AI.md
CHANGED
|
@@ -268,6 +268,8 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
268
268
|
- A page's contract goes in a plain `<script>` block beside `<script setup>`: `export const meta = { contract: 'checkout@2' }`. The build reads it from the server module and writes it into `pages.<page>.meta` (JSON data, at most 4 KiB). The framework never interprets it; the app's check will.
|
|
269
269
|
- The signature (`dokebi-template.sig`) is the template repository's next step: sign the manifest (its file hashes cover the rest).
|
|
270
270
|
- The same source builds the same bundle (`buildId` = the first 12 hex of the manifest's sha256).
|
|
271
|
+
- **`--style <file>`** (repeatable or comma separated, in order, 0.4.27, D-0298; `styles` of `buildTemplateBundle`): the template's own stylesheets (`.css` files of the folder) are carried like `--carry` and listed in the manifest's `styles`. When the app loads the bundle, the first HTML of every page of that template links them in the head, in order, with the CSP nonce, after the app's own stylesheets and before the pages' and Layout's: the first paint has the template's look (no swap after the page starts). Apps before 0.4.27 ignore `styles`.
|
|
272
|
+
- **A template of styles alone** (0.4.27, D-0298): a folder without `Layout.vue` and `Pages/**` builds when it carries something (`--style`, `--carry`) or has `locales/`: no Vite build, `pages: {}`, no `ssr/`. The app then draws every page with its own pages, with the template's stylesheets, words and CSP sources. Nothing at all is `INVALID_TEMPLATE_BUILD`. Apps before 0.4.27 refuse a bundle without pages.
|
|
271
273
|
- **`--carry <file>`** (repeatable or comma separated, 0.4.26, D-0296; `carry` of `buildTemplateBundle`): a file of the template folder, its path relative to the folder (`design.json`, `kit/fonts.json`), goes into the bundle as it is at `browser/<path>`, listed in `files` like every other file, so the signature covers it and `template check` and the app's load find any change. The result lists them (`carried: ['browser/design.json']`). The app reads one in `verifyTemplate` (`bundle.read('browser/design.json')`), and the browser can fetch it at `<base>_dokebi/templates/<app>/<template>/<buildId>/browser/<path>` — it is served like the pages' files, so **never carry a secret**. Refused (`INVALID_TEMPLATE_BUILD`, before anything is emptied or built): a path outside the folder, absolute or with `.`/`..`, a hidden file, a folder, a link, a missing file, and one under `pages/`, `chunks/` or `assets/` in any case (the build's own folders; `Pages/` is the same folder on macOS). Nothing else of the folder goes in. Any app that loads bundles (0.4.21+) takes such a bundle: the format is unchanged.
|
|
272
274
|
- **`npx dokebi template check <dir>`** checks a bundle as the app will: the manifest's shape and format, every file's size and sha256, no file the manifest does not list, no link, the size limit; `--against <app>/dist/.vite/dokebi-shared.json` (repeatable: add `dist/ssr/.vite/dokebi-shared.json` for an app with server rendering) also checks that the app provides every shared module the bundle imports, in the same major version (0.x: minor). Without a server build `vue/server-renderer` is not asked for: only the bundle's server modules import it, and an app without server rendering never loads them.
|
|
273
275
|
- **`--config <vite config>`** merges a vite config of the template repository (aliases, more plugins); @vitejs/plugin-vue is added unless that config has its own `vue()`.
|
|
@@ -289,20 +291,22 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
289
291
|
.filter(([, page]) => !supported(page.meta?.contract))
|
|
290
292
|
.map(([page]) => ({ page, reason: 'unknown contract' }));
|
|
291
293
|
return { accept: true, rejectPages };
|
|
294
|
+
// D-0297: and, to narrow the template's declared CSP sources, csp: { 'connect-src': [...] }
|
|
292
295
|
}
|
|
293
296
|
```
|
|
294
297
|
A refused page answers with the app's page; a refused bundle leaves the template to the app. It may take `templateVerifyTimeoutMs`. **In production (`NODE_ENV=production`) a bundle without `verifyTemplate` is not used** (error `INERTIA_TEMPLATE_UNVERIFIED`): its server modules run in the app's process. In development it is used with a warning.
|
|
295
|
-
- **The first HTML** of such a host carries an import map (with the CSP nonce) from the shared modules to the app build's files of them, so the bundle's `import 'vue'` is the app's vue in the browser too; the bundle's page table (`<script type="application/json" id="dokebi-template">`); the stylesheets and `modulepreload` links of the layout and the page. The bundle's browser files are served at `/_dokebi/templates/<app>/<template>/<buildId>/…` (immutable; the `templateKeep` generations). No CSP change is needed: same origin (`'self'`), and the bundle's modules are imported by the app's own trusted script (`'strict-dynamic'`).
|
|
298
|
+
- **The first HTML** of such a host carries an import map (with the CSP nonce) from the shared modules to the app build's files of them, so the bundle's `import 'vue'` is the app's vue in the browser too; the bundle's page table (`<script type="application/json" id="dokebi-template">`); the stylesheets and `modulepreload` links of the layout and the page. The bundle's browser files are served at `/_dokebi/templates/<app>/<template>/<buildId>/…` (immutable; the `templateKeep` generations). No CSP change is needed for the bundle itself: same origin (`'self'`), and the bundle's modules are imported by the app's own trusted script (`'strict-dynamic'`).
|
|
299
|
+
- **Other origins a template uses (0.4.27, D-0297, web 0.4.28):** a template folder's **`csp.json`** declares them: `{ "connect-src": ["https://api.widget.example"], "font-src": ["https://fonts.example"], "frame-src": ["https://player.example"] }`. Directives: `script-src`, `style-src`, `connect-src`, `font-src`, `img-src`, `frame-src`; at most 32 sources each; each an `https://` origin (host with an optional `*.` in front, optional port and path; `wss://` in `connect-src`) — no keyword, nonce, bare scheme (`https:`, `data:`), `*` or `http://`. `template build` checks it (`INVALID_TEMPLATE_BUILD`; not JSON: `TEMPLATE_BUILD_FAILED`) and writes it, sorted, into the manifest as `csp` (covered by the signature; `template build` and `template check` show it). When the app loads the bundle, `verifyTemplate` sees `bundle.manifest.csp` and may answer `{ accept: true, csp: { … } }`: only the declared sources it lists are used (the rest: warn `INERTIA_TEMPLATE_CSP_REFUSED` with `refused`); without `csp` in the answer (and in development without `verifyTemplate`) every declared source is used. The first HTML of a host whose template has that bundle gets them added to its `Content-Security-Policy` (`web.addCsp`); other hosts and Inertia visits (JSON) do not change, and a new bundle changes them with no restart (its 409 reloads open pages). `templateState` gives `csp` (what is used) and `cspRefused`; `INERTIA_TEMPLATE_LOADED` has `csp`. Under a nonce policy browsers ignore host sources in `script-src` beside `'strict-dynamic'`; a script the page's code loads runs anyway, so declare `script-src` for apps without a nonce. With a web before 0.4.28 the sources are not used (warn `INERTIA_TEMPLATE_CSP_UNSUPPORTED`). Apps before 0.4.27 ignore `csp`.
|
|
296
300
|
- **Asset version:** `<the app's version>+<template>@<buildId>`. A new bundle changes it, so an open page reloads at its next visit (409).
|
|
297
301
|
- **Server rendering** uses the same generation (an AsyncLocalStorage store; `templatePages()` reads it through a global registry, no imports). The bundle's server modules import the shared modules through a resolve hook that answers only importers inside the cache folder: the app build's server entries of them, the same instances as the app's own pages.
|
|
298
302
|
- **Failures never stop the start:**
|
|
299
303
|
- a missing, unreadable, changed, too large or incompatible bundle, one `verifyTemplate` refused, or one that fails to import: the template keeps its previous generation, or the app's pages when there is none (error `INERTIA_TEMPLATE_UNAVAILABLE` / `INERTIA_TEMPLATE_REJECTED`, once per `logRepeatWindowMs` per cause).
|
|
300
304
|
- A bundle page whose server render throws or times out is set aside for this generation and the request renders again with the app's page (then the layout, if it still fails): error `INERTIA_TEMPLATE_PAGE_FAILED`. The next first HTMLs leave it out of the table, so the browser uses the app's page too; a new generation tries it again.
|
|
301
305
|
- In the browser, a bundle page that cannot load (network, syntax) falls back to the app's page with a console warning.
|
|
302
|
-
- **Logs:** info `INERTIA_TEMPLATE_LOADED` (app, template, name, version, buildId, previous, pages, rejectedPages, serverRendering, kept, ms), warn `INERTIA_TEMPLATE_PAGE_REJECTED`, info `INERTIA_TEMPLATE_REMOVED`, info `INERTIA_TEMPLATE_DEV_SKIPPED`, error `INERTIA_TEMPLATE_LISTENER_FAILED` (D-0294). A refused or missing bundle's error says `the bundle in use stays` when an older generation still serves the template (0.4.24; before, it always said the app pages answer).
|
|
306
|
+
- **Logs:** info `INERTIA_TEMPLATE_LOADED` (app, template, name, version, buildId, previous, pages, rejectedPages, serverRendering, styles, csp, kept, ms), warn `INERTIA_TEMPLATE_CSP_REFUSED` and `INERTIA_TEMPLATE_CSP_UNSUPPORTED` (D-0297), warn `INERTIA_TEMPLATE_PAGE_REJECTED`, info `INERTIA_TEMPLATE_REMOVED`, info `INERTIA_TEMPLATE_DEV_SKIPPED`, error `INERTIA_TEMPLATE_LISTENER_FAILED` (D-0294). A refused or missing bundle's error says `the bundle in use stays` when an older generation still serves the template (0.4.24; before, it always said the app pages answer).
|
|
303
307
|
- **Not under `dokebi dev`:** there the pages come from Vite, and bundles are not used (info `INERTIA_TEMPLATE_DEV_SKIPPED`); work on a template in the template repository.
|
|
304
308
|
- **The app reads what happened (0.4.24, [D-0294](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0294-template-bundle-state.md)).** The plugin's API (the value of `context.get(templateInertia)` in a plugin or module setup) has:
|
|
305
|
-
- `templateState(app?)`: every configured template (`templates.<app>.<template>`), or those of `app`, as this process serves it now, frozen: `{ app, template, path, state, name?, version?, buildId?, loadedAt?, rejectedPages, failure?, reason?, checkedAt? }
|
|
309
|
+
- `templateState(app?)`: every configured template (`templates.<app>.<template>`), or those of `app`, as this process serves it now, frozen: `{ app, template, path, state, name?, version?, buildId?, loadedAt?, rejectedPages, failure?, reason?, checkedAt?, csp?, cspRefused? }` (`csp`: the CSP sources the bundle's answers add, 0.4.27).
|
|
306
310
|
- `state` is `loaded` (a bundle serves it: its manifest's `name` and `version`, its `buildId`, `loadedAt`), `rejected` or `unavailable` (no bundle serves it and the app's pages answer; the last load was refused — `INERTIA_TEMPLATE_REJECTED`, or `INERTIA_TEMPLATE_UNVERIFIED` in production — or found no bundle, `INERTIA_TEMPLATE_UNAVAILABLE`; `reason` says why), or `default` (none serves it and none failed: not looked at yet, or this process uses no bundles — under `dokebi dev`, `dokebi describe`, or one that serves no pages; `reason` says which).
|
|
307
311
|
- `rejectedPages`: the pages of the bundle in use that the app's own pages answer for, each `{ page, reason, code, at }`: `INERTIA_TEMPLATE_PAGE_REJECTED` (your `verifyTemplate` refused it, with its reason) or `INERTIA_TEMPLATE_PAGE_FAILED` (its server render failed: `its server render failed: <message>`).
|
|
308
312
|
- `failure`: the last load that failed, `{ code, reason, at, buildId? }`, also while an older bundle still serves the template (then `state` stays `loaded` and the log says `the bundle in use stays`); a load that succeeds clears it.
|
|
@@ -313,10 +317,13 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
313
317
|
|
|
314
318
|
**Working on a template (0.4.22).**
|
|
315
319
|
|
|
316
|
-
- **Preview:** `npx dokebi template preview <dir> [--port 5180] [--host 127.0.0.1] [--config <vite config>]
|
|
320
|
+
- **Preview:** `npx dokebi template preview <dir> [--port 5180] [--host 127.0.0.1] [--config <vite config>] [--csp <file>] [--style <file>]...` in the template repository starts a Vite dev server (HMR, the repository's real vue, Inertia and SDK packages; no app server). `/` lists every page and its cases; `/__dokebi/preview/<page>?case=<case>` draws one in the template's Layout, and a `<Link>` to another preview URL is an Inertia visit. API: `startTemplatePreview(options)` of `@dokebi/template-inertia/template` → `{ url, pages, close() }`.
|
|
317
321
|
- `Pages/<page>.preview.json` beside the page: an object of named cases, `{ "default": { "total": 12000 }, "empty cart": { "total": 0 } }` (JSON data, case names letters, digits, space, `_ . -`; a page without one gets the case `default` with no props). The first case is the one `/__dokebi/preview/<page>` draws.
|
|
318
322
|
- `preview.json` of the template folder: `{ "shared": { "app": { "name": "site", "template": "luxe" }, "auth": { … } } }`, under every case (the props the app's shared data gives in production).
|
|
319
323
|
- The preview files are not in the bundle: `template build` builds the `.vue` pages only.
|
|
324
|
+
- **Pages follow the folder (0.4.27, D-0299):** the list and the page URLs are read from the folder for every request, so a page added or removed while the preview runs is there at once; adding or removing a `Pages/**/*.vue` or `Layout.vue` reloads the open pages and the list (edits stay HMR). The preview starts without any page too (the list says so) — a template of styles alone can grow its first page.
|
|
325
|
+
- **Stylesheets (0.4.27, D-0298):** `--style theme.css,style.css` links the template's stylesheets in every page, in order, as the app does with the bundle; Vite serves them, so an edit shows at once (HMR).
|
|
326
|
+
- **CSP (0.4.27, D-0297):** every page is drawn under a `Content-Security-Policy` as the app would send it: web's default policy, or the app's own setting with `--csp <file>` (a JSON file shaped like `securityHeaders.contentSecurityPolicy`: `{ "directives": { … }, "nonce": true, "styleNonce": true }`), plus the template's `csp.json` sources and the preview's HMR socket; with `nonce` Vite and the preview write the nonce on their scripts. What the policy blocks is listed in a box at the bottom of the page (`connect-src blocked https://…`: declare the origin in `csp.json`) and warned in the console. A changed `csp.json` or setting file reloads the page.
|
|
320
327
|
- The template's own words (`locales/`) become the `i18n` prop of every case (in `preview.json`'s `locale`, else the first locale folder), so pages that call `t()` draw; a case that gives its own `i18n` keeps it. Keys only the app's catalogs have show as their key in the preview.
|
|
321
328
|
- **doctor** (`npx dokebi doctor`, `--production` on the server where the bundles are mounted) checks every bundle of `templates` as the app will: a key that is not an app (`TEMPLATE_APP_UNKNOWN`), a missing bundle (`TEMPLATE_BUNDLE_MISSING`), one the app would refuse (`TEMPLATE_BUNDLE_INVALID`, the check's problems in `details`), shared modules the app build does not provide in the same major version (`TEMPLATE_BUNDLE_SHARED`, against `dist/.vite/dokebi-shared.json` and `dist/ssr/.vite/dokebi-shared.json`; `TEMPLATE_SHARED_FILE_MISSING` without them), and an Inertia entry without `verifyTemplate` (`TEMPLATE_BUNDLE_UNVERIFIED`). With `--production` a missing bundle, a missing shared file and a missing `verifyTemplate` are errors; without, warnings (a laptop has no mounts).
|
|
322
329
|
|
|
@@ -345,6 +352,9 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
345
352
|
- **A type added to a file a barrel re-exports reaches the pages (0.4.23, D-0292)**: `defineProps<X>()` resolves X through @vue/compiler-sfc's type scopes, cached per file; for `export * from './event'` the compiler copies the source file's types into the barrel's scope, and @vitejs/plugin-vue clears only the changed file. A new type in an existing file that a barrel re-exports was `Unresolvable type reference` in dev until the barrel changed or dev restarted (vue-tsc and the build passed). The Vite host (and `dokebi template preview`) now clears, on every change or removal of a `.ts`/`.tsx`/`.mts`/`.cts` file, the type cache of the files that `export *` or `export type *` from it — in its folder and each folder above it up to its package root (the nearest package.json), and their own re-exporters — through the vue/compiler-sfc plugin-vue resolves from the project root (debug `Vue type caches of re-exporting files cleared` with `barrels`). The host also registers a TypeScript with a JS API on that compiler, as `dokebiInertia()` does, so a vite.config without it resolves imported props types too. The type files that compiler reads (outside node_modules) join the host's comparison with the disk (D-0283, D-0289: the page load, app connect, server render and `DOKEBI_DEV_RESCAN_MS` timer), which before saw only the modules Vite loads: an edit of a type file the watcher reports late or never reaches the pages within that time too (info `INERTIA_VITE_WATCH_MISSED` names it). The host learns them by wrapping the compiler's file access (`script.fs`, through @vitejs/plugin-vue's public `api.options`): its own `fs` when the config gives one, else node:fs with the answers of TypeScript's `ts.sys`.
|
|
346
353
|
- **A props type changed by a checkout reaches the pages at once, and stays (0.4.25, [D-0295](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0295-vite-host-type-changes-after-checkout.md))**: after a `git merge --ff` of many files, a page kept the old props of a type a barrel re-exports until the type file and the page were touched (the dev compiler had rebuilt the barrel from the old cache of the changed file while it cleared the barrels, and kept it). The changed type file's own cache is now cleared first, before the barrels, so a page that compiles meanwhile (a server render, another page of the same checkout) reads the new types. And a request that finds changed type files in the comparison with the disk (app connect, server render, a page loading Vite's client) goes on only once Vite has cleared their caches and invalidated the pages compiled with them (at most 2 s; none with `server.hmr: false`): the first server render after a checkout has the new props, where it used to have the old ones until the next request (debug `Vite handled the changed type files before the request`).
|
|
347
354
|
- **Files of the template folder ride in the bundle (0.4.26, [D-0296](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0296-template-bundle-carried-files.md))**: `dokebi template build --carry design.json` (`carry` of `buildTemplateBundle`) puts a file of the template folder — the options a designer declares, say — into the bundle at `browser/<path>`, hashed in the manifest the signature covers, where a template repository had to add it after the build and rewrite the manifest itself (§4.3).
|
|
355
|
+
- **A template declares the other origins it uses (0.4.27, [D-0297](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0297-template-csp-sources.md), web 0.4.28)**: the template folder's `csp.json` goes into the bundle's manifest; the app's `verifyTemplate` may narrow it; the first HTML drawn with the bundle adds those sources to its Content-Security-Policy, and only that host's pages do. `template preview --csp <app setting>` draws the pages under the same policy and lists what it blocks (§4.3).
|
|
356
|
+
- **The template's look is in the first HTML; a template may have no page (0.4.27, [D-0298](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0298-template-styles-and-pageless-bundles.md))**: `dokebi template build --style theme.css` lists the template's stylesheets in the manifest (`styles`), and the app links them, in order and with the nonce, in the head of every first HTML of that template, where a template's stylesheet used to arrive after the first paint. A folder of stylesheets and carried files alone builds into a bundle without pages (§4.3).
|
|
357
|
+
- **The preview follows the folder's pages (0.4.27, [D-0299](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0299-preview-follows-pages.md))**: a page added or removed while `dokebi template preview` runs is listed and drawn at once (the open pages reload), where the preview fixed its pages at start; it also starts without any page.
|
|
348
358
|
- **A module URL the host answers 404 says why (0.4.23, [D-0292](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0292-vite-host-explains-module-404.md))**: Vite turns `ERR_LOAD_URL` ("Failed to load url … (resolved id: …) in <importer>") into `next()` without the error, so a module it could not load answered an empty 404 and nothing was logged. Now, when a module request (`GET`/`HEAD` under the base with a module or style extension, `?import`, or `Sec-Fetch-Dest: script`) ends that way, the host asks Vite again in the same process and logs warn `INERTIA_VITE_NOT_LOADED` with `url`, `module` (the module URL without `t` and `import`), `root`, `file`, `exists` (with `missing`: `ENOENT`, `directory`, …), `readable`, `real` (when it is a link), `allowed` (Vite's `isFileLoadingAllowed`), `graph` (the module graph's entry for the URL: `id`, `file`, `stale` when its id names another file, `transformed`, `invalidatedAt`), `cause` (the error of one more `transformRequest`: the message Vite dropped, with its `code`) and `loadsNow`. Once per URL until it is served again; repeats are debug with `repeats`. Vite's static middleware serves a file that is there and allowed even when its transform fails, so an empty 404 means that this process saw the file missing or not allowed; when the diagnosis finds it there, readable and allowed after all (`retry: true`), the host invalidates the module, drops a URL entry whose id names another file and runs the request through Vite once more: the warning then says it was served after invalidating it, and `retried` is the status of that second answer. A page, a folder and a virtual `/@id/` URL keep the plain 404.
|
|
349
359
|
- **Pre-bundled dependencies that load (D-0128, 0.4.4)**: Vite keeps what its dependency optimizer wrote (each dependency's file under `node_modules/.vite/deps` and the `?v=` hash pages get) in memory, and at start trusts `_metadata.json` whenever the lockfile and config hashes match; it never looks at the files again, and it answers a file that is gone with 504 "Outdated Optimize Dep". A folder changed under it (two Vite optimizers on one folder — two `dokebi dev` sessions, a host still closing while the next starts — or a reinstall) therefore left every page blank through app restarts and dev restarts, until `rm -rf node_modules/.vite`. The host now compares its optimizer's files and metadata hashes with the folder when it starts, whenever an app process connects (every app or worker start) and after it answered a 504; when they differ it removes the deps folder and restarts its Vite (warn `INERTIA_VITE_DEPS_STALE` with `trigger` `start`, `client` or `outdated`, `drift` `missing` or `rewritten`, and a sample of the missing files), and the app process is answered after the repair. Open pages reconnect HMR and reload; a new page load gets the new hashes. At most one repair per `devDepsRepairIntervalMs`; faster changes are reported with warn `INERTIA_VITE_DEPS_CHANGING`. The host records its pid in `<cacheDir>/.dokebi/vite-host.json` and warns `INERTIA_VITE_HOST_SHARED` when another live host recorded itself there (stop one of the two `dokebi dev`). App processes pass Vite's status text on (`504 Outdated Optimize Dep`).
|
|
350
360
|
- SSR: the host runs `ssrLoadModule(<source entry>)` and `render(page)` per request. The app process asks on connections of its own (a render that waits never holds the connections module requests are forwarded on) and cuts the request at `ssr.timeoutMs`, so renders that never finish do not pile up on the host. The source entry is `ssr.entry` (for example `src/apps/admin/views/ssr.js`), otherwise `ssr.js` in the folder of `vite.entry`. When neither exists the start fails (`SSR_ENTRY_MISSING`).
|
|
@@ -410,7 +420,7 @@ A template can live apart from the app: a `views/<template>/` folder (Layout.vue
|
|
|
410
420
|
| `INVALID_TEMPLATE_SHARED` | `InertiaUsageError` | (D-0291) `templates.shared` of `dokebiInertia()` or `--shared` names something that is not a package name with an optional subpath, more than 64, two names that make one entry, or a module that cannot be resolved or imported from the project (§4.3) |
|
|
411
421
|
| `INVALID_TEMPLATE_PREVIEW` | `InertiaUsageError` | (D-0291) `dokebi template preview`: the folder is outside the project or has no `Pages/**/*.vue`, or a `<Page>.preview.json` / `preview.json` is not the documented shape (§4.3) |
|
|
412
422
|
| `INVALID_TEMPLATE_LISTENER` | `InertiaUsageError` | (D-0294) `onTemplateState` was given something other than a function |
|
|
413
|
-
| `INVALID_TEMPLATE_BUILD` | `InertiaUsageError` | (D-0291) `dokebi template build`: the folder is missing
|
|
423
|
+
| `INVALID_TEMPLATE_BUILD` | `InertiaUsageError` | (D-0291) `dokebi template build`: the folder is missing or outside the project, a page path is not a page name, the name or version is wrong, or `--out` is the project, the template folder, or a folder that holds files and no earlier bundle; a folder with no page and nothing carried (0.4.27); a `--style` that is not a `.css` file (0.4.27, D-0298); a `--carry` path that is not a plain file of the template folder or lands in the build's own folders (0.4.26, D-0296) (§4.3) |
|
|
414
424
|
| `INVALID_PRUNE` | `InertiaUsageError` | `pruneBuildFiles` without a manifest path, or an `olderThanMs`, `maxManifestBytes` or `now` that is not a whole number from 0 |
|
|
415
425
|
|
|
416
426
|
## 7. Cautions
|
package/dist/index.js
CHANGED
|
@@ -291,7 +291,7 @@ function hasCookie(header, name) {
|
|
|
291
291
|
}
|
|
292
292
|
const web = providerDependency({
|
|
293
293
|
name: 'dokebi-web',
|
|
294
|
-
version: '^0.4.
|
|
294
|
+
version: '^0.4.28',
|
|
295
295
|
packageName: '@dokebi/web',
|
|
296
296
|
load: () => import('@dokebi/web'),
|
|
297
297
|
});
|
|
@@ -533,6 +533,11 @@ class InertiaRuntime {
|
|
|
533
533
|
const hooks = Object.freeze({
|
|
534
534
|
sealOf: (request) => server.sealOf(request),
|
|
535
535
|
cspNonce: (request) => server.cspNonce(request),
|
|
536
|
+
...(typeof server.addCsp === 'function'
|
|
537
|
+
? {
|
|
538
|
+
addCsp: (request, addition) => server.addCsp(request, addition),
|
|
539
|
+
}
|
|
540
|
+
: {}),
|
|
536
541
|
...(sessions
|
|
537
542
|
? {
|
|
538
543
|
historyReset: async (request) => {
|
|
@@ -876,6 +881,12 @@ class InertiaRuntime {
|
|
|
876
881
|
words: (app, template, directory) => translations.templateBundle(app, template, directory),
|
|
877
882
|
}
|
|
878
883
|
: {}),
|
|
884
|
+
// D-0297: a bundle's declared CSP sources, made into web's addition once per generation.
|
|
885
|
+
...(typeof server.cspAddition === 'function'
|
|
886
|
+
? {
|
|
887
|
+
cspAddition: (directives) => server.cspAddition({ plugin: 'dokebi-template-inertia', directives }),
|
|
888
|
+
}
|
|
889
|
+
: {}),
|
|
879
890
|
});
|
|
880
891
|
templateRuntime = loaded;
|
|
881
892
|
this.#templates = { bundles: loaded, server };
|
|
@@ -1237,7 +1248,7 @@ class InertiaRuntime {
|
|
|
1237
1248
|
}
|
|
1238
1249
|
export const createPlugin = definePlugin({
|
|
1239
1250
|
name: 'dokebi-template-inertia',
|
|
1240
|
-
version: '0.4.
|
|
1251
|
+
version: '0.4.27',
|
|
1241
1252
|
core: '^0.4.2',
|
|
1242
1253
|
options,
|
|
1243
1254
|
entry: parseEntry,
|
package/dist/responder.d.ts
CHANGED
|
@@ -94,6 +94,8 @@ export interface InertiaHooks {
|
|
|
94
94
|
} | undefined;
|
|
95
95
|
/** D-0247: the request's CSP nonce (dokebi-web `cspNonce`), undefined when no policy asks for one. */
|
|
96
96
|
readonly cspNonce?: (request: FastifyRequest) => string | undefined;
|
|
97
|
+
/** D-0297: adds a template bundle's CSP sources to this request's answer (dokebi-web `addCsp`). */
|
|
98
|
+
readonly addCsp?: (request: FastifyRequest, addition: unknown) => void;
|
|
97
99
|
readonly historyReset?: (request: FastifyRequest) => Promise<boolean>;
|
|
98
100
|
/**
|
|
99
101
|
* The validation redirect of an Inertia request (D-0074 §3): flashes `errors` (and `old`) in
|
package/dist/responder.js
CHANGED
|
@@ -327,6 +327,10 @@ export class InertiaResponder {
|
|
|
327
327
|
// a page opened before a swap reloads on its next visit.
|
|
328
328
|
const template = this.hooks.template?.(request, this.options.version);
|
|
329
329
|
const version = template?.version ?? this.options.version;
|
|
330
|
+
// D-0297: the first HTML drawn with a bundle allows the other origins it declared (the page
|
|
331
|
+
// lives on in the browser through visits, so only the document's policy matters).
|
|
332
|
+
if (!inertia && template?.generation.csp?.addition !== undefined)
|
|
333
|
+
this.hooks.addCsp?.(request, template.generation.csp.addition);
|
|
330
334
|
// The protocol's version check is for GET visits only (the official adapters'): the 409 makes
|
|
331
335
|
// the client load X-Inertia-Location, so an error page of a POST must not turn into a GET.
|
|
332
336
|
if (inertia &&
|
package/dist/template-build.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export interface TemplateBuildOptions {
|
|
|
24
24
|
* the pages' files: public, never a secret.
|
|
25
25
|
*/
|
|
26
26
|
readonly carry?: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* D-0298: the template's own stylesheets (`.css` files of the template folder, in order): carried
|
|
29
|
+
* like `carry` and listed in the manifest's `styles`, which the app puts into the first HTML of
|
|
30
|
+
* every page of the template (with the nonce), before the pages' own stylesheets.
|
|
31
|
+
*/
|
|
32
|
+
readonly styles?: readonly string[];
|
|
27
33
|
readonly logger?: Logger;
|
|
28
34
|
}
|
|
29
35
|
export interface TemplateBuildResult {
|
|
@@ -37,6 +43,10 @@ export interface TemplateBuildResult {
|
|
|
37
43
|
readonly shared: Readonly<Record<string, string | null>>;
|
|
38
44
|
/** D-0296: the carried files, as bundle paths (`browser/design.json`). */
|
|
39
45
|
readonly carried: readonly string[];
|
|
46
|
+
/** D-0298: the template's stylesheets, as bundle paths, in order (the manifest's `styles`). */
|
|
47
|
+
readonly styles: readonly string[];
|
|
48
|
+
/** D-0297: the sources of the template folder's `csp.json` (the manifest's `csp`), or undefined. */
|
|
49
|
+
readonly csp?: Readonly<Record<string, readonly string[]>>;
|
|
40
50
|
readonly files: number;
|
|
41
51
|
readonly bytes: number;
|
|
42
52
|
readonly ms: number;
|
|
@@ -45,6 +55,19 @@ export interface TemplateBuildResult {
|
|
|
45
55
|
export declare function packageEntry(root: string, name: string): string | undefined;
|
|
46
56
|
/** The pages of a template folder: `Layout` and `Pages/<path>` → their .vue file. */
|
|
47
57
|
export declare function templatePages(folder: string): Promise<Map<string, string>>;
|
|
58
|
+
/**
|
|
59
|
+
* D-0296: the carried files, checked before the build: bundle path → the file in the template
|
|
60
|
+
* folder. A path is relative to the folder, a plain file inside it (no link on the way), not one of
|
|
61
|
+
* Vite's folders, and a bundle file name.
|
|
62
|
+
*/
|
|
63
|
+
export declare function carriedFiles(folder: string, paths: readonly string[]): Promise<Map<string, string>>;
|
|
64
|
+
/** D-0297: the file of a template folder that declares the sources of other origins it uses. */
|
|
65
|
+
export declare const TEMPLATE_CSP_FILE = "csp.json";
|
|
66
|
+
/**
|
|
67
|
+
* D-0297: the template folder's `csp.json`, checked (INVALID_TEMPLATE_BUILD), each list sorted and
|
|
68
|
+
* without repeats, empty lists left out; undefined without the file or with nothing in it.
|
|
69
|
+
*/
|
|
70
|
+
export declare function templateCsp(folder: string): Promise<Readonly<Record<string, readonly string[]>> | undefined>;
|
|
48
71
|
/**
|
|
49
72
|
* Builds the template folder `options.dir` of `options.root` into a bundle at `options.out`
|
|
50
73
|
* (D-0291). Throws INVALID_TEMPLATE_BUILD for wrong options and TEMPLATE_BUILD_FAILED for a
|