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
@@ -42,7 +42,7 @@ core skill, `nuxt-backend`, lists every public name in its own `references/api.m
42
42
  | `setupReferrals()` | Set the referral program up in its own backend file (`backend/referrals.ts`). |
43
43
  | `setupBilling()` | Configure billing for subscriptions, discounts, prepaid credits, and gift purchases — linked to your auth users and cached reactively inside the `backend` component (so consumers add nothing to their own schema). |
44
44
 
45
- Types: `BillingRateLimiter`, `DiscountInput`, `ProrationBehavior`, `ClientProrationBehavior`, `CancellationReason`, `RefundReason`, `SubscriptionTarget`, `UpdateSubscriptionOptions`, `CancelSubscriptionOptions`, `PauseSubscriptionOptions`, `CurrentSubscriptions`, `OrdersOptions`, `BillingOrder`, `BillingPage`, `UsageHistoryOptions`, `UsageEvent`, `RefundOrderOptions`, `RefundRecord`, `DiscountListOptions`, `BillingDiscounts`, `ApplyDiscountOptions`, `CheckoutPrefill`, `CampaignAttribution`, `CheckoutTrial`, `CheckoutOptions`, `ServerCheckoutOptions`, `FeatureCheckOptions`, `BenefitKind`, `EntitlementBenefit`, `EntitlementMeter`, `CustomerEntitlements`, `CreditMeterConfig`, `BillingCatalogIds`, `CatalogPassIds`, `BillingCatalogDiscount`, `SpendCreditsEvent`, `SpendReservation`, `RefundCreditsEvent`, `CostReport`, `GiftRecord`, `GiftTask`, `PricedCredits`, `PricedTrial`, `PricedPlanPrice`, `PricedPlan`, `PricedPack`, `PricedOffer`, `PricedPromotion`, `Pricing`, `QuotaUsage`, `BillingWebhookEventHandlers`, `SaveOfferTerms`, `BillingComponents`, `BillingEmail`, `BillingEntity`, `BillingAccessRule`, `BillingEntityCtx`, `EntityProfile`, `SetupBillingConfig`, `AccountBillingErasure`, `AccountBillingErasureInput`, `AccountBillingExport`, `AccountBillingRecord`, `Billing`, `BillingAudit`, `BillingLifecycle`, `CancelOutcome`, `BillingConsole`, `SaveOffer`, `SaveOfferRule`, `WithdrawalPeriod`, `MeterUsage`, `RevenueCancellations`, `RevenueInterval`, `RevenueMetric`, `RevenueOptions`, `RevenuePeriod`, `RevenueReport`, `RevenueValues`, `BillingCatalog`, `CatalogCreditGrant`, `CatalogCurrencyPrices`, `CatalogDiscount`, `CatalogDiscountDuration`, `CatalogDiscountProducts`, `CatalogDiscountTerms`, `CatalogFeature`, `CatalogInterval`, `CatalogMeter`, `CatalogPack`, `CatalogPackPrices`, `CatalogPlan`, `CatalogPlanCreditGrant`, `CatalogPlanGift`, `CatalogPlanPrices`, `CatalogQuota`, `ClaimRefusal`, `DueReferral`, `ReferralCodeView`, `ReferralComponents`, `ReferralRefs`, `ReferralConsole`, `ReferralConsoleRow`, `ReferralConsoleRows`, `ReferralEntry`, `ReferralPreview`, `ReferralProgram`, `Referrals`, `ReferralsApi`, `ReferralsView`, `ReferredOffer`, `ReferrerOffer`, `SetupReferralsOptions`, `StoredTerms`, `ReferralCaps`, `ReferralRewards`, `ReferralState`, `ReferralTerms`, `ReferredReward`, `ReferrerReward`.
45
+ Types: `BillingRateLimiter`, `DiscountInput`, `ProrationBehavior`, `ClientProrationBehavior`, `CancellationReason`, `RefundReason`, `SubscriptionTarget`, `UpdateSubscriptionOptions`, `CancelSubscriptionOptions`, `PauseSubscriptionOptions`, `CurrentSubscriptions`, `OrdersOptions`, `BillingOrder`, `BillingPage`, `UsageHistoryOptions`, `UsageEvent`, `RefundOrderOptions`, `RefundRecord`, `DiscountListOptions`, `BillingDiscounts`, `ApplyDiscountOptions`, `CheckoutPrefill`, `CampaignAttribution`, `CheckoutTrial`, `CheckoutOptions`, `ServerCheckoutOptions`, `FeatureCheckOptions`, `BenefitKind`, `EntitlementBenefit`, `EntitlementMeter`, `CustomerEntitlements`, `CreditMeterConfig`, `BillingCatalogIds`, `CatalogPassIds`, `BillingCatalogDiscount`, `SpendCreditsEvent`, `SpendReservation`, `RefundCreditsEvent`, `CostReport`, `GiftRecord`, `GiftTask`, `PricedCredits`, `PricedTrial`, `PricedPlanPrice`, `PricedPlan`, `PricedPack`, `PricedOffer`, `PricedPromotion`, `Pricing`, `QuotaUsage`, `BillingWebhookEventHandlers`, `SaveOfferTerms`, `BillingComponents`, `BillingEmail`, `BillingEntity`, `BillingAccessRule`, `BillingEntityCtx`, `EntityProfile`, `SetupBillingConfig`, `AccountBillingErasure`, `AccountBillingErasureInput`, `AccountBillingExport`, `AccountBillingRecord`, `Billing`, `BillingAudit`, `BillingLifecycle`, `CancelFlowState`, `CancelOutcome`, `BillingConsole`, `SaveOffer`, `SaveOfferRule`, `WithdrawalPeriod`, `MeterUsage`, `RevenueCancellations`, `RevenueInterval`, `RevenueMetric`, `RevenueOptions`, `RevenuePeriod`, `RevenueReport`, `RevenueValues`, `BillingCatalog`, `CatalogCreditGrant`, `CatalogCurrencyPrices`, `CatalogDiscount`, `CatalogDiscountDuration`, `CatalogDiscountProducts`, `CatalogDiscountTerms`, `CatalogFeature`, `CatalogInterval`, `CatalogMeter`, `CatalogPack`, `CatalogPackPrices`, `CatalogPlan`, `CatalogPlanCreditGrant`, `CatalogPlanGift`, `CatalogPlanPrices`, `CatalogQuota`, `MeterUnit`, `ClaimRefusal`, `DueReferral`, `ReferralCodeView`, `ReferralComponents`, `ReferralRefs`, `ReferralConsole`, `ReferralConsoleRow`, `ReferralConsoleRows`, `ReferralEntry`, `ReferralPreview`, `ReferralProgram`, `Referrals`, `ReferralsApi`, `ReferralsView`, `ReferredOffer`, `ReferrerOffer`, `SetupReferralsOptions`, `StoredTerms`, `ReferralCaps`, `ReferralRewards`, `ReferralState`, `ReferralTerms`, `ReferredReward`, `ReferrerReward`.
46
46
 
47
47
  ## CLI
48
48
 
@@ -60,6 +60,15 @@ Push backend/billing.catalog.ts — meters, custom fields, feature/credit benefi
60
60
 
61
61
  `--json`: { environment, dryRun, deployment, log: [{ action, kind, key, id?, note? }], generated, webhook: { url, action: "created" | "exists" | "would-create" | "skipped", secret: "stored" | "kept" | "not-stored" | "none", note? }, products: { status: "synced" | "failed" | "skipped", note? } }.
62
62
 
63
+ ### `npx nuxt-backend billing reset`
64
+
65
+ Start the dev deployment's billing over in the organization BILLING_ACCESS_TOKEN names, after the token moved to another one (a new sandbox): sync the catalog, clear the billing provider component's customers and subscriptions and the entitlement cache, and put every billing entity back on the free plan. Dev deployments only.
66
+
67
+ - `--cwd`: Project directory
68
+ - `--json`: Print the outcome as one JSON document; progress goes to stderr
69
+
70
+ `--json`: { sync: <billing sync --json>, cleared: [{ component, table, status: "cleared" | "failed" | "skipped", note? }], freePlan: { status: "queued" | "skipped" | "failed", note? } }.
71
+
63
72
  ## Doctor findings
64
73
 
65
74
  `npx nuxt-backend doctor --json` reports these ids, each with a `docsUrl` that explains it.
@@ -75,6 +84,7 @@ Push backend/billing.catalog.ts — meters, custom fields, feature/credit benefi
75
84
  | `billing-webhook-events` | billing | Billing webhook events |
76
85
  | `billing-meter-usage` | billing | Billing meters |
77
86
  | `billing-organization` | billing | Billing organization |
87
+ | `billing-customer-mapping` | billing | Customer mappings |
78
88
  | `billing-multiple-subscriptions` | billing | Multiple subscriptions |
79
89
  | `billing-proration` | billing | Plan change proration |
80
90
  | `billing-benefit-grace` | billing | Benefit revocation |
@@ -101,4 +111,4 @@ Push backend/billing.catalog.ts — meters, custom fields, feature/credit benefi
101
111
 
102
112
  The composables call these functions by name; keep them exported from the scaffolded files.
103
113
 
104
- - `backend/billing.ts`: `generateCheckoutLink`, `generateCustomerPortalUrl`, `getConfiguredProducts`, `getPricing`, `listAllSubscriptions`, `giftCheckout`, `getCurrentSubscription`, `getFeatures`, `getBillingAccess`, `getCredits`, `syncEntitlements`, `syncProducts`, `startFreePlan`, `getReceivedGifts`, `claimGift`, `getSentGifts`, `resendGift`, `changeGiftRecipient`, `rescheduleGift`, `cancelGift`, `runGiftSweep`, `updateSubscription`, `cancelSubscription`, `acceptSaveOffer`, `getWithdrawal`, `withdraw`, `uncancelSubscription`, `cancelPendingChange`, `pauseSubscription`, `resumeSubscription`, `getOrders`, `getInvoiceUrl`, `getUsageHistory`, `refundOrder`
114
+ - `backend/billing.ts`: `generateCheckoutLink`, `generateCustomerPortalUrl`, `getConfiguredProducts`, `getPricing`, `listAllSubscriptions`, `giftCheckout`, `getCurrentSubscription`, `getFeatures`, `getBillingAccess`, `getCredits`, `syncEntitlements`, `syncProducts`, `startFreePlan`, `getReceivedGifts`, `claimGift`, `getSentGifts`, `resendGift`, `changeGiftRecipient`, `rescheduleGift`, `cancelGift`, `runGiftSweep`, `updateSubscription`, `cancelSubscription`, `getCancelFlow`, `acceptSaveOffer`, `getWithdrawal`, `withdraw`, `uncancelSubscription`, `cancelPendingChange`, `pauseSubscription`, `resumeSubscription`, `getOrders`, `getInvoiceUrl`, `getUsageHistory`, `refundOrder`
@@ -16,7 +16,10 @@ this one covers reading, writing and background work.
16
16
  storage. The base module's brand-named composables and components are not auto-imported in a
17
17
  nuxt-backend app: use these neutral names.
18
18
  - For user-scoped functions, use the builders in `backend/functions.ts` (`authed`, `workspace`,
19
- `admin`; the `nuxt-backend-auth` skill).
19
+ `admin`; the `nuxt-backend-auth` skill). Read them with `'skip'` until `useAuth().isReady`:
20
+ `useQuery(api.strips.list, () => (isReady.value ? {} : 'skip'))`. `isSignedIn` turns `true` on
21
+ a page load a moment before the connection holds the token, and a read asked then is refused
22
+ `unauthenticated`.
20
23
  - `useConnectionState()` is the live connection; `<ConnectionStatus>` says a drop or going offline
21
24
  in words, and already closes every ready-made page. Do not build a retry button: the client
22
25
  reconnects, resends waiting mutations, and asks before a tab with unsent ones closes.
@@ -17,6 +17,10 @@ branding and language, delivery and the dev inbox.
17
17
  - Never expose a public function that takes a recipient: the scaffolded `send` is an
18
18
  `internalAction`. Call it from server code with an address you trust, or use `admin.action`
19
19
  (like `sendAsAdmin`) when a person types the address.
20
+ - Notification email and push follow `setupEmail({ caps })` (weekly cap, quiet hours). A kind of the
21
+ app's own that people wait for (an order ready, a job failed) takes `transactional: true` in
22
+ `setupNotifications({ notify })`: it goes at once and is not counted, still under the person's
23
+ channel choice. The package's account kinds (passkeys, address, new device) are transactional already.
20
24
  - Sign-in codes go out through `email.sendSecret`: no email record is kept, `sendTemplate`
21
25
  resolves with `null` for them, and they have no status. Deleting an account sends no email.
22
26
 
@@ -53,7 +53,7 @@ Types: `EmailBlock`, `DeletionCanceledEmailData`, `DeletionScheduledEmailData`,
53
53
  |---|---|
54
54
  | `setupNotifications()` | The in-app inbox: what the backend recorded about a person, live, with the unread count and marking read, and the `notify` option that turns your own events into notifications. |
55
55
 
56
- Types: `ChannelGate`, `ChannelHandler`, `Delivery`, `NotificationAudience`, `NotificationChannel`, `NotificationKind`, `NotificationDestination`, `NotificationPlan`, `NotifyEvent`, `NotifyKind`, `NotifyOptions`, `NotificationParty`, `NotificationEntry`, `NotificationsPage`, `UnreadCount`, `MarkedRead`, `NotificationKindChoice`, `PushConfig`, `ScheduledDelivery`, `NotificationsApi`, `Notifications`, `NotificationsWriteCtx`, `ForgottenNotifications`, `NotificationsEmail`, `SetupNotificationsOptions`, `NotificationsComponents`.
56
+ Types: `ChannelGate`, `ChannelHandler`, `Delivery`, `NotificationAudience`, `NotificationChannel`, `NotificationEntity`, `NotificationFeature`, `NotificationKind`, `NotificationDestination`, `NotificationPlan`, `NotificationType`, `NotifyEvent`, `NotifyKind`, `NotifyOptions`, `NotificationParty`, `NotificationEntry`, `NotificationsPage`, `UnreadCount`, `MarkedRead`, `NotificationKindChoice`, `PushConfig`, `ScheduledDelivery`, `NotificationsApi`, `Notifications`, `NotificationsWriteCtx`, `ForgottenNotifications`, `NotificationsEmail`, `SetupNotificationsOptions`, `NotificationsComponents`.
57
57
 
58
58
  ## CLI
59
59
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: nuxt-backend-ui
3
- description: The packaged UI of a Nuxt app on nuxt-backend and how to customize it, in order of reach. The --bk-* tokens on :root in @layer nuxt-backend and the data-* hooks, every word as a label in appConfig.backend, translation with @nuxtjs/i18n, slots, swapping a part by its registered name, headless composables with bind and #backend/a11y, npx nuxt-backend eject, css false and pages.<key> false. Use when restyling, rewording, translating or rearranging the packaged pages and components (sign-in, pricing, settings, profile, security, admin), or replacing one with your own. Read the nuxt-backend core skill first.
3
+ description: The packaged UI of a Nuxt app on nuxt-backend and how to customize it, in order of reach. The --bk-* tokens on :root in @layer nuxt-backend-tokens and the data-* hooks, every word as a label in appConfig.backend, translation with @nuxtjs/i18n, slots, swapping a part by its registered name, headless composables with bind and #backend/a11y, npx nuxt-backend eject, css false and pages.<key> false. Use when restyling, rewording, translating or rearranging the packaged pages and components (sign-in, pricing, settings, profile, security, admin), or replacing one with your own. Read the nuxt-backend core skill first.
4
4
  ---
5
5
 
6
6
  # nuxt-backend: UI and customization
@@ -13,9 +13,10 @@ bridge: put any kit's components in slots, parts or your own markup.
13
13
 
14
14
  ## Customizing, in order of reach
15
15
 
16
- 1. **Tokens**: the `--bk-*` custom properties sit on `:root` inside `@layer nuxt-backend`, so
17
- an override on `:root` in any app stylesheet re-themes every component, with no specificity
18
- to match. A family root (`[data-pricing='table']`) scopes a change; state is `data-state`,
16
+ 1. **Tokens**: the `--bk-*` custom properties sit on `:root` inside `@layer nuxt-backend-tokens`,
17
+ the lowest layer, so an override on `:root` in any app stylesheet, in any layer or none,
18
+ re-themes every component, with no specificity to match. Restyle elements outside layers (or
19
+ in a layer after `nuxt-backend`): `theme`, `base` and `reset` sit below the package's rules. A family root (`[data-pricing='table']`) scopes a change; state is `data-state`,
19
20
  `data-disabled`, `data-invalid`, `data-loading`. Declare `color-scheme` yourself: the
20
21
  tokens are `light-dark()` pairs. Put resets in `@layer reset`, never unlayered.
21
22
  2. **Labels**: `appConfig.backend` holds the brand, the plan catalog copy and the labels:
@@ -67,7 +68,7 @@ https://nuxt-backend.dev/docs/build/ui/accessibility.
67
68
  - [Build the app shell](https://nuxt-backend.dev/docs/build/ui/app-shell): Wrap your signed-in pages in `<AppShell>`: a header with your brand, the workspace switcher, the notification bell and the account menu, the app-wide notices, and your page in the main landmark.
68
69
  - [Show parts of a page to the right people](https://nuxt-backend.dev/docs/build/ui/gate): Show a region only to someone signed in, with a role, in a workspace, on a plan with a feature, or with room left on a quota, with `<Gate>` and its fallback slot. One component replaces the four boundaries.
69
70
  - [Show app-wide notices](https://nuxt-backend.dev/docs/build/ui/notices): Place `<BackendNotices>` once in your layout for every notice the backend raises: an administrator's visit, maintenance, a past-due payment, a scheduled account deletion, low credits, a gift to claim and announcements, each replaceable through a named slot.
70
- - [Restyle with tokens](https://nuxt-backend.dev/docs/build/ui/customize/tokens): Re-theme every packaged component with the --bk-* tokens on :root inside @layer nuxt-backend, scope a change to one family, follow light and dark, and style state through the data-* hooks.
71
+ - [Restyle with tokens](https://nuxt-backend.dev/docs/build/ui/customize/tokens): Re-theme every packaged component with the --bk-* tokens on :root inside @layer nuxt-backend-tokens, scope a change to one family, follow light and dark, and style state through the data-* hooks.
71
72
  - [Change copy and labels](https://nuxt-backend.dev/docs/build/ui/customize/labels): Set the plan catalog copy and the brand, and override any word a packaged component or page renders, from app config or per component. Reach for `useLabels()`.
72
73
  - [Translate the UI](https://nuxt-backend.dev/docs/build/ui/customize/translation): Translate every packaged page and component with @nuxtjs/i18n: backend.* messages per locale, placeholders and plurals, dates and money in the active locale, and localized page paths. Russian, German, Spanish and French come with the package. Reach for `useLabels()`.
73
74
  - [Customize with slots](https://nuxt-backend.dev/docs/build/ui/customize/slots): Keep a packaged component and replace only the regions you care about, with the state and actions it runs on, and set its props and listen to its events.
@@ -494,8 +494,3 @@ export const NO_PERSONAL_DATA: Readonly<Record<string, string>> = {
494
494
  experiments: 'Each experiment\'s variants, goal and guardrails as the code declared them, and when it started.',
495
495
  experimentKinds: 'The event kinds each experiment counts.',
496
496
  }
497
-
498
- /** The participants whose rows an erasure finds by the address alone: what it does for someone without an account. */
499
- export function emailKeyedSources(): AccountDataSourceKey[] {
500
- return (Object.keys(ACCOUNT_DATA_SOURCES) as AccountDataSourceKey[]).filter(key => (ACCOUNT_DATA_SOURCES[key].keyedBy as readonly ErasureKey[]).includes('email'))
501
- }
@@ -29,6 +29,22 @@ export interface CatalogCreditGrant {
29
29
  rollover?: boolean
30
30
  }
31
31
 
32
+ /**
33
+ * What a meter counts, as the packaged labels name it: its word for each
34
+ * plural category of the language (`Intl.PluralRules`), `one` and
35
+ * `other` at least — `{ one: 'page', other: 'pages' }`. A language with
36
+ * more forms names them too (`few` and `many` in Russian); a category it
37
+ * leaves out reads as `other`, and a heading as `other` with a capital.
38
+ */
39
+ export interface MeterUnit {
40
+ one: string
41
+ other: string
42
+ zero?: string
43
+ two?: string
44
+ few?: string
45
+ many?: string
46
+ }
47
+
32
48
  /** A usage meter, keyed by the event name spends use (`spendCredits({ meter })`). */
33
49
  export interface CatalogMeter {
34
50
  /**
@@ -41,6 +57,13 @@ export interface CatalogMeter {
41
57
  property?: string
42
58
  /** Event name the meter filters on. Defaults to the catalog key. */
43
59
  eventName?: string
60
+ /**
61
+ * The unit it counts in, for the packaged labels ("Buy pages", "120
62
+ * pages left."): `billing sync` writes it to the generated map, and the
63
+ * balance, pricing and usage reads carry it. Without it they say
64
+ * "credits", in every language the package speaks.
65
+ */
66
+ unit?: MeterUnit
44
67
  }
45
68
 
46
69
  /**
@@ -15,13 +15,14 @@ import type { Email } from '../integrations/email.js'
15
15
  import { normalizeLocale } from '../locale.js'
16
16
  import { auditDatabaseHooks, recordSignedUp } from './audit.js'
17
17
  import { checkNewDevice } from './devices.js'
18
+ import { clientAddressPlugin } from './client-address.js'
18
19
  import { assertCanSignIn, challengePlugin, disabledRoutes, makeRequestHooks, reauthenticatedWorkspace, reauthenticating } from './guards.js'
19
20
  import { authRefusal } from './refusals.js'
20
21
  import { pausedData } from '../pauses.js'
21
22
  import { type DatabaseHooks, mergeDatabaseHooks } from './hooks.js'
22
23
  import { ACCOUNT_FIELDS, administratorsOf, defaultAdmin, type DefaultAuthPlugin, defaultLastLoginMethod, defaultPasskey, SESSION_FIELDS, sessionSignInMethod } from './plugins.js'
23
24
  import { isAdministrator } from '../integrations/access.js'
24
- import { protectionEnv } from '../proof.js'
25
+ import { CLIENT_IP_HEADER, protectionEnv } from '../proof.js'
25
26
  import { resolveBackendPaths } from '../paths.js'
26
27
  import { type AuthRuntime, asMutationCtx, hookAdapter, readEnv } from './runtime.js'
27
28
  import { ensureActiveWorkspace, organizationOptions } from './workspaces.js'
@@ -453,6 +454,14 @@ export function buildAuthOptions<DM extends GenericDataModel = GenericDataModel>
453
454
  // instead. `authOptions.rateLimit: { enabled: true, storage: 'database' }`
454
455
  // still turns it on, with durable storage.
455
456
  rateLimit: { enabled: false, ...resolvedAuthOptions.rateLimit },
457
+ // The client's address: the one the app's server signed and the
458
+ // client-address plugin checked, else the one the platform wrote into
459
+ // `x-forwarded-for` (see clientAddressPlugin). An app's own
460
+ // `ipAddressHeaders` replace both.
461
+ advanced: {
462
+ ...resolvedAuthOptions.advanced,
463
+ ipAddress: { ipAddressHeaders: [CLIENT_IP_HEADER, 'x-forwarded-for'], ...resolvedAuthOptions.advanced?.ipAddress },
464
+ },
456
465
  // The package's hooks compose with consumer-supplied databaseHooks —
457
466
  // per model and operation, ours run first, theirs second (see
458
467
  // mergeDatabaseHooks) — so a consumer hook extends the packaged
@@ -461,6 +470,7 @@ export function buildAuthOptions<DM extends GenericDataModel = GenericDataModel>
461
470
  // The request guards (and any consumer before-hook after them).
462
471
  hooks,
463
472
  plugins: [
473
+ clientAddressPlugin(protection.proofSecret),
464
474
  convex({
465
475
  authConfig: resolvedAuthConfig,
466
476
  options: {
@@ -0,0 +1,37 @@
1
+ import type { BetterAuthPlugin } from 'better-auth'
2
+ import { CLIENT_ADDRESS_HEADER, CLIENT_IP_HEADER, deploymentAudience, readClientAddress } from '../proof.js'
3
+
4
+ /** The id of the plugin that hands Better Auth the client's address (no tables). */
5
+ export const CLIENT_ADDRESS_PLUGIN_ID = 'nuxt-backend-client-address'
6
+
7
+ /**
8
+ * Hand Better Auth the client's address behind the app's server. Requests
9
+ * that come through the app's auth proxy reach the deployment from the
10
+ * app's server, and the platform writes that server's address into
11
+ * `x-forwarded-for`: every visitor would share one address, and with it one
12
+ * bucket of each per-address limit. The app's server signs the address it
13
+ * received the request from into {@link CLIENT_ADDRESS_HEADER}, under the
14
+ * proof secret it shares with the deployment (`PROTECTION_PROOF_SECRET`).
15
+ *
16
+ * Before any route runs, a {@link CLIENT_IP_HEADER} a request arrived with
17
+ * is dropped, whoever sent it, and set again only from a signed address
18
+ * whose proof holds. Better Auth reads that header first and
19
+ * `x-forwarded-for` after it (`advanced.ipAddress.ipAddressHeaders`), so a
20
+ * request called on the deployment directly keeps the address the platform
21
+ * wrote, and one without a valid signature changes nothing.
22
+ */
23
+ export function clientAddressPlugin(secret: string | undefined): BetterAuthPlugin {
24
+ return {
25
+ id: CLIENT_ADDRESS_PLUGIN_ID,
26
+ onRequest: async (request) => {
27
+ const signed = request.headers.get(CLIENT_ADDRESS_HEADER)
28
+ if (signed === null && !request.headers.has(CLIENT_IP_HEADER)) return
29
+ const headers = new Headers(request.headers)
30
+ headers.delete(CLIENT_ADDRESS_HEADER)
31
+ headers.delete(CLIENT_IP_HEADER)
32
+ const address = secret ? await readClientAddress(secret, signed, deploymentAudience()) : null
33
+ if (address) headers.set(CLIENT_IP_HEADER, address)
34
+ return { request: new Request(request, { headers }) }
35
+ },
36
+ } satisfies BetterAuthPlugin
37
+ }
@@ -4439,6 +4439,18 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
4439
4439
  null,
4440
4440
  Name
4441
4441
  >;
4442
+ features: FunctionReference<
4443
+ "query",
4444
+ "internal",
4445
+ {},
4446
+ {
4447
+ gifts: boolean;
4448
+ passes: boolean;
4449
+ referrals: boolean;
4450
+ trialPasses: boolean;
4451
+ },
4452
+ Name
4453
+ >;
4442
4454
  forget: FunctionReference<
4443
4455
  "mutation",
4444
4456
  "internal",
@@ -794,6 +794,11 @@ export const cancelDeletion = mutation({
794
794
 
795
795
  // ── Export ────────────────────────────────────────────────────────────────
796
796
 
797
+ /** The account's exports made in the day its limit counts. */
798
+ function exportsToday(ctx: QueryCtx, userId: string, now: number) {
799
+ return ctx.db.query('accountExports').withIndex('userId_createdAt', q => q.eq('userId', userId).gt('createdAt', now - DAY_MS))
800
+ }
801
+
797
802
  /**
798
803
  * Count one export of the account's against its daily limit, before
799
804
  * anything is read: `rate_limited` (limit `accountExport`) once
@@ -805,7 +810,7 @@ export const startExport = mutation({
805
810
  returns: v.object({ exportId: v.id('accountExports'), createdAt: v.number(), expiresAt: v.number() }),
806
811
  handler: async (ctx, { userId }) => {
807
812
  const now = Date.now()
808
- const recent = await ctx.db.query('accountExports').withIndex('userId_createdAt', q => q.eq('userId', userId).gt('createdAt', now - DAY_MS)).take(ACCOUNT_EXPORTS_PER_DAY)
813
+ const recent = await exportsToday(ctx, userId, now).take(ACCOUNT_EXPORTS_PER_DAY)
809
814
  if (recent.length >= ACCOUNT_EXPORTS_PER_DAY) {
810
815
  const retryAfter = Math.max(0, recent[0]!.createdAt + DAY_MS - now)
811
816
  throw backendError('rate_limited', { limit: 'accountExport', retryAfter }, `[nuxt-backend] exportAccountData: ${ACCOUNT_EXPORTS_PER_DAY} exports a day; try again later.`)
@@ -1046,7 +1051,7 @@ export const exportStatus = query({
1046
1051
  }),
1047
1052
  handler: async (ctx, { userId }) => {
1048
1053
  const now = Date.now()
1049
- const recent = await ctx.db.query('accountExports').withIndex('userId_createdAt', q => q.eq('userId', userId).gt('createdAt', now - DAY_MS)).order('desc').take(ACCOUNT_EXPORTS_PER_DAY)
1054
+ const recent = await exportsToday(ctx, userId, now).order('desc').take(ACCOUNT_EXPORTS_PER_DAY)
1050
1055
  const remaining = Math.max(0, ACCOUNT_EXPORTS_PER_DAY - recent.length)
1051
1056
  for (const row of recent) {
1052
1057
  if (!row.storageId || row.expiresAt <= now) continue
@@ -5,6 +5,7 @@ import { createApi } from '@convex-dev/better-auth'
5
5
  import { convex } from '@convex-dev/better-auth/plugins'
6
6
  import type { RegisteredMutation, RegisteredQuery } from 'convex/server'
7
7
  import { ACCOUNT_FIELDS, PASSKEY_ONLY_PLUGIN, SESSION_FIELDS } from '../../client/plugins.js'
8
+ import { CLIENT_ADDRESS_PLUGIN_ID } from '../../client/client-address.js'
8
9
  import { SECRET_ROTATION_PLUGIN_ID } from '../../client/secret-rotation.js'
9
10
  import { authSchema as schema } from './schema.js'
10
11
 
@@ -13,7 +14,7 @@ import { authSchema as schema } from './schema.js'
13
14
  * component adapter. Mirrors upstream @convex-dev/better-auth component/adapter
14
15
  * pattern (see their auth-options.ts + adapter.ts) but limited to plugins we
15
16
  * enable by default (convex + emailOTP + passkey + lastLoginMethod + admin +
16
- * organization + passkey-only + the secret rotation) for minimal surface. ⚠ Keep this
17
+ * organization + passkey-only + the secret rotation + the client address) for minimal surface. ⚠ Keep this
17
18
  * plugin set aligned with the default set `buildAuthOptions` builds
18
19
  * (src/convex/client/better-auth-options.ts) —
19
20
  * a plugin enabled there but missing here leaves its tables out of the
@@ -39,6 +40,8 @@ const options: BetterAuthOptions = {
39
40
  { id: PASSKEY_ONLY_PLUGIN.id, schema: PASSKEY_ONLY_PLUGIN.schema },
40
41
  // The AUTH_SECRET rotation's cookie re-signing: no tables.
41
42
  { id: SECRET_ROTATION_PLUGIN_ID },
43
+ // The client's address behind the app's auth proxy: no tables.
44
+ { id: CLIENT_ADDRESS_PLUGIN_ID },
42
45
  ],
43
46
  }
44
47
 
@@ -3,6 +3,7 @@ import { type ObjectType, v } from 'convex/values'
3
3
  import type { Doc, Id } from './_generated/dataModel.js'
4
4
  import { internal } from './_generated/api.js'
5
5
  import { action, internalMutation, mutation, type MutationCtx, query, type QueryCtx } from './_generated/server.js'
6
+ import { vAiDocument, vAiRequest } from './schema.js'
6
7
  import { fileOwnerOf, fileSha256, keepGenerated } from './storage.js'
7
8
 
8
9
  /**
@@ -14,30 +15,8 @@ import { fileOwnerOf, fileSha256, keepGenerated } from './storage.js'
14
15
  * by browser clients (the `email.send` pattern).
15
16
  */
16
17
 
17
- const vRequest = v.object({
18
- streamId: v.string(),
19
- name: v.string(),
20
- entityId: v.string(),
21
- userId: v.string(),
22
- args: v.string(),
23
- meterId: v.optional(v.string()),
24
- cost: v.number(),
25
- externalId: v.string(),
26
- status: v.union(v.literal('reserved'), v.literal('streaming'), v.literal('settled'), v.literal('released')),
27
- createdAt: v.number(),
28
- })
29
-
30
18
  export const createRequest = mutation({
31
- args: {
32
- streamId: v.string(),
33
- name: v.string(),
34
- entityId: v.string(),
35
- userId: v.string(),
36
- args: v.string(),
37
- meterId: v.optional(v.string()),
38
- cost: v.number(),
39
- externalId: v.string(),
40
- },
19
+ args: vAiRequest.omit('status', 'createdAt'),
41
20
  returns: v.null(),
42
21
  handler: async (ctx, args) => {
43
22
  await ctx.db.insert('aiRequests', { ...args, status: 'reserved', createdAt: Date.now() })
@@ -47,7 +26,7 @@ export const createRequest = mutation({
47
26
 
48
27
  export const getByStream = query({
49
28
  args: { streamId: v.string() },
50
- returns: v.union(vRequest, v.null()),
29
+ returns: v.union(vAiRequest, v.null()),
51
30
  handler: async (ctx, { streamId }) => {
52
31
  const row = await requestOf(ctx, streamId)
53
32
  if (!row) return null
@@ -189,24 +168,7 @@ export const listThreads = query({
189
168
  /** Forget a thread's owner row (its messages go through the Agent component). */
190
169
  export const deleteThread = threadWrite(async (ctx, row) => ctx.db.delete('aiThreads', row._id))
191
170
 
192
- const vDocumentStatus = v.union(v.literal('pending'), v.literal('ready'), v.literal('failed'))
193
-
194
- const vDocumentRow = v.object({
195
- id: v.string(),
196
- store: v.string(),
197
- owner: v.string(),
198
- addedBy: v.string(),
199
- title: v.string(),
200
- key: v.optional(v.string()),
201
- status: vDocumentStatus,
202
- entryId: v.optional(v.string()),
203
- characters: v.number(),
204
- createdAt: v.number(),
205
- remove: v.string(),
206
- read: v.string(),
207
- namespaces: v.optional(v.string()),
208
- removeNamespace: v.optional(v.string()),
209
- })
171
+ const vDocumentRow = vAiDocument.extend({ id: v.string() })
210
172
 
211
173
  function documentView(row: { _id: string, _creationTime: number } & Record<string, unknown>) {
212
174
  const { _id, _creationTime, ...document } = row
@@ -215,7 +177,7 @@ function documentView(row: { _id: string, _creationTime: number } & Record<strin
215
177
 
216
178
  /** Record a document waiting for its embeddings, and return its id. */
217
179
  export const createDocument = mutation({
218
- args: { store: v.string(), owner: v.string(), addedBy: v.string(), title: v.string(), key: v.optional(v.string()), characters: v.number(), remove: v.string(), read: v.string(), namespaces: v.optional(v.string()), removeNamespace: v.optional(v.string()) },
180
+ args: vAiDocument.omit('status', 'entryId', 'createdAt'),
219
181
  returns: v.string(),
220
182
  handler: async (ctx, args) => ctx.db.insert('aiDocuments', { ...args, status: 'pending', createdAt: Date.now() }),
221
183
  })
@@ -310,6 +272,15 @@ const vImageRecord = {
310
272
  manifest: v.optional(v.string()),
311
273
  }
312
274
 
275
+ const vImageBytes = { bytes: v.bytes(), ...vImageRecord }
276
+
277
+ /** Store an image's bytes, and answer what its owner record is written with. */
278
+ async function storeBytes(storage: { store: (blob: Blob) => Promise<Id<'_storage'>> }, bytes: ArrayBuffer, record: ObjectType<typeof vImageRecord>) {
279
+ const contentType = record.contentType ?? 'application/octet-stream'
280
+ const storageId = await storage.store(new Blob([bytes], { type: contentType }))
281
+ return { ...record, contentType, storageId, size: bytes.byteLength, sha256: await fileSha256(bytes) }
282
+ }
283
+
313
284
  /**
314
285
  * Keep a generated image (`ctx.storeImage`) and record what made it: an
315
286
  * action, so the bytes go straight to the component's storage and only the
@@ -324,16 +295,15 @@ const vImageRecord = {
324
295
  * again. Answers the image's id in the component's storage.
325
296
  */
326
297
  export const storeGeneratedImage = action({
327
- args: { bytes: v.bytes(), ...vImageRecord },
298
+ args: vImageBytes,
328
299
  returns: v.id('_storage'),
329
300
  handler: async (ctx, { bytes, ...record }): Promise<Id<'_storage'>> => {
330
- const contentType = record.contentType ?? 'application/octet-stream'
331
- const storageId = await ctx.storage.store(new Blob([bytes], { type: contentType }))
301
+ const stored = await storeBytes(ctx.storage, bytes, record)
332
302
  try {
333
- return await ctx.runMutation(internal.ai.recordImage, { ...record, contentType, storageId, size: bytes.byteLength, sha256: await fileSha256(bytes) })
303
+ return await ctx.runMutation(internal.ai.recordImage, stored)
334
304
  }
335
305
  catch (error) {
336
- await ctx.storage.delete(storageId)
306
+ await ctx.storage.delete(stored.storageId)
337
307
  throw error
338
308
  }
339
309
  },
@@ -346,13 +316,9 @@ export const storeGeneratedImage = action({
346
316
  * (`ctx.storeImage` does), so its bytes are never a mutation's argument.
347
317
  */
348
318
  export const storeImage = mutation({
349
- args: { bytes: v.bytes(), ...vImageRecord },
319
+ args: vImageBytes,
350
320
  returns: v.id('_storage'),
351
- handler: async (ctx, { bytes, ...record }): Promise<Id<'_storage'>> => {
352
- const contentType = record.contentType ?? 'application/octet-stream'
353
- const storageId = await ctx.storage.store(new Blob([bytes], { type: contentType }))
354
- return await recordImageRow(ctx, { ...record, contentType, storageId, size: bytes.byteLength, sha256: await fileSha256(bytes) })
355
- },
321
+ handler: async (ctx, { bytes, ...record }): Promise<Id<'_storage'>> => recordImageRow(ctx, await storeBytes(ctx.storage, bytes, record)),
356
322
  })
357
323
 
358
324
  const vRecordImage = { ...vImageRecord, storageId: v.id('_storage'), size: v.number(), sha256: v.string() }
@@ -1,5 +1,5 @@
1
1
  import { v } from 'convex/values'
2
- import { type MutationCtx, mutation, query } from './_generated/server.js'
2
+ import { type MutationCtx, mutation, query, type QueryCtx } from './_generated/server.js'
3
3
  import { retierOwner } from './jobs.js'
4
4
  import { vEntitlementBenefit, vEntitlementMeter } from './schema.js'
5
5
 
@@ -22,6 +22,11 @@ type PendingSpend = {
22
22
  /** The longest a reservation may be held: a week, the longest a queued job waits for its slot. */
23
23
  const MAX_HOLD_MS = 7 * 24 * 60 * 60 * 1000
24
24
 
25
+ /** A user's row in the entitlement cache, if there is one. */
26
+ function entitlementOf(ctx: QueryCtx, userId: string) {
27
+ return ctx.db.query('billingEntitlements').withIndex('userId', q => q.eq('userId', userId)).unique()
28
+ }
29
+
25
30
  function activePendings(pendings: PendingSpend[] | undefined, now: number): PendingSpend[] {
26
31
  return (pendings ?? []).filter(pending => pending.until === undefined ? now - pending.at < PENDING_SPEND_TTL_MS : now < pending.until)
27
32
  }
@@ -66,10 +71,7 @@ export const getByUser = query({
66
71
  v.null(),
67
72
  ),
68
73
  handler: async (ctx, { userId }) => {
69
- const row = await ctx.db
70
- .query('billingEntitlements')
71
- .withIndex('userId', q => q.eq('userId', userId))
72
- .unique()
74
+ const row = await entitlementOf(ctx, userId)
73
75
  if (!row) return null
74
76
  return {
75
77
  customerId: row.customerId ?? null,
@@ -98,10 +100,7 @@ export const upsert = mutation({
98
100
  },
99
101
  returns: v.null(),
100
102
  handler: async (ctx, args) => {
101
- const existing = await ctx.db
102
- .query('billingEntitlements')
103
- .withIndex('userId', q => q.eq('userId', args.userId))
104
- .unique()
103
+ const existing = await entitlementOf(ctx, args.userId)
105
104
  const now = Date.now()
106
105
  const pending = activePendings(existing?.pendingSpends, now)
107
106
  const meters = args.meters.map((meter) => {
@@ -163,10 +162,7 @@ export const debit = mutation({
163
162
  handler: async (ctx, { userId, meterId, amount, externalId, allowOverage, hold }) => {
164
163
  assertAmount(amount, 'debit: `amount`')
165
164
  if (hold !== undefined) assertAmount(hold, 'debit: `hold`')
166
- const row = await ctx.db
167
- .query('billingEntitlements')
168
- .withIndex('userId', q => q.eq('userId', userId))
169
- .unique()
165
+ const row = await entitlementOf(ctx, userId)
170
166
  if (!row) return { ok: false, balance: 0, reason: 'no-row' as const }
171
167
  const index = row.meters.findIndex(meter => meter.meterId === meterId)
172
168
  if (index === -1) return { ok: false, balance: 0, reason: 'no-meter' as const }
@@ -232,10 +228,7 @@ async function closeReservation(
232
228
  externalId: string,
233
229
  finalAmount?: number,
234
230
  ): Promise<SettleOutcome> {
235
- const row = await ctx.db
236
- .query('billingEntitlements')
237
- .withIndex('userId', q => q.eq('userId', userId))
238
- .unique()
231
+ const row = await entitlementOf(ctx, userId)
239
232
  if (!row) return NOTHING_SETTLED
240
233
  const now = Date.now()
241
234
  const pending = activePendings(row.pendingSpends, now)
@@ -326,10 +319,7 @@ export const attachReleaseJob = mutation({
326
319
  args: { userId: v.string(), externalId: v.string(), jobId: v.string() },
327
320
  returns: v.null(),
328
321
  handler: async (ctx, { userId, externalId, jobId }) => {
329
- const row = await ctx.db
330
- .query('billingEntitlements')
331
- .withIndex('userId', q => q.eq('userId', userId))
332
- .unique()
322
+ const row = await entitlementOf(ctx, userId)
333
323
  if (!row) return null
334
324
  const now = Date.now()
335
325
  const pending = activePendings(row.pendingSpends, now)
@@ -355,10 +345,7 @@ export const release = mutation({
355
345
  args: { userId: v.string(), externalId: v.string() },
356
346
  returns: v.null(),
357
347
  handler: async (ctx, { userId, externalId }) => {
358
- const row = await ctx.db
359
- .query('billingEntitlements')
360
- .withIndex('userId', q => q.eq('userId', userId))
361
- .unique()
348
+ const row = await entitlementOf(ctx, userId)
362
349
  if (!row) return null
363
350
  const now = Date.now()
364
351
  const pending = activePendings(row.pendingSpends, now)
@@ -391,10 +378,7 @@ export const clearPendingSpends = mutation({
391
378
  args: { userId: v.string() },
392
379
  returns: v.null(),
393
380
  handler: async (ctx, { userId }) => {
394
- const row = await ctx.db
395
- .query('billingEntitlements')
396
- .withIndex('userId', q => q.eq('userId', userId))
397
- .unique()
381
+ const row = await entitlementOf(ctx, userId)
398
382
  if (!row) return null
399
383
  await ctx.db.patch('billingEntitlements', row._id, { pendingSpends: [], updatedAt: Date.now() })
400
384
  return null
@@ -410,10 +394,7 @@ export const credit = mutation({
410
394
  returns: v.null(),
411
395
  handler: async (ctx, { userId, meterId, amount }) => {
412
396
  assertAmount(amount, 'credit: `amount`')
413
- const row = await ctx.db
414
- .query('billingEntitlements')
415
- .withIndex('userId', q => q.eq('userId', userId))
416
- .unique()
397
+ const row = await entitlementOf(ctx, userId)
417
398
  if (!row) return null
418
399
  const meters = row.meters.map(meter => meter.meterId === meterId
419
400
  ? {
@@ -3,6 +3,7 @@ import type { Doc } from './_generated/dataModel.js'
3
3
  import { mutation, type MutationCtx, query, type QueryCtx } from './_generated/server.js'
4
4
  import type { ConsentDecision } from '../../consent-rules.js'
5
5
  import { addressDigest } from '../../waitlist-rules.js'
6
+ import { vConsent } from './schema.js'
6
7
 
7
8
  /**
8
9
  * The consent ledger: the component's half. One row per decision, a grant or
@@ -137,7 +138,7 @@ export const latest = query({
137
138
  /** Every decision of an account, oldest first: what the export carries and an administrator's tooling reads. */
138
139
  export const history = query({
139
140
  args: { userId: v.string() },
140
- returns: v.array(v.object({ kind: v.string(), version: v.string(), granted: v.boolean(), at: v.number(), source: v.string(), text: v.optional(v.string()), reference: v.optional(v.string()) })),
141
+ returns: v.array(vConsent.omit('userId', 'emailHash')),
141
142
  handler: async (ctx, { userId }) => await consentRows(ctx, userId),
142
143
  })
143
144
 
@@ -1,6 +1,6 @@
1
1
  import type { FunctionHandle } from 'convex/server'
2
2
  import { v } from 'convex/values'
3
- import type { Doc } from './_generated/dataModel.js'
3
+ import type { Doc, Id } from './_generated/dataModel.js'
4
4
  import { internalMutation, mutation, query, type QueryCtx } from './_generated/server.js'
5
5
  import { vGift } from './schema.js'
6
6
  import { keepWake } from './wake.js'
@@ -196,6 +196,12 @@ export const markNotified = mutation({
196
196
  /** Whether the purchaser's cancellation holds the gift now: no claim starts meanwhile. */
197
197
  const canceling = (gift: Doc<'billingGifts'>, now: number): boolean => gift.cancelingUntil !== undefined && gift.cancelingUntil > now
198
198
 
199
+ /** A paid gift nobody started to claim and its purchaser is not canceling: one its purchaser may still change. */
200
+ async function unclaimedGift(ctx: QueryCtx, giftId: Id<'billingGifts'>): Promise<Doc<'billingGifts'> | null> {
201
+ const gift = await ctx.db.get('billingGifts', giftId)
202
+ return gift && gift.status === 'paid' && gift.claimingUserId === undefined && !canceling(gift, Date.now()) ? gift : null
203
+ }
204
+
199
205
  /** Whether a plan pass's claim holds the gift now, while it switches the workspace at the provider. */
200
206
  const passClaiming = (gift: Doc<'billingGifts'>, now: number): boolean => gift.claimingUntil !== undefined && gift.claimingUntil > now
201
207
 
@@ -413,8 +419,8 @@ export const setRecipient = mutation({
413
419
  args: { giftId: v.id('billingGifts'), recipientEmail: v.string() },
414
420
  returns: v.boolean(),
415
421
  handler: async (ctx, { giftId, recipientEmail }) => {
416
- const gift = await ctx.db.get('billingGifts', giftId)
417
- if (!gift || gift.status !== 'paid' || gift.claimingUserId !== undefined || canceling(gift, Date.now())) return false
422
+ const gift = await unclaimedGift(ctx, giftId)
423
+ if (!gift) return false
418
424
  await ctx.db.patch('billingGifts', giftId, {
419
425
  recipientEmail: recipientEmail.toLowerCase(),
420
426
  notifiedAt: undefined,
@@ -436,8 +442,8 @@ export const beginCancel = mutation({
436
442
  args: { giftId: v.id('billingGifts'), until: v.number() },
437
443
  returns: v.boolean(),
438
444
  handler: async (ctx, { giftId, until }) => {
439
- const gift = await ctx.db.get('billingGifts', giftId)
440
- if (!gift || gift.status !== 'paid' || gift.claimingUserId !== undefined || canceling(gift, Date.now())) return false
445
+ const gift = await unclaimedGift(ctx, giftId)
446
+ if (!gift) return false
441
447
  await ctx.db.patch('billingGifts', giftId, { cancelingUntil: until })
442
448
  return true
443
449
  },