nuxt-backend 0.2.0 → 0.2.1

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 (373) hide show
  1. package/dist/chunks/catalog.mjs +1 -1
  2. package/dist/chunks/doctor.mjs +71 -12
  3. package/dist/chunks/email-previews.mjs +1 -1
  4. package/dist/chunks/health.mjs +2 -2
  5. package/dist/chunks/index.mjs +3 -3
  6. package/dist/chunks/install.mjs +4 -4
  7. package/dist/chunks/run.mjs +1 -1
  8. package/dist/chunks/server.mjs +7 -5
  9. package/dist/cli.mjs +122 -23
  10. package/dist/convex/account-data.d.ts +0 -2
  11. package/dist/convex/account-data.d.ts.map +1 -1
  12. package/dist/convex/account-data.js +0 -4
  13. package/dist/convex/account-data.js.map +1 -1
  14. package/dist/convex/catalog.d.ts +22 -0
  15. package/dist/convex/catalog.d.ts.map +1 -1
  16. package/dist/convex/catalog.js.map +1 -1
  17. package/dist/convex/client/better-auth-options.d.ts.map +1 -1
  18. package/dist/convex/client/better-auth-options.js +11 -1
  19. package/dist/convex/client/better-auth-options.js.map +1 -1
  20. package/dist/convex/client/client-address.d.ts +21 -0
  21. package/dist/convex/client/client-address.d.ts.map +1 -0
  22. package/dist/convex/client/client-address.js +37 -0
  23. package/dist/convex/client/client-address.js.map +1 -0
  24. package/dist/convex/client/index.d.ts +34 -2
  25. package/dist/convex/client/index.d.ts.map +1 -1
  26. package/dist/convex/components/backend/_generated/component.d.ts +6 -0
  27. package/dist/convex/components/backend/_generated/component.d.ts.map +1 -1
  28. package/dist/convex/components/backend/account.d.ts +6 -6
  29. package/dist/convex/components/backend/account.d.ts.map +1 -1
  30. package/dist/convex/components/backend/account.js +6 -2
  31. package/dist/convex/components/backend/account.js.map +1 -1
  32. package/dist/convex/components/backend/adapter.d.ts.map +1 -1
  33. package/dist/convex/components/backend/adapter.js +4 -1
  34. package/dist/convex/components/backend/adapter.js.map +1 -1
  35. package/dist/convex/components/backend/ai.d.ts +11 -3
  36. package/dist/convex/components/backend/ai.d.ts.map +1 -1
  37. package/dist/convex/components/backend/ai.js +18 -52
  38. package/dist/convex/components/backend/ai.js.map +1 -1
  39. package/dist/convex/components/backend/billing.d.ts.map +1 -1
  40. package/dist/convex/components/backend/billing.js +12 -32
  41. package/dist/convex/components/backend/billing.js.map +1 -1
  42. package/dist/convex/components/backend/consents.d.ts.map +1 -1
  43. package/dist/convex/components/backend/consents.js +2 -1
  44. package/dist/convex/components/backend/consents.js.map +1 -1
  45. package/dist/convex/components/backend/gifts.d.ts +1 -1
  46. package/dist/convex/components/backend/gifts.d.ts.map +1 -1
  47. package/dist/convex/components/backend/gifts.js +9 -4
  48. package/dist/convex/components/backend/gifts.js.map +1 -1
  49. package/dist/convex/components/backend/lifecycle.d.ts.map +1 -1
  50. package/dist/convex/components/backend/lifecycle.js +18 -14
  51. package/dist/convex/components/backend/lifecycle.js.map +1 -1
  52. package/dist/convex/components/backend/notifications.d.ts +13 -0
  53. package/dist/convex/components/backend/notifications.d.ts.map +1 -1
  54. package/dist/convex/components/backend/notifications.js +21 -0
  55. package/dist/convex/components/backend/notifications.js.map +1 -1
  56. package/dist/convex/components/backend/referrals.d.ts.map +1 -1
  57. package/dist/convex/components/backend/referrals.js +13 -16
  58. package/dist/convex/components/backend/referrals.js.map +1 -1
  59. package/dist/convex/components/backend/reports.js +7 -7
  60. package/dist/convex/components/backend/reports.js.map +1 -1
  61. package/dist/convex/components/backend/schema.d.ts +151 -35
  62. package/dist/convex/components/backend/schema.d.ts.map +1 -1
  63. package/dist/convex/components/backend/schema.js +127 -153
  64. package/dist/convex/components/backend/schema.js.map +1 -1
  65. package/dist/convex/components/backend/storage.d.ts.map +1 -1
  66. package/dist/convex/components/backend/storage.js +10 -10
  67. package/dist/convex/components/backend/storage.js.map +1 -1
  68. package/dist/convex/components/backend/subscriptions.d.ts +3 -3
  69. package/dist/convex/components/backend/subscriptions.d.ts.map +1 -1
  70. package/dist/convex/components/backend/subscriptions.js +6 -35
  71. package/dist/convex/components/backend/subscriptions.js.map +1 -1
  72. package/dist/convex/components/backend/waitlist.d.ts +1 -1
  73. package/dist/convex/components/backend/webhooks.d.ts +0 -1
  74. package/dist/convex/components/backend/webhooks.d.ts.map +1 -1
  75. package/dist/convex/components/backend/webhooks.js +1 -1
  76. package/dist/convex/components/backend/webhooks.js.map +1 -1
  77. package/dist/convex/consent-rules.d.ts +0 -2
  78. package/dist/convex/consent-rules.d.ts.map +1 -1
  79. package/dist/convex/consent-rules.js.map +1 -1
  80. package/dist/convex/constants.d.ts +0 -1
  81. package/dist/convex/constants.d.ts.map +1 -1
  82. package/dist/convex/constants.js +0 -1
  83. package/dist/convex/constants.js.map +1 -1
  84. package/dist/convex/email-templates.d.ts +0 -1
  85. package/dist/convex/email-templates.d.ts.map +1 -1
  86. package/dist/convex/email-templates.js +0 -1
  87. package/dist/convex/email-templates.js.map +1 -1
  88. package/dist/convex/integrations/admin.d.ts +2 -1
  89. package/dist/convex/integrations/admin.d.ts.map +1 -1
  90. package/dist/convex/integrations/admin.js.map +1 -1
  91. package/dist/convex/integrations/ai/job-errors.d.ts +7 -0
  92. package/dist/convex/integrations/ai/job-errors.d.ts.map +1 -1
  93. package/dist/convex/integrations/ai/job-errors.js +22 -0
  94. package/dist/convex/integrations/ai/job-errors.js.map +1 -1
  95. package/dist/convex/integrations/ai/metering.d.ts +12 -0
  96. package/dist/convex/integrations/ai/metering.d.ts.map +1 -1
  97. package/dist/convex/integrations/ai/metering.js +19 -10
  98. package/dist/convex/integrations/ai/metering.js.map +1 -1
  99. package/dist/convex/integrations/ai/models.d.ts.map +1 -1
  100. package/dist/convex/integrations/ai/models.js +3 -1
  101. package/dist/convex/integrations/ai/models.js.map +1 -1
  102. package/dist/convex/integrations/ai/moderation.d.ts +2 -0
  103. package/dist/convex/integrations/ai/moderation.d.ts.map +1 -1
  104. package/dist/convex/integrations/ai/moderation.js +29 -2
  105. package/dist/convex/integrations/ai/moderation.js.map +1 -1
  106. package/dist/convex/integrations/ai/stream.d.ts +1 -1
  107. package/dist/convex/integrations/ai/stream.d.ts.map +1 -1
  108. package/dist/convex/integrations/ai/stream.js +3 -11
  109. package/dist/convex/integrations/ai/stream.js.map +1 -1
  110. package/dist/convex/integrations/billing/context.d.ts +0 -1
  111. package/dist/convex/integrations/billing/context.d.ts.map +1 -1
  112. package/dist/convex/integrations/billing/context.js +1 -4
  113. package/dist/convex/integrations/billing/context.js.map +1 -1
  114. package/dist/convex/integrations/billing/credits.d.ts.map +1 -1
  115. package/dist/convex/integrations/billing/customers.d.ts.map +1 -1
  116. package/dist/convex/integrations/billing/customers.js +25 -5
  117. package/dist/convex/integrations/billing/customers.js.map +1 -1
  118. package/dist/convex/integrations/billing/features.d.ts.map +1 -1
  119. package/dist/convex/integrations/billing/free-plan.d.ts +1 -1
  120. package/dist/convex/integrations/billing/free-plan.d.ts.map +1 -1
  121. package/dist/convex/integrations/billing/free-plan.js +18 -4
  122. package/dist/convex/integrations/billing/free-plan.js.map +1 -1
  123. package/dist/convex/integrations/billing/functions.d.ts +5 -1
  124. package/dist/convex/integrations/billing/functions.d.ts.map +1 -1
  125. package/dist/convex/integrations/billing/functions.js +16 -5
  126. package/dist/convex/integrations/billing/functions.js.map +1 -1
  127. package/dist/convex/integrations/billing/gifts.d.ts.map +1 -1
  128. package/dist/convex/integrations/billing/gifts.js +2 -2
  129. package/dist/convex/integrations/billing/gifts.js.map +1 -1
  130. package/dist/convex/integrations/billing/history.d.ts.map +1 -1
  131. package/dist/convex/integrations/billing/history.js +3 -1
  132. package/dist/convex/integrations/billing/history.js.map +1 -1
  133. package/dist/convex/integrations/billing/lifecycle.d.ts +4 -1
  134. package/dist/convex/integrations/billing/lifecycle.d.ts.map +1 -1
  135. package/dist/convex/integrations/billing/lifecycle.js +33 -2
  136. package/dist/convex/integrations/billing/lifecycle.js.map +1 -1
  137. package/dist/convex/integrations/billing/passes.d.ts +0 -2
  138. package/dist/convex/integrations/billing/passes.d.ts.map +1 -1
  139. package/dist/convex/integrations/billing/passes.js +2 -3
  140. package/dist/convex/integrations/billing/passes.js.map +1 -1
  141. package/dist/convex/integrations/billing/pricing.d.ts +4 -1
  142. package/dist/convex/integrations/billing/pricing.d.ts.map +1 -1
  143. package/dist/convex/integrations/billing/pricing.js +11 -9
  144. package/dist/convex/integrations/billing/pricing.js.map +1 -1
  145. package/dist/convex/integrations/billing/purchase.d.ts.map +1 -1
  146. package/dist/convex/integrations/billing/purchase.js +1 -2
  147. package/dist/convex/integrations/billing/purchase.js.map +1 -1
  148. package/dist/convex/integrations/billing/quotas.d.ts.map +1 -1
  149. package/dist/convex/integrations/billing/subscriptions.d.ts.map +1 -1
  150. package/dist/convex/integrations/billing/types/lifecycle.d.ts +12 -0
  151. package/dist/convex/integrations/billing/types/lifecycle.d.ts.map +1 -1
  152. package/dist/convex/integrations/billing/types/options.d.ts +4 -1
  153. package/dist/convex/integrations/billing/types/options.d.ts.map +1 -1
  154. package/dist/convex/integrations/billing/types/records.d.ts +7 -1
  155. package/dist/convex/integrations/billing/types/records.d.ts.map +1 -1
  156. package/dist/convex/integrations/billing/types/surface.d.ts +5 -1
  157. package/dist/convex/integrations/billing/types/surface.d.ts.map +1 -1
  158. package/dist/convex/integrations/billing.d.ts +2 -2
  159. package/dist/convex/integrations/billing.d.ts.map +1 -1
  160. package/dist/convex/integrations/billing.js +1 -0
  161. package/dist/convex/integrations/billing.js.map +1 -1
  162. package/dist/convex/integrations/email-preferences.d.ts +1 -1
  163. package/dist/convex/integrations/email-preferences.d.ts.map +1 -1
  164. package/dist/convex/integrations/email-sync.d.ts.map +1 -1
  165. package/dist/convex/integrations/email-sync.js +43 -1
  166. package/dist/convex/integrations/email-sync.js.map +1 -1
  167. package/dist/convex/integrations/notifications.d.ts +24 -4
  168. package/dist/convex/integrations/notifications.d.ts.map +1 -1
  169. package/dist/convex/integrations/notifications.js +30 -14
  170. package/dist/convex/integrations/notifications.js.map +1 -1
  171. package/dist/convex/integrations/rate-limit.d.ts +6 -5
  172. package/dist/convex/integrations/rate-limit.d.ts.map +1 -1
  173. package/dist/convex/integrations/rate-limit.js +6 -5
  174. package/dist/convex/integrations/rate-limit.js.map +1 -1
  175. package/dist/convex/integrations/reports.d.ts +1 -1
  176. package/dist/convex/integrations/reports.d.ts.map +1 -1
  177. package/dist/convex/integrations/reports.js +0 -11
  178. package/dist/convex/integrations/reports.js.map +1 -1
  179. package/dist/convex/integrations/webhooks.d.ts +1 -3
  180. package/dist/convex/integrations/webhooks.d.ts.map +1 -1
  181. package/dist/convex/integrations/webhooks.js.map +1 -1
  182. package/dist/convex/label-groups/cancelFlow.d.ts +3 -0
  183. package/dist/convex/label-groups/cancelFlow.d.ts.map +1 -1
  184. package/dist/convex/label-groups/cancelFlow.js +5 -0
  185. package/dist/convex/label-groups/cancelFlow.js.map +1 -1
  186. package/dist/convex/label-groups/credits.d.ts +14 -1
  187. package/dist/convex/label-groups/credits.d.ts.map +1 -1
  188. package/dist/convex/label-groups/credits.js +17 -2
  189. package/dist/convex/label-groups/credits.js.map +1 -1
  190. package/dist/convex/label-groups/notifications.d.ts +19 -2
  191. package/dist/convex/label-groups/notifications.d.ts.map +1 -1
  192. package/dist/convex/label-groups/notifications.js +19 -15
  193. package/dist/convex/label-groups/notifications.js.map +1 -1
  194. package/dist/convex/label-groups/pricing.js +8 -8
  195. package/dist/convex/label-groups/pricing.js.map +1 -1
  196. package/dist/convex/label-groups/settings.d.ts.map +1 -1
  197. package/dist/convex/label-groups/settings.js +4 -3
  198. package/dist/convex/label-groups/settings.js.map +1 -1
  199. package/dist/convex/label-groups/usage.d.ts +1 -1
  200. package/dist/convex/label-groups/usage.d.ts.map +1 -1
  201. package/dist/convex/label-groups/usage.js +2 -2
  202. package/dist/convex/label-groups/usage.js.map +1 -1
  203. package/dist/convex/label-translations.d.ts.map +1 -1
  204. package/dist/convex/label-translations.js +52 -0
  205. package/dist/convex/label-translations.js.map +1 -1
  206. package/dist/convex/labels.d.ts +23 -0
  207. package/dist/convex/labels.d.ts.map +1 -1
  208. package/dist/convex/log.js +2 -0
  209. package/dist/convex/log.js.map +1 -1
  210. package/dist/convex/notifications.d.ts +77 -0
  211. package/dist/convex/notifications.d.ts.map +1 -1
  212. package/dist/convex/notifications.js +64 -13
  213. package/dist/convex/notifications.js.map +1 -1
  214. package/dist/convex/proof.d.ts +25 -0
  215. package/dist/convex/proof.d.ts.map +1 -1
  216. package/dist/convex/proof.js +39 -0
  217. package/dist/convex/proof.js.map +1 -1
  218. package/dist/convex/referral-rules.d.ts +0 -2
  219. package/dist/convex/referral-rules.d.ts.map +1 -1
  220. package/dist/convex/referral-rules.js +0 -2
  221. package/dist/convex/referral-rules.js.map +1 -1
  222. package/dist/convex/waitlist-rules.d.ts +1 -13
  223. package/dist/convex/waitlist-rules.d.ts.map +1 -1
  224. package/dist/convex/waitlist-rules.js +2 -14
  225. package/dist/convex/waitlist-rules.js.map +1 -1
  226. package/dist/devtools-client/index.html +1 -1
  227. package/dist/module.js +2 -2
  228. package/dist/module.json +1 -1
  229. package/dist/runtime/locales/de.json +47 -24
  230. package/dist/runtime/locales/en.json +47 -24
  231. package/dist/runtime/locales/es.json +47 -24
  232. package/dist/runtime/locales/fr.json +47 -24
  233. package/dist/runtime/locales/ru.json +47 -24
  234. package/dist/runtime/server/protection/gate.d.ts +4 -2
  235. package/dist/runtime/server/protection/gate.js +14 -4
  236. package/dist/runtime/vue/admin-client.d.ts +18 -0
  237. package/dist/runtime/vue/admin-client.js +32 -0
  238. package/dist/runtime/vue/auth-client.d.ts +16 -11
  239. package/dist/runtime/vue/auth-client.js +3 -1
  240. package/dist/runtime/vue/components/admin/AdminUsers.d.vue.ts +1 -1
  241. package/dist/runtime/vue/components/admin/AdminUsers.vue.d.ts +1 -1
  242. package/dist/runtime/vue/components/billing/BillingCheckoutLink.d.vue.ts +1 -1
  243. package/dist/runtime/vue/components/billing/BillingCheckoutLink.vue.d.ts +1 -1
  244. package/dist/runtime/vue/components/billing/CancelFlow.css +1 -1
  245. package/dist/runtime/vue/components/billing/CancelFlow.d.vue.ts +3 -0
  246. package/dist/runtime/vue/components/billing/CancelFlow.vue +10 -3
  247. package/dist/runtime/vue/components/billing/CancelFlow.vue.d.ts +3 -0
  248. package/dist/runtime/vue/components/billing/CancelFlowConfirm.d.vue.ts +3 -0
  249. package/dist/runtime/vue/components/billing/CancelFlowConfirm.vue +34 -0
  250. package/dist/runtime/vue/components/billing/CancelFlowConfirm.vue.d.ts +3 -0
  251. package/dist/runtime/vue/components/billing/CancelFlowQuestion.vue +2 -1
  252. package/dist/runtime/vue/components/billing/GiftSent.d.vue.ts +2 -2
  253. package/dist/runtime/vue/components/billing/GiftSent.vue.d.ts +2 -2
  254. package/dist/runtime/vue/components/billing/PricingPackCard.vue +6 -3
  255. package/dist/runtime/vue/components/billing/PricingPlanCard.vue +3 -1
  256. package/dist/runtime/vue/components/billing/PricingTable.d.vue.ts +2 -2
  257. package/dist/runtime/vue/components/billing/PricingTable.vue +3 -1
  258. package/dist/runtime/vue/components/billing/PricingTable.vue.d.ts +2 -2
  259. package/dist/runtime/vue/components/billing/UsageHistoryEvent.vue +3 -1
  260. package/dist/runtime/vue/components/billing/cancel-flow.d.ts +28 -7
  261. package/dist/runtime/vue/components/billing/cancel-flow.js +25 -2
  262. package/dist/runtime/vue/components/shell/NoticeLowCredits.vue +3 -1
  263. package/dist/runtime/vue/components/tokens.css +1 -1
  264. package/dist/runtime/vue/components/workspaces/WorkspaceCredits.vue +6 -3
  265. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +2 -2
  266. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +2 -2
  267. package/dist/runtime/vue/composables/use-auth.d.ts +13 -1
  268. package/dist/runtime/vue/composables/use-auth.js +4 -1
  269. package/dist/runtime/vue/composables/use-billing.d.ts +10 -2
  270. package/dist/runtime/vue/composables/use-credits.d.ts +3 -0
  271. package/dist/runtime/vue/composables/use-credits.js +1 -0
  272. package/dist/runtime/vue/composables/use-notifications.d.ts +5 -1
  273. package/dist/runtime/vue/composables/use-notifications.js +12 -4
  274. package/dist/runtime/vue/composables/use-webhook-log.d.ts +4 -2
  275. package/dist/runtime/vue/organization-client.d.ts +15 -0
  276. package/dist/runtime/vue/organization-client.js +65 -0
  277. package/dist/runtime/vue/parts.d.ts +2 -1
  278. package/dist/runtime/vue/plugins/checkout-return.d.ts +3 -2
  279. package/dist/runtime/vue/plugins/checkout-return.js +2 -4
  280. package/dist/runtime/vue/plugins/first-touch.js +2 -4
  281. package/dist/runtime/vue/utils/checkout-return.d.ts +9 -2
  282. package/dist/runtime/vue/utils/checkout-return.js +2 -1
  283. package/dist/runtime/vue/utils/every-page.d.ts +10 -0
  284. package/dist/runtime/vue/utils/every-page.js +6 -0
  285. package/dist/runtime/vue/utils/meter-unit.d.ts +14 -0
  286. package/dist/runtime/vue/utils/meter-unit.js +18 -0
  287. package/dist/shared/{nuxt-backend.2YoiKo8j.mjs → nuxt-backend.2m535CLS.mjs} +6 -2
  288. package/dist/shared/{nuxt-backend.CPq101Wi.mjs → nuxt-backend.DXEf0rrv.mjs} +1 -1
  289. package/dist/shared/{nuxt-backend.-uB5CGw-.mjs → nuxt-backend.Dm1NkY7v.mjs} +1 -1
  290. package/dist/shared/{nuxt-backend.OQMX-0U7.mjs → nuxt-backend.KEzfHO2K.mjs} +6 -3
  291. package/dist/shared/{nuxt-backend.S5C2b-4I.mjs → nuxt-backend.ikObmtHs.mjs} +2 -2
  292. package/package.json +2 -2
  293. package/skills/nuxt-backend/references/api.md +13 -3
  294. package/skills/nuxt-backend/references/surface.json +12 -0
  295. package/skills/nuxt-backend-auth/SKILL.md +2 -1
  296. package/skills/nuxt-backend-billing/SKILL.md +7 -0
  297. package/skills/nuxt-backend-billing/references/api.md +12 -2
  298. package/skills/nuxt-backend-data/SKILL.md +4 -1
  299. package/skills/nuxt-backend-email/SKILL.md +4 -0
  300. package/skills/nuxt-backend-email/references/api.md +1 -1
  301. package/skills/nuxt-backend-ui/SKILL.md +6 -5
  302. package/src/convex/account-data.ts +0 -5
  303. package/src/convex/catalog.ts +23 -0
  304. package/src/convex/client/better-auth-options.ts +11 -1
  305. package/src/convex/client/client-address.ts +37 -0
  306. package/src/convex/components/backend/_generated/component.ts +12 -0
  307. package/src/convex/components/backend/account.ts +7 -2
  308. package/src/convex/components/backend/adapter.ts +4 -1
  309. package/src/convex/components/backend/ai.ts +20 -54
  310. package/src/convex/components/backend/billing.ts +14 -33
  311. package/src/convex/components/backend/consents.ts +2 -1
  312. package/src/convex/components/backend/gifts.ts +11 -5
  313. package/src/convex/components/backend/lifecycle.ts +17 -12
  314. package/src/convex/components/backend/notifications.ts +22 -0
  315. package/src/convex/components/backend/referrals.ts +14 -16
  316. package/src/convex/components/backend/reports.ts +7 -7
  317. package/src/convex/components/backend/schema.ts +143 -161
  318. package/src/convex/components/backend/storage.ts +11 -10
  319. package/src/convex/components/backend/subscriptions.ts +7 -35
  320. package/src/convex/components/backend/webhooks.ts +1 -10
  321. package/src/convex/consent-rules.ts +0 -3
  322. package/src/convex/constants.ts +0 -1
  323. package/src/convex/email-templates.ts +0 -1
  324. package/src/convex/integrations/admin.ts +2 -1
  325. package/src/convex/integrations/ai/job-errors.ts +21 -0
  326. package/src/convex/integrations/ai/metering.ts +24 -10
  327. package/src/convex/integrations/ai/models.ts +3 -1
  328. package/src/convex/integrations/ai/moderation.ts +31 -2
  329. package/src/convex/integrations/ai/stream.ts +3 -11
  330. package/src/convex/integrations/billing/context.ts +1 -9
  331. package/src/convex/integrations/billing/customers.ts +28 -5
  332. package/src/convex/integrations/billing/free-plan.ts +20 -5
  333. package/src/convex/integrations/billing/functions.ts +17 -5
  334. package/src/convex/integrations/billing/gifts.ts +2 -2
  335. package/src/convex/integrations/billing/history.ts +2 -1
  336. package/src/convex/integrations/billing/lifecycle.ts +30 -3
  337. package/src/convex/integrations/billing/passes.ts +2 -4
  338. package/src/convex/integrations/billing/pricing.ts +14 -10
  339. package/src/convex/integrations/billing/purchase.ts +1 -2
  340. package/src/convex/integrations/billing/types/lifecycle.ts +13 -0
  341. package/src/convex/integrations/billing/types/options.ts +4 -1
  342. package/src/convex/integrations/billing/types/records.ts +7 -1
  343. package/src/convex/integrations/billing/types/surface.ts +3 -1
  344. package/src/convex/integrations/billing.ts +3 -2
  345. package/src/convex/integrations/email-preferences.ts +1 -1
  346. package/src/convex/integrations/email-sync.ts +44 -1
  347. package/src/convex/integrations/notifications.ts +65 -16
  348. package/src/convex/integrations/rate-limit.ts +6 -5
  349. package/src/convex/integrations/reports.ts +1 -1
  350. package/src/convex/integrations/webhooks.ts +1 -4
  351. package/src/convex/label-groups/cancelFlow.ts +5 -0
  352. package/src/convex/label-groups/credits.ts +17 -2
  353. package/src/convex/label-groups/notifications.ts +19 -15
  354. package/src/convex/label-groups/pricing.ts +8 -8
  355. package/src/convex/label-groups/settings.ts +4 -3
  356. package/src/convex/label-groups/usage.ts +2 -2
  357. package/src/convex/label-translations.ts +52 -0
  358. package/src/convex/log.ts +2 -0
  359. package/src/convex/notifications.ts +99 -13
  360. package/src/convex/proof.ts +43 -0
  361. package/src/convex/referral-rules.ts +0 -2
  362. package/src/convex/waitlist-rules.ts +2 -22
  363. package/src/runtime/vue/components/billing/CancelFlow.css +16 -0
  364. package/src/runtime/vue/components/billing/CancelFlow.vue +16 -6
  365. package/src/runtime/vue/components/billing/CancelFlowConfirm.vue +35 -0
  366. package/src/runtime/vue/components/billing/CancelFlowQuestion.vue +8 -2
  367. package/src/runtime/vue/components/billing/PricingPackCard.vue +6 -3
  368. package/src/runtime/vue/components/billing/PricingPlanCard.vue +3 -1
  369. package/src/runtime/vue/components/billing/PricingTable.vue +3 -1
  370. package/src/runtime/vue/components/billing/UsageHistoryEvent.vue +3 -1
  371. package/src/runtime/vue/components/shell/NoticeLowCredits.vue +3 -1
  372. package/src/runtime/vue/components/tokens.css +19 -15
  373. package/src/runtime/vue/components/workspaces/WorkspaceCredits.vue +6 -3
@@ -216,6 +216,19 @@ export const track = mutation({
216
216
  },
217
217
  })
218
218
 
219
+ /**
220
+ * Send one event to the email provider. Answers `true` when a rate limit
221
+ * asks for another try, with attempts left; any other failure is logged
222
+ * with what not sending it again means (`unsent`), and not tried again.
223
+ */
224
+ async function sendProviderEvent(key: string | undefined, args: { event: string, email: string, payload?: Record<string, unknown>, attempt: number }, unsent: string): Promise<boolean> {
225
+ const { error } = await new Resend(key).events.send({ event: args.event, email: args.email, ...(args.payload ? { payload: args.payload } : {}) })
226
+ if (!error) return false
227
+ if (rateLimited(error) && args.attempt < SEND_ATTEMPTS) return true
228
+ logBackend('warn', 'email.event_unsent', `The ${args.event} event failed at the email provider; it is not sent again, so ${unsent}.`, error)
229
+ return false
230
+ }
231
+
219
232
  /** One event to the provider; a rate limit is waited out with backoff, a few times, and any other failure is not tried again. */
220
233
  export const sendEvent = internalAction({
221
234
  args: { event: v.string(), email: v.string(), payload: v.optional(v.record(v.string(), v.any())), attempt: v.number() },
@@ -223,13 +236,9 @@ export const sendEvent = internalAction({
223
236
  handler: async (ctx, args) => {
224
237
  const key = env.EMAIL_API_KEY
225
238
  if (!key) return null
226
- const { error } = await new Resend(key).events.send({ event: args.event, email: args.email, ...(args.payload ? { payload: args.payload } : {}) })
227
- if (!error) return null
228
- if (!rateLimited(error) || args.attempt >= SEND_ATTEMPTS) {
229
- logBackend('warn', 'email.event_unsent', `The ${args.event} event failed at the email provider; it is not sent again, so the automations listening for it start at most once.`, error)
230
- return null
239
+ if (await sendProviderEvent(key, args, 'the automations listening for it start at most once')) {
240
+ await ctx.scheduler.runAfter(2 ** args.attempt * 1000, internal.lifecycle.sendEvent, { ...args, attempt: args.attempt + 1 })
231
241
  }
232
- await ctx.scheduler.runAfter(2 ** args.attempt * 1000, internal.lifecycle.sendEvent, { ...args, attempt: args.attempt + 1 })
233
242
  return null
234
243
  },
235
244
  })
@@ -315,13 +324,9 @@ export const deliver = internalAction({
315
324
  logBackend('warn', 'email.undeliverable', `A lifecycle email (${args.event}) was not sent: ${reason}.`)
316
325
  return null
317
326
  }
318
- const { error } = await new Resend(env.EMAIL_API_KEY).events.send({ event: args.event, email: args.email, ...(args.payload ? { payload: args.payload } : {}) })
319
- if (!error) return null
320
- if (!rateLimited(error) || args.attempt >= SEND_ATTEMPTS) {
321
- logBackend('warn', 'email.event_unsent', `The ${args.event} event failed at the email provider; it is not sent again, so its lifecycle email goes at most once.`, error)
322
- return null
327
+ if (await sendProviderEvent(env.EMAIL_API_KEY, args, 'its lifecycle email goes at most once')) {
328
+ await ctx.scheduler.runAfter(2 ** args.attempt * 1000, internal.lifecycle.deliver, { ...args, attempt: args.attempt + 1 })
323
329
  }
324
- await ctx.scheduler.runAfter(2 ** args.attempt * 1000, internal.lifecycle.deliver, { ...args, attempt: args.attempt + 1 })
325
330
  return null
326
331
  },
327
332
  })
@@ -401,6 +401,28 @@ export const listChoices = query({
401
401
  .map(({ type, channel, enabled }) => ({ type, channel, enabled })),
402
402
  })
403
403
 
404
+ /**
405
+ * Which billing features this deployment has used, so the channel list
406
+ * leaves out the kinds of one it never has: a gift someone bought, a plan
407
+ * pass of any kind, a reverse trial, a referral. One row each answers it.
408
+ * A reverse trial and a reward pass have no purchaser (`purchaserUserId`
409
+ * is empty), and a pass carries its end date from the day it starts.
410
+ */
411
+ export const features = query({
412
+ args: {},
413
+ returns: v.object({ gifts: v.boolean(), passes: v.boolean(), trialPasses: v.boolean(), referrals: v.boolean() }),
414
+ handler: async (ctx) => {
415
+ const gifts = () => ctx.db.query('billingGifts')
416
+ const passRunning = await gifts().withIndex('passEndedAt_passEndsAt', q => q.eq('passEndedAt', undefined).gte('passEndsAt', 0)).first()
417
+ return {
418
+ gifts: await gifts().withIndex('purchaserUserId_createdAt', q => q.gt('purchaserUserId', '')).first() !== null,
419
+ passes: passRunning !== null || await gifts().withIndex('passEndedAt_passEndsAt', q => q.gte('passEndedAt', 0)).first() !== null,
420
+ trialPasses: await gifts().withIndex('status', q => q.eq('status', 'trial')).first() !== null,
421
+ referrals: await ctx.db.query('referrals').first() !== null,
422
+ }
423
+ },
424
+ })
425
+
404
426
  /**
405
427
  * Turn one channel of one kind on or off for a person. The caller, the
406
428
  * app's `setNotificationChannel`, checks the kind allows the channel.
@@ -381,6 +381,12 @@ const vDue = v.object({
381
381
  })
382
382
 
383
383
  /** Whether a held referral may be rewarded at `now`: its hold is over and no flag waits for an administrator. */
384
+ /** A referral by the id the app holds, or `null` for one that is gone or never was. */
385
+ async function referralOf(ctx: QueryCtx, id: string): Promise<Referral | null> {
386
+ const rowId = ctx.db.normalizeId('referrals', id)
387
+ return rowId ? await ctx.db.get('referrals', rowId) : null
388
+ }
389
+
384
390
  function rewardable(row: Referral, now: number): boolean {
385
391
  return row.state === 'held' && row.holdUntil !== undefined && row.holdUntil <= now && !inReview(row)
386
392
  }
@@ -407,8 +413,7 @@ export const get = query({
407
413
  args: { id: v.string() },
408
414
  returns: v.union(v.null(), vDue),
409
415
  handler: async (ctx, { id }) => {
410
- const rowId = ctx.db.normalizeId('referrals', id)
411
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
416
+ const row = await referralOf(ctx, id)
412
417
  if (!row?.orderId || !row.entityId) return null
413
418
  return { id: row._id as string, referrerId: row.referrerId, referredId: row.referredId, orderId: row.orderId, entityId: row.entityId, terms: row.terms, state: row.state, ...(row.grant ? { grant: row.grant } : {}) }
414
419
  },
@@ -480,8 +485,7 @@ export const beginReward = mutation({
480
485
  args: { id: v.string(), now: v.number() },
481
486
  returns: v.union(v.literal('grant'), v.literal('capped'), v.literal('skip')),
482
487
  handler: async (ctx, { id, now }) => {
483
- const rowId = ctx.db.normalizeId('referrals', id)
484
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
488
+ const row = await referralOf(ctx, id)
485
489
  if (!row || !rewardable(row, now)) return 'skip'
486
490
  if (row.reservedMonth) return 'grant'
487
491
  const { perReferrer, perMonth } = row.terms.caps
@@ -503,8 +507,7 @@ export const noteGrant = mutation({
503
507
  args: { id: v.string(), grant: v.object({ discountId: v.optional(v.string()), endsAt: v.optional(v.number()), done: v.optional(v.boolean()) }) },
504
508
  returns: v.null(),
505
509
  handler: async (ctx, { id, grant }) => {
506
- const rowId = ctx.db.normalizeId('referrals', id)
507
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
510
+ const row = await referralOf(ctx, id)
508
511
  if (row) await patchReferral(ctx, row, { grant: { ...row.grant, ...grant } })
509
512
  return null
510
513
  },
@@ -515,8 +518,7 @@ export const finishReward = mutation({
515
518
  args: { id: v.string() },
516
519
  returns: v.boolean(),
517
520
  handler: async (ctx, { id }) => {
518
- const rowId = ctx.db.normalizeId('referrals', id)
519
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
521
+ const row = await referralOf(ctx, id)
520
522
  if (row?.state !== 'held') return false
521
523
  await patchReferral(ctx, row, { state: 'rewarded', rewardedAt: Date.now(), dueAt: undefined })
522
524
  return true
@@ -528,8 +530,7 @@ export const deferReward = mutation({
528
530
  args: { id: v.string(), until: v.number() },
529
531
  returns: v.null(),
530
532
  handler: async (ctx, { id, until }) => {
531
- const rowId = ctx.db.normalizeId('referrals', id)
532
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
533
+ const row = await referralOf(ctx, id)
533
534
  if (row?.state === 'held' && row.dueAt !== undefined) await patchReferral(ctx, row, { dueAt: until })
534
535
  return null
535
536
  },
@@ -544,8 +545,7 @@ export const closeUnrewarded = mutation({
544
545
  args: { id: v.string(), now: v.number() },
545
546
  returns: v.boolean(),
546
547
  handler: async (ctx, { id, now }) => {
547
- const rowId = ctx.db.normalizeId('referrals', id)
548
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
548
+ const row = await referralOf(ctx, id)
549
549
  if (!row || !rewardable(row, now)) return false
550
550
  await releaseSlot(ctx, row)
551
551
  await patchReferral(ctx, row, { state: 'claimed', unrewarded: true, dueAt: undefined })
@@ -558,8 +558,7 @@ export const voidReferral = mutation({
558
558
  args: { id: v.string(), reason: v.union(v.literal('refunded'), v.literal('administrator'), v.literal('account_erased')) },
559
559
  returns: v.boolean(),
560
560
  handler: async (ctx, { id, reason }) => {
561
- const rowId = ctx.db.normalizeId('referrals', id)
562
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
561
+ const row = await referralOf(ctx, id)
563
562
  return row ? await voidRow(ctx, row, reason) : false
564
563
  },
565
564
  })
@@ -651,8 +650,7 @@ export const resolveFlag = mutation({
651
650
  args: { id: v.string(), resolution: v.union(v.literal('release'), v.literal('void')) },
652
651
  returns: v.boolean(),
653
652
  handler: async (ctx, { id, resolution }) => {
654
- const rowId = ctx.db.normalizeId('referrals', id)
655
- const row = rowId ? await ctx.db.get('referrals', rowId) : null
653
+ const row = await referralOf(ctx, id)
656
654
  if (!row?.flags?.length || (row.state !== 'claimed' && row.state !== 'held')) return false
657
655
  if (resolution === 'void') return await voidRow(ctx, row, 'administrator')
658
656
  // A held referral goes back to the sweep, due from the end of its hold.
@@ -3,7 +3,7 @@ import type { Doc, Id } from './_generated/dataModel.js'
3
3
  import { mutation, type MutationCtx, query, type QueryCtx } from './_generated/server.js'
4
4
  import { APPEAL_WINDOW_MS } from '../../constants.js'
5
5
  import { ERASED_PREFIX } from './parties.js'
6
- import { vReportReason } from './schema.js'
6
+ import { vDecisionAction, vDecisionGround, vReportReason } from './schema.js'
7
7
 
8
8
  /**
9
9
  * Content duties: the component's half of `setupAdmin({ reports })`. One
@@ -209,7 +209,7 @@ export const reportsConsole = query({
209
209
  id: v.string(),
210
210
  text: v.string(),
211
211
  createdAt: v.number(),
212
- decision: v.object({ action: v.union(v.literal('hidden'), v.literal('dismissed')), reason: v.string(), at: v.number(), authorId: v.union(v.string(), v.null()) }),
212
+ decision: v.object({ action: vDecisionAction, reason: v.string(), at: v.number(), authorId: v.union(v.string(), v.null()) }),
213
213
  subject: v.union(vSubject, v.null()),
214
214
  })),
215
215
  }),
@@ -313,9 +313,9 @@ export const decide = mutation({
313
313
  notice: v.optional(v.string()),
314
314
  /** Open notices sent without their thing that the app placed on this one: closed with it. */
315
315
  notices: v.optional(v.array(v.string())),
316
- action: v.union(v.literal('hidden'), v.literal('dismissed')),
316
+ action: vDecisionAction,
317
317
  reason: v.string(),
318
- ground: v.union(v.literal('illegal'), v.literal('terms')),
318
+ ground: vDecisionGround,
319
319
  by: v.string(),
320
320
  authorId: v.optional(v.string()),
321
321
  appealTokenHash: v.optional(v.string()),
@@ -359,9 +359,9 @@ export const flagCrime = mutation({
359
359
 
360
360
  const vAppealable = v.object({
361
361
  decisionId: v.string(),
362
- action: v.union(v.literal('hidden'), v.literal('dismissed')),
362
+ action: vDecisionAction,
363
363
  reason: v.string(),
364
- ground: v.union(v.literal('illegal'), v.literal('terms')),
364
+ ground: vDecisionGround,
365
365
  at: v.number(),
366
366
  until: v.number(),
367
367
  subject: v.union(vSubject, v.null()),
@@ -432,7 +432,7 @@ async function actedOnSince(ctx: QueryCtx, subject: Doc<'reportSubjects'> | null
432
432
  export const decideAppeal = mutation({
433
433
  args: { appeal: v.string(), outcome: v.union(v.literal('upheld'), v.literal('reversed')), reason: v.string(), by: v.string() },
434
434
  returns: v.union(v.object({
435
- action: v.union(v.literal('hidden'), v.literal('dismissed')),
435
+ action: vDecisionAction,
436
436
  subject: v.union(vSubject, v.null()),
437
437
  authorId: v.union(v.string(), v.null()),
438
438
  /** Whether the app shows the content again: a removal reversed, and nothing reported or hidden since. */
@@ -267,52 +267,95 @@ export const vPendingSpend = v.object({
267
267
  * recipient — identified by email — receives. Created at gift checkout, marked
268
268
  * `paid` by the billing webhook, and `claimed` once the entitlement is attached
269
269
  * to the recipient's billing entity (automatically when the recipient already
270
- * has an account, otherwise on their first sign-in).
270
+ * has an account, otherwise on their first sign-in). The `billingGifts` row.
271
271
  */
272
- export const vGift = v.object({
273
- id: v.string(),
272
+ const vGiftRow = v.object({
273
+ // Stored lowercased; matched case-insensitively against the claimant's email.
274
274
  recipientEmail: v.string(),
275
275
  purchaserUserId: v.string(),
276
276
  purchaserEmail: v.optional(v.string()),
277
277
  purchaserName: v.optional(v.string()),
278
+ // The credit pack the recipient receives: its provider product.
278
279
  productIds: v.array(v.string()),
280
+ // Plain text, shown only inside the app once the recipient signs in.
279
281
  message: v.optional(v.string()),
282
+ // 'pending' (checkout created) → 'paid' (the purchase order is paid and
283
+ // its claim discount minted) → 'claimed' (the recipient's $0 order is
284
+ // paid), or 'refunded' (the purchase was refunded before the claim).
280
285
  status: v.string(),
286
+ // Before 0.2: the provider customer keyed by the recipient's email,
287
+ // which the purchase was billed to. Gifts are billed to the purchaser now.
281
288
  billingCustomerId: v.optional(v.string()),
289
+ // The purchase order, paid by the purchaser's own billing entity.
282
290
  billingOrderId: v.optional(v.string()),
283
291
  purchaserEntityId: v.optional(v.string()),
292
+ // The pack's catalog key, and the private gift product the purchaser bought.
284
293
  pack: v.optional(v.string()),
285
294
  giftProductId: v.optional(v.string()),
295
+ // What the purchase order charged, in the currency's smallest unit.
286
296
  amount: v.optional(v.number()),
287
297
  currency: v.optional(v.string()),
298
+ // The single-use 100% discount the recipient claims the pack with.
288
299
  discountId: v.optional(v.string()),
300
+ // The claim checkout in flight: who opened it, for which entity. A plan
301
+ // pass's claim holds the gift until `claimingUntil`, while it switches the
302
+ // workspace at the provider.
289
303
  claimingEntityId: v.optional(v.string()),
290
304
  claimingUserId: v.optional(v.string()),
305
+ claimingUntil: v.optional(v.number()),
306
+ // The purchaser's cancellation in flight, until then: no claim starts meanwhile.
307
+ cancelingUntil: v.optional(v.number()),
291
308
  claimOrderId: v.optional(v.string()),
292
309
  claimedByUserId: v.optional(v.string()),
310
+ // The entity the credits landed on: workspace id or user id.
293
311
  claimedEntityId: v.optional(v.string()),
294
312
  createdAt: v.number(),
295
313
  paidAt: v.optional(v.number()),
296
314
  notifiedAt: v.optional(v.number()),
297
315
  claimedAt: v.optional(v.number()),
298
316
  refundedAt: v.optional(v.number()),
317
+ // A plan pass (the gift is a plan for `months` months, not a pack): the
318
+ // plan's catalog key and the length the purchaser paid for.
299
319
  plan: v.optional(v.string()),
300
320
  months: v.optional(v.number()),
321
+ // When the notice goes out: set when the purchase is paid (the moment
322
+ // it is paid, or the date the purchaser chose). The gift is the
323
+ // recipient's to see and claim once `deliveredAt` is stamped; a row
324
+ // with neither is a gift paid before delivery dates, delivered when paid.
301
325
  deliverAt: v.optional(v.number()),
302
326
  deliveredAt: v.optional(v.number()),
327
+ // The last notice sent (the first, a reminder or a resend), and how many.
303
328
  noticedAt: v.optional(v.number()),
304
329
  noticeCount: v.optional(v.number()),
330
+ // How many times the purchaser changed the address: each address's notices carry their own idempotency keys.
305
331
  recipientChanges: v.optional(v.number()),
332
+ // The one reminder, a week after delivery.
306
333
  remindedAt: v.optional(v.number()),
334
+ // A pass once claimed: the free subscription it switched, when it began
335
+ // and ends (the package keeps the end date), the scheduled return to the
336
+ // free plan, the ending notice and the end itself.
307
337
  passSubscriptionId: v.optional(v.string()),
308
338
  passStartedAt: v.optional(v.number()),
309
339
  passEndsAt: v.optional(v.number()),
340
+ // From when the return may be booked: once the pass's last billing cycle began.
341
+ passReturnFrom: v.optional(v.number()),
310
342
  passReturnScheduledAt: v.optional(v.number()),
311
343
  passNoticedAt: v.optional(v.number()),
312
344
  passEndedAt: v.optional(v.number()),
345
+ // A reverse trial (LIFECYCLE): the pass a new workspace started on,
346
+ // with no purchaser (`status` 'trial'). `recipientEmail` holds its
347
+ // owner's address with plus tags and dots taken out, so an address
348
+ // starts one.
313
349
  reverseTrial: v.optional(v.boolean()),
350
+ // A referral reward (REF): the pass a referrer on the free plan got for
351
+ // free months, with no purchaser (`status` 'reward'). `rewardId` is the
352
+ // referral it came from; `recipientEmail` is empty.
353
+ rewardId: v.optional(v.string()),
314
354
  })
315
355
 
356
+ /** A gift as the component's reads return it: its id, without the claim and cancel holds or the reward it came from. */
357
+ export const vGift = vGiftRow.omit('claimingUntil', 'cancelingUntil', 'passReturnFrom', 'rewardId').extend({ id: v.string() })
358
+
316
359
  /** A save offer's terms, as the cancel flow made it (LIFECYCLE). */
317
360
  export const vSaveOfferTerms = v.object({
318
361
  kind: v.union(v.literal('pause'), v.literal('downgrade'), v.literal('discount')),
@@ -323,6 +366,22 @@ export const vSaveOfferTerms = v.object({
323
366
  discount: v.optional(v.string()),
324
367
  })
325
368
 
369
+ /** A renewing checkout's consent proof, as the `billingRenewalConsents` table stores it. */
370
+ export const vRenewalConsent = v.object({
371
+ checkoutId: v.string(),
372
+ entityId: v.string(),
373
+ userId: v.optional(v.string()),
374
+ productId: v.string(),
375
+ amount: v.number(),
376
+ currency: v.string(),
377
+ interval: v.string(),
378
+ intervalCount: v.number(),
379
+ termsVersion: v.optional(v.string()),
380
+ createdAt: v.number(),
381
+ subscriptionId: v.optional(v.string()),
382
+ consentedAt: v.optional(v.number()),
383
+ })
384
+
326
385
  export const billingTables = {
327
386
  billingEntitlements: defineTable({
328
387
  // The billing entity id — the workspace id (billTo: 'workspace', the
@@ -411,89 +470,7 @@ export const billingTables = {
411
470
  })
412
471
  .index('entityId', ['entityId'])
413
472
  .index('at', ['at']),
414
- billingGifts: defineTable({
415
- // Stored lowercased; matched case-insensitively against the claimant's email.
416
- recipientEmail: v.string(),
417
- purchaserUserId: v.string(),
418
- purchaserEmail: v.optional(v.string()),
419
- purchaserName: v.optional(v.string()),
420
- // The credit pack the recipient receives: its provider product.
421
- productIds: v.array(v.string()),
422
- // Plain text, shown only inside the app once the recipient signs in.
423
- message: v.optional(v.string()),
424
- // 'pending' (checkout created) → 'paid' (the purchase order is paid and
425
- // its claim discount minted) → 'claimed' (the recipient's $0 order is
426
- // paid), or 'refunded' (the purchase was refunded before the claim).
427
- status: v.string(),
428
- // Before 0.2: the provider customer keyed by the recipient's email,
429
- // which the purchase was billed to. Gifts are billed to the purchaser now.
430
- billingCustomerId: v.optional(v.string()),
431
- // The purchase order, paid by the purchaser's own billing entity.
432
- billingOrderId: v.optional(v.string()),
433
- purchaserEntityId: v.optional(v.string()),
434
- // The pack's catalog key, and the private gift product the purchaser bought.
435
- pack: v.optional(v.string()),
436
- giftProductId: v.optional(v.string()),
437
- // What the purchase order charged, in the currency's smallest unit.
438
- amount: v.optional(v.number()),
439
- currency: v.optional(v.string()),
440
- // The single-use 100% discount the recipient claims the pack with.
441
- discountId: v.optional(v.string()),
442
- // The claim checkout in flight: who opened it, for which entity. A plan
443
- // pass's claim holds the gift until `claimingUntil`, while it switches the
444
- // workspace at the provider.
445
- claimingEntityId: v.optional(v.string()),
446
- claimingUserId: v.optional(v.string()),
447
- claimingUntil: v.optional(v.number()),
448
- // The purchaser's cancellation in flight, until then: no claim starts meanwhile.
449
- cancelingUntil: v.optional(v.number()),
450
- claimOrderId: v.optional(v.string()),
451
- claimedByUserId: v.optional(v.string()),
452
- // The entity the credits landed on: workspace id or user id.
453
- claimedEntityId: v.optional(v.string()),
454
- createdAt: v.number(),
455
- paidAt: v.optional(v.number()),
456
- notifiedAt: v.optional(v.number()),
457
- claimedAt: v.optional(v.number()),
458
- refundedAt: v.optional(v.number()),
459
- // A plan pass (the gift is a plan for `months` months, not a pack): the
460
- // plan's catalog key and the length the purchaser paid for.
461
- plan: v.optional(v.string()),
462
- months: v.optional(v.number()),
463
- // When the notice goes out: set when the purchase is paid (the moment
464
- // it is paid, or the date the purchaser chose). The gift is the
465
- // recipient's to see and claim once `deliveredAt` is stamped; a row
466
- // with neither is a gift paid before delivery dates, delivered when paid.
467
- deliverAt: v.optional(v.number()),
468
- deliveredAt: v.optional(v.number()),
469
- // The last notice sent (the first, a reminder or a resend), and how many.
470
- noticedAt: v.optional(v.number()),
471
- noticeCount: v.optional(v.number()),
472
- // How many times the purchaser changed the address: each address's notices carry their own idempotency keys.
473
- recipientChanges: v.optional(v.number()),
474
- // The one reminder, a week after delivery.
475
- remindedAt: v.optional(v.number()),
476
- // A pass once claimed: the free subscription it switched, when it began
477
- // and ends (the package keeps the end date), the scheduled return to the
478
- // free plan, the ending notice and the end itself.
479
- passSubscriptionId: v.optional(v.string()),
480
- passStartedAt: v.optional(v.number()),
481
- passEndsAt: v.optional(v.number()),
482
- // From when the return may be booked: once the pass's last billing cycle began.
483
- passReturnFrom: v.optional(v.number()),
484
- passReturnScheduledAt: v.optional(v.number()),
485
- passNoticedAt: v.optional(v.number()),
486
- passEndedAt: v.optional(v.number()),
487
- // A reverse trial (LIFECYCLE): the pass a new workspace started on,
488
- // with no purchaser (`status` 'trial'). `recipientEmail` holds its
489
- // owner's address with plus tags and dots taken out, so an address
490
- // starts one.
491
- reverseTrial: v.optional(v.boolean()),
492
- // A referral reward (REF): the pass a referrer on the free plan got for
493
- // free months, with no purchaser (`status` 'reward'). `rewardId` is the
494
- // referral it came from; `recipientEmail` is empty.
495
- rewardId: v.optional(v.string()),
496
- })
473
+ billingGifts: defineTable(vGiftRow)
497
474
  .index('recipientEmail', ['recipientEmail'])
498
475
  .index('recipientEmail_status', ['recipientEmail', 'status'])
499
476
  .index('recipientEmail_createdAt', ['recipientEmail', 'createdAt'])
@@ -540,20 +517,7 @@ export const billingTables = {
540
517
  // (what it showed: the plan, the price and its interval, the terms
541
518
  // version, who), confirmed when the subscription it started arrives, and
542
519
  // deleted three years after. An unconfirmed row goes after two days.
543
- billingRenewalConsents: defineTable({
544
- checkoutId: v.string(),
545
- entityId: v.string(),
546
- userId: v.optional(v.string()),
547
- productId: v.string(),
548
- amount: v.number(),
549
- currency: v.string(),
550
- interval: v.string(),
551
- intervalCount: v.number(),
552
- termsVersion: v.optional(v.string()),
553
- createdAt: v.number(),
554
- subscriptionId: v.optional(v.string()),
555
- consentedAt: v.optional(v.number()),
556
- })
520
+ billingRenewalConsents: defineTable(vRenewalConsent)
557
521
  .index('checkoutId', ['checkoutId'])
558
522
  .index('entityId', ['entityId'])
559
523
  .index('userId', ['userId'])
@@ -584,6 +548,44 @@ export const billingTables = {
584
548
  .index('at', ['at']),
585
549
  }
586
550
 
551
+ /** A metered stream's request, as the `aiRequests` table stores it. */
552
+ export const vAiRequest = v.object({
553
+ streamId: v.string(),
554
+ /** Which `ai.stream({ name })` definition drives this request. */
555
+ name: v.string(),
556
+ /** The billing entity (workspace/user) the credits reserve against. */
557
+ entityId: v.string(),
558
+ /** The signed-in caller (for member attribution inside workspaces). */
559
+ userId: v.string(),
560
+ /** JSON-encoded handler args. */
561
+ args: v.string(),
562
+ meterId: v.optional(v.string()),
563
+ cost: v.number(),
564
+ externalId: v.string(),
565
+ status: v.union(v.literal('reserved'), v.literal('streaming'), v.literal('settled'), v.literal('released')),
566
+ createdAt: v.number(),
567
+ })
568
+
569
+ /** A knowledge document, as the `aiDocuments` table stores it. */
570
+ export const vAiDocument = v.object({
571
+ /** The knowledge store: its embedding model and dimension. */
572
+ store: v.string(),
573
+ /** The namespace: the billing entity whose members find it, or `app`. */
574
+ owner: v.string(),
575
+ /** The member who added it; empty for the app's own. */
576
+ addedBy: v.string(),
577
+ title: v.string(),
578
+ key: v.optional(v.string()),
579
+ status: v.union(v.literal('pending'), v.literal('ready'), v.literal('failed')),
580
+ entryId: v.optional(v.string()),
581
+ characters: v.number(),
582
+ createdAt: v.number(),
583
+ remove: v.string(),
584
+ read: v.string(),
585
+ namespaces: v.optional(v.string()),
586
+ removeNamespace: v.optional(v.string()),
587
+ })
588
+
587
589
  /**
588
590
  * Metered-stream request plumbing for `setupAi().stream` — the HTTP stream
589
591
  * endpoint can't carry Convex args, so `start` records the request (args,
@@ -595,22 +597,7 @@ export const billingTables = {
595
597
  * prune.
596
598
  */
597
599
  export const aiTables = {
598
- aiRequests: defineTable({
599
- streamId: v.string(),
600
- /** Which `ai.stream({ name })` definition drives this request. */
601
- name: v.string(),
602
- /** The billing entity (workspace/user) the credits reserve against. */
603
- entityId: v.string(),
604
- /** The signed-in caller (for member attribution inside workspaces). */
605
- userId: v.string(),
606
- /** JSON-encoded handler args. */
607
- args: v.string(),
608
- meterId: v.optional(v.string()),
609
- cost: v.number(),
610
- externalId: v.string(),
611
- status: v.union(v.literal('reserved'), v.literal('streaming'), v.literal('settled'), v.literal('released')),
612
- createdAt: v.number(),
613
- })
600
+ aiRequests: defineTable(vAiRequest)
614
601
  .index('streamId', ['streamId'])
615
602
  // Maintenance: finished requests past their window.
616
603
  .index('status_createdAt', ['status', 'createdAt'])
@@ -649,24 +636,7 @@ export const aiTables = {
649
636
  * `namespaces` and `removeNamespace` find its owner's namespace there
650
637
  * and delete it, passages and all, when the owner goes.
651
638
  */
652
- aiDocuments: defineTable({
653
- /** The knowledge store: its embedding model and dimension. */
654
- store: v.string(),
655
- /** The namespace: the billing entity whose members find it, or `app`. */
656
- owner: v.string(),
657
- /** The member who added it; empty for the app's own. */
658
- addedBy: v.string(),
659
- title: v.string(),
660
- key: v.optional(v.string()),
661
- status: v.union(v.literal('pending'), v.literal('ready'), v.literal('failed')),
662
- entryId: v.optional(v.string()),
663
- characters: v.number(),
664
- createdAt: v.number(),
665
- remove: v.string(),
666
- read: v.string(),
667
- namespaces: v.optional(v.string()),
668
- removeNamespace: v.optional(v.string()),
669
- })
639
+ aiDocuments: defineTable(vAiDocument)
670
640
  .index('store_owner_createdAt', ['store', 'owner', 'createdAt'])
671
641
  .index('store_owner_key', ['store', 'owner', 'key'])
672
642
  .index('owner', ['owner'])
@@ -737,6 +707,17 @@ export const aiTables = {
737
707
  .index('by_day_and_shard', ['day', 'shard']),
738
708
  }
739
709
 
710
+ /** How a webhook delivery ended, as the delivery log records it. */
711
+ export const vDeliveryOutcome = v.union(
712
+ v.literal('ok'),
713
+ v.literal('invalid_signature'),
714
+ v.literal('unknown_type'),
715
+ v.literal('handler_error'),
716
+ v.literal('duplicate'),
717
+ v.literal('oversized'),
718
+ v.literal('missing_secret'),
719
+ )
720
+
740
721
  /**
741
722
  * The webhook delivery log (see `webhooks.ts`) — powers redelivery dedupe and
742
723
  * the DevTools Webhooks page, never a source of truth. A delivery whose
@@ -752,15 +733,7 @@ export const webhookTables = {
752
733
  type: v.optional(v.string()),
753
734
  // The tallied outcomes stay in the union for rows written before they
754
735
  // were tallied; the trim ages them out with the rest.
755
- outcome: v.union(
756
- v.literal('ok'),
757
- v.literal('invalid_signature'),
758
- v.literal('unknown_type'),
759
- v.literal('handler_error'),
760
- v.literal('duplicate'),
761
- v.literal('oversized'),
762
- v.literal('missing_secret'),
763
- ),
736
+ outcome: vDeliveryOutcome,
764
737
  note: v.optional(v.string()),
765
738
  receivedAt: v.number(),
766
739
  /** When an administrator last asked the provider to send this delivery again (`replayWebhookDelivery`). */
@@ -1202,6 +1175,12 @@ export const storageTables = {
1202
1175
  .index('sharedBy', ['sharedBy']),
1203
1176
  }
1204
1177
 
1178
+ /** What a report decision did to the content. */
1179
+ export const vDecisionAction = v.union(v.literal('hidden'), v.literal('dismissed'))
1180
+
1181
+ /** What a report decision rests on: the law, or the app's terms. */
1182
+ export const vDecisionGround = v.union(v.literal('illegal'), v.literal('terms'))
1183
+
1205
1184
  /** Why someone reported content: the one-click reasons, and the notice form's legal ones. */
1206
1185
  export const vReportReason = v.union(
1207
1186
  v.literal('abuse'),
@@ -1289,11 +1268,11 @@ export const reportTables = {
1289
1268
  subject: v.optional(v.id('reportSubjects')),
1290
1269
  /** The notice decided, for one the app could not place. */
1291
1270
  notice: v.optional(v.id('reports')),
1292
- action: v.union(v.literal('hidden'), v.literal('dismissed')),
1271
+ action: vDecisionAction,
1293
1272
  /** The facts and the term or law it rests on, as the administrator wrote them. */
1294
1273
  reason: v.string(),
1295
1274
  /** Whether the content broke the law or the app's terms. */
1296
- ground: v.union(v.literal('illegal'), v.literal('terms')),
1275
+ ground: vDecisionGround,
1297
1276
  /** The administrator who decided. */
1298
1277
  by: v.string(),
1299
1278
  at: v.number(),
@@ -1498,6 +1477,24 @@ export const monitoringTables = {
1498
1477
  .index('by_at', ['at']),
1499
1478
  }
1500
1479
 
1480
+ /** A consent decision, as the `consents` table stores it. */
1481
+ export const vConsent = v.object({
1482
+ userId: v.optional(v.string()),
1483
+ /** SHA-256 of the lower-cased address, for a decision given before the account existed. */
1484
+ emailHash: v.optional(v.string()),
1485
+ kind: v.string(),
1486
+ version: v.string(),
1487
+ /** `true` a grant, `false` a withdrawal. */
1488
+ granted: v.boolean(),
1489
+ at: v.number(),
1490
+ /** Where it came from: `sign-up`, `prompt`, `settings`, `waitlist` or `topic`. */
1491
+ source: v.string(),
1492
+ /** The words the person agreed to, when the form showed its own (the launch-news box). */
1493
+ text: v.optional(v.string()),
1494
+ /** What the decision came with: `checkout:<id>` for a topic's soft opt-in at checkout. */
1495
+ reference: v.optional(v.string()),
1496
+ })
1497
+
1501
1498
  /**
1502
1499
  * The consent ledger (see `consents.ts`): one row per decision, a grant or a
1503
1500
  * withdrawal, of one kind at one version, never overwritten, so the history
@@ -1506,22 +1503,7 @@ export const monitoringTables = {
1506
1503
  * signs up.
1507
1504
  */
1508
1505
  export const consentTables = {
1509
- consents: defineTable({
1510
- userId: v.optional(v.string()),
1511
- /** SHA-256 of the lower-cased address, for a decision given before the account existed. */
1512
- emailHash: v.optional(v.string()),
1513
- kind: v.string(),
1514
- version: v.string(),
1515
- /** `true` a grant, `false` a withdrawal. */
1516
- granted: v.boolean(),
1517
- at: v.number(),
1518
- /** Where it came from: `sign-up`, `prompt`, `settings`, `waitlist` or `topic`. */
1519
- source: v.string(),
1520
- /** The words the person agreed to, when the form showed its own (the launch-news box). */
1521
- text: v.optional(v.string()),
1522
- /** What the decision came with: `checkout:<id>` for a topic's soft opt-in at checkout. */
1523
- reference: v.optional(v.string()),
1524
- })
1506
+ consents: defineTable(vConsent)
1525
1507
  .index('userId_kind_at', ['userId', 'kind', 'at'])
1526
1508
  .index('userId_at', ['userId', 'at'])
1527
1509
  .index('emailHash_at', ['emailHash', 'at']),