@sonicjs-cms/core 3.0.0-beta.10 → 3.0.0-beta.12
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/{chunk-V464XBYS.js → chunk-ALNODOY4.js} +3 -3
- package/dist/{chunk-V464XBYS.js.map → chunk-ALNODOY4.js.map} +1 -1
- package/dist/{chunk-MUNO67TT.cjs → chunk-BYLQOBO6.cjs} +13 -13
- package/dist/{chunk-MUNO67TT.cjs.map → chunk-BYLQOBO6.cjs.map} +1 -1
- package/dist/{chunk-IDCZBF35.js → chunk-DMXDQ5YI.js} +4 -4
- package/dist/{chunk-IDCZBF35.js.map → chunk-DMXDQ5YI.js.map} +1 -1
- package/dist/{chunk-ALDRXTUO.js → chunk-INKP2WNU.js} +2 -2
- package/dist/{chunk-ALDRXTUO.js.map → chunk-INKP2WNU.js.map} +1 -1
- package/dist/{chunk-IHTXB7AT.cjs → chunk-KI5KMJH2.cjs} +2 -2
- package/dist/{chunk-IHTXB7AT.cjs.map → chunk-KI5KMJH2.cjs.map} +1 -1
- package/dist/{chunk-R4ILO3W6.cjs → chunk-LLWLHFTD.cjs} +2 -2
- package/dist/{chunk-R4ILO3W6.cjs.map → chunk-LLWLHFTD.cjs.map} +1 -1
- package/dist/{chunk-PMGOBS6X.cjs → chunk-NYLWNR6T.cjs} +4 -4
- package/dist/{chunk-PMGOBS6X.cjs.map → chunk-NYLWNR6T.cjs.map} +1 -1
- package/dist/{chunk-ATUPB6MN.js → chunk-Q3P7Y5VO.js} +4 -4
- package/dist/{chunk-ATUPB6MN.js.map → chunk-Q3P7Y5VO.js.map} +1 -1
- package/dist/{chunk-6OC6MF3C.js → chunk-R2O6TTQS.js} +9 -20
- package/dist/{chunk-TO6EY4P7.cjs.map → chunk-R2O6TTQS.js.map} +1 -1
- package/dist/{chunk-PYVFXCSD.js → chunk-SUHGXAII.js} +2 -2
- package/dist/{chunk-PYVFXCSD.js.map → chunk-SUHGXAII.js.map} +1 -1
- package/dist/{chunk-3KYKEXV7.cjs → chunk-SY7CBACS.cjs} +10 -10
- package/dist/{chunk-3KYKEXV7.cjs.map → chunk-SY7CBACS.cjs.map} +1 -1
- package/dist/{chunk-TO6EY4P7.cjs → chunk-TV7LRFXH.cjs} +200 -211
- package/dist/{chunk-6OC6MF3C.js.map → chunk-TV7LRFXH.cjs.map} +1 -1
- package/dist/{chunk-F67UK75A.cjs → chunk-XGH2FVVR.cjs} +3 -3
- package/dist/{chunk-F67UK75A.cjs.map → chunk-XGH2FVVR.cjs.map} +1 -1
- package/dist/{chunk-IGADDMXH.js → chunk-XHBEFQJ3.js} +3 -3
- package/dist/{chunk-IGADDMXH.js.map → chunk-XHBEFQJ3.js.map} +1 -1
- package/dist/index.cjs +286 -254
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -15
- package/dist/index.js.map +1 -1
- package/dist/middleware.cjs +32 -32
- package/dist/middleware.js +3 -3
- package/dist/migrations-AFSCRO56.cjs +13 -0
- package/dist/{migrations-2XHQEGOQ.cjs.map → migrations-AFSCRO56.cjs.map} +1 -1
- package/dist/migrations-MLBACCPF.js +4 -0
- package/dist/{migrations-PE3CDVSM.js.map → migrations-MLBACCPF.js.map} +1 -1
- package/dist/plugins.cjs +40 -40
- package/dist/plugins.js +3 -3
- package/dist/routes.cjs +26 -26
- package/dist/routes.js +6 -6
- package/dist/services.cjs +18 -18
- package/dist/services.js +2 -2
- package/dist/utils.cjs +3 -3
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/migrations-2XHQEGOQ.cjs +0 -13
- package/dist/migrations-PE3CDVSM.js +0 -4
|
@@ -3,22 +3,21 @@
|
|
|
3
3
|
var chunkHIKBY7MS_cjs = require('./chunk-HIKBY7MS.cjs');
|
|
4
4
|
var chunkN32OWET6_cjs = require('./chunk-N32OWET6.cjs');
|
|
5
5
|
var chunk4BTBSXMR_cjs = require('./chunk-4BTBSXMR.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunkBYLQOBO6_cjs = require('./chunk-BYLQOBO6.cjs');
|
|
7
7
|
var chunk2CB4KY7I_cjs = require('./chunk-2CB4KY7I.cjs');
|
|
8
8
|
var chunkJEQ7FLOD_cjs = require('./chunk-JEQ7FLOD.cjs');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var chunkLLWLHFTD_cjs = require('./chunk-LLWLHFTD.cjs');
|
|
10
|
+
var chunkKI5KMJH2_cjs = require('./chunk-KI5KMJH2.cjs');
|
|
11
11
|
var chunkPXNTCCPE_cjs = require('./chunk-PXNTCCPE.cjs');
|
|
12
12
|
var chunkK623Q6WD_cjs = require('./chunk-K623Q6WD.cjs');
|
|
13
|
-
var
|
|
13
|
+
var chunkNYLWNR6T_cjs = require('./chunk-NYLWNR6T.cjs');
|
|
14
14
|
var chunkJ6JTWD2A_cjs = require('./chunk-J6JTWD2A.cjs');
|
|
15
15
|
var chunkIXUHXTHW_cjs = require('./chunk-IXUHXTHW.cjs');
|
|
16
16
|
var chunkRCQ2HIQD_cjs = require('./chunk-RCQ2HIQD.cjs');
|
|
17
|
-
var
|
|
17
|
+
var chunkXGH2FVVR_cjs = require('./chunk-XGH2FVVR.cjs');
|
|
18
18
|
var chunkMNWKYY5E_cjs = require('./chunk-MNWKYY5E.cjs');
|
|
19
19
|
var hono = require('hono');
|
|
20
20
|
var zod = require('zod');
|
|
21
|
-
var cors = require('hono/cors');
|
|
22
21
|
var cookie = require('hono/cookie');
|
|
23
22
|
var html = require('hono/html');
|
|
24
23
|
|
|
@@ -257,7 +256,7 @@ function getDocumentRequestContext(c) {
|
|
|
257
256
|
|
|
258
257
|
// src/routes/api-documents.ts
|
|
259
258
|
async function aclAllowsRead(db, tenantId, principalSet, row, preloadedType) {
|
|
260
|
-
const docType = preloadedType ?? await new
|
|
259
|
+
const docType = preloadedType ?? await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
261
260
|
if (!docType) return false;
|
|
262
261
|
return new DocumentRepository(db, tenantId).isAllowed(principalSet, row.root_id, "read", docType.settings);
|
|
263
262
|
}
|
|
@@ -275,7 +274,7 @@ apiDocumentsRoutes.get("/", async (c) => {
|
|
|
275
274
|
if (!typeId) {
|
|
276
275
|
return c.json({ error: "type query parameter is required" }, 400);
|
|
277
276
|
}
|
|
278
|
-
const registry = new
|
|
277
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
279
278
|
const docType = await registry.findById(typeId);
|
|
280
279
|
if (!docType || !docType.isActive) {
|
|
281
280
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -357,7 +356,7 @@ apiDocumentsRoutes.get("/root/:rootId", async (c) => {
|
|
|
357
356
|
AND (expires_at IS NULL OR expires_at > ?) LIMIT 1`
|
|
358
357
|
).bind(rootId, now, now).first();
|
|
359
358
|
if (!row) return c.json({ error: "Not found" }, 404);
|
|
360
|
-
const docType = await new
|
|
359
|
+
const docType = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
361
360
|
const effTenant = effectiveTenantForType(tenantId, docType?.settings);
|
|
362
361
|
if (row.tenant_id !== effTenant) return c.json({ error: "Not found" }, 404);
|
|
363
362
|
if (!await aclAllowsRead(db, effTenant, principalSet, row, docType)) {
|
|
@@ -393,7 +392,7 @@ apiDocumentsRoutes.get("/:id", async (c) => {
|
|
|
393
392
|
AND (expires_at IS NULL OR expires_at > ?) LIMIT 1`
|
|
394
393
|
).bind(id, now, now).first();
|
|
395
394
|
if (!row) return c.json({ error: "Not found" }, 404);
|
|
396
|
-
const docType = await new
|
|
395
|
+
const docType = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
397
396
|
const effTenant = effectiveTenantForType(tenantId, docType?.settings);
|
|
398
397
|
if (row.tenant_id !== effTenant) return c.json({ error: "Not found" }, 404);
|
|
399
398
|
if (!await aclAllowsRead(db, effTenant, principalSet, row, docType)) {
|
|
@@ -463,17 +462,17 @@ async function resolveDocScope(c, db, by, opts = {}) {
|
|
|
463
462
|
const draft = opts.currentDraftOnly ? " AND is_current_draft = 1" : "";
|
|
464
463
|
const row = await db.prepare(`SELECT type_id, root_id, tenant_id FROM documents WHERE ${col} = ?${draft} LIMIT 1`).bind(val).first();
|
|
465
464
|
if (!row) return null;
|
|
466
|
-
const docType = await new
|
|
465
|
+
const docType = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
467
466
|
const tenantId = effectiveTenantForType(getRequestTenant(c), docType?.settings);
|
|
468
467
|
if (row.tenant_id !== tenantId) return null;
|
|
469
468
|
return { typeId: row.type_id, rootId: row.root_id, tenantId, docType };
|
|
470
469
|
}
|
|
471
470
|
var adminDocumentsRoutes = new hono.Hono();
|
|
472
|
-
adminDocumentsRoutes.use("*",
|
|
473
|
-
adminDocumentsRoutes.use("*",
|
|
471
|
+
adminDocumentsRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
472
|
+
adminDocumentsRoutes.use("*", chunkBYLQOBO6_cjs.requireRole(["admin", "editor"]));
|
|
474
473
|
adminDocumentsRoutes.get("/types", async (c) => {
|
|
475
474
|
try {
|
|
476
|
-
const registry = new
|
|
475
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(c.env.DB);
|
|
477
476
|
const types = await registry.findAll();
|
|
478
477
|
return c.json({ data: types });
|
|
479
478
|
} catch (error) {
|
|
@@ -501,7 +500,7 @@ adminDocumentsRoutes.get("/", async (c) => {
|
|
|
501
500
|
if (!typeId) {
|
|
502
501
|
return c.json({ error: "type query parameter is required" }, 400);
|
|
503
502
|
}
|
|
504
|
-
const registry = new
|
|
503
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
505
504
|
const docType = await registry.findById(typeId);
|
|
506
505
|
if (!docType || !docType.isActive) {
|
|
507
506
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -612,7 +611,7 @@ adminDocumentsRoutes.post("/", async (c) => {
|
|
|
612
611
|
const input = validation.data;
|
|
613
612
|
const db = c.env.DB;
|
|
614
613
|
const user = c.get("user");
|
|
615
|
-
const registry = new
|
|
614
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
616
615
|
const docType = await registry.findById(input.typeId);
|
|
617
616
|
if (!docType || !docType.isActive) {
|
|
618
617
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -744,7 +743,7 @@ adminDocumentsRoutes.post("/types/:typeId/reindex", async (c) => {
|
|
|
744
743
|
try {
|
|
745
744
|
const { typeId } = c.req.param();
|
|
746
745
|
const db = c.env.DB;
|
|
747
|
-
const registry = new
|
|
746
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
748
747
|
const docType = await registry.findById(typeId);
|
|
749
748
|
if (!docType) return c.json({ error: "Unknown document type" }, 400);
|
|
750
749
|
const reindexTenant = effectiveTenantForType(getRequestTenant(c), docType.settings);
|
|
@@ -898,13 +897,13 @@ async function resolveContentVariables(contentData, db) {
|
|
|
898
897
|
// src/routes/api-content-crud.ts
|
|
899
898
|
var apiContentCrudRoutes = new hono.Hono();
|
|
900
899
|
async function resolveDocBacking(db, collectionIdOrName) {
|
|
901
|
-
const registry =
|
|
900
|
+
const registry = chunkLLWLHFTD_cjs.getCollectionRegistry();
|
|
902
901
|
const record = registry.getBySlugOrName(collectionIdOrName) ?? registry.getById(collectionIdOrName);
|
|
903
902
|
if (record) {
|
|
904
|
-
const docType2 = await new
|
|
903
|
+
const docType2 = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(record.name);
|
|
905
904
|
return docType2 ? { coll: { id: record.id, name: record.name }, docType: docType2 } : null;
|
|
906
905
|
}
|
|
907
|
-
const docType = await new
|
|
906
|
+
const docType = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(collectionIdOrName);
|
|
908
907
|
if (docType) {
|
|
909
908
|
return { coll: { id: collectionIdOrName, name: collectionIdOrName }, docType };
|
|
910
909
|
}
|
|
@@ -947,7 +946,7 @@ apiContentCrudRoutes.get("/check-slug", async (c) => {
|
|
|
947
946
|
}, 500);
|
|
948
947
|
}
|
|
949
948
|
});
|
|
950
|
-
apiContentCrudRoutes.get("/:id",
|
|
949
|
+
apiContentCrudRoutes.get("/:id", chunkBYLQOBO6_cjs.optionalAuth(), async (c) => {
|
|
951
950
|
try {
|
|
952
951
|
const id = c.req.param("id");
|
|
953
952
|
const db = c.env.DB;
|
|
@@ -957,7 +956,7 @@ apiContentCrudRoutes.get("/:id", chunkMUNO67TT_cjs.optionalAuth(), async (c) =>
|
|
|
957
956
|
).bind(id, getRequestTenant(c)).first();
|
|
958
957
|
let transformedContent;
|
|
959
958
|
if (docRow) {
|
|
960
|
-
const coll =
|
|
959
|
+
const coll = chunkLLWLHFTD_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
961
960
|
transformedContent = {
|
|
962
961
|
id: docRow.root_id,
|
|
963
962
|
title: docRow.title,
|
|
@@ -991,7 +990,7 @@ apiContentCrudRoutes.get("/:id", chunkMUNO67TT_cjs.optionalAuth(), async (c) =>
|
|
|
991
990
|
}, 500);
|
|
992
991
|
}
|
|
993
992
|
});
|
|
994
|
-
apiContentCrudRoutes.post("/",
|
|
993
|
+
apiContentCrudRoutes.post("/", chunkBYLQOBO6_cjs.requireAuth(), chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
995
994
|
try {
|
|
996
995
|
const db = c.env.DB;
|
|
997
996
|
const user = c.get("user");
|
|
@@ -1066,7 +1065,7 @@ apiContentCrudRoutes.post("/", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT_cj
|
|
|
1066
1065
|
}, 500);
|
|
1067
1066
|
}
|
|
1068
1067
|
});
|
|
1069
|
-
apiContentCrudRoutes.put("/:id",
|
|
1068
|
+
apiContentCrudRoutes.put("/:id", chunkBYLQOBO6_cjs.requireAuth(), chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
1070
1069
|
try {
|
|
1071
1070
|
const id = c.req.param("id");
|
|
1072
1071
|
const db = c.env.DB;
|
|
@@ -1088,7 +1087,7 @@ apiContentCrudRoutes.put("/:id", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT_
|
|
|
1088
1087
|
} catch (err) {
|
|
1089
1088
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
1090
1089
|
}
|
|
1091
|
-
const docType = await new
|
|
1090
|
+
const docType = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(docRow.type_id);
|
|
1092
1091
|
const svc = new chunk2CB4KY7I_cjs.DocumentsService(db, {
|
|
1093
1092
|
queryableFields: docType?.queryableFields ?? [],
|
|
1094
1093
|
typeSchemaVersion: docType?.schemaVersion ?? 1,
|
|
@@ -1111,7 +1110,7 @@ apiContentCrudRoutes.put("/:id", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT_
|
|
|
1111
1110
|
const cache = chunk4BTBSXMR_cjs.getCacheService(chunk4BTBSXMR_cjs.CACHE_CONFIGS.api);
|
|
1112
1111
|
await cache.invalidate("content-filtered:*");
|
|
1113
1112
|
await cache.invalidate("collection-content-filtered:*");
|
|
1114
|
-
const coll =
|
|
1113
|
+
const coll = chunkLLWLHFTD_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
1115
1114
|
const saved = await db.prepare("SELECT * FROM documents WHERE id = ?").bind(newDraft.id).first();
|
|
1116
1115
|
const savedData = saved?.data ? JSON.parse(saved.data) : {};
|
|
1117
1116
|
dispatchHookEvent(c, "content:after:update", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
@@ -1132,7 +1131,7 @@ apiContentCrudRoutes.put("/:id", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT_
|
|
|
1132
1131
|
}, 500);
|
|
1133
1132
|
}
|
|
1134
1133
|
});
|
|
1135
|
-
apiContentCrudRoutes.delete("/:id",
|
|
1134
|
+
apiContentCrudRoutes.delete("/:id", chunkBYLQOBO6_cjs.requireAuth(), chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
1136
1135
|
try {
|
|
1137
1136
|
const id = c.req.param("id");
|
|
1138
1137
|
const db = c.env.DB;
|
|
@@ -1258,20 +1257,10 @@ apiRoutes.use("*", async (c, next) => {
|
|
|
1258
1257
|
c.header("X-Response-Time", `${totalTime}ms`);
|
|
1259
1258
|
});
|
|
1260
1259
|
apiRoutes.use("*", async (c, next) => {
|
|
1261
|
-
const cacheEnabled = await
|
|
1260
|
+
const cacheEnabled = await chunkBYLQOBO6_cjs.isPluginActive(c.env.DB, "core-cache");
|
|
1262
1261
|
c.set("cacheEnabled", cacheEnabled);
|
|
1263
1262
|
await next();
|
|
1264
1263
|
});
|
|
1265
|
-
apiRoutes.use("*", cors.cors({
|
|
1266
|
-
origin: (origin, c) => {
|
|
1267
|
-
const allowed = c.env?.CORS_ORIGINS;
|
|
1268
|
-
if (!allowed) return null;
|
|
1269
|
-
const list = allowed.split(",").map((s) => s.trim());
|
|
1270
|
-
return list.includes(origin) ? origin : null;
|
|
1271
|
-
},
|
|
1272
|
-
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
1273
|
-
allowHeaders: ["Content-Type", "Authorization", "X-API-Key"]
|
|
1274
|
-
}));
|
|
1275
1264
|
function addTimingMeta(c, meta = {}, executionStartTime) {
|
|
1276
1265
|
const totalTime = Date.now() - c.get("startTime");
|
|
1277
1266
|
const executionTime = executionStartTime ? Date.now() - executionStartTime : void 0;
|
|
@@ -1291,7 +1280,7 @@ apiRoutes.get("/", (c) => {
|
|
|
1291
1280
|
openapi: "3.0.0",
|
|
1292
1281
|
info: {
|
|
1293
1282
|
title: "SonicJS AI API",
|
|
1294
|
-
version:
|
|
1283
|
+
version: chunkXGH2FVVR_cjs.getCoreVersion(),
|
|
1295
1284
|
description: "RESTful API for SonicJS headless CMS - a modern, AI-powered content management system built on Cloudflare Workers",
|
|
1296
1285
|
contact: {
|
|
1297
1286
|
name: "SonicJS Support",
|
|
@@ -1721,8 +1710,8 @@ apiRoutes.get("/collections", async (c) => {
|
|
|
1721
1710
|
}
|
|
1722
1711
|
c.header("X-Cache-Status", "MISS");
|
|
1723
1712
|
c.header("X-Cache-Source", "registry");
|
|
1724
|
-
const records =
|
|
1725
|
-
const transformedResults = records.map(
|
|
1713
|
+
const records = chunkLLWLHFTD_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
1714
|
+
const transformedResults = records.map(chunkLLWLHFTD_cjs.collectionRecordToRow);
|
|
1726
1715
|
const responseData = {
|
|
1727
1716
|
data: transformedResults,
|
|
1728
1717
|
meta: addTimingMeta(c, {
|
|
@@ -1743,7 +1732,7 @@ apiRoutes.get("/collections", async (c) => {
|
|
|
1743
1732
|
return c.json({ error: "Failed to fetch collections" }, 500);
|
|
1744
1733
|
}
|
|
1745
1734
|
});
|
|
1746
|
-
apiRoutes.get("/content",
|
|
1735
|
+
apiRoutes.get("/content", chunkBYLQOBO6_cjs.optionalAuth(), async (c) => {
|
|
1747
1736
|
const executionStart = Date.now();
|
|
1748
1737
|
try {
|
|
1749
1738
|
const db = c.env.DB;
|
|
@@ -1752,7 +1741,7 @@ apiRoutes.get("/content", chunkMUNO67TT_cjs.optionalAuth(), async (c) => {
|
|
|
1752
1741
|
const collIdByName = /* @__PURE__ */ new Map();
|
|
1753
1742
|
let typeId;
|
|
1754
1743
|
let typeIds;
|
|
1755
|
-
const registry =
|
|
1744
|
+
const registry = chunkLLWLHFTD_cjs.getCollectionRegistry();
|
|
1756
1745
|
if (queryParams.collection) {
|
|
1757
1746
|
const collectionName = queryParams.collection;
|
|
1758
1747
|
const record = registry.getByName(collectionName);
|
|
@@ -1851,13 +1840,13 @@ apiRoutes.get("/content", chunkMUNO67TT_cjs.optionalAuth(), async (c) => {
|
|
|
1851
1840
|
}, 500);
|
|
1852
1841
|
}
|
|
1853
1842
|
});
|
|
1854
|
-
apiRoutes.get("/collections/:collection/content",
|
|
1843
|
+
apiRoutes.get("/collections/:collection/content", chunkBYLQOBO6_cjs.optionalAuth(), async (c) => {
|
|
1855
1844
|
const executionStart = Date.now();
|
|
1856
1845
|
try {
|
|
1857
1846
|
const collection = c.req.param("collection");
|
|
1858
1847
|
const db = c.env.DB;
|
|
1859
1848
|
const queryParams = c.req.query();
|
|
1860
|
-
const record =
|
|
1849
|
+
const record = chunkLLWLHFTD_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
1861
1850
|
if (!record || record.isActive === false) {
|
|
1862
1851
|
return c.json({ error: "Collection not found" }, 404);
|
|
1863
1852
|
}
|
|
@@ -1913,7 +1902,7 @@ apiRoutes.get("/collections/:collection/content", chunkMUNO67TT_cjs.optionalAuth
|
|
|
1913
1902
|
const responseData = {
|
|
1914
1903
|
data: transformedResults,
|
|
1915
1904
|
meta: addTimingMeta(c, {
|
|
1916
|
-
...includeCollection ? { collection:
|
|
1905
|
+
...includeCollection ? { collection: chunkLLWLHFTD_cjs.collectionRecordToRow(record) } : {},
|
|
1917
1906
|
count: results.length,
|
|
1918
1907
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1919
1908
|
// D44: echo the caller's filter with the access policy applied (status=published forced for
|
|
@@ -1938,13 +1927,13 @@ apiRoutes.get("/collections/:collection/content", chunkMUNO67TT_cjs.optionalAuth
|
|
|
1938
1927
|
}
|
|
1939
1928
|
});
|
|
1940
1929
|
apiRoutes.route("/content", api_content_crud_default);
|
|
1941
|
-
apiRoutes.get("/:collection",
|
|
1930
|
+
apiRoutes.get("/:collection", chunkBYLQOBO6_cjs.optionalAuth(), async (c) => {
|
|
1942
1931
|
const executionStart = Date.now();
|
|
1943
1932
|
try {
|
|
1944
1933
|
const collection = c.req.param("collection");
|
|
1945
1934
|
const db = c.env.DB;
|
|
1946
1935
|
const queryParams = c.req.query();
|
|
1947
|
-
const record =
|
|
1936
|
+
const record = chunkLLWLHFTD_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
1948
1937
|
if (!record || record.isActive === false) {
|
|
1949
1938
|
return c.json({ error: "Collection not found" }, 404);
|
|
1950
1939
|
}
|
|
@@ -1984,7 +1973,7 @@ apiRoutes.get("/:collection", chunkMUNO67TT_cjs.optionalAuth(), async (c) => {
|
|
|
1984
1973
|
const responseData = {
|
|
1985
1974
|
data: transformedResults,
|
|
1986
1975
|
meta: addTimingMeta(c, {
|
|
1987
|
-
...includeCollection ? { collection:
|
|
1976
|
+
...includeCollection ? { collection: chunkLLWLHFTD_cjs.collectionRecordToRow(record) } : {},
|
|
1988
1977
|
count: results.length,
|
|
1989
1978
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1990
1979
|
filter: normalizePublicContentFilter(filter, role),
|
|
@@ -2002,12 +1991,12 @@ apiRoutes.get("/:collection", chunkMUNO67TT_cjs.optionalAuth(), async (c) => {
|
|
|
2002
1991
|
return c.json({ error: "Failed to fetch content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2003
1992
|
}
|
|
2004
1993
|
});
|
|
2005
|
-
apiRoutes.get("/:collection/:id",
|
|
1994
|
+
apiRoutes.get("/:collection/:id", chunkBYLQOBO6_cjs.optionalAuth(), async (c) => {
|
|
2006
1995
|
try {
|
|
2007
1996
|
const collection = c.req.param("collection");
|
|
2008
1997
|
const id = c.req.param("id");
|
|
2009
1998
|
const db = c.env.DB;
|
|
2010
|
-
const record =
|
|
1999
|
+
const record = chunkLLWLHFTD_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2011
2000
|
if (!record || record.isActive === false) {
|
|
2012
2001
|
return c.json({ error: "Collection not found" }, 404);
|
|
2013
2002
|
}
|
|
@@ -2016,7 +2005,7 @@ apiRoutes.get("/:collection/:id", chunkMUNO67TT_cjs.optionalAuth(), async (c) =>
|
|
|
2016
2005
|
privileged ? "SELECT * FROM documents WHERE root_id = ? AND type_id = ? AND tenant_id = 'default' AND is_current_draft = 1 AND deleted_at IS NULL" : "SELECT * FROM documents WHERE root_id = ? AND type_id = ? AND tenant_id = 'default' AND is_published = 1 AND deleted_at IS NULL"
|
|
2017
2006
|
).bind(id, record.name).first();
|
|
2018
2007
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
2019
|
-
const coll =
|
|
2008
|
+
const coll = chunkLLWLHFTD_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
2020
2009
|
const transformedContent = {
|
|
2021
2010
|
id: docRow.root_id,
|
|
2022
2011
|
title: docRow.title,
|
|
@@ -2034,7 +2023,7 @@ apiRoutes.get("/:collection/:id", chunkMUNO67TT_cjs.optionalAuth(), async (c) =>
|
|
|
2034
2023
|
return c.json({ error: "Failed to fetch content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2035
2024
|
}
|
|
2036
2025
|
});
|
|
2037
|
-
apiRoutes.post("/:collection",
|
|
2026
|
+
apiRoutes.post("/:collection", chunkBYLQOBO6_cjs.requireAuth(), chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2038
2027
|
try {
|
|
2039
2028
|
const collection = c.req.param("collection");
|
|
2040
2029
|
const db = c.env.DB;
|
|
@@ -2067,14 +2056,14 @@ apiRoutes.post("/:collection", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT_cj
|
|
|
2067
2056
|
return c.json({ error: "Failed to create content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2068
2057
|
}
|
|
2069
2058
|
});
|
|
2070
|
-
apiRoutes.put("/:collection/:id",
|
|
2059
|
+
apiRoutes.put("/:collection/:id", chunkBYLQOBO6_cjs.requireAuth(), chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2071
2060
|
try {
|
|
2072
2061
|
const collection = c.req.param("collection");
|
|
2073
2062
|
const id = c.req.param("id");
|
|
2074
2063
|
const db = c.env.DB;
|
|
2075
2064
|
const user = c.get("user");
|
|
2076
2065
|
const body = await c.req.json();
|
|
2077
|
-
const collRecord =
|
|
2066
|
+
const collRecord = chunkLLWLHFTD_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2078
2067
|
const typeName = collRecord?.name ?? collection;
|
|
2079
2068
|
const docRow = await db.prepare("SELECT root_id, type_id FROM documents WHERE root_id = ? AND type_id = ? AND tenant_id = 'default' AND is_current_draft = 1 AND deleted_at IS NULL").bind(id, typeName).first();
|
|
2080
2069
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
@@ -2086,7 +2075,7 @@ apiRoutes.put("/:collection/:id", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT
|
|
|
2086
2075
|
} catch (err) {
|
|
2087
2076
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
2088
2077
|
}
|
|
2089
|
-
const docType = await new
|
|
2078
|
+
const docType = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(docRow.type_id);
|
|
2090
2079
|
const svc = new chunk2CB4KY7I_cjs.DocumentsService(db, { queryableFields: docType?.queryableFields ?? [], typeSchemaVersion: docType?.schemaVersion ?? 1, maxVersionsPerRoot: docType?.settings?.maxVersionsPerRoot ?? 50, tenantId: "default", versioning: docType?.settings?.versioning ?? false });
|
|
2091
2080
|
const input = {};
|
|
2092
2081
|
if (body.title !== void 0) input.title = body.title;
|
|
@@ -2103,7 +2092,7 @@ apiRoutes.put("/:collection/:id", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT
|
|
|
2103
2092
|
const cache = chunk4BTBSXMR_cjs.getCacheService(chunk4BTBSXMR_cjs.CACHE_CONFIGS.api);
|
|
2104
2093
|
await cache.invalidate("content-filtered:*");
|
|
2105
2094
|
await cache.invalidate("collection-content-filtered:*");
|
|
2106
|
-
const coll =
|
|
2095
|
+
const coll = chunkLLWLHFTD_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
2107
2096
|
const saved = await db.prepare("SELECT * FROM documents WHERE id = ?").bind(newDraft.id).first();
|
|
2108
2097
|
const savedData = saved?.data ? JSON.parse(saved.data) : {};
|
|
2109
2098
|
dispatchHookEvent(c, "content:after:update", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
@@ -2115,13 +2104,13 @@ apiRoutes.put("/:collection/:id", chunkMUNO67TT_cjs.requireAuth(), chunkMUNO67TT
|
|
|
2115
2104
|
return c.json({ error: "Failed to update content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2116
2105
|
}
|
|
2117
2106
|
});
|
|
2118
|
-
apiRoutes.delete("/:collection/:id",
|
|
2107
|
+
apiRoutes.delete("/:collection/:id", chunkBYLQOBO6_cjs.requireAuth(), chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2119
2108
|
try {
|
|
2120
2109
|
const collection = c.req.param("collection");
|
|
2121
2110
|
const id = c.req.param("id");
|
|
2122
2111
|
const db = c.env.DB;
|
|
2123
2112
|
const user = c.get("user");
|
|
2124
|
-
const collRecord =
|
|
2113
|
+
const collRecord = chunkLLWLHFTD_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2125
2114
|
const typeName = collRecord?.name ?? collection;
|
|
2126
2115
|
const docRow = await db.prepare("SELECT type_id FROM documents WHERE root_id = ? AND type_id = ? AND tenant_id = 'default' AND deleted_at IS NULL LIMIT 1").bind(id, typeName).first();
|
|
2127
2116
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
@@ -2336,7 +2325,7 @@ var fileValidationSchema = zod.z.object({
|
|
|
2336
2325
|
// 50MB max
|
|
2337
2326
|
});
|
|
2338
2327
|
var apiMediaRoutes = new hono.Hono();
|
|
2339
|
-
apiMediaRoutes.use("*",
|
|
2328
|
+
apiMediaRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
2340
2329
|
apiMediaRoutes.post("/upload", async (c) => {
|
|
2341
2330
|
try {
|
|
2342
2331
|
const user = c.get("user");
|
|
@@ -3034,7 +3023,7 @@ apiSystemRoutes.get("/info", (c) => {
|
|
|
3034
3023
|
apiSystemRoutes.get("/stats", async (c) => {
|
|
3035
3024
|
try {
|
|
3036
3025
|
const db = c.env.DB;
|
|
3037
|
-
const typeIds =
|
|
3026
|
+
const typeIds = chunkLLWLHFTD_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal).map((r) => r.name);
|
|
3038
3027
|
let contentStats = null;
|
|
3039
3028
|
if (typeIds.length > 0) {
|
|
3040
3029
|
const placeholders = typeIds.map(() => "?").join(",");
|
|
@@ -3109,12 +3098,12 @@ apiSystemRoutes.get("/env", (c) => {
|
|
|
3109
3098
|
});
|
|
3110
3099
|
var api_system_default = apiSystemRoutes;
|
|
3111
3100
|
var adminApiRoutes = new hono.Hono();
|
|
3112
|
-
adminApiRoutes.use("*",
|
|
3113
|
-
adminApiRoutes.use("*",
|
|
3101
|
+
adminApiRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
3102
|
+
adminApiRoutes.use("*", chunkBYLQOBO6_cjs.requireRole(["admin", "editor"]));
|
|
3114
3103
|
adminApiRoutes.get("/stats", async (c) => {
|
|
3115
3104
|
try {
|
|
3116
3105
|
const db = c.env.DB;
|
|
3117
|
-
const userCollections =
|
|
3106
|
+
const userCollections = chunkLLWLHFTD_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
3118
3107
|
const collectionsCount = userCollections.length;
|
|
3119
3108
|
let contentCount = 0;
|
|
3120
3109
|
if (userCollections.length > 0) {
|
|
@@ -3205,7 +3194,7 @@ adminApiRoutes.get("/collections", async (c) => {
|
|
|
3205
3194
|
try {
|
|
3206
3195
|
const search = c.req.query("search") || "";
|
|
3207
3196
|
const includeInactive = c.req.query("includeInactive") === "true";
|
|
3208
|
-
let records =
|
|
3197
|
+
let records = chunkLLWLHFTD_cjs.getCollectionRegistry().list().filter((r) => !r.internal);
|
|
3209
3198
|
if (!includeInactive) records = records.filter((r) => r.isActive !== false);
|
|
3210
3199
|
if (search) {
|
|
3211
3200
|
const needle = search.toLowerCase();
|
|
@@ -3237,7 +3226,7 @@ adminApiRoutes.get("/collections", async (c) => {
|
|
|
3237
3226
|
adminApiRoutes.get("/collections/:id", async (c) => {
|
|
3238
3227
|
try {
|
|
3239
3228
|
const id = c.req.param("id");
|
|
3240
|
-
const registry =
|
|
3229
|
+
const registry = chunkLLWLHFTD_cjs.getCollectionRegistry();
|
|
3241
3230
|
const record = registry.getById(id) ?? registry.getByName(id);
|
|
3242
3231
|
if (!record) {
|
|
3243
3232
|
return c.json({ error: "Collection not found" }, 404);
|
|
@@ -3287,7 +3276,7 @@ adminApiRoutes.get("/references", async (c) => {
|
|
|
3287
3276
|
if (collectionParams.length === 0) {
|
|
3288
3277
|
return c.json({ error: "Collection is required" }, 400);
|
|
3289
3278
|
}
|
|
3290
|
-
const registry =
|
|
3279
|
+
const registry = chunkLLWLHFTD_cjs.getCollectionRegistry();
|
|
3291
3280
|
const matched = collectionParams.map((param) => registry.getById(param) ?? registry.getByName(param)).filter((r) => !!r);
|
|
3292
3281
|
const seen = /* @__PURE__ */ new Set();
|
|
3293
3282
|
const collections = matched.filter((r) => {
|
|
@@ -3402,7 +3391,7 @@ adminApiRoutes.patch("/collections/:id", collectionsReadOnly);
|
|
|
3402
3391
|
adminApiRoutes.delete("/collections/:id", collectionsReadOnly);
|
|
3403
3392
|
adminApiRoutes.get("/migrations/status", async (c) => {
|
|
3404
3393
|
try {
|
|
3405
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
3394
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-AFSCRO56.cjs');
|
|
3406
3395
|
const db = c.env.DB;
|
|
3407
3396
|
const migrationService = new MigrationService2(db);
|
|
3408
3397
|
const status = await migrationService.getMigrationStatus();
|
|
@@ -3445,7 +3434,7 @@ adminApiRoutes.post("/migrations/run", async (c) => {
|
|
|
3445
3434
|
});
|
|
3446
3435
|
adminApiRoutes.get("/migrations/validate", async (c) => {
|
|
3447
3436
|
try {
|
|
3448
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
3437
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-AFSCRO56.cjs');
|
|
3449
3438
|
const db = c.env.DB;
|
|
3450
3439
|
const migrationService = new MigrationService2(db);
|
|
3451
3440
|
const validation = await migrationService.validateSchema();
|
|
@@ -3860,7 +3849,7 @@ function renderRegisterPage(data) {
|
|
|
3860
3849
|
}
|
|
3861
3850
|
|
|
3862
3851
|
// src/services/email/email-service-singleton.ts
|
|
3863
|
-
var singleton =
|
|
3852
|
+
var singleton = chunkNYLWNR6T_cjs.createServiceSingleton("EmailService");
|
|
3864
3853
|
function setEmailService(service2) {
|
|
3865
3854
|
singleton.set(service2);
|
|
3866
3855
|
}
|
|
@@ -4668,7 +4657,7 @@ function getLexicalInitScript(settings = {}) {
|
|
|
4668
4657
|
</script>
|
|
4669
4658
|
`;
|
|
4670
4659
|
}
|
|
4671
|
-
var lexicalEditorPlugin =
|
|
4660
|
+
var lexicalEditorPlugin = chunkNYLWNR6T_cjs.definePlugin({
|
|
4672
4661
|
id: "lexical-editor",
|
|
4673
4662
|
version: "1.0.0",
|
|
4674
4663
|
name: "Lexical Editor",
|
|
@@ -6887,7 +6876,7 @@ api.put("/:userId", async (c) => {
|
|
|
6887
6876
|
await saveCustomData(db, userId, sanitized);
|
|
6888
6877
|
return c.json({ success: true });
|
|
6889
6878
|
});
|
|
6890
|
-
var userProfilesPlugin =
|
|
6879
|
+
var userProfilesPlugin = chunkNYLWNR6T_cjs.definePlugin({
|
|
6891
6880
|
id: "user-profiles",
|
|
6892
6881
|
version: "1.0.0",
|
|
6893
6882
|
name: "User Profiles",
|
|
@@ -6925,8 +6914,8 @@ function renderPasswordResetEmail(resetLink, firstName) {
|
|
|
6925
6914
|
async function setCsrfCookie(c, maxAge) {
|
|
6926
6915
|
const secret = c.env?.JWT_SECRET || JWT_SECRET_FALLBACK;
|
|
6927
6916
|
const isDev = c.env?.ENVIRONMENT === "development" || !c.env?.ENVIRONMENT;
|
|
6928
|
-
const csrfToken = await
|
|
6929
|
-
const cookieMaxAge = await
|
|
6917
|
+
const csrfToken = await chunkBYLQOBO6_cjs.generateCsrfToken(secret);
|
|
6918
|
+
const cookieMaxAge = await chunkBYLQOBO6_cjs.getJwtExpirySecondsFromDb(c.env?.DB, c.env);
|
|
6930
6919
|
cookie.setCookie(c, "csrf_token", csrfToken, {
|
|
6931
6920
|
httpOnly: false,
|
|
6932
6921
|
secure: !isDev,
|
|
@@ -6983,7 +6972,7 @@ var loginSchema = zod.z.object({
|
|
|
6983
6972
|
});
|
|
6984
6973
|
authRoutes.post(
|
|
6985
6974
|
"/register",
|
|
6986
|
-
|
|
6975
|
+
chunkBYLQOBO6_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "register" }),
|
|
6987
6976
|
async (c) => {
|
|
6988
6977
|
try {
|
|
6989
6978
|
const db = c.env.DB;
|
|
@@ -7019,7 +7008,7 @@ authRoutes.post(
|
|
|
7019
7008
|
if (existingUser) {
|
|
7020
7009
|
return c.json({ error: "User with this email already exists" }, 400);
|
|
7021
7010
|
}
|
|
7022
|
-
const passwordHash = await
|
|
7011
|
+
const passwordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(password);
|
|
7023
7012
|
const userId = crypto.randomUUID();
|
|
7024
7013
|
const now = /* @__PURE__ */ new Date();
|
|
7025
7014
|
const nowSec = Math.floor(now.getTime() / 1e3);
|
|
@@ -7052,8 +7041,8 @@ authRoutes.post(
|
|
|
7052
7041
|
{ user: { id: userId, email: normalizedEmail, role: "viewer" } },
|
|
7053
7042
|
"fire-and-forget"
|
|
7054
7043
|
);
|
|
7055
|
-
const tokenTtl = await
|
|
7056
|
-
const token = await
|
|
7044
|
+
const tokenTtl = await chunkBYLQOBO6_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7045
|
+
const token = await chunkBYLQOBO6_cjs.AuthManager.generateToken(userId, normalizedEmail, "viewer", c.env.JWT_SECRET, tokenTtl);
|
|
7057
7046
|
cookie.setCookie(c, "auth_token", token, {
|
|
7058
7047
|
httpOnly: true,
|
|
7059
7048
|
secure: true,
|
|
@@ -7085,7 +7074,7 @@ authRoutes.post(
|
|
|
7085
7074
|
);
|
|
7086
7075
|
authRoutes.post(
|
|
7087
7076
|
"/login",
|
|
7088
|
-
|
|
7077
|
+
chunkBYLQOBO6_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "login" }),
|
|
7089
7078
|
async (c) => {
|
|
7090
7079
|
try {
|
|
7091
7080
|
const body = await c.req.json();
|
|
@@ -7164,7 +7153,7 @@ authRoutes.get("/logout", async (c) => {
|
|
|
7164
7153
|
clearCsrfCookie(c);
|
|
7165
7154
|
return c.redirect("/auth/login?message=You have been logged out successfully");
|
|
7166
7155
|
});
|
|
7167
|
-
authRoutes.get("/me",
|
|
7156
|
+
authRoutes.get("/me", chunkBYLQOBO6_cjs.requireAuth(), async (c) => {
|
|
7168
7157
|
try {
|
|
7169
7158
|
const user = c.get("user");
|
|
7170
7159
|
if (!user) {
|
|
@@ -7184,7 +7173,7 @@ authRoutes.get("/me", chunkMUNO67TT_cjs.requireAuth(), async (c) => {
|
|
|
7184
7173
|
});
|
|
7185
7174
|
authRoutes.post(
|
|
7186
7175
|
"/refresh",
|
|
7187
|
-
|
|
7176
|
+
chunkBYLQOBO6_cjs.rateLimit({ max: 60, windowMs: 60 * 1e3, keyPrefix: "refresh" }),
|
|
7188
7177
|
async (c) => {
|
|
7189
7178
|
try {
|
|
7190
7179
|
let token = c.req.header("Authorization")?.replace("Bearer ", "");
|
|
@@ -7193,8 +7182,8 @@ authRoutes.post(
|
|
|
7193
7182
|
return c.json({ error: "Authentication required" }, 401);
|
|
7194
7183
|
}
|
|
7195
7184
|
const db = c.env.DB;
|
|
7196
|
-
const grace = await
|
|
7197
|
-
const payload = await
|
|
7185
|
+
const grace = await chunkBYLQOBO6_cjs.getJwtRefreshGraceSecondsFromDb(db, c.env);
|
|
7186
|
+
const payload = await chunkBYLQOBO6_cjs.AuthManager.verifyToken(token, c.env.JWT_SECRET, grace);
|
|
7198
7187
|
if (!payload) {
|
|
7199
7188
|
return c.json({ error: "Invalid or expired token" }, 401);
|
|
7200
7189
|
}
|
|
@@ -7202,8 +7191,8 @@ authRoutes.post(
|
|
|
7202
7191
|
if (!row || !row.is_active) {
|
|
7203
7192
|
return c.json({ error: "User is not active" }, 401);
|
|
7204
7193
|
}
|
|
7205
|
-
const tokenTtl = await
|
|
7206
|
-
const newToken = await
|
|
7194
|
+
const tokenTtl = await chunkBYLQOBO6_cjs.getJwtExpirySecondsFromDb(db, c.env);
|
|
7195
|
+
const newToken = await chunkBYLQOBO6_cjs.AuthManager.generateToken(row.id, row.email, row.role, c.env.JWT_SECRET, tokenTtl);
|
|
7207
7196
|
cookie.setCookie(c, "auth_token", newToken, {
|
|
7208
7197
|
httpOnly: true,
|
|
7209
7198
|
secure: true,
|
|
@@ -7223,7 +7212,7 @@ authRoutes.post(
|
|
|
7223
7212
|
);
|
|
7224
7213
|
authRoutes.post(
|
|
7225
7214
|
"/register/form",
|
|
7226
|
-
|
|
7215
|
+
chunkBYLQOBO6_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "register" }),
|
|
7227
7216
|
async (c) => {
|
|
7228
7217
|
try {
|
|
7229
7218
|
const db = c.env.DB;
|
|
@@ -7268,7 +7257,7 @@ authRoutes.post(
|
|
|
7268
7257
|
</div>
|
|
7269
7258
|
`);
|
|
7270
7259
|
}
|
|
7271
|
-
const passwordHash = await
|
|
7260
|
+
const passwordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(password);
|
|
7272
7261
|
const role = isFirstUser ? "admin" : "viewer";
|
|
7273
7262
|
const userId = crypto.randomUUID();
|
|
7274
7263
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -7310,8 +7299,8 @@ authRoutes.post(
|
|
|
7310
7299
|
{ user: { id: userId, email: normalizedEmail, role } },
|
|
7311
7300
|
"fire-and-forget"
|
|
7312
7301
|
);
|
|
7313
|
-
const tokenTtl = await
|
|
7314
|
-
const token = await
|
|
7302
|
+
const tokenTtl = await chunkBYLQOBO6_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7303
|
+
const token = await chunkBYLQOBO6_cjs.AuthManager.generateToken(userId, normalizedEmail, role, c.env.JWT_SECRET, tokenTtl);
|
|
7315
7304
|
cookie.setCookie(c, "auth_token", token, {
|
|
7316
7305
|
httpOnly: true,
|
|
7317
7306
|
secure: false,
|
|
@@ -7343,7 +7332,7 @@ authRoutes.post(
|
|
|
7343
7332
|
);
|
|
7344
7333
|
authRoutes.post(
|
|
7345
7334
|
"/login/form",
|
|
7346
|
-
|
|
7335
|
+
chunkBYLQOBO6_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "login" }),
|
|
7347
7336
|
async (c) => {
|
|
7348
7337
|
try {
|
|
7349
7338
|
const formData = await c.req.formData();
|
|
@@ -7410,14 +7399,14 @@ authRoutes.post(
|
|
|
7410
7399
|
);
|
|
7411
7400
|
authRoutes.post(
|
|
7412
7401
|
"/seed-admin",
|
|
7413
|
-
|
|
7402
|
+
chunkBYLQOBO6_cjs.rateLimit({ max: 10, windowMs: 60 * 1e3, keyPrefix: "seed-admin" }),
|
|
7414
7403
|
async (c) => {
|
|
7415
7404
|
try {
|
|
7416
7405
|
const db = c.env.DB;
|
|
7417
7406
|
const rbac = new chunk2CB4KY7I_cjs.RbacService(db);
|
|
7418
7407
|
const results = [];
|
|
7419
7408
|
const upsertSeedUser = async (opts) => {
|
|
7420
|
-
const passwordHash = await
|
|
7409
|
+
const passwordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(opts.password);
|
|
7421
7410
|
const nowMs = Date.now();
|
|
7422
7411
|
const nowSec = Math.floor(nowMs / 1e3);
|
|
7423
7412
|
const existing = await db.prepare("SELECT id FROM auth_user WHERE email = ?").bind(opts.email).first();
|
|
@@ -7642,7 +7631,7 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7642
7631
|
if (invitationAge > maxAge) {
|
|
7643
7632
|
return c.json({ error: "Invitation has expired" }, 400);
|
|
7644
7633
|
}
|
|
7645
|
-
const passwordHash = await
|
|
7634
|
+
const passwordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(password);
|
|
7646
7635
|
const updateStmt = db.prepare(`
|
|
7647
7636
|
UPDATE auth_user SET
|
|
7648
7637
|
password_hash = ?,
|
|
@@ -7659,8 +7648,8 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7659
7648
|
Date.now(),
|
|
7660
7649
|
invitedUser.id
|
|
7661
7650
|
).run();
|
|
7662
|
-
const tokenTtl = await
|
|
7663
|
-
const authToken = await
|
|
7651
|
+
const tokenTtl = await chunkBYLQOBO6_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7652
|
+
const authToken = await chunkBYLQOBO6_cjs.AuthManager.generateToken(invitedUser.id, invitedUser.email, invitedUser.role, c.env.JWT_SECRET, tokenTtl);
|
|
7664
7653
|
cookie.setCookie(c, "auth_token", authToken, {
|
|
7665
7654
|
httpOnly: true,
|
|
7666
7655
|
secure: true,
|
|
@@ -7676,7 +7665,7 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7676
7665
|
});
|
|
7677
7666
|
authRoutes.post(
|
|
7678
7667
|
"/request-password-reset",
|
|
7679
|
-
|
|
7668
|
+
chunkBYLQOBO6_cjs.rateLimit({ max: 3, windowMs: 15 * 60 * 1e3, keyPrefix: "password-reset" }),
|
|
7680
7669
|
async (c) => {
|
|
7681
7670
|
try {
|
|
7682
7671
|
const formData = await c.req.formData();
|
|
@@ -7913,7 +7902,7 @@ authRoutes.post("/reset-password", async (c) => {
|
|
|
7913
7902
|
if (Date.now() > user.password_reset_expires) {
|
|
7914
7903
|
return c.json({ error: "Reset token has expired" }, 400);
|
|
7915
7904
|
}
|
|
7916
|
-
const newPasswordHash = await
|
|
7905
|
+
const newPasswordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(password);
|
|
7917
7906
|
try {
|
|
7918
7907
|
const historyStmt = db.prepare(`
|
|
7919
7908
|
INSERT INTO auth_password_history (id, user_id, password_hash, created_at)
|
|
@@ -8127,7 +8116,7 @@ app.post("/test-seed-defaults", async (c) => {
|
|
|
8127
8116
|
var test_cleanup_default = app;
|
|
8128
8117
|
|
|
8129
8118
|
// src/plugins/available/easy-mdx/index.ts
|
|
8130
|
-
|
|
8119
|
+
chunkNYLWNR6T_cjs.definePlugin({
|
|
8131
8120
|
id: "easy-mdx",
|
|
8132
8121
|
version: "1.0.0",
|
|
8133
8122
|
name: "EasyMDE Markdown Editor",
|
|
@@ -8327,7 +8316,7 @@ function getMDXEditorInitScript(config) {
|
|
|
8327
8316
|
}
|
|
8328
8317
|
|
|
8329
8318
|
// src/plugins/available/tinymce-plugin/index.ts
|
|
8330
|
-
|
|
8319
|
+
chunkNYLWNR6T_cjs.definePlugin({
|
|
8331
8320
|
id: "tinymce-plugin",
|
|
8332
8321
|
version: "1.0.0",
|
|
8333
8322
|
name: "TinyMCE",
|
|
@@ -8597,7 +8586,7 @@ function getQuillCDN(version = "2.0.2") {
|
|
|
8597
8586
|
</style>
|
|
8598
8587
|
`;
|
|
8599
8588
|
}
|
|
8600
|
-
|
|
8589
|
+
chunkNYLWNR6T_cjs.definePlugin({
|
|
8601
8590
|
id: "quill-editor",
|
|
8602
8591
|
version: "1.0.0",
|
|
8603
8592
|
name: "Quill Editor",
|
|
@@ -11171,7 +11160,7 @@ function extractFieldData(fields, formData, options = {}) {
|
|
|
11171
11160
|
}
|
|
11172
11161
|
return { data, errors };
|
|
11173
11162
|
}
|
|
11174
|
-
adminContentRoutes.use("*",
|
|
11163
|
+
adminContentRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
11175
11164
|
async function getCollectionFields(db, collectionId) {
|
|
11176
11165
|
console.log(`[getCollectionFields] Loading fields for collection: ${collectionId}`);
|
|
11177
11166
|
const collectionStmt = db.prepare("SELECT schema, queryable_fields FROM document_types WHERE id = ?");
|
|
@@ -11198,7 +11187,7 @@ async function getCollectionFields(db, collectionId) {
|
|
|
11198
11187
|
};
|
|
11199
11188
|
});
|
|
11200
11189
|
}
|
|
11201
|
-
const codeCollections2 = await
|
|
11190
|
+
const codeCollections2 = await chunkLLWLHFTD_cjs.loadCollectionConfigs();
|
|
11202
11191
|
const codeMatch = codeCollections2.find((c) => c.name === collectionId);
|
|
11203
11192
|
if (codeMatch && codeMatch.schema?.properties) {
|
|
11204
11193
|
console.log(`[getCollectionFields] DB doc type has no properties \u2014 using code collection schema`);
|
|
@@ -11230,7 +11219,7 @@ async function getCollectionFields(db, collectionId) {
|
|
|
11230
11219
|
}
|
|
11231
11220
|
}
|
|
11232
11221
|
console.log(`[getCollectionFields] Not in database, checking code collections`);
|
|
11233
|
-
const codeCollections = await
|
|
11222
|
+
const codeCollections = await chunkLLWLHFTD_cjs.loadCollectionConfigs();
|
|
11234
11223
|
console.log(`[getCollectionFields] Found ${codeCollections.length} code collections`);
|
|
11235
11224
|
const codeCollection = codeCollections.find((c) => c.name === collectionId);
|
|
11236
11225
|
if (codeCollection && codeCollection.schema) {
|
|
@@ -11284,7 +11273,7 @@ async function getCollection(db, collectionId) {
|
|
|
11284
11273
|
};
|
|
11285
11274
|
}
|
|
11286
11275
|
console.log(`[getCollection] Not in database, checking code collections`);
|
|
11287
|
-
const codeCollections = await
|
|
11276
|
+
const codeCollections = await chunkLLWLHFTD_cjs.loadCollectionConfigs();
|
|
11288
11277
|
const codeCollection = codeCollections.find((c) => c.name === collectionId);
|
|
11289
11278
|
if (codeCollection) {
|
|
11290
11279
|
console.log(`[getCollection] Found code collection: ${collectionId}`);
|
|
@@ -11303,7 +11292,7 @@ async function getCollection(db, collectionId) {
|
|
|
11303
11292
|
}
|
|
11304
11293
|
async function getDocBackingType(db, collectionName) {
|
|
11305
11294
|
if (!collectionName) return null;
|
|
11306
|
-
const dt = await new
|
|
11295
|
+
const dt = await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db).findById(collectionName);
|
|
11307
11296
|
return dt && dt.isActive ? dt : null;
|
|
11308
11297
|
}
|
|
11309
11298
|
async function getCollectionByName(db, name) {
|
|
@@ -11320,7 +11309,7 @@ async function getCollectionByName(db, name) {
|
|
|
11320
11309
|
};
|
|
11321
11310
|
}
|
|
11322
11311
|
console.log(`[getCollectionByName] Not in database, checking code collections`);
|
|
11323
|
-
const codeCollections = await
|
|
11312
|
+
const codeCollections = await chunkLLWLHFTD_cjs.loadCollectionConfigs();
|
|
11324
11313
|
const codeCollection = codeCollections.find((c) => c.name === name);
|
|
11325
11314
|
if (codeCollection) {
|
|
11326
11315
|
console.log(`[getCollectionByName] Found code collection: ${name}`);
|
|
@@ -11336,7 +11325,7 @@ async function getCollectionByName(db, name) {
|
|
|
11336
11325
|
return null;
|
|
11337
11326
|
}
|
|
11338
11327
|
async function loadContentEditorFlags(db) {
|
|
11339
|
-
const flags = { workflowEnabled: await
|
|
11328
|
+
const flags = { workflowEnabled: await chunkBYLQOBO6_cjs.isPluginActive(db, "workflow") };
|
|
11340
11329
|
const editors = [
|
|
11341
11330
|
["tinymce-plugin", "tinymce"],
|
|
11342
11331
|
["quill-editor", "quill"],
|
|
@@ -11344,10 +11333,10 @@ async function loadContentEditorFlags(db) {
|
|
|
11344
11333
|
["lexical-editor", "lexical"]
|
|
11345
11334
|
];
|
|
11346
11335
|
for (const [plugin, key] of editors) {
|
|
11347
|
-
const enabled = await
|
|
11336
|
+
const enabled = await chunkBYLQOBO6_cjs.isPluginActive(db, plugin);
|
|
11348
11337
|
flags[`${key}Enabled`] = enabled;
|
|
11349
11338
|
if (enabled) {
|
|
11350
|
-
const ps = new
|
|
11339
|
+
const ps = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11351
11340
|
const p = await ps.getPlugin(plugin);
|
|
11352
11341
|
flags[`${key}Settings`] = p?.settings;
|
|
11353
11342
|
}
|
|
@@ -11383,9 +11372,9 @@ adminContentRoutes.get("/", async (c) => {
|
|
|
11383
11372
|
const offset = (page - 1) * limit;
|
|
11384
11373
|
const collectionsStmt = db.prepare("SELECT id, name, display_name FROM document_types WHERE is_active = 1 ORDER BY display_name");
|
|
11385
11374
|
const { results: collectionsResults } = await collectionsStmt.all();
|
|
11386
|
-
const codeCollections = await
|
|
11375
|
+
const codeCollections = await chunkLLWLHFTD_cjs.loadCollectionConfigs();
|
|
11387
11376
|
const codeCollectionMap = new Map(codeCollections.map((c2) => [c2.name, c2]));
|
|
11388
|
-
const docTypeRegistry = new
|
|
11377
|
+
const docTypeRegistry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
11389
11378
|
const docTypes = (await docTypeRegistry.findAll()).filter((dt) => !dt.settings?.internal && !dt.isAuth);
|
|
11390
11379
|
const visibleTypeIds = new Set(docTypes.map((dt) => dt.id));
|
|
11391
11380
|
const allCollections = [
|
|
@@ -11397,7 +11386,7 @@ adminContentRoutes.get("/", async (c) => {
|
|
|
11397
11386
|
...allCollections.map((c2) => ({ name: c2.name, displayName: c2.displayName })),
|
|
11398
11387
|
...docTypes.filter((dt) => !collectionNames.has(dt.id)).map((dt) => ({ name: `doc:${dt.id}`, displayName: dt.displayName }))
|
|
11399
11388
|
];
|
|
11400
|
-
const newContentCollections = await
|
|
11389
|
+
const newContentCollections = await chunkLLWLHFTD_cjs.getVisibleCollections(db);
|
|
11401
11390
|
const docBackedCollection = !modelName.startsWith("doc:") && modelName !== "all" ? docTypes.find((dt) => dt.id === modelName) : void 0;
|
|
11402
11391
|
const isDocModel = modelName.startsWith("doc:") || !!docBackedCollection;
|
|
11403
11392
|
if (isDocModel) {
|
|
@@ -11674,9 +11663,9 @@ adminContentRoutes.get("/new", async (c) => {
|
|
|
11674
11663
|
const collectionsStmt = db2.prepare("SELECT id, name, display_name, description FROM document_types WHERE is_active = 1 ORDER BY display_name");
|
|
11675
11664
|
const { results } = await collectionsStmt.all();
|
|
11676
11665
|
const visibleTypeIds = new Set(
|
|
11677
|
-
(await new
|
|
11666
|
+
(await new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db2).findAll()).filter((dt) => !dt.settings?.internal && !dt.isAuth).map((dt) => dt.id)
|
|
11678
11667
|
);
|
|
11679
|
-
const codeCollections = await
|
|
11668
|
+
const codeCollections = await chunkLLWLHFTD_cjs.loadCollectionConfigs();
|
|
11680
11669
|
const dbCollectionNames = new Set((results || []).map((r) => r.name));
|
|
11681
11670
|
const allCollections = [
|
|
11682
11671
|
...codeCollections.filter((c2) => !dbCollectionNames.has(c2.name)).map((c2) => ({
|
|
@@ -11742,32 +11731,32 @@ adminContentRoutes.get("/new", async (c) => {
|
|
|
11742
11731
|
return c.html(renderContentFormPage(formData2));
|
|
11743
11732
|
}
|
|
11744
11733
|
const fields = await getCollectionFields(db, collection.id);
|
|
11745
|
-
const workflowEnabled = await
|
|
11746
|
-
const tinymceEnabled = await
|
|
11734
|
+
const workflowEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "workflow");
|
|
11735
|
+
const tinymceEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "tinymce-plugin");
|
|
11747
11736
|
let tinymceSettings;
|
|
11748
11737
|
if (tinymceEnabled) {
|
|
11749
|
-
const pluginService = new
|
|
11738
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11750
11739
|
const tinymcePlugin2 = await pluginService.getPlugin("tinymce-plugin");
|
|
11751
11740
|
tinymceSettings = tinymcePlugin2?.settings;
|
|
11752
11741
|
}
|
|
11753
|
-
const quillEnabled = await
|
|
11742
|
+
const quillEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "quill-editor");
|
|
11754
11743
|
let quillSettings;
|
|
11755
11744
|
if (quillEnabled) {
|
|
11756
|
-
const pluginService = new
|
|
11745
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11757
11746
|
const quillPlugin = await pluginService.getPlugin("quill-editor");
|
|
11758
11747
|
quillSettings = quillPlugin?.settings;
|
|
11759
11748
|
}
|
|
11760
|
-
const mdxeditorEnabled = await
|
|
11749
|
+
const mdxeditorEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "easy-mdx");
|
|
11761
11750
|
let mdxeditorSettings;
|
|
11762
11751
|
if (mdxeditorEnabled) {
|
|
11763
|
-
const pluginService = new
|
|
11752
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11764
11753
|
const mdxeditorPlugin = await pluginService.getPlugin("easy-mdx");
|
|
11765
11754
|
mdxeditorSettings = mdxeditorPlugin?.settings;
|
|
11766
11755
|
}
|
|
11767
|
-
const lexicalEnabled = await
|
|
11756
|
+
const lexicalEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "lexical-editor");
|
|
11768
11757
|
let lexicalSettings;
|
|
11769
11758
|
if (lexicalEnabled) {
|
|
11770
|
-
const pluginService = new
|
|
11759
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11771
11760
|
const lexicalPlugin = await pluginService.getPlugin("lexical-editor");
|
|
11772
11761
|
lexicalSettings = lexicalPlugin?.settings;
|
|
11773
11762
|
}
|
|
@@ -11895,32 +11884,32 @@ adminContentRoutes.get("/:id/edit", async (c) => {
|
|
|
11895
11884
|
};
|
|
11896
11885
|
const fields = await getCollectionFields(db, content.collection_id);
|
|
11897
11886
|
const contentData = content.data ? JSON.parse(content.data) : {};
|
|
11898
|
-
const workflowEnabled = await
|
|
11899
|
-
const tinymceEnabled = await
|
|
11887
|
+
const workflowEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "workflow");
|
|
11888
|
+
const tinymceEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "tinymce-plugin");
|
|
11900
11889
|
let tinymceSettings;
|
|
11901
11890
|
if (tinymceEnabled) {
|
|
11902
|
-
const pluginService = new
|
|
11891
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11903
11892
|
const tinymcePlugin2 = await pluginService.getPlugin("tinymce-plugin");
|
|
11904
11893
|
tinymceSettings = tinymcePlugin2?.settings;
|
|
11905
11894
|
}
|
|
11906
|
-
const quillEnabled = await
|
|
11895
|
+
const quillEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "quill-editor");
|
|
11907
11896
|
let quillSettings;
|
|
11908
11897
|
if (quillEnabled) {
|
|
11909
|
-
const pluginService = new
|
|
11898
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11910
11899
|
const quillPlugin = await pluginService.getPlugin("quill-editor");
|
|
11911
11900
|
quillSettings = quillPlugin?.settings;
|
|
11912
11901
|
}
|
|
11913
|
-
const mdxeditorEnabled = await
|
|
11902
|
+
const mdxeditorEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "easy-mdx");
|
|
11914
11903
|
let mdxeditorSettings;
|
|
11915
11904
|
if (mdxeditorEnabled) {
|
|
11916
|
-
const pluginService = new
|
|
11905
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11917
11906
|
const mdxeditorPlugin = await pluginService.getPlugin("easy-mdx");
|
|
11918
11907
|
mdxeditorSettings = mdxeditorPlugin?.settings;
|
|
11919
11908
|
}
|
|
11920
|
-
const lexicalEnabled = await
|
|
11909
|
+
const lexicalEnabled = await chunkBYLQOBO6_cjs.isPluginActive(db, "lexical-editor");
|
|
11921
11910
|
let lexicalSettings;
|
|
11922
11911
|
if (lexicalEnabled) {
|
|
11923
|
-
const pluginService = new
|
|
11912
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
11924
11913
|
const lexicalPlugin = await pluginService.getPlugin("lexical-editor");
|
|
11925
11914
|
lexicalSettings = lexicalPlugin?.settings;
|
|
11926
11915
|
}
|
|
@@ -12293,7 +12282,7 @@ adminContentRoutes.put("/:id", async (c) => {
|
|
|
12293
12282
|
`);
|
|
12294
12283
|
}
|
|
12295
12284
|
});
|
|
12296
|
-
adminContentRoutes.post("/preview",
|
|
12285
|
+
adminContentRoutes.post("/preview", chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
12297
12286
|
try {
|
|
12298
12287
|
const formData = await c.req.formData();
|
|
12299
12288
|
const collectionId = formData.get("collection_id");
|
|
@@ -12612,7 +12601,7 @@ adminContentRoutes.delete("/:id", async (c) => {
|
|
|
12612
12601
|
return c.json({ success: false, error: "Failed to delete content" }, 500);
|
|
12613
12602
|
}
|
|
12614
12603
|
});
|
|
12615
|
-
adminContentRoutes.get("/:id/version/:version/preview",
|
|
12604
|
+
adminContentRoutes.get("/:id/version/:version/preview", chunkBYLQOBO6_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
12616
12605
|
try {
|
|
12617
12606
|
const id = c.req.param("id");
|
|
12618
12607
|
const version = parseInt(c.req.param("version") || "0");
|
|
@@ -12708,7 +12697,7 @@ function parseDocFormData(formData, queryableFields = []) {
|
|
|
12708
12697
|
return { title, slug, data };
|
|
12709
12698
|
}
|
|
12710
12699
|
async function getDocService(db, typeId, tenantId) {
|
|
12711
|
-
const registry = new
|
|
12700
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
12712
12701
|
const docType = await registry.findById(typeId);
|
|
12713
12702
|
const svc = new chunk2CB4KY7I_cjs.DocumentsService(db, {
|
|
12714
12703
|
queryableFields: docType?.queryableFields ?? [],
|
|
@@ -12721,7 +12710,7 @@ async function getDocService(db, typeId, tenantId) {
|
|
|
12721
12710
|
}
|
|
12722
12711
|
adminContentRoutes.get("/documents/:typeId/new", async (c) => {
|
|
12723
12712
|
const { typeId } = c.req.param();
|
|
12724
|
-
const registry = new
|
|
12713
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(c.env.DB);
|
|
12725
12714
|
const docType = await registry.findById(typeId);
|
|
12726
12715
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12727
12716
|
return c.html(chunkN32OWET6_cjs.renderDocumentFormPage({ docType, isEdit: false, user: userCtx(c) }));
|
|
@@ -12746,7 +12735,7 @@ adminContentRoutes.post("/documents/:typeId/new", async (c) => {
|
|
|
12746
12735
|
}), user?.userId);
|
|
12747
12736
|
return c.redirect(`/admin/content/documents/${typeId}/${doc.rootId}/edit?message=Created+successfully`);
|
|
12748
12737
|
} catch (err) {
|
|
12749
|
-
const registry = new
|
|
12738
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(c.env.DB);
|
|
12750
12739
|
const docType = await registry.findById(typeId);
|
|
12751
12740
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12752
12741
|
return c.html(chunkN32OWET6_cjs.renderDocumentFormPage({ docType, isEdit: false, user: userCtx(c), message: err?.message ?? "Failed to create", messageType: "error" }));
|
|
@@ -12756,7 +12745,7 @@ adminContentRoutes.get("/documents/:typeId/:rootId/edit", async (c) => {
|
|
|
12756
12745
|
const { typeId, rootId } = c.req.param();
|
|
12757
12746
|
const db = c.env.DB;
|
|
12758
12747
|
const message = c.req.query("message");
|
|
12759
|
-
const registry = new
|
|
12748
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
12760
12749
|
const docType = await registry.findById(typeId);
|
|
12761
12750
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12762
12751
|
const tenantId = reqTenant(c);
|
|
@@ -12869,7 +12858,7 @@ adminContentRoutes.get("/documents/:typeId/:rootId/versions", async (c) => {
|
|
|
12869
12858
|
const { typeId, rootId } = c.req.param();
|
|
12870
12859
|
const db = c.env.DB;
|
|
12871
12860
|
const { renderVersionHistoryFragment } = await import('./admin-documents-form.template-LSZKGA5J.cjs');
|
|
12872
|
-
const registry = new
|
|
12861
|
+
const registry = new chunkBYLQOBO6_cjs.DocumentTypeRegistry(db);
|
|
12873
12862
|
const docType = await registry.findById(typeId);
|
|
12874
12863
|
if (!docType) return c.html("<div>Unknown type.</div>", 404);
|
|
12875
12864
|
const result = await db.prepare(
|
|
@@ -14801,7 +14790,7 @@ var TenantService = class {
|
|
|
14801
14790
|
SET name = ?, domain = ?, status = ?, notes = ?, updated_at = ?
|
|
14802
14791
|
WHERE slug = ?
|
|
14803
14792
|
`).bind(name, domain, status, notes, now, slug).run();
|
|
14804
|
-
|
|
14793
|
+
chunkLLWLHFTD_cjs.invalidateTenantCache();
|
|
14805
14794
|
const updated = await this.getTenantBySlug(slug);
|
|
14806
14795
|
if (!updated) throw new Error("Tenant not found");
|
|
14807
14796
|
return updated;
|
|
@@ -14819,7 +14808,7 @@ var TenantService = class {
|
|
|
14819
14808
|
throw new Error(`Tenant '${slug}' still owns ${docCount} document(s). Delete or migrate its content first.`);
|
|
14820
14809
|
}
|
|
14821
14810
|
await this.db.prepare(`DELETE FROM auth_tenant WHERE slug = ?`).bind(slug).run();
|
|
14822
|
-
|
|
14811
|
+
chunkLLWLHFTD_cjs.invalidateTenantCache();
|
|
14823
14812
|
}
|
|
14824
14813
|
// ─── Membership (auth_tenant_member) ───────────────────────────────────────
|
|
14825
14814
|
// Tenant resolution and the admin switcher are gated on membership: an authed user may only
|
|
@@ -15063,7 +15052,7 @@ var TenantService = class {
|
|
|
15063
15052
|
INSERT INTO auth_tenant (id, name, slug, status, domain, notes, metadata, created_at, updated_at)
|
|
15064
15053
|
VALUES (?, ?, ?, 'active', ?, ?, '{}', ?, ?)
|
|
15065
15054
|
`).bind(id, input.name, input.slug, input.domain, input.notes, now, now).run();
|
|
15066
|
-
|
|
15055
|
+
chunkLLWLHFTD_cjs.invalidateTenantCache();
|
|
15067
15056
|
const created = await this.getTenantBySlug(input.slug);
|
|
15068
15057
|
if (!created) throw new Error("Failed to create tenant");
|
|
15069
15058
|
return created;
|
|
@@ -15087,14 +15076,14 @@ function mapRowToTenant(row) {
|
|
|
15087
15076
|
|
|
15088
15077
|
// src/routes/admin-users.ts
|
|
15089
15078
|
var userRoutes = new hono.Hono();
|
|
15090
|
-
userRoutes.use("*",
|
|
15091
|
-
userRoutes.use("/users/*",
|
|
15092
|
-
userRoutes.use("/users",
|
|
15093
|
-
userRoutes.use("/invite-user",
|
|
15094
|
-
userRoutes.use("/resend-invitation/*",
|
|
15095
|
-
userRoutes.use("/cancel-invitation/*",
|
|
15096
|
-
userRoutes.use("/activity-logs",
|
|
15097
|
-
userRoutes.use("/activity-logs/*",
|
|
15079
|
+
userRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
15080
|
+
userRoutes.use("/users/*", chunkBYLQOBO6_cjs.requireRole(["admin"]));
|
|
15081
|
+
userRoutes.use("/users", chunkBYLQOBO6_cjs.requireRole(["admin"]));
|
|
15082
|
+
userRoutes.use("/invite-user", chunkBYLQOBO6_cjs.requireRole(["admin"]));
|
|
15083
|
+
userRoutes.use("/resend-invitation/*", chunkBYLQOBO6_cjs.requireRole(["admin"]));
|
|
15084
|
+
userRoutes.use("/cancel-invitation/*", chunkBYLQOBO6_cjs.requireRole(["admin"]));
|
|
15085
|
+
userRoutes.use("/activity-logs", chunkBYLQOBO6_cjs.requireRole(["admin"]));
|
|
15086
|
+
userRoutes.use("/activity-logs/*", chunkBYLQOBO6_cjs.requireRole(["admin"]));
|
|
15098
15087
|
userRoutes.get("/", (c) => {
|
|
15099
15088
|
return c.redirect("/admin/dashboard");
|
|
15100
15089
|
});
|
|
@@ -15261,7 +15250,7 @@ userRoutes.put("/profile", async (c) => {
|
|
|
15261
15250
|
}
|
|
15262
15251
|
await saveCustomData(db, user.userId, sanitized);
|
|
15263
15252
|
}
|
|
15264
|
-
await
|
|
15253
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
15265
15254
|
db,
|
|
15266
15255
|
user.userId,
|
|
15267
15256
|
"profile.update",
|
|
@@ -15324,7 +15313,7 @@ userRoutes.post("/profile/avatar", async (c) => {
|
|
|
15324
15313
|
SELECT first_name, last_name FROM auth_user WHERE id = ?
|
|
15325
15314
|
`);
|
|
15326
15315
|
const userData = await userStmt.bind(user.userId).first();
|
|
15327
|
-
await
|
|
15316
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
15328
15317
|
db,
|
|
15329
15318
|
user.userId,
|
|
15330
15319
|
"profile.avatar_update",
|
|
@@ -15395,7 +15384,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15395
15384
|
dismissible: true
|
|
15396
15385
|
}));
|
|
15397
15386
|
}
|
|
15398
|
-
const validPassword = await
|
|
15387
|
+
const validPassword = await chunkBYLQOBO6_cjs.AuthManager.verifyPassword(currentPassword, userData.password_hash);
|
|
15399
15388
|
if (!validPassword) {
|
|
15400
15389
|
return c.html(chunkN32OWET6_cjs.renderAlert({
|
|
15401
15390
|
type: "error",
|
|
@@ -15403,7 +15392,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15403
15392
|
dismissible: true
|
|
15404
15393
|
}));
|
|
15405
15394
|
}
|
|
15406
|
-
const newPasswordHash = await
|
|
15395
|
+
const newPasswordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(newPassword);
|
|
15407
15396
|
const historyStmt = db.prepare(`
|
|
15408
15397
|
INSERT INTO auth_password_history (id, user_id, password_hash, created_at)
|
|
15409
15398
|
VALUES (?, ?, ?, ?)
|
|
@@ -15419,7 +15408,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15419
15408
|
WHERE id = ?
|
|
15420
15409
|
`);
|
|
15421
15410
|
await updateStmt.bind(newPasswordHash, Date.now(), user.userId).run();
|
|
15422
|
-
await
|
|
15411
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
15423
15412
|
db,
|
|
15424
15413
|
user.userId,
|
|
15425
15414
|
"profile.password_change",
|
|
@@ -15486,7 +15475,7 @@ userRoutes.get("/users", async (c) => {
|
|
|
15486
15475
|
`);
|
|
15487
15476
|
const countResult = await countStmt.bind(...params).first();
|
|
15488
15477
|
const totalUsers = countResult?.total || 0;
|
|
15489
|
-
await
|
|
15478
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
15490
15479
|
db,
|
|
15491
15480
|
user.userId,
|
|
15492
15481
|
"users.list_view",
|
|
@@ -15667,7 +15656,7 @@ userRoutes.post("/users/new", async (c) => {
|
|
|
15667
15656
|
dismissible: true
|
|
15668
15657
|
}));
|
|
15669
15658
|
}
|
|
15670
|
-
const passwordHash = await
|
|
15659
|
+
const passwordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(password);
|
|
15671
15660
|
const userId = crypto.randomUUID();
|
|
15672
15661
|
const createStmt = db.prepare(`
|
|
15673
15662
|
INSERT INTO auth_user (
|
|
@@ -15692,7 +15681,7 @@ userRoutes.post("/users/new", async (c) => {
|
|
|
15692
15681
|
if (sanitizedRegistrationCustom !== null && Object.keys(sanitizedRegistrationCustom).length > 0) {
|
|
15693
15682
|
await writeProfileData(db, userId, { custom: sanitizedRegistrationCustom }, user.userId);
|
|
15694
15683
|
}
|
|
15695
|
-
await
|
|
15684
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
15696
15685
|
db,
|
|
15697
15686
|
user.userId,
|
|
15698
15687
|
"user!.create",
|
|
@@ -15731,7 +15720,7 @@ userRoutes.get("/users/:id", async (c) => {
|
|
|
15731
15720
|
if (!userRecord) {
|
|
15732
15721
|
return c.json({ error: "User not found" }, 404);
|
|
15733
15722
|
}
|
|
15734
|
-
await
|
|
15723
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
15735
15724
|
db,
|
|
15736
15725
|
user.userId,
|
|
15737
15726
|
"user!.view",
|
|
@@ -15945,7 +15934,7 @@ userRoutes.put("/users/:id", async (c) => {
|
|
|
15945
15934
|
userId
|
|
15946
15935
|
).run();
|
|
15947
15936
|
if (newPassword) {
|
|
15948
|
-
const passwordHash = await
|
|
15937
|
+
const passwordHash = await chunkBYLQOBO6_cjs.AuthManager.hashPassword(newPassword);
|
|
15949
15938
|
const updatePasswordStmt = db.prepare(`
|
|
15950
15939
|
UPDATE auth_user SET password_hash = ?, updated_at = ? WHERE id = ?
|
|
15951
15940
|
`);
|
|
@@ -15958,7 +15947,7 @@ userRoutes.put("/users/:id", async (c) => {
|
|
|
15958
15947
|
...sanitizedCustom !== null ? { custom: sanitizedCustom } : {}
|
|
15959
15948
|
}, user.userId);
|
|
15960
15949
|
}
|
|
15961
|
-
await
|
|
15950
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
15962
15951
|
db,
|
|
15963
15952
|
user.userId,
|
|
15964
15953
|
"user.update",
|
|
@@ -16004,7 +15993,7 @@ userRoutes.post("/users/:id/toggle", async (c) => {
|
|
|
16004
15993
|
UPDATE auth_user SET is_active = ?, updated_at = ? WHERE id = ?
|
|
16005
15994
|
`);
|
|
16006
15995
|
await toggleStmt.bind(active ? 1 : 0, Date.now(), userId).run();
|
|
16007
|
-
await
|
|
15996
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
16008
15997
|
db,
|
|
16009
15998
|
user.userId,
|
|
16010
15999
|
active ? "user.activate" : "user.deactivate",
|
|
@@ -16045,7 +16034,7 @@ userRoutes.delete("/users/:id", async (c) => {
|
|
|
16045
16034
|
DELETE FROM auth_user WHERE id = ?
|
|
16046
16035
|
`);
|
|
16047
16036
|
await deleteStmt.bind(userId).run();
|
|
16048
|
-
await
|
|
16037
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
16049
16038
|
db,
|
|
16050
16039
|
user.userId,
|
|
16051
16040
|
"user!.hard_delete",
|
|
@@ -16064,7 +16053,7 @@ userRoutes.delete("/users/:id", async (c) => {
|
|
|
16064
16053
|
UPDATE auth_user SET is_active = 0, updated_at = ? WHERE id = ?
|
|
16065
16054
|
`);
|
|
16066
16055
|
await deleteStmt.bind(Date.now(), userId).run();
|
|
16067
|
-
await
|
|
16056
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
16068
16057
|
db,
|
|
16069
16058
|
user.userId,
|
|
16070
16059
|
"user!.soft_delete",
|
|
@@ -16130,7 +16119,7 @@ userRoutes.post("/invite-user", async (c) => {
|
|
|
16130
16119
|
Date.now(),
|
|
16131
16120
|
Date.now()
|
|
16132
16121
|
).run();
|
|
16133
|
-
await
|
|
16122
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
16134
16123
|
db,
|
|
16135
16124
|
user.userId,
|
|
16136
16125
|
"user!.invite_sent",
|
|
@@ -16187,7 +16176,7 @@ userRoutes.post("/resend-invitation/:id", async (c) => {
|
|
|
16187
16176
|
Date.now(),
|
|
16188
16177
|
userId
|
|
16189
16178
|
).run();
|
|
16190
|
-
await
|
|
16179
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
16191
16180
|
db,
|
|
16192
16181
|
user.userId,
|
|
16193
16182
|
"user!.invitation_resent",
|
|
@@ -16223,7 +16212,7 @@ userRoutes.delete("/cancel-invitation/:id", async (c) => {
|
|
|
16223
16212
|
}
|
|
16224
16213
|
const deleteStmt = db.prepare(`DELETE FROM auth_user WHERE id = ?`);
|
|
16225
16214
|
await deleteStmt.bind(userId).run();
|
|
16226
|
-
await
|
|
16215
|
+
await chunkBYLQOBO6_cjs.logActivity(
|
|
16227
16216
|
db,
|
|
16228
16217
|
user.userId,
|
|
16229
16218
|
"user!.invitation_cancelled",
|
|
@@ -17604,7 +17593,7 @@ var fileValidationSchema2 = zod.z.object({
|
|
|
17604
17593
|
// 50MB max
|
|
17605
17594
|
});
|
|
17606
17595
|
var adminMediaRoutes = new hono.Hono();
|
|
17607
|
-
adminMediaRoutes.use("*",
|
|
17596
|
+
adminMediaRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
17608
17597
|
adminMediaRoutes.get("/", async (c) => {
|
|
17609
17598
|
try {
|
|
17610
17599
|
const user = c.get("user");
|
|
@@ -17646,7 +17635,7 @@ adminMediaRoutes.get("/selector", async (c) => {
|
|
|
17646
17635
|
const { searchParams } = new URL(c.req.url);
|
|
17647
17636
|
const search = searchParams.get("search") || "";
|
|
17648
17637
|
const db = c.env.DB;
|
|
17649
|
-
const pluginService = new
|
|
17638
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
17650
17639
|
const mediaPlugin = await pluginService.getPlugin("core-media");
|
|
17651
17640
|
if (!mediaPlugin || mediaPlugin.status !== "active") {
|
|
17652
17641
|
return c.html(html.html`
|
|
@@ -18020,7 +18009,7 @@ adminMediaRoutes.put("/:id", async (c) => {
|
|
|
18020
18009
|
`);
|
|
18021
18010
|
}
|
|
18022
18011
|
});
|
|
18023
|
-
adminMediaRoutes.delete("/cleanup",
|
|
18012
|
+
adminMediaRoutes.delete("/cleanup", chunkBYLQOBO6_cjs.requireRole("admin"), async (c) => {
|
|
18024
18013
|
try {
|
|
18025
18014
|
const db = c.env.DB;
|
|
18026
18015
|
const allMediaStmt = db.prepare("SELECT id, r2_key, filename FROM media WHERE deleted_at IS NULL");
|
|
@@ -20453,8 +20442,8 @@ defineUserProfile({
|
|
|
20453
20442
|
|
|
20454
20443
|
// src/routes/admin-plugins.ts
|
|
20455
20444
|
var adminPluginRoutes = new hono.Hono();
|
|
20456
|
-
adminPluginRoutes.use("*",
|
|
20457
|
-
var AVAILABLE_PLUGINS = Object.values(
|
|
20445
|
+
adminPluginRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
20446
|
+
var AVAILABLE_PLUGINS = Object.values(chunkLLWLHFTD_cjs.PLUGIN_REGISTRY).map((p) => ({
|
|
20458
20447
|
id: p.id,
|
|
20459
20448
|
name: p.codeName,
|
|
20460
20449
|
display_name: p.displayName,
|
|
@@ -20474,7 +20463,7 @@ adminPluginRoutes.get("/", async (c) => {
|
|
|
20474
20463
|
if (user?.role !== "admin") {
|
|
20475
20464
|
return c.text("Access denied", 403);
|
|
20476
20465
|
}
|
|
20477
|
-
const pluginService = new
|
|
20466
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20478
20467
|
let installedPlugins = [];
|
|
20479
20468
|
let stats = { total: 0, active: 0, inactive: 0, errors: 0, uninstalled: 0 };
|
|
20480
20469
|
try {
|
|
@@ -20546,10 +20535,10 @@ adminPluginRoutes.get("/:id", async (c) => {
|
|
|
20546
20535
|
if (user?.role !== "admin") {
|
|
20547
20536
|
return c.redirect("/admin/plugins");
|
|
20548
20537
|
}
|
|
20549
|
-
const pluginService = new
|
|
20538
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20550
20539
|
let plugin = await pluginService.getPlugin(pluginId);
|
|
20551
20540
|
if (!plugin) {
|
|
20552
|
-
const def =
|
|
20541
|
+
const def = chunkNYLWNR6T_cjs.getPluginDefinition(pluginId);
|
|
20553
20542
|
if (!def) return c.text("Plugin not found", 404);
|
|
20554
20543
|
plugin = await pluginService.ensurePlugin(pluginId, {
|
|
20555
20544
|
displayName: def.displayName ?? pluginId,
|
|
@@ -20640,14 +20629,14 @@ adminPluginRoutes.get("/:id/configure", async (c) => {
|
|
|
20640
20629
|
const user = c.get("user");
|
|
20641
20630
|
const pluginId = c.req.param("id");
|
|
20642
20631
|
if (user?.role !== "admin") return c.redirect("/admin/plugins");
|
|
20643
|
-
const def =
|
|
20632
|
+
const def = chunkNYLWNR6T_cjs.getPluginDefinition(pluginId);
|
|
20644
20633
|
if (!def?.configSchema) return c.text("No schema-driven settings for this plugin", 404);
|
|
20645
20634
|
const db = c.env.DB;
|
|
20646
|
-
const pluginService = new
|
|
20635
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20647
20636
|
const plugin = await pluginService.getPlugin(pluginId);
|
|
20648
20637
|
const stored = plugin?.settings ?? {};
|
|
20649
|
-
const values =
|
|
20650
|
-
const fieldsHtml =
|
|
20638
|
+
const values = chunkNYLWNR6T_cjs.applySchemaDefaults(def.configSchema, stored);
|
|
20639
|
+
const fieldsHtml = chunkNYLWNR6T_cjs.renderSchemaFields(def.configSchema, values);
|
|
20651
20640
|
const displayName = plugin?.display_name ?? def.displayName ?? def.id;
|
|
20652
20641
|
return c.html(`<!DOCTYPE html>
|
|
20653
20642
|
<html lang="en"><head>
|
|
@@ -20674,12 +20663,12 @@ adminPluginRoutes.post("/:id/configure", async (c) => {
|
|
|
20674
20663
|
const user = c.get("user");
|
|
20675
20664
|
const pluginId = c.req.param("id");
|
|
20676
20665
|
if (user?.role !== "admin") return c.json({ error: "Access denied" }, 403);
|
|
20677
|
-
const def =
|
|
20666
|
+
const def = chunkNYLWNR6T_cjs.getPluginDefinition(pluginId);
|
|
20678
20667
|
if (!def?.configSchema) return c.text("No schema-driven settings for this plugin", 404);
|
|
20679
20668
|
const form = await c.req.formData();
|
|
20680
|
-
const parsed =
|
|
20669
|
+
const parsed = chunkNYLWNR6T_cjs.parseFormDataToSettings(def.configSchema, form);
|
|
20681
20670
|
const db = c.env.DB;
|
|
20682
|
-
const pluginService = new
|
|
20671
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20683
20672
|
await pluginService.ensurePlugin(pluginId, {
|
|
20684
20673
|
displayName: def.displayName ?? pluginId,
|
|
20685
20674
|
version: def.version,
|
|
@@ -20701,7 +20690,7 @@ adminPluginRoutes.post("/:id/activate", async (c) => {
|
|
|
20701
20690
|
if (user?.role !== "admin") {
|
|
20702
20691
|
return c.json({ error: "Access denied" }, 403);
|
|
20703
20692
|
}
|
|
20704
|
-
const pluginService = new
|
|
20693
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20705
20694
|
await pluginService.activatePlugin(pluginId);
|
|
20706
20695
|
return c.json({ success: true });
|
|
20707
20696
|
} catch (error) {
|
|
@@ -20718,7 +20707,7 @@ adminPluginRoutes.post("/:id/deactivate", async (c) => {
|
|
|
20718
20707
|
if (user?.role !== "admin") {
|
|
20719
20708
|
return c.json({ error: "Access denied" }, 403);
|
|
20720
20709
|
}
|
|
20721
|
-
const pluginService = new
|
|
20710
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20722
20711
|
await pluginService.deactivatePlugin(pluginId);
|
|
20723
20712
|
return c.json({ success: true });
|
|
20724
20713
|
} catch (error) {
|
|
@@ -20735,8 +20724,8 @@ adminPluginRoutes.post("/install", async (c) => {
|
|
|
20735
20724
|
return c.json({ error: "Access denied" }, 403);
|
|
20736
20725
|
}
|
|
20737
20726
|
const body = await c.req.json();
|
|
20738
|
-
const pluginService = new
|
|
20739
|
-
const registryEntry =
|
|
20727
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20728
|
+
const registryEntry = chunkLLWLHFTD_cjs.findPluginByCodeName(body.name) || chunkLLWLHFTD_cjs.PLUGIN_REGISTRY[body.name] || chunkLLWLHFTD_cjs.PLUGIN_REGISTRY[body.id];
|
|
20740
20729
|
if (!registryEntry) {
|
|
20741
20730
|
return c.json({ error: "Plugin not found in registry" }, 404);
|
|
20742
20731
|
}
|
|
@@ -20769,7 +20758,7 @@ adminPluginRoutes.post("/:id/uninstall", async (c) => {
|
|
|
20769
20758
|
if (user?.role !== "admin") {
|
|
20770
20759
|
return c.json({ error: "Access denied" }, 403);
|
|
20771
20760
|
}
|
|
20772
|
-
const pluginService = new
|
|
20761
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20773
20762
|
await pluginService.uninstallPlugin(pluginId);
|
|
20774
20763
|
return c.json({ success: true });
|
|
20775
20764
|
} catch (error) {
|
|
@@ -20787,7 +20776,7 @@ adminPluginRoutes.post("/:id/settings", async (c) => {
|
|
|
20787
20776
|
return c.json({ error: "Access denied" }, 403);
|
|
20788
20777
|
}
|
|
20789
20778
|
const settings = await c.req.json();
|
|
20790
|
-
const pluginService = new
|
|
20779
|
+
const pluginService = new chunkLLWLHFTD_cjs.PluginService(db);
|
|
20791
20780
|
await pluginService.updatePluginSettings(pluginId, settings);
|
|
20792
20781
|
if (pluginId === "core-auth") {
|
|
20793
20782
|
try {
|
|
@@ -21595,7 +21584,7 @@ function renderLogConfigPage(data) {
|
|
|
21595
21584
|
|
|
21596
21585
|
// src/routes/admin-logs.ts
|
|
21597
21586
|
var adminLogsRoutes = new hono.Hono();
|
|
21598
|
-
adminLogsRoutes.use("*",
|
|
21587
|
+
adminLogsRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
21599
21588
|
adminLogsRoutes.get("/", async (c) => {
|
|
21600
21589
|
try {
|
|
21601
21590
|
const user = c.get("user");
|
|
@@ -22587,9 +22576,9 @@ function renderStorageUsage(databaseSizeBytes, mediaSizeBytes) {
|
|
|
22587
22576
|
}
|
|
22588
22577
|
|
|
22589
22578
|
// src/routes/admin-dashboard.ts
|
|
22590
|
-
var VERSION =
|
|
22579
|
+
var VERSION = chunkXGH2FVVR_cjs.getCoreVersion();
|
|
22591
22580
|
var router = new hono.Hono();
|
|
22592
|
-
router.use("*",
|
|
22581
|
+
router.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
22593
22582
|
router.get("/", async (c) => {
|
|
22594
22583
|
const user = c.get("user");
|
|
22595
22584
|
try {
|
|
@@ -24554,7 +24543,7 @@ function renderCollectionFormPage(data) {
|
|
|
24554
24543
|
// src/routes/admin-collections.ts
|
|
24555
24544
|
chunkK623Q6WD_cjs.init_admin_layout_catalyst_template();
|
|
24556
24545
|
var adminCollectionsRoutes = new hono.Hono();
|
|
24557
|
-
adminCollectionsRoutes.use("*",
|
|
24546
|
+
adminCollectionsRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
24558
24547
|
adminCollectionsRoutes.get("/", async (c) => {
|
|
24559
24548
|
try {
|
|
24560
24549
|
const user = c.get("user");
|
|
@@ -24571,7 +24560,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24571
24560
|
results = queryResults.results ?? [];
|
|
24572
24561
|
} catch (e) {
|
|
24573
24562
|
}
|
|
24574
|
-
const codeCollections =
|
|
24563
|
+
const codeCollections = chunkLLWLHFTD_cjs.getCollectionRegistry().list();
|
|
24575
24564
|
const codeCollectionsMap = new Map(
|
|
24576
24565
|
codeCollections.map((cfg) => {
|
|
24577
24566
|
const fieldCount = cfg.schema?.properties ? Object.keys(cfg.schema.properties).length : 0;
|
|
@@ -24585,7 +24574,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24585
24574
|
field_count: fieldCount,
|
|
24586
24575
|
managed: cfg.managed !== false,
|
|
24587
24576
|
source_type: "code",
|
|
24588
|
-
internal:
|
|
24577
|
+
internal: chunkLLWLHFTD_cjs.isCodeCollectionInternal(cfg),
|
|
24589
24578
|
versioning: cfg.versioning === true
|
|
24590
24579
|
}];
|
|
24591
24580
|
})
|
|
@@ -24624,7 +24613,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24624
24613
|
field_count: fieldCount,
|
|
24625
24614
|
managed: false,
|
|
24626
24615
|
source_type: row.source === "code" || row.source === "system" || row.source === "plugin" ? "code" : "user",
|
|
24627
|
-
internal:
|
|
24616
|
+
internal: chunkLLWLHFTD_cjs.isDbDocTypeInternal(row.source),
|
|
24628
24617
|
versioning: dbVersioning
|
|
24629
24618
|
};
|
|
24630
24619
|
});
|
|
@@ -24785,7 +24774,7 @@ export const myPlugin = definePlugin({
|
|
|
24785
24774
|
title: "Add a Collection",
|
|
24786
24775
|
pageTitle: "Add a Collection",
|
|
24787
24776
|
currentPath: "/admin/collections",
|
|
24788
|
-
version:
|
|
24777
|
+
version: chunkXGH2FVVR_cjs.getCoreVersion(),
|
|
24789
24778
|
user: u ? { name: u.email ?? "Admin", email: u.email ?? "", role: u.role ?? "admin" } : void 0,
|
|
24790
24779
|
content
|
|
24791
24780
|
})
|
|
@@ -24802,7 +24791,7 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
24802
24791
|
collection = await stmt.bind(id).first();
|
|
24803
24792
|
} catch {
|
|
24804
24793
|
}
|
|
24805
|
-
const registryRecord =
|
|
24794
|
+
const registryRecord = chunkLLWLHFTD_cjs.getCollectionRegistry().getById(id) ?? chunkLLWLHFTD_cjs.getCollectionRegistry().getByName(id);
|
|
24806
24795
|
if (!collection && !registryRecord) {
|
|
24807
24796
|
const formData2 = {
|
|
24808
24797
|
isEdit: true,
|
|
@@ -24849,9 +24838,9 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
24849
24838
|
isCodeDriven = true;
|
|
24850
24839
|
}
|
|
24851
24840
|
const [tinymceActive, quillActive, mdxeditorActive] = await Promise.all([
|
|
24852
|
-
|
|
24853
|
-
|
|
24854
|
-
|
|
24841
|
+
chunkBYLQOBO6_cjs.isPluginActive(db, "tinymce-plugin"),
|
|
24842
|
+
chunkBYLQOBO6_cjs.isPluginActive(db, "quill-editor"),
|
|
24843
|
+
chunkBYLQOBO6_cjs.isPluginActive(db, "easy-mdx")
|
|
24855
24844
|
]);
|
|
24856
24845
|
const displayName = collection?.display_name ?? registryRecord?.displayName ?? id;
|
|
24857
24846
|
const formData = {
|
|
@@ -24871,9 +24860,9 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
24871
24860
|
console.error("Error fetching collection:", error);
|
|
24872
24861
|
const user = c.get("user");
|
|
24873
24862
|
const [tinymceActive, quillActive, mdxeditorActive] = await Promise.all([
|
|
24874
|
-
|
|
24875
|
-
|
|
24876
|
-
|
|
24863
|
+
chunkBYLQOBO6_cjs.isPluginActive(db, "tinymce-plugin"),
|
|
24864
|
+
chunkBYLQOBO6_cjs.isPluginActive(db, "quill-editor"),
|
|
24865
|
+
chunkBYLQOBO6_cjs.isPluginActive(db, "easy-mdx")
|
|
24877
24866
|
]);
|
|
24878
24867
|
const formData = {
|
|
24879
24868
|
isEdit: true,
|
|
@@ -25822,7 +25811,7 @@ function renderDatabaseToolsSettings(settings) {
|
|
|
25822
25811
|
|
|
25823
25812
|
// src/routes/admin-settings.ts
|
|
25824
25813
|
var adminSettingsRoutes = new hono.Hono();
|
|
25825
|
-
adminSettingsRoutes.use("*",
|
|
25814
|
+
adminSettingsRoutes.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
25826
25815
|
function getMockSettings(user) {
|
|
25827
25816
|
return {
|
|
25828
25817
|
general: {
|
|
@@ -25925,7 +25914,7 @@ adminSettingsRoutes.get("/database-tools", (c) => {
|
|
|
25925
25914
|
adminSettingsRoutes.get("/api/migrations/status", async (c) => {
|
|
25926
25915
|
try {
|
|
25927
25916
|
const db = c.env.DB;
|
|
25928
|
-
const migrationService = new
|
|
25917
|
+
const migrationService = new chunkKI5KMJH2_cjs.MigrationService(db);
|
|
25929
25918
|
const status = await migrationService.getMigrationStatus();
|
|
25930
25919
|
return c.json({
|
|
25931
25920
|
success: true,
|
|
@@ -25965,7 +25954,7 @@ adminSettingsRoutes.post("/api/migrations/run", async (c) => {
|
|
|
25965
25954
|
adminSettingsRoutes.get("/api/migrations/validate", async (c) => {
|
|
25966
25955
|
try {
|
|
25967
25956
|
const db = c.env.DB;
|
|
25968
|
-
const migrationService = new
|
|
25957
|
+
const migrationService = new chunkKI5KMJH2_cjs.MigrationService(db);
|
|
25969
25958
|
const validation = await migrationService.validateSchema();
|
|
25970
25959
|
return c.json({
|
|
25971
25960
|
success: true,
|
|
@@ -26558,16 +26547,16 @@ function renderAPIReferencePage(data) {
|
|
|
26558
26547
|
}
|
|
26559
26548
|
|
|
26560
26549
|
// src/routes/admin-api-reference.ts
|
|
26561
|
-
var VERSION2 =
|
|
26550
|
+
var VERSION2 = chunkXGH2FVVR_cjs.getCoreVersion();
|
|
26562
26551
|
var router2 = new hono.Hono();
|
|
26563
|
-
router2.use("*",
|
|
26552
|
+
router2.use("*", chunkBYLQOBO6_cjs.requireAuth());
|
|
26564
26553
|
router2.get("/", async (c) => {
|
|
26565
26554
|
const user = c.get("user");
|
|
26566
26555
|
try {
|
|
26567
26556
|
const app2 = chunk4BTBSXMR_cjs.getAppInstance();
|
|
26568
26557
|
const baseEndpoints = chunk4BTBSXMR_cjs.buildRouteList(app2);
|
|
26569
26558
|
const collectionRoutes = [];
|
|
26570
|
-
const collections =
|
|
26559
|
+
const collections = chunkLLWLHFTD_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
26571
26560
|
const methodOrder = { GET: 0, POST: 1, PUT: 2, PATCH: 3, DELETE: 4 };
|
|
26572
26561
|
for (const col of collections) {
|
|
26573
26562
|
const displayName = col.displayName || col.name;
|
|
@@ -26683,5 +26672,5 @@ exports.setVariablesCache = setVariablesCache;
|
|
|
26683
26672
|
exports.test_cleanup_default = test_cleanup_default;
|
|
26684
26673
|
exports.userProfilesPlugin = userProfilesPlugin;
|
|
26685
26674
|
exports.userRoutes = userRoutes;
|
|
26686
|
-
//# sourceMappingURL=chunk-
|
|
26687
|
-
//# sourceMappingURL=chunk-
|
|
26675
|
+
//# sourceMappingURL=chunk-TV7LRFXH.cjs.map
|
|
26676
|
+
//# sourceMappingURL=chunk-TV7LRFXH.cjs.map
|