@brightsideoy/kama 1.0.0-alpha.32 → 1.0.0-alpha.33
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/content/definitions/blocks/form.yaml +4 -4
- package/dist/assets/AssetEditor-Vu5cl6lr.js +1 -0
- package/dist/assets/CmsFieldTaxonomy-DRTQyTPC.js +1 -0
- package/dist/assets/CmsHelp-PptHvDLD.js +1 -0
- package/dist/assets/CmsImagePreview-DLYdN_0R.js +1 -0
- package/dist/assets/CmsListItem-B6mUoOIw.js +1 -0
- package/dist/assets/{preload-helper-BxFQpwa9.css → CmsListItem-BxVd9_U4.css} +1 -1
- package/dist/assets/CmsPublisher-CR5-YF5j.js +3 -0
- package/dist/assets/EditorSplitPreview-D4gkVuhL.js +1 -0
- package/dist/assets/FormsWorkspace-BgGgVexq.css +1 -0
- package/dist/assets/FormsWorkspace-DtjET7gT.js +2 -0
- package/dist/assets/NodeContextMenu-CP45tlaT.js +1 -0
- package/dist/assets/NodeEditor-CPH0rWvI.css +1 -0
- package/dist/assets/NodeEditor-otvWuidQ.js +4 -0
- package/dist/assets/RteFloatingToolbar-Dvaqq7Vr.js +158 -0
- package/dist/assets/RteFloatingToolbar-mfTSuSyi.css +1 -0
- package/dist/assets/TrashWorkspace-D42-jimc.js +1 -0
- package/dist/assets/{plus-7rv1C56N.js → arrow-right-C5IFL4zO.js} +1 -1
- package/dist/assets/clock-ChD9Pw4R.js +1 -0
- package/dist/assets/external-link-BR6PVQJR.js +1 -0
- package/dist/assets/{globe-TuZP0v6A.js → folder-tree-C9FLiwU1.js} +1 -1
- package/dist/assets/globe-Cc-HpKJl.js +1 -0
- package/dist/assets/{rotate-ccw-DvjWccJd.js → image-CG70efEv.js} +1 -1
- package/dist/assets/index-CGcczV4D.js +14 -0
- package/dist/assets/info-CG1rlb3x.js +1 -0
- package/dist/assets/plus-8qyrJDmU.js +1 -0
- package/dist/assets/preload-helper-Bjj569kd.js +1 -0
- package/dist/assets/preload-helper-CsLomdVG.css +1 -0
- package/dist/assets/refresh-cw-ldhcYUWO.js +1 -0
- package/dist/assets/rotate-ccw-aSXT_vpV.js +1 -0
- package/dist/assets/send-CIIg_931.js +1 -0
- package/dist/assets/useNodes-CoHDhaah.js +1 -0
- package/dist/assets/useTaxonomies-_-T_4Iu-.js +1 -0
- package/dist/assets/x-Ds3gRwZk.js +1 -0
- package/dist/{dist-CpYaG9eL.js → dist-DHy8KsJ-.js} +200 -116
- package/dist/index.html +22 -12
- package/dist/index.js +203 -117
- package/dist/schema-compiler.js +1 -1
- package/documentation/FORMS.md +59 -25
- package/package.json +1 -1
- package/templates/astro-starter/src/components/blocks/Form.astro +48 -4
- package/templates/astro-starter/src/pages/api/forms/[...path].ts +23 -4
- package/dist/assets/AssetEditor-CAvQEsBT.js +0 -1
- package/dist/assets/CmsAccordion-91I5Rx5D.css +0 -1
- package/dist/assets/CmsAccordion-BgdaB8QZ.js +0 -1
- package/dist/assets/CmsFieldTaxonomy-CNY3-MbD.js +0 -1
- package/dist/assets/CmsHelp-DtPeURCv.js +0 -1
- package/dist/assets/CmsImagePreview-BhM7S_v8.js +0 -1
- package/dist/assets/CmsPublisher-DiQhfPID.js +0 -3
- package/dist/assets/EditorSplitPreview-BfGni85I.js +0 -1
- package/dist/assets/FormsWorkspace-CGs6eUjz.css +0 -1
- package/dist/assets/FormsWorkspace-CUK-y2dR.js +0 -2
- package/dist/assets/NodeContextMenu-C5RTK0sr.js +0 -1
- package/dist/assets/NodeEditor-C2meZIvc.css +0 -1
- package/dist/assets/NodeEditor-C5VQu52a.js +0 -161
- package/dist/assets/TrashWorkspace-t0lOrFRK.js +0 -1
- package/dist/assets/index-DTHhZNC5.js +0 -14
- package/dist/assets/preload-helper-BB8Wl1va.js +0 -1
- package/dist/assets/send-Bs4eROle.js +0 -1
- package/dist/assets/useNodes-D-Vuwq5_.js +0 -1
- package/dist/assets/x-DOWbsdzd.js +0 -1
|
@@ -21420,10 +21420,10 @@ var Nb = /* @__PURE__ */ o({
|
|
|
21420
21420
|
optionsLabelKey: "title",
|
|
21421
21421
|
rules: { required: !0 }
|
|
21422
21422
|
},
|
|
21423
|
-
|
|
21424
|
-
label: "
|
|
21425
|
-
type: "
|
|
21426
|
-
description: "Optional
|
|
21423
|
+
submitLabel: {
|
|
21424
|
+
label: "Submit Button Label",
|
|
21425
|
+
type: "string",
|
|
21426
|
+
description: "Optional override for the form's submit button label",
|
|
21427
21427
|
rules: {}
|
|
21428
21428
|
},
|
|
21429
21429
|
isHidden: {
|
|
@@ -29366,22 +29366,26 @@ ew.post("/purge", async (e) => {
|
|
|
29366
29366
|
}, 500);
|
|
29367
29367
|
}
|
|
29368
29368
|
});
|
|
29369
|
-
function tw(e) {
|
|
29369
|
+
function tw(e, t) {
|
|
29370
|
+
let n = (e) => e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
29371
|
+
return `<h2>${n(t)}</h2>` + e.map((e) => `<p><strong>${n(e.label || e.name)}:</strong> {{${e.name}}}</p>`).join("");
|
|
29372
|
+
}
|
|
29373
|
+
function nw(e) {
|
|
29370
29374
|
return e?.BUNDLED_DEFINITIONS ? MS(e.BUNDLED_DEFINITIONS).forms : e?.KAMA_RUNTIME === "node" || !e?.DB && !e?.kama_db ? MS().forms : MS(Fb).forms;
|
|
29371
29375
|
}
|
|
29372
|
-
function
|
|
29376
|
+
function rw(e, t) {
|
|
29373
29377
|
return Object.entries(e).find(([e, n]) => e === t || n.id === t)?.[1];
|
|
29374
29378
|
}
|
|
29375
|
-
function
|
|
29379
|
+
function iw(e) {
|
|
29376
29380
|
return Array.isArray(e.fields) ? e.fields : Object.entries(e.fields || {}).map(([e, t]) => ({
|
|
29377
29381
|
name: e,
|
|
29378
29382
|
...t
|
|
29379
29383
|
}));
|
|
29380
29384
|
}
|
|
29381
|
-
function
|
|
29382
|
-
return (e
|
|
29385
|
+
function aw(e) {
|
|
29386
|
+
return iw(e).flatMap((e) => e.type === "fieldset" && "fields" in e && Array.isArray(e.fields) ? e.fields : [e]);
|
|
29383
29387
|
}
|
|
29384
|
-
function
|
|
29388
|
+
function ow(e, t) {
|
|
29385
29389
|
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("Email overrides must be an object");
|
|
29386
29390
|
let n = e, r = /* @__PURE__ */ new Set([
|
|
29387
29391
|
"from",
|
|
@@ -29421,26 +29425,71 @@ function aw(e, t) {
|
|
|
29421
29425
|
if (i.fromName && i.fromNameField) throw Error("Set either fromName or fromNameField, not both");
|
|
29422
29426
|
return i;
|
|
29423
29427
|
}
|
|
29424
|
-
function
|
|
29428
|
+
function sw(e, t) {
|
|
29425
29429
|
if (!Array.isArray(e)) throw Error("Finishers must be a list");
|
|
29426
|
-
if (e.length > 10) throw Error("A form can have at most 10 finishers");
|
|
29430
|
+
if (e.length > 20 || e.filter((e) => e?.enabled !== !1 && e?.type !== "notification" && e?.type !== "redirect").length > 10) throw Error("A form can have at most 10 active side-effect finishers and 20 finishers total");
|
|
29427
29431
|
let n = /* @__PURE__ */ new Set(), r = [];
|
|
29428
29432
|
for (let [i, a] of e.entries()) {
|
|
29429
29433
|
if (!a || typeof a != "object" || Array.isArray(a)) throw Error("Each finisher must be an object");
|
|
29430
|
-
if (a.
|
|
29431
|
-
|
|
29434
|
+
if (typeof a.type != "string" || !/^[a-z][a-z0-9_-]*$/.test(a.type)) throw Error(`Invalid finisher type "${String(a.type)}"`);
|
|
29435
|
+
let e = a.id === void 0 ? a.type === "database" ? "save-submission" : `${a.type}-${i + 1}` : a.id;
|
|
29436
|
+
if (typeof e != "string" || !/^[a-z][a-z0-9_-]*$/.test(e) || n.has(e)) throw Error("Each finisher must have a unique ID using letters, numbers, hyphens, or underscores");
|
|
29437
|
+
if (n.add(e), a.type === "database") {
|
|
29432
29438
|
if (r.some((e) => e.type === "database")) throw Error("Only one database finisher is allowed");
|
|
29433
29439
|
r.push({
|
|
29434
|
-
id:
|
|
29440
|
+
id: e,
|
|
29435
29441
|
type: "database",
|
|
29436
|
-
enabled: !
|
|
29442
|
+
enabled: a.enabled !== !1
|
|
29437
29443
|
});
|
|
29438
29444
|
continue;
|
|
29439
29445
|
}
|
|
29440
|
-
if (
|
|
29441
|
-
|
|
29442
|
-
|
|
29443
|
-
|
|
29446
|
+
if ((a.type === "notification" || a.type === "redirect") && r.some((e) => e.type === a.type)) throw Error(`Only one ${a.type} finisher is allowed`);
|
|
29447
|
+
if (a.enabled === !1) {
|
|
29448
|
+
let t = JSON.stringify(a);
|
|
29449
|
+
if (t.length > 2e4) throw Error("Finisher settings are too large");
|
|
29450
|
+
r.push({
|
|
29451
|
+
...JSON.parse(t),
|
|
29452
|
+
id: e,
|
|
29453
|
+
enabled: !1
|
|
29454
|
+
});
|
|
29455
|
+
continue;
|
|
29456
|
+
}
|
|
29457
|
+
if (a.type === "notification") {
|
|
29458
|
+
if (typeof a.message != "string" || !a.message.trim() || a.message.length > 2e4) throw Error("Notification message must be non-empty text of at most 20000 characters");
|
|
29459
|
+
r.push({
|
|
29460
|
+
id: e,
|
|
29461
|
+
type: "notification",
|
|
29462
|
+
enabled: !0,
|
|
29463
|
+
message: a.message
|
|
29464
|
+
});
|
|
29465
|
+
continue;
|
|
29466
|
+
}
|
|
29467
|
+
if (a.type === "redirect") {
|
|
29468
|
+
let t = a.link;
|
|
29469
|
+
if (!t || typeof t != "object" || Array.isArray(t) || typeof t.href != "string") throw Error("Redirect requires a destination link");
|
|
29470
|
+
let n = t.href.trim();
|
|
29471
|
+
if (/[\u0000-\u0020\u007f\\]/.test(n) || !/^#node:\d+$/.test(n) && !/^\/(?!\/)/.test(n) && !/^https?:\/\/[^/]+/i.test(n)) throw Error("Redirect destination must be a page or an HTTP(S) URL");
|
|
29472
|
+
if (/^https?:\/\//i.test(n)) try {
|
|
29473
|
+
let e = new URL(n);
|
|
29474
|
+
if (!["http:", "https:"].includes(e.protocol) || !e.hostname) throw Error("Invalid URL");
|
|
29475
|
+
} catch {
|
|
29476
|
+
throw Error("Redirect destination must be a valid HTTP(S) URL");
|
|
29477
|
+
}
|
|
29478
|
+
let i = a.delay ?? 0;
|
|
29479
|
+
if (typeof i != "number" || !Number.isFinite(i) || i < 0 || i > 2147483) throw Error("Redirect delay must be between 0 and 2147483 seconds");
|
|
29480
|
+
r.push({
|
|
29481
|
+
id: e,
|
|
29482
|
+
type: "redirect",
|
|
29483
|
+
enabled: !0,
|
|
29484
|
+
link: {
|
|
29485
|
+
...t,
|
|
29486
|
+
href: n
|
|
29487
|
+
},
|
|
29488
|
+
delay: i
|
|
29489
|
+
});
|
|
29490
|
+
continue;
|
|
29491
|
+
}
|
|
29492
|
+
if (a.type !== "email") {
|
|
29444
29493
|
let t = JSON.stringify(a);
|
|
29445
29494
|
if (t.length > 8e3) throw Error("Custom finisher settings are too large");
|
|
29446
29495
|
r.push({
|
|
@@ -29461,7 +29510,7 @@ function ow(e, t) {
|
|
|
29461
29510
|
} else if (typeof a.to == "string" && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a.to.trim())) o.to = a.to.trim();
|
|
29462
29511
|
else if (Array.isArray(a.to) && a.to.length > 0 && a.to.every((e) => typeof e == "string" && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()))) o.to = a.to.map((e) => e.trim());
|
|
29463
29512
|
else throw Error("Email finishers need a valid recipient address or email field");
|
|
29464
|
-
Object.assign(o,
|
|
29513
|
+
Object.assign(o, ow({
|
|
29465
29514
|
from: a.from,
|
|
29466
29515
|
subject: a.subject,
|
|
29467
29516
|
subjectField: a.subjectField,
|
|
@@ -29475,12 +29524,12 @@ function ow(e, t) {
|
|
|
29475
29524
|
}
|
|
29476
29525
|
return r;
|
|
29477
29526
|
}
|
|
29478
|
-
async function
|
|
29527
|
+
async function cw(e, t, n, r, i, a = []) {
|
|
29479
29528
|
if (typeof t != "string" && typeof t != "number" || typeof n != "string" && typeof n != "number") throw Error("Invalid form block reference");
|
|
29480
|
-
let
|
|
29481
|
-
if (!Number.isSafeInteger(
|
|
29482
|
-
let
|
|
29483
|
-
for (let e of
|
|
29529
|
+
let o = Number(t), s = String(n).trim();
|
|
29530
|
+
if (!Number.isSafeInteger(o) || o < 1 || !s || s.length > 200) throw Error("Invalid form block reference");
|
|
29531
|
+
let c = await e.prepare("SELECT id, elementType, dataJson FROM content_blocks WHERE contentId = ? AND isDraft = 0").all(o), l = Array.isArray(c) ? c : c?.results || [], u;
|
|
29532
|
+
for (let e of l) {
|
|
29484
29533
|
let t;
|
|
29485
29534
|
try {
|
|
29486
29535
|
t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
@@ -29489,75 +29538,93 @@ async function sw(e, t, n, r, i) {
|
|
|
29489
29538
|
}
|
|
29490
29539
|
if (!t || typeof t != "object" || Array.isArray(t)) continue;
|
|
29491
29540
|
let n = String(t.blockId || t._instanceId || t.id || e.id || ""), r = String(e.elementType || "").toLowerCase();
|
|
29492
|
-
if (n ===
|
|
29541
|
+
if (n === s && [
|
|
29493
29542
|
"form",
|
|
29494
29543
|
"form-block",
|
|
29495
29544
|
"form_block"
|
|
29496
29545
|
].includes(r)) {
|
|
29497
|
-
|
|
29546
|
+
u = t;
|
|
29498
29547
|
break;
|
|
29499
29548
|
}
|
|
29500
29549
|
}
|
|
29501
|
-
if (!
|
|
29502
|
-
let
|
|
29503
|
-
if (
|
|
29550
|
+
if (!u || u.formId !== r) throw Error("Published form block was not found");
|
|
29551
|
+
let d = u.finisherOverrides;
|
|
29552
|
+
if (u.finisherOverridesMode !== "per-finisher") return u.finisherOverridesEnabled === !0 ? sw(d, i) : void 0;
|
|
29553
|
+
let f = sw(d, i);
|
|
29554
|
+
if (f.length === 0) return;
|
|
29555
|
+
let p = a.map((e, t) => ({
|
|
29556
|
+
...e,
|
|
29557
|
+
id: e.id || `${e.type}-${t + 1}`
|
|
29558
|
+
})), m = p.map((e) => {
|
|
29559
|
+
let t = f.find((t) => t.id === e.id);
|
|
29560
|
+
if (!t) return e;
|
|
29561
|
+
if (t.type !== e.type) throw Error(`Finisher "${e.id}" type cannot be changed in a block override`);
|
|
29562
|
+
return t;
|
|
29563
|
+
}), h = new Set(p.map((e) => e.id));
|
|
29564
|
+
return m.push(...f.filter((e) => !h.has(e.id || ""))), sw(m, i);
|
|
29504
29565
|
}
|
|
29505
|
-
async function
|
|
29506
|
-
let
|
|
29507
|
-
if (!
|
|
29508
|
-
|
|
29509
|
-
|
|
29510
|
-
|
|
29566
|
+
async function lw(e, t, n, r = !1) {
|
|
29567
|
+
let i = await e.prepare("SELECT finishers_json FROM kama_form_settings WHERE form_id = ?").get(t);
|
|
29568
|
+
if (!i) return (n.finishers || []).map((e, t) => ({
|
|
29569
|
+
...e,
|
|
29570
|
+
id: e.id || `${e.type}-${t + 1}`
|
|
29571
|
+
})).filter((e) => r || e.enabled !== !1);
|
|
29572
|
+
let a = JSON.parse(i.finishers_json);
|
|
29573
|
+
if (!Array.isArray(a)) throw Error(`Invalid stored finisher configuration for form "${t}"`);
|
|
29574
|
+
return a.map((e, t) => ({
|
|
29575
|
+
...e,
|
|
29576
|
+
id: e.id || `${e.type}-${t + 1}`
|
|
29577
|
+
})).filter((e) => r || e.enabled !== !1);
|
|
29511
29578
|
}
|
|
29512
|
-
var
|
|
29513
|
-
function
|
|
29579
|
+
var uw = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, dw = /* @__PURE__ */ new Map();
|
|
29580
|
+
function fw(e, t) {
|
|
29514
29581
|
if (!/^[a-z][a-z0-9_-]*$/.test(e)) throw Error(`Invalid form finisher type "${e}"`);
|
|
29515
|
-
if (
|
|
29516
|
-
return
|
|
29582
|
+
if (dw.has(e)) throw Error(`Form finisher "${e}" is already registered`);
|
|
29583
|
+
return dw.set(e, t), () => dw.delete(e);
|
|
29517
29584
|
}
|
|
29518
|
-
function
|
|
29519
|
-
return Array.from(
|
|
29585
|
+
function pw() {
|
|
29586
|
+
return Array.from(dw.keys());
|
|
29520
29587
|
}
|
|
29521
|
-
function
|
|
29522
|
-
if (typeof e != "string" || !
|
|
29588
|
+
function mw(e, t) {
|
|
29589
|
+
if (typeof e != "string" || !uw.test(e.trim())) throw Error(`${t} must be a valid email address`);
|
|
29523
29590
|
return e.trim();
|
|
29524
29591
|
}
|
|
29525
|
-
function
|
|
29592
|
+
function hw(e) {
|
|
29526
29593
|
return String(e ?? "").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
29527
29594
|
}
|
|
29528
|
-
function
|
|
29595
|
+
function gw(e, t, n = !1) {
|
|
29529
29596
|
return e.replace(/\{\{\s*([a-zA-Z0-9_.-]+)\s*\}\}/g, (e, r) => {
|
|
29530
29597
|
let i = t[r];
|
|
29531
|
-
return n ?
|
|
29598
|
+
return n ? hw(i) : String(i ?? "");
|
|
29532
29599
|
});
|
|
29533
29600
|
}
|
|
29534
|
-
function
|
|
29601
|
+
function _w(e, t, n) {
|
|
29535
29602
|
if (e != null && e !== "") {
|
|
29536
29603
|
if (typeof e != "string" || e.length > n || /[\r\n]/.test(e)) throw Error(`${t} must be text without line breaks and at most ${n} characters`);
|
|
29537
29604
|
return e.trim() || void 0;
|
|
29538
29605
|
}
|
|
29539
29606
|
}
|
|
29540
|
-
function
|
|
29541
|
-
let i =
|
|
29607
|
+
function vw(e, t, n, r) {
|
|
29608
|
+
let i = aw(e), a;
|
|
29542
29609
|
if (t.toField) {
|
|
29543
29610
|
let e = i.find((e) => e.name === t.toField);
|
|
29544
29611
|
if (!e || e.type !== "email") throw Error(`Email finisher recipient field "${t.toField}" must be an email field`);
|
|
29545
|
-
a =
|
|
29612
|
+
a = mw(n[t.toField], `Recipient field "${t.toField}"`);
|
|
29546
29613
|
} else if (Array.isArray(t.to)) {
|
|
29547
29614
|
if (t.to.length === 0) throw Error("Email finisher requires at least one recipient");
|
|
29548
|
-
a = t.to.map((e) =>
|
|
29549
|
-
} else a =
|
|
29550
|
-
let o =
|
|
29615
|
+
a = t.to.map((e) => mw(e, "Email finisher recipient"));
|
|
29616
|
+
} else a = mw(t.to, "Email finisher recipient");
|
|
29617
|
+
let o = mw(t.from || r.FORMS_EMAIL_FROM, t.from ? "Email finisher sender address" : "FORMS_EMAIL_FROM"), s = t.subjectField, c = t.subject || `New submission: ${e.title || e.id || "Form"}`, l = (s ? String(n[s] ?? "").trim() : "") || gw(c || "", n), u = _w(l == null ? "" : String(l), "Email subject", 200);
|
|
29551
29618
|
if (!u) throw Error("Email finisher subject must be non-empty and contain no line breaks");
|
|
29552
|
-
let d = t.fromNameField, f =
|
|
29619
|
+
let d = t.fromNameField, f = _w((d ? String(n[d] ?? "").trim() : "") || t.fromName || r.FORMS_EMAIL_FROM_NAME, "Email sender name", 120), p = f ? {
|
|
29553
29620
|
email: o,
|
|
29554
29621
|
name: f
|
|
29555
|
-
} : o, m = t.text, h = t.html, g = m ?
|
|
29622
|
+
} : o, m = t.text, h = t.html, g = m ? gw(m, n) : i.map((e) => `${e.label || e.name}: ${String(n[e.name] ?? "")}`).join("\n"), _ = gw(h || tw(i, e.title || e.id || "Form submission"), n, !0), v, y = t.replyToField, b = t.replyTo;
|
|
29556
29623
|
if (y) {
|
|
29557
29624
|
let e = i.find((e) => e.name === y);
|
|
29558
29625
|
if (!e || e.type !== "email") throw Error(`Email finisher reply-to field "${y}" must be an email field`);
|
|
29559
|
-
n[y] !== void 0 && String(n[y]).trim() && (v =
|
|
29560
|
-
} else b && (v =
|
|
29626
|
+
n[y] !== void 0 && String(n[y]).trim() && (v = mw(n[y], `Reply-to field "${y}"`));
|
|
29627
|
+
} else b && (v = mw(b, "Email finisher reply-to address"));
|
|
29561
29628
|
return {
|
|
29562
29629
|
from: p,
|
|
29563
29630
|
to: a,
|
|
@@ -29567,8 +29634,8 @@ function _w(e, t, n, r) {
|
|
|
29567
29634
|
...v ? { replyTo: v } : {}
|
|
29568
29635
|
};
|
|
29569
29636
|
}
|
|
29570
|
-
async function
|
|
29571
|
-
let { form: t, payload: n, env: r } = e, i = e.finisher, a =
|
|
29637
|
+
async function yw(e) {
|
|
29638
|
+
let { form: t, payload: n, env: r } = e, i = e.finisher, a = vw(t, i, n, r), o = r.FORMS_EMAIL_PROVIDER ?? "auto";
|
|
29572
29639
|
if (![
|
|
29573
29640
|
"auto",
|
|
29574
29641
|
"cloudflare",
|
|
@@ -29610,13 +29677,13 @@ async function vw(e) {
|
|
|
29610
29677
|
}
|
|
29611
29678
|
throw Error(`Unsupported email provider "${o}"`);
|
|
29612
29679
|
}
|
|
29613
|
-
|
|
29680
|
+
fw("database", async ({ db: e, formId: t, payload: n }) => {
|
|
29614
29681
|
await e.prepare("INSERT INTO kama_forms_table (form_id, payload_json, createdAt) VALUES (?, ?, CURRENT_TIMESTAMP)").run(t, JSON.stringify(n));
|
|
29615
|
-
}),
|
|
29616
|
-
async function
|
|
29617
|
-
let o = a ?? await
|
|
29618
|
-
for (let a of o) {
|
|
29619
|
-
let o =
|
|
29682
|
+
}), fw("email", yw), fw("notification", async () => {}), fw("redirect", async () => {});
|
|
29683
|
+
async function bw(e, t, n, r, i, a) {
|
|
29684
|
+
let o = a ?? await lw(r, t, e);
|
|
29685
|
+
for (let a of o.filter((e) => e.enabled !== !1)) {
|
|
29686
|
+
let o = dw.get(a.type);
|
|
29620
29687
|
if (!o) throw Error(`Unsupported form finisher type "${a.type}"`);
|
|
29621
29688
|
await o({
|
|
29622
29689
|
form: e,
|
|
@@ -29628,35 +29695,36 @@ async function yw(e, t, n, r, i, a) {
|
|
|
29628
29695
|
});
|
|
29629
29696
|
}
|
|
29630
29697
|
}
|
|
29631
|
-
var
|
|
29632
|
-
|
|
29633
|
-
let t =
|
|
29634
|
-
let r = t.id || e, i = await
|
|
29698
|
+
var xw = new e(), Sw = 99, Cw = 1e4;
|
|
29699
|
+
xw.get("/", async (e) => {
|
|
29700
|
+
let t = nw(e.env), n = e.get("db"), r = await Promise.all(Object.entries(t).map(async ([e, t]) => {
|
|
29701
|
+
let r = t.id || e, i = await lw(n, r, t);
|
|
29635
29702
|
return {
|
|
29636
29703
|
id: r,
|
|
29637
29704
|
title: t.title || e,
|
|
29638
29705
|
description: t.description || "",
|
|
29639
|
-
fieldsCount:
|
|
29706
|
+
fieldsCount: aw(t).length,
|
|
29640
29707
|
storesSubmissions: i.some((e) => e.type === "database"),
|
|
29641
29708
|
enabledFinishers: i.length
|
|
29642
29709
|
};
|
|
29643
29710
|
}));
|
|
29644
29711
|
return e.json(r);
|
|
29645
|
-
}),
|
|
29646
|
-
let t = e.req.param("formId"), n = nw(
|
|
29712
|
+
}), xw.get("/:formId/finishers", async (e) => {
|
|
29713
|
+
let t = e.req.param("formId"), n = rw(nw(e.env), t);
|
|
29647
29714
|
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
29648
29715
|
try {
|
|
29649
|
-
let r = await
|
|
29716
|
+
let r = await lw(e.get("db"), n.id || t, n, !0), i = r.filter((e) => e.type === "email" && e.enabled !== !1);
|
|
29650
29717
|
return e.json({
|
|
29651
29718
|
formId: n.id || t,
|
|
29652
29719
|
title: n.title || n.id || t,
|
|
29653
|
-
|
|
29720
|
+
successMessage: n.settings?.successMessage || "Form submitted successfully!",
|
|
29721
|
+
fields: aw(n).map((e) => ({
|
|
29654
29722
|
name: e.name,
|
|
29655
29723
|
label: e.label || e.name,
|
|
29656
29724
|
type: e.type || "text"
|
|
29657
29725
|
})),
|
|
29658
29726
|
finishers: r,
|
|
29659
|
-
availableFinishers:
|
|
29727
|
+
availableFinishers: pw(),
|
|
29660
29728
|
emailTransport: {
|
|
29661
29729
|
provider: e.env?.FORMS_EMAIL_PROVIDER ?? "auto",
|
|
29662
29730
|
cloudflare: typeof e.env?.FORMS_EMAIL?.send == "function",
|
|
@@ -29667,12 +29735,12 @@ bw.get("/", async (e) => {
|
|
|
29667
29735
|
} catch (n) {
|
|
29668
29736
|
return console.error(`[Forms] Failed to load finisher settings for ${t}:`, n), e.json({ error: "Failed to load form settings" }, 500);
|
|
29669
29737
|
}
|
|
29670
|
-
}),
|
|
29671
|
-
let t = e.req.param("formId"), n = nw(
|
|
29738
|
+
}), xw.put("/:formId/finishers", async (e) => {
|
|
29739
|
+
let t = e.req.param("formId"), n = rw(nw(e.env), t);
|
|
29672
29740
|
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
29673
29741
|
let r;
|
|
29674
29742
|
try {
|
|
29675
|
-
r =
|
|
29743
|
+
r = sw((await e.req.json())?.finishers, aw(n));
|
|
29676
29744
|
} catch (t) {
|
|
29677
29745
|
return e.json({ error: t instanceof Error ? t.message : "Invalid form settings" }, 400);
|
|
29678
29746
|
}
|
|
@@ -29684,12 +29752,12 @@ bw.get("/", async (e) => {
|
|
|
29684
29752
|
} catch (n) {
|
|
29685
29753
|
return console.error(`[Forms] Failed to save finisher settings for ${t}:`, n), e.json({ error: "Failed to save form settings" }, 500);
|
|
29686
29754
|
}
|
|
29687
|
-
}),
|
|
29688
|
-
let t = e.req.param("formId"), n = nw(
|
|
29755
|
+
}), xw.get("/:formId/submissions", async (e) => {
|
|
29756
|
+
let t = e.req.param("formId"), n = rw(nw(e.env), t);
|
|
29689
29757
|
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
29690
29758
|
let r = n.id || t;
|
|
29691
29759
|
try {
|
|
29692
|
-
let t = e.get("db"), i = (await
|
|
29760
|
+
let t = e.get("db"), i = (await lw(t, r, n)).some((e) => e.type === "database"), a = aw(n).map((e) => ({
|
|
29693
29761
|
name: e.name,
|
|
29694
29762
|
label: e.label || e.name
|
|
29695
29763
|
}));
|
|
@@ -29713,8 +29781,8 @@ bw.get("/", async (e) => {
|
|
|
29713
29781
|
} catch (n) {
|
|
29714
29782
|
return console.error(`[Forms] Failed to load submissions for ${t}:`, n), e.json({ error: "Failed to load form submissions" }, 500);
|
|
29715
29783
|
}
|
|
29716
|
-
}),
|
|
29717
|
-
let t = e.req.param("formId"), n = nw(
|
|
29784
|
+
}), xw.delete("/:formId/submissions/:submissionId", async (e) => {
|
|
29785
|
+
let t = e.req.param("formId"), n = rw(nw(e.env), t);
|
|
29718
29786
|
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
29719
29787
|
let r = e.req.param("submissionId");
|
|
29720
29788
|
if (!/^[1-9]\d*$/.test(r)) return e.json({ error: "Invalid submission ID" }, 400);
|
|
@@ -29729,14 +29797,14 @@ bw.get("/", async (e) => {
|
|
|
29729
29797
|
} catch (n) {
|
|
29730
29798
|
return console.error(`[Forms] Failed to delete submission ${i} for ${t}:`, n), e.json({ error: "Failed to delete form submission" }, 500);
|
|
29731
29799
|
}
|
|
29732
|
-
}),
|
|
29733
|
-
let t = e.req.param("formId"), n = nw(
|
|
29800
|
+
}), xw.delete("/:formId/submissions", async (e) => {
|
|
29801
|
+
let t = e.req.param("formId"), n = rw(nw(e.env), t);
|
|
29734
29802
|
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
29735
29803
|
let r;
|
|
29736
29804
|
try {
|
|
29737
29805
|
let t = await e.req.json();
|
|
29738
29806
|
if (!t || !Array.isArray(t.ids) || t.ids.length === 0) return e.json({ error: "A non-empty list of submission IDs is required" }, 400);
|
|
29739
|
-
if (t.ids.length >
|
|
29807
|
+
if (t.ids.length > Cw) return e.json({ error: `At most ${Cw} submissions can be deleted at once` }, 400);
|
|
29740
29808
|
let n = [];
|
|
29741
29809
|
for (let r of t.ids) {
|
|
29742
29810
|
if (typeof r != "number" || !Number.isSafeInteger(r) || r < 1) return e.json({ error: "Submission IDs must be positive integers" }, 400);
|
|
@@ -29748,8 +29816,8 @@ bw.get("/", async (e) => {
|
|
|
29748
29816
|
}
|
|
29749
29817
|
try {
|
|
29750
29818
|
let i = e.get("db"), a = 0;
|
|
29751
|
-
for (let e = 0; e < r.length; e +=
|
|
29752
|
-
let o = r.slice(e, e +
|
|
29819
|
+
for (let e = 0; e < r.length; e += Sw) {
|
|
29820
|
+
let o = r.slice(e, e + Sw), s = o.map(() => "?").join(", "), c = await i.prepare(`DELETE FROM kama_forms_table WHERE form_id = ? AND id IN (${s})`).run(n.id || t, ...o);
|
|
29753
29821
|
a += c.changes || 0;
|
|
29754
29822
|
}
|
|
29755
29823
|
return e.json({
|
|
@@ -29760,8 +29828,8 @@ bw.get("/", async (e) => {
|
|
|
29760
29828
|
return console.error(`[Forms] Failed to bulk-delete submissions for ${t}:`, n), e.json({ error: "Failed to delete form submissions" }, 500);
|
|
29761
29829
|
}
|
|
29762
29830
|
});
|
|
29763
|
-
var
|
|
29764
|
-
function
|
|
29831
|
+
var ww = new e();
|
|
29832
|
+
function Tw(e, t) {
|
|
29765
29833
|
let n = {};
|
|
29766
29834
|
try {
|
|
29767
29835
|
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson || {};
|
|
@@ -29777,7 +29845,7 @@ function ww(e, t) {
|
|
|
29777
29845
|
return null;
|
|
29778
29846
|
}
|
|
29779
29847
|
}
|
|
29780
|
-
|
|
29848
|
+
ww.get("/:nodeId", async (e) => {
|
|
29781
29849
|
let t = Number(e.req.param("nodeId")), n = e.req.query("channelId"), r = e.req.query("path") || "", i = e.req.query("revisionId");
|
|
29782
29850
|
if (!Number.isSafeInteger(t) || t < 1 || !n) return e.json({ error: "A valid node and channel are required for preview." }, 400);
|
|
29783
29851
|
if (!r.startsWith("/") || r.startsWith("//") || r.includes("\\") || /[\u0000-\u001f]/.test(r)) return e.json({ error: "Preview path must be an absolute site path." }, 400);
|
|
@@ -29787,7 +29855,7 @@ Cw.get("/:nodeId", async (e) => {
|
|
|
29787
29855
|
if (i && !await a.prepare("SELECT 1 FROM node_revisions WHERE nodeId = ? AND version = ? LIMIT 1").get(t, Number(i))) return e.json({ error: "Revision not found for this node." }, 404);
|
|
29788
29856
|
let o = await a.prepare("SELECT id, baseUrl, dataJson FROM channels WHERE id = ? OR key = ? LIMIT 1").get(Number(n) || -1, n);
|
|
29789
29857
|
if (!o) return e.json({ error: "Preview channel not found." }, 404);
|
|
29790
|
-
let s =
|
|
29858
|
+
let s = Tw(o, e.env || {});
|
|
29791
29859
|
if (!s) return e.json({ error: "The channel has no valid frontend URL configured." }, 503);
|
|
29792
29860
|
let c = new URL(s);
|
|
29793
29861
|
c.pathname = `${c.pathname.replace(/\/+$/, "")}${r}`, c.searchParams.set("preview", "true"), i && c.searchParams.set("revisionId", i), c.searchParams.set("_cms_preview", Date.now().toString());
|
|
@@ -29816,26 +29884,28 @@ Cw.get("/:nodeId", async (e) => {
|
|
|
29816
29884
|
}
|
|
29817
29885
|
});
|
|
29818
29886
|
});
|
|
29819
|
-
var
|
|
29820
|
-
|
|
29821
|
-
let t = e.req.param("formId"), n = nw(
|
|
29887
|
+
var Ew = new e();
|
|
29888
|
+
Ew.get("/:formId", (e) => {
|
|
29889
|
+
let t = e.req.param("formId"), n = rw(nw(e.env), t);
|
|
29822
29890
|
return n ? e.json({
|
|
29823
29891
|
id: n.id || t,
|
|
29824
29892
|
title: n.title || "",
|
|
29825
29893
|
description: n.description || "",
|
|
29826
|
-
fields:
|
|
29894
|
+
fields: aw(n),
|
|
29895
|
+
layout: iw(n),
|
|
29827
29896
|
settings: {
|
|
29828
29897
|
successMessage: n.settings?.successMessage || "Form submitted successfully!",
|
|
29829
|
-
requireTurnstile: n.settings?.requireTurnstile === !0
|
|
29898
|
+
requireTurnstile: n.settings?.requireTurnstile === !0,
|
|
29899
|
+
submitLabel: n.settings?.submitLabel || "Submit"
|
|
29830
29900
|
}
|
|
29831
29901
|
}) : e.json({ error: "Form definition not found" }, 404);
|
|
29832
|
-
}),
|
|
29833
|
-
let t = e.req.param("formId"), n = nw(
|
|
29902
|
+
}), Ew.post("/:formId/submissions", async (e) => {
|
|
29903
|
+
let t = e.req.param("formId"), n = rw(nw(e.env), t);
|
|
29834
29904
|
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
29835
29905
|
try {
|
|
29836
29906
|
let r = await e.req.json();
|
|
29837
29907
|
if (!r || typeof r != "object" || Array.isArray(r)) return e.json({ error: "Invalid form submission" }, 400);
|
|
29838
|
-
let i =
|
|
29908
|
+
let i = aw(n), a = r["cf-turnstile-response"];
|
|
29839
29909
|
if (n.settings?.requireTurnstile === !0) {
|
|
29840
29910
|
if (typeof a != "string" || !a) return e.json({ error: "Security verification failed. Please complete the captcha." }, 400);
|
|
29841
29911
|
let n = e.env?.KAMA_RUNTIME === "node" && (e.env?.NODE_ENV || (typeof process < "u" ? process.env.NODE_ENV : void 0)) !== "production", r = e.env?.TURNSTILE_SECRET_KEY || (typeof process < "u" ? process.env.TURNSTILE_SECRET_KEY : void 0) || (n ? "1x0000000000000000000000000000000AA" : void 0);
|
|
@@ -29858,21 +29928,35 @@ Tw.get("/:formId", (e) => {
|
|
|
29858
29928
|
if (t.required && (n == null || String(n).trim() === "")) return e.json({ error: `Field "${t.label || t.name}" is required` }, 400);
|
|
29859
29929
|
n !== void 0 && (o[t.name] = n);
|
|
29860
29930
|
}
|
|
29861
|
-
let s;
|
|
29931
|
+
let s = await lw(e.get("db"), n.id || t, n, !0), c;
|
|
29862
29932
|
try {
|
|
29863
|
-
r._kamaFinisherBlockId !== void 0 && (
|
|
29933
|
+
r._kamaFinisherBlockId !== void 0 && (c = await cw(e.get("db"), r._kamaFinisherContentId, r._kamaFinisherBlockId, n.id || t, i, s));
|
|
29864
29934
|
} catch (t) {
|
|
29865
29935
|
return e.json({ error: t instanceof Error ? t.message : "Invalid form block settings" }, 400);
|
|
29866
29936
|
}
|
|
29867
|
-
|
|
29937
|
+
let l = c ?? s, u = l.find((e) => e.type === "notification"), d = l.find((e) => e.type === "redirect" && e.enabled !== !1), f;
|
|
29938
|
+
if (d) {
|
|
29939
|
+
let t = sw([d], i)[0].link.href, n = /^#node:(\d+)$/.exec(t);
|
|
29940
|
+
if (n) {
|
|
29941
|
+
let t = typeof r._kamaChannelId == "string" ? r._kamaChannelId : "", i = t ? await e.get("db").prepare("SELECT id FROM channels WHERE id = ? OR key = ? LIMIT 1").get(t, t) : null, a = await e.get("db").prepare("\n SELECT path FROM node_routes WHERE nodeId = ? AND isCanonical = 1\n ORDER BY CASE WHEN channelId = ? THEN 0 ELSE 1 END ASC LIMIT 1\n ").get(Number(n[1]), i?.id ?? -1);
|
|
29942
|
+
if (typeof a?.path != "string" || !/^\/(?!\/)/.test(a.path) || /[\u0000-\u0020\u007f\\]/.test(a.path)) throw Error("Redirect page has no valid published route");
|
|
29943
|
+
f = a.path;
|
|
29944
|
+
} else f = t;
|
|
29945
|
+
}
|
|
29946
|
+
return await bw(n, n.id || t, o, e.get("db"), e.env, l), e.json({
|
|
29868
29947
|
success: !0,
|
|
29869
|
-
message: n.settings?.successMessage || "Form submitted successfully!"
|
|
29948
|
+
message: n.settings?.successMessage || "Form submitted successfully!",
|
|
29949
|
+
notification: u ? u.enabled === !1 ? null : u.message : void 0,
|
|
29950
|
+
redirect: f ? {
|
|
29951
|
+
url: f,
|
|
29952
|
+
delay: d?.delay ?? 0
|
|
29953
|
+
} : void 0
|
|
29870
29954
|
});
|
|
29871
29955
|
} catch (n) {
|
|
29872
29956
|
return console.error(`[Forms] Failed to process submission for ${t}:`, n), e.json({ error: "Failed to process submission" }, 500);
|
|
29873
29957
|
}
|
|
29874
29958
|
});
|
|
29875
|
-
var $ = new ab(),
|
|
29959
|
+
var $ = new ab(), Dw = !1, Ow = null;
|
|
29876
29960
|
$.use("*", t()), $.use("/media/*", t({
|
|
29877
29961
|
origin: "*",
|
|
29878
29962
|
allowMethods: [
|
|
@@ -29892,23 +29976,23 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
29892
29976
|
let n = new URL(e.req.url), r = (e.req.header("host") || n.hostname).split(":")[0];
|
|
29893
29977
|
e.set("currentDomain", r);
|
|
29894
29978
|
let i = Mb(e);
|
|
29895
|
-
if (e.set("db", i), !
|
|
29896
|
-
|
|
29897
|
-
await Bb(i, e.env?.BUNDLED_DEFINITIONS), await rx(i, e.env || {}),
|
|
29979
|
+
if (e.set("db", i), !Dw) {
|
|
29980
|
+
Ow ||= (async () => {
|
|
29981
|
+
await Bb(i, e.env?.BUNDLED_DEFINITIONS), await rx(i, e.env || {}), Dw = !0;
|
|
29898
29982
|
})();
|
|
29899
29983
|
try {
|
|
29900
|
-
await
|
|
29984
|
+
await Ow;
|
|
29901
29985
|
} catch (e) {
|
|
29902
|
-
|
|
29986
|
+
Ow = null, console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
29903
29987
|
}
|
|
29904
29988
|
}
|
|
29905
29989
|
await t();
|
|
29906
|
-
}), $.route("/media", LC), $.use("/media/*", Hb()), $.route("/api/auth", ax), $.use("/api/cms", ix), $.use("/api/cms/*", ix), $.use("/api/admin/assets", ix), $.use("/api/admin/*", ix), $.route("/api/cms/nodes", Hx), $.route("/api/cms/nodes.json", Hx), $.route("/api/cms/formcsv", Hx), $.route("/api/cms/formcsv.json", Hx), $.route("/api/cms/stats", zS), $.route("/api/cms/stats.json", zS), $.route("/api/cms", lS), $.route("/api/cms/trees.json", lS), $.route("/api/cms/channels", pS), $.route("/api/cms/channels.json", pS), $.route("/api/cms/taxonomies", mS), $.route("/api/cms/taxonomies.json", mS), $.route("/api/cms/cache", ew), $.route("/api/cms/cache.json", ew), $.route("/api/cms/schemas", PS), $.route("/api/cms/schemas.json", PS), $.route("/api/cms", IS), $.route("/api/admin/assets", BS), $.route("/api/cms/forms",
|
|
29907
|
-
var
|
|
29990
|
+
}), $.route("/media", LC), $.use("/media/*", Hb()), $.route("/api/auth", ax), $.use("/api/cms", ix), $.use("/api/cms/*", ix), $.use("/api/admin/assets", ix), $.use("/api/admin/*", ix), $.route("/api/cms/nodes", Hx), $.route("/api/cms/nodes.json", Hx), $.route("/api/cms/formcsv", Hx), $.route("/api/cms/formcsv.json", Hx), $.route("/api/cms/stats", zS), $.route("/api/cms/stats.json", zS), $.route("/api/cms", lS), $.route("/api/cms/trees.json", lS), $.route("/api/cms/channels", pS), $.route("/api/cms/channels.json", pS), $.route("/api/cms/taxonomies", mS), $.route("/api/cms/taxonomies.json", mS), $.route("/api/cms/cache", ew), $.route("/api/cms/cache.json", ew), $.route("/api/cms/schemas", PS), $.route("/api/cms/schemas.json", PS), $.route("/api/cms", IS), $.route("/api/admin/assets", BS), $.route("/api/cms/forms", xw), $.route("/api/cms/preview-site", ww);
|
|
29991
|
+
var kw = (e) => {
|
|
29908
29992
|
let t = new URL(e.req.url);
|
|
29909
29993
|
return t.pathname = t.pathname.replace("/api/cms/preview-payload", "/api/v1/node"), GS.fetch(new Request(t, e.req.raw), e.env);
|
|
29910
29994
|
};
|
|
29911
|
-
$.use("/api/cms/preview-payload", ix), $.use("/api/cms/preview-payload/*", ix), $.all("/api/cms/preview-payload",
|
|
29995
|
+
$.use("/api/cms/preview-payload", ix), $.use("/api/cms/preview-payload/*", ix), $.all("/api/cms/preview-payload", kw), $.all("/api/cms/preview-payload/*", kw), $.use("/api/v1/*", async (e, t) => e.req.query("preview") === "true" || e.req.query("revisionId") ? ix(e, t) : t()), $.use("/api/v1/*", async (e, t) => {
|
|
29912
29996
|
if (e.req.path.startsWith("/api/v1/forms/")) return t();
|
|
29913
29997
|
let n = e.env?.FRONTEND_API_SECRET;
|
|
29914
29998
|
if (n) {
|
|
@@ -29916,7 +30000,7 @@ $.use("/api/cms/preview-payload", ix), $.use("/api/cms/preview-payload/*", ix),
|
|
|
29916
30000
|
if (!i || i !== n) return e.json({ error: "Unauthorized: Invalid or missing API secret." }, 401);
|
|
29917
30001
|
} else console.warn("⚠️ [CMS Security] FRONTEND_API_SECRET is not set in .env. The API is completely exposed to the public.");
|
|
29918
30002
|
return t();
|
|
29919
|
-
}), $.route("/api/v1/forms",
|
|
30003
|
+
}), $.route("/api/v1/forms", Ew), $.route("/api/v1/node", GS), $.route("/api/v1/nodes", dC), $.route("/api/v1/tree", hC), $.route("/api/v1/channel", wC), $.route("/api/v1/all-paths", HC), $.route("/api/v1/taxonomies", JC), $.doc("/api/openapi.json", {
|
|
29920
30004
|
openapi: "3.0.0",
|
|
29921
30005
|
info: {
|
|
29922
30006
|
title: "KAMA Engine Public API",
|