@easy-cms/plugin-form-builder 0.48.0 → 0.60.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.d.ts +6 -8
- package/dist/index.js +31 -16
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { TypedPlugin } from '@easy-cms/core';
|
|
|
2
2
|
import { F as FieldKind } from './shared-BP_sUDqY.js';
|
|
3
3
|
export { C as Confirmation, c as FIELD_KINDS, b as PublicField, P as PublicForm, S as Submission, a as SubmitResult } from './shared-BP_sUDqY.js';
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
interface FormBuilderPluginOptions {
|
|
6
6
|
/** Field types editors can add. Default: all. */
|
|
7
|
-
readonly
|
|
7
|
+
readonly fieldKinds?: readonly FieldKind[];
|
|
8
8
|
/** Sender of form emails that don't set one. Default: the email adapter's `from`. */
|
|
9
9
|
readonly defaultFrom?: string;
|
|
10
10
|
/** Recipients of form emails whose "To" is empty, e.g. the site owner. */
|
|
@@ -17,8 +17,8 @@ interface FormBuilderOptions {
|
|
|
17
17
|
readonly max?: number;
|
|
18
18
|
readonly window?: number;
|
|
19
19
|
} | false;
|
|
20
|
-
/** Submissions sent sooner than this after the form loaded are treated as bots. Default
|
|
21
|
-
readonly
|
|
20
|
+
/** Submissions sent sooner than this many seconds after the form loaded are treated as bots. Default 2. */
|
|
21
|
+
readonly minSubmitSeconds?: number;
|
|
22
22
|
/** Cloudflare Turnstile, to check that visitors are people. Keys from the Cloudflare dashboard. */
|
|
23
23
|
readonly turnstile?: {
|
|
24
24
|
readonly siteKey: string;
|
|
@@ -31,8 +31,6 @@ interface FormBuilderOptions {
|
|
|
31
31
|
readonly forms?: string;
|
|
32
32
|
readonly submissions?: string;
|
|
33
33
|
};
|
|
34
|
-
/** For tests: the `fetch` for Turnstile. */
|
|
35
|
-
readonly fetch?: typeof fetch;
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
36
|
* Forms editors build in the admin from field blocks, with submissions, email notifications and
|
|
@@ -142,11 +140,11 @@ type FormBuilderPluginTypes<F extends string, S extends string> = {
|
|
|
142
140
|
}
|
|
143
141
|
];
|
|
144
142
|
};
|
|
145
|
-
declare function formBuilderPlugin<const F extends string = 'forms', const S extends string = 'form-submissions'>(options?:
|
|
143
|
+
declare function formBuilderPlugin<const F extends string = 'forms', const S extends string = 'form-submissions'>(options?: FormBuilderPluginOptions & {
|
|
146
144
|
readonly slugs?: {
|
|
147
145
|
readonly forms?: F;
|
|
148
146
|
readonly submissions?: S;
|
|
149
147
|
};
|
|
150
148
|
}): TypedPlugin<FormBuilderPluginTypes<F, S>>;
|
|
151
149
|
|
|
152
|
-
export { FieldKind, type
|
|
150
|
+
export { FieldKind, type FormBuilderPluginOptions, type FormBuilderPluginTypes, formBuilderPlugin };
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
// src/plugin.ts
|
|
6
6
|
import { readFile } from "fs/promises";
|
|
7
7
|
import {
|
|
8
|
-
definePlugin
|
|
9
|
-
resolveAdminModule
|
|
8
|
+
definePlugin
|
|
10
9
|
} from "@easy-cms/core";
|
|
10
|
+
import { checkRenamedOptions, resolveAdminModule } from "@easy-cms/core/internal";
|
|
11
11
|
import { renderRichText as renderRichText2 } from "@easy-cms/richtext";
|
|
12
12
|
|
|
13
13
|
// src/emails.ts
|
|
@@ -195,7 +195,9 @@ function fieldBlocks(localized, kinds) {
|
|
|
195
195
|
// src/info.ts
|
|
196
196
|
var INFO = {
|
|
197
197
|
name: "@easy-cms/plugin-form-builder",
|
|
198
|
-
|
|
198
|
+
// The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
|
|
199
|
+
apiVersion: 1,
|
|
200
|
+
...true ? { version: "0.60.0" } : {}
|
|
199
201
|
};
|
|
200
202
|
|
|
201
203
|
// src/spam.ts
|
|
@@ -203,8 +205,8 @@ import {
|
|
|
203
205
|
checkFormToken,
|
|
204
206
|
formToken as coreFormToken,
|
|
205
207
|
rateKeys as coreRateKeys
|
|
206
|
-
} from "@easy-cms/core";
|
|
207
|
-
import { honeypotName, verifyTurnstile } from "@easy-cms/core";
|
|
208
|
+
} from "@easy-cms/core/internal";
|
|
209
|
+
import { honeypotName, verifyTurnstile } from "@easy-cms/core/internal";
|
|
208
210
|
var formToken = (secret, slug, now = Date.now()) => coreFormToken(secret, `easy-form:${slug}`, now);
|
|
209
211
|
var checkToken = (secret, slug, token, minTime, now = Date.now()) => checkFormToken(secret, `easy-form:${slug}`, token, minTime, now);
|
|
210
212
|
var rateKeys = (secret, ip, form, window, now = Date.now()) => coreRateKeys(secret, `easy-form-rate:${ip}:${String(form)}`, window, now);
|
|
@@ -315,20 +317,24 @@ var optionValues = (row) => (Array.isArray(row.options) ? row.options : []).map(
|
|
|
315
317
|
// src/plugin.ts
|
|
316
318
|
var ADMIN_MODULE = "@easy-cms/plugin-form-builder/admin";
|
|
317
319
|
function formBuilderPlugin(options = {}) {
|
|
320
|
+
checkRenamedOptions("formBuilderPlugin", options, {
|
|
321
|
+
fields: "fieldKinds",
|
|
322
|
+
minSubmitTime: "minSubmitSeconds (in seconds)"
|
|
323
|
+
});
|
|
318
324
|
return definePlugin((config) => {
|
|
319
325
|
const forms = options.slugs?.forms ?? "forms";
|
|
320
326
|
const submissions = options.slugs?.submissions ?? "form-submissions";
|
|
321
327
|
for (const slug of [forms, submissions])
|
|
322
328
|
if (config.collections?.some((c) => c.slug === slug))
|
|
323
329
|
throw new Error(`formBuilderPlugin: there is already a collection "${slug}"; set \`slugs\``);
|
|
324
|
-
const kinds = options.
|
|
330
|
+
const kinds = options.fieldKinds ?? FIELD_KINDS;
|
|
325
331
|
const localized = !!config.localization;
|
|
326
332
|
const l = localized ? { localized: true } : {};
|
|
327
333
|
const secret = config.secret;
|
|
328
|
-
const locales = config.localization?.locales ?? [];
|
|
329
|
-
const defaultLocale = config.localization?.defaultLocale ?? locales[0] ?? null;
|
|
334
|
+
const locales = (config.localization || void 0)?.locales ?? [];
|
|
335
|
+
const defaultLocale = (config.localization || void 0)?.defaultLocale ?? locales[0] ?? null;
|
|
330
336
|
const rate = options.rateLimit === false ? null : { max: 5, window: 600, ...options.rateLimit };
|
|
331
|
-
const minTime = options.
|
|
337
|
+
const minTime = (options.minSubmitSeconds ?? 2) * 1e3;
|
|
332
338
|
const defaultTo = options.defaultTo === void 0 ? [] : typeof options.defaultTo === "string" ? [options.defaultTo] : [...options.defaultTo];
|
|
333
339
|
const loggedIn = ({ user }) => !!user;
|
|
334
340
|
const formFields = [
|
|
@@ -357,7 +363,7 @@ function formBuilderPlugin(options = {}) {
|
|
|
357
363
|
options: ["message", "redirect"],
|
|
358
364
|
defaultValue: "message",
|
|
359
365
|
label: { en: "After sending", th: "\u0E2B\u0E25\u0E31\u0E07\u0E2A\u0E48\u0E07" },
|
|
360
|
-
position: "sidebar"
|
|
366
|
+
admin: { position: "sidebar" }
|
|
361
367
|
},
|
|
362
368
|
{
|
|
363
369
|
name: "confirmationMessage",
|
|
@@ -407,11 +413,11 @@ function formBuilderPlugin(options = {}) {
|
|
|
407
413
|
const formsCollection = {
|
|
408
414
|
slug: forms,
|
|
409
415
|
labels: { singular: { en: "Form", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }, plural: { en: "Forms", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" } },
|
|
410
|
-
icon: "mail",
|
|
411
416
|
useAsTitle: "title",
|
|
412
417
|
drafts: true,
|
|
413
418
|
fields: formFields,
|
|
414
419
|
admin: {
|
|
420
|
+
icon: "mail",
|
|
415
421
|
group: "forms",
|
|
416
422
|
sidebar: [
|
|
417
423
|
{
|
|
@@ -431,9 +437,8 @@ function formBuilderPlugin(options = {}) {
|
|
|
431
437
|
singular: { en: "Form submission", th: "\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E08\u0E32\u0E01\u0E1F\u0E2D\u0E23\u0E4C\u0E21" },
|
|
432
438
|
plural: { en: "Form submissions", th: "\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E08\u0E32\u0E01\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }
|
|
433
439
|
},
|
|
434
|
-
icon: "message-square",
|
|
435
440
|
useAsTitle: "summary",
|
|
436
|
-
admin: { group: "forms", count: false },
|
|
441
|
+
admin: { icon: "message-square", group: "forms", count: false },
|
|
437
442
|
// Only the form's public endpoint creates submissions, after validation and spam checks.
|
|
438
443
|
access: {
|
|
439
444
|
read: loggedIn,
|
|
@@ -451,8 +456,18 @@ function formBuilderPlugin(options = {}) {
|
|
|
451
456
|
},
|
|
452
457
|
{ name: "summary", type: "text", label: { en: "Summary", th: "\u0E2A\u0E23\u0E38\u0E1B" } },
|
|
453
458
|
{ name: "data", type: "json", label: { en: "Data", th: "\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25" } },
|
|
454
|
-
{
|
|
455
|
-
|
|
459
|
+
{
|
|
460
|
+
name: "locale",
|
|
461
|
+
type: "text",
|
|
462
|
+
label: { en: "Locale", th: "\u0E20\u0E32\u0E29\u0E32" },
|
|
463
|
+
admin: { position: "sidebar" }
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
name: "page",
|
|
467
|
+
type: "text",
|
|
468
|
+
label: { en: "Page", th: "\u0E2B\u0E19\u0E49\u0E32" },
|
|
469
|
+
admin: { position: "sidebar" }
|
|
470
|
+
},
|
|
456
471
|
// A hash of the IP address and the time window, for rate limits; never shown.
|
|
457
472
|
{
|
|
458
473
|
name: "rateKey",
|
|
@@ -568,7 +583,7 @@ function formBuilderPlugin(options = {}) {
|
|
|
568
583
|
const token = checkToken(secret, slug, body.token, minTime);
|
|
569
584
|
if (token === "too-fast") return { confirmation };
|
|
570
585
|
if (token !== "ok") return fail(400, [{ message: reload }]);
|
|
571
|
-
if (options.turnstile && !await verifyTurnstile(options.turnstile.secretKey, body.turnstile, ip
|
|
586
|
+
if (options.turnstile && !await verifyTurnstile(options.turnstile.secretKey, body.turnstile, ip))
|
|
572
587
|
return fail(400, [
|
|
573
588
|
{
|
|
574
589
|
message: locale === "th" ? "\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E27\u0E48\u0E32\u0E44\u0E21\u0E48\u0E43\u0E0A\u0E48\u0E1A\u0E2D\u0E17\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08 \u0E42\u0E1B\u0E23\u0E14\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07" : "Verification failed: try again"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-form-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.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.60.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@easy-cms/core": "^0.
|
|
29
|
+
"@easy-cms/core": "^0.60.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.60.0",
|
|
34
|
+
"@easy-cms/db-sqlite": "^0.60.0"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=22.12"
|