@btst/plugin-form-builder 0.0.0-stage → 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.
Files changed (213) hide show
  1. package/LICENSE.md +17 -0
  2. package/dist/api/getters.cjs +154 -0
  3. package/dist/api/getters.mjs +145 -0
  4. package/dist/api/index.cjs +25 -0
  5. package/dist/api/index.d.cts +119 -0
  6. package/dist/api/index.d.mts +119 -0
  7. package/dist/api/index.d.ts +119 -0
  8. package/dist/api/index.mjs +6 -0
  9. package/dist/api/lifecycle-migrations.cjs +15 -0
  10. package/dist/api/lifecycle-migrations.mjs +13 -0
  11. package/dist/api/operations.cjs +1093 -0
  12. package/dist/api/operations.mjs +1082 -0
  13. package/dist/api/plugin.cjs +201 -0
  14. package/dist/api/plugin.mjs +192 -0
  15. package/dist/api/query-key-defs.cjs +43 -0
  16. package/dist/api/query-key-defs.mjs +39 -0
  17. package/dist/client/components/forms/form-renderer.cjs +193 -0
  18. package/dist/client/components/forms/form-renderer.mjs +191 -0
  19. package/dist/client/components/index.cjs +29 -0
  20. package/dist/client/components/index.d.cts +97 -0
  21. package/dist/client/components/index.d.mts +97 -0
  22. package/dist/client/components/index.d.ts +97 -0
  23. package/dist/client/components/index.mjs +18 -0
  24. package/dist/client/components/loading/form-builder-skeleton.cjs +32 -0
  25. package/dist/client/components/loading/form-builder-skeleton.mjs +30 -0
  26. package/dist/client/components/loading/form-list-skeleton.cjs +21 -0
  27. package/dist/client/components/loading/form-list-skeleton.mjs +19 -0
  28. package/dist/client/components/loading/submissions-skeleton.cjs +34 -0
  29. package/dist/client/components/loading/submissions-skeleton.mjs +32 -0
  30. package/dist/client/components/pages/404-page.cjs +28 -0
  31. package/dist/client/components/pages/404-page.mjs +26 -0
  32. package/dist/client/components/pages/form-builder-page.cjs +77 -0
  33. package/dist/client/components/pages/form-builder-page.internal.cjs +217 -0
  34. package/dist/client/components/pages/form-builder-page.internal.mjs +215 -0
  35. package/dist/client/components/pages/form-builder-page.mjs +75 -0
  36. package/dist/client/components/pages/form-list-page.cjs +44 -0
  37. package/dist/client/components/pages/form-list-page.internal.cjs +282 -0
  38. package/dist/client/components/pages/form-list-page.internal.mjs +280 -0
  39. package/dist/client/components/pages/form-list-page.mjs +42 -0
  40. package/dist/client/components/pages/submissions-page.cjs +64 -0
  41. package/dist/client/components/pages/submissions-page.internal.cjs +255 -0
  42. package/dist/client/components/pages/submissions-page.internal.mjs +253 -0
  43. package/dist/client/components/pages/submissions-page.mjs +62 -0
  44. package/dist/client/components/shared/default-error.cjs +17 -0
  45. package/dist/client/components/shared/default-error.mjs +15 -0
  46. package/dist/client/components/shared/empty-state.cjs +16 -0
  47. package/dist/client/components/shared/empty-state.mjs +14 -0
  48. package/dist/client/components/shared/page-wrapper.cjs +29 -0
  49. package/dist/client/components/shared/page-wrapper.mjs +27 -0
  50. package/dist/client/components/shared/pagination.cjs +49 -0
  51. package/dist/client/components/shared/pagination.mjs +47 -0
  52. package/dist/client/constants.cjs +5 -0
  53. package/dist/client/constants.mjs +3 -0
  54. package/dist/client/hooks/form-builder-hooks.cjs +203 -0
  55. package/dist/client/hooks/form-builder-hooks.mjs +186 -0
  56. package/dist/client/hooks/form-builder-resource.cjs +13 -0
  57. package/dist/client/hooks/form-builder-resource.mjs +11 -0
  58. package/dist/client/hooks/index.cjs +22 -0
  59. package/dist/client/hooks/index.d.cts +378 -0
  60. package/dist/client/hooks/index.d.mts +378 -0
  61. package/dist/client/hooks/index.d.ts +378 -0
  62. package/dist/client/hooks/index.mjs +1 -0
  63. package/dist/client/index.cjs +13 -0
  64. package/dist/client/index.d.cts +410 -0
  65. package/dist/client/index.d.mts +410 -0
  66. package/dist/client/index.d.ts +410 -0
  67. package/dist/client/index.mjs +2 -0
  68. package/dist/client/plugin.cjs +311 -0
  69. package/dist/client/plugin.mjs +309 -0
  70. package/dist/client.css +3 -0
  71. package/dist/db.cjs +99 -0
  72. package/dist/db.mjs +97 -0
  73. package/dist/permissions.cjs +95 -0
  74. package/dist/permissions.d.cts +94 -0
  75. package/dist/permissions.d.mts +94 -0
  76. package/dist/permissions.d.ts +94 -0
  77. package/dist/permissions.mjs +93 -0
  78. package/dist/query-keys.cjs +140 -0
  79. package/dist/query-keys.d.cts +392 -0
  80. package/dist/query-keys.d.mts +392 -0
  81. package/dist/query-keys.d.ts +392 -0
  82. package/dist/query-keys.mjs +137 -0
  83. package/dist/schemas.cjs +91 -0
  84. package/dist/schemas.mjs +82 -0
  85. package/dist/shared/plugin-form-builder.BZYGyFgT.d.mts +351 -0
  86. package/dist/shared/plugin-form-builder.Bbl9NufB.d.cts +408 -0
  87. package/dist/shared/plugin-form-builder.CSP5HR2O.d.ts +408 -0
  88. package/dist/shared/plugin-form-builder.Cmk083dA.d.cts +351 -0
  89. package/dist/shared/plugin-form-builder.D258Qpb8.d.ts +351 -0
  90. package/dist/shared/plugin-form-builder.DWrQ3lRX.d.cts +118 -0
  91. package/dist/shared/plugin-form-builder.DWrQ3lRX.d.mts +118 -0
  92. package/dist/shared/plugin-form-builder.DWrQ3lRX.d.ts +118 -0
  93. package/dist/shared/plugin-form-builder.lp98rFNl.d.mts +408 -0
  94. package/dist/style.css +6 -0
  95. package/dist/types.cjs +2 -0
  96. package/dist/types.d.cts +6 -0
  97. package/dist/types.d.mts +6 -0
  98. package/dist/types.d.ts +6 -0
  99. package/dist/types.mjs +1 -0
  100. package/dist/ui/src/components/accordion.cjs +81 -0
  101. package/dist/ui/src/components/accordion.mjs +62 -0
  102. package/dist/ui/src/components/alert-dialog.cjs +157 -0
  103. package/dist/ui/src/components/alert-dialog.mjs +132 -0
  104. package/dist/ui/src/components/auto-form/common/label.cjs +18 -0
  105. package/dist/ui/src/components/auto-form/common/label.mjs +16 -0
  106. package/dist/ui/src/components/auto-form/common/tooltip.cjs +9 -0
  107. package/dist/ui/src/components/auto-form/common/tooltip.mjs +7 -0
  108. package/dist/ui/src/components/auto-form/config.cjs +40 -0
  109. package/dist/ui/src/components/auto-form/config.mjs +37 -0
  110. package/dist/ui/src/components/auto-form/dependencies.cjs +48 -0
  111. package/dist/ui/src/components/auto-form/dependencies.mjs +46 -0
  112. package/dist/ui/src/components/auto-form/fields/array.cjs +266 -0
  113. package/dist/ui/src/components/auto-form/fields/array.mjs +264 -0
  114. package/dist/ui/src/components/auto-form/fields/checkbox.cjs +38 -0
  115. package/dist/ui/src/components/auto-form/fields/checkbox.mjs +36 -0
  116. package/dist/ui/src/components/auto-form/fields/date.cjs +67 -0
  117. package/dist/ui/src/components/auto-form/fields/date.mjs +65 -0
  118. package/dist/ui/src/components/auto-form/fields/enum.cjs +73 -0
  119. package/dist/ui/src/components/auto-form/fields/enum.mjs +71 -0
  120. package/dist/ui/src/components/auto-form/fields/input.cjs +32 -0
  121. package/dist/ui/src/components/auto-form/fields/input.mjs +30 -0
  122. package/dist/ui/src/components/auto-form/fields/number.cjs +31 -0
  123. package/dist/ui/src/components/auto-form/fields/number.mjs +29 -0
  124. package/dist/ui/src/components/auto-form/fields/object.cjs +233 -0
  125. package/dist/ui/src/components/auto-form/fields/object.mjs +217 -0
  126. package/dist/ui/src/components/auto-form/fields/radio-group.cjs +67 -0
  127. package/dist/ui/src/components/auto-form/fields/radio-group.mjs +65 -0
  128. package/dist/ui/src/components/auto-form/fields/switch.cjs +38 -0
  129. package/dist/ui/src/components/auto-form/fields/switch.mjs +36 -0
  130. package/dist/ui/src/components/auto-form/fields/textarea.cjs +31 -0
  131. package/dist/ui/src/components/auto-form/fields/textarea.mjs +29 -0
  132. package/dist/ui/src/components/auto-form/helpers.cjs +270 -0
  133. package/dist/ui/src/components/auto-form/helpers.mjs +259 -0
  134. package/dist/ui/src/components/auto-form/index.cjs +92 -0
  135. package/dist/ui/src/components/auto-form/index.mjs +86 -0
  136. package/dist/ui/src/components/auto-form/stepped-auto-form.cjs +374 -0
  137. package/dist/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
  138. package/dist/ui/src/components/auto-form/types.cjs +11 -0
  139. package/dist/ui/src/components/auto-form/types.mjs +9 -0
  140. package/dist/ui/src/components/button.cjs +56 -0
  141. package/dist/ui/src/components/button.mjs +53 -0
  142. package/dist/ui/src/components/calendar.cjs +207 -0
  143. package/dist/ui/src/components/calendar.mjs +190 -0
  144. package/dist/ui/src/components/checkbox.cjs +48 -0
  145. package/dist/ui/src/components/checkbox.mjs +32 -0
  146. package/dist/ui/src/components/date-picker.cjs +41 -0
  147. package/dist/ui/src/components/date-picker.mjs +39 -0
  148. package/dist/ui/src/components/dialog.cjs +141 -0
  149. package/dist/ui/src/components/dialog.mjs +118 -0
  150. package/dist/ui/src/components/dropdown-menu.cjs +81 -0
  151. package/dist/ui/src/components/dropdown-menu.mjs +62 -0
  152. package/dist/ui/src/components/form-builder/canvas.cjs +111 -0
  153. package/dist/ui/src/components/form-builder/canvas.mjs +109 -0
  154. package/dist/ui/src/components/form-builder/components/index.cjs +571 -0
  155. package/dist/ui/src/components/form-builder/components/index.mjs +554 -0
  156. package/dist/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
  157. package/dist/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
  158. package/dist/ui/src/components/form-builder/form-preview.cjs +73 -0
  159. package/dist/ui/src/components/form-builder/form-preview.mjs +71 -0
  160. package/dist/ui/src/components/form-builder/index.cjs +350 -0
  161. package/dist/ui/src/components/form-builder/index.mjs +344 -0
  162. package/dist/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
  163. package/dist/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
  164. package/dist/ui/src/components/form-builder/palette.cjs +52 -0
  165. package/dist/ui/src/components/form-builder/palette.mjs +49 -0
  166. package/dist/ui/src/components/form-builder/schema-utils.cjs +128 -0
  167. package/dist/ui/src/components/form-builder/schema-utils.mjs +122 -0
  168. package/dist/ui/src/components/form-builder/sortable-field.cjs +151 -0
  169. package/dist/ui/src/components/form-builder/sortable-field.mjs +148 -0
  170. package/dist/ui/src/components/form-builder/step-tabs.cjs +180 -0
  171. package/dist/ui/src/components/form-builder/step-tabs.mjs +178 -0
  172. package/dist/ui/src/components/form-builder/types.cjs +7 -0
  173. package/dist/ui/src/components/form-builder/types.mjs +5 -0
  174. package/dist/ui/src/components/form-builder/validation-schemas.cjs +67 -0
  175. package/dist/ui/src/components/form-builder/validation-schemas.mjs +56 -0
  176. package/dist/ui/src/components/form.cjs +120 -0
  177. package/dist/ui/src/components/form.mjs +98 -0
  178. package/dist/ui/src/components/input.cjs +23 -0
  179. package/dist/ui/src/components/input.mjs +21 -0
  180. package/dist/ui/src/components/label.cjs +39 -0
  181. package/dist/ui/src/components/label.mjs +23 -0
  182. package/dist/ui/src/components/page-layout.cjs +25 -0
  183. package/dist/ui/src/components/page-layout.mjs +23 -0
  184. package/dist/ui/src/components/page-wrapper.cjs +20 -0
  185. package/dist/ui/src/components/page-wrapper.mjs +18 -0
  186. package/dist/ui/src/components/popover.cjs +60 -0
  187. package/dist/ui/src/components/popover.mjs +42 -0
  188. package/dist/ui/src/components/radio-group.cjs +62 -0
  189. package/dist/ui/src/components/radio-group.mjs +45 -0
  190. package/dist/ui/src/components/select.cjs +161 -0
  191. package/dist/ui/src/components/select.mjs +139 -0
  192. package/dist/ui/src/components/separator.cjs +43 -0
  193. package/dist/ui/src/components/separator.mjs +27 -0
  194. package/dist/ui/src/components/skeleton.cjs +17 -0
  195. package/dist/ui/src/components/skeleton.mjs +15 -0
  196. package/dist/ui/src/components/stack-attribution.cjs +24 -0
  197. package/dist/ui/src/components/stack-attribution.mjs +22 -0
  198. package/dist/ui/src/components/switch.cjs +48 -0
  199. package/dist/ui/src/components/switch.mjs +32 -0
  200. package/dist/ui/src/components/table.cjs +89 -0
  201. package/dist/ui/src/components/table.mjs +82 -0
  202. package/dist/ui/src/components/tabs.cjs +84 -0
  203. package/dist/ui/src/components/tabs.mjs +65 -0
  204. package/dist/ui/src/components/textarea.cjs +20 -0
  205. package/dist/ui/src/components/textarea.mjs +18 -0
  206. package/dist/ui/src/lib/schema-converter.cjs +133 -0
  207. package/dist/ui/src/lib/schema-converter.mjs +127 -0
  208. package/dist/ui/src/lib/utils.cjs +10 -0
  209. package/dist/ui/src/lib/utils.mjs +8 -0
  210. package/dist/utils.cjs +41 -0
  211. package/dist/utils.mjs +32 -0
  212. package/package.json +175 -3
  213. package/README.md +0 -3
package/LICENSE.md ADDED
@@ -0,0 +1,17 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2025 - present, olliethedev
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5
+ and associated documentation files (the "Software"), to deal in the Software without restriction,
6
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
7
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
8
+ is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or
11
+ substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14
+ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,154 @@
1
+ 'use strict';
2
+
3
+ const schemas = require('../schemas.cjs');
4
+
5
+ function serializeForm(form) {
6
+ return {
7
+ id: form.id,
8
+ name: form.name,
9
+ slug: form.slug,
10
+ description: form.description,
11
+ schema: form.schema,
12
+ successMessage: form.successMessage,
13
+ redirectUrl: form.redirectUrl,
14
+ status: form.status,
15
+ createdBy: form.createdBy,
16
+ createdAt: form.createdAt.toISOString(),
17
+ updatedAt: form.updatedAt.toISOString()
18
+ };
19
+ }
20
+ function serializeFormSubmission(submission) {
21
+ return {
22
+ ...submission,
23
+ submittedAt: submission.submittedAt.toISOString()
24
+ };
25
+ }
26
+ function serializeFormSubmissionSummary(submission) {
27
+ return {
28
+ id: submission.id,
29
+ formId: submission.formId,
30
+ submittedAt: typeof submission.submittedAt === "string" ? submission.submittedAt : submission.submittedAt.toISOString(),
31
+ ...submission.submittedBy ? { submittedBy: submission.submittedBy } : {}
32
+ };
33
+ }
34
+ function serializeFormSubmissionWithData(submission) {
35
+ let parsedData = null;
36
+ try {
37
+ parsedData = JSON.parse(submission.data);
38
+ } catch {
39
+ }
40
+ return {
41
+ ...serializeFormSubmission(submission),
42
+ parsedData,
43
+ form: submission.form ? serializeForm(submission.form) : void 0
44
+ };
45
+ }
46
+ function formMatchesSearch(form, searchLower) {
47
+ return form.name.toLowerCase().includes(searchLower) || form.slug.toLowerCase().includes(searchLower);
48
+ }
49
+ async function getAllForms(adapter, params) {
50
+ const whereConditions = [];
51
+ if (params?.status) {
52
+ whereConditions.push({
53
+ field: "status",
54
+ value: params.status,
55
+ operator: "eq"
56
+ });
57
+ }
58
+ const search = params?.search?.trim();
59
+ const needsInMemoryFilter = !!search;
60
+ const dbTotal = !needsInMemoryFilter ? await adapter.count({
61
+ model: "form",
62
+ where: whereConditions.length > 0 ? whereConditions : void 0
63
+ }) : void 0;
64
+ const forms = await adapter.findMany({
65
+ model: "form",
66
+ where: whereConditions.length > 0 ? whereConditions : void 0,
67
+ limit: !needsInMemoryFilter ? params?.limit : schemas.DEFAULT_MAX_PAGE_SIZE,
68
+ offset: !needsInMemoryFilter ? params?.offset : void 0,
69
+ sortBy: { field: "createdAt", direction: "desc" }
70
+ });
71
+ let result = forms.map(serializeForm);
72
+ if (needsInMemoryFilter) {
73
+ const searchLower = search.toLowerCase();
74
+ result = result.filter((form) => formMatchesSearch(form, searchLower));
75
+ const total = result.length;
76
+ const offset = params?.offset ?? 0;
77
+ const limit = params?.limit;
78
+ result = result.slice(
79
+ offset,
80
+ limit !== void 0 ? offset + limit : void 0
81
+ );
82
+ return {
83
+ items: result,
84
+ total,
85
+ limit: params?.limit,
86
+ offset: params?.offset
87
+ };
88
+ }
89
+ return {
90
+ items: result,
91
+ total: dbTotal ?? result.length,
92
+ limit: params?.limit,
93
+ offset: params?.offset
94
+ };
95
+ }
96
+ async function getFormById(adapter, id) {
97
+ const form = await adapter.findOne({
98
+ model: "form",
99
+ where: [{ field: "id", value: id, operator: "eq" }]
100
+ });
101
+ if (!form) return null;
102
+ return serializeForm(form);
103
+ }
104
+ async function getFormBySlug(adapter, slug) {
105
+ const form = await adapter.findOne({
106
+ model: "form",
107
+ where: [{ field: "slug", value: slug, operator: "eq" }]
108
+ });
109
+ if (!form) {
110
+ return null;
111
+ }
112
+ return serializeForm(form);
113
+ }
114
+ async function getFormSubmissions(adapter, formId, params) {
115
+ const form = await adapter.findOne({
116
+ model: "form",
117
+ where: [{ field: "id", value: formId, operator: "eq" }]
118
+ });
119
+ if (!form) {
120
+ return {
121
+ items: [],
122
+ total: 0,
123
+ limit: params?.limit,
124
+ offset: params?.offset
125
+ };
126
+ }
127
+ const total = await adapter.count({
128
+ model: "formSubmission",
129
+ where: [{ field: "formId", value: formId, operator: "eq" }]
130
+ });
131
+ const submissions = await adapter.findMany({
132
+ model: "formSubmission",
133
+ where: [{ field: "formId", value: formId, operator: "eq" }],
134
+ limit: params?.limit,
135
+ offset: params?.offset,
136
+ sortBy: { field: "submittedAt", direction: "desc" },
137
+ join: { form: true }
138
+ });
139
+ return {
140
+ items: submissions.map(serializeFormSubmissionWithData),
141
+ total,
142
+ limit: params?.limit,
143
+ offset: params?.offset
144
+ };
145
+ }
146
+
147
+ exports.getAllForms = getAllForms;
148
+ exports.getFormById = getFormById;
149
+ exports.getFormBySlug = getFormBySlug;
150
+ exports.getFormSubmissions = getFormSubmissions;
151
+ exports.serializeForm = serializeForm;
152
+ exports.serializeFormSubmission = serializeFormSubmission;
153
+ exports.serializeFormSubmissionSummary = serializeFormSubmissionSummary;
154
+ exports.serializeFormSubmissionWithData = serializeFormSubmissionWithData;
@@ -0,0 +1,145 @@
1
+ import { DEFAULT_MAX_PAGE_SIZE } from '../schemas.mjs';
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 serializeFormSubmissionSummary(submission) {
25
+ return {
26
+ id: submission.id,
27
+ formId: submission.formId,
28
+ submittedAt: typeof submission.submittedAt === "string" ? submission.submittedAt : submission.submittedAt.toISOString(),
29
+ ...submission.submittedBy ? { submittedBy: submission.submittedBy } : {}
30
+ };
31
+ }
32
+ function serializeFormSubmissionWithData(submission) {
33
+ let parsedData = null;
34
+ try {
35
+ parsedData = JSON.parse(submission.data);
36
+ } catch {
37
+ }
38
+ return {
39
+ ...serializeFormSubmission(submission),
40
+ parsedData,
41
+ form: submission.form ? serializeForm(submission.form) : void 0
42
+ };
43
+ }
44
+ function formMatchesSearch(form, searchLower) {
45
+ return form.name.toLowerCase().includes(searchLower) || form.slug.toLowerCase().includes(searchLower);
46
+ }
47
+ async function getAllForms(adapter, params) {
48
+ const whereConditions = [];
49
+ if (params?.status) {
50
+ whereConditions.push({
51
+ field: "status",
52
+ value: params.status,
53
+ operator: "eq"
54
+ });
55
+ }
56
+ const search = params?.search?.trim();
57
+ const needsInMemoryFilter = !!search;
58
+ const dbTotal = !needsInMemoryFilter ? await adapter.count({
59
+ model: "form",
60
+ where: whereConditions.length > 0 ? whereConditions : void 0
61
+ }) : void 0;
62
+ const forms = await adapter.findMany({
63
+ model: "form",
64
+ where: whereConditions.length > 0 ? whereConditions : void 0,
65
+ limit: !needsInMemoryFilter ? params?.limit : DEFAULT_MAX_PAGE_SIZE,
66
+ offset: !needsInMemoryFilter ? params?.offset : void 0,
67
+ sortBy: { field: "createdAt", direction: "desc" }
68
+ });
69
+ let result = forms.map(serializeForm);
70
+ if (needsInMemoryFilter) {
71
+ const searchLower = search.toLowerCase();
72
+ result = result.filter((form) => formMatchesSearch(form, searchLower));
73
+ const total = result.length;
74
+ const offset = params?.offset ?? 0;
75
+ const limit = params?.limit;
76
+ result = result.slice(
77
+ offset,
78
+ limit !== void 0 ? offset + limit : void 0
79
+ );
80
+ return {
81
+ items: result,
82
+ total,
83
+ limit: params?.limit,
84
+ offset: params?.offset
85
+ };
86
+ }
87
+ return {
88
+ items: result,
89
+ total: dbTotal ?? result.length,
90
+ limit: params?.limit,
91
+ offset: params?.offset
92
+ };
93
+ }
94
+ async function getFormById(adapter, id) {
95
+ const form = await adapter.findOne({
96
+ model: "form",
97
+ where: [{ field: "id", value: id, operator: "eq" }]
98
+ });
99
+ if (!form) return null;
100
+ return serializeForm(form);
101
+ }
102
+ async function getFormBySlug(adapter, slug) {
103
+ const form = await adapter.findOne({
104
+ model: "form",
105
+ where: [{ field: "slug", value: slug, operator: "eq" }]
106
+ });
107
+ if (!form) {
108
+ return null;
109
+ }
110
+ return serializeForm(form);
111
+ }
112
+ async function getFormSubmissions(adapter, formId, params) {
113
+ const form = await adapter.findOne({
114
+ model: "form",
115
+ where: [{ field: "id", value: formId, operator: "eq" }]
116
+ });
117
+ if (!form) {
118
+ return {
119
+ items: [],
120
+ total: 0,
121
+ limit: params?.limit,
122
+ offset: params?.offset
123
+ };
124
+ }
125
+ const total = await adapter.count({
126
+ model: "formSubmission",
127
+ where: [{ field: "formId", value: formId, operator: "eq" }]
128
+ });
129
+ const submissions = await adapter.findMany({
130
+ model: "formSubmission",
131
+ where: [{ field: "formId", value: formId, operator: "eq" }],
132
+ limit: params?.limit,
133
+ offset: params?.offset,
134
+ sortBy: { field: "submittedAt", direction: "desc" },
135
+ join: { form: true }
136
+ });
137
+ return {
138
+ items: submissions.map(serializeFormSubmissionWithData),
139
+ total,
140
+ limit: params?.limit,
141
+ offset: params?.offset
142
+ };
143
+ }
144
+
145
+ export { getAllForms, getFormById, getFormBySlug, getFormSubmissions, serializeForm, serializeFormSubmission, serializeFormSubmissionSummary, serializeFormSubmissionWithData };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const plugin = require('./plugin.cjs');
4
+ const lifecycleMigrations = require('./lifecycle-migrations.cjs');
5
+ const operations = require('./operations.cjs');
6
+ const permissions = require('../permissions.cjs');
7
+ const getters = require('./getters.cjs');
8
+ const queryKeyDefs = require('./query-key-defs.cjs');
9
+
10
+
11
+
12
+ exports.formBuilderBackendPlugin = plugin.formBuilderBackendPlugin;
13
+ exports.FORM_BUILDER_LIFECYCLE_HOOK_MIGRATIONS = lifecycleMigrations.FORM_BUILDER_LIFECYCLE_HOOK_MIGRATIONS;
14
+ exports.FormBuilderOperationError = operations.FormBuilderOperationError;
15
+ exports.createFormBuilderOperations = operations.createFormBuilderOperations;
16
+ exports.formBuilderPermissions = permissions.formBuilderPermissions;
17
+ exports.getAllForms = getters.getAllForms;
18
+ exports.getFormById = getters.getFormById;
19
+ exports.getFormBySlug = getters.getFormBySlug;
20
+ exports.getFormSubmissions = getters.getFormSubmissions;
21
+ exports.serializeForm = getters.serializeForm;
22
+ exports.serializeFormSubmission = getters.serializeFormSubmission;
23
+ exports.serializeFormSubmissionSummary = getters.serializeFormSubmissionSummary;
24
+ exports.serializeFormSubmissionWithData = getters.serializeFormSubmissionWithData;
25
+ exports.FORM_QUERY_KEYS = queryKeyDefs.FORM_QUERY_KEYS;
@@ -0,0 +1,119 @@
1
+ export { F as FORM_QUERY_KEYS, a as FormBuilderApiRouter, b as FormBuilderOperationError, c as FormBuilderOperations, d as FormBuilderRouteKey, e as FormListOperationResult, S as SubmissionDetailOperationResult, f as SubmissionListOperationResult, g as SubmitOperationResult, h as createFormBuilderOperations, i as formBuilderBackendPlugin } from '../shared/plugin-form-builder.Bbl9NufB.cjs';
2
+ export { formBuilderPermissions } from '../permissions.cjs';
3
+ import { d as SerializedFormSubmissionSummary } from '../shared/plugin-form-builder.Cmk083dA.cjs';
4
+ import { SerializedForm, SerializedFormSubmissionWithData, Form, FormSubmission, SerializedFormSubmission, FormSubmissionWithForm } from '../types.cjs';
5
+ export { f as FormBuilderBackendConfig, g as FormBuilderBackendHooks, h as FormBuilderHookContext, i as FormBuilderOperationHookContext, j as FormCreateOperationContext, k as FormDeleteOperationContext, l as FormGetForUpdateOperationContext, m as FormGetOperationContext, n as FormListOperationContext, o as FormUpdateOperationContext, p as SubmissionCreateOperationContext, q as SubmissionDeleteOperationContext, r as SubmissionGetOperationContext, s as SubmissionHookContext, t as SubmissionListFormContext, u as SubmissionListOperationContext } from '../shared/plugin-form-builder.Cmk083dA.cjs';
6
+ import { DBAdapter } from '@btst/db';
7
+ import '@btst/stack/plugins/api';
8
+ import 'zod';
9
+ import 'zod/v4/core';
10
+ import 'better-call';
11
+ import '@tanstack/react-query';
12
+ import '@btst/stack/authorization';
13
+ import '@btst/stack/context';
14
+
15
+ /**
16
+ * Removed Form Builder lifecycle names and their canonical v3 replacements.
17
+ *
18
+ * Submission receipt keeps its domain vocabulary. Names absent from this map
19
+ * did not change.
20
+ */
21
+ declare const FORM_BUILDER_LIFECYCLE_HOOK_MIGRATIONS: Readonly<{
22
+ readonly onBeforeFormCreated: "onBeforeCreateForm";
23
+ readonly onAfterFormCreated: "onAfterCreateForm";
24
+ readonly onBeforeFormUpdated: "onBeforeUpdateForm";
25
+ readonly onAfterFormUpdated: "onAfterUpdateForm";
26
+ readonly onBeforeFormDeleted: "onBeforeDeleteForm";
27
+ readonly onAfterFormDeleted: "onAfterDeleteForm";
28
+ readonly onSubmissionError: "onErrorSubmission";
29
+ readonly onBeforeSubmissionDeleted: "onBeforeDeleteSubmission";
30
+ readonly onAfterSubmissionDeleted: "onAfterDeleteSubmission";
31
+ }>;
32
+
33
+ /**
34
+ * Serialize a Form for SSR/SSG use (convert dates to strings).
35
+ */
36
+ declare function serializeForm(form: Form): SerializedForm;
37
+ /**
38
+ * Serialize a FormSubmission for SSR/SSG use (convert dates to strings).
39
+ */
40
+ declare function serializeFormSubmission(submission: FormSubmission): SerializedFormSubmission;
41
+ /** Strip a submission down to browser-safe collection metadata. */
42
+ declare function serializeFormSubmissionSummary(submission: FormSubmission | SerializedFormSubmission): SerializedFormSubmissionSummary;
43
+ /**
44
+ * Serialize a FormSubmission with parsed data and joined Form.
45
+ * If `submission.data` is corrupted JSON, `parsedData` is set to `null` rather
46
+ * than throwing, so one bad row cannot crash the entire list or SSG build.
47
+ */
48
+ declare function serializeFormSubmissionWithData(submission: FormSubmissionWithForm): SerializedFormSubmissionWithData;
49
+ /**
50
+ * Retrieve all forms with optional status filter, pagination, and free-text
51
+ * search.
52
+ * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
53
+ *
54
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT
55
+ * called. The caller is responsible for any access-control checks before
56
+ * invoking this function.
57
+ *
58
+ * @param adapter - The database adapter
59
+ * @param params - Optional filter/pagination parameters. `search` matches
60
+ * case-insensitively against form names and slugs.
61
+ */
62
+ declare function getAllForms(adapter: DBAdapter, params?: {
63
+ status?: string;
64
+ limit?: number;
65
+ offset?: number;
66
+ search?: string;
67
+ }): Promise<{
68
+ items: SerializedForm[];
69
+ total: number;
70
+ limit?: number;
71
+ offset?: number;
72
+ }>;
73
+ /**
74
+ * Retrieve a single form by its ID (UUID).
75
+ * Returns null if the form is not found.
76
+ * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
77
+ *
78
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT called. The caller is
79
+ * responsible for any access-control checks before invoking this function.
80
+ *
81
+ * @param adapter - The database adapter
82
+ * @param id - The form UUID
83
+ */
84
+ declare function getFormById(adapter: DBAdapter, id: string): Promise<SerializedForm | null>;
85
+ /**
86
+ * Retrieve a single form by its slug.
87
+ * Returns null if the form is not found.
88
+ * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
89
+ *
90
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT called. The caller is
91
+ * responsible for any access-control checks before invoking this function.
92
+ *
93
+ * @param adapter - The database adapter
94
+ * @param slug - The form slug
95
+ */
96
+ declare function getFormBySlug(adapter: DBAdapter, slug: string): Promise<SerializedForm | null>;
97
+ /**
98
+ * Retrieve submissions for a form by form ID, with optional pagination.
99
+ * Returns an empty result if the form does not exist.
100
+ * Pure DB function — no hooks, no HTTP context. Safe for server-side use.
101
+ *
102
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT called. The caller is
103
+ * responsible for any access-control checks before invoking this function.
104
+ *
105
+ * @param adapter - The database adapter
106
+ * @param formId - The form ID
107
+ * @param params - Optional pagination parameters
108
+ */
109
+ declare function getFormSubmissions(adapter: Pick<DBAdapter, "findOne" | "findMany" | "count">, formId: string, params?: {
110
+ limit?: number;
111
+ offset?: number;
112
+ }): Promise<{
113
+ items: SerializedFormSubmissionWithData[];
114
+ total: number;
115
+ limit?: number;
116
+ offset?: number;
117
+ }>;
118
+
119
+ export { FORM_BUILDER_LIFECYCLE_HOOK_MIGRATIONS, SerializedFormSubmissionSummary, getAllForms, getFormById, getFormBySlug, getFormSubmissions, serializeForm, serializeFormSubmission, serializeFormSubmissionSummary, serializeFormSubmissionWithData };
@@ -0,0 +1,119 @@
1
+ export { F as FORM_QUERY_KEYS, a as FormBuilderApiRouter, b as FormBuilderOperationError, c as FormBuilderOperations, d as FormBuilderRouteKey, e as FormListOperationResult, S as SubmissionDetailOperationResult, f as SubmissionListOperationResult, g as SubmitOperationResult, h as createFormBuilderOperations, i as formBuilderBackendPlugin } from '../shared/plugin-form-builder.lp98rFNl.mjs';
2
+ export { formBuilderPermissions } from '../permissions.mjs';
3
+ import { d as SerializedFormSubmissionSummary } from '../shared/plugin-form-builder.BZYGyFgT.mjs';
4
+ import { SerializedForm, SerializedFormSubmissionWithData, Form, FormSubmission, SerializedFormSubmission, FormSubmissionWithForm } from '../types.mjs';
5
+ export { f as FormBuilderBackendConfig, g as FormBuilderBackendHooks, h as FormBuilderHookContext, i as FormBuilderOperationHookContext, j as FormCreateOperationContext, k as FormDeleteOperationContext, l as FormGetForUpdateOperationContext, m as FormGetOperationContext, n as FormListOperationContext, o as FormUpdateOperationContext, p as SubmissionCreateOperationContext, q as SubmissionDeleteOperationContext, r as SubmissionGetOperationContext, s as SubmissionHookContext, t as SubmissionListFormContext, u as SubmissionListOperationContext } from '../shared/plugin-form-builder.BZYGyFgT.mjs';
6
+ import { DBAdapter } from '@btst/db';
7
+ import '@btst/stack/plugins/api';
8
+ import 'zod';
9
+ import 'zod/v4/core';
10
+ import 'better-call';
11
+ import '@tanstack/react-query';
12
+ import '@btst/stack/authorization';
13
+ import '@btst/stack/context';
14
+
15
+ /**
16
+ * Removed Form Builder lifecycle names and their canonical v3 replacements.
17
+ *
18
+ * Submission receipt keeps its domain vocabulary. Names absent from this map
19
+ * did not change.
20
+ */
21
+ declare const FORM_BUILDER_LIFECYCLE_HOOK_MIGRATIONS: Readonly<{
22
+ readonly onBeforeFormCreated: "onBeforeCreateForm";
23
+ readonly onAfterFormCreated: "onAfterCreateForm";
24
+ readonly onBeforeFormUpdated: "onBeforeUpdateForm";
25
+ readonly onAfterFormUpdated: "onAfterUpdateForm";
26
+ readonly onBeforeFormDeleted: "onBeforeDeleteForm";
27
+ readonly onAfterFormDeleted: "onAfterDeleteForm";
28
+ readonly onSubmissionError: "onErrorSubmission";
29
+ readonly onBeforeSubmissionDeleted: "onBeforeDeleteSubmission";
30
+ readonly onAfterSubmissionDeleted: "onAfterDeleteSubmission";
31
+ }>;
32
+
33
+ /**
34
+ * Serialize a Form for SSR/SSG use (convert dates to strings).
35
+ */
36
+ declare function serializeForm(form: Form): SerializedForm;
37
+ /**
38
+ * Serialize a FormSubmission for SSR/SSG use (convert dates to strings).
39
+ */
40
+ declare function serializeFormSubmission(submission: FormSubmission): SerializedFormSubmission;
41
+ /** Strip a submission down to browser-safe collection metadata. */
42
+ declare function serializeFormSubmissionSummary(submission: FormSubmission | SerializedFormSubmission): SerializedFormSubmissionSummary;
43
+ /**
44
+ * Serialize a FormSubmission with parsed data and joined Form.
45
+ * If `submission.data` is corrupted JSON, `parsedData` is set to `null` rather
46
+ * than throwing, so one bad row cannot crash the entire list or SSG build.
47
+ */
48
+ declare function serializeFormSubmissionWithData(submission: FormSubmissionWithForm): SerializedFormSubmissionWithData;
49
+ /**
50
+ * Retrieve all forms with optional status filter, pagination, and free-text
51
+ * search.
52
+ * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
53
+ *
54
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT
55
+ * called. The caller is responsible for any access-control checks before
56
+ * invoking this function.
57
+ *
58
+ * @param adapter - The database adapter
59
+ * @param params - Optional filter/pagination parameters. `search` matches
60
+ * case-insensitively against form names and slugs.
61
+ */
62
+ declare function getAllForms(adapter: DBAdapter, params?: {
63
+ status?: string;
64
+ limit?: number;
65
+ offset?: number;
66
+ search?: string;
67
+ }): Promise<{
68
+ items: SerializedForm[];
69
+ total: number;
70
+ limit?: number;
71
+ offset?: number;
72
+ }>;
73
+ /**
74
+ * Retrieve a single form by its ID (UUID).
75
+ * Returns null if the form is not found.
76
+ * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
77
+ *
78
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT called. The caller is
79
+ * responsible for any access-control checks before invoking this function.
80
+ *
81
+ * @param adapter - The database adapter
82
+ * @param id - The form UUID
83
+ */
84
+ declare function getFormById(adapter: DBAdapter, id: string): Promise<SerializedForm | null>;
85
+ /**
86
+ * Retrieve a single form by its slug.
87
+ * Returns null if the form is not found.
88
+ * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
89
+ *
90
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT called. The caller is
91
+ * responsible for any access-control checks before invoking this function.
92
+ *
93
+ * @param adapter - The database adapter
94
+ * @param slug - The form slug
95
+ */
96
+ declare function getFormBySlug(adapter: DBAdapter, slug: string): Promise<SerializedForm | null>;
97
+ /**
98
+ * Retrieve submissions for a form by form ID, with optional pagination.
99
+ * Returns an empty result if the form does not exist.
100
+ * Pure DB function — no hooks, no HTTP context. Safe for server-side use.
101
+ *
102
+ * @remarks **Security:** Operation authorization and lifecycle hooks are NOT called. The caller is
103
+ * responsible for any access-control checks before invoking this function.
104
+ *
105
+ * @param adapter - The database adapter
106
+ * @param formId - The form ID
107
+ * @param params - Optional pagination parameters
108
+ */
109
+ declare function getFormSubmissions(adapter: Pick<DBAdapter, "findOne" | "findMany" | "count">, formId: string, params?: {
110
+ limit?: number;
111
+ offset?: number;
112
+ }): Promise<{
113
+ items: SerializedFormSubmissionWithData[];
114
+ total: number;
115
+ limit?: number;
116
+ offset?: number;
117
+ }>;
118
+
119
+ export { FORM_BUILDER_LIFECYCLE_HOOK_MIGRATIONS, SerializedFormSubmissionSummary, getAllForms, getFormById, getFormBySlug, getFormSubmissions, serializeForm, serializeFormSubmission, serializeFormSubmissionSummary, serializeFormSubmissionWithData };