qarpeo 0.1.34 → 0.2.0

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 (364) hide show
  1. package/README.md +114 -26
  2. package/dist/apps/cms.d.ts +4 -0
  3. package/dist/apps/comments.d.ts +4 -0
  4. package/dist/apps/payments.d.ts +4 -0
  5. package/dist/apps/store.d.ts +4 -0
  6. package/dist/chunks/auth-schema.mjs +169 -30
  7. package/dist/chunks/tools.mjs +1680 -0
  8. package/dist/cli/index.mjs +1256 -221
  9. package/dist/core/aliases.d.ts +5 -0
  10. package/dist/core/context.d.ts +10 -0
  11. package/dist/core/cross-drive.d.ts +2 -0
  12. package/dist/core/d1-migrate.d.ts +4 -0
  13. package/dist/core/devtools.d.ts +4 -0
  14. package/dist/core/nitro.d.ts +4 -0
  15. package/dist/core/schema.d.ts +4 -0
  16. package/dist/core/server-utils.d.ts +4 -0
  17. package/dist/core/wrangler.d.ts +4 -0
  18. package/dist/dev/wrangler.d.ts +1 -0
  19. package/dist/fate/index.d.ts +8 -8
  20. package/dist/features/agents.d.ts +4 -0
  21. package/dist/features/auth.d.ts +4 -0
  22. package/dist/features/bots.d.ts +4 -0
  23. package/dist/features/fate.d.ts +4 -0
  24. package/dist/features/mail.d.ts +4 -0
  25. package/dist/features/mcp.d.ts +4 -0
  26. package/dist/features/multitenant.d.ts +4 -0
  27. package/dist/features/notifications.d.ts +4 -0
  28. package/dist/features/realtime.d.ts +4 -0
  29. package/dist/module.d.ts +10 -2
  30. package/dist/module.mjs +6313 -5114
  31. package/dist/primitives/ai.d.ts +4 -0
  32. package/dist/primitives/analytics.d.ts +4 -0
  33. package/dist/primitives/blob.d.ts +4 -0
  34. package/dist/primitives/browser.d.ts +4 -0
  35. package/dist/primitives/cache.d.ts +4 -0
  36. package/dist/primitives/d1.d.ts +4 -0
  37. package/dist/primitives/do.d.ts +4 -0
  38. package/dist/primitives/email.d.ts +4 -0
  39. package/dist/primitives/hyperdrive.d.ts +4 -0
  40. package/dist/primitives/kv.d.ts +4 -0
  41. package/dist/primitives/queue.d.ts +4 -0
  42. package/dist/primitives/ratelimit.d.ts +4 -0
  43. package/dist/primitives/vectorize.d.ts +4 -0
  44. package/dist/primitives/workflows.d.ts +4 -0
  45. package/dist/runtime/ai.d.ts +3 -3
  46. package/dist/runtime/ai.mjs +8 -1
  47. package/dist/runtime/app/components/RealtimeCursors.vue +2 -2
  48. package/dist/runtime/app/composables/ai.d.ts +56 -29
  49. package/dist/runtime/app/composables/analytics.d.ts +26 -106
  50. package/dist/runtime/app/composables/api-tokens.d.ts +31 -34
  51. package/dist/runtime/app/composables/auth.d.ts +147 -51
  52. package/dist/runtime/app/composables/auth.mjs +0 -7
  53. package/dist/runtime/app/composables/chat.d.ts +38 -35
  54. package/dist/runtime/app/composables/cms-preview.d.ts +30 -25
  55. package/dist/runtime/app/composables/cms.d.ts +57 -282
  56. package/dist/runtime/app/composables/cms.mjs +0 -35
  57. package/dist/runtime/app/composables/comments.d.ts +32 -5
  58. package/dist/runtime/app/composables/comments.mjs +29 -1
  59. package/dist/runtime/app/composables/docs-version.d.ts +25 -28
  60. package/dist/runtime/app/composables/impersonation.d.ts +22 -5
  61. package/dist/runtime/app/composables/organization.d.ts +38 -91
  62. package/dist/runtime/app/composables/passkey.d.ts +22 -6
  63. package/dist/runtime/app/composables/passwordless.d.ts +24 -7
  64. package/dist/runtime/app/composables/payments.d.ts +50 -34
  65. package/dist/runtime/app/composables/payments.mjs +1 -0
  66. package/dist/runtime/app/composables/sse.d.ts +76 -0
  67. package/dist/runtime/app/composables/sse.mjs +152 -0
  68. package/dist/runtime/app/composables/storage.d.ts +53 -65
  69. package/dist/runtime/app/composables/storage.mjs +17 -0
  70. package/dist/runtime/app/composables/store.d.ts +198 -0
  71. package/dist/runtime/app/composables/store.mjs +414 -0
  72. package/dist/runtime/app/composables/tenant.d.ts +31 -72
  73. package/dist/runtime/app/composables/turnstile.d.ts +16 -3
  74. package/dist/runtime/app/composables/two-factor.d.ts +23 -6
  75. package/dist/runtime/app/pages/devtools/notifications.vue +30 -27
  76. package/dist/runtime/app/pages/devtools/realtime.vue +19 -31
  77. package/dist/runtime/app/pages/devtools.vue +0 -7
  78. package/dist/runtime/auth.d.ts +9 -9
  79. package/dist/runtime/blob.d.ts +10 -1
  80. package/dist/runtime/blob.mjs +83 -0
  81. package/dist/runtime/cache.d.ts +48 -0
  82. package/dist/runtime/cache.mjs +92 -0
  83. package/dist/runtime/comments.d.ts +4 -0
  84. package/dist/runtime/comments.mjs +2 -0
  85. package/dist/runtime/db.d.ts +21 -1
  86. package/dist/runtime/db.mjs +54 -0
  87. package/dist/runtime/drizzle.d.ts +4 -2
  88. package/dist/runtime/drizzle.mjs +68 -1
  89. package/dist/runtime/durable-object.d.ts +2 -0
  90. package/dist/runtime/durable-object.mjs +2 -0
  91. package/dist/runtime/email.d.ts +1 -1
  92. package/dist/runtime/email.mjs +1 -1
  93. package/dist/runtime/kv.mjs +50 -1
  94. package/dist/runtime/mcp.d.ts +2 -0
  95. package/dist/runtime/mcp.mjs +2 -0
  96. package/dist/runtime/queue.d.ts +12 -2
  97. package/dist/runtime/queue.mjs +19 -1
  98. package/dist/runtime/ratelimit.d.ts +1 -0
  99. package/dist/runtime/ratelimit.mjs +7 -0
  100. package/dist/runtime/schema.d.ts +313 -0
  101. package/dist/runtime/schema.mjs +259 -0
  102. package/dist/runtime/server/db/cms-schema.d.ts +1225 -171
  103. package/dist/runtime/server/db/cms-schema.mjs +69 -70
  104. package/dist/runtime/server/db/store-schema.d.ts +4344 -0
  105. package/dist/runtime/server/db/store-schema.mjs +266 -0
  106. package/dist/runtime/server/durable-objects/agent.mjs +35 -0
  107. package/dist/runtime/server/durable-objects/room.mjs +0 -1
  108. package/dist/runtime/server/middleware/ratelimit.mjs +10 -8
  109. package/dist/runtime/server/plugins/comments.d.ts +7 -0
  110. package/dist/runtime/server/plugins/comments.mjs +7 -0
  111. package/dist/runtime/server/plugins/email-inbound.d.ts +5 -0
  112. package/dist/runtime/server/plugins/email-inbound.mjs +17 -0
  113. package/dist/runtime/server/plugins/store.d.ts +7 -0
  114. package/dist/runtime/server/plugins/store.mjs +7 -0
  115. package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +2 -2
  116. package/dist/runtime/server/routes/atom.xml.get.mjs +3 -1
  117. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +13 -2
  118. package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +9 -3
  119. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -3
  120. package/dist/runtime/server/routes/auth/account.delete.mjs +2 -1
  121. package/dist/runtime/server/routes/auth/audit-logs.get.mjs +1 -1
  122. package/dist/runtime/server/routes/auth/magic-link/send.post.d.ts +1 -9
  123. package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +8 -0
  124. package/dist/runtime/server/routes/auth/organization/sso/[id].delete.mjs +1 -1
  125. package/dist/runtime/server/routes/auth/organization/sso/index.get.mjs +1 -1
  126. package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +1 -1
  127. package/dist/runtime/server/routes/auth/otp/send.post.d.ts +1 -9
  128. package/dist/runtime/server/routes/auth/otp/send.post.mjs +8 -0
  129. package/dist/runtime/server/routes/auth/sso/login.get.mjs +3 -3
  130. package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +1 -1
  131. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +2 -2
  132. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
  133. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +1 -1
  134. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +2 -2
  135. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +1 -1
  136. package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +1 -1
  137. package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.mjs +3 -1
  138. package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.mjs +3 -1
  139. package/dist/runtime/server/routes/cms/bookmarks/[id].delete.mjs +1 -1
  140. package/dist/runtime/server/routes/cms/bookmarks/check.post.mjs +1 -1
  141. package/dist/runtime/server/routes/cms/bookmarks/index.get.mjs +1 -1
  142. package/dist/runtime/server/routes/cms/bookmarks/index.post.mjs +1 -1
  143. package/dist/runtime/server/routes/cms/deploy.post.mjs +1 -1
  144. package/dist/runtime/server/routes/cms/export.post.mjs +4 -3
  145. package/dist/runtime/server/routes/cms/search.get.mjs +7 -5
  146. package/dist/runtime/server/routes/cms/sync.post.mjs +2 -1
  147. package/dist/runtime/server/routes/comments/[id]/react.post.mjs +1 -2
  148. package/dist/runtime/server/routes/comments/[id]/report.post.d.ts +1 -1
  149. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +0 -2
  150. package/dist/runtime/server/routes/comments/[id].delete.mjs +8 -4
  151. package/dist/runtime/server/routes/comments/[id].get.d.ts +1 -1
  152. package/dist/runtime/server/routes/comments/[id].get.mjs +1 -2
  153. package/dist/runtime/server/routes/comments/[id].patch.d.ts +1 -1
  154. package/dist/runtime/server/routes/comments/[id].patch.mjs +6 -3
  155. package/dist/runtime/server/routes/comments/batch.post.d.ts +2 -0
  156. package/dist/runtime/server/routes/comments/batch.post.mjs +33 -0
  157. package/dist/runtime/server/routes/comments/index.get.d.ts +1 -1
  158. package/dist/runtime/server/routes/comments/index.get.mjs +6 -4
  159. package/dist/runtime/server/routes/comments/index.post.d.ts +1 -1
  160. package/dist/runtime/server/routes/comments/index.post.mjs +6 -2
  161. package/dist/runtime/server/routes/feed.xml.get.mjs +3 -1
  162. package/dist/runtime/server/routes/sitemap.xml.get.mjs +3 -1
  163. package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +17 -0
  164. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +29 -0
  165. package/dist/runtime/server/routes/store/cart/index.delete.d.ts +6 -0
  166. package/dist/runtime/server/routes/store/cart/index.delete.mjs +11 -0
  167. package/dist/runtime/server/routes/store/cart/index.get.d.ts +5 -0
  168. package/dist/runtime/server/routes/store/cart/index.get.mjs +14 -0
  169. package/dist/runtime/server/routes/store/cart/items/[id].delete.d.ts +6 -0
  170. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +25 -0
  171. package/dist/runtime/server/routes/store/cart/items/[id].patch.d.ts +6 -0
  172. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +29 -0
  173. package/dist/runtime/server/routes/store/cart/items.post.d.ts +6 -0
  174. package/dist/runtime/server/routes/store/cart/items.post.mjs +36 -0
  175. package/dist/runtime/server/routes/store/categories/index.get.d.ts +2 -0
  176. package/dist/runtime/server/routes/store/categories/index.get.mjs +8 -0
  177. package/dist/runtime/server/routes/store/checkout.post.d.ts +6 -0
  178. package/dist/runtime/server/routes/store/checkout.post.mjs +21 -0
  179. package/dist/runtime/server/routes/store/coupons/apply.post.d.ts +7 -0
  180. package/dist/runtime/server/routes/store/coupons/apply.post.mjs +18 -0
  181. package/dist/runtime/server/routes/store/currencies.get.d.ts +15 -0
  182. package/dist/runtime/server/routes/store/currencies.get.mjs +13 -0
  183. package/dist/runtime/server/routes/store/orders/[id].get.d.ts +2 -0
  184. package/dist/runtime/server/routes/store/orders/[id].get.mjs +26 -0
  185. package/dist/runtime/server/routes/store/orders/download/[token].get.d.ts +7 -0
  186. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +57 -0
  187. package/dist/runtime/server/routes/store/orders/index.get.d.ts +5 -0
  188. package/dist/runtime/server/routes/store/orders/index.get.mjs +30 -0
  189. package/dist/runtime/server/routes/store/products/[slug].get.d.ts +2 -0
  190. package/dist/runtime/server/routes/store/products/[slug].get.mjs +18 -0
  191. package/dist/runtime/server/routes/store/products/index.get.d.ts +5 -0
  192. package/dist/runtime/server/routes/store/products/index.get.mjs +33 -0
  193. package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +9 -0
  194. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +18 -0
  195. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +14 -1
  196. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +14 -1
  197. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +24 -1
  198. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +6 -0
  199. package/dist/runtime/server/utils/ai.d.ts +146 -21
  200. package/dist/runtime/server/utils/ai.mjs +406 -11
  201. package/dist/runtime/server/utils/analytics-query.d.ts +13 -58
  202. package/dist/runtime/server/utils/audit.d.ts +5 -4
  203. package/dist/runtime/server/utils/audit.mjs +25 -14
  204. package/dist/runtime/server/utils/auth.d.ts +29 -12
  205. package/dist/runtime/server/utils/auth.mjs +88 -70
  206. package/dist/runtime/server/utils/bots.d.ts +20 -4
  207. package/dist/runtime/server/utils/bots.mjs +7 -3
  208. package/dist/runtime/server/utils/browser-utils.d.ts +23 -23
  209. package/dist/runtime/server/utils/cache.d.ts +31 -10
  210. package/dist/runtime/server/utils/cache.mjs +130 -53
  211. package/dist/runtime/server/utils/cms/collections.d.ts +23 -0
  212. package/dist/runtime/server/utils/cms/collections.mjs +143 -0
  213. package/dist/runtime/server/utils/cms/common.d.ts +9 -0
  214. package/dist/runtime/server/utils/cms/common.mjs +28 -0
  215. package/dist/runtime/server/utils/cms/git.mjs +2 -2
  216. package/dist/runtime/server/utils/cms/navigation.d.ts +46 -0
  217. package/dist/runtime/server/utils/cms/navigation.mjs +683 -0
  218. package/dist/runtime/server/utils/cms/preview.d.ts +11 -0
  219. package/dist/runtime/server/utils/cms/preview.mjs +50 -0
  220. package/dist/runtime/server/utils/cms/search.d.ts +1 -1
  221. package/dist/runtime/server/utils/cms/search.mjs +11 -7
  222. package/dist/runtime/server/utils/cms/sync.d.ts +34 -0
  223. package/dist/runtime/server/utils/cms/sync.mjs +1082 -0
  224. package/dist/runtime/server/utils/cms/taxonomy.d.ts +103 -0
  225. package/dist/runtime/server/utils/cms/taxonomy.mjs +348 -0
  226. package/dist/runtime/server/utils/cms.d.ts +13 -249
  227. package/dist/runtime/server/utils/cms.mjs +108 -2350
  228. package/dist/runtime/server/utils/comments-filter.d.ts +45 -0
  229. package/dist/runtime/server/utils/comments-filter.mjs +541 -0
  230. package/dist/runtime/server/utils/comments.d.ts +71 -0
  231. package/dist/runtime/server/utils/comments.mjs +137 -61
  232. package/dist/runtime/server/utils/config.d.ts +4 -3
  233. package/dist/runtime/server/utils/config.mjs +7 -6
  234. package/dist/runtime/server/utils/context.d.ts +14 -0
  235. package/dist/runtime/server/utils/context.mjs +2 -2
  236. package/dist/runtime/server/utils/crypto.d.ts +44 -5
  237. package/dist/runtime/server/utils/crypto.mjs +18 -0
  238. package/dist/runtime/server/utils/domains.mjs +9 -5
  239. package/dist/runtime/server/utils/drizzle.d.ts +35 -3
  240. package/dist/runtime/server/utils/drizzle.mjs +115 -6
  241. package/dist/runtime/server/utils/durable-object.d.ts +106 -0
  242. package/dist/runtime/server/utils/durable-object.mjs +628 -0
  243. package/dist/runtime/server/utils/email-inbound.d.ts +29 -0
  244. package/dist/runtime/server/utils/email-inbound.mjs +76 -0
  245. package/dist/runtime/server/utils/impersonation.d.ts +32 -2
  246. package/dist/runtime/server/utils/impersonation.mjs +16 -13
  247. package/dist/runtime/server/utils/lock.d.ts +71 -0
  248. package/dist/runtime/server/utils/lock.mjs +139 -0
  249. package/dist/runtime/server/utils/mail-suppression.mjs +7 -7
  250. package/dist/runtime/server/utils/mail.d.ts +30 -19
  251. package/dist/runtime/server/utils/mcp.d.ts +44 -0
  252. package/dist/runtime/server/utils/mcp.mjs +308 -0
  253. package/dist/runtime/server/utils/notifications.d.ts +72 -7
  254. package/dist/runtime/server/utils/notifications.mjs +67 -55
  255. package/dist/runtime/server/utils/oauth.d.ts +27 -4
  256. package/dist/runtime/server/utils/organization.d.ts +63 -7
  257. package/dist/runtime/server/utils/organization.mjs +26 -21
  258. package/dist/runtime/server/utils/passwordless.d.ts +62 -33
  259. package/dist/runtime/server/utils/payments.d.ts +51 -12
  260. package/dist/runtime/server/utils/payments.mjs +472 -282
  261. package/dist/runtime/server/utils/queue.d.ts +106 -13
  262. package/dist/runtime/server/utils/queue.mjs +313 -28
  263. package/dist/runtime/server/utils/rag.d.ts +42 -14
  264. package/dist/runtime/server/utils/rag.mjs +169 -4
  265. package/dist/runtime/server/utils/ratelimit.d.ts +34 -5
  266. package/dist/runtime/server/utils/ratelimit.mjs +95 -14
  267. package/dist/runtime/server/utils/realtime.d.ts +68 -52
  268. package/dist/runtime/server/utils/scheduled-task.d.ts +42 -1
  269. package/dist/runtime/server/utils/scheduled-task.mjs +29 -0
  270. package/dist/runtime/server/utils/schema-fallback.d.ts +1 -1
  271. package/dist/runtime/server/utils/schema-fallback.mjs +1 -1
  272. package/dist/runtime/server/utils/session.d.ts +84 -10
  273. package/dist/runtime/server/utils/session.mjs +12 -10
  274. package/dist/runtime/server/utils/sse.d.ts +75 -0
  275. package/dist/runtime/server/utils/sse.mjs +147 -0
  276. package/dist/runtime/server/utils/sso.d.ts +1 -1
  277. package/dist/runtime/server/utils/storage.d.ts +53 -4
  278. package/dist/runtime/server/utils/storage.mjs +15 -11
  279. package/dist/runtime/server/utils/store-localization.d.ts +51 -0
  280. package/dist/runtime/server/utils/store-localization.mjs +417 -0
  281. package/dist/runtime/server/utils/store.d.ts +207 -0
  282. package/dist/runtime/server/utils/store.mjs +2227 -0
  283. package/dist/runtime/server/utils/table-names.d.ts +51 -0
  284. package/dist/runtime/server/utils/table-names.mjs +69 -0
  285. package/dist/runtime/server/utils/tenant.d.ts +26 -2
  286. package/dist/runtime/server/utils/tenant.mjs +16 -12
  287. package/dist/runtime/server/utils/tools-registry-fallback.d.ts +1 -0
  288. package/dist/runtime/server/utils/tools-registry-fallback.mjs +1 -0
  289. package/dist/runtime/server/utils/totp.d.ts +45 -2
  290. package/dist/runtime/server/utils/tracker.d.ts +10 -11
  291. package/dist/runtime/server/utils/turnstile.d.ts +16 -1
  292. package/dist/runtime/server/utils/workflows.d.ts +92 -0
  293. package/dist/runtime/server/utils/workflows.mjs +299 -0
  294. package/dist/runtime/server.d.ts +8 -1
  295. package/dist/runtime/server.mjs +8 -5
  296. package/dist/runtime/service.d.ts +10 -10
  297. package/dist/runtime/storage.d.ts +1 -0
  298. package/dist/runtime/storage.mjs +1 -0
  299. package/dist/runtime/store.d.ts +4 -0
  300. package/dist/runtime/store.mjs +2 -0
  301. package/dist/runtime/test-utils.d.ts +11 -10
  302. package/dist/runtime/test-utils.mjs +64 -4
  303. package/dist/runtime/types/ai.d.ts +21 -2
  304. package/dist/runtime/types/d1.d.ts +17 -0
  305. package/dist/runtime/types/drizzle.d.ts +2 -2
  306. package/dist/runtime/types/durable-object.d.ts +62 -2
  307. package/dist/runtime/types/email.d.ts +46 -0
  308. package/dist/runtime/types/imports.d.ts +6 -1
  309. package/dist/runtime/types/index.d.ts +58 -0
  310. package/dist/runtime/types/index.mjs +3 -0
  311. package/dist/runtime/types/mcp.d.ts +83 -0
  312. package/dist/runtime/types/mcp.mjs +0 -0
  313. package/dist/runtime/types/queue.d.ts +36 -0
  314. package/dist/runtime/types/r2.d.ts +41 -0
  315. package/dist/runtime/types/store.d.ts +313 -0
  316. package/dist/runtime/types/store.mjs +0 -0
  317. package/dist/runtime/types/workflows.d.ts +98 -0
  318. package/dist/runtime/types/workflows.mjs +0 -0
  319. package/dist/runtime/workflows.d.ts +5 -0
  320. package/dist/runtime/workflows.mjs +2 -0
  321. package/dist/types/ai.d.ts +721 -0
  322. package/dist/types/cms.d.ts +710 -0
  323. package/dist/types.d.ts +430 -1292
  324. package/dist/utils/auth-schema.d.ts +3 -2
  325. package/dist/utils/bots.d.ts +20 -0
  326. package/dist/utils/comments-schema.d.ts +5 -4
  327. package/dist/utils/drizzle.d.ts +83 -3
  328. package/dist/utils/durable-objects.d.ts +10 -0
  329. package/dist/utils/email-inbound.d.ts +10 -0
  330. package/dist/utils/local-db.d.ts +1 -3
  331. package/dist/utils/mcp.d.ts +24 -0
  332. package/dist/utils/notifications-schema.d.ts +5 -4
  333. package/dist/utils/payments-schema.d.ts +4 -3
  334. package/dist/utils/store-schema.d.ts +14 -0
  335. package/dist/utils/table-names.d.ts +1 -0
  336. package/dist/utils/tenants-schema.d.ts +4 -3
  337. package/dist/utils/tools.d.ts +20 -0
  338. package/dist/utils/workflows.d.ts +8 -0
  339. package/package.json +34 -4
  340. package/dist/chunks/wrangler.mjs +0 -897
  341. package/dist/runtime/app/components/AuthRegister.vue +0 -306
  342. package/dist/runtime/app/components/AuthSessionsList.vue +0 -137
  343. package/dist/runtime/app/components/AuthSignIn.vue +0 -298
  344. package/dist/runtime/app/components/CMSBookmarkButton.vue +0 -59
  345. package/dist/runtime/app/components/CMSImage.vue +0 -47
  346. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +0 -110
  347. package/dist/runtime/app/components/CMSNewsletter.vue +0 -81
  348. package/dist/runtime/app/components/CMSPreviewBanner.vue +0 -83
  349. package/dist/runtime/app/components/CMSTableOfContents.vue +0 -84
  350. package/dist/runtime/app/components/CMSVersionBanner.vue +0 -53
  351. package/dist/runtime/app/components/CMSVersionSwitcher.vue +0 -140
  352. package/dist/runtime/app/components/Comments.vue +0 -411
  353. package/dist/runtime/app/components/FileUpload.vue +0 -200
  354. package/dist/runtime/app/components/ImpersonationBanner.vue +0 -61
  355. package/dist/runtime/app/components/NotificationBell.vue +0 -263
  356. package/dist/runtime/app/components/NotificationList.vue +0 -205
  357. package/dist/runtime/app/components/NotificationPrompt.vue +0 -133
  358. package/dist/runtime/app/components/PricingGated.vue +0 -81
  359. package/dist/runtime/app/components/PricingTable.vue +0 -274
  360. package/dist/runtime/app/components/RealtimeChat.vue +0 -164
  361. package/dist/runtime/app/components/RealtimePresence.vue +0 -129
  362. package/dist/runtime/app/components/RealtimeStatus.vue +0 -79
  363. package/dist/runtime/app/components/SubscriptionCard.vue +0 -207
  364. package/dist/runtime/app/components/UserProfile.vue +0 -558
@@ -2,9 +2,12 @@ import { createError, getRequestHeader } from "nuxt/server";
2
2
  import { getCloudflareEnv } from "../../bindings.mjs";
3
3
  import { getQarpeoConfig } from "./config.mjs";
4
4
  import { assertRateLimit } from "./ratelimit.mjs";
5
+ import { requireTurnstile } from "./turnstile.mjs";
5
6
  import { getAuthContext } from "./context.mjs";
6
7
  import { nanoid } from "./crypto.mjs";
8
+ import { validateCommentContent } from "./comments-filter.mjs";
7
9
  import { validateTargetUrn } from "./urn.mjs";
10
+ import { resolveTableName, resolveIndexName } from "./table-names.mjs";
8
11
  export { isValidTargetUrn, validateTargetUrn } from "./urn.mjs";
9
12
  function getD1(event) {
10
13
  const env = getCloudflareEnv(event);
@@ -13,14 +16,14 @@ function getD1(event) {
13
16
  if (!db) throw new Error("[qarpeo/comments] D1 database binding not found");
14
17
  return db;
15
18
  }
16
- function getTable() {
17
- return "_qarpeo_comments";
19
+ function getTable(event) {
20
+ return resolveTableName("comment", event);
18
21
  }
19
- function getReportsTable() {
20
- return "_qarpeo_comment_reports";
22
+ function getReportsTable(event) {
23
+ return resolveTableName("comment_report", event);
21
24
  }
22
- function getReactionsTable() {
23
- return "_qarpeo_comment_reactions";
25
+ function getReactionsTable(event) {
26
+ return resolveTableName("comment_reaction", event);
24
27
  }
25
28
  export function getCommentsConfig(event) {
26
29
  const cfg = getQarpeoConfig(event).comments || {};
@@ -37,6 +40,7 @@ export function getCommentsConfig(event) {
37
40
  turnstile: cfg.turnstile,
38
41
  reactions: cfg.reactions,
39
42
  roles: cfg.roles,
43
+ moderation: cfg.moderation,
40
44
  prefix: cfg.prefix || "/api/comments"
41
45
  };
42
46
  }
@@ -61,8 +65,10 @@ function getRequireAuth(event) {
61
65
  }
62
66
  function getCallerIp(event) {
63
67
  if (!event) return "unknown";
68
+ const cfIp = getRequestHeader(event, "cf-connecting-ip")?.trim();
69
+ if (cfIp) return cfIp;
64
70
  const forwarded = getRequestHeader(event, "x-forwarded-for") || "";
65
- return forwarded.split(",")[0]?.trim() || getRequestHeader(event, "cf-connecting-ip") || "unknown";
71
+ return forwarded.split(",")[0]?.trim() || "unknown";
66
72
  }
67
73
  function rowToComment(row) {
68
74
  return {
@@ -72,6 +78,7 @@ function rowToComment(row) {
72
78
  parentId: row.parent_id ?? void 0,
73
79
  path: row.path,
74
80
  depth: row.depth,
81
+ authorId: row.author_id ?? void 0,
75
82
  authorName: row.author_name,
76
83
  authorEmail: row.author_email ?? void 0,
77
84
  authorAvatar: row.author_avatar ?? void 0,
@@ -113,9 +120,9 @@ let _ensureCommentsTablesPromise = null;
113
120
  export async function ensureCommentsTables(event) {
114
121
  if (_ensureCommentsTablesPromise) return _ensureCommentsTablesPromise;
115
122
  const db = getD1(event);
116
- const t = getTable();
117
- const rt = getReportsTable();
118
- const rxt = getReactionsTable();
123
+ const t = getTable(event);
124
+ const rt = getReportsTable(event);
125
+ const rxt = getReactionsTable(event);
119
126
  _ensureCommentsTablesPromise = db.batch([
120
127
  db.prepare(`CREATE TABLE IF NOT EXISTS ${t} (
121
128
  id TEXT PRIMARY KEY,
@@ -124,6 +131,7 @@ export async function ensureCommentsTables(event) {
124
131
  parent_id TEXT,
125
132
  path TEXT NOT NULL DEFAULT '/',
126
133
  depth INTEGER NOT NULL DEFAULT 0,
134
+ author_id TEXT,
127
135
  author_name TEXT NOT NULL,
128
136
  author_email TEXT,
129
137
  author_avatar TEXT,
@@ -138,11 +146,12 @@ export async function ensureCommentsTables(event) {
138
146
  updated_at INTEGER NOT NULL
139
147
  )`),
140
148
  db.prepare(
141
- `CREATE INDEX IF NOT EXISTS idx_qarpeo_comments_target ON ${t}(target_urn, status, created_at DESC)`
149
+ `CREATE INDEX IF NOT EXISTS ${resolveIndexName(t, "target")} ON ${t}(target_urn, status, created_at DESC)`
142
150
  ),
143
- db.prepare(`CREATE INDEX IF NOT EXISTS idx_qarpeo_comments_parent ON ${t}(parent_id)`),
144
- db.prepare(`CREATE INDEX IF NOT EXISTS idx_qarpeo_comments_path ON ${t}(path)`),
145
- db.prepare(`CREATE INDEX IF NOT EXISTS idx_qarpeo_comments_tenant ON ${t}(tenant_id)`),
151
+ db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(t, "parent")} ON ${t}(parent_id)`),
152
+ db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(t, "path")} ON ${t}(path)`),
153
+ db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(t, "tenant")} ON ${t}(tenant_id)`),
154
+ db.prepare(`CREATE INDEX IF NOT EXISTS ${resolveIndexName(t, "author")} ON ${t}(author_id)`),
146
155
  db.prepare(`CREATE TABLE IF NOT EXISTS ${rt} (
147
156
  id TEXT PRIMARY KEY,
148
157
  comment_id TEXT NOT NULL,
@@ -153,7 +162,7 @@ export async function ensureCommentsTables(event) {
153
162
  created_at INTEGER NOT NULL
154
163
  )`),
155
164
  db.prepare(
156
- `CREATE INDEX IF NOT EXISTS idx_qarpeo_reports_comment ON ${rt}(comment_id)`
165
+ `CREATE INDEX IF NOT EXISTS ${resolveIndexName(rt, "comment")} ON ${rt}(comment_id)`
157
166
  ),
158
167
  db.prepare(`CREATE TABLE IF NOT EXISTS ${rxt} (
159
168
  id TEXT PRIMARY KEY,
@@ -164,7 +173,7 @@ export async function ensureCommentsTables(event) {
164
173
  created_at INTEGER NOT NULL
165
174
  )`),
166
175
  db.prepare(
167
- `CREATE INDEX IF NOT EXISTS idx_qarpeo_reactions_comment ON ${rxt}(comment_id)`
176
+ `CREATE INDEX IF NOT EXISTS ${resolveIndexName(rxt, "comment")} ON ${rxt}(comment_id)`
168
177
  )
169
178
  ]).then(() => void 0).catch((err) => {
170
179
  _ensureCommentsTablesPromise = null;
@@ -175,7 +184,7 @@ export async function ensureCommentsTables(event) {
175
184
  export async function queryComments(opts, event) {
176
185
  validateTargetUrn(opts.targetUrn);
177
186
  const db = getD1(event);
178
- const t = getTable();
187
+ const t = getTable(event);
179
188
  const statuses = opts.status ? Array.isArray(opts.status) ? opts.status : [opts.status] : ["approved"];
180
189
  const placeholders = statuses.map(() => "?").join(", ");
181
190
  const limit = Math.min(opts.limit ?? 50, 200);
@@ -204,7 +213,7 @@ export async function queryComments(opts, event) {
204
213
  ).bind(...params, limit, offset).all();
205
214
  const rootComments = (rows.results ?? []).map(rowToComment);
206
215
  if (!opts.threaded) {
207
- await populateReactionCounts(db, rootComments);
216
+ await populateReactionCounts(db, rootComments, event);
208
217
  return { comments: rootComments, total };
209
218
  }
210
219
  if (rootComments.length === 0) return { comments: [], total };
@@ -220,7 +229,7 @@ export async function queryComments(opts, event) {
220
229
  const byId = /* @__PURE__ */ new Map();
221
230
  for (const c of rootComments) byId.set(c.id, { ...c, replies: [] });
222
231
  for (const c of allDescendants) byId.set(c.id, { ...c, replies: [] });
223
- await populateReactionCounts(db, [...byId.values()]);
232
+ await populateReactionCounts(db, [...byId.values()], event);
224
233
  const roots = [];
225
234
  for (const c of rootComments) roots.push(byId.get(c.id));
226
235
  for (const c of allDescendants) {
@@ -230,12 +239,12 @@ export async function queryComments(opts, event) {
230
239
  }
231
240
  return { comments: roots, total };
232
241
  }
233
- async function populateReactionCounts(db, comments) {
242
+ async function populateReactionCounts(db, comments, event) {
234
243
  if (comments.length === 0) return;
235
244
  const ids = comments.map((c) => c.id);
236
245
  const placeholders = ids.map(() => "?").join(", ");
237
246
  const rxRows = await db.prepare(
238
- `SELECT comment_id, reaction, COUNT(*) as cnt FROM ${getReactionsTable()} WHERE comment_id IN (${placeholders}) GROUP BY comment_id, reaction`
247
+ `SELECT comment_id, reaction, COUNT(*) as cnt FROM ${getReactionsTable(event)} WHERE comment_id IN (${placeholders}) GROUP BY comment_id, reaction`
239
248
  ).bind(...ids).all().catch(() => ({ results: [] }));
240
249
  const countsMap = /* @__PURE__ */ new Map();
241
250
  for (const r of rxRows.results ?? []) {
@@ -248,10 +257,10 @@ async function populateReactionCounts(db, comments) {
248
257
  }
249
258
  export async function getComment(id, event) {
250
259
  const db = getD1(event);
251
- const row = await db.prepare(`SELECT * FROM ${getTable()} WHERE id = ?`).bind(id).first();
260
+ const row = await db.prepare(`SELECT * FROM ${getTable(event)} WHERE id = ?`).bind(id).first();
252
261
  if (!row) return null;
253
262
  const comment = rowToComment(row);
254
- await populateReactionCounts(db, [comment]);
263
+ await populateReactionCounts(db, [comment], event);
255
264
  return comment;
256
265
  }
257
266
  export async function createComment(input, event) {
@@ -259,7 +268,7 @@ export async function createComment(input, event) {
259
268
  const cfg = getCommentsConfig(event);
260
269
  const requireAuth = getRequireAuth(event);
261
270
  const maxLength = getMaxLength(event);
262
- const t = getTable();
271
+ const t = getTable(event);
263
272
  const auth = event ? await getAuthContext(event).catch(() => null) : null;
264
273
  if (requireAuth && !auth?.user?.id) {
265
274
  throw createError({ statusCode: 401, statusMessage: "Authentication required to comment." });
@@ -283,23 +292,15 @@ export async function createComment(input, event) {
283
292
  statusMessage: `Comment must be ${maxLength} characters or fewer.`
284
293
  });
285
294
  }
295
+ const modResult = validateCommentContent(content, cfg.moderation ?? {});
296
+ let isQuarantined = !modResult.valid;
297
+ let moderationViolation = modResult.violation;
286
298
  const authorName = (input.authorName ?? auth?.user?.name ?? "Anonymous").trim();
287
299
  if (!authorName) {
288
300
  throw createError({ statusCode: 400, statusMessage: "Author name is required." });
289
301
  }
290
- if (input.turnstileToken && process.env.CLOUDFLARE_TURNSTILE_SECRET_KEY) {
291
- const cfRes = await fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
292
- method: "POST",
293
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
294
- body: new URLSearchParams({
295
- secret: process.env.CLOUDFLARE_TURNSTILE_SECRET_KEY,
296
- response: input.turnstileToken
297
- })
298
- });
299
- const cfJson = await cfRes.json();
300
- if (!cfJson.success) {
301
- throw createError({ statusCode: 403, statusMessage: "Turnstile verification failed." });
302
- }
302
+ if (cfg.turnstile && event) {
303
+ await requireTurnstile(event, input.turnstileToken);
303
304
  }
304
305
  const db = getD1(event);
305
306
  const id = nanoid();
@@ -307,7 +308,9 @@ export async function createComment(input, event) {
307
308
  let path = "/";
308
309
  let depth = 0;
309
310
  if (input.parentId) {
310
- const parent = await db.prepare(`SELECT id, path, depth, status FROM ${t} WHERE id = ?`).bind(input.parentId).first();
311
+ const parent = await db.prepare(
312
+ `SELECT id, path, depth, status, (SELECT COUNT(*) FROM ${t} WHERE parent_id = ?) as sibling_cnt FROM ${t} WHERE id = ?`
313
+ ).bind(input.parentId, input.parentId).first();
311
314
  if (!parent) {
312
315
  throw createError({ statusCode: 404, statusMessage: "Parent comment not found." });
313
316
  }
@@ -320,8 +323,7 @@ export async function createComment(input, event) {
320
323
  statusMessage: `Maximum thread depth of ${getThreadDepth(event)} reached.`
321
324
  });
322
325
  }
323
- const siblingResult = await db.prepare(`SELECT COUNT(*) as cnt FROM ${t} WHERE parent_id = ?`).bind(input.parentId).first();
324
- const siblingCount = siblingResult?.cnt ?? 0;
326
+ const siblingCount = Number(parent.sibling_cnt) || 0;
325
327
  path = buildPath(parent.path, siblingCount);
326
328
  depth = parent.depth + 1;
327
329
  } else {
@@ -334,19 +336,54 @@ export async function createComment(input, event) {
334
336
  const autoApprove = cfg.autoApproveAuth ?? process.env.QARPEO_COMMENTS_AUTO_APPROVE_AUTH === "1";
335
337
  if (autoApprove) status = "approved";
336
338
  const role = auth.user?.role || "";
337
- if (role === "admin" || role === "super_admin" || role === "moderator") {
339
+ if (role === "admin" || role === "super" || role === "moderator") {
338
340
  status = "approved";
339
341
  }
340
342
  }
341
343
  const avatar = generateAvatarSvg(authorName);
342
344
  const ip = event ? getCallerIp(event) : void 0;
345
+ const authorId = input.authorId ?? auth?.user?.id ?? null;
346
+ const authorEmail = input.authorEmail ?? auth?.user?.email ?? null;
347
+ const duplicateWindowMs = cfg.moderation?.duplicateWindowMs ?? 3e5;
348
+ if (duplicateWindowMs > 0 && (ip || authorId)) {
349
+ const since = now - duplicateWindowMs;
350
+ const dupQuery = authorId ? `SELECT id FROM ${t} WHERE target_urn = ? AND content = ? AND created_at >= ? AND (author_ip = ? OR author_id = ?) LIMIT 1` : `SELECT id FROM ${t} WHERE target_urn = ? AND content = ? AND created_at >= ? AND author_ip = ? LIMIT 1`;
351
+ const dupParams = authorId ? [input.targetUrn, content, since, ip ?? "", authorId] : [input.targetUrn, content, since, ip ?? ""];
352
+ const existingDup = await db.prepare(dupQuery).bind(...dupParams).first();
353
+ if (existingDup) {
354
+ if (cfg.moderation?.action === "quarantine") {
355
+ isQuarantined = true;
356
+ moderationViolation = {
357
+ rule: "duplicate",
358
+ message: "Duplicate comment detected.",
359
+ match: existingDup.id
360
+ };
361
+ } else {
362
+ throw createError({
363
+ statusCode: 400,
364
+ statusMessage: "Duplicate comment detected. Please do not submit the same comment repeatedly."
365
+ });
366
+ }
367
+ }
368
+ }
369
+ let commentMetadata = { ...input.metadata ?? {} };
370
+ if (isQuarantined && moderationViolation) {
371
+ status = "spam";
372
+ commentMetadata = {
373
+ ...commentMetadata,
374
+ moderation: {
375
+ quarantined: true,
376
+ violation: moderationViolation
377
+ }
378
+ };
379
+ }
343
380
  await db.prepare(
344
381
  `INSERT INTO ${t}
345
382
  (id, target_urn, tenant_id, parent_id, path, depth,
346
- author_name, author_email, author_avatar, author_ip,
383
+ author_id, author_name, author_email, author_avatar, author_ip,
347
384
  content, status, report_count, reaction_counts, metadata_json,
348
385
  created_at, updated_at)
349
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, '{}', ?, ?, ?)`
386
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, '{}', ?, ?, ?)`
350
387
  ).bind(
351
388
  id,
352
389
  input.targetUrn,
@@ -354,40 +391,78 @@ export async function createComment(input, event) {
354
391
  input.parentId ?? null,
355
392
  path,
356
393
  depth,
394
+ authorId,
357
395
  authorName,
358
- input.authorEmail ?? null,
396
+ authorEmail,
359
397
  avatar,
360
398
  ip ?? null,
361
399
  content,
362
400
  status,
363
- JSON.stringify(input.metadata ?? {}),
401
+ JSON.stringify(commentMetadata),
364
402
  now,
365
403
  now
366
404
  ).run();
367
- return await getComment(id, event);
405
+ return {
406
+ id,
407
+ targetUrn: input.targetUrn,
408
+ tenantId: input.tenantId ?? void 0,
409
+ parentId: input.parentId ?? void 0,
410
+ path,
411
+ depth,
412
+ authorId: authorId ?? void 0,
413
+ authorName,
414
+ authorEmail: authorEmail ?? void 0,
415
+ authorAvatar: avatar,
416
+ content,
417
+ status,
418
+ deletedAt: void 0,
419
+ reportCount: 0,
420
+ reactionCounts: {},
421
+ metadata: commentMetadata,
422
+ createdAt: now,
423
+ updatedAt: now
424
+ };
368
425
  }
369
426
  export async function updateCommentStatus(id, status, event) {
370
427
  const db = getD1(event);
371
428
  const now = Date.now();
372
- await db.prepare(`UPDATE ${getTable()} SET status = ?, updated_at = ? WHERE id = ?`).bind(status, now, id).run();
429
+ await db.prepare(`UPDATE ${getTable(event)} SET status = ?, updated_at = ? WHERE id = ?`).bind(status, now, id).run();
373
430
  return getComment(id, event);
374
431
  }
375
432
  export async function deleteComment(id, event) {
376
433
  const db = getD1(event);
377
434
  const now = Date.now();
378
- const replyResult = await db.prepare(`SELECT COUNT(*) as cnt FROM ${getTable()} WHERE parent_id = ?`).bind(id).first();
435
+ const replyResult = await db.prepare(`SELECT COUNT(*) as cnt FROM ${getTable(event)} WHERE parent_id = ?`).bind(id).first();
379
436
  const hasReplies = (replyResult?.cnt ?? 0) > 0;
380
437
  if (hasReplies) {
381
438
  await db.prepare(
382
- `UPDATE ${getTable()}
439
+ `UPDATE ${getTable(event)}
383
440
  SET status = 'deleted', deleted_at = ?, updated_at = ?,
384
441
  content = '[deleted]', author_email = NULL, author_ip = NULL
385
442
  WHERE id = ?`
386
443
  ).bind(now, now, id).run();
387
444
  } else {
388
- await db.prepare(`DELETE FROM ${getTable()} WHERE id = ?`).bind(id).run();
389
- await db.prepare(`DELETE FROM ${getReactionsTable()} WHERE comment_id = ?`).bind(id).run();
445
+ await db.prepare(`DELETE FROM ${getTable(event)} WHERE id = ?`).bind(id).run();
446
+ await db.prepare(`DELETE FROM ${getReactionsTable(event)} WHERE comment_id = ?`).bind(id).run();
447
+ }
448
+ }
449
+ export async function batchModerateComments(input, event) {
450
+ const ids = (input.ids || []).map((id) => typeof id === "string" ? id.trim() : "").filter(Boolean);
451
+ if (ids.length === 0) {
452
+ return { success: true, count: 0 };
453
+ }
454
+ const cappedIds = ids.slice(0, 100);
455
+ if (input.action === "delete") {
456
+ await Promise.all(cappedIds.map((id) => deleteComment(id, event)));
457
+ return { success: true, count: cappedIds.length };
390
458
  }
459
+ const newStatus = input.action === "approve" ? "approved" : "spam";
460
+ const db = getD1(event);
461
+ const t = getTable(event);
462
+ const now = Date.now();
463
+ const placeholders = cappedIds.map(() => "?").join(", ");
464
+ await db.prepare(`UPDATE ${t} SET status = ?, updated_at = ? WHERE id IN (${placeholders})`).bind(newStatus, now, ...cappedIds).run();
465
+ return { success: true, count: cappedIds.length };
391
466
  }
392
467
  export async function reportComment(commentId, reason, opts, event) {
393
468
  const db = getD1(event);
@@ -395,14 +470,14 @@ export async function reportComment(commentId, reason, opts, event) {
395
470
  const now = Date.now();
396
471
  const ip = event ? getCallerIp(event) : void 0;
397
472
  await db.prepare(
398
- `INSERT INTO ${getReportsTable()} (id, comment_id, reporter_ip, reporter_user_id, reason, note, created_at)
473
+ `INSERT INTO ${getReportsTable(event)} (id, comment_id, reporter_ip, reporter_user_id, reason, note, created_at)
399
474
  VALUES (?, ?, ?, ?, ?, ?, ?)`
400
475
  ).bind(id, commentId, ip ?? null, opts?.userId ?? null, reason, opts?.note ?? null, now).run();
401
476
  const updated = await db.prepare(
402
- `UPDATE ${getTable()} SET report_count = report_count + 1, updated_at = ? WHERE id = ? RETURNING report_count`
477
+ `UPDATE ${getTable(event)} SET report_count = report_count + 1, updated_at = ? WHERE id = ? RETURNING report_count`
403
478
  ).bind(now, commentId).first();
404
479
  if ((updated?.report_count ?? 0) >= getAutoHideThreshold(event)) {
405
- await db.prepare(`UPDATE ${getTable()} SET status = 'spam', updated_at = ? WHERE id = ? AND status = 'approved'`).bind(now, commentId).run();
480
+ await db.prepare(`UPDATE ${getTable(event)} SET status = 'spam', updated_at = ? WHERE id = ? AND status = 'approved'`).bind(now, commentId).run();
406
481
  }
407
482
  return { id, commentId, reporterIp: ip, reporterUserId: opts?.userId, reason, note: opts?.note, createdAt: now };
408
483
  }
@@ -410,7 +485,8 @@ export async function reactToComment(commentId, reaction, opts, event) {
410
485
  const db = getD1(event);
411
486
  const ip = event ? getCallerIp(event) : void 0;
412
487
  const now = Date.now();
413
- const allowedReactions = process.env.QARPEO_COMMENTS_REACTIONS ? JSON.parse(process.env.QARPEO_COMMENTS_REACTIONS) : ["like", "heart", "fire", "unicorn"];
488
+ const cfg = getCommentsConfig(event);
489
+ const allowedReactions = Array.isArray(cfg.reactions) ? cfg.reactions : process.env.QARPEO_COMMENTS_REACTIONS ? JSON.parse(process.env.QARPEO_COMMENTS_REACTIONS) : ["like", "heart", "fire", "unicorn"];
414
490
  if (!allowedReactions.includes(reaction)) {
415
491
  throw createError({
416
492
  statusCode: 400,
@@ -420,31 +496,31 @@ export async function reactToComment(commentId, reaction, opts, event) {
420
496
  let existing = null;
421
497
  if (opts?.userId) {
422
498
  existing = await db.prepare(
423
- `SELECT id FROM ${getReactionsTable()} WHERE comment_id = ? AND user_id = ? AND reaction = ?`
499
+ `SELECT id FROM ${getReactionsTable(event)} WHERE comment_id = ? AND user_id = ? AND reaction = ?`
424
500
  ).bind(commentId, opts.userId, reaction).first();
425
501
  } else if (ip) {
426
502
  existing = await db.prepare(
427
- `SELECT id FROM ${getReactionsTable()} WHERE comment_id = ? AND ip = ? AND reaction = ? AND user_id IS NULL`
503
+ `SELECT id FROM ${getReactionsTable(event)} WHERE comment_id = ? AND ip = ? AND reaction = ? AND user_id IS NULL`
428
504
  ).bind(commentId, ip, reaction).first();
429
505
  }
430
506
  let added;
431
507
  if (existing) {
432
- await db.prepare(`DELETE FROM ${getReactionsTable()} WHERE id = ?`).bind(existing.id).run();
508
+ await db.prepare(`DELETE FROM ${getReactionsTable(event)} WHERE id = ?`).bind(existing.id).run();
433
509
  added = false;
434
510
  } else {
435
511
  await db.prepare(
436
- `INSERT INTO ${getReactionsTable()} (id, comment_id, user_id, ip, reaction, created_at)
512
+ `INSERT INTO ${getReactionsTable(event)} (id, comment_id, user_id, ip, reaction, created_at)
437
513
  VALUES (?, ?, ?, ?, ?, ?)`
438
514
  ).bind(nanoid(), commentId, opts?.userId ?? null, ip ?? null, reaction, now).run();
439
515
  added = true;
440
516
  }
441
517
  const rows = await db.prepare(
442
- `SELECT reaction, COUNT(*) as cnt FROM ${getReactionsTable()} WHERE comment_id = ? GROUP BY reaction`
518
+ `SELECT reaction, COUNT(*) as cnt FROM ${getReactionsTable(event)} WHERE comment_id = ? GROUP BY reaction`
443
519
  ).bind(commentId).all();
444
520
  const counts = {};
445
521
  for (const r of rows.results ?? []) {
446
522
  counts[r.reaction] = r.cnt;
447
523
  }
448
- await db.prepare(`UPDATE ${getTable()} SET reaction_counts = ?, updated_at = ? WHERE id = ?`).bind(JSON.stringify(counts), now, commentId).run();
524
+ await db.prepare(`UPDATE ${getTable(event)} SET reaction_counts = ?, updated_at = ? WHERE id = ?`).bind(JSON.stringify(counts), now, commentId).run();
449
525
  return { added, reactionCounts: counts };
450
526
  }
@@ -1,5 +1,5 @@
1
1
  import { type RequestEvent } from "nuxt/server";
2
- import type { AuthOptions, BlobOptions, CMSOptions, CommentsOptions, PaymentsOptions, AppRateLimitOptions, RealtimeOptions, MailOptions, AnalyticsOptions, MultitenantOptions } from "../../../types";
2
+ import type { AuthOptions, BlobOptions, CMSOptions, CommentsOptions, PaymentsOptions, AppRateLimitOptions, RealtimeOptions, MailOptions, AnalyticsOptions, MultitenantOptions, StoreOptions } from "../../../types";
3
3
  export interface QarpeoRuntimeConfig {
4
4
  auth: AuthOptions;
5
5
  blob: BlobOptions;
@@ -12,6 +12,7 @@ export interface QarpeoRuntimeConfig {
12
12
  mail: MailOptions;
13
13
  analytics: AnalyticsOptions;
14
14
  multitenant: MultitenantOptions;
15
+ store: StoreOptions;
15
16
  agents: Record<string, any>;
16
17
  jobs: Record<string, any>;
17
18
  [key: string]: any;
@@ -24,7 +25,7 @@ export declare function getQarpeoConfig(event?: RequestEvent): QarpeoRuntimeConf
24
25
  /** Alias for getQarpeoConfig */
25
26
  export declare const useQarpeoConfig: typeof getQarpeoConfig;
26
27
  /**
27
- * Returns the application secret (NUXT_APP_SECRET or legacy NUXT_SESSION_PASSWORD) from runtime
28
- * config or Cloudflare bindings. Used for HMAC signing where we need a root secret key.
28
+ * Returns the application secret (NUXT_APP_SECRET) from runtime config or Cloudflare bindings.
29
+ * Used for HMAC signing where we need a root secret key.
29
30
  */
30
31
  export declare function getSessionSecret(event?: RequestEvent, fallback?: string): string;
@@ -6,10 +6,10 @@ export function getQarpeoConfig(event) {
6
6
  } catch {
7
7
  rc = void 0;
8
8
  }
9
- if (!rc) {
10
- rc = globalThis.__NUXT_RUNTIME_CONFIG__ || {};
9
+ if (!rc || !rc.qarpeo) {
10
+ rc = globalThis.__NUXT_RUNTIME_CONFIG__ || rc || {};
11
11
  }
12
- const q = rc?.qarpeo || {};
12
+ const q = event?.context?.qarpeo || rc?.qarpeo || {};
13
13
  return {
14
14
  auth: q.auth || {},
15
15
  blob: q.blob || q.storage || {},
@@ -22,6 +22,7 @@ export function getQarpeoConfig(event) {
22
22
  mail: q.mail || {},
23
23
  analytics: q.analytics || {},
24
24
  multitenant: q.multitenant || {},
25
+ store: q.store || {},
25
26
  agents: q.agents || {},
26
27
  jobs: q.jobs || {},
27
28
  ...q
@@ -33,7 +34,7 @@ function getEphemeralDevSecret() {
33
34
  if (!_ephemeralDevSecret) {
34
35
  _ephemeralDevSecret = "qarpeo_dev_" + Math.random().toString(36).slice(2) + Date.now().toString(36);
35
36
  console.warn(
36
- "[qarpeo] Warning: No NUXT_APP_SECRET or NUXT_SESSION_PASSWORD configured. Using ephemeral in-memory key for token signing."
37
+ "[qarpeo] Warning: No NUXT_APP_SECRET configured. Using ephemeral in-memory key for token signing."
37
38
  );
38
39
  }
39
40
  return _ephemeralDevSecret;
@@ -46,7 +47,7 @@ export function getSessionSecret(event, fallback) {
46
47
  rc = void 0;
47
48
  }
48
49
  const env = event?.context?.cloudflare?.env || globalThis.__qarpeo_env__ || {};
49
- const secret = env.NUXT_APP_SECRET || env.APP_SECRET || env.NUXT_SESSION_PASSWORD || rc?.appSecret || rc?.session?.password || globalThis.__NUXT_RUNTIME_CONFIG__?.appSecret || globalThis.__NUXT_RUNTIME_CONFIG__?.session?.password || globalThis.process?.env?.NUXT_APP_SECRET || globalThis.process?.env?.NUXT_SESSION_PASSWORD;
50
+ const secret = env.NUXT_APP_SECRET || env.APP_SECRET || rc?.appSecret || globalThis.__NUXT_RUNTIME_CONFIG__?.appSecret || globalThis.process?.env?.NUXT_APP_SECRET;
50
51
  if (secret) {
51
52
  return secret;
52
53
  }
@@ -58,7 +59,7 @@ export function getSessionSecret(event, fallback) {
58
59
  );
59
60
  if (!isDevOrTest) {
60
61
  throw new Error(
61
- "[qarpeo] Missing required secret: NUXT_APP_SECRET or NUXT_SESSION_PASSWORD must be configured in production for secure token and signature generation."
62
+ "[qarpeo] Missing required secret: NUXT_APP_SECRET must be configured in production for secure token and signature generation."
62
63
  );
63
64
  }
64
65
  return getEphemeralDevSecret();
@@ -5,10 +5,24 @@ export declare function getQarpeoSession(event: RequestEvent): Promise<QarpeoSes
5
5
  /**
6
6
  * Resolves the unified authentication context for the current request. Unifies Bearer PAT tokens
7
7
  * (qp_live_...) and cookie sessions. Returns null if unauthenticated (never throws).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const auth = await getAuthContext(event)
12
+ * if (auth) console.log("User:", auth.user.email, "IsAdmin:", auth.isAdmin)
13
+ * ```
8
14
  */
9
15
  export declare function getAuthContext(event: RequestEvent): Promise<QarpeoAuthContext | null>;
10
16
  /**
11
17
  * Enforces authentication on the current request. Supports cookie sessions, Bearer PAT tokens, role
12
18
  * gates, and organization gates. Throws 401 or 403 on failure.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * export default defineEventHandler(async (event) => {
23
+ * const { user, isAdmin } = await requireAuth(event, { role: "admin" })
24
+ * return { message: `Hello ${user.name}` }
25
+ * })
26
+ * ```
13
27
  */
14
28
  export declare function requireAuth(event: RequestEvent, options?: RequireAuthOptions): Promise<QarpeoAuthContext>;
@@ -15,7 +15,7 @@ export async function getAuthContext(event) {
15
15
  try {
16
16
  const tokenResult = await verifyApiToken(event, bearerMatch[1]);
17
17
  if (tokenResult?.user?.id) {
18
- const isAdmin = tokenResult.user.role === "admin" || tokenResult.user.role === "super_admin";
18
+ const isAdmin = tokenResult.user.role === "admin" || tokenResult.user.role === "super";
19
19
  return {
20
20
  user: tokenResult.user,
21
21
  session: null,
@@ -37,7 +37,7 @@ export async function getAuthContext(event) {
37
37
  }
38
38
  const session = await getQarpeoSession(event);
39
39
  if (session?.user?.id) {
40
- const isAdmin = session.user.role === "admin" || session.user.role === "super_admin";
40
+ const isAdmin = session.user.role === "admin" || session.user.role === "super";
41
41
  return {
42
42
  user: session.user,
43
43
  session,
@@ -5,21 +5,60 @@ import type { RequestEvent } from "nuxt/server";
5
5
  * Both strings are UTF-8 encoded into fixed-length buffers of `Math.max(lenA, lenB)` bytes before
6
6
  * comparison so that length differences do not leak via early exit — a classic timing side-channel
7
7
  * in naive implementations that return early on `a.length !== b.length`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const valid = timingSafeEqualString(sigA, sigB)
12
+ * ```
8
13
  */
9
14
  export declare function timingSafeEqualString(a: string, b: string): boolean;
10
15
  /** Alias for timingSafeEqualString */
11
16
  export declare const constantTimeEqual: typeof timingSafeEqualString;
12
- /** Generates a cryptographically secure URL-friendly unique identifier using Web Crypto. */
17
+ /**
18
+ * Generates a cryptographically secure URL-friendly unique identifier using Web Crypto.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const id = nanoid() // "V1StGXR8_Z5jdHi6B-myT"
23
+ * ```
24
+ */
13
25
  export declare function nanoid(size?: number): string;
14
26
  /**
15
27
  * Encrypts a sensitive string (e.g. an OAuth access/refresh token) with AES-256-GCM. The returned
16
- * value is prefixed with `enc:` followed by the hex-encoded `iv ‖ ciphertext` so legacy plaintext
17
- * values can be distinguished on read.
28
+ * value is prefixed with `enc:` followed by the hex-encoded `iv ‖ ciphertext`.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const ciphertext = await encryptToken(accessToken, event)
33
+ * ```
18
34
  */
19
35
  export declare function encryptToken(plaintext: string, event?: RequestEvent): Promise<string>;
20
36
  /**
21
37
  * Decrypts a value produced by {@link encryptToken}. Values that do not start with `enc:` are
22
- * returned as-is — this preserves backward-compatibility with rows written as plaintext before
23
- * token encryption was introduced. Decryption failures resolve to an empty string.
38
+ * returned as-is. Decryption failures resolve to an empty string.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const plaintext = await decryptToken(ciphertext, event)
43
+ * ```
24
44
  */
25
45
  export declare function decryptToken(ciphertext: string, event?: RequestEvent): Promise<string>;
46
+ /**
47
+ * Computes an HMAC-SHA256 hex signature using standard Web Crypto.
48
+ * Used for tamper-proof download URLs, signed query parameters, and webhooks.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const signature = await signHmacSha256("payload-data", event)
53
+ * ```
54
+ */
55
+ export declare function signHmacSha256(data: string, secretOrEvent?: string | RequestEvent): Promise<string>;
56
+ /**
57
+ * Verifies an HMAC-SHA256 hex signature in constant time.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const isValid = await verifyHmacSha256("payload-data", signature, event)
62
+ * ```
63
+ */
64
+ export declare function verifyHmacSha256(data: string, signature: string, secretOrEvent?: string | RequestEvent): Promise<boolean>;
@@ -87,3 +87,21 @@ export async function decryptToken(ciphertext, event) {
87
87
  return "";
88
88
  }
89
89
  }
90
+ export async function signHmacSha256(data, secretOrEvent) {
91
+ const secret = typeof secretOrEvent === "string" ? secretOrEvent : resolveTokenSecret(secretOrEvent);
92
+ const encoder = new TextEncoder();
93
+ const key = await crypto.subtle.importKey(
94
+ "raw",
95
+ encoder.encode(secret),
96
+ { name: "HMAC", hash: "SHA-256" },
97
+ false,
98
+ ["sign"]
99
+ );
100
+ const signature = await crypto.subtle.sign("HMAC", key, encoder.encode(data));
101
+ return Array.from(new Uint8Array(signature)).map((b) => b.toString(16).padStart(2, "0")).join("");
102
+ }
103
+ export async function verifyHmacSha256(data, signature, secretOrEvent) {
104
+ if (!signature || !data) return false;
105
+ const expected = await signHmacSha256(data, secretOrEvent);
106
+ return timingSafeEqualString(expected, signature);
107
+ }