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:
co-authored by
Claude Fable 5.2
parent
0ba0014ed5
commit
6003b3d7d7
@@ -6,8 +6,13 @@ import { visibleFields } from './builderLogic.js'
|
||||
|
||||
/** A form-builder field, trimmed to what validation needs. */
|
||||
type FormField = {
|
||||
/** file */
|
||||
allowedTypes?: null | string[]
|
||||
blockType?: string
|
||||
label?: string
|
||||
/** file */
|
||||
maxFiles?: null | number
|
||||
maxSizeMB?: null | number
|
||||
/** checkboxGroup limits. */
|
||||
maxSelected?: null | number
|
||||
minSelected?: null | number
|
||||
@@ -20,6 +25,8 @@ type FormField = {
|
||||
}
|
||||
|
||||
type FormDoc = {
|
||||
/** Emails tab — read by the file delivery (which e-mail may carry a file). */
|
||||
emails?: { bcc?: null | string; cc?: null | string; emailTo?: null | string }[] | null
|
||||
fields?: FormField[]
|
||||
id: number | string
|
||||
/** Per-form notification address, when the client added the field. */
|
||||
@@ -39,7 +46,13 @@ export type FormValidationResult =
|
||||
ok: false
|
||||
reason: 'invalid'
|
||||
}
|
||||
| { cleaned: Record<string, unknown>; form: FormDoc; ok: true }
|
||||
| {
|
||||
cleaned: Record<string, unknown>
|
||||
/** File fields the visitor could see — their files are checked separately (attachments/fileGate). */
|
||||
fileFields: ({ name: string } & FormField)[]
|
||||
form: FormDoc
|
||||
ok: true
|
||||
}
|
||||
| { field: string; ok: false; reason: 'consent' }
|
||||
| { ok: false; reason: 'not_found' }
|
||||
|
||||
@@ -186,12 +199,22 @@ export async function validateSubmission(
|
||||
const shown = new Set(visibleFields(form.fields, data))
|
||||
|
||||
const cleaned: Record<string, unknown> = {}
|
||||
const fileFields: ({ name: string } & FormField)[] = []
|
||||
|
||||
for (const field of fields) {
|
||||
// Hidden by a condition: not required, not stored. The consent gate never hides —
|
||||
// an editor can't switch GDPR consent off with a condition.
|
||||
if (!shown.has(field) && field.name !== consentFieldName) {continue}
|
||||
const value = data[field.name]
|
||||
// A File field carries no text value: its files arrive separately and are
|
||||
// checked by the file gate. Anything sent under its key as data is tampering.
|
||||
if (field.blockType === 'file') {
|
||||
if (value != null && value !== '' && !(Array.isArray(value) && value.length === 0)) {
|
||||
return { field: field.name, kind: 'invalid_format', ok: false, reason: 'invalid' }
|
||||
}
|
||||
fileFields.push(field)
|
||||
continue
|
||||
}
|
||||
const isBlank =
|
||||
value == null ||
|
||||
(typeof value === 'string' && value.trim() === '') ||
|
||||
@@ -235,5 +258,5 @@ export async function validateSubmission(
|
||||
return { kind: 'unknown_fields', ok: false, reason: 'invalid' }
|
||||
}
|
||||
|
||||
return { cleaned, form, ok: true }
|
||||
return { cleaned, fileFields, form, ok: true }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user