nuxt-backend 0.3.0 → 0.5.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 +10 -1
- package/dist/chunks/catalog.mjs +1 -1
- package/dist/chunks/doctor.mjs +103 -9
- package/dist/chunks/email-previews.mjs +1 -1
- package/dist/chunks/health.mjs +2 -2
- package/dist/chunks/index.mjs +3 -3
- package/dist/chunks/install.mjs +8 -8
- package/dist/chunks/run.mjs +1 -1
- package/dist/chunks/server.mjs +6 -6
- package/dist/cli.mjs +290 -188
- package/dist/convex/catalog.d.ts +8 -0
- package/dist/convex/catalog.d.ts.map +1 -1
- package/dist/convex/catalog.js +16 -0
- package/dist/convex/catalog.js.map +1 -1
- package/dist/convex/components/backend/_generated/component.d.ts +21 -1
- package/dist/convex/components/backend/_generated/component.d.ts.map +1 -1
- package/dist/convex/components/backend/billing.d.ts +7 -0
- package/dist/convex/components/backend/billing.d.ts.map +1 -1
- package/dist/convex/components/backend/billing.js +20 -5
- package/dist/convex/components/backend/billing.js.map +1 -1
- package/dist/convex/components/backend/jobs.d.ts +69 -1
- package/dist/convex/components/backend/jobs.d.ts.map +1 -1
- package/dist/convex/components/backend/jobs.js +103 -5
- package/dist/convex/components/backend/jobs.js.map +1 -1
- package/dist/convex/components/backend/schema.d.ts +46 -18
- package/dist/convex/components/backend/schema.d.ts.map +1 -1
- package/dist/convex/components/backend/schema.js +11 -0
- package/dist/convex/components/backend/schema.js.map +1 -1
- package/dist/convex/components/backend/subscriptions.d.ts +3 -3
- package/dist/convex/delivery.d.ts +17 -0
- package/dist/convex/delivery.d.ts.map +1 -1
- package/dist/convex/delivery.js +26 -1
- package/dist/convex/delivery.js.map +1 -1
- package/dist/convex/emails/renewal-reminder.d.ts.map +1 -1
- package/dist/convex/emails/renewal-reminder.js +17 -1
- package/dist/convex/emails/renewal-reminder.js.map +1 -1
- package/dist/convex/errors.d.ts +7 -5
- package/dist/convex/errors.d.ts.map +1 -1
- package/dist/convex/errors.js +24 -9
- package/dist/convex/errors.js.map +1 -1
- package/dist/convex/events.d.ts +10 -0
- package/dist/convex/events.d.ts.map +1 -1
- package/dist/convex/events.js +7 -0
- package/dist/convex/events.js.map +1 -1
- package/dist/convex/integrations/ai/images.d.ts.map +1 -1
- package/dist/convex/integrations/ai/images.js +20 -7
- package/dist/convex/integrations/ai/images.js.map +1 -1
- package/dist/convex/integrations/ai/job-errors.d.ts +32 -4
- package/dist/convex/integrations/ai/job-errors.d.ts.map +1 -1
- package/dist/convex/integrations/ai/job-errors.js +55 -8
- package/dist/convex/integrations/ai/job-errors.js.map +1 -1
- package/dist/convex/integrations/ai/jobs.d.ts +128 -7
- package/dist/convex/integrations/ai/jobs.d.ts.map +1 -1
- package/dist/convex/integrations/ai/jobs.js +395 -63
- package/dist/convex/integrations/ai/jobs.js.map +1 -1
- package/dist/convex/integrations/ai/models.d.ts +1 -1
- package/dist/convex/integrations/ai/models.d.ts.map +1 -1
- package/dist/convex/integrations/ai/moderation.d.ts +9 -3
- package/dist/convex/integrations/ai/moderation.d.ts.map +1 -1
- package/dist/convex/integrations/ai/moderation.js +4 -2
- package/dist/convex/integrations/ai/moderation.js.map +1 -1
- package/dist/convex/integrations/ai.d.ts +2 -2
- package/dist/convex/integrations/ai.d.ts.map +1 -1
- package/dist/convex/integrations/ai.js +1 -1
- package/dist/convex/integrations/ai.js.map +1 -1
- package/dist/convex/integrations/billing/context.d.ts.map +1 -1
- package/dist/convex/integrations/billing/context.js +5 -2
- package/dist/convex/integrations/billing/context.js.map +1 -1
- package/dist/convex/integrations/billing/credits.d.ts +1 -0
- package/dist/convex/integrations/billing/credits.d.ts.map +1 -1
- package/dist/convex/integrations/billing/credits.js +4 -1
- package/dist/convex/integrations/billing/credits.js.map +1 -1
- package/dist/convex/integrations/billing/features.d.ts.map +1 -1
- package/dist/convex/integrations/billing/gifts.d.ts.map +1 -1
- package/dist/convex/integrations/billing/history.d.ts.map +1 -1
- package/dist/convex/integrations/billing/passes.d.ts +2 -2
- package/dist/convex/integrations/billing/passes.d.ts.map +1 -1
- package/dist/convex/integrations/billing/passes.js +3 -11
- package/dist/convex/integrations/billing/passes.js.map +1 -1
- package/dist/convex/integrations/billing/provider-failure.d.ts +17 -0
- package/dist/convex/integrations/billing/provider-failure.d.ts.map +1 -0
- package/dist/convex/integrations/billing/provider-failure.js +52 -0
- package/dist/convex/integrations/billing/provider-failure.js.map +1 -0
- package/dist/convex/integrations/billing/quotas.d.ts.map +1 -1
- package/dist/convex/integrations/billing/subscriptions.d.ts.map +1 -1
- package/dist/convex/integrations/billing/types/setup.d.ts +1 -0
- package/dist/convex/integrations/billing/types/setup.d.ts.map +1 -1
- package/dist/convex/integrations/billing/types/surface.d.ts +9 -1
- package/dist/convex/integrations/billing/types/surface.d.ts.map +1 -1
- package/dist/convex/integrations/email-sync.d.ts +24 -2
- package/dist/convex/integrations/email-sync.d.ts.map +1 -1
- package/dist/convex/integrations/email-sync.js +54 -23
- package/dist/convex/integrations/email-sync.js.map +1 -1
- package/dist/convex/integrations/inbound.d.ts +16 -7
- package/dist/convex/integrations/inbound.d.ts.map +1 -1
- package/dist/convex/integrations/inbound.js +21 -10
- package/dist/convex/integrations/inbound.js.map +1 -1
- package/dist/convex/integrations/launch.d.ts +17 -1
- package/dist/convex/integrations/launch.d.ts.map +1 -1
- package/dist/convex/integrations/launch.js +32 -3
- package/dist/convex/integrations/launch.js.map +1 -1
- package/dist/convex/integrations/referrals.d.ts +20 -0
- package/dist/convex/integrations/referrals.d.ts.map +1 -1
- package/dist/convex/integrations/referrals.js +14 -9
- package/dist/convex/integrations/referrals.js.map +1 -1
- package/dist/convex/integrations/storage.d.ts +67 -0
- package/dist/convex/integrations/storage.d.ts.map +1 -1
- package/dist/convex/integrations/storage.js +42 -1
- package/dist/convex/integrations/storage.js.map +1 -1
- package/dist/convex/label-groups/admin.d.ts +3 -0
- package/dist/convex/label-groups/admin.d.ts.map +1 -1
- package/dist/convex/label-groups/admin.js +3 -0
- package/dist/convex/label-groups/admin.js.map +1 -1
- package/dist/convex/label-groups/audit.d.ts +1 -0
- package/dist/convex/label-groups/audit.d.ts.map +1 -1
- package/dist/convex/label-groups/audit.js +1 -0
- package/dist/convex/label-groups/audit.js.map +1 -1
- package/dist/convex/label-groups/auth.d.ts +7 -0
- package/dist/convex/label-groups/auth.d.ts.map +1 -1
- package/dist/convex/label-groups/auth.js +7 -0
- package/dist/convex/label-groups/auth.js.map +1 -1
- package/dist/convex/label-groups/errors.d.ts +9 -0
- package/dist/convex/label-groups/errors.d.ts.map +1 -1
- package/dist/convex/label-groups/errors.js +12 -0
- package/dist/convex/label-groups/errors.js.map +1 -1
- package/dist/convex/label-groups/gift.d.ts +24 -0
- package/dist/convex/label-groups/gift.d.ts.map +1 -1
- package/dist/convex/label-groups/gift.js +27 -0
- package/dist/convex/label-groups/gift.js.map +1 -1
- package/dist/convex/label-groups/legal.d.ts +1 -1
- package/dist/convex/label-groups/pricing.d.ts +15 -0
- package/dist/convex/label-groups/pricing.d.ts.map +1 -1
- package/dist/convex/label-groups/pricing.js +20 -0
- package/dist/convex/label-groups/pricing.js.map +1 -1
- package/dist/convex/label-groups/referral.d.ts +4 -0
- package/dist/convex/label-groups/referral.d.ts.map +1 -1
- package/dist/convex/label-groups/referral.js +4 -0
- package/dist/convex/label-groups/referral.js.map +1 -1
- package/dist/convex/label-groups/settings.d.ts +34 -0
- package/dist/convex/label-groups/settings.d.ts.map +1 -1
- package/dist/convex/label-groups/settings.js +39 -0
- package/dist/convex/label-groups/settings.js.map +1 -1
- package/dist/convex/label-groups/waitlist.d.ts +5 -0
- package/dist/convex/label-groups/waitlist.d.ts.map +1 -1
- package/dist/convex/label-groups/waitlist.js +7 -2
- package/dist/convex/label-groups/waitlist.js.map +1 -1
- package/dist/convex/labels.d.ts +103 -1
- package/dist/convex/labels.d.ts.map +1 -1
- package/dist/convex/legal.d.ts +18 -1
- package/dist/convex/legal.d.ts.map +1 -1
- package/dist/convex/legal.js +17 -2
- package/dist/convex/legal.js.map +1 -1
- package/dist/convex/log.js +8 -0
- package/dist/convex/log.js.map +1 -1
- package/dist/convex/money.d.ts +10 -0
- package/dist/convex/money.d.ts.map +1 -0
- package/dist/convex/money.js +37 -0
- package/dist/convex/money.js.map +1 -0
- package/dist/convex/report-rules.d.ts +6 -0
- package/dist/convex/report-rules.d.ts.map +1 -1
- package/dist/convex/report-rules.js +15 -0
- package/dist/convex/report-rules.js.map +1 -1
- package/dist/convex/test-billing.d.ts +83 -0
- package/dist/convex/test-billing.d.ts.map +1 -0
- package/dist/convex/test-billing.js +131 -0
- package/dist/convex/test-billing.js.map +1 -0
- package/dist/convex/test-models.d.ts +14 -2
- package/dist/convex/test-models.d.ts.map +1 -1
- package/dist/convex/test-models.js +61 -4
- package/dist/convex/test-models.js.map +1 -1
- package/dist/devtools-client/index.html +1 -1
- package/dist/eslint.d.mts +2 -1
- package/dist/eslint.mjs +2 -1
- package/dist/module.d.ts +45 -2
- package/dist/module.js +2 -2
- package/dist/module.json +1 -1
- package/dist/runtime/chunk-recovery.d.ts +13 -0
- package/dist/runtime/chunk-recovery.js +1 -0
- package/dist/runtime/locales/de.json +113 -7
- package/dist/runtime/locales/en.json +114 -8
- package/dist/runtime/locales/es.json +113 -7
- package/dist/runtime/locales/fr.json +113 -7
- package/dist/runtime/locales/ru.json +113 -7
- package/dist/runtime/server/chunk-recovery.d.ts +49 -0
- package/dist/runtime/server/chunk-recovery.js +44 -0
- package/dist/runtime/server/csp.d.ts +7 -2
- package/dist/runtime/server/csp.js +2 -2
- package/dist/runtime/server/photo-decoder-csp.d.ts +17 -0
- package/dist/runtime/server/photo-decoder-csp.js +9 -0
- package/dist/runtime/vue/components/account/AccountDeletion.css +1 -1
- package/dist/runtime/vue/components/account/ActivationChecklist.css +1 -1
- package/dist/runtime/vue/components/account/ConsentPrompt.css +1 -1
- package/dist/runtime/vue/components/account/EmailUnsubscribe.css +1 -1
- package/dist/runtime/vue/components/account/HowDidYouHear.css +1 -1
- package/dist/runtime/vue/components/account/KeepAccount.css +1 -1
- package/dist/runtime/vue/components/account/OnboardingFlow.css +1 -1
- package/dist/runtime/vue/components/account/ProfileIdentity.css +1 -1
- package/dist/runtime/vue/components/account/ProfilePreferencesSection.css +1 -1
- package/dist/runtime/vue/components/account/ProfileSettings.css +1 -1
- package/dist/runtime/vue/components/account/SecurityAlerts.css +1 -1
- package/dist/runtime/vue/components/account/SecurityPasskeys.css +1 -1
- package/dist/runtime/vue/components/account/SecuritySessions.css +1 -1
- package/dist/runtime/vue/components/account/SecuritySettings.css +1 -1
- package/dist/runtime/vue/components/admin/AdminAccess.css +1 -1
- package/dist/runtime/vue/components/admin/AdminAnnouncements.css +1 -1
- package/dist/runtime/vue/components/admin/AdminBilling.css +1 -1
- package/dist/runtime/vue/components/admin/AdminChart.css +1 -1
- package/dist/runtime/vue/components/admin/AdminConsole.css +1 -1
- package/dist/runtime/vue/components/admin/AdminExperiments.css +1 -1
- package/dist/runtime/vue/components/admin/AdminFlags.css +1 -1
- package/dist/runtime/vue/components/admin/AdminQueue.css +1 -1
- package/dist/runtime/vue/components/admin/AdminQueueJob.vue +5 -2
- package/dist/runtime/vue/components/admin/AdminReferrals.css +1 -1
- package/dist/runtime/vue/components/admin/AdminReports.css +1 -1
- package/dist/runtime/vue/components/admin/AdminRevenue.css +1 -1
- package/dist/runtime/vue/components/admin/AdminUsers.d.vue.ts +3 -0
- package/dist/runtime/vue/components/admin/AdminUsers.vue.d.ts +3 -0
- package/dist/runtime/vue/components/admin/AdminWorkspaces.d.vue.ts +3 -0
- package/dist/runtime/vue/components/admin/AdminWorkspaces.vue.d.ts +3 -0
- package/dist/runtime/vue/components/admin/admin-access-tab.js +2 -1
- package/dist/runtime/vue/components/admin/admin-revenue-tab.js +4 -1
- package/dist/runtime/vue/components/admin/admin.css +1 -1
- package/dist/runtime/vue/components/auth/AuthForm.css +1 -1
- package/dist/runtime/vue/components/auth/AuthForm.d.vue.ts +7 -0
- package/dist/runtime/vue/components/auth/AuthForm.vue +1 -2
- package/dist/runtime/vue/components/auth/AuthForm.vue.d.ts +7 -0
- package/dist/runtime/vue/components/auth/AuthFormChoose.css +1 -1
- package/dist/runtime/vue/components/auth/AuthFormHeader.css +1 -1
- package/dist/runtime/vue/components/auth/AuthFormPasskeyOffer.css +1 -1
- package/dist/runtime/vue/components/auth/InviteRedeem.css +1 -1
- package/dist/runtime/vue/components/auth/InviteRedeem.vue +79 -10
- package/dist/runtime/vue/components/auth/ReauthenticateCode.css +1 -1
- package/dist/runtime/vue/components/auth/ReauthenticateDialog.css +1 -1
- package/dist/runtime/vue/components/auth/ReauthenticatePasskey.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistForm.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistForm.d.vue.ts +5 -0
- package/dist/runtime/vue/components/auth/WaitlistForm.vue +3 -5
- package/dist/runtime/vue/components/auth/WaitlistForm.vue.d.ts +5 -0
- package/dist/runtime/vue/components/auth/WaitlistPlace.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistShare.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistShare.vue +1 -7
- package/dist/runtime/vue/components/auth/WaitlistStatus.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistStatus.vue +116 -29
- package/dist/runtime/vue/components/auth/auth-form.d.ts +1 -1
- package/dist/runtime/vue/components/auth/waitlist-form.js +1 -1
- package/dist/runtime/vue/components/billing/BillingHistory.css +1 -1
- package/dist/runtime/vue/components/billing/BillingHistoryOrder.css +1 -1
- package/dist/runtime/vue/components/billing/CancelConfirmGroup.vue +2 -7
- package/dist/runtime/vue/components/billing/CancelFlow.css +1 -1
- package/dist/runtime/vue/components/billing/GiftForm.css +1 -0
- package/dist/runtime/vue/components/billing/GiftForm.d.vue.ts +105 -0
- package/dist/runtime/vue/components/billing/GiftForm.vue +228 -0
- package/dist/runtime/vue/components/billing/GiftForm.vue.d.ts +105 -0
- package/dist/runtime/vue/components/billing/GiftList.css +1 -1
- package/dist/runtime/vue/components/billing/GiftList.d.vue.ts +87 -2
- package/dist/runtime/vue/components/billing/GiftList.vue +7 -4
- package/dist/runtime/vue/components/billing/GiftList.vue.d.ts +87 -2
- package/dist/runtime/vue/components/billing/GiftReceived.vue +11 -3
- package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.d.vue.ts +7 -0
- package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.vue +50 -0
- package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.vue.d.ts +7 -0
- package/dist/runtime/vue/components/billing/PricingChangeConfirm.d.vue.ts +4 -0
- package/dist/runtime/vue/components/billing/PricingChangeConfirm.vue +17 -0
- package/dist/runtime/vue/components/billing/PricingChangeConfirm.vue.d.ts +4 -0
- package/dist/runtime/vue/components/billing/PricingPackCard.css +1 -1
- package/dist/runtime/vue/components/billing/PricingPlanCard.css +1 -1
- package/dist/runtime/vue/components/billing/PricingPlanCard.vue +15 -0
- package/dist/runtime/vue/components/billing/PricingTable.css +1 -1
- package/dist/runtime/vue/components/billing/PricingTable.d.vue.ts +24 -2
- package/dist/runtime/vue/components/billing/PricingTable.vue +70 -37
- package/dist/runtime/vue/components/billing/PricingTable.vue.d.ts +24 -2
- package/dist/runtime/vue/components/billing/ReferralCard.css +1 -1
- package/dist/runtime/vue/components/billing/ReferralCard.d.vue.ts +4 -0
- package/dist/runtime/vue/components/billing/ReferralCard.vue.d.ts +4 -0
- package/dist/runtime/vue/components/billing/ReferralLanding.css +1 -1
- package/dist/runtime/vue/components/billing/ReferralLanding.vue +43 -2
- package/dist/runtime/vue/components/billing/UpgradePrompt.css +1 -1
- package/dist/runtime/vue/components/billing/UsageHistory.css +1 -1
- package/dist/runtime/vue/components/billing/WithdrawalButton.css +1 -1
- package/dist/runtime/vue/components/billing/cancel-flow.js +2 -1
- package/dist/runtime/vue/components/billing/pricing-table.d.ts +10 -0
- package/dist/runtime/vue/components/billing/withdrawal-button.d.ts +3 -2
- package/dist/runtime/vue/components/billing/withdrawal-button.js +13 -33
- package/dist/runtime/vue/components/shared.css +1 -1
- package/dist/runtime/vue/components/shell/AccessDenied.css +1 -1
- package/dist/runtime/vue/components/shell/AiLabel.css +1 -1
- package/dist/runtime/vue/components/shell/AppShell.css +1 -1
- package/dist/runtime/vue/components/shell/ConfirmDialog.css +1 -1
- package/dist/runtime/vue/components/shell/ConnectionStatus.css +1 -1
- package/dist/runtime/vue/components/shell/ContactForm.css +1 -1
- package/dist/runtime/vue/components/shell/Gate.css +1 -1
- package/dist/runtime/vue/components/shell/LegalDocument.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeAnnouncement.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeDeletion.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeGift.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeImpersonation.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeLowCredits.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeMaintenance.css +1 -1
- package/dist/runtime/vue/components/shell/NoticePastDue.css +1 -1
- package/dist/runtime/vue/components/shell/NotificationInbox.css +1 -1
- package/dist/runtime/vue/components/shell/ReportAppeal.vue +16 -13
- package/dist/runtime/vue/components/shell/ReportNotice.css +1 -1
- package/dist/runtime/vue/components/shell/UploadField.css +1 -1
- package/dist/runtime/vue/components/shell/WorkspaceSwitcher.css +1 -1
- package/dist/runtime/vue/components/shell/report-form.js +1 -44
- package/dist/runtime/vue/components/tokens.css +1 -1
- package/dist/runtime/vue/components/workspaces/AuditLog.css +1 -1
- package/dist/runtime/vue/components/workspaces/AuditLog.d.vue.ts +1 -0
- package/dist/runtime/vue/components/workspaces/AuditLog.vue.d.ts +1 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBilling.css +1 -1
- package/dist/runtime/vue/components/workspaces/WorkspaceBilling.vue +34 -58
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.d.vue.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +68 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue.d.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.d.vue.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue +54 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue.d.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceCredits.css +1 -1
- package/dist/runtime/vue/components/workspaces/WorkspaceList.css +1 -1
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +40 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue +20 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +40 -2
- package/dist/runtime/vue/components/workspaces/workspace-billing.d.ts +46 -13
- package/dist/runtime/vue/components/workspaces/workspace-billing.js +93 -16
- package/dist/runtime/vue/components/workspaces/workspace-settings.d.ts +4 -0
- package/dist/runtime/vue/composables/billing-format.d.ts +9 -4
- package/dist/runtime/vue/composables/billing-format.js +17 -9
- package/dist/runtime/vue/composables/billing-provider.js +3 -2
- package/dist/runtime/vue/composables/prepare-photo.d.ts +75 -0
- package/dist/runtime/vue/composables/prepare-photo.js +223 -0
- package/dist/runtime/vue/composables/use-access.d.ts +41 -2
- package/dist/runtime/vue/composables/use-access.js +54 -8
- package/dist/runtime/vue/composables/use-billing-section.d.ts +115 -0
- package/dist/runtime/vue/composables/use-billing-section.js +76 -0
- package/dist/runtime/vue/composables/use-billing.d.ts +76 -5
- package/dist/runtime/vue/composables/use-billing.js +48 -0
- package/dist/runtime/vue/composables/use-gift-form.d.ts +123 -0
- package/dist/runtime/vue/composables/use-gift-form.js +152 -0
- package/dist/runtime/vue/composables/use-gift-list.d.ts +62 -5
- package/dist/runtime/vue/composables/use-gift-list.js +17 -6
- package/dist/runtime/vue/composables/use-install-prompt.d.ts +71 -0
- package/dist/runtime/vue/composables/use-install-prompt.js +53 -0
- package/dist/runtime/vue/composables/use-labels.js +17 -23
- package/dist/runtime/vue/composables/use-login-flow.d.ts +9 -0
- package/dist/runtime/vue/composables/use-login-flow.js +7 -0
- package/dist/runtime/vue/composables/use-orders.d.ts +1 -1
- package/dist/runtime/vue/composables/use-plan-change.d.ts +148 -0
- package/dist/runtime/vue/composables/use-plan-change.js +130 -0
- package/dist/runtime/vue/composables/use-pricing.d.ts +83 -5
- package/dist/runtime/vue/composables/use-pricing.js +83 -17
- package/dist/runtime/vue/composables/use-push-subscription.js +1 -7
- package/dist/runtime/vue/composables/use-referral-invite.d.ts +24 -2
- package/dist/runtime/vue/composables/use-referral-invite.js +14 -2
- package/dist/runtime/vue/composables/use-referrals.js +2 -1
- package/dist/runtime/vue/composables/use-report-appeal.d.ts +86 -0
- package/dist/runtime/vue/composables/use-report-appeal.js +61 -0
- package/dist/runtime/vue/composables/use-return-path.d.ts +5 -4
- package/dist/runtime/vue/composables/use-return-path.js +16 -2
- package/dist/runtime/vue/composables/use-waitlist.d.ts +31 -1
- package/dist/runtime/vue/composables/use-waitlist.js +39 -4
- package/dist/runtime/vue/composables/use-withdrawal.d.ts +63 -0
- package/dist/runtime/vue/composables/use-withdrawal.js +38 -0
- package/dist/runtime/vue/middleware/page-access.js +2 -2
- package/dist/runtime/vue/pages/gifts.vue +2 -0
- package/dist/runtime/vue/pages/login.vue +5 -7
- package/dist/runtime/vue/pages/pricing.vue +1 -2
- package/dist/runtime/vue/pages/report.vue +2 -3
- package/dist/runtime/vue/parts.d.ts +5 -0
- package/dist/runtime/vue/plugins/checkout-return.js +9 -2
- package/dist/runtime/vue/plugins/chunk-recovery.client.d.ts +10 -0
- package/dist/runtime/vue/plugins/chunk-recovery.client.js +10 -0
- package/dist/runtime/vue/plugins/install-banner.client.d.ts +7 -0
- package/dist/runtime/vue/plugins/install-banner.client.js +5 -0
- package/dist/runtime/vue/plugins/install-prompt.client.d.ts +7 -0
- package/dist/runtime/vue/plugins/install-prompt.client.js +6 -0
- package/dist/runtime/vue/plugins/session-ended.js +2 -3
- package/dist/runtime/vue/utils/active-locale.js +8 -0
- package/dist/runtime/vue/utils/checkout-return.d.ts +11 -1
- package/dist/runtime/vue/utils/checkout-return.js +6 -2
- package/dist/runtime/vue/utils/confirm-group.d.ts +18 -0
- package/dist/runtime/vue/utils/confirm-group.js +17 -0
- package/dist/runtime/vue/utils/display-mode.d.ts +8 -0
- package/dist/runtime/vue/utils/display-mode.js +11 -0
- package/dist/runtime/vue/utils/gift-days.d.ts +20 -0
- package/dist/runtime/vue/utils/gift-days.js +32 -0
- package/dist/runtime/vue/utils/heic-absent.d.ts +2 -0
- package/dist/runtime/vue/utils/heic-absent.js +3 -0
- package/dist/runtime/vue/utils/intl.d.ts +12 -4
- package/dist/runtime/vue/utils/intl.js +13 -2
- package/dist/runtime/vue/utils/kept-invite.js +6 -29
- package/dist/runtime/vue/utils/namespace.js +7 -2
- package/dist/runtime/vue/utils/page-open.d.ts +1 -0
- package/dist/runtime/vue/utils/page-open.js +12 -0
- package/dist/runtime/vue/utils/page-origin.d.ts +15 -0
- package/dist/runtime/vue/utils/page-origin.js +8 -0
- package/dist/runtime/vue/utils/page-rules.d.ts +9 -0
- package/dist/runtime/vue/utils/page-rules.js +3 -0
- package/dist/runtime/vue/utils/plan-change-confirm.d.ts +88 -0
- package/dist/runtime/vue/utils/plan-change-confirm.js +48 -0
- package/dist/runtime/vue/utils/pricing-bindings.d.ts +7 -1
- package/dist/runtime/vue/utils/pricing-bindings.js +21 -0
- package/dist/runtime/vue/utils/pricing-checkout.d.ts +39 -0
- package/dist/runtime/vue/utils/pricing-checkout.js +22 -0
- package/dist/runtime/vue/utils/pricing-seo.js +4 -2
- package/dist/runtime/vue/utils/tab-keep.d.ts +19 -0
- package/dist/runtime/vue/utils/tab-keep.js +46 -0
- package/dist/shared/{nuxt-backend.G4JryO1q.mjs → nuxt-backend.BqXAZChe.mjs} +277 -51
- package/dist/shared/{nuxt-backend.Lk2MQI2u.mjs → nuxt-backend.CBvrM7pG.mjs} +26 -2
- package/dist/shared/{nuxt-backend.D9qXcOOI.mjs → nuxt-backend.DH1Ya3uB.mjs} +1 -1
- package/dist/shared/{nuxt-backend.Bq_mhlky.mjs → nuxt-backend.DbaXvH__.mjs} +55 -10
- package/dist/shared/{nuxt-backend.DmZI-QSO.mjs → nuxt-backend.Dikfaocl.mjs} +54 -30
- package/package.json +6 -1
- package/skills/nuxt-backend/references/api.md +28 -10
- package/skills/nuxt-backend/references/install.md +4 -1
- package/skills/nuxt-backend/references/renames.json +112 -0
- package/skills/nuxt-backend/references/surface.json +32 -2
- package/skills/nuxt-backend-ai/references/api.md +2 -1
- package/skills/nuxt-backend-auth/references/api.md +1 -1
- package/skills/nuxt-backend-billing/SKILL.md +9 -0
- package/skills/nuxt-backend-billing/references/api.md +4 -0
- package/skills/nuxt-backend-data/references/api.md +4 -1
- package/skills/nuxt-backend-email/SKILL.md +5 -2
- package/skills/nuxt-backend-email/references/api.md +1 -0
- package/skills/nuxt-backend-growth/references/api.md +4 -0
- package/skills/nuxt-backend-ship/SKILL.md +1 -1
- package/skills/nuxt-backend-ship/references/api.md +9 -5
- package/skills/nuxt-backend-ui/SKILL.md +10 -5
- package/skills/nuxt-backend-upgrade/SKILL.md +4 -3
- package/skills/nuxt-backend-upgrade/references/upgrade.md +49 -0
- package/src/convex/catalog.ts +17 -0
- package/src/convex/components/backend/_generated/component.ts +30 -2
- package/src/convex/components/backend/billing.ts +19 -5
- package/src/convex/components/backend/jobs.ts +102 -5
- package/src/convex/components/backend/schema.ts +11 -0
- package/src/convex/delivery.ts +26 -1
- package/src/convex/emails/renewal-reminder.ts +19 -1
- package/src/convex/errors.ts +23 -9
- package/src/convex/events.ts +7 -0
- package/src/convex/integrations/ai/images.ts +22 -8
- package/src/convex/integrations/ai/job-errors.ts +64 -9
- package/src/convex/integrations/ai/jobs.ts +509 -64
- package/src/convex/integrations/ai/models.ts +1 -1
- package/src/convex/integrations/ai/moderation.ts +10 -5
- package/src/convex/integrations/ai.ts +6 -1
- package/src/convex/integrations/billing/context.ts +6 -3
- package/src/convex/integrations/billing/credits.ts +4 -1
- package/src/convex/integrations/billing/passes.ts +3 -11
- package/src/convex/integrations/billing/provider-failure.ts +56 -0
- package/src/convex/integrations/billing/types/setup.ts +1 -1
- package/src/convex/integrations/billing/types/surface.ts +9 -2
- package/src/convex/integrations/email-sync.ts +74 -26
- package/src/convex/integrations/inbound.ts +32 -16
- package/src/convex/integrations/launch.ts +52 -5
- package/src/convex/integrations/referrals.ts +25 -7
- package/src/convex/integrations/storage.ts +107 -1
- package/src/convex/label-groups/admin.ts +3 -0
- package/src/convex/label-groups/audit.ts +1 -0
- package/src/convex/label-groups/auth.ts +7 -0
- package/src/convex/label-groups/errors.ts +12 -0
- package/src/convex/label-groups/gift.ts +27 -0
- package/src/convex/label-groups/pricing.ts +20 -0
- package/src/convex/label-groups/referral.ts +4 -0
- package/src/convex/label-groups/settings.ts +39 -0
- package/src/convex/label-groups/waitlist.ts +7 -2
- package/src/convex/legal.ts +23 -2
- package/src/convex/log.ts +8 -0
- package/src/convex/money.ts +40 -0
- package/src/convex/report-rules.ts +16 -0
- package/src/convex/test-billing.ts +189 -0
- package/src/convex/test-models.ts +59 -4
- package/src/convex/test.ts +95 -8
- package/src/runtime/vue/components/account/AccountDeletion.css +1 -1
- package/src/runtime/vue/components/account/ActivationChecklist.css +5 -3
- package/src/runtime/vue/components/account/ConsentPrompt.css +7 -5
- package/src/runtime/vue/components/account/EmailUnsubscribe.css +8 -4
- package/src/runtime/vue/components/account/HowDidYouHear.css +9 -5
- package/src/runtime/vue/components/account/KeepAccount.css +4 -2
- package/src/runtime/vue/components/account/OnboardingFlow.css +6 -4
- package/src/runtime/vue/components/account/ProfileIdentity.css +1 -1
- package/src/runtime/vue/components/account/ProfilePreferencesSection.css +4 -2
- package/src/runtime/vue/components/account/ProfileSettings.css +4 -2
- package/src/runtime/vue/components/account/SecurityAlerts.css +1 -1
- package/src/runtime/vue/components/account/SecurityPasskeys.css +3 -3
- package/src/runtime/vue/components/account/SecuritySessions.css +1 -1
- package/src/runtime/vue/components/account/SecuritySettings.css +1 -1
- package/src/runtime/vue/components/admin/AdminAccess.css +1 -1
- package/src/runtime/vue/components/admin/AdminAnnouncements.css +2 -2
- package/src/runtime/vue/components/admin/AdminBilling.css +1 -1
- package/src/runtime/vue/components/admin/AdminChart.css +1 -1
- package/src/runtime/vue/components/admin/AdminConsole.css +1 -0
- package/src/runtime/vue/components/admin/AdminExperiments.css +1 -1
- package/src/runtime/vue/components/admin/AdminFlags.css +2 -2
- package/src/runtime/vue/components/admin/AdminQueue.css +5 -3
- package/src/runtime/vue/components/admin/AdminQueueJob.vue +6 -2
- package/src/runtime/vue/components/admin/AdminReferrals.css +4 -2
- package/src/runtime/vue/components/admin/AdminReports.css +1 -1
- package/src/runtime/vue/components/admin/AdminRevenue.css +1 -1
- package/src/runtime/vue/components/admin/admin.css +3 -3
- package/src/runtime/vue/components/auth/AuthForm.css +7 -4
- package/src/runtime/vue/components/auth/AuthForm.vue +1 -2
- package/src/runtime/vue/components/auth/AuthFormChoose.css +2 -1
- package/src/runtime/vue/components/auth/AuthFormHeader.css +1 -1
- package/src/runtime/vue/components/auth/AuthFormPasskeyOffer.css +1 -1
- package/src/runtime/vue/components/auth/InviteRedeem.css +56 -2
- package/src/runtime/vue/components/auth/InviteRedeem.vue +92 -12
- package/src/runtime/vue/components/auth/ReauthenticateCode.css +1 -1
- package/src/runtime/vue/components/auth/ReauthenticateDialog.css +6 -3
- package/src/runtime/vue/components/auth/ReauthenticatePasskey.css +1 -1
- package/src/runtime/vue/components/auth/WaitlistForm.css +4 -2
- package/src/runtime/vue/components/auth/WaitlistForm.vue +5 -6
- package/src/runtime/vue/components/auth/WaitlistPlace.css +4 -2
- package/src/runtime/vue/components/auth/WaitlistShare.css +6 -4
- package/src/runtime/vue/components/auth/WaitlistShare.vue +2 -8
- package/src/runtime/vue/components/auth/WaitlistStatus.css +27 -1
- package/src/runtime/vue/components/auth/WaitlistStatus.vue +149 -36
- package/src/runtime/vue/components/billing/BillingHistory.css +2 -2
- package/src/runtime/vue/components/billing/BillingHistoryOrder.css +1 -1
- package/src/runtime/vue/components/billing/CancelConfirmGroup.vue +2 -8
- package/src/runtime/vue/components/billing/CancelFlow.css +6 -4
- package/src/runtime/vue/components/billing/GiftForm.css +89 -0
- package/src/runtime/vue/components/billing/GiftForm.vue +251 -0
- package/src/runtime/vue/components/billing/GiftList.css +5 -3
- package/src/runtime/vue/components/billing/GiftList.vue +21 -9
- package/src/runtime/vue/components/billing/GiftReceived.vue +11 -3
- package/src/runtime/vue/components/billing/PlanChangeConfirmGroup.vue +59 -0
- package/src/runtime/vue/components/billing/PricingChangeConfirm.vue +22 -0
- package/src/runtime/vue/components/billing/PricingPackCard.css +1 -1
- package/src/runtime/vue/components/billing/PricingPlanCard.css +31 -4
- package/src/runtime/vue/components/billing/PricingPlanCard.vue +17 -2
- package/src/runtime/vue/components/billing/PricingTable.css +2 -2
- package/src/runtime/vue/components/billing/PricingTable.vue +122 -66
- package/src/runtime/vue/components/billing/ReferralCard.css +6 -4
- package/src/runtime/vue/components/billing/ReferralLanding.css +14 -3
- package/src/runtime/vue/components/billing/ReferralLanding.vue +53 -3
- package/src/runtime/vue/components/billing/UpgradePrompt.css +6 -4
- package/src/runtime/vue/components/billing/UsageHistory.css +2 -2
- package/src/runtime/vue/components/billing/WithdrawalButton.css +5 -3
- package/src/runtime/vue/components/shared.css +62 -9
- package/src/runtime/vue/components/shell/AccessDenied.css +5 -3
- package/src/runtime/vue/components/shell/AiLabel.css +2 -2
- package/src/runtime/vue/components/shell/AppShell.css +5 -3
- package/src/runtime/vue/components/shell/ConfirmDialog.css +5 -3
- package/src/runtime/vue/components/shell/ConnectionStatus.css +1 -1
- package/src/runtime/vue/components/shell/ContactForm.css +4 -2
- package/src/runtime/vue/components/shell/Gate.css +5 -3
- package/src/runtime/vue/components/shell/LegalDocument.css +1 -1
- package/src/runtime/vue/components/shell/NoticeAnnouncement.css +1 -1
- package/src/runtime/vue/components/shell/NoticeDeletion.css +5 -3
- package/src/runtime/vue/components/shell/NoticeGift.css +1 -1
- package/src/runtime/vue/components/shell/NoticeImpersonation.css +1 -1
- package/src/runtime/vue/components/shell/NoticeLowCredits.css +6 -3
- package/src/runtime/vue/components/shell/NoticeMaintenance.css +1 -1
- package/src/runtime/vue/components/shell/NoticePastDue.css +5 -3
- package/src/runtime/vue/components/shell/NotificationInbox.css +6 -4
- package/src/runtime/vue/components/shell/ReportAppeal.vue +17 -14
- package/src/runtime/vue/components/shell/ReportNotice.css +1 -1
- package/src/runtime/vue/components/shell/UploadField.css +5 -3
- package/src/runtime/vue/components/shell/WorkspaceSwitcher.css +5 -3
- package/src/runtime/vue/components/tokens.css +30 -0
- package/src/runtime/vue/components/workspaces/AuditLog.css +2 -2
- package/src/runtime/vue/components/workspaces/WorkspaceBilling.css +75 -2
- package/src/runtime/vue/components/workspaces/WorkspaceBilling.vue +51 -63
- package/src/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +78 -0
- package/src/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue +63 -0
- package/src/runtime/vue/components/workspaces/WorkspaceCredits.css +1 -0
- package/src/runtime/vue/components/workspaces/WorkspaceList.css +2 -2
- package/src/runtime/vue/components/workspaces/WorkspaceSettings.vue +35 -5
- package/src/runtime/vue/pages/gifts.vue +12 -7
- package/src/runtime/vue/pages/invite.vue +4 -2
- package/src/runtime/vue/pages/login.vue +8 -8
- package/src/runtime/vue/pages/pricing.vue +1 -4
- package/src/runtime/vue/pages/report.vue +2 -3
- package/src/runtime/vue/pages/waitlist.vue +8 -5
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { computed, inject, ref } from "vue";
|
|
1
|
+
import { computed, inject, ref, watch } from "vue";
|
|
2
|
+
import { useRoute } from "#imports";
|
|
2
3
|
import { ConvexAuthStateKey, useMutation } from "nuxt-convex-module/client";
|
|
3
4
|
import { useAsyncQuery } from "nuxt-convex-module/app";
|
|
5
|
+
import { normalizeShareCode } from "../../../convex/referral-rules";
|
|
4
6
|
import { useActionState } from "../utils/action-state.js";
|
|
5
7
|
import { failureOf } from "../utils/backend-error.js";
|
|
6
8
|
import { forgetInvite, keepInvite, keptInvite, takeInviteFromAddress } from "../utils/kept-invite.js";
|
|
9
|
+
import { onPageOpen } from "../utils/page-open.js";
|
|
7
10
|
import { absentQuery, diagnostics, useLiveQuery } from "../utils/live-query.js";
|
|
8
|
-
import { useBackendNamespace } from "../utils/namespace.js";
|
|
11
|
+
import { useApiNamespace, useBackendNamespace } from "../utils/namespace.js";
|
|
12
|
+
import { usePageOrigin } from "../utils/page-origin.js";
|
|
9
13
|
import { useBackendPagePath } from "./use-backend-page-path.js";
|
|
10
14
|
export function useAccessPhase(options = {}) {
|
|
11
|
-
const api =
|
|
15
|
+
const api = options.api ?? useApiNamespace("access") ?? {};
|
|
12
16
|
if (!api.getAccessPhase) {
|
|
13
17
|
return { phase: computed(() => "public"), isPublic: computed(() => true), isLoading: computed(() => false), error: computed(() => null) };
|
|
14
18
|
}
|
|
@@ -23,16 +27,28 @@ export function useAccessPhase(options = {}) {
|
|
|
23
27
|
}
|
|
24
28
|
export function useInvite(options = {}) {
|
|
25
29
|
const api = useBackendNamespace("access", "useInvite", options.api);
|
|
30
|
+
const route = useRoute();
|
|
31
|
+
const loginPath = useBackendPagePath("login");
|
|
32
|
+
const landing = useBackendPagePath("referral");
|
|
33
|
+
const claims = Boolean(landing.value && useApiNamespace("referrals")?.claimReferral);
|
|
26
34
|
const runCheck = api.checkInvite ? useMutation(api.checkInvite) : null;
|
|
27
35
|
const { isPending, failure, run } = useActionState();
|
|
28
36
|
const status = ref(null);
|
|
29
37
|
const kept = ref(keptInvite() !== null);
|
|
38
|
+
const linkChecked = ref(!options.fromAddress);
|
|
39
|
+
const asked = ref(false);
|
|
40
|
+
const referral = computed(() => {
|
|
41
|
+
const value = route.query.ref;
|
|
42
|
+
const code = Array.isArray(value) ? value[0] : value;
|
|
43
|
+
return claims && typeof code === "string" ? normalizeShareCode(code) : null;
|
|
44
|
+
});
|
|
30
45
|
const check = async (codeOrToken) => {
|
|
31
46
|
const code = (codeOrToken ?? takeInviteFromAddress() ?? keptInvite() ?? "").trim();
|
|
32
47
|
if (!code) {
|
|
33
48
|
status.value = "unknown";
|
|
34
49
|
return status.value;
|
|
35
50
|
}
|
|
51
|
+
asked.value = true;
|
|
36
52
|
keepInvite(code);
|
|
37
53
|
kept.value = true;
|
|
38
54
|
try {
|
|
@@ -48,16 +64,46 @@ export function useInvite(options = {}) {
|
|
|
48
64
|
return null;
|
|
49
65
|
}
|
|
50
66
|
};
|
|
67
|
+
const forget = () => {
|
|
68
|
+
forgetInvite();
|
|
69
|
+
kept.value = false;
|
|
70
|
+
};
|
|
71
|
+
if (options.fromAddress) {
|
|
72
|
+
const auth = inject(ConvexAuthStateKey, null);
|
|
73
|
+
const open = () => {
|
|
74
|
+
const taken = takeInviteFromAddress();
|
|
75
|
+
if (taken) {
|
|
76
|
+
keepInvite(taken);
|
|
77
|
+
kept.value = true;
|
|
78
|
+
}
|
|
79
|
+
let started = false;
|
|
80
|
+
const stop = watch(() => auth != null && auth.isLoading.value, async (loading) => {
|
|
81
|
+
if (loading || started) return;
|
|
82
|
+
started = true;
|
|
83
|
+
queueMicrotask(() => stop());
|
|
84
|
+
if (auth?.isAuthenticated.value) forget();
|
|
85
|
+
else if (kept.value) await check();
|
|
86
|
+
linkChecked.value = true;
|
|
87
|
+
}, { immediate: true });
|
|
88
|
+
};
|
|
89
|
+
onPageOpen(open);
|
|
90
|
+
}
|
|
51
91
|
return {
|
|
52
92
|
check,
|
|
53
93
|
status,
|
|
54
94
|
isPending,
|
|
55
95
|
error: computed(() => failure.value),
|
|
56
96
|
isKept: computed(() => kept.value),
|
|
57
|
-
forget
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
97
|
+
forget,
|
|
98
|
+
linkChecked,
|
|
99
|
+
asked,
|
|
100
|
+
referral,
|
|
101
|
+
signInTo: computed(() => {
|
|
102
|
+
if (!loginPath.value) return null;
|
|
103
|
+
if (!referral.value || !landing.value) return loginPath.value;
|
|
104
|
+
const back = landing.value.replace(":code", encodeURIComponent(referral.value));
|
|
105
|
+
return `${loginPath.value}?redirect=${encodeURIComponent(back)}`;
|
|
106
|
+
})
|
|
61
107
|
};
|
|
62
108
|
}
|
|
63
109
|
export function useAccessAdmin(options = {}) {
|
|
@@ -110,6 +156,7 @@ export function useMemberTicket(options = {}) {
|
|
|
110
156
|
const { isPending, failure, run } = useActionState(() => signedOut.value);
|
|
111
157
|
const issued = ref(null);
|
|
112
158
|
const invitePath = useBackendPagePath("invite");
|
|
159
|
+
const origin = usePageOrigin();
|
|
113
160
|
const ticket = computed(() => {
|
|
114
161
|
if (authLoading.value) return void 0;
|
|
115
162
|
if (signedOut.value) return null;
|
|
@@ -120,7 +167,6 @@ export function useMemberTicket(options = {}) {
|
|
|
120
167
|
link: computed(() => {
|
|
121
168
|
const current = ticket.value;
|
|
122
169
|
if (current?.state !== "issued" || !invitePath.value) return null;
|
|
123
|
-
const origin = typeof window === "undefined" ? "" : window.location.origin;
|
|
124
170
|
return `${origin}${invitePath.value}#${current.token}`;
|
|
125
171
|
}),
|
|
126
172
|
issue: () => run(async () => {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type ComputedRef, type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import type { BackendError } from '../utils/backend-error.js';
|
|
3
|
+
import { type CheckoutOptions } from './use-billing.js';
|
|
4
|
+
import type { LabelGroupOverrides } from './use-labels.js';
|
|
5
|
+
import { type UsePlanChangeReturn } from './use-plan-change.js';
|
|
6
|
+
/**
|
|
7
|
+
* The states a running plan can be in, in the order they are tried: the
|
|
8
|
+
* first that holds is the one shown. A plan pass gifted until its end date,
|
|
9
|
+
* a failed payment, a pause, a cancellation set for the period's end, a
|
|
10
|
+
* plan change scheduled for it, a trial, else active. The Subscriptions
|
|
11
|
+
* page lists them in this order (test/docs pins it).
|
|
12
|
+
*/
|
|
13
|
+
export declare const PLAN_STATES: readonly ["gifted", "past_due", "paused", "canceling", "changing", "trialing", "active"];
|
|
14
|
+
/** The state a running plan is in: the first of {@link PLAN_STATES} that holds. */
|
|
15
|
+
export type PlanState = typeof PLAN_STATES[number];
|
|
16
|
+
/**
|
|
17
|
+
* The state the billing section shows: `'loading'` until the plan is known,
|
|
18
|
+
* `'error'` when it could not be read (never a plan it might not be),
|
|
19
|
+
* `'free'` on the free plan or none, else the running plan's {@link PlanState}.
|
|
20
|
+
*/
|
|
21
|
+
export type BillingSectionState = 'loading' | 'error' | 'free' | PlanState;
|
|
22
|
+
/** The lengths of a pause the section offers, in months from the period's end. */
|
|
23
|
+
export declare const PAUSE_MONTHS: readonly [1, 2, 3];
|
|
24
|
+
/**
|
|
25
|
+
* One thing a billing manager can do with the plan, as the billing section
|
|
26
|
+
* offers it: keep a gifted plan by checking it out, open the portal (to
|
|
27
|
+
* update the payment method first when one failed), resume a pause, keep a
|
|
28
|
+
* plan set to end, cancel a scheduled change, switch the plan or its
|
|
29
|
+
* billing period, pause it, cancel it.
|
|
30
|
+
*/
|
|
31
|
+
export type BillingSectionAction = 'keep-gifted' | 'portal' | 'resume' | 'uncancel' | 'cancel-change' | 'change-plan' | 'pause' | 'cancel';
|
|
32
|
+
/** Options for {@link useBillingSection}. */
|
|
33
|
+
export interface UseBillingSectionOptions {
|
|
34
|
+
/** Copy for the switch's confirmation (`change`), over `appConfig.backend.labels.pricing` and the translations. */
|
|
35
|
+
labels?: MaybeRefOrGetter<LabelGroupOverrides<'pricing'> | undefined>;
|
|
36
|
+
/** While this is `false` no pricing is read for a switch, and none is offered (default `true`). */
|
|
37
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
38
|
+
}
|
|
39
|
+
/** What {@link useBillingSection} returns. */
|
|
40
|
+
export interface UseBillingSectionReturn {
|
|
41
|
+
/** The state the section shows (see {@link BillingSectionState}). */
|
|
42
|
+
state: ComputedRef<BillingSectionState>;
|
|
43
|
+
/** `true` until the plan is known, unless its read failed, and while a return from checkout is being finished (`useBilling().isFinishingCheckout`): mark the section busy. */
|
|
44
|
+
isLoading: ComputedRef<boolean>;
|
|
45
|
+
/** `true` while a pause or a gifted plan's checkout is on its way. */
|
|
46
|
+
isPending: ComputedRef<boolean>;
|
|
47
|
+
/** Why the last action failed, else why the plan could not be read, else `null`. */
|
|
48
|
+
error: ComputedRef<BackendError | null>;
|
|
49
|
+
/**
|
|
50
|
+
* What the state calls for, in the order the section offers it: on a
|
|
51
|
+
* failed payment the portal first, then the plan's ways back (resume,
|
|
52
|
+
* keep, cancel the scheduled change), the portal, then a switch, a pause
|
|
53
|
+
* and a cancellation where each is open. A gifted plan's one offer is to
|
|
54
|
+
* keep it. Empty for anyone who does not manage the billing
|
|
55
|
+
* (`useBilling().canManage`), on the free plan, while loading and after a
|
|
56
|
+
* failed read.
|
|
57
|
+
*/
|
|
58
|
+
actions: ComputedRef<BillingSectionAction[]>;
|
|
59
|
+
/** Whether a switch is offered: a running plan, not gifted, set to end, paused or already changing, with a price to switch to (`change.targets`). */
|
|
60
|
+
switchable: ComputedRef<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Whether a pause is offered: a running plan, not gifted, set to end,
|
|
63
|
+
* paused, past due or in its trial (the provider pauses only an active
|
|
64
|
+
* subscription), and with no pause scheduled (`resumesAt` is `null`).
|
|
65
|
+
*/
|
|
66
|
+
pausable: ComputedRef<boolean>;
|
|
67
|
+
/** Whether a cancellation is offered: a running plan, not gifted, set to end already or paused, which the provider would refuse a second one for. */
|
|
68
|
+
cancellable: ComputedRef<boolean>;
|
|
69
|
+
/** The lengths a pause is offered for, in months: {@link PAUSE_MONTHS}. */
|
|
70
|
+
pauseLengths: readonly number[];
|
|
71
|
+
/**
|
|
72
|
+
* When a pause of `months` from the period's end resumes: the period's
|
|
73
|
+
* end moved on by whole months in UTC the way the provider counts them,
|
|
74
|
+
* the same day of the month, or its last when the month is shorter (a
|
|
75
|
+
* period ending January 31 paused for a month resumes February 28).
|
|
76
|
+
* `null` while the period's end is not known.
|
|
77
|
+
*/
|
|
78
|
+
resumesAfter: (months: number) => Date | null;
|
|
79
|
+
/** Pause the plan from the period's end for `months`, resuming by itself on `resumesAfter(months)`. Rejects as `useBilling().pause` does. */
|
|
80
|
+
pause: (months: number) => Promise<void>;
|
|
81
|
+
/** Keep a gifted plan: an ordinary checkout of its plan (`options` go with it, `{ redirect: true }` by default), which moves the pass to the paid plan in place. */
|
|
82
|
+
keepGifted: (options?: CheckoutOptions) => Promise<void>;
|
|
83
|
+
/** The switch to another plan or billing period, and its confirmation (`usePlanChange`). */
|
|
84
|
+
change: UsePlanChangeReturn;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The billing section of `/settings` without its markup: the state the
|
|
88
|
+
* plan is in, in the order the section tries them (a gifted plan, a failed
|
|
89
|
+
* payment, a pause, a cancellation or a plan change set for the period's
|
|
90
|
+
* end, a trial, else active), a read that failed as a failure rather than
|
|
91
|
+
* a plan, a return from checkout still finishing as busy, and what each
|
|
92
|
+
* state calls for, with the rules each offer follows: a switch only while
|
|
93
|
+
* nothing is scheduled, a pause only while none is, and its resume date
|
|
94
|
+
* counted the way the provider counts months. `<WorkspaceSettings>`'s
|
|
95
|
+
* billing section is this with the package's markup.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```vue
|
|
99
|
+
* <script setup lang="ts">
|
|
100
|
+
* const section = useBillingSection()
|
|
101
|
+
* // The app's language, not the visitor's, so the server's HTML and the browser's agree.
|
|
102
|
+
* const { locale } = useLabels('settings')
|
|
103
|
+
* const day = (date: Date | null) => (date ? new Intl.DateTimeFormat(locale.value ?? 'en', { dateStyle: 'medium' }).format(date) : '')
|
|
104
|
+
* </script>
|
|
105
|
+
* <template>
|
|
106
|
+
* <section :aria-busy="section.isLoading.value || undefined">
|
|
107
|
+
* <p v-if="section.state.value === 'error'" role="alert">The plan could not be read.</p>
|
|
108
|
+
* <button v-for="months in section.pausable.value ? section.pauseLengths : []" :key="months" @click="section.pause(months)">
|
|
109
|
+
* Pause until {{ day(section.resumesAfter(months)) }}
|
|
110
|
+
* </button>
|
|
111
|
+
* </section>
|
|
112
|
+
* </template>
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function useBillingSection(options?: UseBillingSectionOptions): UseBillingSectionReturn;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { computed, toValue } from "vue";
|
|
2
|
+
import { addMonths } from "../../../convex/catalog.js";
|
|
3
|
+
import { useActionState } from "../utils/action-state.js";
|
|
4
|
+
import { toBillingDate } from "./billing-format.js";
|
|
5
|
+
import { useBilling } from "./use-billing.js";
|
|
6
|
+
import { usePlanChange } from "./use-plan-change.js";
|
|
7
|
+
export const PLAN_STATES = ["gifted", "past_due", "paused", "canceling", "changing", "trialing", "active"];
|
|
8
|
+
export const PAUSE_MONTHS = [1, 2, 3];
|
|
9
|
+
export function useBillingSection(options = {}) {
|
|
10
|
+
const billing = useBilling();
|
|
11
|
+
const change = usePlanChange({ labels: () => toValue(options.labels), enabled: () => toValue(options.enabled) !== false });
|
|
12
|
+
const gifted = computed(() => billing.pass.value !== null);
|
|
13
|
+
const holds = {
|
|
14
|
+
gifted: () => gifted.value,
|
|
15
|
+
past_due: () => billing.isPastDue.value,
|
|
16
|
+
paused: () => billing.isPaused.value,
|
|
17
|
+
canceling: () => billing.cancelAtPeriodEnd.value,
|
|
18
|
+
changing: () => billing.pendingChange.value !== null,
|
|
19
|
+
trialing: () => billing.isTrialing.value,
|
|
20
|
+
active: () => true
|
|
21
|
+
};
|
|
22
|
+
const unknown = computed(() => billing.subscription.value === void 0);
|
|
23
|
+
const state = computed(() => {
|
|
24
|
+
if (unknown.value) return billing.error.value ? "error" : "loading";
|
|
25
|
+
if (!billing.isSubscribed.value) return "free";
|
|
26
|
+
return PLAN_STATES.find((key) => holds[key]()) ?? "active";
|
|
27
|
+
});
|
|
28
|
+
const running = computed(() => billing.isSubscribed.value && !gifted.value && !billing.cancelAtPeriodEnd.value && !billing.isPaused.value);
|
|
29
|
+
const switchable = computed(() => running.value && billing.pendingChange.value === null && (change.targets.value?.length ?? 0) > 0);
|
|
30
|
+
const pausable = computed(() => running.value && !billing.isPastDue.value && !billing.isTrialing.value && billing.resumesAt.value === null);
|
|
31
|
+
const actions = computed(() => {
|
|
32
|
+
const now = state.value;
|
|
33
|
+
if (!PLAN_STATES.includes(now) || !billing.canManage.value) return [];
|
|
34
|
+
const offered = [
|
|
35
|
+
gifted.value && "keep-gifted",
|
|
36
|
+
// A failed payment's first way back is the payment method.
|
|
37
|
+
now === "past_due" && "portal",
|
|
38
|
+
billing.isPaused.value && "resume",
|
|
39
|
+
billing.cancelAtPeriodEnd.value && "uncancel",
|
|
40
|
+
billing.pendingChange.value !== null && !billing.cancelAtPeriodEnd.value && "cancel-change",
|
|
41
|
+
// A gifted plan has no card to manage.
|
|
42
|
+
now !== "past_due" && !gifted.value && "portal",
|
|
43
|
+
switchable.value && "change-plan",
|
|
44
|
+
pausable.value && "pause",
|
|
45
|
+
running.value && "cancel"
|
|
46
|
+
];
|
|
47
|
+
return offered.filter((action) => action !== false);
|
|
48
|
+
});
|
|
49
|
+
const resumesAfter = (months) => {
|
|
50
|
+
const end = toBillingDate(billing.subscription.value?.currentPeriodEnd);
|
|
51
|
+
return end ? new Date(addMonths(end.getTime(), months)) : null;
|
|
52
|
+
};
|
|
53
|
+
const { isPending, failure, run } = useActionState();
|
|
54
|
+
return {
|
|
55
|
+
state,
|
|
56
|
+
isLoading: computed(() => unknown.value && !billing.error.value || billing.isFinishingCheckout.value),
|
|
57
|
+
isPending,
|
|
58
|
+
error: computed(() => failure.value ?? (unknown.value ? billing.error.value : null)),
|
|
59
|
+
actions,
|
|
60
|
+
switchable,
|
|
61
|
+
pausable,
|
|
62
|
+
cancellable: running,
|
|
63
|
+
pauseLengths: PAUSE_MONTHS,
|
|
64
|
+
resumesAfter,
|
|
65
|
+
pause: (months) => {
|
|
66
|
+
const resumesAt = resumesAfter(months);
|
|
67
|
+
return run(() => billing.pause(resumesAt ? { resumesAt } : {}), { silent: true });
|
|
68
|
+
},
|
|
69
|
+
keepGifted: async (checkout = {}) => {
|
|
70
|
+
const plan = billing.pass.value?.plan;
|
|
71
|
+
const product = plan ? billing.products.value?.[plan]?.id : void 0;
|
|
72
|
+
if (product) await run(() => billing.checkout(product, { redirect: true, ...checkout }), { silent: true });
|
|
73
|
+
},
|
|
74
|
+
change
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FunctionReference } from 'convex/server';
|
|
2
2
|
import { type ComputedRef, type MaybeRefOrGetter, type Ref } from 'vue';
|
|
3
3
|
import type { BackendError } from '../utils/backend-error.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type MeterUnit } from '../../../convex/catalog.js';
|
|
5
5
|
import type { QuotaUsage } from '../../../convex/integrations/billing/types/records.js';
|
|
6
6
|
import type { CancelFlowState, CancelOutcome, SaveOffer, WithdrawalPeriod } from '../../../convex/integrations/billing/types/lifecycle.js';
|
|
7
7
|
export type { CancelFlowState, CancelOutcome, SaveOffer, WithdrawalPeriod };
|
|
@@ -87,10 +87,11 @@ export interface BillingPage<Item> {
|
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* The subset of the provider's proration behaviours a **client** may choose
|
|
90
|
-
* (`ProrationBehavior` in `nuxt-backend/billing` has all four).
|
|
91
|
-
* `
|
|
92
|
-
*
|
|
93
|
-
*
|
|
90
|
+
* (`ProrationBehavior` in `nuxt-backend/billing` has all four). Both switch
|
|
91
|
+
* at once: `invoice` charges or credits the difference now, `prorate` on
|
|
92
|
+
* the next invoice. `next_period` schedules the switch for the period's
|
|
93
|
+
* end and `reset` charges the new plan in full and restarts the cycle, so
|
|
94
|
+
* they stay server-side — pass them from your own Convex action via
|
|
94
95
|
* `billing.updateSubscription(ctx, …)`, or make one the organization's default.
|
|
95
96
|
*/
|
|
96
97
|
export type ClientProrationBehavior = 'invoice' | 'prorate';
|
|
@@ -106,6 +107,61 @@ export interface PendingPlanChange {
|
|
|
106
107
|
/** When the change takes effect. */
|
|
107
108
|
appliesAt: Date;
|
|
108
109
|
}
|
|
110
|
+
/** A billing interval a plan is priced at, as a plan change reads it. */
|
|
111
|
+
export type PlanChangeInterval = 'month' | 'year';
|
|
112
|
+
/**
|
|
113
|
+
* What a plan change would do, before it is made ({@link UseBillingReturn.changeOf}):
|
|
114
|
+
* when it takes effect, how the current period's difference is settled,
|
|
115
|
+
* and the rule that decided it. The same rule the server applies
|
|
116
|
+
* (`billing.updateSubscription`), for a switch made with
|
|
117
|
+
* `changePlan(productId, { proration: 'invoice' })`, the one the packaged
|
|
118
|
+
* confirmations make, so a confirmation of your own that switches the same
|
|
119
|
+
* way says what the switch will do. A `changePlan` without `proration`
|
|
120
|
+
* settles by the organization's default instead, which may defer the
|
|
121
|
+
* charge to the next invoice or schedule the switch for the period's end.
|
|
122
|
+
*/
|
|
123
|
+
export interface PlanChangePreview {
|
|
124
|
+
/** The product the subscription would switch to. */
|
|
125
|
+
productId: string;
|
|
126
|
+
/** Its plan's catalog key (`'team'`; a yearly price reads as its plan's key), when the catalog names it. */
|
|
127
|
+
plan?: string;
|
|
128
|
+
/** The interval it bills at, when known. */
|
|
129
|
+
interval?: PlanChangeInterval;
|
|
130
|
+
/** The interval the subscription bills at now, when known. */
|
|
131
|
+
fromInterval?: PlanChangeInterval;
|
|
132
|
+
/**
|
|
133
|
+
* `'now'`: the subscription moves at once. `'period_end'`: the change is
|
|
134
|
+
* scheduled for the end of the current period and reads back as
|
|
135
|
+
* `pendingChange` until then.
|
|
136
|
+
*/
|
|
137
|
+
applies: 'now' | 'period_end';
|
|
138
|
+
/** When a scheduled change takes effect (the current period's end); `null` for one made at once, or while the period's end is not known. */
|
|
139
|
+
appliesAt: Date | null;
|
|
140
|
+
/**
|
|
141
|
+
* How the switch is settled. `'now'`: money changes hands at once — the
|
|
142
|
+
* current period's difference, prorated, is charged or credited; during
|
|
143
|
+
* a trial, the new plan's first period is charged, as a switch to a plan
|
|
144
|
+
* with no trial (or a shorter one, already over) ends the trial.
|
|
145
|
+
* `'none'`: nothing is settled now — the change waits for the period's
|
|
146
|
+
* end and the new price is charged from the renewal on, or, during a
|
|
147
|
+
* trial, the trial carries over to the new plan and nothing is charged
|
|
148
|
+
* until it ends.
|
|
149
|
+
*/
|
|
150
|
+
proration: 'now' | 'none';
|
|
151
|
+
/**
|
|
152
|
+
* `true` while the subscription is in its trial: the switch then
|
|
153
|
+
* settles no difference, and `proration` says whether the trial carries
|
|
154
|
+
* over (`'none'`) or ends with a charge (`'now'`). A change that waits
|
|
155
|
+
* applies when the trial ends.
|
|
156
|
+
*/
|
|
157
|
+
trial: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Why it waits, when it does: `'paid_year'` for a yearly price left for a
|
|
160
|
+
* monthly one, which runs out the year paid for (that price granted the
|
|
161
|
+
* year's credits up front). `null` for a change made at once.
|
|
162
|
+
*/
|
|
163
|
+
rule: 'paid_year' | null;
|
|
164
|
+
}
|
|
109
165
|
type EmptyArgs = Record<string, never>;
|
|
110
166
|
type Query<Result> = FunctionReference<'query', 'public', EmptyArgs, Result>;
|
|
111
167
|
/**
|
|
@@ -653,6 +709,18 @@ export interface UseBillingReturn {
|
|
|
653
709
|
* plan change, so it reads back as soon as `changePlan` returns.
|
|
654
710
|
*/
|
|
655
711
|
pendingChange: ComputedRef<PendingPlanChange | null>;
|
|
712
|
+
/**
|
|
713
|
+
* What switching the subscription to `productId` would do — when it takes
|
|
714
|
+
* effect, how the period's difference is settled, and why — before
|
|
715
|
+
* `changePlan(productId, { proration: 'invoice' })` makes it: what a
|
|
716
|
+
* confirmation step says. A yearly price left for a monthly one waits for
|
|
717
|
+
* the paid year's end; any other change applies at once, settling the
|
|
718
|
+
* period's difference then, or during a trial carrying the trial over
|
|
719
|
+
* when the new plan has one. `null` without a paid subscription to change (none,
|
|
720
|
+
* the free plan, a gifted pass, still loading), and for the product it is
|
|
721
|
+
* already on. Reactive: call it inside a `computed` or the template.
|
|
722
|
+
*/
|
|
723
|
+
changeOf: (productId: string) => PlanChangePreview | null;
|
|
656
724
|
/** Generate a checkout for the given product(s) and open it (returns the URL). */
|
|
657
725
|
checkout: (productIds: string | string[], options?: CheckoutOptions) => Promise<string>;
|
|
658
726
|
/** Open the billing customer portal (returns the URL). */
|
|
@@ -664,6 +732,9 @@ export interface UseBillingReturn {
|
|
|
664
732
|
* Switch the active subscription to another product (upgrade/downgrade).
|
|
665
733
|
* From a yearly price to a monthly one the switch waits for the paid
|
|
666
734
|
* year's end, whatever `proration` says: it reads back as `pendingChange`.
|
|
735
|
+
* Without `proration` the organization's default settles it; `changeOf`
|
|
736
|
+
* describes the switch made with `proration: 'invoice'`, as the packaged
|
|
737
|
+
* confirmations make it.
|
|
667
738
|
*/
|
|
668
739
|
changePlan: (productId: string, options?: ChangePlanOptions) => Promise<void>;
|
|
669
740
|
/**
|
|
@@ -5,11 +5,26 @@ import { useBillingAccess } from "../utils/billing-access.js";
|
|
|
5
5
|
import { finishingCheckout } from "../utils/checkout-return.js";
|
|
6
6
|
import { absentQuery, diagnostics, useLiveQuery } from "../utils/live-query.js";
|
|
7
7
|
import { useBackendNamespace } from "../utils/namespace.js";
|
|
8
|
+
import { addMonths } from "../../../convex/catalog.js";
|
|
8
9
|
import { openProviderUrl } from "../utils/open-url.js";
|
|
9
10
|
import { toBillingDate } from "./billing-format.js";
|
|
10
11
|
import { createCheckout, notConfigured } from "./billing-provider.js";
|
|
11
12
|
export { formatBillingAmount, toBillingDate } from "./billing-format.js";
|
|
12
13
|
export { createCheckout, createProviderPager } from "./billing-provider.js";
|
|
14
|
+
function productTrial(product) {
|
|
15
|
+
const interval = product.trialInterval;
|
|
16
|
+
if (interval !== "day" && interval !== "week" && interval !== "month" && interval !== "year") return null;
|
|
17
|
+
const count = typeof product.trialIntervalCount === "number" && product.trialIntervalCount > 0 ? product.trialIntervalCount : 1;
|
|
18
|
+
return { interval, count };
|
|
19
|
+
}
|
|
20
|
+
function trialRunsAt(trial, start, now) {
|
|
21
|
+
if (!trial) return false;
|
|
22
|
+
if (!start) return true;
|
|
23
|
+
const from = start.getTime();
|
|
24
|
+
const day = 24 * 60 * 60 * 1e3;
|
|
25
|
+
const end = trial.interval === "day" ? from + trial.count * day : trial.interval === "week" ? from + trial.count * 7 * day : addMonths(from, trial.interval === "year" ? trial.count * 12 : trial.count);
|
|
26
|
+
return end > now;
|
|
27
|
+
}
|
|
13
28
|
export function useBilling(options = {}) {
|
|
14
29
|
const billing = useBackendNamespace("billing", "useBilling", options.api);
|
|
15
30
|
const products = billing.getConfiguredProducts ? useLiveQuery(billing.getConfiguredProducts, {}) : absentQuery();
|
|
@@ -44,6 +59,38 @@ export function useBilling(options = {}) {
|
|
|
44
59
|
const trialEnd = field((subscription) => toBillingDate(subscription.trialEnd));
|
|
45
60
|
const resumesAt = field((subscription) => toBillingDate(subscription.resumesAt));
|
|
46
61
|
const { canManage, saveOffers, softOptIn } = useBillingAccess(billing.getBillingAccess);
|
|
62
|
+
const productTerms = computed(() => {
|
|
63
|
+
const terms = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const [key, product] of Object.entries(products.data.value ?? {})) {
|
|
65
|
+
if (!product) continue;
|
|
66
|
+
const recurring = product.recurringInterval;
|
|
67
|
+
const interval = key.endsWith(":year") ? "year" : recurring === "year" || recurring === "month" ? recurring : void 0;
|
|
68
|
+
terms.set(product.id, { plan: key.replace(/:year$/, ""), ...interval ? { interval } : {}, trial: productTrial(product) });
|
|
69
|
+
}
|
|
70
|
+
return terms;
|
|
71
|
+
});
|
|
72
|
+
const changeOf = (productId) => {
|
|
73
|
+
const subscription = currentSubscription.value;
|
|
74
|
+
if (!subscription || subscription.free === true || subscription.pass || subscription.productId === productId) return null;
|
|
75
|
+
const target = productTerms.value.get(productId);
|
|
76
|
+
const recurring = subscription.recurringInterval;
|
|
77
|
+
const fromInterval = recurring === "year" || recurring === "month" ? recurring : typeof subscription.productKey === "string" ? subscription.productKey.endsWith(":year") ? "year" : "month" : productTerms.value.get(subscription.productId)?.interval;
|
|
78
|
+
const waits = fromInterval === "year" && target?.interval === "month";
|
|
79
|
+
const now = Date.now();
|
|
80
|
+
const trial = subscription.status === "trialing" || (toBillingDate(subscription.trialEnd)?.getTime() ?? 0) > now;
|
|
81
|
+
const trialCarries = !target || trialRunsAt(target.trial, toBillingDate(subscription.trialStart), now);
|
|
82
|
+
return {
|
|
83
|
+
productId,
|
|
84
|
+
...target ? { plan: target.plan } : {},
|
|
85
|
+
...target?.interval ? { interval: target.interval } : {},
|
|
86
|
+
...fromInterval ? { fromInterval } : {},
|
|
87
|
+
applies: waits ? "period_end" : "now",
|
|
88
|
+
appliesAt: waits ? toBillingDate(subscription.currentPeriodEnd) : null,
|
|
89
|
+
proration: waits || trial && trialCarries ? "none" : "now",
|
|
90
|
+
trial,
|
|
91
|
+
rule: waits ? "paid_year" : null
|
|
92
|
+
};
|
|
93
|
+
};
|
|
47
94
|
const { isPending, failure, run } = useActionState(() => signedOut.value);
|
|
48
95
|
const checkout = createCheckout(billing);
|
|
49
96
|
const runPortal = billing.generateCustomerPortalUrl ? useAction(billing.generateCustomerPortalUrl) : null;
|
|
@@ -97,6 +144,7 @@ export function useBilling(options = {}) {
|
|
|
97
144
|
if (!change || typeof change.productId !== "string" || !appliesAt) return null;
|
|
98
145
|
return { productId: change.productId, appliesAt };
|
|
99
146
|
}),
|
|
147
|
+
changeOf,
|
|
100
148
|
checkout: (productIds, opts) => run(() => checkout(productIds, opts)),
|
|
101
149
|
portal: (opts = {}) => run(async () => {
|
|
102
150
|
if (!runPortal) notConfigured("portal");
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { type ComputedRef, type Ref } from 'vue';
|
|
2
|
+
import type { PricedGiftLength, PricedPack, PricedPlan } from '../../../convex/integrations/billing/types/records.js';
|
|
3
|
+
import { type BackendError } from '../utils/backend-error.js';
|
|
4
|
+
/** What a gift holds: a credit pack, or a plan for a number of months (a pass). */
|
|
5
|
+
export type GiftKind = 'pack' | 'pass';
|
|
6
|
+
/** The fields a refusal of a gift can name, as the form marks them. */
|
|
7
|
+
export type GiftField = 'recipientEmail' | 'message' | 'deliverAt';
|
|
8
|
+
/** The longest note a gift carries: the server's own limit. */
|
|
9
|
+
export declare const GIFT_MESSAGE_MAX = 500;
|
|
10
|
+
/** Options for {@link useGiftForm}. */
|
|
11
|
+
export interface UseGiftFormOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Where the purchaser returns once paid: a path on the site or a full URL
|
|
14
|
+
* on its origin. Default: the page the form is on, with `?sent=1`, which
|
|
15
|
+
* the form reads back as {@link UseGiftFormReturn.sent}.
|
|
16
|
+
*/
|
|
17
|
+
successUrl?: string;
|
|
18
|
+
/** Open the checkout in the same tab (default `true`); `false` opens a new one. */
|
|
19
|
+
redirect?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** The gift as chosen: what it is and what it costs. */
|
|
22
|
+
export interface GiftChoice {
|
|
23
|
+
kind: GiftKind;
|
|
24
|
+
/** The pack's catalog key, or the plan's for a pass. */
|
|
25
|
+
key: string;
|
|
26
|
+
/** The pack's or the plan's name, as the provider lists it. */
|
|
27
|
+
name: string;
|
|
28
|
+
/** For a pass, how many months it holds the plan. */
|
|
29
|
+
months?: number;
|
|
30
|
+
/** What it costs, in the currency's smallest unit. */
|
|
31
|
+
amount: number;
|
|
32
|
+
/** Lower-case ISO 4217 code. */
|
|
33
|
+
currency: string;
|
|
34
|
+
/** That price, formatted in the app's active locale (English without `@nuxtjs/i18n`), alike on the server and in the browser. */
|
|
35
|
+
price: string;
|
|
36
|
+
}
|
|
37
|
+
/** What {@link useGiftForm} returns. */
|
|
38
|
+
export interface UseGiftFormReturn {
|
|
39
|
+
/** What the gift holds; starts as a pass when the address names a plan (`?plan=`), else a pack. */
|
|
40
|
+
kind: Ref<GiftKind>;
|
|
41
|
+
/** The kinds on sale: `pack` with a pack to give, `pass` with a giftable plan. */
|
|
42
|
+
kinds: ComputedRef<GiftKind[]>;
|
|
43
|
+
/** The credit packs on sale, in catalog order. */
|
|
44
|
+
packs: ComputedRef<PricedPack[]>;
|
|
45
|
+
/** The plans a pass can be bought for: paid, on sale, with gift lengths (`gift: { months }` in the catalog). */
|
|
46
|
+
plans: ComputedRef<PricedPlan[]>;
|
|
47
|
+
/** The pack chosen, by key: the address's `?pack=`, else the first on sale. */
|
|
48
|
+
pack: Ref<string>;
|
|
49
|
+
/** The plan chosen for a pass, by key: the address's `?plan=`, else the first giftable. */
|
|
50
|
+
plan: Ref<string>;
|
|
51
|
+
/** The pass's length in months: the address's `?months=`, else the plan's first length. */
|
|
52
|
+
months: Ref<number>;
|
|
53
|
+
/** The lengths the chosen plan is gifted for, each at its live price: `PricedPlan.gift.lengths`. */
|
|
54
|
+
lengths: ComputedRef<PricedGiftLength[]>;
|
|
55
|
+
/** Who receives it. */
|
|
56
|
+
recipientEmail: Ref<string>;
|
|
57
|
+
/** A plain-text note of at most {@link GIFT_MESSAGE_MAX} characters, no links, shown to them in the app. */
|
|
58
|
+
message: Ref<string>;
|
|
59
|
+
/** The day the notice goes out, `YYYY-MM-DD` in the purchaser's own calendar, at 09:00 their time; `''` sends it once paid. */
|
|
60
|
+
deliverOn: Ref<string>;
|
|
61
|
+
/**
|
|
62
|
+
* The first day the delivery date takes, `YYYY-MM-DD`: a date input's
|
|
63
|
+
* `min`. Today in the purchaser's own calendar once the page is on
|
|
64
|
+
* screen, so it is never a day already over for them; while the page
|
|
65
|
+
* hydrates, today in UTC by the server's clock, as the server rendered it.
|
|
66
|
+
*/
|
|
67
|
+
firstDay: ComputedRef<string>;
|
|
68
|
+
/** The last day it takes, a year after the first: a date input's `max`. */
|
|
69
|
+
lastDay: ComputedRef<string>;
|
|
70
|
+
/** The gift as chosen, with its price; `null` until something on sale is chosen. */
|
|
71
|
+
choice: ComputedRef<GiftChoice | null>;
|
|
72
|
+
/** `true` once the session says someone is signed in: a visitor signs in before paying. */
|
|
73
|
+
isSignedIn: ComputedRef<boolean>;
|
|
74
|
+
/** `true` until the pricing has loaded. */
|
|
75
|
+
isLoading: ComputedRef<boolean>;
|
|
76
|
+
/** `true` while the checkout opens. */
|
|
77
|
+
isPending: ComputedRef<boolean>;
|
|
78
|
+
/** Why the last send failed, else `null`. */
|
|
79
|
+
error: ComputedRef<BackendError | null>;
|
|
80
|
+
/** The field that refusal names, to mark it invalid, else `null`. */
|
|
81
|
+
invalidField: ComputedRef<GiftField | null>;
|
|
82
|
+
/** `true` after the purchaser came back paid (`?sent=1`, taken off the address), until the next send. */
|
|
83
|
+
sent: Ref<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Send the gift: a visitor goes to the sign-in page and back to this form
|
|
86
|
+
* with the choice kept (`?pack=`, or `?plan=` and `?months=`); a signed-in
|
|
87
|
+
* person goes to the checkout of `useGifts().send`, paying in the
|
|
88
|
+
* pricing's currency. Resolves `true` once the checkout opened, `false`
|
|
89
|
+
* when there was nothing to send or it went to sign in first. Never
|
|
90
|
+
* rejects: a refusal lands in `error`.
|
|
91
|
+
*/
|
|
92
|
+
send: () => Promise<boolean>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The gift form without its markup: a credit pack or a plan pass with its
|
|
96
|
+
* length (the lengths the plan is gifted for, at their live prices), the
|
|
97
|
+
* recipient, a note and a delivery day, and the send, which signs a
|
|
98
|
+
* visitor in and brings them back, then opens the purchaser's checkout
|
|
99
|
+
* over `useGifts().send`. The purchaser comes back with `?sent=1`, read as
|
|
100
|
+
* `sent`. What `<GiftForm>` renders, and the packaged `/gifts` page shows.
|
|
101
|
+
*
|
|
102
|
+
* @experimental
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```vue
|
|
106
|
+
* <script setup lang="ts">
|
|
107
|
+
* const gift = useGiftForm()
|
|
108
|
+
* </script>
|
|
109
|
+
* <template>
|
|
110
|
+
* <p v-if="gift.sent.value">Paid. It goes out on the day you picked.</p>
|
|
111
|
+
* <form @submit.prevent="gift.send()">
|
|
112
|
+
* <select v-model="gift.pack.value">
|
|
113
|
+
* <option v-for="pack in gift.packs.value" :key="pack.key" :value="pack.key">{{ pack.name }}</option>
|
|
114
|
+
* </select>
|
|
115
|
+
* <input v-model="gift.recipientEmail.value" type="email" required>
|
|
116
|
+
* <button :aria-disabled="gift.isPending.value || undefined">
|
|
117
|
+
* Send {{ gift.choice.value?.price }}
|
|
118
|
+
* </button>
|
|
119
|
+
* </form>
|
|
120
|
+
* </template>
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function useGiftForm(options?: UseGiftFormOptions): UseGiftFormReturn;
|