nuxt-backend 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/README.md +8 -4
  2. package/dist/capabilities/registry.js +1 -1
  3. package/dist/chunks/catalog.mjs +1 -1
  4. package/dist/chunks/{index.mjs → devtools.mjs} +2 -2
  5. package/dist/chunks/doctor.mjs +14 -6
  6. package/dist/chunks/email-previews.mjs +1 -1
  7. package/dist/chunks/health.mjs +2 -2
  8. package/dist/chunks/install.mjs +4 -4
  9. package/dist/chunks/run.mjs +1 -1
  10. package/dist/chunks/server.mjs +15 -4
  11. package/dist/cli.mjs +28 -8
  12. package/dist/convex/access-tickets.d.ts +17 -2
  13. package/dist/convex/access-tickets.d.ts.map +1 -1
  14. package/dist/convex/account-data.d.ts +4 -4
  15. package/dist/convex/account-data.d.ts.map +1 -1
  16. package/dist/convex/account-data.js +5 -4
  17. package/dist/convex/account-data.js.map +1 -1
  18. package/dist/convex/app.d.ts +1 -0
  19. package/dist/convex/app.d.ts.map +1 -1
  20. package/dist/convex/app.js +2 -1
  21. package/dist/convex/app.js.map +1 -1
  22. package/dist/convex/client/better-auth-options.d.ts.map +1 -1
  23. package/dist/convex/client/better-auth-options.js +12 -3
  24. package/dist/convex/client/better-auth-options.js.map +1 -1
  25. package/dist/convex/client/component.d.ts +4 -0
  26. package/dist/convex/client/component.d.ts.map +1 -1
  27. package/dist/convex/client/index.d.ts +5 -0
  28. package/dist/convex/client/index.d.ts.map +1 -1
  29. package/dist/convex/client/launch-gate.d.ts.map +1 -1
  30. package/dist/convex/client/launch-gate.js +30 -1
  31. package/dist/convex/client/launch-gate.js.map +1 -1
  32. package/dist/convex/client/plugins.d.ts.map +1 -1
  33. package/dist/convex/client/plugins.js +3 -0
  34. package/dist/convex/client/plugins.js.map +1 -1
  35. package/dist/convex/client/two-factor.d.ts +7 -0
  36. package/dist/convex/client/two-factor.d.ts.map +1 -0
  37. package/dist/convex/client/two-factor.js +57 -0
  38. package/dist/convex/client/two-factor.js.map +1 -0
  39. package/dist/convex/components/backend/_generated/api.d.ts +2 -0
  40. package/dist/convex/components/backend/_generated/api.d.ts.map +1 -1
  41. package/dist/convex/components/backend/_generated/api.js.map +1 -1
  42. package/dist/convex/components/backend/_generated/component.d.ts +292 -10
  43. package/dist/convex/components/backend/_generated/component.d.ts.map +1 -1
  44. package/dist/convex/components/backend/account.d.ts +63 -17
  45. package/dist/convex/components/backend/account.d.ts.map +1 -1
  46. package/dist/convex/components/backend/account.js +24 -1
  47. package/dist/convex/components/backend/account.js.map +1 -1
  48. package/dist/convex/components/backend/adapter.d.ts.map +1 -1
  49. package/dist/convex/components/backend/adapter.js +7 -2
  50. package/dist/convex/components/backend/adapter.js.map +1 -1
  51. package/dist/convex/components/backend/ai.d.ts +1 -1
  52. package/dist/convex/components/backend/billing.d.ts +10 -0
  53. package/dist/convex/components/backend/billing.d.ts.map +1 -1
  54. package/dist/convex/components/backend/billing.js +2 -1
  55. package/dist/convex/components/backend/billing.js.map +1 -1
  56. package/dist/convex/components/backend/commerce.d.ts +229 -0
  57. package/dist/convex/components/backend/commerce.d.ts.map +1 -0
  58. package/dist/convex/components/backend/commerce.js +392 -0
  59. package/dist/convex/components/backend/commerce.js.map +1 -0
  60. package/dist/convex/components/backend/funnel.d.ts +6 -6
  61. package/dist/convex/components/backend/jobs.d.ts +1 -1
  62. package/dist/convex/components/backend/referrals.d.ts +2 -2
  63. package/dist/convex/components/backend/schema.d.ts +327 -21
  64. package/dist/convex/components/backend/schema.d.ts.map +1 -1
  65. package/dist/convex/components/backend/schema.js +108 -1
  66. package/dist/convex/components/backend/schema.js.map +1 -1
  67. package/dist/convex/components/backend/waitlist.d.ts +42 -6
  68. package/dist/convex/components/backend/waitlist.d.ts.map +1 -1
  69. package/dist/convex/components/backend/waitlist.js +142 -39
  70. package/dist/convex/components/backend/waitlist.js.map +1 -1
  71. package/dist/convex/email-templates.d.ts +12 -0
  72. package/dist/convex/email-templates.d.ts.map +1 -1
  73. package/dist/convex/email-templates.js +3 -0
  74. package/dist/convex/email-templates.js.map +1 -1
  75. package/dist/convex/emails/waitlist-friend-joined.d.ts +9 -0
  76. package/dist/convex/emails/waitlist-friend-joined.d.ts.map +1 -0
  77. package/dist/convex/emails/waitlist-friend-joined.js +22 -0
  78. package/dist/convex/emails/waitlist-friend-joined.js.map +1 -0
  79. package/dist/convex/errors.d.ts +6 -6
  80. package/dist/convex/errors.d.ts.map +1 -1
  81. package/dist/convex/errors.js +14 -2
  82. package/dist/convex/errors.js.map +1 -1
  83. package/dist/convex/events.d.ts +19 -0
  84. package/dist/convex/events.d.ts.map +1 -1
  85. package/dist/convex/events.js +14 -0
  86. package/dist/convex/events.js.map +1 -1
  87. package/dist/convex/integrations/billing/checkout.d.ts +2 -2
  88. package/dist/convex/integrations/billing/checkout.d.ts.map +1 -1
  89. package/dist/convex/integrations/billing/checkout.js +79 -11
  90. package/dist/convex/integrations/billing/checkout.js.map +1 -1
  91. package/dist/convex/integrations/billing/commerce-entitlements.d.ts +12 -0
  92. package/dist/convex/integrations/billing/commerce-entitlements.d.ts.map +1 -0
  93. package/dist/convex/integrations/billing/commerce-entitlements.js +78 -0
  94. package/dist/convex/integrations/billing/commerce-entitlements.js.map +1 -0
  95. package/dist/convex/integrations/billing/commerce-events.d.ts +15 -0
  96. package/dist/convex/integrations/billing/commerce-events.d.ts.map +1 -0
  97. package/dist/convex/integrations/billing/commerce-events.js +433 -0
  98. package/dist/convex/integrations/billing/commerce-events.js.map +1 -0
  99. package/dist/convex/integrations/billing/commerce-history.d.ts +20 -0
  100. package/dist/convex/integrations/billing/commerce-history.d.ts.map +1 -0
  101. package/dist/convex/integrations/billing/commerce-history.js +106 -0
  102. package/dist/convex/integrations/billing/commerce-history.js.map +1 -0
  103. package/dist/convex/integrations/billing/commerce-webhooks.d.ts +23 -0
  104. package/dist/convex/integrations/billing/commerce-webhooks.d.ts.map +1 -0
  105. package/dist/convex/integrations/billing/commerce-webhooks.js +49 -0
  106. package/dist/convex/integrations/billing/commerce-webhooks.js.map +1 -0
  107. package/dist/convex/integrations/billing/commerce.d.ts +100 -0
  108. package/dist/convex/integrations/billing/commerce.d.ts.map +1 -0
  109. package/dist/convex/integrations/billing/commerce.js +323 -0
  110. package/dist/convex/integrations/billing/commerce.js.map +1 -0
  111. package/dist/convex/integrations/billing/context.d.ts +8 -0
  112. package/dist/convex/integrations/billing/context.d.ts.map +1 -1
  113. package/dist/convex/integrations/billing/context.js +14 -2
  114. package/dist/convex/integrations/billing/context.js.map +1 -1
  115. package/dist/convex/integrations/billing/credits.d.ts +1 -1
  116. package/dist/convex/integrations/billing/credits.d.ts.map +1 -1
  117. package/dist/convex/integrations/billing/credits.js +49 -28
  118. package/dist/convex/integrations/billing/credits.js.map +1 -1
  119. package/dist/convex/integrations/billing/customers.d.ts +1 -1
  120. package/dist/convex/integrations/billing/customers.d.ts.map +1 -1
  121. package/dist/convex/integrations/billing/customers.js +15 -1
  122. package/dist/convex/integrations/billing/customers.js.map +1 -1
  123. package/dist/convex/integrations/billing/entitlements.d.ts +1 -1
  124. package/dist/convex/integrations/billing/entitlements.d.ts.map +1 -1
  125. package/dist/convex/integrations/billing/entitlements.js +6 -1
  126. package/dist/convex/integrations/billing/entitlements.js.map +1 -1
  127. package/dist/convex/integrations/billing/erasure.d.ts +1 -1
  128. package/dist/convex/integrations/billing/erasure.d.ts.map +1 -1
  129. package/dist/convex/integrations/billing/erasure.js +10 -5
  130. package/dist/convex/integrations/billing/erasure.js.map +1 -1
  131. package/dist/convex/integrations/billing/free-plan.d.ts +6 -1
  132. package/dist/convex/integrations/billing/free-plan.d.ts.map +1 -1
  133. package/dist/convex/integrations/billing/free-plan.js +22 -4
  134. package/dist/convex/integrations/billing/free-plan.js.map +1 -1
  135. package/dist/convex/integrations/billing/functions.d.ts +1 -1
  136. package/dist/convex/integrations/billing/functions.d.ts.map +1 -1
  137. package/dist/convex/integrations/billing/functions.js +3 -2
  138. package/dist/convex/integrations/billing/functions.js.map +1 -1
  139. package/dist/convex/integrations/billing/gifts.d.ts.map +1 -1
  140. package/dist/convex/integrations/billing/gifts.js +3 -0
  141. package/dist/convex/integrations/billing/gifts.js.map +1 -1
  142. package/dist/convex/integrations/billing/history.d.ts +1 -1
  143. package/dist/convex/integrations/billing/history.d.ts.map +1 -1
  144. package/dist/convex/integrations/billing/history.js +6 -1
  145. package/dist/convex/integrations/billing/history.js.map +1 -1
  146. package/dist/convex/integrations/billing/lifecycle.d.ts +1 -1
  147. package/dist/convex/integrations/billing/lifecycle.d.ts.map +1 -1
  148. package/dist/convex/integrations/billing/lifecycle.js +4 -1
  149. package/dist/convex/integrations/billing/lifecycle.js.map +1 -1
  150. package/dist/convex/integrations/billing/providers/capabilities.d.ts +17 -0
  151. package/dist/convex/integrations/billing/providers/capabilities.d.ts.map +1 -0
  152. package/dist/convex/integrations/billing/providers/capabilities.js +77 -0
  153. package/dist/convex/integrations/billing/providers/capabilities.js.map +1 -0
  154. package/dist/convex/integrations/billing/providers/consent.d.ts +52 -0
  155. package/dist/convex/integrations/billing/providers/consent.d.ts.map +1 -0
  156. package/dist/convex/integrations/billing/providers/consent.js +79 -0
  157. package/dist/convex/integrations/billing/providers/consent.js.map +1 -0
  158. package/dist/convex/integrations/billing/providers/creem.d.ts +22 -0
  159. package/dist/convex/integrations/billing/providers/creem.d.ts.map +1 -0
  160. package/dist/convex/integrations/billing/providers/creem.js +208 -0
  161. package/dist/convex/integrations/billing/providers/creem.js.map +1 -0
  162. package/dist/convex/integrations/billing/providers/dodo.d.ts +15 -0
  163. package/dist/convex/integrations/billing/providers/dodo.d.ts.map +1 -0
  164. package/dist/convex/integrations/billing/providers/dodo.js +197 -0
  165. package/dist/convex/integrations/billing/providers/dodo.js.map +1 -0
  166. package/dist/convex/integrations/billing/providers/http.d.ts +41 -0
  167. package/dist/convex/integrations/billing/providers/http.d.ts.map +1 -0
  168. package/dist/convex/integrations/billing/providers/http.js +146 -0
  169. package/dist/convex/integrations/billing/providers/http.js.map +1 -0
  170. package/dist/convex/integrations/billing/providers/index.d.ts +35 -0
  171. package/dist/convex/integrations/billing/providers/index.d.ts.map +1 -0
  172. package/dist/convex/integrations/billing/providers/index.js +62 -0
  173. package/dist/convex/integrations/billing/providers/index.js.map +1 -0
  174. package/dist/convex/integrations/billing/providers/stripe.d.ts +28 -0
  175. package/dist/convex/integrations/billing/providers/stripe.d.ts.map +1 -0
  176. package/dist/convex/integrations/billing/providers/stripe.js +327 -0
  177. package/dist/convex/integrations/billing/providers/stripe.js.map +1 -0
  178. package/dist/convex/integrations/billing/providers/types.d.ts +263 -0
  179. package/dist/convex/integrations/billing/providers/types.d.ts.map +1 -0
  180. package/dist/convex/integrations/billing/providers/types.js +48 -0
  181. package/dist/convex/integrations/billing/providers/types.js.map +1 -0
  182. package/dist/convex/integrations/billing/subscriptions.d.ts +1 -1
  183. package/dist/convex/integrations/billing/subscriptions.d.ts.map +1 -1
  184. package/dist/convex/integrations/billing/subscriptions.js +20 -6
  185. package/dist/convex/integrations/billing/subscriptions.js.map +1 -1
  186. package/dist/convex/integrations/billing/types/setup.d.ts +64 -1
  187. package/dist/convex/integrations/billing/types/setup.d.ts.map +1 -1
  188. package/dist/convex/integrations/billing.d.ts +4 -1
  189. package/dist/convex/integrations/billing.d.ts.map +1 -1
  190. package/dist/convex/integrations/billing.js +12 -2
  191. package/dist/convex/integrations/billing.js.map +1 -1
  192. package/dist/convex/integrations/email.d.ts +1 -1
  193. package/dist/convex/integrations/email.d.ts.map +1 -1
  194. package/dist/convex/integrations/email.js.map +1 -1
  195. package/dist/convex/integrations/launch.d.ts +27 -2
  196. package/dist/convex/integrations/launch.d.ts.map +1 -1
  197. package/dist/convex/integrations/launch.js +15 -3
  198. package/dist/convex/integrations/launch.js.map +1 -1
  199. package/dist/convex/integrations/presence.d.ts +110 -0
  200. package/dist/convex/integrations/presence.d.ts.map +1 -0
  201. package/dist/convex/integrations/presence.js +92 -0
  202. package/dist/convex/integrations/presence.js.map +1 -0
  203. package/dist/convex/integrations/waitlist.d.ts +41 -7
  204. package/dist/convex/integrations/waitlist.d.ts.map +1 -1
  205. package/dist/convex/integrations/waitlist.js +45 -6
  206. package/dist/convex/integrations/waitlist.js.map +1 -1
  207. package/dist/convex/integrations/webhook-guard.d.ts +8 -0
  208. package/dist/convex/integrations/webhook-guard.d.ts.map +1 -1
  209. package/dist/convex/integrations/webhook-guard.js +11 -4
  210. package/dist/convex/integrations/webhook-guard.js.map +1 -1
  211. package/dist/convex/label-groups/admin.d.ts +9 -0
  212. package/dist/convex/label-groups/admin.d.ts.map +1 -1
  213. package/dist/convex/label-groups/admin.js +9 -0
  214. package/dist/convex/label-groups/admin.js.map +1 -1
  215. package/dist/convex/label-groups/audit.d.ts +2 -0
  216. package/dist/convex/label-groups/audit.d.ts.map +1 -1
  217. package/dist/convex/label-groups/audit.js +2 -0
  218. package/dist/convex/label-groups/audit.js.map +1 -1
  219. package/dist/convex/label-groups/auth.d.ts +9 -0
  220. package/dist/convex/label-groups/auth.d.ts.map +1 -1
  221. package/dist/convex/label-groups/auth.js +10 -0
  222. package/dist/convex/label-groups/auth.js.map +1 -1
  223. package/dist/convex/label-groups/email.d.ts +6 -0
  224. package/dist/convex/label-groups/email.d.ts.map +1 -1
  225. package/dist/convex/label-groups/email.js +7 -0
  226. package/dist/convex/label-groups/email.js.map +1 -1
  227. package/dist/convex/label-groups/errors.d.ts +4 -0
  228. package/dist/convex/label-groups/errors.d.ts.map +1 -1
  229. package/dist/convex/label-groups/errors.js +4 -0
  230. package/dist/convex/label-groups/errors.js.map +1 -1
  231. package/dist/convex/label-groups/security.d.ts +19 -0
  232. package/dist/convex/label-groups/security.d.ts.map +1 -1
  233. package/dist/convex/label-groups/security.js +20 -0
  234. package/dist/convex/label-groups/security.js.map +1 -1
  235. package/dist/convex/label-groups/waitlist.d.ts +8 -0
  236. package/dist/convex/label-groups/waitlist.d.ts.map +1 -1
  237. package/dist/convex/label-groups/waitlist.js +9 -0
  238. package/dist/convex/label-groups/waitlist.js.map +1 -1
  239. package/dist/convex/label-translations.d.ts.map +1 -1
  240. package/dist/convex/label-translations.js +24 -0
  241. package/dist/convex/label-translations.js.map +1 -1
  242. package/dist/convex/labels.d.ts +57 -0
  243. package/dist/convex/labels.d.ts.map +1 -1
  244. package/dist/convex/log.js +2 -0
  245. package/dist/convex/log.js.map +1 -1
  246. package/dist/convex/sensitive-actions.d.ts.map +1 -1
  247. package/dist/convex/sensitive-actions.js +11 -0
  248. package/dist/convex/sensitive-actions.js.map +1 -1
  249. package/dist/convex/waitlist-rules.d.ts +63 -9
  250. package/dist/convex/waitlist-rules.d.ts.map +1 -1
  251. package/dist/convex/waitlist-rules.js +38 -7
  252. package/dist/convex/waitlist-rules.js.map +1 -1
  253. package/dist/devtools-client/_nuxt/DHNi4uhO.js +6 -0
  254. package/dist/devtools-client/index.html +1 -1
  255. package/dist/env-registry.js +9 -0
  256. package/dist/module.d.ts +14 -2
  257. package/dist/module.js +2 -2
  258. package/dist/module.json +2 -2
  259. package/dist/runtime/locales/de.json +58 -1
  260. package/dist/runtime/locales/en.json +60 -3
  261. package/dist/runtime/locales/es.json +58 -1
  262. package/dist/runtime/locales/fr.json +58 -1
  263. package/dist/runtime/locales/ru.json +58 -1
  264. package/dist/runtime/server/monitoring/backend-calls.d.ts +3 -3
  265. package/dist/runtime/server/monitoring/backend-calls.js +2 -2
  266. package/dist/runtime/server/monitoring/health.js +2 -2
  267. package/dist/runtime/vue/auth-client.d.ts +3 -2
  268. package/dist/runtime/vue/auth-client.js +2 -1
  269. package/dist/runtime/vue/components/account/SecuritySettings.d.vue.ts +25 -2
  270. package/dist/runtime/vue/components/account/SecuritySettings.vue +52 -2
  271. package/dist/runtime/vue/components/account/SecuritySettings.vue.d.ts +25 -2
  272. package/dist/runtime/vue/components/account/SecurityTwoFactor.css +1 -0
  273. package/dist/runtime/vue/components/account/SecurityTwoFactor.d.vue.ts +4 -0
  274. package/dist/runtime/vue/components/account/SecurityTwoFactor.vue +107 -0
  275. package/dist/runtime/vue/components/account/SecurityTwoFactor.vue.d.ts +4 -0
  276. package/dist/runtime/vue/components/account/security-settings.d.ts +18 -1
  277. package/dist/runtime/vue/components/admin/AdminUsers.d.vue.ts +11 -2
  278. package/dist/runtime/vue/components/admin/AdminUsers.vue.d.ts +11 -2
  279. package/dist/runtime/vue/components/admin/AdminWaitlist.css +1 -1
  280. package/dist/runtime/vue/components/admin/AdminWaitlistActions.vue +41 -1
  281. package/dist/runtime/vue/components/admin/AdminWorkspaces.d.vue.ts +9 -0
  282. package/dist/runtime/vue/components/admin/AdminWorkspaces.vue.d.ts +9 -0
  283. package/dist/runtime/vue/components/admin/admin-waitlist-tab.js +28 -0
  284. package/dist/runtime/vue/components/auth/AuthForm.d.vue.ts +9 -0
  285. package/dist/runtime/vue/components/auth/AuthForm.vue +8 -0
  286. package/dist/runtime/vue/components/auth/AuthForm.vue.d.ts +9 -0
  287. package/dist/runtime/vue/components/auth/AuthFormTwoFactor.css +1 -0
  288. package/dist/runtime/vue/components/auth/AuthFormTwoFactor.d.vue.ts +3 -0
  289. package/dist/runtime/vue/components/auth/AuthFormTwoFactor.vue +70 -0
  290. package/dist/runtime/vue/components/auth/AuthFormTwoFactor.vue.d.ts +3 -0
  291. package/dist/runtime/vue/components/auth/AuthFormWaitlisted.vue +7 -2
  292. package/dist/runtime/vue/components/auth/WaitlistForm.d.vue.ts +8 -0
  293. package/dist/runtime/vue/components/auth/WaitlistForm.vue.d.ts +8 -0
  294. package/dist/runtime/vue/components/auth/WaitlistPlace.css +1 -1
  295. package/dist/runtime/vue/components/auth/WaitlistPlace.vue +37 -0
  296. package/dist/runtime/vue/components/auth/WaitlistShare.vue +2 -2
  297. package/dist/runtime/vue/components/auth/auth-form.d.ts +2 -0
  298. package/dist/runtime/vue/components/workspaces/AuditLog.d.vue.ts +2 -0
  299. package/dist/runtime/vue/components/workspaces/AuditLog.vue.d.ts +2 -0
  300. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +2 -2
  301. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +2 -2
  302. package/dist/runtime/vue/composables/use-login-flow.d.ts +19 -4
  303. package/dist/runtime/vue/composables/use-login-flow.js +31 -0
  304. package/dist/runtime/vue/composables/use-room-presence.d.ts +63 -0
  305. package/dist/runtime/vue/composables/use-room-presence.js +31 -0
  306. package/dist/runtime/vue/composables/use-two-factor.d.ts +58 -0
  307. package/dist/runtime/vue/composables/use-two-factor.js +49 -0
  308. package/dist/runtime/vue/composables/use-waitlist-admin.d.ts +5 -0
  309. package/dist/runtime/vue/composables/use-waitlist-admin.js +5 -1
  310. package/dist/runtime/vue/composables/use-waitlist.d.ts +4 -0
  311. package/dist/runtime/vue/composables/use-waitlist.js +1 -1
  312. package/dist/runtime/vue/parts.d.ts +8 -1
  313. package/dist/runtime/vue/two-factor-client.d.ts +15 -0
  314. package/dist/runtime/vue/two-factor-client.js +19 -0
  315. package/dist/runtime/vue/utils/auth-session.js +10 -1
  316. package/dist/runtime/vue/utils/login-bindings.js +1 -0
  317. package/dist/runtime/vue/utils/page-guard.d.ts +2 -2
  318. package/dist/runtime/vue/utils/page-guard.js +2 -2
  319. package/dist/shared/{nuxt-backend.CBvrM7pG.mjs → nuxt-backend.CM_p0XQE.mjs} +1 -1
  320. package/dist/shared/{nuxt-backend.Dikfaocl.mjs → nuxt-backend.C_Y_BtBs.mjs} +128 -5
  321. package/dist/shared/{nuxt-backend.DbaXvH__.mjs → nuxt-backend.ChvlbHQq.mjs} +203 -9
  322. package/dist/shared/{nuxt-backend.BqXAZChe.mjs → nuxt-backend.D16peTIt.mjs} +57 -35
  323. package/dist/shared/{nuxt-backend.DH1Ya3uB.mjs → nuxt-backend.D4JXvCP6.mjs} +3 -2
  324. package/dist/types.d.ts +1 -1
  325. package/package.json +19 -10
  326. package/skills/nuxt-backend/SKILL.md +18 -18
  327. package/skills/nuxt-backend/references/api.md +31 -6
  328. package/skills/nuxt-backend/references/install.md +9 -6
  329. package/skills/nuxt-backend/references/renames.json +8 -0
  330. package/skills/nuxt-backend/references/surface.json +62 -2
  331. package/skills/nuxt-backend-auth/SKILL.md +8 -2
  332. package/skills/nuxt-backend-auth/references/api.md +3 -1
  333. package/skills/nuxt-backend-billing/SKILL.md +15 -0
  334. package/skills/nuxt-backend-billing/references/api.md +14 -1
  335. package/skills/nuxt-backend-data/SKILL.md +1 -0
  336. package/skills/nuxt-backend-data/references/api.md +10 -1
  337. package/skills/nuxt-backend-email/references/api.md +1 -1
  338. package/skills/nuxt-backend-ship/SKILL.md +2 -1
  339. package/skills/nuxt-backend-upgrade/references/upgrade.md +6 -0
  340. package/src/convex/access-tickets.ts +10 -2
  341. package/src/convex/account-data.ts +5 -4
  342. package/src/convex/app.ts +2 -1
  343. package/src/convex/client/better-auth-options.ts +12 -3
  344. package/src/convex/client/launch-gate.ts +28 -1
  345. package/src/convex/client/plugins.ts +3 -0
  346. package/src/convex/client/two-factor.ts +66 -0
  347. package/src/convex/components/backend/_generated/api.ts +2 -0
  348. package/src/convex/components/backend/_generated/component.ts +500 -2
  349. package/src/convex/components/backend/account.ts +25 -1
  350. package/src/convex/components/backend/adapter.ts +7 -2
  351. package/src/convex/components/backend/billing.ts +2 -1
  352. package/src/convex/components/backend/commerce.ts +408 -0
  353. package/src/convex/components/backend/schema.ts +110 -1
  354. package/src/convex/components/backend/waitlist.ts +144 -40
  355. package/src/convex/email-templates.ts +16 -0
  356. package/src/convex/emails/waitlist-friend-joined.ts +23 -0
  357. package/src/convex/errors.ts +15 -2
  358. package/src/convex/events.ts +14 -0
  359. package/src/convex/integrations/billing/checkout.ts +78 -11
  360. package/src/convex/integrations/billing/commerce-entitlements.ts +92 -0
  361. package/src/convex/integrations/billing/commerce-events.ts +487 -0
  362. package/src/convex/integrations/billing/commerce-history.ts +110 -0
  363. package/src/convex/integrations/billing/commerce-webhooks.ts +69 -0
  364. package/src/convex/integrations/billing/commerce.ts +366 -0
  365. package/src/convex/integrations/billing/context.ts +19 -2
  366. package/src/convex/integrations/billing/credits.ts +47 -27
  367. package/src/convex/integrations/billing/customers.ts +15 -1
  368. package/src/convex/integrations/billing/entitlements.ts +5 -1
  369. package/src/convex/integrations/billing/erasure.ts +11 -6
  370. package/src/convex/integrations/billing/free-plan.ts +30 -5
  371. package/src/convex/integrations/billing/functions.ts +3 -2
  372. package/src/convex/integrations/billing/gifts.ts +2 -0
  373. package/src/convex/integrations/billing/history.ts +9 -0
  374. package/src/convex/integrations/billing/lifecycle.ts +3 -1
  375. package/src/convex/integrations/billing/providers/capabilities.ts +78 -0
  376. package/src/convex/integrations/billing/providers/consent.ts +94 -0
  377. package/src/convex/integrations/billing/providers/creem.ts +225 -0
  378. package/src/convex/integrations/billing/providers/dodo.ts +214 -0
  379. package/src/convex/integrations/billing/providers/http.ts +168 -0
  380. package/src/convex/integrations/billing/providers/index.ts +65 -0
  381. package/src/convex/integrations/billing/providers/stripe.ts +345 -0
  382. package/src/convex/integrations/billing/providers/types.ts +281 -0
  383. package/src/convex/integrations/billing/subscriptions.ts +20 -6
  384. package/src/convex/integrations/billing/types/setup.ts +63 -1
  385. package/src/convex/integrations/billing.ts +46 -3
  386. package/src/convex/integrations/email.ts +1 -0
  387. package/src/convex/integrations/launch.ts +45 -7
  388. package/src/convex/integrations/presence.ts +160 -0
  389. package/src/convex/integrations/waitlist.ts +84 -12
  390. package/src/convex/integrations/webhook-guard.ts +20 -4
  391. package/src/convex/label-groups/admin.ts +9 -0
  392. package/src/convex/label-groups/audit.ts +2 -0
  393. package/src/convex/label-groups/auth.ts +10 -0
  394. package/src/convex/label-groups/email.ts +7 -0
  395. package/src/convex/label-groups/errors.ts +4 -0
  396. package/src/convex/label-groups/security.ts +20 -0
  397. package/src/convex/label-groups/waitlist.ts +9 -0
  398. package/src/convex/label-translations.ts +24 -0
  399. package/src/convex/log.ts +2 -0
  400. package/src/convex/sensitive-actions.ts +11 -0
  401. package/src/convex/waitlist-rules.ts +84 -8
  402. package/src/runtime/vue/components/account/SecuritySettings.vue +58 -4
  403. package/src/runtime/vue/components/account/SecurityTwoFactor.css +68 -0
  404. package/src/runtime/vue/components/account/SecurityTwoFactor.vue +113 -0
  405. package/src/runtime/vue/components/admin/AdminWaitlist.css +1 -0
  406. package/src/runtime/vue/components/admin/AdminWaitlistActions.vue +44 -2
  407. package/src/runtime/vue/components/auth/AuthForm.vue +8 -0
  408. package/src/runtime/vue/components/auth/AuthFormTwoFactor.css +40 -0
  409. package/src/runtime/vue/components/auth/AuthFormTwoFactor.vue +75 -0
  410. package/src/runtime/vue/components/auth/AuthFormWaitlisted.vue +11 -4
  411. package/src/runtime/vue/components/auth/WaitlistPlace.css +16 -0
  412. package/src/runtime/vue/components/auth/WaitlistPlace.vue +49 -2
  413. package/src/runtime/vue/components/auth/WaitlistShare.vue +4 -3
  414. package/dist/devtools-client/_nuxt/CiCAOwUc.js +0 -5
@@ -0,0 +1,345 @@
1
+ import { constantTimeEqual, ENTITY_METADATA_KEY, hmacSha256Hex, idOf, millis, num, providerClient, str, stringMetadata, stripeForm } from './http.js'
2
+ import { PROVIDER_CAPABILITIES } from './capabilities.js'
3
+ import type {
4
+ CheckoutRequest,
5
+ CommerceProvider,
6
+ InvoiceAnswer,
7
+ NeutralBillingEvent,
8
+ NeutralOrder,
9
+ NeutralRefund,
10
+ NeutralSubscription,
11
+ NeutralSubscriptionStatus,
12
+ ProviderOptions,
13
+ VerifiedDelivery,
14
+ } from './types.js'
15
+ import { ProviderUnsupportedError } from './types.js'
16
+
17
+ // Stripe Managed Payments: Stripe sells as merchant of record through its
18
+ // Checkout, with `managed_payments[enabled]=true` on every session. Stripe
19
+ // then calculates, collects, files and remits sales tax and VAT, sends the
20
+ // receipts and invoices (from Link), and answers payment support and
21
+ // disputes. Each product needs a tax code Stripe marks "Eligible for Managed
22
+ // Payments"; `billing doctor` cannot check that for you yet.
23
+ // https://docs.stripe.com/payments/managed-payments/set-up
24
+
25
+ /**
26
+ * The API version every request pins. `2026-04-22.dahlia` is the first that
27
+ * types `managed_payments` on Checkout Sessions, Payment Links and
28
+ * Subscriptions. Set the webhook endpoint to the same version, or the
29
+ * deliveries keep an older shape.
30
+ */
31
+ export const STRIPE_API_VERSION = '2026-04-22.dahlia'
32
+
33
+ /** How far a delivery's `t=` may be from now, in seconds: Stripe's own default tolerance. */
34
+ export const STRIPE_WEBHOOK_TOLERANCE_SECONDS = 300
35
+
36
+ const STRIPE_STATUSES: Readonly<Record<string, NeutralSubscriptionStatus>> = {
37
+ trialing: 'trialing',
38
+ active: 'active',
39
+ past_due: 'past_due',
40
+ unpaid: 'past_due',
41
+ paused: 'paused',
42
+ canceled: 'ended',
43
+ incomplete: 'incomplete',
44
+ incomplete_expired: 'ended',
45
+ }
46
+
47
+ /* eslint-disable @typescript-eslint/no-explicit-any -- the provider's JSON, read field by field */
48
+
49
+ /** A Stripe subscription in neutral words. The period end moved onto the items in `2025-03-31.basil`; both places are read. */
50
+ export function stripeSubscription(subscription: any): NeutralSubscription {
51
+ const item = subscription.items?.data?.[0]
52
+ const metadata = stringMetadata(subscription.metadata)
53
+ return {
54
+ id: String(subscription.id),
55
+ customerId: idOf(subscription.customer),
56
+ entityId: metadata[ENTITY_METADATA_KEY] ?? null,
57
+ productId: idOf(item?.price) ?? idOf(item?.plan),
58
+ status: STRIPE_STATUSES[subscription.status] ?? 'incomplete',
59
+ cancelAtPeriodEnd: Boolean(subscription.cancel_at_period_end) || num(subscription.cancel_at) !== null,
60
+ currentPeriodEnd: millis(item?.current_period_end ?? subscription.current_period_end, 'seconds'),
61
+ metadata,
62
+ }
63
+ }
64
+
65
+ /** The subscription an invoice bills: under `parent.subscription_details` since basil, on the invoice before it. */
66
+ function invoiceSubscription(invoice: any): { id: string | null, metadata: Record<string, string> } {
67
+ const details = invoice.parent?.subscription_details
68
+ return {
69
+ id: idOf(details?.subscription) ?? idOf(invoice.subscription),
70
+ metadata: { ...stringMetadata(invoice.metadata), ...stringMetadata(details?.metadata) },
71
+ }
72
+ }
73
+
74
+ /** A paid invoice (a subscription's charge) as an order: the invoice id is the order id. */
75
+ export function stripeInvoiceOrder(invoice: any): NeutralOrder {
76
+ const line = invoice.lines?.data?.[0]
77
+ const { id: subscriptionId, metadata } = invoiceSubscription(invoice)
78
+ const taxes = Array.isArray(invoice.total_taxes) ? invoice.total_taxes.reduce((sum: number, tax: any) => sum + (num(tax.amount) ?? 0), 0) : num(invoice.tax)
79
+ return {
80
+ id: String(invoice.id),
81
+ customerId: idOf(invoice.customer),
82
+ entityId: metadata[ENTITY_METADATA_KEY] ?? null,
83
+ productId: str(line?.pricing?.price_details?.price) ?? idOf(line?.price),
84
+ subscriptionId,
85
+ amount: num(invoice.amount_paid) ?? 0,
86
+ taxAmount: taxes ?? null,
87
+ currency: String(invoice.currency ?? '').toLowerCase(),
88
+ metadata,
89
+ }
90
+ }
91
+
92
+ /** A paid one-time Checkout Session as an order: its PaymentIntent is the order id, which a refund names. */
93
+ export function stripeSessionOrder(session: any): NeutralOrder {
94
+ const metadata = stringMetadata(session.metadata)
95
+ return {
96
+ id: idOf(session.payment_intent) ?? String(session.id),
97
+ customerId: idOf(session.customer),
98
+ entityId: metadata[ENTITY_METADATA_KEY] ?? str(session.client_reference_id),
99
+ productId: metadata.product_id ?? null,
100
+ subscriptionId: null,
101
+ amount: num(session.amount_total) ?? 0,
102
+ taxAmount: num(session.total_details?.amount_tax),
103
+ currency: String(session.currency ?? '').toLowerCase(),
104
+ metadata,
105
+ }
106
+ }
107
+
108
+ function stripeRefund(refund: any): NeutralRefund {
109
+ return {
110
+ id: String(refund.id),
111
+ orderId: idOf(refund.payment_intent) ?? idOf(refund.charge),
112
+ subscriptionId: null,
113
+ amount: num(refund.amount),
114
+ currency: str(refund.currency)?.toLowerCase() ?? null,
115
+ status: refund.status === 'succeeded' ? 'succeeded' : refund.status === 'failed' || refund.status === 'canceled' ? 'failed' : 'pending',
116
+ }
117
+ }
118
+
119
+ /** A verified Stripe event in neutral words. */
120
+ export function readStripeEvent(event: any): NeutralBillingEvent {
121
+ const providerType = String(event.type)
122
+ const object = event.data?.object ?? {}
123
+ switch (providerType) {
124
+ case 'checkout.session.completed':
125
+ case 'checkout.session.async_payment_succeeded':
126
+ // A subscription's first charge arrives as `invoice.paid`, so only a
127
+ // paid one-time session is an order here; an async method (a bank
128
+ // debit) completes unpaid and pays later.
129
+ return object.mode === 'payment' && object.payment_status === 'paid'
130
+ ? { type: 'order.paid', order: stripeSessionOrder(object), providerType }
131
+ : { type: 'ignored', providerType }
132
+ case 'invoice.paid':
133
+ return { type: 'order.paid', order: stripeInvoiceOrder(object), providerType }
134
+ case 'customer.subscription.created':
135
+ case 'customer.subscription.updated':
136
+ case 'customer.subscription.deleted':
137
+ case 'customer.subscription.paused':
138
+ case 'customer.subscription.resumed':
139
+ return { type: 'subscription.updated', subscription: stripeSubscription(object), providerType }
140
+ case 'refund.created':
141
+ case 'refund.updated':
142
+ case 'refund.failed':
143
+ return { type: 'order.refunded', refund: stripeRefund(object), providerType }
144
+ case 'charge.dispute.created':
145
+ return { type: 'order.disputed', orderId: idOf(object.payment_intent) ?? idOf(object.charge), subscriptionId: null, providerType }
146
+ default:
147
+ return { type: 'ignored', providerType }
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Whether `header` (`Stripe-Signature: t=…,v1=…[,v1=…]`) signs `body` under
153
+ * one of `secrets` within the tolerance. Stripe keys the HMAC with the whole
154
+ * `whsec_…` string and signs `${t}.${body}`; a rotation sends one `v1` per
155
+ * live secret.
156
+ */
157
+ export async function verifyStripeSignature(body: string, header: string | null, secrets: readonly string[], now = Date.now()): Promise<boolean> {
158
+ if (!header) return false
159
+ let timestamp: string | undefined
160
+ const signatures: string[] = []
161
+ for (const part of header.split(',')) {
162
+ const [key, value] = part.split('=', 2)
163
+ if (key?.trim() === 't') timestamp = value?.trim()
164
+ else if (key?.trim() === 'v1' && value) signatures.push(value.trim())
165
+ }
166
+ if (!timestamp || !/^\d{1,12}$/.test(timestamp) || signatures.length === 0) return false
167
+ if (Math.abs(now / 1000 - Number(timestamp)) > STRIPE_WEBHOOK_TOLERANCE_SECONDS) return false
168
+ for (const secret of secrets) {
169
+ if (!secret) continue
170
+ const expected = await hmacSha256Hex(secret, `${timestamp}.${body}`)
171
+ if (signatures.some(signature => constantTimeEqual(signature, expected))) return true
172
+ }
173
+ return false
174
+ }
175
+
176
+ /** The Stripe Managed Payments adapter. */
177
+ export function createStripeProvider({ apiKey, environment, fetch: fetchImpl }: ProviderOptions): CommerceProvider {
178
+ // Stripe has one host; a test key (`sk_test_…`) is its sandbox.
179
+ const call = providerClient('stripe', 'https://api.stripe.com/v1', {
180
+ 'authorization': `Bearer ${apiKey}`,
181
+ 'stripe-version': STRIPE_API_VERSION,
182
+ }, fetchImpl)
183
+
184
+ /** A promotion code's id, from the code a buyer typed: Checkout takes ids only. */
185
+ const promotionCodeId = async (code: string): Promise<string> => {
186
+ const found = await call<{ data: Array<{ id: string }> }>('promotion code lookup', { method: 'GET', path: 'promotion_codes', query: { code, active: true, limit: 1 } })
187
+ const id = found.data[0]?.id
188
+ if (!id) throw new Error(`[nuxt-backend] Stripe has no active promotion code "${code}".`)
189
+ return id
190
+ }
191
+
192
+ const createCheckout = async (request: CheckoutRequest) => {
193
+ const metadata = { ...request.metadata, [ENTITY_METADATA_KEY]: request.customer.entityId, product_id: request.productId }
194
+ const subscription = request.kind === 'subscription'
195
+ const session = await call<{ id: string, url: string }>('checkout', {
196
+ method: 'POST',
197
+ path: 'checkout/sessions',
198
+ headers: request.idempotencyKey ? { 'idempotency-key': request.idempotencyKey } : undefined,
199
+ body: stripeForm({
200
+ mode: subscription ? 'subscription' : 'payment',
201
+ managed_payments: { enabled: true },
202
+ line_items: [{ price: request.productId, quantity: request.quantity ?? 1 }],
203
+ success_url: request.successUrl,
204
+ cancel_url: request.cancelUrl,
205
+ client_reference_id: request.customer.entityId,
206
+ customer: request.customer.providerCustomerId,
207
+ customer_email: request.customer.providerCustomerId ? undefined : request.customer.email,
208
+ // A one-time buyer needs a customer for the portal and for their receipts later.
209
+ customer_creation: subscription || request.customer.providerCustomerId ? undefined : 'always',
210
+ locale: request.locale,
211
+ metadata,
212
+ discounts: request.discountCode ? [{ promotion_code: await promotionCodeId(request.discountCode) }] : undefined,
213
+ subscription_data: subscription ? { metadata, trial_period_days: request.trialDays } : undefined,
214
+ payment_intent_data: subscription ? undefined : { metadata },
215
+ }),
216
+ })
217
+ return { id: session.id, url: session.url }
218
+ }
219
+
220
+ const getSubscription = async (subscriptionId: string) =>
221
+ stripeSubscription(await call('subscription read', { method: 'GET', path: `subscriptions/${encodeURIComponent(subscriptionId)}` }))
222
+
223
+ /** The PaymentIntent an order id names: itself, or the one that paid an invoice. */
224
+ const paymentIntentOf = async (orderId: string): Promise<string> => {
225
+ if (!orderId.startsWith('in_')) return orderId
226
+ const payments = await call<{ data: any[] }>('invoice payment read', { method: 'GET', path: 'invoice_payments', query: { invoice: orderId, status: 'paid', limit: 1 } })
227
+ const intent = idOf(payments.data[0]?.payment?.payment_intent)
228
+ if (!intent) throw new Error(`[nuxt-backend] Stripe invoice ${orderId} has no paid PaymentIntent to refund.`)
229
+ return intent
230
+ }
231
+
232
+ /**
233
+ * The invoice order a PaymentIntent paid, as `order.paid` named it: a
234
+ * refund or a dispute names the PaymentIntent, a subscription's order is
235
+ * its invoice. `null` for a one-time order, whose id is the PaymentIntent.
236
+ */
237
+ const invoiceOrderOf = async (paymentIntent: string): Promise<{ orderId: string, subscriptionId: string | null } | null> => {
238
+ const payments = await call<{ data: any[] }>('invoice payment read', {
239
+ method: 'GET',
240
+ path: 'invoice_payments',
241
+ query: { 'payment[type]': 'payment_intent', 'payment[payment_intent]': paymentIntent, 'limit': 1, 'expand[]': 'data.invoice' },
242
+ })
243
+ const invoice = payments.data[0]?.invoice
244
+ const orderId = idOf(invoice)
245
+ return orderId ? { orderId, subscriptionId: idOf(invoice?.parent?.subscription_details?.subscription) } : null
246
+ }
247
+
248
+ /** A refund or dispute event with the order id `order.paid` gave it. */
249
+ const withOrderIds = async (event: NeutralBillingEvent): Promise<NeutralBillingEvent> => {
250
+ const named = event.type === 'order.refunded' ? event.refund.orderId : event.type === 'order.disputed' ? event.orderId : null
251
+ if (!named?.startsWith('pi_')) return event
252
+ const order = await invoiceOrderOf(named)
253
+ if (!order) return event
254
+ return event.type === 'order.refunded'
255
+ ? { ...event, refund: { ...event.refund, ...order } }
256
+ : { ...event, ...order }
257
+ }
258
+
259
+ return {
260
+ name: 'stripe',
261
+ environment,
262
+ capabilities: PROVIDER_CAPABILITIES.stripe,
263
+ createCheckout,
264
+ customerPortalUrl: async (customerId, options) => {
265
+ const session = await call<{ url: string }>('portal', { method: 'POST', path: 'billing_portal/sessions', body: stripeForm({ customer: customerId, return_url: options?.returnUrl }) })
266
+ return session.url
267
+ },
268
+ getSubscription,
269
+ changePlan: async ({ subscriptionId, productId, proration, quantity }) => {
270
+ const current = await call<any>('subscription read', { method: 'GET', path: `subscriptions/${encodeURIComponent(subscriptionId)}` })
271
+ const item = current.items?.data?.[0]
272
+ if (proration === 'next_period') {
273
+ // Stripe bills a change of interval, or from a free price to a paid
274
+ // one, at once, whatever proration says.
275
+ const price = await call<any>('price read', { method: 'GET', path: `prices/${encodeURIComponent(productId)}` })
276
+ const [from, to] = [item?.price?.recurring, price.recurring]
277
+ if (from?.interval !== to?.interval || (from?.interval_count ?? 1) !== (to?.interval_count ?? 1)) {
278
+ throw new ProviderUnsupportedError('stripe', 'change the billing interval at the next renewal', 'change it with proration "immediately", or cancel at period end and check out the new plan.')
279
+ }
280
+ if (item?.price?.unit_amount === 0 && (num(price.unit_amount) ?? 1) > 0) {
281
+ throw new ProviderUnsupportedError('stripe', 'move a free subscription to a paid price at the next renewal', 'change it with proration "immediately": Stripe bills it at once either way.')
282
+ }
283
+ }
284
+ await call('plan change', {
285
+ method: 'POST',
286
+ path: `subscriptions/${encodeURIComponent(subscriptionId)}`,
287
+ body: stripeForm({
288
+ items: [{ id: item?.id, price: productId, quantity }],
289
+ proration_behavior: proration === 'immediately' ? 'always_invoice' : 'none',
290
+ cancel_at_period_end: false,
291
+ }),
292
+ })
293
+ },
294
+ cancelSubscription: async (subscriptionId, options) => {
295
+ await (options?.immediately
296
+ ? call('cancellation', { method: 'DELETE', path: `subscriptions/${encodeURIComponent(subscriptionId)}` })
297
+ : call('cancellation', { method: 'POST', path: `subscriptions/${encodeURIComponent(subscriptionId)}`, body: stripeForm({ cancel_at_period_end: true }) }))
298
+ },
299
+ uncancelSubscription: async (subscriptionId) => {
300
+ await call('uncancellation', { method: 'POST', path: `subscriptions/${encodeURIComponent(subscriptionId)}`, body: stripeForm({ cancel_at_period_end: false }) })
301
+ },
302
+ pauseSubscription: async () => {
303
+ throw new ProviderUnsupportedError('stripe', 'pause a Managed Payments subscription', 'cancel it at period end instead, or let the customer manage it in the portal.')
304
+ },
305
+ resumeSubscription: async () => {
306
+ throw new ProviderUnsupportedError('stripe', 'resume a Managed Payments subscription', 'a cancelled one is bought again through checkout.')
307
+ },
308
+ refundOrder: async ({ orderId, amount, reason, idempotencyKey }) => {
309
+ const refund = await call('refund', {
310
+ method: 'POST',
311
+ path: 'refunds',
312
+ headers: idempotencyKey ? { 'idempotency-key': idempotencyKey } : undefined,
313
+ body: stripeForm({
314
+ payment_intent: await paymentIntentOf(orderId),
315
+ amount,
316
+ reason: 'requested_by_customer',
317
+ metadata: reason ? { reason: reason.slice(0, 500) } : undefined,
318
+ }),
319
+ })
320
+ return { ...stripeRefund(refund), orderId }
321
+ },
322
+ invoice: async (orderId): Promise<InvoiceAnswer> => {
323
+ if (orderId.startsWith('in_')) {
324
+ const invoice = await call<any>('invoice read', { method: 'GET', path: `invoices/${encodeURIComponent(orderId)}` })
325
+ const url = str(invoice.hosted_invoice_url) ?? str(invoice.invoice_pdf)
326
+ if (!url) throw new Error(`[nuxt-backend] Stripe invoice ${orderId} has no link yet: it is not finalized.`)
327
+ return { kind: 'url', url }
328
+ }
329
+ const intent = await call<any>('receipt read', { method: 'GET', path: `payment_intents/${encodeURIComponent(orderId)}`, query: { 'expand[]': 'latest_charge' } })
330
+ const url = str(intent.latest_charge?.receipt_url)
331
+ if (!url) throw new Error(`[nuxt-backend] Stripe order ${orderId} has no receipt link: Managed Payments emails it from Link.`)
332
+ return { kind: 'url', url }
333
+ },
334
+ verifyWebhook: async (body, headers, secrets, now): Promise<VerifiedDelivery | null> => {
335
+ if (!await verifyStripeSignature(body, headers.get('stripe-signature'), secrets, now)) return null
336
+ const event = JSON.parse(body)
337
+ return { id: String(event.id), event: await withOrderIds(readStripeEvent(event)) }
338
+ },
339
+ verifyCheckoutRedirect: async () => {
340
+ throw new ProviderUnsupportedError('stripe', 'verify the success redirect', 'read the session with {CHECKOUT_SESSION_ID} in the success URL, or wait for order.paid.')
341
+ },
342
+ }
343
+ }
344
+
345
+ /* eslint-enable @typescript-eslint/no-explicit-any */
@@ -0,0 +1,281 @@
1
+ // The provider-neutral seam the commerce providers are built behind: one
2
+ // adapter per merchant of record (Stripe Managed Payments, Dodo Payments,
3
+ // Creem), each answering the same calls in the same neutral words, so the
4
+ // billing layer above them never reads a provider's own shapes. Polar keeps
5
+ // its component-backed path (context.ts); its adapter here covers the same
6
+ // calls so a provider can be swapped by configuration alone.
7
+ //
8
+ // Runtime-neutral: `fetch` and Web Crypto only, no Node built-ins and no SDK,
9
+ // so every adapter runs in the Convex isolate as well as under Node.
10
+
11
+ /** The merchants of record the package sells through. */
12
+ export type BillingProviderName = 'polar' | 'stripe' | 'dodo' | 'creem'
13
+
14
+ /** Every provider, in the order the docs list them. */
15
+ export const BILLING_PROVIDER_NAMES: readonly BillingProviderName[] = ['polar', 'stripe', 'dodo', 'creem']
16
+
17
+ /** The provider's environment: its sandbox (test mode) or production (live mode). */
18
+ export type ProviderEnvironment = 'sandbox' | 'production'
19
+
20
+ /** What one provider can do through its API, for the doctor, the docs and a refusal that names what is missing. */
21
+ export interface ProviderCapabilities {
22
+ /** One-time purchases (a comic issue, a credit pack). */
23
+ oneTime: boolean
24
+ /** Renewing subscriptions. */
25
+ subscriptions: boolean
26
+ /** A hosted page where customers manage payment methods, invoices and cancellation. */
27
+ customerPortal: boolean
28
+ /** Moving a subscription to another product, with proration. */
29
+ changePlan: boolean
30
+ /** Cancelling at period end, and taking that back before it ends. */
31
+ cancelAtPeriodEnd: boolean
32
+ /** Taking a scheduled cancellation back through the API. */
33
+ uncancel: boolean
34
+ /** Pausing and resuming a subscription. */
35
+ pause: boolean
36
+ /** Refunding an order through the API (every provider refunds from its dashboard). */
37
+ refundApi: boolean
38
+ /** A link to, or the bytes of, an order's invoice or receipt. */
39
+ invoices: boolean
40
+ /** Discount or promotion codes at checkout. */
41
+ discountCodes: boolean
42
+ /** The provider signs the query it appends to the success URL, so the success page can trust its ids. */
43
+ signedRedirect: boolean
44
+ /** The provider sells as merchant of record: it is the seller, and files and remits sales tax and VAT. */
45
+ merchantOfRecord: boolean
46
+ /** The provider emails receipts and invoices itself. */
47
+ sendsReceipts: boolean
48
+ }
49
+
50
+ /** A checkout's buyer, as the app knows them. */
51
+ export interface CheckoutCustomer {
52
+ /** The billing entity id the order belongs to (the workspace or the user): stored on the provider as metadata and as the external reference. */
53
+ entityId: string
54
+ email?: string
55
+ name?: string
56
+ /** The provider's own customer id, once one exists: the checkout reuses it instead of making another. */
57
+ providerCustomerId?: string
58
+ }
59
+
60
+ /** What a checkout sells. */
61
+ export interface CheckoutRequest {
62
+ /** The provider's product id (Dodo, Creem, Polar) or price id (Stripe). */
63
+ productId: string
64
+ /** Whether the product renews: Stripe needs to know (`mode`), the others read it off the product. */
65
+ kind: 'one_time' | 'subscription'
66
+ quantity?: number
67
+ customer: CheckoutCustomer
68
+ /** Where the provider sends the buyer after paying. */
69
+ successUrl: string
70
+ /** Where it sends a buyer who leaves (Stripe, Dodo). */
71
+ cancelUrl?: string
72
+ /** A discount or promotion code the buyer entered. */
73
+ discountCode?: string
74
+ /** The checkout page's language, as a BCP 47 tag (Stripe). */
75
+ locale?: string
76
+ /** Free trial length in days, for a subscription (Stripe, Dodo). */
77
+ trialDays?: number
78
+ /**
79
+ * Metadata carried through to the order, the subscription and their
80
+ * events (refund and dispute events carry only the order's or the
81
+ * subscription's id). The adapter adds `entity_id` (and Stripe
82
+ * `product_id`, the price, which its session does not echo) and no consent: to
83
+ * keep the digital-content consent with the sale, record the buyer's
84
+ * explicit acceptance with `recordDigitalContentConsent` and pass
85
+ * `consentMetadata(...)` in here. Keys and values stay short: Stripe caps
86
+ * a key at 40 characters and a value at 500.
87
+ */
88
+ metadata?: Record<string, string>
89
+ /**
90
+ * A key that makes a retried create return the first checkout instead of
91
+ * a second one. Only Stripe honors it (`Idempotency-Key`). Creem keeps
92
+ * it as `request_id`, a reference it echoes, not a dedupe; Dodo takes
93
+ * none. On those two a retry can open a second checkout, and a buyer could
94
+ * pay both: keep the open checkout's URL and send the buyer back to it,
95
+ * and refund a second `order.paid` for the same purchase.
96
+ */
97
+ idempotencyKey?: string
98
+ }
99
+
100
+ /** A created checkout: the page to send the buyer to. */
101
+ export interface CheckoutSession {
102
+ id: string
103
+ url: string
104
+ }
105
+
106
+ /** A subscription's status in neutral words. */
107
+ export type NeutralSubscriptionStatus
108
+ = | 'trialing'
109
+ | 'active'
110
+ | 'past_due'
111
+ | 'paused'
112
+ /** Over: cancelled, expired or failed for good. One ending at period end stays `active` with `cancelAtPeriodEnd`. */
113
+ | 'ended'
114
+ | 'incomplete'
115
+
116
+ /** A subscription as every provider reports it, in the package's words. */
117
+ export interface NeutralSubscription {
118
+ id: string
119
+ customerId: string | null
120
+ /** The billing entity id the checkout carried in its metadata, when it did. */
121
+ entityId: string | null
122
+ productId: string | null
123
+ status: NeutralSubscriptionStatus
124
+ /** Whether it ends at the end of the current period instead of renewing. */
125
+ cancelAtPeriodEnd: boolean
126
+ /** When the current period ends (and the next charge falls), in Unix milliseconds. */
127
+ currentPeriodEnd: number | null
128
+ metadata: Record<string, string>
129
+ }
130
+
131
+ /** An order (a one-time purchase or a subscription's charge) in neutral words. */
132
+ export interface NeutralOrder {
133
+ id: string
134
+ customerId: string | null
135
+ entityId: string | null
136
+ productId: string | null
137
+ subscriptionId: string | null
138
+ /** The amount charged in the currency's minor unit, tax included. */
139
+ amount: number
140
+ /** The tax in it, in the minor unit, when the provider reports it. */
141
+ taxAmount: number | null
142
+ /** ISO 4217, lowercase. */
143
+ currency: string
144
+ metadata: Record<string, string>
145
+ }
146
+
147
+ /** A refund in neutral words. */
148
+ export interface NeutralRefund {
149
+ id: string
150
+ orderId: string | null
151
+ subscriptionId: string | null
152
+ amount: number | null
153
+ currency: string | null
154
+ status: 'pending' | 'succeeded' | 'failed'
155
+ }
156
+
157
+ /**
158
+ * A verified delivery, read into what it means for the app. A provider's
159
+ * event that changes nothing the package keeps reads as `ignored`, with its
160
+ * own type kept for the delivery log.
161
+ */
162
+ export type NeutralBillingEvent
163
+ = | { type: 'order.paid', order: NeutralOrder, providerType: string }
164
+ | { type: 'order.refunded', refund: NeutralRefund, providerType: string }
165
+ | { type: 'order.disputed', orderId: string | null, subscriptionId: string | null, providerType: string }
166
+ | { type: 'subscription.updated', subscription: NeutralSubscription, providerType: string }
167
+ | { type: 'ignored', providerType: string }
168
+
169
+ /** A verified delivery: its id (for the redelivery dedupe) and what it means. */
170
+ export interface VerifiedDelivery {
171
+ id: string
172
+ event: NeutralBillingEvent
173
+ }
174
+
175
+ /** Changing a subscription's product. */
176
+ export interface ChangePlanRequest {
177
+ subscriptionId: string
178
+ productId: string
179
+ /**
180
+ * Charge (or credit) the difference now, or move without billing until
181
+ * the next renewal. Stripe refuses `next_period` for a change of billing
182
+ * interval (monthly to yearly) or from a free price to a paid one, which
183
+ * it would bill at once.
184
+ */
185
+ proration: 'immediately' | 'next_period'
186
+ /** The new quantity. Creem refuses it: its plan change takes a product only. */
187
+ quantity?: number
188
+ }
189
+
190
+ /** Refunding an order, in full or in part. */
191
+ export interface RefundRequest {
192
+ orderId: string
193
+ /** In the minor unit; the whole order without one. */
194
+ amount?: number
195
+ reason?: string
196
+ idempotencyKey?: string
197
+ }
198
+
199
+ /** Where a customer reads an order's invoice: a link, or the PDF itself (Dodo serves the bytes). */
200
+ export type InvoiceAnswer = { kind: 'url', url: string } | { kind: 'pdf', bytes: ArrayBuffer }
201
+
202
+ /** The calls every commerce provider answers. A call its API lacks throws {@link ProviderUnsupportedError}. */
203
+ export interface CommerceProvider {
204
+ readonly name: BillingProviderName
205
+ readonly environment: ProviderEnvironment
206
+ readonly capabilities: ProviderCapabilities
207
+ createCheckout: (request: CheckoutRequest) => Promise<CheckoutSession>
208
+ /** The customer portal's link for one of the provider's customers. */
209
+ customerPortalUrl: (providerCustomerId: string, options?: { returnUrl?: string }) => Promise<string>
210
+ getSubscription: (subscriptionId: string) => Promise<NeutralSubscription>
211
+ changePlan: (request: ChangePlanRequest) => Promise<void>
212
+ /** Cancel now (`immediately`), or at the end of the period. */
213
+ cancelSubscription: (subscriptionId: string, options?: { immediately?: boolean }) => Promise<void>
214
+ /** Take a scheduled cancellation back. */
215
+ uncancelSubscription: (subscriptionId: string) => Promise<void>
216
+ /** Stop billing (and access) until resumed. */
217
+ pauseSubscription: (subscriptionId: string) => Promise<void>
218
+ resumeSubscription: (subscriptionId: string) => Promise<void>
219
+ refundOrder: (request: RefundRequest) => Promise<NeutralRefund>
220
+ invoice: (orderId: string) => Promise<InvoiceAnswer>
221
+ /**
222
+ * Whether the query the provider appended to the success URL is its own
223
+ * (`capabilities.signedRedirect`; the others throw
224
+ * `ProviderUnsupportedError`). It lets a success page trust the ids it
225
+ * shows; access is still granted by `order.paid`, never by the redirect.
226
+ */
227
+ verifyCheckoutRedirect: (search: string | URLSearchParams) => Promise<boolean>
228
+ /**
229
+ * Verify a delivery against the accepted secrets (a rotation accept-list,
230
+ * first entry primary) and read it. `null` when no secret verifies it:
231
+ * the route answers 401 and reads nothing of the body.
232
+ */
233
+ verifyWebhook: (body: string, headers: Headers, secrets: readonly string[], now?: number) => Promise<VerifiedDelivery | null>
234
+ }
235
+
236
+ /**
237
+ * A call a provider's API does not offer: the app shows the dashboard or the portal instead.
238
+ *
239
+ * @experimental
240
+ */
241
+ export class ProviderUnsupportedError extends Error {
242
+ override readonly name = 'ProviderUnsupportedError'
243
+ readonly provider: BillingProviderName
244
+ readonly operation: string
245
+ constructor(provider: BillingProviderName, operation: string, hint: string) {
246
+ super(`[nuxt-backend] ${provider} offers no API to ${operation}: ${hint}`)
247
+ this.provider = provider
248
+ this.operation = operation
249
+ }
250
+ }
251
+
252
+ /**
253
+ * A provider's HTTP answer that was not a success. `statusCode` is read by
254
+ * provider-failure.ts to tell a provider having trouble (408, 429, 5xx) from
255
+ * one refusing the request. The body is never kept: it echoes the request.
256
+ *
257
+ * @experimental
258
+ */
259
+ export class ProviderHttpError extends Error {
260
+ override readonly name = 'ProviderHttpError'
261
+ readonly provider: BillingProviderName
262
+ readonly operation: string
263
+ readonly statusCode: number
264
+ readonly code: string | undefined
265
+ constructor(provider: BillingProviderName, operation: string, statusCode: number, code?: string) {
266
+ super(`[nuxt-backend] ${provider} refused ${operation} (HTTP ${statusCode}${code ? `, ${code}` : ''}).`)
267
+ this.provider = provider
268
+ this.operation = operation
269
+ this.statusCode = statusCode
270
+ this.code = code
271
+ }
272
+ }
273
+
274
+ /** What every adapter is built with. */
275
+ export interface ProviderOptions {
276
+ /** The provider's secret API key (Stripe `sk_…`/`rk_…`, Dodo `dodo_…`, Creem `creem_…`). */
277
+ apiKey: string
278
+ environment: ProviderEnvironment
279
+ /** A `fetch` to call the provider with: the global one by default, a fake in tests. */
280
+ fetch?: typeof fetch
281
+ }
@@ -3,6 +3,7 @@ import { discountsDelete } from '@polar-sh/sdk/funcs/discountsDelete.js'
3
3
  import { discountsList } from '@polar-sh/sdk/funcs/discountsList.js'
4
4
  import { subscriptionsUpdate } from '@polar-sh/sdk/funcs/subscriptionsUpdate.js'
5
5
  import type { Auth } from 'convex/server'
6
+ import { applyCommerceUpdate } from './commerce.js'
6
7
  import { BILLING_ACCESS, type BillingContext, resolveLimit, resolvePage } from './context.js'
7
8
  import { logBackend } from '../../log.js'
8
9
  import { type CatalogDiscounts, refusedDiscount } from './discounts.js'
@@ -77,7 +78,7 @@ const PLAN_CHANGES: Readonly<Record<string, string>> = {
77
78
  }
78
79
 
79
80
  export function createSubscriptions(
80
- { components, provider, cache, requireEntity, requireProviderAccess, requireLaunched, unwrapProvider, throttle, recordEvent }: BillingContext,
81
+ { components, provider, commerce, cache, requireEntity, requireProviderAccess, requireLaunched, unwrapProvider, throttle, recordEvent }: BillingContext,
81
82
  { requirePlan }: PurchaseRules,
82
83
  { isFreeProduct }: Pick<BillingFreePlan, 'isFreeProduct'>,
83
84
  catalogDiscounts: CatalogDiscounts,
@@ -250,6 +251,19 @@ export function createSubscriptions(
250
251
  * (a plan switch) is refused while checkout is paused, right after the
251
252
  * caller's check.
252
253
  */
254
+ /**
255
+ * An adapter's change and its read back, keeping a plan change scheduled
256
+ * before it: an adapter reads back no schedule, so a later uncancel or
257
+ * pause would otherwise record none. A subscription that ended keeps none.
258
+ */
259
+ const commerceUpdated = async (ctx: RunWriteCtx, subscription: SyncedSubscription, payload: SubscriptionUpdatePayload, operation: string) => {
260
+ const updated = await applyCommerceUpdate(commerce!, subscription.id, payload as Parameters<typeof applyCommerceUpdate>[2], operation, subscription.currentPeriodEnd)
261
+ if (updated.pendingUpdate || updated.status === 'canceled') return updated
262
+ const [synced] = await withChanges(ctx, [subscription])
263
+ const pending = synced?.pendingChange
264
+ return pending && pending.productId !== updated.productId ? { ...updated, pendingUpdate: { ...pending, modifiedAt: updated.modifiedAt } } : updated
265
+ }
266
+
253
267
  const applySubscriptionUpdate = async (
254
268
  ctx: RunWriteCtx & { auth?: Auth },
255
269
  operation: string,
@@ -267,11 +281,11 @@ export function createSubscriptions(
267
281
  const subscription = await resolveSubscription(ctx, userId, options.subscriptionId)
268
282
  await refuseFreePlan(ctx, operation, subscription)
269
283
  await refuse?.(subscription)
270
- const result = await subscriptionsUpdate(provider.polar, {
271
- id: subscription.id,
272
- subscriptionUpdate: typeof update === 'function' ? update(subscription) : update,
273
- })
274
- const updated = unwrapProvider(result, operation)
284
+ const payload = typeof update === 'function' ? update(subscription) : update
285
+ // On an adapter provider the same change is the adapter's call, and the response its read back.
286
+ const updated = commerce
287
+ ? await commerceUpdated(ctx, subscription, payload, operation) as unknown as ProviderSubscription
288
+ : unwrapProvider(await subscriptionsUpdate(provider.polar, { id: subscription.id, subscriptionUpdate: payload }), operation)
275
289
  // The response is the subscription as the change left it: a scheduled
276
290
  // plan change or a resume date reads back before its webhook lands.
277
291
  await recordApplied(ctx, userId, updated)