@dokebi/app 0.2.0 → 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,34 +2,39 @@
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"
25
26
  },
26
27
  "seal": {
27
28
  "type": "boolean",
28
29
  "default": false,
29
- "description": "Seal every WebSocket frame on this host (D-0059): needs the private dokebi-seal plugin (startup fails with SEAL_PROVIDER_MISSING without it); clients must use the seal bridge or are closed with 4415. Pages get `sealed`."
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`."
30
31
  }
31
- }
32
- }
32
+ },
33
+ "required": [
34
+ "app"
35
+ ]
36
+ },
37
+ "description": "Host name (no port, lower case) -> the app and template that answer it"
33
38
  },
34
39
  "unknownDomain": {
35
40
  "type": "string",
@@ -37,7 +42,6 @@
37
42
  },
38
43
  "apps": {
39
44
  "type": "object",
40
- "description": "Settings per defined app (key = app name; a key that is not a defined app stops startup with UNKNOWN_APP)",
41
45
  "propertyNames": {
42
46
  "pattern": "^[a-z][a-z0-9-]{0,31}$"
43
47
  },
@@ -48,23 +52,29 @@
48
52
  "realtime": {
49
53
  "type": "object",
50
54
  "additionalProperties": false,
51
- "required": ["namespaces"],
52
55
  "properties": {
53
56
  "namespaces": {
54
57
  "type": "array",
55
- "minItems": 1,
56
- "maxItems": 32,
57
- "uniqueItems": true,
58
58
  "items": {
59
59
  "type": "string",
60
60
  "pattern": "^[a-z][a-z0-9-]{0,31}$"
61
61
  },
62
+ "minItems": 1,
63
+ "maxItems": 32,
64
+ "uniqueItems": true,
62
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."
63
66
  }
64
- }
67
+ },
68
+ "required": [
69
+ "namespaces"
70
+ ]
65
71
  }
66
72
  }
67
- }
73
+ },
74
+ "description": "Settings per defined app (key = app name; a key that is not a defined app stops startup with UNKNOWN_APP)"
68
75
  }
69
- }
76
+ },
77
+ "required": [
78
+ "domains"
79
+ ]
70
80
  }
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "@dokebi/app",
3
- "version": "0.2.0",
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,84 +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/sse": "^0.1.0",
36
- "@dokebi/template-ejs": "^0.1.0",
37
- "@dokebi/template-inertia": "^0.2.0",
38
- "@dokebi/web": "^0.2.0",
39
- "@dokebi/websocket": "^0.1.0 || ^0.2.0 || ^0.3.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",
40
46
  "fastify": "^5.12.7"
41
47
  },
42
48
  "peerDependenciesMeta": {
43
- "@dokebi/template-inertia": {
44
- "optional": true
45
- },
46
- "@dokebi/websocket": {
47
- "optional": true
48
- },
49
49
  "@dokebi/module": {
50
50
  "optional": true
51
- },
52
- "@dokebi/sse": {
53
- "optional": true
54
51
  }
55
52
  },
56
53
  "devDependencies": {
57
- "@dokebi/module": "^0.1.0",
58
- "@dokebi/sse": "^0.1.0",
59
- "@dokebi/template-inertia": "^0.2.0",
60
- "@dokebi/websocket": "^0.1.0 || ^0.2.0 || ^0.3.0",
61
- "@dokebi/websocket-hub": "^0.3.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",
62
60
  "ws": "8.22.0"
63
61
  },
64
62
  "dokebi": {
65
63
  "schemaVersion": 2,
66
64
  "id": "dokebi-app",
67
- "core": "^0.2.0",
65
+ "core": "^0.4.0",
68
66
  "dependencies": [
69
67
  {
70
68
  "name": "dokebi-web",
71
- "version": "^0.2.0",
69
+ "version": "^0.4.0",
72
70
  "package": "@dokebi/web"
73
71
  },
74
72
  {
75
73
  "name": "dokebi-controller",
76
- "version": "^0.1.0",
74
+ "version": "^0.4.0",
77
75
  "package": "@dokebi/controller"
78
76
  },
79
77
  {
80
78
  "name": "dokebi-template-ejs",
81
- "version": "^0.1.0",
79
+ "version": "^0.4.0",
82
80
  "package": "@dokebi/template-ejs"
83
81
  },
84
- {
85
- "name": "dokebi-template-inertia",
86
- "version": "^0.2.0",
87
- "optional": true
88
- },
89
- {
90
- "name": "dokebi-websocket",
91
- "version": "^0.1.0 || ^0.2.0 || ^0.3.0",
92
- "optional": true
93
- },
94
82
  {
95
83
  "name": "dokebi-seal",
96
- "version": "^0.1.0",
97
- "optional": true
98
- },
99
- {
100
- "name": "dokebi-sse",
101
- "version": "^0.1.0",
84
+ "version": "^0.4.0",
102
85
  "optional": true
103
86
  }
104
87
  ],
88
+ "collects": [
89
+ "dokebi-web:view-engine",
90
+ "dokebi-web:realtime"
91
+ ],
92
+ "hosts": [
93
+ "apps"
94
+ ],
105
95
  "optionsSchema": "options.schema.json",
106
96
  "documentation": "AI.md",
107
97
  "install": {
@@ -111,6 +101,22 @@
111
101
  ]
112
102
  }
113
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
+ },
114
120
  "publishConfig": {
115
121
  "access": "public",
116
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',
@@ -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',