@brightsideoy/kama 1.0.0-alpha.24 → 1.0.0-alpha.26
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/bin/cli.js +8 -2
- package/dist/assets/AssetEditor-BQp8ufSp.js +1 -0
- package/dist/assets/CmsAccordion-91I5Rx5D.css +1 -0
- package/dist/assets/CmsAccordion-BgdaB8QZ.js +1 -0
- package/dist/assets/CmsBadge-BT2jTJUu.js +1 -0
- package/dist/assets/CmsButton-DnhPsHXA.js +1 -0
- package/dist/assets/CmsFieldTaxonomy-DkAT1fuc.js +1 -0
- package/dist/assets/CmsHelp-BIbzY-Mi.js +1 -0
- package/dist/assets/CmsImagePreview-BhM7S_v8.js +1 -0
- package/dist/assets/CmsPublisher-Dc38zXt9.js +3 -0
- package/dist/assets/CmsUserCenter-CAaiCweN.js +1 -0
- package/dist/assets/EditorSplitPreview-fCwIcjhd.js +1 -0
- package/dist/assets/FormsWorkspace-Bb6wv80Y.js +2 -0
- package/dist/assets/FormsWorkspace-CGs6eUjz.css +1 -0
- package/dist/assets/NodeContextMenu-Bt_TK17e.js +1 -0
- package/dist/assets/{NodeEditor-rrOvlGF8.css → NodeEditor-C82xLR0T.css} +1 -1
- package/dist/assets/NodeEditor-Cv8XIMCm.js +161 -0
- package/dist/assets/StatusPill-HY1gCP9c.js +1 -0
- package/dist/assets/TrashWorkspace-C-PKJBRC.js +1 -0
- package/dist/assets/{_plugin-vue_export-helper-BdT0OEbg.js → _plugin-vue_export-helper-BK_c4R_m.js} +1 -1
- package/dist/assets/circle-check-CksZGUB7.js +1 -0
- package/dist/assets/database--QlkzG9u.js +1 -0
- package/dist/assets/globe-TuZP0v6A.js +1 -0
- package/dist/assets/history-CIbqkRx3.js +1 -0
- package/dist/assets/{index-pbsspAqA.css → index-BYlliwPU.css} +1 -1
- package/dist/assets/index-C2AF4yr_.js +16 -0
- package/dist/assets/layers-BwACvD_U.js +1 -0
- package/dist/assets/loader-circle-DYEFqbD4.js +1 -0
- package/dist/assets/panel-left-close-Cpq52HZy.js +1 -0
- package/dist/assets/plus-BA5G4zTK.js +1 -0
- package/dist/assets/preload-helper-Bjoj7SyZ.js +1 -0
- package/dist/assets/rotate-ccw-DvjWccJd.js +1 -0
- package/dist/assets/save-Dwhm8QNL.js +1 -0
- package/dist/assets/send-Bs4eROle.js +1 -0
- package/dist/assets/smartphone-i429gh5p.js +1 -0
- package/dist/assets/trash-2-CrOsVo1D.js +1 -0
- package/dist/assets/{useCmsState-BblziYb-.js → useCmsState-rZqeAwK1.js} +1 -1
- package/dist/assets/{useNodes-GLoFdA2T.js → useNodes-B-Q6yDsj.js} +1 -1
- package/dist/assets/user-DKryA1QU.js +1 -0
- package/dist/assets/x-DOWbsdzd.js +1 -0
- package/dist/{dist-ZQFhgFUY.js → dist-BAUJQ0-e.js} +95 -38
- package/dist/index.html +25 -26
- package/dist/index.js +94 -37
- package/dist/{nodemailer-Ccic7tRm-Chwouykd.js → nodemailer-Ccic7tRm-Dl2YIOIv.js} +1 -1
- package/dist/schema-compiler.js +1 -1
- package/documentation/FORMS.md +181 -99
- package/package.json +1 -1
- package/templates/astro-starter/astro-preview-dev-integration.mjs +83 -0
- package/templates/astro-starter/astro.config.mjs +11 -0
- package/templates/astro-starter/src/components/global/NavigationMenu.astro +6 -5
- package/templates/astro-starter/src/lib/cms.ts +7 -0
- package/templates/astro-starter/src/middleware.ts +11 -9
- package/templates/astro-starter/src/pages/partials/nav.astro +6 -5
- package/dist/assets/AssetEditor-CVfLHR57.js +0 -1
- package/dist/assets/CmsBadge-DB0WNyWx.js +0 -1
- package/dist/assets/CmsButton-BbvewMhp.js +0 -1
- package/dist/assets/CmsFieldTaxonomy-DWlLLL92.js +0 -1
- package/dist/assets/CmsHelp-D4z0YSWX.js +0 -1
- package/dist/assets/CmsImagePreview-cWi-cfCr.js +0 -1
- package/dist/assets/CmsPublisher-Dz_XTFmW.js +0 -3
- package/dist/assets/CmsUserCenter-DE_op9OZ.js +0 -1
- package/dist/assets/EditorSplitPreview-C9Gb4usO.js +0 -1
- package/dist/assets/FormsWorkspace-DPTcxMpw.css +0 -1
- package/dist/assets/FormsWorkspace-DdYcrdg3.js +0 -1
- package/dist/assets/NodeContextMenu-qV4OaL33.js +0 -1
- package/dist/assets/NodeEditor-BNKrtv8t.js +0 -161
- package/dist/assets/StatusPill-BAnTGDR_.js +0 -1
- package/dist/assets/TrashWorkspace-DtbKBkM2.js +0 -1
- package/dist/assets/circle-check-CB39w7cZ.js +0 -1
- package/dist/assets/createLucideIcon-BIiMnJpN.js +0 -1
- package/dist/assets/database-mgNVRFlp.js +0 -1
- package/dist/assets/globe-Clq_OlnU.js +0 -1
- package/dist/assets/history-ZSqpsbjQ.js +0 -1
- package/dist/assets/index-B962oXcV.js +0 -16
- package/dist/assets/layers-CH2VvrZT.js +0 -1
- package/dist/assets/loader-circle-CwP4GuFX.js +0 -1
- package/dist/assets/panel-left-close-g4nIMIjy.js +0 -1
- package/dist/assets/plus-DCPXsir3.js +0 -1
- package/dist/assets/preload-helper-CstCHdlQ.js +0 -1
- package/dist/assets/rotate-ccw-tUaGL4DO.js +0 -1
- package/dist/assets/save-BUYaWIjt.js +0 -1
- package/dist/assets/send-UE48lWD8.js +0 -1
- package/dist/assets/smartphone-B7c4WqQk.js +0 -1
- package/dist/assets/trash-2-D8h6WxFK.js +0 -1
- package/dist/assets/user-Bo_HcyTz.js +0 -1
- package/dist/assets/x-3cfZis8N.js +0 -1
package/documentation/FORMS.md
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
# Forms
|
|
2
2
|
|
|
3
|
-
KAMA forms are
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.
|
|
7
23
|
|
|
8
24
|
```yaml
|
|
9
25
|
id: contact
|
|
@@ -23,79 +39,83 @@ settings:
|
|
|
23
39
|
requireTurnstile: false
|
|
24
40
|
```
|
|
25
41
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
36
56
|
at startup.
|
|
37
57
|
|
|
38
|
-
|
|
39
|
-
field
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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:
|
|
44
81
|
|
|
45
82
|
```yaml
|
|
46
83
|
finishers:
|
|
47
84
|
- id: notify-team
|
|
48
85
|
type: email
|
|
49
|
-
|
|
86
|
+
from: notifications@example.com
|
|
50
87
|
to: team@example.com
|
|
51
88
|
subject: "New message from {{fullName}}"
|
|
52
89
|
replyToField: email
|
|
53
90
|
- id: confirmation
|
|
54
91
|
type: email
|
|
55
|
-
provider: auto
|
|
56
92
|
toField: email
|
|
57
93
|
subject: "We received your message"
|
|
58
94
|
text: "Thanks {{fullName}}, we received your message."
|
|
59
95
|
```
|
|
60
96
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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.
|
|
71
115
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
`{{field}}` interpolation. The actual sender email remains
|
|
76
|
-
`FORMS_EMAIL_FROM`, while optional `FORMS_EMAIL_FROM_NAME` supplies a
|
|
77
|
-
deployment-wide sender-name fallback. Plain-text and HTML body templates are
|
|
78
|
-
optional; otherwise the message includes all submitted fields. Values
|
|
79
|
-
interpolated into HTML templates are escaped.
|
|
80
|
-
|
|
81
|
-
The Form block's editor sidebar can override the complete finisher list for that
|
|
82
|
-
block. This includes enabling or disabling database storage, adding/removing
|
|
83
|
-
email finishers, setting their recipient or recipient field, provider, subject,
|
|
84
|
-
sender display name, reply-to address/field, and text/HTML templates. Registered
|
|
85
|
-
custom finishers can be added from the registered types, enabled, removed, or
|
|
86
|
-
edited as JSON. With block overrides disabled, the form-level finisher list is
|
|
87
|
-
used unchanged.
|
|
88
|
-
|
|
89
|
-
Block overrides are saved with the page content. The public submission request
|
|
90
|
-
sends the page and block identifiers; KAMA reloads and validates the published
|
|
91
|
-
finisher configuration from the database, rather than trusting settings posted
|
|
92
|
-
by the visitor. Sender email addresses and transport credentials remain
|
|
93
|
-
deployment configuration and cannot be changed in the block sidebar. Custom
|
|
94
|
-
finisher JSON is validated for size and type, but each custom handler remains
|
|
95
|
-
responsible for validating its own settings.
|
|
96
|
-
|
|
97
|
-
KAMA registers `database` and `email` finishers by default. Add custom types by
|
|
98
|
-
registering a handler during server startup, before submissions are handled:
|
|
116
|
+
### Add a custom finisher
|
|
117
|
+
|
|
118
|
+
Register a handler during server startup, before submissions are handled:
|
|
99
119
|
|
|
100
120
|
```ts
|
|
101
121
|
import { registerFormFinisher } from '@brightsideoy/kama';
|
|
@@ -105,25 +125,48 @@ registerFormFinisher('webhook', async ({ finisher, payload, env }) => {
|
|
|
105
125
|
});
|
|
106
126
|
```
|
|
107
127
|
|
|
108
|
-
Then
|
|
109
|
-
order
|
|
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
|
|
110
134
|
|
|
111
|
-
|
|
112
|
-
|
|
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:
|
|
113
151
|
|
|
114
152
|
```jsonc
|
|
115
153
|
{
|
|
154
|
+
"vars": {
|
|
155
|
+
"FORMS_EMAIL_PROVIDER": "cloudflare"
|
|
156
|
+
},
|
|
116
157
|
"send_email": [{ "name": "FORMS_EMAIL" }]
|
|
117
158
|
}
|
|
118
159
|
```
|
|
119
160
|
|
|
120
|
-
Set `FORMS_EMAIL_FROM` to
|
|
121
|
-
|
|
122
|
-
|
|
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.
|
|
123
165
|
|
|
124
166
|
For Node deployments, configure:
|
|
125
167
|
|
|
126
168
|
```sh
|
|
169
|
+
FORMS_EMAIL_PROVIDER=smtp
|
|
127
170
|
FORMS_SMTP_HOST=smtp.example.com
|
|
128
171
|
FORMS_SMTP_PORT=465
|
|
129
172
|
FORMS_SMTP_SECURE=true
|
|
@@ -139,36 +182,75 @@ credentials in the deployment's secret manager, never in form YAML. Use valid
|
|
|
139
182
|
sender and recipient addresses; Email Sending is intended for transactional
|
|
140
183
|
mail, not bulk marketing.
|
|
141
184
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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. |
|
package/package.json
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
export function localPreviewDevIntegration(projectRoot) {
|
|
4
|
+
const sourceFilePrefix = `/@fs${path.resolve(projectRoot, 'src').replace(/\\/g, '/')}/`;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
name: 'kama-local-preview-dev-security',
|
|
8
|
+
hooks: {
|
|
9
|
+
'astro:config:setup': ({ command, updateConfig }) => {
|
|
10
|
+
if (command !== 'dev') return;
|
|
11
|
+
|
|
12
|
+
updateConfig({
|
|
13
|
+
vite: {
|
|
14
|
+
plugins: [{
|
|
15
|
+
name: 'kama:allow-sandboxed-preview-assets',
|
|
16
|
+
enforce: 'post',
|
|
17
|
+
configureServer(server) {
|
|
18
|
+
return () => {
|
|
19
|
+
server.middlewares.stack.unshift({
|
|
20
|
+
route: '',
|
|
21
|
+
handle: async (request, response, next) => {
|
|
22
|
+
if (
|
|
23
|
+
request.headers.origin !== 'null' ||
|
|
24
|
+
request.headers['sec-fetch-site'] !== 'cross-site' ||
|
|
25
|
+
!['GET', 'HEAD'].includes(request.method || '')
|
|
26
|
+
) {
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let pathname;
|
|
31
|
+
try {
|
|
32
|
+
pathname = new URL(request.url || '/', 'http://localhost').pathname;
|
|
33
|
+
} catch {
|
|
34
|
+
return next();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isViteAsset =
|
|
38
|
+
pathname === '/@vite/client' ||
|
|
39
|
+
pathname === '/@vite/env' ||
|
|
40
|
+
pathname.startsWith('/@id/') ||
|
|
41
|
+
pathname.startsWith('/node_modules/.vite/') ||
|
|
42
|
+
pathname.startsWith('/src/') ||
|
|
43
|
+
(pathname.startsWith('/@fs/') && pathname.includes('/node_modules/vite/dist/client/')) ||
|
|
44
|
+
pathname.startsWith(sourceFilePrefix);
|
|
45
|
+
|
|
46
|
+
if (isViteAsset) {
|
|
47
|
+
const isStylesheet = request.headers.accept?.includes('text/css') || false;
|
|
48
|
+
let transformUrl = request.url || '/';
|
|
49
|
+
if (isStylesheet && !/[?&]direct(?:&|$)/.test(transformUrl)) {
|
|
50
|
+
transformUrl += transformUrl.includes('?') ? '&direct' : '?direct';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const result = await server.environments.client.transformRequest(transformUrl);
|
|
55
|
+
if (!result) return next();
|
|
56
|
+
|
|
57
|
+
response.statusCode = 200;
|
|
58
|
+
response.setHeader('Access-Control-Allow-Origin', 'null');
|
|
59
|
+
response.setHeader('Vary', 'Origin');
|
|
60
|
+
response.setHeader('Cache-Control', 'no-cache');
|
|
61
|
+
response.setHeader(
|
|
62
|
+
'Content-Type',
|
|
63
|
+
isStylesheet ? 'text/css; charset=utf-8' : 'text/javascript; charset=utf-8',
|
|
64
|
+
);
|
|
65
|
+
return response.end(request.method === 'HEAD' ? undefined : result.code);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return next(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (pathname.startsWith('/media/')) request.headers['sec-fetch-site'] = 'same-site';
|
|
72
|
+
next();
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
}],
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -2,6 +2,7 @@ import { defineConfig } from 'astro/config';
|
|
|
2
2
|
import node from '@astrojs/node';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { localPreviewDevIntegration } from './astro-preview-dev-integration.mjs';
|
|
5
6
|
|
|
6
7
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
8
|
|
|
@@ -13,7 +14,17 @@ export default defineConfig({
|
|
|
13
14
|
trailingSlash: 'ignore',
|
|
14
15
|
image: { service: { entrypoint: './src/lib/media/kama-image-service.ts' } },
|
|
15
16
|
adapter: node({ mode: "standalone" }),
|
|
17
|
+
integrations: [localPreviewDevIntegration(__dirname)],
|
|
16
18
|
vite: {
|
|
19
|
+
server: {
|
|
20
|
+
cors: {
|
|
21
|
+
origin: [
|
|
22
|
+
"null",
|
|
23
|
+
/^https?:\/\/localhost(?::\d+)?$/,
|
|
24
|
+
/^https?:\/\/127\.0\.0\.1(?::\d+)?$/,
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
17
28
|
resolve: { alias: { '@': path.resolve(__dirname, './src') } },
|
|
18
29
|
ssr: {
|
|
19
30
|
external: ['cloudflare:workers', 'tinyexec', 'node:child_process', 'node:fs', 'node:url', 'node:path', 'node:stream', 'node:readline', 'node:stream/promises']
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
// src/components/global/NavigationMenu.astro
|
|
3
|
-
import type
|
|
3
|
+
import { getTreeNodeMenuTitle, type TreeNode } from "@/lib/cms";
|
|
4
4
|
|
|
5
5
|
export interface Props {
|
|
6
6
|
tree?: TreeNode[];
|
|
@@ -67,6 +67,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
67
67
|
<ul class="nav-list">
|
|
68
68
|
{
|
|
69
69
|
topLevelNavItems.map(item => {
|
|
70
|
+
const menuTitle = getTreeNodeMenuTitle(item);
|
|
70
71
|
// ✨ NEW: Also filter children for notInMenu
|
|
71
72
|
const visibleChildren =
|
|
72
73
|
item.children?.filter(child => !(child as any).notInMenu) || [];
|
|
@@ -84,7 +85,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
84
85
|
{ active: isParentActive },
|
|
85
86
|
]}
|
|
86
87
|
>
|
|
87
|
-
|
|
88
|
+
<span>{menuTitle}</span>
|
|
88
89
|
<span class="indicator">▼</span>
|
|
89
90
|
</summary>
|
|
90
91
|
<div class="submenu-container">
|
|
@@ -98,7 +99,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
98
99
|
{ active: isExactActive(item.path) },
|
|
99
100
|
]}
|
|
100
101
|
>
|
|
101
|
-
{
|
|
102
|
+
{menuTitle} Overview
|
|
102
103
|
</a>
|
|
103
104
|
</li>
|
|
104
105
|
{visibleChildren.map(child => (
|
|
@@ -110,7 +111,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
110
111
|
{ active: isExactActive(child.path) },
|
|
111
112
|
]}
|
|
112
113
|
>
|
|
113
|
-
{child
|
|
114
|
+
{getTreeNodeMenuTitle(child)}
|
|
114
115
|
</a>
|
|
115
116
|
</li>
|
|
116
117
|
))}
|
|
@@ -127,7 +128,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
127
128
|
href={item.path}
|
|
128
129
|
class:list={["nav-button", { active: isExactActive(item.path) }]}
|
|
129
130
|
>
|
|
130
|
-
{
|
|
131
|
+
{menuTitle}
|
|
131
132
|
</a>
|
|
132
133
|
</li>
|
|
133
134
|
);
|
|
@@ -5,6 +5,7 @@ export interface TreeNode {
|
|
|
5
5
|
treeNodeId: number;
|
|
6
6
|
parentId: number | null;
|
|
7
7
|
title: string;
|
|
8
|
+
menuTitle?: string;
|
|
8
9
|
slug: string;
|
|
9
10
|
path: string;
|
|
10
11
|
nodeType: string;
|
|
@@ -16,6 +17,12 @@ export interface TreeNode {
|
|
|
16
17
|
[key: string]: any;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
export function getTreeNodeMenuTitle(node: Pick<TreeNode, 'title' | 'menuTitle'>): string {
|
|
21
|
+
return typeof node.menuTitle === 'string' && node.menuTitle.trim()
|
|
22
|
+
? node.menuTitle.trim()
|
|
23
|
+
: node.title;
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
export interface ContentBlock {
|
|
20
27
|
instanceId: number;
|
|
21
28
|
componentId: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/middleware.ts
|
|
2
2
|
|
|
3
3
|
import { defineMiddleware } from "astro:middleware";
|
|
4
|
+
import { fetchCmsRequest } from "./lib/cms-fetch";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Safely extracts environment variables across Astro 7, Node.js, and Cloudflare Workers
|
|
@@ -104,20 +105,21 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|
|
104
105
|
|
|
105
106
|
// 2. Cold Fetch: Pass to CMS worker for AVIF transformation
|
|
106
107
|
const cmsWorker = workerEnv?.CMS_WORKER;
|
|
107
|
-
const envApiUrl = import.meta.env?.PUBLIC_API_URL;
|
|
108
|
-
const workerApiUrl = workerEnv?.PUBLIC_API_URL;
|
|
109
|
-
const
|
|
108
|
+
const envApiUrl = import.meta.env?.PUBLIC_API_URL || import.meta.env?.PUBLIC_CMS_URL;
|
|
109
|
+
const workerApiUrl = workerEnv?.PUBLIC_API_URL || workerEnv?.PUBLIC_CMS_URL;
|
|
110
|
+
const localDevApiUrl = "http://127.0.0.1:8787";
|
|
111
|
+
const fallbackApiUrl = isDev ? localDevApiUrl : "https://kama.kamaengine.com";
|
|
112
|
+
const baseApiUrl = String(
|
|
113
|
+
isDev && !cmsWorker
|
|
114
|
+
? localDevApiUrl
|
|
115
|
+
: workerApiUrl || envApiUrl || fallbackApiUrl
|
|
116
|
+
);
|
|
110
117
|
const cleanApiUrl = baseApiUrl.endsWith("/") ? baseApiUrl.slice(0, -1) : baseApiUrl;
|
|
111
118
|
|
|
112
119
|
const mediaUrl = `${cleanApiUrl}${pathname}${context.url.search}`;
|
|
113
120
|
const mediaReq = new Request(mediaUrl, { headers: context.request.headers });
|
|
114
121
|
|
|
115
|
-
|
|
116
|
-
if (cmsWorker && typeof cmsWorker.fetch === "function") {
|
|
117
|
-
mediaResponse = await cmsWorker.fetch(mediaReq);
|
|
118
|
-
} else {
|
|
119
|
-
mediaResponse = await fetch(mediaReq);
|
|
120
|
-
}
|
|
122
|
+
const mediaResponse = await fetchCmsRequest(mediaReq, cmsWorker);
|
|
121
123
|
|
|
122
124
|
const newHeaders = new Headers(mediaResponse.headers);
|
|
123
125
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export const partial = true; // 🎯 Tells Astro not to wrap this in <html><body>
|
|
4
4
|
|
|
5
5
|
import { getTree, getTreeId, getChannelId } from "@/lib/cms";
|
|
6
|
-
import type
|
|
6
|
+
import { getTreeNodeMenuTitle, type TreeNode } from "@/lib/cms";
|
|
7
7
|
|
|
8
8
|
const safeEnv = (Astro.locals as any).safeEnv || {};
|
|
9
9
|
const cmsWorker = safeEnv.CMS_WORKER;
|
|
@@ -75,6 +75,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
75
75
|
<ul class="nav-list">
|
|
76
76
|
{
|
|
77
77
|
topLevelNavItems.map(item => {
|
|
78
|
+
const menuTitle = getTreeNodeMenuTitle(item);
|
|
78
79
|
const hasChildren = item.children && item.children.length > 0;
|
|
79
80
|
const isParentActive = isPathActive(item.path);
|
|
80
81
|
|
|
@@ -89,7 +90,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
89
90
|
{ active: isParentActive },
|
|
90
91
|
]}
|
|
91
92
|
>
|
|
92
|
-
<span>{
|
|
93
|
+
<span>{menuTitle}</span>
|
|
93
94
|
<span class="indicator">▼</span>
|
|
94
95
|
</summary>
|
|
95
96
|
<div class="submenu-container">
|
|
@@ -103,7 +104,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
103
104
|
{ active: isExactActive(item.path) },
|
|
104
105
|
]}
|
|
105
106
|
>
|
|
106
|
-
{
|
|
107
|
+
{menuTitle} Overview
|
|
107
108
|
</a>
|
|
108
109
|
</li>
|
|
109
110
|
{item.children?.map(child => (
|
|
@@ -115,7 +116,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
115
116
|
{ active: isExactActive(child.path) },
|
|
116
117
|
]}
|
|
117
118
|
>
|
|
118
|
-
{child
|
|
119
|
+
{getTreeNodeMenuTitle(child)}
|
|
119
120
|
</a>
|
|
120
121
|
</li>
|
|
121
122
|
))}
|
|
@@ -132,7 +133,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
132
133
|
href={item.path}
|
|
133
134
|
class:list={["nav-button", { active: isExactActive(item.path) }]}
|
|
134
135
|
>
|
|
135
|
-
{
|
|
136
|
+
{menuTitle}
|
|
136
137
|
</a>
|
|
137
138
|
</li>
|
|
138
139
|
);
|