@brightsideoy/kama 1.0.0-alpha.22 → 1.0.0-alpha.23
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/assets/{AssetEditor-DW0KuNhg.js → AssetEditor-B5YK3NZZ.js} +1 -1
- package/dist/assets/{CmsFieldTaxonomy-ZB3iCGJl.js → CmsFieldTaxonomy-DpAR9hiH.js} +1 -1
- package/dist/assets/{CmsHelp-y1my4i_c.js → CmsHelp-DwhLI-mW.js} +1 -1
- package/dist/assets/{CmsPublisher-BOylClC7.js → CmsPublisher-Dmgl7E5H.js} +1 -1
- package/dist/assets/EditorSplitPreview-DkLHfob8.js +1 -0
- package/dist/assets/{FormsWorkspace-5Mk4ulr5.js → FormsWorkspace-Dx-yu7Rn.js} +1 -1
- package/dist/assets/NodeEditor-5Caiaqod.js +161 -0
- package/dist/assets/NodeEditor-rrOvlGF8.css +1 -0
- package/dist/assets/{TrashWorkspace-Cot9mtw0.js → TrashWorkspace-CeZzWZEm.js} +1 -1
- package/dist/assets/index-CgystKmt.js +16 -0
- package/dist/assets/index-Cktd5m_n.css +1 -0
- package/dist/assets/{plus-DwPH9Xh7.js → plus-DMowrLHc.js} +1 -1
- package/dist/assets/preload-helper-CstCHdlQ.js +1 -0
- package/dist/assets/{useCmsState-Bc7cgBp5.js → useCmsState-aep6ZB35.js} +1 -1
- package/dist/assets/useNodes-DpypEHNz.js +1 -0
- package/dist/assets/x-3cfZis8N.js +1 -0
- package/dist/{dist-CVtRUnHl.js → dist-BP62QUQb.js} +1321 -917
- package/dist/index.html +7 -7
- package/dist/index.js +3595 -3183
- package/dist/{nodemailer-Ccic7tRm-KQqZAWb5.js → nodemailer-Ccic7tRm-Cf8qGuYa.js} +1 -1
- package/dist/schema-compiler.js +1 -1
- package/documentation/FORMS.md +15 -6
- package/package.json +1 -1
- package/templates/astro-starter/src/components/blocks/BlockRenderer.astro +2 -1
- package/templates/astro-starter/src/components/blocks/Form.astro +133 -15
- package/dist/assets/EditorSplitPreview-c4y6AaHo.js +0 -1
- package/dist/assets/NodeEditor-CMVD5LSR.css +0 -1
- package/dist/assets/NodeEditor-DLhgHaBi.js +0 -161
- package/dist/assets/index-CXtujYMT.js +0 -16
- package/dist/assets/index-M4hAA5qU.css +0 -1
- package/dist/assets/preload-helper-oCQc7Owg.js +0 -1
- package/dist/assets/useLocalStorage-DO_mDpwe.js +0 -1
- package/dist/assets/useNodes-DlRMd4Br.js +0 -1
|
@@ -120,7 +120,7 @@ function C(e, t) {
|
|
|
120
120
|
let n = Object.keys(e);
|
|
121
121
|
return Object.keys(t).every((e) => n.indexOf(e) !== -1) && n.every((n) => C(e[n], t[n]));
|
|
122
122
|
}
|
|
123
|
-
var
|
|
123
|
+
var ee = class {
|
|
124
124
|
constructor() {
|
|
125
125
|
this.buckets = /* @__PURE__ */ new Map();
|
|
126
126
|
}
|
|
@@ -165,39 +165,39 @@ var w = class {
|
|
|
165
165
|
return t;
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
function
|
|
168
|
+
function w(e) {
|
|
169
169
|
return e === void 0;
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function te(e, t) {
|
|
172
172
|
let n = {};
|
|
173
173
|
return Object.entries(e).forEach(([e, r]) => {
|
|
174
174
|
n[e] = t(r);
|
|
175
175
|
}), n;
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function ne(e, t) {
|
|
178
178
|
let n = {};
|
|
179
179
|
return Object.entries(e).forEach(([e, r]) => {
|
|
180
180
|
t.some((t) => t === e) || (n[e] = r);
|
|
181
181
|
}), n;
|
|
182
182
|
}
|
|
183
|
-
function
|
|
183
|
+
function T(e, t) {
|
|
184
184
|
let n = {};
|
|
185
185
|
return Object.entries(e).forEach(([e, r]) => {
|
|
186
186
|
t(r, e) || (n[e] = r);
|
|
187
187
|
}), n;
|
|
188
188
|
}
|
|
189
|
-
function
|
|
190
|
-
return e.filter((e) => !
|
|
189
|
+
function E(e) {
|
|
190
|
+
return e.filter((e) => !w(e));
|
|
191
191
|
}
|
|
192
|
-
var
|
|
193
|
-
function
|
|
194
|
-
let t = new
|
|
192
|
+
var D = C;
|
|
193
|
+
function O(e) {
|
|
194
|
+
let t = new ee();
|
|
195
195
|
return e.forEach((e) => t.put(e)), [...t.values()];
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function re(e) {
|
|
198
198
|
return typeof e == "string";
|
|
199
199
|
}
|
|
200
|
-
function
|
|
200
|
+
function k(e) {
|
|
201
201
|
return Object.fromEntries(Object.entries(e).sort(([e], [t]) => e.localeCompare(t)));
|
|
202
202
|
}
|
|
203
203
|
var A = S(), j = class {
|
|
@@ -233,13 +233,13 @@ var A = S(), j = class {
|
|
|
233
233
|
return Object.assign(Object.assign({}, t), { param: Object.assign(Object.assign({}, t?.description ? { description: t.description } : {}), t?.param) });
|
|
234
234
|
}
|
|
235
235
|
static buildSchemaMetadata(e) {
|
|
236
|
-
return
|
|
236
|
+
return T(ne(e, ["param", "_internal"]), w);
|
|
237
237
|
}
|
|
238
238
|
static buildParameterMetadata(e) {
|
|
239
|
-
return
|
|
239
|
+
return T(e, w);
|
|
240
240
|
}
|
|
241
241
|
static applySchemaMetadata(e, t) {
|
|
242
|
-
return
|
|
242
|
+
return T(Object.assign(Object.assign({}, e), this.buildSchemaMetadata(t)), w);
|
|
243
243
|
}
|
|
244
244
|
static getRefId(e) {
|
|
245
245
|
return this.getInternalMetadata(e)?.refId;
|
|
@@ -327,7 +327,7 @@ function oe(e, t, n) {
|
|
|
327
327
|
};
|
|
328
328
|
}
|
|
329
329
|
function se(e) {
|
|
330
|
-
return
|
|
330
|
+
return T(j.getOpenApiMetadata(e) ?? {}, w);
|
|
331
331
|
}
|
|
332
332
|
var ce = class {
|
|
333
333
|
constructor(e) {
|
|
@@ -438,7 +438,7 @@ var pe = class extends le {
|
|
|
438
438
|
getDiscriminatorValues(e, t) {
|
|
439
439
|
if (_(e, "ZodObject")) {
|
|
440
440
|
let n = e.def.shape?.[t];
|
|
441
|
-
return n ? _(n, "ZodEnum") ? Object.values(n._zod.def.entries).filter(
|
|
441
|
+
return n ? _(n, "ZodEnum") ? Object.values(n._zod.def.entries).filter(re) : _(n, "ZodLiteral") ? n.def.values.filter(re) : [] : [];
|
|
442
442
|
}
|
|
443
443
|
if (_(e, "ZodDiscriminatedUnion")) {
|
|
444
444
|
let n = e.def.options.filter(v);
|
|
@@ -484,14 +484,14 @@ var ve = class {
|
|
|
484
484
|
}
|
|
485
485
|
}, Se = class {
|
|
486
486
|
transform(e, t, n, r) {
|
|
487
|
-
let i = j.getInternalMetadata(e)?.extendedFrom, a = this.requiredKeysOf(e), o =
|
|
487
|
+
let i = j.getInternalMetadata(e)?.extendedFrom, a = this.requiredKeysOf(e), o = te(e.def.shape, r);
|
|
488
488
|
if (!i) return Object.assign(Object.assign(Object.assign(Object.assign({}, n("object")), {
|
|
489
489
|
properties: o,
|
|
490
490
|
default: t
|
|
491
491
|
}), a.length > 0 ? { required: a } : {}), this.generateAdditionalProperties(e, r));
|
|
492
492
|
let s = i.schema;
|
|
493
493
|
r(s);
|
|
494
|
-
let c = this.requiredKeysOf(s), l =
|
|
494
|
+
let c = this.requiredKeysOf(s), l = te(s?.def.shape, r), u = Object.fromEntries(Object.entries(o).filter(([e, t]) => !D(l[e], t))), d = a.filter((e) => !c.includes(e)), f = Object.assign(Object.assign(Object.assign(Object.assign({}, n("object")), {
|
|
495
495
|
default: t,
|
|
496
496
|
properties: u
|
|
497
497
|
}), d.length > 0 ? { required: d } : {}), this.generateAdditionalProperties(e, r));
|
|
@@ -508,7 +508,7 @@ var ve = class {
|
|
|
508
508
|
transform(e, t, n) {
|
|
509
509
|
let r = e.valueType, i = e.keyType, a = v(r) ? n(r) : {};
|
|
510
510
|
if (_(i, "ZodEnum")) {
|
|
511
|
-
let e = Object.values(i._zod.def.entries).filter(
|
|
511
|
+
let e = Object.values(i._zod.def.entries).filter(re).reduce((e, t) => Object.assign(Object.assign({}, e), { [t]: a }), {});
|
|
512
512
|
return Object.assign(Object.assign({}, t("object")), { properties: e });
|
|
513
513
|
}
|
|
514
514
|
return Object.assign(Object.assign({}, t("object")), { additionalProperties: a });
|
|
@@ -659,7 +659,7 @@ var Ee = class {
|
|
|
659
659
|
this.rawComponents.forEach(({ componentType: t, name: n, component: r }) => {
|
|
660
660
|
e[t] ?? (e[t] = {}), e[t][n] = r;
|
|
661
661
|
});
|
|
662
|
-
let t = e.schemas ?? {}, n = Object.assign(Object.assign({}, t), this.filteredSchemaRefs), r = this.options?.sortComponents === "alphabetically" ?
|
|
662
|
+
let t = e.schemas ?? {}, n = Object.assign(Object.assign({}, t), this.filteredSchemaRefs), r = this.options?.sortComponents === "alphabetically" ? k(n) : n, i = e.parameters ?? {}, a = Object.assign(Object.assign({}, i), this.paramRefs), o = this.options?.sortComponents === "alphabetically" ? k(a) : a;
|
|
663
663
|
return Object.assign(Object.assign({}, e), {
|
|
664
664
|
schemas: r,
|
|
665
665
|
parameters: o
|
|
@@ -711,7 +711,7 @@ var Ee = class {
|
|
|
711
711
|
if (!(!r?.refId || !a)) {
|
|
712
712
|
if (i && a.in !== i.in || t?.in && a.in !== t.in) throw new ue(`Conflicting location for parameter ${a.name}`, {
|
|
713
713
|
key: "in",
|
|
714
|
-
values:
|
|
714
|
+
values: E([
|
|
715
715
|
a.in,
|
|
716
716
|
t?.in,
|
|
717
717
|
i?.in
|
|
@@ -719,7 +719,7 @@ var Ee = class {
|
|
|
719
719
|
});
|
|
720
720
|
if (i && a.name !== i.name || t?.name && a.name !== t?.name) throw new ue("Conflicting names for parameter", {
|
|
721
721
|
key: "name",
|
|
722
|
-
values:
|
|
722
|
+
values: E([
|
|
723
723
|
a.name,
|
|
724
724
|
t?.name,
|
|
725
725
|
i?.name
|
|
@@ -789,7 +789,7 @@ var Ee = class {
|
|
|
789
789
|
}
|
|
790
790
|
i && !this.schemaRefs[i] && (this.schemaRefs[i] = "pending");
|
|
791
791
|
let a = n?.type ? { type: n.type } : this.toOpenAPISchema(t, y(e), r);
|
|
792
|
-
return n ? j.applySchemaMetadata(a, n) :
|
|
792
|
+
return n ? j.applySchemaMetadata(a, n) : T(a, w);
|
|
793
793
|
}
|
|
794
794
|
constructReferencedOpenAPISchema(e) {
|
|
795
795
|
let t = j.getOpenApiMetadata(e), n = j.unwrapChained(e), r = j.getDefaultValue(e), i = y(e);
|
|
@@ -807,9 +807,9 @@ var Ee = class {
|
|
|
807
807
|
if (!n || !this.schemaRefs[n]) return this.generateSchemaWithMetadata(e);
|
|
808
808
|
let r = this.schemaRefs[n], i = { $ref: this.generateSchemaRef(n) };
|
|
809
809
|
if (this.schemaRefs[n] === "pending") return this.versionSpecifics.mapNullableOfRef(i, y(e));
|
|
810
|
-
let a =
|
|
810
|
+
let a = T(j.buildSchemaMetadata(t ?? {}), (e, t) => e === void 0 || D(e, r[t]));
|
|
811
811
|
if (a.type) return { allOf: [i, a] };
|
|
812
|
-
let o =
|
|
812
|
+
let o = T(this.constructReferencedOpenAPISchema(e), (e, t) => e === void 0 || D(e, r[t])), s = j.applySchemaMetadata(o, a);
|
|
813
813
|
return Object.keys(s).length > 0 ? { allOf: [i, s] } : i;
|
|
814
814
|
}
|
|
815
815
|
generateSchemaWithRef(e) {
|
|
@@ -853,7 +853,7 @@ var Ee = class {
|
|
|
853
853
|
"path",
|
|
854
854
|
"request",
|
|
855
855
|
"responses"
|
|
856
|
-
]), o =
|
|
856
|
+
]), o = te(i, (e) => this.getResponse(e)), s = fe(() => this.getParameters(r), { route: `${t} ${n}` }), c = this.getRequestBody(r?.body);
|
|
857
857
|
return { [t]: Object.assign(Object.assign(Object.assign(Object.assign({}, a), s.length > 0 ? { parameters: [...a.parameters || [], ...s] } : {}), c ? { requestBody: c } : {}), { responses: o }) };
|
|
858
858
|
}
|
|
859
859
|
generateSingleRoute(e) {
|
|
@@ -872,10 +872,10 @@ var Ee = class {
|
|
|
872
872
|
}
|
|
873
873
|
getResponseHeaders(e) {
|
|
874
874
|
let t = e.def.shape;
|
|
875
|
-
return
|
|
875
|
+
return te(t, (e) => this.generateSimpleParameter(e));
|
|
876
876
|
}
|
|
877
877
|
getBodyContent(e) {
|
|
878
|
-
return
|
|
878
|
+
return te(e, (e) => {
|
|
879
879
|
if (!e || "$ref" in e) return e;
|
|
880
880
|
let { schema: t, itemSchema: n } = e, r = h(e, ["schema", "itemSchema"]), i = typeof t == "object" && v(t) ? this.generateSchemaWithRef(t) : t, a = typeof n == "object" && v(n) ? this.generateSchemaWithRef(n) : n;
|
|
881
881
|
return Object.assign(Object.assign(Object.assign({}, r), i === void 0 ? {} : { schema: i }), a === void 0 ? {} : { itemSchema: a });
|
|
@@ -889,7 +889,7 @@ var Ee = class {
|
|
|
889
889
|
return { nullable: !0 };
|
|
890
890
|
}
|
|
891
891
|
mapNullableOfArray(e, t) {
|
|
892
|
-
return t && !e.some((e) =>
|
|
892
|
+
return t && !e.some((e) => D(e, this.nullType)) ? [...e, this.nullType] : e;
|
|
893
893
|
}
|
|
894
894
|
mapNullableType(e, t) {
|
|
895
895
|
return Object.assign(Object.assign({}, e ? { type: e } : void 0), t ? this.nullType : void 0);
|
|
@@ -898,7 +898,7 @@ var Ee = class {
|
|
|
898
898
|
return t ? { allOf: [e, this.nullType] } : e;
|
|
899
899
|
}
|
|
900
900
|
mapTupleItems(e) {
|
|
901
|
-
let t =
|
|
901
|
+
let t = O(e);
|
|
902
902
|
return {
|
|
903
903
|
items: t.length === 1 ? t[0] : { anyOf: t },
|
|
904
904
|
minItems: e.length,
|
|
@@ -943,10 +943,10 @@ var Ee = class {
|
|
|
943
943
|
return { type: "null" };
|
|
944
944
|
}
|
|
945
945
|
mapNullableOfArray(e, t) {
|
|
946
|
-
return t && !e.some((e) =>
|
|
946
|
+
return t && !e.some((e) => D(e, this.nullType)) ? [...e, this.nullType] : e;
|
|
947
947
|
}
|
|
948
948
|
mapNullableType(e, t) {
|
|
949
|
-
return e ? t ? { type:
|
|
949
|
+
return e ? t ? { type: O([...Array.isArray(e) ? e : [e], "null"]) } : { type: e } : {};
|
|
950
950
|
}
|
|
951
951
|
mapNullableOfRef(e, t) {
|
|
952
952
|
return t ? { oneOf: [e, this.nullType] } : e;
|
|
@@ -22934,14 +22934,17 @@ async function Vb(e, t) {
|
|
|
22934
22934
|
}
|
|
22935
22935
|
function Hb() {
|
|
22936
22936
|
return async (e, t) => {
|
|
22937
|
+
if (e.req.method !== "GET" && e.req.method !== "HEAD") return t();
|
|
22938
|
+
let n = e.req.path.replace(/^\/media\//, ""), r = await Mb(e).prepare("SELECT deletedAt FROM assets WHERE storageKeyPrivate = ? LIMIT 1").get(n);
|
|
22939
|
+
if (r?.deletedAt && String(r.deletedAt).trim() !== "") return e.text("Media File Not Found", 404);
|
|
22937
22940
|
if (e.env?.MEDIA_BUCKET) {
|
|
22938
|
-
let t =
|
|
22939
|
-
if (!
|
|
22941
|
+
let t = await e.env.MEDIA_BUCKET.get(n, { onlyIf: e.req.raw.headers });
|
|
22942
|
+
if (!t) return e.text("Media File Not Found", 404);
|
|
22940
22943
|
let r = new Headers();
|
|
22941
|
-
return
|
|
22944
|
+
return t.writeHttpMetadata(r), t.httpEtag && r.set("ETag", t.httpEtag), r.set("Cache-Control", "public, max-age=31536000, immutable"), r.set("Access-Control-Allow-Origin", "*"), "body" in t && t.body === void 0 ? new Response(null, {
|
|
22942
22945
|
status: 304,
|
|
22943
22946
|
headers: r
|
|
22944
|
-
}) : new Response(
|
|
22947
|
+
}) : new Response(t.body, {
|
|
22945
22948
|
status: 200,
|
|
22946
22949
|
headers: r
|
|
22947
22950
|
});
|
|
@@ -22961,18 +22964,324 @@ function Hb() {
|
|
|
22961
22964
|
return t();
|
|
22962
22965
|
};
|
|
22963
22966
|
}
|
|
22964
|
-
var Ub =
|
|
22965
|
-
|
|
22966
|
-
|
|
22967
|
+
var Ub = (e) => Kb(e.replace(/_|-/g, (e) => ({
|
|
22968
|
+
_: "/",
|
|
22969
|
+
"-": "+"
|
|
22970
|
+
})[e] ?? e)), Wb = (e) => Gb(e).replace(/\/|\+/g, (e) => ({
|
|
22971
|
+
"/": "_",
|
|
22972
|
+
"+": "-"
|
|
22973
|
+
})[e] ?? e), Gb = (e) => {
|
|
22974
|
+
let t = "", n = new Uint8Array(e);
|
|
22975
|
+
for (let e = 0, r = n.length; e < r; e++) t += String.fromCharCode(n[e]);
|
|
22976
|
+
return btoa(t);
|
|
22977
|
+
}, Kb = (e) => {
|
|
22978
|
+
let t = atob(e), n = new Uint8Array(new ArrayBuffer(t.length)), r = t.length / 2;
|
|
22979
|
+
for (let e = 0, i = t.length - 1; e <= r; e++, i--) n[e] = t.charCodeAt(e), n[i] = t.charCodeAt(i);
|
|
22980
|
+
return n;
|
|
22981
|
+
}, qb = /* @__PURE__ */ ((e) => (e.HS256 = "HS256", e.HS384 = "HS384", e.HS512 = "HS512", e.RS256 = "RS256", e.RS384 = "RS384", e.RS512 = "RS512", e.PS256 = "PS256", e.PS384 = "PS384", e.PS512 = "PS512", e.ES256 = "ES256", e.ES384 = "ES384", e.ES512 = "ES512", e.EdDSA = "EdDSA", e))(qb || {}), Jb = {
|
|
22982
|
+
deno: "Deno",
|
|
22983
|
+
bun: "Bun",
|
|
22984
|
+
workerd: "Cloudflare-Workers",
|
|
22985
|
+
node: "Node.js"
|
|
22986
|
+
}, Yb = () => {
|
|
22987
|
+
let e = globalThis;
|
|
22988
|
+
if (typeof navigator < "u" && typeof navigator.userAgent == "string") {
|
|
22989
|
+
for (let [e, t] of Object.entries(Jb)) if (Xb(t)) return e;
|
|
22990
|
+
}
|
|
22991
|
+
return typeof e?.EdgeRuntime == "string" ? "edge-light" : e?.fastly === void 0 ? e?.process?.release?.name === "node" ? "node" : "other" : "fastly";
|
|
22992
|
+
}, Xb = (e) => navigator.userAgent.startsWith(e), Zb = class extends Error {
|
|
22993
|
+
constructor(e) {
|
|
22994
|
+
super(`${e} is not an implemented algorithm`), this.name = "JwtAlgorithmNotImplemented";
|
|
22995
|
+
}
|
|
22996
|
+
}, Qb = class extends Error {
|
|
22997
|
+
constructor() {
|
|
22998
|
+
super("JWT verification requires \"alg\" option to be specified"), this.name = "JwtAlgorithmRequired";
|
|
22999
|
+
}
|
|
23000
|
+
}, $b = class extends Error {
|
|
23001
|
+
constructor(e, t) {
|
|
23002
|
+
super(`JWT algorithm mismatch: expected "${e}", got "${t}"`), this.name = "JwtAlgorithmMismatch";
|
|
23003
|
+
}
|
|
23004
|
+
}, ex = class extends Error {
|
|
23005
|
+
constructor(e) {
|
|
23006
|
+
super(`invalid JWT token: ${e}`), this.name = "JwtTokenInvalid";
|
|
23007
|
+
}
|
|
23008
|
+
}, tx = class extends Error {
|
|
23009
|
+
constructor(e) {
|
|
23010
|
+
super(`token (${e}) is being used before it's valid`), this.name = "JwtTokenNotBefore";
|
|
23011
|
+
}
|
|
23012
|
+
}, nx = class extends Error {
|
|
23013
|
+
constructor(e) {
|
|
23014
|
+
super(`token (${e}) expired`), this.name = "JwtTokenExpired";
|
|
23015
|
+
}
|
|
23016
|
+
}, rx = class extends Error {
|
|
23017
|
+
constructor(e, t) {
|
|
23018
|
+
super(`Invalid "iat" claim, must be a valid number lower than "${e}" (iat: "${t}")`), this.name = "JwtTokenIssuedAt";
|
|
23019
|
+
}
|
|
23020
|
+
}, ix = class extends Error {
|
|
23021
|
+
constructor(e, t) {
|
|
23022
|
+
super(`expected issuer "${e}", got ${t ? `"${t}"` : "none"} `), this.name = "JwtTokenIssuer";
|
|
23023
|
+
}
|
|
23024
|
+
}, ax = class extends Error {
|
|
23025
|
+
constructor(e) {
|
|
23026
|
+
super(`jwt header is invalid: ${JSON.stringify(e)}`), this.name = "JwtHeaderInvalid";
|
|
23027
|
+
}
|
|
23028
|
+
}, ox = class extends Error {
|
|
23029
|
+
constructor(e) {
|
|
23030
|
+
super(`required "kid" in jwt header: ${JSON.stringify(e)}`), this.name = "JwtHeaderRequiresKid";
|
|
23031
|
+
}
|
|
23032
|
+
}, sx = class extends Error {
|
|
23033
|
+
constructor(e) {
|
|
23034
|
+
super(`symmetric algorithm "${e}" is not allowed for JWK verification`), this.name = "JwtSymmetricAlgorithmNotAllowed";
|
|
23035
|
+
}
|
|
23036
|
+
}, cx = class extends Error {
|
|
23037
|
+
constructor(e, t) {
|
|
23038
|
+
super(`algorithm "${e}" is not in the allowed list: [${t.join(", ")}]`), this.name = "JwtAlgorithmNotAllowed";
|
|
23039
|
+
}
|
|
23040
|
+
}, lx = class extends Error {
|
|
23041
|
+
constructor(e) {
|
|
23042
|
+
super(`token(${e}) signature mismatched`), this.name = "JwtTokenSignatureMismatched";
|
|
23043
|
+
}
|
|
23044
|
+
}, ux = class extends Error {
|
|
23045
|
+
constructor(e) {
|
|
23046
|
+
super(`required "aud" in jwt payload: ${JSON.stringify(e)}`), this.name = "JwtPayloadRequiresAud";
|
|
23047
|
+
}
|
|
23048
|
+
}, dx = class extends Error {
|
|
23049
|
+
constructor(e, t) {
|
|
23050
|
+
super(`expected audience "${Array.isArray(e) ? e.join(", ") : e}", got "${t}"`), this.name = "JwtTokenAudience";
|
|
23051
|
+
}
|
|
23052
|
+
}, fx = /* @__PURE__ */ ((e) => (e.Encrypt = "encrypt", e.Decrypt = "decrypt", e.Sign = "sign", e.Verify = "verify", e.DeriveKey = "deriveKey", e.DeriveBits = "deriveBits", e.WrapKey = "wrapKey", e.UnwrapKey = "unwrapKey", e))(fx || {}), px = new TextEncoder(), mx = new TextDecoder();
|
|
23053
|
+
async function hx(e, t, n) {
|
|
23054
|
+
let r = xx(t), i = await vx(e, r);
|
|
23055
|
+
return await crypto.subtle.sign(r, i, n);
|
|
23056
|
+
}
|
|
23057
|
+
async function gx(e, t, n, r) {
|
|
23058
|
+
let i = xx(t), a = await yx(e, i);
|
|
23059
|
+
return await crypto.subtle.verify(i, a, n, r);
|
|
23060
|
+
}
|
|
23061
|
+
function _x(e) {
|
|
23062
|
+
return Kb(e.replace(/-+(BEGIN|END).*?-+/g, "").replace(/\s/g, ""));
|
|
23063
|
+
}
|
|
23064
|
+
async function vx(e, t) {
|
|
23065
|
+
if (!crypto.subtle || !crypto.subtle.importKey) throw Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
|
23066
|
+
if (Sx(e)) {
|
|
23067
|
+
if (e.type !== "private" && e.type !== "secret") throw Error(`unexpected key type: CryptoKey.type is ${e.type}, expected private or secret`);
|
|
23068
|
+
return e;
|
|
23069
|
+
}
|
|
23070
|
+
let n = [fx.Sign];
|
|
23071
|
+
return typeof e == "object" ? await crypto.subtle.importKey("jwk", e, t, !1, n) : e.includes("PRIVATE") ? await crypto.subtle.importKey("pkcs8", _x(e), t, !1, n) : await crypto.subtle.importKey("raw", px.encode(e), t, !1, n);
|
|
23072
|
+
}
|
|
23073
|
+
async function yx(e, t) {
|
|
23074
|
+
if (!crypto.subtle || !crypto.subtle.importKey) throw Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
|
23075
|
+
if (Sx(e)) {
|
|
23076
|
+
if (e.type === "public" || e.type === "secret") return e;
|
|
23077
|
+
e = await bx(e);
|
|
23078
|
+
}
|
|
23079
|
+
typeof e == "string" && e.includes("PRIVATE") && (e = await bx(await crypto.subtle.importKey("pkcs8", _x(e), t, !0, [fx.Sign])));
|
|
23080
|
+
let n = [fx.Verify];
|
|
23081
|
+
return typeof e == "object" ? await crypto.subtle.importKey("jwk", e, t, !1, n) : e.includes("PUBLIC") ? await crypto.subtle.importKey("spki", _x(e), t, !1, n) : await crypto.subtle.importKey("raw", px.encode(e), t, !1, n);
|
|
23082
|
+
}
|
|
23083
|
+
async function bx(e) {
|
|
23084
|
+
if (e.type !== "private") throw Error(`unexpected key type: ${e.type}`);
|
|
23085
|
+
if (!e.extractable) throw Error("unexpected private key is unextractable");
|
|
23086
|
+
let t = await crypto.subtle.exportKey("jwk", e), { kty: n } = t, { alg: r, e: i, n: a } = t, { crv: o, x: s, y: c } = t;
|
|
23087
|
+
return {
|
|
23088
|
+
kty: n,
|
|
23089
|
+
alg: r,
|
|
23090
|
+
e: i,
|
|
23091
|
+
n: a,
|
|
23092
|
+
crv: o,
|
|
23093
|
+
x: s,
|
|
23094
|
+
y: c,
|
|
23095
|
+
key_ops: [fx.Verify]
|
|
23096
|
+
};
|
|
23097
|
+
}
|
|
23098
|
+
function xx(e) {
|
|
23099
|
+
switch (e) {
|
|
23100
|
+
case "HS256": return {
|
|
23101
|
+
name: "HMAC",
|
|
23102
|
+
hash: { name: "SHA-256" }
|
|
23103
|
+
};
|
|
23104
|
+
case "HS384": return {
|
|
23105
|
+
name: "HMAC",
|
|
23106
|
+
hash: { name: "SHA-384" }
|
|
23107
|
+
};
|
|
23108
|
+
case "HS512": return {
|
|
23109
|
+
name: "HMAC",
|
|
23110
|
+
hash: { name: "SHA-512" }
|
|
23111
|
+
};
|
|
23112
|
+
case "RS256": return {
|
|
23113
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
23114
|
+
hash: { name: "SHA-256" }
|
|
23115
|
+
};
|
|
23116
|
+
case "RS384": return {
|
|
23117
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
23118
|
+
hash: { name: "SHA-384" }
|
|
23119
|
+
};
|
|
23120
|
+
case "RS512": return {
|
|
23121
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
23122
|
+
hash: { name: "SHA-512" }
|
|
23123
|
+
};
|
|
23124
|
+
case "PS256": return {
|
|
23125
|
+
name: "RSA-PSS",
|
|
23126
|
+
hash: { name: "SHA-256" },
|
|
23127
|
+
saltLength: 32
|
|
23128
|
+
};
|
|
23129
|
+
case "PS384": return {
|
|
23130
|
+
name: "RSA-PSS",
|
|
23131
|
+
hash: { name: "SHA-384" },
|
|
23132
|
+
saltLength: 48
|
|
23133
|
+
};
|
|
23134
|
+
case "PS512": return {
|
|
23135
|
+
name: "RSA-PSS",
|
|
23136
|
+
hash: { name: "SHA-512" },
|
|
23137
|
+
saltLength: 64
|
|
23138
|
+
};
|
|
23139
|
+
case "ES256": return {
|
|
23140
|
+
name: "ECDSA",
|
|
23141
|
+
hash: { name: "SHA-256" },
|
|
23142
|
+
namedCurve: "P-256"
|
|
23143
|
+
};
|
|
23144
|
+
case "ES384": return {
|
|
23145
|
+
name: "ECDSA",
|
|
23146
|
+
hash: { name: "SHA-384" },
|
|
23147
|
+
namedCurve: "P-384"
|
|
23148
|
+
};
|
|
23149
|
+
case "ES512": return {
|
|
23150
|
+
name: "ECDSA",
|
|
23151
|
+
hash: { name: "SHA-512" },
|
|
23152
|
+
namedCurve: "P-521"
|
|
23153
|
+
};
|
|
23154
|
+
case "EdDSA": return {
|
|
23155
|
+
name: "Ed25519",
|
|
23156
|
+
namedCurve: "Ed25519"
|
|
23157
|
+
};
|
|
23158
|
+
default: throw new Zb(e);
|
|
23159
|
+
}
|
|
23160
|
+
}
|
|
23161
|
+
function Sx(e) {
|
|
23162
|
+
return Yb() === "node" && crypto.webcrypto ? e instanceof crypto.webcrypto.CryptoKey : e instanceof CryptoKey;
|
|
23163
|
+
}
|
|
23164
|
+
var Cx = (e) => Wb(px.encode(JSON.stringify(e)).buffer).replace(/=/g, ""), wx = (e) => Wb(e).replace(/=/g, ""), Tx = (e) => JSON.parse(mx.decode(Ub(e)));
|
|
23165
|
+
function Ex(e) {
|
|
23166
|
+
if (typeof e == "object" && e) {
|
|
23167
|
+
let t = e;
|
|
23168
|
+
return "alg" in t && Object.values(qb).includes(t.alg) && (!("typ" in t) || t.typ === "JWT");
|
|
23169
|
+
}
|
|
23170
|
+
return !1;
|
|
23171
|
+
}
|
|
23172
|
+
var Dx = async (e, t, n = "HS256") => {
|
|
23173
|
+
let r = Cx(e), i;
|
|
23174
|
+
typeof t == "object" && "alg" in t ? (n = t.alg, i = Cx({
|
|
23175
|
+
alg: n,
|
|
23176
|
+
typ: "JWT",
|
|
23177
|
+
kid: t.kid
|
|
23178
|
+
})) : i = Cx({
|
|
23179
|
+
alg: n,
|
|
23180
|
+
typ: "JWT"
|
|
23181
|
+
});
|
|
23182
|
+
let a = `${i}.${r}`;
|
|
23183
|
+
return `${a}.${wx(await hx(t, n, px.encode(a)))}`;
|
|
23184
|
+
}, Ox = async (e, t, n) => {
|
|
23185
|
+
if (!n) throw new Qb();
|
|
23186
|
+
let { alg: r, iss: i, nbf: a = !0, exp: o = !0, iat: s = !0, aud: c } = typeof n == "string" ? { alg: n } : n;
|
|
23187
|
+
if (!r) throw new Qb();
|
|
23188
|
+
let l = e.split(".");
|
|
23189
|
+
if (l.length !== 3) throw new ex(e);
|
|
23190
|
+
let { header: u, payload: d } = jx(e);
|
|
23191
|
+
if (!Ex(u)) throw new ax(u);
|
|
23192
|
+
if (u.alg !== r) throw new $b(r, u.alg);
|
|
23193
|
+
let f = Math.floor(Date.now() / 1e3);
|
|
23194
|
+
if (a && d.nbf !== void 0 && (typeof d.nbf != "number" || !Number.isFinite(d.nbf) || d.nbf > f)) throw new tx(e);
|
|
23195
|
+
if (o && d.exp !== void 0 && (typeof d.exp != "number" || !Number.isFinite(d.exp) || d.exp <= f)) throw new nx(e);
|
|
23196
|
+
if (s && d.iat !== void 0 && (typeof d.iat != "number" || !Number.isFinite(d.iat) || f < d.iat)) throw new rx(f, d.iat);
|
|
23197
|
+
if (i) {
|
|
23198
|
+
if (!d.iss) throw new ix(i, null);
|
|
23199
|
+
if (typeof i == "string" && d.iss !== i || i instanceof RegExp && !i.test(d.iss)) throw new ix(i, d.iss);
|
|
23200
|
+
}
|
|
23201
|
+
if (c) {
|
|
23202
|
+
if (!d.aud) throw new ux(d);
|
|
23203
|
+
if (!(Array.isArray(d.aud) ? d.aud : [d.aud]).some((e) => c instanceof RegExp ? c.test(e) : typeof c == "string" ? e === c : Array.isArray(c) && c.includes(e))) throw new dx(c, d.aud);
|
|
23204
|
+
}
|
|
23205
|
+
let p = e.substring(0, e.lastIndexOf("."));
|
|
23206
|
+
if (!await gx(t, r, Ub(l[2]), px.encode(p))) throw new lx(e);
|
|
23207
|
+
return d;
|
|
23208
|
+
}, kx = [
|
|
23209
|
+
qb.HS256,
|
|
23210
|
+
qb.HS384,
|
|
23211
|
+
qb.HS512
|
|
23212
|
+
], Ax = async (e, t, n) => {
|
|
23213
|
+
let r = t.verification || {}, i = Mx(e);
|
|
23214
|
+
if (!Ex(i)) throw new ax(i);
|
|
23215
|
+
if (!i.kid) throw new ox(i);
|
|
23216
|
+
if (kx.includes(i.alg)) throw new sx(i.alg);
|
|
23217
|
+
if (!t.allowedAlgorithms.includes(i.alg)) throw new cx(i.alg, t.allowedAlgorithms);
|
|
23218
|
+
let a = t.keys ? [...t.keys] : void 0;
|
|
23219
|
+
if (t.jwks_uri) {
|
|
23220
|
+
let e = await fetch(t.jwks_uri, n);
|
|
23221
|
+
if (!e.ok) throw Error(`failed to fetch JWKS from ${t.jwks_uri}`);
|
|
23222
|
+
let r = await e.json();
|
|
23223
|
+
if (!r.keys) throw Error("invalid JWKS response. \"keys\" field is missing");
|
|
23224
|
+
if (!Array.isArray(r.keys)) throw Error("invalid JWKS response. \"keys\" field is not an array");
|
|
23225
|
+
a ??= [], a.push(...r.keys);
|
|
23226
|
+
} else if (!a) throw Error("verifyWithJwks requires options for either \"keys\" or \"jwks_uri\" or both");
|
|
23227
|
+
let o = a.find((e) => e.kid === i.kid);
|
|
23228
|
+
if (!o) throw new ex(e);
|
|
23229
|
+
if (o.alg && o.alg !== i.alg) throw new $b(o.alg, i.alg);
|
|
23230
|
+
return await Ox(e, o, {
|
|
23231
|
+
alg: i.alg,
|
|
23232
|
+
...r
|
|
23233
|
+
});
|
|
23234
|
+
}, jx = (e) => {
|
|
23235
|
+
let t = e.split(".");
|
|
23236
|
+
if (t.length !== 3) throw new ex(e);
|
|
23237
|
+
try {
|
|
23238
|
+
return {
|
|
23239
|
+
header: Tx(t[0]),
|
|
23240
|
+
payload: Tx(t[1])
|
|
23241
|
+
};
|
|
23242
|
+
} catch {
|
|
23243
|
+
throw new ex(e);
|
|
23244
|
+
}
|
|
23245
|
+
}, Mx = (e) => {
|
|
23246
|
+
let t = e.split(".");
|
|
23247
|
+
if (t.length !== 3) throw new ex(e);
|
|
23248
|
+
try {
|
|
23249
|
+
return Tx(t[0]);
|
|
23250
|
+
} catch {
|
|
23251
|
+
throw new ex(e);
|
|
23252
|
+
}
|
|
23253
|
+
}, Nx = {
|
|
23254
|
+
sign: Dx,
|
|
23255
|
+
verify: Ox,
|
|
23256
|
+
decode: jx,
|
|
23257
|
+
verifyWithJwks: Ax
|
|
23258
|
+
};
|
|
23259
|
+
Nx.verifyWithJwks;
|
|
23260
|
+
var Px = Nx.verify;
|
|
23261
|
+
Nx.decode, Nx.sign;
|
|
23262
|
+
var Fx = process.env.JWT_SECRET || "super-secret-cms-key-change-in-production";
|
|
23263
|
+
async function Ix(e, t) {
|
|
23264
|
+
let n = qe(e, "cms_session"), r = e.req.header("Authorization"), i = r?.startsWith("Bearer ") ? r.substring(7) : null, a = n || i;
|
|
23265
|
+
if (!a) return e.json({ error: "Unauthorized: Authentication required" }, 401);
|
|
23266
|
+
try {
|
|
23267
|
+
let n = await Px(a, Fx);
|
|
23268
|
+
e.set("jwtPayload", n), await t();
|
|
23269
|
+
} catch {
|
|
23270
|
+
return e.json({ error: "Unauthorized: Invalid or expired session" }, 401);
|
|
23271
|
+
}
|
|
23272
|
+
}
|
|
23273
|
+
var Lx = { hasSubscribers: !1 }, Rx = Lx, zx = Lx, Bx = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, Vx = () => Rx.hasSubscribers || zx.hasSubscribers, Hx = /* @__PURE__ */ new Set(), Ux = typeof process == "object" && process ? process : {}, Wx = (e, t, n, r) => {
|
|
23274
|
+
typeof Ux.emitWarning == "function" ? Ux.emitWarning(e, t, n, r) : console.error(`[${n}] ${t}: ${e}`);
|
|
23275
|
+
}, Gx = (e) => !Hx.has(e), Kx = (e) => !!e && e === Math.floor(e) && e > 0 && isFinite(e), qx = (e) => Kx(e) ? e <= 256 ? Uint8Array : e <= 2 ** 16 ? Uint16Array : e <= 2 ** 32 ? Uint32Array : e <= 2 ** 53 - 1 ? Jx : null : null, Jx = class extends Array {
|
|
22967
23276
|
constructor(e) {
|
|
22968
23277
|
super(e), this.fill(0);
|
|
22969
23278
|
}
|
|
22970
|
-
},
|
|
23279
|
+
}, Yx = class e {
|
|
22971
23280
|
heap;
|
|
22972
23281
|
length;
|
|
22973
23282
|
static #e = !1;
|
|
22974
23283
|
static create(t) {
|
|
22975
|
-
let n =
|
|
23284
|
+
let n = qx(t);
|
|
22976
23285
|
if (!n) return [];
|
|
22977
23286
|
e.#e = !0;
|
|
22978
23287
|
let r = new e(t, n);
|
|
@@ -22988,7 +23297,7 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
22988
23297
|
pop() {
|
|
22989
23298
|
return this.heap[--this.length];
|
|
22990
23299
|
}
|
|
22991
|
-
},
|
|
23300
|
+
}, Xx = class e {
|
|
22992
23301
|
#e;
|
|
22993
23302
|
#t;
|
|
22994
23303
|
#n;
|
|
@@ -23089,37 +23398,37 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23089
23398
|
return this.#i;
|
|
23090
23399
|
}
|
|
23091
23400
|
constructor(t) {
|
|
23092
|
-
let { max: n = 0, ttl: r, ttlResolution: i = 1, ttlAutopurge: a, updateAgeOnGet: o, updateAgeOnHas: s, allowStale: c, dispose: l, onInsert: u, disposeAfter: d, noDisposeOnSet: f, noUpdateTTL: p, maxSize: m = 0, maxEntrySize: h = 0, sizeCalculation: g, fetchMethod: _, memoMethod: v, noDeleteOnFetchRejection: y, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: x, allowStaleOnFetchAbort: S, ignoreFetchAbort: C, backgroundFetchSize:
|
|
23093
|
-
if (this.backgroundFetchSize =
|
|
23094
|
-
if (this.#s =
|
|
23095
|
-
let
|
|
23096
|
-
if (!
|
|
23401
|
+
let { max: n = 0, ttl: r, ttlResolution: i = 1, ttlAutopurge: a, updateAgeOnGet: o, updateAgeOnHas: s, allowStale: c, dispose: l, onInsert: u, disposeAfter: d, noDisposeOnSet: f, noUpdateTTL: p, maxSize: m = 0, maxEntrySize: h = 0, sizeCalculation: g, fetchMethod: _, memoMethod: v, noDeleteOnFetchRejection: y, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: x, allowStaleOnFetchAbort: S, ignoreFetchAbort: C, backgroundFetchSize: ee = 1, perf: w } = t;
|
|
23402
|
+
if (this.backgroundFetchSize = ee, w !== void 0 && typeof w?.now != "function") throw TypeError("perf option must have a now() method if specified");
|
|
23403
|
+
if (this.#s = w ?? Bx, n !== 0 && !Kx(n)) throw TypeError("max option must be a nonnegative integer");
|
|
23404
|
+
let te = n ? qx(n) : Array;
|
|
23405
|
+
if (!te) throw Error("invalid max value: " + n);
|
|
23097
23406
|
if (this.#e = n, this.#t = m, this.maxEntrySize = h || this.#t, this.sizeCalculation = g, this.sizeCalculation) {
|
|
23098
23407
|
if (!this.#t && !this.maxEntrySize) throw TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
23099
23408
|
if (typeof this.sizeCalculation != "function") throw TypeError("sizeCalculation set to non-function");
|
|
23100
23409
|
}
|
|
23101
23410
|
if (v !== void 0 && typeof v != "function") throw TypeError("memoMethod must be a function if defined");
|
|
23102
23411
|
if (this.#o = v, _ !== void 0 && typeof _ != "function") throw TypeError("fetchMethod must be a function if specified");
|
|
23103
|
-
if (this.#a = _, this.#w = !!_, this.#u = /* @__PURE__ */ new Map(), this.#d = Array.from({ length: n }).fill(void 0), this.#f = Array.from({ length: n }).fill(void 0), this.#p = new
|
|
23104
|
-
if (this.#t !== 0 && !
|
|
23105
|
-
if (!
|
|
23412
|
+
if (this.#a = _, this.#w = !!_, this.#u = /* @__PURE__ */ new Map(), this.#d = Array.from({ length: n }).fill(void 0), this.#f = Array.from({ length: n }).fill(void 0), this.#p = new te(n), this.#m = new te(n), this.#h = 0, this.#g = 0, this.#_ = Yx.create(n), this.#c = 0, this.#l = 0, typeof l == "function" && (this.#n = l), typeof u == "function" && (this.#r = u), typeof d == "function" ? (this.#i = d, this.#v = []) : (this.#i = void 0, this.#v = void 0), this.#C = !!this.#n, this.#E = !!this.#r, this.#T = !!this.#i, this.noDisposeOnSet = !!f, this.noUpdateTTL = !!p, this.noDeleteOnFetchRejection = !!y, this.allowStaleOnFetchRejection = !!x, this.allowStaleOnFetchAbort = !!S, this.ignoreFetchAbort = !!C, this.maxEntrySize !== 0) {
|
|
23413
|
+
if (this.#t !== 0 && !Kx(this.#t)) throw TypeError("maxSize must be a positive integer if specified");
|
|
23414
|
+
if (!Kx(this.maxEntrySize)) throw TypeError("maxEntrySize must be a positive integer if specified");
|
|
23106
23415
|
this.#M();
|
|
23107
23416
|
}
|
|
23108
|
-
if (this.allowStale = !!c, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!s, this.ttlResolution =
|
|
23109
|
-
if (!
|
|
23417
|
+
if (this.allowStale = !!c, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!s, this.ttlResolution = Kx(i) || i === 0 ? i : 1, this.ttlAutopurge = !!a, this.ttl = r || 0, this.ttl) {
|
|
23418
|
+
if (!Kx(this.ttl)) throw TypeError("ttl must be a positive integer if specified");
|
|
23110
23419
|
this.#D();
|
|
23111
23420
|
}
|
|
23112
23421
|
if (this.#e === 0 && this.ttl === 0 && this.#t === 0) throw TypeError("At least one of max, maxSize, or ttl is required");
|
|
23113
23422
|
if (!this.ttlAutopurge && !this.#e && !this.#t) {
|
|
23114
23423
|
let t = "LRU_CACHE_UNBOUNDED";
|
|
23115
|
-
|
|
23424
|
+
Gx(t) && (Hx.add(t), Wx("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", t, e));
|
|
23116
23425
|
}
|
|
23117
23426
|
}
|
|
23118
23427
|
getRemainingTTL(e) {
|
|
23119
23428
|
return this.#u.has(e) ? 1 / 0 : 0;
|
|
23120
23429
|
}
|
|
23121
23430
|
#D() {
|
|
23122
|
-
let e = new
|
|
23431
|
+
let e = new Jx(this.#e), t = new Jx(this.#e);
|
|
23123
23432
|
this.#x = e, this.#b = t;
|
|
23124
23433
|
let n = this.ttlAutopurge ? Array.from({ length: this.#e }) : void 0;
|
|
23125
23434
|
this.#S = n, this.#A = (n, i, a = this.#s.now()) => {
|
|
@@ -23169,15 +23478,15 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23169
23478
|
#A = () => {};
|
|
23170
23479
|
#j = () => !1;
|
|
23171
23480
|
#M() {
|
|
23172
|
-
let e = new
|
|
23481
|
+
let e = new Jx(this.#e);
|
|
23173
23482
|
this.#l = 0, this.#y = e, this.#N = (t) => {
|
|
23174
23483
|
this.#l -= e[t], e[t] = 0;
|
|
23175
23484
|
}, this.#F = (e, t, n, r) => {
|
|
23176
|
-
if (!
|
|
23485
|
+
if (!Kx(n)) {
|
|
23177
23486
|
if (this.#W(t)) return this.backgroundFetchSize;
|
|
23178
23487
|
if (r) {
|
|
23179
23488
|
if (typeof r != "function") throw TypeError("sizeCalculation must be a function");
|
|
23180
|
-
if (n = r(t, e), !
|
|
23489
|
+
if (n = r(t, e), !Kx(n)) throw TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
23181
23490
|
} else throw TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
23182
23491
|
}
|
|
23183
23492
|
return n;
|
|
@@ -23293,10 +23602,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23293
23602
|
}
|
|
23294
23603
|
}
|
|
23295
23604
|
set(e, t, n = {}) {
|
|
23296
|
-
let { status: r =
|
|
23605
|
+
let { status: r = Rx.hasSubscribers ? {} : void 0 } = n;
|
|
23297
23606
|
n.status = r, r && (r.op = "set", r.key = e, t !== void 0 && (r.value = t), r.cache = this);
|
|
23298
23607
|
let i = this.#z(e, t, n);
|
|
23299
|
-
return r &&
|
|
23608
|
+
return r && Rx.hasSubscribers && Rx.publish(r), i;
|
|
23300
23609
|
}
|
|
23301
23610
|
#z(e, t, n, r) {
|
|
23302
23611
|
let { ttl: i = this.ttl, start: a, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: s = this.sizeCalculation, status: c } = n, l = this.#W(t);
|
|
@@ -23364,10 +23673,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23364
23673
|
])), this.#N(t), this.#S?.[t] && (clearTimeout(this.#S[t]), this.#S[t] = void 0), e && (this.#d[t] = void 0, this.#f[t] = void 0, this.#_.push(t)), this.#c === 1 ? (this.#h = this.#g = 0, this.#_.length = 0) : this.#h = this.#p[t], this.#u.delete(n), this.#c--, t;
|
|
23365
23674
|
}
|
|
23366
23675
|
has(e, t = {}) {
|
|
23367
|
-
let { status: n =
|
|
23676
|
+
let { status: n = Rx.hasSubscribers ? {} : void 0 } = t;
|
|
23368
23677
|
t.status = n, n && (n.op = "has", n.key = e, n.cache = this);
|
|
23369
23678
|
let r = this.#V(e, t);
|
|
23370
|
-
return
|
|
23679
|
+
return Rx.hasSubscribers && Rx.publish(n), r;
|
|
23371
23680
|
}
|
|
23372
23681
|
#V(e, t = {}) {
|
|
23373
23682
|
let { updateAgeOnHas: n = this.updateAgeOnHas, status: r } = t, i = this.#u.get(e);
|
|
@@ -23380,10 +23689,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23380
23689
|
return !1;
|
|
23381
23690
|
}
|
|
23382
23691
|
peek(e, t = {}) {
|
|
23383
|
-
let { status: n =
|
|
23692
|
+
let { status: n = Vx() ? {} : void 0 } = t;
|
|
23384
23693
|
n && (n.op = "peek", n.key = e, n.cache = this), t.status = n;
|
|
23385
23694
|
let r = this.#H(e, t);
|
|
23386
|
-
return
|
|
23695
|
+
return Rx.hasSubscribers && Rx.publish(n), r;
|
|
23387
23696
|
}
|
|
23388
23697
|
#H(e, t) {
|
|
23389
23698
|
let { status: n, allowStale: r = this.allowStale } = t, i = this.#u.get(e);
|
|
@@ -23435,10 +23744,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23435
23744
|
return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
|
|
23436
23745
|
}
|
|
23437
23746
|
fetch(e, t = {}) {
|
|
23438
|
-
let n =
|
|
23747
|
+
let n = zx.hasSubscribers, { status: r = Vx() ? {} : void 0 } = t;
|
|
23439
23748
|
t.status = r, r && t.context && (r.context = t.context);
|
|
23440
23749
|
let i = this.#G(e, t);
|
|
23441
|
-
return r && n && (r.trace = !0,
|
|
23750
|
+
return r && n && (r.trace = !0, zx.tracePromise(() => i, r).catch(() => {})), i;
|
|
23442
23751
|
}
|
|
23443
23752
|
async #G(e, t = {}) {
|
|
23444
23753
|
let { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: i = this.noDeleteOnStaleGet, ttl: a = this.ttl, noDisposeOnSet: o = this.noDisposeOnSet, size: s = 0, sizeCalculation: c = this.sizeCalculation, noUpdateTTL: l = this.noUpdateTTL, noDeleteOnFetchRejection: u = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: f = this.ignoreFetchAbort, allowStaleOnFetchAbort: p = this.allowStaleOnFetchAbort, context: m, forceRefresh: h = !1, status: g, signal: _ } = t;
|
|
@@ -23482,10 +23791,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23482
23791
|
}
|
|
23483
23792
|
}
|
|
23484
23793
|
forceFetch(e, t = {}) {
|
|
23485
|
-
let n =
|
|
23794
|
+
let n = zx.hasSubscribers, { status: r = Vx() ? {} : void 0 } = t;
|
|
23486
23795
|
t.status = r, r && t.context && (r.context = t.context);
|
|
23487
23796
|
let i = this.#K(e, t);
|
|
23488
|
-
return r && n && (r.trace = !0,
|
|
23797
|
+
return r && n && (r.trace = !0, zx.tracePromise(() => i, r).catch(() => {})), i;
|
|
23489
23798
|
}
|
|
23490
23799
|
async #K(e, t = {}) {
|
|
23491
23800
|
let n = await this.#G(e, t);
|
|
@@ -23493,10 +23802,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23493
23802
|
return n;
|
|
23494
23803
|
}
|
|
23495
23804
|
memo(e, t = {}) {
|
|
23496
|
-
let { status: n =
|
|
23805
|
+
let { status: n = Rx.hasSubscribers ? {} : void 0 } = t;
|
|
23497
23806
|
t.status = n, n && (n.op = "memo", n.key = e, t.context && (n.context = t.context), n.cache = this);
|
|
23498
23807
|
let r = this.#q(e, t);
|
|
23499
|
-
return n && (n.value = r),
|
|
23808
|
+
return n && (n.value = r), Rx.hasSubscribers && Rx.publish(n), r;
|
|
23500
23809
|
}
|
|
23501
23810
|
#q(e, t = {}) {
|
|
23502
23811
|
let n = this.#o;
|
|
@@ -23512,10 +23821,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23512
23821
|
return i && (i.value = l), this.#z(e, l, o), l;
|
|
23513
23822
|
}
|
|
23514
23823
|
get(e, t = {}) {
|
|
23515
|
-
let { status: n =
|
|
23824
|
+
let { status: n = Rx.hasSubscribers ? {} : void 0 } = t;
|
|
23516
23825
|
t.status = n, n && (n.op = "get", n.key = e, n.cache = this);
|
|
23517
23826
|
let r = this.#J(e, t);
|
|
23518
|
-
return n && (r !== void 0 && (n.value = r),
|
|
23827
|
+
return n && (r !== void 0 && (n.value = r), Rx.hasSubscribers && Rx.publish(n)), r;
|
|
23519
23828
|
}
|
|
23520
23829
|
#J(e, t = {}) {
|
|
23521
23830
|
let { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: i = this.noDeleteOnStaleGet, status: a } = t, o = this.#u.get(e);
|
|
@@ -23536,7 +23845,7 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23536
23845
|
return this.#Z(e, "delete");
|
|
23537
23846
|
}
|
|
23538
23847
|
#Z(e, t) {
|
|
23539
|
-
|
|
23848
|
+
Rx.hasSubscribers && Rx.publish({
|
|
23540
23849
|
op: "delete",
|
|
23541
23850
|
delete: t,
|
|
23542
23851
|
key: e,
|
|
@@ -23598,10 +23907,10 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23598
23907
|
for (; t = e?.shift();) this.#i?.(...t);
|
|
23599
23908
|
}
|
|
23600
23909
|
}
|
|
23601
|
-
},
|
|
23910
|
+
}, Zx = class {
|
|
23602
23911
|
cache;
|
|
23603
23912
|
constructor(e = 1e3, t = 3e5) {
|
|
23604
|
-
this.cache = new
|
|
23913
|
+
this.cache = new Xx({
|
|
23605
23914
|
max: e,
|
|
23606
23915
|
ttl: t
|
|
23607
23916
|
});
|
|
@@ -23620,7 +23929,7 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23620
23929
|
async clear() {
|
|
23621
23930
|
this.cache.clear();
|
|
23622
23931
|
}
|
|
23623
|
-
},
|
|
23932
|
+
}, Qx = class {
|
|
23624
23933
|
kv;
|
|
23625
23934
|
constructor(e) {
|
|
23626
23935
|
this.kv = e;
|
|
@@ -23637,21 +23946,21 @@ var Ub = { hasSubscribers: !1 }, Wb = Ub, Gb = Ub, Kb = typeof performance == "o
|
|
|
23637
23946
|
this.kv && await this.kv.delete(e);
|
|
23638
23947
|
}
|
|
23639
23948
|
async clear() {}
|
|
23640
|
-
},
|
|
23949
|
+
}, $x = class {
|
|
23641
23950
|
async get() {
|
|
23642
23951
|
return null;
|
|
23643
23952
|
}
|
|
23644
23953
|
async set() {}
|
|
23645
23954
|
async delete() {}
|
|
23646
23955
|
async clear() {}
|
|
23647
|
-
},
|
|
23648
|
-
function
|
|
23956
|
+
}, eS = null;
|
|
23957
|
+
function tS(e) {
|
|
23649
23958
|
let t = process.env.CACHE_DRIVER || "lru";
|
|
23650
|
-
if (t === "none" || t === "off" || t === "false") return new
|
|
23959
|
+
if (t === "none" || t === "off" || t === "false") return new $x();
|
|
23651
23960
|
let n = e?.env?.CACHE_KV || e?.env?.CMS_CACHE_KV;
|
|
23652
|
-
return n ? new
|
|
23961
|
+
return n ? new Qx(n) : t === "lru" ? (eS ||= new Zx(), eS) : new $x();
|
|
23653
23962
|
}
|
|
23654
|
-
var
|
|
23963
|
+
var nS = class {
|
|
23655
23964
|
customStoragePath;
|
|
23656
23965
|
constructor(e) {
|
|
23657
23966
|
this.customStoragePath = e;
|
|
@@ -23720,7 +24029,7 @@ var cx = class {
|
|
|
23720
24029
|
if (e.code !== "ENOENT") throw e;
|
|
23721
24030
|
}
|
|
23722
24031
|
}
|
|
23723
|
-
},
|
|
24032
|
+
}, rS = class {
|
|
23724
24033
|
async process(e, t, n) {
|
|
23725
24034
|
let r = await import(
|
|
23726
24035
|
/* @vite-ignore */
|
|
@@ -23747,7 +24056,7 @@ var cx = class {
|
|
|
23747
24056
|
return console.warn("⚠️ [SharpImageOptimizer] Processing failed, returning raw buffer."), e;
|
|
23748
24057
|
}
|
|
23749
24058
|
}
|
|
23750
|
-
},
|
|
24059
|
+
}, iS = class {
|
|
23751
24060
|
bucket;
|
|
23752
24061
|
publicDomain;
|
|
23753
24062
|
constructor(e, t) {
|
|
@@ -23792,7 +24101,7 @@ var cx = class {
|
|
|
23792
24101
|
async delete(e) {
|
|
23793
24102
|
await this.bucket.delete(e);
|
|
23794
24103
|
}
|
|
23795
|
-
},
|
|
24104
|
+
}, aS = class {
|
|
23796
24105
|
async process(e, t, n) {
|
|
23797
24106
|
let { env: r, key: i, req: a } = n;
|
|
23798
24107
|
if (r.IMAGES) try {
|
|
@@ -23827,16 +24136,16 @@ var cx = class {
|
|
|
23827
24136
|
return e;
|
|
23828
24137
|
}
|
|
23829
24138
|
};
|
|
23830
|
-
function
|
|
24139
|
+
function oS(e) {
|
|
23831
24140
|
return e.KAMA_RUNTIME === "cloudflare" || e.MEDIA_BUCKET ? {
|
|
23832
|
-
storage: new
|
|
23833
|
-
optimizer: new
|
|
24141
|
+
storage: new iS(e.MEDIA_BUCKET, e.CDN_DOMAIN || ""),
|
|
24142
|
+
optimizer: new aS()
|
|
23834
24143
|
} : {
|
|
23835
|
-
storage: new
|
|
23836
|
-
optimizer: new
|
|
24144
|
+
storage: new nS(e.LOCAL_MEDIA_PATH),
|
|
24145
|
+
optimizer: new rS()
|
|
23837
24146
|
};
|
|
23838
24147
|
}
|
|
23839
|
-
function
|
|
24148
|
+
function sS(e) {
|
|
23840
24149
|
if (!e || typeof e != "object") return {
|
|
23841
24150
|
cleanedData: e,
|
|
23842
24151
|
assetRefs: [],
|
|
@@ -23983,7 +24292,7 @@ function px(e) {
|
|
|
23983
24292
|
nodeRefs: r
|
|
23984
24293
|
};
|
|
23985
24294
|
}
|
|
23986
|
-
async function
|
|
24295
|
+
async function cS(e, t, n) {
|
|
23987
24296
|
if (await e.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
23988
24297
|
let r = [...new Set(n.map((e) => e.assetId))], i = r.map(() => "?").join(","), a = await e.prepare(`SELECT id FROM assets WHERE id IN (${i})`).all(...r), o = Array.isArray(a) ? a : a?.results || [], s = new Set(o.map((e) => e.id)), c = /* @__PURE__ */ new Set();
|
|
23989
24298
|
for (let r of n) {
|
|
@@ -23992,7 +24301,7 @@ async function mx(e, t, n) {
|
|
|
23992
24301
|
c.has(n) || (c.add(n), await e.prepare("INSERT OR IGNORE INTO node_assets (nodeId, assetId, fieldKey, sortOrder) VALUES (?, ?, ?, ?)").run(t, r.assetId, r.fieldKey, r.sortOrder));
|
|
23993
24302
|
}
|
|
23994
24303
|
}
|
|
23995
|
-
async function
|
|
24304
|
+
async function lS(e, t, n) {
|
|
23996
24305
|
if (await e.prepare("DELETE FROM node_terms WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
23997
24306
|
let r = [...new Set(n.map((e) => e.termId))], i = r.map(() => "?").join(","), a = await e.prepare(`SELECT id FROM taxonomy_terms WHERE id IN (${i})`).all(...r), o = Array.isArray(a) ? a : a?.results || [], s = new Set(o.map((e) => e.id)), c = /* @__PURE__ */ new Set();
|
|
23998
24307
|
for (let r of n) {
|
|
@@ -24001,7 +24310,7 @@ async function hx(e, t, n) {
|
|
|
24001
24310
|
c.has(n) || (c.add(n), await e.prepare("INSERT OR IGNORE INTO node_terms (nodeId, termId, fieldKey, sortOrder) VALUES (?, ?, ?, ?)").run(t, r.termId, r.fieldKey, r.sortOrder));
|
|
24002
24311
|
}
|
|
24003
24312
|
}
|
|
24004
|
-
async function
|
|
24313
|
+
async function uS(e, t, n) {
|
|
24005
24314
|
if (await e.prepare("DELETE FROM node_relations WHERE sourceNodeId = ?").run(t), n.length === 0) return;
|
|
24006
24315
|
let r = [...new Set(n.map((e) => e.targetNodeId))], i = r.map(() => "?").join(","), a = await e.prepare(`SELECT id FROM content_nodes WHERE id IN (${i})`).all(...r), o = Array.isArray(a) ? a : a?.results || [], s = new Set(o.map((e) => e.id)), c = /* @__PURE__ */ new Set();
|
|
24007
24316
|
for (let r of n) {
|
|
@@ -24010,16 +24319,16 @@ async function gx(e, t, n) {
|
|
|
24010
24319
|
c.has(n) || (c.add(n), await e.prepare("INSERT OR IGNORE INTO node_relations (sourceNodeId, targetNodeId, fieldKey, sortOrder) VALUES (?, ?, ?, ?)").run(t, r.targetNodeId, r.fieldKey, r.sortOrder));
|
|
24011
24320
|
}
|
|
24012
24321
|
}
|
|
24013
|
-
function
|
|
24322
|
+
function dS(e) {
|
|
24014
24323
|
if (!e) return null;
|
|
24015
24324
|
if (typeof e == "string" && e.startsWith("ast_")) return e;
|
|
24016
24325
|
if (typeof e == "object" && e) {
|
|
24017
24326
|
if (typeof e.id == "string" && e.id.startsWith("ast_")) return e.id;
|
|
24018
|
-
if (typeof e.id == "object") return
|
|
24327
|
+
if (typeof e.id == "object") return dS(e.id);
|
|
24019
24328
|
}
|
|
24020
24329
|
return null;
|
|
24021
24330
|
}
|
|
24022
|
-
function
|
|
24331
|
+
function fS(e) {
|
|
24023
24332
|
if (!e) return null;
|
|
24024
24333
|
if (typeof e == "string" && e.startsWith("trm_")) {
|
|
24025
24334
|
let t = Number(e.replace("trm_", ""));
|
|
@@ -24031,7 +24340,7 @@ function vx(e) {
|
|
|
24031
24340
|
}
|
|
24032
24341
|
return null;
|
|
24033
24342
|
}
|
|
24034
|
-
function
|
|
24343
|
+
function pS(e) {
|
|
24035
24344
|
if (!e) return null;
|
|
24036
24345
|
if (typeof e == "string" && e.startsWith("nod_")) {
|
|
24037
24346
|
let t = Number(e.replace("nod_", ""));
|
|
@@ -24043,14 +24352,14 @@ function yx(e) {
|
|
|
24043
24352
|
}
|
|
24044
24353
|
return null;
|
|
24045
24354
|
}
|
|
24046
|
-
async function
|
|
24355
|
+
async function mS(e, t) {
|
|
24047
24356
|
if (!t || typeof t != "object") return t;
|
|
24048
24357
|
let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = (e) => {
|
|
24049
24358
|
if (!e) return;
|
|
24050
|
-
let t =
|
|
24359
|
+
let t = dS(e), o = fS(e), s = pS(e);
|
|
24051
24360
|
if (t) {
|
|
24052
24361
|
if (n.add(t), typeof e == "object" && e.parentAssetId) {
|
|
24053
|
-
let t =
|
|
24362
|
+
let t = dS(e.parentAssetId);
|
|
24054
24363
|
t && n.add(t);
|
|
24055
24364
|
}
|
|
24056
24365
|
typeof e == "object" && e.variants && Object.values(e.variants).forEach(a);
|
|
@@ -24098,7 +24407,7 @@ async function bx(e, t) {
|
|
|
24098
24407
|
WHERE isSystemVariant = 1 AND (parentAssetId IN (${t}) OR ${Array.from(n).map(() => "filename LIKE ?").join(" OR ")})
|
|
24099
24408
|
`).all(...Array.from(n), ...Array.from(n).map((e) => `%${e}%`)), o = Array.isArray(a) ? a : a?.results || [], s = /* @__PURE__ */ new Map();
|
|
24100
24409
|
for (let e of o) {
|
|
24101
|
-
let t =
|
|
24410
|
+
let t = dS(e.parentAssetId) || Array.from(n).find((t) => e.filename.includes(t));
|
|
24102
24411
|
if (!t) continue;
|
|
24103
24412
|
let r = e.filename.match(/^crop_([a-z0-9]+)_/i), i = r ? r[1] : "standard", a = null;
|
|
24104
24413
|
try {
|
|
@@ -24135,7 +24444,7 @@ async function bx(e, t) {
|
|
|
24135
24444
|
id: e.id,
|
|
24136
24445
|
url: r,
|
|
24137
24446
|
originalUrl: i,
|
|
24138
|
-
parentAssetId:
|
|
24447
|
+
parentAssetId: dS(e.parentAssetId) || null,
|
|
24139
24448
|
cropCoordinates: a,
|
|
24140
24449
|
variants: o && Object.keys(o).length > 0 ? o : void 0,
|
|
24141
24450
|
filename: e.filename,
|
|
@@ -24148,7 +24457,7 @@ async function bx(e, t) {
|
|
|
24148
24457
|
}
|
|
24149
24458
|
let l = (e) => {
|
|
24150
24459
|
if (!e) return e;
|
|
24151
|
-
let t =
|
|
24460
|
+
let t = dS(e), n = fS(e), r = pS(e);
|
|
24152
24461
|
if (r) return o.get(r) || e;
|
|
24153
24462
|
if (n) return s.get(n) || e;
|
|
24154
24463
|
if (t) {
|
|
@@ -24161,7 +24470,7 @@ async function bx(e, t) {
|
|
|
24161
24470
|
return {
|
|
24162
24471
|
...n || {},
|
|
24163
24472
|
id: t,
|
|
24164
|
-
parentAssetId: n?.parentAssetId ?
|
|
24473
|
+
parentAssetId: n?.parentAssetId ? dS(n.parentAssetId) : null,
|
|
24165
24474
|
url: o,
|
|
24166
24475
|
originalUrl: s,
|
|
24167
24476
|
cropCoordinates: i || n?.cropCoordinates || null,
|
|
@@ -24179,7 +24488,7 @@ async function bx(e, t) {
|
|
|
24179
24488
|
};
|
|
24180
24489
|
return l(t);
|
|
24181
24490
|
}
|
|
24182
|
-
function
|
|
24491
|
+
function hS(e) {
|
|
24183
24492
|
return e ? {
|
|
24184
24493
|
nodes: e.nodes || {},
|
|
24185
24494
|
trees: e.trees || {},
|
|
@@ -24202,7 +24511,7 @@ function xx(e) {
|
|
|
24202
24511
|
treeExposedFields: ["summary"]
|
|
24203
24512
|
};
|
|
24204
24513
|
}
|
|
24205
|
-
var
|
|
24514
|
+
var gS = class {
|
|
24206
24515
|
env;
|
|
24207
24516
|
constructor(e) {
|
|
24208
24517
|
this.env = e || {};
|
|
@@ -24268,7 +24577,7 @@ var Sx = class {
|
|
|
24268
24577
|
}
|
|
24269
24578
|
async purgeInternalWorkerCache(e, t, n, r, i) {
|
|
24270
24579
|
try {
|
|
24271
|
-
let a =
|
|
24580
|
+
let a = tS(e);
|
|
24272
24581
|
if (n) {
|
|
24273
24582
|
let e = t.prepare("\n SELECT DISTINCT\n t.id AS treeId,\n t.key AS treeKey,\n t.dataJson AS treeDataJson,\n c.id AS channelId,\n c.key AS channelKey,\n c.defaultLanguage AS channelDefaultLanguage\n FROM tree_nodes tn\n JOIN trees t ON t.id = tn.treeId\n LEFT JOIN channel_trees ct ON ct.treeId = t.id\n LEFT JOIN channels c ON c.id = ct.channelId\n WHERE tn.contentId = ?\n "), r = typeof e.all == "function" ? await e.all(n) : await e.bind(n).all(), o = Array.isArray(r) ? r : r?.results || [], s = /* @__PURE__ */ new Set();
|
|
24274
24583
|
for (let e of o) {
|
|
@@ -24469,7 +24778,7 @@ var Sx = class {
|
|
|
24469
24778
|
}
|
|
24470
24779
|
}
|
|
24471
24780
|
};
|
|
24472
|
-
async function
|
|
24781
|
+
async function _S(e) {
|
|
24473
24782
|
try {
|
|
24474
24783
|
console.log("[Route Generator] Rebuilding enterprise routing table...");
|
|
24475
24784
|
let t = await e.prepare("SELECT id, key, dataJson FROM channels").all(), n = Array.isArray(t) ? t : t?.results || [], r = /* @__PURE__ */ new Map();
|
|
@@ -24586,14 +24895,14 @@ async function Cx(e) {
|
|
|
24586
24895
|
console.error("[Route Generator] Fatal error rebuilding routes:", e);
|
|
24587
24896
|
}
|
|
24588
24897
|
}
|
|
24589
|
-
var
|
|
24590
|
-
function
|
|
24591
|
-
let r = new
|
|
24898
|
+
var vS = new e();
|
|
24899
|
+
function yS(e, t, n = []) {
|
|
24900
|
+
let r = new gS(e.env), i = (async () => {
|
|
24592
24901
|
for (let i of n) {
|
|
24593
24902
|
let n = t.prepare("SELECT slug, language FROM content_nodes WHERE id = ?"), a = typeof n.get == "function" ? await n.get(i) : (await n.bind(i).all())?.results?.[0];
|
|
24594
24903
|
await r.purgeInternalWorkerCache(e, t, i, a?.slug, a?.language);
|
|
24595
24904
|
}
|
|
24596
|
-
await
|
|
24905
|
+
await _S(t), await r.purgeGlobalCacheDirect(e, t);
|
|
24597
24906
|
})().catch((e) => {
|
|
24598
24907
|
console.error("[Node Routes] Background rebuild/purge failed:", e);
|
|
24599
24908
|
});
|
|
@@ -24605,7 +24914,7 @@ function Tx(e, t, n = []) {
|
|
|
24605
24914
|
}
|
|
24606
24915
|
} catch {}
|
|
24607
24916
|
}
|
|
24608
|
-
async function
|
|
24917
|
+
async function bS(e, t, n = []) {
|
|
24609
24918
|
let r = e.prepare(t);
|
|
24610
24919
|
if (typeof r.bind == "function") {
|
|
24611
24920
|
let e = await r.bind(...n).all();
|
|
@@ -24617,50 +24926,50 @@ async function Ex(e, t, n = []) {
|
|
|
24617
24926
|
}
|
|
24618
24927
|
return [];
|
|
24619
24928
|
}
|
|
24620
|
-
async function
|
|
24929
|
+
async function xS(e, t, n = []) {
|
|
24621
24930
|
let r = e.prepare(t);
|
|
24622
24931
|
if (typeof r.bind == "function") return r.bind(...n).run();
|
|
24623
24932
|
if (typeof r.run == "function") return r.run(...n);
|
|
24624
24933
|
}
|
|
24625
|
-
function
|
|
24934
|
+
function SS(e) {
|
|
24626
24935
|
return !e || !e.trim() ? null : e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
24627
24936
|
}
|
|
24628
|
-
function
|
|
24937
|
+
function CS(e) {
|
|
24629
24938
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
24630
24939
|
}
|
|
24631
|
-
function
|
|
24940
|
+
function wS(e) {
|
|
24632
24941
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
24633
24942
|
let t = Number(e);
|
|
24634
24943
|
return isNaN(t) ? null : t;
|
|
24635
24944
|
}
|
|
24636
|
-
function
|
|
24945
|
+
function TS(e) {
|
|
24637
24946
|
let t = { ...e };
|
|
24638
24947
|
delete t.language, delete t.defaultLanguage;
|
|
24639
24948
|
for (let e of /* @__PURE__ */ "id.treeNodeId.isNew._isTreeDraft._draftParentId.nodeType.contentType.title.slug.path.routePath.hidden.is_hidden.isHidden.startShowingAt.stopShowingAt.status.createdById.updatedById.draftDataJson.publishedDataJson.publishedAt.deletedAt.channelNames.treeNames.hasUnpublishedChanges".split(".")) delete t[e];
|
|
24640
24949
|
return t;
|
|
24641
24950
|
}
|
|
24642
|
-
function
|
|
24643
|
-
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) =>
|
|
24951
|
+
function ES(e, t = /* @__PURE__ */ new Set()) {
|
|
24952
|
+
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) => ES(e, t)), t) : (typeof e == "object" && Object.values(e).forEach((e) => ES(e, t)), t) : t;
|
|
24644
24953
|
}
|
|
24645
|
-
function
|
|
24954
|
+
function DS(e, t) {
|
|
24646
24955
|
if (!e) return !0;
|
|
24647
|
-
let n = t.title !== void 0 && t.title?.trim() !== e.title?.trim(), r = t.slug !== void 0 && t.slug !== e.slug, i = t.isHidden !== void 0 &&
|
|
24956
|
+
let n = t.title !== void 0 && t.title?.trim() !== e.title?.trim(), r = t.slug !== void 0 && t.slug !== e.slug, i = t.isHidden !== void 0 && CS(t.isHidden) !== CS(e.isHidden), a = t.status !== void 0 && t.status !== e.status, o = t.startShowingAt !== void 0 && t.startShowingAt !== e.startShowingAt, s = t.stopShowingAt !== void 0 && t.stopShowingAt !== e.stopShowingAt, c = typeof e.draftDataJson == "string" ? JSON.parse(e.draftDataJson || "{}") : e.draftDataJson || {}, l = t.sanitizedFields || {}, u = l.menuTitle !== void 0 && l.menuTitle !== c.menuTitle;
|
|
24648
24957
|
return n || r || i || a || o || s || u;
|
|
24649
24958
|
}
|
|
24650
|
-
async function
|
|
24959
|
+
async function OS(e, t, n) {
|
|
24651
24960
|
for (let r of n) {
|
|
24652
|
-
let n = (await
|
|
24653
|
-
if (n && n.isSystemVariant && !((await
|
|
24961
|
+
let n = (await bS(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
|
|
24962
|
+
if (n && n.isSystemVariant && !((await bS(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0)) {
|
|
24654
24963
|
if (n.storageKeyPrivate) try {
|
|
24655
24964
|
await t.delete(n.storageKeyPrivate);
|
|
24656
24965
|
} catch (e) {
|
|
24657
24966
|
console.warn(`[Asset Cleanup] Failed to delete crop ${n.storageKeyPrivate}:`, e);
|
|
24658
24967
|
}
|
|
24659
|
-
await
|
|
24968
|
+
await xS(e, "DELETE FROM node_assets WHERE assetId = ?", [n.id]), await xS(e, "DELETE FROM assets WHERE id = ?", [n.id]);
|
|
24660
24969
|
}
|
|
24661
24970
|
}
|
|
24662
24971
|
}
|
|
24663
|
-
async function
|
|
24972
|
+
async function kS(e, t, n) {
|
|
24664
24973
|
let r = {}, i = null;
|
|
24665
24974
|
if (t) {
|
|
24666
24975
|
let a = await e.prepare("\n WITH RECURSIVE ancestor_path(id, parentId, draftDataJson, dataJson, level) AS (\n SELECT t.contentId as id, t.parentId, c.draftDataJson, c.dataJson, 0\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n WHERE t.contentId = ? AND t.treeId = ?\n UNION ALL\n SELECT t.contentId as id, t.parentId, c.draftDataJson, c.dataJson, ap.level + 1\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n INNER JOIN ancestor_path ap ON t.contentId = ap.parentId AND t.treeId = ?\n )\n SELECT draftDataJson, dataJson FROM ancestor_path ORDER BY level ASC\n ").all(t, n, n), o = Array.isArray(a) ? a : a?.results || [];
|
|
@@ -24685,8 +24994,8 @@ async function Fx(e, t, n) {
|
|
|
24685
24994
|
inheritedFields: r
|
|
24686
24995
|
};
|
|
24687
24996
|
}
|
|
24688
|
-
|
|
24689
|
-
let t = e.get("db"), n = e.req.query("id"), r = e.req.query("type"), i = e.req.query("q") || e.req.query("search"), a = e.req.query("channelId"), o = e.req.query("trashed") === "true", s = e.req.query("assetId"), c = e.req.query("sort") || "updatedAt",
|
|
24997
|
+
vS.get("/", async (e) => {
|
|
24998
|
+
let t = e.get("db"), n = e.req.query("id"), r = e.req.query("type"), i = e.req.query("q") || e.req.query("search"), a = e.req.query("channelId"), o = e.req.query("trashed") === "true", s = e.req.query("assetId"), c = e.req.query("termIds"), l = c?.split(",").map((e) => e.trim()) || [], u = e.req.query("sort") || "updatedAt", d = (e.req.query("order") || "DESC").toUpperCase() === "ASC" ? "ASC" : "DESC", f = e.req.query("limit"), p = e.req.query("offset"), m = Math.max(1, Math.min(100, parseInt(f || "50", 10))), h = Math.max(0, parseInt(p || "0", 10));
|
|
24690
24999
|
if (n) {
|
|
24691
25000
|
let r = Number(n);
|
|
24692
25001
|
if (isNaN(r)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
@@ -24721,9 +25030,9 @@ wx.get("/", async (e) => {
|
|
|
24721
25030
|
updatedAt: i.updatedAt
|
|
24722
25031
|
}, l = i.draftDataJson || i.dataJson;
|
|
24723
25032
|
if (l) try {
|
|
24724
|
-
let n = typeof l == "string" ? JSON.parse(l) : l, a = await t.prepare("SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r), o =
|
|
25033
|
+
let n = typeof l == "string" ? JSON.parse(l) : l, a = await t.prepare("SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r), o = hS(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, s = n.layoutId || null;
|
|
24725
25034
|
if (a) {
|
|
24726
|
-
let { resolvedLayoutId: e, inheritedFields: r } = await
|
|
25035
|
+
let { resolvedLayoutId: e, inheritedFields: r } = await kS(t, a.parentId, a.treeId);
|
|
24727
25036
|
(s === "inherit" || !s) && (s = e);
|
|
24728
25037
|
let i = /* @__PURE__ */ new Set();
|
|
24729
25038
|
o.fields && Object.entries(o.fields).forEach(([e, t]) => {
|
|
@@ -24746,7 +25055,7 @@ wx.get("/", async (e) => {
|
|
|
24746
25055
|
let r = t.allowedLayouts;
|
|
24747
25056
|
return r ? typeof r == "string" ? r === e : !Array.isArray(r) || r.length === 0 || r.includes(e) : !0;
|
|
24748
25057
|
})(s) && (s = null), (s === "inherit" || !s) && (s = o.defaultLayout || null);
|
|
24749
|
-
let u = await
|
|
25058
|
+
let u = await mS(t, TS(n));
|
|
24750
25059
|
Object.assign(c, u), c.resolvedLayoutId = s;
|
|
24751
25060
|
} catch {}
|
|
24752
25061
|
let u = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
|
|
@@ -24756,7 +25065,7 @@ wx.get("/", async (e) => {
|
|
|
24756
25065
|
let f = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(r), p = Array.isArray(f) ? f : f?.results || [], m = await Promise.all(p.map(async (e) => {
|
|
24757
25066
|
let n = {};
|
|
24758
25067
|
try {
|
|
24759
|
-
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await
|
|
25068
|
+
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await mS(t, n));
|
|
24760
25069
|
} catch {
|
|
24761
25070
|
n = {};
|
|
24762
25071
|
}
|
|
@@ -24774,17 +25083,21 @@ wx.get("/", async (e) => {
|
|
|
24774
25083
|
blocks: m
|
|
24775
25084
|
});
|
|
24776
25085
|
}
|
|
24777
|
-
|
|
24778
|
-
|
|
25086
|
+
if (c && l.some((e) => !/^[1-9]\d*$/.test(e) || !Number.isSafeInteger(Number(e)))) return e.json({ error: "Invalid taxonomy term IDs" }, 400);
|
|
25087
|
+
let g = [], _ = [o ? "cn.deletedAt IS NOT NULL" : "cn.deletedAt IS NULL"];
|
|
25088
|
+
if (a && a !== "all" && (_.push("EXISTS (SELECT 1 FROM node_channels nc WHERE nc.nodeId = cn.id AND nc.channelId = ?)"), g.push(Number(a) || a)), s && (_.push("\n EXISTS (\n SELECT 1 FROM node_assets na_f \n JOIN assets a_f ON a_f.id = na_f.assetId\n WHERE na_f.nodeId = cn.id \n AND (na_f.assetId = ? OR a_f.parentAssetId = ? OR a_f.id = (SELECT parentAssetId FROM assets WHERE id = ?))\n )\n "), g.push(s, s, s)), l.length > 0 && (_.push(`EXISTS (
|
|
25089
|
+
SELECT 1 FROM node_terms nt
|
|
25090
|
+
WHERE nt.nodeId = cn.id AND nt.termId IN (${l.map(() => "?").join(",")})
|
|
25091
|
+
)`), g.push(...l.map(Number))), r && r !== "all") {
|
|
24779
25092
|
let e = r.split(",").map((e) => e.trim()).filter(Boolean);
|
|
24780
|
-
e.length > 0 && (
|
|
25093
|
+
e.length > 0 && (_.push(`cn.contentType IN (${e.map(() => "?").join(",")})`), g.push(...e));
|
|
24781
25094
|
}
|
|
24782
25095
|
if (i && i.trim()) {
|
|
24783
|
-
|
|
25096
|
+
_.push("(cn.title LIKE ? OR cn.slug LIKE ?)");
|
|
24784
25097
|
let e = `%${i.trim()}%`;
|
|
24785
|
-
|
|
25098
|
+
g.push(e, e);
|
|
24786
25099
|
}
|
|
24787
|
-
let
|
|
25100
|
+
let v = `WHERE ${_.join(" AND ")}`, y = await t.prepare(`SELECT COUNT(*) as total FROM content_nodes cn ${v}`).get(...g), b = y ? y.total : 0, x = "cn.updatedAt", S = {
|
|
24788
25101
|
createdAt: "cn.createdAt",
|
|
24789
25102
|
updatedAt: "cn.updatedAt",
|
|
24790
25103
|
title: "LOWER(cn.title)",
|
|
@@ -24794,10 +25107,10 @@ wx.get("/", async (e) => {
|
|
|
24794
25107
|
status: "LOWER(cn.status)",
|
|
24795
25108
|
isHidden: "cn.isHidden"
|
|
24796
25109
|
};
|
|
24797
|
-
|
|
24798
|
-
let
|
|
25110
|
+
S[u] ? x = S[u] : u && u.length > 0 && (x = `json_extract(CASE WHEN cn.draftDataJson IS NOT NULL AND cn.draftDataJson != '' THEN cn.draftDataJson WHEN cn.dataJson IS NOT NULL AND cn.dataJson != '' THEN cn.dataJson ELSE '{}' END, '$.${u.replace(/[^a-zA-Z0-9_]/g, "")}')`);
|
|
25111
|
+
let C = `
|
|
24799
25112
|
WITH filtered_nodes AS (
|
|
24800
|
-
SELECT cn.* FROM content_nodes cn ${
|
|
25113
|
+
SELECT cn.* FROM content_nodes cn ${v} ORDER BY ${x} ${d} LIMIT ? OFFSET ?
|
|
24801
25114
|
),
|
|
24802
25115
|
node_asset_counts AS (
|
|
24803
25116
|
SELECT
|
|
@@ -24821,27 +25134,27 @@ wx.get("/", async (e) => {
|
|
|
24821
25134
|
(SELECT path FROM node_routes nr WHERE nr.nodeId = fn.id AND isCanonical = 1 LIMIT 1) as routePath
|
|
24822
25135
|
FROM filtered_nodes fn
|
|
24823
25136
|
LEFT JOIN node_asset_counts nac ON fn.id = nac.nodeId
|
|
24824
|
-
ORDER BY ${
|
|
24825
|
-
`,
|
|
24826
|
-
...
|
|
24827
|
-
|
|
24828
|
-
|
|
24829
|
-
],
|
|
24830
|
-
if (
|
|
24831
|
-
let e =
|
|
25137
|
+
ORDER BY ${x.replace(/cn\./g, "fn.")} ${d}
|
|
25138
|
+
`, ee = [
|
|
25139
|
+
...g,
|
|
25140
|
+
m,
|
|
25141
|
+
h
|
|
25142
|
+
], w = await t.prepare(C).all(...ee), te = Array.isArray(w) ? w : w?.results || [], ne = te.map((e) => e.id), T = {}, E = {};
|
|
25143
|
+
if (ne.length > 0) {
|
|
25144
|
+
let e = ne.map(() => "?").join(","), n = await t.prepare(`
|
|
24832
25145
|
SELECT nc.nodeId, c.label FROM node_channels nc JOIN channels c ON nc.channelId = c.id WHERE nc.nodeId IN (${e})
|
|
24833
|
-
`).all(...
|
|
25146
|
+
`).all(...ne);
|
|
24834
25147
|
(Array.isArray(n) ? n : n?.results || []).forEach((e) => {
|
|
24835
|
-
|
|
25148
|
+
T[e.nodeId] || (T[e.nodeId] = []), T[e.nodeId].push(e.label);
|
|
24836
25149
|
});
|
|
24837
25150
|
let r = await t.prepare(`
|
|
24838
25151
|
SELECT tn.contentId as nodeId, t.label FROM tree_nodes tn JOIN trees t ON tn.treeId = t.id WHERE tn.contentId IN (${e})
|
|
24839
|
-
`).all(...
|
|
25152
|
+
`).all(...ne);
|
|
24840
25153
|
(Array.isArray(r) ? r : r?.results || []).forEach((e) => {
|
|
24841
|
-
|
|
25154
|
+
E[e.nodeId] || (E[e.nodeId] = []), E[e.nodeId].includes(e.label) || E[e.nodeId].push(e.label);
|
|
24842
25155
|
});
|
|
24843
25156
|
}
|
|
24844
|
-
let D = await Promise.all(
|
|
25157
|
+
let D = await Promise.all(te.map(async (e) => {
|
|
24845
25158
|
let n = e.status === "draft" || !!e.hasUnpublishedChanges, r = {
|
|
24846
25159
|
id: e.id,
|
|
24847
25160
|
title: e.title,
|
|
@@ -24861,8 +25174,8 @@ wx.get("/", async (e) => {
|
|
|
24861
25174
|
updatedById: e.updatedById || null,
|
|
24862
25175
|
createdAt: e.createdAt,
|
|
24863
25176
|
updatedAt: e.updatedAt,
|
|
24864
|
-
channelNames:
|
|
24865
|
-
treeNames:
|
|
25177
|
+
channelNames: T[e.id] || [],
|
|
25178
|
+
treeNames: E[e.id] || [],
|
|
24866
25179
|
assetCount: e.assetCount || 0,
|
|
24867
25180
|
imageCount: e.imageCount || 0,
|
|
24868
25181
|
videoCount: e.videoCount || 0,
|
|
@@ -24870,47 +25183,47 @@ wx.get("/", async (e) => {
|
|
|
24870
25183
|
otherCount: e.otherCount || 0
|
|
24871
25184
|
}, i = e.draftDataJson || e.dataJson;
|
|
24872
25185
|
if (i) try {
|
|
24873
|
-
let e = typeof i == "string" ? JSON.parse(i) : i, n = await
|
|
25186
|
+
let e = typeof i == "string" ? JSON.parse(i) : i, n = await mS(t, TS(e));
|
|
24874
25187
|
Object.assign(r, n);
|
|
24875
25188
|
} catch {}
|
|
24876
25189
|
return r;
|
|
24877
25190
|
}));
|
|
24878
25191
|
return e.json({
|
|
24879
25192
|
items: D,
|
|
24880
|
-
total:
|
|
24881
|
-
hasMore:
|
|
24882
|
-
offset:
|
|
24883
|
-
limit:
|
|
25193
|
+
total: b,
|
|
25194
|
+
hasMore: h + D.length < b,
|
|
25195
|
+
offset: h,
|
|
25196
|
+
limit: m
|
|
24884
25197
|
});
|
|
24885
|
-
}),
|
|
24886
|
-
let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, startShowingAt: m, stopShowingAt: h, blocks: g, channels: _, trees: v, ...y } = r, { cleanedData: b, assetRefs: x, termRefs: S, nodeRefs: C } =
|
|
24887
|
-
if (
|
|
24888
|
-
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(
|
|
25198
|
+
}), vS.post("/", async (e) => {
|
|
25199
|
+
let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, startShowingAt: m, stopShowingAt: h, blocks: g, channels: _, trees: v, ...y } = r, { cleanedData: b, assetRefs: x, termRefs: S, nodeRefs: C } = sS(TS(y)), ee = CS(d === void 0 ? f === void 0 ? p : f : d), w = l || u || "page", te = e.get("user")?.id || null, ne = typeof c == "string" && c.trim() !== "" ? c.trim() : null, T = v && Array.isArray(v) && v.length > 0 ? v[0] : null, E = T ? T.treeId || T.id : null, D = null;
|
|
25200
|
+
if (E) {
|
|
25201
|
+
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(E) || -1, String(E));
|
|
24889
25202
|
if (e?.dataJson) try {
|
|
24890
25203
|
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
24891
|
-
|
|
25204
|
+
D = t.defaultLanguage?.trim() || t.language?.trim() || null;
|
|
24892
25205
|
} catch {}
|
|
24893
25206
|
}
|
|
24894
|
-
if (!
|
|
25207
|
+
if (!D && _ && Array.isArray(_) && _.length > 0) {
|
|
24895
25208
|
let e = typeof _[0] == "object" ? _[0].id : _[0];
|
|
24896
25209
|
if (e && e !== "all") {
|
|
24897
25210
|
let n = await t.prepare("SELECT defaultLanguage, dataJson FROM channels WHERE id = ? LIMIT 1").get(Number(e));
|
|
24898
25211
|
if (n) {
|
|
24899
|
-
if (n.defaultLanguage)
|
|
25212
|
+
if (n.defaultLanguage) D = n.defaultLanguage.trim();
|
|
24900
25213
|
else if (n.dataJson) try {
|
|
24901
25214
|
let e = typeof n.dataJson == "string" ? JSON.parse(n.dataJson) : n.dataJson;
|
|
24902
|
-
|
|
25215
|
+
D = e.defaultLanguage?.trim() || e.language?.trim() || null;
|
|
24903
25216
|
} catch {}
|
|
24904
25217
|
}
|
|
24905
25218
|
}
|
|
24906
25219
|
}
|
|
24907
|
-
|
|
24908
|
-
let
|
|
25220
|
+
ne && D && ne === D && (ne = null);
|
|
25221
|
+
let O = a, re = /* @__PURE__ */ new Set(), k = !1, A = "draft", j = 0, ie = s === void 0 ? null : SS(s);
|
|
24909
25222
|
if (ie) {
|
|
24910
25223
|
let n = [];
|
|
24911
25224
|
if (v !== void 0 && Array.isArray(v) && v.length > 0) for (let e of v) n.push({
|
|
24912
25225
|
treeId: Number(e.treeId),
|
|
24913
|
-
parentId:
|
|
25226
|
+
parentId: wS(e.parentId ?? e._draftParentId ?? null)
|
|
24914
25227
|
});
|
|
24915
25228
|
else if (a) {
|
|
24916
25229
|
let e = await t.prepare("SELECT treeId, parentId FROM tree_nodes WHERE contentId = ?").all(a), r = Array.isArray(e) ? e : e?.results || [];
|
|
@@ -24936,8 +25249,8 @@ wx.get("/", async (e) => {
|
|
|
24936
25249
|
}
|
|
24937
25250
|
}
|
|
24938
25251
|
if (a) {
|
|
24939
|
-
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, startShowingAt, stopShowingAt, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a), n = o === void 0 ? e?.title || "Untitled" : o, r = ie ?? e?.slug ?? null, i =
|
|
24940
|
-
|
|
25252
|
+
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, startShowingAt, stopShowingAt, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a), n = o === void 0 ? e?.title || "Untitled" : o, r = ie ?? e?.slug ?? null, i = w || e?.contentType || "page", l = c === void 0 ? e?.language ?? null : ne, u = ee === void 0 ? CS(e?.isHidden) : ee, d = m === void 0 ? e?.startShowingAt ?? null : m, f = h === void 0 ? e?.stopShowingAt ?? null : h;
|
|
25253
|
+
k = DS(e, {
|
|
24941
25254
|
title: n,
|
|
24942
25255
|
slug: r,
|
|
24943
25256
|
isHidden: u,
|
|
@@ -24947,7 +25260,7 @@ wx.get("/", async (e) => {
|
|
|
24947
25260
|
});
|
|
24948
25261
|
let p = e?.draftDataJson || e?.dataJson || "{}";
|
|
24949
25262
|
try {
|
|
24950
|
-
|
|
25263
|
+
ES(typeof p == "string" ? JSON.parse(p) : p, re);
|
|
24951
25264
|
} catch {}
|
|
24952
25265
|
let _ = {};
|
|
24953
25266
|
try {
|
|
@@ -24966,7 +25279,7 @@ wx.get("/", async (e) => {
|
|
|
24966
25279
|
..._,
|
|
24967
25280
|
...v
|
|
24968
25281
|
}), x = !1;
|
|
24969
|
-
if (o !== void 0 && o.trim() !== (e?.title || "Untitled") && (x = !0), s !== void 0 && ie !== e?.slug && (x = !0), c !== void 0 &&
|
|
25282
|
+
if (o !== void 0 && o.trim() !== (e?.title || "Untitled") && (x = !0), s !== void 0 && ie !== e?.slug && (x = !0), c !== void 0 && ne !== e?.language && (x = !0), m !== void 0 && d !== e?.startShowingAt && (x = !0), h !== void 0 && f !== e?.stopShowingAt && (x = !0), !x && Object.keys(b).length > 0) {
|
|
24970
25283
|
for (let e of Object.keys(b)) if (JSON.stringify(b[e]) !== JSON.stringify(_[e])) {
|
|
24971
25284
|
x = !0;
|
|
24972
25285
|
break;
|
|
@@ -24991,41 +25304,41 @@ wx.get("/", async (e) => {
|
|
|
24991
25304
|
A = e?.status === "published" || e?.publishedAt ? "published" : "draft";
|
|
24992
25305
|
let S = e?.hasUnpublishedChanges === 1 || e?.hasUnpublishedChanges === !0;
|
|
24993
25306
|
j = x ? 1 : +!!S;
|
|
24994
|
-
let C = e?.publishedAt != null || e?.status === "published",
|
|
24995
|
-
await t.prepare("\n UPDATE content_nodes \n SET title = ?, slug = ?, language = ?, contentType = ?, isHidden = ?, startShowingAt = ?, stopShowingAt = ?, status = ?, draftDataJson = ?, hasUnpublishedChanges = ?, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(
|
|
25307
|
+
let C = e?.publishedAt != null || e?.status === "published", T = C ? e.title : n, E = C ? e.slug : r, D = C ? e.contentType : i, O = C ? e.language : l, ae = C ? e.isHidden : u, oe = C ? e.startShowingAt : d, se = C ? e.stopShowingAt : f;
|
|
25308
|
+
await t.prepare("\n UPDATE content_nodes \n SET title = ?, slug = ?, language = ?, contentType = ?, isHidden = ?, startShowingAt = ?, stopShowingAt = ?, status = ?, draftDataJson = ?, hasUnpublishedChanges = ?, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(T, E, O, D, ae, oe, se, A, y, j, te, a);
|
|
24996
25309
|
} else {
|
|
24997
|
-
|
|
25310
|
+
k = !0;
|
|
24998
25311
|
let e = m === void 0 ? null : m, n = h === void 0 ? null : h, r = {
|
|
24999
25312
|
title: o || "Untitled",
|
|
25000
25313
|
slug: ie,
|
|
25001
|
-
contentType:
|
|
25002
|
-
language:
|
|
25003
|
-
isHidden:
|
|
25314
|
+
contentType: w,
|
|
25315
|
+
language: ne,
|
|
25316
|
+
isHidden: ee,
|
|
25004
25317
|
startShowingAt: e,
|
|
25005
25318
|
stopShowingAt: n,
|
|
25006
25319
|
...b
|
|
25007
|
-
}, i = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, startShowingAt, stopShowingAt, status, draftDataJson, dataJson, hasUnpublishedChanges, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, ?, ?, 'draft', ?, NULL, 0, ?, ?)\n ").run(
|
|
25008
|
-
|
|
25320
|
+
}, i = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, startShowingAt, stopShowingAt, status, draftDataJson, dataJson, hasUnpublishedChanges, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, ?, ?, 'draft', ?, NULL, 0, ?, ?)\n ").run(w, o || "Untitled", ie, ne, ee, e, n, JSON.stringify(r), te, te);
|
|
25321
|
+
O = Number(i.lastInsertRowid);
|
|
25009
25322
|
}
|
|
25010
|
-
if (_ !== void 0 && Array.isArray(_) &&
|
|
25011
|
-
await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(
|
|
25323
|
+
if (_ !== void 0 && Array.isArray(_) && O) {
|
|
25324
|
+
await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(O);
|
|
25012
25325
|
let e = [...new Set(_.map((e) => typeof e == "object" && e ? e.id || e.channelId : e))].filter((e) => e && e !== "all").map((e) => Number(e) || e);
|
|
25013
25326
|
if (e.length > 0) {
|
|
25014
|
-
let n = e.map(() => "(?, ?)").join(", "), r = e.flatMap((e) => [
|
|
25327
|
+
let n = e.map(() => "(?, ?)").join(", "), r = e.flatMap((e) => [O, e]);
|
|
25015
25328
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${n}`).run(...r);
|
|
25016
25329
|
}
|
|
25017
25330
|
}
|
|
25018
|
-
if (v !== void 0 && Array.isArray(v) && v.length > 0 &&
|
|
25331
|
+
if (v !== void 0 && Array.isArray(v) && v.length > 0 && O) for (let e of v) {
|
|
25019
25332
|
if (!e || !e.treeId) continue;
|
|
25020
|
-
let n = Number(e.treeId) || e.treeId, r =
|
|
25021
|
-
a ? ((a.parentId !== r || a.sortOrder !== i) && (
|
|
25333
|
+
let n = Number(e.treeId) || e.treeId, r = wS(e.parentId ?? e._draftParentId ?? null), i = typeof e.sortOrder == "number" ? e.sortOrder : 0, a = await t.prepare("SELECT contentId, parentId, sortOrder FROM tree_nodes WHERE treeId = ? AND contentId = ?").get(n, O);
|
|
25334
|
+
a ? ((a.parentId !== r || a.sortOrder !== i) && (k = !0), await t.prepare("UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE treeId = ? AND contentId = ?").run(r, i, n, O)) : (k = !0, await t.prepare("INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES (?, ?, ?, ?)").run(n, O, r, i));
|
|
25022
25335
|
}
|
|
25023
25336
|
let ae = [], oe = [], se = [];
|
|
25024
|
-
if (g !== void 0 && Array.isArray(g) &&
|
|
25025
|
-
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(
|
|
25337
|
+
if (g !== void 0 && Array.isArray(g) && O) {
|
|
25338
|
+
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(O);
|
|
25026
25339
|
let e = [], n = [];
|
|
25027
25340
|
for (let t = 0; t < g.length; t++) {
|
|
25028
|
-
let r = g[t], i = r.componentId || r.elementType || "text-block", a = r.data || {}, o = String(r.blockId || a.blockId || r.instanceId || r.id || `block-${Date.now()}`), { cleanedData: s, assetRefs: c, termRefs: l, nodeRefs: u } =
|
|
25341
|
+
let r = g[t], i = r.componentId || r.elementType || "text-block", a = r.data || {}, o = String(r.blockId || a.blockId || r.instanceId || r.id || `block-${Date.now()}`), { cleanedData: s, assetRefs: c, termRefs: l, nodeRefs: u } = sS({
|
|
25029
25342
|
...a,
|
|
25030
25343
|
blockId: o,
|
|
25031
25344
|
_instanceId: o
|
|
@@ -25041,27 +25354,27 @@ wx.get("/", async (e) => {
|
|
|
25041
25354
|
fieldKey: `blocks[${t}].${e.fieldKey}`
|
|
25042
25355
|
}));
|
|
25043
25356
|
let d = r.region !== void 0 && r.region !== null && String(r.region).trim() !== "" ? String(r.region) : "content";
|
|
25044
|
-
e.push("(?, ?, ?, ?, ?, 1)"), n.push(
|
|
25357
|
+
e.push("(?, ?, ?, ?, ?, 1)"), n.push(O, t, i, JSON.stringify(s), d);
|
|
25045
25358
|
}
|
|
25046
25359
|
e.length > 0 && await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
|
|
25047
25360
|
}
|
|
25048
|
-
if (
|
|
25361
|
+
if (O) {
|
|
25049
25362
|
let n = [...x, ...ae], r = [...S, ...oe], i = [...C, ...se];
|
|
25050
|
-
await
|
|
25051
|
-
let a = new Set(n.map((e) => e.assetId)), o = new Set([...
|
|
25363
|
+
await cS(t, O, n), await lS(t, O, r), await uS(t, O, i);
|
|
25364
|
+
let a = new Set(n.map((e) => e.assetId)), o = new Set([...re].filter((e) => !a.has(e)));
|
|
25052
25365
|
if (o.size > 0) {
|
|
25053
|
-
let { storage: n } =
|
|
25054
|
-
await
|
|
25366
|
+
let { storage: n } = oS(e.env);
|
|
25367
|
+
await OS(t, n, o);
|
|
25055
25368
|
}
|
|
25056
25369
|
}
|
|
25057
|
-
return await
|
|
25370
|
+
return await tS(e).clear(), e.json({
|
|
25058
25371
|
success: !0,
|
|
25059
|
-
id:
|
|
25372
|
+
id: O,
|
|
25060
25373
|
status: A,
|
|
25061
25374
|
hasUnpublishedChanges: j === 1 || A === "draft",
|
|
25062
|
-
isStructuralChange:
|
|
25375
|
+
isStructuralChange: k
|
|
25063
25376
|
});
|
|
25064
|
-
}),
|
|
25377
|
+
}), vS.post("/publish", async (e) => {
|
|
25065
25378
|
let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
|
|
25066
25379
|
if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
|
|
25067
25380
|
let i = Number(r), a = e.get("user")?.id || null, o = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(i);
|
|
@@ -25074,38 +25387,38 @@ wx.get("/", async (e) => {
|
|
|
25074
25387
|
try {
|
|
25075
25388
|
c = typeof o.draftDataJson == "string" ? JSON.parse(o.draftDataJson) : o.draftDataJson || {};
|
|
25076
25389
|
} catch {}
|
|
25077
|
-
let l = (s.title ?? o.title ?? "").trim(), u = (c.title ?? n.title ?? o.title ?? "").trim(), d = (s.slug ?? o.slug ?? "").trim(), f = (c.slug ?? n.slug ?? o.slug ?? "").trim(), p = (s.menuTitle ?? "").trim(), m = (c.menuTitle ?? "").trim(), h = s.startShowingAt ?? o.startShowingAt ?? "", g = c.startShowingAt ?? n.startShowingAt ?? o.startShowingAt ?? "", _ = s.stopShowingAt ?? o.stopShowingAt ?? "", v = c.stopShowingAt ?? n.stopShowingAt ?? o.stopShowingAt ?? "", y = l !== "" && u !== "" && l !== u || d !== "" && f !== "" && d !== f || p !== "" && m !== "" && p !== m || h !== g || _ !== v, b = o.draftDataJson || o.dataJson || "{}", x = c.title ?? n.title ?? o.title ?? "Untitled", S = c.slug ?? n.slug ?? o.slug ?? null, C = c.language === void 0 ? o.language : c.language,
|
|
25078
|
-
await t.prepare("\n UPDATE content_nodes\n SET title = ?, slug = ?, language = ?, contentType = ?, isHidden = ?, startShowingAt = ?, stopShowingAt = ?, publishedDataJson = ?, dataJson = ?, publishedAt = CURRENT_TIMESTAMP, status = 'published', hasUnpublishedChanges = 0, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(x, S, C,
|
|
25079
|
-
let
|
|
25080
|
-
if (
|
|
25390
|
+
let l = (s.title ?? o.title ?? "").trim(), u = (c.title ?? n.title ?? o.title ?? "").trim(), d = (s.slug ?? o.slug ?? "").trim(), f = (c.slug ?? n.slug ?? o.slug ?? "").trim(), p = (s.menuTitle ?? "").trim(), m = (c.menuTitle ?? "").trim(), h = s.startShowingAt ?? o.startShowingAt ?? "", g = c.startShowingAt ?? n.startShowingAt ?? o.startShowingAt ?? "", _ = s.stopShowingAt ?? o.stopShowingAt ?? "", v = c.stopShowingAt ?? n.stopShowingAt ?? o.stopShowingAt ?? "", y = l !== "" && u !== "" && l !== u || d !== "" && f !== "" && d !== f || p !== "" && m !== "" && p !== m || h !== g || _ !== v, b = o.draftDataJson || o.dataJson || "{}", x = c.title ?? n.title ?? o.title ?? "Untitled", S = c.slug ?? n.slug ?? o.slug ?? null, C = c.language === void 0 ? o.language : c.language, ee = c.contentType ?? o.contentType ?? "page", w = c.isHidden === void 0 ? o.isHidden : c.isHidden, te = c.startShowingAt === void 0 ? n.startShowingAt === void 0 ? o.startShowingAt : n.startShowingAt : c.startShowingAt, ne = c.stopShowingAt === void 0 ? n.stopShowingAt === void 0 ? o.stopShowingAt : n.stopShowingAt : c.stopShowingAt;
|
|
25391
|
+
await t.prepare("\n UPDATE content_nodes\n SET title = ?, slug = ?, language = ?, contentType = ?, isHidden = ?, startShowingAt = ?, stopShowingAt = ?, publishedDataJson = ?, dataJson = ?, publishedAt = CURRENT_TIMESTAMP, status = 'published', hasUnpublishedChanges = 0, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(x, S, C, ee, w, te, ne, b, b, a, i), await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 0").run(i);
|
|
25392
|
+
let T = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(i), E = Array.isArray(T) ? T : T?.results || [];
|
|
25393
|
+
if (E.length > 0) {
|
|
25081
25394
|
let e = [], n = [];
|
|
25082
|
-
for (let t of
|
|
25395
|
+
for (let t of E) {
|
|
25083
25396
|
let r = t.region !== void 0 && t.region !== null && String(t.region).trim() !== "" ? String(t.region) : "content";
|
|
25084
25397
|
e.push("(?, ?, ?, ?, ?, 0)"), n.push(i, t.sortOrder, t.elementType, t.dataJson, r);
|
|
25085
25398
|
}
|
|
25086
25399
|
await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
|
|
25087
25400
|
}
|
|
25088
|
-
let
|
|
25089
|
-
version:
|
|
25401
|
+
let D = ((await t.prepare("SELECT COUNT(*) as count FROM node_revisions WHERE nodeId = ?").get(i))?.count || 0) + 1, O = {
|
|
25402
|
+
version: D,
|
|
25090
25403
|
publishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
25091
25404
|
node: {
|
|
25092
25405
|
...o,
|
|
25093
25406
|
dataJson: b
|
|
25094
25407
|
},
|
|
25095
|
-
blocks:
|
|
25408
|
+
blocks: E
|
|
25096
25409
|
};
|
|
25097
|
-
await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(i,
|
|
25098
|
-
let
|
|
25099
|
-
return y ?
|
|
25410
|
+
await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(i, D, JSON.stringify(O), a), await tS(e).clear();
|
|
25411
|
+
let re = new gS(e.env);
|
|
25412
|
+
return y ? yS(e, t, [i]) : re.purgeNode(e, t, i, !1), e.json({
|
|
25100
25413
|
success: !0,
|
|
25101
25414
|
id: i,
|
|
25102
25415
|
status: "published",
|
|
25103
|
-
version:
|
|
25104
|
-
publishedAt:
|
|
25416
|
+
version: D,
|
|
25417
|
+
publishedAt: O.publishedAt,
|
|
25105
25418
|
hasUnpublishedChanges: !1,
|
|
25106
25419
|
isStructuralChange: y
|
|
25107
25420
|
});
|
|
25108
|
-
}),
|
|
25421
|
+
}), vS.post("/publish/batch", async (e) => {
|
|
25109
25422
|
let t = e.get("db"), n = await e.req.json(), r = n.ids;
|
|
25110
25423
|
if (!Array.isArray(r) || r.length === 0) return e.json({ error: "Array of Node IDs required" }, 400);
|
|
25111
25424
|
let i = e.get("user")?.id || null, a = !1, o = [];
|
|
@@ -25124,31 +25437,31 @@ wx.get("/", async (e) => {
|
|
|
25124
25437
|
} catch {}
|
|
25125
25438
|
let u = (c.title ?? s.title ?? "").trim(), d = (l.title ?? n.title ?? s.title ?? "").trim(), f = (c.slug ?? s.slug ?? "").trim(), p = (l.slug ?? n.slug ?? s.slug ?? "").trim(), m = (c.menuTitle ?? "").trim(), h = (l.menuTitle ?? "").trim(), g = c.startShowingAt ?? s.startShowingAt ?? "", _ = l.startShowingAt ?? n.startShowingAt ?? s.startShowingAt ?? "", v = c.stopShowingAt ?? s.stopShowingAt ?? "", y = l.stopShowingAt ?? n.stopShowingAt ?? s.stopShowingAt ?? "";
|
|
25126
25439
|
(u !== "" && d !== "" && u !== d || f !== "" && p !== "" && f !== p || m !== "" && h !== "" && m !== h || g !== _ || v !== y) && (a = !0);
|
|
25127
|
-
let b = s.draftDataJson || s.dataJson || "{}", x = l.title ?? n.title ?? s.title ?? "Untitled", S = l.slug ?? n.slug ?? s.slug ?? null, C = l.language === void 0 ? s.language : l.language,
|
|
25128
|
-
await t.prepare("\n UPDATE content_nodes\n SET title = ?, slug = ?, language = ?, contentType = ?, isHidden = ?, startShowingAt = ?, stopShowingAt = ?, publishedDataJson = ?, dataJson = ?, publishedAt = CURRENT_TIMESTAMP, status = 'published', hasUnpublishedChanges = 0, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(x, S, C,
|
|
25129
|
-
let
|
|
25130
|
-
if (
|
|
25440
|
+
let b = s.draftDataJson || s.dataJson || "{}", x = l.title ?? n.title ?? s.title ?? "Untitled", S = l.slug ?? n.slug ?? s.slug ?? null, C = l.language === void 0 ? s.language : l.language, ee = l.contentType ?? s.contentType ?? "page", w = l.isHidden === void 0 ? s.isHidden : l.isHidden, te = l.startShowingAt === void 0 ? n.startShowingAt === void 0 ? s.startShowingAt : n.startShowingAt : l.startShowingAt, ne = l.stopShowingAt === void 0 ? n.stopShowingAt === void 0 ? s.stopShowingAt : n.stopShowingAt : l.stopShowingAt;
|
|
25441
|
+
await t.prepare("\n UPDATE content_nodes\n SET title = ?, slug = ?, language = ?, contentType = ?, isHidden = ?, startShowingAt = ?, stopShowingAt = ?, publishedDataJson = ?, dataJson = ?, publishedAt = CURRENT_TIMESTAMP, status = 'published', hasUnpublishedChanges = 0, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(x, S, C, ee, w, te, ne, b, b, i, r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 0").run(r);
|
|
25442
|
+
let T = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(r), E = Array.isArray(T) ? T : T?.results || [];
|
|
25443
|
+
if (E.length > 0) {
|
|
25131
25444
|
let e = [], n = [];
|
|
25132
|
-
for (let t of
|
|
25445
|
+
for (let t of E) {
|
|
25133
25446
|
let i = t.region !== void 0 && t.region !== null && String(t.region).trim() !== "" ? String(t.region) : "content";
|
|
25134
25447
|
e.push("(?, ?, ?, ?, ?, 0)"), n.push(r, t.sortOrder, t.elementType, t.dataJson, i);
|
|
25135
25448
|
}
|
|
25136
25449
|
await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
|
|
25137
25450
|
}
|
|
25138
|
-
let
|
|
25139
|
-
version:
|
|
25451
|
+
let D = ((await t.prepare("SELECT COUNT(*) as count FROM node_revisions WHERE nodeId = ?").get(r))?.count || 0) + 1, O = {
|
|
25452
|
+
version: D,
|
|
25140
25453
|
publishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
25141
25454
|
node: {
|
|
25142
25455
|
...s,
|
|
25143
25456
|
dataJson: b
|
|
25144
25457
|
},
|
|
25145
|
-
blocks:
|
|
25458
|
+
blocks: E
|
|
25146
25459
|
};
|
|
25147
|
-
await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(r,
|
|
25460
|
+
await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(r, D, JSON.stringify(O), i), o.push(r);
|
|
25148
25461
|
}
|
|
25149
|
-
await
|
|
25150
|
-
let s = new
|
|
25151
|
-
if (a)
|
|
25462
|
+
await tS(e).clear();
|
|
25463
|
+
let s = new gS(e.env);
|
|
25464
|
+
if (a) yS(e, t, o);
|
|
25152
25465
|
else for (let n of o) s.purgeNode(e, t, n, !1);
|
|
25153
25466
|
return e.json({
|
|
25154
25467
|
success: !0,
|
|
@@ -25156,29 +25469,29 @@ wx.get("/", async (e) => {
|
|
|
25156
25469
|
publishedIds: o,
|
|
25157
25470
|
isStructuralChange: a
|
|
25158
25471
|
});
|
|
25159
|
-
}),
|
|
25472
|
+
}), vS.delete("/", async (e) => {
|
|
25160
25473
|
let t = e.get("db"), n = e.req.query("id");
|
|
25161
25474
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
25162
25475
|
let r = Number(n);
|
|
25163
|
-
return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await
|
|
25476
|
+
return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await tS(e).clear(), new gS(e.env), yS(e, t, [r]), e.json({
|
|
25164
25477
|
success: !0,
|
|
25165
25478
|
deletedNodeId: r
|
|
25166
25479
|
});
|
|
25167
|
-
}),
|
|
25480
|
+
}), vS.post("/restore", async (e) => {
|
|
25168
25481
|
let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
|
|
25169
|
-
return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await
|
|
25482
|
+
return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await tS(e).clear(), new gS(e.env), yS(e, t, [r]), e.json({
|
|
25170
25483
|
success: !0,
|
|
25171
25484
|
restoredNodeId: r
|
|
25172
25485
|
})) : e.json({ error: "Node not found" }, 404) : e.json({ error: "Node ID required" }, 400);
|
|
25173
|
-
}),
|
|
25486
|
+
}), vS.delete("/purge", async (e) => {
|
|
25174
25487
|
let t = e.get("db"), n = e.req.query("id");
|
|
25175
25488
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
25176
25489
|
let r = Number(n);
|
|
25177
|
-
return await new
|
|
25490
|
+
return await new gS(e.env).purgeInternalWorkerCache(e, t, r), await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ?").run(r), await t.prepare("DELETE FROM node_revisions WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_terms WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM content_nodes WHERE id = ?").run(r), await tS(e).clear(), yS(e, t), e.json({
|
|
25178
25491
|
success: !0,
|
|
25179
25492
|
purgedNodeId: r
|
|
25180
25493
|
});
|
|
25181
|
-
}),
|
|
25494
|
+
}), vS.get("/:id/revisions", async (e) => {
|
|
25182
25495
|
let t = e.get("db"), n = Number(e.req.param("id"));
|
|
25183
25496
|
if (isNaN(n)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
25184
25497
|
let r = await t.prepare("\n SELECT version, createdById, snapshotJson \n FROM node_revisions \n WHERE nodeId = ? \n ORDER BY version DESC\n ").all(n), i = (Array.isArray(r) ? r : r?.results || []).map((e) => {
|
|
@@ -25194,7 +25507,7 @@ wx.get("/", async (e) => {
|
|
|
25194
25507
|
};
|
|
25195
25508
|
});
|
|
25196
25509
|
return e.json({ revisions: i });
|
|
25197
|
-
}),
|
|
25510
|
+
}), vS.get("/:id/revisions/:version", async (e) => {
|
|
25198
25511
|
let t = e.get("db"), n = Number(e.req.param("id")), r = Number(e.req.param("version")), i = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(n, r);
|
|
25199
25512
|
if (!i) return e.json({ error: "Snapshot not found" }, 404);
|
|
25200
25513
|
let a = {};
|
|
@@ -25204,7 +25517,7 @@ wx.get("/", async (e) => {
|
|
|
25204
25517
|
return e.json({ error: "Corrupt snapshot data" }, 500);
|
|
25205
25518
|
}
|
|
25206
25519
|
return e.json({ snapshot: a });
|
|
25207
|
-
}),
|
|
25520
|
+
}), vS.post("/:id/revisions/:version/restore", async (e) => {
|
|
25208
25521
|
let t = e.get("db"), n = Number(e.req.param("id")), r = Number(e.req.param("version")), i = e.get("user")?.id || null, a = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(n);
|
|
25209
25522
|
if (!a) return e.json({ error: "Node not found" }, 404);
|
|
25210
25523
|
let o = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(n, r);
|
|
@@ -25221,11 +25534,11 @@ wx.get("/", async (e) => {
|
|
|
25221
25534
|
for (let t of s.blocks) e.push("(?, ?, ?, ?, ?, 1)"), r.push(n, t.sortOrder, t.elementType, t.dataJson, t.region || "content");
|
|
25222
25535
|
await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...r);
|
|
25223
25536
|
}
|
|
25224
|
-
return await
|
|
25537
|
+
return await tS(e).clear(), e.json({
|
|
25225
25538
|
success: !0,
|
|
25226
25539
|
restoredVersion: r
|
|
25227
25540
|
});
|
|
25228
|
-
}),
|
|
25541
|
+
}), vS.post("/:id/toggle-visibility", async (e) => {
|
|
25229
25542
|
let t = e.get("db"), n = Number(e.req.param("id")), r = await e.req.json();
|
|
25230
25543
|
if (isNaN(n)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
25231
25544
|
let i = +(r.isHidden === !0 || r.isHidden === 1 || r.isHidden === "true"), a = e.get("user")?.id || null, o = await t.prepare("SELECT draftDataJson, dataJson, publishedDataJson, isHidden, status FROM content_nodes WHERE id = ?").get(n);
|
|
@@ -25247,16 +25560,16 @@ wx.get("/", async (e) => {
|
|
|
25247
25560
|
let t = JSON.stringify(e);
|
|
25248
25561
|
s += ", dataJson = ?, publishedDataJson = ?", c.push(t, t);
|
|
25249
25562
|
}
|
|
25250
|
-
s += " WHERE id = ?", c.push(n), await t.prepare(s).run(...c), await
|
|
25251
|
-
let u = await new
|
|
25563
|
+
s += " WHERE id = ?", c.push(n), await t.prepare(s).run(...c), await tS(e).clear();
|
|
25564
|
+
let u = await new gS(e.env).purgeVisibilityChange(e, t, n);
|
|
25252
25565
|
return e.json({
|
|
25253
25566
|
success: !0,
|
|
25254
25567
|
isHidden: i,
|
|
25255
25568
|
cacheInvalidated: u
|
|
25256
25569
|
});
|
|
25257
25570
|
});
|
|
25258
|
-
var
|
|
25259
|
-
function
|
|
25571
|
+
var AS = new e();
|
|
25572
|
+
function jS(e, t = null) {
|
|
25260
25573
|
let n = [];
|
|
25261
25574
|
for (let r = 0; r < e.length; r++) {
|
|
25262
25575
|
let i = e[r];
|
|
@@ -25268,19 +25581,19 @@ function Lx(e, t = null) {
|
|
|
25268
25581
|
id: o,
|
|
25269
25582
|
parentId: t,
|
|
25270
25583
|
sortOrder: r
|
|
25271
|
-
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...
|
|
25584
|
+
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...jS(i.children, o)));
|
|
25272
25585
|
}
|
|
25273
25586
|
return n;
|
|
25274
25587
|
}
|
|
25275
|
-
function
|
|
25588
|
+
function MS(e) {
|
|
25276
25589
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
25277
25590
|
let t = Number(e);
|
|
25278
25591
|
return isNaN(t) ? null : t;
|
|
25279
25592
|
}
|
|
25280
|
-
function
|
|
25593
|
+
function NS(e) {
|
|
25281
25594
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
25282
25595
|
}
|
|
25283
|
-
|
|
25596
|
+
AS.get("/tree.json", async (e) => {
|
|
25284
25597
|
try {
|
|
25285
25598
|
let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
|
|
25286
25599
|
if (isNaN(Number(n))) {
|
|
@@ -25333,9 +25646,9 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25333
25646
|
} catch (t) {
|
|
25334
25647
|
return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
|
|
25335
25648
|
}
|
|
25336
|
-
}),
|
|
25649
|
+
}), AS.post("/tree.json", async (e) => {
|
|
25337
25650
|
try {
|
|
25338
|
-
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i =
|
|
25651
|
+
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = tS(e), a = new gS(e.env), o = 1;
|
|
25339
25652
|
if (isNaN(Number(r))) {
|
|
25340
25653
|
let e = await t.prepare("SELECT id FROM trees WHERE key = ?").get(r);
|
|
25341
25654
|
if (e && e.id) o = Number(e.id);
|
|
@@ -25345,7 +25658,7 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25345
25658
|
}
|
|
25346
25659
|
} else o = Number(r);
|
|
25347
25660
|
if (n.tree && Array.isArray(n.tree)) {
|
|
25348
|
-
let r =
|
|
25661
|
+
let r = jS(n.tree, null);
|
|
25349
25662
|
if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
|
|
25350
25663
|
let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
|
|
25351
25664
|
s += "parentId = CASE contentId \n", n.forEach(() => {
|
|
@@ -25360,14 +25673,14 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25360
25673
|
c.push(e.id, e.sortOrder);
|
|
25361
25674
|
}), c.push(...i), c.push(o), await t.prepare(s).run(...c);
|
|
25362
25675
|
}
|
|
25363
|
-
return await
|
|
25676
|
+
return await _S(t), await i.clear(), r.length > 0 && a.purgeNode(e, t, r[0].id, !0), e.json({
|
|
25364
25677
|
success: !0,
|
|
25365
25678
|
reorderedCount: r.length
|
|
25366
25679
|
});
|
|
25367
25680
|
}
|
|
25368
|
-
let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h =
|
|
25681
|
+
let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h = NS(n.isHidden === void 0 ? m.isHidden === void 0 ? m.hidden : m.isHidden : n.isHidden);
|
|
25369
25682
|
delete m._isTreeDraft, delete m._draftParentId, delete m.isNew, delete m.nodeType, delete m.contentType, delete m.title, delete m.slug, delete m.hidden, delete m.is_hidden, delete m.isHidden, delete m.status;
|
|
25370
|
-
let g =
|
|
25683
|
+
let g = MS(u), _ = e.get("user")?.id || null;
|
|
25371
25684
|
if (s === "create") {
|
|
25372
25685
|
let r = m.slug || n.slug || c, a = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
|
|
25373
25686
|
if (a) {
|
|
@@ -25422,7 +25735,7 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25422
25735
|
let e = x.map(() => "(?, ?)").join(", "), n = x.flatMap((e) => [f, e]);
|
|
25423
25736
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
|
|
25424
25737
|
}
|
|
25425
|
-
return await
|
|
25738
|
+
return await _S(t), await i.clear(), e.json({
|
|
25426
25739
|
success: !0,
|
|
25427
25740
|
id: f,
|
|
25428
25741
|
treeNodeId: f,
|
|
@@ -25459,14 +25772,14 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25459
25772
|
field: "slug"
|
|
25460
25773
|
}, 409);
|
|
25461
25774
|
}
|
|
25462
|
-
return await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d), await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(o, d, g), await
|
|
25775
|
+
return await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d), await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(o, d, g), await _S(t), await i.clear(), a.purgeNode(e, t, d, !0), e.json({
|
|
25463
25776
|
success: !0,
|
|
25464
25777
|
treeNodeId: d
|
|
25465
25778
|
});
|
|
25466
25779
|
}
|
|
25467
25780
|
if (s === "detach") {
|
|
25468
25781
|
let r = n.contentId || n.id || n.treeNodeId;
|
|
25469
|
-
return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE contentId = ? AND treeId = ?) \n WHERE parentId = ? AND treeId = ?\n ").run(r, o, r, o), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ? AND treeId = ?").run(r, o), await
|
|
25782
|
+
return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE contentId = ? AND treeId = ?) \n WHERE parentId = ? AND treeId = ?\n ").run(r, o, r, o), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ? AND treeId = ?").run(r, o), await _S(t), await i.clear(), a.purgeNode(e, t, r, !0), e.json({ success: !0 })) : e.json({ error: "contentId required for detach" }, 400);
|
|
25470
25783
|
}
|
|
25471
25784
|
return e.json({ error: "Invalid payload or action" }, 400);
|
|
25472
25785
|
} catch (t) {
|
|
@@ -25475,7 +25788,7 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25475
25788
|
details: t.message
|
|
25476
25789
|
}, 500);
|
|
25477
25790
|
}
|
|
25478
|
-
}),
|
|
25791
|
+
}), AS.get("/trees.json", async (e) => {
|
|
25479
25792
|
try {
|
|
25480
25793
|
let t = e.get("db"), n = await t.prepare("SELECT * FROM trees ORDER BY LOWER(label) ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId FROM channel_trees").all(), a = (Array.isArray(i) ? i : i?.results || []).reduce((e, t) => {
|
|
25481
25794
|
let n = Number(t.treeId), r = Number(t.channelId);
|
|
@@ -25505,7 +25818,7 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25505
25818
|
} catch {
|
|
25506
25819
|
return e.json([]);
|
|
25507
25820
|
}
|
|
25508
|
-
}),
|
|
25821
|
+
}), AS.post("/trees.json", async (e) => {
|
|
25509
25822
|
try {
|
|
25510
25823
|
let t = e.get("db"), n = await e.req.json(), r = n.id, i = r != null && r !== "" && !isNaN(Number(r)) ? Number(r) : null, a = `tree-${Date.now().toString(36)}`, o = (n.key || n.slug || a).toLowerCase().replace(/[^a-z0-9_-]/g, "-"), s = n.label?.trim() || o, c = n.treeType !== void 0 && n.treeType !== null ? n.treeType : n.type ?? "site", l = n.channelId !== void 0 && n.channelId !== null && Number(n.channelId) || null, u = +(n.isHidden === !0 || n.isHidden === 1 || n.isHidden === "true"), d = e.get("user")?.id || null, f = { ...n };
|
|
25511
25824
|
if (delete f.id, delete f.key, delete f.label, delete f.treeType, delete f.type, delete f.channelId, delete f.channels, delete f.isHidden, delete f.createdById, delete f.updatedById, delete f.createdAt, delete f.updatedAt, await t.prepare("SELECT id FROM trees WHERE key = ? AND id != ? LIMIT 1").get(o, i ?? -1)) return e.json({
|
|
@@ -25530,7 +25843,7 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25530
25843
|
await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
|
|
25531
25844
|
}
|
|
25532
25845
|
}
|
|
25533
|
-
return await
|
|
25846
|
+
return await _S(t), await tS(e).clear(), new gS(e.env).purgeGlobalCache(e, t), e.json({
|
|
25534
25847
|
success: !0,
|
|
25535
25848
|
id: p,
|
|
25536
25849
|
key: o,
|
|
@@ -25544,12 +25857,12 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25544
25857
|
} catch (t) {
|
|
25545
25858
|
return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
|
|
25546
25859
|
}
|
|
25547
|
-
}),
|
|
25860
|
+
}), AS.delete("/trees.json", async (e) => {
|
|
25548
25861
|
let t = e.get("db"), n = e.req.query("id");
|
|
25549
25862
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
25550
25863
|
let r = Number(n);
|
|
25551
25864
|
try {
|
|
25552
|
-
return await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r), await
|
|
25865
|
+
return await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r), await _S(t), await tS(e).clear(), new gS(e.env).purgeGlobalCache(e, t), e.json({
|
|
25553
25866
|
success: !0,
|
|
25554
25867
|
deletedTreeId: r
|
|
25555
25868
|
});
|
|
@@ -25557,8 +25870,8 @@ Ix.get("/tree.json", async (e) => {
|
|
|
25557
25870
|
return e.json({ error: "Failed to delete tree" }, 500);
|
|
25558
25871
|
}
|
|
25559
25872
|
});
|
|
25560
|
-
var
|
|
25561
|
-
|
|
25873
|
+
var PS = new e();
|
|
25874
|
+
PS.get("/", async (e) => {
|
|
25562
25875
|
try {
|
|
25563
25876
|
let t = e.get("db"), n = await t.prepare("SELECT * FROM channels ORDER BY id ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId, key, metaJson FROM channel_trees").all(), a = ((Array.isArray(i) ? i : i?.results || []) || []).reduce((e, t) => {
|
|
25564
25877
|
e[t.channelId] || (e[t.channelId] = []);
|
|
@@ -25574,7 +25887,7 @@ Bx.get("/", async (e) => {
|
|
|
25574
25887
|
}, {}), o = await Promise.all((r || []).map(async (e) => {
|
|
25575
25888
|
let n = {};
|
|
25576
25889
|
try {
|
|
25577
|
-
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n = await
|
|
25890
|
+
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n = await mS(t, n);
|
|
25578
25891
|
} catch {}
|
|
25579
25892
|
return {
|
|
25580
25893
|
...e,
|
|
@@ -25582,7 +25895,7 @@ Bx.get("/", async (e) => {
|
|
|
25582
25895
|
isHidden: !!e.isHidden,
|
|
25583
25896
|
trees: a[e.id] || []
|
|
25584
25897
|
};
|
|
25585
|
-
})), s = e.env?.BUNDLED_DEFINITIONS, c =
|
|
25898
|
+
})), s = e.env?.BUNDLED_DEFINITIONS, c = hS(s), l = c?.channelTemplate || Object.values(c?.channels || {})[0] || {
|
|
25586
25899
|
label: "Channel Settings",
|
|
25587
25900
|
fields: {
|
|
25588
25901
|
key: {
|
|
@@ -25624,27 +25937,27 @@ Bx.get("/", async (e) => {
|
|
|
25624
25937
|
error: t.message
|
|
25625
25938
|
}, 500);
|
|
25626
25939
|
}
|
|
25627
|
-
}),
|
|
25940
|
+
}), PS.post("/", async (e) => {
|
|
25628
25941
|
try {
|
|
25629
|
-
let t = e.get("db"), n = await e.req.json(), r = n.channel || n.data || n, i = r.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { key: o, label: s, channelType: c = "website", domain: l = "localhost", baseUrl: u = "http://localhost:4321", defaultLanguage: d, default_language: f, language: p, isHidden: m, hidden: h, trees: g = [], createdById: _ = null, updatedById: v = null, id: y, createdAt: b, updatedAt: x, ...S } = r, C = o?.trim() || "main",
|
|
25630
|
-
typeof
|
|
25631
|
-
let
|
|
25942
|
+
let t = e.get("db"), n = await e.req.json(), r = n.channel || n.data || n, i = r.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { key: o, label: s, channelType: c = "website", domain: l = "localhost", baseUrl: u = "http://localhost:4321", defaultLanguage: d, default_language: f, language: p, isHidden: m, hidden: h, trees: g = [], createdById: _ = null, updatedById: v = null, id: y, createdAt: b, updatedAt: x, ...S } = r, C = o?.trim() || "main", ee = s?.trim() || "Untitled Channel", w = d || f || p || "";
|
|
25943
|
+
typeof w == "object" && w && (w = w.value || w.id || ""), w = String(w).trim();
|
|
25944
|
+
let te = m === !0 || m === "true" || m === 1 || h === !0 || h === "true" || h === 1, ne = Array.isArray(g) ? g : [], T = JSON.stringify(S || {}), E = e.get("user")?.id || v || _ || null;
|
|
25632
25945
|
if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(C, a ?? -1)) return e.json({
|
|
25633
25946
|
error: `Channel API key "${C}" is already in use.`,
|
|
25634
25947
|
field: "key"
|
|
25635
25948
|
}, 409);
|
|
25636
|
-
let
|
|
25637
|
-
if (a) await t.prepare("\n UPDATE channels \n SET key = ?, label = ?, channelType = ?, domain = ?, baseUrl = ?, defaultLanguage = ?, \n isHidden = ?, dataJson = ?, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(C,
|
|
25949
|
+
let D = a;
|
|
25950
|
+
if (a) await t.prepare("\n UPDATE channels \n SET key = ?, label = ?, channelType = ?, domain = ?, baseUrl = ?, defaultLanguage = ?, \n isHidden = ?, dataJson = ?, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(C, ee, c, l, u, w, +!!te, T, E, a);
|
|
25638
25951
|
else {
|
|
25639
|
-
let e = await t.prepare("\n INSERT INTO channels (key, label, channelType, domain, baseUrl, defaultLanguage, isHidden, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n RETURNING id\n ").get(C,
|
|
25952
|
+
let e = await t.prepare("\n INSERT INTO channels (key, label, channelType, domain, baseUrl, defaultLanguage, isHidden, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n RETURNING id\n ").get(C, ee, c, l, u, w, +!!te, T, E, E), n = e?.results?.[0] || e;
|
|
25640
25953
|
if (!n || !n.id) throw Error("Failed to retrieve newly created Channel ID from Cloudflare D1.");
|
|
25641
|
-
|
|
25954
|
+
D = Number(n.id);
|
|
25642
25955
|
}
|
|
25643
|
-
await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(
|
|
25644
|
-
let
|
|
25645
|
-
if (
|
|
25646
|
-
let e =
|
|
25647
|
-
|
|
25956
|
+
await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(D);
|
|
25957
|
+
let O = ne.filter((e) => e && e.treeId && e.key);
|
|
25958
|
+
if (O.length > 0) {
|
|
25959
|
+
let e = O.map(() => "(?, ?, ?, ?)").join(", "), n = O.flatMap((e) => [
|
|
25960
|
+
D,
|
|
25648
25961
|
Number(e.treeId) || e.treeId,
|
|
25649
25962
|
String(e.key).trim(),
|
|
25650
25963
|
JSON.stringify(e.meta || {})
|
|
@@ -25654,10 +25967,10 @@ Bx.get("/", async (e) => {
|
|
|
25654
25967
|
VALUES ${e}
|
|
25655
25968
|
`).run(...n);
|
|
25656
25969
|
}
|
|
25657
|
-
let
|
|
25658
|
-
return await
|
|
25970
|
+
let re = tS(e);
|
|
25971
|
+
return await re.delete(`channel:${C}`), await re.delete(`channel:${D}`), await re.clear(), await _S(t), new gS(e.env).purgeGlobalCache(e, t), e.json({
|
|
25659
25972
|
success: !0,
|
|
25660
|
-
id:
|
|
25973
|
+
id: D
|
|
25661
25974
|
});
|
|
25662
25975
|
} catch (t) {
|
|
25663
25976
|
return console.error("[API Channels] Error saving channel:", t), e.json({
|
|
@@ -25665,14 +25978,14 @@ Bx.get("/", async (e) => {
|
|
|
25665
25978
|
details: t.message
|
|
25666
25979
|
}, 500);
|
|
25667
25980
|
}
|
|
25668
|
-
}),
|
|
25981
|
+
}), PS.delete("/", async (e) => {
|
|
25669
25982
|
let t = e.get("db"), n = e.req.query("id");
|
|
25670
25983
|
if (!n) return e.json({ error: "Channel ID required" }, 400);
|
|
25671
25984
|
let r = Number(n);
|
|
25672
25985
|
try {
|
|
25673
25986
|
await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(r), await t.prepare("DELETE FROM node_channels WHERE channelId = ?").run(r), await t.prepare("DELETE FROM channels WHERE id = ?").run(r);
|
|
25674
|
-
let n =
|
|
25675
|
-
return await n.delete(`channel:${r}`), await n.clear(), await
|
|
25987
|
+
let n = tS(e);
|
|
25988
|
+
return await n.delete(`channel:${r}`), await n.clear(), await _S(t), new gS(e.env).purgeGlobalCache(e, t), e.json({
|
|
25676
25989
|
success: !0,
|
|
25677
25990
|
deletedSiteId: r
|
|
25678
25991
|
});
|
|
@@ -25683,15 +25996,15 @@ Bx.get("/", async (e) => {
|
|
|
25683
25996
|
}, 500);
|
|
25684
25997
|
}
|
|
25685
25998
|
});
|
|
25686
|
-
var
|
|
25687
|
-
function
|
|
25999
|
+
var FS = new e();
|
|
26000
|
+
function IS(e) {
|
|
25688
26001
|
return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
25689
26002
|
}
|
|
25690
|
-
function
|
|
25691
|
-
let t = (e || "").trim().toLowerCase(), n =
|
|
26003
|
+
function LS(e) {
|
|
26004
|
+
let t = (e || "").trim().toLowerCase(), n = hS()?.taxonomies || {};
|
|
25692
26005
|
return n[t] ? t : n[`${t}s`] ? `${t}s` : t.endsWith("s") && n[t.slice(0, -1)] ? t.slice(0, -1) : t;
|
|
25693
26006
|
}
|
|
25694
|
-
async function
|
|
26007
|
+
async function RS(e, t, n = []) {
|
|
25695
26008
|
let r = e.prepare(t);
|
|
25696
26009
|
if (typeof r.bind == "function") {
|
|
25697
26010
|
let e = await r.bind(...n).all();
|
|
@@ -25703,10 +26016,10 @@ async function Wx(e, t, n = []) {
|
|
|
25703
26016
|
}
|
|
25704
26017
|
return [];
|
|
25705
26018
|
}
|
|
25706
|
-
|
|
25707
|
-
let t = e.get("db"), n =
|
|
26019
|
+
FS.get("/:taxonomy", async (e) => {
|
|
26020
|
+
let t = e.get("db"), n = LS(e.req.param("taxonomy"));
|
|
25708
26021
|
try {
|
|
25709
|
-
let r = (await
|
|
26022
|
+
let r = (await RS(t, "\n SELECT tt.id, tt.taxonomy, tt.key, tt.label, tt.parentId, tt.sortOrder,\n tt.dataJson, tt.createdAt, tt.updatedAt,\n (SELECT COUNT(DISTINCT nt.nodeId)\n FROM node_terms nt\n WHERE nt.termId = tt.id) +\n (SELECT COUNT(DISTINCT at.assetId)\n FROM asset_terms at\n WHERE at.termId = tt.id) AS connectionCount\n FROM taxonomy_terms tt\n WHERE tt.taxonomy = ?\n ORDER BY tt.sortOrder ASC, tt.label ASC\n ", [n])).map((e) => ({
|
|
25710
26023
|
...e,
|
|
25711
26024
|
data: e.dataJson ? JSON.parse(e.dataJson) : {}
|
|
25712
26025
|
}));
|
|
@@ -25717,12 +26030,12 @@ Vx.get("/:taxonomy", async (e) => {
|
|
|
25717
26030
|
} catch (t) {
|
|
25718
26031
|
return console.error("[Taxonomy API] Error fetching terms:", t), e.json({ error: "Failed to fetch taxonomy terms" }, 500);
|
|
25719
26032
|
}
|
|
25720
|
-
}),
|
|
25721
|
-
let t = e.get("db"), n =
|
|
26033
|
+
}), FS.post("/:taxonomy", async (e) => {
|
|
26034
|
+
let t = e.get("db"), n = LS(e.req.param("taxonomy")), r = await e.req.json(), i = r.label?.trim();
|
|
25722
26035
|
if (!i) return e.json({ error: "Label is required" }, 400);
|
|
25723
|
-
let a = r.key?.trim() ||
|
|
26036
|
+
let a = r.key?.trim() || IS(i), o = r.parentId ? Number(r.parentId) : null, s = r.sortOrder ? Number(r.sortOrder) : 0, c = r.data ? JSON.stringify(r.data) : "{}";
|
|
25724
26037
|
try {
|
|
25725
|
-
if ((await
|
|
26038
|
+
if ((await RS(t, "SELECT id FROM taxonomy_terms WHERE taxonomy = ? AND key = ?", [n, a])).length > 0) return e.json({ error: `A term with the key '${a}' already exists in this taxonomy.` }, 409);
|
|
25726
26039
|
let r = t.prepare("\n INSERT INTO taxonomy_terms (taxonomy, key, label, parentId, sortOrder, dataJson)\n VALUES (?, ?, ?, ?, ?, ?)\n "), l;
|
|
25727
26040
|
return l = typeof r.bind == "function" ? await r.bind(n, a, i, o, s, c).run() : await r.run(n, a, i, o, s, c), e.json({
|
|
25728
26041
|
success: !0,
|
|
@@ -25731,12 +26044,12 @@ Vx.get("/:taxonomy", async (e) => {
|
|
|
25731
26044
|
} catch (t) {
|
|
25732
26045
|
return console.error("[Taxonomy API] Error creating term:", t), e.json({ error: "Failed to create taxonomy term" }, 500);
|
|
25733
26046
|
}
|
|
25734
|
-
}),
|
|
25735
|
-
let t = e.get("db"), n =
|
|
26047
|
+
}), FS.put("/:taxonomy/:id", async (e) => {
|
|
26048
|
+
let t = e.get("db"), n = LS(e.req.param("taxonomy")), r = Number(e.req.param("id"));
|
|
25736
26049
|
if (isNaN(r)) return e.json({ error: "Invalid term ID" }, 400);
|
|
25737
26050
|
let i = await e.req.json();
|
|
25738
26051
|
try {
|
|
25739
|
-
let a = await
|
|
26052
|
+
let a = await RS(t, "SELECT * FROM taxonomy_terms WHERE id = ? AND taxonomy = ?", [r, n]);
|
|
25740
26053
|
if (a.length === 0) return e.json({ error: "Term not found" }, 404);
|
|
25741
26054
|
let o = a[0], s = i.label === void 0 ? o.label : i.label.trim(), c = i.key === void 0 ? o.key : i.key.trim(), l = i.parentId === void 0 ? o.parentId : i.parentId ? Number(i.parentId) : null, u = i.sortOrder === void 0 ? o.sortOrder : Number(i.sortOrder), d = o.dataJson;
|
|
25742
26055
|
if (i.data) {
|
|
@@ -25746,14 +26059,14 @@ Vx.get("/:taxonomy", async (e) => {
|
|
|
25746
26059
|
...i.data
|
|
25747
26060
|
});
|
|
25748
26061
|
}
|
|
25749
|
-
if (c !== o.key && (await
|
|
26062
|
+
if (c !== o.key && (await RS(t, "SELECT id FROM taxonomy_terms WHERE taxonomy = ? AND key = ?", [n, c])).length > 0) return e.json({ error: `A term with the key '${c}' already exists in this taxonomy.` }, 409);
|
|
25750
26063
|
let f = t.prepare("\n UPDATE taxonomy_terms \n SET label = ?, key = ?, parentId = ?, sortOrder = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ");
|
|
25751
26064
|
return typeof f.bind == "function" ? await f.bind(s, c, l, u, d, r).run() : await f.run(s, c, l, u, d, r), e.json({ success: !0 });
|
|
25752
26065
|
} catch (t) {
|
|
25753
26066
|
return console.error("[Taxonomy API] Error updating term:", t), e.json({ error: "Failed to update taxonomy term" }, 500);
|
|
25754
26067
|
}
|
|
25755
|
-
}),
|
|
25756
|
-
let t = e.get("db"), n =
|
|
26068
|
+
}), FS.delete("/:taxonomy/:id", async (e) => {
|
|
26069
|
+
let t = e.get("db"), n = LS(e.req.param("taxonomy")), r = Number(e.req.param("id"));
|
|
25757
26070
|
if (isNaN(r)) return e.json({ error: "Invalid term ID" }, 400);
|
|
25758
26071
|
try {
|
|
25759
26072
|
let i = t.prepare("DELETE FROM taxonomy_terms WHERE id = ? AND taxonomy = ?");
|
|
@@ -25762,20 +26075,20 @@ Vx.get("/:taxonomy", async (e) => {
|
|
|
25762
26075
|
return console.error("[Taxonomy API] Error deleting term:", t), e.json({ error: "Failed to delete taxonomy term" }, 500);
|
|
25763
26076
|
}
|
|
25764
26077
|
});
|
|
25765
|
-
var
|
|
26078
|
+
var zS = null, BS = null;
|
|
25766
26079
|
if (typeof process < "u" && process?.versions?.node) try {
|
|
25767
26080
|
let e = i(import.meta.url);
|
|
25768
|
-
|
|
26081
|
+
zS = e("node:fs"), BS = e("node:path");
|
|
25769
26082
|
} catch {}
|
|
25770
|
-
function
|
|
26083
|
+
function VS(e, t = "") {
|
|
25771
26084
|
let n = e.split(/[\\/]/).pop() || "";
|
|
25772
26085
|
return t && n.endsWith(t) ? n.slice(0, -t.length) : n;
|
|
25773
26086
|
}
|
|
25774
|
-
function
|
|
26087
|
+
function HS(e) {
|
|
25775
26088
|
let t = e.match(/\.[^.\\/]+$/);
|
|
25776
26089
|
return t ? t[0] : "";
|
|
25777
26090
|
}
|
|
25778
|
-
var
|
|
26091
|
+
var US = {
|
|
25779
26092
|
nodes: {},
|
|
25780
26093
|
trees: {},
|
|
25781
26094
|
blocks: {},
|
|
@@ -25785,10 +26098,10 @@ var Yx = {
|
|
|
25785
26098
|
nodeLayouts: {},
|
|
25786
26099
|
blockLayouts: {}
|
|
25787
26100
|
};
|
|
25788
|
-
function
|
|
26101
|
+
function WS(e) {
|
|
25789
26102
|
return e ? typeof e == "string" ? e.trim() : Array.isArray(e) ? e.includes("*") ? "*" : e : "*" : "*";
|
|
25790
26103
|
}
|
|
25791
|
-
function
|
|
26104
|
+
function GS(e = {}, t = {}) {
|
|
25792
26105
|
let n = {
|
|
25793
26106
|
...e,
|
|
25794
26107
|
...t,
|
|
@@ -25800,62 +26113,62 @@ function Zx(e = {}, t = {}) {
|
|
|
25800
26113
|
};
|
|
25801
26114
|
return t.required === !0 || String(t.required).toLowerCase() === "true" || t.rules?.required === !0 || String(t.rules?.required).toLowerCase() === "true" || t.required === void 0 && (e.required === !0 || String(e.required).toLowerCase() === "true" || e.rules?.required === !0 || String(e.rules?.required).toLowerCase() === "true") ? (n.required = !0, n.rules.required = !0) : (t.required === !1 || t.rules?.required === !1) && (n.required = !1, n.rules.required = !1), n;
|
|
25802
26115
|
}
|
|
25803
|
-
function
|
|
26116
|
+
function KS(e) {
|
|
25804
26117
|
if (!e || typeof e != "object") return e;
|
|
25805
|
-
if (Array.isArray(e)) return e.map(
|
|
26118
|
+
if (Array.isArray(e)) return e.map(KS);
|
|
25806
26119
|
let t = {};
|
|
25807
26120
|
for (let [n, r] of Object.entries(e)) if (n === "<<" || n === "<<:") {
|
|
25808
|
-
let e =
|
|
26121
|
+
let e = KS(r);
|
|
25809
26122
|
if (typeof e == "object" && e) {
|
|
25810
26123
|
if (Array.isArray(e)) for (let n of e) Object.assign(t, n);
|
|
25811
26124
|
else Object.assign(t, e);
|
|
25812
26125
|
}
|
|
25813
|
-
} else t[n] =
|
|
26126
|
+
} else t[n] = KS(r);
|
|
25814
26127
|
return t;
|
|
25815
26128
|
}
|
|
25816
|
-
function
|
|
25817
|
-
return e ?
|
|
26129
|
+
function qS(e, t) {
|
|
26130
|
+
return e ? KS(n.parseDocument(e, { customTags: [{
|
|
25818
26131
|
tag: "!include",
|
|
25819
26132
|
resolve(e) {
|
|
25820
|
-
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim(), r =
|
|
26133
|
+
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim(), r = VS(n);
|
|
25821
26134
|
if (!r) return n;
|
|
25822
26135
|
if (t && t.fieldSets) {
|
|
25823
26136
|
let e = Object.keys(t.fieldSets).find((e) => e.endsWith("/" + r) || e === r);
|
|
25824
|
-
if (e) return
|
|
26137
|
+
if (e) return qS(t.fieldSets[e], t);
|
|
25825
26138
|
}
|
|
25826
26139
|
return n;
|
|
25827
26140
|
}
|
|
25828
26141
|
}] }).toJS() || {}) : {};
|
|
25829
26142
|
}
|
|
25830
|
-
function
|
|
25831
|
-
if (!
|
|
25832
|
-
let r =
|
|
25833
|
-
if (t.has(r) || (t.add(r), !
|
|
25834
|
-
let i =
|
|
25835
|
-
return
|
|
26143
|
+
function JS(e, t = /* @__PURE__ */ new Set()) {
|
|
26144
|
+
if (!zS || !BS) return {};
|
|
26145
|
+
let r = BS.resolve(e);
|
|
26146
|
+
if (t.has(r) || (t.add(r), !zS.existsSync(r))) return {};
|
|
26147
|
+
let i = zS.readFileSync(r, "utf-8");
|
|
26148
|
+
return KS(n.parseDocument(i, { customTags: [{
|
|
25836
26149
|
tag: "!include",
|
|
25837
26150
|
resolve(e) {
|
|
25838
26151
|
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim();
|
|
25839
|
-
return n ?
|
|
26152
|
+
return n ? JS(BS.resolve(BS.dirname(r), n), new Set(t)) : {};
|
|
25840
26153
|
}
|
|
25841
26154
|
}] }).toJS() || {});
|
|
25842
26155
|
}
|
|
25843
|
-
function
|
|
25844
|
-
if (!
|
|
26156
|
+
function YS() {
|
|
26157
|
+
if (!zS || !BS || typeof process > "u" || !process?.versions?.node) return null;
|
|
25845
26158
|
try {
|
|
25846
26159
|
let e = process.cwd(), t = "", n = [
|
|
25847
|
-
|
|
25848
|
-
|
|
25849
|
-
|
|
25850
|
-
|
|
26160
|
+
BS.resolve(e, "content/definitions"),
|
|
26161
|
+
BS.resolve(e, "content"),
|
|
26162
|
+
BS.resolve(e, "definitions"),
|
|
26163
|
+
BS.resolve(e, "kama-worker/content/definitions")
|
|
25851
26164
|
];
|
|
25852
26165
|
try {
|
|
25853
26166
|
if (import.meta.url) {
|
|
25854
|
-
let e =
|
|
25855
|
-
n.push(
|
|
26167
|
+
let e = BS.dirname(r(import.meta.url));
|
|
26168
|
+
n.push(BS.resolve(e, "../../content/definitions")), n.push(BS.resolve(e, "../content/definitions"));
|
|
25856
26169
|
}
|
|
25857
26170
|
} catch {}
|
|
25858
|
-
for (let e of n) if (
|
|
26171
|
+
for (let e of n) if (zS.existsSync(e)) {
|
|
25859
26172
|
t = e;
|
|
25860
26173
|
break;
|
|
25861
26174
|
}
|
|
@@ -25864,19 +26177,19 @@ function tS() {
|
|
|
25864
26177
|
if (!e) return {};
|
|
25865
26178
|
let n = "";
|
|
25866
26179
|
for (let r of t) {
|
|
25867
|
-
let t =
|
|
25868
|
-
if (
|
|
26180
|
+
let t = BS.join(e, r);
|
|
26181
|
+
if (zS.existsSync(t)) {
|
|
25869
26182
|
n = t;
|
|
25870
26183
|
break;
|
|
25871
26184
|
}
|
|
25872
26185
|
}
|
|
25873
26186
|
if (!n) return {};
|
|
25874
|
-
let r = {}, i =
|
|
26187
|
+
let r = {}, i = zS.readdirSync(n);
|
|
25875
26188
|
for (let e of i) {
|
|
25876
26189
|
if (!e.endsWith(".yaml") && !e.endsWith(".yml")) continue;
|
|
25877
|
-
let t =
|
|
26190
|
+
let t = BS.join(n, e), i = VS(e, HS(e));
|
|
25878
26191
|
try {
|
|
25879
|
-
r[i] =
|
|
26192
|
+
r[i] = JS(t);
|
|
25880
26193
|
} catch (t) {
|
|
25881
26194
|
console.error(`❌ Error parsing ${e}:`, t.message);
|
|
25882
26195
|
}
|
|
@@ -25906,47 +26219,47 @@ function tS() {
|
|
|
25906
26219
|
return console.error("❌ Exception inside readLocalFsBundle:", e), null;
|
|
25907
26220
|
}
|
|
25908
26221
|
}
|
|
25909
|
-
var
|
|
25910
|
-
function
|
|
25911
|
-
if (!e)
|
|
25912
|
-
else if (
|
|
25913
|
-
let t =
|
|
25914
|
-
return
|
|
26222
|
+
var XS = null, ZS = null;
|
|
26223
|
+
function QS(e) {
|
|
26224
|
+
if (!e) XS = null, ZS = null;
|
|
26225
|
+
else if (XS && ZS === e) return XS;
|
|
26226
|
+
let t = $S(e);
|
|
26227
|
+
return XS = t, ZS = e, t;
|
|
25915
26228
|
}
|
|
25916
|
-
function
|
|
26229
|
+
function $S(e) {
|
|
25917
26230
|
if (e) {
|
|
25918
26231
|
let t = {
|
|
25919
26232
|
nodes: {
|
|
25920
26233
|
...e.nodes || e.rawNodes || {},
|
|
25921
|
-
...
|
|
26234
|
+
...US.nodes
|
|
25922
26235
|
},
|
|
25923
26236
|
trees: {
|
|
25924
26237
|
...e.trees || e.rawTrees || {},
|
|
25925
|
-
...
|
|
26238
|
+
...US.trees
|
|
25926
26239
|
},
|
|
25927
26240
|
channels: {
|
|
25928
26241
|
...e.channels || e.rawChannels || {},
|
|
25929
|
-
...
|
|
26242
|
+
...US.channels
|
|
25930
26243
|
},
|
|
25931
26244
|
taxonomies: {
|
|
25932
26245
|
...e.taxonomies || e.rawTaxonomies || {},
|
|
25933
|
-
...
|
|
26246
|
+
...US.taxonomies
|
|
25934
26247
|
},
|
|
25935
26248
|
blocks: {
|
|
25936
26249
|
...e.blocks || e.rawBlocks || {},
|
|
25937
|
-
...
|
|
26250
|
+
...US.blocks
|
|
25938
26251
|
},
|
|
25939
26252
|
nodeLayouts: {
|
|
25940
26253
|
...e.nodeLayouts || e.rawNodeLayouts || {},
|
|
25941
|
-
...
|
|
26254
|
+
...US.nodeLayouts
|
|
25942
26255
|
},
|
|
25943
26256
|
blockLayouts: {
|
|
25944
26257
|
...e.blockLayouts || e.rawBlockLayouts || {},
|
|
25945
|
-
...
|
|
26258
|
+
...US.blockLayouts
|
|
25946
26259
|
},
|
|
25947
26260
|
fieldSets: {
|
|
25948
26261
|
...e.fieldSets || e.rawFieldSets || {},
|
|
25949
|
-
...
|
|
26262
|
+
...US.fieldSets
|
|
25950
26263
|
},
|
|
25951
26264
|
forms: { ...e.forms || e.rawForms || {} }
|
|
25952
26265
|
};
|
|
@@ -25954,12 +26267,12 @@ function aS(e) {
|
|
|
25954
26267
|
let e = (e) => {
|
|
25955
26268
|
let n = {};
|
|
25956
26269
|
for (let [r, i] of Object.entries(e || {})) {
|
|
25957
|
-
let e =
|
|
25958
|
-
n[e] =
|
|
26270
|
+
let e = VS(r, HS(r));
|
|
26271
|
+
n[e] = qS(i, t);
|
|
25959
26272
|
}
|
|
25960
26273
|
return n;
|
|
25961
26274
|
};
|
|
25962
|
-
return
|
|
26275
|
+
return eC({
|
|
25963
26276
|
rawNodes: e(t.nodes),
|
|
25964
26277
|
rawTrees: e(t.trees),
|
|
25965
26278
|
rawChannels: e(t.channels),
|
|
@@ -25971,12 +26284,12 @@ function aS(e) {
|
|
|
25971
26284
|
rawForms: e(t.forms)
|
|
25972
26285
|
});
|
|
25973
26286
|
}
|
|
25974
|
-
return
|
|
26287
|
+
return eC(t);
|
|
25975
26288
|
}
|
|
25976
|
-
let t =
|
|
25977
|
-
return t && (Object.keys(t.rawNodes || {}).length > 0 || Object.keys(t.rawBlocks || {}).length > 0 || Object.keys(t.rawForms || {}).length > 0) ?
|
|
26289
|
+
let t = YS();
|
|
26290
|
+
return t && (Object.keys(t.rawNodes || {}).length > 0 || Object.keys(t.rawBlocks || {}).length > 0 || Object.keys(t.rawForms || {}).length > 0) ? eC(t) : eC(null);
|
|
25978
26291
|
}
|
|
25979
|
-
function
|
|
26292
|
+
function eC(e) {
|
|
25980
26293
|
if (!e) return {
|
|
25981
26294
|
nodes: {},
|
|
25982
26295
|
trees: {},
|
|
@@ -25993,14 +26306,14 @@ function oS(e) {
|
|
|
25993
26306
|
userTemplate: null,
|
|
25994
26307
|
treeExposedFields: ["summary"]
|
|
25995
26308
|
};
|
|
25996
|
-
let { rawNodes: t = {}, rawTrees: n = {}, rawChannels: r = {}, channels: i = {}, rawTaxonomies: a = {}, taxonomies: o = {}, rawBlocks: s = {}, rawElements: c = {}, rawNodeLayouts: l = {}, rawBlockLayouts: u = {}, rawLayouts: d = {}, rawFieldSets: f = {}, rawForms: p = {}, forms: m = {}, rawTemplates: h = {}, nodeTemplate: g = null, treeTemplate: _ = null, channelTemplate: v = null, userTemplate: y = null, nodes: b = {}, trees: x = {}, blocks: S = {}, nodeLayouts: C = {}, blockLayouts:
|
|
26309
|
+
let { rawNodes: t = {}, rawTrees: n = {}, rawChannels: r = {}, channels: i = {}, rawTaxonomies: a = {}, taxonomies: o = {}, rawBlocks: s = {}, rawElements: c = {}, rawNodeLayouts: l = {}, rawBlockLayouts: u = {}, rawLayouts: d = {}, rawFieldSets: f = {}, rawForms: p = {}, forms: m = {}, rawTemplates: h = {}, nodeTemplate: g = null, treeTemplate: _ = null, channelTemplate: v = null, userTemplate: y = null, nodes: b = {}, trees: x = {}, blocks: S = {}, nodeLayouts: C = {}, blockLayouts: ee = {} } = e, w = Object.keys(t).length > 0 ? t : b, te = Object.keys(n).length > 0 ? n : x, ne = Object.keys(r).length > 0 ? r : i, T = Object.keys(a).length > 0 ? a : o, E = Object.keys(s).length > 0 ? s : Object.keys(c).length > 0 ? c : S, D = Object.keys(l).length > 0 ? l : Object.keys(d).length > 0 ? d : C, O = Object.keys(u).length > 0 ? u : ee, re = g?.fields || {}, k = {
|
|
25997
26310
|
...h,
|
|
25998
26311
|
...f
|
|
25999
26312
|
}, A = (e, t = "settings", n, r) => {
|
|
26000
26313
|
let i = {};
|
|
26001
26314
|
if (!e) return i;
|
|
26002
26315
|
let a = (e) => {
|
|
26003
|
-
let a =
|
|
26316
|
+
let a = k[e] || k[`${e}-base`] || {};
|
|
26004
26317
|
r && typeof a == "object" && a && (r.inTree === void 0 && a.inTree !== void 0 && (r.inTree = a.inTree), r.inVault === void 0 && a.inVault !== void 0 && (r.inVault = a.inVault), r.hasCanvas === void 0 && a.hasCanvas !== void 0 && (r.hasCanvas = a.hasCanvas));
|
|
26005
26318
|
let o = a.fields || a, s = A(o, t, n, r);
|
|
26006
26319
|
if (a.tab && n) {
|
|
@@ -26010,11 +26323,11 @@ function oS(e) {
|
|
|
26010
26323
|
fields: {}
|
|
26011
26324
|
}), Object.entries(s).forEach(([e, r]) => {
|
|
26012
26325
|
let i = n[t].fields[e] || {};
|
|
26013
|
-
n[t].fields[e] =
|
|
26326
|
+
n[t].fields[e] = GS(i, r);
|
|
26014
26327
|
});
|
|
26015
26328
|
} else Object.entries(s).forEach(([e, t]) => {
|
|
26016
26329
|
let n = i[e] || {};
|
|
26017
|
-
i[e] =
|
|
26330
|
+
i[e] = GS(n, t);
|
|
26018
26331
|
});
|
|
26019
26332
|
};
|
|
26020
26333
|
return !Array.isArray(e) && typeof e == "object" && e ? (Object.entries(e).forEach(([e, t]) => {
|
|
@@ -26023,15 +26336,15 @@ function oS(e) {
|
|
|
26023
26336
|
a(String(t));
|
|
26024
26337
|
return;
|
|
26025
26338
|
}
|
|
26026
|
-
let n = i[e] ||
|
|
26027
|
-
i[e] =
|
|
26339
|
+
let n = i[e] || re[e] || {};
|
|
26340
|
+
i[e] = GS(n, typeof t == "object" && t ? t : { label: String(t) });
|
|
26028
26341
|
}), i) : (Array.isArray(e) && e.forEach((e) => {
|
|
26029
26342
|
if (typeof e == "string") {
|
|
26030
26343
|
if (e.includes("/") || e.endsWith(".yaml") || e.endsWith(".yml")) return;
|
|
26031
26344
|
if (e.startsWith("fieldSet:")) a(e.replace("fieldSet:", "").trim());
|
|
26032
26345
|
else {
|
|
26033
|
-
let t = i[e] ||
|
|
26034
|
-
i[e] =
|
|
26346
|
+
let t = i[e] || re[e] || {};
|
|
26347
|
+
i[e] = GS(t, {
|
|
26035
26348
|
type: "text",
|
|
26036
26349
|
label: e
|
|
26037
26350
|
});
|
|
@@ -26039,8 +26352,8 @@ function oS(e) {
|
|
|
26039
26352
|
} else typeof e == "object" && e && Object.entries(e).forEach(([e, t]) => {
|
|
26040
26353
|
if (e === "fieldSet") a(String(t));
|
|
26041
26354
|
else if (e !== "<<" && e !== "<<:") {
|
|
26042
|
-
let n = i[e] ||
|
|
26043
|
-
i[e] =
|
|
26355
|
+
let n = i[e] || re[e] || {};
|
|
26356
|
+
i[e] = GS(n, typeof t == "object" && t ? t : {});
|
|
26044
26357
|
}
|
|
26045
26358
|
});
|
|
26046
26359
|
}), i);
|
|
@@ -26048,7 +26361,7 @@ function oS(e) {
|
|
|
26048
26361
|
let n = {};
|
|
26049
26362
|
return !e || typeof e != "object" ? n : Array.isArray(e) ? (e.forEach((e) => {
|
|
26050
26363
|
if (typeof e == "object" && e.fieldSet) {
|
|
26051
|
-
let r = String(e.fieldSet), i =
|
|
26364
|
+
let r = String(e.fieldSet), i = k[r] || k[`${r}-base`] || {};
|
|
26052
26365
|
t && (t.inTree === void 0 && i.inTree !== void 0 && (t.inTree = i.inTree), t.inVault === void 0 && i.inVault !== void 0 && (t.inVault = i.inVault), t.hasCanvas === void 0 && i.hasCanvas !== void 0 && (t.hasCanvas = i.hasCanvas));
|
|
26053
26366
|
let a = i.tab?.id || r, o = i.tab?.label || i.label || a;
|
|
26054
26367
|
n[a] || (n[a] = {
|
|
@@ -26058,7 +26371,7 @@ function oS(e) {
|
|
|
26058
26371
|
let s = A(i.fields || i, a, n, t);
|
|
26059
26372
|
Object.entries(s).forEach(([e, t]) => {
|
|
26060
26373
|
let r = n[a].fields[e] || {};
|
|
26061
|
-
n[a].fields[e] =
|
|
26374
|
+
n[a].fields[e] = GS(r, t);
|
|
26062
26375
|
});
|
|
26063
26376
|
}
|
|
26064
26377
|
}), n) : (Object.entries(e).forEach(([e, r]) => {
|
|
@@ -26074,15 +26387,15 @@ function oS(e) {
|
|
|
26074
26387
|
Object.entries(s).forEach(([t, r]) => {
|
|
26075
26388
|
if (t === "<<" || t === "<<:" || t === "label") return;
|
|
26076
26389
|
let i = n[e].fields[t] || {};
|
|
26077
|
-
n[e].fields[t] =
|
|
26390
|
+
n[e].fields[t] = GS(i, r);
|
|
26078
26391
|
});
|
|
26079
26392
|
}), n);
|
|
26080
26393
|
}, ie = {};
|
|
26081
|
-
Object.entries(
|
|
26394
|
+
Object.entries(w).forEach(([e, t]) => {
|
|
26082
26395
|
g && (t.inTree === void 0 && g.inTree !== void 0 && (t.inTree = g.inTree), t.inVault === void 0 && g.inVault !== void 0 && (t.inVault = g.inVault), t.hasCanvas === void 0 && g.hasCanvas !== void 0 && (t.hasCanvas = g.hasCanvas));
|
|
26083
26396
|
let n = j(t.tabs, t), r = A(t.fields || [], "settings", n, t);
|
|
26084
26397
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
26085
|
-
let i =
|
|
26398
|
+
let i = k[e] || k[`${e}-base`] || {};
|
|
26086
26399
|
t.inTree === void 0 && i.inTree !== void 0 && (t.inTree = i.inTree), t.inVault === void 0 && i.inVault !== void 0 && (t.inVault = i.inVault), t.hasCanvas === void 0 && i.hasCanvas !== void 0 && (t.hasCanvas = i.hasCanvas);
|
|
26087
26400
|
let a = i.fields || i, o = A(a, "settings", n, t);
|
|
26088
26401
|
if (i.tab) {
|
|
@@ -26092,16 +26405,16 @@ function oS(e) {
|
|
|
26092
26405
|
fields: {}
|
|
26093
26406
|
}), Object.entries(o).forEach(([e, r]) => {
|
|
26094
26407
|
let i = n[t].fields[e] || {};
|
|
26095
|
-
n[t].fields[e] =
|
|
26408
|
+
n[t].fields[e] = GS(i, r);
|
|
26096
26409
|
});
|
|
26097
26410
|
} else Object.entries(o).forEach(([e, t]) => {
|
|
26098
|
-
let n = r[e] ||
|
|
26099
|
-
r[e] =
|
|
26411
|
+
let n = r[e] || re[e] || {};
|
|
26412
|
+
r[e] = GS(n, t);
|
|
26100
26413
|
});
|
|
26101
26414
|
}), Object.values(n).forEach((e) => {
|
|
26102
26415
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
26103
26416
|
let n = r[e] || {};
|
|
26104
|
-
r[e] =
|
|
26417
|
+
r[e] = GS(n, t);
|
|
26105
26418
|
});
|
|
26106
26419
|
}), Object.keys(n).length === 0 && Object.keys(r).length > 0 && (n.settings = {
|
|
26107
26420
|
label: t.label || "Settings",
|
|
@@ -26114,23 +26427,23 @@ function oS(e) {
|
|
|
26114
26427
|
inVault: t.inVault !== !1,
|
|
26115
26428
|
hasCanvas: t.hasCanvas === !0,
|
|
26116
26429
|
defaultLayout: t.defaultLayout,
|
|
26117
|
-
allowedBlocks:
|
|
26118
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
26430
|
+
allowedBlocks: WS(t.allowedBlocks),
|
|
26431
|
+
disallowedBlocks: t.disallowedBlocks ? WS(t.disallowedBlocks) : void 0,
|
|
26119
26432
|
tabs: n,
|
|
26120
26433
|
fields: r
|
|
26121
26434
|
};
|
|
26122
26435
|
});
|
|
26123
26436
|
let ae = {};
|
|
26124
|
-
Object.entries(
|
|
26437
|
+
Object.entries(te).forEach(([e, t]) => {
|
|
26125
26438
|
let n = j(t.tabs), r = A(t.fields || [], "settings", n);
|
|
26126
26439
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
26127
|
-
let t =
|
|
26440
|
+
let t = k[e] || {}, i = t.fields || t, a = A(i, "settings", n);
|
|
26128
26441
|
Object.entries(a).forEach(([e, t]) => {
|
|
26129
|
-
r[e] =
|
|
26442
|
+
r[e] = GS(r[e] || {}, t);
|
|
26130
26443
|
});
|
|
26131
26444
|
}), Object.values(n).forEach((e) => {
|
|
26132
26445
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
26133
|
-
r[e] =
|
|
26446
|
+
r[e] = GS(r[e] || {}, t);
|
|
26134
26447
|
});
|
|
26135
26448
|
}), ae[e] = {
|
|
26136
26449
|
...t,
|
|
@@ -26141,16 +26454,16 @@ function oS(e) {
|
|
|
26141
26454
|
};
|
|
26142
26455
|
});
|
|
26143
26456
|
let oe = {};
|
|
26144
|
-
Object.entries(
|
|
26457
|
+
Object.entries(ne).forEach(([e, t]) => {
|
|
26145
26458
|
let n = j(t.tabs), r = A(t.fields || [], "settings", n);
|
|
26146
26459
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
26147
|
-
let t =
|
|
26460
|
+
let t = k[e] || {}, n = t.fields || t, i = A(n);
|
|
26148
26461
|
Object.entries(i).forEach(([e, t]) => {
|
|
26149
|
-
r[e] =
|
|
26462
|
+
r[e] = GS(r[e] || {}, t);
|
|
26150
26463
|
});
|
|
26151
26464
|
}), Object.values(n).forEach((e) => {
|
|
26152
26465
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
26153
|
-
r[e] =
|
|
26466
|
+
r[e] = GS(r[e] || {}, t);
|
|
26154
26467
|
});
|
|
26155
26468
|
}), oe[e] = {
|
|
26156
26469
|
...t,
|
|
@@ -26162,16 +26475,16 @@ function oS(e) {
|
|
|
26162
26475
|
};
|
|
26163
26476
|
});
|
|
26164
26477
|
let se = {};
|
|
26165
|
-
Object.entries(
|
|
26478
|
+
Object.entries(T).forEach(([e, t]) => {
|
|
26166
26479
|
let n = j(t.tabs), r = A(t.fields || [], "settings", n);
|
|
26167
26480
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
26168
|
-
let t =
|
|
26481
|
+
let t = k[e] || {}, i = t.fields || t, a = A(i, "settings", n);
|
|
26169
26482
|
Object.entries(a).forEach(([e, t]) => {
|
|
26170
|
-
r[e] =
|
|
26483
|
+
r[e] = GS(r[e] || {}, t);
|
|
26171
26484
|
});
|
|
26172
26485
|
}), Object.values(n).forEach((e) => {
|
|
26173
26486
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
26174
|
-
r[e] =
|
|
26487
|
+
r[e] = GS(r[e] || {}, t);
|
|
26175
26488
|
});
|
|
26176
26489
|
}), se[e] = {
|
|
26177
26490
|
...t,
|
|
@@ -26183,12 +26496,12 @@ function oS(e) {
|
|
|
26183
26496
|
};
|
|
26184
26497
|
});
|
|
26185
26498
|
let ce = {};
|
|
26186
|
-
Object.entries(
|
|
26499
|
+
Object.entries(E).forEach(([e, t]) => {
|
|
26187
26500
|
let n = A(t.fields || []);
|
|
26188
26501
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
26189
|
-
let t =
|
|
26502
|
+
let t = k[e] || {}, r = t.fields || t, i = A(r);
|
|
26190
26503
|
Object.entries(i).forEach(([e, t]) => {
|
|
26191
|
-
n[e] =
|
|
26504
|
+
n[e] = GS(n[e] || {}, t);
|
|
26192
26505
|
});
|
|
26193
26506
|
}), ce[e] = {
|
|
26194
26507
|
...t,
|
|
@@ -26199,14 +26512,14 @@ function oS(e) {
|
|
|
26199
26512
|
};
|
|
26200
26513
|
});
|
|
26201
26514
|
let le = {};
|
|
26202
|
-
Object.entries(
|
|
26515
|
+
Object.entries(D).forEach(([e, t]) => {
|
|
26203
26516
|
let n = j(t.tabs), r = A(t.fields || [], "settings", n), i = {}, a = t.regions || { content: { label: "Content" } };
|
|
26204
26517
|
Object.entries(a).forEach(([e, t]) => {
|
|
26205
26518
|
i[e] = {
|
|
26206
26519
|
...t,
|
|
26207
26520
|
label: t.label || e,
|
|
26208
|
-
allowedBlocks:
|
|
26209
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
26521
|
+
allowedBlocks: WS(t.allowedBlocks),
|
|
26522
|
+
disallowedBlocks: t.disallowedBlocks ? WS(t.disallowedBlocks) : void 0
|
|
26210
26523
|
};
|
|
26211
26524
|
}), le[e] = {
|
|
26212
26525
|
...t,
|
|
@@ -26222,14 +26535,14 @@ function oS(e) {
|
|
|
26222
26535
|
};
|
|
26223
26536
|
});
|
|
26224
26537
|
let ue = {};
|
|
26225
|
-
Object.entries(
|
|
26538
|
+
Object.entries(O).forEach(([e, t]) => {
|
|
26226
26539
|
let n = j(t.tabs), r = A(t.fields || [], "settings", n), i = {}, a = t.regions || { main: { label: "Main Content" } };
|
|
26227
26540
|
Object.entries(a).forEach(([e, t]) => {
|
|
26228
26541
|
i[e] = {
|
|
26229
26542
|
...t,
|
|
26230
26543
|
label: t.label || e,
|
|
26231
|
-
allowedBlocks:
|
|
26232
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
26544
|
+
allowedBlocks: WS(t.allowedBlocks),
|
|
26545
|
+
disallowedBlocks: t.disallowedBlocks ? WS(t.disallowedBlocks) : void 0
|
|
26233
26546
|
};
|
|
26234
26547
|
}), ue[e] = {
|
|
26235
26548
|
...t,
|
|
@@ -26246,9 +26559,9 @@ function oS(e) {
|
|
|
26246
26559
|
});
|
|
26247
26560
|
let de = v?.fields || {};
|
|
26248
26561
|
Array.isArray(v?.fieldSets) && v?.fieldSets.forEach((e) => {
|
|
26249
|
-
let t =
|
|
26562
|
+
let t = k[e] || {}, n = t.fields || t, r = A(n);
|
|
26250
26563
|
Object.entries(r).forEach(([e, t]) => {
|
|
26251
|
-
de[e] =
|
|
26564
|
+
de[e] = GS(de[e] || {}, t);
|
|
26252
26565
|
});
|
|
26253
26566
|
});
|
|
26254
26567
|
let fe = v ? {
|
|
@@ -26256,16 +26569,16 @@ function oS(e) {
|
|
|
26256
26569
|
fields: de
|
|
26257
26570
|
} : null, pe = y?.fields || {};
|
|
26258
26571
|
Array.isArray(y?.fieldSets) && y?.fieldSets.forEach((e) => {
|
|
26259
|
-
let t =
|
|
26572
|
+
let t = k[e] || {}, n = t.fields || t, r = A(n);
|
|
26260
26573
|
Object.entries(r).forEach(([e, t]) => {
|
|
26261
|
-
pe[e] =
|
|
26574
|
+
pe[e] = GS(pe[e] || {}, t);
|
|
26262
26575
|
});
|
|
26263
26576
|
});
|
|
26264
26577
|
let me = y ? {
|
|
26265
26578
|
...y,
|
|
26266
26579
|
fields: pe
|
|
26267
26580
|
} : null, he = /* @__PURE__ */ new Set(["summary"]);
|
|
26268
|
-
for (let e of Object.values(
|
|
26581
|
+
for (let e of Object.values(k)) {
|
|
26269
26582
|
let t = e.fields || e;
|
|
26270
26583
|
for (let [e, n] of Object.entries(t || {})) n && typeof n == "object" && n.inTree && he.add(e);
|
|
26271
26584
|
}
|
|
@@ -26281,7 +26594,7 @@ function oS(e) {
|
|
|
26281
26594
|
blocks: ce,
|
|
26282
26595
|
nodeLayouts: le,
|
|
26283
26596
|
blockLayouts: ue,
|
|
26284
|
-
fieldSets:
|
|
26597
|
+
fieldSets: k,
|
|
26285
26598
|
forms: Object.keys(p).length > 0 ? p : m,
|
|
26286
26599
|
nodeTemplate: g || null,
|
|
26287
26600
|
treeTemplate: _ || null,
|
|
@@ -26290,11 +26603,11 @@ function oS(e) {
|
|
|
26290
26603
|
treeExposedFields: Array.from(he)
|
|
26291
26604
|
};
|
|
26292
26605
|
}
|
|
26293
|
-
var
|
|
26606
|
+
var tC = new e(), nC = (e) => {
|
|
26294
26607
|
try {
|
|
26295
26608
|
let t = e.env?.BUNDLED_DEFINITIONS;
|
|
26296
26609
|
(!t || Object.keys(t).length === 0) && (t = Fb || Pb || Nb);
|
|
26297
|
-
let n =
|
|
26610
|
+
let n = QS(t);
|
|
26298
26611
|
return e.json(n, 200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
26299
26612
|
} catch (t) {
|
|
26300
26613
|
return console.error("[CMS API] Error loading schemas:", t), e.json({
|
|
@@ -26303,8 +26616,8 @@ var sS = new e(), cS = (e) => {
|
|
|
26303
26616
|
}, 500);
|
|
26304
26617
|
}
|
|
26305
26618
|
};
|
|
26306
|
-
|
|
26307
|
-
var
|
|
26619
|
+
tC.get("/", nC), tC.get("/schemas.json", nC);
|
|
26620
|
+
var rC = new e(), iC = {
|
|
26308
26621
|
node: "content_nodes",
|
|
26309
26622
|
nodes: "content_nodes",
|
|
26310
26623
|
content_node: "content_nodes",
|
|
@@ -26316,7 +26629,7 @@ var lS = new e(), uS = {
|
|
|
26316
26629
|
user: "users",
|
|
26317
26630
|
users: "users",
|
|
26318
26631
|
user_account: "user_accounts"
|
|
26319
|
-
},
|
|
26632
|
+
}, aC = {
|
|
26320
26633
|
content_nodes: [
|
|
26321
26634
|
"id",
|
|
26322
26635
|
"title",
|
|
@@ -26373,11 +26686,11 @@ var lS = new e(), uS = {
|
|
|
26373
26686
|
"createdAt"
|
|
26374
26687
|
]
|
|
26375
26688
|
};
|
|
26376
|
-
|
|
26689
|
+
rC.post("/validate-unique", async (e) => {
|
|
26377
26690
|
try {
|
|
26378
26691
|
let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
|
|
26379
26692
|
if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
|
|
26380
|
-
let o =
|
|
26693
|
+
let o = iC[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (aC[o] || aC.content_nodes).includes(s), l = -1;
|
|
26381
26694
|
if (a != null && String(a).trim() !== "") {
|
|
26382
26695
|
let e = Number(a);
|
|
26383
26696
|
l = isNaN(e) ? String(a) : e;
|
|
@@ -26389,14 +26702,14 @@ lS.post("/validate-unique", async (e) => {
|
|
|
26389
26702
|
} catch (t) {
|
|
26390
26703
|
return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
|
|
26391
26704
|
}
|
|
26392
|
-
}),
|
|
26393
|
-
var
|
|
26394
|
-
|
|
26705
|
+
}), rC.post("/validate-unique-sibling", async (e) => e.json({ isUnique: !0 }));
|
|
26706
|
+
var oC = new e();
|
|
26707
|
+
oC.get("/", async (e) => {
|
|
26395
26708
|
try {
|
|
26396
|
-
let t = e.get("db"), n = await t.prepare("\n SELECT \n COUNT(*) as total,\n SUM(CASE WHEN isHidden = 0 THEN 1 ELSE 0 END) as published,\n SUM(CASE WHEN isHidden = 1 THEN 1 ELSE 0 END) as hidden\n FROM content_nodes\n WHERE deletedAt IS NULL\n ").get(), r = Number(n?.total) || 0, i = Number(n?.published) || 0, a = Number(n?.hidden) || 0, o = await t.prepare("\n SELECT \n (SELECT COUNT(*) FROM channels) as totalChannels,\n (SELECT COUNT(*) FROM trees) as totalTrees,\n (SELECT COUNT(*) FROM users) as totalUsers\n ").get(),
|
|
26709
|
+
let t = e.get("db"), n = await t.prepare("\n SELECT \n COUNT(*) as total,\n SUM(CASE WHEN isHidden = 0 THEN 1 ELSE 0 END) as published,\n SUM(CASE WHEN isHidden = 1 THEN 1 ELSE 0 END) as hidden\n FROM content_nodes\n WHERE deletedAt IS NULL\n ").get(), r = Number(n?.total) || 0, i = Number(n?.published) || 0, a = Number(n?.hidden) || 0, o = await t.prepare("\n SELECT COUNT(*) as pendingCount\n FROM content_nodes\n WHERE deletedAt IS NULL\n AND (status = 'draft' OR hasUnpublishedChanges = 1)\n ").get(), s = Number(o?.pendingCount) || 0, c = await t.prepare("\n SELECT \n (SELECT COUNT(*) FROM channels) as totalChannels,\n (SELECT COUNT(*) FROM trees) as totalTrees,\n (SELECT COUNT(*) FROM users) as totalUsers\n ").get(), l = await t.prepare("\n SELECT contentType as type, COUNT(*) as count \n FROM content_nodes \n WHERE deletedAt IS NULL\n GROUP BY contentType \n ORDER BY count DESC\n ").all(), u = Array.isArray(l) ? l : l?.results || [], d = await t.prepare("\n SELECT id, title, slug, contentType, isHidden, status, updatedAt \n FROM content_nodes \n WHERE deletedAt IS NULL\n ORDER BY updatedAt DESC \n LIMIT 5\n ").all(), f = (Array.isArray(d) ? d : d?.results || []).map((e) => ({
|
|
26397
26710
|
...e,
|
|
26398
26711
|
isHidden: !!e.isHidden
|
|
26399
|
-
})),
|
|
26712
|
+
})), p = await t.prepare("\n WITH pending_drafts AS (\n SELECT id, title, slug, contentType, isHidden, status, publishedAt, hasUnpublishedChanges, updatedAt\n FROM content_nodes\n WHERE deletedAt IS NULL\n AND (status = 'draft' OR hasUnpublishedChanges = 1)\n ORDER BY updatedAt DESC\n LIMIT 100\n )\n SELECT \n pd.*,\n GROUP_CONCAT(DISTINCT ch.label) as channelLabels,\n GROUP_CONCAT(DISTINCT t.label) as treeLabels\n FROM pending_drafts pd\n LEFT JOIN node_channels nc ON pd.id = nc.nodeId\n LEFT JOIN channels ch ON nc.channelId = ch.id\n LEFT JOIN tree_nodes tn ON pd.id = tn.contentId\n LEFT JOIN trees t ON tn.treeId = t.id\n GROUP BY pd.id\n ORDER BY pd.updatedAt DESC\n ").all(), m = (Array.isArray(p) ? p : p?.results || []).map((e) => ({
|
|
26400
26713
|
id: e.id,
|
|
26401
26714
|
title: e.title,
|
|
26402
26715
|
slug: e.slug,
|
|
@@ -26408,8 +26721,8 @@ fS.get("/", async (e) => {
|
|
|
26408
26721
|
isHidden: !!e.isHidden,
|
|
26409
26722
|
channelNames: e.channelLabels ? e.channelLabels.split(",") : [],
|
|
26410
26723
|
treeNames: e.treeLabels ? e.treeLabels.split(",") : []
|
|
26411
|
-
})),
|
|
26412
|
-
let t = e.type || "node", n =
|
|
26724
|
+
})), h = e.env?.BUNDLED_DEFINITIONS, g = hS(h), _ = g.nodes || g.nodeSchemas || {}, v = u.map((e) => {
|
|
26725
|
+
let t = e.type || "node", n = _[t]?.label || t.charAt(0).toUpperCase() + t.slice(1);
|
|
26413
26726
|
return {
|
|
26414
26727
|
type: t,
|
|
26415
26728
|
count: Number(e.count) || 0,
|
|
@@ -26420,12 +26733,13 @@ fS.get("/", async (e) => {
|
|
|
26420
26733
|
total: r,
|
|
26421
26734
|
published: i,
|
|
26422
26735
|
hidden: a,
|
|
26423
|
-
|
|
26424
|
-
|
|
26425
|
-
|
|
26426
|
-
|
|
26427
|
-
|
|
26428
|
-
|
|
26736
|
+
pendingCount: s,
|
|
26737
|
+
totalChannels: Number(c?.totalChannels) || 0,
|
|
26738
|
+
totalTrees: Number(c?.totalTrees) || 0,
|
|
26739
|
+
totalUsers: Number(c?.totalUsers) || 0,
|
|
26740
|
+
byType: v,
|
|
26741
|
+
recentActivity: f,
|
|
26742
|
+
pendingNodes: m
|
|
26429
26743
|
});
|
|
26430
26744
|
} catch (t) {
|
|
26431
26745
|
return console.error("[CMS Admin Stats API] Error fetching stats:", t), e.json({
|
|
@@ -26434,8 +26748,8 @@ fS.get("/", async (e) => {
|
|
|
26434
26748
|
}, 500);
|
|
26435
26749
|
}
|
|
26436
26750
|
});
|
|
26437
|
-
var
|
|
26438
|
-
async function
|
|
26751
|
+
var sC = new e();
|
|
26752
|
+
async function cC(e, t, n = []) {
|
|
26439
26753
|
let r = e.prepare(t);
|
|
26440
26754
|
if (typeof r.bind == "function") {
|
|
26441
26755
|
let e = await r.bind(...n).all();
|
|
@@ -26447,19 +26761,19 @@ async function mS(e, t, n = []) {
|
|
|
26447
26761
|
}
|
|
26448
26762
|
return [];
|
|
26449
26763
|
}
|
|
26450
|
-
async function
|
|
26764
|
+
async function lC(e, t, n = []) {
|
|
26451
26765
|
let r = e.prepare(t);
|
|
26452
26766
|
if (typeof r.bind == "function") return await r.bind(...n).run();
|
|
26453
26767
|
if (typeof r.run == "function") return await r.run(...n);
|
|
26454
26768
|
}
|
|
26455
|
-
function
|
|
26769
|
+
function uC(e) {
|
|
26456
26770
|
return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
26457
26771
|
}
|
|
26458
|
-
function
|
|
26772
|
+
function dC(e, t, n) {
|
|
26459
26773
|
let r = e || (t ? `/media/${t}` : "");
|
|
26460
26774
|
return r && n && r.startsWith(`https://${n}/`) && !r.includes("/media/") && (r = r.replace(`https://${n}/`, `https://${n}/media/`)), r;
|
|
26461
26775
|
}
|
|
26462
|
-
|
|
26776
|
+
sC.get("/", async (e) => {
|
|
26463
26777
|
try {
|
|
26464
26778
|
let t = Mb(e), { search: n = "", type: r = "all", page: i = "1", limit: a = "24", sort: o = "createdAt", order: s = "DESC", nodeId: c, channelId: l, trashed: u, tags: d } = e.req.query(), f = Math.max(1, parseInt(i, 10) || 1), p = Math.max(1, Math.min(100, parseInt(a, 10) || 24)), m = (f - 1) * p, h = {
|
|
26465
26779
|
createdAt: "a.createdAt",
|
|
@@ -26469,7 +26783,7 @@ pS.get("/", async (e) => {
|
|
|
26469
26783
|
sizeBytes: "a.sizeBytes"
|
|
26470
26784
|
}[o] || "a.createdAt", g = s.toUpperCase() === "ASC" ? "ASC" : "DESC", _ = [], v = ["(a.isSystemVariant = 0 OR a.isSystemVariant IS NULL)", u === "true" || u === "1" ? "(a.deletedAt IS NOT NULL AND a.deletedAt != '')" : "(a.deletedAt IS NULL OR a.deletedAt = '')"];
|
|
26471
26785
|
if (c) {
|
|
26472
|
-
let e = await
|
|
26786
|
+
let e = await cC(t, "SELECT a.id, a.filename, a.isSystemVariant FROM node_assets na JOIN assets a ON na.assetId = a.id WHERE na.nodeId = ?", [Number(c)]);
|
|
26473
26787
|
if (e.length === 0) v.push("1 = 0");
|
|
26474
26788
|
else {
|
|
26475
26789
|
let t = e.map((e) => e.isSystemVariant ? `(a.id = '${e.id}' OR a.id IN (SELECT parentAssetId FROM assets WHERE id = '${e.id}'))` : `a.id = '${e.id}'`).join(" OR ");
|
|
@@ -26490,10 +26804,10 @@ pS.get("/", async (e) => {
|
|
|
26490
26804
|
n && n.trim() !== "" && (v.push("a.filename LIKE ?"), _.push(`%${n.trim()}%`)), r && r !== "all" && (r === "image" ? (v.push("a.mimeType LIKE ?"), _.push("image/%")) : r === "document" ? (v.push("(a.mimeType LIKE ? OR a.mimeType LIKE ? OR a.mimeType LIKE ?)"), _.push("application/pdf%", "application/msword%", "application/vnd%")) : r === "video" && (v.push("(a.mimeType LIKE ? OR a.mimeType LIKE ?)"), _.push("video/%", "audio/%")));
|
|
26491
26805
|
let y = `SELECT a.id, a.filename, a.mimeType, a.sizeBytes, a.cdnUrl, a.storageKeyPrivate, a.createdAt, a.updatedAt, a.deletedAt, a.dataJson FROM assets a ${` WHERE ${v.join(" AND ")}`} ORDER BY ${h} ${g} LIMIT ? OFFSET ?`;
|
|
26492
26806
|
_.push(p, m);
|
|
26493
|
-
let b = await
|
|
26807
|
+
let b = await cC(t, y, _), x = b.map((e) => e.id), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map();
|
|
26494
26808
|
if (x.length > 0) {
|
|
26495
26809
|
let e = x.map(() => "?").join(",");
|
|
26496
|
-
(await
|
|
26810
|
+
(await cC(t, `
|
|
26497
26811
|
SELECT master.id AS assetId, COUNT(DISTINCT na.nodeId) AS count
|
|
26498
26812
|
FROM assets master
|
|
26499
26813
|
INNER JOIN node_assets na ON (
|
|
@@ -26501,13 +26815,13 @@ pS.get("/", async (e) => {
|
|
|
26501
26815
|
EXISTS (SELECT 1 FROM assets crop WHERE crop.id = na.assetId AND crop.isSystemVariant = 1 AND crop.parentAssetId = master.id)
|
|
26502
26816
|
)
|
|
26503
26817
|
WHERE master.id IN (${e})
|
|
26504
|
-
GROUP BY master.id`, x)).forEach((e) => S.set(String(e.assetId), e.count || 0)), (await
|
|
26818
|
+
GROUP BY master.id`, x)).forEach((e) => S.set(String(e.assetId), e.count || 0)), (await cC(t, `
|
|
26505
26819
|
SELECT parentAssetId, COUNT(id) AS count
|
|
26506
26820
|
FROM assets
|
|
26507
26821
|
WHERE isSystemVariant = 1 AND parentAssetId IN (${e})
|
|
26508
26822
|
GROUP BY parentAssetId`, x)).forEach((e) => C.set(String(e.parentAssetId), e.count || 0));
|
|
26509
26823
|
}
|
|
26510
|
-
let
|
|
26824
|
+
let ee = b.map((t) => {
|
|
26511
26825
|
let n = {
|
|
26512
26826
|
title: "",
|
|
26513
26827
|
alt: "",
|
|
@@ -26519,7 +26833,7 @@ pS.get("/", async (e) => {
|
|
|
26519
26833
|
...JSON.parse(t.dataJson || "{}")
|
|
26520
26834
|
};
|
|
26521
26835
|
} catch {}
|
|
26522
|
-
let r =
|
|
26836
|
+
let r = dC(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
26523
26837
|
return {
|
|
26524
26838
|
id: t.id,
|
|
26525
26839
|
filename: t.filename || "Untitled Asset",
|
|
@@ -26537,16 +26851,16 @@ pS.get("/", async (e) => {
|
|
|
26537
26851
|
originalUrl: r
|
|
26538
26852
|
};
|
|
26539
26853
|
});
|
|
26540
|
-
return e.json(
|
|
26854
|
+
return e.json(ee);
|
|
26541
26855
|
} catch (t) {
|
|
26542
26856
|
return e.json({
|
|
26543
26857
|
error: "Failed to fetch assets",
|
|
26544
26858
|
details: t.message || String(t)
|
|
26545
26859
|
}, 500);
|
|
26546
26860
|
}
|
|
26547
|
-
}),
|
|
26861
|
+
}), sC.post("/upload", async (e) => {
|
|
26548
26862
|
try {
|
|
26549
|
-
let t = Mb(e), { storage: n } =
|
|
26863
|
+
let t = Mb(e), { storage: n } = oS(e.env), r = await e.req.parseBody(), i = r.file, a = r.folderPath, o = r.isVariant === "true" || r.isVariant === "1" || r.temporary === "true", s = r.replaceAssetId, c = typeof s == "string" && s.trim().length > 0 ? s.trim() : null, l = r.parentAssetId || r.parentAsset, u = typeof l == "string" && l.trim().length > 0 ? l.trim() : null;
|
|
26550
26864
|
if (!i || !(i instanceof File)) return e.json({ error: "No file uploaded" }, 400);
|
|
26551
26865
|
let d = r.cropCoordinates, f = null, p = null;
|
|
26552
26866
|
if (d) {
|
|
@@ -26559,24 +26873,24 @@ pS.get("/", async (e) => {
|
|
|
26559
26873
|
}
|
|
26560
26874
|
let m = crypto.randomUUID().replace(/-/g, "").slice(0, 12), h = (/* @__PURE__ */ new Date()).toISOString().slice(0, 7).replace("-", "/"), g = o || i.name.startsWith("crop_"), _ = g ? `kama/cache/${h}/${m}` : `kama/uploads/${h}/${m}`, v = await n.upload(i, _), y = typeof v == "string" ? v : v?.key || v?.storageKeyPrivate || v?.storageKey || `${_}/${m}_${i.name}`;
|
|
26561
26875
|
if (!y) throw Error("Storage provider failed to return a valid storage key");
|
|
26562
|
-
let b = e.env.CDN_DOMAIN, x = y.replace(/^\//, ""), S = b ? `https://${b}/media/${x}` : `/media/${x}`, C = i.type || "application/octet-stream",
|
|
26563
|
-
|
|
26564
|
-
let
|
|
26876
|
+
let b = e.env.CDN_DOMAIN, x = y.replace(/^\//, ""), S = b ? `https://${b}/media/${x}` : `/media/${x}`, C = i.type || "application/octet-stream", ee = i.size || 0, w = e.get("userId"), te = typeof w == "string" && w.trim().length > 0 ? w : null;
|
|
26877
|
+
te && (await cC(t, "SELECT id FROM users WHERE id = ?", [te])).length === 0 && (te = null);
|
|
26878
|
+
let ne = new gS(e.env);
|
|
26565
26879
|
if (c) {
|
|
26566
|
-
let r = await
|
|
26880
|
+
let r = await cC(t, "SELECT storageKeyPrivate, isSystemVariant, parentAssetId FROM assets WHERE id = ?", [c]);
|
|
26567
26881
|
if (r.length > 0) {
|
|
26568
26882
|
let a = r[0];
|
|
26569
|
-
if (await
|
|
26883
|
+
if (await lC(t, "UPDATE assets SET filename = ?, mimeType = ?, sizeBytes = ?, storageKeyPrivate = ?, cdnUrl = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
26570
26884
|
i.name,
|
|
26571
26885
|
C,
|
|
26572
|
-
|
|
26886
|
+
ee,
|
|
26573
26887
|
y,
|
|
26574
26888
|
S,
|
|
26575
26889
|
c
|
|
26576
26890
|
]), a.storageKeyPrivate) try {
|
|
26577
26891
|
await n.delete(a.storageKeyPrivate);
|
|
26578
26892
|
} catch {}
|
|
26579
|
-
return
|
|
26893
|
+
return ne.purgeAsset(e, t, c), e.json({
|
|
26580
26894
|
id: c,
|
|
26581
26895
|
url: `${S}?v=${Date.now()}`,
|
|
26582
26896
|
originalUrl: `${S}?v=${Date.now()}`,
|
|
@@ -26590,52 +26904,52 @@ pS.get("/", async (e) => {
|
|
|
26590
26904
|
}, 200);
|
|
26591
26905
|
}
|
|
26592
26906
|
}
|
|
26593
|
-
let
|
|
26594
|
-
if (await
|
|
26595
|
-
|
|
26907
|
+
let T = `ast_${m}`, E = +!!g;
|
|
26908
|
+
if (await lC(t, "INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
|
26909
|
+
T,
|
|
26596
26910
|
i.name,
|
|
26597
26911
|
C,
|
|
26598
|
-
|
|
26912
|
+
ee,
|
|
26599
26913
|
y,
|
|
26600
26914
|
S,
|
|
26601
|
-
E,
|
|
26602
26915
|
te,
|
|
26916
|
+
E,
|
|
26603
26917
|
u,
|
|
26604
26918
|
f
|
|
26605
26919
|
]), typeof a == "string" && a.trim()) {
|
|
26606
26920
|
let e = a.split("/").filter((e) => e.trim() !== "");
|
|
26607
26921
|
for (let n of e) {
|
|
26608
|
-
let e =
|
|
26922
|
+
let e = uC(n), r = null, i = await cC(t, "SELECT id FROM taxonomy_terms WHERE taxonomy = ? AND key = ?", ["media-tag", e]);
|
|
26609
26923
|
if (i.length > 0) r = i[0].id;
|
|
26610
26924
|
else {
|
|
26611
|
-
await
|
|
26925
|
+
await lC(t, "INSERT INTO taxonomy_terms (taxonomy, key, label, sortOrder, dataJson) VALUES (?, ?, ?, ?, ?)", [
|
|
26612
26926
|
"media-tag",
|
|
26613
26927
|
e,
|
|
26614
26928
|
n,
|
|
26615
26929
|
0,
|
|
26616
26930
|
"{}"
|
|
26617
26931
|
]);
|
|
26618
|
-
let i = await
|
|
26932
|
+
let i = await cC(t, "SELECT id FROM taxonomy_terms WHERE taxonomy = ? AND key = ?", ["media-tag", e]);
|
|
26619
26933
|
i.length > 0 && (r = i[0].id);
|
|
26620
26934
|
}
|
|
26621
|
-
r && await
|
|
26935
|
+
r && await lC(t, "INSERT OR IGNORE INTO asset_terms (assetId, termId) VALUES (?, ?)", [T, r]);
|
|
26622
26936
|
}
|
|
26623
26937
|
}
|
|
26624
|
-
let
|
|
26938
|
+
let D = S;
|
|
26625
26939
|
if (u) {
|
|
26626
|
-
let n = await
|
|
26627
|
-
n.length > 0 && (
|
|
26940
|
+
let n = await cC(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [u]);
|
|
26941
|
+
n.length > 0 && (D = dC(n[0].cdnUrl, n[0].storageKeyPrivate, b)), ne.purgeAsset(e, t, u);
|
|
26628
26942
|
}
|
|
26629
26943
|
return e.json({
|
|
26630
|
-
id:
|
|
26944
|
+
id: T,
|
|
26631
26945
|
url: S,
|
|
26632
|
-
originalUrl:
|
|
26946
|
+
originalUrl: D,
|
|
26633
26947
|
parentAssetId: u,
|
|
26634
26948
|
cropCoordinates: p,
|
|
26635
26949
|
filename: i.name,
|
|
26636
26950
|
mimeType: C,
|
|
26637
26951
|
usageCount: 0,
|
|
26638
|
-
isSystemVariant: !!
|
|
26952
|
+
isSystemVariant: !!E
|
|
26639
26953
|
}, 201);
|
|
26640
26954
|
} catch (t) {
|
|
26641
26955
|
return e.json({
|
|
@@ -26643,11 +26957,11 @@ pS.get("/", async (e) => {
|
|
|
26643
26957
|
details: t.message || String(t)
|
|
26644
26958
|
}, 500);
|
|
26645
26959
|
}
|
|
26646
|
-
}),
|
|
26960
|
+
}), sC.get("/:id/details", async (e) => {
|
|
26647
26961
|
try {
|
|
26648
|
-
let t = Mb(e), n = e.req.param("id"), r = await
|
|
26962
|
+
let t = Mb(e), n = e.req.param("id"), r = await cC(t, "SELECT * FROM assets WHERE id = ?", [n]);
|
|
26649
26963
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
26650
|
-
let i = r[0], a = await
|
|
26964
|
+
let i = r[0], a = await cC(t, "\n SELECT DISTINCT cn.id, cn.title, cn.contentType, cn.slug, na.fieldKey, na.assetId \n FROM node_assets na \n INNER JOIN content_nodes cn ON na.nodeId = cn.id \n LEFT JOIN assets crop ON na.assetId = crop.id \n WHERE na.assetId = ? OR (crop.isSystemVariant = 1 AND crop.parentAssetId = ?)\n ", [n, n]), o = await cC(t, "\n SELECT id, filename, mimeType, sizeBytes, cdnUrl, storageKeyPrivate, parentAssetId, cropCoordinatesJson, createdAt, updatedAt \n FROM assets \n WHERE isSystemVariant = 1 AND parentAssetId = ? \n ORDER BY createdAt DESC\n ", [n]), s = (await cC(t, "\n SELECT t.id FROM asset_terms at \n JOIN taxonomy_terms t ON at.termId = t.id \n WHERE at.assetId = ?\n ", [n])).map((e) => `trm_${e.id}`), c = {
|
|
26651
26965
|
title: "",
|
|
26652
26966
|
alt: "",
|
|
26653
26967
|
description: ""
|
|
@@ -26658,7 +26972,7 @@ pS.get("/", async (e) => {
|
|
|
26658
26972
|
...JSON.parse(i.dataJson || "{}")
|
|
26659
26973
|
};
|
|
26660
26974
|
} catch {}
|
|
26661
|
-
let l = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), u = `${
|
|
26975
|
+
let l = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), u = `${dC(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN)}?v=${l}`;
|
|
26662
26976
|
return e.json({
|
|
26663
26977
|
id: i.id,
|
|
26664
26978
|
filename: i.filename,
|
|
@@ -26678,7 +26992,7 @@ pS.get("/", async (e) => {
|
|
|
26678
26992
|
if (t.cropCoordinatesJson) try {
|
|
26679
26993
|
n = JSON.parse(t.cropCoordinatesJson);
|
|
26680
26994
|
} catch {}
|
|
26681
|
-
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : l, a =
|
|
26995
|
+
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : l, a = dC(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
26682
26996
|
return {
|
|
26683
26997
|
id: t.id,
|
|
26684
26998
|
filename: t.filename,
|
|
@@ -26695,31 +27009,31 @@ pS.get("/", async (e) => {
|
|
|
26695
27009
|
} catch {
|
|
26696
27010
|
return e.json({ error: "Failed to load details" }, 500);
|
|
26697
27011
|
}
|
|
26698
|
-
}),
|
|
27012
|
+
}), sC.put("/:id", async (e) => {
|
|
26699
27013
|
try {
|
|
26700
|
-
let t = Mb(e), n = e.req.param("id"), r = await e.req.json(), i = await
|
|
27014
|
+
let t = Mb(e), n = e.req.param("id"), r = await e.req.json(), i = await cC(t, "SELECT filename, dataJson FROM assets WHERE id = ?", [n]);
|
|
26701
27015
|
if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
26702
27016
|
let a = i[0], o = {};
|
|
26703
27017
|
try {
|
|
26704
27018
|
o = JSON.parse(a.dataJson || "{}");
|
|
26705
27019
|
} catch {}
|
|
26706
|
-
if (r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await
|
|
27020
|
+
if (r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await lC(t, "UPDATE assets SET filename = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
26707
27021
|
r.filename === void 0 ? a.filename : r.filename,
|
|
26708
27022
|
JSON.stringify(o),
|
|
26709
27023
|
n
|
|
26710
27024
|
]), r.tags !== void 0 && Array.isArray(r.tags)) {
|
|
26711
|
-
await
|
|
27025
|
+
await lC(t, "DELETE FROM asset_terms WHERE assetId = ?", [n]);
|
|
26712
27026
|
let e = r.tags.map((e) => Number(e.replace("trm_", ""))).filter((e) => !isNaN(e));
|
|
26713
|
-
for (let r of e) await
|
|
27027
|
+
for (let r of e) await lC(t, "INSERT OR IGNORE INTO asset_terms (assetId, termId) VALUES (?, ?)", [n, r]);
|
|
26714
27028
|
}
|
|
26715
|
-
return new
|
|
27029
|
+
return new gS(e.env).purgeAsset(e, t, n), e.json({ success: !0 });
|
|
26716
27030
|
} catch {
|
|
26717
27031
|
return e.json({ error: "Failed to update asset" }, 500);
|
|
26718
27032
|
}
|
|
26719
|
-
}),
|
|
27033
|
+
}), sC.delete("/:id", async (e) => {
|
|
26720
27034
|
try {
|
|
26721
|
-
let t = Mb(e), n = e.req.param("id"), r = (await
|
|
26722
|
-
return r ? (new
|
|
27035
|
+
let t = Mb(e), n = e.req.param("id"), r = (await cC(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
27036
|
+
return r ? (new gS(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await lC(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await lC(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ? OR (isSystemVariant = 1 AND parentAssetId = ?)", [n, n]), e.json({
|
|
26723
27037
|
success: !0,
|
|
26724
27038
|
id: n,
|
|
26725
27039
|
trashed: !0
|
|
@@ -26730,10 +27044,10 @@ pS.get("/", async (e) => {
|
|
|
26730
27044
|
details: t.message || String(t)
|
|
26731
27045
|
}, 500);
|
|
26732
27046
|
}
|
|
26733
|
-
}),
|
|
27047
|
+
}), sC.post("/restore", async (e) => {
|
|
26734
27048
|
try {
|
|
26735
27049
|
let t = Mb(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
26736
|
-
return r ? (await
|
|
27050
|
+
return r ? (await cC(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0] ? (await lC(t, "UPDATE assets SET deletedAt = NULL WHERE id = ? OR (isSystemVariant = 1 AND parentAssetId = ?)", [r, r]), new gS(e.env).purgeAsset(e, t, r), e.json({
|
|
26737
27051
|
success: !0,
|
|
26738
27052
|
id: r,
|
|
26739
27053
|
restored: !0
|
|
@@ -26744,13 +27058,13 @@ pS.get("/", async (e) => {
|
|
|
26744
27058
|
details: t.message
|
|
26745
27059
|
}, 500);
|
|
26746
27060
|
}
|
|
26747
|
-
}),
|
|
27061
|
+
}), sC.delete("/purge/:id", async (e) => {
|
|
26748
27062
|
try {
|
|
26749
|
-
let t = Mb(e), { storage: n } =
|
|
27063
|
+
let t = Mb(e), { storage: n } = oS(e.env), r = e.req.param("id"), i = (await cC(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
|
|
26750
27064
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
26751
|
-
new
|
|
27065
|
+
new gS(e.env).purgeAsset(e, t, r);
|
|
26752
27066
|
let a = [i];
|
|
26753
|
-
i.isSystemVariant || (a = [i, ...await
|
|
27067
|
+
i.isSystemVariant || (a = [i, ...await cC(t, "SELECT id, storageKeyPrivate FROM assets WHERE isSystemVariant = 1 AND parentAssetId = ?", [r])]);
|
|
26754
27068
|
let o = a.map((e) => e.id);
|
|
26755
27069
|
if (typeof n.delete == "function") {
|
|
26756
27070
|
for (let e of a) if (e.storageKeyPrivate) try {
|
|
@@ -26760,7 +27074,7 @@ pS.get("/", async (e) => {
|
|
|
26760
27074
|
}
|
|
26761
27075
|
}
|
|
26762
27076
|
let s = o.map(() => "?").join(",");
|
|
26763
|
-
return await
|
|
27077
|
+
return await lC(t, `DELETE FROM node_assets WHERE assetId IN (${s})`, o), await lC(t, `DELETE FROM assets WHERE id IN (${s})`, o), e.json({
|
|
26764
27078
|
success: !0,
|
|
26765
27079
|
id: r,
|
|
26766
27080
|
purged: !0,
|
|
@@ -26774,8 +27088,8 @@ pS.get("/", async (e) => {
|
|
|
26774
27088
|
}, 500);
|
|
26775
27089
|
}
|
|
26776
27090
|
});
|
|
26777
|
-
var
|
|
26778
|
-
function
|
|
27091
|
+
var fC = new sb();
|
|
27092
|
+
function pC() {
|
|
26779
27093
|
return {
|
|
26780
27094
|
fullPath: /* @__PURE__ */ new Map(),
|
|
26781
27095
|
treeEdges: /* @__PURE__ */ new Map(),
|
|
@@ -26783,7 +27097,7 @@ function yS() {
|
|
|
26783
27097
|
assetUrls: /* @__PURE__ */ new Map()
|
|
26784
27098
|
};
|
|
26785
27099
|
}
|
|
26786
|
-
function
|
|
27100
|
+
function mC(e, t, n = []) {
|
|
26787
27101
|
let r = Date.now();
|
|
26788
27102
|
if (e && String(e).trim() !== "") {
|
|
26789
27103
|
let t = Date.parse(e);
|
|
@@ -26794,7 +27108,7 @@ function bS(e, t, n = []) {
|
|
|
26794
27108
|
!isNaN(e) && e > r && n.push(e);
|
|
26795
27109
|
}
|
|
26796
27110
|
}
|
|
26797
|
-
function
|
|
27111
|
+
function hC(e, t) {
|
|
26798
27112
|
let n = Date.now();
|
|
26799
27113
|
if (e && String(e).trim() !== "") {
|
|
26800
27114
|
let t = Date.parse(e);
|
|
@@ -26806,7 +27120,7 @@ function xS(e, t) {
|
|
|
26806
27120
|
}
|
|
26807
27121
|
return !0;
|
|
26808
27122
|
}
|
|
26809
|
-
async function
|
|
27123
|
+
async function gC(e, t, n, r, i, a) {
|
|
26810
27124
|
let o = t.filter((e) => e.componentId === "content-feed" || e.componentId === "article-list" || e.componentId === "nodeList" || e.componentId === "node-list");
|
|
26811
27125
|
await Promise.all(o.map(async (t) => {
|
|
26812
27126
|
let o = t.data || {}, s = o.nodeType || ["article"], c = (Array.isArray(s) ? s : String(s).split(",")).map((e) => String(e).trim()).filter(Boolean), l = {};
|
|
@@ -26873,7 +27187,7 @@ async function SS(e, t, n, r, i, a) {
|
|
|
26873
27187
|
if (e.dataJson) try {
|
|
26874
27188
|
t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
26875
27189
|
} catch {}
|
|
26876
|
-
i &&
|
|
27190
|
+
i && mC(t.startShowingAt, t.stopShowingAt, i);
|
|
26877
27191
|
let n = {};
|
|
26878
27192
|
if (a) {
|
|
26879
27193
|
let r = l[e.contentType || "article"] || [];
|
|
@@ -26898,7 +27212,7 @@ async function SS(e, t, n, r, i, a) {
|
|
|
26898
27212
|
}
|
|
26899
27213
|
}));
|
|
26900
27214
|
}
|
|
26901
|
-
async function
|
|
27215
|
+
async function _C(e, t, n, r, i, a, o = !1, s, c) {
|
|
26902
27216
|
if (!t) return { blocks: [] };
|
|
26903
27217
|
let l = await e.prepare("\n WITH RECURSIVE ancestor_path(contentId, title, slug, parentId, level) AS (\n SELECT t.contentId, c.title, c.slug, t.parentId, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.contentId = ? AND t.treeId = ?\n UNION ALL\n SELECT t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.contentId = ap.parentId AND t.treeId = ?\n )\n SELECT * FROM ancestor_path ORDER BY level ASC\n ").all(t, n, n), u = Array.isArray(l) ? l : l?.results || [];
|
|
26904
27218
|
if (!u || u.length === 0) return { blocks: [] };
|
|
@@ -26934,14 +27248,15 @@ async function CS(e, t, n, r, i, a, o = !1, s, c) {
|
|
|
26934
27248
|
try {
|
|
26935
27249
|
n = (typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : t.dataJson) || {};
|
|
26936
27250
|
} catch {}
|
|
26937
|
-
c &&
|
|
26938
|
-
let l = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", u =
|
|
27251
|
+
c && mC(n.startShowingAt, n.stopShowingAt, c);
|
|
27252
|
+
let l = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", u = hC(n.startShowingAt, n.stopShowingAt);
|
|
26939
27253
|
if (!o && (l || !u)) return null;
|
|
26940
|
-
let d = t.elementType || t.componentId || "text-block", f = i.blocks?.[d]?.fields || i.elements?.[d]?.fields || i.components?.[d]?.fields || {}, p = String(n.blockId || n._instanceId || n.id || t.blockId || t.id), m =
|
|
26941
|
-
return m = await
|
|
27254
|
+
let d = t.elementType || t.componentId || "text-block", f = i.blocks?.[d]?.fields || i.elements?.[d]?.fields || i.components?.[d]?.fields || {}, p = String(n.blockId || n._instanceId || n.id || t.blockId || t.id), m = vC(n, f);
|
|
27255
|
+
return m = await mS(e, m), m = yC(m), m = await bC(e, m, a, s), m.blockId = p, {
|
|
26942
27256
|
region: t.region || r,
|
|
26943
27257
|
block: {
|
|
26944
27258
|
instanceId: t.id,
|
|
27259
|
+
contentId: t.contentId,
|
|
26945
27260
|
blockId: p,
|
|
26946
27261
|
componentId: d,
|
|
26947
27262
|
data: m
|
|
@@ -26958,7 +27273,7 @@ async function CS(e, t, n, r, i, a, o = !1, s, c) {
|
|
|
26958
27273
|
}
|
|
26959
27274
|
return { blocks: [] };
|
|
26960
27275
|
}
|
|
26961
|
-
function
|
|
27276
|
+
function vC(e, t = {}) {
|
|
26962
27277
|
let n = {};
|
|
26963
27278
|
for (let [r, i] of Object.entries(e)) r.endsWith("_meta") || [
|
|
26964
27279
|
"disabledRegions",
|
|
@@ -26974,14 +27289,14 @@ function wS(e, t = {}) {
|
|
|
26974
27289
|
].includes(r) || r.startsWith("_") || (!t[r] || t[r].public !== !1) && (n[r] = i);
|
|
26975
27290
|
return n;
|
|
26976
27291
|
}
|
|
26977
|
-
function
|
|
26978
|
-
if (Array.isArray(e)) return e.map(
|
|
27292
|
+
function yC(e) {
|
|
27293
|
+
if (Array.isArray(e)) return e.map(yC);
|
|
26979
27294
|
if (!e || typeof e != "object") return e;
|
|
26980
27295
|
if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
|
|
26981
27296
|
let t = e.metadataOverrides || {}, n = e.variants && typeof e.variants == "object" ? e.variants : {}, r = Object.entries(n).find(([, t]) => t?.id === e.id)?.[0], i = r ? {
|
|
26982
27297
|
...t,
|
|
26983
27298
|
...t.crops?.[r] || {}
|
|
26984
|
-
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t,
|
|
27299
|
+
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, yC({
|
|
26985
27300
|
...n,
|
|
26986
27301
|
title: n?.title ?? e.title ?? "",
|
|
26987
27302
|
alt: n?.alt ?? e.alt ?? "",
|
|
@@ -26995,9 +27310,9 @@ function TS(e) {
|
|
|
26995
27310
|
...Object.keys(a).length > 0 ? { variants: a } : {}
|
|
26996
27311
|
};
|
|
26997
27312
|
}
|
|
26998
|
-
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e,
|
|
27313
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, yC(t)]));
|
|
26999
27314
|
}
|
|
27000
|
-
async function
|
|
27315
|
+
async function bC(e, t, n, r) {
|
|
27001
27316
|
if (typeof t == "string") {
|
|
27002
27317
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
27003
27318
|
let r = (e, t) => {
|
|
@@ -27038,25 +27353,25 @@ async function ES(e, t, n, r) {
|
|
|
27038
27353
|
return /href\s*=\s*["'][^"']*["']/i.test(d) ? d = d.replace(/href\s*=\s*["'][^"']*["']/i, `href="${u}"`) : d += ` href="${u}"`, `<a ${d}>`;
|
|
27039
27354
|
});
|
|
27040
27355
|
}
|
|
27041
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) =>
|
|
27356
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => bC(e, t, n, r)));
|
|
27042
27357
|
if (t && typeof t == "object") {
|
|
27043
27358
|
if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) return {
|
|
27044
27359
|
...t,
|
|
27045
|
-
href: await
|
|
27360
|
+
href: await xC(e, t, n, r)
|
|
27046
27361
|
};
|
|
27047
|
-
let i = await Promise.all(Object.entries(t).map(async ([t, i]) => [t, await
|
|
27362
|
+
let i = await Promise.all(Object.entries(t).map(async ([t, i]) => [t, await bC(e, i, n, r)]));
|
|
27048
27363
|
return Object.fromEntries(i);
|
|
27049
27364
|
}
|
|
27050
27365
|
return t;
|
|
27051
27366
|
}
|
|
27052
|
-
async function
|
|
27367
|
+
async function xC(e, t, n, r) {
|
|
27053
27368
|
let i = t.href.match(/^#node:(.+)$/), a = t.href.match(/^#asset:(.+)$/);
|
|
27054
|
-
if (a) return
|
|
27369
|
+
if (a) return SC(e, a[1], r);
|
|
27055
27370
|
if (!i) return t.href;
|
|
27056
27371
|
let o = i[1];
|
|
27057
27372
|
return (await e.prepare("\n SELECT path \n FROM node_routes \n WHERE nodeId = ? AND isCanonical = 1 \n ORDER BY CASE WHEN channelId = ? THEN 0 ELSE 1 END ASC \n LIMIT 1\n ").get(Number(o), n))?.path || "#";
|
|
27058
27373
|
}
|
|
27059
|
-
async function
|
|
27374
|
+
async function SC(e, t, n) {
|
|
27060
27375
|
let r = String(t), i = n.assetUrls.get(r);
|
|
27061
27376
|
if (i) return i;
|
|
27062
27377
|
let a = (async () => {
|
|
@@ -27065,7 +27380,7 @@ async function OS(e, t, n) {
|
|
|
27065
27380
|
})();
|
|
27066
27381
|
return n.assetUrls.set(r, a), a;
|
|
27067
27382
|
}
|
|
27068
|
-
function
|
|
27383
|
+
function CC(e) {
|
|
27069
27384
|
let t = e.socialImage;
|
|
27070
27385
|
if (!t || typeof t != "object") return null;
|
|
27071
27386
|
let n = (e, t) => {
|
|
@@ -27096,7 +27411,7 @@ function kS(e) {
|
|
|
27096
27411
|
])
|
|
27097
27412
|
};
|
|
27098
27413
|
}
|
|
27099
|
-
async function
|
|
27414
|
+
async function wC(e, t, n, r, i) {
|
|
27100
27415
|
let a = {}, o = null;
|
|
27101
27416
|
if (t) {
|
|
27102
27417
|
let i = await e.prepare("\n WITH RECURSIVE ancestor_path(contentId, title, slug, parentId, level) AS (\n SELECT t.contentId, c.title, c.slug, t.parentId, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.contentId = ? AND t.treeId = ?\n UNION ALL\n SELECT t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.contentId = ap.parentId AND t.treeId = ?\n )\n SELECT c.dataJson, c.draftDataJson FROM ancestor_path ap INNER JOIN content_nodes c ON ap.contentId = c.id ORDER BY ap.level ASC\n ").all(t, n, n), s = Array.isArray(i) ? i : i?.results || [], c = /* @__PURE__ */ new Set([
|
|
@@ -27134,20 +27449,20 @@ async function AS(e, t, n, r, i) {
|
|
|
27134
27449
|
inheritedFields: a
|
|
27135
27450
|
};
|
|
27136
27451
|
}
|
|
27137
|
-
function
|
|
27452
|
+
function TC(e) {
|
|
27138
27453
|
let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
|
|
27139
27454
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
27140
27455
|
}
|
|
27141
|
-
async function
|
|
27456
|
+
async function EC(e, t, n, r) {
|
|
27142
27457
|
try {
|
|
27143
27458
|
await e.set(t, n, r);
|
|
27144
27459
|
} catch (e) {
|
|
27145
27460
|
console.warn("[CMS Cache] Failed to write node response to cache:", e);
|
|
27146
27461
|
}
|
|
27147
27462
|
}
|
|
27148
|
-
async function
|
|
27463
|
+
async function DC(e) {
|
|
27149
27464
|
try {
|
|
27150
|
-
let t = e.get("db") || Mb(e), n =
|
|
27465
|
+
let t = e.get("db") || Mb(e), n = pC(), r = [], i = new URL(e.req.url), a = i.searchParams.get("channelId") || i.searchParams.get("channel"), o = i.searchParams.get("lang"), s = i.searchParams.get("preview") === "true", c = i.searchParams.get("revisionId"), l = i.searchParams.get("treeId"), u = i.pathname, d = "";
|
|
27151
27466
|
u.includes("/node/") ? d = u.substring(u.indexOf("/node/") + 6) : u.endsWith("/node") && (d = "");
|
|
27152
27467
|
try {
|
|
27153
27468
|
d = decodeURIComponent(d);
|
|
@@ -27156,7 +27471,7 @@ async function NS(e) {
|
|
|
27156
27471
|
let f = d === "" || d === "index" ? "/" : `/${d}`, p = a || "1", m = isNaN(Number(p)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(p) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(p));
|
|
27157
27472
|
if (!m) return e.json({ error: `Channel '${p}' not found` }, 404);
|
|
27158
27473
|
let h = m.status === "disabled" || m.status === "inactive" || m.isEnabled === 0 || m.isEnabled === !1;
|
|
27159
|
-
if (!s && h) return e.json({ error: `Channel '${m.key || p}' is currently
|
|
27474
|
+
if (!s && (h || Number(m.isHidden) === 1)) return e.json({ error: `Channel '${m.key || p}' is currently unavailable` }, 404);
|
|
27160
27475
|
let g = m.id, _ = m.key || p, v = await t.prepare("SELECT * FROM node_routes WHERE path = ? AND channelId = ? LIMIT 1").get(f, g);
|
|
27161
27476
|
if (v?.redirectUrl) return e.json({
|
|
27162
27477
|
redirect: v.redirectUrl,
|
|
@@ -27170,6 +27485,16 @@ async function NS(e) {
|
|
|
27170
27485
|
y = await t.prepare("SELECT * FROM content_nodes WHERE slug = ?").get(e);
|
|
27171
27486
|
}
|
|
27172
27487
|
if (!y) return e.json({ error: `Node '${d}' not found for Channel '${p}'` }, 404);
|
|
27488
|
+
if (!s) {
|
|
27489
|
+
let t = {};
|
|
27490
|
+
try {
|
|
27491
|
+
t = typeof y.dataJson == "string" ? JSON.parse(y.dataJson || "{}") : y.dataJson || {};
|
|
27492
|
+
} catch {
|
|
27493
|
+
t = {};
|
|
27494
|
+
}
|
|
27495
|
+
let n = !!(y.deletedAt && String(y.deletedAt).trim()), r = Number(y.isHidden) === 1 || t.hidden === !0 || t.hidden === 1 || t.hidden === "1" || t.hidden === "true" || t.is_hidden === !0 || t.is_hidden === 1 || t.is_hidden === "1" || t.is_hidden === "true" || t.isHidden === !0 || t.isHidden === 1 || t.isHidden === "1" || t.isHidden === "true", i = !hC(t.startShowingAt || y.startShowingAt, t.stopShowingAt || y.stopShowingAt), a = y.status === "draft" || y.status === "new", o = !!(y.dataJson && y.dataJson !== "{}" && y.dataJson !== "null");
|
|
27496
|
+
if (n || r || i || a && !o) return e.json({ error: "Node is hidden, offline, deleted, or has never been published." }, 404);
|
|
27497
|
+
}
|
|
27173
27498
|
let x = null;
|
|
27174
27499
|
if (c) {
|
|
27175
27500
|
let e = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(y.id, Number(c));
|
|
@@ -27187,20 +27512,20 @@ async function NS(e) {
|
|
|
27187
27512
|
t.defaultLanguage ? C = String(t.defaultLanguage).trim() : t.language && (C = String(t.language).trim());
|
|
27188
27513
|
} catch {}
|
|
27189
27514
|
}
|
|
27190
|
-
let
|
|
27515
|
+
let ee = null;
|
|
27191
27516
|
if (m) {
|
|
27192
|
-
if (m.defaultLanguage)
|
|
27517
|
+
if (m.defaultLanguage) ee = String(m.defaultLanguage).trim();
|
|
27193
27518
|
else if (m.dataJson) try {
|
|
27194
27519
|
let e = typeof m.dataJson == "string" ? JSON.parse(m.dataJson) : m.dataJson;
|
|
27195
|
-
e.defaultLanguage ?
|
|
27520
|
+
e.defaultLanguage ? ee = String(e.defaultLanguage).trim() : e.language && (ee = String(e.language).trim());
|
|
27196
27521
|
} catch {}
|
|
27197
27522
|
}
|
|
27198
|
-
let
|
|
27199
|
-
if (!s && !
|
|
27200
|
-
let t = await
|
|
27523
|
+
let w = y.language?.trim() || null, te = C || ee || o?.trim() || null, ne = w || te || null, T = `node:${g || _}:${ne || "default"}:${d}`, E = e.req.header("x-bypass-cache") === "true" || !!c, D = tS(e), O = TC(e);
|
|
27524
|
+
if (!s && !E) {
|
|
27525
|
+
let t = await D.get(T);
|
|
27201
27526
|
if (t) {
|
|
27202
27527
|
e.header("X-Cache", "HIT");
|
|
27203
|
-
let n =
|
|
27528
|
+
let n = O;
|
|
27204
27529
|
if (t.meta && t.meta.nextEventTimestamp) {
|
|
27205
27530
|
let e = Math.floor((t.meta.nextEventTimestamp - Date.now()) / 1e3);
|
|
27206
27531
|
e > 0 && e < n ? n = e : e <= 0 && (n = 0);
|
|
@@ -27208,32 +27533,32 @@ async function NS(e) {
|
|
|
27208
27533
|
return n > 0 ? e.header("Cache-Control", `public, max-age=${n}, s-maxage=${n}`) : e.header("Cache-Control", "no-cache, no-store, must-revalidate"), e.json(t);
|
|
27209
27534
|
}
|
|
27210
27535
|
}
|
|
27211
|
-
let
|
|
27212
|
-
if (!S && !
|
|
27536
|
+
let re = S?.parentId || null;
|
|
27537
|
+
if (!S && !re) {
|
|
27213
27538
|
let e = f.split("/").filter(Boolean);
|
|
27214
27539
|
if (e.length > 1) {
|
|
27215
27540
|
e.pop();
|
|
27216
27541
|
let n = "/" + e.join("/"), r = await t.prepare("SELECT nodeId FROM node_routes WHERE path = ? AND channelId = ? LIMIT 1").get(n, g);
|
|
27217
27542
|
if (r?.nodeId) {
|
|
27218
27543
|
let e = await t.prepare("SELECT contentId, treeId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r.nodeId);
|
|
27219
|
-
e && (
|
|
27544
|
+
e && (re = e.contentId, b = e.treeId);
|
|
27220
27545
|
}
|
|
27221
27546
|
}
|
|
27222
|
-
if (!
|
|
27547
|
+
if (!re) {
|
|
27223
27548
|
let e = await t.prepare("SELECT contentId, treeId FROM tree_nodes WHERE parentId IS NULL ORDER BY sortOrder ASC LIMIT 1").get();
|
|
27224
|
-
e && (
|
|
27549
|
+
e && (re = e.contentId, b = e.treeId);
|
|
27225
27550
|
}
|
|
27226
27551
|
}
|
|
27227
|
-
let
|
|
27552
|
+
let k = v?.path || (f === "" ? "/" : f), A = {
|
|
27228
27553
|
id: y.id,
|
|
27229
27554
|
title: y.title,
|
|
27230
27555
|
slug: y.slug,
|
|
27231
|
-
language:
|
|
27232
|
-
path:
|
|
27556
|
+
language: ne,
|
|
27557
|
+
path: k,
|
|
27233
27558
|
nodeType: y.contentType,
|
|
27234
27559
|
createdAt: y.createdAt,
|
|
27235
27560
|
updatedAt: y.updatedAt
|
|
27236
|
-
}, j =
|
|
27561
|
+
}, j = hS(e.env?.BUNDLED_DEFINITIONS), ie = y.contentType || "node", ae = j.nodes?.[ie] || Object.values(j.nodes || {})[0] || {}, oe = { ...ae.fields || {} };
|
|
27237
27562
|
ae.tabs && Object.values(ae.tabs).forEach((e) => {
|
|
27238
27563
|
Object.assign(oe, e.fields || {});
|
|
27239
27564
|
});
|
|
@@ -27241,31 +27566,39 @@ async function NS(e) {
|
|
|
27241
27566
|
if (x && x.node && x.node.dataJson && (fe = x.node.dataJson), fe) try {
|
|
27242
27567
|
de = typeof fe == "string" ? JSON.parse(fe) : fe;
|
|
27243
27568
|
} catch {}
|
|
27244
|
-
de.disabledRegions && (se = de.disabledRegions), ue =
|
|
27245
|
-
|
|
27569
|
+
de.disabledRegions && (se = de.disabledRegions), ue = [
|
|
27570
|
+
de.hidden,
|
|
27571
|
+
de.is_hidden,
|
|
27572
|
+
de.isHidden
|
|
27573
|
+
].some((e) => e === !0 || e === 1 || e === "1" || e === "true"), ce = de.startShowingAt || y.startShowingAt || null, le = de.stopShowingAt || y.stopShowingAt || null, mC(ce, le, r);
|
|
27574
|
+
let pe = de.layoutId, me = pe && pe !== "inherit", { resolvedLayoutId: he, inheritedFields: ge } = await wC(t, re, b, s, oe), _e = me ? pe : he || ae.defaultLayout || null;
|
|
27246
27575
|
for (let [e, t] of Object.entries(ge)) (de[e] === void 0 || de[e] === null || de[e] === "" || de[e] === "inherit") && t !== void 0 && (de[e] = t);
|
|
27247
|
-
let ve = await
|
|
27248
|
-
ve =
|
|
27249
|
-
let ye =
|
|
27250
|
-
delete ve.socialImage, delete ve.fbImage, delete ve.xImage, delete ve.whatsappImage, ye && (ve.socialImages = ye), Object.assign(A, ve), A.id = y.id, A.slug = y.slug, A.title = y.title, A.path =
|
|
27251
|
-
let be = Number(y.isHidden) === 1 || ue, xe = !
|
|
27576
|
+
let ve = await mS(t, vC(de, oe));
|
|
27577
|
+
ve = yC(ve), ve = await bC(t, ve, g, n), delete ve.language;
|
|
27578
|
+
let ye = CC(ve);
|
|
27579
|
+
delete ve.socialImage, delete ve.fbImage, delete ve.xImage, delete ve.whatsappImage, ye && (ve.socialImages = ye), Object.assign(A, ve), A.id = y.id, A.slug = y.slug, A.title = y.title, A.path = k, A.layoutId = _e;
|
|
27580
|
+
let be = Number(y.isHidden) === 1 || ue, xe = !hC(ce, le), Se = y.status === "draft" || y.status === "new", Ce = y.dataJson && y.dataJson !== "{}" && y.dataJson !== "null";
|
|
27252
27581
|
if (!s && (be || xe || Se && !Ce)) return e.json({ error: "Node is hidden, offline, or has never been published." }, 404);
|
|
27253
27582
|
let we = [];
|
|
27254
27583
|
if (S?.treeNodeId) {
|
|
27255
|
-
let e = await t.prepare("SELECT t.contentId as treeNodeId, t.contentId as id, c.title, c.slug, c.language, c.contentType as nodeType, c.isHidden, c.dataJson, c.draftDataJson FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.parentId = ? AND t.treeId = ? ORDER BY t.sortOrder ASC").all(S.treeNodeId, b), n = Array.isArray(e) ? e : e?.results || [], i = A.path || "", a = i === "/" ? "" : i;
|
|
27584
|
+
let e = await t.prepare("SELECT t.contentId as treeNodeId, t.contentId as id, c.title, c.slug, c.language, c.contentType as nodeType, c.isHidden, c.status, c.startShowingAt, c.stopShowingAt, c.dataJson, c.draftDataJson, c.deletedAt FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.parentId = ? AND t.treeId = ? AND (c.deletedAt IS NULL OR c.deletedAt = '') ORDER BY t.sortOrder ASC").all(S.treeNodeId, b), n = Array.isArray(e) ? e : e?.results || [], i = A.path || "", a = i === "/" ? "" : i;
|
|
27256
27585
|
we = n.map((e) => {
|
|
27257
27586
|
let t = {}, n = s && e.draftDataJson || e.dataJson;
|
|
27258
27587
|
if (!n) return null;
|
|
27259
27588
|
try {
|
|
27260
27589
|
t = (typeof n == "string" ? JSON.parse(n) : n) || {};
|
|
27261
27590
|
} catch {}
|
|
27262
|
-
let i = Number(e.isHidden) === 1 ||
|
|
27263
|
-
|
|
27591
|
+
let i = Number(e.isHidden) === 1 || [
|
|
27592
|
+
t.hidden,
|
|
27593
|
+
t.is_hidden,
|
|
27594
|
+
t.isHidden
|
|
27595
|
+
].some((e) => e === !0 || e === 1 || e === "1" || e === "true"), o = hC(t.startShowingAt || e.startShowingAt, t.stopShowingAt || e.stopShowingAt), c = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
27596
|
+
return mC(t.startShowingAt, t.stopShowingAt, r), !s && (i || !o || e.status === "draft" || e.status === "new") ? null : {
|
|
27264
27597
|
treeNodeId: e.treeNodeId,
|
|
27265
27598
|
id: e.id,
|
|
27266
27599
|
title: e.title,
|
|
27267
27600
|
slug: c,
|
|
27268
|
-
language: e.language?.trim() ||
|
|
27601
|
+
language: e.language?.trim() || ne || null,
|
|
27269
27602
|
path: `${a}/${c}`.replace(/\/+/g, "/"),
|
|
27270
27603
|
nodeType: e.nodeType
|
|
27271
27604
|
};
|
|
@@ -27286,14 +27619,15 @@ async function NS(e) {
|
|
|
27286
27619
|
try {
|
|
27287
27620
|
a = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
27288
27621
|
} catch {}
|
|
27289
|
-
|
|
27290
|
-
let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", c =
|
|
27622
|
+
mC(a.startShowingAt, a.stopShowingAt, r);
|
|
27623
|
+
let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", c = hC(a.startShowingAt, a.stopShowingAt);
|
|
27291
27624
|
if (!s && (o || !c)) return null;
|
|
27292
|
-
let l = e.elementType || e.componentId || "text-block", u = j.blocks?.[l]?.fields || j.elements?.[l]?.fields || j.components?.[l]?.fields || {}, d = String(a.blockId || a._instanceId || a.id || e.blockId || e.id), f =
|
|
27293
|
-
return f = await
|
|
27625
|
+
let l = e.elementType || e.componentId || "text-block", u = j.blocks?.[l]?.fields || j.elements?.[l]?.fields || j.components?.[l]?.fields || {}, d = String(a.blockId || a._instanceId || a.id || e.blockId || e.id), f = vC(a, u);
|
|
27626
|
+
return f = await mS(t, f), f = yC(f), f = await bC(t, f, g, n), f.blockId = d, {
|
|
27294
27627
|
region: i,
|
|
27295
27628
|
block: {
|
|
27296
27629
|
instanceId: e.id,
|
|
27630
|
+
contentId: e.contentId || y.id,
|
|
27297
27631
|
blockId: d,
|
|
27298
27632
|
componentId: l,
|
|
27299
27633
|
data: f
|
|
@@ -27314,8 +27648,8 @@ async function NS(e) {
|
|
|
27314
27648
|
};
|
|
27315
27649
|
for (let [e, i] of Object.entries(ke)) {
|
|
27316
27650
|
let a = Ee[e] && Ee[e].length > 0, o = !!se[e];
|
|
27317
|
-
if (Ee[e] || (Ee[e] = [], De[e] = { isInherited: !1 }), (i?.inherit === "parent" || i?.inherit === !0 || i?.inherit === "true" || e === "header" || e === "footer") && !a && !o &&
|
|
27318
|
-
let i = await
|
|
27651
|
+
if (Ee[e] || (Ee[e] = [], De[e] = { isInherited: !1 }), (i?.inherit === "parent" || i?.inherit === !0 || i?.inherit === "true" || e === "header" || e === "footer") && !a && !o && re) {
|
|
27652
|
+
let i = await _C(t, re, b, e, j, g, s, n, r);
|
|
27319
27653
|
if (i.blocks.length > 0 && (Ee[e] = i.blocks, De[e] = {
|
|
27320
27654
|
isInherited: !0,
|
|
27321
27655
|
inheritedFromId: i.inheritedFromId,
|
|
@@ -27327,7 +27661,7 @@ async function NS(e) {
|
|
|
27327
27661
|
});
|
|
27328
27662
|
}
|
|
27329
27663
|
}
|
|
27330
|
-
await Promise.all(Object.keys(Ee).map((e) =>
|
|
27664
|
+
await Promise.all(Object.keys(Ee).map((e) => gC(t, Ee[e], g, ne, r, j)));
|
|
27331
27665
|
let Ae = null, je = null;
|
|
27332
27666
|
if (r.length > 0) {
|
|
27333
27667
|
je = Math.min(...r);
|
|
@@ -27337,7 +27671,7 @@ async function NS(e) {
|
|
|
27337
27671
|
let Me = {
|
|
27338
27672
|
channelId: g || _,
|
|
27339
27673
|
treeId: b,
|
|
27340
|
-
language:
|
|
27674
|
+
language: ne,
|
|
27341
27675
|
meta: {
|
|
27342
27676
|
cacheTtl: Ae,
|
|
27343
27677
|
nextEventTimestamp: je
|
|
@@ -27346,10 +27680,10 @@ async function NS(e) {
|
|
|
27346
27680
|
content: Ee,
|
|
27347
27681
|
regionMeta: De
|
|
27348
27682
|
};
|
|
27349
|
-
if (!s && !
|
|
27683
|
+
if (!s && !E) {
|
|
27350
27684
|
e.header("X-Cache", "MISS");
|
|
27351
|
-
let t = Ae === null ?
|
|
27352
|
-
e.header("Cache-Control", `public, max-age=${t}, s-maxage=${t}`), await
|
|
27685
|
+
let t = Ae === null ? O : Ae;
|
|
27686
|
+
e.header("Cache-Control", `public, max-age=${t}, s-maxage=${t}`), await EC(D, T, Me, t);
|
|
27353
27687
|
} else e.header("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
27354
27688
|
return e.json(Me, 200);
|
|
27355
27689
|
} catch (t) {
|
|
@@ -27359,17 +27693,17 @@ async function NS(e) {
|
|
|
27359
27693
|
}, 500);
|
|
27360
27694
|
}
|
|
27361
27695
|
}
|
|
27362
|
-
var
|
|
27696
|
+
var OC = X({
|
|
27363
27697
|
channelId: J().optional().openapi({ description: "The ID or key of the channel" }),
|
|
27364
27698
|
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
27365
27699
|
lang: J().optional().openapi({ description: "Requested language code" }),
|
|
27366
27700
|
preview: _v(["true", "false"]).optional().openapi({ description: "Request unpublished draft data" }),
|
|
27367
27701
|
revisionId: J().optional().openapi({ description: "Historical revision version to load" }),
|
|
27368
27702
|
treeId: J().optional().openapi({ description: "The ID of the tree to resolve paths against" })
|
|
27369
|
-
}),
|
|
27703
|
+
}), kC = X({
|
|
27370
27704
|
error: J(),
|
|
27371
27705
|
details: J().optional()
|
|
27372
|
-
}).openapi("ErrorResponse"),
|
|
27706
|
+
}).openapi("ErrorResponse"), AC = X({
|
|
27373
27707
|
channelId: $_([J(), g_()]),
|
|
27374
27708
|
treeId: J().nullable(),
|
|
27375
27709
|
language: J().nullable(),
|
|
@@ -27384,32 +27718,32 @@ var PS = X({
|
|
|
27384
27718
|
inheritedFromId: J().optional(),
|
|
27385
27719
|
inheritedFromTitle: J().optional()
|
|
27386
27720
|
}))
|
|
27387
|
-
}).openapi("NodeResponse"),
|
|
27721
|
+
}).openapi("NodeResponse"), jC = cb({
|
|
27388
27722
|
method: "get",
|
|
27389
27723
|
path: "/{path}",
|
|
27390
27724
|
summary: "Fetch CMS Node Content",
|
|
27391
27725
|
tags: ["Public Node API"],
|
|
27392
27726
|
request: {
|
|
27393
27727
|
params: X({ path: J().optional() }),
|
|
27394
|
-
query:
|
|
27728
|
+
query: OC
|
|
27395
27729
|
},
|
|
27396
27730
|
responses: {
|
|
27397
27731
|
200: {
|
|
27398
27732
|
description: "Fully hydrated CMS Node",
|
|
27399
|
-
content: { "application/json": { schema:
|
|
27733
|
+
content: { "application/json": { schema: AC } }
|
|
27400
27734
|
},
|
|
27401
27735
|
404: {
|
|
27402
27736
|
description: "Not found",
|
|
27403
|
-
content: { "application/json": { schema:
|
|
27737
|
+
content: { "application/json": { schema: kC } }
|
|
27404
27738
|
},
|
|
27405
27739
|
500: {
|
|
27406
27740
|
description: "Server error",
|
|
27407
|
-
content: { "application/json": { schema:
|
|
27741
|
+
content: { "application/json": { schema: kC } }
|
|
27408
27742
|
}
|
|
27409
27743
|
}
|
|
27410
27744
|
});
|
|
27411
|
-
|
|
27412
|
-
var
|
|
27745
|
+
fC.openapi(jC, DC), fC.get("*", DC);
|
|
27746
|
+
var MC = new sb(), NC = X({
|
|
27413
27747
|
nodeType: J().default("article").openapi({ description: "Content types (comma separated)" }),
|
|
27414
27748
|
channelId: J().optional().openapi({ description: "Channel ID or key" }),
|
|
27415
27749
|
limit: eb().min(1).max(50).default(12).openapi({ description: "Number of items (max 50)" }),
|
|
@@ -27418,44 +27752,66 @@ var RS = new sb(), zS = X({
|
|
|
27418
27752
|
authors: $_([J(), q_(J())]).optional(),
|
|
27419
27753
|
categories: $_([J(), q_(J())]).optional(),
|
|
27420
27754
|
tags: $_([J(), q_(J())]).optional()
|
|
27421
|
-
}),
|
|
27755
|
+
}), PC = async (e) => {
|
|
27422
27756
|
try {
|
|
27423
|
-
let t = e.get("db"), n = e.req.valid("query"), r =
|
|
27424
|
-
|
|
27425
|
-
|
|
27426
|
-
|
|
27757
|
+
let t = e.get("db"), n = e.req.valid("query"), r = null;
|
|
27758
|
+
if (n.channelId && n.channelId !== "all") {
|
|
27759
|
+
let i = isNaN(Number(n.channelId)) ? await t.prepare("SELECT id, isHidden FROM channels WHERE key = ?").get(n.channelId) : await t.prepare("SELECT id, isHidden FROM channels WHERE id = ?").get(Number(n.channelId));
|
|
27760
|
+
if (!i || Number(i.isHidden) === 1) return e.json({
|
|
27761
|
+
items: [],
|
|
27762
|
+
count: 0,
|
|
27763
|
+
rawCount: 0,
|
|
27764
|
+
limit: n.limit,
|
|
27765
|
+
offset: n.offset
|
|
27766
|
+
}, 200);
|
|
27767
|
+
r = Number(i.id);
|
|
27768
|
+
}
|
|
27769
|
+
let i = n.nodeType || "article", a = String(i).split(",").map((e) => e.trim()).filter(Boolean), o = a.map(() => "?").join(","), s = hS(e.env?.BUNDLED_DEFINITIONS), c = {};
|
|
27770
|
+
for (let e of a) {
|
|
27771
|
+
c[e] = [];
|
|
27772
|
+
let t = s.nodes?.[e] || {}, n = { ...t.fields || {} };
|
|
27427
27773
|
t.tabs && Object.values(t.tabs).forEach((e) => {
|
|
27428
27774
|
Object.assign(n, e.fields || {});
|
|
27429
27775
|
});
|
|
27430
|
-
for (let [t, r] of Object.entries(n)) (r.showInList || r.showInLists) &&
|
|
27431
|
-
}
|
|
27432
|
-
let
|
|
27433
|
-
|
|
27434
|
-
|
|
27435
|
-
|
|
27436
|
-
|
|
27776
|
+
for (let [t, r] of Object.entries(n)) (r.showInList || r.showInLists) && c[e].push(t);
|
|
27777
|
+
}
|
|
27778
|
+
let l = `FROM content_nodes
|
|
27779
|
+
WHERE contentType IN (${o})
|
|
27780
|
+
AND COALESCE(isHidden, 0) = 0
|
|
27781
|
+
AND IFNULL(status, 'published') = 'published'
|
|
27782
|
+
AND (deletedAt IS NULL OR deletedAt = '')
|
|
27783
|
+
AND LOWER(CAST(COALESCE(
|
|
27784
|
+
CASE WHEN json_valid(dataJson) THEN json_extract(dataJson, '$.hidden') END,
|
|
27785
|
+
CASE WHEN json_valid(dataJson) THEN json_extract(dataJson, '$.is_hidden') END,
|
|
27786
|
+
CASE WHEN json_valid(dataJson) THEN json_extract(dataJson, '$.isHidden') END,
|
|
27787
|
+
0
|
|
27788
|
+
) AS TEXT)) NOT IN ('1', 'true')`, u = [...a];
|
|
27789
|
+
r !== null && (l += " AND EXISTS (SELECT 1 FROM node_channels nc WHERE nc.nodeId = content_nodes.id AND nc.channelId = ?)", u.push(r));
|
|
27790
|
+
let d = (/* @__PURE__ */ new Date()).toISOString();
|
|
27791
|
+
l += " AND COALESCE(NULLIF(CASE WHEN json_valid(dataJson) THEN json_extract(dataJson, '$.startShowingAt') END, ''), startShowingAt, '') <= ?", u.push(d), l += " AND COALESCE(NULLIF(CASE WHEN json_valid(dataJson) THEN json_extract(dataJson, '$.stopShowingAt') END, ''), stopShowingAt, '9999-12-31') >= ?", u.push(d);
|
|
27792
|
+
let f = (e, t, n = !1) => {
|
|
27437
27793
|
let r = Array.isArray(t) ? t : t.split(",").map((e) => e.trim());
|
|
27438
27794
|
if (r.length === 0) return;
|
|
27439
27795
|
let i = r.map(() => "?").join(",");
|
|
27440
|
-
n ? (
|
|
27796
|
+
n ? (l += ` AND EXISTS (SELECT 1 FROM node_relations nr WHERE nr.sourceNodeId = content_nodes.id AND nr.fieldKey = ? AND nr.targetNodeId IN (${i}))`, u.push(e, ...r)) : (l += ` AND EXISTS (SELECT 1 FROM node_terms nt INNER JOIN taxonomy_terms tt ON nt.termId = tt.id WHERE nt.nodeId = content_nodes.id AND tt.taxonomy = ? AND tt.key IN (${i}))`, u.push(e, ...r));
|
|
27441
27797
|
};
|
|
27442
|
-
n.authors &&
|
|
27443
|
-
let
|
|
27444
|
-
|
|
27445
|
-
let
|
|
27446
|
-
|
|
27447
|
-
let
|
|
27448
|
-
if (
|
|
27449
|
-
let e =
|
|
27798
|
+
n.authors && f("authors", n.authors, !0), n.categories && f("categories", n.categories, !1), n.tags && f("tags", n.tags, !1);
|
|
27799
|
+
let p = String(n.sortBy || "updatedAt_desc"), [m, h] = p.includes("_") ? p.split("_") : [p, "desc"], g = String(h).toLowerCase() === "asc" ? "ASC" : "DESC", _ = String(m).replace(/[^a-zA-Z0-9_]/g, ""), v = `ORDER BY updatedAt ${g}`;
|
|
27800
|
+
_ === "createdAt" || _ === "published" ? v = `ORDER BY createdAt ${g}` : _ === "title" ? v = `ORDER BY LOWER(title) ${g}` : _ !== "updatedAt" && _ !== "" && (v = `ORDER BY json_extract(dataJson, '$.${_}') ${g}`);
|
|
27801
|
+
let y = `SELECT id, title, slug, language, contentType, dataJson, createdAt, updatedAt ${l} ${v} LIMIT ? OFFSET ?`;
|
|
27802
|
+
u.push(n.limit, n.offset);
|
|
27803
|
+
let b = await t.prepare(y).all(...u), x = Array.isArray(b) ? b : b?.results || [], S = x.map((e) => e.id), C = {};
|
|
27804
|
+
if (S.length > 0) {
|
|
27805
|
+
let e = S.map(() => "?").join(",");
|
|
27450
27806
|
try {
|
|
27451
27807
|
let n = await t.prepare(`
|
|
27452
27808
|
SELECT nt.nodeId, tt.taxonomy, tt.key, tt.label
|
|
27453
27809
|
FROM node_terms nt
|
|
27454
27810
|
INNER JOIN taxonomy_terms tt ON nt.termId = tt.id
|
|
27455
27811
|
WHERE nt.nodeId IN (${e})
|
|
27456
|
-
`).all(...
|
|
27812
|
+
`).all(...S);
|
|
27457
27813
|
(Array.isArray(n) ? n : n?.results || []).forEach((e) => {
|
|
27458
|
-
|
|
27814
|
+
C[e.nodeId] || (C[e.nodeId] = {}), C[e.nodeId][e.taxonomy] || (C[e.nodeId][e.taxonomy] = []), C[e.nodeId][e.taxonomy].push({
|
|
27459
27815
|
key: e.key,
|
|
27460
27816
|
label: e.label
|
|
27461
27817
|
});
|
|
@@ -27464,14 +27820,14 @@ var RS = new sb(), zS = X({
|
|
|
27464
27820
|
console.warn("[CMS API] Failed to batch hydrate taxonomies:", e);
|
|
27465
27821
|
}
|
|
27466
27822
|
}
|
|
27467
|
-
let
|
|
27823
|
+
let ee = x.map((e) => {
|
|
27468
27824
|
let t = {};
|
|
27469
27825
|
try {
|
|
27470
27826
|
t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson || {};
|
|
27471
27827
|
} catch {}
|
|
27472
|
-
let n = {}, r =
|
|
27828
|
+
let n = {}, r = c[e.contentType || "article"] || [];
|
|
27473
27829
|
for (let e of r) t[e] !== void 0 && (n[e] = t[e]);
|
|
27474
|
-
if (
|
|
27830
|
+
if (C[e.id]) for (let [t, r] of Object.entries(C[e.id])) n[t] = r;
|
|
27475
27831
|
return {
|
|
27476
27832
|
id: e.id,
|
|
27477
27833
|
title: e.title,
|
|
@@ -27486,21 +27842,21 @@ var RS = new sb(), zS = X({
|
|
|
27486
27842
|
};
|
|
27487
27843
|
});
|
|
27488
27844
|
return e.json({
|
|
27489
|
-
items:
|
|
27490
|
-
count:
|
|
27491
|
-
rawCount:
|
|
27845
|
+
items: ee,
|
|
27846
|
+
count: ee.length,
|
|
27847
|
+
rawCount: x.length,
|
|
27492
27848
|
limit: n.limit,
|
|
27493
27849
|
offset: n.offset
|
|
27494
27850
|
}, 200);
|
|
27495
27851
|
} catch (t) {
|
|
27496
27852
|
return console.error("[CMS API] Error fetching nodes list:", t), e.json({ error: "Failed to fetch nodes list" }, 500);
|
|
27497
27853
|
}
|
|
27498
|
-
},
|
|
27854
|
+
}, FC = cb({
|
|
27499
27855
|
method: "get",
|
|
27500
27856
|
path: "/",
|
|
27501
27857
|
summary: "Fetch filtered list of nodes",
|
|
27502
27858
|
tags: ["Public Node API"],
|
|
27503
|
-
request: { query:
|
|
27859
|
+
request: { query: NC },
|
|
27504
27860
|
responses: {
|
|
27505
27861
|
200: {
|
|
27506
27862
|
description: "List of nodes",
|
|
@@ -27509,9 +27865,9 @@ var RS = new sb(), zS = X({
|
|
|
27509
27865
|
500: { description: "Server error" }
|
|
27510
27866
|
}
|
|
27511
27867
|
});
|
|
27512
|
-
|
|
27513
|
-
var
|
|
27514
|
-
function
|
|
27868
|
+
MC.openapi(FC, PC);
|
|
27869
|
+
var IC = new sb();
|
|
27870
|
+
function LC(e, t) {
|
|
27515
27871
|
let n = /* @__PURE__ */ new Date();
|
|
27516
27872
|
if (e && String(e).trim() !== "") {
|
|
27517
27873
|
let t = new Date(e);
|
|
@@ -27523,22 +27879,22 @@ function US(e, t) {
|
|
|
27523
27879
|
}
|
|
27524
27880
|
return !0;
|
|
27525
27881
|
}
|
|
27526
|
-
async function
|
|
27882
|
+
async function RC(e, t, n, r) {
|
|
27527
27883
|
try {
|
|
27528
27884
|
await e.set(t, n, r);
|
|
27529
27885
|
} catch (e) {
|
|
27530
27886
|
console.warn("[CMS Cache] Failed to write tree response to cache:", e);
|
|
27531
27887
|
}
|
|
27532
27888
|
}
|
|
27533
|
-
var
|
|
27889
|
+
var zC = X({ treeParam: J().openapi({ description: "The ID or key of the requested tree (e.g., \"main-nav\")" }) }), BC = X({
|
|
27534
27890
|
channelId: J().optional().openapi({ description: "Channel ID to resolve context-aware routing" }),
|
|
27535
27891
|
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
27536
27892
|
lang: J().optional().openapi({ description: "Requested language code for tree nodes" }),
|
|
27537
27893
|
preview: _v(["true", "false"]).optional().openapi({ description: "Set to true to retrieve unpublished draft data" })
|
|
27538
|
-
}),
|
|
27894
|
+
}), VC = X({
|
|
27539
27895
|
error: J(),
|
|
27540
27896
|
details: J().optional()
|
|
27541
|
-
}).openapi("ErrorResponse"),
|
|
27897
|
+
}).openapi("ErrorResponse"), HC = ty(() => X({
|
|
27542
27898
|
id: $_([J(), g_()]),
|
|
27543
27899
|
treeNodeId: $_([J(), g_()]),
|
|
27544
27900
|
parentId: $_([J(), g_()]).nullable(),
|
|
@@ -27551,49 +27907,49 @@ var GS = X({ treeParam: J().openapi({ description: "The ID or key of the request
|
|
|
27551
27907
|
summary: J().optional(),
|
|
27552
27908
|
url: J().optional(),
|
|
27553
27909
|
target: J().optional(),
|
|
27554
|
-
children: q_(
|
|
27555
|
-
}).passthrough()).openapi("TreeItem"),
|
|
27910
|
+
children: q_(HC).optional()
|
|
27911
|
+
}).passthrough()).openapi("TreeItem"), UC = X({
|
|
27556
27912
|
treeId: $_([g_(), J()]),
|
|
27557
27913
|
key: J(),
|
|
27558
27914
|
channelId: J(),
|
|
27559
27915
|
language: J().nullable(),
|
|
27560
27916
|
label: J(),
|
|
27561
|
-
items: q_(
|
|
27562
|
-
}).catchall(L_()).openapi("TreeResponse"),
|
|
27917
|
+
items: q_(HC)
|
|
27918
|
+
}).catchall(L_()).openapi("TreeResponse"), WC = cb({
|
|
27563
27919
|
method: "get",
|
|
27564
27920
|
path: "/{treeParam}",
|
|
27565
27921
|
summary: "Fetch CMS Navigation Tree",
|
|
27566
27922
|
description: "Retrieves a fully hydrated, recursive navigation tree structure. Uses $O(1)$ pre-computed routing table paths.",
|
|
27567
27923
|
tags: ["Public Tree API"],
|
|
27568
27924
|
request: {
|
|
27569
|
-
params:
|
|
27570
|
-
query:
|
|
27925
|
+
params: zC,
|
|
27926
|
+
query: BC
|
|
27571
27927
|
},
|
|
27572
27928
|
responses: {
|
|
27573
27929
|
200: {
|
|
27574
27930
|
description: "Fully hydrated CMS Tree payload",
|
|
27575
|
-
content: { "application/json": { schema:
|
|
27931
|
+
content: { "application/json": { schema: UC } }
|
|
27576
27932
|
},
|
|
27577
27933
|
404: {
|
|
27578
27934
|
description: "Tree or Channel not found / inactive",
|
|
27579
|
-
content: { "application/json": { schema:
|
|
27935
|
+
content: { "application/json": { schema: VC } }
|
|
27580
27936
|
},
|
|
27581
27937
|
500: {
|
|
27582
27938
|
description: "Server error during hydration",
|
|
27583
|
-
content: { "application/json": { schema:
|
|
27939
|
+
content: { "application/json": { schema: VC } }
|
|
27584
27940
|
}
|
|
27585
27941
|
}
|
|
27586
27942
|
});
|
|
27587
|
-
|
|
27943
|
+
IC.openapi(WC, async (e) => {
|
|
27588
27944
|
try {
|
|
27589
27945
|
let t = e.get("db"), { treeParam: n } = e.req.valid("param"), r = e.req.valid("query"), i = r.channelId || r.channel || "default", a = r.lang, o = r.preview === "true", s = null, c = -1;
|
|
27590
|
-
if (i && i !== "
|
|
27946
|
+
if (i && i !== "all") {
|
|
27591
27947
|
let n = isNaN(Number(i)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(i) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(i));
|
|
27592
27948
|
if (n) {
|
|
27593
27949
|
c = Number(n.id), n.defaultLanguage && (s = n.defaultLanguage.trim());
|
|
27594
27950
|
let t = n.status === "disabled" || n.status === "inactive" || n.isEnabled === 0 || n.isEnabled === !1;
|
|
27595
|
-
if (!o && t) return e.json({ error: `Channel '${n.key || i}' is currently
|
|
27596
|
-
}
|
|
27951
|
+
if (!o && (t || Number(n.isHidden) === 1)) return e.json({ error: `Channel '${n.key || i}' is currently unavailable` }, 404);
|
|
27952
|
+
} else if (i !== "default") return e.json({ error: `Channel '${i}' not found` }, 404);
|
|
27597
27953
|
}
|
|
27598
27954
|
let l = !isNaN(Number(n)), u = l ? await t.prepare("SELECT * FROM trees WHERE id = ?").get(Number(n)) : await t.prepare("SELECT * FROM trees WHERE key = ?").get(n);
|
|
27599
27955
|
if (u && Number(u.isHidden) === 1 && !o) return e.json({ error: `Tree '${n}' is hidden` }, 404);
|
|
@@ -27605,12 +27961,12 @@ HS.openapi(XS, async (e) => {
|
|
|
27605
27961
|
e.defaultLanguage && (d = String(e.defaultLanguage).trim());
|
|
27606
27962
|
} catch {}
|
|
27607
27963
|
}
|
|
27608
|
-
let f = d || s || a?.trim() || null, p =
|
|
27964
|
+
let f = d || s || a?.trim() || null, p = tS(e), m = `tree:${i}:${n}:${f || "default"}`, h = e.req.header("x-bypass-cache") === "true";
|
|
27609
27965
|
if (!o && !h) {
|
|
27610
27966
|
let t = await p.get(m);
|
|
27611
27967
|
if (t) return e.header("X-Cache", "HIT"), e.json(t, 200);
|
|
27612
27968
|
}
|
|
27613
|
-
let g = u?.id || (l ? Number(n) : null), _ = e.env?.BUNDLED_DEFINITIONS, v =
|
|
27969
|
+
let g = u?.id || (l ? Number(n) : null), _ = e.env?.BUNDLED_DEFINITIONS, v = hS(_), y = v.treeExposedFields || ["summary"], b = {};
|
|
27614
27970
|
if (u && u.dataJson) try {
|
|
27615
27971
|
let e = typeof u.dataJson == "string" ? JSON.parse(u.dataJson) : u.dataJson, t = (v.trees?.[u.treeType || n] || v.trees?.site || {}).fields || {};
|
|
27616
27972
|
for (let [n, r] of Object.entries(e)) t[n]?.public === !0 && (b[n] = r);
|
|
@@ -27642,12 +27998,16 @@ HS.openapi(XS, async (e) => {
|
|
|
27642
27998
|
C.set(t, {});
|
|
27643
27999
|
}
|
|
27644
28000
|
}
|
|
27645
|
-
function
|
|
28001
|
+
function ee(e = null, t = "") {
|
|
27646
28002
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e);
|
|
27647
28003
|
return (S.get(n) || []).map((e) => {
|
|
27648
28004
|
let n = C.get(String(e.id)) || {}, r = {};
|
|
27649
28005
|
for (let [e, t] of Object.entries(n)) e !== "_isTreeDraft" && e !== "_draftParentId" && e !== "isNew" && e !== "hidden" && e !== "is_hidden" && e !== "isHidden" && e !== "status" && (r[e] = t);
|
|
27650
|
-
let i = !o && (e.status === "draft" || e.status === "new"), a = Number(e.isHidden) === 1 || i ||
|
|
28006
|
+
let i = !o && (e.status === "draft" || e.status === "new"), a = Number(e.isHidden) === 1 || i || [
|
|
28007
|
+
n.hidden,
|
|
28008
|
+
n.is_hidden,
|
|
28009
|
+
n.isHidden
|
|
28010
|
+
].some((e) => e === !0 || e === 1 || e === "1" || e === "true"), s = LC(n.startShowingAt || e.startShowingAt, n.stopShowingAt || e.stopShowingAt), c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = !e.parentId || e.parentId === "null" || e.parentId === "", u = e.materializedPath || (l ? `/${c}` : `${t}/${c}`.replace(/\/+/g, "/")), d = e.language && String(e.language).trim() !== "" ? e.language.trim() : f, p = {
|
|
27651
28011
|
id: e.id,
|
|
27652
28012
|
treeNodeId: e.id,
|
|
27653
28013
|
parentId: e.parentId || null,
|
|
@@ -27661,19 +28021,19 @@ HS.openapi(XS, async (e) => {
|
|
|
27661
28021
|
for (let e of y) r[e] !== void 0 && (p[e] = r[e]);
|
|
27662
28022
|
e.nodeType === "external-link" && (r.url && (p.url = r.url), r.target && (p.target = r.target));
|
|
27663
28023
|
let m = u === "/" ? "" : u;
|
|
27664
|
-
return p.children =
|
|
28024
|
+
return p.children = ee(e.id, m), p;
|
|
27665
28025
|
}).filter((e) => o || !e.hidden);
|
|
27666
28026
|
}
|
|
27667
|
-
let
|
|
28027
|
+
let w = {
|
|
27668
28028
|
treeId: u?.id || g,
|
|
27669
28029
|
key: u?.key || n,
|
|
27670
28030
|
channelId: String(i),
|
|
27671
28031
|
language: f,
|
|
27672
28032
|
label: u?.label || n,
|
|
27673
28033
|
...b,
|
|
27674
|
-
items:
|
|
28034
|
+
items: ee(null)
|
|
27675
28035
|
};
|
|
27676
|
-
return !o && !h && (e.header("X-Cache", "MISS"), await
|
|
28036
|
+
return !o && !h && (e.header("X-Cache", "MISS"), await RC(p, m, w, 300)), e.json(w, 200);
|
|
27677
28037
|
} catch (t) {
|
|
27678
28038
|
return console.error("[CMS Public Tree API] Error:", t), e.json({
|
|
27679
28039
|
error: "Failed to fetch public tree",
|
|
@@ -27681,19 +28041,19 @@ HS.openapi(XS, async (e) => {
|
|
|
27681
28041
|
}, 500);
|
|
27682
28042
|
}
|
|
27683
28043
|
});
|
|
27684
|
-
var
|
|
27685
|
-
function
|
|
28044
|
+
var GC = new sb();
|
|
28045
|
+
function KC(e) {
|
|
27686
28046
|
let t = Number(e?.env?.CMS_CHANNEL_CACHE_TTL);
|
|
27687
28047
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
27688
28048
|
}
|
|
27689
|
-
async function
|
|
28049
|
+
async function qC(e, t, n, r) {
|
|
27690
28050
|
try {
|
|
27691
28051
|
await e.set(t, n, r);
|
|
27692
28052
|
} catch (e) {
|
|
27693
28053
|
console.warn("[CMS Cache] Failed to write channel response to cache:", e);
|
|
27694
28054
|
}
|
|
27695
28055
|
}
|
|
27696
|
-
function
|
|
28056
|
+
function JC(e, t) {
|
|
27697
28057
|
let n = {}, r = (e) => {
|
|
27698
28058
|
if (!e || typeof e != "string") return;
|
|
27699
28059
|
let n = t?.fieldSets?.[e] || t?.fieldsets?.[e] || t?.definitions?.[e] || t?.channels?.[e] || t?.[e];
|
|
@@ -27704,7 +28064,7 @@ function eC(e, t) {
|
|
|
27704
28064
|
if (e?.fieldSets && Array.isArray(e.fieldSets) && e.fieldSets.forEach((e) => r(e)), e?.fields && i(e.fields), e?.tabs && typeof e.tabs == "object") for (let t of Object.values(e.tabs)) t?.fields && i(t.fields);
|
|
27705
28065
|
return n;
|
|
27706
28066
|
}
|
|
27707
|
-
function
|
|
28067
|
+
function YC(e, t = {}) {
|
|
27708
28068
|
let n = {}, r = Object.keys(t).length > 0;
|
|
27709
28069
|
for (let [i, a] of Object.entries(e)) {
|
|
27710
28070
|
if (i.endsWith("_meta") || [
|
|
@@ -27723,14 +28083,14 @@ function tC(e, t = {}) {
|
|
|
27723
28083
|
}
|
|
27724
28084
|
return n;
|
|
27725
28085
|
}
|
|
27726
|
-
function
|
|
27727
|
-
if (Array.isArray(e)) return e.map(
|
|
28086
|
+
function XC(e) {
|
|
28087
|
+
if (Array.isArray(e)) return e.map(XC);
|
|
27728
28088
|
if (!e || typeof e != "object") return e;
|
|
27729
28089
|
if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
|
|
27730
28090
|
let t = e.metadataOverrides || {}, n = e.variants && typeof e.variants == "object" ? e.variants : {}, r = Object.entries(n).find(([, t]) => t?.id === e.id)?.[0], i = r ? {
|
|
27731
28091
|
...t,
|
|
27732
28092
|
...t.crops?.[r] || {}
|
|
27733
|
-
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t,
|
|
28093
|
+
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, XC({
|
|
27734
28094
|
...n,
|
|
27735
28095
|
title: n?.title ?? e.title ?? "",
|
|
27736
28096
|
alt: n?.alt ?? e.alt ?? "",
|
|
@@ -27744,9 +28104,9 @@ function nC(e) {
|
|
|
27744
28104
|
...Object.keys(a).length > 0 ? { variants: a } : {}
|
|
27745
28105
|
};
|
|
27746
28106
|
}
|
|
27747
|
-
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e,
|
|
28107
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, XC(t)]));
|
|
27748
28108
|
}
|
|
27749
|
-
async function
|
|
28109
|
+
async function ZC(e, t, n) {
|
|
27750
28110
|
let r = t.href.match(/^#node:(.+)$/), i = t.href.match(/^#asset:(.+)$/);
|
|
27751
28111
|
if (i) {
|
|
27752
28112
|
let t = i[1], n = await e.prepare("SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?").get(t);
|
|
@@ -27756,7 +28116,7 @@ async function rC(e, t, n) {
|
|
|
27756
28116
|
let a = r[1];
|
|
27757
28117
|
return (await e.prepare("SELECT path FROM node_routes WHERE nodeId = ? AND channelId = ? AND isCanonical = 1 LIMIT 1").get(Number(a), n))?.path || "#";
|
|
27758
28118
|
}
|
|
27759
|
-
async function
|
|
28119
|
+
async function QC(e, t, n) {
|
|
27760
28120
|
if (typeof t == "string") {
|
|
27761
28121
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
27762
28122
|
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
|
|
@@ -27789,79 +28149,78 @@ async function iC(e, t, n) {
|
|
|
27789
28149
|
return /href\s*=\s*["'][^"']*["']/i.test(d) ? d = d.replace(/href\s*=\s*["'][^"']*["']/i, `href="${u}"`) : d += ` href="${u}"`, `<a ${d}>`;
|
|
27790
28150
|
});
|
|
27791
28151
|
}
|
|
27792
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) =>
|
|
28152
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => QC(e, t, n)));
|
|
27793
28153
|
if (t && typeof t == "object") {
|
|
27794
28154
|
if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) {
|
|
27795
|
-
let r = await
|
|
28155
|
+
let r = await ZC(e, t, n), i = await Promise.all(Object.entries(t).filter(([e]) => e !== "href").map(async ([t, r]) => [t, await QC(e, r, n)]));
|
|
27796
28156
|
return {
|
|
27797
28157
|
...Object.fromEntries(i),
|
|
27798
28158
|
href: r
|
|
27799
28159
|
};
|
|
27800
28160
|
}
|
|
27801
|
-
let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await
|
|
28161
|
+
let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await QC(e, r, n)]));
|
|
27802
28162
|
return Object.fromEntries(r);
|
|
27803
28163
|
}
|
|
27804
28164
|
return t;
|
|
27805
28165
|
}
|
|
27806
|
-
var
|
|
28166
|
+
var $C = X({ channelParam: J().openapi({ description: "The ID or key (slug) of the requested channel" }) }), ew = X({ preview: _v(["true", "false"]).optional().openapi({ description: "Set to true to retrieve unpublished draft data" }) }), tw = X({
|
|
27807
28167
|
error: J(),
|
|
27808
28168
|
details: J().optional()
|
|
27809
|
-
}).openapi("ErrorResponse"),
|
|
28169
|
+
}).openapi("ErrorResponse"), nw = X({
|
|
27810
28170
|
id: $_([g_(), J()]),
|
|
27811
28171
|
key: J()
|
|
27812
|
-
}).catchall(L_()).openapi("ChannelResponse"),
|
|
28172
|
+
}).catchall(L_()).openapi("ChannelResponse"), rw = cb({
|
|
27813
28173
|
method: "get",
|
|
27814
28174
|
path: "/{channelParam}",
|
|
27815
28175
|
summary: "Fetch CMS Channel Settings",
|
|
27816
28176
|
description: "Retrieves the fully hydrated, public-facing settings and payload for a specific CMS channel.",
|
|
27817
28177
|
tags: ["Public Channel API"],
|
|
27818
28178
|
request: {
|
|
27819
|
-
params:
|
|
27820
|
-
query:
|
|
28179
|
+
params: $C,
|
|
28180
|
+
query: ew
|
|
27821
28181
|
},
|
|
27822
28182
|
responses: {
|
|
27823
28183
|
200: {
|
|
27824
28184
|
description: "Fully hydrated CMS Channel payload",
|
|
27825
|
-
content: { "application/json": { schema:
|
|
28185
|
+
content: { "application/json": { schema: nw } }
|
|
27826
28186
|
},
|
|
27827
28187
|
404: {
|
|
27828
28188
|
description: "Channel not found or inactive",
|
|
27829
|
-
content: { "application/json": { schema:
|
|
28189
|
+
content: { "application/json": { schema: tw } }
|
|
27830
28190
|
},
|
|
27831
28191
|
500: {
|
|
27832
28192
|
description: "Server error during hydration",
|
|
27833
|
-
content: { "application/json": { schema:
|
|
28193
|
+
content: { "application/json": { schema: tw } }
|
|
27834
28194
|
}
|
|
27835
28195
|
}
|
|
27836
28196
|
});
|
|
27837
|
-
|
|
28197
|
+
GC.openapi(rw, async (e) => {
|
|
27838
28198
|
try {
|
|
27839
|
-
let t = e.get("db"), { channelParam: n } = e.req.valid("param"), { preview: r } = e.req.valid("query"), i = r === "true", a = e.req.header("x-bypass-cache") === "true", o = `channel:${n}:${i ? "preview" : "live"}`, s =
|
|
28199
|
+
let t = e.get("db"), { channelParam: n } = e.req.valid("param"), { preview: r } = e.req.valid("query"), i = r === "true", a = e.req.header("x-bypass-cache") === "true", o = `channel:${n}:${i ? "preview" : "live"}`, s = tS(e), c = isNaN(Number(n)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(n) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(n));
|
|
28200
|
+
if (!c) return e.json({ error: `Channel '${n}' not found` }, 404);
|
|
28201
|
+
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
28202
|
+
if (!i && (l || Number(c.isHidden) === 1)) return e.json({ error: `Channel '${c.key || n}' is currently inactive` }, 404);
|
|
27840
28203
|
if (!i && !a) {
|
|
27841
28204
|
let t = await s.get(o);
|
|
27842
28205
|
if (t) return e.header("X-Cache", "HIT"), e.json(t, 200);
|
|
27843
28206
|
}
|
|
27844
|
-
let
|
|
27845
|
-
if (!c) return e.json({ error: `Channel '${n}' not found` }, 404);
|
|
27846
|
-
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
27847
|
-
if (!i && l) return e.json({ error: `Channel '${c.key || n}' is currently inactive` }, 404);
|
|
27848
|
-
let u = Number(c.id), d = e.env?.BUNDLED_DEFINITIONS, f = xx(d), p = c.channelType || c.key || "website", m = eC(f.channels?.[p] || f.channels?.[c.key] || f.channels?.website || f.definitions?.["channel-base"] || {}, f), h = {}, g = i && c.draftDataJson || c.dataJson;
|
|
28207
|
+
let u = Number(c.id), d = e.env?.BUNDLED_DEFINITIONS, f = hS(d), p = c.channelType || c.key || "website", m = JC(f.channels?.[p] || f.channels?.[c.key] || f.channels?.website || f.definitions?.["channel-base"] || {}, f), h = {}, g = i && c.draftDataJson || c.dataJson;
|
|
27849
28208
|
if (g) try {
|
|
27850
28209
|
h = typeof g == "string" ? JSON.parse(g) : g;
|
|
27851
28210
|
} catch (e) {
|
|
27852
28211
|
console.warn("[CMS Public Channel API] Failed to parse channel dataJson:", e);
|
|
27853
28212
|
}
|
|
27854
|
-
let _ =
|
|
28213
|
+
let _ = YC({
|
|
27855
28214
|
...h,
|
|
27856
28215
|
...c
|
|
27857
28216
|
}, m);
|
|
27858
|
-
_ = await
|
|
28217
|
+
_ = await mS(t, _), _ = XC(_), _ = await QC(t, _, u);
|
|
27859
28218
|
let v = {
|
|
27860
28219
|
id: c.id,
|
|
27861
28220
|
key: c.key,
|
|
27862
28221
|
..._
|
|
27863
28222
|
};
|
|
27864
|
-
return !i && !a && (e.header("X-Cache", "MISS"), await
|
|
28223
|
+
return !i && !a && (e.header("X-Cache", "MISS"), await qC(s, o, v, KC(e))), e.json(v, 200);
|
|
27865
28224
|
} catch (t) {
|
|
27866
28225
|
return console.error("[CMS Public Channel API] Error:", t), e.json({
|
|
27867
28226
|
error: "Failed to fetch public channel",
|
|
@@ -27869,8 +28228,8 @@ ZS.openapi(lC, async (e) => {
|
|
|
27869
28228
|
}, 500);
|
|
27870
28229
|
}
|
|
27871
28230
|
});
|
|
27872
|
-
var
|
|
27873
|
-
function
|
|
28231
|
+
var iw = new sb();
|
|
28232
|
+
function aw(e, t) {
|
|
27874
28233
|
if (t === "webp") return "image/webp";
|
|
27875
28234
|
if (t === "avif") return "image/avif";
|
|
27876
28235
|
if (t === "jpeg" || t === "jpg") return "image/jpeg";
|
|
@@ -27879,7 +28238,7 @@ function dC(e, t) {
|
|
|
27879
28238
|
let n = e.toLowerCase();
|
|
27880
28239
|
return n.endsWith(".jpg") || n.endsWith(".jpeg") ? "image/jpeg" : n.endsWith(".png") ? "image/png" : n.endsWith(".webp") ? "image/webp" : n.endsWith(".gif") ? "image/gif" : n.endsWith(".svg") ? "image/svg+xml" : n.endsWith(".pdf") ? "application/pdf" : n.endsWith(".mp4") ? "video/mp4" : "application/octet-stream";
|
|
27881
28240
|
}
|
|
27882
|
-
var
|
|
28241
|
+
var ow = [
|
|
27883
28242
|
320,
|
|
27884
28243
|
640,
|
|
27885
28244
|
768,
|
|
@@ -27889,10 +28248,10 @@ var fC = [
|
|
|
27889
28248
|
2560,
|
|
27890
28249
|
3840
|
|
27891
28250
|
];
|
|
27892
|
-
function
|
|
27893
|
-
if (!(!e || isNaN(e) || e <= 0)) return
|
|
28251
|
+
function sw(e) {
|
|
28252
|
+
if (!(!e || isNaN(e) || e <= 0)) return ow.reduce((t, n) => Math.abs(n - e) < Math.abs(t - e) ? n : t);
|
|
27894
28253
|
}
|
|
27895
|
-
var
|
|
28254
|
+
var cw = cb({
|
|
27896
28255
|
method: "get",
|
|
27897
28256
|
path: "/*",
|
|
27898
28257
|
summary: "Serve & Optimize Media Assets",
|
|
@@ -27952,54 +28311,56 @@ var mC = cb({
|
|
|
27952
28311
|
}
|
|
27953
28312
|
}
|
|
27954
28313
|
});
|
|
27955
|
-
|
|
28314
|
+
iw.openapi(cw, async (e) => {
|
|
27956
28315
|
try {
|
|
27957
28316
|
let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
|
|
27958
28317
|
if (!t) return e.text("Asset key missing", 400);
|
|
27959
|
-
let
|
|
27960
|
-
if (
|
|
27961
|
-
|
|
27962
|
-
|
|
27963
|
-
|
|
27964
|
-
|
|
27965
|
-
|
|
27966
|
-
|
|
27967
|
-
|
|
27968
|
-
|
|
27969
|
-
|
|
27970
|
-
|
|
27971
|
-
|
|
28318
|
+
let n = await Mb(e).prepare("SELECT deletedAt FROM assets WHERE storageKeyPrivate = ? LIMIT 1").get(t);
|
|
28319
|
+
if (n?.deletedAt && String(n.deletedAt).trim() !== "") return e.text("Asset not found", 404);
|
|
28320
|
+
let { w: r, h: i, q: a, f: o } = e.req.valid("query"), s = !!(r || i || a || o), c = sw(r ? parseInt(r, 10) : void 0), l = e.req.header("Accept") || "", u = "";
|
|
28321
|
+
if (s) {
|
|
28322
|
+
let e = !o || o === "auto";
|
|
28323
|
+
o === "avif" || e && l.includes("image/avif") ? u = "avif" : o === "webp" || e && l.includes("image/webp") ? u = "webp" : o === "jpeg" || o === "jpg" ? u = "jpeg" : o === "png" && (u = "png");
|
|
28324
|
+
}
|
|
28325
|
+
let d = typeof caches < "u" && caches?.default ? caches.default : null, f = e.req.url;
|
|
28326
|
+
if (s) {
|
|
28327
|
+
let e = new URL(f);
|
|
28328
|
+
c && e.searchParams.set("w", String(c)), u && !o && e.searchParams.set("_resolvedFormat", u), f = e.toString();
|
|
28329
|
+
}
|
|
28330
|
+
let p = d ? new Request(f, e.req.raw) : null;
|
|
28331
|
+
if (d && p) {
|
|
28332
|
+
let e = await d.match(p);
|
|
27972
28333
|
if (e) return e;
|
|
27973
28334
|
}
|
|
27974
|
-
let { storage:
|
|
27975
|
-
if (!
|
|
27976
|
-
if (!
|
|
27977
|
-
let n = e.body(
|
|
27978
|
-
"Content-Type":
|
|
28335
|
+
let { storage: m, optimizer: h } = oS(e.env), g = await m.get(t);
|
|
28336
|
+
if (!g) return e.text(`Asset not found: ${t}`, 404);
|
|
28337
|
+
if (!s) {
|
|
28338
|
+
let n = e.body(g, 200, {
|
|
28339
|
+
"Content-Type": aw(t),
|
|
27979
28340
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
27980
28341
|
});
|
|
27981
|
-
return
|
|
27982
|
-
}
|
|
27983
|
-
let
|
|
27984
|
-
width:
|
|
27985
|
-
height:
|
|
27986
|
-
quality:
|
|
27987
|
-
format:
|
|
27988
|
-
},
|
|
28342
|
+
return d && p && e.executionCtx?.waitUntil && e.executionCtx.waitUntil(d.put(p, n.clone())), n;
|
|
28343
|
+
}
|
|
28344
|
+
let _ = {
|
|
28345
|
+
width: c,
|
|
28346
|
+
height: i ? parseInt(i, 10) : void 0,
|
|
28347
|
+
quality: a ? parseInt(a, 10) : 80,
|
|
28348
|
+
format: u
|
|
28349
|
+
}, v = await h.process(g, _, {
|
|
27989
28350
|
key: t,
|
|
27990
28351
|
env: e.env,
|
|
27991
28352
|
req: e.req.raw
|
|
27992
|
-
}),
|
|
27993
|
-
"Content-Type":
|
|
28353
|
+
}), y = aw(t, u), b = e.body(v, 200, {
|
|
28354
|
+
"Content-Type": y,
|
|
27994
28355
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
27995
28356
|
});
|
|
27996
|
-
return
|
|
28357
|
+
return d && p && e.executionCtx?.waitUntil && e.executionCtx.waitUntil(d.put(p, b.clone())), b;
|
|
27997
28358
|
} catch (t) {
|
|
27998
28359
|
return console.error("❌ [Public Assets Error]:", t), e.text("Internal Server Error", 500);
|
|
27999
28360
|
}
|
|
28000
28361
|
});
|
|
28001
|
-
var
|
|
28002
|
-
function
|
|
28362
|
+
var lw = new sb();
|
|
28363
|
+
function uw(e, t) {
|
|
28003
28364
|
let n = /* @__PURE__ */ new Date();
|
|
28004
28365
|
if (e && String(e).trim() !== "") {
|
|
28005
28366
|
let t = new Date(e);
|
|
@@ -28011,64 +28372,76 @@ function gC(e, t) {
|
|
|
28011
28372
|
}
|
|
28012
28373
|
return !0;
|
|
28013
28374
|
}
|
|
28014
|
-
var
|
|
28375
|
+
var dw = X({
|
|
28015
28376
|
channelId: J().optional().openapi({ description: "Optional channel ID/key to filter and resolve root paths for" }),
|
|
28016
28377
|
channel: J().optional().openapi({ description: "Legacy alias for channelId" })
|
|
28017
|
-
}),
|
|
28378
|
+
}), fw = q_(J()).openapi("PathsResponse"), pw = X({
|
|
28018
28379
|
error: J(),
|
|
28019
28380
|
details: J().optional()
|
|
28020
|
-
}).openapi("ErrorResponse"),
|
|
28381
|
+
}).openapi("ErrorResponse"), mw = cb({
|
|
28021
28382
|
method: "get",
|
|
28022
28383
|
path: "/",
|
|
28023
28384
|
summary: "Fetch All Public Paths",
|
|
28024
28385
|
description: "Retrieves a deduplicated array of all active, published node paths leveraging the $O(1)$ node_routes table. Includes both tree-bound and standalone pages.",
|
|
28025
28386
|
tags: ["Public Paths API"],
|
|
28026
|
-
request: { query:
|
|
28387
|
+
request: { query: dw },
|
|
28027
28388
|
responses: {
|
|
28028
28389
|
200: {
|
|
28029
28390
|
description: "Array of valid public URL paths",
|
|
28030
|
-
content: { "application/json": { schema:
|
|
28391
|
+
content: { "application/json": { schema: fw } }
|
|
28031
28392
|
},
|
|
28032
28393
|
500: {
|
|
28033
28394
|
description: "Server error fetching paths",
|
|
28034
|
-
content: { "application/json": { schema:
|
|
28395
|
+
content: { "application/json": { schema: pw } }
|
|
28035
28396
|
}
|
|
28036
28397
|
}
|
|
28037
28398
|
});
|
|
28038
|
-
|
|
28399
|
+
lw.openapi(mw, async (e) => {
|
|
28039
28400
|
try {
|
|
28040
28401
|
let t = e.get("db"), n = e.req.valid("query"), r = n.channelId || n.channel, i = "", a = [];
|
|
28041
28402
|
if (r && r !== "all") {
|
|
28042
|
-
let
|
|
28043
|
-
|
|
28403
|
+
let n = isNaN(Number(r)) ? await t.prepare("SELECT id, isHidden FROM channels WHERE key = ?").get(r) : await t.prepare("SELECT id, isHidden FROM channels WHERE id = ?").get(Number(r));
|
|
28404
|
+
if (!n || Number(n.isHidden) === 1) return e.json([]);
|
|
28405
|
+
i = "AND nr.channelId = ?", a.push(Number(n.id));
|
|
28044
28406
|
}
|
|
28045
28407
|
let o = await t.prepare(`
|
|
28046
28408
|
SELECT
|
|
28047
28409
|
nr.path,
|
|
28048
28410
|
cn.contentType as nodeType,
|
|
28049
28411
|
cn.startShowingAt,
|
|
28050
|
-
cn.stopShowingAt
|
|
28412
|
+
cn.stopShowingAt,
|
|
28413
|
+
CASE WHEN json_valid(cn.dataJson) THEN json_extract(cn.dataJson, '$.startShowingAt') END AS customStartShowingAt,
|
|
28414
|
+
CASE WHEN json_valid(cn.dataJson) THEN json_extract(cn.dataJson, '$.stopShowingAt') END AS customStopShowingAt
|
|
28051
28415
|
FROM node_routes nr
|
|
28052
28416
|
INNER JOIN content_nodes cn ON nr.nodeId = cn.id
|
|
28417
|
+
INNER JOIN channels ch ON nr.channelId = ch.id
|
|
28053
28418
|
WHERE nr.isCanonical = 1
|
|
28054
28419
|
AND (cn.status = 'published' OR cn.status = 'active')
|
|
28055
28420
|
AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
28421
|
+
AND COALESCE(cn.isHidden, 0) = 0
|
|
28422
|
+
AND LOWER(CAST(COALESCE(
|
|
28423
|
+
CASE WHEN json_valid(cn.dataJson) THEN json_extract(cn.dataJson, '$.hidden') END,
|
|
28424
|
+
CASE WHEN json_valid(cn.dataJson) THEN json_extract(cn.dataJson, '$.is_hidden') END,
|
|
28425
|
+
CASE WHEN json_valid(cn.dataJson) THEN json_extract(cn.dataJson, '$.isHidden') END,
|
|
28426
|
+
0
|
|
28427
|
+
) AS TEXT)) NOT IN ('1', 'true')
|
|
28428
|
+
AND COALESCE(ch.isHidden, 0) = 0
|
|
28056
28429
|
${i}
|
|
28057
28430
|
ORDER BY nr.path ASC
|
|
28058
28431
|
`).all(...a), s = Array.isArray(o) ? o : o?.results || [], c = [];
|
|
28059
|
-
for (let e of s) e.nodeType !== "external-link" && e.path &&
|
|
28432
|
+
for (let e of s) e.nodeType !== "external-link" && e.path && uw(e.customStartShowingAt || e.startShowingAt, e.customStopShowingAt || e.stopShowingAt) && c.push(e.path);
|
|
28060
28433
|
let l = [...new Set(c)];
|
|
28061
28434
|
return e.json(l, 200);
|
|
28062
28435
|
} catch (t) {
|
|
28063
28436
|
return console.error("[CMS Paths API] Error:", t), e.json({ error: "Failed to fetch paths" }, 500);
|
|
28064
28437
|
}
|
|
28065
28438
|
});
|
|
28066
|
-
var
|
|
28067
|
-
function
|
|
28068
|
-
let t = (e || "").trim().toLowerCase(), n =
|
|
28439
|
+
var hw = new sb();
|
|
28440
|
+
function gw(e) {
|
|
28441
|
+
let t = (e || "").trim().toLowerCase(), n = hS()?.taxonomies || {};
|
|
28069
28442
|
return n[t] ? t : n[`${t}s`] ? `${t}s` : t.endsWith("s") && n[t.slice(0, -1)] ? t.slice(0, -1) : t;
|
|
28070
28443
|
}
|
|
28071
|
-
var
|
|
28444
|
+
var _w = X({
|
|
28072
28445
|
id: g_(),
|
|
28073
28446
|
taxonomy: J(),
|
|
28074
28447
|
key: J(),
|
|
@@ -28078,14 +28451,14 @@ var CC = X({
|
|
|
28078
28451
|
data: lv(L_()),
|
|
28079
28452
|
createdAt: J(),
|
|
28080
28453
|
updatedAt: J()
|
|
28081
|
-
}),
|
|
28454
|
+
}), vw = X({
|
|
28082
28455
|
taxonomy: J(),
|
|
28083
|
-
items: q_(
|
|
28456
|
+
items: q_(_w),
|
|
28084
28457
|
total: g_()
|
|
28085
|
-
}).openapi("TaxonomyResponse"),
|
|
28458
|
+
}).openapi("TaxonomyResponse"), yw = X({
|
|
28086
28459
|
error: J(),
|
|
28087
28460
|
details: J().optional()
|
|
28088
|
-
}).openapi("ErrorResponse"),
|
|
28461
|
+
}).openapi("ErrorResponse"), bw = cb({
|
|
28089
28462
|
method: "get",
|
|
28090
28463
|
path: "/{taxonomy}",
|
|
28091
28464
|
summary: "Fetch Public Taxonomy Terms",
|
|
@@ -28095,17 +28468,17 @@ var CC = X({
|
|
|
28095
28468
|
responses: {
|
|
28096
28469
|
200: {
|
|
28097
28470
|
description: "List of taxonomy terms",
|
|
28098
|
-
content: { "application/json": { schema:
|
|
28471
|
+
content: { "application/json": { schema: vw } }
|
|
28099
28472
|
},
|
|
28100
28473
|
500: {
|
|
28101
28474
|
description: "Server error",
|
|
28102
|
-
content: { "application/json": { schema:
|
|
28475
|
+
content: { "application/json": { schema: yw } }
|
|
28103
28476
|
}
|
|
28104
28477
|
}
|
|
28105
28478
|
});
|
|
28106
|
-
|
|
28479
|
+
hw.openapi(bw, async (e) => {
|
|
28107
28480
|
try {
|
|
28108
|
-
let t = e.get("db"), n =
|
|
28481
|
+
let t = e.get("db"), n = tS(e), r = e.req.valid("param").taxonomy, i = gw(r), a = `taxonomy:public:${i}`, o = e.req.header("x-bypass-cache") === "true";
|
|
28109
28482
|
if (!o) {
|
|
28110
28483
|
let t = await n.get(a);
|
|
28111
28484
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
@@ -28139,11 +28512,11 @@ xC.openapi(EC, async (e) => {
|
|
|
28139
28512
|
return console.error("[Public Taxonomy API] Error fetching terms:", t), e.json({ error: "Failed to fetch taxonomy terms" }, 500);
|
|
28140
28513
|
}
|
|
28141
28514
|
});
|
|
28142
|
-
var
|
|
28143
|
-
|
|
28515
|
+
var xw = new e();
|
|
28516
|
+
xw.post("/purge", async (e) => {
|
|
28144
28517
|
let t = e.get("db");
|
|
28145
28518
|
try {
|
|
28146
|
-
return await
|
|
28519
|
+
return await tS(e).clear(), await _S(t), await new gS(e.env).purgeGlobalCacheDirect(e, t), e.json({
|
|
28147
28520
|
success: !0,
|
|
28148
28521
|
message: "Global site cache purged successfully"
|
|
28149
28522
|
});
|
|
@@ -28154,22 +28527,22 @@ DC.post("/purge", async (e) => {
|
|
|
28154
28527
|
}, 500);
|
|
28155
28528
|
}
|
|
28156
28529
|
});
|
|
28157
|
-
function
|
|
28158
|
-
return e?.BUNDLED_DEFINITIONS ?
|
|
28530
|
+
function Sw(e) {
|
|
28531
|
+
return e?.BUNDLED_DEFINITIONS ? $S(e.BUNDLED_DEFINITIONS).forms : e?.KAMA_RUNTIME === "node" || !e?.DB && !e?.kama_db ? $S().forms : $S(Fb).forms;
|
|
28159
28532
|
}
|
|
28160
|
-
function
|
|
28533
|
+
function Cw(e, t) {
|
|
28161
28534
|
return Object.entries(e).find(([e, n]) => e === t || n.id === t)?.[1];
|
|
28162
28535
|
}
|
|
28163
|
-
function
|
|
28536
|
+
function ww(e) {
|
|
28164
28537
|
return Array.isArray(e.fields) ? e.fields : Object.entries(e.fields || {}).map(([e, t]) => ({
|
|
28165
28538
|
name: e,
|
|
28166
28539
|
...t
|
|
28167
28540
|
}));
|
|
28168
28541
|
}
|
|
28169
|
-
function
|
|
28542
|
+
function Tw(e) {
|
|
28170
28543
|
return (e.finishers || []).filter((e) => e.enabled !== !1);
|
|
28171
28544
|
}
|
|
28172
|
-
function
|
|
28545
|
+
function Ew(e, t) {
|
|
28173
28546
|
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("Email overrides must be an object");
|
|
28174
28547
|
let n = e, r = /* @__PURE__ */ new Set([
|
|
28175
28548
|
"subject",
|
|
@@ -28207,25 +28580,15 @@ function MC(e, t) {
|
|
|
28207
28580
|
if (i.fromName && i.fromNameField) throw Error("Set either fromName or fromNameField, not both");
|
|
28208
28581
|
return i;
|
|
28209
28582
|
}
|
|
28210
|
-
|
|
28211
|
-
let r = await e.prepare("SELECT finishers_json FROM kama_form_settings WHERE form_id = ?").get(t);
|
|
28212
|
-
if (!r) return jC(n);
|
|
28213
|
-
let i = JSON.parse(r.finishers_json);
|
|
28214
|
-
if (!Array.isArray(i)) throw Error(`Invalid stored finisher configuration for form "${t}"`);
|
|
28215
|
-
return i.filter((e) => e.enabled !== !1);
|
|
28216
|
-
}
|
|
28217
|
-
var PC = new e();
|
|
28218
|
-
function FC(e) {
|
|
28219
|
-
return typeof e == "string" && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim());
|
|
28220
|
-
}
|
|
28221
|
-
function IC(e, t) {
|
|
28583
|
+
function Dw(e, t) {
|
|
28222
28584
|
if (!Array.isArray(e)) throw Error("Finishers must be a list");
|
|
28223
28585
|
if (e.length > 10) throw Error("A form can have at most 10 finishers");
|
|
28224
|
-
let n = /* @__PURE__ */ new Set(), r = []
|
|
28225
|
-
for (let
|
|
28226
|
-
if (!
|
|
28227
|
-
if (
|
|
28228
|
-
|
|
28586
|
+
let n = /* @__PURE__ */ new Set(), r = [];
|
|
28587
|
+
for (let [i, a] of e.entries()) {
|
|
28588
|
+
if (!a || typeof a != "object" || Array.isArray(a)) throw Error("Each finisher must be an object");
|
|
28589
|
+
if (a.enabled === !1) continue;
|
|
28590
|
+
if (a.type === "database") {
|
|
28591
|
+
if (r.some((e) => e.type === "database")) throw Error("Only one database finisher is allowed");
|
|
28229
28592
|
r.push({
|
|
28230
28593
|
id: "save-submission",
|
|
28231
28594
|
type: "database",
|
|
@@ -28233,178 +28596,143 @@ function IC(e, t) {
|
|
|
28233
28596
|
});
|
|
28234
28597
|
continue;
|
|
28235
28598
|
}
|
|
28236
|
-
if (typeof
|
|
28237
|
-
|
|
28238
|
-
if (n.
|
|
28239
|
-
|
|
28240
|
-
|
|
28241
|
-
|
|
28242
|
-
|
|
28599
|
+
if (typeof a.type != "string" || !/^[a-z][a-z0-9_-]*$/.test(a.type)) throw Error(`Invalid finisher type "${String(a.type)}"`);
|
|
28600
|
+
let e = a.id === void 0 ? `${a.type}-${i + 1}` : a.id;
|
|
28601
|
+
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");
|
|
28602
|
+
if (n.add(e), a.type !== "email") {
|
|
28603
|
+
let t = JSON.stringify(a);
|
|
28604
|
+
if (t.length > 8e3) throw Error("Custom finisher settings are too large");
|
|
28605
|
+
r.push({
|
|
28606
|
+
...JSON.parse(t),
|
|
28607
|
+
id: e,
|
|
28243
28608
|
enabled: !0
|
|
28244
28609
|
});
|
|
28245
28610
|
continue;
|
|
28246
28611
|
}
|
|
28247
|
-
let
|
|
28248
|
-
id:
|
|
28612
|
+
let o = {
|
|
28613
|
+
id: e,
|
|
28249
28614
|
type: "email",
|
|
28250
28615
|
enabled: !0,
|
|
28251
|
-
provider: "auto"
|
|
28616
|
+
provider: a.provider === void 0 ? "auto" : a.provider
|
|
28252
28617
|
};
|
|
28253
|
-
if (
|
|
28254
|
-
|
|
28255
|
-
|
|
28256
|
-
|
|
28618
|
+
if (![
|
|
28619
|
+
"auto",
|
|
28620
|
+
"cloudflare",
|
|
28621
|
+
"smtp"
|
|
28622
|
+
].includes(o.provider)) throw Error("Email provider must be auto, cloudflare, or smtp");
|
|
28623
|
+
if (a.toField !== void 0) {
|
|
28624
|
+
if (typeof a.toField != "string" || !t.some((e) => e.name === a.toField && e.type === "email")) throw Error(`Recipient field "${String(a.toField)}" must be an email field`);
|
|
28625
|
+
o.toField = a.toField;
|
|
28626
|
+
} else if (typeof a.to == "string" && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a.to.trim())) o.to = a.to.trim();
|
|
28627
|
+
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());
|
|
28257
28628
|
else throw Error("Email finishers need a valid recipient address or email field");
|
|
28258
|
-
|
|
28259
|
-
subject:
|
|
28260
|
-
subjectField:
|
|
28261
|
-
fromName:
|
|
28262
|
-
fromNameField:
|
|
28263
|
-
replyTo:
|
|
28264
|
-
replyToField:
|
|
28265
|
-
text:
|
|
28266
|
-
html:
|
|
28267
|
-
}, t)),
|
|
28268
|
-
}
|
|
28269
|
-
return [
|
|
28270
|
-
...r,
|
|
28271
|
-
...i,
|
|
28272
|
-
...a
|
|
28273
|
-
];
|
|
28274
|
-
}
|
|
28275
|
-
PC.get("/", async (e) => {
|
|
28276
|
-
let t = OC(e.env), n = e.get("db"), r = await Promise.all(Object.entries(t).map(async ([e, t]) => {
|
|
28277
|
-
let r = t.id || e, i = await NC(n, r, t);
|
|
28278
|
-
return {
|
|
28279
|
-
id: r,
|
|
28280
|
-
title: t.title || e,
|
|
28281
|
-
description: t.description || "",
|
|
28282
|
-
fieldsCount: AC(t).length,
|
|
28283
|
-
storesSubmissions: i.some((e) => e.type === "database"),
|
|
28284
|
-
enabledFinishers: i.length
|
|
28285
|
-
};
|
|
28286
|
-
}));
|
|
28287
|
-
return e.json(r);
|
|
28288
|
-
}), PC.get("/:formId/finishers", async (e) => {
|
|
28289
|
-
let t = e.req.param("formId"), n = kC(OC(e.env), t);
|
|
28290
|
-
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
28291
|
-
try {
|
|
28292
|
-
return e.json({
|
|
28293
|
-
formId: n.id || t,
|
|
28294
|
-
title: n.title || n.id || t,
|
|
28295
|
-
fields: AC(n).map((e) => ({
|
|
28296
|
-
name: e.name,
|
|
28297
|
-
label: e.label || e.name,
|
|
28298
|
-
type: e.type || "text"
|
|
28299
|
-
})),
|
|
28300
|
-
finishers: await NC(e.get("db"), n.id || t, n),
|
|
28301
|
-
emailTransport: {
|
|
28302
|
-
cloudflare: typeof e.env?.FORMS_EMAIL?.send == "function",
|
|
28303
|
-
smtp: e.env?.KAMA_RUNTIME === "node" && !!e.env?.FORMS_SMTP_HOST,
|
|
28304
|
-
senderConfigured: !!e.env?.FORMS_EMAIL_FROM
|
|
28305
|
-
}
|
|
28306
|
-
});
|
|
28307
|
-
} catch (n) {
|
|
28308
|
-
return console.error(`[Forms] Failed to load finisher settings for ${t}:`, n), e.json({ error: "Failed to load form settings" }, 500);
|
|
28629
|
+
Object.assign(o, Ew({
|
|
28630
|
+
subject: a.subject,
|
|
28631
|
+
subjectField: a.subjectField,
|
|
28632
|
+
fromName: a.fromName,
|
|
28633
|
+
fromNameField: a.fromNameField,
|
|
28634
|
+
replyTo: a.replyTo,
|
|
28635
|
+
replyToField: a.replyToField,
|
|
28636
|
+
text: a.text,
|
|
28637
|
+
html: a.html
|
|
28638
|
+
}, t)), r.push(o);
|
|
28309
28639
|
}
|
|
28310
|
-
|
|
28311
|
-
|
|
28312
|
-
|
|
28313
|
-
|
|
28314
|
-
|
|
28315
|
-
|
|
28316
|
-
|
|
28317
|
-
|
|
28318
|
-
|
|
28319
|
-
|
|
28320
|
-
|
|
28321
|
-
|
|
28322
|
-
|
|
28323
|
-
}
|
|
28324
|
-
|
|
28325
|
-
|
|
28326
|
-
|
|
28327
|
-
|
|
28328
|
-
|
|
28329
|
-
|
|
28330
|
-
|
|
28331
|
-
|
|
28332
|
-
|
|
28333
|
-
|
|
28334
|
-
storageEnabled: !1,
|
|
28335
|
-
submissions: []
|
|
28336
|
-
});
|
|
28337
|
-
let i = await r.prepare("SELECT id, payload_json, createdAt FROM kama_forms_table WHERE form_id = ? ORDER BY createdAt DESC").all(t);
|
|
28338
|
-
return e.json({
|
|
28339
|
-
formTitle: n.title || n.id || t,
|
|
28340
|
-
storageEnabled: !0,
|
|
28341
|
-
submissions: i.map((e) => ({
|
|
28342
|
-
id: e.id,
|
|
28343
|
-
data: JSON.parse(e.payload_json),
|
|
28344
|
-
createdAt: e.createdAt
|
|
28345
|
-
}))
|
|
28346
|
-
});
|
|
28347
|
-
} catch (n) {
|
|
28348
|
-
return console.error(`[Forms] Failed to load submissions for ${t}:`, n), e.json({ error: "Failed to load form submissions" }, 500);
|
|
28640
|
+
return r;
|
|
28641
|
+
}
|
|
28642
|
+
async function Ow(e, t, n, r, i) {
|
|
28643
|
+
if (typeof t != "string" && typeof t != "number" || typeof n != "string" && typeof n != "number") throw Error("Invalid form block reference");
|
|
28644
|
+
let a = Number(t), o = String(n).trim();
|
|
28645
|
+
if (!Number.isSafeInteger(a) || a < 1 || !o || o.length > 200) throw Error("Invalid form block reference");
|
|
28646
|
+
let s = await e.prepare("SELECT id, elementType, dataJson FROM content_blocks WHERE contentId = ? AND isDraft = 0").all(a), c = Array.isArray(s) ? s : s?.results || [], l;
|
|
28647
|
+
for (let e of c) {
|
|
28648
|
+
let t;
|
|
28649
|
+
try {
|
|
28650
|
+
t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
28651
|
+
} catch {
|
|
28652
|
+
continue;
|
|
28653
|
+
}
|
|
28654
|
+
if (!t || typeof t != "object" || Array.isArray(t)) continue;
|
|
28655
|
+
let n = String(t.blockId || t._instanceId || t.id || e.id || ""), r = String(e.elementType || "").toLowerCase();
|
|
28656
|
+
if (n === o && [
|
|
28657
|
+
"form",
|
|
28658
|
+
"form-block",
|
|
28659
|
+
"form_block"
|
|
28660
|
+
].includes(r)) {
|
|
28661
|
+
l = t;
|
|
28662
|
+
break;
|
|
28663
|
+
}
|
|
28349
28664
|
}
|
|
28350
|
-
|
|
28351
|
-
|
|
28352
|
-
|
|
28665
|
+
if (!l || l.formId !== r) throw Error("Published form block was not found");
|
|
28666
|
+
let u = l.finisherOverrides;
|
|
28667
|
+
if (l.finisherOverridesEnabled === !0) return Dw(u, i);
|
|
28668
|
+
}
|
|
28669
|
+
async function kw(e, t, n) {
|
|
28670
|
+
let r = await e.prepare("SELECT finishers_json FROM kama_form_settings WHERE form_id = ?").get(t);
|
|
28671
|
+
if (!r) return Tw(n);
|
|
28672
|
+
let i = JSON.parse(r.finishers_json);
|
|
28673
|
+
if (!Array.isArray(i)) throw Error(`Invalid stored finisher configuration for form "${t}"`);
|
|
28674
|
+
return i.filter((e) => e.enabled !== !1);
|
|
28675
|
+
}
|
|
28676
|
+
var Aw = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, jw = /* @__PURE__ */ new Map();
|
|
28677
|
+
function Mw(e, t) {
|
|
28353
28678
|
if (!/^[a-z][a-z0-9_-]*$/.test(e)) throw Error(`Invalid form finisher type "${e}"`);
|
|
28354
|
-
if (
|
|
28355
|
-
return
|
|
28679
|
+
if (jw.has(e)) throw Error(`Form finisher "${e}" is already registered`);
|
|
28680
|
+
return jw.set(e, t), () => jw.delete(e);
|
|
28681
|
+
}
|
|
28682
|
+
function Nw() {
|
|
28683
|
+
return Array.from(jw.keys());
|
|
28356
28684
|
}
|
|
28357
|
-
function
|
|
28358
|
-
if (typeof e != "string" || !
|
|
28685
|
+
function Pw(e, t) {
|
|
28686
|
+
if (typeof e != "string" || !Aw.test(e.trim())) throw Error(`${t} must be a valid email address`);
|
|
28359
28687
|
return e.trim();
|
|
28360
28688
|
}
|
|
28361
|
-
function
|
|
28689
|
+
function Fw(e) {
|
|
28362
28690
|
return String(e ?? "").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
28363
28691
|
}
|
|
28364
|
-
function
|
|
28692
|
+
function Iw(e, t, n = !1) {
|
|
28365
28693
|
return e.replace(/\{\{\s*([a-zA-Z0-9_.-]+)\s*\}\}/g, (e, r) => {
|
|
28366
28694
|
let i = t[r];
|
|
28367
|
-
return n ?
|
|
28695
|
+
return n ? Fw(i) : String(i ?? "");
|
|
28368
28696
|
});
|
|
28369
28697
|
}
|
|
28370
|
-
function
|
|
28698
|
+
function Lw(e, t, n) {
|
|
28371
28699
|
if (e != null && e !== "") {
|
|
28372
28700
|
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`);
|
|
28373
28701
|
return e.trim() || void 0;
|
|
28374
28702
|
}
|
|
28375
28703
|
}
|
|
28376
|
-
function
|
|
28377
|
-
let
|
|
28704
|
+
function Rw(e, t, n, r) {
|
|
28705
|
+
let i = ww(e), a;
|
|
28378
28706
|
if (t.toField) {
|
|
28379
|
-
let e =
|
|
28707
|
+
let e = i.find((e) => e.name === t.toField);
|
|
28380
28708
|
if (!e || e.type !== "email") throw Error(`Email finisher recipient field "${t.toField}" must be an email field`);
|
|
28381
|
-
|
|
28709
|
+
a = Pw(n[t.toField], `Recipient field "${t.toField}"`);
|
|
28382
28710
|
} else if (Array.isArray(t.to)) {
|
|
28383
28711
|
if (t.to.length === 0) throw Error("Email finisher requires at least one recipient");
|
|
28384
|
-
|
|
28385
|
-
} else
|
|
28386
|
-
let
|
|
28387
|
-
if (!
|
|
28388
|
-
let
|
|
28389
|
-
email:
|
|
28390
|
-
name:
|
|
28391
|
-
} :
|
|
28392
|
-
if (
|
|
28393
|
-
let e =
|
|
28394
|
-
if (!e || e.type !== "email") throw Error(`Email finisher reply-to field "${
|
|
28395
|
-
n[
|
|
28396
|
-
} else
|
|
28712
|
+
a = t.to.map((e) => Pw(e, "Email finisher recipient"));
|
|
28713
|
+
} else a = Pw(t.to, "Email finisher recipient");
|
|
28714
|
+
let o = Pw(r.FORMS_EMAIL_FROM, "FORMS_EMAIL_FROM"), s = t.subjectField, c = t.subject || `New submission: ${e.title || e.id || "Form"}`, l = (s ? String(n[s] ?? "").trim() : "") || Iw(c || "", n), u = Lw(l == null ? "" : String(l), "Email subject", 200);
|
|
28715
|
+
if (!u) throw Error("Email finisher subject must be non-empty and contain no line breaks");
|
|
28716
|
+
let d = t.fromNameField, f = Lw((d ? String(n[d] ?? "").trim() : "") || t.fromName || r.FORMS_EMAIL_FROM_NAME, "Email sender name", 120), p = f ? {
|
|
28717
|
+
email: o,
|
|
28718
|
+
name: f
|
|
28719
|
+
} : o, m = t.text, h = t.html, g = m ? Iw(m, n) : i.map((e) => `${e.label || e.name}: ${String(n[e.name] ?? "")}`).join("\n"), _ = h ? Iw(h, n, !0) : `<h2>${Fw(e.title || e.id || "Form submission")}</h2><dl>${i.map((e) => `<dt>${Fw(e.label || e.name)}</dt><dd>${Fw(n[e.name])}</dd>`).join("")}</dl>`, v, y = t.replyToField, b = t.replyTo;
|
|
28720
|
+
if (y) {
|
|
28721
|
+
let e = i.find((e) => e.name === y);
|
|
28722
|
+
if (!e || e.type !== "email") throw Error(`Email finisher reply-to field "${y}" must be an email field`);
|
|
28723
|
+
n[y] !== void 0 && String(n[y]).trim() && (v = Pw(n[y], `Reply-to field "${y}"`));
|
|
28724
|
+
} else b && (v = Pw(b, "Email finisher reply-to address"));
|
|
28397
28725
|
return {
|
|
28398
|
-
from:
|
|
28399
|
-
to:
|
|
28400
|
-
subject:
|
|
28401
|
-
text:
|
|
28402
|
-
html:
|
|
28403
|
-
...
|
|
28726
|
+
from: p,
|
|
28727
|
+
to: a,
|
|
28728
|
+
subject: u,
|
|
28729
|
+
text: g,
|
|
28730
|
+
html: _,
|
|
28731
|
+
...v ? { replyTo: v } : {}
|
|
28404
28732
|
};
|
|
28405
28733
|
}
|
|
28406
|
-
async function
|
|
28407
|
-
let { form: t, payload: n, env: r } = e, i = e.finisher, a =
|
|
28734
|
+
async function zw(e) {
|
|
28735
|
+
let { form: t, payload: n, env: r } = e, i = e.finisher, a = Rw(t, i, n, r), o = i.provider || "auto", s = r.FORMS_EMAIL;
|
|
28408
28736
|
if (o === "cloudflare" || o === "auto" && s) {
|
|
28409
28737
|
if (!s || typeof s.send != "function") throw Error("Cloudflare Email Sending binding FORMS_EMAIL is not configured");
|
|
28410
28738
|
await s.send(a);
|
|
@@ -28415,7 +28743,7 @@ async function GC(e) {
|
|
|
28415
28743
|
let e = r.FORMS_SMTP_HOST, t = Number(r.FORMS_SMTP_PORT || 465);
|
|
28416
28744
|
if (typeof e != "string" || !e.trim() || !Number.isInteger(t) || t < 1 || t > 65535) throw Error("FORMS_SMTP_HOST and a valid FORMS_SMTP_PORT are required for SMTP");
|
|
28417
28745
|
if (!!r.FORMS_SMTP_USER != !!r.FORMS_SMTP_PASSWORD) throw Error("FORMS_SMTP_USER and FORMS_SMTP_PASSWORD must be configured together");
|
|
28418
|
-
let n = (await import("./nodemailer-Ccic7tRm-
|
|
28746
|
+
let n = (await import("./nodemailer-Ccic7tRm-Cf8qGuYa.js")).createTransport({
|
|
28419
28747
|
host: e,
|
|
28420
28748
|
port: t,
|
|
28421
28749
|
secure: r.FORMS_SMTP_SECURE === void 0 ? t === 465 : r.FORMS_SMTP_SECURE === "true",
|
|
@@ -28440,45 +28768,122 @@ async function GC(e) {
|
|
|
28440
28768
|
}
|
|
28441
28769
|
throw Error(`Unsupported email provider "${o}"`);
|
|
28442
28770
|
}
|
|
28443
|
-
|
|
28771
|
+
Mw("database", async ({ db: e, formId: t, payload: n }) => {
|
|
28444
28772
|
await e.prepare("INSERT INTO kama_forms_table (form_id, payload_json, createdAt) VALUES (?, ?, CURRENT_TIMESTAMP)").run(t, JSON.stringify(n));
|
|
28445
|
-
}),
|
|
28446
|
-
async function
|
|
28447
|
-
let o = await
|
|
28448
|
-
for (let
|
|
28449
|
-
let o =
|
|
28450
|
-
if (!o) throw Error(`Unsupported form finisher type "${
|
|
28773
|
+
}), Mw("email", zw);
|
|
28774
|
+
async function Bw(e, t, n, r, i, a) {
|
|
28775
|
+
let o = a ?? await kw(r, t, e);
|
|
28776
|
+
for (let a of o) {
|
|
28777
|
+
let o = jw.get(a.type);
|
|
28778
|
+
if (!o) throw Error(`Unsupported form finisher type "${a.type}"`);
|
|
28451
28779
|
await o({
|
|
28452
28780
|
form: e,
|
|
28453
28781
|
formId: t,
|
|
28454
|
-
finisher:
|
|
28782
|
+
finisher: a,
|
|
28455
28783
|
payload: n,
|
|
28456
28784
|
db: r,
|
|
28457
|
-
env: i
|
|
28458
|
-
...s.type === "email" ? { emailOverrides: a } : {}
|
|
28785
|
+
env: i
|
|
28459
28786
|
});
|
|
28460
28787
|
}
|
|
28461
28788
|
}
|
|
28462
|
-
var
|
|
28463
|
-
|
|
28464
|
-
let t = e.
|
|
28789
|
+
var Vw = new e();
|
|
28790
|
+
Vw.get("/", async (e) => {
|
|
28791
|
+
let t = Sw(e.env), n = e.get("db"), r = await Promise.all(Object.entries(t).map(async ([e, t]) => {
|
|
28792
|
+
let r = t.id || e, i = await kw(n, r, t);
|
|
28793
|
+
return {
|
|
28794
|
+
id: r,
|
|
28795
|
+
title: t.title || e,
|
|
28796
|
+
description: t.description || "",
|
|
28797
|
+
fieldsCount: ww(t).length,
|
|
28798
|
+
storesSubmissions: i.some((e) => e.type === "database"),
|
|
28799
|
+
enabledFinishers: i.length
|
|
28800
|
+
};
|
|
28801
|
+
}));
|
|
28802
|
+
return e.json(r);
|
|
28803
|
+
}), Vw.get("/:formId/finishers", async (e) => {
|
|
28804
|
+
let t = e.req.param("formId"), n = Cw(Sw(e.env), t);
|
|
28805
|
+
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
28806
|
+
try {
|
|
28807
|
+
return e.json({
|
|
28808
|
+
formId: n.id || t,
|
|
28809
|
+
title: n.title || n.id || t,
|
|
28810
|
+
fields: ww(n).map((e) => ({
|
|
28811
|
+
name: e.name,
|
|
28812
|
+
label: e.label || e.name,
|
|
28813
|
+
type: e.type || "text"
|
|
28814
|
+
})),
|
|
28815
|
+
finishers: await kw(e.get("db"), n.id || t, n),
|
|
28816
|
+
availableFinishers: Nw(),
|
|
28817
|
+
emailTransport: {
|
|
28818
|
+
cloudflare: typeof e.env?.FORMS_EMAIL?.send == "function",
|
|
28819
|
+
smtp: e.env?.KAMA_RUNTIME === "node" && !!e.env?.FORMS_SMTP_HOST,
|
|
28820
|
+
senderConfigured: !!e.env?.FORMS_EMAIL_FROM
|
|
28821
|
+
}
|
|
28822
|
+
});
|
|
28823
|
+
} catch (n) {
|
|
28824
|
+
return console.error(`[Forms] Failed to load finisher settings for ${t}:`, n), e.json({ error: "Failed to load form settings" }, 500);
|
|
28825
|
+
}
|
|
28826
|
+
}), Vw.put("/:formId/finishers", async (e) => {
|
|
28827
|
+
let t = e.req.param("formId"), n = Cw(Sw(e.env), t);
|
|
28828
|
+
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
28829
|
+
let r;
|
|
28830
|
+
try {
|
|
28831
|
+
r = Dw((await e.req.json())?.finishers, ww(n));
|
|
28832
|
+
} catch (t) {
|
|
28833
|
+
return e.json({ error: t instanceof Error ? t.message : "Invalid form settings" }, 400);
|
|
28834
|
+
}
|
|
28835
|
+
try {
|
|
28836
|
+
return await e.get("db").prepare("\n INSERT INTO kama_form_settings (form_id, finishers_json, updatedAt)\n VALUES (?, ?, CURRENT_TIMESTAMP)\n ON CONFLICT(form_id) DO UPDATE SET\n finishers_json = excluded.finishers_json,\n updatedAt = CURRENT_TIMESTAMP\n ").run(n.id || t, JSON.stringify(r)), e.json({
|
|
28837
|
+
success: !0,
|
|
28838
|
+
finishers: r
|
|
28839
|
+
});
|
|
28840
|
+
} catch (n) {
|
|
28841
|
+
return console.error(`[Forms] Failed to save finisher settings for ${t}:`, n), e.json({ error: "Failed to save form settings" }, 500);
|
|
28842
|
+
}
|
|
28843
|
+
}), Vw.get("/:formId/submissions", async (e) => {
|
|
28844
|
+
let t = e.req.param("formId"), n = Cw(Sw(e.env), t);
|
|
28845
|
+
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
28846
|
+
try {
|
|
28847
|
+
let r = e.get("db");
|
|
28848
|
+
if (!(await kw(r, n.id || t, n)).some((e) => e.type === "database")) return e.json({
|
|
28849
|
+
formTitle: n.title || n.id || t,
|
|
28850
|
+
storageEnabled: !1,
|
|
28851
|
+
submissions: []
|
|
28852
|
+
});
|
|
28853
|
+
let i = await r.prepare("SELECT id, payload_json, createdAt FROM kama_forms_table WHERE form_id = ? ORDER BY createdAt DESC").all(t);
|
|
28854
|
+
return e.json({
|
|
28855
|
+
formTitle: n.title || n.id || t,
|
|
28856
|
+
storageEnabled: !0,
|
|
28857
|
+
submissions: i.map((e) => ({
|
|
28858
|
+
id: e.id,
|
|
28859
|
+
data: JSON.parse(e.payload_json),
|
|
28860
|
+
createdAt: e.createdAt
|
|
28861
|
+
}))
|
|
28862
|
+
});
|
|
28863
|
+
} catch (n) {
|
|
28864
|
+
return console.error(`[Forms] Failed to load submissions for ${t}:`, n), e.json({ error: "Failed to load form submissions" }, 500);
|
|
28865
|
+
}
|
|
28866
|
+
});
|
|
28867
|
+
var Hw = new e();
|
|
28868
|
+
Hw.get("/:formId", (e) => {
|
|
28869
|
+
let t = e.req.param("formId"), n = Cw(Sw(e.env), t);
|
|
28465
28870
|
return n ? e.json({
|
|
28466
28871
|
id: n.id || t,
|
|
28467
28872
|
title: n.title || "",
|
|
28468
28873
|
description: n.description || "",
|
|
28469
|
-
fields:
|
|
28874
|
+
fields: ww(n),
|
|
28470
28875
|
settings: {
|
|
28471
28876
|
successMessage: n.settings?.successMessage || "Form submitted successfully!",
|
|
28472
28877
|
requireTurnstile: n.settings?.requireTurnstile === !0
|
|
28473
28878
|
}
|
|
28474
28879
|
}) : e.json({ error: "Form definition not found" }, 404);
|
|
28475
|
-
}),
|
|
28476
|
-
let t = e.req.param("formId"), n =
|
|
28880
|
+
}), Hw.post("/:formId/submissions", async (e) => {
|
|
28881
|
+
let t = e.req.param("formId"), n = Cw(Sw(e.env), t);
|
|
28477
28882
|
if (!n) return e.json({ error: "Form definition not found" }, 404);
|
|
28478
28883
|
try {
|
|
28479
28884
|
let r = await e.req.json();
|
|
28480
28885
|
if (!r || typeof r != "object" || Array.isArray(r)) return e.json({ error: "Invalid form submission" }, 400);
|
|
28481
|
-
let i =
|
|
28886
|
+
let i = ww(n), a = r["cf-turnstile-response"];
|
|
28482
28887
|
if (n.settings?.requireTurnstile === !0) {
|
|
28483
28888
|
if (typeof a != "string" || !a) return e.json({ error: "Security verification failed. Please complete the captcha." }, 400);
|
|
28484
28889
|
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);
|
|
@@ -28503,11 +28908,11 @@ qC.get("/:formId", (e) => {
|
|
|
28503
28908
|
}
|
|
28504
28909
|
let s;
|
|
28505
28910
|
try {
|
|
28506
|
-
s =
|
|
28911
|
+
r._kamaFinisherBlockId !== void 0 && (s = await Ow(e.get("db"), r._kamaFinisherContentId, r._kamaFinisherBlockId, n.id || t, i));
|
|
28507
28912
|
} catch (t) {
|
|
28508
|
-
return e.json({ error: t instanceof Error ? t.message : "Invalid
|
|
28913
|
+
return e.json({ error: t instanceof Error ? t.message : "Invalid form block settings" }, 400);
|
|
28509
28914
|
}
|
|
28510
|
-
return await
|
|
28915
|
+
return await Bw(n, n.id || t, o, e.get("db"), e.env, s), e.json({
|
|
28511
28916
|
success: !0,
|
|
28512
28917
|
message: n.settings?.successMessage || "Form submitted successfully!"
|
|
28513
28918
|
});
|
|
@@ -28515,7 +28920,7 @@ qC.get("/:formId", (e) => {
|
|
|
28515
28920
|
return console.error(`[Forms] Failed to process submission for ${t}:`, n), e.json({ error: "Failed to process submission" }, 500);
|
|
28516
28921
|
}
|
|
28517
28922
|
});
|
|
28518
|
-
var $ = new sb(),
|
|
28923
|
+
var $ = new sb(), Uw = !1;
|
|
28519
28924
|
$.use("*", t()), $.use("/media/*", t({
|
|
28520
28925
|
origin: "*",
|
|
28521
28926
|
allowMethods: [
|
|
@@ -28530,24 +28935,23 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
28530
28935
|
],
|
|
28531
28936
|
maxAge: 86400
|
|
28532
28937
|
})), $.use("/media/*", async (e, t) => {
|
|
28533
|
-
await t(), e.header("Cache-Control", "public, max-age=31536000, immutable"), e.header("Access-Control-Allow-Origin", "*");
|
|
28938
|
+
await t(), e.header("Cache-Control", e.res.status < 400 ? "public, max-age=31536000, immutable" : "no-store"), e.header("Access-Control-Allow-Origin", "*");
|
|
28534
28939
|
}), $.use("*", async (e, t) => {
|
|
28535
|
-
if (e.req.path.startsWith("/media/")) return t();
|
|
28536
28940
|
let n = new URL(e.req.url), r = (e.req.header("host") || n.hostname).split(":")[0];
|
|
28537
28941
|
e.set("currentDomain", r);
|
|
28538
28942
|
let i = Mb(e);
|
|
28539
|
-
if (e.set("db", i), !
|
|
28540
|
-
await Bb(i, e.env?.BUNDLED_DEFINITIONS),
|
|
28943
|
+
if (e.set("db", i), !Uw) try {
|
|
28944
|
+
await Bb(i, e.env?.BUNDLED_DEFINITIONS), Uw = !0;
|
|
28541
28945
|
} catch (e) {
|
|
28542
28946
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
28543
28947
|
}
|
|
28544
28948
|
await t();
|
|
28545
|
-
}), $.route("/media",
|
|
28546
|
-
var
|
|
28949
|
+
}), $.route("/media", iw), $.use("/media/*", Hb()), $.route("/api/cms/nodes", vS), $.route("/api/cms/nodes.json", vS), $.route("/api/cms/formcsv", vS), $.route("/api/cms/formcsv.json", vS), $.route("/api/cms/stats", oC), $.route("/api/cms/stats.json", oC), $.route("/api/cms", AS), $.route("/api/cms/trees.json", AS), $.route("/api/cms/channels", PS), $.route("/api/cms/channels.json", PS), $.route("/api/cms/taxonomies", FS), $.route("/api/cms/taxonomies.json", FS), $.route("/api/cms/cache", xw), $.route("/api/cms/cache.json", xw), $.route("/api/cms/schemas", tC), $.route("/api/cms/schemas.json", tC), $.route("/api/cms", rC), $.route("/api/admin/assets", sC), $.route("/api/cms/forms", Vw);
|
|
28950
|
+
var Ww = (e) => {
|
|
28547
28951
|
let t = new URL(e.req.url);
|
|
28548
|
-
return t.pathname = t.pathname.replace("/api/cms/preview-payload", "/api/v1/node"),
|
|
28952
|
+
return t.pathname = t.pathname.replace("/api/cms/preview-payload", "/api/v1/node"), fC.fetch(new Request(t, e.req.raw), e.env);
|
|
28549
28953
|
};
|
|
28550
|
-
$.all("/api/cms/preview-payload",
|
|
28954
|
+
$.use("/api/cms/preview-payload", Ix), $.use("/api/cms/preview-payload/*", Ix), $.all("/api/cms/preview-payload", Ww), $.all("/api/cms/preview-payload/*", Ww), $.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) => {
|
|
28551
28955
|
if (e.req.path.startsWith("/api/v1/forms/")) return t();
|
|
28552
28956
|
let n = e.env?.FRONTEND_API_SECRET;
|
|
28553
28957
|
if (n) {
|
|
@@ -28555,7 +28959,7 @@ $.all("/api/cms/preview-payload", YC), $.all("/api/cms/preview-payload/*", YC),
|
|
|
28555
28959
|
if (!i || i !== n) return e.json({ error: "Unauthorized: Invalid or missing API secret." }, 401);
|
|
28556
28960
|
} else console.warn("⚠️ [CMS Security] FRONTEND_API_SECRET is not set in .env. The API is completely exposed to the public.");
|
|
28557
28961
|
return t();
|
|
28558
|
-
}), $.route("/api/v1/forms",
|
|
28962
|
+
}), $.route("/api/v1/forms", Hw), $.route("/api/v1/node", fC), $.route("/api/v1/nodes", MC), $.route("/api/v1/tree", IC), $.route("/api/v1/channel", GC), $.route("/api/v1/all-paths", lw), $.route("/api/v1/taxonomies", hw), $.doc("/api/openapi.json", {
|
|
28559
28963
|
openapi: "3.0.0",
|
|
28560
28964
|
info: {
|
|
28561
28965
|
title: "KAMA Engine Public API",
|
|
@@ -28574,4 +28978,4 @@ $.all("/api/cms/preview-payload", YC), $.all("/api/cms/preview-payload/*", YC),
|
|
|
28574
28978
|
return t();
|
|
28575
28979
|
});
|
|
28576
28980
|
//#endregion
|
|
28577
|
-
export {
|
|
28981
|
+
export { QS as compileDefinitions, d as n, m as t };
|