@dokebi/app 0.4.5 → 0.4.6

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
@@ -272,7 +272,7 @@ dokebi-app:
272
272
  - Pages: when `sealed` is true, load `/dokebi/seal/seal.mjs` and `socket.mjs`, call `initSeal()`, then `connectChannel({ path, seal: sealBridge })`. (Passing the bridge always is fine: the client offers both `dokebi.seal` and `dokebi.plain`, and a plain host picks `dokebi.plain` and runs in plain text. `sealed` decides whether to fetch the wasm early.) Connecting to a seal host without a bridge closes with 4415 (no reconnect); an unopenable frame closes with 4400. Details are in @dokebi/websocket AI.md §4a and the @dokebi/seal README.
273
273
  - Same app = same hub tenant, so a broadcast sent on a seal host reaches plain-host sockets in plain text and sealed sockets sealed.
274
274
  - **HTTP (D-0062)**: when sealed domains exist, app registers `sealRequests(is the host sealed)` with dokebi-web. Every HTTP request to such a host (app routes or `/api/*` routes a module put directly on web) gets sealed JSON responses, 415 for plain JSON bodies, a sealed Inertia first page and sealed SSE data. An app route with `seal: false` (`route.post('/hook', handler, { seal: false })`) stays plain (webhooks, server to server), as does dokebi-web `sealExclude`. EJS HTML stays as it is (page navigations and their error pages, D-0092 §1).
275
- - **EJS forms on seal hosts (D-0092)**: every EJS page and error view gets **`data.seal`**: `{ head }`, on a seal host the HTML of an import map (`@dokebi/seal/http` → `/dokebi/seal/http.mjs`, `@dokebi/seal/forms` → `/dokebi/seal/forms.mjs`) and the module script of `/dokebi/seal/forms.mjs`, on a plain host `''`. Write **`<%- data.seal.head %>`** in the `<head>` of the layout, before other module scripts (the shared layout of `npx dokebi add @dokebi/template-ejs` does). The forms module sends every POST form sealed with `x-dokebi-form: 1`: handlers read the urlencoded shape as usual (`dokebi-web.formBody: true`), a 422 (or `data.formErrors`) goes back with `errors` and `old` like any HTML form, other errors render the error views, and REST calls of the page use `sealedFetch` (`@dokebi/seal/http`, the same module instance). **Do not give form routes `seal: false`**: that was the old workaround and leaves the form body plain. A form posted without the module (no JavaScript) gets the HTML 415 page `This page needs its seal script to send forms`. `seal` is a reserved view data key. Example: `examples/45-ejs-seal`. Inertia scopes of apps on sealed domains get `sealed: true`, and combining that with SSR fails the start (`SEAL_SSR_CONFLICT`). Browser: `sealInertia`, `sealedFetch` and `currentSealBridge` of `@dokebi/seal/http` (the CLI template `views/app.js` imports `@dokebi/seal/http` and calls `sealInertia(http)` on sealed pages; `dokebiInertia()` of the generated `vite.config.ts`, from `@dokebi/template-inertia/vite`, makes every import of `@dokebi/seal/http` load the served `/dokebi/seal/http.mjs`, so pages import `sealedFetch` statically and share that seal).
275
+ - **EJS forms on seal hosts (D-0092)**: every EJS page and error view gets **`data.seal`**: `{ head }`, on a seal host the HTML of an import map (`@dokebi/seal/http` → `/dokebi/seal/http.mjs`, `@dokebi/seal/forms` → `/dokebi/seal/forms.mjs`) and the module script of `/dokebi/seal/forms.mjs`, on a plain host `''`. Write **`<%- data.seal.head %>`** in the `<head>` of the layout, before other module scripts (the shared layout of `npx dokebi add @dokebi/template-ejs` does). The forms module sends every POST form sealed with `x-dokebi-form: 1`: handlers read the urlencoded shape as usual (`dokebi-web.formBody: true`), a 422 (or `data.formErrors`) goes back with `errors` and `old` like any HTML form, other errors render the error views, and REST calls of the page use `sealedFetch` (`@dokebi/seal/http`, the same module instance). **Do not give form routes `seal: false`**: that was the old workaround and leaves the form body plain. A form posted without the module (no JavaScript) gets the HTML 415 page `This page needs its seal script to send forms`. `seal` is a reserved view data key. Example: `examples/45-ejs-seal`. Inertia scopes of apps on sealed domains get `sealed: true`; with SSR only public pages (`page.inertia.render(…, { public: true })`, 0.4.6, D-0195) are server rendered there, plain, and every other page stays sealed (template-inertia AI.md §3.5). The scope's `app` and `sealed` props go in as `publicShared` (the same for every visitor), so a public page's SSR knows `app.template`; `AppInertia.render` takes `public` and `head` (`AppInertiaRenderOptions`). Browser: `sealInertia`, `sealedFetch` and `currentSealBridge` of `@dokebi/seal/http` (the CLI template `views/app.js` imports `@dokebi/seal/http` and calls `sealInertia(http)` on sealed pages and on public pages of a seal host (`meta[name="dokebi-seal"][content="host"]`); `dokebiInertia()` of the generated `vite.config.ts`, from `@dokebi/template-inertia/vite`, makes every import of `@dokebi/seal/http` load the served `/dokebi/seal/http.mjs`, so pages import `sealedFetch` statically and share that seal).
276
276
 
277
277
  ## 5. API
278
278
 
package/dist/index.d.ts CHANGED
@@ -35,11 +35,42 @@ export interface AppView {
35
35
  has(name: string): boolean;
36
36
  }
37
37
  /** The Inertia renderer of an app, from the `inertia` view engine (@dokebi/template-inertia). */
38
+ /**
39
+ * The render options of an app's Inertia page (@dokebi/template-inertia `InertiaRenderOptions`;
40
+ * `public` and `head` need template-inertia 0.4.6, D-0195).
41
+ */
42
+ export interface AppInertiaRenderOptions {
43
+ readonly encryptHistory?: boolean;
44
+ readonly clearHistory?: boolean;
45
+ /**
46
+ * A public page: its first HTML is the same for every visitor (no auth, csrf or flash in it;
47
+ * they come right after it through a visit), server rendered on a seal host too when the app
48
+ * has `ssr`. `cacheControl` replaces `no-store` for that HTML.
49
+ */
50
+ readonly public?: boolean | {
51
+ readonly cacheControl?: string;
52
+ };
53
+ /** Head tags of the first HTML: title, description, canonical, robots, alternates, meta. */
54
+ readonly head?: {
55
+ readonly title?: string;
56
+ readonly description?: string;
57
+ readonly canonical?: string;
58
+ readonly robots?: string;
59
+ readonly alternates?: readonly {
60
+ readonly hreflang: string;
61
+ readonly href: string;
62
+ }[];
63
+ readonly meta?: readonly ({
64
+ readonly name: string;
65
+ readonly content: string;
66
+ } | {
67
+ readonly property: string;
68
+ readonly content: string;
69
+ })[];
70
+ };
71
+ }
38
72
  export interface AppInertia {
39
- render(request: FastifyRequest, reply: FastifyReply, component: string, props?: Readonly<Record<string, unknown>>, options?: {
40
- readonly encryptHistory?: boolean;
41
- readonly clearHistory?: boolean;
42
- }): Promise<FastifyReply>;
73
+ render(request: FastifyRequest, reply: FastifyReply, component: string, props?: Readonly<Record<string, unknown>>, options?: AppInertiaRenderOptions): Promise<FastifyReply>;
43
74
  redirect(request: FastifyRequest, reply: FastifyReply, url: string): FastifyReply;
44
75
  location(request: FastifyRequest, reply: FastifyReply, url: string): FastifyReply;
45
76
  /**
package/dist/index.js CHANGED
@@ -730,16 +730,22 @@ class AppRuntime {
730
730
  await this.#servePublic(context, name, definition.views);
731
731
  let inertiaApi;
732
732
  if (definition.inertia) {
733
- inertiaApi = await engine('inertia', name).scope({
733
+ const inertia = engine('inertia', name);
734
+ // `app` and `sealed` are the host's, the same for every visitor: with template-inertia
735
+ // 0.4.6 they go into the first HTML of public pages too (D-0195), where the browser entry
736
+ // and the SSR bundle read `app.template`.
737
+ const hostProps = (request) => {
738
+ const entry = hostEntry(request);
739
+ return { app: entry ? { ...entry.info } : null, sealed: entry?.sealed === true };
740
+ };
741
+ inertiaApi = await inertia.scope({
734
742
  ...definition.inertia,
735
743
  // Named in the scope's log records (INERTIA_VERSION_DEFAULT says which app).
736
744
  app: name,
737
- // SSR would write the props of a sealed host as plain HTML: refused (D-0062).
745
+ // A sealed host's pages leave sealed; with SSR only public first pages are server
746
+ // rendered there (D-0062, D-0195).
738
747
  ...(appSealed ? { sealed: true } : {}),
739
- shared: (request) => {
740
- const entry = hostEntry(request);
741
- return { app: entry ? { ...entry.info } : null, sealed: entry?.sealed === true };
742
- },
748
+ ...(inertia.publicPages === true ? { publicShared: hostProps } : { shared: hostProps }),
743
749
  });
744
750
  }
745
751
  // Names are looked up in the app's templates; a module page looks first in the app's
@@ -1106,7 +1112,7 @@ function missingViews(name) {
1106
1112
  }
1107
1113
  export const createPlugin = definePlugin({
1108
1114
  name: 'dokebi-app',
1109
- version: '0.4.5',
1115
+ version: '0.4.6',
1110
1116
  core: '^0.4.0',
1111
1117
  options: declaration,
1112
1118
  entry: parseEntry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/app",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Multiple apps per project for Dokebi: pick the app and template by request domain, with EJS and Inertia skeletons.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -9,9 +9,15 @@ import { createApp, createSSRApp, h } from 'vue';
9
9
  // @dokebi/seal plugin serves its browser module (/dokebi/seal/http.mjs): it opens the page and
10
10
  // seals every later visit. dokebiInertia() of vite.config.ts makes every import of
11
11
  // '@dokebi/seal/http' load that served file, so pages import sealedFetch and currentSealBridge
12
- // from '@dokebi/seal/http' as usual and share this bootstrap's seal. Plain pages skip this, so a
13
- // project without @dokebi/seal never loads it.
14
- if (document.querySelector('script[data-page][data-sealed="true"]'))
12
+ // from '@dokebi/seal/http' as usual and share this bootstrap's seal. A public page of a seal host
13
+ // (render(…, { public: true }), D-0195) comes plain for crawlers with
14
+ // <meta name="dokebi-seal" content="host">: the visits after it are sealed the same way. Pages of
15
+ // a plain host skip this, so a project without @dokebi/seal never loads it.
16
+ if (
17
+ document.querySelector(
18
+ 'script[data-page][data-sealed="true"], meta[name="dokebi-seal"][content="host"]',
19
+ )
20
+ )
15
21
  await (await import('@dokebi/seal/http')).sealInertia(http);
16
22
 
17
23
  const files = import.meta.glob('./*/{Layout,Pages/**/*}.vue', { eager: true });