@aotter/mantle 0.1.2-alpha.6 → 0.1.2

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.
Files changed (110) hide show
  1. package/README.md +15 -10
  2. package/dist/cli/generate.d.ts +9 -0
  3. package/dist/cli/generate.d.ts.map +1 -1
  4. package/dist/cli/generate.js +40 -1
  5. package/dist/cli/generate.js.map +1 -1
  6. package/dist/cli/main.d.ts +1 -1
  7. package/dist/cli/main.d.ts.map +1 -1
  8. package/dist/cli/main.js +37 -9
  9. package/dist/cli/main.js.map +1 -1
  10. package/docs/adapter-guide.md +6 -1
  11. package/docs/adr/adr-lite-845-frontend-client.md +38 -0
  12. package/docs/agent-prompts.md +91 -0
  13. package/docs/api-mcp-authorization.md +1 -1
  14. package/docs/auth-hosting-model.md +1 -1
  15. package/docs/examples/README.md +22 -0
  16. package/docs/examples/builtin-commerce.md +269 -0
  17. package/docs/examples/builtin-intake.md +143 -0
  18. package/docs/examples/builtin-legal-documents.md +189 -0
  19. package/docs/examples/builtin-procurement.md +241 -0
  20. package/docs/examples/builtin-publication.md +241 -0
  21. package/docs/examples/builtin-reservation.md +149 -0
  22. package/docs/examples/cf-primitives-commerce-inventory.md +809 -0
  23. package/docs/examples/cf-primitives-guarded-api.md +429 -0
  24. package/docs/examples/cf-primitives-intake-hooks.md +319 -0
  25. package/docs/examples/host-chatgpt-sites/.openai/hosting.json +1 -0
  26. package/docs/examples/host-chatgpt-sites/README.md +53 -0
  27. package/docs/examples/host-chatgpt-sites/drizzle/0000_sites_users.sql +8 -0
  28. package/docs/examples/host-chatgpt-sites/drizzle/0001_mantle.sql +294 -0
  29. package/docs/examples/host-chatgpt-sites/drizzle/0002_article_cover.sql +5 -0
  30. package/docs/examples/host-chatgpt-sites/drizzle/meta/_journal.json +1 -0
  31. package/docs/examples/host-chatgpt-sites/manifests/site.yaml +27 -0
  32. package/docs/examples/host-chatgpt-sites/package.json +1 -0
  33. package/docs/examples/host-chatgpt-sites/public/site.css +1 -0
  34. package/docs/examples/host-chatgpt-sites/scripts/build.mjs +12 -0
  35. package/docs/examples/host-chatgpt-sites/scripts/check.mjs +99 -0
  36. package/docs/examples/host-chatgpt-sites/scripts/migration.mjs +9 -0
  37. package/docs/examples/host-chatgpt-sites/src/chatgpt-auth.ts +63 -0
  38. package/docs/examples/host-chatgpt-sites/src/index.ts +46 -0
  39. package/docs/examples/host-chatgpt-sites/src/mcp.ts +49 -0
  40. package/docs/examples/host-chatgpt-sites/src/media.ts +109 -0
  41. package/docs/examples/host-chatgpt-sites/src/r2-lab.ts +38 -0
  42. package/docs/examples/host-chatgpt-sites/src/storage-fingerprint.json +1 -0
  43. package/docs/examples/host-chatgpt-sites/src/web.ts +35 -0
  44. package/docs/examples/host-chatgpt-sites/tsconfig.json +1 -0
  45. package/docs/examples/host-chatgpt-sites/wrangler.jsonc +10 -0
  46. package/docs/examples/host-local-admin-otp/.dev.vars.example +3 -0
  47. package/docs/examples/host-local-admin-otp/README.md +70 -0
  48. package/docs/examples/host-local-admin-otp/ensure-dev-vars.mjs +5 -0
  49. package/docs/examples/host-local-admin-otp/package.json +29 -0
  50. package/docs/examples/host-local-admin-otp/public/.gitkeep +1 -0
  51. package/docs/examples/host-local-admin-otp/smoke.mjs +141 -0
  52. package/docs/examples/host-local-admin-otp/src/index.ts +54 -0
  53. package/docs/examples/host-local-admin-otp/wrangler.jsonc +23 -0
  54. package/docs/examples/{minimal-worker → host-minimal-worker}/README.md +9 -5
  55. package/docs/examples/host-minimal-worker/manifests/site.yaml +25 -0
  56. package/docs/examples/{minimal-worker → host-minimal-worker}/package.json +3 -3
  57. package/docs/examples/host-minimal-worker/tsconfig.json +17 -0
  58. package/docs/handbook/cloudflare/authentication.md +17 -2
  59. package/docs/handbook/cloudflare/bindings.md +9 -7
  60. package/docs/handbook/cloudflare/chatgpt-sites.md +29 -0
  61. package/docs/handbook/cloudflare/conventional-worker.md +3 -3
  62. package/docs/handbook/cloudflare/deferred-hooks-queues.md +0 -1
  63. package/docs/handbook/cloudflare/deploy-and-operate.md +14 -20
  64. package/docs/handbook/cloudflare/media-r2.md +2 -2
  65. package/docs/handbook/cloudflare/public-web.md +1 -1
  66. package/docs/handbook/cloudflare/site-chrome.md +75 -0
  67. package/docs/handbook/concepts/authorization.md +2 -2
  68. package/docs/handbook/concepts/four-atoms.md +2 -2
  69. package/docs/handbook/concepts/lifecycle-and-locales.md +1 -1
  70. package/docs/handbook/concepts/mcp-and-agents.md +1 -1
  71. package/docs/handbook/concepts/procedures-and-triggers.md +1 -1
  72. package/docs/handbook/concepts/runtime-and-adapters.md +2 -2
  73. package/docs/handbook/concepts/views.md +2 -2
  74. package/docs/handbook/examples/commerce-transaction.md +4 -806
  75. package/docs/handbook/examples/commerce.md +11 -0
  76. package/docs/handbook/examples/guarded-api.md +3 -420
  77. package/docs/handbook/examples/hub.md +10 -0
  78. package/docs/handbook/examples/intake-form.md +6 -313
  79. package/docs/handbook/examples/intake-hooks.md +11 -0
  80. package/docs/handbook/examples/legal-documents.md +3 -211
  81. package/docs/handbook/examples/procurement-approvals.md +3 -233
  82. package/docs/handbook/examples/publication.md +3 -233
  83. package/docs/handbook/examples/reservation.md +3 -213
  84. package/docs/handbook/navigation.json +17 -2
  85. package/docs/handbook/reference/authorization.md +1 -1
  86. package/docs/handbook/reference/procedure.md +2 -2
  87. package/docs/handbook/reference/schema.md +3 -3
  88. package/docs/handbook/reference/site-config.md +5 -16
  89. package/docs/handbook/reference/surface.md +3 -7
  90. package/docs/handbook/sites/equipment-checkout.md +231 -0
  91. package/docs/handbook/sites/host-reference.md +113 -0
  92. package/docs/handbook/sites/index.md +111 -0
  93. package/docs/handbook/start/project-and-cli.md +22 -14
  94. package/docs/handbook/start/quickstart-admin.md +239 -0
  95. package/docs/handbook/start/quickstart-worker.md +22 -23
  96. package/docs/migration-0.1.2.md +26 -0
  97. package/docs/release-process.md +92 -7
  98. package/docs/sealed-pipeline-ownership.md +2 -2
  99. package/docs/spec-only-host-adoption.md +3 -4
  100. package/docs/transaction-patterns.md +2 -2
  101. package/package.json +15 -15
  102. package/skills/README.md +18 -2
  103. package/skills/develop/SKILL.md +32 -23
  104. package/skills/install/SKILL.md +50 -11
  105. package/skills/provision/SKILL.md +21 -5
  106. /package/docs/examples/{minimal-worker → host-local-admin-otp}/manifests/site.yaml +0 -0
  107. /package/docs/examples/{minimal-worker → host-local-admin-otp}/tsconfig.json +0 -0
  108. /package/docs/examples/{minimal-worker → host-minimal-worker}/smoke.mjs +0 -0
  109. /package/docs/examples/{minimal-worker → host-minimal-worker}/src/index.ts +0 -0
  110. /package/docs/examples/{minimal-worker → host-minimal-worker}/wrangler.jsonc +0 -0
@@ -0,0 +1,241 @@
1
+ ---
2
+ description: Members submit purchase requisitions they can only see themselves; staff review them with optimistic concurrency.
3
+ ---
4
+ # Procurement approvals with member and staff roles
5
+
6
+ **Handler class:** builtin · **Builder:** yes · [Examples hub](./README.md).
7
+
8
+ This example separates two audiences: signed-in members who submit and track their own requisitions, and staff who approve or reject them. Every Procedure is `handler.kind: builtin`. Read it if you need per-user rows and a staff decision step.
9
+
10
+ ## Problem
11
+
12
+ A signed-in member submits a purchase requisition: a request number, an item, a quantity, a need-by date and a justification. The member sees only their own requisitions and their current status. Staff with the `owner` or `editor` role see the queue of `submitted` requisitions ordered by need-by date and mark each `approved` or `rejected` with a note. Two reviewers must not silently overwrite each other's decision. Requisitions are live operational records.
13
+
14
+ ## Manifest
15
+
16
+ ```yaml
17
+ apiVersion: cms.mantle.aotter.net/v1
18
+ kind: Schema
19
+ metadata:
20
+ name: purchase-requisitions
21
+ spec:
22
+ title: Purchase requisitions
23
+ description: Member-submitted purchase needs waiting for staff review.
24
+ lifecycle: operational
25
+ uniqueIndexes:
26
+ - [requestNumber]
27
+ indexes:
28
+ - [requestedBy, requestedAt]
29
+ - [requestStatus, needBy]
30
+ schema:
31
+ type: object
32
+ additionalProperties: false
33
+ required: [requestNumber, requestedBy, item, quantity, needBy, justification, requestStatus, requestedAt]
34
+ properties:
35
+ requestNumber: { type: string, pattern: "^REQ-[A-Z0-9-]+$" }
36
+ requestedBy: { type: string, x-mantle-bind: ctx.user }
37
+ item: { type: string, minLength: 1, maxLength: 160 }
38
+ quantity: { type: integer, minimum: 1 }
39
+ needBy: { type: number, x-mcp-hint: timestamp-ms }
40
+ justification: { type: string, minLength: 1, maxLength: 1000 }
41
+ requestStatus: { type: string, enum: [submitted, approved, rejected] }
42
+ reviewerNote: { type: string, maxLength: 1000 }
43
+ requestedAt: { type: number, x-mcp-hint: timestamp-ms, x-mantle-bind: now }
44
+ ---
45
+ apiVersion: cms.mantle.aotter.net/v1
46
+ kind: View
47
+ metadata:
48
+ name: my-requisitions
49
+ spec:
50
+ title: My requisitions
51
+ surface: public
52
+ from: purchase-requisitions
53
+ requires:
54
+ auth:
55
+ all: [ctx.user]
56
+ fields: [id, requestNumber, item, quantity, needBy, justification, requestStatus, reviewerNote, requestedAt]
57
+ filter:
58
+ eq: { field: requestedBy, value: { "$ctx.user": id } }
59
+ orderBy:
60
+ - { field: requestedAt, direction: desc }
61
+ limit: 100
62
+ ---
63
+ apiVersion: cms.mantle.aotter.net/v1
64
+ kind: View
65
+ metadata:
66
+ name: pending-approvals
67
+ spec:
68
+ title: Pending approvals
69
+ surface: staff
70
+ from: purchase-requisitions
71
+ requires:
72
+ auth:
73
+ all:
74
+ - { "ctx.staff": [owner, editor] }
75
+ fields: [id, version, requestNumber, requestedBy, item, quantity, needBy, justification, requestedAt]
76
+ filter:
77
+ eq: { field: requestStatus, value: submitted }
78
+ orderBy:
79
+ - { field: needBy, direction: asc }
80
+ limit: 100
81
+ ---
82
+ apiVersion: cms.mantle.aotter.net/v1
83
+ kind: Procedure
84
+ metadata:
85
+ name: submit-requisition
86
+ spec:
87
+ title: Submit requisition
88
+ requires:
89
+ auth:
90
+ all: [ctx.user]
91
+ input:
92
+ type: object
93
+ additionalProperties: false
94
+ required: [requestNumber, item, quantity, needBy, justification, requestStatus]
95
+ properties:
96
+ requestNumber: { type: string, pattern: "^REQ-[A-Z0-9-]+$" }
97
+ item: { type: string, minLength: 1, maxLength: 160 }
98
+ quantity: { type: integer, minimum: 1 }
99
+ needBy: { type: number, x-mcp-hint: timestamp-ms }
100
+ justification: { type: string, minLength: 1, maxLength: 1000 }
101
+ requestStatus: { type: string, enum: [submitted] }
102
+ output: { type: object }
103
+ handler: { kind: builtin, op: create, schema: purchase-requisitions }
104
+ ---
105
+ apiVersion: cms.mantle.aotter.net/v1
106
+ kind: Procedure
107
+ metadata:
108
+ name: review-requisition
109
+ spec:
110
+ title: Review requisition
111
+ requires:
112
+ auth:
113
+ all:
114
+ - { "ctx.staff": [owner, editor] }
115
+ input:
116
+ type: object
117
+ additionalProperties: false
118
+ required: [id, expectedVersion, requestStatus]
119
+ properties:
120
+ id: { type: string }
121
+ expectedVersion: { type: number, minimum: 1 }
122
+ requestStatus: { type: string, enum: [approved, rejected] }
123
+ reviewerNote: { type: string, maxLength: 1000 }
124
+ output: { type: object }
125
+ handler: { kind: builtin, op: update, schema: purchase-requisitions }
126
+ ---
127
+ apiVersion: cms.mantle.aotter.net/v1
128
+ kind: Trigger
129
+ metadata:
130
+ name: submit-requisition-http
131
+ spec:
132
+ source: { kind: http, method: POST, path: /api/requisitions }
133
+ target: { procedure: submit-requisition }
134
+ ---
135
+ apiVersion: cms.mantle.aotter.net/v1
136
+ kind: Trigger
137
+ metadata:
138
+ name: submit-requisition-mcp
139
+ spec:
140
+ source: { kind: mcp, surface: public }
141
+ target: { procedure: submit-requisition }
142
+ ---
143
+ apiVersion: cms.mantle.aotter.net/v1
144
+ kind: Trigger
145
+ metadata:
146
+ name: review-requisition-mcp
147
+ spec:
148
+ source: { kind: mcp, surface: staff }
149
+ target: { procedure: review-requisition }
150
+ ```
151
+
152
+ ### Ownership without trusting the caller
153
+
154
+ `requestedBy` carries `x-mantle-bind: ctx.user`. On create the server stamps the signed-in user's id and ignores any caller value; on update the stamp is preserved. `requestedAt` is stamped the same way with `now`. Because both are in `required`, and because `submit-requisition` requires `ctx.user`, an anonymous caller is rejected with `UNAUTHENTICATED` before the row is even projected.
155
+
156
+ `my-requisitions` filters with the closed sentinel `{ "$ctx.user": id }`. The caller never supplies this value, so the same View is safe over REST and public MCP. Three rules make the sentinel legal, and the parser enforces each:
157
+
158
+ | Rule | Diagnostic when violated |
159
+ |---|---|
160
+ | The View's `requires.auth.all` includes `ctx.user` | `VIEW_FILTER_CTX_USER_REF_REQUIRES_AUTH` |
161
+ | The sentinel appears only under `eq`, as a single-key object whose value is the literal `id` | `VIEW_FILTER_CTX_USER_REF_INVALID` |
162
+ | The filtered field is the leftmost field of a declared index (`[requestedBy, requestedAt]` here) | `VIEW_FILTER_CTX_USER_REF_REQUIRES_INDEX` |
163
+
164
+ A missing identity fails with 401; the runtime never drops the filter and never falls back to all rows.
165
+
166
+ `pending-approvals` uses the staff predicate `{ "ctx.staff": [owner, editor] }`. It includes `version` in `fields` so a reviewer can pass it back as `expectedVersion`.
167
+
168
+ ### Optimistic concurrency
169
+
170
+ `review-requisition` is a builtin `update`. Its input must declare `id` (string) and `expectedVersion` (number) in `required`; the parser rejects the Manifest otherwise. `expectedVersion` is the version the reviewer **read**, not that value plus one. At runtime the row is loaded, the patch is merged over existing data (omitted fields and server stamps survive), and the write is applied only if the stored version equals `expectedVersion`. A stale version fails with `CONFLICT` (HTTP 409) and nothing changes; the reviewer re-reads and decides again. Admin binds and hides `expectedVersion` on row-bound forms. `requestStatus` is narrowed to `approved | rejected`, so this Procedure cannot move a row back to `submitted`.
171
+
172
+ ### Review operation
173
+
174
+ `pending-approvals` exposes the entry `id` and `version` required by `review-requisition`. Drive reviews from that View through Staff MCP or `POST /admin/api/operations/review-requisition`.
175
+
176
+ The Procedure deliberately does not mark `id` with `x-mantle-ref`. This Schema's lone single-field unique index is `[requestNumber]`; a row-bound Admin action would therefore prefill the reference with the request number, while builtin `update` requires the entry id. Leaving the field unbound keeps every advertised path executable instead of publishing a row action that returns `NOT_FOUND`.
177
+
178
+ See [Authorization](../handbook/concepts/authorization.md) and the [Procedure reference](../handbook/reference/procedure.md).
179
+
180
+ ## Worker and handlers
181
+
182
+ None. Both Procedures are builtin and the Worker is `export default createMantleWorker({ plan })`. Sign-in is provided by the conventional Worker's Auth; see [Authentication](../handbook/cloudflare/authentication.md).
183
+
184
+ ## Try it
185
+
186
+ Anonymous read of the member View:
187
+
188
+ ```sh
189
+ curl -i http://localhost:8787/api/views/my-requisitions
190
+ ```
191
+
192
+ ```txt
193
+ HTTP/1.1 401 Unauthorized
194
+ {"ok":false,"diagnostic":{"code":"UNAUTHENTICATED","phase":"runtime","severity":"error","path":"...#/requires/auth/all/0", ...}}
195
+ ```
196
+
197
+ Signed in (session cookie), the same request returns only rows whose `requestedBy` equals the caller's id:
198
+
199
+ ```sh
200
+ curl -sS http://localhost:8787/api/views/my-requisitions \
201
+ -H "cookie: $SESSION_COOKIE"
202
+ # {"ok":true,"data":{"rows":[{"id":"pr_01j...","requestNumber":"REQ-2026-0001","item":"Standing desk","quantity":1,"needBy":1791475200000,"justification":"...","requestStatus":"submitted","requestedAt":1788879363492}],"page":1,"show":100,"hasMore":false}}
203
+ ```
204
+
205
+ Submit as a member (mutations authenticated by a session cookie also pass a same-origin check):
206
+
207
+ ```sh
208
+ curl -sS -X POST http://localhost:8787/api/requisitions \
209
+ -H 'content-type: application/json' -H "cookie: $SESSION_COOKIE" \
210
+ -d '{"requestNumber":"REQ-2026-0002","item":"Monitor arm","quantity":2,"needBy":1791475200000,"justification":"Second screen for review work.","requestStatus":"submitted"}'
211
+ ```
212
+
213
+ The response is `{ ok: true, data: <EntryRow> }`; `data.requestedBy` is the caller's id even if the body tried to set it. A duplicate `requestNumber` is HTTP 409 `CONFLICT`.
214
+
215
+ Staff review through Staff MCP on `/mcp/staff`. First `query_view_pending_approvals` returns `id` and `version`; then:
216
+
217
+ ```json
218
+ {
219
+ "jsonrpc": "2.0", "id": 2, "method": "tools/call",
220
+ "params": {
221
+ "name": "review_requisition",
222
+ "arguments": { "id": "pr_01j...", "expectedVersion": 1, "requestStatus": "approved", "reviewerNote": "Within budget." }
223
+ }
224
+ }
225
+ ```
226
+
227
+ A second reviewer replaying `expectedVersion: 1` after that succeeds receives a JSON-RPC error whose `error.data.code` is `CONFLICT`. A contributor-role session is denied with `AUTH_DENIED`. `review_requisition` appears only in `tools/list` on `/mcp/staff`; the public surface lists `submit_requisition` and `query_view_my_requisitions`.
228
+
229
+ ## What this deliberately leaves out
230
+
231
+ - **Multi-step approval chains.** One decision by one staff member. Sequential approvers would add a step field, more enum states and a `before_update` hook that validates the transition.
232
+ - **Budgets.** No cost field and no per-department limit; add a `ref` guard Procedure when a live check is needed.
233
+ - **Notifications.** Neither the submitter nor the reviewer is emailed. The [intake form](./cf-primitives-intake-hooks.md) shows the `after_create` pattern.
234
+
235
+ Related: [Guarded API access](./cf-primitives-guarded-api.md) covers credentials and scopes for non-browser callers.
236
+
237
+ ## Source
238
+
239
+ - [Procedure reference](../handbook/reference/procedure.md) — `x-mantle-bind`, `x-mantle-ref`, builtin `update` contract, RBAC
240
+ - [`packages/mantle-admin/src/mountMantleAdmin.ts`](../../packages/mantle-admin/src/mountMantleAdmin.ts) — `discoverRowBindings` and `rowField` derivation
241
+ - [`packages/mantle-runtime/src/domain/service/AuthPredicateEvaluator.ts`](../../packages/mantle-runtime/src/domain/service/AuthPredicateEvaluator.ts) — `UNAUTHENTICATED` versus `AUTH_DENIED`
@@ -0,0 +1,241 @@
1
+ ---
2
+ description: Localized blog posts with a stable parent identity, a public per-locale list and an optional reader suggestion box.
3
+ ---
4
+ # Publication: localized posts with a public list
5
+
6
+ **Handler class:** builtin · **Builder:** yes · [Examples hub](./README.md).
7
+
8
+ This example publishes posts in several languages, serves a public list per locale, and accepts reader suggestions. It is fully declarative: every Procedure is `handler.kind: builtin`. Read it if you run a blog, a news section or any authored, translated content.
9
+
10
+ ## Problem
11
+
12
+ Editors draft posts in one or more locales, review them in Admin, and publish each language version independently. Every language version of a post shares one stable identity (its slug) so the site can link translations together and Admin can show translation completeness. Visitors read a per-locale list of published posts, newest first, over REST and public MCP. Readers may suggest topics; those suggestions are live records staff read in Admin, not content that is published.
13
+
14
+ ## Manifest
15
+
16
+ ```yaml
17
+ apiVersion: cms.mantle.aotter.net/v1
18
+ kind: Schema
19
+ metadata:
20
+ name: posts
21
+ spec:
22
+ title: Posts
23
+ description: Stable post identities shared by every language version.
24
+ localized: false
25
+ lifecycle: publishing
26
+ uniqueIndexes:
27
+ - [slug]
28
+ schema:
29
+ type: object
30
+ required: [slug]
31
+ properties:
32
+ slug: { type: string, pattern: "^[a-z0-9-]+$" }
33
+ ---
34
+ apiVersion: cms.mantle.aotter.net/v1
35
+ kind: Schema
36
+ metadata:
37
+ name: post-translations
38
+ spec:
39
+ title: Post translations
40
+ description: Localized titles and bodies for each post.
41
+ localized: true
42
+ translates:
43
+ parent: posts
44
+ on: slug
45
+ lifecycle: publishing
46
+ uniqueIndexes:
47
+ - [slug, locale]
48
+ indexes:
49
+ - [locale, publishedAt]
50
+ schema:
51
+ type: object
52
+ required: [slug, locale, title, publishedAt]
53
+ properties:
54
+ slug: { type: string, pattern: "^[a-z0-9-]+$" }
55
+ locale: { type: string }
56
+ title: { type: string }
57
+ excerpt: { type: string }
58
+ body: { type: string, x-mcp-hint: markdown }
59
+ publishedAt: { type: number, x-mcp-hint: timestamp-ms }
60
+ ---
61
+ apiVersion: cms.mantle.aotter.net/v1
62
+ kind: View
63
+ metadata:
64
+ name: published-posts
65
+ spec:
66
+ title: Published posts
67
+ surface: public
68
+ from: post-translations
69
+ params:
70
+ type: object
71
+ additionalProperties: false
72
+ required: [locale]
73
+ properties:
74
+ locale: { type: string }
75
+ fields: [id, slug, locale, title, excerpt, body, publishedAt, updatedAt]
76
+ filter:
77
+ and:
78
+ - eq: { field: status, value: published }
79
+ - eq: { field: locale, value: { $param: locale } }
80
+ - gte: { field: publishedAt, value: 0 }
81
+ orderBy:
82
+ - { field: publishedAt, direction: desc }
83
+ limit: 50
84
+ ---
85
+ apiVersion: cms.mantle.aotter.net/v1
86
+ kind: Schema
87
+ metadata:
88
+ name: post-suggestions
89
+ spec:
90
+ title: Post suggestions
91
+ description: Reader suggestions for future posts.
92
+ lifecycle: operational
93
+ schema:
94
+ type: object
95
+ required: [title, email]
96
+ properties:
97
+ title: { type: string }
98
+ email: { type: string, format: email }
99
+ note: { type: string }
100
+ createdAt: { type: integer, x-mcp-hint: timestamp-ms, x-mantle-bind: now }
101
+ ---
102
+ apiVersion: cms.mantle.aotter.net/v1
103
+ kind: Procedure
104
+ metadata:
105
+ name: submit-post-suggestion
106
+ spec:
107
+ input:
108
+ type: object
109
+ additionalProperties: false
110
+ required: [title, email]
111
+ properties:
112
+ title: { type: string }
113
+ email: { type: string, format: email }
114
+ note: { type: string }
115
+ output: { type: object }
116
+ handler: { kind: builtin, op: create, schema: post-suggestions }
117
+ ---
118
+ apiVersion: cms.mantle.aotter.net/v1
119
+ kind: Trigger
120
+ metadata:
121
+ name: submit-post-suggestion-http
122
+ spec:
123
+ source: { kind: http, method: POST, path: /api/post-suggestions }
124
+ target: { procedure: submit-post-suggestion }
125
+ ```
126
+
127
+ How the pieces fit:
128
+
129
+ - `posts` is the non-localized parent. It holds only what every language shares; here that is the slug.
130
+ - `post-translations` is the localized child. `translates: { parent: posts, on: slug }` requires `localized: true`, at least one content field besides `slug` and `locale`, and a parent that exists and is not itself localized. Admin renders the child as locale tabs inside the parent's editor.
131
+ - `published-posts` takes a required `locale` parameter. `{ $param: locale }` must name a property in `params.properties` that is also in `params.required`. The `gte publishedAt 0` clause keeps the filter aligned with the declared `[locale, publishedAt]` index; confirm the plan with `mantle-harness indexes`.
132
+ - Site locales must be configured. A localized Schema with zero `siteDefaults.locales` fails at boot with `SCHEMA_LOCALIZED_REQUIRES_SITE_LOCALES`, and a write whose `locale` is not in the site list fails with `INPUT_VALIDATION_FAILED`.
133
+
134
+ See [Lifecycle and locales](../handbook/concepts/lifecycle-and-locales.md) and the [Schema reference](../handbook/reference/schema.md).
135
+
136
+ ## Worker and handlers
137
+
138
+ There are none. Every Procedure here is `builtin`, and Views need no Trigger. The Worker is the minimal one:
139
+
140
+ ```ts
141
+ import { createMantleWorker } from "@aotter/mantle/cloudflare";
142
+ import { plan } from "../.mantle/generated/mantle.js";
143
+
144
+ export default createMantleWorker({ plan });
145
+ ```
146
+
147
+ ### Rendering
148
+
149
+ Public HTML pages are optional and separate from the data contract. If you want `/en/posts/<slug>` rendered by the Worker, register a template for the translations collection and pass it to `createMantleWorker({ templates, publicPathResolver })`. A trimmed entry template:
150
+
151
+ ```ts
152
+ import { TemplateRegistry } from "@aotter/mantle/web";
153
+ import MarkdownIt from "markdown-it";
154
+
155
+ const markdown = new MarkdownIt({ html: false, linkify: true });
156
+
157
+ export function createTemplates(): TemplateRegistry {
158
+ const templates = new TemplateRegistry();
159
+ templates.registerEntryTemplate("post-translations", ({ entry, site, seo }) => {
160
+ const title = typeof entry.data.title === "string" ? entry.data.title : site.title;
161
+ const body = typeof entry.data.body === "string" ? entry.data.body : "";
162
+ return `<html lang="${entry.locale ?? "en"}"><head><title>${escapeHtml(title)}</title></head>
163
+ <body><main><h1>${escapeHtml(title)}</h1><div>${markdown.render(body)}</div></main></body></html>`;
164
+ });
165
+ return templates;
166
+ }
167
+ ```
168
+
169
+ The template receives `{ entry, site, seo, mediaAssets }` and returns a complete HTML string. Escape every field you interpolate; `body` is rendered from Markdown because the Schema marks it `x-mcp-hint: markdown`. Paths, Markdown mirrors, `llms.txt`, sitemap and cache headers are covered in [Public web, SEO and cache](../handbook/cloudflare/public-web.md).
170
+
171
+ ### The single-Schema alternative
172
+
173
+ The simpler alternative is one localized `posts` Schema with `uniqueIndexes: [[slug, locale]]` and no parent. Each locale row is an independent record; nothing is shared except the slug convention. Choose that shape when translations do not need shared fields or Admin translation grouping. Choose the parent/child shape above when several locale rows are versions of one entity and editors need to see which languages are missing. Both shapes serve the same `published-posts` View contract.
174
+
175
+ ## Try it
176
+
177
+ Public list for one locale:
178
+
179
+ ```sh
180
+ curl -sS 'http://localhost:8787/api/views/published-posts?locale=en&show=10'
181
+ ```
182
+
183
+ ```json
184
+ {
185
+ "ok": true,
186
+ "data": {
187
+ "rows": [
188
+ {
189
+ "id": "tr_01j...",
190
+ "slug": "hello-world",
191
+ "locale": "en",
192
+ "title": "Hello, world",
193
+ "excerpt": "First post.",
194
+ "body": "# Hello\n\nFirst post.",
195
+ "publishedAt": 1788879363492,
196
+ "updatedAt": 1788879400000
197
+ }
198
+ ],
199
+ "page": 1,
200
+ "show": 10,
201
+ "hasMore": false
202
+ }
203
+ }
204
+ ```
205
+
206
+ Omitting `locale` returns HTTP 400 `INPUT_VALIDATION_FAILED`. `show` is capped at the View's `limit` (50); `hasMore` is `rows.length === show`. A View may declare `cache.sharedMaxAge` to cache eligible anonymous REST responses under the Worker's deployment-scoped tag; publishing content changes purge that tag.
207
+
208
+ Submit a suggestion:
209
+
210
+ ```sh
211
+ curl -sS -X POST http://localhost:8787/api/post-suggestions \
212
+ -H 'content-type: application/json' \
213
+ -d '{"title":"Write about indexes","email":"reader@example.test"}'
214
+ ```
215
+
216
+ The response is `{ ok: true, data: <EntryRow> }` with `collection: "post-suggestions"` and `status: "published"`.
217
+
218
+ MCP tools:
219
+
220
+ | Surface | Tool | Origin |
221
+ |---|---|---|
222
+ | `/mcp` | `query_view_published_posts` (arguments `locale`, `page`, `show`) | public View |
223
+ | `/mcp/staff` | `create_draft_posts`, `update_draft_posts` | publishing Schema `posts` |
224
+ | `/mcp/staff` | `create_draft_post_translations`, `update_draft_post_translations` | publishing Schema `post-translations` |
225
+ | `/mcp/staff` | `create_record_post_suggestions`, `update_record_post_suggestions` | operational Schema `post-suggestions` |
226
+ | `/mcp/staff` | `request_publish`, `unpublish_entry`, `archive_entry`, `delete_entry` | generic lifecycle tools |
227
+
228
+ There is no `submit_post_suggestion` tool because no MCP Trigger targets that Procedure. See [MCP and agents](../handbook/concepts/mcp-and-agents.md).
229
+
230
+ ## What this deliberately leaves out
231
+
232
+ - **Comments.** Reader comments would be another operational Schema with its own moderation Procedures.
233
+ - **Search.** `searchableFields` powers Admin and Staff MCP substring search only; public full-text search is application code.
234
+ - **Scheduling.** `publishedAt` is a display timestamp set by editors. Nothing publishes a draft at that time; publishing remains an explicit `request_publish` or Admin action.
235
+
236
+ Related: [Intake form](./builtin-intake.md) is the same suggestion-box write without hooks; [Intake Turnstile and email hooks](./cf-primitives-intake-hooks.md) hardens it with a bot check.
237
+
238
+ ## Source
239
+
240
+ - [Schema reference](../handbook/reference/schema.md) and [View reference](../handbook/reference/view.md) — `localized`, `translates`, param-driven Views
241
+ - [`packages/mantle-web/src/model/TemplateRegistry.ts`](../../packages/mantle-web/src/model/TemplateRegistry.ts) — `registerEntryTemplate` and `EntryContext`
@@ -0,0 +1,149 @@
1
+ ---
2
+ description: Accept public reservation requests and expose the queue to staff. Every Procedure is builtin create.
3
+ ---
4
+ # Reservation requests
5
+
6
+ **Handler class:** builtin · **Builder:** yes · [Examples hub](./README.md).
7
+
8
+ This example accepts reservation requests from the public and lists them for staff. The published Manifest is fully declarative: every Procedure is `handler.kind: builtin`. Read it if you take appointments, bookings or table requests and confirm them by hand. A `before_create` date guard is application code; see [Intake Turnstile and email hooks](./cf-primitives-intake-hooks.md) for that `ref` pattern.
9
+
10
+ ## Problem
11
+
12
+ A visitor asks for a reservation by giving a name, an email address, the requested date or slot, an optional party size and a note. Staff see the newest requests first in Admin, over the staff View REST route, or through Staff MCP, and follow up outside the system. Requests are live operational records; nothing is drafted or published. The system does not decide whether a slot is free.
13
+
14
+ ## Manifest
15
+
16
+ ```yaml
17
+ apiVersion: cms.mantle.aotter.net/v1
18
+ kind: Schema
19
+ metadata:
20
+ name: reservations
21
+ spec:
22
+ title: Reservations
23
+ lifecycle: operational
24
+ schema:
25
+ type: object
26
+ additionalProperties: false
27
+ required: [name, email, requestedFor]
28
+ properties:
29
+ name: { type: string, minLength: 1, maxLength: 120 }
30
+ email: { type: string, format: email }
31
+ requestedFor: { type: string, description: Requested date, time, or slot. }
32
+ partySize: { type: integer, minimum: 1 }
33
+ note: { type: string, maxLength: 1000 }
34
+ createdAt: { type: number, x-mcp-hint: timestamp-ms, x-mantle-bind: now }
35
+ ---
36
+ apiVersion: cms.mantle.aotter.net/v1
37
+ kind: View
38
+ metadata:
39
+ name: reservation-queue
40
+ spec:
41
+ title: Reservation queue
42
+ surface: staff
43
+ from: reservations
44
+ fields: [id, name, email, requestedFor, partySize, note, createdAt]
45
+ orderBy:
46
+ - { field: createdAt, direction: desc }
47
+ limit: 50
48
+ ---
49
+ apiVersion: cms.mantle.aotter.net/v1
50
+ kind: Procedure
51
+ metadata:
52
+ name: submit-reservation
53
+ spec:
54
+ title: Submit reservation
55
+ input:
56
+ type: object
57
+ additionalProperties: false
58
+ required: [name, email, requestedFor]
59
+ properties:
60
+ name: { type: string, minLength: 1, maxLength: 120 }
61
+ email: { type: string, format: email }
62
+ requestedFor: { type: string }
63
+ partySize: { type: integer, minimum: 1 }
64
+ note: { type: string, maxLength: 1000 }
65
+ output: { type: object }
66
+ handler: { kind: builtin, op: create, schema: reservations }
67
+ ---
68
+ apiVersion: cms.mantle.aotter.net/v1
69
+ kind: Trigger
70
+ metadata:
71
+ name: submit-reservation-http
72
+ spec:
73
+ source: { kind: http, method: POST, path: /api/reservations }
74
+ target: { procedure: submit-reservation }
75
+ ---
76
+ apiVersion: cms.mantle.aotter.net/v1
77
+ kind: Trigger
78
+ metadata:
79
+ name: submit-reservation-mcp
80
+ spec:
81
+ source: { kind: mcp, surface: public }
82
+ target: { procedure: submit-reservation }
83
+ ```
84
+
85
+ `createdAt` is stamped by the server (`x-mantle-bind: now`); a caller-supplied value is ignored. `requestedFor` is a free string on purpose: this example does not impose a calendar model. The staff View orders by `createdAt`, so the newest request is first regardless of the requested slot.
86
+
87
+ ## Worker and handlers
88
+
89
+ None are required. The Manifest above runs on the minimal Worker:
90
+
91
+ ```ts
92
+ import { createMantleWorker } from "@aotter/mantle/cloudflare";
93
+ import { plan } from "../.mantle/generated/mantle.js";
94
+
95
+ export default createMantleWorker({ plan });
96
+ ```
97
+
98
+ A `before_create` guard that rejects ISO dates already in the past is a `handler.kind: ref` Procedure. It is not part of this Manifest. The abort-hook shape, `InvokeFailure`, and `LIFECYCLE_HOOK_REJECTED` (HTTP 409) are in [Intake Turnstile and email hooks](./cf-primitives-intake-hooks.md) and [Writes: Procedures, Triggers and hooks](../handbook/concepts/procedures-and-triggers.md).
99
+
100
+ ## Try it
101
+
102
+ ```sh
103
+ curl -sS -X POST http://localhost:8787/api/reservations \
104
+ -H 'content-type: application/json' \
105
+ -d '{"name":"Ada","email":"ada@example.test","requestedFor":"2026-10-03T19:00:00+08:00","partySize":4}'
106
+ ```
107
+
108
+ ```json
109
+ {
110
+ "ok": true,
111
+ "data": {
112
+ "id": "res_01j...",
113
+ "collection": "reservations",
114
+ "status": "published",
115
+ "version": 1,
116
+ "data": { "name": "Ada", "email": "ada@example.test", "requestedFor": "2026-10-03T19:00:00+08:00", "partySize": 4, "createdAt": 1788879363492 },
117
+ "authorId": null,
118
+ "createdAt": 1788879363492,
119
+ "updatedAt": 1788879363492
120
+ }
121
+ }
122
+ ```
123
+
124
+ A `partySize` of `0` is HTTP 400 `INPUT_VALIDATION_FAILED`.
125
+
126
+ Staff list the queue at `GET /admin/api/views/reservation-queue?page=1&show=50` (staff session required); `GET /admin/api/views/reservation-queue/export` returns the matching rows as CSV.
127
+
128
+ MCP tools:
129
+
130
+ | Surface | Tool | Origin |
131
+ |---|---|---|
132
+ | `/mcp` | `submit_reservation` | `submit-reservation-mcp` Trigger |
133
+ | `/mcp/staff` | `query_view_reservation_queue` | `reservation-queue` View |
134
+ | `/mcp/staff` | `create_record_reservations`, `update_record_reservations` | operational Schema `reservations` |
135
+
136
+ ## What this deliberately leaves out
137
+
138
+ Requests are **not confirmed automatically**. A successful `POST` means the request was recorded, nothing more. The pattern omits:
139
+
140
+ - **Slot inventory.** There is no `slots` Schema and no capacity count.
141
+ - **Double-booking prevention.** Two requests for the same time both succeed. Preventing that needs an authority that serializes reservations, as the [commerce example](./cf-primitives-commerce-inventory.md) does for stock with a Durable Object.
142
+ - **Calendar sync, payments, deposits.**
143
+ - **Confirmation messages.** Add an `after_create` handler as in the [intake form](./cf-primitives-intake-hooks.md) when staff want a notification.
144
+
145
+ ## Source
146
+
147
+ - [`README.md`](../../README.md) — reservations excerpt
148
+ - [Procedure reference](../handbook/reference/procedure.md) — builtin `create`
149
+ - [Intake Turnstile and email hooks](./cf-primitives-intake-hooks.md) — optional `before_create` `ref` guard