@sonicjs-cms/core 2.18.1 → 3.0.0-beta.10

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 (232) hide show
  1. package/README.md +52 -52
  2. package/dist/admin-documents-form.template-DDSH6ROU.js +6 -0
  3. package/dist/{admin-layout-catalyst.template-UMTIN66R.js.map → admin-documents-form.template-DDSH6ROU.js.map} +1 -1
  4. package/dist/admin-documents-form.template-LSZKGA5J.cjs +19 -0
  5. package/dist/{admin-layout-catalyst.template-HFD37TY5.cjs.map → admin-documents-form.template-LSZKGA5J.cjs.map} +1 -1
  6. package/dist/{filter-bar.template-DlVYMk-T.d.cts → admin-layout-catalyst.template-DrwDUfsE.d.cts} +25 -1
  7. package/dist/{filter-bar.template-DlVYMk-T.d.ts → admin-layout-catalyst.template-DrwDUfsE.d.ts} +25 -1
  8. package/dist/admin-layout-catalyst.template-KDHKVLXR.cjs +21 -0
  9. package/dist/admin-layout-catalyst.template-KDHKVLXR.cjs.map +1 -0
  10. package/dist/admin-layout-catalyst.template-YQ4EMF2J.js +7 -0
  11. package/dist/admin-layout-catalyst.template-YQ4EMF2J.js.map +1 -0
  12. package/dist/app-Bo0X1OWX.d.ts +1268 -0
  13. package/dist/app-Do66yCcV.d.cts +1268 -0
  14. package/dist/cache-DDARE4QE.js +4 -0
  15. package/dist/cache-DDARE4QE.js.map +1 -0
  16. package/dist/cache-LVYS4BPL.cjs +33 -0
  17. package/dist/cache-LVYS4BPL.cjs.map +1 -0
  18. package/dist/chunk-2CB4KY7I.cjs +771 -0
  19. package/dist/chunk-2CB4KY7I.cjs.map +1 -0
  20. package/dist/{chunk-ABB34XUS.cjs → chunk-3KYKEXV7.cjs} +667 -19
  21. package/dist/chunk-3KYKEXV7.cjs.map +1 -0
  22. package/dist/chunk-4BTBSXMR.cjs +912 -0
  23. package/dist/chunk-4BTBSXMR.cjs.map +1 -0
  24. package/dist/{chunk-55RDMDOP.js → chunk-5V62WT6M.js} +181 -57
  25. package/dist/chunk-5V62WT6M.js.map +1 -0
  26. package/dist/{chunk-XXDFQERJ.js → chunk-6OC6MF3C.js} +7192 -9806
  27. package/dist/chunk-6OC6MF3C.js.map +1 -0
  28. package/dist/chunk-AI663NBO.js +821 -0
  29. package/dist/chunk-AI663NBO.js.map +1 -0
  30. package/dist/chunk-ALDRXTUO.js +273 -0
  31. package/dist/chunk-ALDRXTUO.js.map +1 -0
  32. package/dist/{chunk-TFNTM3OA.js → chunk-ATUPB6MN.js} +645 -15
  33. package/dist/chunk-ATUPB6MN.js.map +1 -0
  34. package/dist/chunk-BLMTL57B.js +767 -0
  35. package/dist/chunk-BLMTL57B.js.map +1 -0
  36. package/dist/{chunk-4ZSNJDLS.cjs → chunk-CRGUD4KC.cjs} +9 -9
  37. package/dist/chunk-CRGUD4KC.cjs.map +1 -0
  38. package/dist/chunk-F67UK75A.cjs +158 -0
  39. package/dist/chunk-F67UK75A.cjs.map +1 -0
  40. package/dist/chunk-GCDZZNIN.js +192 -0
  41. package/dist/chunk-GCDZZNIN.js.map +1 -0
  42. package/dist/chunk-HIKBY7MS.cjs +70 -0
  43. package/dist/chunk-HIKBY7MS.cjs.map +1 -0
  44. package/dist/chunk-IDCZBF35.js +1186 -0
  45. package/dist/chunk-IDCZBF35.js.map +1 -0
  46. package/dist/chunk-IESEVHXL.js +66 -0
  47. package/dist/chunk-IESEVHXL.js.map +1 -0
  48. package/dist/chunk-IGADDMXH.js +387 -0
  49. package/dist/chunk-IGADDMXH.js.map +1 -0
  50. package/dist/chunk-IHTXB7AT.cjs +276 -0
  51. package/dist/chunk-IHTXB7AT.cjs.map +1 -0
  52. package/dist/chunk-IVPRUGTY.js +242 -0
  53. package/dist/chunk-IVPRUGTY.js.map +1 -0
  54. package/dist/{chunk-SQ6FNXU2.cjs → chunk-IXUHXTHW.cjs} +2 -151
  55. package/dist/chunk-IXUHXTHW.cjs.map +1 -0
  56. package/dist/chunk-J6JTWD2A.cjs +100 -0
  57. package/dist/chunk-J6JTWD2A.cjs.map +1 -0
  58. package/dist/chunk-JEQ7FLOD.cjs +199 -0
  59. package/dist/chunk-JEQ7FLOD.cjs.map +1 -0
  60. package/dist/{chunk-ON5ZMSU4.js → chunk-JQISFW6U.js} +3 -3
  61. package/dist/chunk-JQISFW6U.js.map +1 -0
  62. package/dist/chunk-K25XHMM3.js +566 -0
  63. package/dist/chunk-K25XHMM3.js.map +1 -0
  64. package/dist/{chunk-UYJ6TJHX.cjs → chunk-K623Q6WD.cjs} +181 -56
  65. package/dist/chunk-K623Q6WD.cjs.map +1 -0
  66. package/dist/chunk-MUNO67TT.cjs +1219 -0
  67. package/dist/chunk-MUNO67TT.cjs.map +1 -0
  68. package/dist/chunk-N32OWET6.cjs +327 -0
  69. package/dist/chunk-N32OWET6.cjs.map +1 -0
  70. package/dist/chunk-NUKJ54GA.cjs +245 -0
  71. package/dist/chunk-NUKJ54GA.cjs.map +1 -0
  72. package/dist/{chunk-XWIA3HVX.js → chunk-OBA2RYZN.js} +6 -1249
  73. package/dist/chunk-OBA2RYZN.js.map +1 -0
  74. package/dist/chunk-PMGOBS6X.cjs +408 -0
  75. package/dist/chunk-PMGOBS6X.cjs.map +1 -0
  76. package/dist/{chunk-OHYBNCVL.cjs → chunk-PXNTCCPE.cjs} +10 -1256
  77. package/dist/chunk-PXNTCCPE.cjs.map +1 -0
  78. package/dist/chunk-PYVFXCSD.js +1828 -0
  79. package/dist/chunk-PYVFXCSD.js.map +1 -0
  80. package/dist/{chunk-MGFRZO24.js → chunk-QZGABF2M.js} +3 -149
  81. package/dist/chunk-QZGABF2M.js.map +1 -0
  82. package/dist/{chunk-T3Q5V33G.cjs → chunk-R4ILO3W6.cjs} +876 -829
  83. package/dist/chunk-R4ILO3W6.cjs.map +1 -0
  84. package/dist/chunk-RMRJGMDE.js +323 -0
  85. package/dist/chunk-RMRJGMDE.js.map +1 -0
  86. package/dist/chunk-RNZFGN4R.js +88 -0
  87. package/dist/chunk-RNZFGN4R.js.map +1 -0
  88. package/dist/chunk-RQ6N3FTV.js +900 -0
  89. package/dist/chunk-RQ6N3FTV.js.map +1 -0
  90. package/dist/{chunk-SXXTQETM.cjs → chunk-TO6EY4P7.cjs} +8722 -11323
  91. package/dist/chunk-TO6EY4P7.cjs.map +1 -0
  92. package/dist/chunk-V464XBYS.js +154 -0
  93. package/dist/chunk-V464XBYS.js.map +1 -0
  94. package/dist/chunk-YA3TJ65D.cjs +575 -0
  95. package/dist/chunk-YA3TJ65D.cjs.map +1 -0
  96. package/dist/chunk-YP7GW2G5.cjs +866 -0
  97. package/dist/chunk-YP7GW2G5.cjs.map +1 -0
  98. package/dist/{collection-config-B4PG-AaF.d.cts → collection-config-JgHOpFCG.d.cts} +30 -2
  99. package/dist/{collection-config-B4PG-AaF.d.ts → collection-config-JgHOpFCG.d.ts} +30 -2
  100. package/dist/config-HFXANXCC.js +6 -0
  101. package/dist/config-HFXANXCC.js.map +1 -0
  102. package/dist/config-ON6FNMYX.cjs +19 -0
  103. package/dist/config-ON6FNMYX.cjs.map +1 -0
  104. package/dist/define-plugin-BzNHc1ZI.d.ts +1321 -0
  105. package/dist/define-plugin-IWDKYaVm.d.cts +1321 -0
  106. package/dist/document-projection-TDWRJX3Z.cjs +13 -0
  107. package/dist/document-projection-TDWRJX3Z.cjs.map +1 -0
  108. package/dist/document-projection-YYMC6I4U.js +4 -0
  109. package/dist/document-projection-YYMC6I4U.js.map +1 -0
  110. package/dist/index.cjs +13737 -4327
  111. package/dist/index.cjs.map +1 -1
  112. package/dist/index.d.cts +331 -493
  113. package/dist/index.d.ts +331 -493
  114. package/dist/index.js +13456 -4068
  115. package/dist/index.js.map +1 -1
  116. package/dist/middleware.cjs +38 -32
  117. package/dist/middleware.d.cts +69 -7
  118. package/dist/middleware.d.ts +69 -7
  119. package/dist/middleware.js +9 -3
  120. package/dist/migrations-2XHQEGOQ.cjs +13 -0
  121. package/dist/{migrations-IYNTWDC6.cjs.map → migrations-2XHQEGOQ.cjs.map} +1 -1
  122. package/dist/migrations-PE3CDVSM.js +4 -0
  123. package/dist/{migrations-R337UD46.js.map → migrations-PE3CDVSM.js.map} +1 -1
  124. package/dist/{plugin-bootstrap-DfVerYV4.d.cts → plugin-bootstrap-B8ThJU21.d.cts} +4315 -1661
  125. package/dist/{plugin-bootstrap-P_ciLp_C.d.ts → plugin-bootstrap-qu8hJgUt.d.ts} +4315 -1661
  126. package/dist/plugins.cjs +171 -12
  127. package/dist/plugins.d.cts +36 -2
  128. package/dist/plugins.d.ts +36 -2
  129. package/dist/plugins.js +5 -2
  130. package/dist/rbac-O73MFKDA.js +5 -0
  131. package/dist/rbac-O73MFKDA.js.map +1 -0
  132. package/dist/rbac-VONLJJKB.cjs +14 -0
  133. package/dist/rbac-VONLJJKB.cjs.map +1 -0
  134. package/dist/routes.cjs +42 -46
  135. package/dist/routes.d.cts +56 -146
  136. package/dist/routes.d.ts +56 -146
  137. package/dist/routes.js +18 -10
  138. package/dist/services.cjs +43 -76
  139. package/dist/services.d.cts +93 -55
  140. package/dist/services.d.ts +93 -55
  141. package/dist/services.js +6 -3
  142. package/dist/{telemetry-B9vIV4wh.d.cts → telemetry-Cku1ax74.d.cts} +1 -1
  143. package/dist/{telemetry-B9vIV4wh.d.ts → telemetry-Cku1ax74.d.ts} +1 -1
  144. package/dist/templates.cjs +17 -29
  145. package/dist/templates.d.cts +2 -89
  146. package/dist/templates.d.ts +2 -89
  147. package/dist/templates.js +3 -3
  148. package/dist/types-Dea1eNxU.d.cts +286 -0
  149. package/dist/types-Dea1eNxU.d.ts +286 -0
  150. package/dist/types.d.cts +2 -2
  151. package/dist/types.d.ts +2 -2
  152. package/dist/utils.cjs +21 -20
  153. package/dist/utils.d.cts +2 -2
  154. package/dist/utils.d.ts +2 -2
  155. package/dist/utils.js +3 -2
  156. package/migrations/0001_core.sql +184 -0
  157. package/migrations/0002_documents.sql +163 -0
  158. package/package.json +12 -7
  159. package/dist/admin-layout-catalyst.template-HFD37TY5.cjs +0 -17
  160. package/dist/admin-layout-catalyst.template-UMTIN66R.js +0 -7
  161. package/dist/app-C9esKLmh.d.cts +0 -112
  162. package/dist/app-C9esKLmh.d.ts +0 -112
  163. package/dist/chunk-4R3NOOL3.js +0 -2217
  164. package/dist/chunk-4R3NOOL3.js.map +0 -1
  165. package/dist/chunk-4ZSNJDLS.cjs.map +0 -1
  166. package/dist/chunk-55RDMDOP.js.map +0 -1
  167. package/dist/chunk-635JAMSE.cjs +0 -653
  168. package/dist/chunk-635JAMSE.cjs.map +0 -1
  169. package/dist/chunk-ABB34XUS.cjs.map +0 -1
  170. package/dist/chunk-C54YUA23.cjs +0 -2219
  171. package/dist/chunk-C54YUA23.cjs.map +0 -1
  172. package/dist/chunk-DSUJ5YQH.cjs +0 -722
  173. package/dist/chunk-DSUJ5YQH.cjs.map +0 -1
  174. package/dist/chunk-EW5NOBVU.js +0 -1783
  175. package/dist/chunk-EW5NOBVU.js.map +0 -1
  176. package/dist/chunk-EXNEW5US.js +0 -648
  177. package/dist/chunk-EXNEW5US.js.map +0 -1
  178. package/dist/chunk-I2H5NGJQ.js +0 -692
  179. package/dist/chunk-I2H5NGJQ.js.map +0 -1
  180. package/dist/chunk-MGFRZO24.js.map +0 -1
  181. package/dist/chunk-OHYBNCVL.cjs.map +0 -1
  182. package/dist/chunk-ON5ZMSU4.js.map +0 -1
  183. package/dist/chunk-QFWHAFEO.js +0 -1843
  184. package/dist/chunk-QFWHAFEO.js.map +0 -1
  185. package/dist/chunk-SQ6FNXU2.cjs.map +0 -1
  186. package/dist/chunk-SXXTQETM.cjs.map +0 -1
  187. package/dist/chunk-T3Q5V33G.cjs.map +0 -1
  188. package/dist/chunk-TFNTM3OA.js.map +0 -1
  189. package/dist/chunk-UYJ6TJHX.cjs.map +0 -1
  190. package/dist/chunk-WAEQXGCX.cjs +0 -1898
  191. package/dist/chunk-WAEQXGCX.cjs.map +0 -1
  192. package/dist/chunk-XWIA3HVX.js.map +0 -1
  193. package/dist/chunk-XXDFQERJ.js.map +0 -1
  194. package/dist/migrations-IYNTWDC6.cjs +0 -13
  195. package/dist/migrations-R337UD46.js +0 -4
  196. package/dist/plugin-manager-BoM3Q7o7.d.cts +0 -328
  197. package/dist/plugin-manager-Efx9RyDX.d.ts +0 -328
  198. package/migrations/001_initial_schema.sql +0 -170
  199. package/migrations/002_faq_plugin.sql +0 -86
  200. package/migrations/003_stage5_enhancements.sql +0 -121
  201. package/migrations/004_stage6_user_management.sql +0 -183
  202. package/migrations/005_stage7_workflow_automation.sql +0 -294
  203. package/migrations/006_plugin_system.sql +0 -155
  204. package/migrations/007_demo_login_plugin.sql +0 -23
  205. package/migrations/008_fix_slug_validation.sql +0 -22
  206. package/migrations/009_system_logging.sql +0 -57
  207. package/migrations/011_config_managed_collections.sql +0 -15
  208. package/migrations/012_testimonials_plugin.sql +0 -80
  209. package/migrations/013_code_examples_plugin.sql +0 -177
  210. package/migrations/014_fix_plugin_registry.sql +0 -88
  211. package/migrations/015_add_remaining_plugins.sql +0 -89
  212. package/migrations/016_remove_duplicate_cache_plugin.sql +0 -17
  213. package/migrations/017_auth_configurable_fields.sql +0 -49
  214. package/migrations/018_settings_table.sql +0 -23
  215. package/migrations/019_remove_blog_posts_collection.sql +0 -15
  216. package/migrations/020_add_email_plugin.sql +0 -22
  217. package/migrations/021_add_magic_link_auth_plugin.sql +0 -42
  218. package/migrations/022_add_tinymce_plugin.sql +0 -25
  219. package/migrations/023_add_easy_mdx_plugin.sql +0 -25
  220. package/migrations/024_add_quill_editor_plugin.sql +0 -25
  221. package/migrations/025_add_easymde_plugin.sql +0 -25
  222. package/migrations/026_add_otp_login.sql +0 -42
  223. package/migrations/027_fix_slug_field_type.sql +0 -18
  224. package/migrations/028_fix_slug_field_type_in_schemas.sql +0 -30
  225. package/migrations/029_add_forms_system.sql +0 -184
  226. package/migrations/030_add_turnstile_to_forms.sql +0 -14
  227. package/migrations/031_ai_search_plugin.sql +0 -45
  228. package/migrations/032_user_profiles.sql +0 -37
  229. package/migrations/033_form_content_integration.sql +0 -19
  230. package/migrations/034_security_audit_plugin.sql +0 -27
  231. package/migrations/035_user_profiles_data_column.sql +0 -16
  232. package/migrations/036_analytics_events.sql +0 -22
@@ -0,0 +1,912 @@
1
+ 'use strict';
2
+
3
+ var chunkYA3TJ65D_cjs = require('./chunk-YA3TJ65D.cjs');
4
+ var chunkYP7GW2G5_cjs = require('./chunk-YP7GW2G5.cjs');
5
+ var d1 = require('drizzle-orm/d1');
6
+ var drizzleOrm = require('drizzle-orm');
7
+ var dev = require('hono/dev');
8
+
9
+ var Logger = class {
10
+ db;
11
+ enabled = true;
12
+ configCache = /* @__PURE__ */ new Map();
13
+ lastConfigRefresh = 0;
14
+ configRefreshInterval = 6e4;
15
+ // 1 minute
16
+ constructor(database) {
17
+ this.db = d1.drizzle(database);
18
+ }
19
+ /**
20
+ * Log a debug message
21
+ */
22
+ async debug(category, message, data, context) {
23
+ return this.log("debug", category, message, data, context);
24
+ }
25
+ /**
26
+ * Log an info message
27
+ */
28
+ async info(category, message, data, context) {
29
+ return this.log("info", category, message, data, context);
30
+ }
31
+ /**
32
+ * Log a warning message
33
+ */
34
+ async warn(category, message, data, context) {
35
+ return this.log("warn", category, message, data, context);
36
+ }
37
+ /**
38
+ * Log an error message
39
+ */
40
+ async error(category, message, error, context) {
41
+ const errorData = error instanceof Error ? {
42
+ name: error.name,
43
+ message: error.message,
44
+ stack: error.stack
45
+ } : error;
46
+ return this.log("error", category, message, errorData, {
47
+ ...context,
48
+ stackTrace: error instanceof Error ? error.stack : void 0
49
+ });
50
+ }
51
+ /**
52
+ * Log a fatal message
53
+ */
54
+ async fatal(category, message, error, context) {
55
+ const errorData = error instanceof Error ? {
56
+ name: error.name,
57
+ message: error.message,
58
+ stack: error.stack
59
+ } : error;
60
+ return this.log("fatal", category, message, errorData, {
61
+ ...context,
62
+ stackTrace: error instanceof Error ? error.stack : void 0
63
+ });
64
+ }
65
+ /**
66
+ * Log an API request
67
+ */
68
+ async logRequest(method, url, statusCode, duration, context) {
69
+ const level = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "info";
70
+ return this.log(level, "api", `${method} ${url} - ${statusCode}`, {
71
+ method,
72
+ url,
73
+ statusCode,
74
+ duration
75
+ }, {
76
+ ...context,
77
+ method,
78
+ url,
79
+ statusCode,
80
+ duration
81
+ });
82
+ }
83
+ /**
84
+ * Log an authentication event
85
+ */
86
+ async logAuth(action, userId, success = true, context) {
87
+ const level = success ? "info" : "warn";
88
+ return this.log(level, "auth", `Authentication ${action}: ${success ? "success" : "failed"}`, {
89
+ action,
90
+ success,
91
+ userId
92
+ }, {
93
+ ...context,
94
+ userId,
95
+ tags: ["authentication", action]
96
+ });
97
+ }
98
+ /**
99
+ * Log a security event
100
+ */
101
+ async logSecurity(event, severity, context) {
102
+ const level = severity === "critical" ? "fatal" : severity === "high" ? "error" : "warn";
103
+ return this.log(level, "security", `Security event: ${event}`, {
104
+ event,
105
+ severity
106
+ }, {
107
+ ...context,
108
+ tags: ["security", severity]
109
+ });
110
+ }
111
+ /**
112
+ * Core logging method
113
+ */
114
+ async log(level, category, message, data, context) {
115
+ if (!this.enabled) return;
116
+ try {
117
+ const config = await this.getConfig(category);
118
+ if (!config || !config.enabled || !this.shouldLog(level, config.level)) {
119
+ return;
120
+ }
121
+ const logEntry = {
122
+ id: crypto.randomUUID(),
123
+ level,
124
+ category,
125
+ message,
126
+ data: data ? JSON.stringify(data) : null,
127
+ userId: context?.userId || null,
128
+ sessionId: context?.sessionId || null,
129
+ requestId: context?.requestId || null,
130
+ ipAddress: context?.ipAddress || null,
131
+ userAgent: context?.userAgent || null,
132
+ method: context?.method || null,
133
+ url: context?.url || null,
134
+ statusCode: context?.statusCode || null,
135
+ duration: context?.duration || null,
136
+ stackTrace: context?.stackTrace || null,
137
+ tags: context?.tags ? JSON.stringify(context.tags) : null,
138
+ source: context?.source || null,
139
+ createdAt: /* @__PURE__ */ new Date()
140
+ };
141
+ await this.db.insert(chunkYP7GW2G5_cjs.systemLogs).values(logEntry);
142
+ if (config.maxSize) {
143
+ await this.cleanupCategory(category, config.maxSize);
144
+ }
145
+ } catch (error) {
146
+ console.error("Logger error:", error);
147
+ }
148
+ }
149
+ /**
150
+ * Get logs with filtering and pagination
151
+ */
152
+ async getLogs(filter = {}) {
153
+ try {
154
+ const conditions = [];
155
+ if (filter.level && filter.level.length > 0) {
156
+ conditions.push(drizzleOrm.inArray(chunkYP7GW2G5_cjs.systemLogs.level, filter.level));
157
+ }
158
+ if (filter.category && filter.category.length > 0) {
159
+ conditions.push(drizzleOrm.inArray(chunkYP7GW2G5_cjs.systemLogs.category, filter.category));
160
+ }
161
+ if (filter.userId) {
162
+ conditions.push(drizzleOrm.eq(chunkYP7GW2G5_cjs.systemLogs.userId, filter.userId));
163
+ }
164
+ if (filter.source) {
165
+ conditions.push(drizzleOrm.eq(chunkYP7GW2G5_cjs.systemLogs.source, filter.source));
166
+ }
167
+ if (filter.search) {
168
+ conditions.push(
169
+ drizzleOrm.like(chunkYP7GW2G5_cjs.systemLogs.message, `%${filter.search}%`)
170
+ );
171
+ }
172
+ if (filter.startDate) {
173
+ conditions.push(drizzleOrm.gte(chunkYP7GW2G5_cjs.systemLogs.createdAt, filter.startDate));
174
+ }
175
+ if (filter.endDate) {
176
+ conditions.push(drizzleOrm.lte(chunkYP7GW2G5_cjs.systemLogs.createdAt, filter.endDate));
177
+ }
178
+ const whereClause = conditions.length > 0 ? drizzleOrm.and(...conditions) : void 0;
179
+ const totalResult = await this.db.select({ count: drizzleOrm.count() }).from(chunkYP7GW2G5_cjs.systemLogs).where(whereClause);
180
+ const total = totalResult[0]?.count || 0;
181
+ const sortColumn = filter.sortBy === "level" ? chunkYP7GW2G5_cjs.systemLogs.level : filter.sortBy === "category" ? chunkYP7GW2G5_cjs.systemLogs.category : chunkYP7GW2G5_cjs.systemLogs.createdAt;
182
+ const sortFn = filter.sortOrder === "asc" ? drizzleOrm.asc : drizzleOrm.desc;
183
+ const logs = await this.db.select().from(chunkYP7GW2G5_cjs.systemLogs).where(whereClause).orderBy(sortFn(sortColumn)).limit(filter.limit || 50).offset(filter.offset || 0);
184
+ return { logs, total };
185
+ } catch (error) {
186
+ console.error("Error getting logs:", error);
187
+ return { logs: [], total: 0 };
188
+ }
189
+ }
190
+ /**
191
+ * Get log configuration for a category
192
+ */
193
+ async getConfig(category) {
194
+ try {
195
+ const now = Date.now();
196
+ if (this.configCache.has(category) && now - this.lastConfigRefresh < this.configRefreshInterval) {
197
+ return this.configCache.get(category) || null;
198
+ }
199
+ const configs = await this.db.select().from(chunkYP7GW2G5_cjs.logConfig).where(drizzleOrm.eq(chunkYP7GW2G5_cjs.logConfig.category, category));
200
+ const config = configs[0] || null;
201
+ if (config) {
202
+ this.configCache.set(category, config);
203
+ this.lastConfigRefresh = now;
204
+ }
205
+ return config;
206
+ } catch (error) {
207
+ console.error("Error getting log config:", error);
208
+ return null;
209
+ }
210
+ }
211
+ /**
212
+ * Update log configuration
213
+ */
214
+ async updateConfig(category, updates) {
215
+ try {
216
+ await this.db.update(chunkYP7GW2G5_cjs.logConfig).set({
217
+ ...updates,
218
+ updatedAt: /* @__PURE__ */ new Date()
219
+ }).where(drizzleOrm.eq(chunkYP7GW2G5_cjs.logConfig.category, category));
220
+ this.configCache.delete(category);
221
+ } catch (error) {
222
+ console.error("Error updating log config:", error);
223
+ }
224
+ }
225
+ /**
226
+ * Get all log configurations
227
+ */
228
+ async getAllConfigs() {
229
+ try {
230
+ return await this.db.select().from(chunkYP7GW2G5_cjs.logConfig);
231
+ } catch (error) {
232
+ console.error("Error getting log configs:", error);
233
+ return [];
234
+ }
235
+ }
236
+ /**
237
+ * Clean up old logs for a category
238
+ */
239
+ async cleanupCategory(category, maxSize) {
240
+ try {
241
+ const countResult = await this.db.select({ count: drizzleOrm.count() }).from(chunkYP7GW2G5_cjs.systemLogs).where(drizzleOrm.eq(chunkYP7GW2G5_cjs.systemLogs.category, category));
242
+ const currentCount = countResult[0]?.count || 0;
243
+ if (currentCount > maxSize) {
244
+ const cutoffLogs = await this.db.select({ createdAt: chunkYP7GW2G5_cjs.systemLogs.createdAt }).from(chunkYP7GW2G5_cjs.systemLogs).where(drizzleOrm.eq(chunkYP7GW2G5_cjs.systemLogs.category, category)).orderBy(drizzleOrm.desc(chunkYP7GW2G5_cjs.systemLogs.createdAt)).limit(1).offset(maxSize - 1);
245
+ if (cutoffLogs[0]) {
246
+ await this.db.delete(chunkYP7GW2G5_cjs.systemLogs).where(
247
+ drizzleOrm.and(
248
+ drizzleOrm.eq(chunkYP7GW2G5_cjs.systemLogs.category, category),
249
+ drizzleOrm.lte(chunkYP7GW2G5_cjs.systemLogs.createdAt, cutoffLogs[0].createdAt)
250
+ )
251
+ );
252
+ }
253
+ }
254
+ } catch (error) {
255
+ console.error("Error cleaning up logs:", error);
256
+ }
257
+ }
258
+ /**
259
+ * Clean up logs based on retention policy
260
+ */
261
+ async cleanupByRetention() {
262
+ try {
263
+ const configs = await this.getAllConfigs();
264
+ for (const config of configs) {
265
+ if (config.retention > 0) {
266
+ const cutoffDate = /* @__PURE__ */ new Date();
267
+ cutoffDate.setDate(cutoffDate.getDate() - config.retention);
268
+ await this.db.delete(chunkYP7GW2G5_cjs.systemLogs).where(
269
+ drizzleOrm.and(
270
+ drizzleOrm.eq(chunkYP7GW2G5_cjs.systemLogs.category, config.category),
271
+ drizzleOrm.lte(chunkYP7GW2G5_cjs.systemLogs.createdAt, cutoffDate)
272
+ )
273
+ );
274
+ }
275
+ }
276
+ } catch (error) {
277
+ console.error("Error cleaning up logs by retention:", error);
278
+ }
279
+ }
280
+ /**
281
+ * Check if a log level should be recorded based on configuration
282
+ */
283
+ shouldLog(level, configLevel) {
284
+ const levels = ["debug", "info", "warn", "error", "fatal"];
285
+ const levelIndex = levels.indexOf(level);
286
+ const configLevelIndex = levels.indexOf(configLevel);
287
+ return levelIndex >= configLevelIndex;
288
+ }
289
+ /**
290
+ * Enable or disable logging
291
+ */
292
+ setEnabled(enabled) {
293
+ this.enabled = enabled;
294
+ }
295
+ /**
296
+ * Check if logging is enabled
297
+ */
298
+ isEnabled() {
299
+ return this.enabled;
300
+ }
301
+ };
302
+ var loggerInstance = null;
303
+ function getLogger(database) {
304
+ if (!loggerInstance && database) {
305
+ loggerInstance = new Logger(database);
306
+ }
307
+ if (!loggerInstance) {
308
+ throw new Error("Logger not initialized. Call getLogger with a database instance first.");
309
+ }
310
+ return loggerInstance;
311
+ }
312
+ function initLogger(database) {
313
+ loggerInstance = new Logger(database);
314
+ return loggerInstance;
315
+ }
316
+
317
+ // src/services/cache.ts
318
+ function toPluginConfig(config) {
319
+ return {
320
+ ttl: config.ttl,
321
+ namespace: config.keyPrefix,
322
+ // KV survives isolate evictions — required for the dashboard to show non-zero
323
+ // counts across requests in production. Falls back to memory-only when the
324
+ // CACHE_KV binding is missing (cache plugin handles the null case).
325
+ kvEnabled: true,
326
+ memoryEnabled: true,
327
+ invalidateOn: [],
328
+ version: "v1"
329
+ };
330
+ }
331
+ var CacheService = class {
332
+ config;
333
+ inner;
334
+ // Tracks expiry times so getWithSource can distinguish 'none' vs 'expired'.
335
+ // The plugin returns source:'miss' for both cases; we differentiate here.
336
+ keyExpiry = /* @__PURE__ */ new Map();
337
+ constructor(config) {
338
+ this.config = config;
339
+ this.inner = chunkYA3TJ65D_cjs.getCacheService(toPluginConfig(config));
340
+ }
341
+ generateKey(type, identifier) {
342
+ const parts = [this.config.keyPrefix, type];
343
+ if (identifier !== void 0 && identifier !== "") parts.push(identifier);
344
+ return parts.join(":");
345
+ }
346
+ async get(key) {
347
+ return this.inner.get(key);
348
+ }
349
+ async getWithSource(key) {
350
+ const result = await this.inner.getWithSource(key);
351
+ if (result.hit) {
352
+ const out = {
353
+ hit: true,
354
+ data: result.data,
355
+ source: result.source
356
+ };
357
+ if (result.ttl !== void 0) out.ttl = result.ttl;
358
+ return out;
359
+ }
360
+ const expiry = this.keyExpiry.get(key);
361
+ if (expiry !== void 0) {
362
+ this.keyExpiry.delete(key);
363
+ return { hit: false, data: null, source: "expired" };
364
+ }
365
+ return { hit: false, data: null, source: "none" };
366
+ }
367
+ async set(key, value, ttl) {
368
+ const effectiveTtl = ttl ?? this.config.ttl;
369
+ this.keyExpiry.set(key, Date.now() + effectiveTtl * 1e3);
370
+ await this.inner.set(key, value, ttl !== void 0 ? { ttl } : void 0);
371
+ }
372
+ async delete(key) {
373
+ this.keyExpiry.delete(key);
374
+ await this.inner.delete(key);
375
+ }
376
+ async invalidate(pattern) {
377
+ if (pattern.includes("*") || pattern.includes("?")) {
378
+ const regex = new RegExp("^" + pattern.replace(/\*/g, ".*").replace(/\?/g, ".") + "$");
379
+ for (const k of this.keyExpiry.keys()) {
380
+ if (regex.test(k)) this.keyExpiry.delete(k);
381
+ }
382
+ } else {
383
+ this.keyExpiry.delete(pattern);
384
+ }
385
+ await this.inner.invalidate(pattern);
386
+ }
387
+ async clear() {
388
+ this.keyExpiry.clear();
389
+ await this.inner.clear();
390
+ }
391
+ async getOrSet(key, callback, ttl) {
392
+ const cached = await this.get(key);
393
+ if (cached !== null) return cached;
394
+ const value = await callback();
395
+ await this.set(key, value, ttl);
396
+ return value;
397
+ }
398
+ };
399
+ var CACHE_CONFIGS = {
400
+ api: {
401
+ ttl: 300,
402
+ // 5 minutes
403
+ keyPrefix: "api"
404
+ },
405
+ user: {
406
+ ttl: 600,
407
+ // 10 minutes
408
+ keyPrefix: "user"
409
+ },
410
+ content: {
411
+ ttl: 300,
412
+ // 5 minutes
413
+ keyPrefix: "content"
414
+ },
415
+ collection: {
416
+ ttl: 600,
417
+ // 10 minutes
418
+ keyPrefix: "collection"
419
+ }
420
+ };
421
+ function getCacheService2(config) {
422
+ return new CacheService(config);
423
+ }
424
+
425
+ // src/services/settings.ts
426
+ var TYPE_ID = "site_settings";
427
+ var TENANT = "default";
428
+ var SettingsService = class {
429
+ constructor(db) {
430
+ this.db = db;
431
+ }
432
+ /**
433
+ * Get settings document for a category (general or security)
434
+ */
435
+ async getSettingsDocument(category) {
436
+ try {
437
+ const row = await this.db.prepare(`
438
+ SELECT data FROM documents
439
+ WHERE type_id = ? AND slug = ? AND tenant_id = ? AND is_current_draft = 1 AND deleted_at IS NULL
440
+ `).bind(TYPE_ID, category, TENANT).first();
441
+ if (!row) {
442
+ return null;
443
+ }
444
+ return JSON.parse(row.data);
445
+ } catch (error) {
446
+ console.error(`Error getting settings document for ${category}:`, error);
447
+ return null;
448
+ }
449
+ }
450
+ /**
451
+ * Save settings document for a category (general or security)
452
+ */
453
+ async saveSettingsDocument(category, data) {
454
+ try {
455
+ const now = Math.floor(Date.now() / 1e3);
456
+ const jsonData = JSON.stringify(data);
457
+ await this.db.prepare(`
458
+ INSERT OR IGNORE INTO document_types (id, name, display_name, description, schema, source, is_system, is_active, created_at, updated_at)
459
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
460
+ `).bind(
461
+ TYPE_ID,
462
+ TYPE_ID,
463
+ "Site Settings",
464
+ "Global site configuration settings",
465
+ "{}",
466
+ "system",
467
+ 1,
468
+ 1,
469
+ now,
470
+ now
471
+ ).run();
472
+ const existing = await this.db.prepare(`
473
+ SELECT id FROM documents
474
+ WHERE type_id = ? AND slug = ? AND tenant_id = ? AND is_current_draft = 1 AND deleted_at IS NULL
475
+ `).bind(TYPE_ID, category, TENANT).first();
476
+ if (existing) {
477
+ await this.db.prepare(`
478
+ UPDATE documents
479
+ SET data = ?, updated_at = ?
480
+ WHERE id = ? AND is_current_draft = 1
481
+ `).bind(jsonData, now, existing.id).run();
482
+ } else {
483
+ const docId = crypto.randomUUID();
484
+ const rootId = docId;
485
+ const title = category === "general" ? "General Settings" : "Security Settings";
486
+ await this.db.prepare(`
487
+ INSERT INTO documents (
488
+ id, root_id, type_id, version_number, is_current_draft, is_published, status,
489
+ parent_root_id, slug, title, tenant_id, locale, translation_group_id,
490
+ data, metadata, created_at, updated_at
491
+ ) VALUES (
492
+ ?, ?, ?, 1, 1, 1, 'published',
493
+ '', ?, ?, ?, 'default', '',
494
+ ?, '{}', ?, ?
495
+ )
496
+ `).bind(
497
+ docId,
498
+ rootId,
499
+ TYPE_ID,
500
+ category,
501
+ title,
502
+ TENANT,
503
+ jsonData,
504
+ now,
505
+ now
506
+ ).run();
507
+ }
508
+ return true;
509
+ } catch (error) {
510
+ console.error(`Error saving settings document for ${category}:`, error);
511
+ return false;
512
+ }
513
+ }
514
+ /**
515
+ * Get general settings with defaults
516
+ */
517
+ async getGeneralSettings(userEmail) {
518
+ const settings = await this.getSettingsDocument("general");
519
+ return {
520
+ siteName: settings?.siteName || "SonicJS AI",
521
+ siteDescription: settings?.siteDescription || "A modern headless CMS powered by AI",
522
+ adminEmail: settings?.adminEmail || userEmail || "admin@example.com",
523
+ timezone: settings?.timezone || "UTC",
524
+ language: settings?.language || "en",
525
+ maintenanceMode: settings?.maintenanceMode || false
526
+ };
527
+ }
528
+ /**
529
+ * Save general settings
530
+ */
531
+ async saveGeneralSettings(settings) {
532
+ const existing = await this.getSettingsDocument("general");
533
+ const merged = { ...existing, ...settings };
534
+ return await this.saveSettingsDocument("general", merged);
535
+ }
536
+ /**
537
+ * Get security settings with defaults
538
+ */
539
+ async getSecuritySettings() {
540
+ const settings = await this.getSettingsDocument("security");
541
+ return {
542
+ jwtExpiresIn: settings?.jwtExpiresIn || "30d",
543
+ jwtRefreshGraceSeconds: typeof settings?.jwtRefreshGraceSeconds === "number" ? settings.jwtRefreshGraceSeconds : 60 * 60 * 24 * 7
544
+ };
545
+ }
546
+ /**
547
+ * Save security settings
548
+ */
549
+ async saveSecuritySettings(settings) {
550
+ const existing = await this.getSettingsDocument("security");
551
+ const merged = { ...existing, ...settings };
552
+ return await this.saveSettingsDocument("security", merged);
553
+ }
554
+ };
555
+ var appInstance = null;
556
+ function setAppInstance(app) {
557
+ appInstance = app;
558
+ }
559
+ function getAppInstance() {
560
+ return appInstance;
561
+ }
562
+ var CATEGORY_INFO = {
563
+ "Auth": {
564
+ title: "Authentication",
565
+ description: "User authentication and authorization endpoints",
566
+ icon: "&#x1f510;"
567
+ },
568
+ "Content": {
569
+ title: "Content Management",
570
+ description: "Content creation, retrieval, and management",
571
+ icon: "&#x1f4dd;"
572
+ },
573
+ "Media": {
574
+ title: "Media Management",
575
+ description: "File upload, storage, and media operations",
576
+ icon: "&#x1f5bc;&#xfe0f;"
577
+ },
578
+ "Admin": {
579
+ title: "Admin Interface",
580
+ description: "Administrative panel and management features",
581
+ icon: "&#x2699;&#xfe0f;"
582
+ },
583
+ "System": {
584
+ title: "System",
585
+ description: "Health checks and system information",
586
+ icon: "&#x1f527;"
587
+ },
588
+ "Search": {
589
+ title: "Search",
590
+ description: "AI-powered search, full-text search, and analytics",
591
+ icon: "&#x1f50d;"
592
+ },
593
+ "API Keys": {
594
+ title: "API Keys",
595
+ description: "API key management and authentication",
596
+ icon: "&#x1f511;"
597
+ },
598
+ "Workflow": {
599
+ title: "Workflow",
600
+ description: "Content workflow and approval processes",
601
+ icon: "&#x1f504;"
602
+ },
603
+ "Cache": {
604
+ title: "Cache",
605
+ description: "Cache management and invalidation",
606
+ icon: "&#x26a1;"
607
+ },
608
+ "Forms": {
609
+ title: "Forms",
610
+ description: "Form submissions and management",
611
+ icon: "&#x1f4cb;"
612
+ },
613
+ "Files": {
614
+ title: "Files",
615
+ description: "File serving from R2 storage",
616
+ icon: "&#x1f4c1;"
617
+ },
618
+ "Collections": {
619
+ title: "Collections",
620
+ description: "Per-collection REST endpoints (auto-generated from registered collections)",
621
+ icon: "&#x1f4da;"
622
+ }
623
+ };
624
+ var ROUTE_METADATA = {
625
+ // Auth endpoints
626
+ "POST /auth/login": { description: "Authenticate user with email and password (returns JWT)", category: "Auth", authentication: false },
627
+ "POST /auth/login/form": { description: "Form-based login (sets session cookie)", category: "Auth", authentication: false },
628
+ "POST /auth/register": { description: "Register a new user account", category: "Auth", authentication: false },
629
+ "POST /auth/logout": { description: "Log out the current user and invalidate session", category: "Auth", authentication: true },
630
+ "GET /auth/me": { description: "Get current authenticated user information", category: "Auth", authentication: true },
631
+ "POST /auth/refresh": { description: "Refresh authentication token", category: "Auth", authentication: true },
632
+ "POST /auth/seed-admin": { description: "Create or reset the admin user account", category: "Auth", authentication: false },
633
+ "POST /auth/magic-link/request": { description: "Request a magic link login email", category: "Auth", authentication: false },
634
+ "GET /auth/magic-link/verify": { description: "Verify magic link token and authenticate", category: "Auth", authentication: false },
635
+ "POST /auth/otp/request": { description: "Request a one-time password via email", category: "Auth", authentication: false },
636
+ "POST /auth/otp/verify": { description: "Verify OTP code and authenticate", category: "Auth", authentication: false },
637
+ // Content endpoints
638
+ "GET /api/collections": { description: "List all available collections", category: "Content", authentication: false },
639
+ "GET /api/collections/:collection/content": { description: "Get all content items from a specific collection", category: "Content", authentication: false },
640
+ "GET /api/content/:id": { description: "Get a specific content item by ID", category: "Content", authentication: false },
641
+ "POST /api/content": { description: "Create a new content item", category: "Content", authentication: true },
642
+ "PUT /api/content/:id": { description: "Update an existing content item", category: "Content", authentication: true },
643
+ "DELETE /api/content/:id": { description: "Delete a content item", category: "Content", authentication: true },
644
+ "GET /api/content/:id/versions": { description: "Get version history for a content item", category: "Content", authentication: true },
645
+ "POST /api/content/:id/restore/:versionId": { description: "Restore a content item to a previous version", category: "Content", authentication: true },
646
+ // Media endpoints
647
+ "GET /api/media": { description: "List all media files with pagination", category: "Media", authentication: false },
648
+ "GET /api/media/:id": { description: "Get a specific media file by ID", category: "Media", authentication: false },
649
+ "POST /api/media/upload": { description: "Upload a new media file to R2 storage", category: "Media", authentication: true },
650
+ "DELETE /api/media/:id": { description: "Delete a media file from storage", category: "Media", authentication: true },
651
+ // Admin API endpoints
652
+ "GET /admin/api/stats": { description: "Get dashboard statistics (collections, content, media, users)", category: "Admin", authentication: true },
653
+ "GET /admin/api/storage": { description: "Get storage usage information", category: "Admin", authentication: true },
654
+ "GET /admin/api/activity": { description: "Get recent activity logs", category: "Admin", authentication: true },
655
+ "GET /admin/api/collections": { description: "List all collections with field counts", category: "Admin", authentication: true },
656
+ "POST /admin/api/collections": { description: "Create a new collection", category: "Admin", authentication: true },
657
+ "GET /admin/api/collections/:id": { description: "Get a specific collection with its fields", category: "Admin", authentication: true },
658
+ "PATCH /admin/api/collections/:id": { description: "Update an existing collection", category: "Admin", authentication: true },
659
+ "DELETE /admin/api/collections/:id": { description: "Delete a collection (must be empty)", category: "Admin", authentication: true },
660
+ "GET /admin/api/collections/:id/fields": { description: "Get fields for a specific collection", category: "Admin", authentication: true },
661
+ "POST /admin/api/collections/:id/fields": { description: "Add a field to a collection", category: "Admin", authentication: true },
662
+ "PATCH /admin/api/collections/:id/fields/:fieldId": { description: "Update a collection field", category: "Admin", authentication: true },
663
+ "DELETE /admin/api/collections/:id/fields/:fieldId": { description: "Remove a field from a collection", category: "Admin", authentication: true },
664
+ "POST /admin/api/collections/:id/fields/reorder": { description: "Reorder fields in a collection", category: "Admin", authentication: true },
665
+ "GET /admin/api/migrations/status": { description: "Get database migration status", category: "Admin", authentication: true },
666
+ "POST /admin/api/migrations/run": { description: "Explain how to run D1 migrations with Wrangler", category: "Admin", authentication: true },
667
+ "GET /admin/api/content": { description: "List content items with filtering and pagination", category: "Admin", authentication: true },
668
+ "GET /admin/api/content/:id": { description: "Get a content item for admin editing", category: "Admin", authentication: true },
669
+ "POST /admin/api/content": { description: "Create content via admin API", category: "Admin", authentication: true },
670
+ "PUT /admin/api/content/:id": { description: "Update content via admin API", category: "Admin", authentication: true },
671
+ "DELETE /admin/api/content/:id": { description: "Delete content via admin API", category: "Admin", authentication: true },
672
+ "GET /admin/api/media": { description: "List media files for admin management", category: "Admin", authentication: true },
673
+ "POST /admin/api/media/upload": { description: "Upload media via admin interface", category: "Admin", authentication: true },
674
+ "DELETE /admin/api/media/:id": { description: "Delete media via admin interface", category: "Admin", authentication: true },
675
+ "GET /admin/api/users": { description: "List all users", category: "Admin", authentication: true },
676
+ "POST /admin/api/users": { description: "Create a new user", category: "Admin", authentication: true },
677
+ "PUT /admin/api/users/:id": { description: "Update a user", category: "Admin", authentication: true },
678
+ "DELETE /admin/api/users/:id": { description: "Delete a user", category: "Admin", authentication: true },
679
+ "GET /admin/api/logs": { description: "Get application logs with filtering", category: "Admin", authentication: true },
680
+ "GET /admin/api/plugins": { description: "List all registered plugins", category: "Admin", authentication: true },
681
+ "POST /admin/api/plugins/:id/toggle": { description: "Enable or disable a plugin", category: "Admin", authentication: true },
682
+ "GET /admin/api/settings": { description: "Get application settings", category: "Admin", authentication: true },
683
+ "PUT /admin/api/settings": { description: "Update application settings", category: "Admin", authentication: true },
684
+ "GET /admin/api/forms": { description: "List all forms", category: "Admin", authentication: true },
685
+ "GET /admin/api/forms/:id": { description: "Get form details and submissions", category: "Admin", authentication: true },
686
+ "POST /admin/api/forms": { description: "Create a new form", category: "Admin", authentication: true },
687
+ "PUT /admin/api/forms/:id": { description: "Update a form", category: "Admin", authentication: true },
688
+ "DELETE /admin/api/forms/:id": { description: "Delete a form", category: "Admin", authentication: true },
689
+ "GET /admin/api/forms/:id/submissions": { description: "Get form submissions", category: "Admin", authentication: true },
690
+ "DELETE /admin/api/forms/:id/submissions/:submissionId": { description: "Delete a form submission", category: "Admin", authentication: true },
691
+ // Search endpoints
692
+ "GET /api/search": { description: "Search content using AI, FTS5, keyword, or hybrid mode", category: "Search", authentication: false },
693
+ "POST /api/search/click": { description: "Track a search result click for analytics", category: "Search", authentication: false },
694
+ "GET /admin/plugins/ai-search/api/status": { description: "Get search plugin status and configuration", category: "Search", authentication: true },
695
+ "POST /admin/plugins/ai-search/api/index": { description: "Trigger content indexing for search", category: "Search", authentication: true },
696
+ "POST /admin/plugins/ai-search/api/index/reset": { description: "Reset the search index", category: "Search", authentication: true },
697
+ "GET /admin/plugins/ai-search/api/analytics": { description: "Get search analytics and metrics", category: "Search", authentication: true },
698
+ "GET /admin/plugins/ai-search/api/analytics/queries": { description: "Get top search queries", category: "Search", authentication: true },
699
+ "GET /admin/plugins/ai-search/api/analytics/clicks": { description: "Get click-through analytics", category: "Search", authentication: true },
700
+ "GET /admin/plugins/ai-search/api/fts5/status": { description: "Get FTS5 full-text search status", category: "Search", authentication: true },
701
+ "POST /admin/plugins/ai-search/api/fts5/rebuild": { description: "Rebuild the FTS5 search index", category: "Search", authentication: true },
702
+ "GET /admin/plugins/ai-search/api/facets": { description: "Get available search facets", category: "Search", authentication: true },
703
+ "GET /admin/plugins/ai-search/api/experiments": { description: "List search A/B test experiments", category: "Search", authentication: true },
704
+ "POST /admin/plugins/ai-search/api/experiments": { description: "Create a search A/B test experiment", category: "Search", authentication: true },
705
+ "GET /admin/plugins/ai-search/api/experiments/:id": { description: "Get experiment details", category: "Search", authentication: true },
706
+ "PUT /admin/plugins/ai-search/api/experiments/:id": { description: "Update an experiment", category: "Search", authentication: true },
707
+ "DELETE /admin/plugins/ai-search/api/experiments/:id": { description: "Delete an experiment", category: "Search", authentication: true },
708
+ "POST /admin/plugins/ai-search/api/experiments/:id/start": { description: "Start an experiment", category: "Search", authentication: true },
709
+ "POST /admin/plugins/ai-search/api/experiments/:id/stop": { description: "Stop a running experiment", category: "Search", authentication: true },
710
+ "GET /admin/plugins/ai-search/api/experiments/:id/results": { description: "Get experiment results and statistics", category: "Search", authentication: true },
711
+ "GET /admin/plugins/ai-search/api/quality": { description: "Get search quality agent analysis", category: "Search", authentication: true },
712
+ "POST /admin/plugins/ai-search/api/quality/run": { description: "Run search quality analysis", category: "Search", authentication: true },
713
+ "GET /admin/plugins/ai-search/api/quality/recommendations": { description: "Get quality improvement recommendations", category: "Search", authentication: true },
714
+ "POST /admin/plugins/ai-search/api/quality/recommendations/:id/apply": { description: "Apply a quality recommendation", category: "Search", authentication: true },
715
+ "POST /admin/plugins/ai-search/api/quality/recommendations/:id/dismiss": { description: "Dismiss a quality recommendation", category: "Search", authentication: true },
716
+ "GET /admin/plugins/ai-search/api/synonyms": { description: "List search synonyms", category: "Search", authentication: true },
717
+ "POST /admin/plugins/ai-search/api/synonyms": { description: "Add a search synonym", category: "Search", authentication: true },
718
+ "DELETE /admin/plugins/ai-search/api/synonyms/:id": { description: "Delete a search synonym", category: "Search", authentication: true },
719
+ "GET /admin/plugins/ai-search/api/query-rules": { description: "List search query rules", category: "Search", authentication: true },
720
+ "POST /admin/plugins/ai-search/api/query-rules": { description: "Create a query rule", category: "Search", authentication: true },
721
+ "PUT /admin/plugins/ai-search/api/query-rules/:id": { description: "Update a query rule", category: "Search", authentication: true },
722
+ "DELETE /admin/plugins/ai-search/api/query-rules/:id": { description: "Delete a query rule", category: "Search", authentication: true },
723
+ "GET /admin/plugins/ai-search/api/settings": { description: "Get search plugin settings", category: "Search", authentication: true },
724
+ "PUT /admin/plugins/ai-search/api/settings": { description: "Update search plugin settings", category: "Search", authentication: true },
725
+ // API Key endpoints
726
+ "GET /admin/api-keys/api/keys": { description: "List all API keys", category: "API Keys", authentication: true },
727
+ "POST /admin/api-keys/api/keys": { description: "Create a new API key", category: "API Keys", authentication: true },
728
+ "DELETE /admin/api-keys/api/keys/:id": { description: "Revoke an API key", category: "API Keys", authentication: true },
729
+ "PUT /admin/api-keys/api/keys/:id": { description: "Update an API key", category: "API Keys", authentication: true },
730
+ // Cache endpoints
731
+ "GET /admin/cache/api/stats": { description: "Get cache statistics", category: "Cache", authentication: true },
732
+ "POST /admin/cache/api/purge": { description: "Purge cache entries", category: "Cache", authentication: true },
733
+ "GET /admin/cache/api/entries": { description: "List cache entries", category: "Cache", authentication: true },
734
+ "DELETE /admin/cache/api/entries/:key": { description: "Delete a specific cache entry", category: "Cache", authentication: true },
735
+ // Workflow endpoints
736
+ "GET /workflow/status/:id": { description: "Get workflow status for a content item", category: "Workflow", authentication: true },
737
+ "POST /workflow/submit/:id": { description: "Submit content for review", category: "Workflow", authentication: true },
738
+ "POST /workflow/approve/:id": { description: "Approve content in review", category: "Workflow", authentication: true },
739
+ "POST /workflow/reject/:id": { description: "Reject content in review", category: "Workflow", authentication: true },
740
+ "POST /workflow/publish/:id": { description: "Publish approved content", category: "Workflow", authentication: true },
741
+ "POST /workflow/unpublish/:id": { description: "Unpublish content", category: "Workflow", authentication: true },
742
+ "GET /workflow/history/:id": { description: "Get workflow history for a content item", category: "Workflow", authentication: true },
743
+ // Form endpoints (public)
744
+ "POST /forms/:formId/submit": { description: "Submit a form (public endpoint)", category: "Forms", authentication: false },
745
+ "GET /forms/:formId": { description: "Get form definition for rendering", category: "Forms", authentication: false },
746
+ "POST /api/forms/:formId/submit": { description: "Submit a form via API", category: "Forms", authentication: false },
747
+ "GET /api/forms/:formId": { description: "Get form definition via API", category: "Forms", authentication: false },
748
+ // System endpoints
749
+ "GET /health": { description: "Health check endpoint for monitoring", category: "System", authentication: false },
750
+ "GET /api/health": { description: "API health check with schema information", category: "System", authentication: false },
751
+ "GET /api": { description: "API root - returns API information and available endpoints", category: "System", authentication: false },
752
+ "GET /api/system/info": { description: "Get system information and version", category: "System", authentication: false },
753
+ "GET /api/system/schema": { description: "Get database schema information", category: "System", authentication: false },
754
+ // Collection shorthand routes
755
+ "GET /api/:collection": { description: "List items from a collection (shorthand route)", category: "Collections", authentication: false },
756
+ "GET /api/:collection/:id": { description: "Get a single item by ID from a collection", category: "Collections", authentication: false },
757
+ "POST /api/:collection": { description: "Create an item in a collection", category: "Collections", authentication: true },
758
+ "PUT /api/:collection/:id": { description: "Update an item in a collection", category: "Collections", authentication: true },
759
+ "DELETE /api/:collection/:id": { description: "Delete an item from a collection", category: "Collections", authentication: true },
760
+ // File serving
761
+ "GET /files/*": { description: "Serve files from R2 storage (public access)", category: "Files", authentication: false },
762
+ // Database tools
763
+ "POST /admin/database-tools/api/query": { description: "Execute a database query", category: "Admin", authentication: true },
764
+ "GET /admin/database-tools/api/tables": { description: "List database tables", category: "Admin", authentication: true },
765
+ "GET /admin/database-tools/api/tables/:name": { description: "Get table schema and sample data", category: "Admin", authentication: true },
766
+ // Seed data
767
+ "POST /admin/seed-data/api/generate": { description: "Generate seed data for development", category: "Admin", authentication: true },
768
+ "GET /admin/seed-data/api/status": { description: "Get seed data generation status", category: "Admin", authentication: true },
769
+ // Email plugin
770
+ "POST /admin/plugins/email/api/send": { description: "Send an email", category: "Admin", authentication: true },
771
+ "GET /admin/plugins/email/api/templates": { description: "List email templates", category: "Admin", authentication: true },
772
+ "POST /admin/plugins/email/api/test": { description: "Send a test email", category: "Admin", authentication: true }
773
+ };
774
+ var INCLUDED_ROUTE_PATTERNS = [
775
+ /^\/api\//,
776
+ // All /api/* routes
777
+ /^\/api$/,
778
+ // API root
779
+ /^\/auth\/(?!login$|register$)/,
780
+ // Auth routes except GET login/register HTML pages
781
+ /^\/auth\/login$/,
782
+ // POST /auth/login (method filtered later)
783
+ /^\/auth\/register$/,
784
+ // POST /auth/register (method filtered later)
785
+ /^\/admin\/api\//,
786
+ // Admin API endpoints
787
+ /^\/admin\/api-keys\/api\//,
788
+ // API key management
789
+ /^\/admin\/cache\/api\//,
790
+ // Cache management API
791
+ /^\/admin\/plugins\/.*\/api\//,
792
+ // Plugin API endpoints
793
+ /^\/admin\/database-tools\/api\//,
794
+ // Database tools API
795
+ /^\/admin\/seed-data\/api\//,
796
+ // Seed data API
797
+ /^\/workflow\//,
798
+ // Workflow endpoints
799
+ /^\/health$/,
800
+ // Health check
801
+ /^\/files\//,
802
+ // File serving
803
+ /^\/forms\//
804
+ // Public form endpoints
805
+ ];
806
+ var EXCLUDED_ROUTES = /* @__PURE__ */ new Set([
807
+ "GET /auth/login",
808
+ "GET /auth/register",
809
+ "GET /auth/login/form"
810
+ ]);
811
+ var cachedRouteList = null;
812
+ function isIncludedRoute(method, path) {
813
+ const key = `${method} ${path}`;
814
+ if (EXCLUDED_ROUTES.has(key)) {
815
+ return false;
816
+ }
817
+ return INCLUDED_ROUTE_PATTERNS.some((pattern) => pattern.test(path));
818
+ }
819
+ function inferCategory(path) {
820
+ if (path.startsWith("/auth/")) return "Auth";
821
+ if (path.startsWith("/api/search")) return "Search";
822
+ if (path.startsWith("/api/media")) return "Media";
823
+ if (path.startsWith("/api/system")) return "System";
824
+ if (path.startsWith("/api/content") || path.startsWith("/api/collections")) return "Content";
825
+ if (path.startsWith("/api/forms")) return "Forms";
826
+ if (path.startsWith("/admin/api-keys")) return "API Keys";
827
+ if (path.startsWith("/admin/cache")) return "Cache";
828
+ if (path.startsWith("/admin/plugins/ai-search")) return "Search";
829
+ if (path.startsWith("/admin/api")) return "Admin";
830
+ if (path.startsWith("/admin/database-tools")) return "Admin";
831
+ if (path.startsWith("/admin/seed-data")) return "Admin";
832
+ if (path.startsWith("/admin/plugins/email")) return "Admin";
833
+ if (path.startsWith("/workflow/")) return "Workflow";
834
+ if (path.startsWith("/forms/")) return "Forms";
835
+ if (path.startsWith("/files/")) return "Files";
836
+ if (path === "/health" || path.startsWith("/api")) return "System";
837
+ if (path.match(/^\/api\/[^/]+(\/:id)?$/) && !path.startsWith("/api/content") && !path.startsWith("/api/collections") && !path.startsWith("/api/media") && !path.startsWith("/api/search") && !path.startsWith("/api/system") && !path.startsWith("/api/health") && !path.startsWith("/api/documents") && !path.startsWith("/api/forms")) return "Collections";
838
+ return "Other";
839
+ }
840
+ function inferAuth(path) {
841
+ if (path === "/health" || path === "/api" || path === "/api/health") return false;
842
+ if (path === "/api/system/info" || path === "/api/system/schema") return false;
843
+ if (path.startsWith("/files/")) return false;
844
+ if (path.startsWith("/forms/") || path.startsWith("/api/forms/")) return false;
845
+ if (path.startsWith("/admin/")) return true;
846
+ if (path.startsWith("/workflow/")) return true;
847
+ return "unknown";
848
+ }
849
+ function buildRouteList(app) {
850
+ if (cachedRouteList) return cachedRouteList;
851
+ if (!app) return [];
852
+ try {
853
+ const routes = dev.inspectRoutes(app);
854
+ const seen = /* @__PURE__ */ new Set();
855
+ const result = [];
856
+ for (const route of routes) {
857
+ if (route.isMiddleware) continue;
858
+ if (route.method === "ALL") continue;
859
+ const key = `${route.method} ${route.path}`;
860
+ if (seen.has(key)) continue;
861
+ seen.add(key);
862
+ if (!isIncludedRoute(route.method, route.path)) continue;
863
+ const meta = ROUTE_METADATA[key];
864
+ if (meta) {
865
+ result.push({
866
+ method: route.method,
867
+ path: route.path,
868
+ description: meta.description,
869
+ authentication: meta.authentication,
870
+ category: meta.category,
871
+ documented: true
872
+ });
873
+ } else {
874
+ result.push({
875
+ method: route.method,
876
+ path: route.path,
877
+ description: "",
878
+ authentication: inferAuth(route.path),
879
+ category: inferCategory(route.path),
880
+ documented: false
881
+ });
882
+ }
883
+ }
884
+ const methodOrder = { GET: 0, POST: 1, PUT: 2, PATCH: 3, DELETE: 4 };
885
+ result.sort((a, b) => {
886
+ const catCmp = a.category.localeCompare(b.category);
887
+ if (catCmp !== 0) return catCmp;
888
+ const methCmp = (methodOrder[a.method] ?? 5) - (methodOrder[b.method] ?? 5);
889
+ if (methCmp !== 0) return methCmp;
890
+ return a.path.localeCompare(b.path);
891
+ });
892
+ cachedRouteList = result;
893
+ return result;
894
+ } catch (error) {
895
+ console.error("Failed to inspect routes:", error);
896
+ return [];
897
+ }
898
+ }
899
+
900
+ exports.CACHE_CONFIGS = CACHE_CONFIGS;
901
+ exports.CATEGORY_INFO = CATEGORY_INFO;
902
+ exports.CacheService = CacheService;
903
+ exports.Logger = Logger;
904
+ exports.SettingsService = SettingsService;
905
+ exports.buildRouteList = buildRouteList;
906
+ exports.getAppInstance = getAppInstance;
907
+ exports.getCacheService = getCacheService2;
908
+ exports.getLogger = getLogger;
909
+ exports.initLogger = initLogger;
910
+ exports.setAppInstance = setAppInstance;
911
+ //# sourceMappingURL=chunk-4BTBSXMR.cjs.map
912
+ //# sourceMappingURL=chunk-4BTBSXMR.cjs.map