@sonicjs-cms/core 3.0.0-beta.21 → 3.0.0-beta.22
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-5U75XP74.js → chunk-2FCKKOA5.js} +2 -2
- package/dist/{chunk-5U75XP74.js.map → chunk-2FCKKOA5.js.map} +1 -1
- package/dist/{chunk-OJC4G5JE.cjs → chunk-3CT3SUR4.cjs} +2 -2
- package/dist/{chunk-OJC4G5JE.cjs.map → chunk-3CT3SUR4.cjs.map} +1 -1
- package/dist/{chunk-ZP77LTN4.js → chunk-6KNTZ67K.js} +106 -11
- package/dist/chunk-6KNTZ67K.js.map +1 -0
- package/dist/{chunk-JEX3UPZL.js → chunk-73O4GPJ6.js} +3 -3
- package/dist/{chunk-JEX3UPZL.js.map → chunk-73O4GPJ6.js.map} +1 -1
- package/dist/{chunk-4UYJPHSV.js → chunk-CHWT5KBK.js} +5 -5
- package/dist/{chunk-4UYJPHSV.js.map → chunk-CHWT5KBK.js.map} +1 -1
- package/dist/{chunk-4LVVMVQI.js → chunk-DOMXI5PM.js} +2 -2
- package/dist/{chunk-4LVVMVQI.js.map → chunk-DOMXI5PM.js.map} +1 -1
- package/dist/{chunk-A4KUJ3LD.cjs → chunk-EUJAEB6W.cjs} +4 -4
- package/dist/{chunk-A4KUJ3LD.cjs.map → chunk-EUJAEB6W.cjs.map} +1 -1
- package/dist/{chunk-FCLKX2OS.cjs → chunk-FTXGZ3BF.cjs} +15 -15
- package/dist/{chunk-FCLKX2OS.cjs.map → chunk-FTXGZ3BF.cjs.map} +1 -1
- package/dist/{chunk-GICS5AIO.js → chunk-GB2Q2DNK.js} +4 -4
- package/dist/{chunk-GICS5AIO.js.map → chunk-GB2Q2DNK.js.map} +1 -1
- package/dist/{chunk-7OTOXWEB.js → chunk-I2DM27HP.js} +3 -3
- package/dist/{chunk-7OTOXWEB.js.map → chunk-I2DM27HP.js.map} +1 -1
- package/dist/{chunk-7RUW244J.cjs → chunk-JFLZHOQP.cjs} +299 -204
- package/dist/chunk-JFLZHOQP.cjs.map +1 -0
- package/dist/{chunk-5UXU3LP4.cjs → chunk-MGHHPNJN.cjs} +10 -10
- package/dist/{chunk-5UXU3LP4.cjs.map → chunk-MGHHPNJN.cjs.map} +1 -1
- package/dist/{chunk-KVBHB7QP.cjs → chunk-PYZYU7EK.cjs} +2 -2
- package/dist/{chunk-KVBHB7QP.cjs.map → chunk-PYZYU7EK.cjs.map} +1 -1
- package/dist/{chunk-AOUVUF32.cjs → chunk-QWSR4THH.cjs} +3 -3
- package/dist/{chunk-AOUVUF32.cjs.map → chunk-QWSR4THH.cjs.map} +1 -1
- package/dist/index.cjs +308 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -19
- package/dist/index.js.map +1 -1
- package/dist/middleware.cjs +33 -33
- package/dist/middleware.js +4 -4
- package/dist/migrations-HLK2QF4T.js +4 -0
- package/dist/{migrations-HMX5SPN2.js.map → migrations-HLK2QF4T.js.map} +1 -1
- package/dist/migrations-UIMA6ZL6.cjs +13 -0
- package/dist/{migrations-V73ARYV5.cjs.map → migrations-UIMA6ZL6.cjs.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/chunk-7RUW244J.cjs.map +0 -1
- package/dist/chunk-ZP77LTN4.js.map +0 -1
- package/dist/migrations-HMX5SPN2.js +0 -4
- package/dist/migrations-V73ARYV5.cjs +0 -13
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
var chunkXWVDSM2L_cjs = require('./chunk-XWVDSM2L.cjs');
|
|
4
4
|
var chunkN32OWET6_cjs = require('./chunk-N32OWET6.cjs');
|
|
5
5
|
var chunk36Z3AKX3_cjs = require('./chunk-36Z3AKX3.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunkFTXGZ3BF_cjs = require('./chunk-FTXGZ3BF.cjs');
|
|
7
7
|
var chunkLTZ5WYOK_cjs = require('./chunk-LTZ5WYOK.cjs');
|
|
8
8
|
var chunkKIGVVO6N_cjs = require('./chunk-KIGVVO6N.cjs');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var chunkPYZYU7EK_cjs = require('./chunk-PYZYU7EK.cjs');
|
|
10
|
+
var chunk3CT3SUR4_cjs = require('./chunk-3CT3SUR4.cjs');
|
|
11
11
|
var chunkPXNTCCPE_cjs = require('./chunk-PXNTCCPE.cjs');
|
|
12
12
|
var chunkK623Q6WD_cjs = require('./chunk-K623Q6WD.cjs');
|
|
13
|
-
var
|
|
13
|
+
var chunkEUJAEB6W_cjs = require('./chunk-EUJAEB6W.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 chunkQWSR4THH_cjs = require('./chunk-QWSR4THH.cjs');
|
|
18
18
|
var chunkMNWKYY5E_cjs = require('./chunk-MNWKYY5E.cjs');
|
|
19
19
|
var hono = require('hono');
|
|
20
20
|
var zod = require('zod');
|
|
@@ -259,7 +259,7 @@ function getDocumentRequestContext(c) {
|
|
|
259
259
|
|
|
260
260
|
// src/routes/api-documents.ts
|
|
261
261
|
async function aclAllowsRead(db, tenantId, principalSet, row, preloadedType) {
|
|
262
|
-
const docType = preloadedType ?? await new
|
|
262
|
+
const docType = preloadedType ?? await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
263
263
|
if (!docType) return false;
|
|
264
264
|
return new DocumentRepository(db, tenantId).isAllowed(principalSet, row.root_id, "read", docType.settings);
|
|
265
265
|
}
|
|
@@ -277,7 +277,7 @@ apiDocumentsRoutes.get("/", async (c) => {
|
|
|
277
277
|
if (!typeId) {
|
|
278
278
|
return c.json({ error: "type query parameter is required" }, 400);
|
|
279
279
|
}
|
|
280
|
-
const registry = new
|
|
280
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
281
281
|
const docType = await registry.findById(typeId);
|
|
282
282
|
if (!docType || !docType.isActive) {
|
|
283
283
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -359,7 +359,7 @@ apiDocumentsRoutes.get("/root/:rootId", async (c) => {
|
|
|
359
359
|
AND (expires_at IS NULL OR expires_at > ?) LIMIT 1`
|
|
360
360
|
).bind(rootId, now, now).first();
|
|
361
361
|
if (!row) return c.json({ error: "Not found" }, 404);
|
|
362
|
-
const docType = await new
|
|
362
|
+
const docType = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
363
363
|
const effTenant = effectiveTenantForType(tenantId, docType?.settings);
|
|
364
364
|
if (row.tenant_id !== effTenant) return c.json({ error: "Not found" }, 404);
|
|
365
365
|
if (!await aclAllowsRead(db, effTenant, principalSet, row, docType)) {
|
|
@@ -395,7 +395,7 @@ apiDocumentsRoutes.get("/:id", async (c) => {
|
|
|
395
395
|
AND (expires_at IS NULL OR expires_at > ?) LIMIT 1`
|
|
396
396
|
).bind(id, now, now).first();
|
|
397
397
|
if (!row) return c.json({ error: "Not found" }, 404);
|
|
398
|
-
const docType = await new
|
|
398
|
+
const docType = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
399
399
|
const effTenant = effectiveTenantForType(tenantId, docType?.settings);
|
|
400
400
|
if (row.tenant_id !== effTenant) return c.json({ error: "Not found" }, 404);
|
|
401
401
|
if (!await aclAllowsRead(db, effTenant, principalSet, row, docType)) {
|
|
@@ -465,17 +465,17 @@ async function resolveDocScope(c, db, by, opts = {}) {
|
|
|
465
465
|
const draft = opts.currentDraftOnly ? " AND is_current_draft = 1" : "";
|
|
466
466
|
const row = await db.prepare(`SELECT type_id, root_id, tenant_id FROM documents WHERE ${col} = ?${draft} LIMIT 1`).bind(val).first();
|
|
467
467
|
if (!row) return null;
|
|
468
|
-
const docType = await new
|
|
468
|
+
const docType = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
469
469
|
const tenantId = effectiveTenantForType(getRequestTenant(c), docType?.settings);
|
|
470
470
|
if (row.tenant_id !== tenantId) return null;
|
|
471
471
|
return { typeId: row.type_id, rootId: row.root_id, tenantId, docType };
|
|
472
472
|
}
|
|
473
473
|
var adminDocumentsRoutes = new hono.Hono();
|
|
474
|
-
adminDocumentsRoutes.use("*",
|
|
475
|
-
adminDocumentsRoutes.use("*",
|
|
474
|
+
adminDocumentsRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
475
|
+
adminDocumentsRoutes.use("*", chunkFTXGZ3BF_cjs.requireRole(["admin", "editor"]));
|
|
476
476
|
adminDocumentsRoutes.get("/types", async (c) => {
|
|
477
477
|
try {
|
|
478
|
-
const registry = new
|
|
478
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(c.env.DB);
|
|
479
479
|
const types = await registry.findAll();
|
|
480
480
|
return c.json({ data: types });
|
|
481
481
|
} catch (error) {
|
|
@@ -503,7 +503,7 @@ adminDocumentsRoutes.get("/", async (c) => {
|
|
|
503
503
|
if (!typeId) {
|
|
504
504
|
return c.json({ error: "type query parameter is required" }, 400);
|
|
505
505
|
}
|
|
506
|
-
const registry = new
|
|
506
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
507
507
|
const docType = await registry.findById(typeId);
|
|
508
508
|
if (!docType || !docType.isActive) {
|
|
509
509
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -614,7 +614,7 @@ adminDocumentsRoutes.post("/", async (c) => {
|
|
|
614
614
|
const input = validation.data;
|
|
615
615
|
const db = c.env.DB;
|
|
616
616
|
const user = c.get("user");
|
|
617
|
-
const registry = new
|
|
617
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
618
618
|
const docType = await registry.findById(input.typeId);
|
|
619
619
|
if (!docType || !docType.isActive) {
|
|
620
620
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -746,7 +746,7 @@ adminDocumentsRoutes.post("/types/:typeId/reindex", async (c) => {
|
|
|
746
746
|
try {
|
|
747
747
|
const { typeId } = c.req.param();
|
|
748
748
|
const db = c.env.DB;
|
|
749
|
-
const registry = new
|
|
749
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
750
750
|
const docType = await registry.findById(typeId);
|
|
751
751
|
if (!docType) return c.json({ error: "Unknown document type" }, 400);
|
|
752
752
|
const reindexTenant = effectiveTenantForType(getRequestTenant(c), docType.settings);
|
|
@@ -900,13 +900,13 @@ async function resolveContentVariables(contentData, db) {
|
|
|
900
900
|
// src/routes/api-content-crud.ts
|
|
901
901
|
var apiContentCrudRoutes = new hono.Hono();
|
|
902
902
|
async function resolveDocBacking(db, collectionIdOrName) {
|
|
903
|
-
const registry =
|
|
903
|
+
const registry = chunkPYZYU7EK_cjs.getCollectionRegistry();
|
|
904
904
|
const record = registry.getBySlugOrName(collectionIdOrName) ?? registry.getById(collectionIdOrName);
|
|
905
905
|
if (record) {
|
|
906
|
-
const docType2 = await new
|
|
906
|
+
const docType2 = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(record.name);
|
|
907
907
|
return docType2 ? { coll: { id: record.id, name: record.name }, docType: docType2 } : null;
|
|
908
908
|
}
|
|
909
|
-
const docType = await new
|
|
909
|
+
const docType = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(collectionIdOrName);
|
|
910
910
|
if (docType) {
|
|
911
911
|
return { coll: { id: collectionIdOrName, name: collectionIdOrName }, docType };
|
|
912
912
|
}
|
|
@@ -949,7 +949,7 @@ apiContentCrudRoutes.get("/check-slug", async (c) => {
|
|
|
949
949
|
}, 500);
|
|
950
950
|
}
|
|
951
951
|
});
|
|
952
|
-
apiContentCrudRoutes.get("/:id",
|
|
952
|
+
apiContentCrudRoutes.get("/:id", chunkFTXGZ3BF_cjs.optionalAuth(), async (c) => {
|
|
953
953
|
try {
|
|
954
954
|
const id = c.req.param("id");
|
|
955
955
|
const db = c.env.DB;
|
|
@@ -959,7 +959,7 @@ apiContentCrudRoutes.get("/:id", chunkFCLKX2OS_cjs.optionalAuth(), async (c) =>
|
|
|
959
959
|
).bind(id, getRequestTenant(c)).first();
|
|
960
960
|
let transformedContent;
|
|
961
961
|
if (docRow) {
|
|
962
|
-
const coll =
|
|
962
|
+
const coll = chunkPYZYU7EK_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
963
963
|
transformedContent = {
|
|
964
964
|
id: docRow.root_id,
|
|
965
965
|
title: docRow.title,
|
|
@@ -993,7 +993,7 @@ apiContentCrudRoutes.get("/:id", chunkFCLKX2OS_cjs.optionalAuth(), async (c) =>
|
|
|
993
993
|
}, 500);
|
|
994
994
|
}
|
|
995
995
|
});
|
|
996
|
-
apiContentCrudRoutes.post("/",
|
|
996
|
+
apiContentCrudRoutes.post("/", chunkFTXGZ3BF_cjs.requireAuth(), chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
997
997
|
try {
|
|
998
998
|
const db = c.env.DB;
|
|
999
999
|
const user = c.get("user");
|
|
@@ -1068,7 +1068,7 @@ apiContentCrudRoutes.post("/", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS_cj
|
|
|
1068
1068
|
}, 500);
|
|
1069
1069
|
}
|
|
1070
1070
|
});
|
|
1071
|
-
apiContentCrudRoutes.put("/:id",
|
|
1071
|
+
apiContentCrudRoutes.put("/:id", chunkFTXGZ3BF_cjs.requireAuth(), chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
1072
1072
|
try {
|
|
1073
1073
|
const id = c.req.param("id");
|
|
1074
1074
|
const db = c.env.DB;
|
|
@@ -1090,7 +1090,7 @@ apiContentCrudRoutes.put("/:id", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS_
|
|
|
1090
1090
|
} catch (err) {
|
|
1091
1091
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
1092
1092
|
}
|
|
1093
|
-
const docType = await new
|
|
1093
|
+
const docType = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(docRow.type_id);
|
|
1094
1094
|
const svc = new chunkLTZ5WYOK_cjs.DocumentsService(db, {
|
|
1095
1095
|
queryableFields: docType?.queryableFields ?? [],
|
|
1096
1096
|
typeSchemaVersion: docType?.schemaVersion ?? 1,
|
|
@@ -1113,7 +1113,7 @@ apiContentCrudRoutes.put("/:id", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS_
|
|
|
1113
1113
|
const cache = chunk36Z3AKX3_cjs.getCacheService(chunk36Z3AKX3_cjs.CACHE_CONFIGS.api);
|
|
1114
1114
|
await cache.invalidate("content-filtered:*");
|
|
1115
1115
|
await cache.invalidate("collection-content-filtered:*");
|
|
1116
|
-
const coll =
|
|
1116
|
+
const coll = chunkPYZYU7EK_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
1117
1117
|
const saved = await db.prepare("SELECT * FROM documents WHERE id = ?").bind(newDraft.id).first();
|
|
1118
1118
|
const savedData = saved?.data ? JSON.parse(saved.data) : {};
|
|
1119
1119
|
dispatchHookEvent(c, "content:after:update", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
@@ -1134,7 +1134,7 @@ apiContentCrudRoutes.put("/:id", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS_
|
|
|
1134
1134
|
}, 500);
|
|
1135
1135
|
}
|
|
1136
1136
|
});
|
|
1137
|
-
apiContentCrudRoutes.delete("/:id",
|
|
1137
|
+
apiContentCrudRoutes.delete("/:id", chunkFTXGZ3BF_cjs.requireAuth(), chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
1138
1138
|
try {
|
|
1139
1139
|
const id = c.req.param("id");
|
|
1140
1140
|
const db = c.env.DB;
|
|
@@ -1260,7 +1260,7 @@ apiRoutes.use("*", async (c, next) => {
|
|
|
1260
1260
|
c.header("X-Response-Time", `${totalTime}ms`);
|
|
1261
1261
|
});
|
|
1262
1262
|
apiRoutes.use("*", async (c, next) => {
|
|
1263
|
-
const cacheEnabled = await
|
|
1263
|
+
const cacheEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(c.env.DB, "core-cache");
|
|
1264
1264
|
c.set("cacheEnabled", cacheEnabled);
|
|
1265
1265
|
await next();
|
|
1266
1266
|
});
|
|
@@ -1283,7 +1283,7 @@ apiRoutes.get("/", (c) => {
|
|
|
1283
1283
|
openapi: "3.0.0",
|
|
1284
1284
|
info: {
|
|
1285
1285
|
title: "SonicJS AI API",
|
|
1286
|
-
version:
|
|
1286
|
+
version: chunkQWSR4THH_cjs.getCoreVersion(),
|
|
1287
1287
|
description: "RESTful API for SonicJS headless CMS - a modern, AI-powered content management system built on Cloudflare Workers",
|
|
1288
1288
|
contact: {
|
|
1289
1289
|
name: "SonicJS Support",
|
|
@@ -1713,8 +1713,8 @@ apiRoutes.get("/collections", async (c) => {
|
|
|
1713
1713
|
}
|
|
1714
1714
|
c.header("X-Cache-Status", "MISS");
|
|
1715
1715
|
c.header("X-Cache-Source", "registry");
|
|
1716
|
-
const records =
|
|
1717
|
-
const transformedResults = records.map(
|
|
1716
|
+
const records = chunkPYZYU7EK_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
1717
|
+
const transformedResults = records.map(chunkPYZYU7EK_cjs.collectionRecordToRow);
|
|
1718
1718
|
const responseData = {
|
|
1719
1719
|
data: transformedResults,
|
|
1720
1720
|
meta: addTimingMeta(c, {
|
|
@@ -1735,7 +1735,7 @@ apiRoutes.get("/collections", async (c) => {
|
|
|
1735
1735
|
return c.json({ error: "Failed to fetch collections" }, 500);
|
|
1736
1736
|
}
|
|
1737
1737
|
});
|
|
1738
|
-
apiRoutes.get("/content",
|
|
1738
|
+
apiRoutes.get("/content", chunkFTXGZ3BF_cjs.optionalAuth(), async (c) => {
|
|
1739
1739
|
const executionStart = Date.now();
|
|
1740
1740
|
try {
|
|
1741
1741
|
const db = c.env.DB;
|
|
@@ -1744,7 +1744,7 @@ apiRoutes.get("/content", chunkFCLKX2OS_cjs.optionalAuth(), async (c) => {
|
|
|
1744
1744
|
const collIdByName = /* @__PURE__ */ new Map();
|
|
1745
1745
|
let typeId;
|
|
1746
1746
|
let typeIds;
|
|
1747
|
-
const registry =
|
|
1747
|
+
const registry = chunkPYZYU7EK_cjs.getCollectionRegistry();
|
|
1748
1748
|
if (queryParams.collection) {
|
|
1749
1749
|
const collectionName = queryParams.collection;
|
|
1750
1750
|
const record = registry.getByName(collectionName);
|
|
@@ -1843,13 +1843,13 @@ apiRoutes.get("/content", chunkFCLKX2OS_cjs.optionalAuth(), async (c) => {
|
|
|
1843
1843
|
}, 500);
|
|
1844
1844
|
}
|
|
1845
1845
|
});
|
|
1846
|
-
apiRoutes.get("/collections/:collection/content",
|
|
1846
|
+
apiRoutes.get("/collections/:collection/content", chunkFTXGZ3BF_cjs.optionalAuth(), async (c) => {
|
|
1847
1847
|
const executionStart = Date.now();
|
|
1848
1848
|
try {
|
|
1849
1849
|
const collection = c.req.param("collection");
|
|
1850
1850
|
const db = c.env.DB;
|
|
1851
1851
|
const queryParams = c.req.query();
|
|
1852
|
-
const record =
|
|
1852
|
+
const record = chunkPYZYU7EK_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
1853
1853
|
if (!record || record.isActive === false) {
|
|
1854
1854
|
return c.json({ error: "Collection not found" }, 404);
|
|
1855
1855
|
}
|
|
@@ -1905,7 +1905,7 @@ apiRoutes.get("/collections/:collection/content", chunkFCLKX2OS_cjs.optionalAuth
|
|
|
1905
1905
|
const responseData = {
|
|
1906
1906
|
data: transformedResults,
|
|
1907
1907
|
meta: addTimingMeta(c, {
|
|
1908
|
-
...includeCollection ? { collection:
|
|
1908
|
+
...includeCollection ? { collection: chunkPYZYU7EK_cjs.collectionRecordToRow(record) } : {},
|
|
1909
1909
|
count: results.length,
|
|
1910
1910
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1911
1911
|
// D44: echo the caller's filter with the access policy applied (status=published forced for
|
|
@@ -1930,13 +1930,13 @@ apiRoutes.get("/collections/:collection/content", chunkFCLKX2OS_cjs.optionalAuth
|
|
|
1930
1930
|
}
|
|
1931
1931
|
});
|
|
1932
1932
|
apiRoutes.route("/content", api_content_crud_default);
|
|
1933
|
-
apiRoutes.get("/:collection",
|
|
1933
|
+
apiRoutes.get("/:collection", chunkFTXGZ3BF_cjs.optionalAuth(), async (c) => {
|
|
1934
1934
|
const executionStart = Date.now();
|
|
1935
1935
|
try {
|
|
1936
1936
|
const collection = c.req.param("collection");
|
|
1937
1937
|
const db = c.env.DB;
|
|
1938
1938
|
const queryParams = c.req.query();
|
|
1939
|
-
const record =
|
|
1939
|
+
const record = chunkPYZYU7EK_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
1940
1940
|
if (!record || record.isActive === false) {
|
|
1941
1941
|
return c.json({ error: "Collection not found" }, 404);
|
|
1942
1942
|
}
|
|
@@ -1976,7 +1976,7 @@ apiRoutes.get("/:collection", chunkFCLKX2OS_cjs.optionalAuth(), async (c) => {
|
|
|
1976
1976
|
const responseData = {
|
|
1977
1977
|
data: transformedResults,
|
|
1978
1978
|
meta: addTimingMeta(c, {
|
|
1979
|
-
...includeCollection ? { collection:
|
|
1979
|
+
...includeCollection ? { collection: chunkPYZYU7EK_cjs.collectionRecordToRow(record) } : {},
|
|
1980
1980
|
count: results.length,
|
|
1981
1981
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1982
1982
|
filter: normalizePublicContentFilter(filter, role),
|
|
@@ -1994,12 +1994,12 @@ apiRoutes.get("/:collection", chunkFCLKX2OS_cjs.optionalAuth(), async (c) => {
|
|
|
1994
1994
|
return c.json({ error: "Failed to fetch content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
1995
1995
|
}
|
|
1996
1996
|
});
|
|
1997
|
-
apiRoutes.get("/:collection/:id",
|
|
1997
|
+
apiRoutes.get("/:collection/:id", chunkFTXGZ3BF_cjs.optionalAuth(), async (c) => {
|
|
1998
1998
|
try {
|
|
1999
1999
|
const collection = c.req.param("collection");
|
|
2000
2000
|
const id = c.req.param("id");
|
|
2001
2001
|
const db = c.env.DB;
|
|
2002
|
-
const record =
|
|
2002
|
+
const record = chunkPYZYU7EK_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2003
2003
|
if (!record || record.isActive === false) {
|
|
2004
2004
|
return c.json({ error: "Collection not found" }, 404);
|
|
2005
2005
|
}
|
|
@@ -2008,7 +2008,7 @@ apiRoutes.get("/:collection/:id", chunkFCLKX2OS_cjs.optionalAuth(), async (c) =>
|
|
|
2008
2008
|
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"
|
|
2009
2009
|
).bind(id, record.name).first();
|
|
2010
2010
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
2011
|
-
const coll =
|
|
2011
|
+
const coll = chunkPYZYU7EK_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
2012
2012
|
const transformedContent = {
|
|
2013
2013
|
id: docRow.root_id,
|
|
2014
2014
|
title: docRow.title,
|
|
@@ -2026,7 +2026,7 @@ apiRoutes.get("/:collection/:id", chunkFCLKX2OS_cjs.optionalAuth(), async (c) =>
|
|
|
2026
2026
|
return c.json({ error: "Failed to fetch content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2027
2027
|
}
|
|
2028
2028
|
});
|
|
2029
|
-
apiRoutes.post("/:collection",
|
|
2029
|
+
apiRoutes.post("/:collection", chunkFTXGZ3BF_cjs.requireAuth(), chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2030
2030
|
try {
|
|
2031
2031
|
const collection = c.req.param("collection");
|
|
2032
2032
|
const db = c.env.DB;
|
|
@@ -2059,14 +2059,14 @@ apiRoutes.post("/:collection", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS_cj
|
|
|
2059
2059
|
return c.json({ error: "Failed to create content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2060
2060
|
}
|
|
2061
2061
|
});
|
|
2062
|
-
apiRoutes.put("/:collection/:id",
|
|
2062
|
+
apiRoutes.put("/:collection/:id", chunkFTXGZ3BF_cjs.requireAuth(), chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2063
2063
|
try {
|
|
2064
2064
|
const collection = c.req.param("collection");
|
|
2065
2065
|
const id = c.req.param("id");
|
|
2066
2066
|
const db = c.env.DB;
|
|
2067
2067
|
const user = c.get("user");
|
|
2068
2068
|
const body = await c.req.json();
|
|
2069
|
-
const collRecord =
|
|
2069
|
+
const collRecord = chunkPYZYU7EK_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2070
2070
|
const typeName = collRecord?.name ?? collection;
|
|
2071
2071
|
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();
|
|
2072
2072
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
@@ -2078,7 +2078,7 @@ apiRoutes.put("/:collection/:id", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS
|
|
|
2078
2078
|
} catch (err) {
|
|
2079
2079
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
2080
2080
|
}
|
|
2081
|
-
const docType = await new
|
|
2081
|
+
const docType = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(docRow.type_id);
|
|
2082
2082
|
const svc = new chunkLTZ5WYOK_cjs.DocumentsService(db, { queryableFields: docType?.queryableFields ?? [], typeSchemaVersion: docType?.schemaVersion ?? 1, maxVersionsPerRoot: docType?.settings?.maxVersionsPerRoot ?? 50, tenantId: "default", versioning: docType?.settings?.versioning ?? false });
|
|
2083
2083
|
const input = {};
|
|
2084
2084
|
if (body.title !== void 0) input.title = body.title;
|
|
@@ -2095,7 +2095,7 @@ apiRoutes.put("/:collection/:id", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS
|
|
|
2095
2095
|
const cache = chunk36Z3AKX3_cjs.getCacheService(chunk36Z3AKX3_cjs.CACHE_CONFIGS.api);
|
|
2096
2096
|
await cache.invalidate("content-filtered:*");
|
|
2097
2097
|
await cache.invalidate("collection-content-filtered:*");
|
|
2098
|
-
const coll =
|
|
2098
|
+
const coll = chunkPYZYU7EK_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
2099
2099
|
const saved = await db.prepare("SELECT * FROM documents WHERE id = ?").bind(newDraft.id).first();
|
|
2100
2100
|
const savedData = saved?.data ? JSON.parse(saved.data) : {};
|
|
2101
2101
|
dispatchHookEvent(c, "content:after:update", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
@@ -2107,13 +2107,13 @@ apiRoutes.put("/:collection/:id", chunkFCLKX2OS_cjs.requireAuth(), chunkFCLKX2OS
|
|
|
2107
2107
|
return c.json({ error: "Failed to update content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2108
2108
|
}
|
|
2109
2109
|
});
|
|
2110
|
-
apiRoutes.delete("/:collection/:id",
|
|
2110
|
+
apiRoutes.delete("/:collection/:id", chunkFTXGZ3BF_cjs.requireAuth(), chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2111
2111
|
try {
|
|
2112
2112
|
const collection = c.req.param("collection");
|
|
2113
2113
|
const id = c.req.param("id");
|
|
2114
2114
|
const db = c.env.DB;
|
|
2115
2115
|
const user = c.get("user");
|
|
2116
|
-
const collRecord =
|
|
2116
|
+
const collRecord = chunkPYZYU7EK_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2117
2117
|
const typeName = collRecord?.name ?? collection;
|
|
2118
2118
|
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();
|
|
2119
2119
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
@@ -2335,7 +2335,7 @@ var fileValidationSchema = zod.z.object({
|
|
|
2335
2335
|
// 50MB max
|
|
2336
2336
|
});
|
|
2337
2337
|
var apiMediaRoutes = new hono.Hono();
|
|
2338
|
-
apiMediaRoutes.use("*",
|
|
2338
|
+
apiMediaRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
2339
2339
|
apiMediaRoutes.post("/upload", async (c) => {
|
|
2340
2340
|
try {
|
|
2341
2341
|
const user = c.get("user");
|
|
@@ -3033,7 +3033,7 @@ apiSystemRoutes.get("/info", (c) => {
|
|
|
3033
3033
|
apiSystemRoutes.get("/stats", async (c) => {
|
|
3034
3034
|
try {
|
|
3035
3035
|
const db = c.env.DB;
|
|
3036
|
-
const typeIds =
|
|
3036
|
+
const typeIds = chunkPYZYU7EK_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal).map((r) => r.name);
|
|
3037
3037
|
let contentStats = null;
|
|
3038
3038
|
if (typeIds.length > 0) {
|
|
3039
3039
|
const placeholders = typeIds.map(() => "?").join(",");
|
|
@@ -3108,12 +3108,12 @@ apiSystemRoutes.get("/env", (c) => {
|
|
|
3108
3108
|
});
|
|
3109
3109
|
var api_system_default = apiSystemRoutes;
|
|
3110
3110
|
var adminApiRoutes = new hono.Hono();
|
|
3111
|
-
adminApiRoutes.use("*",
|
|
3112
|
-
adminApiRoutes.use("*",
|
|
3111
|
+
adminApiRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
3112
|
+
adminApiRoutes.use("*", chunkFTXGZ3BF_cjs.requireRole(["admin", "editor"]));
|
|
3113
3113
|
adminApiRoutes.get("/stats", async (c) => {
|
|
3114
3114
|
try {
|
|
3115
3115
|
const db = c.env.DB;
|
|
3116
|
-
const userCollections =
|
|
3116
|
+
const userCollections = chunkPYZYU7EK_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
3117
3117
|
const collectionsCount = userCollections.length;
|
|
3118
3118
|
let contentCount = 0;
|
|
3119
3119
|
if (userCollections.length > 0) {
|
|
@@ -3204,7 +3204,7 @@ adminApiRoutes.get("/collections", async (c) => {
|
|
|
3204
3204
|
try {
|
|
3205
3205
|
const search = c.req.query("search") || "";
|
|
3206
3206
|
const includeInactive = c.req.query("includeInactive") === "true";
|
|
3207
|
-
let records =
|
|
3207
|
+
let records = chunkPYZYU7EK_cjs.getCollectionRegistry().list().filter((r) => !r.internal);
|
|
3208
3208
|
if (!includeInactive) records = records.filter((r) => r.isActive !== false);
|
|
3209
3209
|
if (search) {
|
|
3210
3210
|
const needle = search.toLowerCase();
|
|
@@ -3236,7 +3236,7 @@ adminApiRoutes.get("/collections", async (c) => {
|
|
|
3236
3236
|
adminApiRoutes.get("/collections/:id", async (c) => {
|
|
3237
3237
|
try {
|
|
3238
3238
|
const id = c.req.param("id");
|
|
3239
|
-
const registry =
|
|
3239
|
+
const registry = chunkPYZYU7EK_cjs.getCollectionRegistry();
|
|
3240
3240
|
const record = registry.getById(id) ?? registry.getByName(id);
|
|
3241
3241
|
if (!record) {
|
|
3242
3242
|
return c.json({ error: "Collection not found" }, 404);
|
|
@@ -3286,7 +3286,7 @@ adminApiRoutes.get("/references", async (c) => {
|
|
|
3286
3286
|
if (collectionParams.length === 0) {
|
|
3287
3287
|
return c.json({ error: "Collection is required" }, 400);
|
|
3288
3288
|
}
|
|
3289
|
-
const registry =
|
|
3289
|
+
const registry = chunkPYZYU7EK_cjs.getCollectionRegistry();
|
|
3290
3290
|
const matched = collectionParams.map((param) => registry.getById(param) ?? registry.getByName(param)).filter((r) => !!r);
|
|
3291
3291
|
const seen = /* @__PURE__ */ new Set();
|
|
3292
3292
|
const collections = matched.filter((r) => {
|
|
@@ -3401,7 +3401,7 @@ adminApiRoutes.patch("/collections/:id", collectionsReadOnly);
|
|
|
3401
3401
|
adminApiRoutes.delete("/collections/:id", collectionsReadOnly);
|
|
3402
3402
|
adminApiRoutes.get("/migrations/status", async (c) => {
|
|
3403
3403
|
try {
|
|
3404
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
3404
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-UIMA6ZL6.cjs');
|
|
3405
3405
|
const db = c.env.DB;
|
|
3406
3406
|
const migrationService = new MigrationService2(db);
|
|
3407
3407
|
const status = await migrationService.getMigrationStatus();
|
|
@@ -3444,7 +3444,7 @@ adminApiRoutes.post("/migrations/run", async (c) => {
|
|
|
3444
3444
|
});
|
|
3445
3445
|
adminApiRoutes.get("/migrations/validate", async (c) => {
|
|
3446
3446
|
try {
|
|
3447
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
3447
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-UIMA6ZL6.cjs');
|
|
3448
3448
|
const db = c.env.DB;
|
|
3449
3449
|
const migrationService = new MigrationService2(db);
|
|
3450
3450
|
const validation = await migrationService.validateSchema();
|
|
@@ -3859,7 +3859,7 @@ function renderRegisterPage(data) {
|
|
|
3859
3859
|
}
|
|
3860
3860
|
|
|
3861
3861
|
// src/services/email/email-service-singleton.ts
|
|
3862
|
-
var singleton =
|
|
3862
|
+
var singleton = chunkEUJAEB6W_cjs.createServiceSingleton("EmailService");
|
|
3863
3863
|
function setEmailService(service2) {
|
|
3864
3864
|
singleton.set(service2);
|
|
3865
3865
|
}
|
|
@@ -4667,7 +4667,7 @@ function getLexicalInitScript(settings = {}) {
|
|
|
4667
4667
|
</script>
|
|
4668
4668
|
`;
|
|
4669
4669
|
}
|
|
4670
|
-
var lexicalEditorPlugin =
|
|
4670
|
+
var lexicalEditorPlugin = chunkEUJAEB6W_cjs.definePlugin({
|
|
4671
4671
|
id: "lexical-editor",
|
|
4672
4672
|
version: "1.0.0",
|
|
4673
4673
|
name: "Lexical Editor",
|
|
@@ -7073,7 +7073,7 @@ api.put("/:userId", async (c) => {
|
|
|
7073
7073
|
await saveCustomData(db, userId, sanitized);
|
|
7074
7074
|
return c.json({ success: true });
|
|
7075
7075
|
});
|
|
7076
|
-
var userProfilesPlugin =
|
|
7076
|
+
var userProfilesPlugin = chunkEUJAEB6W_cjs.definePlugin({
|
|
7077
7077
|
id: "user-profiles",
|
|
7078
7078
|
version: "1.0.0",
|
|
7079
7079
|
name: "User Profiles",
|
|
@@ -7111,8 +7111,8 @@ function renderPasswordResetEmail(resetLink, firstName) {
|
|
|
7111
7111
|
async function setCsrfCookie(c, maxAge) {
|
|
7112
7112
|
const secret = c.env?.JWT_SECRET || JWT_SECRET_FALLBACK;
|
|
7113
7113
|
const isDev = c.env?.ENVIRONMENT === "development" || !c.env?.ENVIRONMENT;
|
|
7114
|
-
const csrfToken = await
|
|
7115
|
-
const cookieMaxAge = await
|
|
7114
|
+
const csrfToken = await chunkFTXGZ3BF_cjs.generateCsrfToken(secret);
|
|
7115
|
+
const cookieMaxAge = await chunkFTXGZ3BF_cjs.getJwtExpirySecondsFromDb(c.env?.DB, c.env);
|
|
7116
7116
|
cookie.setCookie(c, "csrf_token", csrfToken, {
|
|
7117
7117
|
httpOnly: false,
|
|
7118
7118
|
secure: !isDev,
|
|
@@ -7171,7 +7171,7 @@ var loginSchema = zod.z.object({
|
|
|
7171
7171
|
});
|
|
7172
7172
|
authRoutes.post(
|
|
7173
7173
|
"/register",
|
|
7174
|
-
|
|
7174
|
+
chunkFTXGZ3BF_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "register" }),
|
|
7175
7175
|
async (c) => {
|
|
7176
7176
|
try {
|
|
7177
7177
|
const db = c.env.DB;
|
|
@@ -7207,7 +7207,7 @@ authRoutes.post(
|
|
|
7207
7207
|
if (existingUser) {
|
|
7208
7208
|
return c.json({ error: "User with this email already exists" }, 400);
|
|
7209
7209
|
}
|
|
7210
|
-
const passwordHash = await
|
|
7210
|
+
const passwordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(password);
|
|
7211
7211
|
const userId = crypto.randomUUID();
|
|
7212
7212
|
const now = /* @__PURE__ */ new Date();
|
|
7213
7213
|
const nowSec = Math.floor(now.getTime() / 1e3);
|
|
@@ -7240,8 +7240,8 @@ authRoutes.post(
|
|
|
7240
7240
|
{ user: { id: userId, email: normalizedEmail, role: "viewer" } },
|
|
7241
7241
|
"fire-and-forget"
|
|
7242
7242
|
);
|
|
7243
|
-
const tokenTtl = await
|
|
7244
|
-
const token = await
|
|
7243
|
+
const tokenTtl = await chunkFTXGZ3BF_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7244
|
+
const token = await chunkFTXGZ3BF_cjs.AuthManager.generateToken(userId, normalizedEmail, "viewer", c.env.JWT_SECRET, tokenTtl);
|
|
7245
7245
|
cookie.setCookie(c, "auth_token", token, {
|
|
7246
7246
|
httpOnly: true,
|
|
7247
7247
|
secure: true,
|
|
@@ -7273,7 +7273,7 @@ authRoutes.post(
|
|
|
7273
7273
|
);
|
|
7274
7274
|
authRoutes.post(
|
|
7275
7275
|
"/login",
|
|
7276
|
-
|
|
7276
|
+
chunkFTXGZ3BF_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "login" }),
|
|
7277
7277
|
async (c) => {
|
|
7278
7278
|
try {
|
|
7279
7279
|
const body = await c.req.json();
|
|
@@ -7305,8 +7305,8 @@ authRoutes.post(
|
|
|
7305
7305
|
await setCsrfCookie(c);
|
|
7306
7306
|
const baBody = await baRes.json();
|
|
7307
7307
|
const user = baBody.user ?? {};
|
|
7308
|
-
const tokenTtl = await
|
|
7309
|
-
const token = await
|
|
7308
|
+
const tokenTtl = await chunkFTXGZ3BF_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7309
|
+
const token = await chunkFTXGZ3BF_cjs.AuthManager.generateToken(
|
|
7310
7310
|
user.id,
|
|
7311
7311
|
user.email,
|
|
7312
7312
|
user.role ?? "viewer",
|
|
@@ -7367,7 +7367,7 @@ authRoutes.get("/logout", async (c) => {
|
|
|
7367
7367
|
clearCsrfCookie(c);
|
|
7368
7368
|
return c.redirect("/auth/login?message=You have been logged out successfully");
|
|
7369
7369
|
});
|
|
7370
|
-
authRoutes.get("/me",
|
|
7370
|
+
authRoutes.get("/me", chunkFTXGZ3BF_cjs.requireAuth(), async (c) => {
|
|
7371
7371
|
try {
|
|
7372
7372
|
const user = c.get("user");
|
|
7373
7373
|
if (!user) {
|
|
@@ -7387,7 +7387,7 @@ authRoutes.get("/me", chunkFCLKX2OS_cjs.requireAuth(), async (c) => {
|
|
|
7387
7387
|
});
|
|
7388
7388
|
authRoutes.post(
|
|
7389
7389
|
"/refresh",
|
|
7390
|
-
|
|
7390
|
+
chunkFTXGZ3BF_cjs.rateLimit({ max: 60, windowMs: 60 * 1e3, keyPrefix: "refresh" }),
|
|
7391
7391
|
async (c) => {
|
|
7392
7392
|
try {
|
|
7393
7393
|
let token = c.req.header("Authorization")?.replace("Bearer ", "");
|
|
@@ -7396,8 +7396,8 @@ authRoutes.post(
|
|
|
7396
7396
|
return c.json({ error: "Authentication required" }, 401);
|
|
7397
7397
|
}
|
|
7398
7398
|
const db = c.env.DB;
|
|
7399
|
-
const grace = await
|
|
7400
|
-
const payload = await
|
|
7399
|
+
const grace = await chunkFTXGZ3BF_cjs.getJwtRefreshGraceSecondsFromDb(db, c.env);
|
|
7400
|
+
const payload = await chunkFTXGZ3BF_cjs.AuthManager.verifyToken(token, c.env.JWT_SECRET, grace);
|
|
7401
7401
|
if (!payload) {
|
|
7402
7402
|
return c.json({ error: "Invalid or expired token" }, 401);
|
|
7403
7403
|
}
|
|
@@ -7405,8 +7405,8 @@ authRoutes.post(
|
|
|
7405
7405
|
if (!row || !row.is_active) {
|
|
7406
7406
|
return c.json({ error: "User is not active" }, 401);
|
|
7407
7407
|
}
|
|
7408
|
-
const tokenTtl = await
|
|
7409
|
-
const newToken = await
|
|
7408
|
+
const tokenTtl = await chunkFTXGZ3BF_cjs.getJwtExpirySecondsFromDb(db, c.env);
|
|
7409
|
+
const newToken = await chunkFTXGZ3BF_cjs.AuthManager.generateToken(row.id, row.email, row.role, c.env.JWT_SECRET, tokenTtl);
|
|
7410
7410
|
cookie.setCookie(c, "auth_token", newToken, {
|
|
7411
7411
|
httpOnly: true,
|
|
7412
7412
|
secure: true,
|
|
@@ -7426,7 +7426,7 @@ authRoutes.post(
|
|
|
7426
7426
|
);
|
|
7427
7427
|
authRoutes.post(
|
|
7428
7428
|
"/register/form",
|
|
7429
|
-
|
|
7429
|
+
chunkFTXGZ3BF_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "register" }),
|
|
7430
7430
|
async (c) => {
|
|
7431
7431
|
try {
|
|
7432
7432
|
const db = c.env.DB;
|
|
@@ -7471,7 +7471,7 @@ authRoutes.post(
|
|
|
7471
7471
|
</div>
|
|
7472
7472
|
`);
|
|
7473
7473
|
}
|
|
7474
|
-
const passwordHash = await
|
|
7474
|
+
const passwordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(password);
|
|
7475
7475
|
const role = isFirstUser ? "admin" : "viewer";
|
|
7476
7476
|
const userId = crypto.randomUUID();
|
|
7477
7477
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -7513,8 +7513,8 @@ authRoutes.post(
|
|
|
7513
7513
|
{ user: { id: userId, email: normalizedEmail, role } },
|
|
7514
7514
|
"fire-and-forget"
|
|
7515
7515
|
);
|
|
7516
|
-
const tokenTtl = await
|
|
7517
|
-
const token = await
|
|
7516
|
+
const tokenTtl = await chunkFTXGZ3BF_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7517
|
+
const token = await chunkFTXGZ3BF_cjs.AuthManager.generateToken(userId, normalizedEmail, role, c.env.JWT_SECRET, tokenTtl);
|
|
7518
7518
|
cookie.setCookie(c, "auth_token", token, {
|
|
7519
7519
|
httpOnly: true,
|
|
7520
7520
|
secure: false,
|
|
@@ -7546,7 +7546,7 @@ authRoutes.post(
|
|
|
7546
7546
|
);
|
|
7547
7547
|
authRoutes.post(
|
|
7548
7548
|
"/login/form",
|
|
7549
|
-
|
|
7549
|
+
chunkFTXGZ3BF_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "login" }),
|
|
7550
7550
|
async (c) => {
|
|
7551
7551
|
try {
|
|
7552
7552
|
const formData = await c.req.formData();
|
|
@@ -7615,14 +7615,14 @@ authRoutes.post(
|
|
|
7615
7615
|
);
|
|
7616
7616
|
authRoutes.post(
|
|
7617
7617
|
"/seed-admin",
|
|
7618
|
-
|
|
7618
|
+
chunkFTXGZ3BF_cjs.rateLimit({ max: 10, windowMs: 60 * 1e3, keyPrefix: "seed-admin" }),
|
|
7619
7619
|
async (c) => {
|
|
7620
7620
|
try {
|
|
7621
7621
|
const db = c.env.DB;
|
|
7622
7622
|
const rbac = new chunkLTZ5WYOK_cjs.RbacService(db);
|
|
7623
7623
|
const results = [];
|
|
7624
7624
|
const upsertSeedUser = async (opts) => {
|
|
7625
|
-
const passwordHash = await
|
|
7625
|
+
const passwordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(opts.password);
|
|
7626
7626
|
const nowMs = Date.now();
|
|
7627
7627
|
const nowSec = Math.floor(nowMs / 1e3);
|
|
7628
7628
|
const existing = await db.prepare("SELECT id FROM auth_user WHERE email = ?").bind(opts.email).first();
|
|
@@ -7847,7 +7847,7 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7847
7847
|
if (invitationAge > maxAge) {
|
|
7848
7848
|
return c.json({ error: "Invitation has expired" }, 400);
|
|
7849
7849
|
}
|
|
7850
|
-
const passwordHash = await
|
|
7850
|
+
const passwordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(password);
|
|
7851
7851
|
const updateStmt = db.prepare(`
|
|
7852
7852
|
UPDATE auth_user SET
|
|
7853
7853
|
password_hash = ?,
|
|
@@ -7864,8 +7864,8 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7864
7864
|
Date.now(),
|
|
7865
7865
|
invitedUser.id
|
|
7866
7866
|
).run();
|
|
7867
|
-
const tokenTtl = await
|
|
7868
|
-
const authToken = await
|
|
7867
|
+
const tokenTtl = await chunkFTXGZ3BF_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7868
|
+
const authToken = await chunkFTXGZ3BF_cjs.AuthManager.generateToken(invitedUser.id, invitedUser.email, invitedUser.role, c.env.JWT_SECRET, tokenTtl);
|
|
7869
7869
|
cookie.setCookie(c, "auth_token", authToken, {
|
|
7870
7870
|
httpOnly: true,
|
|
7871
7871
|
secure: true,
|
|
@@ -7881,7 +7881,7 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7881
7881
|
});
|
|
7882
7882
|
authRoutes.post(
|
|
7883
7883
|
"/request-password-reset",
|
|
7884
|
-
|
|
7884
|
+
chunkFTXGZ3BF_cjs.rateLimit({ max: 3, windowMs: 15 * 60 * 1e3, keyPrefix: "password-reset" }),
|
|
7885
7885
|
async (c) => {
|
|
7886
7886
|
try {
|
|
7887
7887
|
const formData = await c.req.formData();
|
|
@@ -8118,7 +8118,7 @@ authRoutes.post("/reset-password", async (c) => {
|
|
|
8118
8118
|
if (Date.now() > user.password_reset_expires) {
|
|
8119
8119
|
return c.json({ error: "Reset token has expired" }, 400);
|
|
8120
8120
|
}
|
|
8121
|
-
const newPasswordHash = await
|
|
8121
|
+
const newPasswordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(password);
|
|
8122
8122
|
try {
|
|
8123
8123
|
const historyStmt = db.prepare(`
|
|
8124
8124
|
INSERT INTO auth_password_history (id, user_id, password_hash, created_at)
|
|
@@ -8332,7 +8332,7 @@ app.post("/test-seed-defaults", async (c) => {
|
|
|
8332
8332
|
var test_cleanup_default = app;
|
|
8333
8333
|
|
|
8334
8334
|
// src/plugins/available/easy-mdx/index.ts
|
|
8335
|
-
|
|
8335
|
+
chunkEUJAEB6W_cjs.definePlugin({
|
|
8336
8336
|
id: "easy-mdx",
|
|
8337
8337
|
version: "1.0.0",
|
|
8338
8338
|
name: "EasyMDE Markdown Editor",
|
|
@@ -8532,7 +8532,7 @@ function getMDXEditorInitScript(config) {
|
|
|
8532
8532
|
}
|
|
8533
8533
|
|
|
8534
8534
|
// src/plugins/available/tinymce-plugin/index.ts
|
|
8535
|
-
|
|
8535
|
+
chunkEUJAEB6W_cjs.definePlugin({
|
|
8536
8536
|
id: "tinymce-plugin",
|
|
8537
8537
|
version: "1.0.0",
|
|
8538
8538
|
name: "TinyMCE",
|
|
@@ -8802,7 +8802,7 @@ function getQuillCDN(version = "2.0.2") {
|
|
|
8802
8802
|
</style>
|
|
8803
8803
|
`;
|
|
8804
8804
|
}
|
|
8805
|
-
|
|
8805
|
+
chunkEUJAEB6W_cjs.definePlugin({
|
|
8806
8806
|
id: "quill-editor",
|
|
8807
8807
|
version: "1.0.0",
|
|
8808
8808
|
name: "Quill Editor",
|
|
@@ -11376,7 +11376,7 @@ function extractFieldData(fields, formData, options = {}) {
|
|
|
11376
11376
|
}
|
|
11377
11377
|
return { data, errors };
|
|
11378
11378
|
}
|
|
11379
|
-
adminContentRoutes.use("*",
|
|
11379
|
+
adminContentRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
11380
11380
|
async function getCollectionFields(db, collectionId) {
|
|
11381
11381
|
console.log(`[getCollectionFields] Loading fields for collection: ${collectionId}`);
|
|
11382
11382
|
const collectionStmt = db.prepare("SELECT schema, queryable_fields FROM document_types WHERE id = ?");
|
|
@@ -11403,7 +11403,7 @@ async function getCollectionFields(db, collectionId) {
|
|
|
11403
11403
|
};
|
|
11404
11404
|
});
|
|
11405
11405
|
}
|
|
11406
|
-
const codeCollections2 = await
|
|
11406
|
+
const codeCollections2 = await chunkPYZYU7EK_cjs.loadCollectionConfigs();
|
|
11407
11407
|
const codeMatch = codeCollections2.find((c) => c.name === collectionId);
|
|
11408
11408
|
if (codeMatch && codeMatch.schema?.properties) {
|
|
11409
11409
|
console.log(`[getCollectionFields] DB doc type has no properties \u2014 using code collection schema`);
|
|
@@ -11435,7 +11435,7 @@ async function getCollectionFields(db, collectionId) {
|
|
|
11435
11435
|
}
|
|
11436
11436
|
}
|
|
11437
11437
|
console.log(`[getCollectionFields] Not in database, checking code collections`);
|
|
11438
|
-
const codeCollections = await
|
|
11438
|
+
const codeCollections = await chunkPYZYU7EK_cjs.loadCollectionConfigs();
|
|
11439
11439
|
console.log(`[getCollectionFields] Found ${codeCollections.length} code collections`);
|
|
11440
11440
|
const codeCollection = codeCollections.find((c) => c.name === collectionId);
|
|
11441
11441
|
if (codeCollection && codeCollection.schema) {
|
|
@@ -11489,7 +11489,7 @@ async function getCollection(db, collectionId) {
|
|
|
11489
11489
|
};
|
|
11490
11490
|
}
|
|
11491
11491
|
console.log(`[getCollection] Not in database, checking code collections`);
|
|
11492
|
-
const codeCollections = await
|
|
11492
|
+
const codeCollections = await chunkPYZYU7EK_cjs.loadCollectionConfigs();
|
|
11493
11493
|
const codeCollection = codeCollections.find((c) => c.name === collectionId);
|
|
11494
11494
|
if (codeCollection) {
|
|
11495
11495
|
console.log(`[getCollection] Found code collection: ${collectionId}`);
|
|
@@ -11508,7 +11508,7 @@ async function getCollection(db, collectionId) {
|
|
|
11508
11508
|
}
|
|
11509
11509
|
async function getDocBackingType(db, collectionName) {
|
|
11510
11510
|
if (!collectionName) return null;
|
|
11511
|
-
const dt = await new
|
|
11511
|
+
const dt = await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db).findById(collectionName);
|
|
11512
11512
|
return dt && dt.isActive ? dt : null;
|
|
11513
11513
|
}
|
|
11514
11514
|
async function getCollectionByName(db, name) {
|
|
@@ -11525,7 +11525,7 @@ async function getCollectionByName(db, name) {
|
|
|
11525
11525
|
};
|
|
11526
11526
|
}
|
|
11527
11527
|
console.log(`[getCollectionByName] Not in database, checking code collections`);
|
|
11528
|
-
const codeCollections = await
|
|
11528
|
+
const codeCollections = await chunkPYZYU7EK_cjs.loadCollectionConfigs();
|
|
11529
11529
|
const codeCollection = codeCollections.find((c) => c.name === name);
|
|
11530
11530
|
if (codeCollection) {
|
|
11531
11531
|
console.log(`[getCollectionByName] Found code collection: ${name}`);
|
|
@@ -11541,7 +11541,7 @@ async function getCollectionByName(db, name) {
|
|
|
11541
11541
|
return null;
|
|
11542
11542
|
}
|
|
11543
11543
|
async function loadContentEditorFlags(db) {
|
|
11544
|
-
const flags = { workflowEnabled: await
|
|
11544
|
+
const flags = { workflowEnabled: await chunkFTXGZ3BF_cjs.isPluginActive(db, "workflow") };
|
|
11545
11545
|
const editors = [
|
|
11546
11546
|
["tinymce-plugin", "tinymce"],
|
|
11547
11547
|
["quill-editor", "quill"],
|
|
@@ -11549,10 +11549,10 @@ async function loadContentEditorFlags(db) {
|
|
|
11549
11549
|
["lexical-editor", "lexical"]
|
|
11550
11550
|
];
|
|
11551
11551
|
for (const [plugin, key] of editors) {
|
|
11552
|
-
const enabled = await
|
|
11552
|
+
const enabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, plugin);
|
|
11553
11553
|
flags[`${key}Enabled`] = enabled;
|
|
11554
11554
|
if (enabled) {
|
|
11555
|
-
const ps = new
|
|
11555
|
+
const ps = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
11556
11556
|
const p = await ps.getPlugin(plugin);
|
|
11557
11557
|
flags[`${key}Settings`] = p?.settings;
|
|
11558
11558
|
}
|
|
@@ -11588,9 +11588,9 @@ adminContentRoutes.get("/", async (c) => {
|
|
|
11588
11588
|
const offset = (page - 1) * limit;
|
|
11589
11589
|
const collectionsStmt = db.prepare("SELECT id, name, display_name FROM document_types WHERE is_active = 1 ORDER BY display_name");
|
|
11590
11590
|
const { results: collectionsResults } = await collectionsStmt.all();
|
|
11591
|
-
const codeCollections = await
|
|
11591
|
+
const codeCollections = await chunkPYZYU7EK_cjs.loadCollectionConfigs();
|
|
11592
11592
|
const codeCollectionMap = new Map(codeCollections.map((c2) => [c2.name, c2]));
|
|
11593
|
-
const docTypeRegistry = new
|
|
11593
|
+
const docTypeRegistry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
11594
11594
|
const docTypes = (await docTypeRegistry.findAll()).filter((dt) => !dt.settings?.internal && !dt.isAuth);
|
|
11595
11595
|
const visibleTypeIds = new Set(docTypes.map((dt) => dt.id));
|
|
11596
11596
|
const allCollections = [
|
|
@@ -11602,7 +11602,7 @@ adminContentRoutes.get("/", async (c) => {
|
|
|
11602
11602
|
...allCollections.map((c2) => ({ name: c2.name, displayName: c2.displayName })),
|
|
11603
11603
|
...docTypes.filter((dt) => !collectionNames.has(dt.id)).map((dt) => ({ name: `doc:${dt.id}`, displayName: dt.displayName }))
|
|
11604
11604
|
];
|
|
11605
|
-
const newContentCollections = await
|
|
11605
|
+
const newContentCollections = await chunkPYZYU7EK_cjs.getVisibleCollections(db);
|
|
11606
11606
|
const docBackedCollection = !modelName.startsWith("doc:") && modelName !== "all" ? docTypes.find((dt) => dt.id === modelName) : void 0;
|
|
11607
11607
|
const isDocModel = modelName.startsWith("doc:") || !!docBackedCollection;
|
|
11608
11608
|
if (isDocModel) {
|
|
@@ -11879,9 +11879,9 @@ adminContentRoutes.get("/new", async (c) => {
|
|
|
11879
11879
|
const collectionsStmt = db2.prepare("SELECT id, name, display_name, description FROM document_types WHERE is_active = 1 ORDER BY display_name");
|
|
11880
11880
|
const { results } = await collectionsStmt.all();
|
|
11881
11881
|
const visibleTypeIds = new Set(
|
|
11882
|
-
(await new
|
|
11882
|
+
(await new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db2).findAll()).filter((dt) => !dt.settings?.internal && !dt.isAuth).map((dt) => dt.id)
|
|
11883
11883
|
);
|
|
11884
|
-
const codeCollections = await
|
|
11884
|
+
const codeCollections = await chunkPYZYU7EK_cjs.loadCollectionConfigs();
|
|
11885
11885
|
const dbCollectionNames = new Set((results || []).map((r) => r.name));
|
|
11886
11886
|
const allCollections = [
|
|
11887
11887
|
...codeCollections.filter((c2) => !dbCollectionNames.has(c2.name)).map((c2) => ({
|
|
@@ -11947,32 +11947,32 @@ adminContentRoutes.get("/new", async (c) => {
|
|
|
11947
11947
|
return c.html(renderContentFormPage(formData2));
|
|
11948
11948
|
}
|
|
11949
11949
|
const fields = await getCollectionFields(db, collection.id);
|
|
11950
|
-
const workflowEnabled = await
|
|
11951
|
-
const tinymceEnabled = await
|
|
11950
|
+
const workflowEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "workflow");
|
|
11951
|
+
const tinymceEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "tinymce-plugin");
|
|
11952
11952
|
let tinymceSettings;
|
|
11953
11953
|
if (tinymceEnabled) {
|
|
11954
|
-
const pluginService = new
|
|
11954
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
11955
11955
|
const tinymcePlugin2 = await pluginService.getPlugin("tinymce-plugin");
|
|
11956
11956
|
tinymceSettings = tinymcePlugin2?.settings;
|
|
11957
11957
|
}
|
|
11958
|
-
const quillEnabled = await
|
|
11958
|
+
const quillEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "quill-editor");
|
|
11959
11959
|
let quillSettings;
|
|
11960
11960
|
if (quillEnabled) {
|
|
11961
|
-
const pluginService = new
|
|
11961
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
11962
11962
|
const quillPlugin = await pluginService.getPlugin("quill-editor");
|
|
11963
11963
|
quillSettings = quillPlugin?.settings;
|
|
11964
11964
|
}
|
|
11965
|
-
const mdxeditorEnabled = await
|
|
11965
|
+
const mdxeditorEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "easy-mdx");
|
|
11966
11966
|
let mdxeditorSettings;
|
|
11967
11967
|
if (mdxeditorEnabled) {
|
|
11968
|
-
const pluginService = new
|
|
11968
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
11969
11969
|
const mdxeditorPlugin = await pluginService.getPlugin("easy-mdx");
|
|
11970
11970
|
mdxeditorSettings = mdxeditorPlugin?.settings;
|
|
11971
11971
|
}
|
|
11972
|
-
const lexicalEnabled = await
|
|
11972
|
+
const lexicalEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "lexical-editor");
|
|
11973
11973
|
let lexicalSettings;
|
|
11974
11974
|
if (lexicalEnabled) {
|
|
11975
|
-
const pluginService = new
|
|
11975
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
11976
11976
|
const lexicalPlugin = await pluginService.getPlugin("lexical-editor");
|
|
11977
11977
|
lexicalSettings = lexicalPlugin?.settings;
|
|
11978
11978
|
}
|
|
@@ -12100,32 +12100,32 @@ adminContentRoutes.get("/:id/edit", async (c) => {
|
|
|
12100
12100
|
};
|
|
12101
12101
|
const fields = await getCollectionFields(db, content.collection_id);
|
|
12102
12102
|
const contentData = content.data ? JSON.parse(content.data) : {};
|
|
12103
|
-
const workflowEnabled = await
|
|
12104
|
-
const tinymceEnabled = await
|
|
12103
|
+
const workflowEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "workflow");
|
|
12104
|
+
const tinymceEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "tinymce-plugin");
|
|
12105
12105
|
let tinymceSettings;
|
|
12106
12106
|
if (tinymceEnabled) {
|
|
12107
|
-
const pluginService = new
|
|
12107
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
12108
12108
|
const tinymcePlugin2 = await pluginService.getPlugin("tinymce-plugin");
|
|
12109
12109
|
tinymceSettings = tinymcePlugin2?.settings;
|
|
12110
12110
|
}
|
|
12111
|
-
const quillEnabled = await
|
|
12111
|
+
const quillEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "quill-editor");
|
|
12112
12112
|
let quillSettings;
|
|
12113
12113
|
if (quillEnabled) {
|
|
12114
|
-
const pluginService = new
|
|
12114
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
12115
12115
|
const quillPlugin = await pluginService.getPlugin("quill-editor");
|
|
12116
12116
|
quillSettings = quillPlugin?.settings;
|
|
12117
12117
|
}
|
|
12118
|
-
const mdxeditorEnabled = await
|
|
12118
|
+
const mdxeditorEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "easy-mdx");
|
|
12119
12119
|
let mdxeditorSettings;
|
|
12120
12120
|
if (mdxeditorEnabled) {
|
|
12121
|
-
const pluginService = new
|
|
12121
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
12122
12122
|
const mdxeditorPlugin = await pluginService.getPlugin("easy-mdx");
|
|
12123
12123
|
mdxeditorSettings = mdxeditorPlugin?.settings;
|
|
12124
12124
|
}
|
|
12125
|
-
const lexicalEnabled = await
|
|
12125
|
+
const lexicalEnabled = await chunkFTXGZ3BF_cjs.isPluginActive(db, "lexical-editor");
|
|
12126
12126
|
let lexicalSettings;
|
|
12127
12127
|
if (lexicalEnabled) {
|
|
12128
|
-
const pluginService = new
|
|
12128
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
12129
12129
|
const lexicalPlugin = await pluginService.getPlugin("lexical-editor");
|
|
12130
12130
|
lexicalSettings = lexicalPlugin?.settings;
|
|
12131
12131
|
}
|
|
@@ -12498,7 +12498,7 @@ adminContentRoutes.put("/:id", async (c) => {
|
|
|
12498
12498
|
`);
|
|
12499
12499
|
}
|
|
12500
12500
|
});
|
|
12501
|
-
adminContentRoutes.post("/preview",
|
|
12501
|
+
adminContentRoutes.post("/preview", chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
12502
12502
|
try {
|
|
12503
12503
|
const formData = await c.req.formData();
|
|
12504
12504
|
const collectionId = formData.get("collection_id");
|
|
@@ -12817,7 +12817,7 @@ adminContentRoutes.delete("/:id", async (c) => {
|
|
|
12817
12817
|
return c.json({ success: false, error: "Failed to delete content" }, 500);
|
|
12818
12818
|
}
|
|
12819
12819
|
});
|
|
12820
|
-
adminContentRoutes.get("/:id/version/:version/preview",
|
|
12820
|
+
adminContentRoutes.get("/:id/version/:version/preview", chunkFTXGZ3BF_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
12821
12821
|
try {
|
|
12822
12822
|
const id = c.req.param("id");
|
|
12823
12823
|
const version = parseInt(c.req.param("version") || "0");
|
|
@@ -12913,7 +12913,7 @@ function parseDocFormData(formData, queryableFields = []) {
|
|
|
12913
12913
|
return { title, slug, data };
|
|
12914
12914
|
}
|
|
12915
12915
|
async function getDocService(db, typeId, tenantId) {
|
|
12916
|
-
const registry = new
|
|
12916
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
12917
12917
|
const docType = await registry.findById(typeId);
|
|
12918
12918
|
const svc = new chunkLTZ5WYOK_cjs.DocumentsService(db, {
|
|
12919
12919
|
queryableFields: docType?.queryableFields ?? [],
|
|
@@ -12926,7 +12926,7 @@ async function getDocService(db, typeId, tenantId) {
|
|
|
12926
12926
|
}
|
|
12927
12927
|
adminContentRoutes.get("/documents/:typeId/new", async (c) => {
|
|
12928
12928
|
const { typeId } = c.req.param();
|
|
12929
|
-
const registry = new
|
|
12929
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(c.env.DB);
|
|
12930
12930
|
const docType = await registry.findById(typeId);
|
|
12931
12931
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12932
12932
|
return c.html(chunkN32OWET6_cjs.renderDocumentFormPage({ docType, isEdit: false, user: userCtx(c) }));
|
|
@@ -12951,7 +12951,7 @@ adminContentRoutes.post("/documents/:typeId/new", async (c) => {
|
|
|
12951
12951
|
}), user?.userId);
|
|
12952
12952
|
return c.redirect(`/admin/content/documents/${typeId}/${doc.rootId}/edit?message=Created+successfully`);
|
|
12953
12953
|
} catch (err) {
|
|
12954
|
-
const registry = new
|
|
12954
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(c.env.DB);
|
|
12955
12955
|
const docType = await registry.findById(typeId);
|
|
12956
12956
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12957
12957
|
return c.html(chunkN32OWET6_cjs.renderDocumentFormPage({ docType, isEdit: false, user: userCtx(c), message: err?.message ?? "Failed to create", messageType: "error" }));
|
|
@@ -12961,7 +12961,7 @@ adminContentRoutes.get("/documents/:typeId/:rootId/edit", async (c) => {
|
|
|
12961
12961
|
const { typeId, rootId } = c.req.param();
|
|
12962
12962
|
const db = c.env.DB;
|
|
12963
12963
|
const message = c.req.query("message");
|
|
12964
|
-
const registry = new
|
|
12964
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
12965
12965
|
const docType = await registry.findById(typeId);
|
|
12966
12966
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12967
12967
|
const tenantId = reqTenant(c);
|
|
@@ -13074,7 +13074,7 @@ adminContentRoutes.get("/documents/:typeId/:rootId/versions", async (c) => {
|
|
|
13074
13074
|
const { typeId, rootId } = c.req.param();
|
|
13075
13075
|
const db = c.env.DB;
|
|
13076
13076
|
const { renderVersionHistoryFragment } = await import('./admin-documents-form.template-LSZKGA5J.cjs');
|
|
13077
|
-
const registry = new
|
|
13077
|
+
const registry = new chunkFTXGZ3BF_cjs.DocumentTypeRegistry(db);
|
|
13078
13078
|
const docType = await registry.findById(typeId);
|
|
13079
13079
|
if (!docType) return c.html("<div>Unknown type.</div>", 404);
|
|
13080
13080
|
const result = await db.prepare(
|
|
@@ -15007,7 +15007,7 @@ var TenantService = class {
|
|
|
15007
15007
|
SET name = ?, domain = ?, status = ?, notes = ?, updated_at = ?
|
|
15008
15008
|
WHERE slug = ?
|
|
15009
15009
|
`).bind(name, domain, status, notes, now, slug).run();
|
|
15010
|
-
|
|
15010
|
+
chunkPYZYU7EK_cjs.invalidateTenantCache();
|
|
15011
15011
|
const updated = await this.getTenantBySlug(slug);
|
|
15012
15012
|
if (!updated) throw new Error("Tenant not found");
|
|
15013
15013
|
return updated;
|
|
@@ -15025,7 +15025,7 @@ var TenantService = class {
|
|
|
15025
15025
|
throw new Error(`Tenant '${slug}' still owns ${docCount} document(s). Delete or migrate its content first.`);
|
|
15026
15026
|
}
|
|
15027
15027
|
await this.db.prepare(`DELETE FROM auth_tenant WHERE slug = ?`).bind(slug).run();
|
|
15028
|
-
|
|
15028
|
+
chunkPYZYU7EK_cjs.invalidateTenantCache();
|
|
15029
15029
|
}
|
|
15030
15030
|
// ─── Membership (auth_tenant_member) ───────────────────────────────────────
|
|
15031
15031
|
// Tenant resolution and the admin switcher are gated on membership: an authed user may only
|
|
@@ -15269,7 +15269,7 @@ var TenantService = class {
|
|
|
15269
15269
|
INSERT INTO auth_tenant (id, name, slug, status, domain, notes, metadata, created_at, updated_at)
|
|
15270
15270
|
VALUES (?, ?, ?, 'active', ?, ?, '{}', ?, ?)
|
|
15271
15271
|
`).bind(id, input.name, input.slug, input.domain, input.notes, now, now).run();
|
|
15272
|
-
|
|
15272
|
+
chunkPYZYU7EK_cjs.invalidateTenantCache();
|
|
15273
15273
|
const created = await this.getTenantBySlug(input.slug);
|
|
15274
15274
|
if (!created) throw new Error("Failed to create tenant");
|
|
15275
15275
|
return created;
|
|
@@ -15293,14 +15293,14 @@ function mapRowToTenant(row) {
|
|
|
15293
15293
|
|
|
15294
15294
|
// src/routes/admin-users.ts
|
|
15295
15295
|
var userRoutes = new hono.Hono();
|
|
15296
|
-
userRoutes.use("*",
|
|
15297
|
-
userRoutes.use("/users/*",
|
|
15298
|
-
userRoutes.use("/users",
|
|
15299
|
-
userRoutes.use("/invite-user",
|
|
15300
|
-
userRoutes.use("/resend-invitation/*",
|
|
15301
|
-
userRoutes.use("/cancel-invitation/*",
|
|
15302
|
-
userRoutes.use("/activity-logs",
|
|
15303
|
-
userRoutes.use("/activity-logs/*",
|
|
15296
|
+
userRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
15297
|
+
userRoutes.use("/users/*", chunkFTXGZ3BF_cjs.requireRole(["admin"]));
|
|
15298
|
+
userRoutes.use("/users", chunkFTXGZ3BF_cjs.requireRole(["admin"]));
|
|
15299
|
+
userRoutes.use("/invite-user", chunkFTXGZ3BF_cjs.requireRole(["admin"]));
|
|
15300
|
+
userRoutes.use("/resend-invitation/*", chunkFTXGZ3BF_cjs.requireRole(["admin"]));
|
|
15301
|
+
userRoutes.use("/cancel-invitation/*", chunkFTXGZ3BF_cjs.requireRole(["admin"]));
|
|
15302
|
+
userRoutes.use("/activity-logs", chunkFTXGZ3BF_cjs.requireRole(["admin"]));
|
|
15303
|
+
userRoutes.use("/activity-logs/*", chunkFTXGZ3BF_cjs.requireRole(["admin"]));
|
|
15304
15304
|
userRoutes.get("/", (c) => {
|
|
15305
15305
|
return c.redirect("/admin/dashboard");
|
|
15306
15306
|
});
|
|
@@ -15467,7 +15467,7 @@ userRoutes.put("/profile", async (c) => {
|
|
|
15467
15467
|
}
|
|
15468
15468
|
await saveCustomData(db, user.userId, sanitized);
|
|
15469
15469
|
}
|
|
15470
|
-
await
|
|
15470
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
15471
15471
|
db,
|
|
15472
15472
|
user.userId,
|
|
15473
15473
|
"profile.update",
|
|
@@ -15530,7 +15530,7 @@ userRoutes.post("/profile/avatar", async (c) => {
|
|
|
15530
15530
|
SELECT first_name, last_name FROM auth_user WHERE id = ?
|
|
15531
15531
|
`);
|
|
15532
15532
|
const userData = await userStmt.bind(user.userId).first();
|
|
15533
|
-
await
|
|
15533
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
15534
15534
|
db,
|
|
15535
15535
|
user.userId,
|
|
15536
15536
|
"profile.avatar_update",
|
|
@@ -15601,7 +15601,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15601
15601
|
dismissible: true
|
|
15602
15602
|
}));
|
|
15603
15603
|
}
|
|
15604
|
-
const validPassword = await
|
|
15604
|
+
const validPassword = await chunkFTXGZ3BF_cjs.AuthManager.verifyPassword(currentPassword, userData.password_hash);
|
|
15605
15605
|
if (!validPassword) {
|
|
15606
15606
|
return c.html(chunkN32OWET6_cjs.renderAlert({
|
|
15607
15607
|
type: "error",
|
|
@@ -15609,7 +15609,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15609
15609
|
dismissible: true
|
|
15610
15610
|
}));
|
|
15611
15611
|
}
|
|
15612
|
-
const newPasswordHash = await
|
|
15612
|
+
const newPasswordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(newPassword);
|
|
15613
15613
|
const historyStmt = db.prepare(`
|
|
15614
15614
|
INSERT INTO auth_password_history (id, user_id, password_hash, created_at)
|
|
15615
15615
|
VALUES (?, ?, ?, ?)
|
|
@@ -15625,7 +15625,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15625
15625
|
WHERE id = ?
|
|
15626
15626
|
`);
|
|
15627
15627
|
await updateStmt.bind(newPasswordHash, Date.now(), user.userId).run();
|
|
15628
|
-
await
|
|
15628
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
15629
15629
|
db,
|
|
15630
15630
|
user.userId,
|
|
15631
15631
|
"profile.password_change",
|
|
@@ -15692,7 +15692,7 @@ userRoutes.get("/users", async (c) => {
|
|
|
15692
15692
|
`);
|
|
15693
15693
|
const countResult = await countStmt.bind(...params).first();
|
|
15694
15694
|
const totalUsers = countResult?.total || 0;
|
|
15695
|
-
await
|
|
15695
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
15696
15696
|
db,
|
|
15697
15697
|
user.userId,
|
|
15698
15698
|
"users.list_view",
|
|
@@ -15873,7 +15873,7 @@ userRoutes.post("/users/new", async (c) => {
|
|
|
15873
15873
|
dismissible: true
|
|
15874
15874
|
}));
|
|
15875
15875
|
}
|
|
15876
|
-
const passwordHash = await
|
|
15876
|
+
const passwordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(password);
|
|
15877
15877
|
const userId = crypto.randomUUID();
|
|
15878
15878
|
const createStmt = db.prepare(`
|
|
15879
15879
|
INSERT INTO auth_user (
|
|
@@ -15898,7 +15898,7 @@ userRoutes.post("/users/new", async (c) => {
|
|
|
15898
15898
|
if (sanitizedRegistrationCustom !== null && Object.keys(sanitizedRegistrationCustom).length > 0) {
|
|
15899
15899
|
await writeProfileData(db, userId, { custom: sanitizedRegistrationCustom }, user.userId);
|
|
15900
15900
|
}
|
|
15901
|
-
await
|
|
15901
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
15902
15902
|
db,
|
|
15903
15903
|
user.userId,
|
|
15904
15904
|
"user!.create",
|
|
@@ -15937,7 +15937,7 @@ userRoutes.get("/users/:id", async (c) => {
|
|
|
15937
15937
|
if (!userRecord) {
|
|
15938
15938
|
return c.json({ error: "User not found" }, 404);
|
|
15939
15939
|
}
|
|
15940
|
-
await
|
|
15940
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
15941
15941
|
db,
|
|
15942
15942
|
user.userId,
|
|
15943
15943
|
"user!.view",
|
|
@@ -16151,7 +16151,7 @@ userRoutes.put("/users/:id", async (c) => {
|
|
|
16151
16151
|
userId
|
|
16152
16152
|
).run();
|
|
16153
16153
|
if (newPassword) {
|
|
16154
|
-
const passwordHash = await
|
|
16154
|
+
const passwordHash = await chunkFTXGZ3BF_cjs.AuthManager.hashPassword(newPassword);
|
|
16155
16155
|
const updatePasswordStmt = db.prepare(`
|
|
16156
16156
|
UPDATE auth_user SET password_hash = ?, updated_at = ? WHERE id = ?
|
|
16157
16157
|
`);
|
|
@@ -16164,7 +16164,7 @@ userRoutes.put("/users/:id", async (c) => {
|
|
|
16164
16164
|
...sanitizedCustom !== null ? { custom: sanitizedCustom } : {}
|
|
16165
16165
|
}, user.userId);
|
|
16166
16166
|
}
|
|
16167
|
-
await
|
|
16167
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
16168
16168
|
db,
|
|
16169
16169
|
user.userId,
|
|
16170
16170
|
"user.update",
|
|
@@ -16210,7 +16210,7 @@ userRoutes.post("/users/:id/toggle", async (c) => {
|
|
|
16210
16210
|
UPDATE auth_user SET is_active = ?, updated_at = ? WHERE id = ?
|
|
16211
16211
|
`);
|
|
16212
16212
|
await toggleStmt.bind(active ? 1 : 0, Date.now(), userId).run();
|
|
16213
|
-
await
|
|
16213
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
16214
16214
|
db,
|
|
16215
16215
|
user.userId,
|
|
16216
16216
|
active ? "user.activate" : "user.deactivate",
|
|
@@ -16251,7 +16251,7 @@ userRoutes.delete("/users/:id", async (c) => {
|
|
|
16251
16251
|
DELETE FROM auth_user WHERE id = ?
|
|
16252
16252
|
`);
|
|
16253
16253
|
await deleteStmt.bind(userId).run();
|
|
16254
|
-
await
|
|
16254
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
16255
16255
|
db,
|
|
16256
16256
|
user.userId,
|
|
16257
16257
|
"user!.hard_delete",
|
|
@@ -16270,7 +16270,7 @@ userRoutes.delete("/users/:id", async (c) => {
|
|
|
16270
16270
|
UPDATE auth_user SET is_active = 0, updated_at = ? WHERE id = ?
|
|
16271
16271
|
`);
|
|
16272
16272
|
await deleteStmt.bind(Date.now(), userId).run();
|
|
16273
|
-
await
|
|
16273
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
16274
16274
|
db,
|
|
16275
16275
|
user.userId,
|
|
16276
16276
|
"user!.soft_delete",
|
|
@@ -16336,7 +16336,7 @@ userRoutes.post("/invite-user", async (c) => {
|
|
|
16336
16336
|
Date.now(),
|
|
16337
16337
|
Date.now()
|
|
16338
16338
|
).run();
|
|
16339
|
-
await
|
|
16339
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
16340
16340
|
db,
|
|
16341
16341
|
user.userId,
|
|
16342
16342
|
"user!.invite_sent",
|
|
@@ -16393,7 +16393,7 @@ userRoutes.post("/resend-invitation/:id", async (c) => {
|
|
|
16393
16393
|
Date.now(),
|
|
16394
16394
|
userId
|
|
16395
16395
|
).run();
|
|
16396
|
-
await
|
|
16396
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
16397
16397
|
db,
|
|
16398
16398
|
user.userId,
|
|
16399
16399
|
"user!.invitation_resent",
|
|
@@ -16429,7 +16429,7 @@ userRoutes.delete("/cancel-invitation/:id", async (c) => {
|
|
|
16429
16429
|
}
|
|
16430
16430
|
const deleteStmt = db.prepare(`DELETE FROM auth_user WHERE id = ?`);
|
|
16431
16431
|
await deleteStmt.bind(userId).run();
|
|
16432
|
-
await
|
|
16432
|
+
await chunkFTXGZ3BF_cjs.logActivity(
|
|
16433
16433
|
db,
|
|
16434
16434
|
user.userId,
|
|
16435
16435
|
"user!.invitation_cancelled",
|
|
@@ -17810,7 +17810,7 @@ var fileValidationSchema2 = zod.z.object({
|
|
|
17810
17810
|
// 50MB max
|
|
17811
17811
|
});
|
|
17812
17812
|
var adminMediaRoutes = new hono.Hono();
|
|
17813
|
-
adminMediaRoutes.use("*",
|
|
17813
|
+
adminMediaRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
17814
17814
|
adminMediaRoutes.get("/", async (c) => {
|
|
17815
17815
|
try {
|
|
17816
17816
|
const user = c.get("user");
|
|
@@ -17852,7 +17852,7 @@ adminMediaRoutes.get("/selector", async (c) => {
|
|
|
17852
17852
|
const { searchParams } = new URL(c.req.url);
|
|
17853
17853
|
const search = searchParams.get("search") || "";
|
|
17854
17854
|
const db = c.env.DB;
|
|
17855
|
-
const pluginService = new
|
|
17855
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
17856
17856
|
const mediaPlugin = await pluginService.getPlugin("core-media");
|
|
17857
17857
|
if (!mediaPlugin || mediaPlugin.status !== "active") {
|
|
17858
17858
|
return c.html(html.html`
|
|
@@ -18228,7 +18228,7 @@ adminMediaRoutes.put("/:id", async (c) => {
|
|
|
18228
18228
|
`);
|
|
18229
18229
|
}
|
|
18230
18230
|
});
|
|
18231
|
-
adminMediaRoutes.delete("/cleanup",
|
|
18231
|
+
adminMediaRoutes.delete("/cleanup", chunkFTXGZ3BF_cjs.requireRole("admin"), async (c) => {
|
|
18232
18232
|
try {
|
|
18233
18233
|
const db = c.env.DB;
|
|
18234
18234
|
const allMediaStmt = db.prepare("SELECT id, r2_key, filename FROM media WHERE deleted_at IS NULL");
|
|
@@ -19347,7 +19347,7 @@ function escapeHtmlAttr(value) {
|
|
|
19347
19347
|
}
|
|
19348
19348
|
function renderPluginSettingsPage(data) {
|
|
19349
19349
|
const { plugin, activity = [], user } = data;
|
|
19350
|
-
const hasUserSettings = Object.keys(plugin.settings || {}).some((k) => !k.startsWith("_"));
|
|
19350
|
+
const hasUserSettings = plugin.id in pluginSettingsComponents || Object.keys(plugin.settings || {}).some((k) => !k.startsWith("_"));
|
|
19351
19351
|
const defaultTab = hasUserSettings ? "settings" : "info";
|
|
19352
19352
|
const pageContent = `
|
|
19353
19353
|
<div class="w-full px-4 sm:px-6 lg:px-8 py-6">
|
|
@@ -19998,7 +19998,8 @@ function formatTimestamp(timestamp) {
|
|
|
19998
19998
|
}
|
|
19999
19999
|
var pluginSettingsComponents = {
|
|
20000
20000
|
"otp-login": renderOTPLoginSettingsContent,
|
|
20001
|
-
"email": renderEmailSettingsContent
|
|
20001
|
+
"email": renderEmailSettingsContent,
|
|
20002
|
+
"oauth-providers": renderOAuthProvidersSettingsContent
|
|
20002
20003
|
};
|
|
20003
20004
|
function renderOTPLoginSettingsContent(plugin, settings) {
|
|
20004
20005
|
const siteName = settings.siteName || "SonicJS";
|
|
@@ -20721,11 +20722,105 @@ defineUserProfile({
|
|
|
20721
20722
|
</div>
|
|
20722
20723
|
`;
|
|
20723
20724
|
}
|
|
20725
|
+
function renderOAuthProvidersSettingsContent(_plugin, settings) {
|
|
20726
|
+
const providers = settings.providers || {};
|
|
20727
|
+
const github = providers.github || {};
|
|
20728
|
+
const google = providers.google || {};
|
|
20729
|
+
const inputClass = "w-full px-3 py-2 rounded-lg bg-white/5 border border-white/10 focus:border-blue-500 focus:outline-none text-white";
|
|
20730
|
+
function renderProviderCard(name, label, icon, data) {
|
|
20731
|
+
const clientId = escapeHtmlAttr(data.clientId || "");
|
|
20732
|
+
const clientSecret = escapeHtmlAttr(data.clientSecret || "");
|
|
20733
|
+
const enabled = data.enabled === true;
|
|
20734
|
+
return `
|
|
20735
|
+
<div class="backdrop-blur-md bg-white/5 rounded-xl border border-white/10 p-6">
|
|
20736
|
+
<div class="flex items-center justify-between mb-4">
|
|
20737
|
+
<h3 class="text-lg font-semibold text-white flex items-center gap-2">
|
|
20738
|
+
<span>${icon}</span> ${label}
|
|
20739
|
+
</h3>
|
|
20740
|
+
<label class="relative inline-flex items-center cursor-pointer">
|
|
20741
|
+
<input type="checkbox" id="oauth_${name}_enabled" ${enabled ? "checked" : ""} class="sr-only peer">
|
|
20742
|
+
<div class="w-11 h-6 bg-gray-600 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-800 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-600"></div>
|
|
20743
|
+
<span class="ml-2 text-sm text-gray-300">Enabled</span>
|
|
20744
|
+
</label>
|
|
20745
|
+
</div>
|
|
20746
|
+
<div class="space-y-4">
|
|
20747
|
+
<div>
|
|
20748
|
+
<label for="oauth_${name}_clientId" class="block text-sm font-medium text-gray-300 mb-2">Client ID</label>
|
|
20749
|
+
<input type="text" id="oauth_${name}_clientId" value="${clientId}" placeholder="${label} OAuth Client ID" class="${inputClass}">
|
|
20750
|
+
</div>
|
|
20751
|
+
<div>
|
|
20752
|
+
<label for="oauth_${name}_clientSecret" class="block text-sm font-medium text-gray-300 mb-2">Client Secret</label>
|
|
20753
|
+
<input type="password" id="oauth_${name}_clientSecret" value="${clientSecret}" placeholder="${label} OAuth Client Secret" class="${inputClass}">
|
|
20754
|
+
</div>
|
|
20755
|
+
</div>
|
|
20756
|
+
</div>
|
|
20757
|
+
`;
|
|
20758
|
+
}
|
|
20759
|
+
return `
|
|
20760
|
+
<div class="space-y-6">
|
|
20761
|
+
<div class="bg-blue-500/10 border border-blue-500/20 rounded-lg p-4">
|
|
20762
|
+
<p class="text-blue-200 text-sm">
|
|
20763
|
+
Configure OAuth provider credentials below. Credentials are stored securely and used server-side only.
|
|
20764
|
+
Make sure to add the callback URL <code class="text-blue-300">/auth/oauth/[provider]/callback</code> to your OAuth app's allowed redirect URIs.
|
|
20765
|
+
</p>
|
|
20766
|
+
</div>
|
|
20767
|
+
|
|
20768
|
+
${renderProviderCard("github", "GitHub", "\u{1F419}", github)}
|
|
20769
|
+
${renderProviderCard("google", "Google", "\u{1F535}", google)}
|
|
20770
|
+
</div>
|
|
20771
|
+
|
|
20772
|
+
<script>
|
|
20773
|
+
(function () {
|
|
20774
|
+
const origSave = window.saveSettings;
|
|
20775
|
+
window.saveSettings = async function () {
|
|
20776
|
+
const settings = {
|
|
20777
|
+
providers: {
|
|
20778
|
+
github: {
|
|
20779
|
+
clientId: document.getElementById('oauth_github_clientId').value,
|
|
20780
|
+
clientSecret: document.getElementById('oauth_github_clientSecret').value,
|
|
20781
|
+
enabled: document.getElementById('oauth_github_enabled').checked,
|
|
20782
|
+
},
|
|
20783
|
+
google: {
|
|
20784
|
+
clientId: document.getElementById('oauth_google_clientId').value,
|
|
20785
|
+
clientSecret: document.getElementById('oauth_google_clientSecret').value,
|
|
20786
|
+
enabled: document.getElementById('oauth_google_enabled').checked,
|
|
20787
|
+
},
|
|
20788
|
+
}
|
|
20789
|
+
};
|
|
20790
|
+
|
|
20791
|
+
const saveButton = document.getElementById('save-button');
|
|
20792
|
+
saveButton.disabled = true;
|
|
20793
|
+
saveButton.textContent = 'Saving...';
|
|
20794
|
+
|
|
20795
|
+
try {
|
|
20796
|
+
const response = await fetch('/admin/plugins/oauth-providers/settings', {
|
|
20797
|
+
method: 'POST',
|
|
20798
|
+
headers: { 'Content-Type': 'application/json' },
|
|
20799
|
+
body: JSON.stringify(settings),
|
|
20800
|
+
});
|
|
20801
|
+
const result = await response.json();
|
|
20802
|
+
if (result.success) {
|
|
20803
|
+
showNotification('Settings saved successfully', 'success');
|
|
20804
|
+
setTimeout(() => location.reload(), 1000);
|
|
20805
|
+
} else {
|
|
20806
|
+
throw new Error(result.error || 'Failed to save settings');
|
|
20807
|
+
}
|
|
20808
|
+
} catch (error) {
|
|
20809
|
+
showNotification(error.message, 'error');
|
|
20810
|
+
} finally {
|
|
20811
|
+
saveButton.disabled = false;
|
|
20812
|
+
saveButton.textContent = 'Save Settings';
|
|
20813
|
+
}
|
|
20814
|
+
};
|
|
20815
|
+
})();
|
|
20816
|
+
</script>
|
|
20817
|
+
`;
|
|
20818
|
+
}
|
|
20724
20819
|
|
|
20725
20820
|
// src/routes/admin-plugins.ts
|
|
20726
20821
|
var adminPluginRoutes = new hono.Hono();
|
|
20727
|
-
adminPluginRoutes.use("*",
|
|
20728
|
-
var AVAILABLE_PLUGINS = Object.values(
|
|
20822
|
+
adminPluginRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
20823
|
+
var AVAILABLE_PLUGINS = Object.values(chunkPYZYU7EK_cjs.PLUGIN_REGISTRY).map((p) => ({
|
|
20729
20824
|
id: p.id,
|
|
20730
20825
|
name: p.codeName,
|
|
20731
20826
|
display_name: p.displayName,
|
|
@@ -20745,7 +20840,7 @@ adminPluginRoutes.get("/", async (c) => {
|
|
|
20745
20840
|
if (user?.role !== "admin") {
|
|
20746
20841
|
return c.text("Access denied", 403);
|
|
20747
20842
|
}
|
|
20748
|
-
const pluginService = new
|
|
20843
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
20749
20844
|
let installedPlugins = [];
|
|
20750
20845
|
let stats = { total: 0, active: 0, inactive: 0, errors: 0, uninstalled: 0 };
|
|
20751
20846
|
try {
|
|
@@ -20817,10 +20912,10 @@ adminPluginRoutes.get("/:id", async (c) => {
|
|
|
20817
20912
|
if (user?.role !== "admin") {
|
|
20818
20913
|
return c.redirect("/admin/plugins");
|
|
20819
20914
|
}
|
|
20820
|
-
const pluginService = new
|
|
20915
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
20821
20916
|
let plugin = await pluginService.getPlugin(pluginId);
|
|
20822
20917
|
if (!plugin) {
|
|
20823
|
-
const def =
|
|
20918
|
+
const def = chunkEUJAEB6W_cjs.getPluginDefinition(pluginId);
|
|
20824
20919
|
if (!def) return c.text("Plugin not found", 404);
|
|
20825
20920
|
plugin = await pluginService.ensurePlugin(pluginId, {
|
|
20826
20921
|
displayName: def.displayName ?? pluginId,
|
|
@@ -20911,14 +21006,14 @@ adminPluginRoutes.get("/:id/configure", async (c) => {
|
|
|
20911
21006
|
const user = c.get("user");
|
|
20912
21007
|
const pluginId = c.req.param("id");
|
|
20913
21008
|
if (user?.role !== "admin") return c.redirect("/admin/plugins");
|
|
20914
|
-
const def =
|
|
21009
|
+
const def = chunkEUJAEB6W_cjs.getPluginDefinition(pluginId);
|
|
20915
21010
|
if (!def?.configSchema) return c.text("No schema-driven settings for this plugin", 404);
|
|
20916
21011
|
const db = c.env.DB;
|
|
20917
|
-
const pluginService = new
|
|
21012
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
20918
21013
|
const plugin = await pluginService.getPlugin(pluginId);
|
|
20919
21014
|
const stored = plugin?.settings ?? {};
|
|
20920
|
-
const values =
|
|
20921
|
-
const fieldsHtml =
|
|
21015
|
+
const values = chunkEUJAEB6W_cjs.applySchemaDefaults(def.configSchema, stored);
|
|
21016
|
+
const fieldsHtml = chunkEUJAEB6W_cjs.renderSchemaFields(def.configSchema, values);
|
|
20922
21017
|
const displayName = plugin?.display_name ?? def.displayName ?? def.id;
|
|
20923
21018
|
return c.html(`<!DOCTYPE html>
|
|
20924
21019
|
<html lang="en"><head>
|
|
@@ -20945,12 +21040,12 @@ adminPluginRoutes.post("/:id/configure", async (c) => {
|
|
|
20945
21040
|
const user = c.get("user");
|
|
20946
21041
|
const pluginId = c.req.param("id");
|
|
20947
21042
|
if (user?.role !== "admin") return c.json({ error: "Access denied" }, 403);
|
|
20948
|
-
const def =
|
|
21043
|
+
const def = chunkEUJAEB6W_cjs.getPluginDefinition(pluginId);
|
|
20949
21044
|
if (!def?.configSchema) return c.text("No schema-driven settings for this plugin", 404);
|
|
20950
21045
|
const form = await c.req.formData();
|
|
20951
|
-
const parsed =
|
|
21046
|
+
const parsed = chunkEUJAEB6W_cjs.parseFormDataToSettings(def.configSchema, form);
|
|
20952
21047
|
const db = c.env.DB;
|
|
20953
|
-
const pluginService = new
|
|
21048
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
20954
21049
|
await pluginService.ensurePlugin(pluginId, {
|
|
20955
21050
|
displayName: def.displayName ?? pluginId,
|
|
20956
21051
|
version: def.version,
|
|
@@ -20974,7 +21069,7 @@ adminPluginRoutes.post("/:id/activate", async (c) => {
|
|
|
20974
21069
|
if (user?.role !== "admin") {
|
|
20975
21070
|
return c.json({ error: "Access denied" }, 403);
|
|
20976
21071
|
}
|
|
20977
|
-
const pluginService = new
|
|
21072
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
20978
21073
|
await pluginService.activatePlugin(pluginId);
|
|
20979
21074
|
return c.json({ success: true });
|
|
20980
21075
|
} catch (error) {
|
|
@@ -20991,7 +21086,7 @@ adminPluginRoutes.post("/:id/deactivate", async (c) => {
|
|
|
20991
21086
|
if (user?.role !== "admin") {
|
|
20992
21087
|
return c.json({ error: "Access denied" }, 403);
|
|
20993
21088
|
}
|
|
20994
|
-
const pluginService = new
|
|
21089
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
20995
21090
|
await pluginService.deactivatePlugin(pluginId);
|
|
20996
21091
|
return c.json({ success: true });
|
|
20997
21092
|
} catch (error) {
|
|
@@ -21008,8 +21103,8 @@ adminPluginRoutes.post("/install", async (c) => {
|
|
|
21008
21103
|
return c.json({ error: "Access denied" }, 403);
|
|
21009
21104
|
}
|
|
21010
21105
|
const body = await c.req.json();
|
|
21011
|
-
const pluginService = new
|
|
21012
|
-
const registryEntry =
|
|
21106
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
21107
|
+
const registryEntry = chunkPYZYU7EK_cjs.findPluginByCodeName(body.name) || chunkPYZYU7EK_cjs.PLUGIN_REGISTRY[body.name] || chunkPYZYU7EK_cjs.PLUGIN_REGISTRY[body.id];
|
|
21013
21108
|
if (!registryEntry) {
|
|
21014
21109
|
return c.json({ error: "Plugin not found in registry" }, 404);
|
|
21015
21110
|
}
|
|
@@ -21042,7 +21137,7 @@ adminPluginRoutes.post("/:id/uninstall", async (c) => {
|
|
|
21042
21137
|
if (user?.role !== "admin") {
|
|
21043
21138
|
return c.json({ error: "Access denied" }, 403);
|
|
21044
21139
|
}
|
|
21045
|
-
const pluginService = new
|
|
21140
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
21046
21141
|
await pluginService.uninstallPlugin(pluginId);
|
|
21047
21142
|
return c.json({ success: true });
|
|
21048
21143
|
} catch (error) {
|
|
@@ -21060,7 +21155,7 @@ adminPluginRoutes.post("/:id/settings", async (c) => {
|
|
|
21060
21155
|
return c.json({ error: "Access denied" }, 403);
|
|
21061
21156
|
}
|
|
21062
21157
|
const settings = await c.req.json();
|
|
21063
|
-
const pluginService = new
|
|
21158
|
+
const pluginService = new chunkPYZYU7EK_cjs.PluginService(db);
|
|
21064
21159
|
const existingPlugin = await pluginService.getPlugin(pluginId);
|
|
21065
21160
|
const existingSettings = existingPlugin?.settings ?? {};
|
|
21066
21161
|
await pluginService.updatePluginSettings(pluginId, { ...existingSettings, ...settings });
|
|
@@ -21870,7 +21965,7 @@ function renderLogConfigPage(data) {
|
|
|
21870
21965
|
|
|
21871
21966
|
// src/routes/admin-logs.ts
|
|
21872
21967
|
var adminLogsRoutes = new hono.Hono();
|
|
21873
|
-
adminLogsRoutes.use("*",
|
|
21968
|
+
adminLogsRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
21874
21969
|
adminLogsRoutes.get("/", async (c) => {
|
|
21875
21970
|
try {
|
|
21876
21971
|
const user = c.get("user");
|
|
@@ -22862,9 +22957,9 @@ function renderStorageUsage(databaseSizeBytes, mediaSizeBytes) {
|
|
|
22862
22957
|
}
|
|
22863
22958
|
|
|
22864
22959
|
// src/routes/admin-dashboard.ts
|
|
22865
|
-
var VERSION =
|
|
22960
|
+
var VERSION = chunkQWSR4THH_cjs.getCoreVersion();
|
|
22866
22961
|
var router = new hono.Hono();
|
|
22867
|
-
router.use("*",
|
|
22962
|
+
router.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
22868
22963
|
router.get("/", async (c) => {
|
|
22869
22964
|
const user = c.get("user");
|
|
22870
22965
|
try {
|
|
@@ -24829,7 +24924,7 @@ function renderCollectionFormPage(data) {
|
|
|
24829
24924
|
// src/routes/admin-collections.ts
|
|
24830
24925
|
chunkK623Q6WD_cjs.init_admin_layout_catalyst_template();
|
|
24831
24926
|
var adminCollectionsRoutes = new hono.Hono();
|
|
24832
|
-
adminCollectionsRoutes.use("*",
|
|
24927
|
+
adminCollectionsRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
24833
24928
|
adminCollectionsRoutes.get("/", async (c) => {
|
|
24834
24929
|
try {
|
|
24835
24930
|
const user = c.get("user");
|
|
@@ -24846,7 +24941,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24846
24941
|
results = queryResults.results ?? [];
|
|
24847
24942
|
} catch (e) {
|
|
24848
24943
|
}
|
|
24849
|
-
const codeCollections =
|
|
24944
|
+
const codeCollections = chunkPYZYU7EK_cjs.getCollectionRegistry().list();
|
|
24850
24945
|
const codeCollectionsMap = new Map(
|
|
24851
24946
|
codeCollections.map((cfg) => {
|
|
24852
24947
|
const fieldCount = cfg.schema?.properties ? Object.keys(cfg.schema.properties).length : 0;
|
|
@@ -24860,7 +24955,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24860
24955
|
field_count: fieldCount,
|
|
24861
24956
|
managed: cfg.managed !== false,
|
|
24862
24957
|
source_type: "code",
|
|
24863
|
-
internal:
|
|
24958
|
+
internal: chunkPYZYU7EK_cjs.isCodeCollectionInternal(cfg),
|
|
24864
24959
|
versioning: cfg.versioning === true
|
|
24865
24960
|
}];
|
|
24866
24961
|
})
|
|
@@ -24899,7 +24994,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24899
24994
|
field_count: fieldCount,
|
|
24900
24995
|
managed: false,
|
|
24901
24996
|
source_type: row.source === "code" || row.source === "system" || row.source === "plugin" ? "code" : "user",
|
|
24902
|
-
internal:
|
|
24997
|
+
internal: chunkPYZYU7EK_cjs.isDbDocTypeInternal(row.source),
|
|
24903
24998
|
versioning: dbVersioning
|
|
24904
24999
|
};
|
|
24905
25000
|
});
|
|
@@ -25060,7 +25155,7 @@ export const myPlugin = definePlugin({
|
|
|
25060
25155
|
title: "Add a Collection",
|
|
25061
25156
|
pageTitle: "Add a Collection",
|
|
25062
25157
|
currentPath: "/admin/collections",
|
|
25063
|
-
version:
|
|
25158
|
+
version: chunkQWSR4THH_cjs.getCoreVersion(),
|
|
25064
25159
|
user: u ? { name: u.email ?? "Admin", email: u.email ?? "", role: u.role ?? "admin" } : void 0,
|
|
25065
25160
|
content
|
|
25066
25161
|
})
|
|
@@ -25077,7 +25172,7 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
25077
25172
|
collection = await stmt.bind(id).first();
|
|
25078
25173
|
} catch {
|
|
25079
25174
|
}
|
|
25080
|
-
const registryRecord =
|
|
25175
|
+
const registryRecord = chunkPYZYU7EK_cjs.getCollectionRegistry().getById(id) ?? chunkPYZYU7EK_cjs.getCollectionRegistry().getByName(id);
|
|
25081
25176
|
if (!collection && !registryRecord) {
|
|
25082
25177
|
const formData2 = {
|
|
25083
25178
|
isEdit: true,
|
|
@@ -25124,9 +25219,9 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
25124
25219
|
isCodeDriven = true;
|
|
25125
25220
|
}
|
|
25126
25221
|
const [tinymceActive, quillActive, mdxeditorActive] = await Promise.all([
|
|
25127
|
-
|
|
25128
|
-
|
|
25129
|
-
|
|
25222
|
+
chunkFTXGZ3BF_cjs.isPluginActive(db, "tinymce-plugin"),
|
|
25223
|
+
chunkFTXGZ3BF_cjs.isPluginActive(db, "quill-editor"),
|
|
25224
|
+
chunkFTXGZ3BF_cjs.isPluginActive(db, "easy-mdx")
|
|
25130
25225
|
]);
|
|
25131
25226
|
const displayName = collection?.display_name ?? registryRecord?.displayName ?? id;
|
|
25132
25227
|
const formData = {
|
|
@@ -25146,9 +25241,9 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
25146
25241
|
console.error("Error fetching collection:", error);
|
|
25147
25242
|
const user = c.get("user");
|
|
25148
25243
|
const [tinymceActive, quillActive, mdxeditorActive] = await Promise.all([
|
|
25149
|
-
|
|
25150
|
-
|
|
25151
|
-
|
|
25244
|
+
chunkFTXGZ3BF_cjs.isPluginActive(db, "tinymce-plugin"),
|
|
25245
|
+
chunkFTXGZ3BF_cjs.isPluginActive(db, "quill-editor"),
|
|
25246
|
+
chunkFTXGZ3BF_cjs.isPluginActive(db, "easy-mdx")
|
|
25152
25247
|
]);
|
|
25153
25248
|
const formData = {
|
|
25154
25249
|
isEdit: true,
|
|
@@ -26097,7 +26192,7 @@ function renderDatabaseToolsSettings(settings) {
|
|
|
26097
26192
|
|
|
26098
26193
|
// src/routes/admin-settings.ts
|
|
26099
26194
|
var adminSettingsRoutes = new hono.Hono();
|
|
26100
|
-
adminSettingsRoutes.use("*",
|
|
26195
|
+
adminSettingsRoutes.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
26101
26196
|
function getMockSettings(user) {
|
|
26102
26197
|
return {
|
|
26103
26198
|
general: {
|
|
@@ -26200,7 +26295,7 @@ adminSettingsRoutes.get("/database-tools", (c) => {
|
|
|
26200
26295
|
adminSettingsRoutes.get("/api/migrations/status", async (c) => {
|
|
26201
26296
|
try {
|
|
26202
26297
|
const db = c.env.DB;
|
|
26203
|
-
const migrationService = new
|
|
26298
|
+
const migrationService = new chunk3CT3SUR4_cjs.MigrationService(db);
|
|
26204
26299
|
const status = await migrationService.getMigrationStatus();
|
|
26205
26300
|
return c.json({
|
|
26206
26301
|
success: true,
|
|
@@ -26240,7 +26335,7 @@ adminSettingsRoutes.post("/api/migrations/run", async (c) => {
|
|
|
26240
26335
|
adminSettingsRoutes.get("/api/migrations/validate", async (c) => {
|
|
26241
26336
|
try {
|
|
26242
26337
|
const db = c.env.DB;
|
|
26243
|
-
const migrationService = new
|
|
26338
|
+
const migrationService = new chunk3CT3SUR4_cjs.MigrationService(db);
|
|
26244
26339
|
const validation = await migrationService.validateSchema();
|
|
26245
26340
|
return c.json({
|
|
26246
26341
|
success: true,
|
|
@@ -26833,16 +26928,16 @@ function renderAPIReferencePage(data) {
|
|
|
26833
26928
|
}
|
|
26834
26929
|
|
|
26835
26930
|
// src/routes/admin-api-reference.ts
|
|
26836
|
-
var VERSION2 =
|
|
26931
|
+
var VERSION2 = chunkQWSR4THH_cjs.getCoreVersion();
|
|
26837
26932
|
var router2 = new hono.Hono();
|
|
26838
|
-
router2.use("*",
|
|
26933
|
+
router2.use("*", chunkFTXGZ3BF_cjs.requireAuth());
|
|
26839
26934
|
router2.get("/", async (c) => {
|
|
26840
26935
|
const user = c.get("user");
|
|
26841
26936
|
try {
|
|
26842
26937
|
const app2 = chunk36Z3AKX3_cjs.getAppInstance();
|
|
26843
26938
|
const baseEndpoints = chunk36Z3AKX3_cjs.buildRouteList(app2);
|
|
26844
26939
|
const collectionRoutes = [];
|
|
26845
|
-
const collections =
|
|
26940
|
+
const collections = chunkPYZYU7EK_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
26846
26941
|
const methodOrder = { GET: 0, POST: 1, PUT: 2, PATCH: 3, DELETE: 4 };
|
|
26847
26942
|
for (const col of collections) {
|
|
26848
26943
|
const displayName = col.displayName || col.name;
|
|
@@ -26959,5 +27054,5 @@ exports.setVariablesCache = setVariablesCache;
|
|
|
26959
27054
|
exports.test_cleanup_default = test_cleanup_default;
|
|
26960
27055
|
exports.userProfilesPlugin = userProfilesPlugin;
|
|
26961
27056
|
exports.userRoutes = userRoutes;
|
|
26962
|
-
//# sourceMappingURL=chunk-
|
|
26963
|
-
//# sourceMappingURL=chunk-
|
|
27057
|
+
//# sourceMappingURL=chunk-JFLZHOQP.cjs.map
|
|
27058
|
+
//# sourceMappingURL=chunk-JFLZHOQP.cjs.map
|