@btst/stack 2.1.0 → 2.2.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/dist/api/index.cjs +9 -1
- package/dist/api/index.d.cts +4 -4
- package/dist/api/index.d.mts +4 -4
- package/dist/api/index.d.ts +4 -4
- package/dist/api/index.mjs +9 -1
- package/dist/client/index.d.cts +2 -2
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/api/getters.cjs +42 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/getters.mjs +39 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.cjs +5 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.mjs +5 -0
- package/dist/packages/stack/src/plugins/blog/api/getters.cjs +131 -0
- package/dist/packages/stack/src/plugins/blog/api/getters.mjs +127 -0
- package/dist/packages/stack/src/plugins/blog/api/plugin.cjs +9 -107
- package/dist/packages/stack/src/plugins/blog/api/plugin.mjs +9 -107
- package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +1 -1
- package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +1 -1
- package/dist/packages/stack/src/plugins/cms/api/getters.cjs +146 -0
- package/dist/packages/stack/src/plugins/cms/api/getters.mjs +138 -0
- package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +560 -622
- package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +559 -621
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.cjs +1 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.mjs +1 -1
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.cjs +6 -3
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.mjs +6 -3
- package/dist/packages/stack/src/plugins/form-builder/api/getters.cjs +111 -0
- package/dist/packages/stack/src/plugins/form-builder/api/getters.mjs +104 -0
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.cjs +16 -88
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.mjs +12 -84
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +1 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +1 -1
- package/dist/packages/stack/src/plugins/kanban/api/getters.cjs +84 -0
- package/dist/packages/stack/src/plugins/kanban/api/getters.mjs +81 -0
- package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +9 -123
- package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +9 -123
- package/dist/packages/stack/src/plugins/kanban/client/plugin.cjs +1 -1
- package/dist/packages/stack/src/plugins/kanban/client/plugin.mjs +1 -1
- package/dist/plugins/ai-chat/api/index.cjs +3 -0
- package/dist/plugins/ai-chat/api/index.d.cts +27 -4
- package/dist/plugins/ai-chat/api/index.d.mts +27 -4
- package/dist/plugins/ai-chat/api/index.d.ts +27 -4
- package/dist/plugins/ai-chat/api/index.mjs +1 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.cts +2 -2
- package/dist/plugins/ai-chat/client/hooks/index.d.mts +2 -2
- package/dist/plugins/ai-chat/client/hooks/index.d.ts +2 -2
- package/dist/plugins/ai-chat/query-keys.d.cts +9 -284
- package/dist/plugins/ai-chat/query-keys.d.mts +9 -284
- package/dist/plugins/ai-chat/query-keys.d.ts +9 -284
- package/dist/plugins/api/index.d.cts +4 -3
- package/dist/plugins/api/index.d.mts +4 -3
- package/dist/plugins/api/index.d.ts +4 -3
- package/dist/plugins/blog/api/index.cjs +4 -0
- package/dist/plugins/blog/api/index.d.cts +3 -2
- package/dist/plugins/blog/api/index.d.mts +3 -2
- package/dist/plugins/blog/api/index.d.ts +3 -2
- package/dist/plugins/blog/api/index.mjs +1 -0
- package/dist/plugins/blog/client/hooks/index.d.cts +4 -4
- package/dist/plugins/blog/client/hooks/index.d.mts +4 -4
- package/dist/plugins/blog/client/hooks/index.d.ts +4 -4
- package/dist/plugins/blog/client/index.d.cts +1 -1
- package/dist/plugins/blog/client/index.d.mts +1 -1
- package/dist/plugins/blog/client/index.d.ts +1 -1
- package/dist/plugins/blog/query-keys.cjs +7 -4
- package/dist/plugins/blog/query-keys.d.cts +81 -27
- package/dist/plugins/blog/query-keys.d.mts +81 -27
- package/dist/plugins/blog/query-keys.d.ts +81 -27
- package/dist/plugins/blog/query-keys.mjs +7 -4
- package/dist/plugins/client/index.d.cts +2 -2
- package/dist/plugins/client/index.d.mts +2 -2
- package/dist/plugins/client/index.d.ts +2 -2
- package/dist/plugins/cms/api/index.cjs +4 -0
- package/dist/plugins/cms/api/index.d.cts +61 -5
- package/dist/plugins/cms/api/index.d.mts +61 -5
- package/dist/plugins/cms/api/index.d.ts +61 -5
- package/dist/plugins/cms/api/index.mjs +1 -0
- package/dist/plugins/cms/client/hooks/index.d.cts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.mts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.ts +1 -1
- package/dist/plugins/cms/query-keys.d.cts +2 -1
- package/dist/plugins/cms/query-keys.d.mts +2 -1
- package/dist/plugins/cms/query-keys.d.ts +2 -1
- package/dist/plugins/form-builder/api/index.cjs +4 -0
- package/dist/plugins/form-builder/api/index.d.cts +77 -7
- package/dist/plugins/form-builder/api/index.d.mts +77 -7
- package/dist/plugins/form-builder/api/index.d.ts +77 -7
- package/dist/plugins/form-builder/api/index.mjs +1 -0
- package/dist/plugins/form-builder/client/components/index.d.cts +1 -1
- package/dist/plugins/form-builder/client/components/index.d.mts +1 -1
- package/dist/plugins/form-builder/client/components/index.d.ts +1 -1
- package/dist/plugins/form-builder/client/hooks/index.d.cts +1 -1
- package/dist/plugins/form-builder/client/hooks/index.d.mts +1 -1
- package/dist/plugins/form-builder/client/hooks/index.d.ts +1 -1
- package/dist/plugins/form-builder/query-keys.d.cts +2 -1
- package/dist/plugins/form-builder/query-keys.d.mts +2 -1
- package/dist/plugins/form-builder/query-keys.d.ts +2 -1
- package/dist/plugins/kanban/api/index.cjs +3 -0
- package/dist/plugins/kanban/api/index.d.cts +40 -43
- package/dist/plugins/kanban/api/index.d.mts +40 -43
- package/dist/plugins/kanban/api/index.d.ts +40 -43
- package/dist/plugins/kanban/api/index.mjs +1 -0
- package/dist/plugins/kanban/client/components/index.d.cts +1 -1
- package/dist/plugins/kanban/client/components/index.d.mts +1 -1
- package/dist/plugins/kanban/client/components/index.d.ts +1 -1
- package/dist/plugins/kanban/client/hooks/index.d.cts +1 -1
- package/dist/plugins/kanban/client/hooks/index.d.mts +1 -1
- package/dist/plugins/kanban/client/hooks/index.d.ts +1 -1
- package/dist/plugins/kanban/client/index.d.cts +1 -1
- package/dist/plugins/kanban/client/index.d.mts +1 -1
- package/dist/plugins/kanban/client/index.d.ts +1 -1
- package/dist/plugins/kanban/query-keys.cjs +4 -3
- package/dist/plugins/kanban/query-keys.d.cts +2 -1
- package/dist/plugins/kanban/query-keys.d.mts +2 -1
- package/dist/plugins/kanban/query-keys.d.ts +2 -1
- package/dist/plugins/kanban/query-keys.mjs +4 -3
- package/dist/plugins/open-api/api/index.d.cts +2 -2
- package/dist/plugins/open-api/api/index.d.mts +2 -2
- package/dist/plugins/open-api/api/index.d.ts +2 -2
- package/dist/plugins/route-docs/client/index.d.cts +1 -1
- package/dist/plugins/route-docs/client/index.d.mts +1 -1
- package/dist/plugins/route-docs/client/index.d.ts +1 -1
- package/dist/plugins/ui-builder/index.d.cts +1 -1
- package/dist/plugins/ui-builder/index.d.mts +1 -1
- package/dist/plugins/ui-builder/index.d.ts +1 -1
- package/dist/shared/{stack.BoA0xkJv.d.cts → stack.7n9Y_u7N.d.cts} +33 -7
- package/dist/shared/{stack.BoA0xkJv.d.mts → stack.7n9Y_u7N.d.mts} +33 -7
- package/dist/shared/{stack.BoA0xkJv.d.ts → stack.7n9Y_u7N.d.ts} +33 -7
- package/dist/shared/stack.BeSm90va.d.ts +289 -0
- package/dist/shared/{stack.DzH_wcvr.d.mts → stack.CIrIsc-A.d.cts} +2 -2
- package/dist/shared/{stack.DzH_wcvr.d.ts → stack.CIrIsc-A.d.mts} +2 -2
- package/dist/shared/{stack.DzH_wcvr.d.cts → stack.CIrIsc-A.d.ts} +2 -2
- package/dist/shared/stack.CMh_EdxW.d.cts +289 -0
- package/dist/shared/{stack.BsXokfNh.d.mts → stack.CXjzTMsb.d.cts} +1 -1
- package/dist/shared/{stack.BsXokfNh.d.ts → stack.CXjzTMsb.d.mts} +1 -1
- package/dist/shared/{stack.BsXokfNh.d.cts → stack.CXjzTMsb.d.ts} +1 -1
- package/dist/shared/stack.Dg09R0oB.d.mts +289 -0
- package/dist/shared/{stack.DKDMI-QO.d.mts → stack.QD1y_7NY.d.cts} +7 -1
- package/dist/shared/{stack.DKDMI-QO.d.ts → stack.QD1y_7NY.d.mts} +7 -1
- package/dist/shared/{stack.DKDMI-QO.d.cts → stack.QD1y_7NY.d.ts} +7 -1
- package/package.json +1 -1
- package/src/__tests__/stack-api.test.ts +118 -0
- package/src/api/index.ts +15 -1
- package/src/plugins/ai-chat/__tests__/getters.test.ts +109 -0
- package/src/plugins/ai-chat/api/getters.ts +71 -0
- package/src/plugins/ai-chat/api/index.ts +1 -0
- package/src/plugins/ai-chat/api/plugin.ts +8 -0
- package/src/plugins/api/index.ts +3 -1
- package/src/plugins/blog/__tests__/getters.test.ts +540 -0
- package/src/plugins/blog/api/getters.ts +243 -0
- package/src/plugins/blog/api/index.ts +7 -0
- package/src/plugins/blog/api/plugin.ts +13 -141
- package/src/plugins/blog/client/plugin.tsx +2 -1
- package/src/plugins/blog/query-keys.ts +16 -13
- package/src/plugins/cms/__tests__/getters.test.ts +206 -0
- package/src/plugins/cms/api/getters.ts +244 -0
- package/src/plugins/cms/api/index.ts +5 -0
- package/src/plugins/cms/api/plugin.ts +50 -154
- package/src/plugins/cms/client/components/pages/content-editor-page.internal.tsx +1 -1
- package/src/plugins/cms/client/hooks/cms-hooks.tsx +3 -0
- package/src/plugins/cms/types.ts +1 -1
- package/src/plugins/form-builder/__tests__/getters.test.ts +159 -0
- package/src/plugins/form-builder/api/getters.ts +203 -0
- package/src/plugins/form-builder/api/index.ts +1 -0
- package/src/plugins/form-builder/api/plugin.ts +22 -115
- package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +1 -1
- package/src/plugins/form-builder/types.ts +2 -2
- package/src/plugins/kanban/__tests__/getters.test.ts +172 -0
- package/src/plugins/kanban/api/getters.ts +149 -0
- package/src/plugins/kanban/api/index.ts +1 -0
- package/src/plugins/kanban/api/plugin.ts +16 -146
- package/src/plugins/kanban/client/plugin.tsx +2 -1
- package/src/plugins/kanban/query-keys.ts +8 -5
- package/src/types.ts +44 -5
- package/dist/shared/{stack.CbuN2zVV.d.cts → stack.BkYlUT_8.d.cts} +6 -6
- package/dist/shared/{stack.CbuN2zVV.d.mts → stack.BkYlUT_8.d.mts} +6 -6
- package/dist/shared/{stack.CbuN2zVV.d.ts → stack.BkYlUT_8.d.ts} +6 -6
package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.cjs
CHANGED
|
@@ -136,7 +136,7 @@ function ContentEditorPage({ typeSlug, id }) {
|
|
|
136
136
|
contentForm.ContentForm,
|
|
137
137
|
{
|
|
138
138
|
contentType,
|
|
139
|
-
initialData: isEditing ? item?.parsedData : Object.keys(prefillParams).length > 0 ? convertPrefillToFormData(
|
|
139
|
+
initialData: isEditing ? item?.parsedData ?? void 0 : Object.keys(prefillParams).length > 0 ? convertPrefillToFormData(
|
|
140
140
|
prefillParams,
|
|
141
141
|
JSON.parse(contentType.jsonSchema)
|
|
142
142
|
) : void 0,
|
package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.mjs
CHANGED
|
@@ -134,7 +134,7 @@ function ContentEditorPage({ typeSlug, id }) {
|
|
|
134
134
|
ContentForm,
|
|
135
135
|
{
|
|
136
136
|
contentType,
|
|
137
|
-
initialData: isEditing ? item?.parsedData : Object.keys(prefillParams).length > 0 ? convertPrefillToFormData(
|
|
137
|
+
initialData: isEditing ? item?.parsedData ?? void 0 : Object.keys(prefillParams).length > 0 ? convertPrefillToFormData(
|
|
138
138
|
prefillParams,
|
|
139
139
|
JSON.parse(contentType.jsonSchema)
|
|
140
140
|
) : void 0,
|
|
@@ -305,10 +305,12 @@ function useCreateContent(typeSlug) {
|
|
|
305
305
|
},
|
|
306
306
|
onSuccess: async () => {
|
|
307
307
|
await queryClient.invalidateQueries({
|
|
308
|
-
queryKey: queries.cmsContent.list._def
|
|
308
|
+
queryKey: queries.cmsContent.list._def,
|
|
309
|
+
refetchType: "all"
|
|
309
310
|
});
|
|
310
311
|
await queryClient.invalidateQueries({
|
|
311
|
-
queryKey: queries.cmsTypes.list._def
|
|
312
|
+
queryKey: queries.cmsTypes.list._def,
|
|
313
|
+
refetchType: "all"
|
|
312
314
|
});
|
|
313
315
|
if (refresh) {
|
|
314
316
|
await refresh();
|
|
@@ -346,7 +348,8 @@ function useUpdateContent(typeSlug) {
|
|
|
346
348
|
);
|
|
347
349
|
}
|
|
348
350
|
await queryClient.invalidateQueries({
|
|
349
|
-
queryKey: queries.cmsContent.list._def
|
|
351
|
+
queryKey: queries.cmsContent.list._def,
|
|
352
|
+
refetchType: "all"
|
|
350
353
|
});
|
|
351
354
|
if (refresh) {
|
|
352
355
|
await refresh();
|
|
@@ -303,10 +303,12 @@ function useCreateContent(typeSlug) {
|
|
|
303
303
|
},
|
|
304
304
|
onSuccess: async () => {
|
|
305
305
|
await queryClient.invalidateQueries({
|
|
306
|
-
queryKey: queries.cmsContent.list._def
|
|
306
|
+
queryKey: queries.cmsContent.list._def,
|
|
307
|
+
refetchType: "all"
|
|
307
308
|
});
|
|
308
309
|
await queryClient.invalidateQueries({
|
|
309
|
-
queryKey: queries.cmsTypes.list._def
|
|
310
|
+
queryKey: queries.cmsTypes.list._def,
|
|
311
|
+
refetchType: "all"
|
|
310
312
|
});
|
|
311
313
|
if (refresh) {
|
|
312
314
|
await refresh();
|
|
@@ -344,7 +346,8 @@ function useUpdateContent(typeSlug) {
|
|
|
344
346
|
);
|
|
345
347
|
}
|
|
346
348
|
await queryClient.invalidateQueries({
|
|
347
|
-
queryKey: queries.cmsContent.list._def
|
|
349
|
+
queryKey: queries.cmsContent.list._def,
|
|
350
|
+
refetchType: "all"
|
|
348
351
|
});
|
|
349
352
|
if (refresh) {
|
|
350
353
|
await refresh();
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function serializeForm(form) {
|
|
4
|
+
return {
|
|
5
|
+
id: form.id,
|
|
6
|
+
name: form.name,
|
|
7
|
+
slug: form.slug,
|
|
8
|
+
description: form.description,
|
|
9
|
+
schema: form.schema,
|
|
10
|
+
successMessage: form.successMessage,
|
|
11
|
+
redirectUrl: form.redirectUrl,
|
|
12
|
+
status: form.status,
|
|
13
|
+
createdBy: form.createdBy,
|
|
14
|
+
createdAt: form.createdAt.toISOString(),
|
|
15
|
+
updatedAt: form.updatedAt.toISOString()
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function serializeFormSubmission(submission) {
|
|
19
|
+
return {
|
|
20
|
+
...submission,
|
|
21
|
+
submittedAt: submission.submittedAt.toISOString()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function serializeFormSubmissionWithData(submission) {
|
|
25
|
+
let parsedData = null;
|
|
26
|
+
try {
|
|
27
|
+
parsedData = JSON.parse(submission.data);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...serializeFormSubmission(submission),
|
|
32
|
+
parsedData,
|
|
33
|
+
form: submission.form ? serializeForm(submission.form) : void 0
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function getAllForms(adapter, params) {
|
|
37
|
+
const whereConditions = [];
|
|
38
|
+
if (params?.status) {
|
|
39
|
+
whereConditions.push({
|
|
40
|
+
field: "status",
|
|
41
|
+
value: params.status,
|
|
42
|
+
operator: "eq"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const total = await adapter.count({
|
|
46
|
+
model: "form",
|
|
47
|
+
where: whereConditions.length > 0 ? whereConditions : void 0
|
|
48
|
+
});
|
|
49
|
+
const forms = await adapter.findMany({
|
|
50
|
+
model: "form",
|
|
51
|
+
where: whereConditions.length > 0 ? whereConditions : void 0,
|
|
52
|
+
limit: params?.limit,
|
|
53
|
+
offset: params?.offset,
|
|
54
|
+
sortBy: { field: "createdAt", direction: "desc" }
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
items: forms.map(serializeForm),
|
|
58
|
+
total,
|
|
59
|
+
limit: params?.limit,
|
|
60
|
+
offset: params?.offset
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function getFormBySlug(adapter, slug) {
|
|
64
|
+
const form = await adapter.findOne({
|
|
65
|
+
model: "form",
|
|
66
|
+
where: [{ field: "slug", value: slug, operator: "eq" }]
|
|
67
|
+
});
|
|
68
|
+
if (!form) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return serializeForm(form);
|
|
72
|
+
}
|
|
73
|
+
async function getFormSubmissions(adapter, formId, params) {
|
|
74
|
+
const form = await adapter.findOne({
|
|
75
|
+
model: "form",
|
|
76
|
+
where: [{ field: "id", value: formId, operator: "eq" }]
|
|
77
|
+
});
|
|
78
|
+
if (!form) {
|
|
79
|
+
return {
|
|
80
|
+
items: [],
|
|
81
|
+
total: 0,
|
|
82
|
+
limit: params?.limit,
|
|
83
|
+
offset: params?.offset
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const total = await adapter.count({
|
|
87
|
+
model: "formSubmission",
|
|
88
|
+
where: [{ field: "formId", value: formId, operator: "eq" }]
|
|
89
|
+
});
|
|
90
|
+
const submissions = await adapter.findMany({
|
|
91
|
+
model: "formSubmission",
|
|
92
|
+
where: [{ field: "formId", value: formId, operator: "eq" }],
|
|
93
|
+
limit: params?.limit,
|
|
94
|
+
offset: params?.offset,
|
|
95
|
+
sortBy: { field: "submittedAt", direction: "desc" },
|
|
96
|
+
join: { form: true }
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
items: submissions.map(serializeFormSubmissionWithData),
|
|
100
|
+
total,
|
|
101
|
+
limit: params?.limit,
|
|
102
|
+
offset: params?.offset
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.getAllForms = getAllForms;
|
|
107
|
+
exports.getFormBySlug = getFormBySlug;
|
|
108
|
+
exports.getFormSubmissions = getFormSubmissions;
|
|
109
|
+
exports.serializeForm = serializeForm;
|
|
110
|
+
exports.serializeFormSubmission = serializeFormSubmission;
|
|
111
|
+
exports.serializeFormSubmissionWithData = serializeFormSubmissionWithData;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function serializeForm(form) {
|
|
2
|
+
return {
|
|
3
|
+
id: form.id,
|
|
4
|
+
name: form.name,
|
|
5
|
+
slug: form.slug,
|
|
6
|
+
description: form.description,
|
|
7
|
+
schema: form.schema,
|
|
8
|
+
successMessage: form.successMessage,
|
|
9
|
+
redirectUrl: form.redirectUrl,
|
|
10
|
+
status: form.status,
|
|
11
|
+
createdBy: form.createdBy,
|
|
12
|
+
createdAt: form.createdAt.toISOString(),
|
|
13
|
+
updatedAt: form.updatedAt.toISOString()
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function serializeFormSubmission(submission) {
|
|
17
|
+
return {
|
|
18
|
+
...submission,
|
|
19
|
+
submittedAt: submission.submittedAt.toISOString()
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function serializeFormSubmissionWithData(submission) {
|
|
23
|
+
let parsedData = null;
|
|
24
|
+
try {
|
|
25
|
+
parsedData = JSON.parse(submission.data);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
...serializeFormSubmission(submission),
|
|
30
|
+
parsedData,
|
|
31
|
+
form: submission.form ? serializeForm(submission.form) : void 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function getAllForms(adapter, params) {
|
|
35
|
+
const whereConditions = [];
|
|
36
|
+
if (params?.status) {
|
|
37
|
+
whereConditions.push({
|
|
38
|
+
field: "status",
|
|
39
|
+
value: params.status,
|
|
40
|
+
operator: "eq"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const total = await adapter.count({
|
|
44
|
+
model: "form",
|
|
45
|
+
where: whereConditions.length > 0 ? whereConditions : void 0
|
|
46
|
+
});
|
|
47
|
+
const forms = await adapter.findMany({
|
|
48
|
+
model: "form",
|
|
49
|
+
where: whereConditions.length > 0 ? whereConditions : void 0,
|
|
50
|
+
limit: params?.limit,
|
|
51
|
+
offset: params?.offset,
|
|
52
|
+
sortBy: { field: "createdAt", direction: "desc" }
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
items: forms.map(serializeForm),
|
|
56
|
+
total,
|
|
57
|
+
limit: params?.limit,
|
|
58
|
+
offset: params?.offset
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function getFormBySlug(adapter, slug) {
|
|
62
|
+
const form = await adapter.findOne({
|
|
63
|
+
model: "form",
|
|
64
|
+
where: [{ field: "slug", value: slug, operator: "eq" }]
|
|
65
|
+
});
|
|
66
|
+
if (!form) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return serializeForm(form);
|
|
70
|
+
}
|
|
71
|
+
async function getFormSubmissions(adapter, formId, params) {
|
|
72
|
+
const form = await adapter.findOne({
|
|
73
|
+
model: "form",
|
|
74
|
+
where: [{ field: "id", value: formId, operator: "eq" }]
|
|
75
|
+
});
|
|
76
|
+
if (!form) {
|
|
77
|
+
return {
|
|
78
|
+
items: [],
|
|
79
|
+
total: 0,
|
|
80
|
+
limit: params?.limit,
|
|
81
|
+
offset: params?.offset
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const total = await adapter.count({
|
|
85
|
+
model: "formSubmission",
|
|
86
|
+
where: [{ field: "formId", value: formId, operator: "eq" }]
|
|
87
|
+
});
|
|
88
|
+
const submissions = await adapter.findMany({
|
|
89
|
+
model: "formSubmission",
|
|
90
|
+
where: [{ field: "formId", value: formId, operator: "eq" }],
|
|
91
|
+
limit: params?.limit,
|
|
92
|
+
offset: params?.offset,
|
|
93
|
+
sortBy: { field: "submittedAt", direction: "desc" },
|
|
94
|
+
join: { form: true }
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
items: submissions.map(serializeFormSubmissionWithData),
|
|
98
|
+
total,
|
|
99
|
+
limit: params?.limit,
|
|
100
|
+
offset: params?.offset
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { getAllForms, getFormBySlug, getFormSubmissions, serializeForm, serializeFormSubmission, serializeFormSubmissionWithData };
|
|
@@ -6,38 +6,16 @@ const schemaConverter = require('../../../../../ui/src/lib/schema-converter.cjs'
|
|
|
6
6
|
const db = require('../db.cjs');
|
|
7
7
|
const schemas = require('../schemas.cjs');
|
|
8
8
|
const utils = require('../utils.cjs');
|
|
9
|
+
const getters = require('./getters.cjs');
|
|
9
10
|
|
|
10
|
-
function serializeForm(form) {
|
|
11
|
-
return {
|
|
12
|
-
id: form.id,
|
|
13
|
-
name: form.name,
|
|
14
|
-
slug: form.slug,
|
|
15
|
-
description: form.description,
|
|
16
|
-
schema: form.schema,
|
|
17
|
-
successMessage: form.successMessage,
|
|
18
|
-
redirectUrl: form.redirectUrl,
|
|
19
|
-
status: form.status,
|
|
20
|
-
createdBy: form.createdBy,
|
|
21
|
-
createdAt: form.createdAt.toISOString(),
|
|
22
|
-
updatedAt: form.updatedAt.toISOString()
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function serializeFormSubmission(submission) {
|
|
26
|
-
return {
|
|
27
|
-
...submission,
|
|
28
|
-
submittedAt: submission.submittedAt.toISOString()
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function serializeFormSubmissionWithData(submission) {
|
|
32
|
-
return {
|
|
33
|
-
...serializeFormSubmission(submission),
|
|
34
|
-
parsedData: JSON.parse(submission.data),
|
|
35
|
-
form: submission.form ? serializeForm(submission.form) : void 0
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
11
|
const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
39
12
|
name: "form-builder",
|
|
40
13
|
dbPlugin: db.formBuilderSchema,
|
|
14
|
+
api: (adapter) => ({
|
|
15
|
+
getAllForms: (params) => getters.getAllForms(adapter, params),
|
|
16
|
+
getFormBySlug: (slug) => getters.getFormBySlug(adapter, slug),
|
|
17
|
+
getFormSubmissions: (formId, params) => getters.getFormSubmissions(adapter, formId, params)
|
|
18
|
+
}),
|
|
41
19
|
routes: (adapter) => {
|
|
42
20
|
const createContext = (headers) => ({
|
|
43
21
|
headers,
|
|
@@ -64,32 +42,7 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
64
42
|
throw ctx.error(403, { message: "Access denied" });
|
|
65
43
|
}
|
|
66
44
|
}
|
|
67
|
-
|
|
68
|
-
if (status) {
|
|
69
|
-
whereConditions.push({
|
|
70
|
-
field: "status",
|
|
71
|
-
value: status,
|
|
72
|
-
operator: "eq"
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
const allForms = await adapter.findMany({
|
|
76
|
-
model: "form",
|
|
77
|
-
where: whereConditions.length > 0 ? whereConditions : void 0
|
|
78
|
-
});
|
|
79
|
-
const total = allForms.length;
|
|
80
|
-
const forms = await adapter.findMany({
|
|
81
|
-
model: "form",
|
|
82
|
-
where: whereConditions.length > 0 ? whereConditions : void 0,
|
|
83
|
-
limit,
|
|
84
|
-
offset,
|
|
85
|
-
sortBy: { field: "createdAt", direction: "desc" }
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
items: forms.map(serializeForm),
|
|
89
|
-
total,
|
|
90
|
-
limit,
|
|
91
|
-
offset
|
|
92
|
-
};
|
|
45
|
+
return getters.getAllForms(adapter, { status, limit, offset });
|
|
93
46
|
}
|
|
94
47
|
);
|
|
95
48
|
const getFormBySlug = api.createEndpoint(
|
|
@@ -107,14 +60,11 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
107
60
|
throw ctx.error(403, { message: "Access denied" });
|
|
108
61
|
}
|
|
109
62
|
}
|
|
110
|
-
const form = await
|
|
111
|
-
model: "form",
|
|
112
|
-
where: [{ field: "slug", value: slug, operator: "eq" }]
|
|
113
|
-
});
|
|
63
|
+
const form = await getters.getFormBySlug(adapter, slug);
|
|
114
64
|
if (!form) {
|
|
115
65
|
throw ctx.error(404, { message: "Form not found" });
|
|
116
66
|
}
|
|
117
|
-
return
|
|
67
|
+
return form;
|
|
118
68
|
}
|
|
119
69
|
);
|
|
120
70
|
const getFormById = api.createEndpoint(
|
|
@@ -139,7 +89,7 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
139
89
|
if (!form) {
|
|
140
90
|
throw ctx.error(404, { message: "Form not found" });
|
|
141
91
|
}
|
|
142
|
-
return serializeForm(form);
|
|
92
|
+
return getters.serializeForm(form);
|
|
143
93
|
}
|
|
144
94
|
);
|
|
145
95
|
const createForm = api.createEndpoint(
|
|
@@ -207,7 +157,7 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
207
157
|
updatedAt: /* @__PURE__ */ new Date()
|
|
208
158
|
}
|
|
209
159
|
});
|
|
210
|
-
const serialized = serializeForm(form);
|
|
160
|
+
const serialized = getters.serializeForm(form);
|
|
211
161
|
if (config.hooks?.onAfterFormCreated) {
|
|
212
162
|
await config.hooks.onAfterFormCreated(serialized, context);
|
|
213
163
|
}
|
|
@@ -308,7 +258,7 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
308
258
|
if (!updated) {
|
|
309
259
|
throw ctx.error(500, { message: "Failed to fetch updated form" });
|
|
310
260
|
}
|
|
311
|
-
const serialized = serializeForm(updated);
|
|
261
|
+
const serialized = getters.serializeForm(updated);
|
|
312
262
|
if (config.hooks?.onAfterFormUpdated) {
|
|
313
263
|
await config.hooks.onAfterFormUpdated(serialized, context);
|
|
314
264
|
}
|
|
@@ -437,11 +387,11 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
437
387
|
userAgent: baseContext.userAgent
|
|
438
388
|
}
|
|
439
389
|
});
|
|
440
|
-
const serialized = serializeFormSubmission(submission);
|
|
390
|
+
const serialized = getters.serializeFormSubmission(submission);
|
|
441
391
|
if (config.hooks?.onAfterSubmission) {
|
|
442
392
|
await config.hooks.onAfterSubmission(
|
|
443
393
|
serialized,
|
|
444
|
-
serializeForm(form),
|
|
394
|
+
getters.serializeForm(form),
|
|
445
395
|
submissionContext
|
|
446
396
|
);
|
|
447
397
|
}
|
|
@@ -481,29 +431,7 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
481
431
|
throw ctx.error(403, { message: "Access denied" });
|
|
482
432
|
}
|
|
483
433
|
}
|
|
484
|
-
|
|
485
|
-
model: "formSubmission",
|
|
486
|
-
where: [
|
|
487
|
-
{ field: "formId", value: formId, operator: "eq" }
|
|
488
|
-
]
|
|
489
|
-
});
|
|
490
|
-
const total = allSubmissions.length;
|
|
491
|
-
const submissions = await adapter.findMany({
|
|
492
|
-
model: "formSubmission",
|
|
493
|
-
where: [
|
|
494
|
-
{ field: "formId", value: formId, operator: "eq" }
|
|
495
|
-
],
|
|
496
|
-
limit,
|
|
497
|
-
offset,
|
|
498
|
-
sortBy: { field: "submittedAt", direction: "desc" },
|
|
499
|
-
join: { form: true }
|
|
500
|
-
});
|
|
501
|
-
return {
|
|
502
|
-
items: submissions.map(serializeFormSubmissionWithData),
|
|
503
|
-
total,
|
|
504
|
-
limit,
|
|
505
|
-
offset
|
|
506
|
-
};
|
|
434
|
+
return getters.getFormSubmissions(adapter, formId, { limit, offset });
|
|
507
435
|
}
|
|
508
436
|
);
|
|
509
437
|
const getSubmission = api.createEndpoint(
|
|
@@ -532,7 +460,7 @@ const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
|
|
|
532
460
|
if (!submission || submission.formId !== formId) {
|
|
533
461
|
throw ctx.error(404, { message: "Submission not found" });
|
|
534
462
|
}
|
|
535
|
-
return serializeFormSubmissionWithData(submission);
|
|
463
|
+
return getters.serializeFormSubmissionWithData(submission);
|
|
536
464
|
}
|
|
537
465
|
);
|
|
538
466
|
const deleteSubmission = api.createEndpoint(
|
|
@@ -4,38 +4,16 @@ import { formSchemaToZod } from '../../../../../ui/src/lib/schema-converter.mjs'
|
|
|
4
4
|
import { formBuilderSchema } from '../db.mjs';
|
|
5
5
|
import { listFormsQuerySchema, createFormSchema, updateFormSchema, listSubmissionsQuerySchema } from '../schemas.mjs';
|
|
6
6
|
import { extractUserAgent, extractIpAddress, slugify } from '../utils.mjs';
|
|
7
|
+
import { getFormSubmissions, getFormBySlug, getAllForms, serializeForm, serializeFormSubmission, serializeFormSubmissionWithData } from './getters.mjs';
|
|
7
8
|
|
|
8
|
-
function serializeForm(form) {
|
|
9
|
-
return {
|
|
10
|
-
id: form.id,
|
|
11
|
-
name: form.name,
|
|
12
|
-
slug: form.slug,
|
|
13
|
-
description: form.description,
|
|
14
|
-
schema: form.schema,
|
|
15
|
-
successMessage: form.successMessage,
|
|
16
|
-
redirectUrl: form.redirectUrl,
|
|
17
|
-
status: form.status,
|
|
18
|
-
createdBy: form.createdBy,
|
|
19
|
-
createdAt: form.createdAt.toISOString(),
|
|
20
|
-
updatedAt: form.updatedAt.toISOString()
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function serializeFormSubmission(submission) {
|
|
24
|
-
return {
|
|
25
|
-
...submission,
|
|
26
|
-
submittedAt: submission.submittedAt.toISOString()
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function serializeFormSubmissionWithData(submission) {
|
|
30
|
-
return {
|
|
31
|
-
...serializeFormSubmission(submission),
|
|
32
|
-
parsedData: JSON.parse(submission.data),
|
|
33
|
-
form: submission.form ? serializeForm(submission.form) : void 0
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
9
|
const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
|
|
37
10
|
name: "form-builder",
|
|
38
11
|
dbPlugin: formBuilderSchema,
|
|
12
|
+
api: (adapter) => ({
|
|
13
|
+
getAllForms: (params) => getAllForms(adapter, params),
|
|
14
|
+
getFormBySlug: (slug) => getFormBySlug(adapter, slug),
|
|
15
|
+
getFormSubmissions: (formId, params) => getFormSubmissions(adapter, formId, params)
|
|
16
|
+
}),
|
|
39
17
|
routes: (adapter) => {
|
|
40
18
|
const createContext = (headers) => ({
|
|
41
19
|
headers,
|
|
@@ -62,35 +40,10 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
|
|
|
62
40
|
throw ctx.error(403, { message: "Access denied" });
|
|
63
41
|
}
|
|
64
42
|
}
|
|
65
|
-
|
|
66
|
-
if (status) {
|
|
67
|
-
whereConditions.push({
|
|
68
|
-
field: "status",
|
|
69
|
-
value: status,
|
|
70
|
-
operator: "eq"
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
const allForms = await adapter.findMany({
|
|
74
|
-
model: "form",
|
|
75
|
-
where: whereConditions.length > 0 ? whereConditions : void 0
|
|
76
|
-
});
|
|
77
|
-
const total = allForms.length;
|
|
78
|
-
const forms = await adapter.findMany({
|
|
79
|
-
model: "form",
|
|
80
|
-
where: whereConditions.length > 0 ? whereConditions : void 0,
|
|
81
|
-
limit,
|
|
82
|
-
offset,
|
|
83
|
-
sortBy: { field: "createdAt", direction: "desc" }
|
|
84
|
-
});
|
|
85
|
-
return {
|
|
86
|
-
items: forms.map(serializeForm),
|
|
87
|
-
total,
|
|
88
|
-
limit,
|
|
89
|
-
offset
|
|
90
|
-
};
|
|
43
|
+
return getAllForms(adapter, { status, limit, offset });
|
|
91
44
|
}
|
|
92
45
|
);
|
|
93
|
-
const getFormBySlug = createEndpoint(
|
|
46
|
+
const getFormBySlug$1 = createEndpoint(
|
|
94
47
|
"/forms/:slug",
|
|
95
48
|
{
|
|
96
49
|
method: "GET",
|
|
@@ -105,14 +58,11 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
|
|
|
105
58
|
throw ctx.error(403, { message: "Access denied" });
|
|
106
59
|
}
|
|
107
60
|
}
|
|
108
|
-
const form = await adapter
|
|
109
|
-
model: "form",
|
|
110
|
-
where: [{ field: "slug", value: slug, operator: "eq" }]
|
|
111
|
-
});
|
|
61
|
+
const form = await getFormBySlug(adapter, slug);
|
|
112
62
|
if (!form) {
|
|
113
63
|
throw ctx.error(404, { message: "Form not found" });
|
|
114
64
|
}
|
|
115
|
-
return
|
|
65
|
+
return form;
|
|
116
66
|
}
|
|
117
67
|
);
|
|
118
68
|
const getFormById = createEndpoint(
|
|
@@ -479,29 +429,7 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
|
|
|
479
429
|
throw ctx.error(403, { message: "Access denied" });
|
|
480
430
|
}
|
|
481
431
|
}
|
|
482
|
-
|
|
483
|
-
model: "formSubmission",
|
|
484
|
-
where: [
|
|
485
|
-
{ field: "formId", value: formId, operator: "eq" }
|
|
486
|
-
]
|
|
487
|
-
});
|
|
488
|
-
const total = allSubmissions.length;
|
|
489
|
-
const submissions = await adapter.findMany({
|
|
490
|
-
model: "formSubmission",
|
|
491
|
-
where: [
|
|
492
|
-
{ field: "formId", value: formId, operator: "eq" }
|
|
493
|
-
],
|
|
494
|
-
limit,
|
|
495
|
-
offset,
|
|
496
|
-
sortBy: { field: "submittedAt", direction: "desc" },
|
|
497
|
-
join: { form: true }
|
|
498
|
-
});
|
|
499
|
-
return {
|
|
500
|
-
items: submissions.map(serializeFormSubmissionWithData),
|
|
501
|
-
total,
|
|
502
|
-
limit,
|
|
503
|
-
offset
|
|
504
|
-
};
|
|
432
|
+
return getFormSubmissions(adapter, formId, { limit, offset });
|
|
505
433
|
}
|
|
506
434
|
);
|
|
507
435
|
const getSubmission = createEndpoint(
|
|
@@ -570,7 +498,7 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
|
|
|
570
498
|
);
|
|
571
499
|
return {
|
|
572
500
|
listForms,
|
|
573
|
-
getFormBySlug,
|
|
501
|
+
getFormBySlug: getFormBySlug$1,
|
|
574
502
|
getFormById,
|
|
575
503
|
createForm,
|
|
576
504
|
updateForm,
|
|
@@ -76,7 +76,7 @@ function SubmissionsPage({ formId }) {
|
|
|
76
76
|
sub.id.slice(0, 8),
|
|
77
77
|
"..."
|
|
78
78
|
] }),
|
|
79
|
-
/* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData) }),
|
|
79
|
+
/* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData ?? {}) }),
|
|
80
80
|
/* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "text-muted-foreground", children: new Date(sub.submittedAt).toLocaleString() }),
|
|
81
81
|
/* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "text-muted-foreground font-mono text-xs", children: sub.ipAddress || "-" }),
|
|
82
82
|
/* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-1", children: [
|
|
@@ -74,7 +74,7 @@ function SubmissionsPage({ formId }) {
|
|
|
74
74
|
sub.id.slice(0, 8),
|
|
75
75
|
"..."
|
|
76
76
|
] }),
|
|
77
|
-
/* @__PURE__ */ jsx(TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData) }),
|
|
77
|
+
/* @__PURE__ */ jsx(TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData ?? {}) }),
|
|
78
78
|
/* @__PURE__ */ jsx(TableCell, { className: "text-muted-foreground", children: new Date(sub.submittedAt).toLocaleString() }),
|
|
79
79
|
/* @__PURE__ */ jsx(TableCell, { className: "text-muted-foreground font-mono text-xs", children: sub.ipAddress || "-" }),
|
|
80
80
|
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex gap-1", children: [
|