Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -5,22 +5,27 @@
|
||||
* The embedded renderer + submission API both parse against the same schemas
|
||||
* so the contract is enforced at every boundary.
|
||||
*
|
||||
* Field-type set is intentionally conservative for Phase-1: text, email,
|
||||
* number, textarea, select, radio, checkbox, honeypot. File-upload is
|
||||
* out-of-scope (see security notes in the detail-md).
|
||||
* AK-P16c field-type set: 12 user-facing types plus the hidden honeypot
|
||||
* system field. The public renderer and submit API parse the same schema so
|
||||
* builder changes cannot bypass server validation.
|
||||
*/
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
/** Field-types accepted by the Phase-1 form-builder. */
|
||||
/** Field-types accepted by the AK-P16c form-builder. */
|
||||
export const FieldTypeSchema = z.enum([
|
||||
"text",
|
||||
"email",
|
||||
"number",
|
||||
"textarea",
|
||||
"number",
|
||||
"date",
|
||||
"time",
|
||||
"select",
|
||||
"radio",
|
||||
"checkbox",
|
||||
"multiselect",
|
||||
"boolean",
|
||||
"email",
|
||||
"phone",
|
||||
"file",
|
||||
"photo",
|
||||
"honeypot",
|
||||
]);
|
||||
|
||||
@@ -34,6 +39,36 @@ const FieldOption = z.object({
|
||||
label: z.string().min(1).max(200),
|
||||
});
|
||||
|
||||
export const ConditionalOperatorSchema = z.enum([
|
||||
"equals",
|
||||
"not_equals",
|
||||
"contains",
|
||||
"not_empty",
|
||||
"empty",
|
||||
"in",
|
||||
]);
|
||||
|
||||
export const ConditionalLogicRuleSchema = z.object({
|
||||
fieldKey: z.string().min(1).max(64),
|
||||
operator: ConditionalOperatorSchema,
|
||||
value: z.union([z.string().max(500), z.number(), z.boolean(), z.array(z.string().max(120)).max(50), z.null()]).optional(),
|
||||
});
|
||||
|
||||
export const FieldValidationRulesSchema = z.object({
|
||||
minLength: z.number().int().min(0).max(10000).optional(),
|
||||
maxLength: z.number().int().min(1).max(10000).optional(),
|
||||
min: z.number().optional(),
|
||||
max: z.number().optional(),
|
||||
pattern: z.string().max(500).optional(),
|
||||
minSelected: z.number().int().min(0).max(50).optional(),
|
||||
maxSelected: z.number().int().min(1).max(50).optional(),
|
||||
acceptedFileTypes: z.array(z.string().min(1).max(100)).max(50).optional(),
|
||||
maxFileSizeMb: z.number().int().min(1).max(100).optional(),
|
||||
});
|
||||
|
||||
export type ConditionalLogicRule = z.infer<typeof ConditionalLogicRuleSchema>;
|
||||
export type FieldValidationRules = z.infer<typeof FieldValidationRulesSchema>;
|
||||
|
||||
export const FormFieldSchema = z
|
||||
.object({
|
||||
key: z
|
||||
@@ -47,11 +82,13 @@ export const FormFieldSchema = z
|
||||
placeholder: z.string().max(200).optional(),
|
||||
required: z.boolean().default(false),
|
||||
options: z.array(FieldOption).max(50).optional(),
|
||||
conditionalLogic: z.array(ConditionalLogicRuleSchema).max(20).default([]),
|
||||
validationRules: FieldValidationRulesSchema.default({}),
|
||||
minLength: z.number().int().min(0).max(10000).optional(),
|
||||
maxLength: z.number().int().min(1).max(10000).optional(),
|
||||
})
|
||||
.superRefine((field, ctx) => {
|
||||
if ((field.type === "select" || field.type === "radio") && (!field.options || field.options.length === 0)) {
|
||||
if ((field.type === "select" || field.type === "multiselect") && (!field.options || field.options.length === 0)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `field ${field.key}: type ${field.type} requires at least one option`,
|
||||
@@ -63,6 +100,25 @@ export const FormFieldSchema = z
|
||||
message: `field ${field.key}: minLength must be <= maxLength`,
|
||||
});
|
||||
}
|
||||
const rules = field.validationRules ?? {};
|
||||
if (rules.minLength !== undefined && rules.maxLength !== undefined && rules.minLength > rules.maxLength) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `field ${field.key}: validationRules.minLength must be <= maxLength`,
|
||||
});
|
||||
}
|
||||
if (rules.min !== undefined && rules.max !== undefined && rules.min > rules.max) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `field ${field.key}: validationRules.min must be <= max`,
|
||||
});
|
||||
}
|
||||
if (rules.minSelected !== undefined && rules.maxSelected !== undefined && rules.minSelected > rules.maxSelected) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `field ${field.key}: validationRules.minSelected must be <= maxSelected`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export type FormField = z.infer<typeof FormFieldSchema>;
|
||||
@@ -92,6 +148,8 @@ export const FormDefinitionSchema = z
|
||||
description: z.string().max(2000).optional(),
|
||||
submitLabel: z.string().min(1).max(100).default("Submit"),
|
||||
successMessage: z.string().min(1).max(500).default("Thanks — we received your submission."),
|
||||
gdprConsentLabel: z.string().min(1).max(500).default("I agree to the processing of my data for this request."),
|
||||
captchaEnabled: z.boolean().default(true),
|
||||
fields: z.array(FormFieldSchema).min(1).max(50),
|
||||
})
|
||||
.superRefine((def, ctx) => {
|
||||
@@ -101,6 +159,11 @@ export const FormDefinitionSchema = z
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `duplicate field key: ${field.key}` });
|
||||
}
|
||||
seen.add(field.key);
|
||||
for (const rule of field.conditionalLogic ?? []) {
|
||||
if (rule.fieldKey === field.key) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `field ${field.key}: conditional rule cannot reference itself` });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -110,9 +173,21 @@ export type FormDefinition = z.infer<typeof FormDefinitionSchema>;
|
||||
* here because each form has a different shape; the route handler validates
|
||||
* required-ness + length against the form's stored definition. */
|
||||
export const FormSubmissionPayloadSchema = z.object({
|
||||
values: z.record(z.string().max(64), z.union([z.string().max(10000), z.boolean(), z.number(), z.null()])),
|
||||
values: z.record(
|
||||
z.string().max(64),
|
||||
z.union([
|
||||
z.string().max(10000),
|
||||
z.boolean(),
|
||||
z.number(),
|
||||
z.array(z.string().max(1000)).max(50),
|
||||
z.null(),
|
||||
]),
|
||||
),
|
||||
origin: z.string().max(500).optional(),
|
||||
turnstileToken: z.string().max(4096).optional(),
|
||||
captchaToken: z.string().max(4096).optional(),
|
||||
gdprAccepted: z.boolean().optional(),
|
||||
idempotencyKey: z.string().min(8).max(120).optional(),
|
||||
});
|
||||
|
||||
export type FormSubmissionPayload = z.infer<typeof FormSubmissionPayloadSchema>;
|
||||
Reference in new issue
Block a user