@stacksjs/forms 0.72.98 → 0.72.99

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.
@@ -1,4 +1,4 @@
1
- import type { FormDefinition } from './types';
1
+ import type { FormDefinition, PublicFormDefinition } from './types';
2
2
  /**
3
3
  * Load a form + its fields by uuid. `siteId` is REQUIRED and matched against
4
4
  * the row (null site allowed for single-site apps passing null): a form uuid
@@ -11,4 +11,4 @@ export declare function loadFormByUuid(uuid: string, siteId: number | null): Pro
11
11
  * attacker wants (notify addresses, payment internals beyond what the UI
12
12
  * must show).
13
13
  */
14
- export declare function publicDefinition(form: FormDefinition): Record<string, unknown>;
14
+ export declare function publicDefinition(form: FormDefinition): PublicFormDefinition;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export type {
8
8
  FormFieldDefinition,
9
9
  FormFieldType,
10
10
  FormSettings,
11
+ PublicFormDefinition,
12
+ PublicFormField,
11
13
  SubmissionErrors,
12
14
  ValidateSubmissionResult,
13
15
  } from './types';
package/dist/types.d.ts CHANGED
@@ -55,10 +55,42 @@ export declare interface FormDefinition {
55
55
  settings: FormSettings
56
56
  fields: FormFieldDefinition[]
57
57
  }
58
+ /**
59
+ * What `GET /api/forms/:uuid` returns: everything a renderer needs, nothing an
60
+ * attacker wants.
61
+ *
62
+ * `publicDefinition` used to be typed `Record<string, unknown>`, so the one
63
+ * contract between the server projection and the CMS form block was described
64
+ * nowhere. The block rendered a `state(null)` it then indexed freely, and the
65
+ * server could have dropped a key without anything noticing.
66
+ */
67
+ export declare interface PublicFormDefinition {
68
+ uuid: string
69
+ name: string
70
+ status: FormDefinition['status']
71
+ submitLabel: string
72
+ confirmation: string | null
73
+ payment: {
74
+ mode: NonNullable<FormSettings['payment']>['mode']
75
+ amountCents?: number
76
+ currency: string
77
+ minAmountCents?: number
78
+ } | null
79
+ fields: PublicFormField[]
80
+ }
58
81
  export declare interface SubmissionErrors {
59
82
  [fieldName: string]: string
60
83
  }
61
84
  export type FormFieldType = | 'text' | 'textarea' | 'email' | 'phone' | 'select' | 'checkbox'
62
85
  | 'radio' | 'date' | 'file' | 'currency' | 'section_break';
86
+ /**
87
+ * A field as the public renderer receives it.
88
+ *
89
+ * The same field minus what only the server needs. Derived from
90
+ * `FormFieldDefinition` rather than restated, so adding a field property
91
+ * cannot leave the two out of step.
92
+ */
93
+ export type PublicFormField = Pick<FormFieldDefinition, 'name' | 'label' | 'type' | 'required' | 'width' | 'conditions'>
94
+ & { options: Pick<FieldOptions, 'placeholder' | 'choices' | 'min' | 'max' | 'accept'> }
63
95
  export type ValidateSubmissionResult = | { ok: true, values: Record<string, unknown>, email: string | null, name: string | null, amountCents: number | null }
64
96
  | { ok: false, errors: SubmissionErrors }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/forms",
3
3
  "type": "module",
4
- "version": "0.72.98",
4
+ "version": "0.72.99",
5
5
  "description": "The Stacks form-builder functionality.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -56,11 +56,11 @@
56
56
  "prepublishOnly": "bun run build"
57
57
  },
58
58
  "devDependencies": {
59
- "@stacksjs/config": "0.72.98",
60
- "@stacksjs/database": "0.72.98",
61
- "@stacksjs/notifications": "0.72.98",
62
- "@stacksjs/storage": "0.72.98",
63
- "@stacksjs/validation": "0.72.98",
59
+ "@stacksjs/config": "0.72.99",
60
+ "@stacksjs/database": "0.72.99",
61
+ "@stacksjs/notifications": "0.72.99",
62
+ "@stacksjs/storage": "0.72.99",
63
+ "@stacksjs/validation": "0.72.99",
64
64
  "better-dx": "^0.2.24"
65
65
  },
66
66
  "sideEffects": false