@easy-cms/plugin-form-builder 0.44.0 → 0.45.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/index.js +25 -15
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -195,7 +195,7 @@ function fieldBlocks(localized, kinds) {
|
|
|
195
195
|
// src/info.ts
|
|
196
196
|
var INFO = {
|
|
197
197
|
name: "@easy-cms/plugin-form-builder",
|
|
198
|
-
...true ? { version: "0.
|
|
198
|
+
...true ? { version: "0.45.0" } : {}
|
|
199
199
|
};
|
|
200
200
|
|
|
201
201
|
// src/spam.ts
|
|
@@ -491,9 +491,15 @@ function formBuilderPlugin(options = {}) {
|
|
|
491
491
|
}
|
|
492
492
|
]
|
|
493
493
|
};
|
|
494
|
-
const findForm = async (cms, slug, locale) => {
|
|
494
|
+
const findForm = async (cms, slug, locale, context) => {
|
|
495
|
+
const scope = await cms.uniqueScope(forms, "slug", { context });
|
|
495
496
|
const { docs } = await cms.find(forms, {
|
|
496
|
-
where: {
|
|
497
|
+
where: {
|
|
498
|
+
and: [
|
|
499
|
+
{ slug: { equals: slug } },
|
|
500
|
+
...Object.entries(scope).map(([name, value]) => ({ [name]: { equals: value } }))
|
|
501
|
+
]
|
|
502
|
+
},
|
|
497
503
|
limit: 1,
|
|
498
504
|
depth: 0,
|
|
499
505
|
...locale ? { locale } : {}
|
|
@@ -561,10 +567,10 @@ function formBuilderPlugin(options = {}) {
|
|
|
561
567
|
const getEndpoint = {
|
|
562
568
|
path: "/form/:slug",
|
|
563
569
|
method: "get",
|
|
564
|
-
handler: async ({ params, url, cms }) => {
|
|
570
|
+
handler: async ({ params, url, cms, context }) => {
|
|
565
571
|
const slug = params.slug;
|
|
566
572
|
const locale = localeOf(url.searchParams.get("locale"));
|
|
567
|
-
const form = await findForm(cms, slug, locale);
|
|
573
|
+
const form = await findForm(cms, slug, locale, context);
|
|
568
574
|
if (!form) return fail(404, [{ message: `No published form "${slug}"` }]);
|
|
569
575
|
return Response.json(publicForm(form, slug, locale), {
|
|
570
576
|
// The token is fresh on every request.
|
|
@@ -575,11 +581,11 @@ function formBuilderPlugin(options = {}) {
|
|
|
575
581
|
const submitEndpoint = {
|
|
576
582
|
path: "/form/:slug/submit",
|
|
577
583
|
method: "post",
|
|
578
|
-
handler: async ({ params, json, ip, cms }) => {
|
|
584
|
+
handler: async ({ params, json, ip, cms, context }) => {
|
|
579
585
|
const slug = params.slug;
|
|
580
586
|
const body = await json();
|
|
581
587
|
const locale = localeOf(body.locale);
|
|
582
|
-
const form = await findForm(cms, slug, locale);
|
|
588
|
+
const form = await findForm(cms, slug, locale, context);
|
|
583
589
|
if (!form) return fail(404, [{ message: `No published form "${slug}"` }]);
|
|
584
590
|
const confirmation = confirmationOf(form, locale);
|
|
585
591
|
const reload = locale === "th" ? "\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E2B\u0E21\u0E14\u0E2D\u0E32\u0E22\u0E38 \u0E42\u0E1B\u0E23\u0E14\u0E42\u0E2B\u0E25\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E43\u0E2B\u0E21\u0E48\u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07" : "The form expired: reload the page and try again";
|
|
@@ -619,14 +625,18 @@ function formBuilderPlugin(options = {}) {
|
|
|
619
625
|
rateKey = keys.current;
|
|
620
626
|
}
|
|
621
627
|
const page = typeof body.page === "string" ? body.page.slice(0, 500) : null;
|
|
622
|
-
await cms.create(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
628
|
+
await cms.create(
|
|
629
|
+
submissions,
|
|
630
|
+
{
|
|
631
|
+
form: form.id,
|
|
632
|
+
data: values,
|
|
633
|
+
summary: summarize(rowsOf(form), values),
|
|
634
|
+
locale,
|
|
635
|
+
page,
|
|
636
|
+
...rateKey ? { rateKey } : {}
|
|
637
|
+
},
|
|
638
|
+
{ context }
|
|
639
|
+
);
|
|
630
640
|
for (const email of buildEmails({
|
|
631
641
|
form,
|
|
632
642
|
fields: rowsOf(form),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-form-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"description": "Forms for Easy CMS: build forms in the admin, collect submissions, email notifications, spam protection and an <easy-form> element",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@easy-cms/richtext": "^0.
|
|
26
|
+
"@easy-cms/richtext": "^0.45.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@easy-cms/core": "^0.
|
|
29
|
+
"@easy-cms/core": "^0.45.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"happy-dom": "^20.14.5",
|
|
33
|
-
"@easy-cms/core": "^0.
|
|
34
|
-
"@easy-cms/db-sqlite": "^0.
|
|
33
|
+
"@easy-cms/core": "^0.45.0",
|
|
34
|
+
"@easy-cms/db-sqlite": "^0.45.0"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=22.12"
|