@evanschleret/formforgeclient 1.2.2 → 1.2.3

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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "1.2.2",
7
+ "version": "1.2.3",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -16,6 +16,7 @@ import UStepper from "@nuxt/ui/components/Stepper.vue";
16
16
  import USwitch from "@nuxt/ui/components/Switch.vue";
17
17
  import UTextarea from "@nuxt/ui/components/Textarea.vue";
18
18
  import { isFormForgeJsonObject } from "../../utils/object";
19
+ import { sanitizePayloadWithSchema } from "../../utils/renderer-payload";
19
20
  import { useFormForgeForm } from "../../composables/useFormForgeForm";
20
21
  import { useFormForgeI18n } from "../../composables/useFormForgeI18n";
21
22
  import { useFormForgeSubmit } from "../../composables/useFormForgeSubmit";
@@ -137,43 +138,6 @@ function getResolvedZodSchema() {
137
138
  }
138
139
  return internalForm.zodSchema.value;
139
140
  }
140
- function resolveSchemaFieldNames(schema) {
141
- const names = /* @__PURE__ */ new Set();
142
- if (Array.isArray(schema.fields)) {
143
- for (const field of schema.fields) {
144
- if (typeof field.name === "string" && field.name !== "") {
145
- names.add(field.name);
146
- }
147
- }
148
- }
149
- if (Array.isArray(schema.pages)) {
150
- for (const page of schema.pages) {
151
- if (!Array.isArray(page.fields)) {
152
- continue;
153
- }
154
- for (const field of page.fields) {
155
- if (typeof field.name === "string" && field.name !== "") {
156
- names.add(field.name);
157
- }
158
- }
159
- }
160
- }
161
- return names;
162
- }
163
- function sanitizePayloadWithSchema(value, schema) {
164
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
165
- return {};
166
- }
167
- const allowedFieldNames = resolveSchemaFieldNames(schema);
168
- const sanitizedPayload = {};
169
- for (const [key, entryValue] of Object.entries(value)) {
170
- if (!allowedFieldNames.has(key)) {
171
- continue;
172
- }
173
- sanitizedPayload[key] = entryValue;
174
- }
175
- return sanitizedPayload;
176
- }
177
141
  const formState = computed({
178
142
  get: () => {
179
143
  const value = usesExternalModel.value ? unwrapModelValueProp(props.modelValue) : internalForm.state.value;
@@ -0,0 +1,5 @@
1
+ import type { FormForgeSubmissionPayload } from '../types/index.js';
2
+ import type { FormForgeFormSchema } from '../types/schema.js';
3
+ export declare function resolveSchemaFieldNames(schema: FormForgeFormSchema): Set<string>;
4
+ export declare function sanitizePayloadWithSchema(value: FormForgeSubmissionPayload, schema: FormForgeFormSchema): FormForgeSubmissionPayload;
5
+ //# sourceMappingURL=renderer-payload.d.ts.map
@@ -0,0 +1,71 @@
1
+ function collectSchemaFields(schema) {
2
+ const collected = [];
3
+ if (Array.isArray(schema.fields)) {
4
+ collected.push(...schema.fields);
5
+ }
6
+ if (Array.isArray(schema.pages)) {
7
+ for (const page of schema.pages) {
8
+ if (!Array.isArray(page.fields)) {
9
+ continue;
10
+ }
11
+ collected.push(...page.fields);
12
+ }
13
+ }
14
+ return collected;
15
+ }
16
+ function buildFieldAliases(schema) {
17
+ const aliasesByName = /* @__PURE__ */ new Map();
18
+ for (const field of collectSchemaFields(schema)) {
19
+ const name = typeof field.name === "string" ? field.name.trim() : "";
20
+ const fieldKey = typeof field.field_key === "string" ? field.field_key.trim() : "";
21
+ if (name === "") {
22
+ continue;
23
+ }
24
+ if (!aliasesByName.has(name)) {
25
+ aliasesByName.set(name, /* @__PURE__ */ new Set());
26
+ }
27
+ const aliases = aliasesByName.get(name);
28
+ aliases.add(name);
29
+ if (fieldKey !== "") {
30
+ aliases.add(fieldKey);
31
+ }
32
+ }
33
+ return Array.from(aliasesByName.entries()).map(([name, aliases]) => ({
34
+ name,
35
+ aliases: Array.from(aliases)
36
+ }));
37
+ }
38
+ export function resolveSchemaFieldNames(schema) {
39
+ const names = /* @__PURE__ */ new Set();
40
+ for (const field of buildFieldAliases(schema)) {
41
+ for (const alias of field.aliases) {
42
+ names.add(alias);
43
+ }
44
+ }
45
+ return names;
46
+ }
47
+ export function sanitizePayloadWithSchema(value, schema) {
48
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
49
+ return {};
50
+ }
51
+ const sanitizedPayload = {};
52
+ const aliasesByName = buildFieldAliases(schema);
53
+ for (const field of aliasesByName) {
54
+ const nameValue = Object.prototype.hasOwnProperty.call(value, field.name) ? value[field.name] : void 0;
55
+ if (nameValue !== void 0) {
56
+ sanitizedPayload[field.name] = nameValue;
57
+ continue;
58
+ }
59
+ for (const alias of field.aliases) {
60
+ if (alias === field.name) {
61
+ continue;
62
+ }
63
+ if (!Object.prototype.hasOwnProperty.call(value, alias)) {
64
+ continue;
65
+ }
66
+ sanitizedPayload[field.name] = value[alias];
67
+ break;
68
+ }
69
+ }
70
+ return sanitizedPayload;
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanschleret/formforgeclient",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Nuxt module and runtime client for FormForge",
5
5
  "license": "MIT",
6
6
  "type": "module",