@sonicjs-cms/core 2.19.0 → 3.0.0-beta.11

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