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