@easy-cms/plugin-form-builder 0.45.0 → 0.47.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 (2) hide show
  1. package/dist/index.js +19 -42
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -195,50 +195,19 @@ 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.45.0" } : {}
198
+ ...true ? { version: "0.47.0" } : {}
199
199
  };
200
200
 
201
201
  // src/spam.ts
202
- import { createHmac, timingSafeEqual } from "crypto";
203
- var MAX_AGE = 24 * 36e5;
204
- var sign = (secret, value) => createHmac("sha256", secret).update(value).digest("base64url");
205
- function formToken(secret, slug, now = Date.now()) {
206
- return `${now}.${sign(secret, `easy-form:${slug}:${now}`)}`;
207
- }
208
- function checkToken(secret, slug, token, minTime, now = Date.now()) {
209
- if (typeof token !== "string") return "invalid";
210
- const [time, signature] = token.split(".");
211
- const issued = Number(time);
212
- if (!Number.isFinite(issued) || !signature) return "invalid";
213
- const expected = Buffer.from(sign(secret, `easy-form:${slug}:${issued}`));
214
- const given = Buffer.from(signature);
215
- if (expected.length !== given.length || !timingSafeEqual(expected, given)) return "invalid";
216
- if (now - issued < minTime) return "too-fast";
217
- if (now - issued > MAX_AGE) return "expired";
218
- return "ok";
219
- }
220
- function rateKeys(secret, ip, form, window, now = Date.now()) {
221
- const bucket = Math.floor(now / (window * 1e3));
222
- const key = (b) => sign(secret, `easy-form-rate:${ip}:${String(form)}:${b}`).slice(0, 32);
223
- return { current: key(bucket), previous: key(bucket - 1) };
224
- }
225
- function honeypotName(names) {
226
- return ["website", "homepage", "url_address"].find((n) => !names.includes(n)) ?? "hp_field";
227
- }
228
- async function verifyTurnstile(secretKey, response, ip, fetcher = fetch) {
229
- if (typeof response !== "string" || !response) return false;
230
- const body = new URLSearchParams({ secret: secretKey, response, ...ip ? { remoteip: ip } : {} });
231
- try {
232
- const result = await fetcher("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
233
- method: "POST",
234
- body,
235
- signal: AbortSignal.timeout(1e4)
236
- });
237
- return (await result.json()).success === true;
238
- } catch {
239
- return false;
240
- }
241
- }
202
+ import {
203
+ checkFormToken,
204
+ formToken as coreFormToken,
205
+ rateKeys as coreRateKeys
206
+ } from "@easy-cms/core";
207
+ import { honeypotName, verifyTurnstile } from "@easy-cms/core";
208
+ var formToken = (secret, slug, now = Date.now()) => coreFormToken(secret, `easy-form:${slug}`, now);
209
+ var checkToken = (secret, slug, token, minTime, now = Date.now()) => checkFormToken(secret, `easy-form:${slug}`, token, minTime, now);
210
+ var rateKeys = (secret, ip, form, window, now = Date.now()) => coreRateKeys(secret, `easy-form-rate:${ip}:${String(form)}`, window, now);
242
211
 
243
212
  // src/validate.ts
244
213
  var MESSAGES = {
@@ -443,6 +412,7 @@ function formBuilderPlugin(options = {}) {
443
412
  drafts: true,
444
413
  fields: formFields,
445
414
  admin: {
415
+ group: "forms",
446
416
  sidebar: [
447
417
  {
448
418
  tag: "ecms-form-submissions",
@@ -463,6 +433,7 @@ function formBuilderPlugin(options = {}) {
463
433
  },
464
434
  icon: "message-square",
465
435
  useAsTitle: "summary",
436
+ admin: { group: "forms", count: false },
466
437
  // Only the form's public endpoint creates submissions, after validation and spam checks.
467
438
  access: {
468
439
  read: loggedIn,
@@ -805,13 +776,19 @@ function formBuilderPlugin(options = {}) {
805
776
  admin: {
806
777
  ...config.admin,
807
778
  modules: [.../* @__PURE__ */ new Set([...config.admin?.modules ?? [], ADMIN_MODULE])],
808
- // Submissions at a glance: a page under Content and a dashboard panel.
779
+ // The menu's Forms group: forms, submissions and their overview.
780
+ nav: [
781
+ ...config.admin?.nav ?? [],
782
+ { id: "forms", label: { en: "Forms", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }, icon: "mail", order: 200 }
783
+ ],
784
+ // Submissions at a glance: a page and a dashboard panel.
809
785
  pages: [
810
786
  ...config.admin?.pages ?? [],
811
787
  {
812
788
  path: "forms-overview",
813
789
  label: { en: "Form overview", th: "\u0E20\u0E32\u0E1E\u0E23\u0E27\u0E21\u0E1F\u0E2D\u0E23\u0E4C\u0E21" },
814
790
  icon: "chart-column",
791
+ group: "forms",
815
792
  component: { tag: "ecms-forms-overview", props: { forms, submissions, adminPath } }
816
793
  }
817
794
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-form-builder",
3
- "version": "0.45.0",
3
+ "version": "0.47.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.45.0"
26
+ "@easy-cms/richtext": "^0.47.0"
27
27
  },
28
28
  "peerDependencies": {
29
- "@easy-cms/core": "^0.45.0"
29
+ "@easy-cms/core": "^0.47.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "happy-dom": "^20.14.5",
33
- "@easy-cms/core": "^0.45.0",
34
- "@easy-cms/db-sqlite": "^0.45.0"
33
+ "@easy-cms/core": "^0.47.0",
34
+ "@easy-cms/db-sqlite": "^0.47.0"
35
35
  },
36
36
  "engines": {
37
37
  "node": ">=22.12"