@easy-cms/plugin-form-builder 0.43.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 +35 -21
- 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),
|
|
@@ -643,7 +653,7 @@ function formBuilderPlugin(options = {}) {
|
|
|
643
653
|
const csvEndpoint = {
|
|
644
654
|
path: "/form/:slug/submissions.csv",
|
|
645
655
|
method: "get",
|
|
646
|
-
handler: async ({ params, user, cms }) => {
|
|
656
|
+
handler: async ({ params, user, context, cms }) => {
|
|
647
657
|
const slug = params.slug;
|
|
648
658
|
if (!user) return fail(401, [{ message: "Log in to export submissions" }]);
|
|
649
659
|
const { docs } = await cms.find(forms, {
|
|
@@ -652,7 +662,8 @@ function formBuilderPlugin(options = {}) {
|
|
|
652
662
|
depth: 0,
|
|
653
663
|
draft: true,
|
|
654
664
|
overrideAccess: false,
|
|
655
|
-
user
|
|
665
|
+
user,
|
|
666
|
+
context
|
|
656
667
|
});
|
|
657
668
|
const form = docs[0];
|
|
658
669
|
if (!form) return fail(404, [{ message: `No form "${slug}"` }]);
|
|
@@ -665,7 +676,8 @@ function formBuilderPlugin(options = {}) {
|
|
|
665
676
|
page,
|
|
666
677
|
depth: 0,
|
|
667
678
|
overrideAccess: false,
|
|
668
|
-
user
|
|
679
|
+
user,
|
|
680
|
+
context
|
|
669
681
|
});
|
|
670
682
|
rows.push(...result.docs);
|
|
671
683
|
if (!result.hasNextPage) break;
|
|
@@ -698,7 +710,7 @@ function formBuilderPlugin(options = {}) {
|
|
|
698
710
|
const statsEndpoint = {
|
|
699
711
|
path: "/form/stats.json",
|
|
700
712
|
method: "get",
|
|
701
|
-
handler: async ({ url, user, cms }) => {
|
|
713
|
+
handler: async ({ url, user, context, cms }) => {
|
|
702
714
|
if (!user) return fail(401, [{ message: "Log in to see form statistics" }]);
|
|
703
715
|
const days = url.searchParams.get("days") === "30" ? 30 : 7;
|
|
704
716
|
const timeZone = validTimeZone(url.searchParams.get("tz"));
|
|
@@ -723,7 +735,8 @@ function formBuilderPlugin(options = {}) {
|
|
|
723
735
|
depth: 0,
|
|
724
736
|
draft: true,
|
|
725
737
|
overrideAccess: false,
|
|
726
|
-
user
|
|
738
|
+
user,
|
|
739
|
+
context
|
|
727
740
|
});
|
|
728
741
|
formRows.push(...result.docs);
|
|
729
742
|
if (!result.hasNextPage) break;
|
|
@@ -737,7 +750,8 @@ function formBuilderPlugin(options = {}) {
|
|
|
737
750
|
page,
|
|
738
751
|
depth: 0,
|
|
739
752
|
overrideAccess: false,
|
|
740
|
-
user
|
|
753
|
+
user,
|
|
754
|
+
context
|
|
741
755
|
});
|
|
742
756
|
for (const row of result.docs) {
|
|
743
757
|
const perDay = counts.get(String(row.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"
|