qarpeo 0.1.35 → 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 (363) 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 -5118
  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 +3 -3
  210. package/dist/runtime/server/utils/cms/collections.d.ts +23 -0
  211. package/dist/runtime/server/utils/cms/collections.mjs +143 -0
  212. package/dist/runtime/server/utils/cms/common.d.ts +9 -0
  213. package/dist/runtime/server/utils/cms/common.mjs +28 -0
  214. package/dist/runtime/server/utils/cms/git.mjs +2 -2
  215. package/dist/runtime/server/utils/cms/navigation.d.ts +46 -0
  216. package/dist/runtime/server/utils/cms/navigation.mjs +683 -0
  217. package/dist/runtime/server/utils/cms/preview.d.ts +11 -0
  218. package/dist/runtime/server/utils/cms/preview.mjs +50 -0
  219. package/dist/runtime/server/utils/cms/search.d.ts +1 -1
  220. package/dist/runtime/server/utils/cms/search.mjs +11 -7
  221. package/dist/runtime/server/utils/cms/sync.d.ts +34 -0
  222. package/dist/runtime/server/utils/cms/sync.mjs +1082 -0
  223. package/dist/runtime/server/utils/cms/taxonomy.d.ts +103 -0
  224. package/dist/runtime/server/utils/cms/taxonomy.mjs +348 -0
  225. package/dist/runtime/server/utils/cms.d.ts +13 -249
  226. package/dist/runtime/server/utils/cms.mjs +108 -2350
  227. package/dist/runtime/server/utils/comments-filter.d.ts +45 -0
  228. package/dist/runtime/server/utils/comments-filter.mjs +541 -0
  229. package/dist/runtime/server/utils/comments.d.ts +71 -0
  230. package/dist/runtime/server/utils/comments.mjs +137 -61
  231. package/dist/runtime/server/utils/config.d.ts +4 -3
  232. package/dist/runtime/server/utils/config.mjs +7 -6
  233. package/dist/runtime/server/utils/context.d.ts +14 -0
  234. package/dist/runtime/server/utils/context.mjs +2 -2
  235. package/dist/runtime/server/utils/crypto.d.ts +44 -5
  236. package/dist/runtime/server/utils/crypto.mjs +18 -0
  237. package/dist/runtime/server/utils/domains.mjs +9 -5
  238. package/dist/runtime/server/utils/drizzle.d.ts +35 -3
  239. package/dist/runtime/server/utils/drizzle.mjs +115 -6
  240. package/dist/runtime/server/utils/durable-object.d.ts +106 -0
  241. package/dist/runtime/server/utils/durable-object.mjs +628 -0
  242. package/dist/runtime/server/utils/email-inbound.d.ts +29 -0
  243. package/dist/runtime/server/utils/email-inbound.mjs +76 -0
  244. package/dist/runtime/server/utils/impersonation.d.ts +32 -2
  245. package/dist/runtime/server/utils/impersonation.mjs +16 -13
  246. package/dist/runtime/server/utils/lock.d.ts +71 -0
  247. package/dist/runtime/server/utils/lock.mjs +139 -0
  248. package/dist/runtime/server/utils/mail-suppression.mjs +7 -7
  249. package/dist/runtime/server/utils/mail.d.ts +30 -19
  250. package/dist/runtime/server/utils/mcp.d.ts +44 -0
  251. package/dist/runtime/server/utils/mcp.mjs +308 -0
  252. package/dist/runtime/server/utils/notifications.d.ts +72 -7
  253. package/dist/runtime/server/utils/notifications.mjs +67 -55
  254. package/dist/runtime/server/utils/oauth.d.ts +27 -4
  255. package/dist/runtime/server/utils/organization.d.ts +63 -7
  256. package/dist/runtime/server/utils/organization.mjs +26 -21
  257. package/dist/runtime/server/utils/passwordless.d.ts +62 -33
  258. package/dist/runtime/server/utils/payments.d.ts +51 -12
  259. package/dist/runtime/server/utils/payments.mjs +472 -282
  260. package/dist/runtime/server/utils/queue.d.ts +106 -13
  261. package/dist/runtime/server/utils/queue.mjs +313 -28
  262. package/dist/runtime/server/utils/rag.d.ts +42 -14
  263. package/dist/runtime/server/utils/rag.mjs +169 -4
  264. package/dist/runtime/server/utils/ratelimit.d.ts +34 -5
  265. package/dist/runtime/server/utils/ratelimit.mjs +95 -14
  266. package/dist/runtime/server/utils/realtime.d.ts +68 -52
  267. package/dist/runtime/server/utils/scheduled-task.d.ts +42 -1
  268. package/dist/runtime/server/utils/scheduled-task.mjs +29 -0
  269. package/dist/runtime/server/utils/schema-fallback.d.ts +1 -1
  270. package/dist/runtime/server/utils/schema-fallback.mjs +1 -1
  271. package/dist/runtime/server/utils/session.d.ts +84 -10
  272. package/dist/runtime/server/utils/session.mjs +12 -10
  273. package/dist/runtime/server/utils/sse.d.ts +75 -0
  274. package/dist/runtime/server/utils/sse.mjs +147 -0
  275. package/dist/runtime/server/utils/sso.d.ts +1 -1
  276. package/dist/runtime/server/utils/storage.d.ts +53 -4
  277. package/dist/runtime/server/utils/storage.mjs +15 -11
  278. package/dist/runtime/server/utils/store-localization.d.ts +51 -0
  279. package/dist/runtime/server/utils/store-localization.mjs +417 -0
  280. package/dist/runtime/server/utils/store.d.ts +207 -0
  281. package/dist/runtime/server/utils/store.mjs +2227 -0
  282. package/dist/runtime/server/utils/table-names.d.ts +51 -0
  283. package/dist/runtime/server/utils/table-names.mjs +69 -0
  284. package/dist/runtime/server/utils/tenant.d.ts +26 -2
  285. package/dist/runtime/server/utils/tenant.mjs +16 -12
  286. package/dist/runtime/server/utils/tools-registry-fallback.d.ts +1 -0
  287. package/dist/runtime/server/utils/tools-registry-fallback.mjs +1 -0
  288. package/dist/runtime/server/utils/totp.d.ts +45 -2
  289. package/dist/runtime/server/utils/tracker.d.ts +10 -11
  290. package/dist/runtime/server/utils/turnstile.d.ts +16 -1
  291. package/dist/runtime/server/utils/workflows.d.ts +92 -0
  292. package/dist/runtime/server/utils/workflows.mjs +299 -0
  293. package/dist/runtime/server.d.ts +8 -1
  294. package/dist/runtime/server.mjs +8 -5
  295. package/dist/runtime/service.d.ts +10 -10
  296. package/dist/runtime/storage.d.ts +1 -0
  297. package/dist/runtime/storage.mjs +1 -0
  298. package/dist/runtime/store.d.ts +4 -0
  299. package/dist/runtime/store.mjs +2 -0
  300. package/dist/runtime/test-utils.d.ts +11 -10
  301. package/dist/runtime/test-utils.mjs +64 -4
  302. package/dist/runtime/types/ai.d.ts +21 -2
  303. package/dist/runtime/types/d1.d.ts +17 -0
  304. package/dist/runtime/types/drizzle.d.ts +2 -2
  305. package/dist/runtime/types/durable-object.d.ts +62 -2
  306. package/dist/runtime/types/email.d.ts +46 -0
  307. package/dist/runtime/types/imports.d.ts +6 -1
  308. package/dist/runtime/types/index.d.ts +58 -0
  309. package/dist/runtime/types/index.mjs +3 -0
  310. package/dist/runtime/types/mcp.d.ts +83 -0
  311. package/dist/runtime/types/mcp.mjs +0 -0
  312. package/dist/runtime/types/queue.d.ts +36 -0
  313. package/dist/runtime/types/r2.d.ts +41 -0
  314. package/dist/runtime/types/store.d.ts +313 -0
  315. package/dist/runtime/types/store.mjs +0 -0
  316. package/dist/runtime/types/workflows.d.ts +98 -0
  317. package/dist/runtime/types/workflows.mjs +0 -0
  318. package/dist/runtime/workflows.d.ts +5 -0
  319. package/dist/runtime/workflows.mjs +2 -0
  320. package/dist/types/ai.d.ts +721 -0
  321. package/dist/types/cms.d.ts +710 -0
  322. package/dist/types.d.ts +406 -1288
  323. package/dist/utils/auth-schema.d.ts +3 -2
  324. package/dist/utils/bots.d.ts +20 -0
  325. package/dist/utils/comments-schema.d.ts +5 -4
  326. package/dist/utils/drizzle.d.ts +83 -3
  327. package/dist/utils/durable-objects.d.ts +10 -0
  328. package/dist/utils/email-inbound.d.ts +10 -0
  329. package/dist/utils/local-db.d.ts +1 -3
  330. package/dist/utils/mcp.d.ts +24 -0
  331. package/dist/utils/notifications-schema.d.ts +5 -4
  332. package/dist/utils/payments-schema.d.ts +4 -3
  333. package/dist/utils/store-schema.d.ts +14 -0
  334. package/dist/utils/table-names.d.ts +1 -0
  335. package/dist/utils/tenants-schema.d.ts +4 -3
  336. package/dist/utils/tools.d.ts +20 -0
  337. package/dist/utils/workflows.d.ts +8 -0
  338. package/package.json +34 -4
  339. package/dist/chunks/wrangler.mjs +0 -897
  340. package/dist/runtime/app/components/AuthRegister.vue +0 -306
  341. package/dist/runtime/app/components/AuthSessionsList.vue +0 -137
  342. package/dist/runtime/app/components/AuthSignIn.vue +0 -298
  343. package/dist/runtime/app/components/CMSBookmarkButton.vue +0 -59
  344. package/dist/runtime/app/components/CMSImage.vue +0 -47
  345. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +0 -110
  346. package/dist/runtime/app/components/CMSNewsletter.vue +0 -81
  347. package/dist/runtime/app/components/CMSPreviewBanner.vue +0 -83
  348. package/dist/runtime/app/components/CMSTableOfContents.vue +0 -84
  349. package/dist/runtime/app/components/CMSVersionBanner.vue +0 -53
  350. package/dist/runtime/app/components/CMSVersionSwitcher.vue +0 -140
  351. package/dist/runtime/app/components/Comments.vue +0 -411
  352. package/dist/runtime/app/components/FileUpload.vue +0 -200
  353. package/dist/runtime/app/components/ImpersonationBanner.vue +0 -61
  354. package/dist/runtime/app/components/NotificationBell.vue +0 -263
  355. package/dist/runtime/app/components/NotificationList.vue +0 -205
  356. package/dist/runtime/app/components/NotificationPrompt.vue +0 -133
  357. package/dist/runtime/app/components/PricingGated.vue +0 -81
  358. package/dist/runtime/app/components/PricingTable.vue +0 -274
  359. package/dist/runtime/app/components/RealtimeChat.vue +0 -164
  360. package/dist/runtime/app/components/RealtimePresence.vue +0 -129
  361. package/dist/runtime/app/components/RealtimeStatus.vue +0 -79
  362. package/dist/runtime/app/components/SubscriptionCard.vue +0 -207
  363. package/dist/runtime/app/components/UserProfile.vue +0 -558
@@ -0,0 +1,628 @@
1
+ import { getCloudflareEnv, resolveRuntimeBinding } from "../../bindings.mjs";
2
+ export class InMemorySqlStorageCursor {
3
+ constructor(rows, columnNames = [], rowsRead = 0, rowsWritten = 0) {
4
+ this.rows = rows;
5
+ this.columnNames = columnNames;
6
+ this.rowsRead = rowsRead;
7
+ this.rowsWritten = rowsWritten;
8
+ }
9
+ toArray() {
10
+ return [...this.rows];
11
+ }
12
+ one() {
13
+ return this.rows.length > 0 ? this.rows[0] : null;
14
+ }
15
+ [Symbol.iterator]() {
16
+ return this.rows[Symbol.iterator]();
17
+ }
18
+ }
19
+ export class InMemorySqlStorage {
20
+ tables = /* @__PURE__ */ new Map();
21
+ get databaseSize() {
22
+ let bytes = 0;
23
+ for (const table of this.tables.values()) {
24
+ bytes += JSON.stringify(table).length;
25
+ }
26
+ return bytes;
27
+ }
28
+ exec(query, ...bindings) {
29
+ const trimmed = query.trim();
30
+ const bindingQueue = [...bindings];
31
+ const upper = trimmed.toUpperCase();
32
+ if (upper.startsWith("CREATE TABLE")) {
33
+ const match = trimmed.match(
34
+ /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?([^\s(]+)\s*\(([\s\S]+)\)/i
35
+ );
36
+ if (match) {
37
+ const tableName = match[1].replace(/["`]/g, "").trim().toLowerCase();
38
+ const colDefs = match[2].split(",");
39
+ const columns = [];
40
+ for (const colDef of colDefs) {
41
+ const colName = colDef.trim().split(/\s+/)[0]?.replace(/["`]/g, "");
42
+ if (colName && !["PRIMARY", "KEY", "CONSTRAINT", "FOREIGN"].includes(colName.toUpperCase())) {
43
+ columns.push(colName);
44
+ }
45
+ }
46
+ if (!this.tables.has(tableName)) {
47
+ this.tables.set(tableName, { name: tableName, columns, rows: [] });
48
+ }
49
+ return new InMemorySqlStorageCursor([], columns, 0, 0);
50
+ }
51
+ return new InMemorySqlStorageCursor([], [], 0, 0);
52
+ }
53
+ if (upper.startsWith("DROP TABLE")) {
54
+ const match = trimmed.match(/DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?([^\s;]+)/i);
55
+ if (match) {
56
+ const tableName = match[1].replace(/["`]/g, "").trim().toLowerCase();
57
+ this.tables.delete(tableName);
58
+ }
59
+ return new InMemorySqlStorageCursor([], [], 0, 0);
60
+ }
61
+ if (upper.startsWith("INSERT INTO") || upper.startsWith("INSERT OR REPLACE INTO")) {
62
+ const match = trimmed.match(
63
+ /INSERT(?:\s+OR\s+REPLACE)?\s+INTO\s+([^\s(]+)(?:\s*\(([^)]+)\))?\s+VALUES\s*\(([^)]+)\)/i
64
+ );
65
+ if (match) {
66
+ const tableName = match[1].replace(/["`]/g, "").trim().toLowerCase();
67
+ let table = this.tables.get(tableName);
68
+ if (!table) {
69
+ table = { name: tableName, columns: [], rows: [] };
70
+ this.tables.set(tableName, table);
71
+ }
72
+ const colNames = match[2] ? match[2].split(",").map((c) => c.replace(/["`]/g, "").trim()) : table.columns;
73
+ const valPlaceholders = match[3].split(",").map((v) => v.trim());
74
+ const row = {};
75
+ for (let i = 0; i < valPlaceholders.length; i++) {
76
+ const p = valPlaceholders[i];
77
+ const col = colNames[i] || `col_${i}`;
78
+ let val;
79
+ if (p === "?") {
80
+ val = bindingQueue.shift();
81
+ } else if (p.startsWith("'") && p.endsWith("'")) {
82
+ val = p.slice(1, -1);
83
+ } else if (!isNaN(Number(p))) {
84
+ val = Number(p);
85
+ } else if (p.toLowerCase() === "true") {
86
+ val = true;
87
+ } else if (p.toLowerCase() === "false") {
88
+ val = false;
89
+ } else if (p.toLowerCase() === "null") {
90
+ val = null;
91
+ } else {
92
+ val = p;
93
+ }
94
+ row[col] = val;
95
+ if (!table.columns.includes(col)) {
96
+ table.columns.push(col);
97
+ }
98
+ }
99
+ table.rows.push(row);
100
+ return new InMemorySqlStorageCursor([], table.columns, 0, 1);
101
+ }
102
+ return new InMemorySqlStorageCursor([], [], 0, 0);
103
+ }
104
+ if (upper.startsWith("SELECT")) {
105
+ const match = trimmed.match(/SELECT\s+([\s\S]+?)\s+FROM\s+([^\s;]+)([\s\S]*)/i);
106
+ if (match) {
107
+ const selectFields = match[1].trim();
108
+ const tableName = match[2].replace(/["`]/g, "").trim().toLowerCase();
109
+ const rest = match[3] || "";
110
+ const table = this.tables.get(tableName);
111
+ if (!table) {
112
+ return new InMemorySqlStorageCursor([], [], 0, 0);
113
+ }
114
+ let filteredRows = [...table.rows];
115
+ const rowsRead = filteredRows.length;
116
+ const whereMatch = rest.match(/WHERE\s+([\s\S]+?)(?=\s+ORDER\s+BY|\s+LIMIT|\s+OFFSET|$)/i);
117
+ if (whereMatch) {
118
+ const conditionStr = whereMatch[1].trim();
119
+ const qCount = (conditionStr.match(/\?/g) || []).length;
120
+ const whereBindings = bindingQueue.splice(0, qCount);
121
+ filteredRows = filteredRows.filter(
122
+ (r) => this.evalCondition(r, conditionStr, [...whereBindings])
123
+ );
124
+ }
125
+ const orderMatch = rest.match(/ORDER\s+BY\s+([^\s,]+)(?:\s+(ASC|DESC))?/i);
126
+ if (orderMatch) {
127
+ const orderCol = orderMatch[1].replace(/["`]/g, "").trim();
128
+ const isDesc = (orderMatch[2] || "ASC").toUpperCase() === "DESC";
129
+ filteredRows.sort((a, b) => {
130
+ const valA = a[orderCol];
131
+ const valB = b[orderCol];
132
+ if (valA === valB) return 0;
133
+ if (valA === void 0 || valA === null) return isDesc ? 1 : -1;
134
+ if (valB === void 0 || valB === null) return isDesc ? -1 : 1;
135
+ if (valA < valB) return isDesc ? 1 : -1;
136
+ return isDesc ? -1 : 1;
137
+ });
138
+ }
139
+ const offsetMatch = rest.match(/OFFSET\s+(\d+|\?)/i);
140
+ if (offsetMatch) {
141
+ const offsetVal = offsetMatch[1] === "?" ? Number(bindingQueue.shift()) : Number(offsetMatch[1]);
142
+ filteredRows = filteredRows.slice(offsetVal);
143
+ }
144
+ const limitMatch = rest.match(/LIMIT\s+(\d+|\?)/i);
145
+ if (limitMatch) {
146
+ const limitVal = limitMatch[1] === "?" ? Number(bindingQueue.shift()) : Number(limitMatch[1]);
147
+ filteredRows = filteredRows.slice(0, limitVal);
148
+ }
149
+ if (/COUNT\s*\(\s*\*\s*\)/i.test(selectFields)) {
150
+ const countRows = [
151
+ { "count(*)": filteredRows.length, count: filteredRows.length }
152
+ ];
153
+ return new InMemorySqlStorageCursor(countRows, ["count"], rowsRead, 0);
154
+ }
155
+ let resultRows;
156
+ let colNames;
157
+ if (selectFields === "*") {
158
+ resultRows = filteredRows.map((r) => ({ ...r }));
159
+ colNames = table.columns;
160
+ } else {
161
+ const requestedCols = selectFields.split(",").map((c) => c.replace(/["`]/g, "").trim());
162
+ colNames = requestedCols;
163
+ resultRows = filteredRows.map((r) => {
164
+ const projected = {};
165
+ for (const col of requestedCols) {
166
+ projected[col] = r[col];
167
+ }
168
+ return projected;
169
+ });
170
+ }
171
+ return new InMemorySqlStorageCursor(resultRows, colNames, rowsRead, 0);
172
+ }
173
+ return new InMemorySqlStorageCursor([], [], 0, 0);
174
+ }
175
+ if (upper.startsWith("UPDATE")) {
176
+ const match = trimmed.match(
177
+ /UPDATE\s+([^\s]+)\s+SET\s+([\s\S]+?)(?:\s+WHERE\s+([\s\S]+))?$/i
178
+ );
179
+ if (match) {
180
+ const tableName = match[1].replace(/["`]/g, "").trim().toLowerCase();
181
+ const setClause = match[2].trim();
182
+ const whereClause = match[3] ? match[3].trim() : void 0;
183
+ const table = this.tables.get(tableName);
184
+ if (!table) return new InMemorySqlStorageCursor([], [], 0, 0);
185
+ const setQCount = (setClause.match(/\?/g) || []).length;
186
+ const setBindings = bindingQueue.splice(0, setQCount);
187
+ const assignments = setClause.split(",").map((a) => {
188
+ const [col, valExpr] = a.split("=").map((s) => s.trim());
189
+ const cleanCol = col.replace(/["`]/g, "");
190
+ let val;
191
+ if (valExpr === "?") {
192
+ val = setBindings.shift();
193
+ } else if (valExpr.startsWith("'") && valExpr.endsWith("'")) {
194
+ val = valExpr.slice(1, -1);
195
+ } else if (!isNaN(Number(valExpr))) {
196
+ val = Number(valExpr);
197
+ } else {
198
+ val = valExpr;
199
+ }
200
+ return { col: cleanCol, val };
201
+ });
202
+ const whereQCount = whereClause ? (whereClause.match(/\?/g) || []).length : 0;
203
+ const whereBindings = bindingQueue.splice(0, whereQCount);
204
+ let written = 0;
205
+ for (const row of table.rows) {
206
+ if (!whereClause || this.evalCondition(row, whereClause, [...whereBindings])) {
207
+ for (const { col, val } of assignments) {
208
+ row[col] = val;
209
+ }
210
+ written++;
211
+ }
212
+ }
213
+ return new InMemorySqlStorageCursor([], table.columns, table.rows.length, written);
214
+ }
215
+ return new InMemorySqlStorageCursor([], [], 0, 0);
216
+ }
217
+ if (upper.startsWith("DELETE FROM")) {
218
+ const match = trimmed.match(/DELETE\s+FROM\s+([^\s]+)(?:\s+WHERE\s+([\s\S]+))?$/i);
219
+ if (match) {
220
+ const tableName = match[1].replace(/["`]/g, "").trim().toLowerCase();
221
+ const whereClause = match[2] ? match[2].trim() : void 0;
222
+ const table = this.tables.get(tableName);
223
+ if (!table) return new InMemorySqlStorageCursor([], [], 0, 0);
224
+ const initialCount = table.rows.length;
225
+ if (!whereClause) {
226
+ table.rows = [];
227
+ return new InMemorySqlStorageCursor([], table.columns, initialCount, initialCount);
228
+ }
229
+ const whereQCount = whereClause ? (whereClause.match(/\?/g) || []).length : 0;
230
+ const whereBindings = bindingQueue.splice(0, whereQCount);
231
+ table.rows = table.rows.filter(
232
+ (r) => !this.evalCondition(r, whereClause, [...whereBindings])
233
+ );
234
+ const written = initialCount - table.rows.length;
235
+ return new InMemorySqlStorageCursor([], table.columns, initialCount, written);
236
+ }
237
+ return new InMemorySqlStorageCursor([], [], 0, 0);
238
+ }
239
+ return new InMemorySqlStorageCursor([], [], 0, 0);
240
+ }
241
+ evalCondition(row, conditionStr, bindings) {
242
+ const parts = conditionStr.split(/\s+AND\s+/i);
243
+ for (const part of parts) {
244
+ const match = part.trim().match(/([^\s<>=!]+)\s*(=|!=|<>|>|<|>=|<=|LIKE)\s*([\s\S]+)/i);
245
+ if (!match) continue;
246
+ const col = match[1].replace(/["`]/g, "").trim();
247
+ const op = match[2].toUpperCase();
248
+ const valExpr = match[3].trim();
249
+ let targetVal;
250
+ if (valExpr === "?") {
251
+ targetVal = bindings.shift();
252
+ } else if (valExpr.startsWith("'") && valExpr.endsWith("'")) {
253
+ targetVal = valExpr.slice(1, -1);
254
+ } else if (!isNaN(Number(valExpr))) {
255
+ targetVal = Number(valExpr);
256
+ } else {
257
+ targetVal = valExpr;
258
+ }
259
+ const actual = row[col];
260
+ if (op === "=" && actual !== targetVal) return false;
261
+ if ((op === "!=" || op === "<>") && actual === targetVal) return false;
262
+ if (op === ">" && !(actual > targetVal)) return false;
263
+ if (op === "<" && !(actual < targetVal)) return false;
264
+ if (op === ">=" && !(actual >= targetVal)) return false;
265
+ if (op === "<=" && !(actual <= targetVal)) return false;
266
+ if (op === "LIKE") {
267
+ const pattern = String(targetVal).replace(/%/g, ".*").replace(/_/g, ".");
268
+ if (!new RegExp(`^${pattern}$`, "i").test(String(actual || ""))) return false;
269
+ }
270
+ }
271
+ return true;
272
+ }
273
+ }
274
+ export class InMemoryDurableObjectStorage {
275
+ store = /* @__PURE__ */ new Map();
276
+ alarmTime = null;
277
+ sql = new InMemorySqlStorage();
278
+ async get(keyOrKeys) {
279
+ if (Array.isArray(keyOrKeys)) {
280
+ const result = /* @__PURE__ */ new Map();
281
+ for (const k of keyOrKeys) {
282
+ if (this.store.has(k)) {
283
+ result.set(k, this.clone(this.store.get(k)));
284
+ }
285
+ }
286
+ return result;
287
+ }
288
+ const val = this.store.get(keyOrKeys);
289
+ return val !== void 0 ? this.clone(val) : void 0;
290
+ }
291
+ async put(keyOrEntries, value) {
292
+ if (typeof keyOrEntries === "object" && keyOrEntries !== null) {
293
+ for (const [k, v] of Object.entries(keyOrEntries)) {
294
+ this.store.set(k, this.clone(v));
295
+ }
296
+ return;
297
+ }
298
+ this.store.set(keyOrEntries, this.clone(value));
299
+ }
300
+ async delete(keyOrKeys) {
301
+ if (Array.isArray(keyOrKeys)) {
302
+ let count = 0;
303
+ for (const k of keyOrKeys) {
304
+ if (this.store.delete(k)) count++;
305
+ }
306
+ return count;
307
+ }
308
+ return this.store.delete(keyOrKeys);
309
+ }
310
+ async deleteAll() {
311
+ this.store.clear();
312
+ }
313
+ async list(options) {
314
+ let keys = Array.from(this.store.keys()).sort();
315
+ if (options?.reverse) keys.reverse();
316
+ if (options?.prefix) {
317
+ keys = keys.filter((k) => k.startsWith(options.prefix));
318
+ }
319
+ if (options?.start) {
320
+ keys = keys.filter((k) => k >= options.start);
321
+ }
322
+ if (options?.startAfter) {
323
+ keys = keys.filter((k) => k > options.startAfter);
324
+ }
325
+ if (options?.end) {
326
+ keys = keys.filter((k) => k < options.end);
327
+ }
328
+ if (options?.limit) {
329
+ keys = keys.slice(0, options.limit);
330
+ }
331
+ const result = /* @__PURE__ */ new Map();
332
+ for (const k of keys) {
333
+ result.set(k, this.clone(this.store.get(k)));
334
+ }
335
+ return result;
336
+ }
337
+ async transaction(closure) {
338
+ return await closure(this);
339
+ }
340
+ async setAlarm(scheduledTime) {
341
+ this.alarmTime = typeof scheduledTime === "number" ? scheduledTime : scheduledTime.getTime();
342
+ }
343
+ async getAlarm() {
344
+ return this.alarmTime;
345
+ }
346
+ async deleteAlarm() {
347
+ this.alarmTime = null;
348
+ }
349
+ clone(val) {
350
+ if (val === void 0 || val === null || typeof val !== "object") return val;
351
+ try {
352
+ return structuredClone(val);
353
+ } catch {
354
+ return JSON.parse(JSON.stringify(val));
355
+ }
356
+ }
357
+ }
358
+ class InMemoryDurableObjectId {
359
+ constructor(nameStr) {
360
+ this.nameStr = nameStr;
361
+ }
362
+ toString() {
363
+ return this.nameStr;
364
+ }
365
+ equals(other) {
366
+ return this.nameStr === other.toString();
367
+ }
368
+ get name() {
369
+ return this.nameStr;
370
+ }
371
+ }
372
+ export class InMemoryDurableObjectState {
373
+ id;
374
+ storage;
375
+ webSockets = [];
376
+ constructor(name) {
377
+ this.id = new InMemoryDurableObjectId(name);
378
+ this.storage = new InMemoryDurableObjectStorage();
379
+ }
380
+ waitUntil(_promise) {
381
+ }
382
+ async blockConcurrencyWhile(callback) {
383
+ return await callback();
384
+ }
385
+ acceptWebSocket(ws) {
386
+ this.webSockets.push(ws);
387
+ }
388
+ getWebSockets() {
389
+ return this.webSockets;
390
+ }
391
+ }
392
+ const durableObjectRegistry = /* @__PURE__ */ new Map();
393
+ const simulatedInstances = /* @__PURE__ */ new Map();
394
+ export function registerDurableObject(name, doClass) {
395
+ const normalized = name.toUpperCase().replace(/[-_]/g, "");
396
+ durableObjectRegistry.set(normalized, doClass);
397
+ durableObjectRegistry.set(name, doClass);
398
+ }
399
+ export function clearDurableObjectStore() {
400
+ simulatedInstances.clear();
401
+ durableObjectRegistry.clear();
402
+ }
403
+ export function defineDurableObject(definitionOrClass) {
404
+ let GeneratedClass;
405
+ if (typeof definitionOrClass === "function") {
406
+ const BaseClass = definitionOrClass;
407
+ GeneratedClass = class extends BaseClass {
408
+ state;
409
+ storage;
410
+ sql;
411
+ env;
412
+ id;
413
+ constructor(state, env) {
414
+ super(state, env);
415
+ this.state = state;
416
+ this.storage = state?.storage;
417
+ this.sql = state?.storage?.sql;
418
+ this.env = env || {};
419
+ this.id = state?.id;
420
+ }
421
+ async fetch(request) {
422
+ const rpcRes = await dispatchHttpRpc(this, request);
423
+ if (rpcRes) return rpcRes;
424
+ if (typeof super.fetch === "function") {
425
+ return await super.fetch(request);
426
+ }
427
+ return new Response("Not Found", { status: 404 });
428
+ }
429
+ };
430
+ } else {
431
+ const definition = definitionOrClass;
432
+ GeneratedClass = class {
433
+ state;
434
+ storage;
435
+ sql;
436
+ env;
437
+ id;
438
+ constructor(state, env) {
439
+ this.state = state;
440
+ this.storage = state?.storage;
441
+ this.sql = state?.storage?.sql;
442
+ this.env = env || {};
443
+ this.id = state?.id;
444
+ for (const [key, val] of Object.entries(definition)) {
445
+ if (typeof val === "function") {
446
+ ;
447
+ this[key] = val.bind(this);
448
+ } else {
449
+ ;
450
+ this[key] = val;
451
+ }
452
+ }
453
+ }
454
+ waitUntil(promise) {
455
+ this.state?.waitUntil?.(promise);
456
+ }
457
+ async blockConcurrencyWhile(callback) {
458
+ if (typeof this.state?.blockConcurrencyWhile === "function") {
459
+ return await this.state.blockConcurrencyWhile(callback);
460
+ }
461
+ return await callback();
462
+ }
463
+ async fetch(request) {
464
+ const rpcRes = await dispatchHttpRpc(this, request);
465
+ if (rpcRes) return rpcRes;
466
+ if (typeof this.handleFetch === "function") {
467
+ return await this.handleFetch(request);
468
+ }
469
+ return new Response("Not Found", { status: 404 });
470
+ }
471
+ };
472
+ for (const [key, val] of Object.entries(definition)) {
473
+ if (typeof val === "function") {
474
+ ;
475
+ GeneratedClass.prototype[key] = val;
476
+ }
477
+ }
478
+ }
479
+ const doName = definitionOrClass.name || definitionOrClass.className;
480
+ if (doName && doName !== "default" && doName !== "GeneratedClass") {
481
+ registerDurableObject(doName, GeneratedClass);
482
+ }
483
+ return GeneratedClass;
484
+ }
485
+ async function dispatchHttpRpc(instance, request) {
486
+ const url = new URL(request.url);
487
+ const prefixes = ["/__rpc/", "/rpc/"];
488
+ const prefix = prefixes.find((p) => url.pathname.startsWith(p));
489
+ if (!prefix) return null;
490
+ const methodName = url.pathname.slice(prefix.length);
491
+ if (typeof instance[methodName] !== "function") {
492
+ return Response.json(
493
+ { success: false, error: `Method "${methodName}" not found on Durable Object` },
494
+ { status: 404 }
495
+ );
496
+ }
497
+ try {
498
+ let args = [];
499
+ if (request.method === "POST") {
500
+ const body = await request.json().catch(() => []);
501
+ args = Array.isArray(body) ? body : [body];
502
+ }
503
+ const result = await instance[methodName](...args);
504
+ return Response.json({ success: true, result });
505
+ } catch (err) {
506
+ return Response.json(
507
+ { success: false, error: err?.message || String(err) },
508
+ { status: 500 }
509
+ );
510
+ }
511
+ }
512
+ function createSimulatedNamespace(bindingNameOrClass) {
513
+ const instances = /* @__PURE__ */ new Map();
514
+ const isClass = typeof bindingNameOrClass === "function";
515
+ const bindingName = isClass ? bindingNameOrClass.name || "AnonymousDO" : String(bindingNameOrClass);
516
+ const getOrCreateInstance = (idString) => {
517
+ let instance = instances.get(idString);
518
+ if (!instance) {
519
+ let DOClass = isClass ? bindingNameOrClass : void 0;
520
+ if (!DOClass) {
521
+ const normalized = bindingName.toUpperCase().replace(/[-_]/g, "");
522
+ DOClass = durableObjectRegistry.get(normalized) || durableObjectRegistry.get(bindingName) || Array.from(durableObjectRegistry.values())[0];
523
+ }
524
+ const state = new InMemoryDurableObjectState(idString);
525
+ const env = getCloudflareEnv();
526
+ if (DOClass) {
527
+ instance = new DOClass(state, env);
528
+ } else {
529
+ instance = {
530
+ state,
531
+ storage: state.storage,
532
+ env,
533
+ id: state.id,
534
+ async fetch(req) {
535
+ return dispatchHttpRpc(this, req) || new Response("OK");
536
+ }
537
+ };
538
+ }
539
+ instances.set(idString, instance);
540
+ }
541
+ return instance;
542
+ };
543
+ const createStub = (id) => {
544
+ const idString = id.toString();
545
+ const instance = getOrCreateInstance(idString);
546
+ const baseStub = {
547
+ id,
548
+ name: id.name || idString,
549
+ fetch: (req, init) => {
550
+ const request = typeof req === "string" ? new Request(req, init) : req;
551
+ if (typeof instance.fetch === "function") {
552
+ return instance.fetch(request);
553
+ }
554
+ return Promise.resolve(new Response("OK"));
555
+ }
556
+ };
557
+ return new Proxy(baseStub, {
558
+ get(target, prop, receiver) {
559
+ if (prop in target) {
560
+ return Reflect.get(target, prop, receiver);
561
+ }
562
+ if (typeof instance[prop] === "function") {
563
+ return async (...args) => {
564
+ return await instance[prop](...args);
565
+ };
566
+ }
567
+ return instance[prop];
568
+ }
569
+ });
570
+ };
571
+ return {
572
+ newUniqueId: () => new InMemoryDurableObjectId(`uid_${crypto.randomUUID()}`),
573
+ idFromName: (name) => new InMemoryDurableObjectId(name),
574
+ idFromString: (id) => new InMemoryDurableObjectId(id),
575
+ get: (id) => createStub(id),
576
+ getByName: (name) => createStub(new InMemoryDurableObjectId(name))
577
+ };
578
+ }
579
+ export function getDurableObjectNamespace(bindingName, event) {
580
+ if (typeof bindingName === "function") {
581
+ return createSimulatedNamespace(bindingName);
582
+ }
583
+ const resolved = resolveRuntimeBinding("do", bindingName, bindingName);
584
+ const env = getCloudflareEnv(event);
585
+ const nativeNs = env[resolved] || env[bindingName];
586
+ if (nativeNs && typeof nativeNs.get === "function") {
587
+ return {
588
+ newUniqueId: (opts) => nativeNs.newUniqueId(opts),
589
+ idFromName: (name) => nativeNs.idFromName(name),
590
+ idFromString: (id) => nativeNs.idFromString(id),
591
+ get: (id) => wrapNativeStubRpc(nativeNs.get(id)),
592
+ getByName: (name) => wrapNativeStubRpc(nativeNs.get(nativeNs.idFromName(name)))
593
+ };
594
+ }
595
+ return createSimulatedNamespace(resolved);
596
+ }
597
+ function wrapNativeStubRpc(stub) {
598
+ return new Proxy(stub, {
599
+ get(target, prop, receiver) {
600
+ if (prop in target) {
601
+ const val = Reflect.get(target, prop, receiver);
602
+ return typeof val === "function" ? val.bind(target) : val;
603
+ }
604
+ return async (...args) => {
605
+ if (typeof target[prop] === "function") {
606
+ return await target[prop](...args);
607
+ }
608
+ const res = await target.fetch(
609
+ new Request(`https://durable-object.local/__rpc/${String(prop)}`, {
610
+ method: "POST",
611
+ headers: { "Content-Type": "application/json" },
612
+ body: JSON.stringify(args)
613
+ })
614
+ );
615
+ const json = await res.json();
616
+ if (!json.success) {
617
+ throw new Error(json.error || `RPC execution failed for "${String(prop)}"`);
618
+ }
619
+ return json.result;
620
+ };
621
+ }
622
+ });
623
+ }
624
+ export function useDurableObject(bindingName, idOrName, event) {
625
+ const ns = getDurableObjectNamespace(bindingName, event);
626
+ const id = typeof idOrName === "string" ? ns.idFromName(idOrName) : idOrName;
627
+ return ns.get(id);
628
+ }
@@ -0,0 +1,29 @@
1
+ import type { InboundEmailContext, InboundEmailHandler } from "../../types/email";
2
+ /**
3
+ * Defines an inbound email handler for Cloudflare Email Workers.
4
+ *
5
+ * @example
6
+ * ```ts [server/email/incoming.ts]
7
+ * export default defineEmailHandler(async ({ message, forward, reply }) => {
8
+ * console.log("From:", message.from)
9
+ * console.log("Subject:", message.headers.get("subject"))
10
+ * const text = await message.text()
11
+ *
12
+ * if (message.from.endsWith("@spam.com")) {
13
+ * message.setReject("Spam not accepted")
14
+ * return
15
+ * }
16
+ *
17
+ * await reply({
18
+ * subject: "Received your message",
19
+ * text: "Thank you for contacting us!",
20
+ * })
21
+ * })
22
+ * ```
23
+ */
24
+ export declare function defineEmailHandler(handler: InboundEmailHandler): InboundEmailHandler;
25
+ /**
26
+ * Wraps raw Cloudflare `ForwardableEmailMessage` (or a mock/simulated message)
27
+ * into a typed, convenient InboundEmailContext.
28
+ */
29
+ export declare function createInboundEmailContext(rawMessage: any, env?: any, ctx?: any): InboundEmailContext;