From b7fb1b0e31ece55d1ed0b942e3e6b8a7bdddaedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Fri, 13 Nov 2026 16:32:45 +0100 Subject: [PATCH] =?UTF-8?q?WIP:=20form=20attachments=20=E2=80=94=20agent?= =?UTF-8?q?=20guide,=20skills,=20seed=20template,=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5.2 --- docs/CHANGELOG.md | 59 +++++++++++++++++++ docs/agent/AGENT.md | 5 +- docs/agent/skills/ipal-form/SKILL.md | 41 +++++++++++++ .../skills/ipal-form/resources/formClasses.ts | 6 ++ .../ipal-form/resources/seed-form.template.ts | 5 ++ docs/agent/skills/ipal-reference/SKILL.md | 5 +- .../skills/ipal-reference/resources/api.md | 12 +++- docs/dev/form-attachments-proposal.md | 22 +++---- 8 files changed, 140 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index cf09ffe..283952f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,65 @@ versions at once, go through every "Requires project changes" section in order, version you have. A new release = a new section at the top; we remove the oldest ones only once there are more than 20. +## Unreleased + +### Added +- **Files on forms, sent by e-mail and never stored** (`forms: { attachments: true }`, [forms.md](./forms.md) "Files"). + A new **File** field in the form builder: label and help text per language, required, allowed file types, + maximum size and number of files, "Show only when". A file a visitor attaches is checked, attached to the + company notification e-mail and dropped. There is no upload collection, bucket, disk write or download route; + the submission keeps the file's name, type and size and whether the mail server took the message. + - **Checks, in order, before a file is accepted:** same origin, rate limit, declared size, a concurrency guard, + honeypot, Turnstile, field validation and GDPR consent, then per file: count, name (double and refused + extensions), size while reading, content signature, container and macro checks. Programs, scripts, + macro-enabled Office files, archives, HTML and SVG are refused unless the project allows the extension + (`allowRisky`). **No antivirus is built in** — `attachments.scan` is the hook for one. + - **E-mail:** the file goes to every e-mail of the form whose recipients are fixed addresses from the panel; an + e-mail addressed with a placeholder (the confirmation to the visitor) never carries it. `{{field}}`, `{{*}}` and + `{{*:table}}` show the file name. + - **A failed send is visible:** the visitor sees "We could not send your file…" and can retry, staff get the + notification without the file, the submission is marked **File delivery: Not sent**. A repeated request + (double click, a resend) sends nothing twice. + - Browser: `RenderForm` / `BuilderForm` render a native file input with help text, the list of picked files and + a "Remove" button; `useBuilderForm` gains `getFileProps`, `getFiles`, `removeFile`, `helpId`, + `getHoneypotProps`; new `classNames` keys `file`, `help`, `fileList`, `fileItem`, `fileRemove`. + - New texts in Form messages → **Files** (`fileTooLarge`, `fileType`, `fileCount`, `fileNotSent`, `fileRemove`), + English and Polish defaults. + - New exports: `buildFileBlock`, `fileBlock`, `FORM_FILE_TYPES`, `RISKY_FILE_EXTENSIONS`, `formatFileSize`, + `mailAttachmentLimit` (root); `fileFieldRules`, `fileFieldError`, `formatFileSize` (`/client`); + `splitFormFiles` (`/server`); `submitForm({ files, attemptKey })`; result codes `kind: 'file_too_large' | + 'file_type' | 'file_count'` and `reason: 'delivery'`. +- **Attachments over both e-mail transports** ([email.md](./email.md) "Attachments"). SMTP passes them through. + Microsoft Graph sends attachments under 3 MB in the one `sendMail` call; larger ones go through a draft and an + upload session, and the copy the mailbox keeps is deleted afterwards. That path needs the `Mail.ReadWrite` + application permission (limit it to the forms mailbox — steps in email.md). Without the permission the message + goes over SMTP when the panel has SMTP settings; otherwise the form's file limit drops to about 2.8 MB. + `mailAdapter({ graph: { largeAttachments: false } })` turns the large path off. +- **Test e-mail with a 10 MB file:** a checkbox next to "Send test e-mail" (endpoint body `attachmentMB`) — shows + whether the mail server takes a file of that size. + +### Fixed +- **The honeypot of `BuilderForm` / `RenderForm` now reaches the server.** The hidden field was rendered, but its + value was not part of what the form sent, so a bot that filled it was not dropped. It is now sent with the + submission (`createSubmitAction` checks and strips it, as before). A hand-written action that calls `submitForm` + directly must strip `HONEYPOT_FIELD` first, as the example in forms.md always did — otherwise a filled honeypot + is answered with "unknown field" instead of the fake success. + +### Changed +- The Microsoft Graph access token is cached in the process until a minute before it expires (it was fetched on + every send). + +### What projects must update +- **Nothing is required.** Without `forms.attachments` the forms config, collections and routes are unchanged. +- To use files on forms: set `forms: { attachments: true }`, add a **File** field to the form (panel or seed), keep + one e-mail with a fixed recipient on that form, run `pnpm generate:types`. **Postgres / SQLite:** + `pnpm payload migrate:create` (the File block tables, three columns and one array table on submissions, the new + Form messages columns — all additive). MongoDB: no migration. +- Add the classes `file`, `help`, `fileList`, `fileItem`, `fileRemove` to `src/components/forms/formClasses.ts` + (template in the `ipal-form` skill) and fill Form messages → Files for languages other than English and Polish. +- Send the test e-mail with the 10 MB file once per site; with Microsoft Graph, grant `Mail.ReadWrite` limited to + the forms mailbox, or keep files under 3 MB. + ## 1.15.5 ### Fixed diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index 587bb7f..4fde28a 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -220,6 +220,7 @@ Do not make the provider or the widget conditional in code — always wire them. | Instead of the plugin | Why not | Use | |---|---|---| | your own form with fields in JSX, `react-hook-form`, `formik`, your own form renderer | the client cannot change the fields; no Turnstile, rate limit, GDPR consent; a copy of the engine passes addresses from the Emails tab into HTML | the builder in the panel + `` (look: `formClasses`, unusual cases: `useBuilderForm`) | +| a file input wired by hand, your own upload route, form files saved to Media / R2 / disk | candidate and customer documents end up public or kept forever; no type, size or macro checks; the gates are skipped | `forms: { attachments: true }` + the **File** field — the file is e-mailed to the company and never stored (forms.md "Files") | | your own `api/contact` / `api/send` / `api/form` route, `nodemailer` / `resend` / `@sendgrid` in the project | bypasses the `submitForm` validation and gates, a second mail transport | the `sendForm` server action → `submitForm`, mails from Forms → Emails via `mailAdapter()` | | reCAPTCHA, hCaptcha, your own captcha | a second mechanism, no status in the panel | Turnstile from the plugin | | a hand-written `