qarpeo 0.2.1 → 0.3.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 (260) hide show
  1. package/dist/chunks/tools.mjs +993 -31
  2. package/dist/cli/index.mjs +1071 -31
  3. package/dist/fate/index.d.ts +9 -1
  4. package/dist/fate/index.mjs +20 -3
  5. package/dist/module.mjs +292 -748
  6. package/dist/runtime/browser.mjs +2 -2
  7. package/dist/runtime/comments-server.d.ts +3 -0
  8. package/dist/runtime/comments-server.mjs +2 -0
  9. package/dist/runtime/comments.d.ts +0 -2
  10. package/dist/runtime/comments.mjs +0 -2
  11. package/dist/runtime/db.d.ts +10 -9
  12. package/dist/runtime/db.mjs +79 -8
  13. package/dist/runtime/drizzle.mjs +21 -6
  14. package/dist/runtime/index.d.ts +4 -0
  15. package/dist/runtime/realtime-server.d.ts +4 -0
  16. package/dist/runtime/realtime-server.mjs +13 -0
  17. package/dist/runtime/realtime.d.ts +1 -4
  18. package/dist/runtime/realtime.mjs +0 -13
  19. package/dist/runtime/replica.d.ts +27 -0
  20. package/dist/runtime/replica.mjs +229 -0
  21. package/dist/runtime/server/durable-objects/agent.mjs +14 -2
  22. package/dist/runtime/server/durable-objects/room.d.ts +10 -0
  23. package/dist/runtime/server/durable-objects/room.mjs +119 -28
  24. package/dist/runtime/server/middleware/devtools.mjs +1 -1
  25. package/dist/runtime/server/middleware/tenancy.mjs +7 -4
  26. package/dist/runtime/server/plugins/store.mjs +1 -1
  27. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +57 -17
  28. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +19 -12
  29. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -9
  30. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -9
  31. package/dist/runtime/server/routes/analytics/events.get.mjs +12 -2
  32. package/dist/runtime/server/routes/analytics/pageviews.get.mjs +10 -1
  33. package/dist/runtime/server/routes/analytics/summary.get.mjs +10 -1
  34. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +11 -2
  35. package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +7 -0
  36. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -2
  37. package/dist/runtime/server/routes/auth/account.delete.mjs +7 -0
  38. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +5 -3
  39. package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +10 -0
  40. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +5 -3
  41. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +18 -0
  42. package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +1 -1
  43. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +11 -2
  44. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +10 -1
  45. package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +1 -1
  46. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +10 -1
  47. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +10 -1
  48. package/dist/runtime/server/routes/browser/crawl.post.mjs +13 -0
  49. package/dist/runtime/server/routes/browser/invoice.post.mjs +15 -1
  50. package/dist/runtime/server/routes/browser/og-image.post.mjs +13 -0
  51. package/dist/runtime/server/routes/browser/pdf.post.mjs +15 -1
  52. package/dist/runtime/server/routes/browser/screenshot.post.mjs +13 -0
  53. package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +23 -8
  54. package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +2 -1
  55. package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +2 -1
  56. package/dist/runtime/server/routes/cms/[collection]/[id]/revisions/[revId]/restore.post.mjs +2 -1
  57. package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +2 -1
  58. package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +2 -1
  59. package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +2 -1
  60. package/dist/runtime/server/routes/cms/categories/[id].delete.mjs +2 -1
  61. package/dist/runtime/server/routes/cms/categories/[id].put.mjs +2 -1
  62. package/dist/runtime/server/routes/cms/categories.post.mjs +2 -1
  63. package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +2 -1
  64. package/dist/runtime/server/routes/cms/collections/[id].put.mjs +2 -1
  65. package/dist/runtime/server/routes/cms/collections/index.post.mjs +2 -1
  66. package/dist/runtime/server/routes/cms/export.post.mjs +1 -1
  67. package/dist/runtime/server/routes/cms/subscribers/[id].delete.mjs +2 -1
  68. package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +2 -1
  69. package/dist/runtime/server/routes/cms/tags/[id].delete.mjs +2 -1
  70. package/dist/runtime/server/routes/cms/tags.post.mjs +2 -1
  71. package/dist/runtime/server/routes/comments/[id]/react.post.mjs +7 -3
  72. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +3 -0
  73. package/dist/runtime/server/routes/comments/[id].delete.mjs +1 -1
  74. package/dist/runtime/server/routes/comments/[id].get.mjs +13 -0
  75. package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -1
  76. package/dist/runtime/server/routes/fate.d.ts +6 -0
  77. package/dist/runtime/server/routes/fate.mjs +32 -3
  78. package/dist/runtime/server/routes/mail/bounce.post.mjs +14 -2
  79. package/dist/runtime/server/routes/mail/unsubscribe.mjs +2 -1
  80. package/dist/runtime/server/routes/mail/webhooks.post.mjs +18 -4
  81. package/dist/runtime/server/routes/notifications/[id].get.mjs +3 -4
  82. package/dist/runtime/server/routes/notifications/index.get.mjs +4 -2
  83. package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +3 -1
  84. package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +5 -3
  85. package/dist/runtime/server/routes/notifications/read-all.post.mjs +6 -2
  86. package/dist/runtime/server/routes/notifications/send.post.mjs +13 -2
  87. package/dist/runtime/server/routes/payments/cancel.post.mjs +1 -1
  88. package/dist/runtime/server/routes/payments/change-plan.post.mjs +1 -1
  89. package/dist/runtime/server/routes/payments/checkout.post.mjs +1 -1
  90. package/dist/runtime/server/routes/payments/pause.post.mjs +1 -1
  91. package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
  92. package/dist/runtime/server/routes/payments/subscription.get.mjs +1 -1
  93. package/dist/runtime/server/routes/payments/usage.get.mjs +1 -1
  94. package/dist/runtime/server/routes/payments/usage.post.mjs +1 -1
  95. package/dist/runtime/server/routes/payments/webhook.post.mjs +8 -1
  96. package/dist/runtime/server/routes/realtime/broadcast.post.mjs +3 -2
  97. package/dist/runtime/server/routes/realtime/history.delete.mjs +2 -2
  98. package/dist/runtime/server/routes/realtime/history.get.mjs +2 -2
  99. package/dist/runtime/server/routes/realtime/presence.get.mjs +3 -3
  100. package/dist/runtime/server/routes/realtime/state.get.mjs +3 -3
  101. package/dist/runtime/server/routes/realtime/state.post.mjs +13 -4
  102. package/dist/runtime/server/routes/realtime/ws.get.mjs +2 -2
  103. package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +1 -1
  104. package/dist/runtime/server/routes/storage/file/[...key].get.mjs +7 -0
  105. package/dist/runtime/server/routes/storage/files.get.d.ts +1 -1
  106. package/dist/runtime/server/routes/storage/files.get.mjs +24 -4
  107. package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +16 -1
  108. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +1 -1
  109. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +15 -1
  110. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -0
  111. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +15 -1
  112. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +8 -1
  113. package/dist/runtime/server/routes/storage/presigned.post.d.ts +1 -1
  114. package/dist/runtime/server/routes/storage/presigned.post.mjs +8 -1
  115. package/dist/runtime/server/routes/storage/sign.post.mjs +7 -0
  116. package/dist/runtime/server/routes/storage/upload.post.d.ts +2 -2
  117. package/dist/runtime/server/routes/store/cart/index.delete.mjs +3 -4
  118. package/dist/runtime/server/routes/store/cart/index.get.mjs +3 -10
  119. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +6 -4
  120. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +12 -4
  121. package/dist/runtime/server/routes/store/cart/items.post.mjs +9 -10
  122. package/dist/runtime/server/routes/store/categories/index.get.mjs +4 -2
  123. package/dist/runtime/server/routes/store/checkout.post.mjs +13 -3
  124. package/dist/runtime/server/routes/store/coupons/apply.post.mjs +6 -5
  125. package/dist/runtime/server/routes/store/orders/[id].get.mjs +2 -2
  126. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +6 -3
  127. package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
  128. package/dist/runtime/server/routes/store/products/[slug].get.mjs +2 -2
  129. package/dist/runtime/server/routes/store/products/index.get.mjs +1 -1
  130. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +10 -0
  131. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +26 -25
  132. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +26 -25
  133. package/dist/runtime/server/utils/ai.d.ts +6 -0
  134. package/dist/runtime/server/utils/ai.mjs +12 -2
  135. package/dist/runtime/server/utils/analytics-query.mjs +8 -4
  136. package/dist/runtime/server/utils/browser-utils.d.ts +9 -0
  137. package/dist/runtime/server/utils/browser-utils.mjs +135 -0
  138. package/dist/runtime/server/utils/cms/cache.d.ts +13 -0
  139. package/dist/runtime/server/utils/cms/cache.mjs +95 -0
  140. package/dist/runtime/server/utils/cms/common.mjs +1 -1
  141. package/dist/runtime/server/utils/cms/markdown.mjs +38 -8
  142. package/dist/runtime/server/utils/cms/mutations.d.ts +26 -0
  143. package/dist/runtime/server/utils/cms/mutations.mjs +569 -0
  144. package/dist/runtime/server/utils/cms/path.d.ts +8 -0
  145. package/dist/runtime/server/utils/cms/path.mjs +23 -0
  146. package/dist/runtime/server/utils/cms/queries.d.ts +27 -0
  147. package/dist/runtime/server/utils/cms/queries.mjs +366 -0
  148. package/dist/runtime/server/utils/cms/references.d.ts +48 -0
  149. package/dist/runtime/server/utils/cms/references.mjs +309 -0
  150. package/dist/runtime/server/utils/cms/revisions.d.ts +7 -0
  151. package/dist/runtime/server/utils/cms/revisions.mjs +60 -0
  152. package/dist/runtime/server/utils/cms/sync.mjs +3 -3
  153. package/dist/runtime/server/utils/cms.d.ts +5 -82
  154. package/dist/runtime/server/utils/cms.mjs +28 -1367
  155. package/dist/runtime/server/utils/comments.d.ts +11 -0
  156. package/dist/runtime/server/utils/comments.mjs +65 -17
  157. package/dist/runtime/server/utils/crypto.mjs +1 -1
  158. package/dist/runtime/server/utils/domains.mjs +9 -0
  159. package/dist/runtime/server/utils/drizzle.d.ts +26 -1
  160. package/dist/runtime/server/utils/drizzle.mjs +78 -19
  161. package/dist/runtime/server/utils/email-inbound.mjs +9 -1
  162. package/dist/runtime/server/utils/impersonation.mjs +58 -1
  163. package/dist/runtime/server/utils/lock.d.ts +11 -0
  164. package/dist/runtime/server/utils/lock.mjs +4 -0
  165. package/dist/runtime/server/utils/mail-suppression.mjs +48 -13
  166. package/dist/runtime/server/utils/mail.d.ts +2 -1
  167. package/dist/runtime/server/utils/mail.mjs +17 -11
  168. package/dist/runtime/server/utils/notifications.d.ts +13 -4
  169. package/dist/runtime/server/utils/notifications.mjs +20 -4
  170. package/dist/runtime/server/utils/organization.mjs +36 -1
  171. package/dist/runtime/server/utils/passwordless.mjs +8 -0
  172. package/dist/runtime/server/utils/payments/checkout.d.ts +34 -0
  173. package/dist/runtime/server/utils/payments/checkout.mjs +158 -0
  174. package/dist/runtime/server/utils/payments/common.d.ts +45 -0
  175. package/dist/runtime/server/utils/payments/common.mjs +234 -0
  176. package/dist/runtime/server/utils/payments/index.d.ts +9 -0
  177. package/dist/runtime/server/utils/payments/index.mjs +21 -0
  178. package/dist/runtime/server/utils/payments/lemonsqueezy.d.ts +7 -0
  179. package/dist/runtime/server/utils/payments/lemonsqueezy.mjs +55 -0
  180. package/dist/runtime/server/utils/payments/paddle.d.ts +7 -0
  181. package/dist/runtime/server/utils/payments/paddle.mjs +92 -0
  182. package/dist/runtime/server/utils/payments/polar.d.ts +11 -0
  183. package/dist/runtime/server/utils/payments/polar.mjs +66 -0
  184. package/dist/runtime/server/utils/payments/stripe.d.ts +7 -0
  185. package/dist/runtime/server/utils/payments/stripe.mjs +159 -0
  186. package/dist/runtime/server/utils/payments/subscriptions.d.ts +89 -0
  187. package/dist/runtime/server/utils/payments/subscriptions.mjs +236 -0
  188. package/dist/runtime/server/utils/payments/usage.d.ts +12 -0
  189. package/dist/runtime/server/utils/payments/usage.mjs +143 -0
  190. package/dist/runtime/server/utils/payments/webhooks.d.ts +10 -0
  191. package/dist/runtime/server/utils/payments/webhooks.mjs +200 -0
  192. package/dist/runtime/server/utils/payments.d.ts +1 -158
  193. package/dist/runtime/server/utils/payments.mjs +1 -1289
  194. package/dist/runtime/server/utils/queue.d.ts +2 -0
  195. package/dist/runtime/server/utils/queue.mjs +34 -21
  196. package/dist/runtime/server/utils/rag.mjs +30 -17
  197. package/dist/runtime/server/utils/realtime.d.ts +5 -1
  198. package/dist/runtime/server/utils/realtime.mjs +43 -7
  199. package/dist/runtime/server/utils/session.mjs +16 -3
  200. package/dist/runtime/server/utils/sso.d.ts +3 -0
  201. package/dist/runtime/server/utils/sso.mjs +43 -0
  202. package/dist/runtime/server/utils/storage.mjs +12 -1
  203. package/dist/runtime/server/utils/store/cart.d.ts +63 -0
  204. package/dist/runtime/server/utils/store/cart.mjs +542 -0
  205. package/dist/runtime/server/utils/store/checkout.d.ts +14 -0
  206. package/dist/runtime/server/utils/store/checkout.mjs +118 -0
  207. package/dist/runtime/server/utils/store/common.d.ts +29 -0
  208. package/dist/runtime/server/utils/store/common.mjs +479 -0
  209. package/dist/runtime/server/utils/store/index.d.ts +7 -0
  210. package/dist/runtime/server/utils/store/index.mjs +30 -0
  211. package/dist/runtime/server/utils/store/inventory.d.ts +25 -0
  212. package/dist/runtime/server/utils/store/inventory.mjs +190 -0
  213. package/dist/runtime/server/utils/store/orders.d.ts +60 -0
  214. package/dist/runtime/server/utils/store/orders.mjs +590 -0
  215. package/dist/runtime/server/utils/store/products.d.ts +35 -0
  216. package/dist/runtime/server/utils/store/products.mjs +461 -0
  217. package/dist/runtime/server/utils/store/vendor.d.ts +18 -0
  218. package/dist/runtime/server/utils/store/vendor.mjs +68 -0
  219. package/dist/runtime/server/utils/store.d.ts +1 -207
  220. package/dist/runtime/server/utils/store.mjs +1 -2227
  221. package/dist/runtime/server/utils/string.d.ts +1 -1
  222. package/dist/runtime/server/utils/string.mjs +12 -4
  223. package/dist/runtime/server/utils/tenant.mjs +19 -5
  224. package/dist/runtime/server/utils/tracker.mjs +2 -0
  225. package/dist/runtime/server.d.ts +3 -3
  226. package/dist/runtime/server.mjs +4 -4
  227. package/dist/runtime/storage-server.d.ts +2 -0
  228. package/dist/runtime/storage-server.mjs +1 -0
  229. package/dist/runtime/storage.d.ts +1 -1
  230. package/dist/runtime/storage.mjs +0 -1
  231. package/dist/runtime/store.d.ts +0 -1
  232. package/dist/runtime/store.mjs +0 -1
  233. package/dist/runtime/test-utils.d.ts +4 -0
  234. package/dist/runtime/test-utils.mjs +54 -0
  235. package/dist/runtime/types/d1.d.ts +43 -0
  236. package/dist/runtime/types/drizzle.d.ts +6 -0
  237. package/dist/runtime/types/store.d.ts +1 -1
  238. package/dist/types/analytics.d.ts +80 -0
  239. package/dist/types/auth.d.ts +282 -0
  240. package/dist/types/cache.d.ts +55 -0
  241. package/dist/types/comments.d.ts +130 -0
  242. package/dist/types/db.d.ts +29 -0
  243. package/dist/types/email.d.ts +182 -0
  244. package/dist/types/index.d.ts +22 -0
  245. package/dist/types/jobs.d.ts +58 -0
  246. package/dist/types/notifications.d.ts +77 -0
  247. package/dist/types/options.d.ts +363 -0
  248. package/dist/types/payments.d.ts +145 -0
  249. package/dist/types/ratelimit.d.ts +71 -0
  250. package/dist/types/realtime.d.ts +136 -0
  251. package/dist/types/site.d.ts +121 -0
  252. package/dist/types/storage.d.ts +164 -0
  253. package/dist/types/store-options.d.ts +199 -0
  254. package/dist/types/tenant.d.ts +100 -0
  255. package/dist/types.d.ts +1 -2174
  256. package/dist/utils/migration-lock.d.ts +139 -0
  257. package/dist/utils/pkg.d.ts +14 -1
  258. package/dist/utils/schema-diff.d.ts +39 -0
  259. package/package.json +55 -17
  260. package/dist/chunks/auth-schema.mjs +0 -364
@@ -6,6 +6,6 @@ export declare function escapeHtml(str: string): string;
6
6
  export declare function sanitizeUrl(url: string): string;
7
7
  /**
8
8
  * Validates a redirect URL to ensure it is a safe local/relative path, preventing open redirect
9
- * phishing attacks (e.g. `//evil.com`, `https://evil.com`, `/\evil.com`).
9
+ * phishing attacks (e.g. `//evil.com`, `https://evil.com`, `/\evil.com`, `/%2f%2fevil.com`).
10
10
  */
11
11
  export declare function safeRedirect(url: unknown, fallback?: string): string;
@@ -16,9 +16,17 @@ export function safeRedirect(url, fallback = "/") {
16
16
  if (typeof url !== "string") return fallback;
17
17
  const trimmed = url.trim();
18
18
  if (!trimmed) return fallback;
19
- if (trimmed.startsWith("/") && !trimmed.startsWith("//") && !trimmed.startsWith("/\\") && !trimmed.startsWith("\\")) {
20
- if (/[\r\n\0]/.test(trimmed)) return fallback;
21
- return trimmed;
19
+ if (/[\r\n\0]/.test(trimmed)) return fallback;
20
+ if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("\\")) {
21
+ return fallback;
22
+ }
23
+ try {
24
+ const decoded = decodeURIComponent(trimmed);
25
+ if (!decoded.startsWith("/") || decoded.startsWith("//") || decoded.includes("\\") || /[\r\n\0]/.test(decoded)) {
26
+ return fallback;
27
+ }
28
+ } catch {
29
+ return fallback;
22
30
  }
23
- return fallback;
31
+ return trimmed;
24
32
  }
@@ -1,4 +1,4 @@
1
- import { createError } from "nuxt/server";
1
+ import { createError, getRequestHeader } from "nuxt/server";
2
2
  import { getDomainCache, getMultitenantConfig, normalizeDomain } from "./domains.mjs";
3
3
  import { resolveTableName } from "./table-names.mjs";
4
4
  function tenantTbl(event) {
@@ -28,9 +28,16 @@ const DEFAULT_RESERVED_SLUGS = [
28
28
  "www"
29
29
  ];
30
30
  export function extractHostname(event) {
31
- const req = event.node?.req;
32
- const rawHost = req?.headers?.["x-forwarded-host"] || req?.headers?.host || "localhost";
33
- const host = Array.isArray(rawHost) ? rawHost[0] : rawHost;
31
+ let rawHost;
32
+ try {
33
+ rawHost = getRequestHeader(event, "x-forwarded-host") || getRequestHeader(event, "host");
34
+ } catch {
35
+ }
36
+ if (!rawHost) {
37
+ const req = event.node?.req;
38
+ rawHost = req?.headers?.["x-forwarded-host"] || req?.headers?.host || "localhost";
39
+ }
40
+ const host = Array.isArray(rawHost) ? rawHost[0] : rawHost || "localhost";
34
41
  return host.split(":")[0].toLowerCase().trim();
35
42
  }
36
43
  export function extractSubdomain(host, rootDomains) {
@@ -227,7 +234,14 @@ export async function resolveTenant(event) {
227
234
  const allowHeader = isDev || Boolean(config.allowHeaderOverrideInProduction);
228
235
  if (allowHeader) {
229
236
  const headerName = (config.headerName || "x-tenant-id").toLowerCase();
230
- const headerVal = headers[headerName];
237
+ let headerVal;
238
+ try {
239
+ headerVal = getRequestHeader(event, headerName);
240
+ } catch {
241
+ }
242
+ if (!headerVal) {
243
+ headerVal = headers[headerName];
244
+ }
231
245
  if (headerVal && typeof headerVal === "string") {
232
246
  const fromId = await getTenantById(headerVal, event);
233
247
  if (fromId) {
@@ -28,6 +28,8 @@ function resolveSiteId(event, override) {
28
28
  if (configured) return configured;
29
29
  } catch {
30
30
  }
31
+ const tenantId = event.context?.tenant?.id || event.context?.tenant?.slug;
32
+ if (tenantId) return `tenant_${tenantId}`;
31
33
  return event.node?.req?.headers?.host || "unknown";
32
34
  }
33
35
  function resolveAnalyticsBinding(event, override) {
@@ -24,6 +24,7 @@ export * from "./bindings";
24
24
  export * from "./kv";
25
25
  export * from "./blob";
26
26
  export * from "./db";
27
+ export * from "./replica";
27
28
  export * from "./drizzle";
28
29
  export * from "./email";
29
30
  export * from "./cache";
@@ -36,12 +37,11 @@ export * from "./hyperdrive";
36
37
  export * from "./browser";
37
38
  export * from "./service";
38
39
  export * from "./auth";
39
- export * from "./realtime";
40
+ export * from "./realtime-server";
40
41
  export * from "./cms";
41
- export * from "./comments";
42
+ export * from "./comments-server";
42
43
  export * from "./server/utils/store";
43
44
  export * from "./payments";
44
- export * from "./storage";
45
45
  export * from "./workflows";
46
46
  export * from "./bots";
47
47
  export * from "./rag";
@@ -3,6 +3,7 @@ export * from "./bindings.mjs";
3
3
  export * from "./kv.mjs";
4
4
  export * from "./blob.mjs";
5
5
  export * from "./db.mjs";
6
+ export * from "./replica.mjs";
6
7
  export * from "./drizzle.mjs";
7
8
  export * from "./email.mjs";
8
9
  export * from "./cache.mjs";
@@ -15,12 +16,11 @@ export * from "./hyperdrive.mjs";
15
16
  export * from "./browser.mjs";
16
17
  export * from "./service.mjs";
17
18
  export * from "./auth.mjs";
18
- export * from "./realtime.mjs";
19
+ export * from "./realtime-server.mjs";
19
20
  export * from "./cms.mjs";
20
- export * from "./comments.mjs";
21
- export * from "./server/utils/store.mjs";
21
+ export * from "./comments-server.mjs";
22
+ export * from "./server/utils/store/index.mjs";
22
23
  export * from "./payments.mjs";
23
- export * from "./storage.mjs";
24
24
  export * from "./workflows.mjs";
25
25
  export * from "./bots.mjs";
26
26
  export * from "./rag.mjs";
@@ -0,0 +1,2 @@
1
+ export * from "./blob";
2
+ export type { StorageImagePreset, BlobAccessTier, SignedDownloadUrlOptions, StorageOptions, BlobOptions, UploadedFile, ResumableUploadSession, ResumableUploadOptions, } from "../types";
@@ -0,0 +1 @@
1
+ export * from "./blob.mjs";
@@ -1,2 +1,2 @@
1
1
  export type * from "./app/composables/storage";
2
- export * from "./blob";
2
+ export type { StorageImagePreset, BlobAccessTier, SignedDownloadUrlOptions, StorageOptions, BlobOptions, UploadedFile, ResumableUploadSession, ResumableUploadOptions, UseResumableUploadReturn, } from "../types";
@@ -1 +0,0 @@
1
- export * from "./blob.mjs";
@@ -1,4 +1,3 @@
1
1
  export * from "./types/store";
2
- export * from "./server/utils/store";
3
2
  export type * from "./app/composables/store";
4
3
  export type { StoreOptions } from "../types";
@@ -1,2 +1 @@
1
1
  export * from "./types/store.mjs";
2
- export * from "./server/utils/store.mjs";
@@ -33,9 +33,13 @@ export interface MockD1Database {
33
33
  duration: number;
34
34
  }>;
35
35
  dump(): Promise<ArrayBuffer>;
36
+ withSession?(bookmark?: string): MockD1DatabaseSession;
36
37
  _tables: Map<string, any[]>;
37
38
  _queries: string[];
38
39
  }
40
+ export interface MockD1DatabaseSession extends MockD1Database {
41
+ getBookmark(): string | null;
42
+ }
39
43
  export interface MockKVNamespace {
40
44
  get(key: string, options?: any): Promise<any>;
41
45
  getWithMetadata(key: string, options?: any): Promise<{
@@ -110,6 +110,60 @@ export function createMockD1Database() {
110
110
  async dump() {
111
111
  return new ArrayBuffer(0);
112
112
  },
113
+ withSession(bookmark) {
114
+ const sessionQueries = [];
115
+ let currentBookmark = bookmark || "mock-session-bm-1";
116
+ return {
117
+ prepare(query) {
118
+ return {
119
+ bind(..._values) {
120
+ return this;
121
+ },
122
+ async first(colName) {
123
+ sessionQueries.push(query);
124
+ queries.push(query);
125
+ return null;
126
+ },
127
+ async all() {
128
+ sessionQueries.push(query);
129
+ queries.push(query);
130
+ return { results: [], success: true, meta: { duration: 1, served_by: "d1-replica-session-mock" } };
131
+ },
132
+ async run() {
133
+ sessionQueries.push(query);
134
+ queries.push(query);
135
+ currentBookmark = `mock-session-bm-${Date.now()}`;
136
+ return { success: true, meta: { changes: 1, last_row_id: 1 } };
137
+ },
138
+ async raw() {
139
+ sessionQueries.push(query);
140
+ queries.push(query);
141
+ return [];
142
+ }
143
+ };
144
+ },
145
+ async batch(statements) {
146
+ const results = [];
147
+ for (const stmt of statements) {
148
+ results.push(await stmt.all());
149
+ }
150
+ return results;
151
+ },
152
+ async exec(query) {
153
+ sessionQueries.push(query);
154
+ queries.push(query);
155
+ return { count: 1, duration: 1 };
156
+ },
157
+ async dump() {
158
+ return new ArrayBuffer(0);
159
+ },
160
+ getBookmark() {
161
+ return currentBookmark;
162
+ },
163
+ _tables: tables,
164
+ _queries: sessionQueries
165
+ };
166
+ },
113
167
  _tables: tables,
114
168
  _queries: queries
115
169
  };
@@ -1,3 +1,4 @@
1
+ import type { CFEvent } from "./index";
1
2
  /** Cloudflare D1 Database types. */
2
3
  export interface D1Result<T = Record<string, unknown>> {
3
4
  results: T[];
@@ -25,6 +26,10 @@ export interface D1PreparedStatement {
25
26
  /** Return raw arrays of rows without column keys. */
26
27
  raw<T = unknown[]>(): Promise<T[]>;
27
28
  }
29
+ export interface D1DatabaseSession extends D1Database {
30
+ /** Returns the session's latest bookmark token representing replication progress. */
31
+ getBookmark(): string | null;
32
+ }
28
33
  export interface D1Database {
29
34
  /** Prepare a SQL query for execution. */
30
35
  prepare(query: string): D1PreparedStatement;
@@ -37,10 +42,48 @@ export interface D1Database {
37
42
  exec(query: string): Promise<D1ExecResult>;
38
43
  /** Dump the database as a SQLite binary format. */
39
44
  dump(): Promise<ArrayBuffer>;
45
+ /**
46
+ * Creates a session for read replication consistency and routing.
47
+ *
48
+ * @param bookmark Optional bookmark token or routing constraint ("first-unconstrained" | "first-primary")
49
+ */
50
+ withSession?(bookmark?: string): D1DatabaseSession;
40
51
  }
41
52
  export interface QarpeoDB extends D1Database {
42
53
  /** Access the raw underlying Cloudflare D1Database binding. */
43
54
  raw(bindingName?: string): D1Database;
55
+ /** Current session bookmark token for Cloudflare D1 read replicas. */
56
+ getBookmark?(): string | null;
57
+ /** Access the underlying primary database binding directly. */
58
+ primary?(): D1Database;
59
+ /** Access the underlying replica database binding directly. */
60
+ replica?(): D1Database;
61
+ }
62
+ /** Options for Cloudflare D1 Read Replica routing and sessions. */
63
+ export interface D1ReplicaOptions {
64
+ /**
65
+ * Route reads to Cloudflare D1 Read Replicas:
66
+ * - `true`: routes to nearest replica using "first-unconstrained" session
67
+ * - `"first-unconstrained"`: reads from nearest replica immediately
68
+ * - `"first-primary"`: first query routed to primary, subsequent reads routed to replica
69
+ * - `string`: bookmark token string to guarantee sequential consistency
70
+ */
71
+ replica?: boolean | "first-unconstrained" | "first-primary" | string;
72
+ /**
73
+ * Cloudflare D1 session bookmark token.
74
+ */
75
+ bookmark?: string;
76
+ /**
77
+ * Automatically fallback to primary database if replica read fails.
78
+ * Default: `true`.
79
+ */
80
+ fallbackToPrimary?: boolean;
81
+ /**
82
+ * Optional Cloudflare event context.
83
+ */
84
+ event?: CFEvent;
85
+ }
86
+ export interface D1DatabaseOptions extends D1ReplicaOptions {
44
87
  }
45
88
  /** Inferred database dialect based on connection configuration. */
46
89
  export type DatabaseDialect = "d1" | "postgres" | "mysql";
@@ -10,4 +10,10 @@ export type InferDrizzleRelations<TSchema extends Record<string, unknown>> = Ret
10
10
  export type QarpeoDrizzleDB<TRelations extends AnyRelations = AnyRelations> = DrizzleD1Database<TRelations> & {
11
11
  /** Access the raw underlying Cloudflare D1Database binding or database client. */
12
12
  raw(bindingName?: string): D1Database | any;
13
+ /** Current session bookmark token for Cloudflare D1 read replicas. */
14
+ getBookmark?(): string | null;
15
+ /** Access the underlying primary database binding directly. */
16
+ primary?(): D1Database;
17
+ /** Access the underlying replica database binding directly. */
18
+ replica?(): D1Database;
13
19
  };
@@ -310,4 +310,4 @@ export interface StoreLocalizationOptions {
310
310
  /** Rule-based edge tax and VAT configuration */
311
311
  tax?: StoreTaxOptions;
312
312
  }
313
- export type { StoreOptions } from "../../types";
313
+ export type { StoreOptions } from "../../types/store-options";
@@ -0,0 +1,80 @@
1
+ export interface AnalyticsOptions {
2
+ /**
3
+ * Cloudflare Analytics Engine binding name.
4
+ *
5
+ * @default "ANALYTICS"
6
+ */
7
+ binding?: string;
8
+ /**
9
+ * Cloudflare Analytics Engine dataset name (used in wrangler.json). Defaults to
10
+ * `<binding-lowercase>-prod` in production, `<binding-lowercase>-local-dev` in dev.
11
+ */
12
+ dataset?: string;
13
+ /**
14
+ * Cloudflare Account ID — required for the SQL API (read queries / dashboard). Falls back to
15
+ * `CLOUDFLARE_ACCOUNT_ID` environment variable.
16
+ */
17
+ accountId?: string;
18
+ /**
19
+ * Cloudflare API token with Analytics Engine read permissions. Falls back to
20
+ * `CLOUDFLARE_API_TOKEN` environment variable.
21
+ */
22
+ apiToken?: string;
23
+ /**
24
+ * Site identifier written to `indexes[0]` on every data point. Useful when a single AE dataset
25
+ * tracks multiple sites. Falls back to the request hostname.
26
+ */
27
+ siteId?: string;
28
+ /**
29
+ * Automatically track a pageview on every non-API SSR request via a server middleware.
30
+ *
31
+ * @default true
32
+ */
33
+ autoTrack?: boolean;
34
+ /**
35
+ * Base path for the analytics dashboard API routes.
36
+ *
37
+ * @default "/api/analytics"
38
+ */
39
+ path?: string;
40
+ }
41
+ /** Time range shorthand for dashboard queries. */
42
+ export type AnalyticsRange = "1h" | "24h" | "7d" | "30d" | "90d";
43
+ /** A single time-series bucket returned by AE SQL queries. */
44
+ export interface AnalyticsTimeSeriesPoint {
45
+ date: string;
46
+ count: number;
47
+ }
48
+ /** Pageview summary returned by the dashboard API. */
49
+ export interface PageviewSummary {
50
+ total: number;
51
+ series: AnalyticsTimeSeriesPoint[];
52
+ }
53
+ /** KPI summary returned by `/api/analytics/summary`. */
54
+ export interface AnalyticsSummary {
55
+ pageviews: number;
56
+ visitors: number;
57
+ topPages: Array<{
58
+ path: string;
59
+ views: number;
60
+ }>;
61
+ topReferrers: Array<{
62
+ referrer: string;
63
+ count: number;
64
+ }>;
65
+ countries: Array<{
66
+ country: string;
67
+ count: number;
68
+ }>;
69
+ devices: {
70
+ mobile: number;
71
+ desktop: number;
72
+ bot: number;
73
+ };
74
+ }
75
+ /** Tracked event record returned by `/api/analytics/events`. */
76
+ export interface AnalyticsEventRecord {
77
+ name: string;
78
+ count: number;
79
+ lastSeen: string;
80
+ }
@@ -0,0 +1,282 @@
1
+ export interface RateLimitConfig {
2
+ /**
3
+ * Max number of requests permitted within the time window.
4
+ *
5
+ * @default 100
6
+ */
7
+ limit?: number;
8
+ /**
9
+ * Period window in seconds: must be 10 or 60.
10
+ *
11
+ * @default 60
12
+ */
13
+ period?: 10 | 60;
14
+ /**
15
+ * Unique namespace ID grouping rate limit counters.
16
+ *
17
+ * @default 1001
18
+ */
19
+ namespaceId?: number;
20
+ }
21
+ export interface EmailInboundOptions {
22
+ /**
23
+ * Whether Cloudflare Inbound Email handling is enabled.
24
+ * @default true
25
+ */
26
+ enabled?: boolean;
27
+ /**
28
+ * Custom directory or file path for email handlers (defaults to auto-discovering server/email.ts, server/email/*.ts).
29
+ */
30
+ dir?: string;
31
+ }
32
+ export interface EmailOptions {
33
+ /**
34
+ * Default sender address or map of named sender presets.
35
+ *
36
+ * @example
37
+ * // Single default address:
38
+ * from: "MyApp <noreply@myapp.com>"
39
+ *
40
+ * // Map of named presets:
41
+ * from: {
42
+ * default: "MyApp <noreply@myapp.com>",
43
+ * support: "Support Team <support@myapp.com>",
44
+ * billing: "Acme Invoicing <billing@myapp.com>",
45
+ * }
46
+ */
47
+ from?: string | Record<string, string>;
48
+ /**
49
+ * Cloudflare send_email binding name override.
50
+ *
51
+ * @default "EMAIL"
52
+ */
53
+ binding?: string;
54
+ /**
55
+ * Cloudflare Inbound Email configuration.
56
+ * When enabled, routes incoming emails to your server/email handler.
57
+ */
58
+ inbound?: boolean | EmailInboundOptions;
59
+ }
60
+ export interface AuthRedirectConfig {
61
+ /**
62
+ * Route to redirect after successful login.
63
+ *
64
+ * @default "/dashboard"
65
+ */
66
+ success?: string;
67
+ /**
68
+ * Route to redirect after logout.
69
+ *
70
+ * @default "/login"
71
+ */
72
+ logout?: string;
73
+ /**
74
+ * Route to redirect when an unauthenticated user accesses a protected route.
75
+ *
76
+ * @default "/login"
77
+ */
78
+ login?: string;
79
+ }
80
+ export interface AuthSessionConfig {
81
+ /**
82
+ * Session storage backend: sealed cookie or Cloudflare KV.
83
+ *
84
+ * @default "cookie"
85
+ */
86
+ backend?: "cookie" | "kv";
87
+ /**
88
+ * Session expiration maxAge in seconds.
89
+ *
90
+ * @default 604800 (7 days)
91
+ */
92
+ maxAge?: number;
93
+ /**
94
+ * Maximum concurrent sessions per user before LRU eviction.
95
+ *
96
+ * @default 5
97
+ */
98
+ maxSessionsPerUser?: number;
99
+ /**
100
+ * Throttled device tracking in D1.
101
+ *
102
+ * @default false
103
+ */
104
+ trackDevice?: boolean;
105
+ }
106
+ export interface AuthPasswordlessOtpConfig {
107
+ /** Enable 6-digit OTP codes */
108
+ enabled?: boolean;
109
+ /** Code TTL in seconds @default 300 */
110
+ ttl?: number;
111
+ /** Delivery channels @default ["email"] */
112
+ channels?: Array<"email" | "sms" | "whatsapp" | "telegram">;
113
+ }
114
+ export interface AuthPasswordlessMagicLinkConfig {
115
+ /** Enable email magic login links */
116
+ enabled?: boolean;
117
+ /** Link TTL in seconds @default 900 */
118
+ ttl?: number;
119
+ }
120
+ export interface AuthPasswordlessConfig {
121
+ otp?: boolean | AuthPasswordlessOtpConfig;
122
+ magicLink?: boolean | AuthPasswordlessMagicLinkConfig;
123
+ }
124
+ export interface AuthFieldDefinition {
125
+ type: "string" | "number" | "boolean" | "json";
126
+ default?: string | number | boolean;
127
+ enum?: readonly string[];
128
+ nullable?: boolean;
129
+ }
130
+ export interface AuthFieldsConfig {
131
+ extends?: Record<string, AuthFieldDefinition>;
132
+ }
133
+ export interface AuthOptions {
134
+ /** Route protection rules mapping path patterns to required role/permissions or boolean. */
135
+ rules?: Record<string, any>;
136
+ /**
137
+ * Base route prefix for auto-injected auth endpoints.
138
+ *
139
+ * @default "/api/auth"
140
+ */
141
+ prefix?: string;
142
+ /**
143
+ * Enabled OAuth providers (e.g. ['github', 'google', 'discord']). Auto-uses
144
+ * `NUXT_OAUTH_<PROVIDER>_CLIENT_ID` and `_CLIENT_SECRET`.
145
+ */
146
+ providers?: string[];
147
+ /**
148
+ * Automatic account linking for accounts sharing the same verified email address. Enforces
149
+ * dual-verified email check.
150
+ *
151
+ * @default true
152
+ */
153
+ linkAccounts?: boolean;
154
+ /** Redirect paths for auth flows. */
155
+ redirect?: AuthRedirectConfig;
156
+ /** Session storage configuration. */
157
+ session?: AuthSessionConfig;
158
+ /** Passwordless authentication (OTP / Magic Links). */
159
+ passwordless?: AuthPasswordlessConfig;
160
+ /** Declarative custom user fields (Tier 2). */
161
+ fields?: AuthFieldsConfig;
162
+ /**
163
+ * Enable Two-Factor Authentication (TOTP Authenticator Apps).
164
+ *
165
+ * @default false
166
+ */
167
+ twoFactor?: boolean;
168
+ /**
169
+ * Enable Multi-tenant Organizations & Teams.
170
+ *
171
+ * @default false
172
+ */
173
+ organizations?: boolean;
174
+ /**
175
+ * Enable Admin Impersonation.
176
+ *
177
+ * @default false
178
+ */
179
+ impersonation?: boolean;
180
+ /**
181
+ * Enable WebAuthn / Passkeys.
182
+ *
183
+ * @default false
184
+ */
185
+ webauthn?: boolean;
186
+ /**
187
+ * Alias for `webauthn`. Enable WebAuthn / Passkeys.
188
+ *
189
+ * @default false
190
+ */
191
+ webAuthn?: boolean;
192
+ /**
193
+ * Enable Personal Access Tokens (CLI keys).
194
+ *
195
+ * @default false
196
+ */
197
+ apiTokens?: boolean;
198
+ /** Enterprise: Cloudflare Turnstile bot and abuse protection. */
199
+ turnstile?: boolean | AuthTurnstileConfig;
200
+ /** Enterprise: Mandatory Multi-Factor Authentication enforcement policies. */
201
+ mfa?: AuthMfaConfig;
202
+ /**
203
+ * Enterprise: SAML 2.0 & Enterprise OIDC Single Sign-On (SSO).
204
+ *
205
+ * @default false
206
+ */
207
+ sso?: boolean | AuthSSOConfig;
208
+ /** Enterprise / GDPR: Self-serve account deletion settings. */
209
+ accountDeletion?: boolean | AuthAccountDeletionConfig;
210
+ }
211
+ export interface AuthTurnstileConfig {
212
+ /** Turnstile secret key (or set NUXT_TURNSTILE_SECRET_KEY). */
213
+ secretKey?: string;
214
+ /** Turnstile public site key. */
215
+ siteKey?: string;
216
+ /** Automatic protection toggles for auth operations. */
217
+ protect?: {
218
+ login?: boolean;
219
+ register?: boolean;
220
+ otp?: boolean;
221
+ magicLink?: boolean;
222
+ accountDelete?: boolean;
223
+ };
224
+ }
225
+ export interface AuthMfaConfig {
226
+ /**
227
+ * Policy for MFA enforcement:
228
+ *
229
+ * - False / undefined: Optional MFA
230
+ * - True: Enforced for all authenticated users
231
+ * - "org": Enforced if user's current organization has mfaRequired set
232
+ * - "role": Enforced if user's role is in roles
233
+ */
234
+ enforce?: boolean | "org" | "role";
235
+ /** Roles that require MFA when enforce === "role" (default: ['admin', 'owner']) */
236
+ roles?: string[];
237
+ /** Redirect path when MFA is required but unverified (default: "/auth/2fa/verify") */
238
+ redirect?: string;
239
+ }
240
+ export interface AuthSSOConfig {
241
+ /** Enable Enterprise SSO endpoints & database tables. */
242
+ enabled?: boolean;
243
+ /** Default organization role for new users created via SSO (default: "member"). */
244
+ defaultRole?: string;
245
+ /** Allow automated self-registration for matching SSO domains (default: true). */
246
+ allowSelfRegistration?: boolean;
247
+ }
248
+ export interface AuthAccountDeletionConfig {
249
+ /** Allow users to delete their account self-serve (default: true). */
250
+ enabled?: boolean;
251
+ /** Require Cloudflare Turnstile verification token before deleting (default: false). */
252
+ requireTurnstile?: boolean;
253
+ /** Require explicit confirmation phrase (e.g. "DELETE") (default: false). */
254
+ requireConfirmationPhrase?: boolean;
255
+ /** Confirmation phrase string (default: "DELETE"). */
256
+ confirmationPhrase?: string;
257
+ /** Allow cascade deleting owned organizations if user is sole owner (default: false). */
258
+ allowOrgCascade?: boolean;
259
+ }
260
+ export interface QarpeoSSOConnection {
261
+ id: string;
262
+ organizationId?: string | null;
263
+ providerType: "saml" | "oidc";
264
+ name: string;
265
+ domain?: string | null;
266
+ clientId?: string | null;
267
+ clientSecret?: string | null;
268
+ issuer?: string | null;
269
+ ssoUrl: string;
270
+ tokenUrl?: string | null;
271
+ userinfoUrl?: string | null;
272
+ cert?: string | null;
273
+ enabled: boolean;
274
+ createdAt: number;
275
+ updatedAt: number;
276
+ }
277
+ export interface DeleteAccountOptions {
278
+ confirm?: boolean;
279
+ phrase?: string;
280
+ turnstileToken?: string;
281
+ cascadeOrg?: boolean;
282
+ }