WIP: form attachments (e-mail only) — core, endpoint, Graph large upload

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-13 16:20:02 +01:00
co-authored by Claude Fable 5.2
parent 0ba0014ed5
commit 6003b3d7d7
36 changed files with 2399 additions and 97 deletions
@@ -1,6 +1,15 @@
import type { SubmitFormResult } from '../forms/index.js'
import type { FormNotificationTexts } from './types.js'
/**
* The texts resolveFormMessage needs. The File-field texts are optional, so an
* object written before they existed still fits (the field or general text is used).
*/
export type FormMessageTexts = { [K in 'fileCount' | 'fileNotSent' | 'fileRemove' | 'fileTooLarge' | 'fileType']?: string } & Omit<
FormNotificationTexts,
'fileCount' | 'fileNotSent' | 'fileRemove' | 'fileTooLarge' | 'fileType'
>
/**
* Maps a submitForm result to the user-facing message, interpolating {field}
* with the field's label (its key when the form has no label) for validation
@@ -12,12 +21,14 @@ import type { FormNotificationTexts } from './types.js'
* Never surfaces raw backend/exception detail — 'error' maps to a friendly
* generic message, not the thrown error's text (which could leak internals).
*/
export function resolveFormMessage(result: SubmitFormResult, texts: FormNotificationTexts): string {
export function resolveFormMessage(result: SubmitFormResult, texts: FormMessageTexts): string {
if (result.success) {return texts.success}
switch (result.reason) {
case 'consent':
return texts.consent
case 'delivery':
return texts.fileNotSent ?? texts.error
case 'not_found':
return texts.notFound
case 'rate_limited':
@@ -27,6 +38,15 @@ export function resolveFormMessage(result: SubmitFormResult, texts: FormNotifica
case 'validation': {
// {field} → the label the visitor sees; no single field at fault → the generic error.
const field = result.label || result.field
const fill = (text: string) =>
text
.replace('{file}', result.file ?? '')
.replace('{max}', result.max === undefined ? '' : String(result.max))
.replace('{types}', result.types ?? '')
.replace('{field}', field ?? '')
if (result.kind === 'file_too_large' && texts.fileTooLarge) {return fill(texts.fileTooLarge)}
if (result.kind === 'file_type' && texts.fileType) {return fill(texts.fileType)}
if (result.kind === 'file_count' && texts.fileCount) {return fill(texts.fileCount)}
return field ? texts.validation.replace('{field}', field) : texts.error
}
case 'error':