nuxt-backend 0.5.1 → 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 +5 -2
  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 +24 -4
  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.BvKvJ1mo.mjs → nuxt-backend.CM_p0XQE.mjs} +1 -1
  320. package/dist/shared/{nuxt-backend.DRuHg-IQ.mjs → nuxt-backend.C_Y_BtBs.mjs} +2 -2
  321. package/dist/shared/{nuxt-backend.suXOnqOQ.mjs → nuxt-backend.ChvlbHQq.mjs} +42 -7
  322. package/dist/shared/{nuxt-backend.0r1vvS1c.mjs → nuxt-backend.D16peTIt.mjs} +56 -34
  323. package/dist/shared/{nuxt-backend.zY6UDqDu.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 +30 -5
  328. package/skills/nuxt-backend/references/install.md +1 -1
  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,366 @@
1
+ import { type BillingCatalog, type CatalogInterval, type CatalogPlan, freePlanOf, isFreePlan, packPricesByCurrency, planCreditUnits, planPricesByCurrency, planProductKey, planQuotasKey, pricedIntervals, providerTrialOf, QUOTA_METADATA_PREFIX } from '../../catalog.js'
2
+ import { backendError } from '../../errors.js'
3
+ import { billingProviderName, createCommerceProvider, isAdapterProvider } from './providers/index.js'
4
+ import type { BillingProviderName, CommerceProvider, ProviderEnvironment } from './providers/types.js'
5
+ import { ProviderHttpError, ProviderUnsupportedError } from './providers/types.js'
6
+ import type { BillingCatalogIds, CreditMeterConfig } from './types/records.js'
7
+ import type { BillingComponents, CommerceConfig } from './types/setup.js'
8
+
9
+ // Adapter mode: billing on a provider served by the neutral adapters
10
+ // (Stripe Managed Payments, Dodo, Creem), named by `BILLING_PROVIDER`.
11
+ // None of them holds what Polar holds for the package (benefits, meters,
12
+ // customer state), so the catalog definition says what each plan and pack
13
+ // grants, and the app keeps it: the catalog's products are written to the
14
+ // provider component's products table as Polar's sync would write them
15
+ // (every read of pricing, features and quotas works on them unchanged), the
16
+ // subscriptions a provider delivers are written to its subscriptions table,
17
+ // and the credits land on the entitlement cache through the component's
18
+ // grant ledger (`components.backend.commerce`).
19
+
20
+ /** The prefix of an id the app made rather than the provider: the free plan's product, a catalog benefit. */
21
+ export const LOCAL_ID_PREFIX = 'local:'
22
+
23
+ /** Every synthesized row's timestamp: fixed, so a re-sync of an unchanged catalog writes the same row. */
24
+ const CATALOG_EPOCH = '2026-01-01T00:00:00.000Z'
25
+
26
+ /** The organization the synthesized rows name. */
27
+ const LOCAL_ORGANIZATION = 'local'
28
+
29
+ /** The adapter providers. */
30
+ export type AdapterProviderName = Exclude<BillingProviderName, 'polar'>
31
+
32
+ /** Adapter mode as one `setupBilling` call resolved it. */
33
+ export interface CommerceMode {
34
+ name: AdapterProviderName
35
+ config: CommerceConfig
36
+ /** The component's records: customers, orders, grants. */
37
+ refs: NonNullable<BillingComponents['backend']['commerce']>
38
+ /** The adapter, built on first use: a deployment without a key still reads. */
39
+ client: () => CommerceProvider
40
+ /** The ids in force: the deployment's billing environment's. */
41
+ ids: BillingCatalogIds
42
+ }
43
+
44
+ /** The free plan's product id, which no provider holds: the app's own. */
45
+ export function localPlanProductId(plan: string): string {
46
+ return `${LOCAL_ID_PREFIX}plan:${plan}`
47
+ }
48
+
49
+ /** A catalog meter as the credit guard reads it: the catalog key is its id, as no provider meter exists. */
50
+ function localMeters(definition: BillingCatalog): Record<string, CreditMeterConfig> {
51
+ return Object.fromEntries(Object.entries(definition.meters ?? {}).map(([key, meter]) => [key, {
52
+ meterId: key,
53
+ eventName: meter.eventName ?? key,
54
+ // A count meter has no property: a refund of it is refused, as on Polar.
55
+ ...(meter.aggregation === 'count' ? {} : { property: meter.property ?? 'amount' }),
56
+ ...(meter.unit ? { unit: meter.unit } : {}),
57
+ }]))
58
+ }
59
+
60
+ /** Whether the catalog prices its plans and packs in more than one currency. */
61
+ export function pricesManyCurrencies(definition: BillingCatalog): boolean {
62
+ const currency = definition.currency?.toLowerCase()
63
+ const codes = new Set([
64
+ ...Object.values(definition.plans ?? {}).flatMap(plan => planPricesByCurrency(plan, currency).map(([code]) => code)),
65
+ ...Object.values(definition.packs ?? {}).flatMap(pack => packPricesByCurrency(pack, currency).map(([code]) => code)),
66
+ ].filter(Boolean))
67
+ return codes.size > 1
68
+ }
69
+
70
+ /** The fallback currency, written as billing sync writes it: for a catalog that prices more than one. */
71
+ function currencyOf(definition: BillingCatalog): string | undefined {
72
+ return pricesManyCurrencies(definition) ? definition.currency?.toLowerCase() : undefined
73
+ }
74
+
75
+ /**
76
+ * The generated id map's shape for adapter mode, from the catalog and the
77
+ * provider ids the app named: what `billing sync` writes for Polar. The
78
+ * free plan gets a local product; a product the app named no id for is
79
+ * left out, so it is never sold.
80
+ *
81
+ * @internal
82
+ */
83
+ export function adapterCatalogIds(definition: BillingCatalog, providerIds: Readonly<Record<string, string>>): BillingCatalogIds {
84
+ const [free, freePlan] = freePlanOf(definition) ?? []
85
+ const { products, plans } = planIds(definition, providerIds, free)
86
+ const packs = Object.keys(definition.packs ?? {}).filter(key => providerIds[key])
87
+ for (const key of packs) products[key] = providerIds[key]!
88
+ const retired = Object.entries(definition.plans ?? {}).filter(([, plan]) => plan.retired).map(([key]) => key)
89
+ return {
90
+ products,
91
+ plans,
92
+ ...(retired.length > 0 ? { retired } : {}),
93
+ ...(packs.length > 0 ? { packs } : {}),
94
+ meters: localMeters(definition),
95
+ ...optionalIds(definition, free, freePlan),
96
+ }
97
+ }
98
+
99
+ /** Each plan's product ids by interval: the free plan's local one, every other's as the app named them. */
100
+ function planIds(definition: BillingCatalog, providerIds: Readonly<Record<string, string>>, free: string | undefined) {
101
+ const products: Record<string, string> = {}
102
+ const plans: NonNullable<BillingCatalogIds['plans']> = {}
103
+ for (const [key, plan] of Object.entries(definition.plans ?? {})) {
104
+ const named = key === free
105
+ ? [['month', localPlanProductId(key)] as const]
106
+ : pricedIntervals(plan).flatMap(interval => providerIds[planProductKey(key, interval)] ? [[interval, providerIds[planProductKey(key, interval)]!] as const] : [])
107
+ for (const [interval, id] of named) {
108
+ products[key === free ? key : planProductKey(key, interval)] = id
109
+ plans[key] = { ...plans[key], [interval]: id }
110
+ }
111
+ }
112
+ return { products, plans }
113
+ }
114
+
115
+ /** The id map's entries a catalog may leave out: the quotas, the free plan and its welcome credits, the fallback currency. */
116
+ function optionalIds(definition: BillingCatalog, free: string | undefined, freePlan: CatalogPlan | undefined): Partial<BillingCatalogIds> {
117
+ const quotas = Object.entries(definition.quotas ?? {})
118
+ const welcome = freePlan?.credits?.once && typeof freePlan.credits.units === 'number' ? { meter: freePlan.credits.meter, units: freePlan.credits.units } : undefined
119
+ const currency = currencyOf(definition)
120
+ return {
121
+ ...(quotas.length > 0 ? { quotas: Object.fromEntries(quotas.map(([key, { description }]) => [key, description])) } : {}),
122
+ ...(free ? { free } : {}),
123
+ // Welcome credits are no benefit: the runtime grants them once, as the plan first starts.
124
+ ...(welcome ? { welcome } : {}),
125
+ ...(currency ? { currency } : {}),
126
+ }
127
+ }
128
+
129
+ /** A benefit row as the provider component's products table keeps one. */
130
+ function benefitRow(id: string, type: string, description: string, metadata: Record<string, string | number | boolean>, properties: Record<string, unknown> = {}) {
131
+ return { id, createdAt: CATALOG_EPOCH, modifiedAt: CATALOG_EPOCH, type, description, selectable: false, deletable: false, organizationId: LOCAL_ORGANIZATION, metadata, properties }
132
+ }
133
+
134
+ /** The benefits a plan's product at `interval` carries: its features, its quotas, its credit grant. */
135
+ function planBenefits(definition: BillingCatalog, key: string, plan: CatalogPlan, interval: CatalogInterval, productKey: string) {
136
+ const benefits = (plan.features ?? []).map(feature => benefitRow(`${LOCAL_ID_PREFIX}feature:${feature}`, 'feature_flag', definition.features?.[feature]?.description ?? feature, { key: feature }))
137
+ const quotas = Object.entries(plan.quotas ?? {})
138
+ if (quotas.length > 0) {
139
+ benefits.push(benefitRow(`${LOCAL_ID_PREFIX}quotas:${key}`, 'feature_flag', `${plan.name} limits`, { key: planQuotasKey(key), ...Object.fromEntries(quotas.map(([quota, limit]) => [`${QUOTA_METADATA_PREFIX}${quota}`, limit])) }))
140
+ }
141
+ // Welcome credits (`once`) are the runtime's, never a grant every cycle.
142
+ const grantInterval = interval === 'year' && plan.meterCycle === 'month' ? 'month' : interval
143
+ const units = plan.credits && !plan.credits.once ? planCreditUnits(plan.credits, grantInterval) : undefined
144
+ if (plan.credits && units) {
145
+ benefits.push(benefitRow(`${LOCAL_ID_PREFIX}credits:${productKey}`, 'meter_credit', `${units} credits`, { key: `${productKey}-credits` }, { units, rollover: plan.credits.rollover ?? false, meterId: plan.credits.meter }))
146
+ }
147
+ return benefits
148
+ }
149
+
150
+ /** A price row of a synthesized product. */
151
+ function priceRow(productId: string, currency: string, amount: number, interval: CatalogInterval | null) {
152
+ return {
153
+ id: `${productId}:${currency}`,
154
+ createdAt: CATALOG_EPOCH,
155
+ modifiedAt: CATALOG_EPOCH,
156
+ amountType: amount === 0 ? 'free' : 'fixed',
157
+ isArchived: false,
158
+ productId,
159
+ priceCurrency: currency,
160
+ priceAmount: amount,
161
+ type: interval ? 'recurring' : 'one_time',
162
+ recurringInterval: interval,
163
+ }
164
+ }
165
+
166
+ /** A product row with the fields every synthesized one shares. */
167
+ function productRow(id: string, fields: { name: string, description?: string, interval: CatalogInterval | null, archived: boolean, metadata: Record<string, string>, prices: ReturnType<typeof priceRow>[], benefits: ReturnType<typeof benefitRow>[], trial?: { interval: string, count?: number } }) {
168
+ return {
169
+ id,
170
+ organizationId: LOCAL_ORGANIZATION,
171
+ name: fields.name,
172
+ description: fields.description ?? null,
173
+ isRecurring: fields.interval !== null,
174
+ isArchived: fields.archived,
175
+ createdAt: CATALOG_EPOCH,
176
+ modifiedAt: CATALOG_EPOCH,
177
+ recurringInterval: fields.interval,
178
+ metadata: fields.metadata,
179
+ trialInterval: fields.trial?.interval ?? null,
180
+ trialIntervalCount: fields.trial ? fields.trial.count ?? 1 : null,
181
+ prices: fields.prices,
182
+ benefits: fields.benefits,
183
+ medias: [],
184
+ }
185
+ }
186
+
187
+ /**
188
+ * The catalog's products as the provider component's products table keeps
189
+ * them, by the ids in force: what pricing, features and quotas read. Each
190
+ * product a plan or pack has an id for; prices in every currency the
191
+ * catalog names.
192
+ *
193
+ * @internal
194
+ */
195
+ export function catalogProductRows(definition: BillingCatalog, ids: BillingCatalogIds): Array<ReturnType<typeof productRow>> {
196
+ const plans = Object.entries(definition.plans ?? {}).flatMap(([key, plan]) => planRows(definition, ids, key, plan))
197
+ const packs = (ids.packs ?? []).flatMap((key) => {
198
+ const pack = definition.packs?.[key]
199
+ const id = ids.products?.[key]
200
+ return pack && id ? [packRow(definition, key, pack, id)] : []
201
+ })
202
+ return [...plans, ...packs]
203
+ }
204
+
205
+ /** A plan's product rows, one per interval it has an id for. */
206
+ function planRows(definition: BillingCatalog, ids: BillingCatalogIds, key: string, plan: CatalogPlan) {
207
+ const trial = isFreePlan(plan) ? undefined : providerTrialOf(plan.trial)
208
+ return (Object.entries(ids.plans?.[key] ?? {}) as Array<[CatalogInterval, string]>).map(([interval, id]) => {
209
+ const productKey = planProductKey(key, interval)
210
+ const prices = planPricesByCurrency(plan, definition.currency).flatMap(([currency, amounts]) => typeof amounts[interval] === 'number' ? [priceRow(id, currency ?? 'usd', amounts[interval], interval)] : [])
211
+ return productRow(id, { name: plan.name, description: plan.description, interval, archived: plan.retired === true, metadata: { key: productKey }, prices, benefits: planBenefits(definition, key, plan, interval, productKey), ...(trial ? { trial } : {}) })
212
+ })
213
+ }
214
+
215
+ /** A pack's product row: one-time, its credits kept. */
216
+ function packRow(definition: BillingCatalog, key: string, pack: NonNullable<BillingCatalog['packs']>[string], id: string) {
217
+ const prices = packPricesByCurrency(pack, definition.currency).map(([currency, amount]) => priceRow(id, currency ?? 'usd', amount, null))
218
+ const credits = benefitRow(`${LOCAL_ID_PREFIX}credits:${key}`, 'meter_credit', `${pack.credits.units} credits`, { key: `${key}-credits` }, { units: pack.credits.units, rollover: pack.credits.rollover ?? true, meterId: pack.credits.meter })
219
+ return productRow(id, { name: pack.name, description: pack.description, interval: null, archived: false, metadata: { key }, prices, benefits: [credits] })
220
+ }
221
+
222
+ /** What a catalog product id sells: a plan at an interval, a pack, or nothing of the catalog. */
223
+ export type CatalogProduct = { kind: 'plan', key: string, plan: CatalogPlan, interval: CatalogInterval } | { kind: 'pack', key: string } | null
224
+
225
+ /** The catalog product an id names, by the ids in force. */
226
+ export function catalogProductOf(definition: BillingCatalog, ids: BillingCatalogIds, productId: string | null | undefined): CatalogProduct {
227
+ if (!productId) return null
228
+ for (const [key, prices] of Object.entries(ids.plans ?? {})) {
229
+ for (const [interval, id] of Object.entries(prices ?? {})) {
230
+ if (id === productId && definition.plans?.[key]) return { kind: 'plan', key, plan: definition.plans[key], interval: interval as CatalogInterval }
231
+ }
232
+ }
233
+ const pack = (ids.packs ?? []).find(key => ids.products?.[key] === productId)
234
+ return pack ? { kind: 'pack', key: pack } : null
235
+ }
236
+
237
+ /**
238
+ * What an adapter's refusal reads as at the package boundary, like a
239
+ * Polar SDK error through `unwrapProvider`: `unavailable`, reason
240
+ * `provider_unsupported` for a call the provider has no API for (its hint
241
+ * kept, which names what to do instead), else `provider_refused`.
242
+ */
243
+ export function commerceFailure(error: unknown, operation: string): Error {
244
+ if (error instanceof ProviderUnsupportedError) {
245
+ return backendError('unavailable', { service: 'billing', reason: 'provider_unsupported' }, error.message)
246
+ }
247
+ if (error instanceof ProviderHttpError || error instanceof TypeError) {
248
+ return backendError('unavailable', { service: 'billing', reason: 'provider_refused' }, `[nuxt-backend] Billing is temporarily unavailable — the provider refused the ${operation}. Try again shortly.`)
249
+ }
250
+ return error instanceof Error ? error : new Error(String(error))
251
+ }
252
+
253
+ /** Run one adapter call, its failure turned into the package's refusal (see {@link commerceFailure}). */
254
+ export async function commerceCall<T>(operation: string, run: () => Promise<T>): Promise<T> {
255
+ try {
256
+ return await run()
257
+ }
258
+ catch (error) {
259
+ throw commerceFailure(error, operation)
260
+ }
261
+ }
262
+
263
+ /** The refusal of a feature only Polar serves, on an adapter provider. */
264
+ export function polarOnly(name: AdapterProviderName, what: string): Error {
265
+ return backendError('unavailable', { service: 'billing', reason: 'provider_unsupported' }, `[nuxt-backend] Billing: ${what} is Polar's for now — ${name} billing does not offer it.`)
266
+ }
267
+
268
+ /**
269
+ * The Polar SDK client in adapter mode: any use of it is refused (see
270
+ * {@link polarOnly}), so a path the adapters do not serve yet (gifts,
271
+ * passes, discounts, revenue, usage history, rewards) fails clearly
272
+ * instead of calling Polar with a key of another provider.
273
+ */
274
+ export function refusingPolarClient<T extends object>(name: AdapterProviderName): T {
275
+ return new Proxy({} as T, {
276
+ get(_target, property) {
277
+ // Promise resolution and inspection probe these: answer them as an object would.
278
+ if (property === 'then' || typeof property === 'symbol') return undefined
279
+ throw polarOnly(name, 'this billing feature')
280
+ },
281
+ })
282
+ }
283
+
284
+ /**
285
+ * Adapter mode for one `setupBilling` call, or `null` on Polar. An adapter
286
+ * provider without `commerce` config, or on a component without its
287
+ * records, is a setup error, said at once.
288
+ */
289
+ export function commerceModeOf(components: BillingComponents, config: { commerce?: CommerceConfig }, provider: string | undefined, environment: ProviderEnvironment, accessToken: string | undefined): CommerceMode | null {
290
+ const name = billingProviderName(provider)
291
+ if (!isAdapterProvider(name)) return null
292
+ if (!config.commerce?.definition) {
293
+ throw new TypeError(`[nuxt-backend] setupBilling: BILLING_PROVIDER is ${name}, which needs \`commerce: { definition, products }\` — the catalog (billing.catalog.ts) and ${name}'s id for each product.`)
294
+ }
295
+ const refs = components.backend.commerce
296
+ if (!refs) throw new TypeError(`[nuxt-backend] setupBilling: BILLING_PROVIDER is ${name}, and this backend component has no commerce records — update nuxt-backend.`)
297
+ const commerce = config.commerce
298
+ let client: CommerceProvider | undefined
299
+ return {
300
+ name,
301
+ config: commerce,
302
+ refs,
303
+ client: () => client ??= createCommerceProvider(name, { apiKey: accessToken ?? '', environment, fetch: (input, init) => globalThis.fetch(input, init) }),
304
+ ids: adapterCatalogIds(commerce.definition, commerce.products[environment] ?? {}),
305
+ }
306
+ }
307
+
308
+ /** A lifecycle change as the Polar SDK's `subscriptions.update` takes it: the arms adapter mode reads. */
309
+ interface LifecycleUpdate {
310
+ productId?: string | null
311
+ prorationBehavior?: string | null
312
+ cancelAtPeriodEnd?: boolean | null
313
+ revoke?: boolean | null
314
+ pendingUpdate?: null
315
+ pauseAtPeriodEnd?: boolean | null
316
+ resumesAt?: Date | string | null
317
+ resume?: boolean | null
318
+ discountId?: string | null
319
+ }
320
+
321
+ /**
322
+ * Make one lifecycle change at an adapter provider, as Polar's update arm
323
+ * names it, and answer the subscription as the provider now has it, in the
324
+ * shape a lifecycle caller reads (`endsAt`, `currentPeriodEnd` as dates).
325
+ * An arm the adapters have no call for (a scheduled change's removal, a
326
+ * discount, a pause that resumes on a date) is refused as Polar's. A plan
327
+ * change for the next period answers the change it scheduled, which the
328
+ * read back does not show, at the period's end (the synced row's, where the
329
+ * read back has none).
330
+ */
331
+ export async function applyCommerceUpdate(mode: CommerceMode, subscriptionId: string, update: LifecycleUpdate, operation: string, syncedPeriodEnd?: unknown) {
332
+ const client = mode.client()
333
+ await commerceCall(operation, async () => {
334
+ if ('pendingUpdate' in update) throw polarOnly(mode.name, 'taking back a scheduled plan change')
335
+ if ('discountId' in update) throw polarOnly(mode.name, 'a discount on a subscription')
336
+ if (update.pauseAtPeriodEnd && update.resumesAt) throw polarOnly(mode.name, 'a pause that resumes on a date')
337
+ if (update.productId) {
338
+ await client.changePlan({ subscriptionId, productId: update.productId, proration: update.prorationBehavior === 'next_period' ? 'next_period' : 'immediately' })
339
+ }
340
+ else if (update.revoke) await client.cancelSubscription(subscriptionId, { immediately: true })
341
+ else if (update.cancelAtPeriodEnd === true) await client.cancelSubscription(subscriptionId)
342
+ else if (update.cancelAtPeriodEnd === false) await client.uncancelSubscription(subscriptionId)
343
+ else if (update.pauseAtPeriodEnd) await client.pauseSubscription(subscriptionId)
344
+ else if (update.resume) await client.resumeSubscription(subscriptionId)
345
+ else throw polarOnly(mode.name, operation)
346
+ })
347
+ const now = new Date()
348
+ // Read back for the caller; the provider's webhook brings the same into the synced table.
349
+ const read = await commerceCall(operation, () => client.getSubscription(subscriptionId))
350
+ const periodEnd = read.currentPeriodEnd === null ? null : new Date(read.currentPeriodEnd)
351
+ // A read back without its period's end schedules the change at the end the synced row knows.
352
+ const synced = typeof syncedPeriodEnd === 'string' || syncedPeriodEnd instanceof Date ? new Date(syncedPeriodEnd) : null
353
+ const appliesAt = periodEnd ?? (synced && Number.isFinite(synced.getTime()) ? synced : null)
354
+ const scheduled = update.productId && update.prorationBehavior === 'next_period' && read.productId !== update.productId && appliesAt
355
+ return {
356
+ id: read.id,
357
+ productId: read.productId,
358
+ status: read.status === 'ended' ? 'canceled' : read.status,
359
+ cancelAtPeriodEnd: read.cancelAtPeriodEnd,
360
+ currentPeriodEnd: periodEnd,
361
+ endsAt: read.status === 'ended' ? now : read.cancelAtPeriodEnd ? periodEnd : null,
362
+ createdAt: now,
363
+ modifiedAt: now,
364
+ ...(scheduled ? { pendingUpdate: { productId: update.productId, appliesAt, modifiedAt: now } } : {}),
365
+ }
366
+ }
@@ -5,6 +5,7 @@ import { type BillingLaunch, billingLaunch } from '../../billing-launch.js'
5
5
  import { BILLING_MANAGER_ROLES, RECENT_SIGN_IN_SECONDS } from '../../constants.js'
6
6
  import { type AdapterFindOne, type CallerRule, callerRefusal, createAccessReads, hasAnyRole, refuseCaller, refuseStaleSignIn, sandboxAdminRefusal } from '../access.js'
7
7
  import { createBillingActivity, type RecordBillingEvent } from './activity.js'
8
+ import { catalogProductRows, type CommerceMode, commerceModeOf, refusingPolarClient } from './commerce.js'
8
9
  import { syncProviderProducts } from './provider-events.js'
9
10
  import { markPassing } from './provider-failure.js'
10
11
  import { markRateLimited } from './rate-limit.js'
@@ -159,6 +160,13 @@ export interface BillingContext {
159
160
  /** The account as the user table holds it now (role, ban), read once per call; `null` once it is deleted. */
160
161
  account: (ctx: RunQueryCtx, userId: string) => Promise<{ role: string, banned: boolean } | null>
161
162
  provider: Polar
163
+ /**
164
+ * Adapter mode (`BILLING_PROVIDER` stripe, dodo or creem): the adapter,
165
+ * the component's records and the ids in force; `null` on Polar. In
166
+ * adapter mode `provider` reads the component's tables only: its SDK
167
+ * client refuses every call.
168
+ */
169
+ commerce: CommerceMode | null
162
170
  cache: BillingComponents['backend']['billing']
163
171
  providerLib: ProviderLibRefs['lib']
164
172
  webhookLog: BillingComponents['backend']['webhooks']
@@ -203,10 +211,13 @@ export function createBillingContext(components: BillingComponents, config: Setu
203
211
  const environment = billingEnvironment(backendEnvironment())
204
212
  const accessToken = config.accessToken ?? readEnv('BILLING_ACCESS_TOKEN')
205
213
  const webhookSecret = config.webhookSecret ?? readEnv('BILLING_WEBHOOK_SECRET')
214
+ // A provider on the neutral adapters keeps nothing of the catalog: its
215
+ // definition and the provider's ids stand in for billing sync's map.
216
+ const commerce = commerceModeOf(components, config, readEnv('BILLING_PROVIDER'), environment, accessToken)
206
217
 
207
218
  // The generated catalog (billing.generated.ts) supplies the environment's
208
219
  // product ids and named credit meters; explicit config wins over it.
209
- const catalogIds = config.catalog?.[environment]
220
+ const catalogIds = commerce ? commerce.ids : config.catalog?.[environment]
210
221
  const products = config.products ?? catalogIds?.products
211
222
  const retiredProductIds = new Set((catalogIds?.retired ?? []).flatMap(key => Object.values(catalogIds?.plans?.[key] ?? {})))
212
223
  const freePlan = freePlanIds(catalogIds)
@@ -350,6 +361,7 @@ export function createBillingContext(components: BillingComponents, config: Setu
350
361
  organizationToken: accessToken,
351
362
  server: environment,
352
363
  })
364
+ if (commerce) provider.polar = refusingPolarClient(commerce.name)
353
365
  const cache = components.backend.billing
354
366
  const providerLib = (components.polar as unknown as ProviderLibRefs).lib
355
367
  const webhookLog = components.backend.webhooks
@@ -502,6 +514,7 @@ export function createBillingContext(components: BillingComponents, config: Setu
502
514
  memberRole: (ctx, userId, workspaceId) => reads.memberRole(ctx, userId, workspaceId),
503
515
  account: (ctx, userId) => reads.account(ctx, userId),
504
516
  provider,
517
+ commerce,
505
518
  cache,
506
519
  providerLib,
507
520
  webhookLog,
@@ -509,7 +522,11 @@ export function createBillingContext(components: BillingComponents, config: Setu
509
522
  launch,
510
523
  requireLaunched,
511
524
  unwrapProvider,
512
- syncProducts: ctx => syncProviderProducts(ctx, async page => unwrapProvider(await productsList(provider.polar, { page, limit: 100 }), 'product sync'), providerLib.updateProduct),
525
+ syncProducts: commerce
526
+ ? async (ctx) => {
527
+ for (const product of catalogProductRows(commerce.config.definition, commerce.ids)) await ctx.runMutation(providerLib.updateProduct, { product })
528
+ }
529
+ : ctx => syncProviderProducts(ctx, async page => unwrapProvider(await productsList(provider.polar, { page, limit: 100 }), 'product sync'), providerLib.updateProduct),
513
530
  throttle,
514
531
  customerOwner,
515
532
  requireAdmin,
@@ -27,7 +27,7 @@ function holdArgs(hold: number | undefined): { hold?: number } {
27
27
 
28
28
  /** Prepaid credits: reserve, settle, release, spend and refund. */
29
29
  export function createCredits(
30
- { provider, cache, resolveMeter, requireEntity, unwrapProvider }: BillingContext,
30
+ { provider, commerce, cache, resolveMeter, requireEntity, unwrapProvider }: BillingContext,
31
31
  { refreshEntitlements }: BillingEntitlements,
32
32
  ) {
33
33
  /**
@@ -100,34 +100,18 @@ export function createCredits(
100
100
  return { entityId, externalId, reserved: true, meter: meter.key, meterId: meter.meterId, value }
101
101
  }
102
102
 
103
- const settleSpend: Billing['settleSpend'] = async (ctx, reservation, options = {}) => {
104
- // A reservation is plain data that crosses function boundaries, so it is
105
- // checked like any other input before an event is ingested on its word.
106
- const reserved = requireCreditAmount(reservation.value, 'settleSpend: the reservation\'s `value`')
107
- const final = options.finalAmount === undefined
108
- ? reserved
109
- : requireCreditAmount(options.finalAmount, 'settleSpend: `finalAmount`', { orZero: true })
110
- const meter = resolveMeter(reservation)
111
- const name = options.name ?? meter?.eventName ?? meter?.key
112
- if (!name) {
113
- throw new Error('[nuxt-backend] settleSpend: pass `name`, or a configured `meter` whose key/eventName names the event.')
114
- }
115
- // The estimate is the ceiling: settling above it would be a second,
116
- // unguarded debit — the reservation is what made the spend safe against a
117
- // concurrent one.
118
- const value = Math.min(final, reserved)
119
- if (value === 0) {
120
- // Nothing was spent, so there is no event to ingest (on a count meter
121
- // one would bill a credit); closing at zero hands the reservation back.
122
- if (reservation.reserved) await ctx.runMutation(cache.settle, { userId: reservation.entityId, externalId: reservation.externalId, finalAmount: 0 })
123
- return
124
- }
103
+ /**
104
+ * Report a settled spend to the provider as its usage event, by the
105
+ * entity's id. A refused report releases the reservation (or keeps
106
+ * `value` held, with `keepReservation`) and throws.
107
+ */
108
+ const ingestSpend = async (ctx: Parameters<Billing['settleSpend']>[0], reservation: Parameters<Billing['settleSpend']>[1], { name, value, property }: { name: string, value: number, property?: string }, options: NonNullable<Parameters<Billing['settleSpend']>[2]>): Promise<void> => {
125
109
  try {
126
110
  if (!await provider.getCustomerByUserId(ctx as unknown as ProviderCtx, reservation.entityId)) {
127
111
  throw backendError('not_ready', { reason: 'no_customer' }, `[nuxt-backend] No billing customer for ${reservation.entityId}. Start a checkout first.`)
128
112
  }
129
- const metadata = meter?.property
130
- ? { ...options.metadata, [meter.property]: value }
113
+ const metadata = property
114
+ ? { ...options.metadata, [property]: value }
131
115
  : options.metadata
132
116
  // By the entity's id, never a member's: usage counts against the customer.
133
117
  const events: EventsIngestRequest['events'] = [{
@@ -146,6 +130,32 @@ export function createCredits(
146
130
  if (reservation.reserved) await ctx.runMutation(cache.release, { userId: reservation.entityId, externalId: reservation.externalId, ...(options.keepReservation ? { keep: value } : {}) })
147
131
  throw error
148
132
  }
133
+ }
134
+
135
+ const settleSpend: Billing['settleSpend'] = async (ctx, reservation, options = {}) => {
136
+ // A reservation is plain data that crosses function boundaries, so it is
137
+ // checked like any other input before an event is ingested on its word.
138
+ const reserved = requireCreditAmount(reservation.value, 'settleSpend: the reservation\'s `value`')
139
+ const final = options.finalAmount === undefined
140
+ ? reserved
141
+ : requireCreditAmount(options.finalAmount, 'settleSpend: `finalAmount`', { orZero: true })
142
+ const meter = resolveMeter(reservation)
143
+ const name = options.name ?? meter?.eventName ?? meter?.key
144
+ if (!name) {
145
+ throw new Error('[nuxt-backend] settleSpend: pass `name`, or a configured `meter` whose key/eventName names the event.')
146
+ }
147
+ // The estimate is the ceiling: settling above it would be a second,
148
+ // unguarded debit — the reservation is what made the spend safe against a
149
+ // concurrent one.
150
+ const value = Math.min(final, reserved)
151
+ if (value === 0) {
152
+ // Nothing was spent, so there is no event to ingest (on a count meter
153
+ // one would bill a credit); closing at zero hands the reservation back.
154
+ if (reservation.reserved) await ctx.runMutation(cache.settle, { userId: reservation.entityId, externalId: reservation.externalId, finalAmount: 0 })
155
+ return
156
+ }
157
+ // On an adapter provider the cache is the record: closing the reservation is the spend.
158
+ if (!commerce) await ingestSpend(ctx, reservation, { name, value, property: meter?.property }, options)
149
159
  if (reservation.reserved) await closeSpent(ctx, reservation, value)
150
160
  }
151
161
 
@@ -154,12 +164,15 @@ export function createCredits(
154
164
  * was gone by the time the event landed (an earlier attempt whose ingest
155
165
  * failed released it, or it lapsed) is taken from the cached balance
156
166
  * again: the provider consumed the credits all the same, and the cache is
157
- * the only spend guard.
167
+ * the only spend guard. On an adapter provider no provider took an event:
168
+ * a reservation already gone was settled before (the same spend, settled
169
+ * twice), released (nothing is charged twice), or lapsed (its debit stays
170
+ * spent), so nothing is taken again.
158
171
  */
159
172
  const closeSpent = async (ctx: RunWriteCtx, reservation: SpendReservation, value: number): Promise<void> => {
160
173
  const keys = { userId: reservation.entityId, externalId: reservation.externalId }
161
174
  const closed = await ctx.runMutation(cache.finalize, { ...keys, finalAmount: value })
162
- if (closed.settled || !reservation.meterId) return
175
+ if (closed.settled || !reservation.meterId || commerce) return
163
176
  const taken = await ctx.runMutation(cache.debit, { ...keys, meterId: reservation.meterId, amount: value, allowOverage: true })
164
177
  if (taken.ok) await ctx.runMutation(cache.settle, { ...keys, finalAmount: value })
165
178
  }
@@ -194,6 +207,11 @@ export function createCredits(
194
207
  `[nuxt-backend] refundCredits: meter '${event.meter}' has no \`property\` (count meter) — only sum meters can be refunded.`,
195
208
  )
196
209
  }
210
+ // On an adapter provider the credit is a grant of the ledger, once per key.
211
+ if (commerce) {
212
+ const granted = await ctx.runMutation(commerce.refs.grantCredits, { userId: entityId, meterId: meter.meterId, amount: value, externalId: `refund:${event.externalId ?? crypto.randomUUID()}`, source: 'grant', rollover: true })
213
+ return granted.granted
214
+ }
197
215
  if (!await provider.getCustomerByUserId(ctx as unknown as ProviderCtx, entityId)) {
198
216
  throw backendError('not_ready', { reason: 'no_customer' }, `[nuxt-backend] No billing customer for ${entityId}.`)
199
217
  }
@@ -220,6 +238,8 @@ export function createCredits(
220
238
  }
221
239
 
222
240
  const reportCost: Billing['reportCost'] = async (ctx, report) => {
241
+ // Costs are reported to Polar's cost insights; an adapter provider has none.
242
+ if (commerce) return
223
243
  if (!await provider.getCustomerByUserId(ctx as unknown as ProviderCtx, report.userId)) return
224
244
  const llm = report.llm
225
245
  const metadata = {
@@ -6,6 +6,7 @@ import { customersList } from '@polar-sh/sdk/funcs/customersList.js'
6
6
  import { customersUpdate } from '@polar-sh/sdk/funcs/customersUpdate.js'
7
7
  import { membersListMembers } from '@polar-sh/sdk/funcs/membersListMembers.js'
8
8
  import type { Auth } from 'convex/server'
9
+ import { commerceCall } from './commerce.js'
9
10
  import { BILLING_ACCESS, type BillingContext, isProviderNotFound } from './context.js'
10
11
  import type { PurchaseRules } from './purchase.js'
11
12
  import type { ProviderCtx, RunQueryCtx, RunWriteCtx } from './types/base.js'
@@ -99,7 +100,7 @@ async function callerOf(ctx: { auth?: Auth }): Promise<Caller | null> {
99
100
 
100
101
  /** Find, create and map the provider customer of each billing entity; open its portal. */
101
102
  export function createCustomers(
102
- { billTo, provider, providerLib, cache, requireEntity, requireProviderAccess, unwrapProvider, throttle, customerOwner }: BillingContext,
103
+ { billTo, provider, commerce, providerLib, cache, requireEntity, requireProviderAccess, unwrapProvider, throttle, customerOwner }: BillingContext,
103
104
  { requireTrustedUrl }: PurchaseRules,
104
105
  ) {
105
106
  /** The provider customer the component maps this entity to, or `null`. */
@@ -275,6 +276,11 @@ export function createCustomers(
275
276
  operation: string,
276
277
  onBehalfOf?: Caller,
277
278
  ): Promise<string> => {
279
+ // An adapter provider makes its customer at checkout: the provider component maps the entity to itself.
280
+ if (commerce) {
281
+ await ctx.runMutation(providerLib.insertCustomer, { id: entity.userId, userId: entity.userId })
282
+ return entity.userId
283
+ }
278
284
  const mapped = await mappedCustomer(ctx, entity.userId)
279
285
  if (mapped) return await keyMapped(mapped, entity.userId, operation)
280
286
  const customerId = (await customerByExternalId(entity.userId, operation))?.id
@@ -349,6 +355,14 @@ export function createCustomers(
349
355
  requireProviderAccess('portal session')
350
356
  requireTrustedUrl(options.returnUrl, 'returnUrl')
351
357
  await throttle(ctx, userId, 'portal sessions')
358
+ // On an adapter provider the customer is the one its checkout made, and the portal is the provider's own.
359
+ if (commerce) {
360
+ const providerCustomerId = await ctx.runQuery(commerce.refs.customerOf, { entityId: userId, provider: commerce.name })
361
+ if (!providerCustomerId) {
362
+ throw backendError('not_ready', { reason: 'no_customer' }, '[nuxt-backend] No billing customer yet — the portal opens after a first checkout.')
363
+ }
364
+ return { url: await commerceCall('portal session', () => commerce.client().customerPortalUrl(providerCustomerId, options.returnUrl ? { returnUrl: options.returnUrl } : {})) }
365
+ }
352
366
  const customerId = await mappedCustomer(ctx, userId)
353
367
  if (!customerId) {
354
368
  throw backendError('not_ready', { reason: 'no_customer' }, '[nuxt-backend] No billing customer yet — the portal opens after a first checkout.')
@@ -1,5 +1,6 @@
1
1
  import { benefitsGet } from '@polar-sh/sdk/funcs/benefitsGet.js'
2
2
  import { customersGetStateExternal } from '@polar-sh/sdk/funcs/customersGetStateExternal.js'
3
+ import { createCommerceEntitlements } from './commerce-entitlements.js'
3
4
  import { type BillingContext, isProviderNotFound } from './context.js'
4
5
  import type { BillingCustomers } from './customers.js'
5
6
  import type { RunQueryCtx, RunWriteCtx } from './types/base.js'
@@ -64,9 +65,12 @@ function grantDetails(grant: StateGrant): Pick<EntitlementBenefit, 'licenseKey'
64
65
 
65
66
  /** The entitlement cache: read live from the provider, written to the component, forgotten on erasure. */
66
67
  export function createEntitlements(
67
- { provider, cache, unwrapProvider }: BillingContext,
68
+ context: BillingContext,
68
69
  { keyedCustomer }: Pick<BillingCustomers, 'keyedCustomer'>,
69
70
  ) {
71
+ // Adapter mode keeps no provider customer state: the app's records are the state.
72
+ if (context.commerce) return createCommerceEntitlements(context)
73
+ const { provider, cache, unwrapProvider } = context
70
74
  /**
71
75
  * An entity's customer state, by the entity's id, the customer's external
72
76
  * id. An entity that never paid has no customer, and the provider says so.