@brightsideoy/kama 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (111) hide show
  1. package/README.md +25 -7
  2. package/bin/cli.js +539 -359
  3. package/content/definitions/blocks/button.yaml +15 -5
  4. package/content/definitions/blocks/form.yaml +20 -0
  5. package/content/definitions/blocks/image-gallery.yaml +34 -0
  6. package/content/definitions/blocks/node-list.yaml +75 -0
  7. package/content/definitions/blocks/youtube.yaml +8 -0
  8. package/content/definitions/field-sets/access.yaml +14 -0
  9. package/content/definitions/field-sets/page-base.yaml +19 -1
  10. package/content/definitions/forms/.gitkeep +0 -0
  11. package/content/definitions/forms/contact.yaml +38 -0
  12. package/content/definitions/forms/subscription.yaml +26 -0
  13. package/content/definitions/nodes/article.yaml +19 -1
  14. package/content/definitions/taxonomies/categories.yaml +5 -2
  15. package/content/definitions/taxonomies/media-tag.yaml +15 -0
  16. package/content/definitions/taxonomies/tags.yaml +5 -2
  17. package/definitions/editor/default.ts +19 -2
  18. package/dist/assets/AssetEditor-CAvQEsBT.js +1 -0
  19. package/dist/assets/AssetEditor-CQtKSOjX.css +1 -0
  20. package/dist/assets/CmsAccordion-91I5Rx5D.css +1 -0
  21. package/dist/assets/CmsAccordion-BgdaB8QZ.js +1 -0
  22. package/dist/assets/CmsBadge-BT2jTJUu.js +1 -0
  23. package/dist/assets/CmsBadge-Ip5hXw8G.css +1 -0
  24. package/dist/assets/CmsButton-DATGQeoC.css +1 -0
  25. package/dist/assets/CmsButton-DnhPsHXA.js +1 -0
  26. package/dist/assets/CmsFieldTaxonomy-CNY3-MbD.js +1 -0
  27. package/dist/assets/CmsFieldTaxonomy-CVlKL-l2.css +1 -0
  28. package/dist/assets/CmsHelp-BO_vWABq.css +1 -0
  29. package/dist/assets/CmsHelp-DtPeURCv.js +1 -0
  30. package/dist/assets/CmsImagePreview-BhM7S_v8.js +1 -0
  31. package/dist/assets/CmsImagePreview-CujwG8r_.css +1 -0
  32. package/dist/assets/CmsPublisher-BcrQAr1m.css +1 -0
  33. package/dist/assets/CmsPublisher-DiQhfPID.js +3 -0
  34. package/dist/assets/CmsUserCenter-CAaiCweN.js +1 -0
  35. package/dist/assets/CmsUserCenter-D3OZYHD0.css +1 -0
  36. package/dist/assets/EditorSplitPreview-BfGni85I.js +1 -0
  37. package/dist/assets/EditorSplitPreview-CMoTjLW5.css +1 -0
  38. package/dist/assets/FormsWorkspace-CGs6eUjz.css +1 -0
  39. package/dist/assets/FormsWorkspace-CUK-y2dR.js +2 -0
  40. package/dist/assets/NodeContextMenu-C5RTK0sr.js +1 -0
  41. package/dist/assets/NodeContextMenu-Cj-2TvQC.css +1 -0
  42. package/dist/assets/NodeEditor-CNj66ogv.js +161 -0
  43. package/dist/assets/NodeEditor-hYW5aA6B.css +1 -0
  44. package/dist/assets/SettingsDashboard-XBOgYUn3.css +1 -0
  45. package/dist/assets/SettingsDashboard-gzHzxsIc.js +1 -0
  46. package/dist/assets/StatusPill-Dlm6uvGe.css +1 -0
  47. package/dist/assets/StatusPill-HY1gCP9c.js +1 -0
  48. package/dist/assets/TrashWorkspace-DtMgxg13.css +1 -0
  49. package/dist/assets/TrashWorkspace-t0lOrFRK.js +1 -0
  50. package/dist/assets/_plugin-vue_export-helper-BK_c4R_m.js +5 -0
  51. package/dist/assets/circle-check-CksZGUB7.js +1 -0
  52. package/dist/assets/database--QlkzG9u.js +1 -0
  53. package/dist/assets/file-U7h4eOhG.js +1 -0
  54. package/dist/assets/globe-TuZP0v6A.js +1 -0
  55. package/dist/assets/history-CIbqkRx3.js +1 -0
  56. package/dist/assets/index-0nWRArpY.js +14 -0
  57. package/dist/assets/index-C171UGo4.css +1 -0
  58. package/dist/assets/layers-BwACvD_U.js +1 -0
  59. package/dist/assets/loader-circle-DYEFqbD4.js +1 -0
  60. package/dist/assets/panel-left-close-Cpq52HZy.js +1 -0
  61. package/dist/assets/plus-7rv1C56N.js +1 -0
  62. package/dist/assets/preload-helper-BB8Wl1va.js +1 -0
  63. package/dist/assets/preload-helper-BxFQpwa9.css +1 -0
  64. package/dist/assets/rotate-ccw-DvjWccJd.js +1 -0
  65. package/dist/assets/save-Dwhm8QNL.js +1 -0
  66. package/dist/assets/schema-helpers-uuDCw8Rb.js +1 -0
  67. package/dist/assets/send-Bs4eROle.js +1 -0
  68. package/dist/assets/smartphone-i429gh5p.js +1 -0
  69. package/dist/assets/trash-2-BbKTm8cC.js +1 -0
  70. package/dist/assets/useCmsState-CDENPbKL.js +1 -0
  71. package/dist/assets/useNodes-D-Vuwq5_.js +1 -0
  72. package/dist/assets/user-DKryA1QU.js +1 -0
  73. package/dist/assets/x-DOWbsdzd.js +1 -0
  74. package/dist/build-seed.js +495 -0
  75. package/dist/{dist-cK3xGnBZ.js → dist-DKRU6nhX.js} +9254 -5762
  76. package/dist/index.html +32 -2
  77. package/dist/index.js +9179 -5689
  78. package/dist/nodemailer-Ccic7tRm-Dw2jwzbm.js +7877 -0
  79. package/dist/nodemailer-Ccic7tRm.js +7908 -0
  80. package/dist/rolldown-runtime-B0aSnxlc.js +20 -0
  81. package/dist/schema-compiler.js +1 -1
  82. package/documentation/FORMS.md +256 -0
  83. package/documentation/SCHEMAS.md +450 -119
  84. package/package.json +14 -6
  85. package/schema.sql +46 -1
  86. package/templates/astro-starter/astro-preview-dev-integration.mjs +83 -0
  87. package/templates/astro-starter/astro.config.mjs +11 -0
  88. package/templates/astro-starter/src/components/blocks/BlockRenderer.astro +17 -0
  89. package/templates/astro-starter/src/components/blocks/Form.astro +313 -0
  90. package/templates/astro-starter/src/components/blocks/HeaderImage.astro +6 -12
  91. package/templates/astro-starter/src/components/blocks/ImageBlock.astro +5 -6
  92. package/templates/astro-starter/src/components/blocks/NodeList.astro +274 -0
  93. package/templates/astro-starter/src/components/global/NavigationMenu.astro +17 -8
  94. package/templates/astro-starter/src/components/ui/KamaImage.astro +13 -5
  95. package/templates/astro-starter/src/layouts/StandardLayout.astro +4 -3
  96. package/templates/astro-starter/src/lib/cms-fetch.ts +22 -0
  97. package/templates/astro-starter/src/lib/cms.ts +18 -9
  98. package/templates/astro-starter/src/lib/media/kama-image-service.ts +15 -4
  99. package/templates/astro-starter/src/lib/media/media-proxy.ts +22 -3
  100. package/templates/astro-starter/src/lib/media/media-url.ts +17 -3
  101. package/templates/astro-starter/src/middleware.ts +199 -71
  102. package/templates/astro-starter/src/pages/[...slug].astro +122 -45
  103. package/templates/astro-starter/src/pages/api/forms/[...path].ts +57 -0
  104. package/templates/astro-starter/src/pages/api/load-nodes.ts +68 -0
  105. package/templates/astro-starter/src/pages/api/partials/node-cards.astro +98 -0
  106. package/templates/astro-starter/src/pages/partials/nav.astro +6 -5
  107. package/templates/kama-worker/index.js +22 -12
  108. package/templates/kama-worker/setup-local-db.mjs +17 -0
  109. package/wrangler.json +19 -0
  110. package/dist/assets/index-C3LzwJjY.css +0 -1
  111. package/dist/assets/index-DhguVxzs.js +0 -164
@@ -0,0 +1,20 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, n) => {
3
+ let r = {};
4
+ for (var i in e) t(r, i, {
5
+ get: e[i],
6
+ enumerable: !0
7
+ });
8
+ return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ }, c = (e, i, o, s) => {
10
+ if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
11
+ get: ((e) => i[e]).bind(null, d),
12
+ enumerable: !(s = n(i, d)) || s.enumerable
13
+ });
14
+ return e;
15
+ }, l = (n, r, o) => (o = n == null ? {} : e(i(n)), c(r || !n || !n.__esModule || !a.call(n, "default") ? t(o, "default", {
16
+ value: n,
17
+ enumerable: !0
18
+ }) : o, n));
19
+ //#endregion
20
+ export { s as n, l as r, o as t };
@@ -30,7 +30,7 @@ async function f() {
30
30
  if (n(f)) l = (await import(t(f).href)).compileDefinitions;
31
31
  else if (n(p)) l = (await import(t(p).href)).compileDefinitions;
32
32
  else try {
33
- l = (await import("./dist-cK3xGnBZ.js")).compileDefinitions;
33
+ l = (await import("./dist-DKRU6nhX.js")).compileDefinitions;
34
34
  } catch (e) {
35
35
  console.error("\x1B[31m ✖\x1B[0m \x1B[31mCould not resolve Kama Schema Engine:\x1B[0m", e), process.exit(1);
36
36
  }
@@ -0,0 +1,256 @@
1
+ # Forms
2
+
3
+ KAMA forms are defined in YAML and can be added to pages with the built-in
4
+ **Form** block. The CMS lets you configure submission storage and email
5
+ finishers, and view saved submissions.
6
+
7
+ ## Contents
8
+
9
+ - [Form definitions](#form-definitions)
10
+ - [Add a form to a page](#add-a-form-to-a-page)
11
+ - [Submissions](#submissions)
12
+ - [Finishers](#finishers)
13
+ - [Email delivery](#email-delivery)
14
+ - [Turnstile verification](#turnstile-verification)
15
+ - [Local development](#local-development)
16
+ - [API reference](#api-reference)
17
+
18
+ ## Form definitions
19
+
20
+ Create a YAML file in `content/definitions/forms/`. Its filename is used as the
21
+ form ID if you do not set `id` in the file. After adding or changing definitions,
22
+ run `npm run bundle:definitions` before deploying.
23
+
24
+ ```yaml
25
+ id: contact
26
+ title: Contact us
27
+ description: Send our team a message.
28
+ fields:
29
+ - name: email
30
+ label: Email
31
+ type: email
32
+ required: true
33
+ - name: message
34
+ label: Message
35
+ type: textarea
36
+ required: true
37
+ settings:
38
+ successMessage: Thanks for getting in touch.
39
+ requireTurnstile: false
40
+ ```
41
+
42
+ ## Add a form to a page
43
+
44
+ Add the **Form** block to a page and select the form. The block's optional
45
+ **Success Message** overrides the message in the form definition.
46
+
47
+ ## Submissions
48
+
49
+ All finishers are disabled by default. A valid submission with no finisher
50
+ enabled receives the configured success response, but is not saved or emailed.
51
+
52
+ Select a form in the Forms sidebar, then use the **Finishers** tab in the main
53
+ workspace to enable **Save submissions to database**. Saved entries are
54
+ available in the **Submissions** tab. That tab is shown only when database
55
+ storage is enabled. If an existing table has the old schema, KAMA recreates it
56
+ at startup.
57
+
58
+ Expand a submission to view its values in a field/value table using the form's
59
+ field labels. Use **Download CSV** to export submissions, or select individual
60
+ submissions and delete them together; each submission can also be deleted on
61
+ its own.
62
+
63
+ The **Finishers** tab also lets you configure email notifications, including a
64
+ fixed team recipient or the form's email field for a submitter confirmation.
65
+ Provider credentials remain deployment configuration. Set a package-wide
66
+ default sender with `FORMS_EMAIL_FROM`, or set a sender address on an individual
67
+ email finisher. Finisher settings are grouped into collapsible sections to make
68
+ the configuration easier to scan. Team notifications and submitter confirmations
69
+ have separate sections and can be enabled and configured independently. Each
70
+ section shows its enabled state while collapsed.
71
+
72
+ ## Finishers
73
+
74
+ Finishers run after field validation and Turnstile verification, in the order
75
+ listed. KAMA registers the `database` and `email` finishers by default. You can
76
+ configure finishers on the form or override them on an individual Form block.
77
+
78
+ ### Configure finishers on a form
79
+
80
+ For code-defined forms, configure email finishers in the form's YAML:
81
+
82
+ ```yaml
83
+ finishers:
84
+ - id: notify-team
85
+ type: email
86
+ from: notifications@example.com
87
+ to: team@example.com
88
+ subject: "New message from {{fullName}}"
89
+ replyToField: email
90
+ - id: confirmation
91
+ type: email
92
+ toField: email
93
+ subject: "We received your message"
94
+ text: "Thanks {{fullName}}, we received your message."
95
+ ```
96
+
97
+ When finisher settings are saved in the CMS, they override the YAML settings.
98
+ Registered custom finishers are preserved when built-in settings are edited.
99
+
100
+ ### Override finishers on a Form block
101
+
102
+ The block editor can replace the form's complete finisher list. It supports
103
+ enabling or disabling database storage, adding or removing email finishers, and
104
+ setting their recipient, sender email, subject, sender name, reply-to, and
105
+ message templates. Registered custom finishers can also be added, enabled,
106
+ removed, or edited as JSON. Email transport is configured once for the KAMA
107
+ package environment, not per form or block.
108
+
109
+ Block overrides are saved with the page. On submission, KAMA reloads and
110
+ validates the published finisher configuration from the database instead of
111
+ trusting settings sent by the visitor. Transport credentials cannot be changed
112
+ in the block editor. Sender addresses must be authorized by the configured
113
+ email provider. Custom finisher JSON is validated for size and type; each
114
+ custom handler must validate its own settings.
115
+
116
+ ### Add a custom finisher
117
+
118
+ Register a handler during server startup, before submissions are handled:
119
+
120
+ ```ts
121
+ import { registerFormFinisher } from '@brightsideoy/kama';
122
+
123
+ registerFormFinisher('webhook', async ({ finisher, payload, env }) => {
124
+ // Implement this finisher and throw if it fails.
125
+ });
126
+ ```
127
+
128
+ Then add `type: webhook` to a form's `finishers` list. Handlers run in list
129
+ order. If one throws, later finishers do not run and the submission fails.
130
+
131
+ ## Email delivery
132
+
133
+ ### Configure the transport
134
+
135
+ Set `FORMS_EMAIL_PROVIDER` once in the KAMA package's runtime environment. For
136
+ local Cloudflare development, put it in `.dev.vars`; for deployed Workers, put
137
+ it in Wrangler `vars`:
138
+
139
+ ```sh
140
+ # .dev.vars
141
+ FORMS_EMAIL_PROVIDER=cloudflare
142
+ ```
143
+
144
+ - `cloudflare` requires the Cloudflare Email Sending binding.
145
+ - `smtp` requires SMTP configuration and is available in the Node runtime.
146
+ - `auto` (the default) uses the Cloudflare binding when available; otherwise
147
+ it uses SMTP in Node.
148
+
149
+ For Workers, set the provider as a Wrangler variable and add the Email Sending
150
+ binding after onboarding a sender domain in Cloudflare Email Service:
151
+
152
+ ```jsonc
153
+ {
154
+ "vars": {
155
+ "FORMS_EMAIL_PROVIDER": "cloudflare"
156
+ },
157
+ "send_email": [{ "name": "FORMS_EMAIL" }]
158
+ }
159
+ ```
160
+
161
+ Set `FORMS_EMAIL_FROM` to the package-wide default sender address at the
162
+ onboarded domain. An individual email finisher can override it with `from`.
163
+ Cloudflare Email Sending requires the appropriate Workers plan for arbitrary
164
+ external recipients. KAMA does not enable the binding automatically.
165
+
166
+ For Node deployments, configure:
167
+
168
+ ```sh
169
+ FORMS_EMAIL_PROVIDER=smtp
170
+ FORMS_SMTP_HOST=smtp.example.com
171
+ FORMS_SMTP_PORT=465
172
+ FORMS_SMTP_SECURE=true
173
+ FORMS_SMTP_USER=...
174
+ FORMS_SMTP_PASSWORD=...
175
+ FORMS_EMAIL_FROM=forms@example.com
176
+ FORMS_EMAIL_FROM_NAME=KAMA
177
+ ```
178
+
179
+ For Cloudflare authenticated SMTP, use `smtp.mx.cloudflare.net:465`, username
180
+ `api_token`, and an Email Sending: Edit API token as the password. Keep SMTP
181
+ credentials in the deployment's secret manager, never in form YAML. Use valid
182
+ sender and recipient addresses; Email Sending is intended for transactional
183
+ mail, not bulk marketing.
184
+
185
+ ### Customize email content
186
+
187
+ Use `from` to override the package-wide `FORMS_EMAIL_FROM` sender for this
188
+ finisher. The address must be authorized by the selected email provider. If
189
+ omitted, the package-wide sender is used.
190
+
191
+ Use `toField` to select a recipient from the submission; it must name a form
192
+ field with `type: email`. Use `subjectField`, `fromNameField`, or
193
+ `replyToField` to select submission values. `replyToField` must also name an
194
+ email field. Keep the sender address fixed; use `replyToField` when replies
195
+ should go to the submitter. Subject text and optional `text` or `html` bodies
196
+ support `{{field}}` placeholders. Interpolated HTML values are escaped.
197
+
198
+ If no body template is set, the message includes all submitted fields.
199
+ `FORMS_EMAIL_FROM` is the sender fallback, and `FORMS_EMAIL_FROM_NAME` provides
200
+ an optional deployment-wide sender-name fallback.
201
+
202
+ If an email finisher fails, the submission fails and KAMA does not return a
203
+ success response. Email delivery and database writes cannot be rolled back
204
+ atomically, so earlier finishers may already have run. Retrying can repeat
205
+ those side effects.
206
+
207
+ ## Turnstile verification
208
+
209
+ For forms with `settings.requireTurnstile: true`, configure both keys:
210
+
211
+ - `PUBLIC_TURNSTILE_SITE_KEY` on the frontend site, as a public Wrangler `vars`
212
+ value or local `.dev.vars` value. This renders the widget.
213
+ - `TURNSTILE_SECRET_KEY` on the KAMA Worker, as a Wrangler secret or local
214
+ `.dev.vars` value. The server uses it to verify each response.
215
+
216
+ Use keys from the same Turnstile widget. The Form block warns when Turnstile is
217
+ required but the site key is missing.
218
+
219
+ For local Astro development only, KAMA uses Cloudflare's documented always-pass
220
+ test keys when no site key or secret is configured. These keys do not protect a
221
+ production form; configure real keys for deployed environments.
222
+
223
+ ## Local development
224
+
225
+ ### Connect the Astro site to KAMA
226
+
227
+ When available, the Astro starter uses the `CMS_WORKER` service binding for CMS
228
+ API and `/media/*` requests. Form submissions go through the same-origin
229
+ `/api/forms/:formId/submissions` proxy. Without the binding, it uses
230
+ `PUBLIC_API_URL` server-side; local development defaults to the CMS Worker at
231
+ `http://127.0.0.1:8787`.
232
+
233
+ For local Astro development, run the CMS Worker on port `8787` as well as the
234
+ Astro site. If the local service binding reports that its target Worker is not
235
+ running, page and media proxies fall back to `127.0.0.1:8787`. Keep the site's
236
+ and CMS Worker's `FRONTEND_API_SECRET` values matched in their local secret
237
+ files. Never expose a server-only API secret in browser code.
238
+
239
+ ### Draft preview iframe
240
+
241
+ The starter serves Vite modules requested by KAMA's sandboxed Draft iframe from
242
+ the local dev server. The exception is limited to opaque-origin `GET` and `HEAD`
243
+ requests for Vite/source assets and media; API and page requests remain
244
+ protected by Astro's cross-origin dev guard. Keep the dev server bound to
245
+ loopback.
246
+
247
+ ## API reference
248
+
249
+ | Method | Endpoint | Purpose |
250
+ | --- | --- | --- |
251
+ | `GET` | `/api/v1/forms/:formId` | Fetch a form definition. |
252
+ | `POST` | `/api/v1/forms/:formId/submissions` | Submit a form. |
253
+ | `GET` | `/api/cms/forms` | Populate the Form block selector. |
254
+ | `GET` | `/api/cms/forms/:formId/submissions` | Fetch saved submissions and field labels. |
255
+ | `DELETE` | `/api/cms/forms/:formId/submissions/:submissionId` | Delete one saved submission. |
256
+ | `DELETE` | `/api/cms/forms/:formId/submissions` | Delete selected submissions; send `{ "ids": [1, 2] }` as JSON. |