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
@@ -1,6 +1,8 @@
1
1
  import type { WebhookEventHandlers } from '@convex-dev/polar'
2
+ import type { ComponentApi } from '../../../components/backend/_generated/component.js'
2
3
  import type { Auth, FunctionReference, GenericActionCtx, GenericDataModel } from 'convex/server'
3
- import type { CatalogInterval } from '../../../catalog.js'
4
+ import type { BillingCatalog, CatalogInterval } from '../../../catalog.js'
5
+ import type { NeutralBillingEvent } from '../providers/types.js'
4
6
  import type { CallerRule } from '../../access.js'
5
7
  import type { ShardedCounter } from '@convex-dev/sharded-counter'
6
8
  import type { Workpool } from '@convex-dev/workpool'
@@ -232,6 +234,12 @@ export interface BillingComponents {
232
234
  consents: {
233
235
  latest: FunctionReference<'query', 'internal', { userId: string, kind: string }, { kind: string, version: string, granted: boolean, at: number } | null>
234
236
  }
237
+ /**
238
+ * The records of a provider on the neutral adapters (`BILLING_PROVIDER`
239
+ * stripe, dodo or creem): customers, orders and credit grants. Absent on
240
+ * a component built before them, which sells through Polar only.
241
+ */
242
+ commerce?: ComponentApi['commerce']
235
243
  /**
236
244
  * What the storage module counts by billing quota key (a holder's files
237
245
  * and bytes): a quota read adds it to the count the app claims itself,
@@ -335,6 +343,32 @@ export interface BillingEntityCtx {
335
343
  * user (`billTo: 'user'`) — so {@link SetupBillingConfig.resolveEntity} is an
336
344
  * override, not required wiring.
337
345
  */
346
+ /**
347
+ * What billing sells through a provider on the neutral adapters: see
348
+ * {@link SetupBillingConfig.commerce}.
349
+ *
350
+ * @experimental
351
+ */
352
+ export interface CommerceConfig {
353
+ /** The catalog, as `billing.catalog.ts` defines it. */
354
+ definition: BillingCatalog
355
+ /**
356
+ * Catalog key → the provider's id for what its checkout sells (a product
357
+ * id, or a price id where the provider sells prices), per billing
358
+ * environment: packs by their key, a plan's monthly price
359
+ * by the plan's key and its yearly one as `<plan>:year`. The free plan
360
+ * needs none: it is the app's own.
361
+ */
362
+ products: Partial<Record<'sandbox' | 'production', Record<string, string>>>
363
+ /**
364
+ * What the app does with each verified event, in neutral words, after
365
+ * the package kept its records: the place for the app's own reaction to
366
+ * a paid order or a subscription's change. It must be idempotent: a
367
+ * provider sends an event again until it gets a 2xx.
368
+ */
369
+ onEvent?: (ctx: RunWriteCtx, event: NeutralBillingEvent, delivery: { id: string }) => Promise<void>
370
+ }
371
+
338
372
  export interface SetupBillingConfig {
339
373
  /**
340
374
  * The app's `setupEmail` instance. A gift's recipient hears of it through
@@ -538,6 +572,34 @@ export interface SetupBillingConfig {
538
572
  * generated file. Explicit `products`/`credits` config wins.
539
573
  */
540
574
  catalog?: Partial<Record<'sandbox' | 'production', BillingCatalogIds | undefined>>
575
+ /**
576
+ * What billing sells through a provider on the neutral adapters, read
577
+ * when `BILLING_PROVIDER` is `stripe`, `dodo` or `creem` (and refused
578
+ * without it there): the catalog itself (`billing.catalog.ts`'s default
579
+ * export), whose plans, packs, features, quotas and credit grants the app
580
+ * keeps where no provider holds them, and the provider's id for each of
581
+ * its products, by catalog key and billing environment. `billing sync`
582
+ * writes Polar's ids only: create the products in the provider's
583
+ * dashboard and name them here.
584
+ *
585
+ * @example
586
+ * ```ts
587
+ * import definition from './billing.catalog'
588
+ *
589
+ * setupBilling(components, {
590
+ * email,
591
+ * commerce: {
592
+ * definition,
593
+ * products: {
594
+ * sandbox: { 'studio': 'price_123', 'studio:year': 'price_456', 'credits100': 'price_789' },
595
+ * },
596
+ * },
597
+ * })
598
+ * ```
599
+ *
600
+ * @experimental
601
+ */
602
+ commerce?: CommerceConfig
541
603
  /**
542
604
  * The billing lifecycle beyond the provider's own: save offers
543
605
  * by cancellation reason for the cancel flow, the abandoned-checkout
@@ -1,4 +1,5 @@
1
1
  import { createCheckout } from './billing/checkout.js'
2
+ import { createCommerceEvents } from './billing/commerce-events.js'
2
3
  import { BILLING_METERS, BILLING_TO, createBillingContext } from './billing/context.js'
3
4
  import { createCredits } from './billing/credits.js'
4
5
  import { createCustomers } from './billing/customers.js'
@@ -79,7 +80,7 @@ export type {
79
80
  Pricing,
80
81
  QuotaUsage,
81
82
  } from './billing/types/records.js'
82
- export type { BillingWebhookEventHandlers, SaveOfferTerms, BillingComponents, BillingEmail, BillingEntity, BillingAccessRule, BillingEntityCtx, EntityProfile, SetupBillingConfig } from './billing/types/setup.js'
83
+ export type { BillingWebhookEventHandlers, SaveOfferTerms, BillingComponents, BillingEmail, BillingEntity, BillingAccessRule, BillingEntityCtx, EntityProfile, SetupBillingConfig, CommerceConfig } from './billing/types/setup.js'
83
84
  export type { AccountBillingErasure, AccountBillingErasureInput, AccountBillingExport, AccountBillingRecord, Billing } from './billing/types/surface.js'
84
85
  export type { BillingAudit } from './billing/activity.js'
85
86
  export type { BillingLifecycle, CancelFlowState, CancelOutcome, BillingConsole, SaveOffer, SaveOfferRule, WithdrawalPeriod } from './billing/types/lifecycle.js'
@@ -88,6 +89,45 @@ export type { MeterUsage, RevenueCancellations, RevenueInterval, RevenueMetric,
88
89
  // Catalog-as-code authoring surface (billing.catalog.ts / `billing sync`).
89
90
  export { type BillingCatalog, type CatalogCreditGrant, type CatalogCurrencyPrices, type CatalogDiscount, type CatalogDiscountDuration, type CatalogDiscountProducts, type CatalogDiscountTerms, type CatalogFeature, type CatalogInterval, type CatalogMeter, type CatalogPack, type CatalogPackPrices, type CatalogPlan, type CatalogPlanCreditGrant, type CatalogPlanGift, type CatalogPlanPrices, type CatalogQuota, defineBillingCatalog, type MeterUnit } from '../catalog.js'
90
91
  export { ALL_BILLING_EVENTS } from './billing/events.js'
92
+
93
+ // The other merchants of record (Stripe Managed Payments, Dodo Payments,
94
+ // Creem), on the provider-neutral adapters: checkout, portal, plan changes,
95
+ // cancellation, refunds, invoices and the guarded webhook route.
96
+ export {
97
+ billingProviderName,
98
+ commerceProviderFromEnv,
99
+ consentFromMetadata,
100
+ consentMetadata,
101
+ createCommerceProvider,
102
+ DIGITAL_CONTENT_CONSENT_TEXT,
103
+ DIGITAL_CONTENT_CONSENT_VERSION,
104
+ PROVIDER_CAPABILITIES,
105
+ ProviderHttpError,
106
+ ProviderUnsupportedError,
107
+ recordDigitalContentConsent,
108
+ webhookSecretsFromEnv,
109
+ } from './billing/providers/index.js'
110
+ export type {
111
+ BillingProviderName,
112
+ ChangePlanRequest,
113
+ CheckoutCustomer,
114
+ CheckoutRequest,
115
+ CheckoutSession,
116
+ CommerceProvider,
117
+ DigitalContentConsent,
118
+ InvoiceAnswer,
119
+ NeutralBillingEvent,
120
+ NeutralOrder,
121
+ NeutralRefund,
122
+ NeutralSubscription,
123
+ NeutralSubscriptionStatus,
124
+ ProviderCapabilities,
125
+ ProviderEnvironment,
126
+ ProviderOptions,
127
+ RefundRequest,
128
+ VerifiedDelivery,
129
+ } from './billing/providers/index.js'
130
+ export { createCommerceWebhookHandler, type CommerceEventHandler, type CommerceWebhookOptions } from './billing/commerce-webhooks.js'
91
131
  export type { BillingLaunch, BillingLaunchReason } from '../billing-launch.js'
92
132
 
93
133
  // The referral program, set up in its own backend file beside billing.
@@ -177,7 +217,10 @@ export function setupBilling(
177
217
  const { giftCheckout, claimGift, getReceivedGifts, getSentGifts, resendGift, changeGiftRecipient, rescheduleGift, cancelGift, runGiftSweep } = gifts
178
218
  const functions = createBillingFunctions(context, entitlements, subscriptions, history, customers, quotas, freePlan, lifecycle, revenue, gifts)
179
219
  const { resyncEntitlements } = createResync(context, entitlements)
180
- const { webhookEvents, webhookHandler } = createWebhooks(context, entitlements, gifts, customers, subscriptions, freePlan, lifecycle, createReferralOrders(context, rewards))
220
+ // Adapter mode: the provider's neutral events and the credit cycle it does not run.
221
+ const commerceEvents = context.commerce ? createCommerceEvents(context, entitlements, customers, freePlan) : null
222
+ if (commerceEvents) freePlan.hooks.localStart = commerceEvents.cycle
223
+ const { webhookEvents, webhookHandler: polarWebhookHandler } = createWebhooks(context, entitlements, gifts, customers, subscriptions, freePlan, lifecycle, createReferralOrders(context, rewards))
181
224
  const { hasFeature, requireFeature, activePlans } = createFeatures(context, pricing)
182
225
  // The counts first: they are found by the grants the cache still holds.
183
226
  const forgetBillingEntity: Billing['forgetEntity'] = async (ctx, userId) => {
@@ -231,7 +274,7 @@ export function setupBilling(
231
274
  getRevenue: functions.getRevenueFn,
232
275
  },
233
276
  webhookEvents,
234
- webhookHandler,
277
+ webhookHandler: commerceEvents ? commerceEvents.webhookHandler : polarWebhookHandler,
235
278
  getCustomerState,
236
279
  checkout,
237
280
  portal: customers.portal,
@@ -86,6 +86,7 @@ export type {
86
86
  TrustedHtml,
87
87
  WaitlistAdmittedEmailData,
88
88
  WaitlistConfirmationEmailData,
89
+ WaitlistFriendJoinedEmailData,
89
90
  WelcomeEmailData,
90
91
  NoticeReceivedEmailData,
91
92
  NoticeDecidedEmailData,
@@ -22,7 +22,7 @@ import {
22
22
  newLinkToken,
23
23
  } from '../access-tickets.js'
24
24
  import { DEFAULT_ADMIN_ROLES, IMPERSONATED_BY_CLAIM } from '../constants.js'
25
- import { DEFAULT_BOOST, statusToken } from '../waitlist-rules.js'
25
+ import { checkedWaitlistRule, statusToken, type WaitlistBoostRule, type WaitlistOptions, type WaitlistRule } from '../waitlist-rules.js'
26
26
  import { readEnv } from '../delivery.js'
27
27
  import { authSecrets, liveSecrets } from '../auth-secrets.js'
28
28
  import { backendError } from '../errors.js'
@@ -296,6 +296,8 @@ export interface Access {
296
296
  /** Whether the caller is an administrator now (a read: no recent sign-in asked). */
297
297
  is: (ctx: AccessCtx, what: string) => Promise<boolean>
298
298
  }
299
+ /** The waitlist's rule, checked (`setupAccess({ waitlist })`): the sign-in gate and setupWaitlist read it. */
300
+ waitlistRule: WaitlistRule
299
301
  }
300
302
  }
301
303
 
@@ -347,6 +349,30 @@ export interface SetupAccessOptions {
347
349
  email?: AccessEmail
348
350
  /** The paths the Nuxt module writes to `paths.generated.ts`: an invitation email links to the sign-in page and the privacy policy there. */
349
351
  paths?: Partial<BackendPaths>
352
+ /**
353
+ * The rule the waitlist's line runs on, in early access. It lives here,
354
+ * not on `setupWaitlist`, because the sign-in page records entries
355
+ * through this access, in code that never loads `backend/waitlist.ts`.
356
+ *
357
+ * - `boost`: how sharing moves people. Each friend who joins through a
358
+ * person's link moves them `perFriend` up the line (ms, a day by
359
+ * default), for up to `cap` friends (10 by default, `null` for no
360
+ * limit); the friend starts `welcome` up (0 by default); `notify` emails
361
+ * the person when a friend joins, at most once a day. `false` turns
362
+ * sharing off.
363
+ * - `place`: `{ rank: false }` keeps a person's position and the size of
364
+ * the list to the administrators: the status page, the sign-in page and
365
+ * the confirmation email show the day they joined, the credit their
366
+ * friends earned and the next wave instead.
367
+ *
368
+ * @example
369
+ * ```ts
370
+ * import { DAY } from 'nuxt-backend/rate-limit'
371
+ *
372
+ * waitlist: { boost: { perFriend: 7 * DAY, cap: null, welcome: 7 * DAY, notify: true }, place: { rank: false } }
373
+ * ```
374
+ */
375
+ waitlist?: WaitlistOptions
350
376
  }
351
377
 
352
378
  /** What "Email them" needs of `setupEmail`'s instance: the layout and words, and the sending rules. */
@@ -388,8 +414,8 @@ interface AccessRefs {
388
414
  consoleRows: FunctionReference<'query', 'internal', Record<string, never>, { invites: AccessInvite[], memberTickets: AccessMemberTicket[], admissions: AccessAdmission[] }>
389
415
  }
390
416
  waitlist: {
391
- verify: FunctionReference<'mutation', 'internal', { email: string, join?: string, locale?: string, boost: { cap: number, days: number } }, { id: string, created: boolean, source: string, referred: boolean, news: boolean }>
392
- place: FunctionReference<'query', 'internal', { id: string }, { position: number | null, total: number, shareCode: string } | null>
417
+ verify: FunctionReference<'mutation', 'internal', { email: string, join?: string, locale?: string, boost: WaitlistBoostRule }, { id: string, created: boolean, status: string, source: string, referred: boolean, news: boolean, sharer?: { id: string, email: string, locale: string | null, friends: number, credit: number } }>
418
+ place: FunctionReference<'query', 'internal', { id: string, rank?: boolean }, { position: number | null, total: number, shareCode: string } | null>
393
419
  }
394
420
  adapter: { findOne: AdapterFindOne }
395
421
  email: { send: FunctionReference<'mutation', 'internal', Record<string, unknown>, string | null> }
@@ -482,6 +508,8 @@ const usedTicket = (row: { ticket: string, label?: string }): { ticket: AccessTi
482
508
  export function setupAccess(components: AccessComponents, options: SetupAccessOptions): Access {
483
509
  const refs = components.backend as AccessRefs
484
510
  const phases = [...(options.phases ?? ACCESS_PHASES)]
511
+ // Checked once, here: the sign-in gate and setupWaitlist both read it.
512
+ const waitlistRule = checkedWaitlistRule(options.waitlist)
485
513
  const domains = options.domains ?? []
486
514
  // A workspace invitation's share of sign-ups per inviter; 0 turns them off as tickets.
487
515
  const perInviter = options.workspaceInvitations === false ? 0 : (options.workspaceInvitations ?? WORKSPACE_INVITATIONS)
@@ -636,17 +664,26 @@ export function setupAccess(components: AccessComponents, options: SetupAccessOp
636
664
 
637
665
  const waitlist: AccessGate['waitlist'] = phases.includes('early-access')
638
666
  ? async (ctx, { email, locale, join }) => {
639
- const entry = await ctx.runMutation(refs.waitlist.verify, { email: admissionEmail(email), ...(join ? { join } : {}), ...(locale ? { locale } : {}), boost: DEFAULT_BOOST })
640
- const place = await ctx.runQuery(refs.waitlist.place, { id: entry.id })
667
+ const rule = waitlistRule
668
+ const entry = await ctx.runMutation(refs.waitlist.verify, { email: admissionEmail(email), ...(join ? { join } : {}), ...(locale ? { locale } : {}), boost: rule.boost })
669
+ const waiting = entry.status === 'waiting'
670
+ // A private rank is never read, so nothing about the list's size leaves here.
671
+ const place = waiting && rule.rank ? await ctx.runQuery(refs.waitlist.place, { id: entry.id }) : null
672
+ // The event records every credited friend; `notify` decides only the email.
673
+ const sharer = entry.sharer
674
+ ? { email: entry.sharer.email, locale: entry.sharer.locale, friends: entry.sharer.friends, credit: entry.sharer.credit, token: await statusToken(secret(), entry.sharer.id), notify: rule.notify }
675
+ : undefined
641
676
  return {
642
677
  id: entry.id,
643
678
  created: entry.created,
679
+ waiting,
644
680
  position: place?.position ?? null,
645
681
  total: place?.total ?? 0,
646
682
  token: await statusToken(secret(), entry.id),
647
683
  source: entry.source,
648
684
  referred: entry.referred,
649
685
  news: entry.news,
686
+ ...(sharer ? { sharer } : {}),
650
687
  }
651
688
  }
652
689
  : undefined
@@ -869,12 +906,13 @@ export function setupAccess(components: AccessComponents, options: SetupAccessOp
869
906
  require: requireAdministrator,
870
907
  is: (ctx, what) => isAdministratorNow(ctx, reads, administrators, what),
871
908
  },
909
+ waitlistRule,
872
910
  },
873
911
  }
874
912
  }
875
913
 
876
914
  export { setupWaitlist } from './waitlist.js'
877
- export type { SetupWaitlistOptions, Waitlist, WaitlistApi, WaitlistCaps, WaitlistConsole, WaitlistEntryRow, WaitlistPlace, WaitlistStatusView } from './waitlist.js'
878
- export type { WaitlistQuestions, WaitlistStatus } from '../waitlist-rules.js'
915
+ export type { SetupWaitlistOptions, Waitlist, WaitlistApi, WaitlistCaps, WaitlistConsole, WaitlistEntryRow, WaitlistPlace, WaitlistStatusView, WaitlistWaveStanding } from './waitlist.js'
916
+ export type { WaitlistBoostOptions, WaitlistBoostRule, WaitlistOptions, WaitlistQuestions, WaitlistRule, WaitlistStatus } from '../waitlist-rules.js'
879
917
  export { ACCESS_PHASES } from '../access-tickets.js'
880
918
  export type { AccessPhase, AccessTicket, InviteKind, InviteStatus } from '../access-tickets.js'
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Who is here: Convex's presence component, behind the backend's sign-in.
3
+ * A heartbeat counts the signed-in account, never an id the browser names;
4
+ * the room token it hands back is what lists the room, so only someone the
5
+ * room let in reads who else is there, by name.
6
+ *
7
+ * Experimental: it follows the presence component's pre-1.0 shapes, so this
8
+ * entry's shape may change in a minor release.
9
+ *
10
+ * @module
11
+ * @experimental
12
+ */
13
+ import { Presence } from '@convex-dev/presence'
14
+ import { v } from 'convex/values'
15
+ import { type FunctionReference, type GenericMutationCtx, type GenericDataModel, mutationGeneric, queryGeneric, type RegisteredMutation, type RegisteredQuery } from 'convex/server'
16
+ import { backendError } from '../errors.js'
17
+ import { ownCaller } from './access.js'
18
+
19
+ /** The presence component's handle, `components.presence`. */
20
+ type PresenceComponent = ConstructorParameters<typeof Presence>[0]
21
+
22
+ /** The component handles `setupPresence` reads: pass the whole generated `components` object. */
23
+ export interface PresenceComponents {
24
+ presence: PresenceComponent
25
+ backend: { adapter: { findOne: FunctionReference<'query', 'internal'> } }
26
+ }
27
+
28
+ /** Who a room may let in, asked on every heartbeat. */
29
+ export interface PresenceRoomCheck {
30
+ /** The room the browser names, as `useRoomPresence` was given it. */
31
+ roomId: string
32
+ /** The signed-in account. */
33
+ userId: string
34
+ /** Its identity claims: its role, its active workspace (`activeOrganizationId`) and the rest. */
35
+ claims: Record<string, unknown>
36
+ }
37
+
38
+ /** Options for {@link setupPresence}. */
39
+ export interface SetupPresenceOptions {
40
+ /**
41
+ * Whether a signed-in account may join a room, with the mutation's `ctx` to read your tables by. Unset, every signed-in
42
+ * account may join any room; refuse one by returning `false`, and the
43
+ * heartbeat answers `forbidden`. Rooms are the app's own strings: a
44
+ * document's id, `workspace:<id>`. It runs on heartbeats only, so it lets
45
+ * people in but never takes anyone out: the mutation that takes access away
46
+ * (a member removed from a workspace) also calls `presence.removeRoomUser`.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * canJoin: ({ roomId, claims }) => !roomId.startsWith('workspace:') || roomId === `workspace:${claims.activeOrganizationId}`
51
+ * ```
52
+ */
53
+ canJoin?: (room: PresenceRoomCheck, ctx: GenericMutationCtx<GenericDataModel>) => boolean | Promise<boolean>
54
+ /** How many people a room lists at most. Default 50. */
55
+ limit?: number
56
+ }
57
+
58
+ /** One person in a room, as `useRoomPresence` and the base module's `<FacePile>` read it. */
59
+ export interface RoomMember {
60
+ userId: string
61
+ online: boolean
62
+ lastDisconnected: number
63
+ /** Their name, when the account has one. */
64
+ name?: string
65
+ /** Their picture, when the account has one. */
66
+ image?: string
67
+ }
68
+
69
+ /** What {@link setupPresence} returns: the three functions `backend/presence.ts` exports, and the component's own client. */
70
+ export interface PresenceSetup {
71
+ /**
72
+ * The room's people, by the room token a heartbeat handed back: who is online first, as the component orders them.
73
+ * Signed out, as an administrator acting as someone, or once `removeRoomUser` took the caller out of the room, it lists nobody and refuses.
74
+ */
75
+ list: RegisteredQuery<'public', { roomToken: string }, Promise<RoomMember[]>>
76
+ /** Keep the signed-in account in a room. The browser's `userId` is checked against the account, never trusted. */
77
+ heartbeat: RegisteredMutation<'public', { roomId: string, userId: string, sessionId: string, interval: number }, Promise<{ roomToken: string, sessionToken: string }>>
78
+ /** Leave the room the session token names, as a tab closes. */
79
+ disconnect: RegisteredMutation<'public', { sessionToken: string }, Promise<null>>
80
+ /**
81
+ * The component's client, for a room of your own (`listRoom`, `removeRoomUser`, `removeRoom`), which checks no sign-in.
82
+ * A refused heartbeat leaves the person in the room, with a room token that still lists it: `removeRoomUser`, called from the mutation that takes their access away, takes them out, and `list` then refuses them.
83
+ */
84
+ presence: Presence
85
+ }
86
+
87
+ /** The fewest and most heartbeat intervals the server accepts, in milliseconds. */
88
+ const INTERVAL = { min: 1_000, max: 5 * 60_000 }
89
+ /** The longest room id: a document's id or a key of the app's own. */
90
+ const ROOM_ID_MAX = 256
91
+ /** The most people `list` reads to find the caller in a room fuller than its `limit`. */
92
+ const MEMBER_CHECK_MAX = 1_000
93
+
94
+ /**
95
+ * Who is here, for a page, a document or a workspace: Convex's presence
96
+ * component (`@convex-dev/presence`, mounted as `presence` in
97
+ * `convex.config.ts`) behind the backend's sign-in. Export what it returns
98
+ * from `backend/presence.ts`, and `useRoomPresence(roomId)` keeps the
99
+ * signed-in person in the room and lists who else is there.
100
+ *
101
+ * @example
102
+ * ```ts [backend/presence.ts]
103
+ * import { setupPresence } from 'nuxt-backend/presence'
104
+ * import { components } from './_generated/api'
105
+ *
106
+ * export const { list, heartbeat, disconnect } = setupPresence(components)
107
+ * ```
108
+ */
109
+ export function setupPresence(components: PresenceComponents, options: SetupPresenceOptions = {}): PresenceSetup {
110
+ const presence = new Presence(components.presence)
111
+ const limit = options.limit ?? 50
112
+ if (!Number.isInteger(limit) || limit < 1 || limit > 200) throw new TypeError('[nuxt-backend] setupPresence({ limit }): a whole number from 1 to 200.')
113
+ const findUser = components.backend.adapter.findOne
114
+
115
+ const heartbeat = mutationGeneric({
116
+ args: { roomId: v.string(), userId: v.string(), sessionId: v.string(), interval: v.number() },
117
+ handler: async (ctx, { roomId, userId, sessionId, interval }) => {
118
+ const caller = await ownCaller(ctx, 'presence:heartbeat')
119
+ if (userId !== caller) throw backendError('forbidden', { reason: 'presence_user' }, '[nuxt-backend] presence:heartbeat: a heartbeat counts the signed-in account only.')
120
+ if (!roomId || roomId.length > ROOM_ID_MAX) throw backendError('invalid_input', { field: 'roomId' }, `[nuxt-backend] presence:heartbeat: a room id of 1 to ${ROOM_ID_MAX} characters.`)
121
+ if (!sessionId || sessionId.length > 128) throw backendError('invalid_input', { field: 'sessionId' }, '[nuxt-backend] presence:heartbeat: a session id of 1 to 128 characters.')
122
+ if (options.canJoin) {
123
+ const claims = await ctx.auth.getUserIdentity() as unknown as Record<string, unknown>
124
+ if (!await options.canJoin({ roomId, userId: caller, claims }, ctx)) throw backendError('forbidden', { reason: 'presence_room' }, `[nuxt-backend] presence:heartbeat: ${JSON.stringify(roomId)} does not let this account in.`)
125
+ }
126
+ return presence.heartbeat(ctx, roomId, caller, sessionId, Math.min(INTERVAL.max, Math.max(INTERVAL.min, interval)))
127
+ },
128
+ })
129
+
130
+ const list = queryGeneric({
131
+ args: { roomToken: v.string() },
132
+ handler: async (ctx, { roomToken }): Promise<RoomMember[]> => {
133
+ // A token outlives the sign-in that earned it: names and pictures go to a signed-in caller only.
134
+ const caller = await ownCaller(ctx, 'presence:list')
135
+ // The token is the room's, shared by everyone in it, and outlives a removal: the caller must still be in the room.
136
+ const people = await presence.list(ctx, roomToken, limit)
137
+ const inRoom = (rows: typeof people) => rows.some(row => row.userId === caller)
138
+ if (!inRoom(people) && (people.length < limit || !inRoom(await presence.list(ctx, roomToken, MEMBER_CHECK_MAX)))) {
139
+ throw backendError('forbidden', { reason: 'presence_room' }, '[nuxt-backend] presence:list: the caller is not in this room.')
140
+ }
141
+ return Promise.all(people.map(async ({ userId, online, lastDisconnected }) => {
142
+ const user = await ctx.runQuery(findUser, { model: 'user', where: [{ field: '_id', value: userId }] }) as { name?: unknown, image?: unknown } | null
143
+ return {
144
+ userId,
145
+ online,
146
+ lastDisconnected,
147
+ ...(typeof user?.name === 'string' && user.name ? { name: user.name } : {}),
148
+ ...(typeof user?.image === 'string' && user.image ? { image: user.image } : {}),
149
+ }
150
+ }))
151
+ },
152
+ })
153
+
154
+ const disconnect = mutationGeneric({
155
+ args: { sessionToken: v.string() },
156
+ handler: async (ctx, { sessionToken }) => presence.disconnect(ctx, sessionToken),
157
+ })
158
+
159
+ return { list, heartbeat, disconnect, presence }
160
+ }
@@ -12,13 +12,14 @@ import {
12
12
  addressDigest,
13
13
  answersProblem,
14
14
  checkedQuestions,
15
- DEFAULT_BOOST,
16
15
  readStatusToken,
17
16
  SOURCE_FORM,
18
17
  WAITLIST_SOURCE_MAX,
19
18
  WAITLIST_STATUSES,
20
19
  WAITLIST_WAVE_MAX,
20
+ WAITLIST_WAVE_PLAN_MAX,
21
21
  type WaitlistQuestions,
22
+ type WaitlistRule,
22
23
  type WaitlistStatus,
23
24
  } from '../waitlist-rules.js'
24
25
  import type { Email } from './email.js'
@@ -34,17 +35,35 @@ import { DEFAULT_LIMITS } from './rate-limit.js'
34
35
  // what the app serves: the join, a place by its signed link, leaving, and
35
36
  // the Waitlist tab's functions.
36
37
 
38
+ /** Where a waiting person stands against the next wave an administrator planned: in it or not, never its size. */
39
+ export interface WaitlistWaveStanding {
40
+ /** When the wave opens, epoch ms; `null` when no date is set. */
41
+ opensAt: number | null
42
+ /** Whether the person is in it now (a later friend of someone else may still move them out). */
43
+ included: boolean
44
+ /** How many more friends would put them in it: 0 when in it, `null` when sharing is off or the friend cap leaves no room for that many. */
45
+ friendsShort: number | null
46
+ }
47
+
37
48
  /** One person's standing, as their status page reads it. */
38
49
  export interface WaitlistStatusView {
39
50
  status: WaitlistStatus
40
- /** The place among the people waiting, 1-based; `null` once the person is no longer waiting. */
51
+ /** The place among the people waiting, 1-based; `null` once the person is no longer waiting, and always where rank is private (`place: { rank: false }`). */
41
52
  position: number | null
42
- /** How many people wait. */
53
+ /** How many people wait; 0 where rank is private. */
43
54
  total: number
44
- /** The friends who joined through their link and count, up to `cap`. */
55
+ /** When the code proved the address, epoch ms: the date the line goes by. Friends never move it; they move the place. 0 on `useWaitlist`'s stand-in before the live status answers. */
56
+ joinedAt: number
57
+ /** The friends who joined through their link and count. */
45
58
  friends: number
46
- /** The most friends that count for one person. */
47
- cap: number
59
+ /** The most friends that count for one person; `null` for no limit, 0 when sharing is off. */
60
+ cap: number | null
61
+ /** How far up the line friends (and a friend's welcome) moved them, in ms; 0 once they stop waiting. */
62
+ credit: number
63
+ /** How far each friend moves them, in ms; 0 when sharing is off. */
64
+ perFriend: number
65
+ /** Where they stand against the planned wave; `null` when none is planned or they no longer wait. */
66
+ wave: WaitlistWaveStanding | null
48
67
  /** The code of their share link: `?ref=<shareCode>` on the page that holds the form. */
49
68
  shareCode: string
50
69
  /** Whether they asked for launch news. */
@@ -87,6 +106,8 @@ export interface WaitlistConsole {
87
106
  entries: WaitlistEntryRow[]
88
107
  /** The questions the app asks, with their choices: the filter's. */
89
108
  questions: WaitlistQuestions
109
+ /** The next wave as planned: how many from the front of the line, and when it opens; `null` when none is planned. */
110
+ wave: { size: number, opensAt: number | null } | null
90
111
  }
91
112
 
92
113
  /** The room a wave has, read from the services that bound it. */
@@ -124,12 +145,21 @@ export interface WaitlistApi {
124
145
  noteWaitlist: RegisteredMutation<'public', { id: string, note: string }, Promise<null>>
125
146
  /** The room a wave has. `null` for anyone who is not an administrator now. */
126
147
  getWaitlistCaps: RegisteredAction<'public', Record<string, never>, Promise<WaitlistCaps | null>>
148
+ /**
149
+ * Plan the next wave: `size` people from the front of the line, opening at
150
+ * `opensAt` (epoch ms) if a date is set; `size: null` clears the plan.
151
+ * Each waiting person then reads whether they are in it, never its size.
152
+ * An administrator's, in person, with a recent sign-in.
153
+ */
154
+ planWaitlistWave: RegisteredMutation<'public', { size: number | null, opensAt?: number | null }, Promise<null>>
127
155
  }
128
156
 
129
157
  /** The app's waitlist, from {@link setupWaitlist}. */
130
158
  export interface Waitlist {
131
159
  /** The questions asked beside the address. */
132
160
  questions: WaitlistQuestions
161
+ /** The rule the line runs on, from `setupAccess({ waitlist })`: how sharing moves people, and whether a person reads their rank. */
162
+ rule: WaitlistRule
133
163
  /** The public functions `backend/waitlist.ts` re-exports. */
134
164
  api: WaitlistApi
135
165
  /**
@@ -164,7 +194,8 @@ export interface SetupWaitlistOptions {
164
194
  interface WaitlistRefs {
165
195
  waitlist: {
166
196
  stage: FunctionReference<'mutation', 'internal', { email: string, key: string, answers?: Record<string, string>, launchNews?: { text: string }, source: string, ref?: string, locale?: string }, null>
167
- place: FunctionReference<'query', 'internal', { id: string }, { status: WaitlistStatus, position: number | null, total: number, boost: number, shareCode: string, launchNews: boolean } | null>
197
+ place: FunctionReference<'query', 'internal', { id: string, rank?: boolean, perFriend?: number | null }, { status: WaitlistStatus, position: number | null, total: number, boost: number, credit: number, shareCode: string, launchNews: boolean, verifiedAt: number, wave: WaitlistWaveStanding | null } | null>
198
+ planWave: FunctionReference<'mutation', 'internal', { wave: { size: number, opensAt?: number } | null }, null>
168
199
  leave: FunctionReference<'mutation', 'internal', { id: string }, null>
169
200
  queue: FunctionReference<'query', 'internal', { limit: number }, string[]>
170
201
  admit: FunctionReference<'mutation', 'internal', { ids: string[], max?: number, label?: string, createdBy?: string }, Array<{ id: string, email: string, locale: string | null }>>
@@ -184,6 +215,14 @@ function checkedWave(ids: string[] | undefined, next: number | undefined): void
184
215
  if (!ids && next === undefined) throw backendError('invalid_input', { field: 'ids' }, '[nuxt-backend] admitWaitlist: pass the entries (`ids`) or how many are next (`next`).')
185
216
  }
186
217
 
218
+ /** The plan `planWaitlistWave` takes, checked: a size within a planned wave's bounds, and a date that is a time. */
219
+ function checkedPlan(size: number | null, opensAt: number | null | undefined): { size: number, opensAt?: number } | null {
220
+ if (size === null) return null
221
+ if (!Number.isInteger(size) || size < 1 || size > WAITLIST_WAVE_PLAN_MAX) throw backendError('invalid_input', { field: 'size' }, `[nuxt-backend] planWaitlistWave: the size is a whole number from 1 to ${WAITLIST_WAVE_PLAN_MAX}.`)
222
+ if (opensAt !== undefined && opensAt !== null && !Number.isFinite(opensAt)) throw backendError('invalid_input', { field: 'opensAt' }, '[nuxt-backend] planWaitlistWave: the opening date is a time in epoch milliseconds.')
223
+ return { size, ...(typeof opensAt === 'number' ? { opensAt } : {}) }
224
+ }
225
+
187
226
  /** The words of the launch-news box the person agreed to, kept with the time as the record of consent: the form sends the ones it showed, else these. */
188
227
  const LAUNCH_NEWS_TEXT = 'Email me when it launches'
189
228
 
@@ -220,7 +259,7 @@ const siteUrl = (): string | undefined => readEnv('SITE_URL')?.replace(/\/+$/, '
220
259
  * questions: { role: ['Writer', 'Illustrator', 'Reader'] },
221
260
  * })
222
261
  *
223
- * export const { getWaitlistQuestions, joinWaitlist, waitlistStatus, leaveWaitlist, getWaitlistConsole, admitWaitlist, declineWaitlist, noteWaitlist, getWaitlistCaps } = waitlist.api
262
+ * export const { getWaitlistQuestions, joinWaitlist, waitlistStatus, leaveWaitlist, getWaitlistConsole, admitWaitlist, declineWaitlist, noteWaitlist, getWaitlistCaps, planWaitlistWave } = waitlist.api
224
263
  * ```
225
264
  */
226
265
  export function setupWaitlist(components: AccessComponents, options: SetupWaitlistOptions): Waitlist {
@@ -232,6 +271,8 @@ export function setupWaitlist(components: AccessComponents, options: SetupWaitli
232
271
  }
233
272
  const { access, email } = options
234
273
  const questions = checkedQuestions(options.questions)
274
+ // The rule is the access's (setupAccess({ waitlist })): the sign-in page records entries by it too.
275
+ const rule: WaitlistRule = access.internals.waitlistRule
235
276
  // Where an admitted person signs up: the sign-in page, wherever nuxt.config moves it.
236
277
  const signInPath = resolveBackendPaths(options.paths, 'setupWaitlist').login
237
278
  const refs = access.internals.refs as WaitlistRefs & Record<string, unknown>
@@ -245,11 +286,29 @@ export function setupWaitlist(components: AccessComponents, options: SetupWaitli
245
286
  /** The entry a status token names, if the token was signed here. */
246
287
  const entryOf = async (token: string): Promise<string | null> => firstVerified(secrets(), value => readStatusToken(value, token))
247
288
 
248
- /** An entry's standing, as its status page reads it. */
289
+ const sharing = rule.boost.cap === null || rule.boost.cap > 0
290
+
291
+ /** A wave's friends-short count only where the cap leaves room for that many more friends. */
292
+ const reachable = (wave: WaitlistWaveStanding, friends: number): WaitlistWaveStanding =>
293
+ wave.friendsShort !== null && rule.boost.cap !== null && wave.friendsShort > rule.boost.cap - friends ? { ...wave, friendsShort: null } : wave
294
+
295
+ /** An entry's standing, as its status page reads it: the place and the count only where rank is shown. */
249
296
  async function placeFor(ctx: Pick<AccessCtx, 'runQuery'>, id: string): Promise<WaitlistStatusView | null> {
250
- const place = await ctx.runQuery(refs.waitlist.place, { id })
297
+ const place = await ctx.runQuery(refs.waitlist.place, { id, rank: rule.rank, perFriend: sharing ? rule.boost.perFriend : null })
251
298
  if (!place) return null
252
- return { status: place.status, position: place.position, total: place.total, friends: place.boost, cap: DEFAULT_BOOST.cap, shareCode: place.shareCode, launchNews: place.launchNews }
299
+ return {
300
+ status: place.status,
301
+ position: place.position,
302
+ total: place.total,
303
+ joinedAt: place.verifiedAt,
304
+ friends: place.boost,
305
+ cap: rule.boost.cap,
306
+ credit: place.credit,
307
+ perFriend: sharing ? rule.boost.perFriend : 0,
308
+ wave: place.wave && reachable(place.wave, place.boost),
309
+ shareCode: place.shareCode,
310
+ launchNews: place.launchNews,
311
+ }
253
312
  }
254
313
 
255
314
  const getWaitlistQuestions = queryGeneric({ args: {}, handler: async (): Promise<WaitlistQuestions> => questions })
@@ -388,10 +447,23 @@ export function setupWaitlist(components: AccessComponents, options: SetupWaitli
388
447
  },
389
448
  })
390
449
 
450
+ const planWaitlistWave = mutationGeneric({
451
+ args: { size: v.union(v.null(), v.number()), opensAt: v.optional(v.union(v.null(), v.number())) },
452
+ returns: v.null(),
453
+ handler: async (ctx, { size, opensAt }) => {
454
+ await administrators.require(ctx, 'planWaitlistWave')
455
+ const wave = checkedPlan(size, opensAt)
456
+ await ctx.runMutation(refs.waitlist.planWave, { wave })
457
+ await audit.recordBackendEvent(ctx, { type: 'waitlist.wave_planned', data: wave ? { size: wave.size, ...(wave.opensAt !== undefined ? { opensAt: wave.opensAt } : {}) } : {} })
458
+ return null
459
+ },
460
+ })
461
+
391
462
  return {
392
463
  questions,
464
+ rule,
393
465
  launchAudience: ctx => ctx.runQuery(refs.waitlist.audience, {}),
394
- api: { getWaitlistQuestions, joinWaitlist, waitlistStatus, leaveWaitlist, getWaitlistConsole, admitWaitlist, declineWaitlist, noteWaitlist, getWaitlistCaps } as unknown as WaitlistApi,
466
+ api: { getWaitlistQuestions, joinWaitlist, waitlistStatus, leaveWaitlist, getWaitlistConsole, admitWaitlist, declineWaitlist, noteWaitlist, getWaitlistCaps, planWaitlistWave } as unknown as WaitlistApi,
395
467
  }
396
468
  }
397
469