@evanschleret/formforgeclient 1.0.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/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/module.cjs +112 -0
- package/dist/module.d.cts +20 -0
- package/dist/module.d.mts +20 -0
- package/dist/module.d.ts +20 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +109 -0
- package/dist/runtime/api/categories.d.ts +9 -0
- package/dist/runtime/api/categories.js +83 -0
- package/dist/runtime/api/client.d.ts +45 -0
- package/dist/runtime/api/client.js +148 -0
- package/dist/runtime/api/drafts.d.ts +6 -0
- package/dist/runtime/api/drafts.js +77 -0
- package/dist/runtime/api/http.d.ts +3 -0
- package/dist/runtime/api/http.js +138 -0
- package/dist/runtime/api/index.d.ts +9 -0
- package/dist/runtime/api/index.js +11 -0
- package/dist/runtime/api/management.d.ts +19 -0
- package/dist/runtime/api/management.js +180 -0
- package/dist/runtime/api/request.d.ts +8 -0
- package/dist/runtime/api/request.js +52 -0
- package/dist/runtime/api/responses.d.ts +6 -0
- package/dist/runtime/api/responses.js +61 -0
- package/dist/runtime/api/schema.d.ts +7 -0
- package/dist/runtime/api/schema.js +56 -0
- package/dist/runtime/api/submission.d.ts +11 -0
- package/dist/runtime/api/submission.js +47 -0
- package/dist/runtime/api/upload.d.ts +8 -0
- package/dist/runtime/api/upload.js +37 -0
- package/dist/runtime/composables/index.d.ts +31 -0
- package/dist/runtime/composables/index.js +16 -0
- package/dist/runtime/composables/useFormForgeApi.d.ts +3 -0
- package/dist/runtime/composables/useFormForgeApi.js +4 -0
- package/dist/runtime/composables/useFormForgeBuilder.d.ts +57 -0
- package/dist/runtime/composables/useFormForgeBuilder.js +515 -0
- package/dist/runtime/composables/useFormForgeCategory.d.ts +61 -0
- package/dist/runtime/composables/useFormForgeCategory.js +248 -0
- package/dist/runtime/composables/useFormForgeClient.d.ts +3 -0
- package/dist/runtime/composables/useFormForgeClient.js +200 -0
- package/dist/runtime/composables/useFormForgeDrafts.d.ts +20 -0
- package/dist/runtime/composables/useFormForgeDrafts.js +78 -0
- package/dist/runtime/composables/useFormForgeForm.d.ts +26 -0
- package/dist/runtime/composables/useFormForgeForm.js +114 -0
- package/dist/runtime/composables/useFormForgeGetForm.d.ts +22 -0
- package/dist/runtime/composables/useFormForgeGetForm.js +36 -0
- package/dist/runtime/composables/useFormForgeI18n.d.ts +250 -0
- package/dist/runtime/composables/useFormForgeI18n.js +324 -0
- package/dist/runtime/composables/useFormForgeManagement.d.ts +40 -0
- package/dist/runtime/composables/useFormForgeManagement.js +153 -0
- package/dist/runtime/composables/useFormForgeResolver.d.ts +28 -0
- package/dist/runtime/composables/useFormForgeResolver.js +88 -0
- package/dist/runtime/composables/useFormForgeResponses.d.ts +45 -0
- package/dist/runtime/composables/useFormForgeResponses.js +206 -0
- package/dist/runtime/composables/useFormForgeSchema.d.ts +24 -0
- package/dist/runtime/composables/useFormForgeSchema.js +69 -0
- package/dist/runtime/composables/useFormForgeSubmission.d.ts +12 -0
- package/dist/runtime/composables/useFormForgeSubmission.js +4 -0
- package/dist/runtime/composables/useFormForgeSubmit.d.ts +29 -0
- package/dist/runtime/composables/useFormForgeSubmit.js +291 -0
- package/dist/runtime/composables/useFormForgeUploads.d.ts +21 -0
- package/dist/runtime/composables/useFormForgeUploads.js +37 -0
- package/dist/runtime/composables/useFormForgeWizard.d.ts +20 -0
- package/dist/runtime/composables/useFormForgeWizard.js +83 -0
- package/dist/runtime/index.d.ts +11 -0
- package/dist/runtime/index.js +14 -0
- package/dist/runtime/plugin.d.ts +3 -0
- package/dist/runtime/plugin.js +175 -0
- package/dist/runtime/renderers/default/FormForgeBuilder.d.vue.ts +40 -0
- package/dist/runtime/renderers/default/FormForgeBuilder.vue +1159 -0
- package/dist/runtime/renderers/default/FormForgeBuilder.vue.d.ts +40 -0
- package/dist/runtime/renderers/default/FormForgeCategoryCreateModal.d.vue.ts +16 -0
- package/dist/runtime/renderers/default/FormForgeCategoryCreateModal.vue +129 -0
- package/dist/runtime/renderers/default/FormForgeCategoryCreateModal.vue.d.ts +16 -0
- package/dist/runtime/renderers/default/FormForgeRenderer.d.vue.ts +72 -0
- package/dist/runtime/renderers/default/FormForgeRenderer.vue +1188 -0
- package/dist/runtime/renderers/default/FormForgeRenderer.vue.d.ts +72 -0
- package/dist/runtime/renderers/default/FormForgeResponse.d.vue.ts +18 -0
- package/dist/runtime/renderers/default/FormForgeResponse.vue +744 -0
- package/dist/runtime/renderers/default/FormForgeResponse.vue.d.ts +18 -0
- package/dist/runtime/renderers/default/index.d.ts +5 -0
- package/dist/runtime/renderers/default/index.js +4 -0
- package/dist/runtime/renderers/index.d.ts +2 -0
- package/dist/runtime/renderers/index.js +1 -0
- package/dist/runtime/types/api.d.ts +129 -0
- package/dist/runtime/types/api.js +0 -0
- package/dist/runtime/types/category.d.ts +42 -0
- package/dist/runtime/types/category.js +0 -0
- package/dist/runtime/types/errors.d.ts +16 -0
- package/dist/runtime/types/errors.js +0 -0
- package/dist/runtime/types/index.d.ts +8 -0
- package/dist/runtime/types/index.js +0 -0
- package/dist/runtime/types/json.d.ts +6 -0
- package/dist/runtime/types/json.js +0 -0
- package/dist/runtime/types/management.d.ts +46 -0
- package/dist/runtime/types/management.js +0 -0
- package/dist/runtime/types/nuxt.d.ts +13 -0
- package/dist/runtime/types/nuxt.js +1 -0
- package/dist/runtime/types/schema.d.ts +93 -0
- package/dist/runtime/types/schema.js +0 -0
- package/dist/runtime/utils/category.d.ts +5 -0
- package/dist/runtime/utils/category.js +101 -0
- package/dist/runtime/utils/form-data.d.ts +8 -0
- package/dist/runtime/utils/form-data.js +64 -0
- package/dist/runtime/utils/object.d.ts +8 -0
- package/dist/runtime/utils/object.js +43 -0
- package/dist/runtime/utils/schema.d.ts +3 -0
- package/dist/runtime/utils/schema.js +309 -0
- package/dist/runtime/utils/submission.d.ts +4 -0
- package/dist/runtime/utils/submission.js +45 -0
- package/dist/runtime/validation/errors.d.ts +5 -0
- package/dist/runtime/validation/errors.js +130 -0
- package/dist/runtime/validation/zod.d.ts +6 -0
- package/dist/runtime/validation/zod.js +203 -0
- package/dist/runtime.cjs +16 -0
- package/dist/runtime.d.cts +1 -0
- package/dist/runtime.d.mts +1 -0
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.mjs +1 -0
- package/dist/types.d.mts +3 -0
- package/package.json +60 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FormForgeManagementRequestOptions } from '../api/management.js';
|
|
2
|
+
import type { FormForgeClient, FormForgeClientConfig, FormForgeDiffResponse, FormForgeManagementCreateInput, FormForgeManagementForm, FormForgeManagementPatchInput, FormForgeScope, FormForgeRevisionSummary } from '../types/index.js';
|
|
3
|
+
export interface UseFormForgeManagementOptions {
|
|
4
|
+
endpoint?: string;
|
|
5
|
+
scope?: FormForgeScope;
|
|
6
|
+
client?: FormForgeClient;
|
|
7
|
+
clientConfig?: FormForgeClientConfig;
|
|
8
|
+
}
|
|
9
|
+
export interface UseFormForgeManagementMutationInputOptions {
|
|
10
|
+
idempotencyKey?: string;
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
scope?: FormForgeScope;
|
|
13
|
+
}
|
|
14
|
+
type UseFormForgeManagementMutationOptions = string | UseFormForgeManagementMutationInputOptions | undefined;
|
|
15
|
+
export declare function useFormForgeManagement(options?: UseFormForgeManagementOptions): {
|
|
16
|
+
client: FormForgeClient;
|
|
17
|
+
loading: any;
|
|
18
|
+
error: any;
|
|
19
|
+
clientError: any;
|
|
20
|
+
fieldErrors: any;
|
|
21
|
+
businessErrorCode: any;
|
|
22
|
+
hasCategoryValidationError: any;
|
|
23
|
+
forms: any;
|
|
24
|
+
lastListIncludeDeleted: any;
|
|
25
|
+
lastListEndpoint: any;
|
|
26
|
+
lastListScope: any;
|
|
27
|
+
lastListFilters: any;
|
|
28
|
+
listForms: (includeDeleted?: boolean, options?: FormForgeManagementRequestOptions) => Promise<FormForgeManagementForm[]>;
|
|
29
|
+
refreshForms: () => Promise<FormForgeManagementForm[]>;
|
|
30
|
+
refresh: () => Promise<FormForgeManagementForm[]>;
|
|
31
|
+
createForm: (input: FormForgeManagementCreateInput, options?: UseFormForgeManagementMutationOptions) => Promise<FormForgeManagementForm>;
|
|
32
|
+
patchForm: (key: string, input: FormForgeManagementPatchInput, options?: UseFormForgeManagementMutationOptions) => Promise<FormForgeManagementForm>;
|
|
33
|
+
publishForm: (key: string, options?: UseFormForgeManagementMutationOptions) => Promise<FormForgeManagementForm>;
|
|
34
|
+
unpublishForm: (key: string, options?: UseFormForgeManagementMutationOptions) => Promise<FormForgeManagementForm>;
|
|
35
|
+
deleteForm: (key: string, options?: UseFormForgeManagementMutationOptions) => Promise<FormForgeManagementForm>;
|
|
36
|
+
getRevisions: (key: string, includeDeleted?: boolean, options?: FormForgeManagementRequestOptions) => Promise<FormForgeRevisionSummary[]>;
|
|
37
|
+
getDiff: (key: string, fromVersion: number, toVersion: number, options?: FormForgeManagementRequestOptions) => Promise<FormForgeDiffResponse>;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=useFormForgeManagement.d.ts.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { computed, ref } from "#imports";
|
|
2
|
+
import { useFormForgeClient } from "./useFormForgeClient.js";
|
|
3
|
+
function isFormForgeClientError(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const candidate = value;
|
|
8
|
+
return typeof candidate.status === "number" && typeof candidate.code === "string" && typeof candidate.message === "string";
|
|
9
|
+
}
|
|
10
|
+
export function useFormForgeManagement(options = {}) {
|
|
11
|
+
const client = options.client ?? useFormForgeClient(options.clientConfig);
|
|
12
|
+
const loading = ref(false);
|
|
13
|
+
const error = ref(null);
|
|
14
|
+
const clientError = ref(null);
|
|
15
|
+
const forms = ref([]);
|
|
16
|
+
const lastListIncludeDeleted = ref(false);
|
|
17
|
+
const lastListEndpoint = ref(options.endpoint);
|
|
18
|
+
const lastListScope = ref(options.scope);
|
|
19
|
+
const lastListFilters = ref({});
|
|
20
|
+
const fieldErrors = computed(() => clientError.value?.fieldErrors ?? {});
|
|
21
|
+
const businessErrorCode = computed(() => clientError.value?.businessCode);
|
|
22
|
+
const hasCategoryValidationError = computed(() => {
|
|
23
|
+
const errors = fieldErrors.value;
|
|
24
|
+
return errors.category !== void 0 || errors.category_key !== void 0;
|
|
25
|
+
});
|
|
26
|
+
async function withLoading(callback) {
|
|
27
|
+
loading.value = true;
|
|
28
|
+
error.value = null;
|
|
29
|
+
clientError.value = null;
|
|
30
|
+
try {
|
|
31
|
+
return await callback();
|
|
32
|
+
} catch (caughtError) {
|
|
33
|
+
error.value = caughtError instanceof Error ? caughtError.message : "Management request failed";
|
|
34
|
+
if (isFormForgeClientError(caughtError)) {
|
|
35
|
+
clientError.value = caughtError;
|
|
36
|
+
}
|
|
37
|
+
throw caughtError;
|
|
38
|
+
} finally {
|
|
39
|
+
loading.value = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function normalizeMutationOptions(options2) {
|
|
43
|
+
if (typeof options2 === "string") {
|
|
44
|
+
return {
|
|
45
|
+
idempotencyKey: options2,
|
|
46
|
+
endpoint: void 0,
|
|
47
|
+
scope: void 0
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
idempotencyKey: options2?.idempotencyKey,
|
|
52
|
+
endpoint: options2?.endpoint ?? void 0,
|
|
53
|
+
scope: options2?.scope ?? void 0
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function resolveRequestEndpoint(endpoint) {
|
|
57
|
+
return endpoint ?? options.endpoint;
|
|
58
|
+
}
|
|
59
|
+
function resolveRequestScope(scope) {
|
|
60
|
+
return scope ?? options.scope;
|
|
61
|
+
}
|
|
62
|
+
async function createForm(input, options2) {
|
|
63
|
+
const mutationOptions = normalizeMutationOptions(options2);
|
|
64
|
+
mutationOptions.endpoint = resolveRequestEndpoint(mutationOptions.endpoint);
|
|
65
|
+
mutationOptions.scope = resolveRequestScope(mutationOptions.scope);
|
|
66
|
+
return withLoading(() => client.createForm(input, mutationOptions));
|
|
67
|
+
}
|
|
68
|
+
async function listForms(includeDeleted = false, options2 = {}) {
|
|
69
|
+
return withLoading(async () => {
|
|
70
|
+
const endpoint = resolveRequestEndpoint(options2.endpoint);
|
|
71
|
+
const scope = resolveRequestScope(options2.scope);
|
|
72
|
+
const filters = options2.filters ?? {};
|
|
73
|
+
const response = await client.listForms(includeDeleted, {
|
|
74
|
+
endpoint,
|
|
75
|
+
scope,
|
|
76
|
+
filters
|
|
77
|
+
});
|
|
78
|
+
forms.value = response;
|
|
79
|
+
lastListIncludeDeleted.value = includeDeleted;
|
|
80
|
+
lastListEndpoint.value = endpoint;
|
|
81
|
+
lastListScope.value = scope;
|
|
82
|
+
lastListFilters.value = filters;
|
|
83
|
+
return response;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async function refreshForms() {
|
|
87
|
+
return listForms(lastListIncludeDeleted.value, {
|
|
88
|
+
endpoint: lastListEndpoint.value,
|
|
89
|
+
scope: lastListScope.value,
|
|
90
|
+
filters: lastListFilters.value
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async function patchForm(key, input, options2) {
|
|
94
|
+
const mutationOptions = normalizeMutationOptions(options2);
|
|
95
|
+
mutationOptions.endpoint = resolveRequestEndpoint(mutationOptions.endpoint);
|
|
96
|
+
mutationOptions.scope = resolveRequestScope(mutationOptions.scope);
|
|
97
|
+
return withLoading(() => client.patchForm(key, input, mutationOptions));
|
|
98
|
+
}
|
|
99
|
+
async function publishForm(key, options2) {
|
|
100
|
+
const mutationOptions = normalizeMutationOptions(options2);
|
|
101
|
+
mutationOptions.endpoint = resolveRequestEndpoint(mutationOptions.endpoint);
|
|
102
|
+
mutationOptions.scope = resolveRequestScope(mutationOptions.scope);
|
|
103
|
+
return withLoading(() => client.publishForm(key, mutationOptions));
|
|
104
|
+
}
|
|
105
|
+
async function unpublishForm(key, options2) {
|
|
106
|
+
const mutationOptions = normalizeMutationOptions(options2);
|
|
107
|
+
mutationOptions.endpoint = resolveRequestEndpoint(mutationOptions.endpoint);
|
|
108
|
+
mutationOptions.scope = resolveRequestScope(mutationOptions.scope);
|
|
109
|
+
return withLoading(() => client.unpublishForm(key, mutationOptions));
|
|
110
|
+
}
|
|
111
|
+
async function deleteForm(key, options2) {
|
|
112
|
+
const mutationOptions = normalizeMutationOptions(options2);
|
|
113
|
+
mutationOptions.endpoint = resolveRequestEndpoint(mutationOptions.endpoint);
|
|
114
|
+
mutationOptions.scope = resolveRequestScope(mutationOptions.scope);
|
|
115
|
+
return withLoading(() => client.deleteForm(key, mutationOptions));
|
|
116
|
+
}
|
|
117
|
+
async function getRevisions(key, includeDeleted = false, options2 = {}) {
|
|
118
|
+
return withLoading(() => client.getRevisions(key, includeDeleted, {
|
|
119
|
+
endpoint: resolveRequestEndpoint(options2.endpoint),
|
|
120
|
+
scope: resolveRequestScope(options2.scope)
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
async function getDiff(key, fromVersion, toVersion, options2 = {}) {
|
|
124
|
+
return withLoading(() => client.getDiff(key, fromVersion, toVersion, {
|
|
125
|
+
endpoint: resolveRequestEndpoint(options2.endpoint),
|
|
126
|
+
scope: resolveRequestScope(options2.scope)
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
client,
|
|
131
|
+
loading,
|
|
132
|
+
error,
|
|
133
|
+
clientError,
|
|
134
|
+
fieldErrors,
|
|
135
|
+
businessErrorCode,
|
|
136
|
+
hasCategoryValidationError,
|
|
137
|
+
forms,
|
|
138
|
+
lastListIncludeDeleted,
|
|
139
|
+
lastListEndpoint,
|
|
140
|
+
lastListScope,
|
|
141
|
+
lastListFilters,
|
|
142
|
+
listForms,
|
|
143
|
+
refreshForms,
|
|
144
|
+
refresh: refreshForms,
|
|
145
|
+
createForm,
|
|
146
|
+
patchForm,
|
|
147
|
+
publishForm,
|
|
148
|
+
unpublishForm,
|
|
149
|
+
deleteForm,
|
|
150
|
+
getRevisions,
|
|
151
|
+
getDiff
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FormForgeClient, FormForgeClientConfig, FormForgeFormSchema, FormForgeScope, FormForgeSubmissionPayload } from '../types/index.js';
|
|
2
|
+
import type { FormForgeRequestOptions } from '../api/request.js';
|
|
3
|
+
export interface UseFormForgeResolverOptions {
|
|
4
|
+
key: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
scope?: FormForgeScope;
|
|
8
|
+
delay?: number;
|
|
9
|
+
payload?: () => FormForgeSubmissionPayload;
|
|
10
|
+
immediate?: boolean;
|
|
11
|
+
watchPayload?: boolean;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
client?: FormForgeClient;
|
|
14
|
+
clientConfig?: FormForgeClientConfig;
|
|
15
|
+
}
|
|
16
|
+
export interface FormForgeResolveOptions extends FormForgeRequestOptions {
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function useFormForgeResolver(options: UseFormForgeResolverOptions): {
|
|
20
|
+
client: FormForgeClient;
|
|
21
|
+
schema: any;
|
|
22
|
+
resolving: any;
|
|
23
|
+
error: any;
|
|
24
|
+
resolve: (payload?: FormForgeSubmissionPayload, resolveOptions?: FormForgeResolveOptions) => Promise<FormForgeFormSchema>;
|
|
25
|
+
resolveNow: (payload?: FormForgeSubmissionPayload, resolveOptions?: FormForgeResolveOptions) => Promise<FormForgeFormSchema>;
|
|
26
|
+
clearScheduledResolve: () => void;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useFormForgeResolver.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { onBeforeUnmount, ref, watch } from "#imports";
|
|
2
|
+
import { toFormForgeJsonSubmissionPayload } from "../utils/submission.js";
|
|
3
|
+
import { useFormForgeClient } from "./useFormForgeClient.js";
|
|
4
|
+
export function useFormForgeResolver(options) {
|
|
5
|
+
const client = options.client ?? useFormForgeClient(options.clientConfig);
|
|
6
|
+
const delay = options.delay ?? 200;
|
|
7
|
+
const resolving = ref(false);
|
|
8
|
+
const error = ref(null);
|
|
9
|
+
const schema = ref(null);
|
|
10
|
+
let timer;
|
|
11
|
+
let requestId = 0;
|
|
12
|
+
function clearScheduledResolve() {
|
|
13
|
+
if (timer === void 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
timer = void 0;
|
|
18
|
+
}
|
|
19
|
+
async function resolveNow(payload = {}, resolveOptions = {}) {
|
|
20
|
+
const nextRequestId = requestId + 1;
|
|
21
|
+
requestId = nextRequestId;
|
|
22
|
+
resolving.value = true;
|
|
23
|
+
error.value = null;
|
|
24
|
+
try {
|
|
25
|
+
const resolved = await client.resolveForm(
|
|
26
|
+
options.key,
|
|
27
|
+
{
|
|
28
|
+
payload: toFormForgeJsonSubmissionPayload(payload),
|
|
29
|
+
debug: resolveOptions.debug === true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
version: options.version,
|
|
33
|
+
endpoint: resolveOptions.endpoint ?? options.endpoint,
|
|
34
|
+
scope: resolveOptions.scope ?? options.scope
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
if (requestId === nextRequestId) {
|
|
38
|
+
schema.value = resolved;
|
|
39
|
+
}
|
|
40
|
+
return resolved;
|
|
41
|
+
} catch (caughtError) {
|
|
42
|
+
if (requestId === nextRequestId) {
|
|
43
|
+
error.value = caughtError instanceof Error ? caughtError.message : "Failed to resolve schema";
|
|
44
|
+
}
|
|
45
|
+
throw caughtError;
|
|
46
|
+
} finally {
|
|
47
|
+
if (requestId === nextRequestId) {
|
|
48
|
+
resolving.value = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function resolve(payload = {}, resolveOptions = {}) {
|
|
53
|
+
clearScheduledResolve();
|
|
54
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
55
|
+
timer = setTimeout(() => {
|
|
56
|
+
resolveNow(payload, resolveOptions).then(resolvePromise).catch(rejectPromise);
|
|
57
|
+
}, delay);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
onBeforeUnmount(() => {
|
|
61
|
+
clearScheduledResolve();
|
|
62
|
+
});
|
|
63
|
+
if (options.payload !== void 0 && options.watchPayload === true) {
|
|
64
|
+
watch(options.payload, (nextPayload) => {
|
|
65
|
+
resolve(nextPayload, {
|
|
66
|
+
debug: options.debug
|
|
67
|
+
}).catch(() => {
|
|
68
|
+
});
|
|
69
|
+
}, {
|
|
70
|
+
deep: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (options.payload !== void 0 && options.immediate === true) {
|
|
74
|
+
resolve(options.payload(), {
|
|
75
|
+
debug: options.debug
|
|
76
|
+
}).catch(() => {
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
client,
|
|
81
|
+
schema,
|
|
82
|
+
resolving,
|
|
83
|
+
error,
|
|
84
|
+
resolve,
|
|
85
|
+
resolveNow,
|
|
86
|
+
clearScheduledResolve
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { FormForgeRequestOptions } from '../api/request.js';
|
|
2
|
+
import type { FormForgeClient, FormForgeClientConfig, FormForgeJsonObject, FormForgeResponsesListResponse, FormForgeScope } from '../types/index.js';
|
|
3
|
+
type FormForgeResponsesQueryValue = string | number | boolean | undefined;
|
|
4
|
+
type FormForgeResponsesQuery = Record<string, FormForgeResponsesQueryValue>;
|
|
5
|
+
export interface UseFormForgeResponsesQuerySync {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
pageKey?: string;
|
|
8
|
+
perPageKey?: string;
|
|
9
|
+
extraKeys?: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface UseFormForgeResponsesOptions {
|
|
12
|
+
key: string;
|
|
13
|
+
immediate?: boolean;
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
scope?: FormForgeScope;
|
|
16
|
+
client?: FormForgeClient;
|
|
17
|
+
clientConfig?: FormForgeClientConfig;
|
|
18
|
+
querySync?: UseFormForgeResponsesQuerySync;
|
|
19
|
+
}
|
|
20
|
+
export type FormForgeResponsesRequestOptions = FormForgeRequestOptions;
|
|
21
|
+
export interface FormForgeResponsesRefreshOptions {
|
|
22
|
+
mode?: 'auto' | 'list' | 'resource';
|
|
23
|
+
query?: FormForgeResponsesQuery;
|
|
24
|
+
submissionId?: string;
|
|
25
|
+
endpoint?: string;
|
|
26
|
+
scope?: FormForgeScope;
|
|
27
|
+
}
|
|
28
|
+
export declare function useFormForgeResponses(options: UseFormForgeResponsesOptions): {
|
|
29
|
+
client: FormForgeClient;
|
|
30
|
+
loading: any;
|
|
31
|
+
error: any;
|
|
32
|
+
list: any;
|
|
33
|
+
lastMeta: any;
|
|
34
|
+
current: any;
|
|
35
|
+
lastListQuery: any;
|
|
36
|
+
lastListEndpoint: any;
|
|
37
|
+
lastListScope: any;
|
|
38
|
+
lastSubmissionId: any;
|
|
39
|
+
refresh: (options?: FormForgeResponsesRefreshOptions) => Promise<FormForgeResponsesListResponse | FormForgeJsonObject>;
|
|
40
|
+
listResponses: (query?: FormForgeResponsesQuery, requestOptions?: FormForgeResponsesRequestOptions) => Promise<FormForgeResponsesListResponse>;
|
|
41
|
+
getResponse: (submissionId: string, requestOptions?: FormForgeResponsesRequestOptions) => Promise<FormForgeJsonObject>;
|
|
42
|
+
deleteResponse: (submissionId: string, requestOptions?: FormForgeResponsesRequestOptions) => Promise<FormForgeJsonObject>;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=useFormForgeResponses.d.ts.map
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { ref, useRoute, watch } from "#imports";
|
|
2
|
+
import { useFormForgeClient } from "./useFormForgeClient.js";
|
|
3
|
+
function normalizeRouteQueryValue(value) {
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
if (value.length === 0) {
|
|
6
|
+
return void 0;
|
|
7
|
+
}
|
|
8
|
+
return normalizeRouteQueryValue(value[0]);
|
|
9
|
+
}
|
|
10
|
+
if (value === null || value === void 0 || value === "") {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
if (value === "true") {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (value === "false") {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (/^-?\d+$/.test(value)) {
|
|
20
|
+
return Number(value);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
export function useFormForgeResponses(options) {
|
|
25
|
+
const client = options.client ?? useFormForgeClient(options.clientConfig);
|
|
26
|
+
const route = useRoute();
|
|
27
|
+
const loading = ref(false);
|
|
28
|
+
const error = ref(null);
|
|
29
|
+
const list = ref([]);
|
|
30
|
+
const lastMeta = ref(void 0);
|
|
31
|
+
const current = ref(null);
|
|
32
|
+
const lastListQuery = ref({});
|
|
33
|
+
const lastListEndpoint = ref(options.endpoint);
|
|
34
|
+
const lastListScope = ref(options.scope);
|
|
35
|
+
const lastSubmissionId = ref(null);
|
|
36
|
+
const lastMode = ref(null);
|
|
37
|
+
const immediateLoad = options.immediate ?? true;
|
|
38
|
+
const syncOptions = {
|
|
39
|
+
enabled: options.querySync?.enabled ?? true,
|
|
40
|
+
pageKey: options.querySync?.pageKey ?? "page",
|
|
41
|
+
perPageKey: options.querySync?.perPageKey ?? "per_page",
|
|
42
|
+
extraKeys: options.querySync?.extraKeys ?? []
|
|
43
|
+
};
|
|
44
|
+
function resolveRouteListQuery() {
|
|
45
|
+
if (syncOptions.enabled === false) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
const query = {};
|
|
49
|
+
const keys = [syncOptions.pageKey, syncOptions.perPageKey, ...syncOptions.extraKeys];
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
const rawValue = route.query[key];
|
|
52
|
+
const value = normalizeRouteQueryValue(rawValue);
|
|
53
|
+
if (value !== void 0) {
|
|
54
|
+
query[key] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return query;
|
|
58
|
+
}
|
|
59
|
+
function createListQuery(override = {}) {
|
|
60
|
+
return {
|
|
61
|
+
...resolveRouteListQuery(),
|
|
62
|
+
...override
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function resolveEndpoint(requestOptions = {}) {
|
|
66
|
+
return requestOptions.endpoint ?? options.endpoint;
|
|
67
|
+
}
|
|
68
|
+
function resolveScope(requestOptions = {}) {
|
|
69
|
+
return requestOptions.scope ?? options.scope;
|
|
70
|
+
}
|
|
71
|
+
async function withLoading(callback) {
|
|
72
|
+
loading.value = true;
|
|
73
|
+
error.value = null;
|
|
74
|
+
try {
|
|
75
|
+
return await callback();
|
|
76
|
+
} catch (caughtError) {
|
|
77
|
+
error.value = caughtError instanceof Error ? caughtError.message : "Responses request failed";
|
|
78
|
+
throw caughtError;
|
|
79
|
+
} finally {
|
|
80
|
+
loading.value = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function listResponses(query = {}, requestOptions = {}) {
|
|
84
|
+
return withLoading(async () => {
|
|
85
|
+
const resolvedQuery = createListQuery(query);
|
|
86
|
+
const endpoint = resolveEndpoint(requestOptions);
|
|
87
|
+
const scope = resolveScope(requestOptions);
|
|
88
|
+
const response = await client.listResponses(options.key, resolvedQuery, {
|
|
89
|
+
endpoint,
|
|
90
|
+
scope
|
|
91
|
+
});
|
|
92
|
+
list.value = response.data;
|
|
93
|
+
lastMeta.value = response.meta;
|
|
94
|
+
lastListQuery.value = resolvedQuery;
|
|
95
|
+
lastListEndpoint.value = endpoint;
|
|
96
|
+
lastListScope.value = scope;
|
|
97
|
+
lastMode.value = "list";
|
|
98
|
+
return response;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async function getResponse(submissionId, requestOptions = {}) {
|
|
102
|
+
return withLoading(async () => {
|
|
103
|
+
const response = await client.getResponse(options.key, submissionId, {
|
|
104
|
+
endpoint: resolveEndpoint(requestOptions),
|
|
105
|
+
scope: resolveScope(requestOptions)
|
|
106
|
+
});
|
|
107
|
+
current.value = response;
|
|
108
|
+
lastSubmissionId.value = submissionId;
|
|
109
|
+
lastMode.value = "resource";
|
|
110
|
+
return response;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function deleteResponse(submissionId, requestOptions = {}) {
|
|
114
|
+
return withLoading(async () => {
|
|
115
|
+
const response = await client.deleteResponse(options.key, submissionId, {
|
|
116
|
+
endpoint: resolveEndpoint(requestOptions),
|
|
117
|
+
scope: resolveScope(requestOptions)
|
|
118
|
+
});
|
|
119
|
+
current.value = response;
|
|
120
|
+
list.value = list.value.filter((item) => {
|
|
121
|
+
const id = item.submission_id;
|
|
122
|
+
return !(typeof id === "string" && id === submissionId);
|
|
123
|
+
});
|
|
124
|
+
return response;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async function refresh(options2 = {}) {
|
|
128
|
+
const mode = options2.mode ?? "auto";
|
|
129
|
+
const endpoint = options2.endpoint ?? lastListEndpoint.value ?? void 0;
|
|
130
|
+
const scope = options2.scope ?? lastListScope.value;
|
|
131
|
+
if (mode === "list") {
|
|
132
|
+
return listResponses(options2.query ?? lastListQuery.value, {
|
|
133
|
+
endpoint,
|
|
134
|
+
scope
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (mode === "resource") {
|
|
138
|
+
const submissionId = options2.submissionId ?? lastSubmissionId.value;
|
|
139
|
+
if (typeof submissionId === "string" && submissionId !== "") {
|
|
140
|
+
return getResponse(submissionId, {
|
|
141
|
+
endpoint,
|
|
142
|
+
scope
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return listResponses(options2.query ?? lastListQuery.value, {
|
|
146
|
+
endpoint,
|
|
147
|
+
scope
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (lastMode.value === "resource") {
|
|
151
|
+
const submissionId = options2.submissionId ?? lastSubmissionId.value;
|
|
152
|
+
if (typeof submissionId === "string" && submissionId !== "") {
|
|
153
|
+
return getResponse(submissionId, {
|
|
154
|
+
endpoint,
|
|
155
|
+
scope
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return listResponses(options2.query ?? lastListQuery.value, {
|
|
160
|
+
endpoint,
|
|
161
|
+
scope
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (syncOptions.enabled === true) {
|
|
165
|
+
watch(
|
|
166
|
+
() => [
|
|
167
|
+
route.query[syncOptions.pageKey],
|
|
168
|
+
route.query[syncOptions.perPageKey],
|
|
169
|
+
...syncOptions.extraKeys.map((key) => route.query[key])
|
|
170
|
+
],
|
|
171
|
+
() => {
|
|
172
|
+
listResponses({}, {
|
|
173
|
+
endpoint: lastListEndpoint.value ?? options.endpoint,
|
|
174
|
+
scope: lastListScope.value ?? options.scope
|
|
175
|
+
}).catch(() => {
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
immediate: false
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (immediateLoad === true) {
|
|
184
|
+
listResponses({}, {
|
|
185
|
+
endpoint: options.endpoint,
|
|
186
|
+
scope: options.scope
|
|
187
|
+
}).catch(() => {
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
client,
|
|
192
|
+
loading,
|
|
193
|
+
error,
|
|
194
|
+
list,
|
|
195
|
+
lastMeta,
|
|
196
|
+
current,
|
|
197
|
+
lastListQuery,
|
|
198
|
+
lastListEndpoint,
|
|
199
|
+
lastListScope,
|
|
200
|
+
lastSubmissionId,
|
|
201
|
+
refresh,
|
|
202
|
+
listResponses,
|
|
203
|
+
getResponse,
|
|
204
|
+
deleteResponse
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FormForgeClient, FormForgeClientConfig, FormForgeFormSchema, FormForgeSchemaVersionsResponse, FormForgeScope } from '../types/index.js';
|
|
2
|
+
import type { FormForgeRequestOptions } from '../api/request.js';
|
|
3
|
+
export interface UseFormForgeSchemaOptions {
|
|
4
|
+
key: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
scope?: FormForgeScope;
|
|
8
|
+
immediate?: boolean;
|
|
9
|
+
loadVersions?: boolean;
|
|
10
|
+
client?: FormForgeClient;
|
|
11
|
+
clientConfig?: FormForgeClientConfig;
|
|
12
|
+
}
|
|
13
|
+
export type FormForgeSchemaFetchOptions = FormForgeRequestOptions;
|
|
14
|
+
export declare function useFormForgeSchema(options: UseFormForgeSchemaOptions): {
|
|
15
|
+
client: FormForgeClient;
|
|
16
|
+
schema: any;
|
|
17
|
+
versions: any;
|
|
18
|
+
loading: any;
|
|
19
|
+
error: any;
|
|
20
|
+
fetchSchema: (requestOptions?: FormForgeSchemaFetchOptions) => Promise<FormForgeFormSchema>;
|
|
21
|
+
fetchVersions: (requestOptions?: FormForgeSchemaFetchOptions) => Promise<FormForgeSchemaVersionsResponse>;
|
|
22
|
+
refresh: (requestOptions?: FormForgeSchemaFetchOptions) => Promise<FormForgeFormSchema>;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=useFormForgeSchema.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ref } from "#imports";
|
|
2
|
+
import { useFormForgeClient } from "./useFormForgeClient.js";
|
|
3
|
+
export function useFormForgeSchema(options) {
|
|
4
|
+
const client = options.client ?? useFormForgeClient(options.clientConfig);
|
|
5
|
+
const schema = ref(null);
|
|
6
|
+
const versions = ref(null);
|
|
7
|
+
const loading = ref(false);
|
|
8
|
+
const error = ref(null);
|
|
9
|
+
function resolveEndpoint(requestOptions = {}) {
|
|
10
|
+
return requestOptions.endpoint ?? options.endpoint;
|
|
11
|
+
}
|
|
12
|
+
function resolveScope(requestOptions = {}) {
|
|
13
|
+
return requestOptions.scope ?? options.scope;
|
|
14
|
+
}
|
|
15
|
+
async function fetchSchema(requestOptions = {}) {
|
|
16
|
+
loading.value = true;
|
|
17
|
+
error.value = null;
|
|
18
|
+
try {
|
|
19
|
+
const endpoint = resolveEndpoint(requestOptions);
|
|
20
|
+
const scope = resolveScope(requestOptions);
|
|
21
|
+
const nextSchema = options.version !== void 0 && options.version !== "" ? await client.getFormVersion(options.key, options.version, { endpoint, scope }) : await client.getForm(options.key, { endpoint, scope });
|
|
22
|
+
schema.value = nextSchema;
|
|
23
|
+
return nextSchema;
|
|
24
|
+
} catch (caughtError) {
|
|
25
|
+
error.value = caughtError instanceof Error ? caughtError.message : "Failed to fetch schema";
|
|
26
|
+
throw caughtError;
|
|
27
|
+
} finally {
|
|
28
|
+
loading.value = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function fetchVersions(requestOptions = {}) {
|
|
32
|
+
loading.value = true;
|
|
33
|
+
error.value = null;
|
|
34
|
+
try {
|
|
35
|
+
const nextVersions = await client.getFormVersions(options.key, {
|
|
36
|
+
endpoint: resolveEndpoint(requestOptions),
|
|
37
|
+
scope: resolveScope(requestOptions)
|
|
38
|
+
});
|
|
39
|
+
versions.value = nextVersions;
|
|
40
|
+
return nextVersions;
|
|
41
|
+
} catch (caughtError) {
|
|
42
|
+
error.value = caughtError instanceof Error ? caughtError.message : "Failed to fetch schema versions";
|
|
43
|
+
throw caughtError;
|
|
44
|
+
} finally {
|
|
45
|
+
loading.value = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function refresh(requestOptions = {}) {
|
|
49
|
+
const nextSchema = await fetchSchema(requestOptions);
|
|
50
|
+
if (options.loadVersions === true) {
|
|
51
|
+
await fetchVersions(requestOptions);
|
|
52
|
+
}
|
|
53
|
+
return nextSchema;
|
|
54
|
+
}
|
|
55
|
+
if (options.immediate !== false) {
|
|
56
|
+
refresh().catch(() => {
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
client,
|
|
61
|
+
schema,
|
|
62
|
+
versions,
|
|
63
|
+
loading,
|
|
64
|
+
error,
|
|
65
|
+
fetchSchema,
|
|
66
|
+
fetchVersions,
|
|
67
|
+
refresh
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FormForgeSubmitOptions, UseFormForgeSubmitOptions } from './useFormForgeSubmit.js';
|
|
2
|
+
export type UseFormForgeSubmissionOptions = UseFormForgeSubmitOptions;
|
|
3
|
+
export type FormForgeSubmissionOptions = FormForgeSubmitOptions;
|
|
4
|
+
export declare function useFormForgeSubmission(options: UseFormForgeSubmissionOptions): {
|
|
5
|
+
client: import("..").FormForgeClient;
|
|
6
|
+
submitting: any;
|
|
7
|
+
fieldErrors: any;
|
|
8
|
+
error: any;
|
|
9
|
+
response: any;
|
|
10
|
+
submit: (submitOptions?: FormForgeSubmitOptions) => Promise<import("..").FormForgeSubmissionResponse>;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=useFormForgeSubmission.d.ts.map
|