@sonicjs-cms/core 3.0.0-beta.25 → 3.0.0-beta.26

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.
Files changed (116) hide show
  1. package/dist/{app-01M0dIwt.d.ts → app-BP5IlK94.d.ts} +7 -7
  2. package/dist/{app-aj39TGHB.d.cts → app-fdq4K3vw.d.cts} +7 -7
  3. package/dist/catalog-56DR6OXI.cjs +41 -0
  4. package/dist/catalog-56DR6OXI.cjs.map +1 -0
  5. package/dist/catalog-6MB37KY7.js +4 -0
  6. package/dist/catalog-6MB37KY7.js.map +1 -0
  7. package/dist/{chunk-YAURVGUK.cjs → chunk-4DHPR7KR.cjs} +77 -17
  8. package/dist/chunk-4DHPR7KR.cjs.map +1 -0
  9. package/dist/{chunk-D7RLBBHE.js → chunk-5YSFQO7X.js} +40 -13
  10. package/dist/chunk-5YSFQO7X.js.map +1 -0
  11. package/dist/{chunk-RSBZITK3.cjs → chunk-6UAI4SGN.cjs} +3 -3
  12. package/dist/{chunk-RSBZITK3.cjs.map → chunk-6UAI4SGN.cjs.map} +1 -1
  13. package/dist/{chunk-2XAQTPAE.js → chunk-6X22VFEV.js} +8 -2
  14. package/dist/chunk-6X22VFEV.js.map +1 -0
  15. package/dist/{chunk-I7MIRRFJ.cjs → chunk-A22RBHO7.cjs} +11 -11
  16. package/dist/{chunk-I7MIRRFJ.cjs.map → chunk-A22RBHO7.cjs.map} +1 -1
  17. package/dist/{chunk-FVAK4C6L.js → chunk-AMP4BSJE.js} +3 -3
  18. package/dist/{chunk-FVAK4C6L.js.map → chunk-AMP4BSJE.js.map} +1 -1
  19. package/dist/{chunk-E7E3NL3Y.cjs → chunk-BRKXMRMB.cjs} +93 -93
  20. package/dist/chunk-BRKXMRMB.cjs.map +1 -0
  21. package/dist/{chunk-36Z3AKX3.cjs → chunk-C5LDQ3SH.cjs} +8 -2
  22. package/dist/chunk-C5LDQ3SH.cjs.map +1 -0
  23. package/dist/{chunk-2OXFMMA3.js → chunk-EEA476CJ.js} +84 -80
  24. package/dist/chunk-EEA476CJ.js.map +1 -0
  25. package/dist/chunk-F6BTBE4S.js +119 -0
  26. package/dist/chunk-F6BTBE4S.js.map +1 -0
  27. package/dist/chunk-FZGIU5AZ.cjs +128 -0
  28. package/dist/chunk-FZGIU5AZ.cjs.map +1 -0
  29. package/dist/{chunk-C54MH5UI.js → chunk-JD7BZU3A.js} +3 -3
  30. package/dist/{chunk-C54MH5UI.js.map → chunk-JD7BZU3A.js.map} +1 -1
  31. package/dist/{chunk-3KGY4IBW.js → chunk-JG5J434C.js} +3 -3
  32. package/dist/{chunk-3KGY4IBW.js.map → chunk-JG5J434C.js.map} +1 -1
  33. package/dist/{chunk-D6FWEYQE.cjs → chunk-KWQNB6UM.cjs} +4 -4
  34. package/dist/{chunk-D6FWEYQE.cjs.map → chunk-KWQNB6UM.cjs.map} +1 -1
  35. package/dist/{chunk-7P5OCUPS.js → chunk-OJFIQGZB.js} +107 -29
  36. package/dist/chunk-OJFIQGZB.js.map +1 -0
  37. package/dist/{chunk-JCBDXEY2.cjs → chunk-OLEOKHDX.cjs} +9 -2
  38. package/dist/chunk-OLEOKHDX.cjs.map +1 -0
  39. package/dist/{chunk-MOGK3U4A.cjs → chunk-PAS7GZBS.cjs} +40 -13
  40. package/dist/chunk-PAS7GZBS.cjs.map +1 -0
  41. package/dist/{chunk-2D3A4X52.js → chunk-RVOX2WH2.js} +74 -18
  42. package/dist/chunk-RVOX2WH2.js.map +1 -0
  43. package/dist/{chunk-BDQ55MWV.js → chunk-RXLI3ADU.js} +9 -2
  44. package/dist/chunk-RXLI3ADU.js.map +1 -0
  45. package/dist/{chunk-6OA77UM7.cjs → chunk-S2QN4LFD.cjs} +386 -306
  46. package/dist/chunk-S2QN4LFD.cjs.map +1 -0
  47. package/dist/{chunk-DLTT7QZU.cjs → chunk-SFGYZUWU.cjs} +3 -3
  48. package/dist/{chunk-DLTT7QZU.cjs.map → chunk-SFGYZUWU.cjs.map} +1 -1
  49. package/dist/{chunk-CWIGQYRR.js → chunk-UB5QSRO7.js} +5 -5
  50. package/dist/chunk-UB5QSRO7.js.map +1 -0
  51. package/dist/{chunk-F26HP3B6.js → chunk-UKIDWRA3.js} +4 -4
  52. package/dist/{chunk-F26HP3B6.js.map → chunk-UKIDWRA3.js.map} +1 -1
  53. package/dist/{chunk-BJ6NJL2E.cjs → chunk-XZUEGFXE.cjs} +5 -5
  54. package/dist/chunk-XZUEGFXE.cjs.map +1 -0
  55. package/dist/{collection-config-BTzAvKt2.d.cts → collection-config-U2dydD_O.d.cts} +14 -0
  56. package/dist/{collection-config-BTzAvKt2.d.ts → collection-config-U2dydD_O.d.ts} +14 -0
  57. package/dist/config-DOAWXZBG.js +6 -0
  58. package/dist/{config-4TIHSNW6.js.map → config-DOAWXZBG.js.map} +1 -1
  59. package/dist/{config-XN2ETAJ3.cjs → config-VLU73ZW7.cjs} +5 -5
  60. package/dist/{config-XN2ETAJ3.cjs.map → config-VLU73ZW7.cjs.map} +1 -1
  61. package/dist/index.cjs +600 -332
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +17 -10
  64. package/dist/index.d.ts +17 -10
  65. package/dist/index.js +292 -25
  66. package/dist/index.js.map +1 -1
  67. package/dist/middleware.cjs +46 -46
  68. package/dist/middleware.d.cts +6 -9
  69. package/dist/middleware.d.ts +6 -9
  70. package/dist/middleware.js +5 -5
  71. package/dist/migrations-6M6772UC.cjs +13 -0
  72. package/dist/{migrations-KU4V6T73.cjs.map → migrations-6M6772UC.cjs.map} +1 -1
  73. package/dist/migrations-GZ2HIB4I.js +4 -0
  74. package/dist/{migrations-JAHMI5MK.js.map → migrations-GZ2HIB4I.js.map} +1 -1
  75. package/dist/{plugin-bootstrap-BHWQ2df8.d.cts → plugin-bootstrap-CfVILQeP.d.ts} +1 -1
  76. package/dist/{plugin-bootstrap-Bj4fxX1q.d.ts → plugin-bootstrap-RY5pkoOT.d.cts} +1 -1
  77. package/dist/plugins.cjs +40 -40
  78. package/dist/plugins.js +3 -3
  79. package/dist/rbac-TFUOYIVN.cjs +14 -0
  80. package/dist/{rbac-AORZ6O3N.cjs.map → rbac-TFUOYIVN.cjs.map} +1 -1
  81. package/dist/rbac-XSNP76CV.js +5 -0
  82. package/dist/{rbac-P44772FP.js.map → rbac-XSNP76CV.js.map} +1 -1
  83. package/dist/routes.cjs +31 -30
  84. package/dist/routes.d.cts +3 -5
  85. package/dist/routes.d.ts +3 -5
  86. package/dist/routes.js +11 -10
  87. package/dist/services.cjs +30 -30
  88. package/dist/services.d.cts +9 -2
  89. package/dist/services.d.ts +9 -2
  90. package/dist/services.js +3 -3
  91. package/dist/types.d.cts +1 -1
  92. package/dist/types.d.ts +1 -1
  93. package/dist/utils.cjs +12 -12
  94. package/dist/utils.d.cts +1 -1
  95. package/dist/utils.d.ts +1 -1
  96. package/dist/utils.js +2 -2
  97. package/package.json +3 -3
  98. package/dist/chunk-2D3A4X52.js.map +0 -1
  99. package/dist/chunk-2OXFMMA3.js.map +0 -1
  100. package/dist/chunk-2XAQTPAE.js.map +0 -1
  101. package/dist/chunk-36Z3AKX3.cjs.map +0 -1
  102. package/dist/chunk-6OA77UM7.cjs.map +0 -1
  103. package/dist/chunk-7P5OCUPS.js.map +0 -1
  104. package/dist/chunk-BDQ55MWV.js.map +0 -1
  105. package/dist/chunk-BJ6NJL2E.cjs.map +0 -1
  106. package/dist/chunk-CWIGQYRR.js.map +0 -1
  107. package/dist/chunk-D7RLBBHE.js.map +0 -1
  108. package/dist/chunk-E7E3NL3Y.cjs.map +0 -1
  109. package/dist/chunk-JCBDXEY2.cjs.map +0 -1
  110. package/dist/chunk-MOGK3U4A.cjs.map +0 -1
  111. package/dist/chunk-YAURVGUK.cjs.map +0 -1
  112. package/dist/config-4TIHSNW6.js +0 -6
  113. package/dist/migrations-JAHMI5MK.js +0 -4
  114. package/dist/migrations-KU4V6T73.cjs +0 -13
  115. package/dist/rbac-AORZ6O3N.cjs +0 -14
  116. package/dist/rbac-P44772FP.js +0 -5
@@ -1,18 +1,19 @@
1
- import { isFirstUserRegistration, isRegistrationEnabled, authValidationService } from './chunk-VVYVFCML.js';
2
1
  import { renderDocumentFormPage, renderAlert } from './chunk-E3TQG7AA.js';
3
- import { getCacheService, CACHE_CONFIGS, SettingsService, getLogger, getAppInstance, buildRouteList, CATEGORY_INFO } from './chunk-2XAQTPAE.js';
4
- import { DocumentTypeRegistry, requireAuth, requireRole, optionalAuth, isPluginActive, rateLimit, AuthManager, getJwtExpirySecondsFromDb, getJwtRefreshGraceSecondsFromDb, logActivity, generateCsrfToken } from './chunk-2OXFMMA3.js';
5
- import { DocumentsService, documentSecondsToMs, RbacService } from './chunk-BDQ55MWV.js';
2
+ import { recordCatalogRequest, scheduleKvWrite } from './chunk-F6BTBE4S.js';
3
+ import { isFirstUserRegistration, isRegistrationEnabled, authValidationService } from './chunk-VVYVFCML.js';
4
+ import { getCacheService, CACHE_CONFIGS, SettingsService, getLogger, getAppInstance, buildRouteList, CATEGORY_INFO } from './chunk-6X22VFEV.js';
5
+ import { DocumentTypeRegistry, requireAuth, requireRole, optionalAuth, rateLimit, AuthManager, getJwtExpirySecondsFromDb, getJwtRefreshGraceSecondsFromDb, logActivity, generateCsrfToken } from './chunk-EEA476CJ.js';
6
+ import { DocumentsService, documentSecondsToMs, RbacService } from './chunk-RXLI3ADU.js';
6
7
  import { nanoid } from './chunk-UWUP2VMT.js';
7
- import { getCollectionRegistry, collectionRecordToRow, loadCollectionConfigs, getVisibleCollections, PluginService, PLUGIN_REGISTRY, findPluginByCodeName, isCodeCollectionInternal, isDbDocTypeInternal, invalidateTenantCache } from './chunk-2D3A4X52.js';
8
- import { MigrationService } from './chunk-D7RLBBHE.js';
8
+ import { getCollectionRegistry, isPluginActive, collectionRecordToRow, loadCollectionConfigs, getVisibleCollections, PluginService, PLUGIN_REGISTRY, findPluginByCodeName, isCodeCollectionInternal, isDbDocTypeInternal, invalidateTenantCache } from './chunk-RVOX2WH2.js';
9
+ import { MigrationService } from './chunk-5YSFQO7X.js';
9
10
  import { renderCheckboxPage, renderAlert as renderAlert$1, renderTable, renderPagination, renderConfirmationDialog, getConfirmationDialogScript, renderAdminLayout, adminLayoutV2, renderForm } from './chunk-HSDJDWLV.js';
10
11
  import { init_admin_layout_catalyst_template, renderAdminLayoutCatalyst } from './chunk-SXC4HPK6.js';
11
- import { createServiceSingleton, definePlugin, getPluginDefinition, applySchemaDefaults, renderSchemaFields, parseFormDataToSettings, getPluginMenu } from './chunk-C54MH5UI.js';
12
+ import { createServiceSingleton, definePlugin, getPluginDefinition, applySchemaDefaults, renderSchemaFields, parseFormDataToSettings, getPluginMenu } from './chunk-JD7BZU3A.js';
12
13
  import { hasHookSystem, getTypedHooks } from './chunk-RNZFGN4R.js';
13
- import { QueryFilterBuilder, getBlocksFieldConfig, parseBlocksValue } from './chunk-FVAK4C6L.js';
14
+ import { QueryFilterBuilder, getBlocksFieldConfig, parseBlocksValue } from './chunk-AMP4BSJE.js';
14
15
  import { metricsTracker } from './chunk-FICTAGD4.js';
15
- import { getCoreVersion } from './chunk-CWIGQYRR.js';
16
+ import { getCoreVersion } from './chunk-UB5QSRO7.js';
16
17
  import { escapeHtml, sanitizeRichText, sanitizeInput } from './chunk-TQABQWOP.js';
17
18
  import { Hono } from 'hono';
18
19
  import { z } from 'zod';
@@ -843,6 +844,34 @@ async function dispatchHookEvent(c, event, payload, mode = "fire-and-forget") {
843
844
  return hooks.dispatch(event, payload);
844
845
  }
845
846
 
847
+ // src/plugins/cache/services/swr.ts
848
+ var STALE_TTL_MS = 3e4;
849
+ var staleMap = /* @__PURE__ */ new Map();
850
+ function markStale(cacheKey, data, collection) {
851
+ staleMap.set(cacheKey, {
852
+ data,
853
+ collection,
854
+ expiresAt: Date.now() + STALE_TTL_MS
855
+ });
856
+ }
857
+ function getAndConsumeStale(cacheKey) {
858
+ const entry = staleMap.get(cacheKey);
859
+ if (!entry) return null;
860
+ if (Date.now() > entry.expiresAt) {
861
+ staleMap.delete(cacheKey);
862
+ return null;
863
+ }
864
+ staleMap.delete(cacheKey);
865
+ return entry.data;
866
+ }
867
+ function swrStats() {
868
+ const now = Date.now();
869
+ for (const [key, entry] of staleMap.entries()) {
870
+ if (now > entry.expiresAt) staleMap.delete(key);
871
+ }
872
+ return { count: staleMap.size };
873
+ }
874
+
846
875
  // src/plugins/core-plugins/global-variables-plugin/variable-resolver.ts
847
876
  var TOKEN_PATTERN = /\{([a-z0-9_]+)\}/g;
848
877
  function resolveVariables(text, variables) {
@@ -1340,7 +1369,8 @@ apiRoutes.use("*", async (c, next) => {
1340
1369
  c.header("X-Response-Time", `${totalTime}ms`);
1341
1370
  });
1342
1371
  apiRoutes.use("*", async (c, next) => {
1343
- const cacheEnabled = await isPluginActive(c.env.DB, "core-cache");
1372
+ const bypass = c.req.header("Cache-Control") === "no-cache";
1373
+ const cacheEnabled = !bypass && await isPluginActive(c.env.DB, "core-cache");
1344
1374
  c.set("cacheEnabled", cacheEnabled);
1345
1375
  await next();
1346
1376
  });
@@ -1871,7 +1901,7 @@ apiRoutes.get("/content", optionalAuth(), async (c) => {
1871
1901
  details: queryResult.errors
1872
1902
  }, 400);
1873
1903
  }
1874
- const cacheEnabled = c.get("cacheEnabled") && cAnon;
1904
+ const cacheEnabled = c.get("cacheEnabled") && !cNeedsAcl;
1875
1905
  const cache = getCacheService(CACHE_CONFIGS.api);
1876
1906
  const cacheKey = cache.generateKey("content-filtered", JSON.stringify({ filter: normalizedFilter, query: queryResult.sql }));
1877
1907
  if (cacheEnabled) {
@@ -1893,8 +1923,20 @@ apiRoutes.get("/content", optionalAuth(), async (c) => {
1893
1923
  }
1894
1924
  }, executionStart)
1895
1925
  };
1926
+ recordCatalogRequest({ cacheKey, collection: typeId ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: cacheResult.source });
1927
+ scheduleKvWrite(cacheKey, c.executionCtx);
1896
1928
  return c.json(dataWithMeta);
1897
1929
  }
1930
+ const swrData = getAndConsumeStale(cacheKey);
1931
+ if (swrData) {
1932
+ c.header("X-Cache-Status", "STALE");
1933
+ c.header("X-Cache-Source", "swr");
1934
+ recordCatalogRequest({ cacheKey, collection: typeId ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: "swr" });
1935
+ scheduleKvWrite(cacheKey, c.executionCtx);
1936
+ return c.json({ ...swrData, meta: addTimingMeta(c, { ...swrData.meta, cache: { hit: true, source: "swr", stale: true } }, executionStart) });
1937
+ }
1938
+ recordCatalogRequest({ cacheKey, collection: typeId ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: "miss" });
1939
+ scheduleKvWrite(cacheKey, c.executionCtx);
1898
1940
  }
1899
1941
  c.header("X-Cache-Status", "MISS");
1900
1942
  c.header("X-Cache-Source", "database");
@@ -1995,7 +2037,7 @@ apiRoutes.get("/collections/:collection/content", optionalAuth(), async (c) => {
1995
2037
  details: queryResult.errors
1996
2038
  }, 400);
1997
2039
  }
1998
- const cacheEnabled = c.get("cacheEnabled") && ccAnon;
2040
+ const cacheEnabled = c.get("cacheEnabled") && !ccNeedsAcl;
1999
2041
  const cache = getCacheService(CACHE_CONFIGS.api);
2000
2042
  const includeCollection = queryParams.include?.split(",").map((s) => s.trim()).includes("collection");
2001
2043
  const cacheKey = cache.generateKey("collection-content-filtered", `${collection}:${JSON.stringify({ filter: normalizedFilter, query: queryResult.sql, includeCollection })}`);
@@ -2018,8 +2060,20 @@ apiRoutes.get("/collections/:collection/content", optionalAuth(), async (c) => {
2018
2060
  }
2019
2061
  }, executionStart)
2020
2062
  };
2063
+ recordCatalogRequest({ cacheKey, collection: collection ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: cacheResult.source });
2064
+ scheduleKvWrite(cacheKey, c.executionCtx);
2021
2065
  return c.json(dataWithMeta);
2022
2066
  }
2067
+ const swrData = getAndConsumeStale(cacheKey);
2068
+ if (swrData) {
2069
+ c.header("X-Cache-Status", "STALE");
2070
+ c.header("X-Cache-Source", "swr");
2071
+ recordCatalogRequest({ cacheKey, collection: collection ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: "swr" });
2072
+ scheduleKvWrite(cacheKey, c.executionCtx);
2073
+ return c.json({ ...swrData, meta: addTimingMeta(c, { ...swrData.meta, cache: { hit: true, source: "swr", stale: true } }, executionStart) });
2074
+ }
2075
+ recordCatalogRequest({ cacheKey, collection: collection ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: "miss" });
2076
+ scheduleKvWrite(cacheKey, c.executionCtx);
2023
2077
  }
2024
2078
  c.header("X-Cache-Status", "MISS");
2025
2079
  c.header("X-Cache-Source", "database");
@@ -2103,7 +2157,7 @@ apiRoutes.get("/:collection", optionalAuth(), async (c) => {
2103
2157
  }
2104
2158
  const collectionCache = record.cache;
2105
2159
  const collectionCacheDisabled = collectionCache?.enabled === false;
2106
- const cacheEnabled = c.get("cacheEnabled") && !collectionCacheDisabled && projFields.length === 0 && anon;
2160
+ const cacheEnabled = c.get("cacheEnabled") && !collectionCacheDisabled && projFields.length === 0 && !needsAcl;
2107
2161
  const cache = getCacheService(CACHE_CONFIGS.api);
2108
2162
  const includeCollection = queryParams.include?.split(",").map((s) => s.trim()).includes("collection");
2109
2163
  const cacheKey = cache.generateKey("collection-content-filtered", `${collection}:${JSON.stringify({ filter: normalizedFilter, query: queryResult.sql, includeCollection })}`);
@@ -2113,8 +2167,20 @@ apiRoutes.get("/:collection", optionalAuth(), async (c) => {
2113
2167
  c.header("X-Cache-Status", "HIT");
2114
2168
  c.header("X-Cache-Source", cacheResult.source);
2115
2169
  if (cacheResult.ttl) c.header("X-Cache-TTL", Math.floor(cacheResult.ttl).toString());
2170
+ recordCatalogRequest({ cacheKey, collection: collection ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: cacheResult.source });
2171
+ scheduleKvWrite(cacheKey, c.executionCtx);
2116
2172
  return c.json({ ...cacheResult.data, meta: addTimingMeta(c, { ...cacheResult.data.meta, cache: { hit: true, source: cacheResult.source, ttl: cacheResult.ttl ? Math.floor(cacheResult.ttl) : void 0 } }, executionStart) });
2117
2173
  }
2174
+ const swrData = getAndConsumeStale(cacheKey);
2175
+ if (swrData) {
2176
+ c.header("X-Cache-Status", "STALE");
2177
+ c.header("X-Cache-Source", "swr");
2178
+ recordCatalogRequest({ cacheKey, collection: collection ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: "swr" });
2179
+ scheduleKvWrite(cacheKey, c.executionCtx);
2180
+ return c.json({ ...swrData, meta: addTimingMeta(c, { ...swrData.meta, cache: { hit: true, source: "swr", stale: true } }, executionStart) });
2181
+ }
2182
+ recordCatalogRequest({ cacheKey, collection: collection ?? null, path: c.req.path, queryString: c.req.raw.url.split("?")[1] ?? "", source: "miss" });
2183
+ scheduleKvWrite(cacheKey, c.executionCtx);
2118
2184
  }
2119
2185
  c.header("X-Cache-Status", "MISS");
2120
2186
  c.header("X-Cache-Source", "database");
@@ -2229,6 +2295,9 @@ apiRoutes.post("/:collection", requireAuth(), requireRole(["admin", "editor", "a
2229
2295
  const svc = new 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 });
2230
2296
  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);
2231
2297
  const cache = getCacheService(CACHE_CONFIGS.api);
2298
+ const createAffectedKeys = (await cache.listKeys()).map((k) => k.key).filter((k) => k.startsWith("api:content-filtered:") || k.startsWith(`api:collection-content-filtered:${backing.coll.name}:`));
2299
+ const createStaleValues = await cache.getMany(createAffectedKeys);
2300
+ for (const [key, val] of createStaleValues) markStale(key, val, backing.coll.name);
2232
2301
  await cache.invalidate("api:content-filtered:*");
2233
2302
  await cache.invalidate(`api:collection-content-filtered:${backing.coll.name}:*`);
2234
2303
  dispatchHookEvent(c, "content:after:create", { collection: backing.coll.name, id: doc.rootId, data: doc.data ?? {}, user: actor }, "fire-and-forget");
@@ -2272,6 +2341,9 @@ apiRoutes.put("/:collection/:id", requireAuth(), requireRole(["admin", "editor",
2272
2341
  await svc.unpublish(pub.id);
2273
2342
  }
2274
2343
  const cache = getCacheService(CACHE_CONFIGS.api);
2344
+ const updateAffectedKeys = (await cache.listKeys()).map((k) => k.key).filter((k) => k.startsWith("api:content-filtered:") || k.startsWith(`api:collection-content-filtered:${docRow.type_id}:`));
2345
+ const updateStaleValues = await cache.getMany(updateAffectedKeys);
2346
+ for (const [key, val] of updateStaleValues) markStale(key, val, docRow.type_id);
2275
2347
  await cache.invalidate("api:content-filtered:*");
2276
2348
  await cache.invalidate(`api:collection-content-filtered:${docRow.type_id}:*`);
2277
2349
  const coll = getCollectionRegistry().getByName(docRow.type_id);
@@ -2305,6 +2377,9 @@ apiRoutes.delete("/:collection/:id", requireAuth(), requireRole(["admin", "edito
2305
2377
  const now = Math.floor(Date.now() / 1e3);
2306
2378
  await db.prepare("UPDATE documents SET deleted_at = ?, updated_at = ? WHERE root_id = ? AND tenant_id = 'default'").bind(now, now, id).run();
2307
2379
  const cache = getCacheService(CACHE_CONFIGS.api);
2380
+ const deleteAffectedKeys = (await cache.listKeys()).map((k) => k.key).filter((k) => k.startsWith("api:content-filtered:") || k.startsWith(`api:collection-content-filtered:${docRow.type_id}:`));
2381
+ const deleteStaleValues = await cache.getMany(deleteAffectedKeys);
2382
+ for (const [key, val] of deleteStaleValues) markStale(key, val, docRow.type_id);
2308
2383
  await cache.invalidate("api:content-filtered:*");
2309
2384
  await cache.invalidate(`api:collection-content-filtered:${docRow.type_id}:*`);
2310
2385
  dispatchHookEvent(c, "content:after:delete", { collection: docRow.type_id, id, data: {}, user: actor }, "fire-and-forget");
@@ -3584,7 +3659,7 @@ adminApiRoutes.patch("/collections/:id", collectionsReadOnly);
3584
3659
  adminApiRoutes.delete("/collections/:id", collectionsReadOnly);
3585
3660
  adminApiRoutes.get("/migrations/status", async (c) => {
3586
3661
  try {
3587
- const { MigrationService: MigrationService2 } = await import('./migrations-JAHMI5MK.js');
3662
+ const { MigrationService: MigrationService2 } = await import('./migrations-GZ2HIB4I.js');
3588
3663
  const db = c.env.DB;
3589
3664
  const migrationService = new MigrationService2(db);
3590
3665
  const status = await migrationService.getMigrationStatus();
@@ -3627,7 +3702,7 @@ adminApiRoutes.post("/migrations/run", async (c) => {
3627
3702
  });
3628
3703
  adminApiRoutes.get("/migrations/validate", async (c) => {
3629
3704
  try {
3630
- const { MigrationService: MigrationService2 } = await import('./migrations-JAHMI5MK.js');
3705
+ const { MigrationService: MigrationService2 } = await import('./migrations-GZ2HIB4I.js');
3631
3706
  const db = c.env.DB;
3632
3707
  const migrationService = new MigrationService2(db);
3633
3708
  const validation = await migrationService.validateSchema();
@@ -7278,6 +7353,15 @@ function createUserProfilesPlugin() {
7278
7353
  return userProfilesPlugin;
7279
7354
  }
7280
7355
 
7356
+ // src/services/demo-mode.ts
7357
+ var _demoModeActive = false;
7358
+ function setDemoModeActive() {
7359
+ _demoModeActive = true;
7360
+ }
7361
+ function isDemoModeActive() {
7362
+ return _demoModeActive;
7363
+ }
7364
+
7281
7365
  // src/routes/auth.ts
7282
7366
  var JWT_SECRET_FALLBACK = "your-super-secret-jwt-key-change-in-production";
7283
7367
  var DEMO_EMAIL = "admin@sonicjs.com";
@@ -7344,13 +7428,7 @@ authRoutes.get("/login", async (c) => {
7344
7428
  version: c.get("appVersion"),
7345
7429
  redirect: redirect && redirect.startsWith("/") ? redirect : void 0
7346
7430
  };
7347
- const db = c.env.DB;
7348
- let demoLoginActive = false;
7349
- try {
7350
- const plugin = await db.prepare("SELECT * FROM plugins WHERE id = ? AND status = ?").bind("demo-login-prefill", "active").first();
7351
- demoLoginActive = !!plugin;
7352
- } catch (error2) {
7353
- }
7431
+ const demoLoginActive = isDemoModeActive();
7354
7432
  return c.html(renderLoginPage(pageData, demoLoginActive));
7355
7433
  });
7356
7434
  authRoutes.get("/register", async (c) => {
@@ -7486,7 +7564,7 @@ authRoutes.post(
7486
7564
  }
7487
7565
  const { email, password } = validation.data;
7488
7566
  const normalizedEmail = email.toLowerCase();
7489
- const { createAuth } = await import('./config-4TIHSNW6.js');
7567
+ const { createAuth } = await import('./config-DOAWXZBG.js');
7490
7568
  const auth = createAuth(c.env, void 0, new URL(c.req.url).origin);
7491
7569
  const baReq = new Request(new URL("/auth/sign-in/email", c.req.url).href, {
7492
7570
  method: "POST",
@@ -7545,7 +7623,7 @@ authRoutes.post(
7545
7623
  );
7546
7624
  authRoutes.post("/logout", async (c) => {
7547
7625
  try {
7548
- const { createAuth } = await import('./config-4TIHSNW6.js');
7626
+ const { createAuth } = await import('./config-DOAWXZBG.js');
7549
7627
  const auth = createAuth(c.env, void 0, new URL(c.req.url).origin);
7550
7628
  const baReq = new Request(new URL("/auth/sign-out", c.req.url).href, {
7551
7629
  method: "POST",
@@ -7562,7 +7640,7 @@ authRoutes.post("/logout", async (c) => {
7562
7640
  });
7563
7641
  authRoutes.get("/logout", async (c) => {
7564
7642
  try {
7565
- const { createAuth } = await import('./config-4TIHSNW6.js');
7643
+ const { createAuth } = await import('./config-DOAWXZBG.js');
7566
7644
  const auth = createAuth(c.env, void 0, new URL(c.req.url).origin);
7567
7645
  const baReq = new Request(new URL("/auth/sign-out", c.req.url).href, {
7568
7646
  method: "POST",
@@ -7770,7 +7848,7 @@ authRoutes.post(
7770
7848
  </div>
7771
7849
  `);
7772
7850
  }
7773
- const { createAuth } = await import('./config-4TIHSNW6.js');
7851
+ const { createAuth } = await import('./config-DOAWXZBG.js');
7774
7852
  const auth = createAuth(c.env, void 0, new URL(c.req.url).origin);
7775
7853
  const baReq = new Request(new URL("/auth/sign-in/email", c.req.url).href, {
7776
7854
  method: "POST",
@@ -27402,6 +27480,6 @@ var ROUTES_INFO = {
27402
27480
  reference: "https://github.com/sonicjs/sonicjs"
27403
27481
  };
27404
27482
 
27405
- export { DocumentRepository, ROUTES_INFO, TenantService, VALID_MEMBER_ROLES, adminCheckboxRoutes, adminCollectionsRoutes, adminDocumentsRoutes, adminLogsRoutes, adminMediaRoutes, adminPluginRoutes, adminSettingsRoutes, admin_api_default, admin_content_default, apiDocumentsRoutes, api_content_crud_default, api_default, api_media_default, api_system_default, auth_default, createDocumentSchema, createUserProfilesPlugin, defineUserProfile, denyIfNotAllowed, dispatchHookEvent, effectiveTenantForType, getConfirmationDialogScript2 as getConfirmationDialogScript, getCustomData, getDocumentRequestContext, getEmailService, getUserProfileConfig, getVariablesCached, hasEmailService, invalidateVariablesCache, isValidMemberRole, lexicalEditorPlugin, reconcileMenuFromPlugins, renderConfirmationDialog2 as renderConfirmationDialog, renderTable2 as renderTable, resolveDocScope, resolveVariablesInObject, router, router2, setEmailService, setVariablesCache, test_cleanup_default, updateDocumentSchema, userProfilesPlugin, userRoutes };
27406
- //# sourceMappingURL=chunk-7P5OCUPS.js.map
27407
- //# sourceMappingURL=chunk-7P5OCUPS.js.map
27483
+ export { DocumentRepository, ROUTES_INFO, TenantService, VALID_MEMBER_ROLES, adminCheckboxRoutes, adminCollectionsRoutes, adminDocumentsRoutes, adminLogsRoutes, adminMediaRoutes, adminPluginRoutes, adminSettingsRoutes, admin_api_default, admin_content_default, apiDocumentsRoutes, api_content_crud_default, api_default, api_media_default, api_system_default, auth_default, createDocumentSchema, createUserProfilesPlugin, defineUserProfile, denyIfNotAllowed, dispatchHookEvent, effectiveTenantForType, getConfirmationDialogScript2 as getConfirmationDialogScript, getCustomData, getDocumentRequestContext, getEmailService, getUserProfileConfig, getVariablesCached, hasEmailService, invalidateVariablesCache, isValidMemberRole, lexicalEditorPlugin, reconcileMenuFromPlugins, renderConfirmationDialog2 as renderConfirmationDialog, renderTable2 as renderTable, resolveDocScope, resolveVariablesInObject, router, router2, setDemoModeActive, setEmailService, setVariablesCache, swrStats, test_cleanup_default, updateDocumentSchema, userProfilesPlugin, userRoutes };
27484
+ //# sourceMappingURL=chunk-OJFIQGZB.js.map
27485
+ //# sourceMappingURL=chunk-OJFIQGZB.js.map