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.
- package/README.md +5 -2
- package/dist/capabilities/registry.js +1 -1
- package/dist/chunks/catalog.mjs +1 -1
- package/dist/chunks/{index.mjs → devtools.mjs} +2 -2
- package/dist/chunks/doctor.mjs +14 -6
- package/dist/chunks/email-previews.mjs +1 -1
- package/dist/chunks/health.mjs +2 -2
- package/dist/chunks/install.mjs +4 -4
- package/dist/chunks/run.mjs +1 -1
- package/dist/chunks/server.mjs +15 -4
- package/dist/cli.mjs +24 -4
- package/dist/convex/access-tickets.d.ts +17 -2
- package/dist/convex/access-tickets.d.ts.map +1 -1
- package/dist/convex/account-data.d.ts +4 -4
- package/dist/convex/account-data.d.ts.map +1 -1
- package/dist/convex/account-data.js +5 -4
- package/dist/convex/account-data.js.map +1 -1
- package/dist/convex/app.d.ts +1 -0
- package/dist/convex/app.d.ts.map +1 -1
- package/dist/convex/app.js +2 -1
- package/dist/convex/app.js.map +1 -1
- package/dist/convex/client/better-auth-options.d.ts.map +1 -1
- package/dist/convex/client/better-auth-options.js +12 -3
- package/dist/convex/client/better-auth-options.js.map +1 -1
- package/dist/convex/client/component.d.ts +4 -0
- package/dist/convex/client/component.d.ts.map +1 -1
- package/dist/convex/client/index.d.ts +5 -0
- package/dist/convex/client/index.d.ts.map +1 -1
- package/dist/convex/client/launch-gate.d.ts.map +1 -1
- package/dist/convex/client/launch-gate.js +30 -1
- package/dist/convex/client/launch-gate.js.map +1 -1
- package/dist/convex/client/plugins.d.ts.map +1 -1
- package/dist/convex/client/plugins.js +3 -0
- package/dist/convex/client/plugins.js.map +1 -1
- package/dist/convex/client/two-factor.d.ts +7 -0
- package/dist/convex/client/two-factor.d.ts.map +1 -0
- package/dist/convex/client/two-factor.js +57 -0
- package/dist/convex/client/two-factor.js.map +1 -0
- package/dist/convex/components/backend/_generated/api.d.ts +2 -0
- package/dist/convex/components/backend/_generated/api.d.ts.map +1 -1
- package/dist/convex/components/backend/_generated/api.js.map +1 -1
- package/dist/convex/components/backend/_generated/component.d.ts +292 -10
- package/dist/convex/components/backend/_generated/component.d.ts.map +1 -1
- package/dist/convex/components/backend/account.d.ts +63 -17
- package/dist/convex/components/backend/account.d.ts.map +1 -1
- package/dist/convex/components/backend/account.js +24 -1
- package/dist/convex/components/backend/account.js.map +1 -1
- package/dist/convex/components/backend/adapter.d.ts.map +1 -1
- package/dist/convex/components/backend/adapter.js +7 -2
- package/dist/convex/components/backend/adapter.js.map +1 -1
- package/dist/convex/components/backend/ai.d.ts +1 -1
- package/dist/convex/components/backend/billing.d.ts +10 -0
- package/dist/convex/components/backend/billing.d.ts.map +1 -1
- package/dist/convex/components/backend/billing.js +2 -1
- package/dist/convex/components/backend/billing.js.map +1 -1
- package/dist/convex/components/backend/commerce.d.ts +229 -0
- package/dist/convex/components/backend/commerce.d.ts.map +1 -0
- package/dist/convex/components/backend/commerce.js +392 -0
- package/dist/convex/components/backend/commerce.js.map +1 -0
- package/dist/convex/components/backend/funnel.d.ts +6 -6
- package/dist/convex/components/backend/jobs.d.ts +1 -1
- package/dist/convex/components/backend/referrals.d.ts +2 -2
- package/dist/convex/components/backend/schema.d.ts +327 -21
- package/dist/convex/components/backend/schema.d.ts.map +1 -1
- package/dist/convex/components/backend/schema.js +108 -1
- package/dist/convex/components/backend/schema.js.map +1 -1
- package/dist/convex/components/backend/waitlist.d.ts +42 -6
- package/dist/convex/components/backend/waitlist.d.ts.map +1 -1
- package/dist/convex/components/backend/waitlist.js +142 -39
- package/dist/convex/components/backend/waitlist.js.map +1 -1
- package/dist/convex/email-templates.d.ts +12 -0
- package/dist/convex/email-templates.d.ts.map +1 -1
- package/dist/convex/email-templates.js +3 -0
- package/dist/convex/email-templates.js.map +1 -1
- package/dist/convex/emails/waitlist-friend-joined.d.ts +9 -0
- package/dist/convex/emails/waitlist-friend-joined.d.ts.map +1 -0
- package/dist/convex/emails/waitlist-friend-joined.js +22 -0
- package/dist/convex/emails/waitlist-friend-joined.js.map +1 -0
- package/dist/convex/errors.d.ts +6 -6
- package/dist/convex/errors.d.ts.map +1 -1
- package/dist/convex/errors.js +14 -2
- package/dist/convex/errors.js.map +1 -1
- package/dist/convex/events.d.ts +19 -0
- package/dist/convex/events.d.ts.map +1 -1
- package/dist/convex/events.js +14 -0
- package/dist/convex/events.js.map +1 -1
- package/dist/convex/integrations/billing/checkout.d.ts +2 -2
- package/dist/convex/integrations/billing/checkout.d.ts.map +1 -1
- package/dist/convex/integrations/billing/checkout.js +79 -11
- package/dist/convex/integrations/billing/checkout.js.map +1 -1
- package/dist/convex/integrations/billing/commerce-entitlements.d.ts +12 -0
- package/dist/convex/integrations/billing/commerce-entitlements.d.ts.map +1 -0
- package/dist/convex/integrations/billing/commerce-entitlements.js +78 -0
- package/dist/convex/integrations/billing/commerce-entitlements.js.map +1 -0
- package/dist/convex/integrations/billing/commerce-events.d.ts +15 -0
- package/dist/convex/integrations/billing/commerce-events.d.ts.map +1 -0
- package/dist/convex/integrations/billing/commerce-events.js +433 -0
- package/dist/convex/integrations/billing/commerce-events.js.map +1 -0
- package/dist/convex/integrations/billing/commerce-history.d.ts +20 -0
- package/dist/convex/integrations/billing/commerce-history.d.ts.map +1 -0
- package/dist/convex/integrations/billing/commerce-history.js +106 -0
- package/dist/convex/integrations/billing/commerce-history.js.map +1 -0
- package/dist/convex/integrations/billing/commerce-webhooks.d.ts +23 -0
- package/dist/convex/integrations/billing/commerce-webhooks.d.ts.map +1 -0
- package/dist/convex/integrations/billing/commerce-webhooks.js +49 -0
- package/dist/convex/integrations/billing/commerce-webhooks.js.map +1 -0
- package/dist/convex/integrations/billing/commerce.d.ts +100 -0
- package/dist/convex/integrations/billing/commerce.d.ts.map +1 -0
- package/dist/convex/integrations/billing/commerce.js +323 -0
- package/dist/convex/integrations/billing/commerce.js.map +1 -0
- package/dist/convex/integrations/billing/context.d.ts +8 -0
- package/dist/convex/integrations/billing/context.d.ts.map +1 -1
- package/dist/convex/integrations/billing/context.js +14 -2
- package/dist/convex/integrations/billing/context.js.map +1 -1
- package/dist/convex/integrations/billing/credits.d.ts +1 -1
- package/dist/convex/integrations/billing/credits.d.ts.map +1 -1
- package/dist/convex/integrations/billing/credits.js +49 -28
- package/dist/convex/integrations/billing/credits.js.map +1 -1
- package/dist/convex/integrations/billing/customers.d.ts +1 -1
- package/dist/convex/integrations/billing/customers.d.ts.map +1 -1
- package/dist/convex/integrations/billing/customers.js +15 -1
- package/dist/convex/integrations/billing/customers.js.map +1 -1
- package/dist/convex/integrations/billing/entitlements.d.ts +1 -1
- package/dist/convex/integrations/billing/entitlements.d.ts.map +1 -1
- package/dist/convex/integrations/billing/entitlements.js +6 -1
- package/dist/convex/integrations/billing/entitlements.js.map +1 -1
- package/dist/convex/integrations/billing/erasure.d.ts +1 -1
- package/dist/convex/integrations/billing/erasure.d.ts.map +1 -1
- package/dist/convex/integrations/billing/erasure.js +10 -5
- package/dist/convex/integrations/billing/erasure.js.map +1 -1
- package/dist/convex/integrations/billing/free-plan.d.ts +6 -1
- package/dist/convex/integrations/billing/free-plan.d.ts.map +1 -1
- package/dist/convex/integrations/billing/free-plan.js +22 -4
- package/dist/convex/integrations/billing/free-plan.js.map +1 -1
- package/dist/convex/integrations/billing/functions.d.ts +1 -1
- package/dist/convex/integrations/billing/functions.d.ts.map +1 -1
- package/dist/convex/integrations/billing/functions.js +3 -2
- package/dist/convex/integrations/billing/functions.js.map +1 -1
- package/dist/convex/integrations/billing/gifts.d.ts.map +1 -1
- package/dist/convex/integrations/billing/gifts.js +3 -0
- package/dist/convex/integrations/billing/gifts.js.map +1 -1
- package/dist/convex/integrations/billing/history.d.ts +1 -1
- package/dist/convex/integrations/billing/history.d.ts.map +1 -1
- package/dist/convex/integrations/billing/history.js +6 -1
- package/dist/convex/integrations/billing/history.js.map +1 -1
- package/dist/convex/integrations/billing/lifecycle.d.ts +1 -1
- package/dist/convex/integrations/billing/lifecycle.d.ts.map +1 -1
- package/dist/convex/integrations/billing/lifecycle.js +4 -1
- package/dist/convex/integrations/billing/lifecycle.js.map +1 -1
- package/dist/convex/integrations/billing/providers/capabilities.d.ts +17 -0
- package/dist/convex/integrations/billing/providers/capabilities.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/capabilities.js +77 -0
- package/dist/convex/integrations/billing/providers/capabilities.js.map +1 -0
- package/dist/convex/integrations/billing/providers/consent.d.ts +52 -0
- package/dist/convex/integrations/billing/providers/consent.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/consent.js +79 -0
- package/dist/convex/integrations/billing/providers/consent.js.map +1 -0
- package/dist/convex/integrations/billing/providers/creem.d.ts +22 -0
- package/dist/convex/integrations/billing/providers/creem.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/creem.js +208 -0
- package/dist/convex/integrations/billing/providers/creem.js.map +1 -0
- package/dist/convex/integrations/billing/providers/dodo.d.ts +15 -0
- package/dist/convex/integrations/billing/providers/dodo.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/dodo.js +197 -0
- package/dist/convex/integrations/billing/providers/dodo.js.map +1 -0
- package/dist/convex/integrations/billing/providers/http.d.ts +41 -0
- package/dist/convex/integrations/billing/providers/http.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/http.js +146 -0
- package/dist/convex/integrations/billing/providers/http.js.map +1 -0
- package/dist/convex/integrations/billing/providers/index.d.ts +35 -0
- package/dist/convex/integrations/billing/providers/index.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/index.js +62 -0
- package/dist/convex/integrations/billing/providers/index.js.map +1 -0
- package/dist/convex/integrations/billing/providers/stripe.d.ts +28 -0
- package/dist/convex/integrations/billing/providers/stripe.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/stripe.js +327 -0
- package/dist/convex/integrations/billing/providers/stripe.js.map +1 -0
- package/dist/convex/integrations/billing/providers/types.d.ts +263 -0
- package/dist/convex/integrations/billing/providers/types.d.ts.map +1 -0
- package/dist/convex/integrations/billing/providers/types.js +48 -0
- package/dist/convex/integrations/billing/providers/types.js.map +1 -0
- package/dist/convex/integrations/billing/subscriptions.d.ts +1 -1
- package/dist/convex/integrations/billing/subscriptions.d.ts.map +1 -1
- package/dist/convex/integrations/billing/subscriptions.js +20 -6
- package/dist/convex/integrations/billing/subscriptions.js.map +1 -1
- package/dist/convex/integrations/billing/types/setup.d.ts +64 -1
- package/dist/convex/integrations/billing/types/setup.d.ts.map +1 -1
- package/dist/convex/integrations/billing.d.ts +4 -1
- package/dist/convex/integrations/billing.d.ts.map +1 -1
- package/dist/convex/integrations/billing.js +12 -2
- package/dist/convex/integrations/billing.js.map +1 -1
- package/dist/convex/integrations/email.d.ts +1 -1
- package/dist/convex/integrations/email.d.ts.map +1 -1
- package/dist/convex/integrations/email.js.map +1 -1
- package/dist/convex/integrations/launch.d.ts +27 -2
- package/dist/convex/integrations/launch.d.ts.map +1 -1
- package/dist/convex/integrations/launch.js +15 -3
- package/dist/convex/integrations/launch.js.map +1 -1
- package/dist/convex/integrations/presence.d.ts +110 -0
- package/dist/convex/integrations/presence.d.ts.map +1 -0
- package/dist/convex/integrations/presence.js +92 -0
- package/dist/convex/integrations/presence.js.map +1 -0
- package/dist/convex/integrations/waitlist.d.ts +41 -7
- package/dist/convex/integrations/waitlist.d.ts.map +1 -1
- package/dist/convex/integrations/waitlist.js +45 -6
- package/dist/convex/integrations/waitlist.js.map +1 -1
- package/dist/convex/integrations/webhook-guard.d.ts +8 -0
- package/dist/convex/integrations/webhook-guard.d.ts.map +1 -1
- package/dist/convex/integrations/webhook-guard.js +11 -4
- package/dist/convex/integrations/webhook-guard.js.map +1 -1
- package/dist/convex/label-groups/admin.d.ts +9 -0
- package/dist/convex/label-groups/admin.d.ts.map +1 -1
- package/dist/convex/label-groups/admin.js +9 -0
- package/dist/convex/label-groups/admin.js.map +1 -1
- package/dist/convex/label-groups/audit.d.ts +2 -0
- package/dist/convex/label-groups/audit.d.ts.map +1 -1
- package/dist/convex/label-groups/audit.js +2 -0
- package/dist/convex/label-groups/audit.js.map +1 -1
- package/dist/convex/label-groups/auth.d.ts +9 -0
- package/dist/convex/label-groups/auth.d.ts.map +1 -1
- package/dist/convex/label-groups/auth.js +10 -0
- package/dist/convex/label-groups/auth.js.map +1 -1
- package/dist/convex/label-groups/email.d.ts +6 -0
- package/dist/convex/label-groups/email.d.ts.map +1 -1
- package/dist/convex/label-groups/email.js +7 -0
- package/dist/convex/label-groups/email.js.map +1 -1
- package/dist/convex/label-groups/errors.d.ts +4 -0
- package/dist/convex/label-groups/errors.d.ts.map +1 -1
- package/dist/convex/label-groups/errors.js +4 -0
- package/dist/convex/label-groups/errors.js.map +1 -1
- package/dist/convex/label-groups/security.d.ts +19 -0
- package/dist/convex/label-groups/security.d.ts.map +1 -1
- package/dist/convex/label-groups/security.js +20 -0
- package/dist/convex/label-groups/security.js.map +1 -1
- package/dist/convex/label-groups/waitlist.d.ts +8 -0
- package/dist/convex/label-groups/waitlist.d.ts.map +1 -1
- package/dist/convex/label-groups/waitlist.js +9 -0
- package/dist/convex/label-groups/waitlist.js.map +1 -1
- package/dist/convex/label-translations.d.ts.map +1 -1
- package/dist/convex/label-translations.js +24 -0
- package/dist/convex/label-translations.js.map +1 -1
- package/dist/convex/labels.d.ts +57 -0
- package/dist/convex/labels.d.ts.map +1 -1
- package/dist/convex/log.js +2 -0
- package/dist/convex/log.js.map +1 -1
- package/dist/convex/sensitive-actions.d.ts.map +1 -1
- package/dist/convex/sensitive-actions.js +11 -0
- package/dist/convex/sensitive-actions.js.map +1 -1
- package/dist/convex/waitlist-rules.d.ts +63 -9
- package/dist/convex/waitlist-rules.d.ts.map +1 -1
- package/dist/convex/waitlist-rules.js +38 -7
- package/dist/convex/waitlist-rules.js.map +1 -1
- package/dist/devtools-client/_nuxt/DHNi4uhO.js +6 -0
- package/dist/devtools-client/index.html +1 -1
- package/dist/env-registry.js +9 -0
- package/dist/module.d.ts +14 -2
- package/dist/module.js +2 -2
- package/dist/module.json +2 -2
- package/dist/runtime/locales/de.json +58 -1
- package/dist/runtime/locales/en.json +60 -3
- package/dist/runtime/locales/es.json +58 -1
- package/dist/runtime/locales/fr.json +58 -1
- package/dist/runtime/locales/ru.json +58 -1
- package/dist/runtime/server/monitoring/backend-calls.d.ts +3 -3
- package/dist/runtime/server/monitoring/backend-calls.js +2 -2
- package/dist/runtime/server/monitoring/health.js +2 -2
- package/dist/runtime/vue/auth-client.d.ts +3 -2
- package/dist/runtime/vue/auth-client.js +2 -1
- package/dist/runtime/vue/components/account/SecuritySettings.d.vue.ts +25 -2
- package/dist/runtime/vue/components/account/SecuritySettings.vue +52 -2
- package/dist/runtime/vue/components/account/SecuritySettings.vue.d.ts +25 -2
- package/dist/runtime/vue/components/account/SecurityTwoFactor.css +1 -0
- package/dist/runtime/vue/components/account/SecurityTwoFactor.d.vue.ts +4 -0
- package/dist/runtime/vue/components/account/SecurityTwoFactor.vue +107 -0
- package/dist/runtime/vue/components/account/SecurityTwoFactor.vue.d.ts +4 -0
- package/dist/runtime/vue/components/account/security-settings.d.ts +18 -1
- package/dist/runtime/vue/components/admin/AdminUsers.d.vue.ts +11 -2
- package/dist/runtime/vue/components/admin/AdminUsers.vue.d.ts +11 -2
- package/dist/runtime/vue/components/admin/AdminWaitlist.css +1 -1
- package/dist/runtime/vue/components/admin/AdminWaitlistActions.vue +41 -1
- package/dist/runtime/vue/components/admin/AdminWorkspaces.d.vue.ts +9 -0
- package/dist/runtime/vue/components/admin/AdminWorkspaces.vue.d.ts +9 -0
- package/dist/runtime/vue/components/admin/admin-waitlist-tab.js +28 -0
- package/dist/runtime/vue/components/auth/AuthForm.d.vue.ts +9 -0
- package/dist/runtime/vue/components/auth/AuthForm.vue +8 -0
- package/dist/runtime/vue/components/auth/AuthForm.vue.d.ts +9 -0
- package/dist/runtime/vue/components/auth/AuthFormTwoFactor.css +1 -0
- package/dist/runtime/vue/components/auth/AuthFormTwoFactor.d.vue.ts +3 -0
- package/dist/runtime/vue/components/auth/AuthFormTwoFactor.vue +70 -0
- package/dist/runtime/vue/components/auth/AuthFormTwoFactor.vue.d.ts +3 -0
- package/dist/runtime/vue/components/auth/AuthFormWaitlisted.vue +7 -2
- package/dist/runtime/vue/components/auth/WaitlistForm.d.vue.ts +8 -0
- package/dist/runtime/vue/components/auth/WaitlistForm.vue.d.ts +8 -0
- package/dist/runtime/vue/components/auth/WaitlistPlace.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistPlace.vue +37 -0
- package/dist/runtime/vue/components/auth/WaitlistShare.vue +2 -2
- package/dist/runtime/vue/components/auth/auth-form.d.ts +2 -0
- package/dist/runtime/vue/components/workspaces/AuditLog.d.vue.ts +2 -0
- package/dist/runtime/vue/components/workspaces/AuditLog.vue.d.ts +2 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +2 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +2 -2
- package/dist/runtime/vue/composables/use-login-flow.d.ts +19 -4
- package/dist/runtime/vue/composables/use-login-flow.js +31 -0
- package/dist/runtime/vue/composables/use-room-presence.d.ts +63 -0
- package/dist/runtime/vue/composables/use-room-presence.js +31 -0
- package/dist/runtime/vue/composables/use-two-factor.d.ts +58 -0
- package/dist/runtime/vue/composables/use-two-factor.js +49 -0
- package/dist/runtime/vue/composables/use-waitlist-admin.d.ts +5 -0
- package/dist/runtime/vue/composables/use-waitlist-admin.js +5 -1
- package/dist/runtime/vue/composables/use-waitlist.d.ts +4 -0
- package/dist/runtime/vue/composables/use-waitlist.js +1 -1
- package/dist/runtime/vue/parts.d.ts +8 -1
- package/dist/runtime/vue/two-factor-client.d.ts +15 -0
- package/dist/runtime/vue/two-factor-client.js +19 -0
- package/dist/runtime/vue/utils/auth-session.js +10 -1
- package/dist/runtime/vue/utils/login-bindings.js +1 -0
- package/dist/runtime/vue/utils/page-guard.d.ts +2 -2
- package/dist/runtime/vue/utils/page-guard.js +2 -2
- package/dist/shared/{nuxt-backend.BvKvJ1mo.mjs → nuxt-backend.CM_p0XQE.mjs} +1 -1
- package/dist/shared/{nuxt-backend.DRuHg-IQ.mjs → nuxt-backend.C_Y_BtBs.mjs} +2 -2
- package/dist/shared/{nuxt-backend.suXOnqOQ.mjs → nuxt-backend.ChvlbHQq.mjs} +42 -7
- package/dist/shared/{nuxt-backend.0r1vvS1c.mjs → nuxt-backend.D16peTIt.mjs} +56 -34
- package/dist/shared/{nuxt-backend.zY6UDqDu.mjs → nuxt-backend.D4JXvCP6.mjs} +3 -2
- package/dist/types.d.ts +1 -1
- package/package.json +19 -10
- package/skills/nuxt-backend/SKILL.md +18 -18
- package/skills/nuxt-backend/references/api.md +30 -5
- package/skills/nuxt-backend/references/install.md +1 -1
- package/skills/nuxt-backend/references/renames.json +8 -0
- package/skills/nuxt-backend/references/surface.json +62 -2
- package/skills/nuxt-backend-auth/SKILL.md +8 -2
- package/skills/nuxt-backend-auth/references/api.md +3 -1
- package/skills/nuxt-backend-billing/SKILL.md +15 -0
- package/skills/nuxt-backend-billing/references/api.md +14 -1
- package/skills/nuxt-backend-data/SKILL.md +1 -0
- package/skills/nuxt-backend-data/references/api.md +10 -1
- package/skills/nuxt-backend-email/references/api.md +1 -1
- package/skills/nuxt-backend-ship/SKILL.md +2 -1
- package/skills/nuxt-backend-upgrade/references/upgrade.md +6 -0
- package/src/convex/access-tickets.ts +10 -2
- package/src/convex/account-data.ts +5 -4
- package/src/convex/app.ts +2 -1
- package/src/convex/client/better-auth-options.ts +12 -3
- package/src/convex/client/launch-gate.ts +28 -1
- package/src/convex/client/plugins.ts +3 -0
- package/src/convex/client/two-factor.ts +66 -0
- package/src/convex/components/backend/_generated/api.ts +2 -0
- package/src/convex/components/backend/_generated/component.ts +500 -2
- package/src/convex/components/backend/account.ts +25 -1
- package/src/convex/components/backend/adapter.ts +7 -2
- package/src/convex/components/backend/billing.ts +2 -1
- package/src/convex/components/backend/commerce.ts +408 -0
- package/src/convex/components/backend/schema.ts +110 -1
- package/src/convex/components/backend/waitlist.ts +144 -40
- package/src/convex/email-templates.ts +16 -0
- package/src/convex/emails/waitlist-friend-joined.ts +23 -0
- package/src/convex/errors.ts +15 -2
- package/src/convex/events.ts +14 -0
- package/src/convex/integrations/billing/checkout.ts +78 -11
- package/src/convex/integrations/billing/commerce-entitlements.ts +92 -0
- package/src/convex/integrations/billing/commerce-events.ts +487 -0
- package/src/convex/integrations/billing/commerce-history.ts +110 -0
- package/src/convex/integrations/billing/commerce-webhooks.ts +69 -0
- package/src/convex/integrations/billing/commerce.ts +366 -0
- package/src/convex/integrations/billing/context.ts +19 -2
- package/src/convex/integrations/billing/credits.ts +47 -27
- package/src/convex/integrations/billing/customers.ts +15 -1
- package/src/convex/integrations/billing/entitlements.ts +5 -1
- package/src/convex/integrations/billing/erasure.ts +11 -6
- package/src/convex/integrations/billing/free-plan.ts +30 -5
- package/src/convex/integrations/billing/functions.ts +3 -2
- package/src/convex/integrations/billing/gifts.ts +2 -0
- package/src/convex/integrations/billing/history.ts +9 -0
- package/src/convex/integrations/billing/lifecycle.ts +3 -1
- package/src/convex/integrations/billing/providers/capabilities.ts +78 -0
- package/src/convex/integrations/billing/providers/consent.ts +94 -0
- package/src/convex/integrations/billing/providers/creem.ts +225 -0
- package/src/convex/integrations/billing/providers/dodo.ts +214 -0
- package/src/convex/integrations/billing/providers/http.ts +168 -0
- package/src/convex/integrations/billing/providers/index.ts +65 -0
- package/src/convex/integrations/billing/providers/stripe.ts +345 -0
- package/src/convex/integrations/billing/providers/types.ts +281 -0
- package/src/convex/integrations/billing/subscriptions.ts +20 -6
- package/src/convex/integrations/billing/types/setup.ts +63 -1
- package/src/convex/integrations/billing.ts +46 -3
- package/src/convex/integrations/email.ts +1 -0
- package/src/convex/integrations/launch.ts +45 -7
- package/src/convex/integrations/presence.ts +160 -0
- package/src/convex/integrations/waitlist.ts +84 -12
- package/src/convex/integrations/webhook-guard.ts +20 -4
- package/src/convex/label-groups/admin.ts +9 -0
- package/src/convex/label-groups/audit.ts +2 -0
- package/src/convex/label-groups/auth.ts +10 -0
- package/src/convex/label-groups/email.ts +7 -0
- package/src/convex/label-groups/errors.ts +4 -0
- package/src/convex/label-groups/security.ts +20 -0
- package/src/convex/label-groups/waitlist.ts +9 -0
- package/src/convex/label-translations.ts +24 -0
- package/src/convex/log.ts +2 -0
- package/src/convex/sensitive-actions.ts +11 -0
- package/src/convex/waitlist-rules.ts +84 -8
- package/src/runtime/vue/components/account/SecuritySettings.vue +58 -4
- package/src/runtime/vue/components/account/SecurityTwoFactor.css +68 -0
- package/src/runtime/vue/components/account/SecurityTwoFactor.vue +113 -0
- package/src/runtime/vue/components/admin/AdminWaitlist.css +1 -0
- package/src/runtime/vue/components/admin/AdminWaitlistActions.vue +44 -2
- package/src/runtime/vue/components/auth/AuthForm.vue +8 -0
- package/src/runtime/vue/components/auth/AuthFormTwoFactor.css +40 -0
- package/src/runtime/vue/components/auth/AuthFormTwoFactor.vue +75 -0
- package/src/runtime/vue/components/auth/AuthFormWaitlisted.vue +11 -4
- package/src/runtime/vue/components/auth/WaitlistPlace.css +16 -0
- package/src/runtime/vue/components/auth/WaitlistPlace.vue +49 -2
- package/src/runtime/vue/components/auth/WaitlistShare.vue +4 -3
- package/dist/devtools-client/_nuxt/CiCAOwUc.js +0 -5
|
@@ -5,7 +5,7 @@ import { ordersList } from '@polar-sh/sdk/funcs/ordersList.js'
|
|
|
5
5
|
import { logBackend } from '../../log.js'
|
|
6
6
|
import { type BillingContext, isProviderNotFound } from './context.js'
|
|
7
7
|
import type { BillingCustomers } from './customers.js'
|
|
8
|
-
import type { ProviderCtx, RunWriteCtx } from './types/base.js'
|
|
8
|
+
import type { ProviderCtx, RunQueryCtx, RunWriteCtx } from './types/base.js'
|
|
9
9
|
import type { AccountBillingErasure, AccountBillingExport } from './types/surface.js'
|
|
10
10
|
|
|
11
11
|
// Billing's part of an account's export and erasure, in the app: the
|
|
@@ -20,7 +20,7 @@ const EXPORT_ORDERS_MAX = 100
|
|
|
20
20
|
|
|
21
21
|
/** Export and erasure of one `setupBilling` call. */
|
|
22
22
|
export function createBillingErasure(
|
|
23
|
-
{ billTo, provider, accessToken, unwrapProvider }: BillingContext,
|
|
23
|
+
{ billTo, provider, commerce, accessToken, unwrapProvider }: BillingContext,
|
|
24
24
|
forgetEntity: (ctx: RunWriteCtx, entityId: string) => Promise<void>,
|
|
25
25
|
{ mappedCustomer }: Pick<BillingCustomers, 'mappedCustomer'>,
|
|
26
26
|
) {
|
|
@@ -55,17 +55,22 @@ export function createBillingErasure(
|
|
|
55
55
|
*/
|
|
56
56
|
const forgetAccount: AccountBillingErasure = async (ctx, erasure) => {
|
|
57
57
|
for (const entityId of entitiesOf(erasure)) {
|
|
58
|
-
|
|
58
|
+
// An adapter provider, the merchant of record, keeps its customer for its books: it has no erasure call.
|
|
59
|
+
if (accessToken && !commerce) await deleteCustomer(ctx, entityId)
|
|
59
60
|
await forgetEntity(ctx, entityId)
|
|
60
61
|
}
|
|
61
|
-
if (billTo !== 'workspace' || !accessToken) return
|
|
62
|
+
if (billTo !== 'workspace' || !accessToken || commerce) return
|
|
62
63
|
for (const workspaceId of erasure.left) {
|
|
63
64
|
unlessGone(await customersMembersDeleteExternal(provider.polar, { externalId: workspaceId, memberExternalId: erasure.userId }), 'member erasure')
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
/** The newest orders of one entity's customer, as an export lists them; `null` when the provider could not be read. */
|
|
68
|
-
const ordersOf = async (entityId: string) => {
|
|
69
|
+
const ordersOf = async (ctx: RunQueryCtx, entityId: string) => {
|
|
70
|
+
if (commerce) {
|
|
71
|
+
const read = await ctx.runQuery(commerce.refs.listOrders, { entityId, paginationOpts: { cursor: null, numItems: EXPORT_ORDERS_MAX } })
|
|
72
|
+
return read.page.map(order => ({ id: order.orderId, createdAt: new Date(order.createdAt).toISOString(), status: order.status, productId: order.productId ?? null, amount: order.amount, currency: order.currency, billingReason: order.subscriptionId ? 'subscription' : 'purchase' }))
|
|
73
|
+
}
|
|
69
74
|
if (!accessToken) return []
|
|
70
75
|
const result = await ordersList(provider.polar, { externalCustomerId: entityId, limit: EXPORT_ORDERS_MAX, sorting: ['-created_at'] })
|
|
71
76
|
if (!result.ok) {
|
|
@@ -92,7 +97,7 @@ export function createBillingErasure(
|
|
|
92
97
|
const exportAccount: AccountBillingExport = async (ctx, account) => Promise.all(entitiesOf(account).map(async entityId => ({
|
|
93
98
|
entityId,
|
|
94
99
|
subscriptions: await provider.listAllUserSubscriptions(ctx as unknown as ProviderCtx, { userId: entityId }),
|
|
95
|
-
orders: await ordersOf(entityId),
|
|
100
|
+
orders: await ordersOf(ctx, entityId),
|
|
96
101
|
})))
|
|
97
102
|
|
|
98
103
|
return { forgetAccount, exportAccount }
|
|
@@ -112,9 +112,12 @@ export async function pageBillingEntities(ctx: RunQueryCtx, { components, billTo
|
|
|
112
112
|
return { ids: read.page.flatMap(row => row._id ?? row.id ?? []), isDone: read.isDone, continueCursor: read.continueCursor }
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/** A billing entity the free plan starts for, with its profile and the account behind it. */
|
|
116
|
+
interface FoundEntity { entity: BillingEntity, profile: EntityProfile | null, account?: Caller }
|
|
117
|
+
|
|
115
118
|
/** The free plan of one `setupBilling` call: started, recognised, and restarted when a paid plan ends. */
|
|
116
119
|
export function createFreePlan(
|
|
117
|
-
{ freePlan, billTo, provider, components, accessToken, unwrapProvider, entityDeleting: deleting, catalogIds }: BillingContext,
|
|
120
|
+
{ freePlan, billTo, provider, components, accessToken, unwrapProvider, entityDeleting: deleting, catalogIds, commerce }: BillingContext,
|
|
118
121
|
{ ensureCustomer, profileOf }: Pick<BillingCustomers, 'ensureCustomer' | 'profileOf'>,
|
|
119
122
|
) {
|
|
120
123
|
// The scaffold's `startFreePlan` (`billing.api.startFreePlan`), by the
|
|
@@ -151,6 +154,11 @@ export function createFreePlan(
|
|
|
151
154
|
* `firstStart`, and on its own for a first start whose answer was lost.
|
|
152
155
|
*/
|
|
153
156
|
queueWelcome?: (ctx: RunWriteCtx, entityId: string, owner: { userId: string, email: string }) => Promise<void>
|
|
157
|
+
/**
|
|
158
|
+
* The start on an adapter provider, which holds no free plan: the app's
|
|
159
|
+
* own credit cycle, `first` run for an entity that never had billing.
|
|
160
|
+
*/
|
|
161
|
+
localStart?: (ctx: RunWriteCtx, entityId: string, first: () => Promise<void>) => Promise<FreePlanStart>
|
|
154
162
|
} = {}
|
|
155
163
|
|
|
156
164
|
/**
|
|
@@ -212,7 +220,7 @@ export function createFreePlan(
|
|
|
212
220
|
* exists: a workspace by its profile (its owner's email), a user by their
|
|
213
221
|
* account. A workspace whose owner left can't own a customer: `null` too.
|
|
214
222
|
*/
|
|
215
|
-
const entityOf = async (ctx: RunQueryCtx, entityId: string): Promise<
|
|
223
|
+
const entityOf = async (ctx: RunQueryCtx, entityId: string): Promise<FoundEntity | null> => {
|
|
216
224
|
if (billTo === 'workspace') {
|
|
217
225
|
const profile = await profileOf(ctx, entityId)
|
|
218
226
|
return profile?.owner ? { entity: { userId: entityId, email: profile.owner.email }, profile } : null
|
|
@@ -268,12 +276,29 @@ export function createFreePlan(
|
|
|
268
276
|
* subscribed.
|
|
269
277
|
*/
|
|
270
278
|
const start = async (ctx: RunWriteCtx, entityId: string, kind?: CreatedEntityKind): Promise<FreePlanStart> => {
|
|
271
|
-
|
|
279
|
+
// On an adapter provider a paid plan's monthly credit cycle runs here too, free plan or not.
|
|
280
|
+
if (!freePlan && !commerce) return 'no_plan'
|
|
272
281
|
// A workspace with `billTo: 'user'`, an account without: queued by name, never billed.
|
|
273
282
|
if (kind && kind !== billedKind) return 'not_billed'
|
|
274
|
-
if (!accessToken) return 'not_configured'
|
|
283
|
+
if (!accessToken && !commerce) return 'not_configured'
|
|
275
284
|
const found = await deleting(ctx, entityId) ? null : await entityOf(ctx, entityId)
|
|
276
285
|
if (!found) return 'gone'
|
|
286
|
+
// The free plan is the app's own on an adapter provider: no subscription, its credits a cycle of grants.
|
|
287
|
+
if (commerce) return await localStart(ctx, entityId, found)
|
|
288
|
+
return freePlan ? await providerStart(ctx, entityId, found, freePlan.productId) : 'no_plan'
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The start on an adapter provider: the app's own credit cycle, the welcome credits queued the first time. */
|
|
292
|
+
const localStart = async (ctx: RunWriteCtx, entityId: string, found: FoundEntity): Promise<FreePlanStart> => {
|
|
293
|
+
if (!hooks.localStart) return 'no_plan'
|
|
294
|
+
const owner = found.profile?.owner ?? found.account
|
|
295
|
+
return await hooks.localStart(ctx, entityId, async () => {
|
|
296
|
+
if (owner && hooks.queueWelcome) await hooks.queueWelcome(ctx, entityId, { userId: owner.userId, email: owner.email })
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** The start on Polar: the free plan's subscription at the provider, once. */
|
|
301
|
+
const providerStart = async (ctx: RunWriteCtx, entityId: string, found: FoundEntity, productId: string): Promise<FreePlanStart> => {
|
|
277
302
|
try {
|
|
278
303
|
await ensureCustomer(ctx, found.entity, found.profile, 'free plan', found.account)
|
|
279
304
|
}
|
|
@@ -286,7 +311,7 @@ export function createFreePlan(
|
|
|
286
311
|
if (held.length > 0) return await subscribedAlready(ctx, entityId, held, found)
|
|
287
312
|
// Its first subscription ever: none was synced for it, ended or not.
|
|
288
313
|
const first = (await provider.listAllUserSubscriptions(ctx as unknown as ProviderCtx, { userId: entityId })).length === 0
|
|
289
|
-
const created = await subscriptionsCreate(provider.polar, { productId
|
|
314
|
+
const created = await subscriptionsCreate(provider.polar, { productId, externalCustomerId: entityId })
|
|
290
315
|
if (!created.ok) {
|
|
291
316
|
const after = await providerSubscriptions(entityId)
|
|
292
317
|
if (after.length > 0) return await subscribedAlready(ctx, entityId, after, found)
|
|
@@ -41,7 +41,7 @@ const LIVE_SUBSCRIPTION_STATUSES = new Set(['active', 'trialing', 'past_due', 'p
|
|
|
41
41
|
|
|
42
42
|
/** The registered queries and actions `setupBilling` hands the app in `billing.api`. */
|
|
43
43
|
export function createBillingFunctions(
|
|
44
|
-
{ components, config, products, creditMeters, meterNameById, provider, cache, allowedEntity, requireEntity, throttle, requireAdmin, requireProviderAccess, syncProducts: syncProductsTable }: BillingContext,
|
|
44
|
+
{ components, config, products, creditMeters, meterNameById, provider, commerce, cache, allowedEntity, requireEntity, throttle, requireAdmin, requireProviderAccess, syncProducts: syncProductsTable }: BillingContext,
|
|
45
45
|
{ refreshEntitlements }: BillingEntitlements,
|
|
46
46
|
{ withChanges, updateSubscription, uncancelSubscription, cancelPendingChange, pauseSubscription, resumeSubscription }: BillingSubscriptions,
|
|
47
47
|
{ getOrders, getInvoiceUrl, getUsageHistory, refundOrder }: BillingHistory,
|
|
@@ -259,7 +259,8 @@ export function createBillingFunctions(
|
|
|
259
259
|
// can't loop this to burn the access token's quota / trip provider limits.
|
|
260
260
|
await throttle(ctx, userId, 'entitlement syncs')
|
|
261
261
|
// A gift the return cannot settle is the webhook's to settle: the refresh goes ahead.
|
|
262
|
-
|
|
262
|
+
// Gifts are Polar's: an adapter provider's checkout settles none.
|
|
263
|
+
if (checkoutId && !commerce) {
|
|
263
264
|
await settleCheckout(ctx, checkoutId.slice(0, 200)).catch((error: unknown) => {
|
|
264
265
|
logBackend('warn', 'billing.gift_settle_failed', 'A return from a gift checkout could not settle the gift; its order.paid webhook still does.', error)
|
|
265
266
|
})
|
|
@@ -9,6 +9,7 @@ import { v } from 'convex/values'
|
|
|
9
9
|
import { BILLING_MANAGER_ROLES, RUN_GIFT_SWEEP_FUNCTION } from '../../constants.js'
|
|
10
10
|
import { hasAnyRole } from '../access.js'
|
|
11
11
|
import { mintClaimDiscount, voidClaimDiscount } from './claim-discount.js'
|
|
12
|
+
import { polarOnly } from './commerce.js'
|
|
12
13
|
import { type BillingContext, isProviderNotFound } from './context.js'
|
|
13
14
|
import { readEnv, UNDELIVERABLE_CAUSES, undeliverableReason } from '../../delivery.js'
|
|
14
15
|
import type { BillingCustomers } from './customers.js'
|
|
@@ -266,6 +267,7 @@ export function createGifts(
|
|
|
266
267
|
const purchaser = await giftCaller(ctx, 'giftCheckout', GIFT_ACCESS.buy, account)
|
|
267
268
|
await refusePaused(paused, ctx, 'checkout')
|
|
268
269
|
requireLaunched('gift checkout')
|
|
270
|
+
if (context.commerce) throw polarOnly(context.commerce.name, 'a gift')
|
|
269
271
|
const recipientEmail = requireRecipient(args.recipientEmail, purchaser.email)
|
|
270
272
|
const message = giftMessage(args.message)
|
|
271
273
|
const deliverAt = giftDeliverAt(args.deliverAt)
|
|
@@ -5,6 +5,7 @@ import { ordersInvoice } from '@polar-sh/sdk/funcs/ordersInvoice.js'
|
|
|
5
5
|
import { ordersList } from '@polar-sh/sdk/funcs/ordersList.js'
|
|
6
6
|
import { refundsCreate } from '@polar-sh/sdk/funcs/refundsCreate.js'
|
|
7
7
|
import { ADMIN_WRITE, BILLING_ACCESS, type BillingContext, isProviderNotFound, resolveLimit, resolvePage } from './context.js'
|
|
8
|
+
import { createCommerceHistory } from './commerce-history.js'
|
|
8
9
|
import type { BillingCustomers } from './customers.js'
|
|
9
10
|
import type { ProviderCtx } from './types/base.js'
|
|
10
11
|
import type { BillingOrder, UsageEvent } from './types/options.js'
|
|
@@ -45,6 +46,14 @@ function isFreeCycle(order: { totalAmount?: number, billingReason?: string, subs
|
|
|
45
46
|
|
|
46
47
|
/** Orders, invoices, usage and refunds: live provider reads — no local ledger. */
|
|
47
48
|
export function createHistory(
|
|
49
|
+
context: BillingContext,
|
|
50
|
+
customers: Pick<BillingCustomers, 'keyedCustomer'>,
|
|
51
|
+
) {
|
|
52
|
+
// Adapter mode reads the app's order ledger, and its provider's invoice and refund.
|
|
53
|
+
return context.commerce ? createCommerceHistory(context) : createPolarHistory(context, customers)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createPolarHistory(
|
|
48
57
|
{
|
|
49
58
|
components,
|
|
50
59
|
accessToken,
|
|
@@ -103,7 +103,7 @@ function offerRuleProblem(rule: SaveOfferRule): string | undefined {
|
|
|
103
103
|
|
|
104
104
|
/** The billing lifecycle of one `setupBilling` call. */
|
|
105
105
|
export function createLifecycle(
|
|
106
|
-
{ components, config, catalogIds, provider, requireEntity, allowedEntity, unwrapProvider, throttle, recordEvent, cache }: BillingContext,
|
|
106
|
+
{ components, config, catalogIds, provider, requireEntity, allowedEntity, unwrapProvider, throttle, recordEvent, cache, commerce }: BillingContext,
|
|
107
107
|
subscriptions: BillingSubscriptions,
|
|
108
108
|
discounts: CatalogDiscounts,
|
|
109
109
|
passes: Pick<BillingPasses, 'managersOf' | 'planName' | 'startTrialPass'>,
|
|
@@ -158,6 +158,8 @@ export function createLifecycle(
|
|
|
158
158
|
*/
|
|
159
159
|
const termsOf = async (ctx: RunQueryCtx, subscription: SyncedSubscription, rule: SaveOfferRule) => {
|
|
160
160
|
const periodEnd = epochOf(subscription.currentPeriodEnd)
|
|
161
|
+
// An adapter provider (Stripe, Dodo, Creem) pauses with no resume date and takes no catalog discount: neither offer is made there.
|
|
162
|
+
if (commerce && !('downgrade' in rule)) return null
|
|
161
163
|
if ('pause' in rule) {
|
|
162
164
|
if (periodEnd === null || subscription.status !== 'active') return null
|
|
163
165
|
return { kind: 'pause' as const, months: rule.pause.months, resumesAt: addMonths(periodEnd, rule.pause.months) }
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { BillingProviderName, ProviderCapabilities } from './types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What each provider's API offers, checked against its docs on 2026-11-24.
|
|
5
|
+
* The doctor and the docs read this table; a call a provider lacks throws
|
|
6
|
+
* `ProviderUnsupportedError` and the app sends the customer to the portal
|
|
7
|
+
* (or the seller to the dashboard) instead.
|
|
8
|
+
*
|
|
9
|
+
* - Stripe Managed Payments: docs.stripe.com/payments/managed-payments
|
|
10
|
+
* - Dodo Payments: docs.dodopayments.com/api-reference
|
|
11
|
+
* - Creem: docs.creem.io/api-reference. No refund or invoice endpoint is
|
|
12
|
+
* documented: refunds are made in the dashboard (the `refund.created`
|
|
13
|
+
* webhook still reaches the app) and Creem emails every receipt.
|
|
14
|
+
*
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
export const PROVIDER_CAPABILITIES: Readonly<Record<BillingProviderName, ProviderCapabilities>> = {
|
|
18
|
+
polar: {
|
|
19
|
+
oneTime: true,
|
|
20
|
+
subscriptions: true,
|
|
21
|
+
customerPortal: true,
|
|
22
|
+
changePlan: true,
|
|
23
|
+
cancelAtPeriodEnd: true,
|
|
24
|
+
uncancel: true,
|
|
25
|
+
pause: false,
|
|
26
|
+
refundApi: true,
|
|
27
|
+
invoices: true,
|
|
28
|
+
discountCodes: true,
|
|
29
|
+
signedRedirect: false,
|
|
30
|
+
merchantOfRecord: true,
|
|
31
|
+
sendsReceipts: true,
|
|
32
|
+
},
|
|
33
|
+
stripe: {
|
|
34
|
+
oneTime: true,
|
|
35
|
+
subscriptions: true,
|
|
36
|
+
customerPortal: true,
|
|
37
|
+
changePlan: true,
|
|
38
|
+
cancelAtPeriodEnd: true,
|
|
39
|
+
uncancel: true,
|
|
40
|
+
pause: false,
|
|
41
|
+
refundApi: true,
|
|
42
|
+
invoices: true,
|
|
43
|
+
discountCodes: true,
|
|
44
|
+
signedRedirect: false,
|
|
45
|
+
merchantOfRecord: true,
|
|
46
|
+
sendsReceipts: true,
|
|
47
|
+
},
|
|
48
|
+
dodo: {
|
|
49
|
+
oneTime: true,
|
|
50
|
+
subscriptions: true,
|
|
51
|
+
customerPortal: true,
|
|
52
|
+
changePlan: true,
|
|
53
|
+
cancelAtPeriodEnd: true,
|
|
54
|
+
uncancel: true,
|
|
55
|
+
pause: true,
|
|
56
|
+
refundApi: true,
|
|
57
|
+
invoices: true,
|
|
58
|
+
discountCodes: true,
|
|
59
|
+
signedRedirect: false,
|
|
60
|
+
merchantOfRecord: true,
|
|
61
|
+
sendsReceipts: true,
|
|
62
|
+
},
|
|
63
|
+
creem: {
|
|
64
|
+
oneTime: true,
|
|
65
|
+
subscriptions: true,
|
|
66
|
+
customerPortal: true,
|
|
67
|
+
changePlan: true,
|
|
68
|
+
cancelAtPeriodEnd: true,
|
|
69
|
+
uncancel: true,
|
|
70
|
+
pause: true,
|
|
71
|
+
refundApi: false,
|
|
72
|
+
invoices: false,
|
|
73
|
+
discountCodes: true,
|
|
74
|
+
signedRedirect: true,
|
|
75
|
+
merchantOfRecord: true,
|
|
76
|
+
sendsReceipts: true,
|
|
77
|
+
},
|
|
78
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { sha256Hex } from './http.js'
|
|
2
|
+
|
|
3
|
+
// The EU consent that lets digital content (a comic issue, an e-book, a
|
|
4
|
+
// credit pack) be delivered at once without a 14-day withdrawal window. Under
|
|
5
|
+
// the Consumer Rights Directive (2011/83/EU, as amended by 2019/2161), the
|
|
6
|
+
// right of withdrawal ends when delivery starts only if the buyer
|
|
7
|
+
//
|
|
8
|
+
// 1. gave prior express consent to delivery starting within the window,
|
|
9
|
+
// 2. acknowledged that they lose the right of withdrawal by it, and
|
|
10
|
+
// 3. got a confirmation of the contract on a durable medium that records
|
|
11
|
+
// both (Art. 16(m) with Art. 8(7)).
|
|
12
|
+
//
|
|
13
|
+
// Without all three the buyer may withdraw within 14 days and owes nothing
|
|
14
|
+
// for what they already read (Art. 14(4)(b)). The app asks for (1) and (2)
|
|
15
|
+
// with an unticked checkbox beside the buy button, and the checkout carries
|
|
16
|
+
// the proof in the order's metadata, where it stays with the provider's
|
|
17
|
+
// record of the sale. (3) is the merchant of record's receipt plus the app's
|
|
18
|
+
// own order confirmation email (see the docs' "Sell digital content in the
|
|
19
|
+
// EU" page). Not legal advice.
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The version of the wording below: bump it whenever the text changes, so a record names what was shown.
|
|
23
|
+
*
|
|
24
|
+
* @experimental
|
|
25
|
+
*/
|
|
26
|
+
export const DIGITAL_CONTENT_CONSENT_VERSION = '2026-11-24'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The checkbox's text, in English. Translate it with the app's labels; the record keeps the hash of what was shown.
|
|
30
|
+
*
|
|
31
|
+
* @experimental
|
|
32
|
+
*/
|
|
33
|
+
export const DIGITAL_CONTENT_CONSENT_TEXT
|
|
34
|
+
= 'I want access to start right away, and I understand that I lose my right to withdraw from this purchase once it starts.'
|
|
35
|
+
|
|
36
|
+
/** The metadata keys the proof travels under: short, as every provider caps key length. */
|
|
37
|
+
export const CONSENT_METADATA_KEYS = {
|
|
38
|
+
at: 'dc_consent_at',
|
|
39
|
+
version: 'dc_consent_v',
|
|
40
|
+
text: 'dc_consent_text',
|
|
41
|
+
} as const
|
|
42
|
+
|
|
43
|
+
/** What the buyer agreed to, as a checkout records it. */
|
|
44
|
+
export interface DigitalContentConsent {
|
|
45
|
+
/** When they ticked it, in Unix milliseconds. */
|
|
46
|
+
at: number
|
|
47
|
+
version: string
|
|
48
|
+
/** The SHA-256 hex of the exact text shown, in the language shown. */
|
|
49
|
+
textHash: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The proof for a checkout of digital content, from what the page sent: it
|
|
54
|
+
* refuses unless `accepted` is the literal `true` (a pre-ticked box or a
|
|
55
|
+
* missing field is no consent), and hashes the text the page showed.
|
|
56
|
+
*
|
|
57
|
+
* @experimental
|
|
58
|
+
*/
|
|
59
|
+
export async function recordDigitalContentConsent(input: { accepted: unknown, text?: string, version?: string, now?: number }): Promise<DigitalContentConsent> {
|
|
60
|
+
if (input.accepted !== true) {
|
|
61
|
+
throw new Error('[nuxt-backend] This purchase starts delivery at once: the buyer must tick the consent to immediate access and the loss of the withdrawal right first.')
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
at: input.now ?? Date.now(),
|
|
65
|
+
version: input.version ?? DIGITAL_CONTENT_CONSENT_VERSION,
|
|
66
|
+
textHash: await sha256Hex(input.text ?? DIGITAL_CONTENT_CONSENT_TEXT),
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The proof as checkout metadata.
|
|
72
|
+
*
|
|
73
|
+
* @experimental
|
|
74
|
+
*/
|
|
75
|
+
export function consentMetadata(consent: DigitalContentConsent): Record<string, string> {
|
|
76
|
+
return {
|
|
77
|
+
[CONSENT_METADATA_KEYS.at]: new Date(consent.at).toISOString(),
|
|
78
|
+
[CONSENT_METADATA_KEYS.version]: consent.version,
|
|
79
|
+
[CONSENT_METADATA_KEYS.text]: consent.textHash.slice(0, 64),
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The proof an order's metadata carries back in a webhook, or `null` when the checkout had none.
|
|
85
|
+
*
|
|
86
|
+
* @experimental
|
|
87
|
+
*/
|
|
88
|
+
export function consentFromMetadata(metadata: Readonly<Record<string, string>>): DigitalContentConsent | null {
|
|
89
|
+
const at = Date.parse(metadata[CONSENT_METADATA_KEYS.at] ?? '')
|
|
90
|
+
const version = metadata[CONSENT_METADATA_KEYS.version]
|
|
91
|
+
const textHash = metadata[CONSENT_METADATA_KEYS.text]
|
|
92
|
+
if (Number.isNaN(at) || !version || !textHash) return null
|
|
93
|
+
return { at, version, textHash }
|
|
94
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { PROVIDER_CAPABILITIES } from './capabilities.js'
|
|
2
|
+
import { constantTimeEqual, ENTITY_METADATA_KEY, hmacSha256Hex, idOf, millis, num, providerClient, sha256Hex, str, stringMetadata } from './http.js'
|
|
3
|
+
import {
|
|
4
|
+
type CommerceProvider,
|
|
5
|
+
type NeutralBillingEvent,
|
|
6
|
+
type NeutralOrder,
|
|
7
|
+
type NeutralRefund,
|
|
8
|
+
type NeutralSubscription,
|
|
9
|
+
type NeutralSubscriptionStatus,
|
|
10
|
+
type ProviderOptions,
|
|
11
|
+
ProviderUnsupportedError,
|
|
12
|
+
type VerifiedDelivery,
|
|
13
|
+
} from './types.js'
|
|
14
|
+
|
|
15
|
+
// Creem: a merchant of record that sells in its own name, handles sales tax
|
|
16
|
+
// and VAT, and emails receipts. Its API has no refund or invoice endpoint:
|
|
17
|
+
// refunds are made in its dashboard, and the `refund.created` webhook still
|
|
18
|
+
// tells the app. Its webhooks carry an HMAC of the body alone, with no
|
|
19
|
+
// timestamp, so a replay is caught by the delivery log's dedupe on the
|
|
20
|
+
// event id, never by the signature.
|
|
21
|
+
// https://docs.creem.io/api-reference/introduction
|
|
22
|
+
|
|
23
|
+
/** Creem's hosts: test mode and production take separate keys. */
|
|
24
|
+
export const CREEM_BASE_URLS = {
|
|
25
|
+
sandbox: 'https://test-api.creem.io/v1',
|
|
26
|
+
production: 'https://api.creem.io/v1',
|
|
27
|
+
} as const
|
|
28
|
+
|
|
29
|
+
const CREEM_STATUSES: Readonly<Record<string, NeutralSubscriptionStatus>> = {
|
|
30
|
+
trialing: 'trialing',
|
|
31
|
+
active: 'active',
|
|
32
|
+
scheduled_cancel: 'active',
|
|
33
|
+
past_due: 'past_due',
|
|
34
|
+
unpaid: 'past_due',
|
|
35
|
+
paused: 'paused',
|
|
36
|
+
canceled: 'ended',
|
|
37
|
+
expired: 'ended',
|
|
38
|
+
incomplete: 'incomplete',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- the provider's JSON, read field by field */
|
|
42
|
+
|
|
43
|
+
/** A Creem subscription in neutral words. */
|
|
44
|
+
export function creemSubscription(subscription: any): NeutralSubscription {
|
|
45
|
+
const metadata = stringMetadata(subscription.metadata)
|
|
46
|
+
return {
|
|
47
|
+
id: String(subscription.id),
|
|
48
|
+
customerId: idOf(subscription.customer),
|
|
49
|
+
entityId: metadata[ENTITY_METADATA_KEY] ?? null,
|
|
50
|
+
productId: idOf(subscription.product),
|
|
51
|
+
status: CREEM_STATUSES[subscription.status] ?? 'incomplete',
|
|
52
|
+
cancelAtPeriodEnd: subscription.status === 'scheduled_cancel',
|
|
53
|
+
currentPeriodEnd: millis(subscription.current_period_end_date),
|
|
54
|
+
metadata,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A completed checkout's order. The transaction id is the order id, as a
|
|
60
|
+
* `refund.created` names the transaction it refunds.
|
|
61
|
+
*/
|
|
62
|
+
export function creemCheckoutOrder(checkout: any): NeutralOrder {
|
|
63
|
+
const order = checkout.order ?? {}
|
|
64
|
+
const metadata = stringMetadata(checkout.metadata)
|
|
65
|
+
return {
|
|
66
|
+
id: idOf(order.transaction) ?? String(order.id ?? checkout.id),
|
|
67
|
+
customerId: idOf(checkout.customer) ?? idOf(order.customer),
|
|
68
|
+
entityId: metadata[ENTITY_METADATA_KEY] ?? null,
|
|
69
|
+
productId: idOf(checkout.product) ?? idOf(order.product),
|
|
70
|
+
subscriptionId: idOf(checkout.subscription),
|
|
71
|
+
amount: num(order.amount_paid) ?? num(order.amount) ?? 0,
|
|
72
|
+
taxAmount: num(order.tax_amount),
|
|
73
|
+
currency: String(order.currency ?? '').toLowerCase(),
|
|
74
|
+
metadata,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A subscription's charge (`subscription.paid`) as an order: its last transaction. */
|
|
79
|
+
export function creemRenewalOrder(subscription: any): NeutralOrder {
|
|
80
|
+
const transaction = subscription.last_transaction ?? {}
|
|
81
|
+
const metadata = stringMetadata(subscription.metadata)
|
|
82
|
+
return {
|
|
83
|
+
id: String(transaction.id ?? subscription.last_transaction_id ?? subscription.id),
|
|
84
|
+
customerId: idOf(subscription.customer),
|
|
85
|
+
entityId: metadata[ENTITY_METADATA_KEY] ?? null,
|
|
86
|
+
productId: idOf(subscription.product),
|
|
87
|
+
subscriptionId: str(subscription.id),
|
|
88
|
+
amount: num(transaction.amount_paid) ?? num(transaction.amount) ?? 0,
|
|
89
|
+
taxAmount: num(transaction.tax_amount),
|
|
90
|
+
currency: String(transaction.currency ?? '').toLowerCase(),
|
|
91
|
+
metadata,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function creemRefund(refund: any): NeutralRefund {
|
|
96
|
+
return {
|
|
97
|
+
id: String(refund.id),
|
|
98
|
+
orderId: idOf(refund.transaction),
|
|
99
|
+
subscriptionId: idOf(refund.subscription),
|
|
100
|
+
amount: num(refund.refund_amount),
|
|
101
|
+
currency: str(refund.refund_currency)?.toLowerCase() ?? null,
|
|
102
|
+
status: refund.status === 'succeeded' ? 'succeeded' : refund.status === 'failed' ? 'failed' : 'pending',
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A verified Creem event in neutral words. */
|
|
107
|
+
export function readCreemEvent(event: any): NeutralBillingEvent {
|
|
108
|
+
const providerType = String(event.eventType)
|
|
109
|
+
const object = event.object ?? {}
|
|
110
|
+
switch (providerType) {
|
|
111
|
+
case 'checkout.completed':
|
|
112
|
+
// A subscription's charges arrive as `subscription.paid`, its first
|
|
113
|
+
// one included, so only a one-time checkout is an order here.
|
|
114
|
+
return object.subscription
|
|
115
|
+
? { type: 'ignored', providerType }
|
|
116
|
+
: { type: 'order.paid', order: creemCheckoutOrder(object), providerType }
|
|
117
|
+
case 'subscription.paid':
|
|
118
|
+
return { type: 'order.paid', order: creemRenewalOrder(object), providerType }
|
|
119
|
+
case 'refund.created':
|
|
120
|
+
return { type: 'order.refunded', refund: creemRefund(object), providerType }
|
|
121
|
+
case 'dispute.created':
|
|
122
|
+
return { type: 'order.disputed', orderId: idOf(object.transaction), subscriptionId: idOf(object.subscription), providerType }
|
|
123
|
+
default:
|
|
124
|
+
return providerType.startsWith('subscription.')
|
|
125
|
+
? { type: 'subscription.updated', subscription: creemSubscription(object), providerType }
|
|
126
|
+
: { type: 'ignored', providerType }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Whether `signature` (the `creem-signature` header) is the HMAC-SHA256 hex of `body` under one of `secrets`. */
|
|
131
|
+
export async function verifyCreemSignature(body: string, signature: string | null, secrets: readonly string[]): Promise<boolean> {
|
|
132
|
+
if (!signature) return false
|
|
133
|
+
for (const secret of secrets) {
|
|
134
|
+
if (secret && constantTimeEqual(signature.trim().toLowerCase(), await hmacSha256Hex(secret, body))) return true
|
|
135
|
+
}
|
|
136
|
+
return false
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Whether the query Creem appends to a checkout's success URL is its own:
|
|
141
|
+
* a SHA-256 hex over the `key=value` pairs in URL order, empty ones
|
|
142
|
+
* dropped, joined by `|`, with `salt=<api key>` last.
|
|
143
|
+
*/
|
|
144
|
+
async function verifyCreemRedirect(search: string | URLSearchParams, apiKey: string): Promise<boolean> {
|
|
145
|
+
const params = typeof search === 'string' ? new URLSearchParams(search) : search
|
|
146
|
+
const signature = params.get('signature')
|
|
147
|
+
if (!signature) return false
|
|
148
|
+
const pairs: string[] = []
|
|
149
|
+
for (const [key, value] of params) {
|
|
150
|
+
if (key !== 'signature' && value && value !== 'null') pairs.push(`${key}=${value}`)
|
|
151
|
+
}
|
|
152
|
+
pairs.push(`salt=${apiKey}`)
|
|
153
|
+
return constantTimeEqual(signature.toLowerCase(), await sha256Hex(pairs.join('|')))
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The Creem adapter. */
|
|
157
|
+
export function createCreemProvider({ apiKey, environment, fetch: fetchImpl }: ProviderOptions): CommerceProvider {
|
|
158
|
+
const call = providerClient('creem', CREEM_BASE_URLS[environment], { 'x-api-key': apiKey }, fetchImpl)
|
|
159
|
+
const subscriptionPath = (id: string) => `subscriptions/${encodeURIComponent(id)}`
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
name: 'creem',
|
|
163
|
+
environment,
|
|
164
|
+
capabilities: PROVIDER_CAPABILITIES.creem,
|
|
165
|
+
createCheckout: async (request) => {
|
|
166
|
+
const { providerCustomerId, email, entityId } = request.customer
|
|
167
|
+
const checkout = await call<{ id: string, checkout_url: string }>('checkout', {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
path: 'checkouts',
|
|
170
|
+
body: {
|
|
171
|
+
product_id: request.productId,
|
|
172
|
+
// Creem's own reference for the checkout, returned on the success URL and every webhook.
|
|
173
|
+
request_id: request.idempotencyKey ?? entityId,
|
|
174
|
+
units: request.quantity,
|
|
175
|
+
discount_code: request.discountCode,
|
|
176
|
+
customer: providerCustomerId ? { id: providerCustomerId } : email ? { email } : undefined,
|
|
177
|
+
success_url: request.successUrl,
|
|
178
|
+
metadata: { ...request.metadata, [ENTITY_METADATA_KEY]: entityId },
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
return { id: checkout.id, url: checkout.checkout_url }
|
|
182
|
+
},
|
|
183
|
+
customerPortalUrl: async (customerId) => {
|
|
184
|
+
const portal = await call<{ customer_portal_link: string }>('portal', { method: 'POST', path: 'customers/billing', body: { customer_id: customerId } })
|
|
185
|
+
return portal.customer_portal_link
|
|
186
|
+
},
|
|
187
|
+
getSubscription: async id => creemSubscription(await call('subscription read', { method: 'GET', path: 'subscriptions', query: { subscription_id: id } })),
|
|
188
|
+
changePlan: async ({ subscriptionId, productId, proration, quantity }) => {
|
|
189
|
+
// Creem's upgrade takes a product only: units change in a separate update.
|
|
190
|
+
if (quantity !== undefined) throw new ProviderUnsupportedError('creem', 'change the quantity in a plan change', 'change the product alone, or let the customer change seats in the Creem portal.')
|
|
191
|
+
await call('plan change', {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
path: `${subscriptionPath(subscriptionId)}/upgrade`,
|
|
194
|
+
body: { product_id: productId, update_behavior: proration === 'immediately' ? 'proration-charge-immediately' : 'proration-none' },
|
|
195
|
+
})
|
|
196
|
+
},
|
|
197
|
+
cancelSubscription: async (id, options) => {
|
|
198
|
+
await call('cancellation', { method: 'POST', path: `${subscriptionPath(id)}/cancel`, body: { mode: options?.immediately ? 'immediate' : 'scheduled' } })
|
|
199
|
+
},
|
|
200
|
+
// Resuming before the period ends takes a scheduled cancellation back.
|
|
201
|
+
uncancelSubscription: async (id) => {
|
|
202
|
+
await call('uncancellation', { method: 'POST', path: `${subscriptionPath(id)}/resume` })
|
|
203
|
+
},
|
|
204
|
+
pauseSubscription: async (id) => {
|
|
205
|
+
await call('pause', { method: 'POST', path: `${subscriptionPath(id)}/pause` })
|
|
206
|
+
},
|
|
207
|
+
resumeSubscription: async (id) => {
|
|
208
|
+
await call('resume', { method: 'POST', path: `${subscriptionPath(id)}/resume` })
|
|
209
|
+
},
|
|
210
|
+
refundOrder: async () => {
|
|
211
|
+
throw new ProviderUnsupportedError('creem', 'refund an order', 'refund it in the Creem dashboard; the refund.created webhook updates the app.')
|
|
212
|
+
},
|
|
213
|
+
invoice: async () => {
|
|
214
|
+
throw new ProviderUnsupportedError('creem', 'read an invoice', 'Creem emails each receipt to the customer, and the portal lists them.')
|
|
215
|
+
},
|
|
216
|
+
verifyWebhook: async (body, headers, secrets): Promise<VerifiedDelivery | null> => {
|
|
217
|
+
if (!await verifyCreemSignature(body, headers.get('creem-signature'), secrets)) return null
|
|
218
|
+
const event = JSON.parse(body)
|
|
219
|
+
return { id: String(event.id), event: readCreemEvent(event) }
|
|
220
|
+
},
|
|
221
|
+
verifyCheckoutRedirect: search => verifyCreemRedirect(search, apiKey),
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|