@foundrykit/form-plugin 1.16.6 → 1.17.0

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/README.md CHANGED
@@ -107,6 +107,23 @@ forgiven. Watch the logs for `[forms] captcha could not be verified`.
107
107
  Register the site key against every domain that serves forms, including
108
108
  `localhost` for development, or every local submit will fail verification.
109
109
 
110
+ ## Rate limiting
111
+
112
+ Opt in with `rateLimit` to cap submissions per client IP on
113
+ `POST /api/form-submit/:formSlug`. Counts live in Payload's KV store, via
114
+ [`@foundrykit/rate-limit`](../rate-limit). Over the limit, the endpoint answers
115
+ `429` with `Retry-After`.
116
+
117
+ ```ts
118
+ formPlugin({
119
+ rateLimit: { limit: 5, window: 60, trustedProxies: true }, // 5 per minute per IP
120
+ });
121
+ ```
122
+
123
+ Set `trustedProxies` to `true` behind a single proxy (Vercel, Dokploy's
124
+ Traefik), or to a list of proxy IPs. Without it, `x-forwarded-for` is ignored
125
+ and every visitor shares one bucket.
126
+
110
127
  ---
111
128
 
112
129
  ## Collections
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { withRateLimit } from '@foundrykit/rate-limit';
1
2
  import { recordActivePlugin } from './activePlugins.js';
2
3
  import { AddressBlock } from './blocks/fields/Address.js';
3
4
  import { CheckboxBlock } from './blocks/fields/Checkbox.js';
@@ -92,7 +93,10 @@ export const formPlugin = (pluginOptions)=>(config)=>{
92
93
  path: `/form-data/:slug`
93
94
  },
94
95
  {
95
- handler: createSubmitFormHandler(pluginOptions),
96
+ handler: pluginOptions.rateLimit ? withRateLimit(createSubmitFormHandler(pluginOptions), {
97
+ key: (_req, ip)=>`form-submit:${ip}`,
98
+ ...pluginOptions.rateLimit
99
+ }) : createSubmitFormHandler(pluginOptions),
96
100
  method: 'post',
97
101
  path: `/${FORM_SUBMIT_PATH}/:formSlug`
98
102
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Block, Config } from 'payload';\nimport { recordActivePlugin } from './activePlugins.js';\nimport { AddressBlock } from './blocks/fields/Address.js';\nimport { CheckboxBlock } from './blocks/fields/Checkbox.js';\nimport { CheckboxGroupBlock } from './blocks/fields/CheckboxGroup.js';\nimport { DateBlock } from './blocks/fields/Date.js';\nimport { EmailBlock } from './blocks/fields/Email.js';\nimport { FileBlock } from './blocks/fields/File.js';\nimport { NumberBlock } from './blocks/fields/Number.js';\nimport { PhoneBlock } from './blocks/fields/Phone.js';\nimport { RadioGroupBlock } from './blocks/fields/RadioGroup.js';\nimport { SelectBlock } from './blocks/fields/Select.js';\nimport { TextBlock } from './blocks/fields/Text.js';\nimport { TextareaBlock } from './blocks/fields/Textarea.js';\nimport { createFormsCollection } from './collections/Forms.js';\nimport { createSubmissionsCollection } from './collections/Submissions.js';\nimport { createFetchFormHandler } from './endpoints/fetchFormHandler.js';\nimport { createSubmitFormHandler } from './endpoints/submitFormHandler.js';\nimport type { FieldsConfig, FormPluginConfig } from './types.js';\nimport { FORM_SUBMIT_PATH } from './utilities/buildSubmitURL.js';\n\nexport {\n baseFieldBlockFields,\n optionsArrayField,\n} from './blocks/fields/shared.js';\nexport { TravelDateBlock } from './blocks/fields/TravelDate.js';\nexport { buildVisibilityField } from './blocks/fields/visibility.js';\nexport { lockableTextField } from './fields/lockable/index.js';\nexport type {\n CaptchaConfig,\n FormPluginConfig,\n PublicCaptchaConfig,\n} from './types.js';\nexport { parseTravelDate, type TravelDate } from './utilities/travelDate.js';\nexport { validateVisibleSubmission } from './utilities/validateVisibleSubmission.js';\nexport {\n type CaptchaVerification,\n DEFAULT_ACTION,\n DEFAULT_MIN_SCORE,\n isCaptchaEnabled,\n verifyCaptcha,\n} from './utilities/verifyCaptcha.js';\n\nconst DEFAULT_FIELD_BLOCKS: Block[] = [\n TextBlock,\n EmailBlock,\n PhoneBlock,\n TextareaBlock,\n CheckboxBlock,\n RadioGroupBlock,\n CheckboxGroupBlock,\n SelectBlock,\n NumberBlock,\n DateBlock,\n FileBlock,\n AddressBlock,\n];\n\nfunction buildFieldBlocks(fieldsConfig: FieldsConfig | undefined): Block[] {\n if (!fieldsConfig) return DEFAULT_FIELD_BLOCKS;\n const result: Block[] = [];\n for (const block of DEFAULT_FIELD_BLOCKS) {\n const entry = fieldsConfig[block.slug];\n if (entry === false) continue;\n if (entry && typeof entry === 'object' && 'block' in entry) {\n result.push(entry.block);\n continue;\n }\n result.push(block);\n }\n const defaultSlugs = new Set(DEFAULT_FIELD_BLOCKS.map(b => b.slug));\n for (const [slug, entry] of Object.entries(fieldsConfig)) {\n if (\n !defaultSlugs.has(slug) &&\n entry &&\n typeof entry === 'object' &&\n 'block' in entry\n ) {\n result.push(entry.block);\n }\n }\n return result;\n}\n\nexport const formPlugin =\n (pluginOptions: FormPluginConfig) =>\n (config: Config): Config => {\n const formsSlug = pluginOptions.collections?.forms ?? 'forms';\n const submissionsSlug =\n pluginOptions.collections?.submissions ?? 'form-submissions';\n const mediaCollection = pluginOptions.mediaCollection ?? 'media';\n const singularFormsLabel = pluginOptions.labels?.forms ?? 'Form';\n const singularSubmissionsLabel =\n pluginOptions.labels?.submissions ?? 'Form Submission';\n const fieldBlocks = buildFieldBlocks(pluginOptions.fields);\n\n config.collections = [\n ...(config.collections ?? []),\n createFormsCollection({\n formsSlug,\n mediaCollection,\n singularLabel: singularFormsLabel,\n pluralLabel: `${singularFormsLabel}s`,\n fieldBlocks,\n richTextEditor: pluginOptions.richTextEditor,\n }),\n createSubmissionsCollection({\n submissionsSlug,\n formsSlug,\n singularLabel: singularSubmissionsLabel,\n pluralLabel: `${singularSubmissionsLabel}s`,\n }),\n ];\n\n if (pluginOptions.disabled) {\n return config;\n }\n\n config.endpoints = [\n ...(config.endpoints ?? []),\n {\n handler: createFetchFormHandler(pluginOptions),\n method: 'get',\n path: `/form-data/:slug`,\n },\n {\n handler: createSubmitFormHandler(pluginOptions),\n method: 'post',\n path: `/${FORM_SUBMIT_PATH}/:formSlug`,\n },\n ];\n\n return recordActivePlugin(config, '@foundrykit/form-plugin');\n };\n"],"names":["recordActivePlugin","AddressBlock","CheckboxBlock","CheckboxGroupBlock","DateBlock","EmailBlock","FileBlock","NumberBlock","PhoneBlock","RadioGroupBlock","SelectBlock","TextBlock","TextareaBlock","createFormsCollection","createSubmissionsCollection","createFetchFormHandler","createSubmitFormHandler","FORM_SUBMIT_PATH","baseFieldBlockFields","optionsArrayField","TravelDateBlock","buildVisibilityField","lockableTextField","parseTravelDate","validateVisibleSubmission","DEFAULT_ACTION","DEFAULT_MIN_SCORE","isCaptchaEnabled","verifyCaptcha","DEFAULT_FIELD_BLOCKS","buildFieldBlocks","fieldsConfig","result","block","entry","slug","push","defaultSlugs","Set","map","b","Object","entries","has","formPlugin","pluginOptions","config","formsSlug","collections","forms","submissionsSlug","submissions","mediaCollection","singularFormsLabel","labels","singularSubmissionsLabel","fieldBlocks","fields","singularLabel","pluralLabel","richTextEditor","disabled","endpoints","handler","method","path"],"mappings":"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"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { withRateLimit } from '@foundrykit/rate-limit';\nimport type { Block, Config } from 'payload';\nimport { recordActivePlugin } from './activePlugins.js';\nimport { AddressBlock } from './blocks/fields/Address.js';\nimport { CheckboxBlock } from './blocks/fields/Checkbox.js';\nimport { CheckboxGroupBlock } from './blocks/fields/CheckboxGroup.js';\nimport { DateBlock } from './blocks/fields/Date.js';\nimport { EmailBlock } from './blocks/fields/Email.js';\nimport { FileBlock } from './blocks/fields/File.js';\nimport { NumberBlock } from './blocks/fields/Number.js';\nimport { PhoneBlock } from './blocks/fields/Phone.js';\nimport { RadioGroupBlock } from './blocks/fields/RadioGroup.js';\nimport { SelectBlock } from './blocks/fields/Select.js';\nimport { TextBlock } from './blocks/fields/Text.js';\nimport { TextareaBlock } from './blocks/fields/Textarea.js';\nimport { createFormsCollection } from './collections/Forms.js';\nimport { createSubmissionsCollection } from './collections/Submissions.js';\nimport { createFetchFormHandler } from './endpoints/fetchFormHandler.js';\nimport { createSubmitFormHandler } from './endpoints/submitFormHandler.js';\nimport type { FieldsConfig, FormPluginConfig } from './types.js';\nimport { FORM_SUBMIT_PATH } from './utilities/buildSubmitURL.js';\n\nexport {\n baseFieldBlockFields,\n optionsArrayField,\n} from './blocks/fields/shared.js';\nexport { TravelDateBlock } from './blocks/fields/TravelDate.js';\nexport { buildVisibilityField } from './blocks/fields/visibility.js';\nexport { lockableTextField } from './fields/lockable/index.js';\nexport type {\n CaptchaConfig,\n FormPluginConfig,\n PublicCaptchaConfig,\n} from './types.js';\nexport { parseTravelDate, type TravelDate } from './utilities/travelDate.js';\nexport { validateVisibleSubmission } from './utilities/validateVisibleSubmission.js';\nexport {\n type CaptchaVerification,\n DEFAULT_ACTION,\n DEFAULT_MIN_SCORE,\n isCaptchaEnabled,\n verifyCaptcha,\n} from './utilities/verifyCaptcha.js';\n\nconst DEFAULT_FIELD_BLOCKS: Block[] = [\n TextBlock,\n EmailBlock,\n PhoneBlock,\n TextareaBlock,\n CheckboxBlock,\n RadioGroupBlock,\n CheckboxGroupBlock,\n SelectBlock,\n NumberBlock,\n DateBlock,\n FileBlock,\n AddressBlock,\n];\n\nfunction buildFieldBlocks(fieldsConfig: FieldsConfig | undefined): Block[] {\n if (!fieldsConfig) return DEFAULT_FIELD_BLOCKS;\n const result: Block[] = [];\n for (const block of DEFAULT_FIELD_BLOCKS) {\n const entry = fieldsConfig[block.slug];\n if (entry === false) continue;\n if (entry && typeof entry === 'object' && 'block' in entry) {\n result.push(entry.block);\n continue;\n }\n result.push(block);\n }\n const defaultSlugs = new Set(DEFAULT_FIELD_BLOCKS.map(b => b.slug));\n for (const [slug, entry] of Object.entries(fieldsConfig)) {\n if (\n !defaultSlugs.has(slug) &&\n entry &&\n typeof entry === 'object' &&\n 'block' in entry\n ) {\n result.push(entry.block);\n }\n }\n return result;\n}\n\nexport const formPlugin =\n (pluginOptions: FormPluginConfig) =>\n (config: Config): Config => {\n const formsSlug = pluginOptions.collections?.forms ?? 'forms';\n const submissionsSlug =\n pluginOptions.collections?.submissions ?? 'form-submissions';\n const mediaCollection = pluginOptions.mediaCollection ?? 'media';\n const singularFormsLabel = pluginOptions.labels?.forms ?? 'Form';\n const singularSubmissionsLabel =\n pluginOptions.labels?.submissions ?? 'Form Submission';\n const fieldBlocks = buildFieldBlocks(pluginOptions.fields);\n\n config.collections = [\n ...(config.collections ?? []),\n createFormsCollection({\n formsSlug,\n mediaCollection,\n singularLabel: singularFormsLabel,\n pluralLabel: `${singularFormsLabel}s`,\n fieldBlocks,\n richTextEditor: pluginOptions.richTextEditor,\n }),\n createSubmissionsCollection({\n submissionsSlug,\n formsSlug,\n singularLabel: singularSubmissionsLabel,\n pluralLabel: `${singularSubmissionsLabel}s`,\n }),\n ];\n\n if (pluginOptions.disabled) {\n return config;\n }\n\n config.endpoints = [\n ...(config.endpoints ?? []),\n {\n handler: createFetchFormHandler(pluginOptions),\n method: 'get',\n path: `/form-data/:slug`,\n },\n {\n handler: pluginOptions.rateLimit\n ? withRateLimit(createSubmitFormHandler(pluginOptions), {\n key: (_req, ip) => `form-submit:${ip}`,\n ...pluginOptions.rateLimit,\n })\n : createSubmitFormHandler(pluginOptions),\n method: 'post',\n path: `/${FORM_SUBMIT_PATH}/:formSlug`,\n },\n ];\n\n return recordActivePlugin(config, '@foundrykit/form-plugin');\n };\n"],"names":["withRateLimit","recordActivePlugin","AddressBlock","CheckboxBlock","CheckboxGroupBlock","DateBlock","EmailBlock","FileBlock","NumberBlock","PhoneBlock","RadioGroupBlock","SelectBlock","TextBlock","TextareaBlock","createFormsCollection","createSubmissionsCollection","createFetchFormHandler","createSubmitFormHandler","FORM_SUBMIT_PATH","baseFieldBlockFields","optionsArrayField","TravelDateBlock","buildVisibilityField","lockableTextField","parseTravelDate","validateVisibleSubmission","DEFAULT_ACTION","DEFAULT_MIN_SCORE","isCaptchaEnabled","verifyCaptcha","DEFAULT_FIELD_BLOCKS","buildFieldBlocks","fieldsConfig","result","block","entry","slug","push","defaultSlugs","Set","map","b","Object","entries","has","formPlugin","pluginOptions","config","formsSlug","collections","forms","submissionsSlug","submissions","mediaCollection","singularFormsLabel","labels","singularSubmissionsLabel","fieldBlocks","fields","singularLabel","pluralLabel","richTextEditor","disabled","endpoints","handler","method","path","rateLimit","key","_req","ip"],"mappings":"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"}
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { RateLimitOptions } from '@foundrykit/rate-limit';
1
2
  import type { Block, RichTextField } from 'payload';
2
3
  import type { ReactNode } from 'react';
3
4
  import type { Resolver, UseFormReturn } from 'react-hook-form';
@@ -369,6 +370,12 @@ export type FormPluginConfig = {
369
370
  * is required.
370
371
  */
371
372
  captcha?: CaptchaConfig;
373
+ /**
374
+ * Rate-limit the public submit endpoint per client IP, using Payload's KV store.
375
+ * `{ limit: 5, window: 60 }` allows 5 submissions a minute; over that it answers 429.
376
+ * Set `trustedProxies` (see `@foundrykit/rate-limit`) or every visitor shares one bucket.
377
+ */
378
+ rateLimit?: Pick<RateLimitOptions, 'limit' | 'window' | 'trustedProxies'>;
372
379
  };
373
380
  export type FormProps = {
374
381
  form: FormDocument;
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Block, RichTextField } from 'payload';\nimport type { ReactNode } from 'react';\nimport type { Resolver, UseFormReturn } from 'react-hook-form';\n\n// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\nexport type FieldTooltip = {\n enabled?: boolean | null;\n text?: string | null;\n};\n\nexport type MediaObject = {\n id: string;\n url?: string | null;\n alt?: string | null;\n};\n\nexport type SelectOption = {\n id?: string;\n label: string;\n value: string;\n};\n\n/**\n * Optional, admin-configurable validation rules. Applied via `buildFieldRules`\n * to RHF's `register(..., rules)` and merged with the form-level resolver if\n * one is provided.\n */\nexport type FieldValidation = {\n requiredMessage?: string | null;\n // Text-shaped (text, email, phone, textarea, select)\n minLength?: number | null;\n maxLength?: number | null;\n pattern?: string | null;\n patternMessage?: string | null;\n // Numeric-shaped (number, numberStepper, multiCounter total)\n min?: number | null;\n max?: number | null;\n minMessage?: string | null;\n maxMessage?: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Conditional visibility (see docs/superpowers/plans/2026-07-03-conditional-fields.md)\n// ---------------------------------------------------------------------------\n\nexport type ConditionOperator =\n | 'equals'\n | 'notEquals'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'isChecked'\n | 'isNotChecked'\n | 'contains'\n | 'isEmpty'\n | 'isNotEmpty';\n\nexport type ConditionMatch = 'all' | 'any';\n\nexport type Condition = {\n blockType?: 'condition';\n id?: string;\n /** Name (or dot-path e.g. `guests.adults`) of the field to test. */\n source: string;\n operator: ConditionOperator;\n /** Compared value. Ignored for unary operators (isChecked/isEmpty/etc). */\n value?: string | null;\n};\n\n/** One level of nesting only: a group holds plain conditions, never groups. */\nexport type ConditionGroup = {\n blockType: 'group';\n id?: string;\n match?: ConditionMatch | null;\n conditions?: Condition[] | null;\n};\n\nexport type ConditionNode = Condition | ConditionGroup;\n\nexport type VisibilityAction = 'show' | 'require';\n\nexport type VisibilityRule = {\n enabled?: boolean | null;\n /** What happens when the rule matches. Steps always behave as 'show'. */\n action?: VisibilityAction | null;\n match?: ConditionMatch | null;\n conditions?: ConditionNode[] | null;\n};\n\n// ---------------------------------------------------------------------------\n// Base — all field blocks extend this\n// ---------------------------------------------------------------------------\n\nexport type BaseFieldBlock = {\n id?: string;\n name: string;\n label: string;\n required?: boolean | null;\n tooltip?: FieldTooltip | null;\n validation?: FieldValidation | null;\n visibility?: VisibilityRule | null;\n};\n\n// ---------------------------------------------------------------------------\n// Field block types (discriminated union on blockType)\n// ---------------------------------------------------------------------------\n\n/** Width of an input within a step. Consecutive non-`'full'` fields in `Step`\n * are grouped into the same row. */\nexport type FieldWidth = 'full' | 'half' | 'third';\n\nexport type TextBlock = BaseFieldBlock & {\n blockType: 'text';\n placeholder?: string | null;\n width?: FieldWidth | null;\n};\n\nexport type EmailBlock = BaseFieldBlock & {\n blockType: 'email';\n placeholder?: string | null;\n width?: FieldWidth | null;\n};\n\nexport type PhoneBlock = BaseFieldBlock & {\n blockType: 'phone';\n placeholder?: string | null;\n width?: FieldWidth | null;\n /** ISO/dial value of the default selected country (e.g. `\"+44\"`). */\n defaultCountry?: string | null;\n /** Country options for the picker. `value` should be the dial code so the\n * field can build an E.164 number. Defaults to a small built-in list. */\n countries?: SelectOption[] | null;\n};\n\nexport type TextareaBlock = BaseFieldBlock & {\n blockType: 'textarea';\n placeholder?: string | null;\n rows?: number | null;\n};\n\nexport type CheckboxBlock = BaseFieldBlock & {\n blockType: 'checkbox';\n /** Visual presentation. Defaults to `'checkbox'`. Data shape is unchanged. */\n appearance?: 'checkbox' | 'switch' | null;\n};\n\nexport type RadioGroupBlock = BaseFieldBlock & {\n blockType: 'radioGroup';\n options?: SelectOption[] | null;\n layout?: 'row' | 'grid' | null;\n};\n\nexport type CheckboxGroupBlock = BaseFieldBlock & {\n blockType: 'checkboxGroup';\n options?: SelectOption[] | null;\n layout?: 'row' | 'grid' | null;\n};\n\nexport type SelectBlock = BaseFieldBlock & {\n blockType: 'select';\n placeholder?: string | null;\n options?: SelectOption[] | null;\n width?: FieldWidth | null;\n};\n\nexport type NumberBlock = BaseFieldBlock & {\n blockType: 'number';\n placeholder?: string | null;\n defaultValue?: number | null;\n min?: number | null;\n max?: number | null;\n step?: number | null;\n};\n\nexport type DateBlock = BaseFieldBlock & {\n blockType: 'date';\n placeholder?: string | null;\n min?: string | null;\n max?: string | null;\n};\n\nexport type FileBlock = BaseFieldBlock & {\n blockType: 'file';\n accept?: string | null;\n maxSizeMB?: number | null;\n collection?: string | null;\n};\n\n// Custom / extension field block types (can be used via the `fields` config option)\n\nexport type YesNoBlock = BaseFieldBlock & { blockType: 'yesNo' };\n\n/**\n * A month or an exact date, the visitor's choice. Stored as `YYYY-MM` or `YYYY-MM-DD`, so\n * an answer is still readable as plain text wherever it ends up (emails, CRMs, exports).\n */\nexport type TravelDateBlock = BaseFieldBlock & {\n blockType: 'travelDate';\n /** How many years after this one the month picker offers. */\n yearsAhead?: number | null;\n};\n\nexport type OptionCardsBlock = BaseFieldBlock & {\n blockType: 'optionCards';\n options?: SelectOption[] | null;\n layout?: 'row' | 'grid' | null;\n};\n\nexport type NumberStepperBlock = BaseFieldBlock & {\n blockType: 'numberStepper';\n placeholder?: string | null;\n defaultValue?: number | null;\n min?: number | null;\n max?: number | null;\n step?: number | null;\n};\n\nexport type MultiCounterItem = {\n name: string;\n label: string;\n defaultValue?: number | null;\n min?: number | null;\n max?: number | null;\n};\n\nexport type MultiCounterBlock = BaseFieldBlock & {\n blockType: 'multiCounter';\n counters?: MultiCounterItem[] | null;\n};\n\nexport type BudgetRangeBlock = BaseFieldBlock & {\n blockType: 'budgetRange';\n options?: SelectOption[] | null;\n};\n\n/** Composite runtime value of an address field. */\nexport type AddressValue = {\n line1: string;\n line2: string;\n city: string;\n county: string;\n postcode: string;\n country: string;\n};\n\nexport type AddressBlock = BaseFieldBlock & {\n blockType: 'address';\n /** Pre-filled country, used until a postcode lookup overwrites it. */\n defaultCountry?: string | null;\n /** Whether the second address line is shown. Defaults to true. */\n showLine2?: boolean | null;\n /** Label on the lookup button. Defaults to \"Find address\". */\n lookupLabel?: string | null;\n};\n\nexport type FormFieldBlock =\n | TextBlock\n | EmailBlock\n | PhoneBlock\n | TextareaBlock\n | CheckboxBlock\n | RadioGroupBlock\n | CheckboxGroupBlock\n | SelectBlock\n | NumberBlock\n | DateBlock\n | FileBlock\n | YesNoBlock\n | TravelDateBlock\n | OptionCardsBlock\n | NumberStepperBlock\n | MultiCounterBlock\n | BudgetRangeBlock\n | AddressBlock;\n\n// ---------------------------------------------------------------------------\n// Submission action block types\n// ---------------------------------------------------------------------------\n\nexport type SendEmailActionBlock = {\n id?: string;\n blockType: 'sendEmail';\n to: string;\n replyTo?: string | null;\n subject: string;\n includeSubmissionData?: boolean | null;\n};\n\nexport type ConfirmationMessageActionBlock = {\n id?: string;\n blockType: 'confirmationMessage';\n message?: unknown;\n};\n\nexport type RedirectActionBlock = {\n id?: string;\n blockType: 'redirect';\n url: string;\n delay?: number | null;\n};\n\nexport type SubmissionActionBlock =\n | SendEmailActionBlock\n | ConfirmationMessageActionBlock\n | RedirectActionBlock;\n\n// ---------------------------------------------------------------------------\n// FormDocument aggregate (formerly EnquiryForm)\n// ---------------------------------------------------------------------------\n\nexport type FormStep = {\n id?: string;\n title: string;\n icon?: MediaObject | null;\n /** Optional icon shown in the StepIndicator when this step is complete.\n * Falls back to a built-in tick icon. */\n completedIcon?: MediaObject | null;\n introContent?: unknown;\n fields: FormFieldBlock[];\n visibility?: VisibilityRule | null;\n /** Per-step override for the \"Back\" button label. */\n backLabel?: string | null;\n /** Per-step override for the \"Next\" (or \"Submit\" on the final step) button label. */\n nextLabel?: string | null;\n};\n\nexport type FormButtonLabels = {\n back?: string | null;\n next?: string | null;\n submit?: string | null;\n /** Label for the \"Back\" button on the final step. Falls back to `back`. */\n backLast?: string | null;\n};\n\nexport type AdditionalContent = {\n enabled?: boolean | null;\n position?: 'above' | 'below' | null;\n content?: unknown;\n};\n\n/** Optional synthetic final stage shown in the step indicator (only) of a\n * multi-stage form, representing the post-submit confirmation screen. It is\n * never a navigable field step. */\nexport type ConfirmationStage = {\n enabled?: boolean | null;\n /** Label shown under the stage dot. Falls back to \"Confirmation\". */\n label?: string | null;\n /** Icon shown in the indicator for the confirmation stage. */\n icon?: MediaObject | null;\n};\n\nexport type FormDocument = {\n id: string;\n title: string;\n slug: string;\n /**\n * Captcha details for this form, added by the fetch endpoint when the plugin\n * has a complete captcha config. Absent when captcha is off, which is how\n * the client decides whether to mint a token at all. Not a stored field.\n */\n captcha?: PublicCaptchaConfig | null;\n /** Whether this form is authored as multiple stages. When false (the\n * default), fields live on the top-level `fields` array instead of `steps`. */\n multiStep?: boolean | null;\n /** Flat field list used by single-stage forms (`multiStep` falsy). The API\n * response always also exposes a normalized `steps` array. */\n fields?: FormFieldBlock[] | null;\n steps: FormStep[];\n /** Optional confirmation stage appended to the step indicator only (does not\n * add a navigable step). Only meaningful for multi-stage forms. */\n confirmationStage?: ConfirmationStage | null;\n additionalContent?: AdditionalContent | null;\n /** Document-level overrides for navigation button labels. Per-step `backLabel`\n * / `nextLabel` take precedence over these. */\n buttonLabels?: FormButtonLabels | null;\n submissionActions: SubmissionActionBlock[];\n updatedAt: string;\n createdAt: string;\n};\n\n// ---------------------------------------------------------------------------\n// API response types\n// ---------------------------------------------------------------------------\n\n/** Arbitrary, JSON-serialisable context recorded against the submission.\n * Not rendered; not part of `data`. Stored verbatim on the submission. */\nexport type EnquirySubmissionContext = Record<string, unknown>;\n\nexport type SubmitResult = {\n success: true;\n actions: {\n confirmationMessage?: unknown;\n redirectUrl?: string;\n };\n /** ID of the created submission, when the endpoint returns it. */\n submissionId?: string;\n};\n\nexport type SubmitError = {\n success: false;\n errors: Array<{ field: string; message: string }>;\n};\n\n// ---------------------------------------------------------------------------\n// Plugin config\n// ---------------------------------------------------------------------------\n\nexport type BuiltInFieldSlug =\n | 'text'\n | 'email'\n | 'phone'\n | 'textarea'\n | 'checkbox'\n | 'radioGroup'\n | 'checkboxGroup'\n | 'select'\n | 'number'\n | 'date'\n | 'file';\n\nexport type FieldsConfig = Record<\n string,\n boolean | { block: Block } | undefined\n>;\n\n/**\n * reCAPTCHA v3 settings. Both keys must be present for the captcha to be\n * enforced — with either missing, forms behave exactly as they did before, so\n * a site can ship this config before its keys exist.\n *\n * `siteKey` is public by design (it is served to the browser with the form);\n * `secretKey` must come from the server environment and never be committed.\n */\nexport type CaptchaConfig = {\n /** Only reCAPTCHA v3 is supported today; named so other providers can be added. */\n provider?: 'recaptcha-v3';\n /** Public site key, sent to the browser. */\n siteKey?: string;\n /** Secret key, server-side only. */\n secretKey?: string;\n /** Reject submissions scoring below this (0–1). Defaults to 0.5. */\n minScore?: number;\n /** Action name minted into the token and asserted on verify. Defaults to 'form_submit'. */\n action?: string;\n};\n\n/** Captcha details safe to expose to the browser alongside a form. */\nexport type PublicCaptchaConfig = {\n provider: 'recaptcha-v3';\n siteKey: string;\n action: string;\n};\n\nexport type FormPluginConfig = {\n disabled?: boolean;\n baseUrl?: string;\n /** Slug of the Payload media collection used for step icons. Defaults to 'media'. */\n mediaCollection?: string;\n collections?: {\n /** Slug for the forms collection. Defaults to 'forms'. */\n forms?: string;\n /** Slug for the submissions collection. Defaults to 'form-submissions'. */\n submissions?: string;\n };\n /** Override admin labels for the plugin's collections. */\n labels?: {\n /** Singular label for the forms collection. Defaults to 'Form'. */\n forms?: string;\n /** Singular label for the submissions collection. Defaults to 'Form Submission'. */\n submissions?: string;\n };\n /**\n * Configure which field blocks are available in the form builder.\n * - Omit key or set to `true`: include default block\n * - Set to `false`: exclude block\n * - Set to `{ block: MyBlock }`: replace default block with custom\n * - Add a new key with `{ block: MyBlock }`: add custom block type\n */\n fields?: FieldsConfig;\n /**\n * Editor applied to the consumer-facing rich-text fields — the confirmation\n * message and the additional content. Pass a configured `lexicalEditor(...)`\n * to enable custom Lexical blocks/features in those fields. When omitted, the\n * fields fall back to the Payload root editor. Does not affect a step's intro\n * content (which keeps its own headings-enabled editor).\n */\n richTextEditor?: RichTextField['editor'];\n /**\n * Protect every form's submit endpoint with reCAPTCHA v3. Omit it, or leave\n * either key unset, and nothing changes — no script is loaded and no token\n * is required.\n */\n captcha?: CaptchaConfig;\n};\n\n// ---------------------------------------------------------------------------\n// Frontend component props\n// ---------------------------------------------------------------------------\n\nexport type FormProps = {\n form: FormDocument;\n apiBase?: string;\n className?: string;\n onSuccess?: (result: SubmitResult) => void;\n onError?: (error: SubmitError) => void;\n additionalContent?: ReactNode;\n /**\n * Optional render function for the per-step `introContent` rich text.\n * Called for each step; return `null`/`undefined` to render nothing.\n */\n renderStepIntro?: (step: FormStep, index: number) => ReactNode;\n /**\n * Optional render function for the confirmation message after a successful\n * submission. Receives the raw `confirmationMessage` payload (typically\n * Lexical JSON) plus the full `SubmitResult`. If omitted, a default\n * \"Form submitted successfully.\" message is shown.\n */\n renderConfirmation?: (message: unknown, result: SubmitResult) => ReactNode;\n /**\n * Optional react-hook-form `Resolver` (e.g. `zodResolver(schema)`). Runs\n * alongside the per-field admin rules — RHF natively merges both, so either\n * source can flag a field as invalid.\n */\n resolver?: Resolver<Record<string, unknown>>;\n /**\n * Arbitrary, JSON-serialisable context recorded against the submission\n * (e.g. hotel/itinerary/offer reference). Not rendered and not part of\n * `data` — stored verbatim on the submission.\n */\n context?: EnquirySubmissionContext;\n};\n\n// ---------------------------------------------------------------------------\n// Frontend component hook return type\n// ---------------------------------------------------------------------------\n\nexport type UseEnquiryFormReturn = {\n currentStep: number;\n totalSteps: number;\n stepData: FormStep;\n form: UseFormReturn<Record<string, unknown>>;\n goNext: () => Promise<boolean>;\n goBack: () => void;\n submit: () => Promise<SubmitResult>;\n isSubmitting: boolean;\n isComplete: boolean;\n result: SubmitResult | null;\n error: SubmitError | null;\n /**\n * The form values captured at the moment of a successful submit. `null` until\n * then. The live form is reset on success, so this is the only remaining\n * record of the path the visitor took — the confirmation screen's step\n * indicator is built from it.\n */\n submittedValues: null | Record<string, unknown>;\n};\n\n// ---------------------------------------------------------------------------\n// Legacy type aliases (renamed from earlier versions)\n// ---------------------------------------------------------------------------\n\nexport type TextInputBlock = TextBlock;\nexport type EmailInputBlock = EmailBlock;\nexport type CheckboxInputBlock = CheckboxBlock;\nexport type SelectInputBlock = SelectBlock;\nexport type TextareaInputBlock = TextareaBlock;\nexport type EnquiryFormProps = FormProps;\nexport type EnquiryFormStep = FormStep;\nexport type EnquiryForm = FormDocument;\n"],"names":[],"mappings":"AA4jBA,WAAuC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { RateLimitOptions } from '@foundrykit/rate-limit';\nimport type { Block, RichTextField } from 'payload';\nimport type { ReactNode } from 'react';\nimport type { Resolver, UseFormReturn } from 'react-hook-form';\n\n// ---------------------------------------------------------------------------\n// Shared sub-types\n// ---------------------------------------------------------------------------\n\nexport type FieldTooltip = {\n enabled?: boolean | null;\n text?: string | null;\n};\n\nexport type MediaObject = {\n id: string;\n url?: string | null;\n alt?: string | null;\n};\n\nexport type SelectOption = {\n id?: string;\n label: string;\n value: string;\n};\n\n/**\n * Optional, admin-configurable validation rules. Applied via `buildFieldRules`\n * to RHF's `register(..., rules)` and merged with the form-level resolver if\n * one is provided.\n */\nexport type FieldValidation = {\n requiredMessage?: string | null;\n // Text-shaped (text, email, phone, textarea, select)\n minLength?: number | null;\n maxLength?: number | null;\n pattern?: string | null;\n patternMessage?: string | null;\n // Numeric-shaped (number, numberStepper, multiCounter total)\n min?: number | null;\n max?: number | null;\n minMessage?: string | null;\n maxMessage?: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Conditional visibility (see docs/superpowers/plans/2026-07-03-conditional-fields.md)\n// ---------------------------------------------------------------------------\n\nexport type ConditionOperator =\n | 'equals'\n | 'notEquals'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'isChecked'\n | 'isNotChecked'\n | 'contains'\n | 'isEmpty'\n | 'isNotEmpty';\n\nexport type ConditionMatch = 'all' | 'any';\n\nexport type Condition = {\n blockType?: 'condition';\n id?: string;\n /** Name (or dot-path e.g. `guests.adults`) of the field to test. */\n source: string;\n operator: ConditionOperator;\n /** Compared value. Ignored for unary operators (isChecked/isEmpty/etc). */\n value?: string | null;\n};\n\n/** One level of nesting only: a group holds plain conditions, never groups. */\nexport type ConditionGroup = {\n blockType: 'group';\n id?: string;\n match?: ConditionMatch | null;\n conditions?: Condition[] | null;\n};\n\nexport type ConditionNode = Condition | ConditionGroup;\n\nexport type VisibilityAction = 'show' | 'require';\n\nexport type VisibilityRule = {\n enabled?: boolean | null;\n /** What happens when the rule matches. Steps always behave as 'show'. */\n action?: VisibilityAction | null;\n match?: ConditionMatch | null;\n conditions?: ConditionNode[] | null;\n};\n\n// ---------------------------------------------------------------------------\n// Base — all field blocks extend this\n// ---------------------------------------------------------------------------\n\nexport type BaseFieldBlock = {\n id?: string;\n name: string;\n label: string;\n required?: boolean | null;\n tooltip?: FieldTooltip | null;\n validation?: FieldValidation | null;\n visibility?: VisibilityRule | null;\n};\n\n// ---------------------------------------------------------------------------\n// Field block types (discriminated union on blockType)\n// ---------------------------------------------------------------------------\n\n/** Width of an input within a step. Consecutive non-`'full'` fields in `Step`\n * are grouped into the same row. */\nexport type FieldWidth = 'full' | 'half' | 'third';\n\nexport type TextBlock = BaseFieldBlock & {\n blockType: 'text';\n placeholder?: string | null;\n width?: FieldWidth | null;\n};\n\nexport type EmailBlock = BaseFieldBlock & {\n blockType: 'email';\n placeholder?: string | null;\n width?: FieldWidth | null;\n};\n\nexport type PhoneBlock = BaseFieldBlock & {\n blockType: 'phone';\n placeholder?: string | null;\n width?: FieldWidth | null;\n /** ISO/dial value of the default selected country (e.g. `\"+44\"`). */\n defaultCountry?: string | null;\n /** Country options for the picker. `value` should be the dial code so the\n * field can build an E.164 number. Defaults to a small built-in list. */\n countries?: SelectOption[] | null;\n};\n\nexport type TextareaBlock = BaseFieldBlock & {\n blockType: 'textarea';\n placeholder?: string | null;\n rows?: number | null;\n};\n\nexport type CheckboxBlock = BaseFieldBlock & {\n blockType: 'checkbox';\n /** Visual presentation. Defaults to `'checkbox'`. Data shape is unchanged. */\n appearance?: 'checkbox' | 'switch' | null;\n};\n\nexport type RadioGroupBlock = BaseFieldBlock & {\n blockType: 'radioGroup';\n options?: SelectOption[] | null;\n layout?: 'row' | 'grid' | null;\n};\n\nexport type CheckboxGroupBlock = BaseFieldBlock & {\n blockType: 'checkboxGroup';\n options?: SelectOption[] | null;\n layout?: 'row' | 'grid' | null;\n};\n\nexport type SelectBlock = BaseFieldBlock & {\n blockType: 'select';\n placeholder?: string | null;\n options?: SelectOption[] | null;\n width?: FieldWidth | null;\n};\n\nexport type NumberBlock = BaseFieldBlock & {\n blockType: 'number';\n placeholder?: string | null;\n defaultValue?: number | null;\n min?: number | null;\n max?: number | null;\n step?: number | null;\n};\n\nexport type DateBlock = BaseFieldBlock & {\n blockType: 'date';\n placeholder?: string | null;\n min?: string | null;\n max?: string | null;\n};\n\nexport type FileBlock = BaseFieldBlock & {\n blockType: 'file';\n accept?: string | null;\n maxSizeMB?: number | null;\n collection?: string | null;\n};\n\n// Custom / extension field block types (can be used via the `fields` config option)\n\nexport type YesNoBlock = BaseFieldBlock & { blockType: 'yesNo' };\n\n/**\n * A month or an exact date, the visitor's choice. Stored as `YYYY-MM` or `YYYY-MM-DD`, so\n * an answer is still readable as plain text wherever it ends up (emails, CRMs, exports).\n */\nexport type TravelDateBlock = BaseFieldBlock & {\n blockType: 'travelDate';\n /** How many years after this one the month picker offers. */\n yearsAhead?: number | null;\n};\n\nexport type OptionCardsBlock = BaseFieldBlock & {\n blockType: 'optionCards';\n options?: SelectOption[] | null;\n layout?: 'row' | 'grid' | null;\n};\n\nexport type NumberStepperBlock = BaseFieldBlock & {\n blockType: 'numberStepper';\n placeholder?: string | null;\n defaultValue?: number | null;\n min?: number | null;\n max?: number | null;\n step?: number | null;\n};\n\nexport type MultiCounterItem = {\n name: string;\n label: string;\n defaultValue?: number | null;\n min?: number | null;\n max?: number | null;\n};\n\nexport type MultiCounterBlock = BaseFieldBlock & {\n blockType: 'multiCounter';\n counters?: MultiCounterItem[] | null;\n};\n\nexport type BudgetRangeBlock = BaseFieldBlock & {\n blockType: 'budgetRange';\n options?: SelectOption[] | null;\n};\n\n/** Composite runtime value of an address field. */\nexport type AddressValue = {\n line1: string;\n line2: string;\n city: string;\n county: string;\n postcode: string;\n country: string;\n};\n\nexport type AddressBlock = BaseFieldBlock & {\n blockType: 'address';\n /** Pre-filled country, used until a postcode lookup overwrites it. */\n defaultCountry?: string | null;\n /** Whether the second address line is shown. Defaults to true. */\n showLine2?: boolean | null;\n /** Label on the lookup button. Defaults to \"Find address\". */\n lookupLabel?: string | null;\n};\n\nexport type FormFieldBlock =\n | TextBlock\n | EmailBlock\n | PhoneBlock\n | TextareaBlock\n | CheckboxBlock\n | RadioGroupBlock\n | CheckboxGroupBlock\n | SelectBlock\n | NumberBlock\n | DateBlock\n | FileBlock\n | YesNoBlock\n | TravelDateBlock\n | OptionCardsBlock\n | NumberStepperBlock\n | MultiCounterBlock\n | BudgetRangeBlock\n | AddressBlock;\n\n// ---------------------------------------------------------------------------\n// Submission action block types\n// ---------------------------------------------------------------------------\n\nexport type SendEmailActionBlock = {\n id?: string;\n blockType: 'sendEmail';\n to: string;\n replyTo?: string | null;\n subject: string;\n includeSubmissionData?: boolean | null;\n};\n\nexport type ConfirmationMessageActionBlock = {\n id?: string;\n blockType: 'confirmationMessage';\n message?: unknown;\n};\n\nexport type RedirectActionBlock = {\n id?: string;\n blockType: 'redirect';\n url: string;\n delay?: number | null;\n};\n\nexport type SubmissionActionBlock =\n | SendEmailActionBlock\n | ConfirmationMessageActionBlock\n | RedirectActionBlock;\n\n// ---------------------------------------------------------------------------\n// FormDocument aggregate (formerly EnquiryForm)\n// ---------------------------------------------------------------------------\n\nexport type FormStep = {\n id?: string;\n title: string;\n icon?: MediaObject | null;\n /** Optional icon shown in the StepIndicator when this step is complete.\n * Falls back to a built-in tick icon. */\n completedIcon?: MediaObject | null;\n introContent?: unknown;\n fields: FormFieldBlock[];\n visibility?: VisibilityRule | null;\n /** Per-step override for the \"Back\" button label. */\n backLabel?: string | null;\n /** Per-step override for the \"Next\" (or \"Submit\" on the final step) button label. */\n nextLabel?: string | null;\n};\n\nexport type FormButtonLabels = {\n back?: string | null;\n next?: string | null;\n submit?: string | null;\n /** Label for the \"Back\" button on the final step. Falls back to `back`. */\n backLast?: string | null;\n};\n\nexport type AdditionalContent = {\n enabled?: boolean | null;\n position?: 'above' | 'below' | null;\n content?: unknown;\n};\n\n/** Optional synthetic final stage shown in the step indicator (only) of a\n * multi-stage form, representing the post-submit confirmation screen. It is\n * never a navigable field step. */\nexport type ConfirmationStage = {\n enabled?: boolean | null;\n /** Label shown under the stage dot. Falls back to \"Confirmation\". */\n label?: string | null;\n /** Icon shown in the indicator for the confirmation stage. */\n icon?: MediaObject | null;\n};\n\nexport type FormDocument = {\n id: string;\n title: string;\n slug: string;\n /**\n * Captcha details for this form, added by the fetch endpoint when the plugin\n * has a complete captcha config. Absent when captcha is off, which is how\n * the client decides whether to mint a token at all. Not a stored field.\n */\n captcha?: PublicCaptchaConfig | null;\n /** Whether this form is authored as multiple stages. When false (the\n * default), fields live on the top-level `fields` array instead of `steps`. */\n multiStep?: boolean | null;\n /** Flat field list used by single-stage forms (`multiStep` falsy). The API\n * response always also exposes a normalized `steps` array. */\n fields?: FormFieldBlock[] | null;\n steps: FormStep[];\n /** Optional confirmation stage appended to the step indicator only (does not\n * add a navigable step). Only meaningful for multi-stage forms. */\n confirmationStage?: ConfirmationStage | null;\n additionalContent?: AdditionalContent | null;\n /** Document-level overrides for navigation button labels. Per-step `backLabel`\n * / `nextLabel` take precedence over these. */\n buttonLabels?: FormButtonLabels | null;\n submissionActions: SubmissionActionBlock[];\n updatedAt: string;\n createdAt: string;\n};\n\n// ---------------------------------------------------------------------------\n// API response types\n// ---------------------------------------------------------------------------\n\n/** Arbitrary, JSON-serialisable context recorded against the submission.\n * Not rendered; not part of `data`. Stored verbatim on the submission. */\nexport type EnquirySubmissionContext = Record<string, unknown>;\n\nexport type SubmitResult = {\n success: true;\n actions: {\n confirmationMessage?: unknown;\n redirectUrl?: string;\n };\n /** ID of the created submission, when the endpoint returns it. */\n submissionId?: string;\n};\n\nexport type SubmitError = {\n success: false;\n errors: Array<{ field: string; message: string }>;\n};\n\n// ---------------------------------------------------------------------------\n// Plugin config\n// ---------------------------------------------------------------------------\n\nexport type BuiltInFieldSlug =\n | 'text'\n | 'email'\n | 'phone'\n | 'textarea'\n | 'checkbox'\n | 'radioGroup'\n | 'checkboxGroup'\n | 'select'\n | 'number'\n | 'date'\n | 'file';\n\nexport type FieldsConfig = Record<\n string,\n boolean | { block: Block } | undefined\n>;\n\n/**\n * reCAPTCHA v3 settings. Both keys must be present for the captcha to be\n * enforced — with either missing, forms behave exactly as they did before, so\n * a site can ship this config before its keys exist.\n *\n * `siteKey` is public by design (it is served to the browser with the form);\n * `secretKey` must come from the server environment and never be committed.\n */\nexport type CaptchaConfig = {\n /** Only reCAPTCHA v3 is supported today; named so other providers can be added. */\n provider?: 'recaptcha-v3';\n /** Public site key, sent to the browser. */\n siteKey?: string;\n /** Secret key, server-side only. */\n secretKey?: string;\n /** Reject submissions scoring below this (0–1). Defaults to 0.5. */\n minScore?: number;\n /** Action name minted into the token and asserted on verify. Defaults to 'form_submit'. */\n action?: string;\n};\n\n/** Captcha details safe to expose to the browser alongside a form. */\nexport type PublicCaptchaConfig = {\n provider: 'recaptcha-v3';\n siteKey: string;\n action: string;\n};\n\nexport type FormPluginConfig = {\n disabled?: boolean;\n baseUrl?: string;\n /** Slug of the Payload media collection used for step icons. Defaults to 'media'. */\n mediaCollection?: string;\n collections?: {\n /** Slug for the forms collection. Defaults to 'forms'. */\n forms?: string;\n /** Slug for the submissions collection. Defaults to 'form-submissions'. */\n submissions?: string;\n };\n /** Override admin labels for the plugin's collections. */\n labels?: {\n /** Singular label for the forms collection. Defaults to 'Form'. */\n forms?: string;\n /** Singular label for the submissions collection. Defaults to 'Form Submission'. */\n submissions?: string;\n };\n /**\n * Configure which field blocks are available in the form builder.\n * - Omit key or set to `true`: include default block\n * - Set to `false`: exclude block\n * - Set to `{ block: MyBlock }`: replace default block with custom\n * - Add a new key with `{ block: MyBlock }`: add custom block type\n */\n fields?: FieldsConfig;\n /**\n * Editor applied to the consumer-facing rich-text fields — the confirmation\n * message and the additional content. Pass a configured `lexicalEditor(...)`\n * to enable custom Lexical blocks/features in those fields. When omitted, the\n * fields fall back to the Payload root editor. Does not affect a step's intro\n * content (which keeps its own headings-enabled editor).\n */\n richTextEditor?: RichTextField['editor'];\n /**\n * Protect every form's submit endpoint with reCAPTCHA v3. Omit it, or leave\n * either key unset, and nothing changes — no script is loaded and no token\n * is required.\n */\n captcha?: CaptchaConfig;\n /**\n * Rate-limit the public submit endpoint per client IP, using Payload's KV store.\n * `{ limit: 5, window: 60 }` allows 5 submissions a minute; over that it answers 429.\n * Set `trustedProxies` (see `@foundrykit/rate-limit`) or every visitor shares one bucket.\n */\n rateLimit?: Pick<RateLimitOptions, 'limit' | 'window' | 'trustedProxies'>;\n};\n\n// ---------------------------------------------------------------------------\n// Frontend component props\n// ---------------------------------------------------------------------------\n\nexport type FormProps = {\n form: FormDocument;\n apiBase?: string;\n className?: string;\n onSuccess?: (result: SubmitResult) => void;\n onError?: (error: SubmitError) => void;\n additionalContent?: ReactNode;\n /**\n * Optional render function for the per-step `introContent` rich text.\n * Called for each step; return `null`/`undefined` to render nothing.\n */\n renderStepIntro?: (step: FormStep, index: number) => ReactNode;\n /**\n * Optional render function for the confirmation message after a successful\n * submission. Receives the raw `confirmationMessage` payload (typically\n * Lexical JSON) plus the full `SubmitResult`. If omitted, a default\n * \"Form submitted successfully.\" message is shown.\n */\n renderConfirmation?: (message: unknown, result: SubmitResult) => ReactNode;\n /**\n * Optional react-hook-form `Resolver` (e.g. `zodResolver(schema)`). Runs\n * alongside the per-field admin rules — RHF natively merges both, so either\n * source can flag a field as invalid.\n */\n resolver?: Resolver<Record<string, unknown>>;\n /**\n * Arbitrary, JSON-serialisable context recorded against the submission\n * (e.g. hotel/itinerary/offer reference). Not rendered and not part of\n * `data` — stored verbatim on the submission.\n */\n context?: EnquirySubmissionContext;\n};\n\n// ---------------------------------------------------------------------------\n// Frontend component hook return type\n// ---------------------------------------------------------------------------\n\nexport type UseEnquiryFormReturn = {\n currentStep: number;\n totalSteps: number;\n stepData: FormStep;\n form: UseFormReturn<Record<string, unknown>>;\n goNext: () => Promise<boolean>;\n goBack: () => void;\n submit: () => Promise<SubmitResult>;\n isSubmitting: boolean;\n isComplete: boolean;\n result: SubmitResult | null;\n error: SubmitError | null;\n /**\n * The form values captured at the moment of a successful submit. `null` until\n * then. The live form is reset on success, so this is the only remaining\n * record of the path the visitor took — the confirmation screen's step\n * indicator is built from it.\n */\n submittedValues: null | Record<string, unknown>;\n};\n\n// ---------------------------------------------------------------------------\n// Legacy type aliases (renamed from earlier versions)\n// ---------------------------------------------------------------------------\n\nexport type TextInputBlock = TextBlock;\nexport type EmailInputBlock = EmailBlock;\nexport type CheckboxInputBlock = CheckboxBlock;\nexport type SelectInputBlock = SelectBlock;\nexport type TextareaInputBlock = TextareaBlock;\nexport type EnquiryFormProps = FormProps;\nexport type EnquiryFormStep = FormStep;\nexport type EnquiryForm = FormDocument;\n"],"names":[],"mappings":"AAmkBA,WAAuC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foundrykit/form-plugin",
3
- "version": "1.16.6",
3
+ "version": "1.17.0",
4
4
  "description": "Multi-step enquiry form plugin for Payload CMS 3",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -37,12 +37,12 @@
37
37
  "dist"
38
38
  ],
39
39
  "devDependencies": {
40
- "@payloadcms/db-mongodb": "3.84.1",
41
- "@payloadcms/db-postgres": "3.84.1",
42
- "@payloadcms/db-sqlite": "3.84.1",
43
- "@payloadcms/next": "3.84.1",
44
- "@payloadcms/richtext-lexical": "3.84.1",
45
- "@payloadcms/ui": "3.84.1",
40
+ "@payloadcms/db-mongodb": "3.90.0",
41
+ "@payloadcms/db-postgres": "3.90.0",
42
+ "@payloadcms/db-sqlite": "3.90.0",
43
+ "@payloadcms/next": "3.90.0",
44
+ "@payloadcms/richtext-lexical": "3.90.0",
45
+ "@payloadcms/ui": "3.90.0",
46
46
  "@playwright/test": "1.58.2",
47
47
  "@radix-ui/react-popover": "^1.1.14",
48
48
  "@swc-node/register": "1.10.9",
@@ -55,12 +55,12 @@
55
55
  "dotenv": "^16.0.3",
56
56
  "graphql": "^16.8.1",
57
57
  "mongodb-memory-server": "10.1.4",
58
- "next": "16.2.6",
58
+ "next": "16.3.8",
59
59
  "open": "^10.1.0",
60
- "payload": "3.84.1",
60
+ "payload": "3.90.0",
61
61
  "qs-esm": "8.0.1",
62
- "react": "19.2.6",
63
- "react-dom": "19.2.6",
62
+ "react": "19.2.8",
63
+ "react-dom": "19.2.8",
64
64
  "react-hook-form": "^7.54.2",
65
65
  "rimraf": "3.0.2",
66
66
  "sharp": "0.34.2",
@@ -71,9 +71,9 @@
71
71
  "zod": "^4.4.3"
72
72
  },
73
73
  "peerDependencies": {
74
- "@payloadcms/richtext-lexical": "^3.0.0",
74
+ "@payloadcms/richtext-lexical": "^3.84.0",
75
75
  "@radix-ui/react-popover": "^1.1.0",
76
- "payload": "^3.84.1",
76
+ "payload": "^3.84.0",
77
77
  "react": "^19",
78
78
  "react-hook-form": "^7",
79
79
  "zod": "^3.23.0 || ^4"
@@ -98,7 +98,8 @@
98
98
  "directory": "packages/payload/form-plugin"
99
99
  },
100
100
  "dependencies": {
101
- "react-day-picker": "9.14.0"
101
+ "react-day-picker": "9.14.0",
102
+ "@foundrykit/rate-limit": "^0.1.1"
102
103
  },
103
104
  "homepage": "https://github.com/umi-labs/foundry/tree/prod/packages/payload/form-plugin#readme",
104
105
  "bugs": {