@evanschleret/formforgeclient 1.2.2 → 1.2.4
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
|
@@ -121,11 +121,10 @@ export function useFormForgeClient(config = {}) {
|
|
|
121
121
|
const nuxtApp = useNuxtApp();
|
|
122
122
|
const route = useRoute();
|
|
123
123
|
const injectedClient = nuxtApp.$formforge;
|
|
124
|
+
const baseConfig = injectedClient?.config ?? useRuntimeConfig().public.formforge;
|
|
124
125
|
if (injectedClient !== void 0 && !hasConfigOverrides(config)) {
|
|
125
126
|
return injectedClient;
|
|
126
127
|
}
|
|
127
|
-
const runtimeConfig = useRuntimeConfig();
|
|
128
|
-
const runtimePublicConfig = runtimeConfig.public.formforge;
|
|
129
128
|
const routeParamsResolver = () => {
|
|
130
129
|
const appRouteQuery = nuxtApp._route?.value?.query;
|
|
131
130
|
const appRouteParams = nuxtApp._route?.value?.params;
|
|
@@ -144,14 +143,13 @@ export function useFormForgeClient(config = {}) {
|
|
|
144
143
|
}
|
|
145
144
|
);
|
|
146
145
|
const resolvedPath = composableRoutePath || appRoutePath;
|
|
147
|
-
const resolvedBaseURL = config.baseURL ??
|
|
148
|
-
const resolvedScopedRoutes = config.scopedRoutes ??
|
|
146
|
+
const resolvedBaseURL = config.baseURL ?? baseConfig?.baseURL;
|
|
147
|
+
const resolvedScopedRoutes = config.scopedRoutes ?? baseConfig?.scopedRoutes;
|
|
149
148
|
const inferredFromBaseURL = inferParamsFromPath(resolvedBaseURL, resolvedPath);
|
|
150
149
|
const withBaseURLValues = withInferredMissingValues(mergedRouteValues, inferredFromBaseURL);
|
|
151
150
|
const inferredFromScopes = inferScopeSourcesFromPath(resolvedScopedRoutes, resolvedPath);
|
|
152
151
|
return withInferredMissingValues(withBaseURLValues, inferredFromScopes);
|
|
153
152
|
};
|
|
154
|
-
const baseConfig = runtimePublicConfig;
|
|
155
153
|
const mergedConfig = {
|
|
156
154
|
...baseConfig,
|
|
157
155
|
...config
|
|
@@ -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
|
+
}
|