@dokebi/app 0.1.2 → 0.4.0

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.
@@ -0,0 +1,16 @@
1
+ import { type OptionsOf } from '@dokebi/core';
2
+ export declare const options: import("@dokebi/core").OptionsDeclaration<{
3
+ readonly apps?: Readonly<Record<string, {
4
+ readonly realtime?: {
5
+ readonly namespaces: readonly string[];
6
+ };
7
+ }>>;
8
+ readonly domains: Readonly<Record<string, {
9
+ readonly app: string;
10
+ readonly seal: boolean;
11
+ readonly template: string;
12
+ }>>;
13
+ readonly unknownDomain?: string;
14
+ }>;
15
+ /** The parsed options of dokebi-app (`options.dokebi-app`). */
16
+ export type AppPluginOptions = OptionsOf<typeof options>;
@@ -0,0 +1,55 @@
1
+ import { defineOptions, option as o } from '@dokebi/core';
2
+ /*
3
+ * Options of dokebi-app (D-0063 §3): one declaration is the parser and, at build time,
4
+ * options.schema.json. The rules are the hand parser's before wave B.
5
+ */
6
+ /** An app, template or namespace name. */
7
+ const NAME = '^[a-z][a-z0-9-]{0,31}$';
8
+ /** A host name without port, lower case. */
9
+ const HOST = '^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$';
10
+ export const options = defineOptions({
11
+ domains: o.record(o.object({
12
+ app: o.string({ pattern: NAME, required: true }),
13
+ template: o.string({
14
+ pattern: NAME,
15
+ default: 'default',
16
+ description: 'Folder under the app views; default: default',
17
+ }),
18
+ seal: o.boolean({
19
+ default: false,
20
+ description: 'Seal this host (D-0059, D-0062): WebSocket frames, HTTP JSON bodies, Inertia pages and SSE data. Needs the dokebi-seal plugin (startup fails with SEAL_PROVIDER_MISSING without it). Pages get `sealed`.',
21
+ }),
22
+ }), {
23
+ required: true,
24
+ keys: { pattern: HOST, maxLength: 253 },
25
+ maxProperties: 1024,
26
+ description: 'Host name (no port, lower case) -> the app and template that answer it',
27
+ }),
28
+ unknownDomain: o.string({
29
+ description: 'reject (404, default) or a key of domains whose app and template answer unknown hosts',
30
+ }),
31
+ apps: o.record(o.object({
32
+ realtime: o.object({
33
+ namespaces: o.array(o.string({ pattern: NAME }), {
34
+ required: true,
35
+ minItems: 1,
36
+ maxItems: 32,
37
+ uniqueItems: true,
38
+ description: 'Realtime namespaces of this app (D-0061); default [<app>]. WebSocket and SSE hub tenants are <namespace>:<tenant>; authenticate may pick one with `namespace` (default the first). Apps sharing a namespace share presence, broadcasts and SSE publications; app.realtime(namespace) reaches any listed one.',
39
+ }),
40
+ }),
41
+ }), {
42
+ keys: { pattern: NAME },
43
+ description: 'Settings per defined app (key = app name; a key that is not a defined app stops startup with UNKNOWN_APP)',
44
+ }),
45
+ }, {
46
+ checks: [
47
+ {
48
+ path: 'unknownDomain',
49
+ message: 'must be reject or a key of domains',
50
+ test: (value) => value.unknownDomain === undefined ||
51
+ value.unknownDomain === 'reject' ||
52
+ Object.hasOwn(value.domains, value.unknownDomain),
53
+ },
54
+ ],
55
+ });
@@ -2,33 +2,79 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "type": "object",
4
4
  "additionalProperties": false,
5
- "required": ["domains"],
6
5
  "properties": {
7
6
  "domains": {
8
7
  "type": "object",
9
- "description": "Host name (no port, lower case) -> the app and template that answer it",
10
- "maxProperties": 1024,
11
8
  "propertyNames": {
12
9
  "pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$",
13
10
  "maxLength": 253
14
11
  },
12
+ "maxProperties": 1024,
15
13
  "additionalProperties": {
16
14
  "type": "object",
17
15
  "additionalProperties": false,
18
- "required": ["app"],
19
16
  "properties": {
20
- "app": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,31}$" },
17
+ "app": {
18
+ "type": "string",
19
+ "pattern": "^[a-z][a-z0-9-]{0,31}$"
20
+ },
21
21
  "template": {
22
22
  "type": "string",
23
23
  "pattern": "^[a-z][a-z0-9-]{0,31}$",
24
+ "default": "default",
24
25
  "description": "Folder under the app views; default: default"
26
+ },
27
+ "seal": {
28
+ "type": "boolean",
29
+ "default": false,
30
+ "description": "Seal this host (D-0059, D-0062): WebSocket frames, HTTP JSON bodies, Inertia pages and SSE data. Needs the dokebi-seal plugin (startup fails with SEAL_PROVIDER_MISSING without it). Pages get `sealed`."
25
31
  }
26
- }
27
- }
32
+ },
33
+ "required": [
34
+ "app"
35
+ ]
36
+ },
37
+ "description": "Host name (no port, lower case) -> the app and template that answer it"
28
38
  },
29
39
  "unknownDomain": {
30
40
  "type": "string",
31
41
  "description": "reject (404, default) or a key of domains whose app and template answer unknown hosts"
42
+ },
43
+ "apps": {
44
+ "type": "object",
45
+ "propertyNames": {
46
+ "pattern": "^[a-z][a-z0-9-]{0,31}$"
47
+ },
48
+ "additionalProperties": {
49
+ "type": "object",
50
+ "additionalProperties": false,
51
+ "properties": {
52
+ "realtime": {
53
+ "type": "object",
54
+ "additionalProperties": false,
55
+ "properties": {
56
+ "namespaces": {
57
+ "type": "array",
58
+ "items": {
59
+ "type": "string",
60
+ "pattern": "^[a-z][a-z0-9-]{0,31}$"
61
+ },
62
+ "minItems": 1,
63
+ "maxItems": 32,
64
+ "uniqueItems": true,
65
+ "description": "Realtime namespaces of this app (D-0061); default [<app>]. WebSocket and SSE hub tenants are <namespace>:<tenant>; authenticate may pick one with `namespace` (default the first). Apps sharing a namespace share presence, broadcasts and SSE publications; app.realtime(namespace) reaches any listed one."
66
+ }
67
+ },
68
+ "required": [
69
+ "namespaces"
70
+ ]
71
+ }
72
+ }
73
+ },
74
+ "description": "Settings per defined app (key = app name; a key that is not a defined app stops startup with UNKNOWN_APP)"
32
75
  }
33
- }
76
+ },
77
+ "required": [
78
+ "domains"
79
+ ]
34
80
  }
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "@dokebi/app",
3
- "version": "0.1.2",
3
+ "version": "0.4.0",
4
+ "description": "Multiple apps per project for Dokebi: pick the app and template by request domain, with EJS and Inertia skeletons.",
5
+ "keywords": [
6
+ "dokebi",
7
+ "dokebi-plugin",
8
+ "web",
9
+ "apps",
10
+ "domains",
11
+ "mvc"
12
+ ],
4
13
  "private": false,
5
14
  "type": "module",
6
15
  "license": "MIT",
@@ -24,67 +33,65 @@
24
33
  "node": ">=24.0.0"
25
34
  },
26
35
  "scripts": {
27
- "build": "tsc -p tsconfig.json",
36
+ "build": "tsc -p tsconfig.json && node -e \"import('./dist/options.js').then(async (m) => { const { renderOptionsSchema } = await import('@dokebi/core'); process.stdout.write(renderOptionsSchema(m.options)); })\" > options.schema.json",
28
37
  "typecheck": "tsc -p tsconfig.test.json --noEmit",
29
- "test": "tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
38
+ "test": "node -e \"require('node:fs').rmSync('.tmp/tests',{recursive:true,force:true})\" && tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
30
39
  },
31
40
  "peerDependencies": {
32
- "@dokebi/controller": "^0.1.0",
33
- "@dokebi/core": "^0.2.0",
34
- "@dokebi/module": "^0.1.0",
35
- "@dokebi/template-ejs": "^0.1.0",
36
- "@dokebi/template-inertia": "^0.1.0",
37
- "@dokebi/web": "^0.1.0",
38
- "@dokebi/websocket": "^0.1.0 || ^0.2.0",
41
+ "@dokebi/controller": "^0.4.0",
42
+ "@dokebi/core": "^0.4.0",
43
+ "@dokebi/module": "^0.4.0",
44
+ "@dokebi/template-ejs": "^0.4.0",
45
+ "@dokebi/web": "^0.4.0",
39
46
  "fastify": "^5.12.7"
40
47
  },
41
48
  "peerDependenciesMeta": {
42
- "@dokebi/template-inertia": {
43
- "optional": true
44
- },
45
- "@dokebi/websocket": {
46
- "optional": true
47
- },
48
49
  "@dokebi/module": {
49
50
  "optional": true
50
51
  }
51
52
  },
52
53
  "devDependencies": {
53
- "@dokebi/module": "^0.1.0",
54
- "@dokebi/template-inertia": "^0.1.0",
55
- "@dokebi/websocket": "^0.1.0 || ^0.2.0"
54
+ "@dokebi/module": "^0.4.0",
55
+ "@dokebi/sse": "^0.4.0",
56
+ "@dokebi/template-ejs": "^0.4.0",
57
+ "@dokebi/template-inertia": "^0.4.0",
58
+ "@dokebi/websocket": "^0.4.0",
59
+ "@dokebi/websocket-hub": "^0.4.0",
60
+ "ws": "8.22.0"
56
61
  },
57
62
  "dokebi": {
58
63
  "schemaVersion": 2,
59
64
  "id": "dokebi-app",
60
- "core": "^0.2.0",
65
+ "core": "^0.4.0",
61
66
  "dependencies": [
62
67
  {
63
68
  "name": "dokebi-web",
64
- "version": "^0.1.0",
69
+ "version": "^0.4.0",
65
70
  "package": "@dokebi/web"
66
71
  },
67
72
  {
68
73
  "name": "dokebi-controller",
69
- "version": "^0.1.0",
74
+ "version": "^0.4.0",
70
75
  "package": "@dokebi/controller"
71
76
  },
72
77
  {
73
78
  "name": "dokebi-template-ejs",
74
- "version": "^0.1.0",
79
+ "version": "^0.4.0",
75
80
  "package": "@dokebi/template-ejs"
76
81
  },
77
82
  {
78
- "name": "dokebi-template-inertia",
79
- "version": "^0.1.0",
80
- "optional": true
81
- },
82
- {
83
- "name": "dokebi-websocket",
84
- "version": "^0.1.0 || ^0.2.0",
83
+ "name": "dokebi-seal",
84
+ "version": "^0.4.0",
85
85
  "optional": true
86
86
  }
87
87
  ],
88
+ "collects": [
89
+ "dokebi-web:view-engine",
90
+ "dokebi-web:realtime"
91
+ ],
92
+ "hosts": [
93
+ "apps"
94
+ ],
88
95
  "optionsSchema": "options.schema.json",
89
96
  "documentation": "AI.md",
90
97
  "install": {
@@ -94,6 +101,22 @@
94
101
  ]
95
102
  }
96
103
  },
104
+ "dokebiCatalog": {
105
+ "kind": "plugin",
106
+ "summary": "Several apps chosen by request domain (src/apps/<app>) with a template each; installs web, controller and template-ejs with it",
107
+ "maturity": "preview",
108
+ "provides": [
109
+ "web.apps"
110
+ ],
111
+ "doesNot": [
112
+ "No login, permissions or admin screens",
113
+ "No React skeleton (EJS and Inertia Vue only)"
114
+ ],
115
+ "recipes": [
116
+ "api",
117
+ "blog"
118
+ ]
119
+ },
97
120
  "publishConfig": {
98
121
  "access": "public",
99
122
  "registry": "https://registry.npmjs.org/"
@@ -0,0 +1,7 @@
1
+ <%# This app's page for an unknown address (D-0074). Browser pages only: scripts, fetch and
2
+ Inertia get JSON. Data: status, title, error, message, hint, fields, fix (development). %>
3
+ <main>
4
+ <h1>Page not found</h1>
5
+ <p><%= data.hint %></p>
6
+ <p><a href="/">Home</a></p>
7
+ </main>
@@ -0,0 +1,14 @@
1
+ <%# Every other error page of this app (D-0074): 403, 500, an HTML form refused with 422 (the
2
+ fields are listed). Make errors/<status>.ejs for a status that needs its own page. %>
3
+ <main>
4
+ <h1><%= data.title %></h1>
5
+ <p><% if (data.message) { %><%= data.message %><% } %></p>
6
+ <% if (data.hint) { %><p><%= data.hint %></p><% } %>
7
+ <% if (data.fields.length) { %>
8
+ <ul>
9
+ <% for (const field of data.fields) { %><li><%= field.field %>: <%= field.message %></li><% } %>
10
+ </ul>
11
+ <% } %>
12
+ <% if (data.fix) { %><pre><%= data.fix %></pre><% } %>
13
+ <p><a href="/">Home</a></p>
14
+ </main>
@@ -14,6 +14,9 @@ export default defineApp({
14
14
  // @dokebi/template-inertia serves the built files at /build/.
15
15
  inertia: {
16
16
  title: '{{app}}',
17
+ // Error answers of Inertia visits and page loads render views/<template>/Pages/Error.vue with
18
+ // { status, error, message, hint } (D-0074). Validation errors go back to the form instead.
19
+ errorPage: 'Error',
17
20
  vite: {
18
21
  manifest: 'dist/.vite/manifest.json',
19
22
  entry: 'src/apps/{{app}}/views/app.js',
@@ -1,9 +1,15 @@
1
1
  // Browser entry of this app (Vite input). Pages and the layout are looked up in the template the
2
2
  // domain selected and then in `default`, like the EJS views. The template comes from the shared
3
3
  // prop `app.template` (dokebi-app) of the first page; it is fixed for a domain.
4
- import { createInertiaApp } from '@inertiajs/vue3';
4
+ import { createInertiaApp, http } from '@inertiajs/vue3';
5
5
  import { createApp, createSSRApp, h } from 'vue';
6
6
 
7
+ // A seal host (`seal: true` in dokebi-app domains, D-0062) sends the first page sealed. The
8
+ // @dokebi/seal plugin serves its browser module: it opens the page and seals every later visit.
9
+ // Plain pages skip this, so a project without @dokebi/seal never loads it.
10
+ if (document.querySelector('script[data-page][data-sealed="true"]'))
11
+ await (await import(/* @vite-ignore */ '/dokebi/seal/http.mjs')).sealInertia(http);
12
+
7
13
  const files = import.meta.glob('./*/{Layout,Pages/*}.vue', { eager: true });
8
14
  const first = JSON.parse(document.querySelector('script[data-page]')?.textContent || '{}');
9
15
  const template = first.props?.app?.template ?? 'default';
@@ -0,0 +1,12 @@
1
+ <script setup>
2
+ // The error page of this app (`errorPage: 'Error'` in app.ts, D-0074): an unknown address, a
3
+ // forbidden page or a server error, for Inertia visits and page loads alike. Validation errors
4
+ // never come here: they go back to the form, in `form.errors`.
5
+ defineProps({ status: Number, error: String, message: String, hint: String });
6
+ </script>
7
+ <template>
8
+ <h1>{{ status === 404 ? 'Page not found' : `Error ${status}` }}</h1>
9
+ <p v-if="hint">{{ hint }}</p>
10
+ <p v-else-if="message">{{ message }}</p>
11
+ <p><a href="/">Home</a></p>
12
+ </template>
@@ -15,6 +15,9 @@ export default defineApp({
15
15
  // vite.ssr.config.ts). @dokebi/template-inertia serves the browser files at /build/.
16
16
  inertia: {
17
17
  title: '{{app}}',
18
+ // Error answers of Inertia visits and page loads render views/<template>/Pages/Error.vue with
19
+ // { status, error, message, hint } (D-0074). Validation errors go back to the form instead.
20
+ errorPage: 'Error',
18
21
  ssr: { bundle: 'dist/ssr/{{app}}/ssr.js' },
19
22
  vite: {
20
23
  manifest: 'dist/.vite/manifest.json',