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,214 @@
|
|
|
1
|
+
import { verifyWebhookSignature } from '../../../webhook-signatures.js'
|
|
2
|
+
import { PROVIDER_CAPABILITIES } from './capabilities.js'
|
|
3
|
+
import { ENTITY_METADATA_KEY, idOf, millis, num, providerClient, str, stringMetadata } from './http.js'
|
|
4
|
+
import type {
|
|
5
|
+
CommerceProvider,
|
|
6
|
+
NeutralBillingEvent,
|
|
7
|
+
NeutralOrder,
|
|
8
|
+
NeutralRefund,
|
|
9
|
+
NeutralSubscription,
|
|
10
|
+
NeutralSubscriptionStatus,
|
|
11
|
+
ProviderOptions,
|
|
12
|
+
VerifiedDelivery,
|
|
13
|
+
} from './types.js'
|
|
14
|
+
import { ProviderHttpError, ProviderUnsupportedError } from './types.js'
|
|
15
|
+
|
|
16
|
+
// Dodo Payments: a merchant of record that sells in its own name, collects
|
|
17
|
+
// and remits sales tax and VAT, and emails the receipts. Its webhooks sign
|
|
18
|
+
// to Standard Webhooks, so they go through the package's one verifier
|
|
19
|
+
// (webhook-signatures.ts), the same one Polar's and Resend's do.
|
|
20
|
+
// https://docs.dodopayments.com/api-reference/introduction
|
|
21
|
+
|
|
22
|
+
/** Dodo's hosts: test mode and live mode take separate keys. */
|
|
23
|
+
export const DODO_BASE_URLS = {
|
|
24
|
+
sandbox: 'https://test.dodopayments.com',
|
|
25
|
+
production: 'https://live.dodopayments.com',
|
|
26
|
+
} as const
|
|
27
|
+
|
|
28
|
+
const DODO_STATUSES: Readonly<Record<string, NeutralSubscriptionStatus>> = {
|
|
29
|
+
pending: 'incomplete',
|
|
30
|
+
active: 'active',
|
|
31
|
+
on_hold: 'past_due',
|
|
32
|
+
past_due: 'past_due',
|
|
33
|
+
paused: 'paused',
|
|
34
|
+
cancelled: 'ended',
|
|
35
|
+
failed: 'ended',
|
|
36
|
+
expired: 'ended',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- the provider's JSON, read field by field */
|
|
40
|
+
|
|
41
|
+
/** A Dodo subscription (an API answer, or a `Subscription` webhook payload) in neutral words. */
|
|
42
|
+
export function dodoSubscription(subscription: any): NeutralSubscription {
|
|
43
|
+
const metadata = stringMetadata(subscription.metadata)
|
|
44
|
+
return {
|
|
45
|
+
id: String(subscription.subscription_id),
|
|
46
|
+
customerId: idOf(subscription.customer?.customer_id) ?? str(subscription.customer_id),
|
|
47
|
+
entityId: metadata[ENTITY_METADATA_KEY] ?? null,
|
|
48
|
+
productId: str(subscription.product_id),
|
|
49
|
+
status: DODO_STATUSES[subscription.status] ?? 'incomplete',
|
|
50
|
+
cancelAtPeriodEnd: Boolean(subscription.cancel_at_next_billing_date),
|
|
51
|
+
currentPeriodEnd: millis(subscription.next_billing_date),
|
|
52
|
+
metadata,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A succeeded Dodo payment (a purchase, or a subscription's charge) as an order: the payment id is the order id. */
|
|
57
|
+
export function dodoOrder(payment: any): NeutralOrder {
|
|
58
|
+
const metadata = stringMetadata(payment.metadata)
|
|
59
|
+
const cart = Array.isArray(payment.product_cart) ? payment.product_cart : []
|
|
60
|
+
return {
|
|
61
|
+
id: String(payment.payment_id),
|
|
62
|
+
customerId: str(payment.customer?.customer_id),
|
|
63
|
+
entityId: metadata[ENTITY_METADATA_KEY] ?? null,
|
|
64
|
+
productId: str(cart[0]?.product_id),
|
|
65
|
+
subscriptionId: str(payment.subscription_id),
|
|
66
|
+
amount: num(payment.total_amount) ?? 0,
|
|
67
|
+
taxAmount: num(payment.tax),
|
|
68
|
+
currency: String(payment.currency ?? '').toLowerCase(),
|
|
69
|
+
metadata,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function dodoRefund(refund: any): NeutralRefund {
|
|
74
|
+
return {
|
|
75
|
+
id: String(refund.refund_id),
|
|
76
|
+
orderId: str(refund.payment_id),
|
|
77
|
+
subscriptionId: null,
|
|
78
|
+
amount: num(refund.amount),
|
|
79
|
+
currency: str(refund.currency)?.toLowerCase() ?? null,
|
|
80
|
+
status: refund.status === 'succeeded' ? 'succeeded' : refund.status === 'failed' ? 'failed' : 'pending',
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A verified Dodo event in neutral words. */
|
|
85
|
+
export function readDodoEvent(event: any): NeutralBillingEvent {
|
|
86
|
+
const providerType = String(event.type)
|
|
87
|
+
const data = event.data ?? {}
|
|
88
|
+
if (providerType.startsWith('subscription.')) {
|
|
89
|
+
return { type: 'subscription.updated', subscription: dodoSubscription(data), providerType }
|
|
90
|
+
}
|
|
91
|
+
switch (providerType) {
|
|
92
|
+
case 'payment.succeeded':
|
|
93
|
+
return { type: 'order.paid', order: dodoOrder(data), providerType }
|
|
94
|
+
case 'refund.succeeded':
|
|
95
|
+
case 'refund.failed':
|
|
96
|
+
return { type: 'order.refunded', refund: dodoRefund(data), providerType }
|
|
97
|
+
case 'dispute.opened':
|
|
98
|
+
return { type: 'order.disputed', orderId: str(data.payment_id), subscriptionId: null, providerType }
|
|
99
|
+
default:
|
|
100
|
+
return { type: 'ignored', providerType }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The Dodo Payments adapter. */
|
|
105
|
+
export function createDodoProvider({ apiKey, environment, fetch: fetchImpl }: ProviderOptions): CommerceProvider {
|
|
106
|
+
const call = providerClient('dodo', DODO_BASE_URLS[environment], { authorization: `Bearer ${apiKey}` }, fetchImpl)
|
|
107
|
+
const subscriptionPath = (id: string) => `subscriptions/${encodeURIComponent(id)}`
|
|
108
|
+
const patch = (operation: string, id: string, body: Record<string, unknown>) => call(operation, { method: 'PATCH', path: subscriptionPath(id), body })
|
|
109
|
+
/**
|
|
110
|
+
* The line item a partial refund names: the payment's own first line, as
|
|
111
|
+
* the payment was charged (a subscription's product may have changed
|
|
112
|
+
* since), with the amounts in the currency the customer paid in.
|
|
113
|
+
*/
|
|
114
|
+
const refundableItemOf = async (paymentId: string): Promise<{ itemId: string, currency: string }> => {
|
|
115
|
+
const payment = await call<any>('payment read', { method: 'GET', path: `payments/${encodeURIComponent(paymentId)}` })
|
|
116
|
+
const lines = await call<any>('payment line items read', { method: 'GET', path: `payments/${encodeURIComponent(paymentId)}/line-items`, query: { currency: str(payment.currency) ?? undefined } })
|
|
117
|
+
if (lines.partial_refund_allowed === false) throw new ProviderUnsupportedError('dodo', 'refund part of this payment', 'its payment method refunds in full only: refund the whole order.')
|
|
118
|
+
const itemId = str(lines.items?.[0]?.items_id)
|
|
119
|
+
if (!itemId) throw new Error(`[nuxt-backend] Dodo payment ${paymentId} has no line item to refund part of.`)
|
|
120
|
+
return { itemId, currency: String(lines.currency) }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
name: 'dodo',
|
|
125
|
+
environment,
|
|
126
|
+
capabilities: PROVIDER_CAPABILITIES.dodo,
|
|
127
|
+
createCheckout: async (request) => {
|
|
128
|
+
const { providerCustomerId, email, name, entityId } = request.customer
|
|
129
|
+
const session = await call<{ session_id: string, checkout_url: string }>('checkout', {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
path: 'checkouts',
|
|
132
|
+
body: {
|
|
133
|
+
product_cart: [{ product_id: request.productId, quantity: request.quantity ?? 1 }],
|
|
134
|
+
customer: providerCustomerId ? { customer_id: providerCustomerId } : email ? { email, name } : undefined,
|
|
135
|
+
return_url: request.successUrl,
|
|
136
|
+
cancel_url: request.cancelUrl,
|
|
137
|
+
metadata: { ...request.metadata, [ENTITY_METADATA_KEY]: entityId },
|
|
138
|
+
discount_codes: request.discountCode ? [request.discountCode] : undefined,
|
|
139
|
+
subscription_data: request.kind === 'subscription' && request.trialDays ? { trial_period_days: request.trialDays } : undefined,
|
|
140
|
+
},
|
|
141
|
+
})
|
|
142
|
+
return { id: session.session_id, url: session.checkout_url }
|
|
143
|
+
},
|
|
144
|
+
customerPortalUrl: async (customerId, options) => {
|
|
145
|
+
const session = await call<{ link: string }>('portal', {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
path: `customers/${encodeURIComponent(customerId)}/customer-portal/session`,
|
|
148
|
+
query: { return_url: options?.returnUrl },
|
|
149
|
+
})
|
|
150
|
+
return session.link
|
|
151
|
+
},
|
|
152
|
+
getSubscription: async id => dodoSubscription(await call('subscription read', { method: 'GET', path: subscriptionPath(id) })),
|
|
153
|
+
changePlan: async ({ subscriptionId, productId, proration, quantity }) => {
|
|
154
|
+
await call('plan change', {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
path: `${subscriptionPath(subscriptionId)}/change-plan`,
|
|
157
|
+
body: proration === 'immediately'
|
|
158
|
+
? { product_id: productId, quantity: quantity ?? 1, proration_billing_mode: 'prorated_immediately', effective_at: 'immediately', on_payment_failure: 'prevent_change' }
|
|
159
|
+
: { product_id: productId, quantity: quantity ?? 1, proration_billing_mode: 'do_not_bill', effective_at: 'next_billing_date' },
|
|
160
|
+
})
|
|
161
|
+
},
|
|
162
|
+
cancelSubscription: async (id, options) => {
|
|
163
|
+
await patch('cancellation', id, options?.immediately ? { status: 'cancelled', cancel_reason: 'cancelled_by_customer' } : { cancel_at_next_billing_date: true })
|
|
164
|
+
},
|
|
165
|
+
// Dodo documents no un-cancel: clearing the flag it set is the documented
|
|
166
|
+
// field's other value. Confirm on a test-mode subscription before relying on it.
|
|
167
|
+
uncancelSubscription: async (id) => {
|
|
168
|
+
await patch('uncancellation', id, { cancel_at_next_billing_date: false })
|
|
169
|
+
},
|
|
170
|
+
// `paused` and `active` must be sent alone, or Dodo answers 422.
|
|
171
|
+
pauseSubscription: async (id) => {
|
|
172
|
+
await patch('pause', id, { status: 'paused' })
|
|
173
|
+
},
|
|
174
|
+
resumeSubscription: async (id) => {
|
|
175
|
+
await patch('resume', id, { status: 'active' })
|
|
176
|
+
},
|
|
177
|
+
refundOrder: async ({ orderId, amount, reason }) => {
|
|
178
|
+
// A partial refund names the item it refunds, in the payment's currency.
|
|
179
|
+
let partial: { items: Array<{ item_id: string, amount: number }>, currency: string } | undefined
|
|
180
|
+
if (amount !== undefined) {
|
|
181
|
+
const { itemId, currency } = await refundableItemOf(orderId)
|
|
182
|
+
partial = { items: [{ item_id: itemId, amount }], currency }
|
|
183
|
+
}
|
|
184
|
+
const refund = await call('refund', {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
path: 'refunds',
|
|
187
|
+
// Dodo asks for a reason of 5 to 3,000 characters.
|
|
188
|
+
body: { payment_id: orderId, ...partial, reason: (reason && reason.length >= 5 ? reason : 'Refund requested by the customer').slice(0, 3000) },
|
|
189
|
+
}).catch((error: unknown) => {
|
|
190
|
+
// An earlier refund made in the settlement currency (in the dashboard)
|
|
191
|
+
// leaves the payment refundable in that currency only; amounts here
|
|
192
|
+
// are always the currency the customer paid in.
|
|
193
|
+
if (partial && error instanceof ProviderHttpError && error.code === 'REFUND_CURRENCY_NOT_SUPPORTED') {
|
|
194
|
+
throw new ProviderUnsupportedError('dodo', 'refund part of this payment in the currency the customer paid', 'an earlier refund was made in the settlement currency: refund the rest in the Dodo dashboard.')
|
|
195
|
+
}
|
|
196
|
+
throw error
|
|
197
|
+
})
|
|
198
|
+
return dodoRefund(refund)
|
|
199
|
+
},
|
|
200
|
+
invoice: async (orderId) => {
|
|
201
|
+
const bytes = await call<ArrayBuffer>('invoice read', { method: 'GET', path: `invoices/payments/${encodeURIComponent(orderId)}`, binary: true })
|
|
202
|
+
return { kind: 'pdf', bytes }
|
|
203
|
+
},
|
|
204
|
+
verifyWebhook: async (body, headers, secrets): Promise<VerifiedDelivery | null> => {
|
|
205
|
+
if (!verifyWebhookSignature(secrets, body, headers)) return null
|
|
206
|
+
return { id: headers.get('webhook-id') ?? '', event: readDodoEvent(JSON.parse(body)) }
|
|
207
|
+
},
|
|
208
|
+
verifyCheckoutRedirect: async () => {
|
|
209
|
+
throw new ProviderUnsupportedError('dodo', 'verify the success redirect', 'read the payment by the payment_id in the success URL, or wait for order.paid.')
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { type BillingProviderName, ProviderHttpError } from './types.js'
|
|
2
|
+
|
|
3
|
+
// The one HTTP path every commerce adapter calls its provider through, and
|
|
4
|
+
// the signature primitives their webhooks need, on Web Crypto alone.
|
|
5
|
+
|
|
6
|
+
/** One request to a provider's API. */
|
|
7
|
+
export interface ProviderRequest {
|
|
8
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE'
|
|
9
|
+
path: string
|
|
10
|
+
/** A JSON body, or a form (Stripe) as `URLSearchParams`. */
|
|
11
|
+
body?: unknown
|
|
12
|
+
query?: Record<string, string | number | boolean | undefined>
|
|
13
|
+
headers?: Record<string, string>
|
|
14
|
+
/** Read the answer as bytes instead of JSON (an invoice PDF). */
|
|
15
|
+
binary?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A JSON client bound to one provider's base URL and credentials. */
|
|
19
|
+
export type ProviderCall = <T = unknown>(operation: string, request: ProviderRequest) => Promise<T>
|
|
20
|
+
|
|
21
|
+
/** The provider's own error code, when its error body carries one, for the log; never its message. */
|
|
22
|
+
function errorCodeOf(body: unknown): string | undefined {
|
|
23
|
+
if (typeof body !== 'object' || body === null) return undefined
|
|
24
|
+
const record = body as Record<string, unknown>
|
|
25
|
+
const nested = typeof record.error === 'object' && record.error !== null ? record.error as Record<string, unknown> : record
|
|
26
|
+
const code = nested.code ?? nested.type ?? record.code
|
|
27
|
+
return typeof code === 'string' && code.length <= 80 ? code : undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The request's URL: `path` under `baseUrl`, with the query's defined values. */
|
|
31
|
+
function requestUrl(baseUrl: string, request: ProviderRequest): URL {
|
|
32
|
+
const url = new URL(request.path.replace(/^\//, ''), baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`)
|
|
33
|
+
for (const [key, value] of Object.entries(request.query ?? {})) {
|
|
34
|
+
if (value !== undefined) url.searchParams.set(key, String(value))
|
|
35
|
+
}
|
|
36
|
+
return url
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The request's body and its content type: a form as Stripe takes it, anything else as JSON. */
|
|
40
|
+
function encodedBody(body: unknown): { body?: string, headers: Record<string, string> } {
|
|
41
|
+
if (body === undefined) return { headers: {} }
|
|
42
|
+
if (body instanceof URLSearchParams) return { body: body.toString(), headers: { 'content-type': 'application/x-www-form-urlencoded' } }
|
|
43
|
+
return { body: JSON.stringify(body), headers: { 'content-type': 'application/json' } }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The refusal a failed answer becomes: its status, and the provider's error code when the body names one. */
|
|
47
|
+
async function refusalOf(provider: BillingProviderName, operation: string, response: Response): Promise<ProviderHttpError> {
|
|
48
|
+
let code: string | undefined
|
|
49
|
+
try {
|
|
50
|
+
code = errorCodeOf(await response.json())
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// No JSON body: the status says enough.
|
|
54
|
+
}
|
|
55
|
+
return new ProviderHttpError(provider, operation, response.status, code)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A successful answer's body: bytes, nothing, or JSON. */
|
|
59
|
+
async function answerOf<T>(response: Response, binary: boolean | undefined): Promise<T> {
|
|
60
|
+
if (binary) return await response.arrayBuffer() as T
|
|
61
|
+
const text = response.status === 204 ? '' : await response.text()
|
|
62
|
+
return (text ? JSON.parse(text) : undefined) as T
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A client for `baseUrl`, sending `headers` (the credentials) with every request. */
|
|
66
|
+
export function providerClient(
|
|
67
|
+
provider: BillingProviderName,
|
|
68
|
+
baseUrl: string,
|
|
69
|
+
headers: Record<string, string>,
|
|
70
|
+
fetchImpl: typeof fetch = globalThis.fetch,
|
|
71
|
+
): ProviderCall {
|
|
72
|
+
return async <T>(operation: string, request: ProviderRequest): Promise<T> => {
|
|
73
|
+
const encoded = encodedBody(request.body)
|
|
74
|
+
const response = await fetchImpl(requestUrl(baseUrl, request), {
|
|
75
|
+
method: request.method,
|
|
76
|
+
headers: { ...headers, ...encoded.headers, ...request.headers },
|
|
77
|
+
body: encoded.body,
|
|
78
|
+
})
|
|
79
|
+
if (!response.ok) throw await refusalOf(provider, operation, response)
|
|
80
|
+
return answerOf<T>(response, request.binary)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A nested object as Stripe's form encoding writes it:
|
|
86
|
+
* `{ line_items: [{ price: 'p' }] }` → `line_items[0][price]=p`. Undefined
|
|
87
|
+
* values are left out.
|
|
88
|
+
*/
|
|
89
|
+
export function stripeForm(value: Record<string, unknown>): URLSearchParams {
|
|
90
|
+
const form = new URLSearchParams()
|
|
91
|
+
const walk = (prefix: string, node: unknown): void => {
|
|
92
|
+
if (node === undefined || node === null) return
|
|
93
|
+
if (Array.isArray(node)) {
|
|
94
|
+
node.forEach((item, index) => walk(`${prefix}[${index}]`, item))
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
if (typeof node === 'object') {
|
|
98
|
+
for (const [key, child] of Object.entries(node as Record<string, unknown>)) walk(prefix ? `${prefix}[${key}]` : key, child)
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
form.append(prefix, String(node as string | number | boolean | bigint))
|
|
102
|
+
}
|
|
103
|
+
walk('', value)
|
|
104
|
+
return form
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const encoder = new TextEncoder()
|
|
108
|
+
|
|
109
|
+
/** HMAC-SHA256 of `message` under `key`, as lowercase hex. */
|
|
110
|
+
export async function hmacSha256Hex(key: string | Uint8Array, message: string): Promise<string> {
|
|
111
|
+
const keyBytes = typeof key === 'string' ? encoder.encode(key) : key
|
|
112
|
+
const cryptoKey = await crypto.subtle.importKey('raw', keyBytes as BufferSource, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
|
|
113
|
+
const signature = new Uint8Array(await crypto.subtle.sign('HMAC', cryptoKey, encoder.encode(message)))
|
|
114
|
+
return Array.from(signature, byte => byte.toString(16).padStart(2, '0')).join('')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** SHA-256 of `message`, as lowercase hex. */
|
|
118
|
+
export async function sha256Hex(message: string): Promise<string> {
|
|
119
|
+
const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', encoder.encode(message)))
|
|
120
|
+
return Array.from(digest, byte => byte.toString(16).padStart(2, '0')).join('')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Whether two strings are equal, in time that depends on their length alone. */
|
|
124
|
+
export function constantTimeEqual(a: string, b: string): boolean {
|
|
125
|
+
if (a.length !== b.length) return false
|
|
126
|
+
let difference = 0
|
|
127
|
+
for (let index = 0; index < a.length; index++) difference |= a.charCodeAt(index) ^ b.charCodeAt(index)
|
|
128
|
+
return difference === 0
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** A metadata object reduced to its string values, as every provider's metadata is read. */
|
|
132
|
+
export function stringMetadata(value: unknown): Record<string, string> {
|
|
133
|
+
if (typeof value !== 'object' || value === null) return {}
|
|
134
|
+
const out: Record<string, string> = {}
|
|
135
|
+
for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
|
|
136
|
+
if (typeof item === 'string') out[key] = item
|
|
137
|
+
else if (typeof item === 'number' || typeof item === 'boolean') out[key] = String(item)
|
|
138
|
+
}
|
|
139
|
+
return out
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The metadata key every adapter stores the billing entity id under. */
|
|
143
|
+
export const ENTITY_METADATA_KEY = 'entity_id'
|
|
144
|
+
|
|
145
|
+
/** A field read as a string, or `null`. */
|
|
146
|
+
export function str(value: unknown): string | null {
|
|
147
|
+
return typeof value === 'string' && value.length > 0 ? value : null
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A field read as an object's `id` or as the id string itself (an expandable reference). */
|
|
151
|
+
export function idOf(value: unknown): string | null {
|
|
152
|
+
if (typeof value === 'string') return value || null
|
|
153
|
+
if (typeof value === 'object' && value !== null) return str((value as { id?: unknown }).id)
|
|
154
|
+
return null
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** A field read as a finite number, or `null`. */
|
|
158
|
+
export function num(value: unknown): number | null {
|
|
159
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** An ISO date or Unix seconds read as Unix milliseconds, or `null`. */
|
|
163
|
+
export function millis(value: unknown, unit: 'seconds' | 'iso' = 'iso'): number | null {
|
|
164
|
+
if (unit === 'seconds') return typeof value === 'number' ? value * 1000 : null
|
|
165
|
+
if (typeof value !== 'string') return null
|
|
166
|
+
const parsed = Date.parse(value)
|
|
167
|
+
return Number.isNaN(parsed) ? null : parsed
|
|
168
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createCreemProvider } from './creem.js'
|
|
2
|
+
import { createDodoProvider } from './dodo.js'
|
|
3
|
+
import { createStripeProvider } from './stripe.js'
|
|
4
|
+
import { BILLING_PROVIDER_NAMES, type BillingProviderName, type CommerceProvider, type ProviderEnvironment, type ProviderOptions } from './types.js'
|
|
5
|
+
|
|
6
|
+
export { PROVIDER_CAPABILITIES } from './capabilities.js'
|
|
7
|
+
export * from './consent.js'
|
|
8
|
+
export * from './types.js'
|
|
9
|
+
|
|
10
|
+
/** The adapters built on the neutral seam. Polar is served by its Convex component (context.ts). */
|
|
11
|
+
const FACTORIES: Readonly<Record<Exclude<BillingProviderName, 'polar'>, (options: ProviderOptions) => CommerceProvider>> = {
|
|
12
|
+
stripe: createStripeProvider,
|
|
13
|
+
dodo: createDodoProvider,
|
|
14
|
+
creem: createCreemProvider,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The provider `BILLING_PROVIDER` names, `polar` when it is unset. A name
|
|
19
|
+
* the package does not know is refused, so a typo never sells through the
|
|
20
|
+
* wrong provider.
|
|
21
|
+
*
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
24
|
+
export function billingProviderName(value: string | undefined): BillingProviderName {
|
|
25
|
+
const name = (value ?? '').trim().toLowerCase() || 'polar'
|
|
26
|
+
if ((BILLING_PROVIDER_NAMES as readonly string[]).includes(name)) return name as BillingProviderName
|
|
27
|
+
throw new Error(`[nuxt-backend] BILLING_PROVIDER is "${value}": set it to one of ${BILLING_PROVIDER_NAMES.join(', ')}.`)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether a provider is served by the neutral adapters (every one but Polar). */
|
|
31
|
+
export function isAdapterProvider(name: BillingProviderName): name is Exclude<BillingProviderName, 'polar'> {
|
|
32
|
+
return name !== 'polar'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The adapter for `name`.
|
|
37
|
+
*
|
|
38
|
+
* @experimental
|
|
39
|
+
*/
|
|
40
|
+
export function createCommerceProvider(name: Exclude<BillingProviderName, 'polar'>, options: ProviderOptions): CommerceProvider {
|
|
41
|
+
if (!options.apiKey) throw new Error(`[nuxt-backend] ${name} billing needs BILLING_ACCESS_TOKEN: the provider's secret API key.`)
|
|
42
|
+
return FACTORIES[name](options)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The adapter the deployment's env names: `BILLING_PROVIDER`, the key in
|
|
47
|
+
* `BILLING_ACCESS_TOKEN`, and the provider's sandbox everywhere but
|
|
48
|
+
* production. `null` for Polar, which the component path serves.
|
|
49
|
+
*
|
|
50
|
+
* @experimental
|
|
51
|
+
*/
|
|
52
|
+
export function commerceProviderFromEnv(env: Readonly<Record<string, string | undefined>>, environment: ProviderEnvironment, fetchImpl?: typeof fetch): CommerceProvider | null {
|
|
53
|
+
const name = billingProviderName(env.BILLING_PROVIDER)
|
|
54
|
+
if (!isAdapterProvider(name)) return null
|
|
55
|
+
return createCommerceProvider(name, { apiKey: env.BILLING_ACCESS_TOKEN ?? '', environment, fetch: fetchImpl })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The webhook secrets the env accepts: a rotation list, first entry primary.
|
|
60
|
+
*
|
|
61
|
+
* @experimental
|
|
62
|
+
*/
|
|
63
|
+
export function webhookSecretsFromEnv(env: Readonly<Record<string, string | undefined>>): string[] {
|
|
64
|
+
return (env.BILLING_WEBHOOK_SECRET ?? '').split(',').map(secret => secret.trim()).filter(Boolean)
|
|
65
|
+
}
|