@sonicjs-cms/core 3.0.0-beta.13 → 3.0.0-beta.15
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/{app-Bo0X1OWX.d.ts → app-01M0dIwt.d.ts} +1 -1
- package/dist/{app-Do66yCcV.d.cts → app-aj39TGHB.d.cts} +1 -1
- package/dist/{chunk-YNYEQP3K.cjs → chunk-4AB3PQHF.cjs} +2 -2
- package/dist/{chunk-YNYEQP3K.cjs.map → chunk-4AB3PQHF.cjs.map} +1 -1
- package/dist/{chunk-KG6GQE6B.js → chunk-4ENXIP4M.js} +27 -2
- package/dist/chunk-4ENXIP4M.js.map +1 -0
- package/dist/{chunk-6KFX4LAT.js → chunk-75WXXLAU.js} +4 -4
- package/dist/{chunk-6KFX4LAT.js.map → chunk-75WXXLAU.js.map} +1 -1
- package/dist/{chunk-VT77YUTP.cjs → chunk-BDQOPRA3.cjs} +441 -249
- package/dist/chunk-BDQOPRA3.cjs.map +1 -0
- package/dist/{chunk-PPFQDMZE.js → chunk-CE6POA7A.js} +3 -3
- package/dist/{chunk-PPFQDMZE.js.map → chunk-CE6POA7A.js.map} +1 -1
- package/dist/{chunk-IM3UG4QW.cjs → chunk-FVI3H6RG.cjs} +10 -10
- package/dist/{chunk-IM3UG4QW.cjs.map → chunk-FVI3H6RG.cjs.map} +1 -1
- package/dist/{chunk-KPQ57HAH.cjs → chunk-FXZSZ7C7.cjs} +27 -2
- package/dist/chunk-FXZSZ7C7.cjs.map +1 -0
- package/dist/{chunk-BK3NB35S.js → chunk-GQXVDFIG.js} +35 -13
- package/dist/chunk-GQXVDFIG.js.map +1 -0
- package/dist/{chunk-IVPRUGTY.js → chunk-IQZA2OY5.js} +4 -4
- package/dist/{chunk-IVPRUGTY.js.map → chunk-IQZA2OY5.js.map} +1 -1
- package/dist/{chunk-EKMN6W5B.js → chunk-JRLADH5B.js} +3 -3
- package/dist/{chunk-EKMN6W5B.js.map → chunk-JRLADH5B.js.map} +1 -1
- package/dist/{chunk-NUKJ54GA.cjs → chunk-KMCLNO4K.cjs} +6 -6
- package/dist/{chunk-NUKJ54GA.cjs.map → chunk-KMCLNO4K.cjs.map} +1 -1
- package/dist/{chunk-3FBZFYSQ.js → chunk-L3VIH6U4.js} +210 -19
- package/dist/chunk-L3VIH6U4.js.map +1 -0
- package/dist/{chunk-BLMTL57B.js → chunk-PDC7DLOV.js} +21 -3
- package/dist/chunk-PDC7DLOV.js.map +1 -0
- package/dist/{chunk-6CKXZFED.cjs → chunk-PK3ODTAL.cjs} +3 -3
- package/dist/{chunk-6CKXZFED.cjs.map → chunk-PK3ODTAL.cjs.map} +1 -1
- package/dist/{chunk-PZGGIJI6.cjs → chunk-PTTFLUEX.cjs} +4 -4
- package/dist/{chunk-PZGGIJI6.cjs.map → chunk-PTTFLUEX.cjs.map} +1 -1
- package/dist/{chunk-IV3NA6WZ.js → chunk-VOAP3KFU.js} +2 -2
- package/dist/{chunk-IV3NA6WZ.js.map → chunk-VOAP3KFU.js.map} +1 -1
- package/dist/{chunk-IESEVHXL.js → chunk-VVYVFCML.js} +12 -3
- package/dist/chunk-VVYVFCML.js.map +1 -0
- package/dist/{chunk-2CB4KY7I.cjs → chunk-W36OZTJ5.cjs} +21 -3
- package/dist/chunk-W36OZTJ5.cjs.map +1 -0
- package/dist/{chunk-HIKBY7MS.cjs → chunk-XWVDSM2L.cjs} +12 -3
- package/dist/chunk-XWVDSM2L.cjs.map +1 -0
- package/dist/{chunk-VMBQ6NQB.cjs → chunk-ZBDDZYA3.cjs} +45 -23
- package/dist/chunk-ZBDDZYA3.cjs.map +1 -0
- package/dist/{collection-config-JgHOpFCG.d.ts → collection-config-BTzAvKt2.d.cts} +25 -0
- package/dist/{collection-config-JgHOpFCG.d.cts → collection-config-BTzAvKt2.d.ts} +25 -0
- package/dist/config-SM2UWSDN.js +6 -0
- package/dist/{config-HFXANXCC.js.map → config-SM2UWSDN.js.map} +1 -1
- package/dist/config-YCRSU7ZP.cjs +19 -0
- package/dist/{config-ON6FNMYX.cjs.map → config-YCRSU7ZP.cjs.map} +1 -1
- package/dist/{define-plugin-BzNHc1ZI.d.ts → define-plugin-BYIey6sp.d.ts} +1 -1
- package/dist/{define-plugin-IWDKYaVm.d.cts → define-plugin-DsKiGu1q.d.cts} +1 -1
- package/dist/index.cjs +772 -314
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -10
- package/dist/index.d.ts +21 -10
- package/dist/index.js +517 -61
- package/dist/index.js.map +1 -1
- package/dist/middleware.cjs +34 -33
- package/dist/middleware.d.cts +2 -2
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.js +5 -4
- package/dist/migrations-6R2N6G2P.js +4 -0
- package/dist/{migrations-KKLQ2CEF.js.map → migrations-6R2N6G2P.js.map} +1 -1
- package/dist/migrations-X3UX24QG.cjs +13 -0
- package/dist/{migrations-XOXYLHHU.cjs.map → migrations-X3UX24QG.cjs.map} +1 -1
- package/dist/{plugin-bootstrap-B8ThJU21.d.cts → plugin-bootstrap-BHWQ2df8.d.cts} +1 -1
- package/dist/{plugin-bootstrap-qu8hJgUt.d.ts → plugin-bootstrap-Bj4fxX1q.d.ts} +1 -1
- package/dist/plugins.cjs +40 -40
- package/dist/plugins.d.cts +2 -2
- package/dist/plugins.d.ts +2 -2
- package/dist/plugins.js +3 -3
- package/dist/rbac-4QLDXIDF.js +5 -0
- package/dist/{rbac-O73MFKDA.js.map → rbac-4QLDXIDF.js.map} +1 -1
- package/dist/rbac-ESTOCVT2.cjs +14 -0
- package/dist/{rbac-VONLJJKB.cjs.map → rbac-ESTOCVT2.cjs.map} +1 -1
- package/dist/routes.cjs +28 -28
- package/dist/routes.d.cts +2 -2
- package/dist/routes.d.ts +2 -2
- package/dist/routes.js +8 -8
- package/dist/services.cjs +18 -18
- package/dist/services.d.cts +2 -2
- package/dist/services.d.ts +2 -2
- package/dist/services.js +2 -2
- package/dist/{types-Dea1eNxU.d.ts → types-DT7XN5TX.d.cts} +1 -1
- package/dist/{types-Dea1eNxU.d.cts → types-DT7XN5TX.d.ts} +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils.cjs +3 -3
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2CB4KY7I.cjs.map +0 -1
- package/dist/chunk-3FBZFYSQ.js.map +0 -1
- package/dist/chunk-BK3NB35S.js.map +0 -1
- package/dist/chunk-BLMTL57B.js.map +0 -1
- package/dist/chunk-HIKBY7MS.cjs.map +0 -1
- package/dist/chunk-IESEVHXL.js.map +0 -1
- package/dist/chunk-KG6GQE6B.js.map +0 -1
- package/dist/chunk-KPQ57HAH.cjs.map +0 -1
- package/dist/chunk-VMBQ6NQB.cjs.map +0 -1
- package/dist/chunk-VT77YUTP.cjs.map +0 -1
- package/dist/config-HFXANXCC.js +0 -6
- package/dist/config-ON6FNMYX.cjs +0 -19
- package/dist/migrations-KKLQ2CEF.js +0 -4
- package/dist/migrations-XOXYLHHU.cjs +0 -13
- package/dist/rbac-O73MFKDA.js +0 -5
- package/dist/rbac-VONLJJKB.cjs +0 -14
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkXWVDSM2L_cjs = require('./chunk-XWVDSM2L.cjs');
|
|
4
4
|
var chunkN32OWET6_cjs = require('./chunk-N32OWET6.cjs');
|
|
5
5
|
var chunk4BTBSXMR_cjs = require('./chunk-4BTBSXMR.cjs');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var chunkZBDDZYA3_cjs = require('./chunk-ZBDDZYA3.cjs');
|
|
7
|
+
var chunkW36OZTJ5_cjs = require('./chunk-W36OZTJ5.cjs');
|
|
8
8
|
var chunkJEQ7FLOD_cjs = require('./chunk-JEQ7FLOD.cjs');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var chunkFXZSZ7C7_cjs = require('./chunk-FXZSZ7C7.cjs');
|
|
10
|
+
var chunk4AB3PQHF_cjs = require('./chunk-4AB3PQHF.cjs');
|
|
11
11
|
var chunkPXNTCCPE_cjs = require('./chunk-PXNTCCPE.cjs');
|
|
12
12
|
var chunkK623Q6WD_cjs = require('./chunk-K623Q6WD.cjs');
|
|
13
|
-
var
|
|
13
|
+
var chunkPTTFLUEX_cjs = require('./chunk-PTTFLUEX.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 chunkPK3ODTAL_cjs = require('./chunk-PK3ODTAL.cjs');
|
|
18
18
|
var chunkMNWKYY5E_cjs = require('./chunk-MNWKYY5E.cjs');
|
|
19
19
|
var hono = require('hono');
|
|
20
20
|
var zod = require('zod');
|
|
@@ -256,7 +256,7 @@ function getDocumentRequestContext(c) {
|
|
|
256
256
|
|
|
257
257
|
// src/routes/api-documents.ts
|
|
258
258
|
async function aclAllowsRead(db, tenantId, principalSet, row, preloadedType) {
|
|
259
|
-
const docType = preloadedType ?? await new
|
|
259
|
+
const docType = preloadedType ?? await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
260
260
|
if (!docType) return false;
|
|
261
261
|
return new DocumentRepository(db, tenantId).isAllowed(principalSet, row.root_id, "read", docType.settings);
|
|
262
262
|
}
|
|
@@ -274,7 +274,7 @@ apiDocumentsRoutes.get("/", async (c) => {
|
|
|
274
274
|
if (!typeId) {
|
|
275
275
|
return c.json({ error: "type query parameter is required" }, 400);
|
|
276
276
|
}
|
|
277
|
-
const registry = new
|
|
277
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
278
278
|
const docType = await registry.findById(typeId);
|
|
279
279
|
if (!docType || !docType.isActive) {
|
|
280
280
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -356,7 +356,7 @@ apiDocumentsRoutes.get("/root/:rootId", async (c) => {
|
|
|
356
356
|
AND (expires_at IS NULL OR expires_at > ?) LIMIT 1`
|
|
357
357
|
).bind(rootId, now, now).first();
|
|
358
358
|
if (!row) return c.json({ error: "Not found" }, 404);
|
|
359
|
-
const docType = await new
|
|
359
|
+
const docType = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
360
360
|
const effTenant = effectiveTenantForType(tenantId, docType?.settings);
|
|
361
361
|
if (row.tenant_id !== effTenant) return c.json({ error: "Not found" }, 404);
|
|
362
362
|
if (!await aclAllowsRead(db, effTenant, principalSet, row, docType)) {
|
|
@@ -392,7 +392,7 @@ apiDocumentsRoutes.get("/:id", async (c) => {
|
|
|
392
392
|
AND (expires_at IS NULL OR expires_at > ?) LIMIT 1`
|
|
393
393
|
).bind(id, now, now).first();
|
|
394
394
|
if (!row) return c.json({ error: "Not found" }, 404);
|
|
395
|
-
const docType = await new
|
|
395
|
+
const docType = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
396
396
|
const effTenant = effectiveTenantForType(tenantId, docType?.settings);
|
|
397
397
|
if (row.tenant_id !== effTenant) return c.json({ error: "Not found" }, 404);
|
|
398
398
|
if (!await aclAllowsRead(db, effTenant, principalSet, row, docType)) {
|
|
@@ -462,17 +462,17 @@ async function resolveDocScope(c, db, by, opts = {}) {
|
|
|
462
462
|
const draft = opts.currentDraftOnly ? " AND is_current_draft = 1" : "";
|
|
463
463
|
const row = await db.prepare(`SELECT type_id, root_id, tenant_id FROM documents WHERE ${col} = ?${draft} LIMIT 1`).bind(val).first();
|
|
464
464
|
if (!row) return null;
|
|
465
|
-
const docType = await new
|
|
465
|
+
const docType = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(row.type_id);
|
|
466
466
|
const tenantId = effectiveTenantForType(getRequestTenant(c), docType?.settings);
|
|
467
467
|
if (row.tenant_id !== tenantId) return null;
|
|
468
468
|
return { typeId: row.type_id, rootId: row.root_id, tenantId, docType };
|
|
469
469
|
}
|
|
470
470
|
var adminDocumentsRoutes = new hono.Hono();
|
|
471
|
-
adminDocumentsRoutes.use("*",
|
|
472
|
-
adminDocumentsRoutes.use("*",
|
|
471
|
+
adminDocumentsRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
472
|
+
adminDocumentsRoutes.use("*", chunkZBDDZYA3_cjs.requireRole(["admin", "editor"]));
|
|
473
473
|
adminDocumentsRoutes.get("/types", async (c) => {
|
|
474
474
|
try {
|
|
475
|
-
const registry = new
|
|
475
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(c.env.DB);
|
|
476
476
|
const types = await registry.findAll();
|
|
477
477
|
return c.json({ data: types });
|
|
478
478
|
} catch (error) {
|
|
@@ -500,7 +500,7 @@ adminDocumentsRoutes.get("/", async (c) => {
|
|
|
500
500
|
if (!typeId) {
|
|
501
501
|
return c.json({ error: "type query parameter is required" }, 400);
|
|
502
502
|
}
|
|
503
|
-
const registry = new
|
|
503
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
504
504
|
const docType = await registry.findById(typeId);
|
|
505
505
|
if (!docType || !docType.isActive) {
|
|
506
506
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -611,7 +611,7 @@ adminDocumentsRoutes.post("/", async (c) => {
|
|
|
611
611
|
const input = validation.data;
|
|
612
612
|
const db = c.env.DB;
|
|
613
613
|
const user = c.get("user");
|
|
614
|
-
const registry = new
|
|
614
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
615
615
|
const docType = await registry.findById(input.typeId);
|
|
616
616
|
if (!docType || !docType.isActive) {
|
|
617
617
|
return c.json({ error: "Unknown document type" }, 400);
|
|
@@ -619,7 +619,7 @@ adminDocumentsRoutes.post("/", async (c) => {
|
|
|
619
619
|
const createDenied = await denyIfNotAllowed(c, db, "", "create", docType.settings);
|
|
620
620
|
if (createDenied) return createDenied;
|
|
621
621
|
const tenantId = effectiveTenantForType(getRequestTenant(c), docType.settings);
|
|
622
|
-
const svc = new
|
|
622
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
623
623
|
queryableFields: docType.queryableFields,
|
|
624
624
|
typeSchemaVersion: docType.schemaVersion,
|
|
625
625
|
maxVersionsPerRoot: docType.settings.maxVersionsPerRoot,
|
|
@@ -657,7 +657,7 @@ adminDocumentsRoutes.put("/:rootId", async (c) => {
|
|
|
657
657
|
const docType = scope.docType;
|
|
658
658
|
const updateDenied = await denyIfNotAllowed(c, db, rootId, "update", docType?.settings, scope.tenantId);
|
|
659
659
|
if (updateDenied) return updateDenied;
|
|
660
|
-
const svc = new
|
|
660
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
661
661
|
queryableFields: docType?.queryableFields ?? [],
|
|
662
662
|
typeSchemaVersion: docType?.schemaVersion,
|
|
663
663
|
maxVersionsPerRoot: docType?.settings.maxVersionsPerRoot,
|
|
@@ -682,7 +682,7 @@ adminDocumentsRoutes.post("/:id/publish", async (c) => {
|
|
|
682
682
|
const docType = scope.docType;
|
|
683
683
|
const publishDenied = await denyIfNotAllowed(c, db, scope.rootId, "publish", docType?.settings, scope.tenantId);
|
|
684
684
|
if (publishDenied) return publishDenied;
|
|
685
|
-
const svc = new
|
|
685
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
686
686
|
queryableFields: docType?.queryableFields ?? [],
|
|
687
687
|
typeSchemaVersion: docType?.schemaVersion,
|
|
688
688
|
tenantId: scope.tenantId,
|
|
@@ -705,7 +705,7 @@ adminDocumentsRoutes.post("/:id/unpublish", async (c) => {
|
|
|
705
705
|
const docType = scope.docType;
|
|
706
706
|
const unpublishDenied = await denyIfNotAllowed(c, db, scope.rootId, "publish", docType?.settings, scope.tenantId);
|
|
707
707
|
if (unpublishDenied) return unpublishDenied;
|
|
708
|
-
const svc = new
|
|
708
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
709
709
|
queryableFields: docType?.queryableFields ?? [],
|
|
710
710
|
tenantId: scope.tenantId
|
|
711
711
|
});
|
|
@@ -727,7 +727,7 @@ adminDocumentsRoutes.delete("/:id", async (c) => {
|
|
|
727
727
|
const docType = scope.docType;
|
|
728
728
|
const deleteDenied = await denyIfNotAllowed(c, db, scope.rootId, "delete", docType?.settings, scope.tenantId);
|
|
729
729
|
if (deleteDenied) return deleteDenied;
|
|
730
|
-
const svc = new
|
|
730
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, { queryableFields: docType?.queryableFields ?? [], tenantId: scope.tenantId });
|
|
731
731
|
if (docType?.settings.pii) {
|
|
732
732
|
if (scope.rootId) await svc.erase(scope.rootId, scope.tenantId);
|
|
733
733
|
} else {
|
|
@@ -743,7 +743,7 @@ adminDocumentsRoutes.post("/types/:typeId/reindex", async (c) => {
|
|
|
743
743
|
try {
|
|
744
744
|
const { typeId } = c.req.param();
|
|
745
745
|
const db = c.env.DB;
|
|
746
|
-
const registry = new
|
|
746
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
747
747
|
const docType = await registry.findById(typeId);
|
|
748
748
|
if (!docType) return c.json({ error: "Unknown document type" }, 400);
|
|
749
749
|
const reindexTenant = effectiveTenantForType(getRequestTenant(c), docType.settings);
|
|
@@ -897,13 +897,13 @@ async function resolveContentVariables(contentData, db) {
|
|
|
897
897
|
// src/routes/api-content-crud.ts
|
|
898
898
|
var apiContentCrudRoutes = new hono.Hono();
|
|
899
899
|
async function resolveDocBacking(db, collectionIdOrName) {
|
|
900
|
-
const registry =
|
|
900
|
+
const registry = chunkFXZSZ7C7_cjs.getCollectionRegistry();
|
|
901
901
|
const record = registry.getBySlugOrName(collectionIdOrName) ?? registry.getById(collectionIdOrName);
|
|
902
902
|
if (record) {
|
|
903
|
-
const docType2 = await new
|
|
903
|
+
const docType2 = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(record.name);
|
|
904
904
|
return docType2 ? { coll: { id: record.id, name: record.name }, docType: docType2 } : null;
|
|
905
905
|
}
|
|
906
|
-
const docType = await new
|
|
906
|
+
const docType = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(collectionIdOrName);
|
|
907
907
|
if (docType) {
|
|
908
908
|
return { coll: { id: collectionIdOrName, name: collectionIdOrName }, docType };
|
|
909
909
|
}
|
|
@@ -946,7 +946,7 @@ apiContentCrudRoutes.get("/check-slug", async (c) => {
|
|
|
946
946
|
}, 500);
|
|
947
947
|
}
|
|
948
948
|
});
|
|
949
|
-
apiContentCrudRoutes.get("/:id",
|
|
949
|
+
apiContentCrudRoutes.get("/:id", chunkZBDDZYA3_cjs.optionalAuth(), async (c) => {
|
|
950
950
|
try {
|
|
951
951
|
const id = c.req.param("id");
|
|
952
952
|
const db = c.env.DB;
|
|
@@ -956,7 +956,7 @@ apiContentCrudRoutes.get("/:id", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) =>
|
|
|
956
956
|
).bind(id, getRequestTenant(c)).first();
|
|
957
957
|
let transformedContent;
|
|
958
958
|
if (docRow) {
|
|
959
|
-
const coll =
|
|
959
|
+
const coll = chunkFXZSZ7C7_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
960
960
|
transformedContent = {
|
|
961
961
|
id: docRow.root_id,
|
|
962
962
|
title: docRow.title,
|
|
@@ -965,8 +965,8 @@ apiContentCrudRoutes.get("/:id", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) =>
|
|
|
965
965
|
collectionId: coll?.id ?? docRow.type_id,
|
|
966
966
|
data: docRow.data ? JSON.parse(docRow.data) : {},
|
|
967
967
|
// D29: document timestamps are SECONDS; legacy `content` API contract is MILLISECONDS.
|
|
968
|
-
created_at:
|
|
969
|
-
updated_at:
|
|
968
|
+
created_at: chunkW36OZTJ5_cjs.documentSecondsToMs(docRow.created_at),
|
|
969
|
+
updated_at: chunkW36OZTJ5_cjs.documentSecondsToMs(docRow.updated_at)
|
|
970
970
|
};
|
|
971
971
|
} else {
|
|
972
972
|
return c.json({ error: "Content not found" }, 404);
|
|
@@ -990,7 +990,7 @@ apiContentCrudRoutes.get("/:id", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) =>
|
|
|
990
990
|
}, 500);
|
|
991
991
|
}
|
|
992
992
|
});
|
|
993
|
-
apiContentCrudRoutes.post("/",
|
|
993
|
+
apiContentCrudRoutes.post("/", chunkZBDDZYA3_cjs.requireAuth(), chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
994
994
|
try {
|
|
995
995
|
const db = c.env.DB;
|
|
996
996
|
const user = c.get("user");
|
|
@@ -1024,7 +1024,7 @@ apiContentCrudRoutes.post("/", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_cj
|
|
|
1024
1024
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
1025
1025
|
}
|
|
1026
1026
|
const tenantId = getRequestTenant(c);
|
|
1027
|
-
const svc = new
|
|
1027
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
1028
1028
|
queryableFields: backing.docType.queryableFields ?? [],
|
|
1029
1029
|
typeSchemaVersion: backing.docType.schemaVersion ?? 1,
|
|
1030
1030
|
maxVersionsPerRoot: backing.docType.settings?.maxVersionsPerRoot ?? 50,
|
|
@@ -1053,7 +1053,7 @@ apiContentCrudRoutes.post("/", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_cj
|
|
|
1053
1053
|
"fire-and-forget"
|
|
1054
1054
|
);
|
|
1055
1055
|
return c.json({
|
|
1056
|
-
data: { id: doc.rootId, title: doc.title, slug: doc.slug, status: doc.status, collectionId: backing.coll.id, data: doc.data, created_at:
|
|
1056
|
+
data: { id: doc.rootId, title: doc.title, slug: doc.slug, status: doc.status, collectionId: backing.coll.id, data: doc.data, created_at: chunkW36OZTJ5_cjs.documentSecondsToMs(doc.createdAt), updated_at: chunkW36OZTJ5_cjs.documentSecondsToMs(doc.updatedAt) }
|
|
1057
1057
|
}, 201);
|
|
1058
1058
|
}
|
|
1059
1059
|
return c.json({ error: "Collection is not document-backed" }, 400);
|
|
@@ -1065,7 +1065,7 @@ apiContentCrudRoutes.post("/", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_cj
|
|
|
1065
1065
|
}, 500);
|
|
1066
1066
|
}
|
|
1067
1067
|
});
|
|
1068
|
-
apiContentCrudRoutes.put("/:id",
|
|
1068
|
+
apiContentCrudRoutes.put("/:id", chunkZBDDZYA3_cjs.requireAuth(), chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
1069
1069
|
try {
|
|
1070
1070
|
const id = c.req.param("id");
|
|
1071
1071
|
const db = c.env.DB;
|
|
@@ -1087,8 +1087,8 @@ apiContentCrudRoutes.put("/:id", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_
|
|
|
1087
1087
|
} catch (err) {
|
|
1088
1088
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
1089
1089
|
}
|
|
1090
|
-
const docType = await new
|
|
1091
|
-
const svc = new
|
|
1090
|
+
const docType = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(docRow.type_id);
|
|
1091
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
1092
1092
|
queryableFields: docType?.queryableFields ?? [],
|
|
1093
1093
|
typeSchemaVersion: docType?.schemaVersion ?? 1,
|
|
1094
1094
|
maxVersionsPerRoot: docType?.settings?.maxVersionsPerRoot ?? 50,
|
|
@@ -1110,7 +1110,7 @@ apiContentCrudRoutes.put("/:id", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_
|
|
|
1110
1110
|
const cache = chunk4BTBSXMR_cjs.getCacheService(chunk4BTBSXMR_cjs.CACHE_CONFIGS.api);
|
|
1111
1111
|
await cache.invalidate("content-filtered:*");
|
|
1112
1112
|
await cache.invalidate("collection-content-filtered:*");
|
|
1113
|
-
const coll =
|
|
1113
|
+
const coll = chunkFXZSZ7C7_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
1114
1114
|
const saved = await db.prepare("SELECT * FROM documents WHERE id = ?").bind(newDraft.id).first();
|
|
1115
1115
|
const savedData = saved?.data ? JSON.parse(saved.data) : {};
|
|
1116
1116
|
dispatchHookEvent(c, "content:after:update", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
@@ -1119,7 +1119,7 @@ apiContentCrudRoutes.put("/:id", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_
|
|
|
1119
1119
|
dispatchHookEvent(c, "content:after:publish", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
1120
1120
|
}
|
|
1121
1121
|
return c.json({
|
|
1122
|
-
data: { id: saved.root_id, title: saved.title, slug: saved.slug, status: saved.status, collectionId: coll?.id ?? docRow.type_id, data: savedData, created_at:
|
|
1122
|
+
data: { id: saved.root_id, title: saved.title, slug: saved.slug, status: saved.status, collectionId: coll?.id ?? docRow.type_id, data: savedData, created_at: chunkW36OZTJ5_cjs.documentSecondsToMs(saved.created_at), updated_at: chunkW36OZTJ5_cjs.documentSecondsToMs(saved.updated_at) }
|
|
1123
1123
|
});
|
|
1124
1124
|
}
|
|
1125
1125
|
return c.json({ error: "Content not found" }, 404);
|
|
@@ -1131,7 +1131,7 @@ apiContentCrudRoutes.put("/:id", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_
|
|
|
1131
1131
|
}, 500);
|
|
1132
1132
|
}
|
|
1133
1133
|
});
|
|
1134
|
-
apiContentCrudRoutes.delete("/:id",
|
|
1134
|
+
apiContentCrudRoutes.delete("/:id", chunkZBDDZYA3_cjs.requireAuth(), chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
1135
1135
|
try {
|
|
1136
1136
|
const id = c.req.param("id");
|
|
1137
1137
|
const db = c.env.DB;
|
|
@@ -1244,8 +1244,8 @@ function mapDocRowToContent(row, collectionId) {
|
|
|
1244
1244
|
collectionId,
|
|
1245
1245
|
data: row.data ? JSON.parse(row.data) : {},
|
|
1246
1246
|
// D29: document timestamps are SECONDS; the legacy `content` API contract is MILLISECONDS.
|
|
1247
|
-
created_at:
|
|
1248
|
-
updated_at:
|
|
1247
|
+
created_at: chunkW36OZTJ5_cjs.documentSecondsToMs(row.created_at),
|
|
1248
|
+
updated_at: chunkW36OZTJ5_cjs.documentSecondsToMs(row.updated_at)
|
|
1249
1249
|
};
|
|
1250
1250
|
}
|
|
1251
1251
|
var apiRoutes = new hono.Hono();
|
|
@@ -1257,7 +1257,7 @@ apiRoutes.use("*", async (c, next) => {
|
|
|
1257
1257
|
c.header("X-Response-Time", `${totalTime}ms`);
|
|
1258
1258
|
});
|
|
1259
1259
|
apiRoutes.use("*", async (c, next) => {
|
|
1260
|
-
const cacheEnabled = await
|
|
1260
|
+
const cacheEnabled = await chunkZBDDZYA3_cjs.isPluginActive(c.env.DB, "core-cache");
|
|
1261
1261
|
c.set("cacheEnabled", cacheEnabled);
|
|
1262
1262
|
await next();
|
|
1263
1263
|
});
|
|
@@ -1280,7 +1280,7 @@ apiRoutes.get("/", (c) => {
|
|
|
1280
1280
|
openapi: "3.0.0",
|
|
1281
1281
|
info: {
|
|
1282
1282
|
title: "SonicJS AI API",
|
|
1283
|
-
version:
|
|
1283
|
+
version: chunkPK3ODTAL_cjs.getCoreVersion(),
|
|
1284
1284
|
description: "RESTful API for SonicJS headless CMS - a modern, AI-powered content management system built on Cloudflare Workers",
|
|
1285
1285
|
contact: {
|
|
1286
1286
|
name: "SonicJS Support",
|
|
@@ -1710,8 +1710,8 @@ apiRoutes.get("/collections", async (c) => {
|
|
|
1710
1710
|
}
|
|
1711
1711
|
c.header("X-Cache-Status", "MISS");
|
|
1712
1712
|
c.header("X-Cache-Source", "registry");
|
|
1713
|
-
const records =
|
|
1714
|
-
const transformedResults = records.map(
|
|
1713
|
+
const records = chunkFXZSZ7C7_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
1714
|
+
const transformedResults = records.map(chunkFXZSZ7C7_cjs.collectionRecordToRow);
|
|
1715
1715
|
const responseData = {
|
|
1716
1716
|
data: transformedResults,
|
|
1717
1717
|
meta: addTimingMeta(c, {
|
|
@@ -1732,7 +1732,7 @@ apiRoutes.get("/collections", async (c) => {
|
|
|
1732
1732
|
return c.json({ error: "Failed to fetch collections" }, 500);
|
|
1733
1733
|
}
|
|
1734
1734
|
});
|
|
1735
|
-
apiRoutes.get("/content",
|
|
1735
|
+
apiRoutes.get("/content", chunkZBDDZYA3_cjs.optionalAuth(), async (c) => {
|
|
1736
1736
|
const executionStart = Date.now();
|
|
1737
1737
|
try {
|
|
1738
1738
|
const db = c.env.DB;
|
|
@@ -1741,7 +1741,7 @@ apiRoutes.get("/content", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) => {
|
|
|
1741
1741
|
const collIdByName = /* @__PURE__ */ new Map();
|
|
1742
1742
|
let typeId;
|
|
1743
1743
|
let typeIds;
|
|
1744
|
-
const registry =
|
|
1744
|
+
const registry = chunkFXZSZ7C7_cjs.getCollectionRegistry();
|
|
1745
1745
|
if (queryParams.collection) {
|
|
1746
1746
|
const collectionName = queryParams.collection;
|
|
1747
1747
|
const record = registry.getByName(collectionName);
|
|
@@ -1840,13 +1840,13 @@ apiRoutes.get("/content", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) => {
|
|
|
1840
1840
|
}, 500);
|
|
1841
1841
|
}
|
|
1842
1842
|
});
|
|
1843
|
-
apiRoutes.get("/collections/:collection/content",
|
|
1843
|
+
apiRoutes.get("/collections/:collection/content", chunkZBDDZYA3_cjs.optionalAuth(), async (c) => {
|
|
1844
1844
|
const executionStart = Date.now();
|
|
1845
1845
|
try {
|
|
1846
1846
|
const collection = c.req.param("collection");
|
|
1847
1847
|
const db = c.env.DB;
|
|
1848
1848
|
const queryParams = c.req.query();
|
|
1849
|
-
const record =
|
|
1849
|
+
const record = chunkFXZSZ7C7_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
1850
1850
|
if (!record || record.isActive === false) {
|
|
1851
1851
|
return c.json({ error: "Collection not found" }, 404);
|
|
1852
1852
|
}
|
|
@@ -1902,7 +1902,7 @@ apiRoutes.get("/collections/:collection/content", chunkVMBQ6NQB_cjs.optionalAuth
|
|
|
1902
1902
|
const responseData = {
|
|
1903
1903
|
data: transformedResults,
|
|
1904
1904
|
meta: addTimingMeta(c, {
|
|
1905
|
-
...includeCollection ? { collection:
|
|
1905
|
+
...includeCollection ? { collection: chunkFXZSZ7C7_cjs.collectionRecordToRow(record) } : {},
|
|
1906
1906
|
count: results.length,
|
|
1907
1907
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1908
1908
|
// D44: echo the caller's filter with the access policy applied (status=published forced for
|
|
@@ -1927,13 +1927,13 @@ apiRoutes.get("/collections/:collection/content", chunkVMBQ6NQB_cjs.optionalAuth
|
|
|
1927
1927
|
}
|
|
1928
1928
|
});
|
|
1929
1929
|
apiRoutes.route("/content", api_content_crud_default);
|
|
1930
|
-
apiRoutes.get("/:collection",
|
|
1930
|
+
apiRoutes.get("/:collection", chunkZBDDZYA3_cjs.optionalAuth(), async (c) => {
|
|
1931
1931
|
const executionStart = Date.now();
|
|
1932
1932
|
try {
|
|
1933
1933
|
const collection = c.req.param("collection");
|
|
1934
1934
|
const db = c.env.DB;
|
|
1935
1935
|
const queryParams = c.req.query();
|
|
1936
|
-
const record =
|
|
1936
|
+
const record = chunkFXZSZ7C7_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
1937
1937
|
if (!record || record.isActive === false) {
|
|
1938
1938
|
return c.json({ error: "Collection not found" }, 404);
|
|
1939
1939
|
}
|
|
@@ -1973,7 +1973,7 @@ apiRoutes.get("/:collection", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) => {
|
|
|
1973
1973
|
const responseData = {
|
|
1974
1974
|
data: transformedResults,
|
|
1975
1975
|
meta: addTimingMeta(c, {
|
|
1976
|
-
...includeCollection ? { collection:
|
|
1976
|
+
...includeCollection ? { collection: chunkFXZSZ7C7_cjs.collectionRecordToRow(record) } : {},
|
|
1977
1977
|
count: results.length,
|
|
1978
1978
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1979
1979
|
filter: normalizePublicContentFilter(filter, role),
|
|
@@ -1991,12 +1991,12 @@ apiRoutes.get("/:collection", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) => {
|
|
|
1991
1991
|
return c.json({ error: "Failed to fetch content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
1992
1992
|
}
|
|
1993
1993
|
});
|
|
1994
|
-
apiRoutes.get("/:collection/:id",
|
|
1994
|
+
apiRoutes.get("/:collection/:id", chunkZBDDZYA3_cjs.optionalAuth(), async (c) => {
|
|
1995
1995
|
try {
|
|
1996
1996
|
const collection = c.req.param("collection");
|
|
1997
1997
|
const id = c.req.param("id");
|
|
1998
1998
|
const db = c.env.DB;
|
|
1999
|
-
const record =
|
|
1999
|
+
const record = chunkFXZSZ7C7_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2000
2000
|
if (!record || record.isActive === false) {
|
|
2001
2001
|
return c.json({ error: "Collection not found" }, 404);
|
|
2002
2002
|
}
|
|
@@ -2005,7 +2005,7 @@ apiRoutes.get("/:collection/:id", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) =>
|
|
|
2005
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"
|
|
2006
2006
|
).bind(id, record.name).first();
|
|
2007
2007
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
2008
|
-
const coll =
|
|
2008
|
+
const coll = chunkFXZSZ7C7_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
2009
2009
|
const transformedContent = {
|
|
2010
2010
|
id: docRow.root_id,
|
|
2011
2011
|
title: docRow.title,
|
|
@@ -2013,8 +2013,8 @@ apiRoutes.get("/:collection/:id", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) =>
|
|
|
2013
2013
|
status: docRow.status,
|
|
2014
2014
|
collectionId: coll?.id ?? docRow.type_id,
|
|
2015
2015
|
data: docRow.data ? JSON.parse(docRow.data) : {},
|
|
2016
|
-
created_at:
|
|
2017
|
-
updated_at:
|
|
2016
|
+
created_at: chunkW36OZTJ5_cjs.documentSecondsToMs(docRow.created_at),
|
|
2017
|
+
updated_at: chunkW36OZTJ5_cjs.documentSecondsToMs(docRow.updated_at)
|
|
2018
2018
|
};
|
|
2019
2019
|
dispatchHookEvent(c, "content:read", { collection: docRow.type_id, id: docRow.root_id, data: transformedContent.data }, "fire-and-forget");
|
|
2020
2020
|
return c.json({ data: transformedContent });
|
|
@@ -2023,7 +2023,7 @@ apiRoutes.get("/:collection/:id", chunkVMBQ6NQB_cjs.optionalAuth(), async (c) =>
|
|
|
2023
2023
|
return c.json({ error: "Failed to fetch content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2024
2024
|
}
|
|
2025
2025
|
});
|
|
2026
|
-
apiRoutes.post("/:collection",
|
|
2026
|
+
apiRoutes.post("/:collection", chunkZBDDZYA3_cjs.requireAuth(), chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2027
2027
|
try {
|
|
2028
2028
|
const collection = c.req.param("collection");
|
|
2029
2029
|
const db = c.env.DB;
|
|
@@ -2044,26 +2044,26 @@ apiRoutes.post("/:collection", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB_cj
|
|
|
2044
2044
|
} catch (err) {
|
|
2045
2045
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
2046
2046
|
}
|
|
2047
|
-
const svc = new
|
|
2047
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, { queryableFields: backing.docType.queryableFields ?? [], typeSchemaVersion: backing.docType.schemaVersion ?? 1, maxVersionsPerRoot: backing.docType.settings?.maxVersionsPerRoot ?? 50, tenantId: "default", versioning: backing.docType.settings?.versioning ?? false });
|
|
2048
2048
|
const doc = await svc.create(createDocumentSchema.parse({ typeId: backing.coll.name, tenantId: "default", locale: "default", title, slug: finalSlug, data: hookData, publishOnCreate: (status || "draft") === "published" }), user?.userId);
|
|
2049
2049
|
const cache = chunk4BTBSXMR_cjs.getCacheService(chunk4BTBSXMR_cjs.CACHE_CONFIGS.api);
|
|
2050
2050
|
await cache.invalidate("content-filtered:*");
|
|
2051
2051
|
await cache.invalidate("collection-content-filtered:*");
|
|
2052
2052
|
dispatchHookEvent(c, "content:after:create", { collection: backing.coll.name, id: doc.rootId, data: doc.data ?? {}, user: actor }, "fire-and-forget");
|
|
2053
|
-
return c.json({ data: { id: doc.rootId, title: doc.title, slug: doc.slug, status: doc.status, collectionId: backing.coll.id, data: doc.data, created_at:
|
|
2053
|
+
return c.json({ data: { id: doc.rootId, title: doc.title, slug: doc.slug, status: doc.status, collectionId: backing.coll.id, data: doc.data, created_at: chunkW36OZTJ5_cjs.documentSecondsToMs(doc.createdAt), updated_at: chunkW36OZTJ5_cjs.documentSecondsToMs(doc.updatedAt) } }, 201);
|
|
2054
2054
|
} catch (error) {
|
|
2055
2055
|
console.error("Error creating content:", error);
|
|
2056
2056
|
return c.json({ error: "Failed to create content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2057
2057
|
}
|
|
2058
2058
|
});
|
|
2059
|
-
apiRoutes.put("/:collection/:id",
|
|
2059
|
+
apiRoutes.put("/:collection/:id", chunkZBDDZYA3_cjs.requireAuth(), chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2060
2060
|
try {
|
|
2061
2061
|
const collection = c.req.param("collection");
|
|
2062
2062
|
const id = c.req.param("id");
|
|
2063
2063
|
const db = c.env.DB;
|
|
2064
2064
|
const user = c.get("user");
|
|
2065
2065
|
const body = await c.req.json();
|
|
2066
|
-
const collRecord =
|
|
2066
|
+
const collRecord = chunkFXZSZ7C7_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2067
2067
|
const typeName = collRecord?.name ?? collection;
|
|
2068
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();
|
|
2069
2069
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
@@ -2075,8 +2075,8 @@ apiRoutes.put("/:collection/:id", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB
|
|
|
2075
2075
|
} catch (err) {
|
|
2076
2076
|
return c.json({ error: "Write cancelled by plugin", details: String(err) }, 400);
|
|
2077
2077
|
}
|
|
2078
|
-
const docType = await new
|
|
2079
|
-
const svc = new
|
|
2078
|
+
const docType = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(docRow.type_id);
|
|
2079
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, { queryableFields: docType?.queryableFields ?? [], typeSchemaVersion: docType?.schemaVersion ?? 1, maxVersionsPerRoot: docType?.settings?.maxVersionsPerRoot ?? 50, tenantId: "default", versioning: docType?.settings?.versioning ?? false });
|
|
2080
2080
|
const input = {};
|
|
2081
2081
|
if (body.title !== void 0) input.title = body.title;
|
|
2082
2082
|
if (body.slug !== void 0) input.slug = slugify(body.slug);
|
|
@@ -2092,25 +2092,25 @@ apiRoutes.put("/:collection/:id", chunkVMBQ6NQB_cjs.requireAuth(), chunkVMBQ6NQB
|
|
|
2092
2092
|
const cache = chunk4BTBSXMR_cjs.getCacheService(chunk4BTBSXMR_cjs.CACHE_CONFIGS.api);
|
|
2093
2093
|
await cache.invalidate("content-filtered:*");
|
|
2094
2094
|
await cache.invalidate("collection-content-filtered:*");
|
|
2095
|
-
const coll =
|
|
2095
|
+
const coll = chunkFXZSZ7C7_cjs.getCollectionRegistry().getByName(docRow.type_id);
|
|
2096
2096
|
const saved = await db.prepare("SELECT * FROM documents WHERE id = ?").bind(newDraft.id).first();
|
|
2097
2097
|
const savedData = saved?.data ? JSON.parse(saved.data) : {};
|
|
2098
2098
|
dispatchHookEvent(c, "content:after:update", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
2099
2099
|
const nowPublished = body.status === "published" || body.status === void 0 && wasPublished;
|
|
2100
2100
|
if (nowPublished && !wasPublished) dispatchHookEvent(c, "content:after:publish", { collection: docRow.type_id, id, data: savedData, user: actor }, "fire-and-forget");
|
|
2101
|
-
return c.json({ data: { id: saved.root_id, title: saved.title, slug: saved.slug, status: saved.status, collectionId: coll?.id ?? docRow.type_id, data: savedData, created_at:
|
|
2101
|
+
return c.json({ data: { id: saved.root_id, title: saved.title, slug: saved.slug, status: saved.status, collectionId: coll?.id ?? docRow.type_id, data: savedData, created_at: chunkW36OZTJ5_cjs.documentSecondsToMs(saved.created_at), updated_at: chunkW36OZTJ5_cjs.documentSecondsToMs(saved.updated_at) } });
|
|
2102
2102
|
} catch (error) {
|
|
2103
2103
|
console.error("Error updating content:", error);
|
|
2104
2104
|
return c.json({ error: "Failed to update content", details: error instanceof Error ? error.message : String(error) }, 500);
|
|
2105
2105
|
}
|
|
2106
2106
|
});
|
|
2107
|
-
apiRoutes.delete("/:collection/:id",
|
|
2107
|
+
apiRoutes.delete("/:collection/:id", chunkZBDDZYA3_cjs.requireAuth(), chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
2108
2108
|
try {
|
|
2109
2109
|
const collection = c.req.param("collection");
|
|
2110
2110
|
const id = c.req.param("id");
|
|
2111
2111
|
const db = c.env.DB;
|
|
2112
2112
|
const user = c.get("user");
|
|
2113
|
-
const collRecord =
|
|
2113
|
+
const collRecord = chunkFXZSZ7C7_cjs.getCollectionRegistry().getBySlugOrName(collection);
|
|
2114
2114
|
const typeName = collRecord?.name ?? collection;
|
|
2115
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();
|
|
2116
2116
|
if (!docRow) return c.json({ error: "Content not found" }, 404);
|
|
@@ -2195,7 +2195,7 @@ var MediaDocumentService = class {
|
|
|
2195
2195
|
}
|
|
2196
2196
|
/** Create a media_asset document from R2 upload metadata. Published-on-create (immediately usable). */
|
|
2197
2197
|
async createFromUpload(meta, createdBy) {
|
|
2198
|
-
const svc = new
|
|
2198
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(this.db, { queryableFields: MEDIA_QUERYABLE, tenantId: this.tenantId, maxVersionsPerRoot: 5 });
|
|
2199
2199
|
return svc.create(
|
|
2200
2200
|
createDocumentSchema.parse({
|
|
2201
2201
|
typeId: "media_asset",
|
|
@@ -2268,7 +2268,7 @@ var MediaDocumentService = class {
|
|
|
2268
2268
|
}
|
|
2269
2269
|
/** Update alt/caption/tags on a media_asset document (saveDraft + publish atomically). */
|
|
2270
2270
|
async updateMetadata(rootId, meta, updatedBy) {
|
|
2271
|
-
const svc = new
|
|
2271
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(this.db, { queryableFields: MEDIA_QUERYABLE, tenantId: this.tenantId, maxVersionsPerRoot: 5 });
|
|
2272
2272
|
const newDraft = await svc.saveDraft(rootId, { data: meta }, updatedBy);
|
|
2273
2273
|
return svc.publish(newDraft.id, updatedBy);
|
|
2274
2274
|
}
|
|
@@ -2325,7 +2325,7 @@ var fileValidationSchema = zod.z.object({
|
|
|
2325
2325
|
// 50MB max
|
|
2326
2326
|
});
|
|
2327
2327
|
var apiMediaRoutes = new hono.Hono();
|
|
2328
|
-
apiMediaRoutes.use("*",
|
|
2328
|
+
apiMediaRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
2329
2329
|
apiMediaRoutes.post("/upload", async (c) => {
|
|
2330
2330
|
try {
|
|
2331
2331
|
const user = c.get("user");
|
|
@@ -3023,7 +3023,7 @@ apiSystemRoutes.get("/info", (c) => {
|
|
|
3023
3023
|
apiSystemRoutes.get("/stats", async (c) => {
|
|
3024
3024
|
try {
|
|
3025
3025
|
const db = c.env.DB;
|
|
3026
|
-
const typeIds =
|
|
3026
|
+
const typeIds = chunkFXZSZ7C7_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal).map((r) => r.name);
|
|
3027
3027
|
let contentStats = null;
|
|
3028
3028
|
if (typeIds.length > 0) {
|
|
3029
3029
|
const placeholders = typeIds.map(() => "?").join(",");
|
|
@@ -3098,12 +3098,12 @@ apiSystemRoutes.get("/env", (c) => {
|
|
|
3098
3098
|
});
|
|
3099
3099
|
var api_system_default = apiSystemRoutes;
|
|
3100
3100
|
var adminApiRoutes = new hono.Hono();
|
|
3101
|
-
adminApiRoutes.use("*",
|
|
3102
|
-
adminApiRoutes.use("*",
|
|
3101
|
+
adminApiRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
3102
|
+
adminApiRoutes.use("*", chunkZBDDZYA3_cjs.requireRole(["admin", "editor"]));
|
|
3103
3103
|
adminApiRoutes.get("/stats", async (c) => {
|
|
3104
3104
|
try {
|
|
3105
3105
|
const db = c.env.DB;
|
|
3106
|
-
const userCollections =
|
|
3106
|
+
const userCollections = chunkFXZSZ7C7_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
3107
3107
|
const collectionsCount = userCollections.length;
|
|
3108
3108
|
let contentCount = 0;
|
|
3109
3109
|
if (userCollections.length > 0) {
|
|
@@ -3194,7 +3194,7 @@ adminApiRoutes.get("/collections", async (c) => {
|
|
|
3194
3194
|
try {
|
|
3195
3195
|
const search = c.req.query("search") || "";
|
|
3196
3196
|
const includeInactive = c.req.query("includeInactive") === "true";
|
|
3197
|
-
let records =
|
|
3197
|
+
let records = chunkFXZSZ7C7_cjs.getCollectionRegistry().list().filter((r) => !r.internal);
|
|
3198
3198
|
if (!includeInactive) records = records.filter((r) => r.isActive !== false);
|
|
3199
3199
|
if (search) {
|
|
3200
3200
|
const needle = search.toLowerCase();
|
|
@@ -3226,7 +3226,7 @@ adminApiRoutes.get("/collections", async (c) => {
|
|
|
3226
3226
|
adminApiRoutes.get("/collections/:id", async (c) => {
|
|
3227
3227
|
try {
|
|
3228
3228
|
const id = c.req.param("id");
|
|
3229
|
-
const registry =
|
|
3229
|
+
const registry = chunkFXZSZ7C7_cjs.getCollectionRegistry();
|
|
3230
3230
|
const record = registry.getById(id) ?? registry.getByName(id);
|
|
3231
3231
|
if (!record) {
|
|
3232
3232
|
return c.json({ error: "Collection not found" }, 404);
|
|
@@ -3276,7 +3276,7 @@ adminApiRoutes.get("/references", async (c) => {
|
|
|
3276
3276
|
if (collectionParams.length === 0) {
|
|
3277
3277
|
return c.json({ error: "Collection is required" }, 400);
|
|
3278
3278
|
}
|
|
3279
|
-
const registry =
|
|
3279
|
+
const registry = chunkFXZSZ7C7_cjs.getCollectionRegistry();
|
|
3280
3280
|
const matched = collectionParams.map((param) => registry.getById(param) ?? registry.getByName(param)).filter((r) => !!r);
|
|
3281
3281
|
const seen = /* @__PURE__ */ new Set();
|
|
3282
3282
|
const collections = matched.filter((r) => {
|
|
@@ -3391,7 +3391,7 @@ adminApiRoutes.patch("/collections/:id", collectionsReadOnly);
|
|
|
3391
3391
|
adminApiRoutes.delete("/collections/:id", collectionsReadOnly);
|
|
3392
3392
|
adminApiRoutes.get("/migrations/status", async (c) => {
|
|
3393
3393
|
try {
|
|
3394
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
3394
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-X3UX24QG.cjs');
|
|
3395
3395
|
const db = c.env.DB;
|
|
3396
3396
|
const migrationService = new MigrationService2(db);
|
|
3397
3397
|
const status = await migrationService.getMigrationStatus();
|
|
@@ -3434,7 +3434,7 @@ adminApiRoutes.post("/migrations/run", async (c) => {
|
|
|
3434
3434
|
});
|
|
3435
3435
|
adminApiRoutes.get("/migrations/validate", async (c) => {
|
|
3436
3436
|
try {
|
|
3437
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
3437
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-X3UX24QG.cjs');
|
|
3438
3438
|
const db = c.env.DB;
|
|
3439
3439
|
const migrationService = new MigrationService2(db);
|
|
3440
3440
|
const validation = await migrationService.validateSchema();
|
|
@@ -3593,7 +3593,7 @@ function renderLoginPage(data, demoLoginActive = false) {
|
|
|
3593
3593
|
<!-- Form -->
|
|
3594
3594
|
<form
|
|
3595
3595
|
id="login-form"
|
|
3596
|
-
hx-post="/auth/login/form"
|
|
3596
|
+
hx-post="/auth/login/form${data.redirect ? `?redirect=${encodeURIComponent(data.redirect)}` : ""}"
|
|
3597
3597
|
hx-target="#form-response"
|
|
3598
3598
|
hx-swap="innerHTML"
|
|
3599
3599
|
class="space-y-6"
|
|
@@ -3849,7 +3849,7 @@ function renderRegisterPage(data) {
|
|
|
3849
3849
|
}
|
|
3850
3850
|
|
|
3851
3851
|
// src/services/email/email-service-singleton.ts
|
|
3852
|
-
var singleton =
|
|
3852
|
+
var singleton = chunkPTTFLUEX_cjs.createServiceSingleton("EmailService");
|
|
3853
3853
|
function setEmailService(service2) {
|
|
3854
3854
|
singleton.set(service2);
|
|
3855
3855
|
}
|
|
@@ -3893,7 +3893,7 @@ function emptyProfile() {
|
|
|
3893
3893
|
return { custom: {} };
|
|
3894
3894
|
}
|
|
3895
3895
|
function service(db) {
|
|
3896
|
-
return new
|
|
3896
|
+
return new chunkW36OZTJ5_cjs.DocumentsService(db, { tenantId: "default", maxVersionsPerRoot: 1, queryableFields: [] });
|
|
3897
3897
|
}
|
|
3898
3898
|
async function readProfileData(db, userId) {
|
|
3899
3899
|
const row = await db.prepare(
|
|
@@ -4657,7 +4657,7 @@ function getLexicalInitScript(settings = {}) {
|
|
|
4657
4657
|
</script>
|
|
4658
4658
|
`;
|
|
4659
4659
|
}
|
|
4660
|
-
var lexicalEditorPlugin =
|
|
4660
|
+
var lexicalEditorPlugin = chunkPTTFLUEX_cjs.definePlugin({
|
|
4661
4661
|
id: "lexical-editor",
|
|
4662
4662
|
version: "1.0.0",
|
|
4663
4663
|
name: "Lexical Editor",
|
|
@@ -5581,6 +5581,79 @@ function renderDynamicField(field, options = {}) {
|
|
|
5581
5581
|
`;
|
|
5582
5582
|
break;
|
|
5583
5583
|
}
|
|
5584
|
+
case "json": {
|
|
5585
|
+
const jsonParsedValue = value !== null && value !== void 0 && typeof value !== "string" ? value : typeof value === "string" && value !== "" ? (() => {
|
|
5586
|
+
try {
|
|
5587
|
+
return JSON.parse(value);
|
|
5588
|
+
} catch {
|
|
5589
|
+
return value;
|
|
5590
|
+
}
|
|
5591
|
+
})() : null;
|
|
5592
|
+
const jsonDisplayValue = jsonParsedValue !== null && typeof jsonParsedValue !== "string" ? JSON.stringify(jsonParsedValue, null, 2) : typeof jsonParsedValue === "string" ? jsonParsedValue : "";
|
|
5593
|
+
const viewerId = `${fieldId}-viewer`;
|
|
5594
|
+
const textareaId = `${fieldId}-textarea`;
|
|
5595
|
+
const jsonDataAttr = escapeHtml2(JSON.stringify(jsonParsedValue ?? null));
|
|
5596
|
+
const isEmpty = jsonParsedValue === null || jsonDisplayValue === "";
|
|
5597
|
+
if (disabled) {
|
|
5598
|
+
fieldHTML = `
|
|
5599
|
+
<div
|
|
5600
|
+
id="${viewerId}"
|
|
5601
|
+
class="json-viewer-host rounded-lg px-3 py-2 text-xs bg-white dark:bg-zinc-800 shadow-sm ring-1 ring-inset ring-zinc-950/10 dark:ring-white/10 min-h-[2.5rem] overflow-auto"
|
|
5602
|
+
data-json-viewer
|
|
5603
|
+
data-json="${jsonDataAttr}"
|
|
5604
|
+
data-open="${opts.open ?? 2}"
|
|
5605
|
+
>${isEmpty ? '<span class="text-zinc-400 dark:text-zinc-500 italic">empty</span>' : ""}</div>
|
|
5606
|
+
${getJsonViewerScript()}
|
|
5607
|
+
`;
|
|
5608
|
+
} else {
|
|
5609
|
+
fieldHTML = `
|
|
5610
|
+
<div class="json-field-wrapper space-y-2">
|
|
5611
|
+
<div class="flex items-center justify-end">
|
|
5612
|
+
<button
|
|
5613
|
+
type="button"
|
|
5614
|
+
id="${fieldId}-toggle"
|
|
5615
|
+
class="text-xs text-zinc-500 dark:text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-200 underline transition-colors"
|
|
5616
|
+
data-json-toggle
|
|
5617
|
+
data-viewer="${viewerId}"
|
|
5618
|
+
data-textarea="${textareaId}"
|
|
5619
|
+
data-hidden-input="${fieldId}"
|
|
5620
|
+
>Edit JSON</button>
|
|
5621
|
+
</div>
|
|
5622
|
+
|
|
5623
|
+
<div
|
|
5624
|
+
id="${viewerId}"
|
|
5625
|
+
class="json-viewer-host rounded-lg px-3 py-2 text-xs bg-white dark:bg-zinc-800 shadow-sm ring-1 ring-inset ring-zinc-950/10 dark:ring-white/10 min-h-[2.5rem] overflow-auto"
|
|
5626
|
+
data-json-viewer
|
|
5627
|
+
data-json="${jsonDataAttr}"
|
|
5628
|
+
data-open="${opts.open ?? 2}"
|
|
5629
|
+
>${isEmpty ? '<span class="text-zinc-400 dark:text-zinc-500 italic">empty \u2014 click "Edit JSON" to add data</span>' : ""}</div>
|
|
5630
|
+
|
|
5631
|
+
<textarea
|
|
5632
|
+
id="${textareaId}"
|
|
5633
|
+
rows="${opts.rows || 8}"
|
|
5634
|
+
placeholder="${opts.placeholder || "{}"}"
|
|
5635
|
+
class="${baseClasses} ${errorClasses} resize-y font-mono text-xs hidden"
|
|
5636
|
+
aria-label="${escapeHtml2(field.field_label)}"
|
|
5637
|
+
data-json-edit-area
|
|
5638
|
+
data-viewer="${viewerId}"
|
|
5639
|
+
data-hidden-input="${fieldId}"
|
|
5640
|
+
>${escapeHtml2(jsonDisplayValue)}</textarea>
|
|
5641
|
+
|
|
5642
|
+
<input
|
|
5643
|
+
type="hidden"
|
|
5644
|
+
id="${fieldId}"
|
|
5645
|
+
name="${fieldName}"
|
|
5646
|
+
value="${escapeHtml2(jsonDisplayValue)}"
|
|
5647
|
+
${required}
|
|
5648
|
+
>
|
|
5649
|
+
|
|
5650
|
+
<div id="${fieldId}-json-error" class="text-xs text-pink-500 dark:text-pink-400 hidden"></div>
|
|
5651
|
+
</div>
|
|
5652
|
+
${getJsonViewerScript()}
|
|
5653
|
+
`;
|
|
5654
|
+
}
|
|
5655
|
+
break;
|
|
5656
|
+
}
|
|
5584
5657
|
default:
|
|
5585
5658
|
fieldHTML = `
|
|
5586
5659
|
<input
|
|
@@ -6077,6 +6150,120 @@ function normalizeBlockField(fieldConfig, fieldName) {
|
|
|
6077
6150
|
options
|
|
6078
6151
|
};
|
|
6079
6152
|
}
|
|
6153
|
+
function getJsonViewerScript() {
|
|
6154
|
+
return `
|
|
6155
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/json-formatter-js@2.5.23/dist/json-formatter.min.css" id="json-formatter-css" onload="this.removeAttribute('onload')" onerror="">
|
|
6156
|
+
<script>
|
|
6157
|
+
(function() {
|
|
6158
|
+
var JS_URL = 'https://cdn.jsdelivr.net/npm/json-formatter-js@2.5.23/dist/json-formatter.umd.min.js';
|
|
6159
|
+
|
|
6160
|
+
function isDark() {
|
|
6161
|
+
return document.documentElement.classList.contains('dark') ||
|
|
6162
|
+
document.documentElement.dataset.theme === 'dark' ||
|
|
6163
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
6164
|
+
}
|
|
6165
|
+
|
|
6166
|
+
function initViewer(el) {
|
|
6167
|
+
var raw = el.dataset.json;
|
|
6168
|
+
var open = parseInt(el.dataset.open || '2', 10);
|
|
6169
|
+
if (!raw || raw === 'null') return;
|
|
6170
|
+
var data;
|
|
6171
|
+
try { data = JSON.parse(raw); } catch(e) { el.textContent = raw; return; }
|
|
6172
|
+
var fmt = new JSONFormatter(data, open, {
|
|
6173
|
+
hoverPreviewEnabled: true,
|
|
6174
|
+
hoverPreviewArrayCount: 5,
|
|
6175
|
+
hoverPreviewFieldCount: 5,
|
|
6176
|
+
theme: isDark() ? 'dark' : '',
|
|
6177
|
+
animateOpen: true,
|
|
6178
|
+
animateClose: true,
|
|
6179
|
+
});
|
|
6180
|
+
el.innerHTML = '';
|
|
6181
|
+
el.appendChild(fmt.render());
|
|
6182
|
+
}
|
|
6183
|
+
|
|
6184
|
+
function initAllViewers() {
|
|
6185
|
+
document.querySelectorAll('[data-json-viewer]').forEach(function(el) { initViewer(el); });
|
|
6186
|
+
}
|
|
6187
|
+
|
|
6188
|
+
function ensureLoaded(cb) {
|
|
6189
|
+
if (window.JSONFormatter) { cb(); return; }
|
|
6190
|
+
if (window.__jsonFormatterCallbacks) { window.__jsonFormatterCallbacks.push(cb); return; }
|
|
6191
|
+
window.__jsonFormatterCallbacks = [cb];
|
|
6192
|
+
var s = document.createElement('script');
|
|
6193
|
+
s.src = JS_URL;
|
|
6194
|
+
s.onload = function() {
|
|
6195
|
+
(window.__jsonFormatterCallbacks || []).forEach(function(fn) { fn(); });
|
|
6196
|
+
window.__jsonFormatterCallbacks = null;
|
|
6197
|
+
};
|
|
6198
|
+
document.head.appendChild(s);
|
|
6199
|
+
}
|
|
6200
|
+
|
|
6201
|
+
if (!window.__sonicJsonViewerInit) {
|
|
6202
|
+
window.__sonicJsonViewerInit = true;
|
|
6203
|
+
|
|
6204
|
+
// Toggle between viewer and edit textarea
|
|
6205
|
+
document.addEventListener('click', function(e) {
|
|
6206
|
+
var btn = e.target.closest('[data-json-toggle]');
|
|
6207
|
+
if (!btn) return;
|
|
6208
|
+
var viewerId = btn.dataset.viewer;
|
|
6209
|
+
var textareaId = btn.dataset.textarea;
|
|
6210
|
+
var hiddenId = btn.dataset.hiddenInput;
|
|
6211
|
+
var viewer = document.getElementById(viewerId);
|
|
6212
|
+
var textarea = document.getElementById(textareaId);
|
|
6213
|
+
var hidden = document.getElementById(hiddenId);
|
|
6214
|
+
var errorEl = hidden ? document.getElementById(hiddenId + '-json-error') : null;
|
|
6215
|
+
if (!viewer || !textarea) return;
|
|
6216
|
+
var isEditing = !textarea.classList.contains('hidden');
|
|
6217
|
+
if (isEditing) {
|
|
6218
|
+
// Switching back to viewer \u2014 validate + refresh
|
|
6219
|
+
var raw = textarea.value.trim();
|
|
6220
|
+
if (raw) {
|
|
6221
|
+
try {
|
|
6222
|
+
var parsed = JSON.parse(raw);
|
|
6223
|
+
if (hidden) hidden.value = raw;
|
|
6224
|
+
viewer.dataset.json = JSON.stringify(parsed);
|
|
6225
|
+
ensureLoaded(function() { initViewer(viewer); });
|
|
6226
|
+
if (errorEl) { errorEl.textContent = ''; errorEl.classList.add('hidden'); }
|
|
6227
|
+
} catch(ex) {
|
|
6228
|
+
if (errorEl) { errorEl.textContent = 'Invalid JSON: ' + ex.message; errorEl.classList.remove('hidden'); }
|
|
6229
|
+
return;
|
|
6230
|
+
}
|
|
6231
|
+
} else {
|
|
6232
|
+
if (hidden) hidden.value = '';
|
|
6233
|
+
viewer.innerHTML = '<span class="text-zinc-400 dark:text-zinc-500 italic">empty</span>';
|
|
6234
|
+
}
|
|
6235
|
+
textarea.classList.add('hidden');
|
|
6236
|
+
viewer.classList.remove('hidden');
|
|
6237
|
+
btn.textContent = 'Edit JSON';
|
|
6238
|
+
} else {
|
|
6239
|
+
// Switching to edit \u2014 populate textarea from hidden input
|
|
6240
|
+
if (hidden && hidden.value) {
|
|
6241
|
+
try {
|
|
6242
|
+
textarea.value = JSON.stringify(JSON.parse(hidden.value), null, 2);
|
|
6243
|
+
} catch(e) {
|
|
6244
|
+
textarea.value = hidden.value;
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
viewer.classList.add('hidden');
|
|
6248
|
+
textarea.classList.remove('hidden');
|
|
6249
|
+
btn.textContent = 'Preview';
|
|
6250
|
+
}
|
|
6251
|
+
});
|
|
6252
|
+
}
|
|
6253
|
+
|
|
6254
|
+
function run() {
|
|
6255
|
+
ensureLoaded(initAllViewers);
|
|
6256
|
+
}
|
|
6257
|
+
|
|
6258
|
+
if (document.readyState === 'loading') {
|
|
6259
|
+
document.addEventListener('DOMContentLoaded', run);
|
|
6260
|
+
} else {
|
|
6261
|
+
run();
|
|
6262
|
+
}
|
|
6263
|
+
})();
|
|
6264
|
+
</script>
|
|
6265
|
+
`;
|
|
6266
|
+
}
|
|
6080
6267
|
function getStructuredFieldScript() {
|
|
6081
6268
|
return `
|
|
6082
6269
|
${getReadFieldValueScript()}
|
|
@@ -6876,7 +7063,7 @@ api.put("/:userId", async (c) => {
|
|
|
6876
7063
|
await saveCustomData(db, userId, sanitized);
|
|
6877
7064
|
return c.json({ success: true });
|
|
6878
7065
|
});
|
|
6879
|
-
var userProfilesPlugin =
|
|
7066
|
+
var userProfilesPlugin = chunkPTTFLUEX_cjs.definePlugin({
|
|
6880
7067
|
id: "user-profiles",
|
|
6881
7068
|
version: "1.0.0",
|
|
6882
7069
|
name: "User Profiles",
|
|
@@ -6914,8 +7101,8 @@ function renderPasswordResetEmail(resetLink, firstName) {
|
|
|
6914
7101
|
async function setCsrfCookie(c, maxAge) {
|
|
6915
7102
|
const secret = c.env?.JWT_SECRET || JWT_SECRET_FALLBACK;
|
|
6916
7103
|
const isDev = c.env?.ENVIRONMENT === "development" || !c.env?.ENVIRONMENT;
|
|
6917
|
-
const csrfToken = await
|
|
6918
|
-
const cookieMaxAge = await
|
|
7104
|
+
const csrfToken = await chunkZBDDZYA3_cjs.generateCsrfToken(secret);
|
|
7105
|
+
const cookieMaxAge = await chunkZBDDZYA3_cjs.getJwtExpirySecondsFromDb(c.env?.DB, c.env);
|
|
6919
7106
|
cookie.setCookie(c, "csrf_token", csrfToken, {
|
|
6920
7107
|
httpOnly: false,
|
|
6921
7108
|
secure: !isDev,
|
|
@@ -6937,10 +7124,12 @@ var authRoutes = new hono.Hono();
|
|
|
6937
7124
|
authRoutes.get("/login", async (c) => {
|
|
6938
7125
|
const error = c.req.query("error");
|
|
6939
7126
|
const message = c.req.query("message");
|
|
7127
|
+
const redirect = c.req.query("redirect");
|
|
6940
7128
|
const pageData = {
|
|
6941
7129
|
error: error || void 0,
|
|
6942
7130
|
message: message || void 0,
|
|
6943
|
-
version: c.get("appVersion")
|
|
7131
|
+
version: c.get("appVersion"),
|
|
7132
|
+
redirect: redirect && redirect.startsWith("/") ? redirect : void 0
|
|
6944
7133
|
};
|
|
6945
7134
|
const db = c.env.DB;
|
|
6946
7135
|
let demoLoginActive = false;
|
|
@@ -6953,9 +7142,9 @@ authRoutes.get("/login", async (c) => {
|
|
|
6953
7142
|
});
|
|
6954
7143
|
authRoutes.get("/register", async (c) => {
|
|
6955
7144
|
const db = c.env.DB;
|
|
6956
|
-
const isFirstUser = await
|
|
7145
|
+
const isFirstUser = await chunkXWVDSM2L_cjs.isFirstUserRegistration(db);
|
|
6957
7146
|
if (!isFirstUser) {
|
|
6958
|
-
const registrationEnabled = await
|
|
7147
|
+
const registrationEnabled = await chunkXWVDSM2L_cjs.isRegistrationEnabled(db);
|
|
6959
7148
|
if (!registrationEnabled) {
|
|
6960
7149
|
return c.redirect("/auth/login?error=Registration is currently disabled");
|
|
6961
7150
|
}
|
|
@@ -6972,13 +7161,13 @@ var loginSchema = zod.z.object({
|
|
|
6972
7161
|
});
|
|
6973
7162
|
authRoutes.post(
|
|
6974
7163
|
"/register",
|
|
6975
|
-
|
|
7164
|
+
chunkZBDDZYA3_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "register" }),
|
|
6976
7165
|
async (c) => {
|
|
6977
7166
|
try {
|
|
6978
7167
|
const db = c.env.DB;
|
|
6979
|
-
const isFirstUser = await
|
|
7168
|
+
const isFirstUser = await chunkXWVDSM2L_cjs.isFirstUserRegistration(db);
|
|
6980
7169
|
if (!isFirstUser) {
|
|
6981
|
-
const registrationEnabled = await
|
|
7170
|
+
const registrationEnabled = await chunkXWVDSM2L_cjs.isRegistrationEnabled(db);
|
|
6982
7171
|
if (!registrationEnabled) {
|
|
6983
7172
|
return c.json({ error: "Registration is currently disabled" }, 403);
|
|
6984
7173
|
}
|
|
@@ -6989,7 +7178,7 @@ authRoutes.post(
|
|
|
6989
7178
|
} catch (parseError) {
|
|
6990
7179
|
return c.json({ error: "Invalid JSON in request body" }, 400);
|
|
6991
7180
|
}
|
|
6992
|
-
const validationSchema = await
|
|
7181
|
+
const validationSchema = await chunkXWVDSM2L_cjs.authValidationService.buildRegistrationSchema(db);
|
|
6993
7182
|
let validatedData;
|
|
6994
7183
|
try {
|
|
6995
7184
|
validatedData = await validationSchema.parseAsync(requestData);
|
|
@@ -7001,14 +7190,14 @@ authRoutes.post(
|
|
|
7001
7190
|
}
|
|
7002
7191
|
const email = validatedData.email;
|
|
7003
7192
|
const password = validatedData.password;
|
|
7004
|
-
const firstName = validatedData.firstName ||
|
|
7005
|
-
const lastName = validatedData.lastName ||
|
|
7193
|
+
const firstName = validatedData.firstName || chunkXWVDSM2L_cjs.authValidationService.generateDefaultValue("firstName", validatedData);
|
|
7194
|
+
const lastName = validatedData.lastName || chunkXWVDSM2L_cjs.authValidationService.generateDefaultValue("lastName", validatedData);
|
|
7006
7195
|
const normalizedEmail = email.toLowerCase();
|
|
7007
7196
|
const existingUser = await db.prepare("SELECT id FROM auth_user WHERE email = ?").bind(normalizedEmail).first();
|
|
7008
7197
|
if (existingUser) {
|
|
7009
7198
|
return c.json({ error: "User with this email already exists" }, 400);
|
|
7010
7199
|
}
|
|
7011
|
-
const passwordHash = await
|
|
7200
|
+
const passwordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(password);
|
|
7012
7201
|
const userId = crypto.randomUUID();
|
|
7013
7202
|
const now = /* @__PURE__ */ new Date();
|
|
7014
7203
|
const nowSec = Math.floor(now.getTime() / 1e3);
|
|
@@ -7041,8 +7230,8 @@ authRoutes.post(
|
|
|
7041
7230
|
{ user: { id: userId, email: normalizedEmail, role: "viewer" } },
|
|
7042
7231
|
"fire-and-forget"
|
|
7043
7232
|
);
|
|
7044
|
-
const tokenTtl = await
|
|
7045
|
-
const token = await
|
|
7233
|
+
const tokenTtl = await chunkZBDDZYA3_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7234
|
+
const token = await chunkZBDDZYA3_cjs.AuthManager.generateToken(userId, normalizedEmail, "viewer", c.env.JWT_SECRET, tokenTtl);
|
|
7046
7235
|
cookie.setCookie(c, "auth_token", token, {
|
|
7047
7236
|
httpOnly: true,
|
|
7048
7237
|
secure: true,
|
|
@@ -7074,7 +7263,7 @@ authRoutes.post(
|
|
|
7074
7263
|
);
|
|
7075
7264
|
authRoutes.post(
|
|
7076
7265
|
"/login",
|
|
7077
|
-
|
|
7266
|
+
chunkZBDDZYA3_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "login" }),
|
|
7078
7267
|
async (c) => {
|
|
7079
7268
|
try {
|
|
7080
7269
|
const body = await c.req.json();
|
|
@@ -7084,7 +7273,7 @@ authRoutes.post(
|
|
|
7084
7273
|
}
|
|
7085
7274
|
const { email, password } = validation.data;
|
|
7086
7275
|
const normalizedEmail = email.toLowerCase();
|
|
7087
|
-
const { createAuth } = await import('./config-
|
|
7276
|
+
const { createAuth } = await import('./config-YCRSU7ZP.cjs');
|
|
7088
7277
|
const auth = createAuth(c.env);
|
|
7089
7278
|
const baReq = new Request(new URL("/auth/sign-in/email", c.req.url).href, {
|
|
7090
7279
|
method: "POST",
|
|
@@ -7106,8 +7295,8 @@ authRoutes.post(
|
|
|
7106
7295
|
await setCsrfCookie(c);
|
|
7107
7296
|
const baBody = await baRes.json();
|
|
7108
7297
|
const user = baBody.user ?? {};
|
|
7109
|
-
const tokenTtl = await
|
|
7110
|
-
const token = await
|
|
7298
|
+
const tokenTtl = await chunkZBDDZYA3_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7299
|
+
const token = await chunkZBDDZYA3_cjs.AuthManager.generateToken(
|
|
7111
7300
|
user.id,
|
|
7112
7301
|
user.email,
|
|
7113
7302
|
user.role ?? "viewer",
|
|
@@ -7138,7 +7327,7 @@ authRoutes.post(
|
|
|
7138
7327
|
);
|
|
7139
7328
|
authRoutes.post("/logout", async (c) => {
|
|
7140
7329
|
try {
|
|
7141
|
-
const { createAuth } = await import('./config-
|
|
7330
|
+
const { createAuth } = await import('./config-YCRSU7ZP.cjs');
|
|
7142
7331
|
const auth = createAuth(c.env);
|
|
7143
7332
|
const baReq = new Request(new URL("/auth/sign-out", c.req.url).href, {
|
|
7144
7333
|
method: "POST",
|
|
@@ -7154,7 +7343,7 @@ authRoutes.post("/logout", async (c) => {
|
|
|
7154
7343
|
});
|
|
7155
7344
|
authRoutes.get("/logout", async (c) => {
|
|
7156
7345
|
try {
|
|
7157
|
-
const { createAuth } = await import('./config-
|
|
7346
|
+
const { createAuth } = await import('./config-YCRSU7ZP.cjs');
|
|
7158
7347
|
const auth = createAuth(c.env);
|
|
7159
7348
|
const baReq = new Request(new URL("/auth/sign-out", c.req.url).href, {
|
|
7160
7349
|
method: "POST",
|
|
@@ -7168,7 +7357,7 @@ authRoutes.get("/logout", async (c) => {
|
|
|
7168
7357
|
clearCsrfCookie(c);
|
|
7169
7358
|
return c.redirect("/auth/login?message=You have been logged out successfully");
|
|
7170
7359
|
});
|
|
7171
|
-
authRoutes.get("/me",
|
|
7360
|
+
authRoutes.get("/me", chunkZBDDZYA3_cjs.requireAuth(), async (c) => {
|
|
7172
7361
|
try {
|
|
7173
7362
|
const user = c.get("user");
|
|
7174
7363
|
if (!user) {
|
|
@@ -7188,7 +7377,7 @@ authRoutes.get("/me", chunkVMBQ6NQB_cjs.requireAuth(), async (c) => {
|
|
|
7188
7377
|
});
|
|
7189
7378
|
authRoutes.post(
|
|
7190
7379
|
"/refresh",
|
|
7191
|
-
|
|
7380
|
+
chunkZBDDZYA3_cjs.rateLimit({ max: 60, windowMs: 60 * 1e3, keyPrefix: "refresh" }),
|
|
7192
7381
|
async (c) => {
|
|
7193
7382
|
try {
|
|
7194
7383
|
let token = c.req.header("Authorization")?.replace("Bearer ", "");
|
|
@@ -7197,8 +7386,8 @@ authRoutes.post(
|
|
|
7197
7386
|
return c.json({ error: "Authentication required" }, 401);
|
|
7198
7387
|
}
|
|
7199
7388
|
const db = c.env.DB;
|
|
7200
|
-
const grace = await
|
|
7201
|
-
const payload = await
|
|
7389
|
+
const grace = await chunkZBDDZYA3_cjs.getJwtRefreshGraceSecondsFromDb(db, c.env);
|
|
7390
|
+
const payload = await chunkZBDDZYA3_cjs.AuthManager.verifyToken(token, c.env.JWT_SECRET, grace);
|
|
7202
7391
|
if (!payload) {
|
|
7203
7392
|
return c.json({ error: "Invalid or expired token" }, 401);
|
|
7204
7393
|
}
|
|
@@ -7206,8 +7395,8 @@ authRoutes.post(
|
|
|
7206
7395
|
if (!row || !row.is_active) {
|
|
7207
7396
|
return c.json({ error: "User is not active" }, 401);
|
|
7208
7397
|
}
|
|
7209
|
-
const tokenTtl = await
|
|
7210
|
-
const newToken = await
|
|
7398
|
+
const tokenTtl = await chunkZBDDZYA3_cjs.getJwtExpirySecondsFromDb(db, c.env);
|
|
7399
|
+
const newToken = await chunkZBDDZYA3_cjs.AuthManager.generateToken(row.id, row.email, row.role, c.env.JWT_SECRET, tokenTtl);
|
|
7211
7400
|
cookie.setCookie(c, "auth_token", newToken, {
|
|
7212
7401
|
httpOnly: true,
|
|
7213
7402
|
secure: true,
|
|
@@ -7227,13 +7416,13 @@ authRoutes.post(
|
|
|
7227
7416
|
);
|
|
7228
7417
|
authRoutes.post(
|
|
7229
7418
|
"/register/form",
|
|
7230
|
-
|
|
7419
|
+
chunkZBDDZYA3_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "register" }),
|
|
7231
7420
|
async (c) => {
|
|
7232
7421
|
try {
|
|
7233
7422
|
const db = c.env.DB;
|
|
7234
|
-
const isFirstUser = await
|
|
7423
|
+
const isFirstUser = await chunkXWVDSM2L_cjs.isFirstUserRegistration(db);
|
|
7235
7424
|
if (!isFirstUser) {
|
|
7236
|
-
const registrationEnabled = await
|
|
7425
|
+
const registrationEnabled = await chunkXWVDSM2L_cjs.isRegistrationEnabled(db);
|
|
7237
7426
|
if (!registrationEnabled) {
|
|
7238
7427
|
return c.html(html.html`
|
|
7239
7428
|
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded">
|
|
@@ -7251,7 +7440,7 @@ authRoutes.post(
|
|
|
7251
7440
|
};
|
|
7252
7441
|
const normalizedEmail = requestData.email?.toLowerCase();
|
|
7253
7442
|
requestData.email = normalizedEmail;
|
|
7254
|
-
const validationSchema = await
|
|
7443
|
+
const validationSchema = await chunkXWVDSM2L_cjs.authValidationService.buildRegistrationSchema(db);
|
|
7255
7444
|
const validation = await validationSchema.safeParseAsync(requestData);
|
|
7256
7445
|
if (!validation.success) {
|
|
7257
7446
|
return c.html(html.html`
|
|
@@ -7262,8 +7451,8 @@ authRoutes.post(
|
|
|
7262
7451
|
}
|
|
7263
7452
|
const validatedData = validation.data;
|
|
7264
7453
|
const password = validatedData.password;
|
|
7265
|
-
const firstName = validatedData.firstName ||
|
|
7266
|
-
const lastName = validatedData.lastName ||
|
|
7454
|
+
const firstName = validatedData.firstName || chunkXWVDSM2L_cjs.authValidationService.generateDefaultValue("firstName", validatedData);
|
|
7455
|
+
const lastName = validatedData.lastName || chunkXWVDSM2L_cjs.authValidationService.generateDefaultValue("lastName", validatedData);
|
|
7267
7456
|
const existingUser = await db.prepare("SELECT id FROM auth_user WHERE email = ?").bind(normalizedEmail).first();
|
|
7268
7457
|
if (existingUser) {
|
|
7269
7458
|
return c.html(html.html`
|
|
@@ -7272,7 +7461,7 @@ authRoutes.post(
|
|
|
7272
7461
|
</div>
|
|
7273
7462
|
`);
|
|
7274
7463
|
}
|
|
7275
|
-
const passwordHash = await
|
|
7464
|
+
const passwordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(password);
|
|
7276
7465
|
const role = isFirstUser ? "admin" : "viewer";
|
|
7277
7466
|
const userId = crypto.randomUUID();
|
|
7278
7467
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -7306,7 +7495,7 @@ authRoutes.post(
|
|
|
7306
7495
|
await saveCustomData(db, userId, sanitized);
|
|
7307
7496
|
}
|
|
7308
7497
|
}
|
|
7309
|
-
const rbacService = new
|
|
7498
|
+
const rbacService = new chunkW36OZTJ5_cjs.RbacService(db);
|
|
7310
7499
|
await rbacService.addUserRoleByName(userId, role);
|
|
7311
7500
|
dispatchHookEvent(
|
|
7312
7501
|
c,
|
|
@@ -7314,8 +7503,8 @@ authRoutes.post(
|
|
|
7314
7503
|
{ user: { id: userId, email: normalizedEmail, role } },
|
|
7315
7504
|
"fire-and-forget"
|
|
7316
7505
|
);
|
|
7317
|
-
const tokenTtl = await
|
|
7318
|
-
const token = await
|
|
7506
|
+
const tokenTtl = await chunkZBDDZYA3_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7507
|
+
const token = await chunkZBDDZYA3_cjs.AuthManager.generateToken(userId, normalizedEmail, role, c.env.JWT_SECRET, tokenTtl);
|
|
7319
7508
|
cookie.setCookie(c, "auth_token", token, {
|
|
7320
7509
|
httpOnly: true,
|
|
7321
7510
|
secure: false,
|
|
@@ -7347,7 +7536,7 @@ authRoutes.post(
|
|
|
7347
7536
|
);
|
|
7348
7537
|
authRoutes.post(
|
|
7349
7538
|
"/login/form",
|
|
7350
|
-
|
|
7539
|
+
chunkZBDDZYA3_cjs.rateLimit({ max: 30, windowMs: 60 * 1e3, keyPrefix: "login" }),
|
|
7351
7540
|
async (c) => {
|
|
7352
7541
|
try {
|
|
7353
7542
|
const formData = await c.req.formData();
|
|
@@ -7361,7 +7550,7 @@ authRoutes.post(
|
|
|
7361
7550
|
</div>
|
|
7362
7551
|
`);
|
|
7363
7552
|
}
|
|
7364
|
-
const { createAuth } = await import('./config-
|
|
7553
|
+
const { createAuth } = await import('./config-YCRSU7ZP.cjs');
|
|
7365
7554
|
const auth = createAuth(c.env);
|
|
7366
7555
|
const baReq = new Request(new URL("/auth/sign-in/email", c.req.url).href, {
|
|
7367
7556
|
method: "POST",
|
|
@@ -7385,6 +7574,8 @@ authRoutes.post(
|
|
|
7385
7574
|
}
|
|
7386
7575
|
}
|
|
7387
7576
|
await setCsrfCookie(c);
|
|
7577
|
+
const rawRedirect = c.req.query("redirect");
|
|
7578
|
+
const redirectUrl = rawRedirect && rawRedirect.startsWith("/") ? rawRedirect : "/admin/content";
|
|
7388
7579
|
return c.html(html.html`
|
|
7389
7580
|
<div id="form-response">
|
|
7390
7581
|
<div class="rounded-lg bg-green-100 dark:bg-lime-500/10 p-4 ring-1 ring-green-400 dark:ring-lime-500/20">
|
|
@@ -7397,7 +7588,7 @@ authRoutes.post(
|
|
|
7397
7588
|
</div>
|
|
7398
7589
|
</div>
|
|
7399
7590
|
<script>
|
|
7400
|
-
setTimeout(() => { window.location.href = '
|
|
7591
|
+
setTimeout(() => { window.location.href = '${redirectUrl}'; }, 500);
|
|
7401
7592
|
</script>
|
|
7402
7593
|
</div>
|
|
7403
7594
|
</div>
|
|
@@ -7414,14 +7605,14 @@ authRoutes.post(
|
|
|
7414
7605
|
);
|
|
7415
7606
|
authRoutes.post(
|
|
7416
7607
|
"/seed-admin",
|
|
7417
|
-
|
|
7608
|
+
chunkZBDDZYA3_cjs.rateLimit({ max: 10, windowMs: 60 * 1e3, keyPrefix: "seed-admin" }),
|
|
7418
7609
|
async (c) => {
|
|
7419
7610
|
try {
|
|
7420
7611
|
const db = c.env.DB;
|
|
7421
|
-
const rbac = new
|
|
7612
|
+
const rbac = new chunkW36OZTJ5_cjs.RbacService(db);
|
|
7422
7613
|
const results = [];
|
|
7423
7614
|
const upsertSeedUser = async (opts) => {
|
|
7424
|
-
const passwordHash = await
|
|
7615
|
+
const passwordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(opts.password);
|
|
7425
7616
|
const nowMs = Date.now();
|
|
7426
7617
|
const nowSec = Math.floor(nowMs / 1e3);
|
|
7427
7618
|
const existing = await db.prepare("SELECT id FROM auth_user WHERE email = ?").bind(opts.email).first();
|
|
@@ -7646,7 +7837,7 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7646
7837
|
if (invitationAge > maxAge) {
|
|
7647
7838
|
return c.json({ error: "Invitation has expired" }, 400);
|
|
7648
7839
|
}
|
|
7649
|
-
const passwordHash = await
|
|
7840
|
+
const passwordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(password);
|
|
7650
7841
|
const updateStmt = db.prepare(`
|
|
7651
7842
|
UPDATE auth_user SET
|
|
7652
7843
|
password_hash = ?,
|
|
@@ -7663,8 +7854,8 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7663
7854
|
Date.now(),
|
|
7664
7855
|
invitedUser.id
|
|
7665
7856
|
).run();
|
|
7666
|
-
const tokenTtl = await
|
|
7667
|
-
const authToken = await
|
|
7857
|
+
const tokenTtl = await chunkZBDDZYA3_cjs.getJwtExpirySecondsFromDb(c.env.DB, c.env);
|
|
7858
|
+
const authToken = await chunkZBDDZYA3_cjs.AuthManager.generateToken(invitedUser.id, invitedUser.email, invitedUser.role, c.env.JWT_SECRET, tokenTtl);
|
|
7668
7859
|
cookie.setCookie(c, "auth_token", authToken, {
|
|
7669
7860
|
httpOnly: true,
|
|
7670
7861
|
secure: true,
|
|
@@ -7680,7 +7871,7 @@ authRoutes.post("/accept-invitation", async (c) => {
|
|
|
7680
7871
|
});
|
|
7681
7872
|
authRoutes.post(
|
|
7682
7873
|
"/request-password-reset",
|
|
7683
|
-
|
|
7874
|
+
chunkZBDDZYA3_cjs.rateLimit({ max: 3, windowMs: 15 * 60 * 1e3, keyPrefix: "password-reset" }),
|
|
7684
7875
|
async (c) => {
|
|
7685
7876
|
try {
|
|
7686
7877
|
const formData = await c.req.formData();
|
|
@@ -7917,7 +8108,7 @@ authRoutes.post("/reset-password", async (c) => {
|
|
|
7917
8108
|
if (Date.now() > user.password_reset_expires) {
|
|
7918
8109
|
return c.json({ error: "Reset token has expired" }, 400);
|
|
7919
8110
|
}
|
|
7920
|
-
const newPasswordHash = await
|
|
8111
|
+
const newPasswordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(password);
|
|
7921
8112
|
try {
|
|
7922
8113
|
const historyStmt = db.prepare(`
|
|
7923
8114
|
INSERT INTO auth_password_history (id, user_id, password_hash, created_at)
|
|
@@ -8131,7 +8322,7 @@ app.post("/test-seed-defaults", async (c) => {
|
|
|
8131
8322
|
var test_cleanup_default = app;
|
|
8132
8323
|
|
|
8133
8324
|
// src/plugins/available/easy-mdx/index.ts
|
|
8134
|
-
|
|
8325
|
+
chunkPTTFLUEX_cjs.definePlugin({
|
|
8135
8326
|
id: "easy-mdx",
|
|
8136
8327
|
version: "1.0.0",
|
|
8137
8328
|
name: "EasyMDE Markdown Editor",
|
|
@@ -8331,7 +8522,7 @@ function getMDXEditorInitScript(config) {
|
|
|
8331
8522
|
}
|
|
8332
8523
|
|
|
8333
8524
|
// src/plugins/available/tinymce-plugin/index.ts
|
|
8334
|
-
|
|
8525
|
+
chunkPTTFLUEX_cjs.definePlugin({
|
|
8335
8526
|
id: "tinymce-plugin",
|
|
8336
8527
|
version: "1.0.0",
|
|
8337
8528
|
name: "TinyMCE",
|
|
@@ -8601,7 +8792,7 @@ function getQuillCDN(version = "2.0.2") {
|
|
|
8601
8792
|
</style>
|
|
8602
8793
|
`;
|
|
8603
8794
|
}
|
|
8604
|
-
|
|
8795
|
+
chunkPTTFLUEX_cjs.definePlugin({
|
|
8605
8796
|
id: "quill-editor",
|
|
8606
8797
|
version: "1.0.0",
|
|
8607
8798
|
name: "Quill Editor",
|
|
@@ -11175,7 +11366,7 @@ function extractFieldData(fields, formData, options = {}) {
|
|
|
11175
11366
|
}
|
|
11176
11367
|
return { data, errors };
|
|
11177
11368
|
}
|
|
11178
|
-
adminContentRoutes.use("*",
|
|
11369
|
+
adminContentRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
11179
11370
|
async function getCollectionFields(db, collectionId) {
|
|
11180
11371
|
console.log(`[getCollectionFields] Loading fields for collection: ${collectionId}`);
|
|
11181
11372
|
const collectionStmt = db.prepare("SELECT schema, queryable_fields FROM document_types WHERE id = ?");
|
|
@@ -11202,7 +11393,7 @@ async function getCollectionFields(db, collectionId) {
|
|
|
11202
11393
|
};
|
|
11203
11394
|
});
|
|
11204
11395
|
}
|
|
11205
|
-
const codeCollections2 = await
|
|
11396
|
+
const codeCollections2 = await chunkFXZSZ7C7_cjs.loadCollectionConfigs();
|
|
11206
11397
|
const codeMatch = codeCollections2.find((c) => c.name === collectionId);
|
|
11207
11398
|
if (codeMatch && codeMatch.schema?.properties) {
|
|
11208
11399
|
console.log(`[getCollectionFields] DB doc type has no properties \u2014 using code collection schema`);
|
|
@@ -11234,7 +11425,7 @@ async function getCollectionFields(db, collectionId) {
|
|
|
11234
11425
|
}
|
|
11235
11426
|
}
|
|
11236
11427
|
console.log(`[getCollectionFields] Not in database, checking code collections`);
|
|
11237
|
-
const codeCollections = await
|
|
11428
|
+
const codeCollections = await chunkFXZSZ7C7_cjs.loadCollectionConfigs();
|
|
11238
11429
|
console.log(`[getCollectionFields] Found ${codeCollections.length} code collections`);
|
|
11239
11430
|
const codeCollection = codeCollections.find((c) => c.name === collectionId);
|
|
11240
11431
|
if (codeCollection && codeCollection.schema) {
|
|
@@ -11288,7 +11479,7 @@ async function getCollection(db, collectionId) {
|
|
|
11288
11479
|
};
|
|
11289
11480
|
}
|
|
11290
11481
|
console.log(`[getCollection] Not in database, checking code collections`);
|
|
11291
|
-
const codeCollections = await
|
|
11482
|
+
const codeCollections = await chunkFXZSZ7C7_cjs.loadCollectionConfigs();
|
|
11292
11483
|
const codeCollection = codeCollections.find((c) => c.name === collectionId);
|
|
11293
11484
|
if (codeCollection) {
|
|
11294
11485
|
console.log(`[getCollection] Found code collection: ${collectionId}`);
|
|
@@ -11307,7 +11498,7 @@ async function getCollection(db, collectionId) {
|
|
|
11307
11498
|
}
|
|
11308
11499
|
async function getDocBackingType(db, collectionName) {
|
|
11309
11500
|
if (!collectionName) return null;
|
|
11310
|
-
const dt = await new
|
|
11501
|
+
const dt = await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db).findById(collectionName);
|
|
11311
11502
|
return dt && dt.isActive ? dt : null;
|
|
11312
11503
|
}
|
|
11313
11504
|
async function getCollectionByName(db, name) {
|
|
@@ -11324,7 +11515,7 @@ async function getCollectionByName(db, name) {
|
|
|
11324
11515
|
};
|
|
11325
11516
|
}
|
|
11326
11517
|
console.log(`[getCollectionByName] Not in database, checking code collections`);
|
|
11327
|
-
const codeCollections = await
|
|
11518
|
+
const codeCollections = await chunkFXZSZ7C7_cjs.loadCollectionConfigs();
|
|
11328
11519
|
const codeCollection = codeCollections.find((c) => c.name === name);
|
|
11329
11520
|
if (codeCollection) {
|
|
11330
11521
|
console.log(`[getCollectionByName] Found code collection: ${name}`);
|
|
@@ -11340,7 +11531,7 @@ async function getCollectionByName(db, name) {
|
|
|
11340
11531
|
return null;
|
|
11341
11532
|
}
|
|
11342
11533
|
async function loadContentEditorFlags(db) {
|
|
11343
|
-
const flags = { workflowEnabled: await
|
|
11534
|
+
const flags = { workflowEnabled: await chunkZBDDZYA3_cjs.isPluginActive(db, "workflow") };
|
|
11344
11535
|
const editors = [
|
|
11345
11536
|
["tinymce-plugin", "tinymce"],
|
|
11346
11537
|
["quill-editor", "quill"],
|
|
@@ -11348,10 +11539,10 @@ async function loadContentEditorFlags(db) {
|
|
|
11348
11539
|
["lexical-editor", "lexical"]
|
|
11349
11540
|
];
|
|
11350
11541
|
for (const [plugin, key] of editors) {
|
|
11351
|
-
const enabled = await
|
|
11542
|
+
const enabled = await chunkZBDDZYA3_cjs.isPluginActive(db, plugin);
|
|
11352
11543
|
flags[`${key}Enabled`] = enabled;
|
|
11353
11544
|
if (enabled) {
|
|
11354
|
-
const ps = new
|
|
11545
|
+
const ps = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11355
11546
|
const p = await ps.getPlugin(plugin);
|
|
11356
11547
|
flags[`${key}Settings`] = p?.settings;
|
|
11357
11548
|
}
|
|
@@ -11359,7 +11550,7 @@ async function loadContentEditorFlags(db) {
|
|
|
11359
11550
|
return flags;
|
|
11360
11551
|
}
|
|
11361
11552
|
function makeDocService(db, docType, tenantId) {
|
|
11362
|
-
return new
|
|
11553
|
+
return new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
11363
11554
|
queryableFields: docType.queryableFields ?? [],
|
|
11364
11555
|
typeSchemaVersion: docType.schemaVersion ?? 1,
|
|
11365
11556
|
maxVersionsPerRoot: docType.settings?.maxVersionsPerRoot ?? 50,
|
|
@@ -11387,9 +11578,9 @@ adminContentRoutes.get("/", async (c) => {
|
|
|
11387
11578
|
const offset = (page - 1) * limit;
|
|
11388
11579
|
const collectionsStmt = db.prepare("SELECT id, name, display_name FROM document_types WHERE is_active = 1 ORDER BY display_name");
|
|
11389
11580
|
const { results: collectionsResults } = await collectionsStmt.all();
|
|
11390
|
-
const codeCollections = await
|
|
11581
|
+
const codeCollections = await chunkFXZSZ7C7_cjs.loadCollectionConfigs();
|
|
11391
11582
|
const codeCollectionMap = new Map(codeCollections.map((c2) => [c2.name, c2]));
|
|
11392
|
-
const docTypeRegistry = new
|
|
11583
|
+
const docTypeRegistry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
11393
11584
|
const docTypes = (await docTypeRegistry.findAll()).filter((dt) => !dt.settings?.internal && !dt.isAuth);
|
|
11394
11585
|
const visibleTypeIds = new Set(docTypes.map((dt) => dt.id));
|
|
11395
11586
|
const allCollections = [
|
|
@@ -11401,7 +11592,7 @@ adminContentRoutes.get("/", async (c) => {
|
|
|
11401
11592
|
...allCollections.map((c2) => ({ name: c2.name, displayName: c2.displayName })),
|
|
11402
11593
|
...docTypes.filter((dt) => !collectionNames.has(dt.id)).map((dt) => ({ name: `doc:${dt.id}`, displayName: dt.displayName }))
|
|
11403
11594
|
];
|
|
11404
|
-
const newContentCollections = await
|
|
11595
|
+
const newContentCollections = await chunkFXZSZ7C7_cjs.getVisibleCollections(db);
|
|
11405
11596
|
const docBackedCollection = !modelName.startsWith("doc:") && modelName !== "all" ? docTypes.find((dt) => dt.id === modelName) : void 0;
|
|
11406
11597
|
const isDocModel = modelName.startsWith("doc:") || !!docBackedCollection;
|
|
11407
11598
|
if (isDocModel) {
|
|
@@ -11678,9 +11869,9 @@ adminContentRoutes.get("/new", async (c) => {
|
|
|
11678
11869
|
const collectionsStmt = db2.prepare("SELECT id, name, display_name, description FROM document_types WHERE is_active = 1 ORDER BY display_name");
|
|
11679
11870
|
const { results } = await collectionsStmt.all();
|
|
11680
11871
|
const visibleTypeIds = new Set(
|
|
11681
|
-
(await new
|
|
11872
|
+
(await new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db2).findAll()).filter((dt) => !dt.settings?.internal && !dt.isAuth).map((dt) => dt.id)
|
|
11682
11873
|
);
|
|
11683
|
-
const codeCollections = await
|
|
11874
|
+
const codeCollections = await chunkFXZSZ7C7_cjs.loadCollectionConfigs();
|
|
11684
11875
|
const dbCollectionNames = new Set((results || []).map((r) => r.name));
|
|
11685
11876
|
const allCollections = [
|
|
11686
11877
|
...codeCollections.filter((c2) => !dbCollectionNames.has(c2.name)).map((c2) => ({
|
|
@@ -11746,32 +11937,32 @@ adminContentRoutes.get("/new", async (c) => {
|
|
|
11746
11937
|
return c.html(renderContentFormPage(formData2));
|
|
11747
11938
|
}
|
|
11748
11939
|
const fields = await getCollectionFields(db, collection.id);
|
|
11749
|
-
const workflowEnabled = await
|
|
11750
|
-
const tinymceEnabled = await
|
|
11940
|
+
const workflowEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "workflow");
|
|
11941
|
+
const tinymceEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "tinymce-plugin");
|
|
11751
11942
|
let tinymceSettings;
|
|
11752
11943
|
if (tinymceEnabled) {
|
|
11753
|
-
const pluginService = new
|
|
11944
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11754
11945
|
const tinymcePlugin2 = await pluginService.getPlugin("tinymce-plugin");
|
|
11755
11946
|
tinymceSettings = tinymcePlugin2?.settings;
|
|
11756
11947
|
}
|
|
11757
|
-
const quillEnabled = await
|
|
11948
|
+
const quillEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "quill-editor");
|
|
11758
11949
|
let quillSettings;
|
|
11759
11950
|
if (quillEnabled) {
|
|
11760
|
-
const pluginService = new
|
|
11951
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11761
11952
|
const quillPlugin = await pluginService.getPlugin("quill-editor");
|
|
11762
11953
|
quillSettings = quillPlugin?.settings;
|
|
11763
11954
|
}
|
|
11764
|
-
const mdxeditorEnabled = await
|
|
11955
|
+
const mdxeditorEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "easy-mdx");
|
|
11765
11956
|
let mdxeditorSettings;
|
|
11766
11957
|
if (mdxeditorEnabled) {
|
|
11767
|
-
const pluginService = new
|
|
11958
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11768
11959
|
const mdxeditorPlugin = await pluginService.getPlugin("easy-mdx");
|
|
11769
11960
|
mdxeditorSettings = mdxeditorPlugin?.settings;
|
|
11770
11961
|
}
|
|
11771
|
-
const lexicalEnabled = await
|
|
11962
|
+
const lexicalEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "lexical-editor");
|
|
11772
11963
|
let lexicalSettings;
|
|
11773
11964
|
if (lexicalEnabled) {
|
|
11774
|
-
const pluginService = new
|
|
11965
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11775
11966
|
const lexicalPlugin = await pluginService.getPlugin("lexical-editor");
|
|
11776
11967
|
lexicalSettings = lexicalPlugin?.settings;
|
|
11777
11968
|
}
|
|
@@ -11899,32 +12090,32 @@ adminContentRoutes.get("/:id/edit", async (c) => {
|
|
|
11899
12090
|
};
|
|
11900
12091
|
const fields = await getCollectionFields(db, content.collection_id);
|
|
11901
12092
|
const contentData = content.data ? JSON.parse(content.data) : {};
|
|
11902
|
-
const workflowEnabled = await
|
|
11903
|
-
const tinymceEnabled = await
|
|
12093
|
+
const workflowEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "workflow");
|
|
12094
|
+
const tinymceEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "tinymce-plugin");
|
|
11904
12095
|
let tinymceSettings;
|
|
11905
12096
|
if (tinymceEnabled) {
|
|
11906
|
-
const pluginService = new
|
|
12097
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11907
12098
|
const tinymcePlugin2 = await pluginService.getPlugin("tinymce-plugin");
|
|
11908
12099
|
tinymceSettings = tinymcePlugin2?.settings;
|
|
11909
12100
|
}
|
|
11910
|
-
const quillEnabled = await
|
|
12101
|
+
const quillEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "quill-editor");
|
|
11911
12102
|
let quillSettings;
|
|
11912
12103
|
if (quillEnabled) {
|
|
11913
|
-
const pluginService = new
|
|
12104
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11914
12105
|
const quillPlugin = await pluginService.getPlugin("quill-editor");
|
|
11915
12106
|
quillSettings = quillPlugin?.settings;
|
|
11916
12107
|
}
|
|
11917
|
-
const mdxeditorEnabled = await
|
|
12108
|
+
const mdxeditorEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "easy-mdx");
|
|
11918
12109
|
let mdxeditorSettings;
|
|
11919
12110
|
if (mdxeditorEnabled) {
|
|
11920
|
-
const pluginService = new
|
|
12111
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11921
12112
|
const mdxeditorPlugin = await pluginService.getPlugin("easy-mdx");
|
|
11922
12113
|
mdxeditorSettings = mdxeditorPlugin?.settings;
|
|
11923
12114
|
}
|
|
11924
|
-
const lexicalEnabled = await
|
|
12115
|
+
const lexicalEnabled = await chunkZBDDZYA3_cjs.isPluginActive(db, "lexical-editor");
|
|
11925
12116
|
let lexicalSettings;
|
|
11926
12117
|
if (lexicalEnabled) {
|
|
11927
|
-
const pluginService = new
|
|
12118
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
11928
12119
|
const lexicalPlugin = await pluginService.getPlugin("lexical-editor");
|
|
11929
12120
|
lexicalSettings = lexicalPlugin?.settings;
|
|
11930
12121
|
}
|
|
@@ -12297,7 +12488,7 @@ adminContentRoutes.put("/:id", async (c) => {
|
|
|
12297
12488
|
`);
|
|
12298
12489
|
}
|
|
12299
12490
|
});
|
|
12300
|
-
adminContentRoutes.post("/preview",
|
|
12491
|
+
adminContentRoutes.post("/preview", chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
12301
12492
|
try {
|
|
12302
12493
|
const formData = await c.req.formData();
|
|
12303
12494
|
const collectionId = formData.get("collection_id");
|
|
@@ -12616,7 +12807,7 @@ adminContentRoutes.delete("/:id", async (c) => {
|
|
|
12616
12807
|
return c.json({ success: false, error: "Failed to delete content" }, 500);
|
|
12617
12808
|
}
|
|
12618
12809
|
});
|
|
12619
|
-
adminContentRoutes.get("/:id/version/:version/preview",
|
|
12810
|
+
adminContentRoutes.get("/:id/version/:version/preview", chunkZBDDZYA3_cjs.requireRole(["admin", "editor", "author"]), async (c) => {
|
|
12620
12811
|
try {
|
|
12621
12812
|
const id = c.req.param("id");
|
|
12622
12813
|
const version = parseInt(c.req.param("version") || "0");
|
|
@@ -12712,9 +12903,9 @@ function parseDocFormData(formData, queryableFields = []) {
|
|
|
12712
12903
|
return { title, slug, data };
|
|
12713
12904
|
}
|
|
12714
12905
|
async function getDocService(db, typeId, tenantId) {
|
|
12715
|
-
const registry = new
|
|
12906
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
12716
12907
|
const docType = await registry.findById(typeId);
|
|
12717
|
-
const svc = new
|
|
12908
|
+
const svc = new chunkW36OZTJ5_cjs.DocumentsService(db, {
|
|
12718
12909
|
queryableFields: docType?.queryableFields ?? [],
|
|
12719
12910
|
typeSchemaVersion: docType?.schemaVersion ?? 1,
|
|
12720
12911
|
maxVersionsPerRoot: docType?.settings?.maxVersionsPerRoot ?? 50,
|
|
@@ -12725,7 +12916,7 @@ async function getDocService(db, typeId, tenantId) {
|
|
|
12725
12916
|
}
|
|
12726
12917
|
adminContentRoutes.get("/documents/:typeId/new", async (c) => {
|
|
12727
12918
|
const { typeId } = c.req.param();
|
|
12728
|
-
const registry = new
|
|
12919
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(c.env.DB);
|
|
12729
12920
|
const docType = await registry.findById(typeId);
|
|
12730
12921
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12731
12922
|
return c.html(chunkN32OWET6_cjs.renderDocumentFormPage({ docType, isEdit: false, user: userCtx(c) }));
|
|
@@ -12750,7 +12941,7 @@ adminContentRoutes.post("/documents/:typeId/new", async (c) => {
|
|
|
12750
12941
|
}), user?.userId);
|
|
12751
12942
|
return c.redirect(`/admin/content/documents/${typeId}/${doc.rootId}/edit?message=Created+successfully`);
|
|
12752
12943
|
} catch (err) {
|
|
12753
|
-
const registry = new
|
|
12944
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(c.env.DB);
|
|
12754
12945
|
const docType = await registry.findById(typeId);
|
|
12755
12946
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12756
12947
|
return c.html(chunkN32OWET6_cjs.renderDocumentFormPage({ docType, isEdit: false, user: userCtx(c), message: err?.message ?? "Failed to create", messageType: "error" }));
|
|
@@ -12760,7 +12951,7 @@ adminContentRoutes.get("/documents/:typeId/:rootId/edit", async (c) => {
|
|
|
12760
12951
|
const { typeId, rootId } = c.req.param();
|
|
12761
12952
|
const db = c.env.DB;
|
|
12762
12953
|
const message = c.req.query("message");
|
|
12763
|
-
const registry = new
|
|
12954
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
12764
12955
|
const docType = await registry.findById(typeId);
|
|
12765
12956
|
if (!docType) return c.html("<p>Unknown document type.</p>", 404);
|
|
12766
12957
|
const tenantId = reqTenant(c);
|
|
@@ -12873,7 +13064,7 @@ adminContentRoutes.get("/documents/:typeId/:rootId/versions", async (c) => {
|
|
|
12873
13064
|
const { typeId, rootId } = c.req.param();
|
|
12874
13065
|
const db = c.env.DB;
|
|
12875
13066
|
const { renderVersionHistoryFragment } = await import('./admin-documents-form.template-LSZKGA5J.cjs');
|
|
12876
|
-
const registry = new
|
|
13067
|
+
const registry = new chunkZBDDZYA3_cjs.DocumentTypeRegistry(db);
|
|
12877
13068
|
const docType = await registry.findById(typeId);
|
|
12878
13069
|
if (!docType) return c.html("<div>Unknown type.</div>", 404);
|
|
12879
13070
|
const result = await db.prepare(
|
|
@@ -14805,7 +14996,7 @@ var TenantService = class {
|
|
|
14805
14996
|
SET name = ?, domain = ?, status = ?, notes = ?, updated_at = ?
|
|
14806
14997
|
WHERE slug = ?
|
|
14807
14998
|
`).bind(name, domain, status, notes, now, slug).run();
|
|
14808
|
-
|
|
14999
|
+
chunkFXZSZ7C7_cjs.invalidateTenantCache();
|
|
14809
15000
|
const updated = await this.getTenantBySlug(slug);
|
|
14810
15001
|
if (!updated) throw new Error("Tenant not found");
|
|
14811
15002
|
return updated;
|
|
@@ -14823,7 +15014,7 @@ var TenantService = class {
|
|
|
14823
15014
|
throw new Error(`Tenant '${slug}' still owns ${docCount} document(s). Delete or migrate its content first.`);
|
|
14824
15015
|
}
|
|
14825
15016
|
await this.db.prepare(`DELETE FROM auth_tenant WHERE slug = ?`).bind(slug).run();
|
|
14826
|
-
|
|
15017
|
+
chunkFXZSZ7C7_cjs.invalidateTenantCache();
|
|
14827
15018
|
}
|
|
14828
15019
|
// ─── Membership (auth_tenant_member) ───────────────────────────────────────
|
|
14829
15020
|
// Tenant resolution and the admin switcher are gated on membership: an authed user may only
|
|
@@ -15067,7 +15258,7 @@ var TenantService = class {
|
|
|
15067
15258
|
INSERT INTO auth_tenant (id, name, slug, status, domain, notes, metadata, created_at, updated_at)
|
|
15068
15259
|
VALUES (?, ?, ?, 'active', ?, ?, '{}', ?, ?)
|
|
15069
15260
|
`).bind(id, input.name, input.slug, input.domain, input.notes, now, now).run();
|
|
15070
|
-
|
|
15261
|
+
chunkFXZSZ7C7_cjs.invalidateTenantCache();
|
|
15071
15262
|
const created = await this.getTenantBySlug(input.slug);
|
|
15072
15263
|
if (!created) throw new Error("Failed to create tenant");
|
|
15073
15264
|
return created;
|
|
@@ -15091,14 +15282,14 @@ function mapRowToTenant(row) {
|
|
|
15091
15282
|
|
|
15092
15283
|
// src/routes/admin-users.ts
|
|
15093
15284
|
var userRoutes = new hono.Hono();
|
|
15094
|
-
userRoutes.use("*",
|
|
15095
|
-
userRoutes.use("/users/*",
|
|
15096
|
-
userRoutes.use("/users",
|
|
15097
|
-
userRoutes.use("/invite-user",
|
|
15098
|
-
userRoutes.use("/resend-invitation/*",
|
|
15099
|
-
userRoutes.use("/cancel-invitation/*",
|
|
15100
|
-
userRoutes.use("/activity-logs",
|
|
15101
|
-
userRoutes.use("/activity-logs/*",
|
|
15285
|
+
userRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
15286
|
+
userRoutes.use("/users/*", chunkZBDDZYA3_cjs.requireRole(["admin"]));
|
|
15287
|
+
userRoutes.use("/users", chunkZBDDZYA3_cjs.requireRole(["admin"]));
|
|
15288
|
+
userRoutes.use("/invite-user", chunkZBDDZYA3_cjs.requireRole(["admin"]));
|
|
15289
|
+
userRoutes.use("/resend-invitation/*", chunkZBDDZYA3_cjs.requireRole(["admin"]));
|
|
15290
|
+
userRoutes.use("/cancel-invitation/*", chunkZBDDZYA3_cjs.requireRole(["admin"]));
|
|
15291
|
+
userRoutes.use("/activity-logs", chunkZBDDZYA3_cjs.requireRole(["admin"]));
|
|
15292
|
+
userRoutes.use("/activity-logs/*", chunkZBDDZYA3_cjs.requireRole(["admin"]));
|
|
15102
15293
|
userRoutes.get("/", (c) => {
|
|
15103
15294
|
return c.redirect("/admin/dashboard");
|
|
15104
15295
|
});
|
|
@@ -15265,7 +15456,7 @@ userRoutes.put("/profile", async (c) => {
|
|
|
15265
15456
|
}
|
|
15266
15457
|
await saveCustomData(db, user.userId, sanitized);
|
|
15267
15458
|
}
|
|
15268
|
-
await
|
|
15459
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
15269
15460
|
db,
|
|
15270
15461
|
user.userId,
|
|
15271
15462
|
"profile.update",
|
|
@@ -15328,7 +15519,7 @@ userRoutes.post("/profile/avatar", async (c) => {
|
|
|
15328
15519
|
SELECT first_name, last_name FROM auth_user WHERE id = ?
|
|
15329
15520
|
`);
|
|
15330
15521
|
const userData = await userStmt.bind(user.userId).first();
|
|
15331
|
-
await
|
|
15522
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
15332
15523
|
db,
|
|
15333
15524
|
user.userId,
|
|
15334
15525
|
"profile.avatar_update",
|
|
@@ -15399,7 +15590,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15399
15590
|
dismissible: true
|
|
15400
15591
|
}));
|
|
15401
15592
|
}
|
|
15402
|
-
const validPassword = await
|
|
15593
|
+
const validPassword = await chunkZBDDZYA3_cjs.AuthManager.verifyPassword(currentPassword, userData.password_hash);
|
|
15403
15594
|
if (!validPassword) {
|
|
15404
15595
|
return c.html(chunkN32OWET6_cjs.renderAlert({
|
|
15405
15596
|
type: "error",
|
|
@@ -15407,7 +15598,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15407
15598
|
dismissible: true
|
|
15408
15599
|
}));
|
|
15409
15600
|
}
|
|
15410
|
-
const newPasswordHash = await
|
|
15601
|
+
const newPasswordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(newPassword);
|
|
15411
15602
|
const historyStmt = db.prepare(`
|
|
15412
15603
|
INSERT INTO auth_password_history (id, user_id, password_hash, created_at)
|
|
15413
15604
|
VALUES (?, ?, ?, ?)
|
|
@@ -15423,7 +15614,7 @@ userRoutes.post("/profile/password", async (c) => {
|
|
|
15423
15614
|
WHERE id = ?
|
|
15424
15615
|
`);
|
|
15425
15616
|
await updateStmt.bind(newPasswordHash, Date.now(), user.userId).run();
|
|
15426
|
-
await
|
|
15617
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
15427
15618
|
db,
|
|
15428
15619
|
user.userId,
|
|
15429
15620
|
"profile.password_change",
|
|
@@ -15490,7 +15681,7 @@ userRoutes.get("/users", async (c) => {
|
|
|
15490
15681
|
`);
|
|
15491
15682
|
const countResult = await countStmt.bind(...params).first();
|
|
15492
15683
|
const totalUsers = countResult?.total || 0;
|
|
15493
|
-
await
|
|
15684
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
15494
15685
|
db,
|
|
15495
15686
|
user.userId,
|
|
15496
15687
|
"users.list_view",
|
|
@@ -15671,7 +15862,7 @@ userRoutes.post("/users/new", async (c) => {
|
|
|
15671
15862
|
dismissible: true
|
|
15672
15863
|
}));
|
|
15673
15864
|
}
|
|
15674
|
-
const passwordHash = await
|
|
15865
|
+
const passwordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(password);
|
|
15675
15866
|
const userId = crypto.randomUUID();
|
|
15676
15867
|
const createStmt = db.prepare(`
|
|
15677
15868
|
INSERT INTO auth_user (
|
|
@@ -15696,7 +15887,7 @@ userRoutes.post("/users/new", async (c) => {
|
|
|
15696
15887
|
if (sanitizedRegistrationCustom !== null && Object.keys(sanitizedRegistrationCustom).length > 0) {
|
|
15697
15888
|
await writeProfileData(db, userId, { custom: sanitizedRegistrationCustom }, user.userId);
|
|
15698
15889
|
}
|
|
15699
|
-
await
|
|
15890
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
15700
15891
|
db,
|
|
15701
15892
|
user.userId,
|
|
15702
15893
|
"user!.create",
|
|
@@ -15735,7 +15926,7 @@ userRoutes.get("/users/:id", async (c) => {
|
|
|
15735
15926
|
if (!userRecord) {
|
|
15736
15927
|
return c.json({ error: "User not found" }, 404);
|
|
15737
15928
|
}
|
|
15738
|
-
await
|
|
15929
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
15739
15930
|
db,
|
|
15740
15931
|
user.userId,
|
|
15741
15932
|
"user!.view",
|
|
@@ -15949,7 +16140,7 @@ userRoutes.put("/users/:id", async (c) => {
|
|
|
15949
16140
|
userId
|
|
15950
16141
|
).run();
|
|
15951
16142
|
if (newPassword) {
|
|
15952
|
-
const passwordHash = await
|
|
16143
|
+
const passwordHash = await chunkZBDDZYA3_cjs.AuthManager.hashPassword(newPassword);
|
|
15953
16144
|
const updatePasswordStmt = db.prepare(`
|
|
15954
16145
|
UPDATE auth_user SET password_hash = ?, updated_at = ? WHERE id = ?
|
|
15955
16146
|
`);
|
|
@@ -15962,7 +16153,7 @@ userRoutes.put("/users/:id", async (c) => {
|
|
|
15962
16153
|
...sanitizedCustom !== null ? { custom: sanitizedCustom } : {}
|
|
15963
16154
|
}, user.userId);
|
|
15964
16155
|
}
|
|
15965
|
-
await
|
|
16156
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
15966
16157
|
db,
|
|
15967
16158
|
user.userId,
|
|
15968
16159
|
"user.update",
|
|
@@ -16008,7 +16199,7 @@ userRoutes.post("/users/:id/toggle", async (c) => {
|
|
|
16008
16199
|
UPDATE auth_user SET is_active = ?, updated_at = ? WHERE id = ?
|
|
16009
16200
|
`);
|
|
16010
16201
|
await toggleStmt.bind(active ? 1 : 0, Date.now(), userId).run();
|
|
16011
|
-
await
|
|
16202
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
16012
16203
|
db,
|
|
16013
16204
|
user.userId,
|
|
16014
16205
|
active ? "user.activate" : "user.deactivate",
|
|
@@ -16049,7 +16240,7 @@ userRoutes.delete("/users/:id", async (c) => {
|
|
|
16049
16240
|
DELETE FROM auth_user WHERE id = ?
|
|
16050
16241
|
`);
|
|
16051
16242
|
await deleteStmt.bind(userId).run();
|
|
16052
|
-
await
|
|
16243
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
16053
16244
|
db,
|
|
16054
16245
|
user.userId,
|
|
16055
16246
|
"user!.hard_delete",
|
|
@@ -16068,7 +16259,7 @@ userRoutes.delete("/users/:id", async (c) => {
|
|
|
16068
16259
|
UPDATE auth_user SET is_active = 0, updated_at = ? WHERE id = ?
|
|
16069
16260
|
`);
|
|
16070
16261
|
await deleteStmt.bind(Date.now(), userId).run();
|
|
16071
|
-
await
|
|
16262
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
16072
16263
|
db,
|
|
16073
16264
|
user.userId,
|
|
16074
16265
|
"user!.soft_delete",
|
|
@@ -16134,7 +16325,7 @@ userRoutes.post("/invite-user", async (c) => {
|
|
|
16134
16325
|
Date.now(),
|
|
16135
16326
|
Date.now()
|
|
16136
16327
|
).run();
|
|
16137
|
-
await
|
|
16328
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
16138
16329
|
db,
|
|
16139
16330
|
user.userId,
|
|
16140
16331
|
"user!.invite_sent",
|
|
@@ -16191,7 +16382,7 @@ userRoutes.post("/resend-invitation/:id", async (c) => {
|
|
|
16191
16382
|
Date.now(),
|
|
16192
16383
|
userId
|
|
16193
16384
|
).run();
|
|
16194
|
-
await
|
|
16385
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
16195
16386
|
db,
|
|
16196
16387
|
user.userId,
|
|
16197
16388
|
"user!.invitation_resent",
|
|
@@ -16227,7 +16418,7 @@ userRoutes.delete("/cancel-invitation/:id", async (c) => {
|
|
|
16227
16418
|
}
|
|
16228
16419
|
const deleteStmt = db.prepare(`DELETE FROM auth_user WHERE id = ?`);
|
|
16229
16420
|
await deleteStmt.bind(userId).run();
|
|
16230
|
-
await
|
|
16421
|
+
await chunkZBDDZYA3_cjs.logActivity(
|
|
16231
16422
|
db,
|
|
16232
16423
|
user.userId,
|
|
16233
16424
|
"user!.invitation_cancelled",
|
|
@@ -17608,7 +17799,7 @@ var fileValidationSchema2 = zod.z.object({
|
|
|
17608
17799
|
// 50MB max
|
|
17609
17800
|
});
|
|
17610
17801
|
var adminMediaRoutes = new hono.Hono();
|
|
17611
|
-
adminMediaRoutes.use("*",
|
|
17802
|
+
adminMediaRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
17612
17803
|
adminMediaRoutes.get("/", async (c) => {
|
|
17613
17804
|
try {
|
|
17614
17805
|
const user = c.get("user");
|
|
@@ -17650,7 +17841,7 @@ adminMediaRoutes.get("/selector", async (c) => {
|
|
|
17650
17841
|
const { searchParams } = new URL(c.req.url);
|
|
17651
17842
|
const search = searchParams.get("search") || "";
|
|
17652
17843
|
const db = c.env.DB;
|
|
17653
|
-
const pluginService = new
|
|
17844
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
17654
17845
|
const mediaPlugin = await pluginService.getPlugin("core-media");
|
|
17655
17846
|
if (!mediaPlugin || mediaPlugin.status !== "active") {
|
|
17656
17847
|
return c.html(html.html`
|
|
@@ -18024,7 +18215,7 @@ adminMediaRoutes.put("/:id", async (c) => {
|
|
|
18024
18215
|
`);
|
|
18025
18216
|
}
|
|
18026
18217
|
});
|
|
18027
|
-
adminMediaRoutes.delete("/cleanup",
|
|
18218
|
+
adminMediaRoutes.delete("/cleanup", chunkZBDDZYA3_cjs.requireRole("admin"), async (c) => {
|
|
18028
18219
|
try {
|
|
18029
18220
|
const db = c.env.DB;
|
|
18030
18221
|
const allMediaStmt = db.prepare("SELECT id, r2_key, filename FROM media WHERE deleted_at IS NULL");
|
|
@@ -20457,8 +20648,8 @@ defineUserProfile({
|
|
|
20457
20648
|
|
|
20458
20649
|
// src/routes/admin-plugins.ts
|
|
20459
20650
|
var adminPluginRoutes = new hono.Hono();
|
|
20460
|
-
adminPluginRoutes.use("*",
|
|
20461
|
-
var AVAILABLE_PLUGINS = Object.values(
|
|
20651
|
+
adminPluginRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
20652
|
+
var AVAILABLE_PLUGINS = Object.values(chunkFXZSZ7C7_cjs.PLUGIN_REGISTRY).map((p) => ({
|
|
20462
20653
|
id: p.id,
|
|
20463
20654
|
name: p.codeName,
|
|
20464
20655
|
display_name: p.displayName,
|
|
@@ -20478,7 +20669,7 @@ adminPluginRoutes.get("/", async (c) => {
|
|
|
20478
20669
|
if (user?.role !== "admin") {
|
|
20479
20670
|
return c.text("Access denied", 403);
|
|
20480
20671
|
}
|
|
20481
|
-
const pluginService = new
|
|
20672
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20482
20673
|
let installedPlugins = [];
|
|
20483
20674
|
let stats = { total: 0, active: 0, inactive: 0, errors: 0, uninstalled: 0 };
|
|
20484
20675
|
try {
|
|
@@ -20550,10 +20741,10 @@ adminPluginRoutes.get("/:id", async (c) => {
|
|
|
20550
20741
|
if (user?.role !== "admin") {
|
|
20551
20742
|
return c.redirect("/admin/plugins");
|
|
20552
20743
|
}
|
|
20553
|
-
const pluginService = new
|
|
20744
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20554
20745
|
let plugin = await pluginService.getPlugin(pluginId);
|
|
20555
20746
|
if (!plugin) {
|
|
20556
|
-
const def =
|
|
20747
|
+
const def = chunkPTTFLUEX_cjs.getPluginDefinition(pluginId);
|
|
20557
20748
|
if (!def) return c.text("Plugin not found", 404);
|
|
20558
20749
|
plugin = await pluginService.ensurePlugin(pluginId, {
|
|
20559
20750
|
displayName: def.displayName ?? pluginId,
|
|
@@ -20644,14 +20835,14 @@ adminPluginRoutes.get("/:id/configure", async (c) => {
|
|
|
20644
20835
|
const user = c.get("user");
|
|
20645
20836
|
const pluginId = c.req.param("id");
|
|
20646
20837
|
if (user?.role !== "admin") return c.redirect("/admin/plugins");
|
|
20647
|
-
const def =
|
|
20838
|
+
const def = chunkPTTFLUEX_cjs.getPluginDefinition(pluginId);
|
|
20648
20839
|
if (!def?.configSchema) return c.text("No schema-driven settings for this plugin", 404);
|
|
20649
20840
|
const db = c.env.DB;
|
|
20650
|
-
const pluginService = new
|
|
20841
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20651
20842
|
const plugin = await pluginService.getPlugin(pluginId);
|
|
20652
20843
|
const stored = plugin?.settings ?? {};
|
|
20653
|
-
const values =
|
|
20654
|
-
const fieldsHtml =
|
|
20844
|
+
const values = chunkPTTFLUEX_cjs.applySchemaDefaults(def.configSchema, stored);
|
|
20845
|
+
const fieldsHtml = chunkPTTFLUEX_cjs.renderSchemaFields(def.configSchema, values);
|
|
20655
20846
|
const displayName = plugin?.display_name ?? def.displayName ?? def.id;
|
|
20656
20847
|
return c.html(`<!DOCTYPE html>
|
|
20657
20848
|
<html lang="en"><head>
|
|
@@ -20678,12 +20869,12 @@ adminPluginRoutes.post("/:id/configure", async (c) => {
|
|
|
20678
20869
|
const user = c.get("user");
|
|
20679
20870
|
const pluginId = c.req.param("id");
|
|
20680
20871
|
if (user?.role !== "admin") return c.json({ error: "Access denied" }, 403);
|
|
20681
|
-
const def =
|
|
20872
|
+
const def = chunkPTTFLUEX_cjs.getPluginDefinition(pluginId);
|
|
20682
20873
|
if (!def?.configSchema) return c.text("No schema-driven settings for this plugin", 404);
|
|
20683
20874
|
const form = await c.req.formData();
|
|
20684
|
-
const parsed =
|
|
20875
|
+
const parsed = chunkPTTFLUEX_cjs.parseFormDataToSettings(def.configSchema, form);
|
|
20685
20876
|
const db = c.env.DB;
|
|
20686
|
-
const pluginService = new
|
|
20877
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20687
20878
|
await pluginService.ensurePlugin(pluginId, {
|
|
20688
20879
|
displayName: def.displayName ?? pluginId,
|
|
20689
20880
|
version: def.version,
|
|
@@ -20705,7 +20896,7 @@ adminPluginRoutes.post("/:id/activate", async (c) => {
|
|
|
20705
20896
|
if (user?.role !== "admin") {
|
|
20706
20897
|
return c.json({ error: "Access denied" }, 403);
|
|
20707
20898
|
}
|
|
20708
|
-
const pluginService = new
|
|
20899
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20709
20900
|
await pluginService.activatePlugin(pluginId);
|
|
20710
20901
|
return c.json({ success: true });
|
|
20711
20902
|
} catch (error) {
|
|
@@ -20722,7 +20913,7 @@ adminPluginRoutes.post("/:id/deactivate", async (c) => {
|
|
|
20722
20913
|
if (user?.role !== "admin") {
|
|
20723
20914
|
return c.json({ error: "Access denied" }, 403);
|
|
20724
20915
|
}
|
|
20725
|
-
const pluginService = new
|
|
20916
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20726
20917
|
await pluginService.deactivatePlugin(pluginId);
|
|
20727
20918
|
return c.json({ success: true });
|
|
20728
20919
|
} catch (error) {
|
|
@@ -20739,8 +20930,8 @@ adminPluginRoutes.post("/install", async (c) => {
|
|
|
20739
20930
|
return c.json({ error: "Access denied" }, 403);
|
|
20740
20931
|
}
|
|
20741
20932
|
const body = await c.req.json();
|
|
20742
|
-
const pluginService = new
|
|
20743
|
-
const registryEntry =
|
|
20933
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20934
|
+
const registryEntry = chunkFXZSZ7C7_cjs.findPluginByCodeName(body.name) || chunkFXZSZ7C7_cjs.PLUGIN_REGISTRY[body.name] || chunkFXZSZ7C7_cjs.PLUGIN_REGISTRY[body.id];
|
|
20744
20935
|
if (!registryEntry) {
|
|
20745
20936
|
return c.json({ error: "Plugin not found in registry" }, 404);
|
|
20746
20937
|
}
|
|
@@ -20773,7 +20964,7 @@ adminPluginRoutes.post("/:id/uninstall", async (c) => {
|
|
|
20773
20964
|
if (user?.role !== "admin") {
|
|
20774
20965
|
return c.json({ error: "Access denied" }, 403);
|
|
20775
20966
|
}
|
|
20776
|
-
const pluginService = new
|
|
20967
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20777
20968
|
await pluginService.uninstallPlugin(pluginId);
|
|
20778
20969
|
return c.json({ success: true });
|
|
20779
20970
|
} catch (error) {
|
|
@@ -20791,7 +20982,7 @@ adminPluginRoutes.post("/:id/settings", async (c) => {
|
|
|
20791
20982
|
return c.json({ error: "Access denied" }, 403);
|
|
20792
20983
|
}
|
|
20793
20984
|
const settings = await c.req.json();
|
|
20794
|
-
const pluginService = new
|
|
20985
|
+
const pluginService = new chunkFXZSZ7C7_cjs.PluginService(db);
|
|
20795
20986
|
await pluginService.updatePluginSettings(pluginId, settings);
|
|
20796
20987
|
if (pluginId === "core-auth") {
|
|
20797
20988
|
try {
|
|
@@ -21599,7 +21790,7 @@ function renderLogConfigPage(data) {
|
|
|
21599
21790
|
|
|
21600
21791
|
// src/routes/admin-logs.ts
|
|
21601
21792
|
var adminLogsRoutes = new hono.Hono();
|
|
21602
|
-
adminLogsRoutes.use("*",
|
|
21793
|
+
adminLogsRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
21603
21794
|
adminLogsRoutes.get("/", async (c) => {
|
|
21604
21795
|
try {
|
|
21605
21796
|
const user = c.get("user");
|
|
@@ -22591,9 +22782,9 @@ function renderStorageUsage(databaseSizeBytes, mediaSizeBytes) {
|
|
|
22591
22782
|
}
|
|
22592
22783
|
|
|
22593
22784
|
// src/routes/admin-dashboard.ts
|
|
22594
|
-
var VERSION =
|
|
22785
|
+
var VERSION = chunkPK3ODTAL_cjs.getCoreVersion();
|
|
22595
22786
|
var router = new hono.Hono();
|
|
22596
|
-
router.use("*",
|
|
22787
|
+
router.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
22597
22788
|
router.get("/", async (c) => {
|
|
22598
22789
|
const user = c.get("user");
|
|
22599
22790
|
try {
|
|
@@ -24558,7 +24749,7 @@ function renderCollectionFormPage(data) {
|
|
|
24558
24749
|
// src/routes/admin-collections.ts
|
|
24559
24750
|
chunkK623Q6WD_cjs.init_admin_layout_catalyst_template();
|
|
24560
24751
|
var adminCollectionsRoutes = new hono.Hono();
|
|
24561
|
-
adminCollectionsRoutes.use("*",
|
|
24752
|
+
adminCollectionsRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
24562
24753
|
adminCollectionsRoutes.get("/", async (c) => {
|
|
24563
24754
|
try {
|
|
24564
24755
|
const user = c.get("user");
|
|
@@ -24575,7 +24766,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24575
24766
|
results = queryResults.results ?? [];
|
|
24576
24767
|
} catch (e) {
|
|
24577
24768
|
}
|
|
24578
|
-
const codeCollections =
|
|
24769
|
+
const codeCollections = chunkFXZSZ7C7_cjs.getCollectionRegistry().list();
|
|
24579
24770
|
const codeCollectionsMap = new Map(
|
|
24580
24771
|
codeCollections.map((cfg) => {
|
|
24581
24772
|
const fieldCount = cfg.schema?.properties ? Object.keys(cfg.schema.properties).length : 0;
|
|
@@ -24589,7 +24780,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24589
24780
|
field_count: fieldCount,
|
|
24590
24781
|
managed: cfg.managed !== false,
|
|
24591
24782
|
source_type: "code",
|
|
24592
|
-
internal:
|
|
24783
|
+
internal: chunkFXZSZ7C7_cjs.isCodeCollectionInternal(cfg),
|
|
24593
24784
|
versioning: cfg.versioning === true
|
|
24594
24785
|
}];
|
|
24595
24786
|
})
|
|
@@ -24628,7 +24819,7 @@ adminCollectionsRoutes.get("/", async (c) => {
|
|
|
24628
24819
|
field_count: fieldCount,
|
|
24629
24820
|
managed: false,
|
|
24630
24821
|
source_type: row.source === "code" || row.source === "system" || row.source === "plugin" ? "code" : "user",
|
|
24631
|
-
internal:
|
|
24822
|
+
internal: chunkFXZSZ7C7_cjs.isDbDocTypeInternal(row.source),
|
|
24632
24823
|
versioning: dbVersioning
|
|
24633
24824
|
};
|
|
24634
24825
|
});
|
|
@@ -24789,7 +24980,7 @@ export const myPlugin = definePlugin({
|
|
|
24789
24980
|
title: "Add a Collection",
|
|
24790
24981
|
pageTitle: "Add a Collection",
|
|
24791
24982
|
currentPath: "/admin/collections",
|
|
24792
|
-
version:
|
|
24983
|
+
version: chunkPK3ODTAL_cjs.getCoreVersion(),
|
|
24793
24984
|
user: u ? { name: u.email ?? "Admin", email: u.email ?? "", role: u.role ?? "admin" } : void 0,
|
|
24794
24985
|
content
|
|
24795
24986
|
})
|
|
@@ -24806,7 +24997,7 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
24806
24997
|
collection = await stmt.bind(id).first();
|
|
24807
24998
|
} catch {
|
|
24808
24999
|
}
|
|
24809
|
-
const registryRecord =
|
|
25000
|
+
const registryRecord = chunkFXZSZ7C7_cjs.getCollectionRegistry().getById(id) ?? chunkFXZSZ7C7_cjs.getCollectionRegistry().getByName(id);
|
|
24810
25001
|
if (!collection && !registryRecord) {
|
|
24811
25002
|
const formData2 = {
|
|
24812
25003
|
isEdit: true,
|
|
@@ -24853,9 +25044,9 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
24853
25044
|
isCodeDriven = true;
|
|
24854
25045
|
}
|
|
24855
25046
|
const [tinymceActive, quillActive, mdxeditorActive] = await Promise.all([
|
|
24856
|
-
|
|
24857
|
-
|
|
24858
|
-
|
|
25047
|
+
chunkZBDDZYA3_cjs.isPluginActive(db, "tinymce-plugin"),
|
|
25048
|
+
chunkZBDDZYA3_cjs.isPluginActive(db, "quill-editor"),
|
|
25049
|
+
chunkZBDDZYA3_cjs.isPluginActive(db, "easy-mdx")
|
|
24859
25050
|
]);
|
|
24860
25051
|
const displayName = collection?.display_name ?? registryRecord?.displayName ?? id;
|
|
24861
25052
|
const formData = {
|
|
@@ -24875,9 +25066,9 @@ adminCollectionsRoutes.get("/:id", async (c) => {
|
|
|
24875
25066
|
console.error("Error fetching collection:", error);
|
|
24876
25067
|
const user = c.get("user");
|
|
24877
25068
|
const [tinymceActive, quillActive, mdxeditorActive] = await Promise.all([
|
|
24878
|
-
|
|
24879
|
-
|
|
24880
|
-
|
|
25069
|
+
chunkZBDDZYA3_cjs.isPluginActive(db, "tinymce-plugin"),
|
|
25070
|
+
chunkZBDDZYA3_cjs.isPluginActive(db, "quill-editor"),
|
|
25071
|
+
chunkZBDDZYA3_cjs.isPluginActive(db, "easy-mdx")
|
|
24881
25072
|
]);
|
|
24882
25073
|
const formData = {
|
|
24883
25074
|
isEdit: true,
|
|
@@ -25826,7 +26017,7 @@ function renderDatabaseToolsSettings(settings) {
|
|
|
25826
26017
|
|
|
25827
26018
|
// src/routes/admin-settings.ts
|
|
25828
26019
|
var adminSettingsRoutes = new hono.Hono();
|
|
25829
|
-
adminSettingsRoutes.use("*",
|
|
26020
|
+
adminSettingsRoutes.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
25830
26021
|
function getMockSettings(user) {
|
|
25831
26022
|
return {
|
|
25832
26023
|
general: {
|
|
@@ -25929,7 +26120,7 @@ adminSettingsRoutes.get("/database-tools", (c) => {
|
|
|
25929
26120
|
adminSettingsRoutes.get("/api/migrations/status", async (c) => {
|
|
25930
26121
|
try {
|
|
25931
26122
|
const db = c.env.DB;
|
|
25932
|
-
const migrationService = new
|
|
26123
|
+
const migrationService = new chunk4AB3PQHF_cjs.MigrationService(db);
|
|
25933
26124
|
const status = await migrationService.getMigrationStatus();
|
|
25934
26125
|
return c.json({
|
|
25935
26126
|
success: true,
|
|
@@ -25969,7 +26160,7 @@ adminSettingsRoutes.post("/api/migrations/run", async (c) => {
|
|
|
25969
26160
|
adminSettingsRoutes.get("/api/migrations/validate", async (c) => {
|
|
25970
26161
|
try {
|
|
25971
26162
|
const db = c.env.DB;
|
|
25972
|
-
const migrationService = new
|
|
26163
|
+
const migrationService = new chunk4AB3PQHF_cjs.MigrationService(db);
|
|
25973
26164
|
const validation = await migrationService.validateSchema();
|
|
25974
26165
|
return c.json({
|
|
25975
26166
|
success: true,
|
|
@@ -26562,16 +26753,16 @@ function renderAPIReferencePage(data) {
|
|
|
26562
26753
|
}
|
|
26563
26754
|
|
|
26564
26755
|
// src/routes/admin-api-reference.ts
|
|
26565
|
-
var VERSION2 =
|
|
26756
|
+
var VERSION2 = chunkPK3ODTAL_cjs.getCoreVersion();
|
|
26566
26757
|
var router2 = new hono.Hono();
|
|
26567
|
-
router2.use("*",
|
|
26758
|
+
router2.use("*", chunkZBDDZYA3_cjs.requireAuth());
|
|
26568
26759
|
router2.get("/", async (c) => {
|
|
26569
26760
|
const user = c.get("user");
|
|
26570
26761
|
try {
|
|
26571
26762
|
const app2 = chunk4BTBSXMR_cjs.getAppInstance();
|
|
26572
26763
|
const baseEndpoints = chunk4BTBSXMR_cjs.buildRouteList(app2);
|
|
26573
26764
|
const collectionRoutes = [];
|
|
26574
|
-
const collections =
|
|
26765
|
+
const collections = chunkFXZSZ7C7_cjs.getCollectionRegistry().listActive().filter((r) => !r.internal);
|
|
26575
26766
|
const methodOrder = { GET: 0, POST: 1, PUT: 2, PATCH: 3, DELETE: 4 };
|
|
26576
26767
|
for (const col of collections) {
|
|
26577
26768
|
const displayName = col.displayName || col.name;
|
|
@@ -26663,6 +26854,7 @@ exports.api_default = api_default;
|
|
|
26663
26854
|
exports.api_media_default = api_media_default;
|
|
26664
26855
|
exports.api_system_default = api_system_default;
|
|
26665
26856
|
exports.auth_default = auth_default;
|
|
26857
|
+
exports.createDocumentSchema = createDocumentSchema;
|
|
26666
26858
|
exports.createUserProfilesPlugin = createUserProfilesPlugin;
|
|
26667
26859
|
exports.defineUserProfile = defineUserProfile;
|
|
26668
26860
|
exports.denyIfNotAllowed = denyIfNotAllowed;
|
|
@@ -26687,5 +26879,5 @@ exports.setVariablesCache = setVariablesCache;
|
|
|
26687
26879
|
exports.test_cleanup_default = test_cleanup_default;
|
|
26688
26880
|
exports.userProfilesPlugin = userProfilesPlugin;
|
|
26689
26881
|
exports.userRoutes = userRoutes;
|
|
26690
|
-
//# sourceMappingURL=chunk-
|
|
26691
|
-
//# sourceMappingURL=chunk-
|
|
26882
|
+
//# sourceMappingURL=chunk-BDQOPRA3.cjs.map
|
|
26883
|
+
//# sourceMappingURL=chunk-BDQOPRA3.cjs.map
|