@sonicjs-cms/core 2.8.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-JDFPB6UW.js → chunk-7Q2XPM2U.js} +2 -2
- package/dist/{chunk-JDFPB6UW.js.map → chunk-7Q2XPM2U.js.map} +1 -1
- package/dist/{chunk-BAWMAS5S.js → chunk-FZRZYQYU.js} +82 -30
- package/dist/chunk-FZRZYQYU.js.map +1 -0
- package/dist/{chunk-GPTMGUFN.cjs → chunk-GIWIJNBH.cjs} +4 -4
- package/dist/{chunk-GPTMGUFN.cjs.map → chunk-GIWIJNBH.cjs.map} +1 -1
- package/dist/{chunk-YE2MU7CN.cjs → chunk-JVRRG36J.cjs} +178 -126
- package/dist/chunk-JVRRG36J.cjs.map +1 -0
- package/dist/{chunk-34QIAULP.js → chunk-KAT3OKHE.js} +3 -3
- package/dist/{chunk-34QIAULP.js.map → chunk-KAT3OKHE.js.map} +1 -1
- package/dist/{chunk-3E76TKR5.js → chunk-QWTS6NSP.js} +3 -3
- package/dist/{chunk-3E76TKR5.js.map → chunk-QWTS6NSP.js.map} +1 -1
- package/dist/{chunk-5CENPGR2.cjs → chunk-SKLRRFJJ.cjs} +2 -2
- package/dist/{chunk-5CENPGR2.cjs.map → chunk-SKLRRFJJ.cjs.map} +1 -1
- package/dist/{chunk-5HMR2SJW.cjs → chunk-WDQZYCQO.cjs} +3 -3
- package/dist/{chunk-5HMR2SJW.cjs.map → chunk-WDQZYCQO.cjs.map} +1 -1
- package/dist/index.cjs +84 -84
- package/dist/index.js +7 -7
- package/dist/middleware.cjs +23 -23
- package/dist/middleware.js +2 -2
- package/dist/migrations-2NTJ44OR.js +4 -0
- package/dist/{migrations-YB77VTVF.js.map → migrations-2NTJ44OR.js.map} +1 -1
- package/dist/migrations-76NR5BVF.cjs +13 -0
- package/dist/{migrations-7JGSFOCM.cjs.map → migrations-76NR5BVF.cjs.map} +1 -1
- package/dist/routes.cjs +27 -27
- package/dist/routes.js +4 -4
- package/dist/services.cjs +2 -2
- package/dist/services.js +1 -1
- package/dist/utils.cjs +14 -14
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-BAWMAS5S.js.map +0 -1
- package/dist/chunk-YE2MU7CN.cjs.map +0 -1
- package/dist/migrations-7JGSFOCM.cjs +0 -13
- package/dist/migrations-YB77VTVF.js +0 -4
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getCacheService, CACHE_CONFIGS, getLogger, SettingsService } from './chunk-G44QUVNM.js';
|
|
2
|
-
import { requireAuth, isPluginActive, requireRole, AuthManager, logActivity } from './chunk-
|
|
2
|
+
import { requireAuth, isPluginActive, optionalAuth, requireRole, AuthManager, logActivity } from './chunk-QWTS6NSP.js';
|
|
3
3
|
import { PluginService } from './chunk-YFJJU26H.js';
|
|
4
|
-
import { MigrationService } from './chunk-
|
|
4
|
+
import { MigrationService } from './chunk-7Q2XPM2U.js';
|
|
5
5
|
import { init_admin_layout_catalyst_template, renderDesignPage, renderCheckboxPage, renderTestimonialsList, renderCodeExamplesList, renderAlert, renderTable, renderPagination, renderConfirmationDialog, getConfirmationDialogScript, renderAdminLayoutCatalyst, renderAdminLayout, adminLayoutV2, renderForm } from './chunk-VCH6HXVP.js';
|
|
6
6
|
import { PluginBuilder, TurnstileService } from './chunk-J5WGMRSU.js';
|
|
7
|
-
import { QueryFilterBuilder, sanitizeInput, getCoreVersion, escapeHtml, getBlocksFieldConfig, parseBlocksValue } from './chunk-
|
|
7
|
+
import { QueryFilterBuilder, sanitizeInput, getCoreVersion, escapeHtml, getBlocksFieldConfig, parseBlocksValue } from './chunk-KAT3OKHE.js';
|
|
8
8
|
import { metricsTracker } from './chunk-FICTAGD4.js';
|
|
9
9
|
import { Hono } from 'hono';
|
|
10
10
|
import { cors } from 'hono/cors';
|
|
@@ -14,6 +14,50 @@ import { html, raw } from 'hono/html';
|
|
|
14
14
|
|
|
15
15
|
// src/schemas/index.ts
|
|
16
16
|
var schemaDefinitions = [];
|
|
17
|
+
|
|
18
|
+
// src/routes/api-content-access-policy.ts
|
|
19
|
+
function canReadNonPublicContent(userRole) {
|
|
20
|
+
return userRole === "admin" || userRole === "editor";
|
|
21
|
+
}
|
|
22
|
+
function isStatusCondition(condition) {
|
|
23
|
+
return condition.field === "status";
|
|
24
|
+
}
|
|
25
|
+
function stripStatusConditions(group) {
|
|
26
|
+
if (!group) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
const and = group.and?.filter((condition) => !isStatusCondition(condition));
|
|
30
|
+
const or = group.or?.filter((condition) => !isStatusCondition(condition));
|
|
31
|
+
const normalizedGroup = {};
|
|
32
|
+
if (and && and.length > 0) {
|
|
33
|
+
normalizedGroup.and = and;
|
|
34
|
+
}
|
|
35
|
+
if (or && or.length > 0) {
|
|
36
|
+
normalizedGroup.or = or;
|
|
37
|
+
}
|
|
38
|
+
return normalizedGroup;
|
|
39
|
+
}
|
|
40
|
+
function normalizePublicContentFilter(filter, userRole) {
|
|
41
|
+
if (canReadNonPublicContent(userRole)) {
|
|
42
|
+
return filter;
|
|
43
|
+
}
|
|
44
|
+
const normalizedFilter = {
|
|
45
|
+
...filter,
|
|
46
|
+
where: stripStatusConditions(filter.where)
|
|
47
|
+
};
|
|
48
|
+
if (!normalizedFilter.where) {
|
|
49
|
+
normalizedFilter.where = { and: [] };
|
|
50
|
+
}
|
|
51
|
+
if (!normalizedFilter.where.and) {
|
|
52
|
+
normalizedFilter.where.and = [];
|
|
53
|
+
}
|
|
54
|
+
normalizedFilter.where.and.push({
|
|
55
|
+
field: "status",
|
|
56
|
+
operator: "equals",
|
|
57
|
+
value: "published"
|
|
58
|
+
});
|
|
59
|
+
return normalizedFilter;
|
|
60
|
+
}
|
|
17
61
|
var apiContentCrudRoutes = new Hono();
|
|
18
62
|
apiContentCrudRoutes.get("/check-slug", async (c) => {
|
|
19
63
|
try {
|
|
@@ -369,7 +413,7 @@ apiRoutes.get("/", (c) => {
|
|
|
369
413
|
"/api/collections/{collection}/content": {
|
|
370
414
|
get: {
|
|
371
415
|
summary: "Get Collection Content",
|
|
372
|
-
description: "Returns content items from a specific collection with filtering support",
|
|
416
|
+
description: "Returns content items from a specific collection with filtering support. Anonymous, viewer, and author requests are restricted to published content; admin and editor requests may query other statuses.",
|
|
373
417
|
operationId: "getCollectionContent",
|
|
374
418
|
tags: ["Content"],
|
|
375
419
|
parameters: [
|
|
@@ -396,7 +440,7 @@ apiRoutes.get("/", (c) => {
|
|
|
396
440
|
name: "status",
|
|
397
441
|
in: "query",
|
|
398
442
|
schema: { type: "string", enum: ["draft", "published", "archived"] },
|
|
399
|
-
description: "Filter by content status"
|
|
443
|
+
description: "Filter by content status. Anonymous, viewer, and author requests are limited to published content."
|
|
400
444
|
}
|
|
401
445
|
],
|
|
402
446
|
responses: {
|
|
@@ -423,7 +467,7 @@ apiRoutes.get("/", (c) => {
|
|
|
423
467
|
"/api/content": {
|
|
424
468
|
get: {
|
|
425
469
|
summary: "List Content",
|
|
426
|
-
description: "Returns content items with advanced filtering support",
|
|
470
|
+
description: "Returns content items with advanced filtering support. Anonymous, viewer, and author requests are restricted to published content; admin and editor requests may query other statuses.",
|
|
427
471
|
operationId: "getContent",
|
|
428
472
|
tags: ["Content"],
|
|
429
473
|
parameters: [
|
|
@@ -444,6 +488,12 @@ apiRoutes.get("/", (c) => {
|
|
|
444
488
|
in: "query",
|
|
445
489
|
schema: { type: "integer", default: 0 },
|
|
446
490
|
description: "Number of items to skip"
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
name: "status",
|
|
494
|
+
in: "query",
|
|
495
|
+
schema: { type: "string", enum: ["draft", "published", "archived"] },
|
|
496
|
+
description: "Filter by content status. Anonymous, viewer, and author requests are limited to published content."
|
|
447
497
|
}
|
|
448
498
|
],
|
|
449
499
|
responses: {
|
|
@@ -720,7 +770,7 @@ apiRoutes.get("/collections", async (c) => {
|
|
|
720
770
|
return c.json({ error: "Failed to fetch collections" }, 500);
|
|
721
771
|
}
|
|
722
772
|
});
|
|
723
|
-
apiRoutes.get("/content", async (c) => {
|
|
773
|
+
apiRoutes.get("/content", optionalAuth(), async (c) => {
|
|
724
774
|
const executionStart = Date.now();
|
|
725
775
|
try {
|
|
726
776
|
const db = c.env.DB;
|
|
@@ -744,12 +794,13 @@ apiRoutes.get("/content", async (c) => {
|
|
|
744
794
|
}
|
|
745
795
|
}
|
|
746
796
|
const filter = QueryFilterBuilder.parseFromQuery(queryParams);
|
|
747
|
-
|
|
748
|
-
|
|
797
|
+
const normalizedFilter = normalizePublicContentFilter(filter, c.get("user")?.role);
|
|
798
|
+
if (!normalizedFilter.limit) {
|
|
799
|
+
normalizedFilter.limit = 50;
|
|
749
800
|
}
|
|
750
|
-
|
|
801
|
+
normalizedFilter.limit = Math.min(normalizedFilter.limit, 1e3);
|
|
751
802
|
const builder3 = new QueryFilterBuilder();
|
|
752
|
-
const queryResult = builder3.build("content",
|
|
803
|
+
const queryResult = builder3.build("content", normalizedFilter);
|
|
753
804
|
if (queryResult.errors.length > 0) {
|
|
754
805
|
return c.json({
|
|
755
806
|
error: "Invalid filter parameters",
|
|
@@ -758,7 +809,7 @@ apiRoutes.get("/content", async (c) => {
|
|
|
758
809
|
}
|
|
759
810
|
const cacheEnabled = c.get("cacheEnabled");
|
|
760
811
|
const cache = getCacheService(CACHE_CONFIGS.api);
|
|
761
|
-
const cacheKey = cache.generateKey("content-filtered", JSON.stringify({ filter, query: queryResult.sql }));
|
|
812
|
+
const cacheKey = cache.generateKey("content-filtered", JSON.stringify({ filter: normalizedFilter, query: queryResult.sql }));
|
|
762
813
|
if (cacheEnabled) {
|
|
763
814
|
const cacheResult = await cache.getWithSource(cacheKey);
|
|
764
815
|
if (cacheResult.hit && cacheResult.data) {
|
|
@@ -801,7 +852,7 @@ apiRoutes.get("/content", async (c) => {
|
|
|
801
852
|
meta: addTimingMeta(c, {
|
|
802
853
|
count: results.length,
|
|
803
854
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
804
|
-
filter,
|
|
855
|
+
filter: normalizedFilter,
|
|
805
856
|
query: {
|
|
806
857
|
sql: queryResult.sql,
|
|
807
858
|
params: queryResult.params
|
|
@@ -824,7 +875,7 @@ apiRoutes.get("/content", async (c) => {
|
|
|
824
875
|
}, 500);
|
|
825
876
|
}
|
|
826
877
|
});
|
|
827
|
-
apiRoutes.get("/collections/:collection/content", async (c) => {
|
|
878
|
+
apiRoutes.get("/collections/:collection/content", optionalAuth(), async (c) => {
|
|
828
879
|
const executionStart = Date.now();
|
|
829
880
|
try {
|
|
830
881
|
const collection = c.req.param("collection");
|
|
@@ -836,23 +887,24 @@ apiRoutes.get("/collections/:collection/content", async (c) => {
|
|
|
836
887
|
return c.json({ error: "Collection not found" }, 404);
|
|
837
888
|
}
|
|
838
889
|
const filter = QueryFilterBuilder.parseFromQuery(queryParams);
|
|
839
|
-
|
|
840
|
-
|
|
890
|
+
const normalizedFilter = normalizePublicContentFilter(filter, c.get("user")?.role);
|
|
891
|
+
if (!normalizedFilter.where) {
|
|
892
|
+
normalizedFilter.where = { and: [] };
|
|
841
893
|
}
|
|
842
|
-
if (!
|
|
843
|
-
|
|
894
|
+
if (!normalizedFilter.where.and) {
|
|
895
|
+
normalizedFilter.where.and = [];
|
|
844
896
|
}
|
|
845
|
-
|
|
897
|
+
normalizedFilter.where.and.push({
|
|
846
898
|
field: "collection_id",
|
|
847
899
|
operator: "equals",
|
|
848
900
|
value: collectionResult.id
|
|
849
901
|
});
|
|
850
|
-
if (!
|
|
851
|
-
|
|
902
|
+
if (!normalizedFilter.limit) {
|
|
903
|
+
normalizedFilter.limit = 50;
|
|
852
904
|
}
|
|
853
|
-
|
|
905
|
+
normalizedFilter.limit = Math.min(normalizedFilter.limit, 1e3);
|
|
854
906
|
const builder3 = new QueryFilterBuilder();
|
|
855
|
-
const queryResult = builder3.build("content",
|
|
907
|
+
const queryResult = builder3.build("content", normalizedFilter);
|
|
856
908
|
if (queryResult.errors.length > 0) {
|
|
857
909
|
return c.json({
|
|
858
910
|
error: "Invalid filter parameters",
|
|
@@ -861,7 +913,7 @@ apiRoutes.get("/collections/:collection/content", async (c) => {
|
|
|
861
913
|
}
|
|
862
914
|
const cacheEnabled = c.get("cacheEnabled");
|
|
863
915
|
const cache = getCacheService(CACHE_CONFIGS.api);
|
|
864
|
-
const cacheKey = cache.generateKey("collection-content-filtered", `${collection}:${JSON.stringify({ filter, query: queryResult.sql })}`);
|
|
916
|
+
const cacheKey = cache.generateKey("collection-content-filtered", `${collection}:${JSON.stringify({ filter: normalizedFilter, query: queryResult.sql })}`);
|
|
865
917
|
if (cacheEnabled) {
|
|
866
918
|
const cacheResult = await cache.getWithSource(cacheKey);
|
|
867
919
|
if (cacheResult.hit && cacheResult.data) {
|
|
@@ -908,7 +960,7 @@ apiRoutes.get("/collections/:collection/content", async (c) => {
|
|
|
908
960
|
},
|
|
909
961
|
count: results.length,
|
|
910
962
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
911
|
-
filter,
|
|
963
|
+
filter: normalizedFilter,
|
|
912
964
|
query: {
|
|
913
965
|
sql: queryResult.sql,
|
|
914
966
|
params: queryResult.params
|
|
@@ -2231,7 +2283,7 @@ adminApiRoutes.delete("/collections/:id", async (c) => {
|
|
|
2231
2283
|
});
|
|
2232
2284
|
adminApiRoutes.get("/migrations/status", async (c) => {
|
|
2233
2285
|
try {
|
|
2234
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
2286
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-2NTJ44OR.js');
|
|
2235
2287
|
const db = c.env.DB;
|
|
2236
2288
|
const migrationService = new MigrationService2(db);
|
|
2237
2289
|
const status = await migrationService.getMigrationStatus();
|
|
@@ -2256,7 +2308,7 @@ adminApiRoutes.post("/migrations/run", async (c) => {
|
|
|
2256
2308
|
error: "Unauthorized. Admin access required."
|
|
2257
2309
|
}, 403);
|
|
2258
2310
|
}
|
|
2259
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
2311
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-2NTJ44OR.js');
|
|
2260
2312
|
const db = c.env.DB;
|
|
2261
2313
|
const migrationService = new MigrationService2(db);
|
|
2262
2314
|
const result = await migrationService.runPendingMigrations();
|
|
@@ -2275,7 +2327,7 @@ adminApiRoutes.post("/migrations/run", async (c) => {
|
|
|
2275
2327
|
});
|
|
2276
2328
|
adminApiRoutes.get("/migrations/validate", async (c) => {
|
|
2277
2329
|
try {
|
|
2278
|
-
const { MigrationService: MigrationService2 } = await import('./migrations-
|
|
2330
|
+
const { MigrationService: MigrationService2 } = await import('./migrations-2NTJ44OR.js');
|
|
2279
2331
|
const db = c.env.DB;
|
|
2280
2332
|
const migrationService = new MigrationService2(db);
|
|
2281
2333
|
const validation = await migrationService.validateSchema();
|
|
@@ -27758,5 +27810,5 @@ var ROUTES_INFO = {
|
|
|
27758
27810
|
};
|
|
27759
27811
|
|
|
27760
27812
|
export { ROUTES_INFO, adminCheckboxRoutes, adminCollectionsRoutes, adminDesignRoutes, adminFormsRoutes, adminLogsRoutes, adminMediaRoutes, adminPluginRoutes, adminSettingsRoutes, admin_api_default, admin_code_examples_default, admin_content_default, admin_testimonials_default, api_content_crud_default, api_default, api_media_default, api_system_default, auth_default, getConfirmationDialogScript2 as getConfirmationDialogScript, public_forms_default, renderConfirmationDialog2 as renderConfirmationDialog, router, router2, test_cleanup_default, userRoutes };
|
|
27761
|
-
//# sourceMappingURL=chunk-
|
|
27762
|
-
//# sourceMappingURL=chunk-
|
|
27813
|
+
//# sourceMappingURL=chunk-FZRZYQYU.js.map
|
|
27814
|
+
//# sourceMappingURL=chunk-FZRZYQYU.js.map
|