nuxt-backend 0.2.0 → 0.2.1
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/dist/chunks/catalog.mjs +1 -1
- package/dist/chunks/doctor.mjs +71 -12
- 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 +4 -4
- package/dist/chunks/run.mjs +1 -1
- package/dist/chunks/server.mjs +7 -5
- package/dist/cli.mjs +122 -23
- package/dist/convex/account-data.d.ts +0 -2
- package/dist/convex/account-data.d.ts.map +1 -1
- package/dist/convex/account-data.js +0 -4
- package/dist/convex/account-data.js.map +1 -1
- package/dist/convex/catalog.d.ts +22 -0
- package/dist/convex/catalog.d.ts.map +1 -1
- package/dist/convex/catalog.js.map +1 -1
- package/dist/convex/client/better-auth-options.d.ts.map +1 -1
- package/dist/convex/client/better-auth-options.js +11 -1
- package/dist/convex/client/better-auth-options.js.map +1 -1
- package/dist/convex/client/client-address.d.ts +21 -0
- package/dist/convex/client/client-address.d.ts.map +1 -0
- package/dist/convex/client/client-address.js +37 -0
- package/dist/convex/client/client-address.js.map +1 -0
- package/dist/convex/client/index.d.ts +34 -2
- package/dist/convex/client/index.d.ts.map +1 -1
- package/dist/convex/components/backend/_generated/component.d.ts +6 -0
- package/dist/convex/components/backend/_generated/component.d.ts.map +1 -1
- package/dist/convex/components/backend/account.d.ts +6 -6
- package/dist/convex/components/backend/account.d.ts.map +1 -1
- package/dist/convex/components/backend/account.js +6 -2
- 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 +4 -1
- package/dist/convex/components/backend/adapter.js.map +1 -1
- package/dist/convex/components/backend/ai.d.ts +11 -3
- package/dist/convex/components/backend/ai.d.ts.map +1 -1
- package/dist/convex/components/backend/ai.js +18 -52
- package/dist/convex/components/backend/ai.js.map +1 -1
- package/dist/convex/components/backend/billing.d.ts.map +1 -1
- package/dist/convex/components/backend/billing.js +12 -32
- package/dist/convex/components/backend/billing.js.map +1 -1
- package/dist/convex/components/backend/consents.d.ts.map +1 -1
- package/dist/convex/components/backend/consents.js +2 -1
- package/dist/convex/components/backend/consents.js.map +1 -1
- package/dist/convex/components/backend/gifts.d.ts +1 -1
- package/dist/convex/components/backend/gifts.d.ts.map +1 -1
- package/dist/convex/components/backend/gifts.js +9 -4
- package/dist/convex/components/backend/gifts.js.map +1 -1
- package/dist/convex/components/backend/lifecycle.d.ts.map +1 -1
- package/dist/convex/components/backend/lifecycle.js +18 -14
- package/dist/convex/components/backend/lifecycle.js.map +1 -1
- package/dist/convex/components/backend/notifications.d.ts +13 -0
- package/dist/convex/components/backend/notifications.d.ts.map +1 -1
- package/dist/convex/components/backend/notifications.js +21 -0
- package/dist/convex/components/backend/notifications.js.map +1 -1
- package/dist/convex/components/backend/referrals.d.ts.map +1 -1
- package/dist/convex/components/backend/referrals.js +13 -16
- package/dist/convex/components/backend/referrals.js.map +1 -1
- package/dist/convex/components/backend/reports.js +7 -7
- package/dist/convex/components/backend/reports.js.map +1 -1
- package/dist/convex/components/backend/schema.d.ts +151 -35
- package/dist/convex/components/backend/schema.d.ts.map +1 -1
- package/dist/convex/components/backend/schema.js +127 -153
- package/dist/convex/components/backend/schema.js.map +1 -1
- package/dist/convex/components/backend/storage.d.ts.map +1 -1
- package/dist/convex/components/backend/storage.js +10 -10
- package/dist/convex/components/backend/storage.js.map +1 -1
- package/dist/convex/components/backend/subscriptions.d.ts +3 -3
- package/dist/convex/components/backend/subscriptions.d.ts.map +1 -1
- package/dist/convex/components/backend/subscriptions.js +6 -35
- package/dist/convex/components/backend/subscriptions.js.map +1 -1
- package/dist/convex/components/backend/waitlist.d.ts +1 -1
- package/dist/convex/components/backend/webhooks.d.ts +0 -1
- package/dist/convex/components/backend/webhooks.d.ts.map +1 -1
- package/dist/convex/components/backend/webhooks.js +1 -1
- package/dist/convex/components/backend/webhooks.js.map +1 -1
- package/dist/convex/consent-rules.d.ts +0 -2
- package/dist/convex/consent-rules.d.ts.map +1 -1
- package/dist/convex/consent-rules.js.map +1 -1
- package/dist/convex/constants.d.ts +0 -1
- package/dist/convex/constants.d.ts.map +1 -1
- package/dist/convex/constants.js +0 -1
- package/dist/convex/constants.js.map +1 -1
- package/dist/convex/email-templates.d.ts +0 -1
- package/dist/convex/email-templates.d.ts.map +1 -1
- package/dist/convex/email-templates.js +0 -1
- package/dist/convex/email-templates.js.map +1 -1
- package/dist/convex/integrations/admin.d.ts +2 -1
- package/dist/convex/integrations/admin.d.ts.map +1 -1
- package/dist/convex/integrations/admin.js.map +1 -1
- package/dist/convex/integrations/ai/job-errors.d.ts +7 -0
- package/dist/convex/integrations/ai/job-errors.d.ts.map +1 -1
- package/dist/convex/integrations/ai/job-errors.js +22 -0
- package/dist/convex/integrations/ai/job-errors.js.map +1 -1
- package/dist/convex/integrations/ai/metering.d.ts +12 -0
- package/dist/convex/integrations/ai/metering.d.ts.map +1 -1
- package/dist/convex/integrations/ai/metering.js +19 -10
- package/dist/convex/integrations/ai/metering.js.map +1 -1
- package/dist/convex/integrations/ai/models.d.ts.map +1 -1
- package/dist/convex/integrations/ai/models.js +3 -1
- package/dist/convex/integrations/ai/models.js.map +1 -1
- package/dist/convex/integrations/ai/moderation.d.ts +2 -0
- package/dist/convex/integrations/ai/moderation.d.ts.map +1 -1
- package/dist/convex/integrations/ai/moderation.js +29 -2
- package/dist/convex/integrations/ai/moderation.js.map +1 -1
- package/dist/convex/integrations/ai/stream.d.ts +1 -1
- package/dist/convex/integrations/ai/stream.d.ts.map +1 -1
- package/dist/convex/integrations/ai/stream.js +3 -11
- package/dist/convex/integrations/ai/stream.js.map +1 -1
- package/dist/convex/integrations/billing/context.d.ts +0 -1
- package/dist/convex/integrations/billing/context.d.ts.map +1 -1
- package/dist/convex/integrations/billing/context.js +1 -4
- package/dist/convex/integrations/billing/context.js.map +1 -1
- package/dist/convex/integrations/billing/credits.d.ts.map +1 -1
- package/dist/convex/integrations/billing/customers.d.ts.map +1 -1
- package/dist/convex/integrations/billing/customers.js +25 -5
- package/dist/convex/integrations/billing/customers.js.map +1 -1
- package/dist/convex/integrations/billing/features.d.ts.map +1 -1
- package/dist/convex/integrations/billing/free-plan.d.ts +1 -1
- package/dist/convex/integrations/billing/free-plan.d.ts.map +1 -1
- package/dist/convex/integrations/billing/free-plan.js +18 -4
- package/dist/convex/integrations/billing/free-plan.js.map +1 -1
- package/dist/convex/integrations/billing/functions.d.ts +5 -1
- package/dist/convex/integrations/billing/functions.d.ts.map +1 -1
- package/dist/convex/integrations/billing/functions.js +16 -5
- 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 +2 -2
- package/dist/convex/integrations/billing/gifts.js.map +1 -1
- package/dist/convex/integrations/billing/history.d.ts.map +1 -1
- package/dist/convex/integrations/billing/history.js +3 -1
- package/dist/convex/integrations/billing/history.js.map +1 -1
- package/dist/convex/integrations/billing/lifecycle.d.ts +4 -1
- package/dist/convex/integrations/billing/lifecycle.d.ts.map +1 -1
- package/dist/convex/integrations/billing/lifecycle.js +33 -2
- package/dist/convex/integrations/billing/lifecycle.js.map +1 -1
- package/dist/convex/integrations/billing/passes.d.ts +0 -2
- package/dist/convex/integrations/billing/passes.d.ts.map +1 -1
- package/dist/convex/integrations/billing/passes.js +2 -3
- package/dist/convex/integrations/billing/passes.js.map +1 -1
- package/dist/convex/integrations/billing/pricing.d.ts +4 -1
- package/dist/convex/integrations/billing/pricing.d.ts.map +1 -1
- package/dist/convex/integrations/billing/pricing.js +11 -9
- package/dist/convex/integrations/billing/pricing.js.map +1 -1
- package/dist/convex/integrations/billing/purchase.d.ts.map +1 -1
- package/dist/convex/integrations/billing/purchase.js +1 -2
- package/dist/convex/integrations/billing/purchase.js.map +1 -1
- 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/lifecycle.d.ts +12 -0
- package/dist/convex/integrations/billing/types/lifecycle.d.ts.map +1 -1
- package/dist/convex/integrations/billing/types/options.d.ts +4 -1
- package/dist/convex/integrations/billing/types/options.d.ts.map +1 -1
- package/dist/convex/integrations/billing/types/records.d.ts +7 -1
- package/dist/convex/integrations/billing/types/records.d.ts.map +1 -1
- package/dist/convex/integrations/billing/types/surface.d.ts +5 -1
- package/dist/convex/integrations/billing/types/surface.d.ts.map +1 -1
- package/dist/convex/integrations/billing.d.ts +2 -2
- package/dist/convex/integrations/billing.d.ts.map +1 -1
- package/dist/convex/integrations/billing.js +1 -0
- package/dist/convex/integrations/billing.js.map +1 -1
- package/dist/convex/integrations/email-preferences.d.ts +1 -1
- package/dist/convex/integrations/email-preferences.d.ts.map +1 -1
- package/dist/convex/integrations/email-sync.d.ts.map +1 -1
- package/dist/convex/integrations/email-sync.js +43 -1
- package/dist/convex/integrations/email-sync.js.map +1 -1
- package/dist/convex/integrations/notifications.d.ts +24 -4
- package/dist/convex/integrations/notifications.d.ts.map +1 -1
- package/dist/convex/integrations/notifications.js +30 -14
- package/dist/convex/integrations/notifications.js.map +1 -1
- package/dist/convex/integrations/rate-limit.d.ts +6 -5
- package/dist/convex/integrations/rate-limit.d.ts.map +1 -1
- package/dist/convex/integrations/rate-limit.js +6 -5
- package/dist/convex/integrations/rate-limit.js.map +1 -1
- package/dist/convex/integrations/reports.d.ts +1 -1
- package/dist/convex/integrations/reports.d.ts.map +1 -1
- package/dist/convex/integrations/reports.js +0 -11
- package/dist/convex/integrations/reports.js.map +1 -1
- package/dist/convex/integrations/webhooks.d.ts +1 -3
- package/dist/convex/integrations/webhooks.d.ts.map +1 -1
- package/dist/convex/integrations/webhooks.js.map +1 -1
- package/dist/convex/label-groups/cancelFlow.d.ts +3 -0
- package/dist/convex/label-groups/cancelFlow.d.ts.map +1 -1
- package/dist/convex/label-groups/cancelFlow.js +5 -0
- package/dist/convex/label-groups/cancelFlow.js.map +1 -1
- package/dist/convex/label-groups/credits.d.ts +14 -1
- package/dist/convex/label-groups/credits.d.ts.map +1 -1
- package/dist/convex/label-groups/credits.js +17 -2
- package/dist/convex/label-groups/credits.js.map +1 -1
- package/dist/convex/label-groups/notifications.d.ts +19 -2
- package/dist/convex/label-groups/notifications.d.ts.map +1 -1
- package/dist/convex/label-groups/notifications.js +19 -15
- package/dist/convex/label-groups/notifications.js.map +1 -1
- package/dist/convex/label-groups/pricing.js +8 -8
- package/dist/convex/label-groups/pricing.js.map +1 -1
- package/dist/convex/label-groups/settings.d.ts.map +1 -1
- package/dist/convex/label-groups/settings.js +4 -3
- package/dist/convex/label-groups/settings.js.map +1 -1
- package/dist/convex/label-groups/usage.d.ts +1 -1
- package/dist/convex/label-groups/usage.d.ts.map +1 -1
- package/dist/convex/label-groups/usage.js +2 -2
- package/dist/convex/label-groups/usage.js.map +1 -1
- package/dist/convex/label-translations.d.ts.map +1 -1
- package/dist/convex/label-translations.js +52 -0
- package/dist/convex/label-translations.js.map +1 -1
- package/dist/convex/labels.d.ts +23 -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/notifications.d.ts +77 -0
- package/dist/convex/notifications.d.ts.map +1 -1
- package/dist/convex/notifications.js +64 -13
- package/dist/convex/notifications.js.map +1 -1
- package/dist/convex/proof.d.ts +25 -0
- package/dist/convex/proof.d.ts.map +1 -1
- package/dist/convex/proof.js +39 -0
- package/dist/convex/proof.js.map +1 -1
- package/dist/convex/referral-rules.d.ts +0 -2
- package/dist/convex/referral-rules.d.ts.map +1 -1
- package/dist/convex/referral-rules.js +0 -2
- package/dist/convex/referral-rules.js.map +1 -1
- package/dist/convex/waitlist-rules.d.ts +1 -13
- package/dist/convex/waitlist-rules.d.ts.map +1 -1
- package/dist/convex/waitlist-rules.js +2 -14
- package/dist/convex/waitlist-rules.js.map +1 -1
- package/dist/devtools-client/index.html +1 -1
- package/dist/module.js +2 -2
- package/dist/module.json +1 -1
- package/dist/runtime/locales/de.json +47 -24
- package/dist/runtime/locales/en.json +47 -24
- package/dist/runtime/locales/es.json +47 -24
- package/dist/runtime/locales/fr.json +47 -24
- package/dist/runtime/locales/ru.json +47 -24
- package/dist/runtime/server/protection/gate.d.ts +4 -2
- package/dist/runtime/server/protection/gate.js +14 -4
- package/dist/runtime/vue/admin-client.d.ts +18 -0
- package/dist/runtime/vue/admin-client.js +32 -0
- package/dist/runtime/vue/auth-client.d.ts +16 -11
- package/dist/runtime/vue/auth-client.js +3 -1
- package/dist/runtime/vue/components/admin/AdminUsers.d.vue.ts +1 -1
- package/dist/runtime/vue/components/admin/AdminUsers.vue.d.ts +1 -1
- package/dist/runtime/vue/components/billing/BillingCheckoutLink.d.vue.ts +1 -1
- package/dist/runtime/vue/components/billing/BillingCheckoutLink.vue.d.ts +1 -1
- package/dist/runtime/vue/components/billing/CancelFlow.css +1 -1
- package/dist/runtime/vue/components/billing/CancelFlow.d.vue.ts +3 -0
- package/dist/runtime/vue/components/billing/CancelFlow.vue +10 -3
- package/dist/runtime/vue/components/billing/CancelFlow.vue.d.ts +3 -0
- package/dist/runtime/vue/components/billing/CancelFlowConfirm.d.vue.ts +3 -0
- package/dist/runtime/vue/components/billing/CancelFlowConfirm.vue +34 -0
- package/dist/runtime/vue/components/billing/CancelFlowConfirm.vue.d.ts +3 -0
- package/dist/runtime/vue/components/billing/CancelFlowQuestion.vue +2 -1
- package/dist/runtime/vue/components/billing/GiftSent.d.vue.ts +2 -2
- package/dist/runtime/vue/components/billing/GiftSent.vue.d.ts +2 -2
- package/dist/runtime/vue/components/billing/PricingPackCard.vue +6 -3
- package/dist/runtime/vue/components/billing/PricingPlanCard.vue +3 -1
- package/dist/runtime/vue/components/billing/PricingTable.d.vue.ts +2 -2
- package/dist/runtime/vue/components/billing/PricingTable.vue +3 -1
- package/dist/runtime/vue/components/billing/PricingTable.vue.d.ts +2 -2
- package/dist/runtime/vue/components/billing/UsageHistoryEvent.vue +3 -1
- package/dist/runtime/vue/components/billing/cancel-flow.d.ts +28 -7
- package/dist/runtime/vue/components/billing/cancel-flow.js +25 -2
- package/dist/runtime/vue/components/shell/NoticeLowCredits.vue +3 -1
- package/dist/runtime/vue/components/tokens.css +1 -1
- package/dist/runtime/vue/components/workspaces/WorkspaceCredits.vue +6 -3
- 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-auth.d.ts +13 -1
- package/dist/runtime/vue/composables/use-auth.js +4 -1
- package/dist/runtime/vue/composables/use-billing.d.ts +10 -2
- package/dist/runtime/vue/composables/use-credits.d.ts +3 -0
- package/dist/runtime/vue/composables/use-credits.js +1 -0
- package/dist/runtime/vue/composables/use-notifications.d.ts +5 -1
- package/dist/runtime/vue/composables/use-notifications.js +12 -4
- package/dist/runtime/vue/composables/use-webhook-log.d.ts +4 -2
- package/dist/runtime/vue/organization-client.d.ts +15 -0
- package/dist/runtime/vue/organization-client.js +65 -0
- package/dist/runtime/vue/parts.d.ts +2 -1
- package/dist/runtime/vue/plugins/checkout-return.d.ts +3 -2
- package/dist/runtime/vue/plugins/checkout-return.js +2 -4
- package/dist/runtime/vue/plugins/first-touch.js +2 -4
- package/dist/runtime/vue/utils/checkout-return.d.ts +9 -2
- package/dist/runtime/vue/utils/checkout-return.js +2 -1
- package/dist/runtime/vue/utils/every-page.d.ts +10 -0
- package/dist/runtime/vue/utils/every-page.js +6 -0
- package/dist/runtime/vue/utils/meter-unit.d.ts +14 -0
- package/dist/runtime/vue/utils/meter-unit.js +18 -0
- package/dist/shared/{nuxt-backend.2YoiKo8j.mjs → nuxt-backend.2m535CLS.mjs} +6 -2
- package/dist/shared/{nuxt-backend.CPq101Wi.mjs → nuxt-backend.DXEf0rrv.mjs} +1 -1
- package/dist/shared/{nuxt-backend.-uB5CGw-.mjs → nuxt-backend.Dm1NkY7v.mjs} +1 -1
- package/dist/shared/{nuxt-backend.OQMX-0U7.mjs → nuxt-backend.KEzfHO2K.mjs} +6 -3
- package/dist/shared/{nuxt-backend.S5C2b-4I.mjs → nuxt-backend.ikObmtHs.mjs} +2 -2
- package/package.json +2 -2
- package/skills/nuxt-backend/references/api.md +13 -3
- package/skills/nuxt-backend/references/surface.json +12 -0
- package/skills/nuxt-backend-auth/SKILL.md +2 -1
- package/skills/nuxt-backend-billing/SKILL.md +7 -0
- package/skills/nuxt-backend-billing/references/api.md +12 -2
- package/skills/nuxt-backend-data/SKILL.md +4 -1
- package/skills/nuxt-backend-email/SKILL.md +4 -0
- package/skills/nuxt-backend-email/references/api.md +1 -1
- package/skills/nuxt-backend-ui/SKILL.md +6 -5
- package/src/convex/account-data.ts +0 -5
- package/src/convex/catalog.ts +23 -0
- package/src/convex/client/better-auth-options.ts +11 -1
- package/src/convex/client/client-address.ts +37 -0
- package/src/convex/components/backend/_generated/component.ts +12 -0
- package/src/convex/components/backend/account.ts +7 -2
- package/src/convex/components/backend/adapter.ts +4 -1
- package/src/convex/components/backend/ai.ts +20 -54
- package/src/convex/components/backend/billing.ts +14 -33
- package/src/convex/components/backend/consents.ts +2 -1
- package/src/convex/components/backend/gifts.ts +11 -5
- package/src/convex/components/backend/lifecycle.ts +17 -12
- package/src/convex/components/backend/notifications.ts +22 -0
- package/src/convex/components/backend/referrals.ts +14 -16
- package/src/convex/components/backend/reports.ts +7 -7
- package/src/convex/components/backend/schema.ts +143 -161
- package/src/convex/components/backend/storage.ts +11 -10
- package/src/convex/components/backend/subscriptions.ts +7 -35
- package/src/convex/components/backend/webhooks.ts +1 -10
- package/src/convex/consent-rules.ts +0 -3
- package/src/convex/constants.ts +0 -1
- package/src/convex/email-templates.ts +0 -1
- package/src/convex/integrations/admin.ts +2 -1
- package/src/convex/integrations/ai/job-errors.ts +21 -0
- package/src/convex/integrations/ai/metering.ts +24 -10
- package/src/convex/integrations/ai/models.ts +3 -1
- package/src/convex/integrations/ai/moderation.ts +31 -2
- package/src/convex/integrations/ai/stream.ts +3 -11
- package/src/convex/integrations/billing/context.ts +1 -9
- package/src/convex/integrations/billing/customers.ts +28 -5
- package/src/convex/integrations/billing/free-plan.ts +20 -5
- package/src/convex/integrations/billing/functions.ts +17 -5
- package/src/convex/integrations/billing/gifts.ts +2 -2
- package/src/convex/integrations/billing/history.ts +2 -1
- package/src/convex/integrations/billing/lifecycle.ts +30 -3
- package/src/convex/integrations/billing/passes.ts +2 -4
- package/src/convex/integrations/billing/pricing.ts +14 -10
- package/src/convex/integrations/billing/purchase.ts +1 -2
- package/src/convex/integrations/billing/types/lifecycle.ts +13 -0
- package/src/convex/integrations/billing/types/options.ts +4 -1
- package/src/convex/integrations/billing/types/records.ts +7 -1
- package/src/convex/integrations/billing/types/surface.ts +3 -1
- package/src/convex/integrations/billing.ts +3 -2
- package/src/convex/integrations/email-preferences.ts +1 -1
- package/src/convex/integrations/email-sync.ts +44 -1
- package/src/convex/integrations/notifications.ts +65 -16
- package/src/convex/integrations/rate-limit.ts +6 -5
- package/src/convex/integrations/reports.ts +1 -1
- package/src/convex/integrations/webhooks.ts +1 -4
- package/src/convex/label-groups/cancelFlow.ts +5 -0
- package/src/convex/label-groups/credits.ts +17 -2
- package/src/convex/label-groups/notifications.ts +19 -15
- package/src/convex/label-groups/pricing.ts +8 -8
- package/src/convex/label-groups/settings.ts +4 -3
- package/src/convex/label-groups/usage.ts +2 -2
- package/src/convex/label-translations.ts +52 -0
- package/src/convex/log.ts +2 -0
- package/src/convex/notifications.ts +99 -13
- package/src/convex/proof.ts +43 -0
- package/src/convex/referral-rules.ts +0 -2
- package/src/convex/waitlist-rules.ts +2 -22
- package/src/runtime/vue/components/billing/CancelFlow.css +16 -0
- package/src/runtime/vue/components/billing/CancelFlow.vue +16 -6
- package/src/runtime/vue/components/billing/CancelFlowConfirm.vue +35 -0
- package/src/runtime/vue/components/billing/CancelFlowQuestion.vue +8 -2
- package/src/runtime/vue/components/billing/PricingPackCard.vue +6 -3
- package/src/runtime/vue/components/billing/PricingPlanCard.vue +3 -1
- package/src/runtime/vue/components/billing/PricingTable.vue +3 -1
- package/src/runtime/vue/components/billing/UsageHistoryEvent.vue +3 -1
- package/src/runtime/vue/components/shell/NoticeLowCredits.vue +3 -1
- package/src/runtime/vue/components/tokens.css +19 -15
- package/src/runtime/vue/components/workspaces/WorkspaceCredits.vue +6 -3
|
@@ -107,6 +107,12 @@ function storageIdOf(ctx: QueryCtx, id: string): Id<'_storage'> | null {
|
|
|
107
107
|
return ctx.db.system.normalizeId('_storage', id)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
/** A file's owner record by an id from the app, which may name no file of the component's. */
|
|
111
|
+
async function recordById(ctx: QueryCtx, id: string): Promise<Doc<'files'> | null> {
|
|
112
|
+
const storageId = storageIdOf(ctx, id)
|
|
113
|
+
return storageId ? await recordOf(ctx, storageId) : null
|
|
114
|
+
}
|
|
115
|
+
|
|
110
116
|
/** Delete a file's bytes (the original and the served copy), its record, and its count. */
|
|
111
117
|
async function deleteFile(ctx: MutationCtx, record: Doc<'files'>): Promise<void> {
|
|
112
118
|
for (const id of new Set([record.storageId, record.servedId])) {
|
|
@@ -361,8 +367,7 @@ export const release = mutation({
|
|
|
361
367
|
args: { storageId: v.string() },
|
|
362
368
|
returns: v.boolean(),
|
|
363
369
|
handler: async (ctx, { storageId: id }) => {
|
|
364
|
-
const
|
|
365
|
-
const record = storageId ? await recordOf(ctx, storageId) : null
|
|
370
|
+
const record = await recordById(ctx, id)
|
|
366
371
|
if (!record) return false
|
|
367
372
|
await deleteFile(ctx, record)
|
|
368
373
|
return true
|
|
@@ -397,8 +402,7 @@ export const url = query({
|
|
|
397
402
|
args: { storageId: v.string(), userId: v.optional(v.string()) },
|
|
398
403
|
returns: v.union(v.string(), v.null()),
|
|
399
404
|
handler: async (ctx, { storageId: id, userId }) => {
|
|
400
|
-
const
|
|
401
|
-
const record = storageId ? await recordOf(ctx, storageId) : null
|
|
405
|
+
const record = await recordById(ctx, id)
|
|
402
406
|
if (record?.status !== 'ready') return null
|
|
403
407
|
if (userId !== undefined && !await mayRead(ctx, record, userId)) return null
|
|
404
408
|
return ctx.storage.getUrl(record.servedId ?? record.storageId)
|
|
@@ -410,8 +414,7 @@ export const served = query({
|
|
|
410
414
|
args: { storageId: v.string() },
|
|
411
415
|
returns: v.union(v.object({ url: v.string(), contentType: v.string(), size: v.number() }), v.null()),
|
|
412
416
|
handler: async (ctx, { storageId: id }) => {
|
|
413
|
-
const
|
|
414
|
-
const record = storageId ? await recordOf(ctx, storageId) : null
|
|
417
|
+
const record = await recordById(ctx, id)
|
|
415
418
|
if (record?.status !== 'ready') return null
|
|
416
419
|
const url = await ctx.storage.getUrl(record.servedId ?? record.storageId)
|
|
417
420
|
return url ? { url, contentType: record.contentType ?? 'application/octet-stream', size: record.size } : null
|
|
@@ -423,8 +426,7 @@ export const isReady = query({
|
|
|
423
426
|
args: { storageId: v.string() },
|
|
424
427
|
returns: v.boolean(),
|
|
425
428
|
handler: async (ctx, { storageId: id }) => {
|
|
426
|
-
const
|
|
427
|
-
const record = storageId ? await recordOf(ctx, storageId) : null
|
|
429
|
+
const record = await recordById(ctx, id)
|
|
428
430
|
return record?.status === 'ready'
|
|
429
431
|
},
|
|
430
432
|
})
|
|
@@ -473,8 +475,7 @@ export const removeCopies = mutation({
|
|
|
473
475
|
const decision = decisionId ? ctx.db.normalizeId('reportDecisions', decisionId) ?? undefined : undefined
|
|
474
476
|
let removed = 0
|
|
475
477
|
for (const id of storageIds.slice(0, 20)) {
|
|
476
|
-
const
|
|
477
|
-
const record = storageId ? await recordOf(ctx, storageId) : null
|
|
478
|
+
const record = await recordById(ctx, id)
|
|
478
479
|
if (!record) {
|
|
479
480
|
logBackend('warn', 'reports.copies_unmatched', 'A removed intimate image names a file setupStorage does not keep: its identical copies were not looked for.')
|
|
480
481
|
continue
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v } from 'convex/values'
|
|
2
2
|
import { mutation, query } from './_generated/server.js'
|
|
3
|
-
import { vSaveOfferTerms } from './schema.js'
|
|
3
|
+
import { vRenewalConsent, vSaveOfferTerms } from './schema.js'
|
|
4
4
|
|
|
5
5
|
// The billing lifecycle's own records (LIFECYCLE): the cancel flow's save
|
|
6
6
|
// offers, the renewal consent proof, what was sent once (an annual reminder,
|
|
@@ -11,6 +11,9 @@ import { vSaveOfferTerms } from './schema.js'
|
|
|
11
11
|
/** How long an offer stays open after the cancel flow made it: the flow is one sitting. */
|
|
12
12
|
export const SAVE_OFFER_OPEN_MS = 60 * 60 * 1000
|
|
13
13
|
|
|
14
|
+
/** A confirmed consent proof, as an administrator reads it. */
|
|
15
|
+
const vConsentProof = vRenewalConsent.omit('checkoutId', 'entityId', 'createdAt', 'consentedAt').extend({ consentedAt: v.number() })
|
|
16
|
+
|
|
14
17
|
const vOfferRow = v.object({
|
|
15
18
|
id: v.string(),
|
|
16
19
|
entityId: v.string(),
|
|
@@ -97,17 +100,7 @@ export const releaseOffer = mutation({
|
|
|
97
100
|
|
|
98
101
|
/** The renewal consent a checkout showed, kept as it is made and confirmed when its subscription arrives. */
|
|
99
102
|
export const recordConsent = mutation({
|
|
100
|
-
args:
|
|
101
|
-
checkoutId: v.string(),
|
|
102
|
-
entityId: v.string(),
|
|
103
|
-
userId: v.optional(v.string()),
|
|
104
|
-
productId: v.string(),
|
|
105
|
-
amount: v.number(),
|
|
106
|
-
currency: v.string(),
|
|
107
|
-
interval: v.string(),
|
|
108
|
-
intervalCount: v.number(),
|
|
109
|
-
termsVersion: v.optional(v.string()),
|
|
110
|
-
},
|
|
103
|
+
args: vRenewalConsent.omit('createdAt', 'subscriptionId', 'consentedAt'),
|
|
111
104
|
returns: v.null(),
|
|
112
105
|
handler: async (ctx, args) => {
|
|
113
106
|
const existing = await ctx.db.query('billingRenewalConsents').withIndex('checkoutId', q => q.eq('checkoutId', args.checkoutId)).first()
|
|
@@ -146,17 +139,7 @@ export const purchasedAt = query({
|
|
|
146
139
|
/** A billing entity's confirmed consent proofs, newest first: what an administrator shows a regulator. */
|
|
147
140
|
export const consents = query({
|
|
148
141
|
args: { entityId: v.string() },
|
|
149
|
-
returns: v.array(
|
|
150
|
-
subscriptionId: v.optional(v.string()),
|
|
151
|
-
productId: v.string(),
|
|
152
|
-
amount: v.number(),
|
|
153
|
-
currency: v.string(),
|
|
154
|
-
interval: v.string(),
|
|
155
|
-
intervalCount: v.number(),
|
|
156
|
-
termsVersion: v.optional(v.string()),
|
|
157
|
-
userId: v.optional(v.string()),
|
|
158
|
-
consentedAt: v.number(),
|
|
159
|
-
})),
|
|
142
|
+
returns: v.array(vConsentProof),
|
|
160
143
|
handler: async (ctx, { entityId }) => {
|
|
161
144
|
const rows = await ctx.db.query('billingRenewalConsents').withIndex('entityId', q => q.eq('entityId', entityId)).order('desc').take(100)
|
|
162
145
|
return rows.flatMap(({ subscriptionId, productId, amount, currency, interval, intervalCount, termsVersion, userId, consentedAt }) =>
|
|
@@ -230,18 +213,7 @@ export const lifecycleConsole = query({
|
|
|
230
213
|
returns: v.object({
|
|
231
214
|
saveOffers: v.array(vOfferRow),
|
|
232
215
|
withdrawals: v.array(v.object({ entityId: v.string(), subscriptionId: v.string(), userId: v.string(), productId: v.string(), at: v.number() })),
|
|
233
|
-
consents: v.array(v.
|
|
234
|
-
entityId: v.string(),
|
|
235
|
-
subscriptionId: v.optional(v.string()),
|
|
236
|
-
productId: v.string(),
|
|
237
|
-
amount: v.number(),
|
|
238
|
-
currency: v.string(),
|
|
239
|
-
interval: v.string(),
|
|
240
|
-
intervalCount: v.number(),
|
|
241
|
-
termsVersion: v.optional(v.string()),
|
|
242
|
-
userId: v.optional(v.string()),
|
|
243
|
-
consentedAt: v.number(),
|
|
244
|
-
})),
|
|
216
|
+
consents: v.array(vConsentProof.extend({ entityId: v.string() })),
|
|
245
217
|
}),
|
|
246
218
|
handler: async (ctx, { entityId }) => {
|
|
247
219
|
const offers = entityId === undefined
|
|
@@ -2,6 +2,7 @@ import { v } from 'convex/values'
|
|
|
2
2
|
import { internal } from './_generated/api.js'
|
|
3
3
|
import type { Doc } from './_generated/dataModel.js'
|
|
4
4
|
import { internalMutation, type MutationCtx, mutation, query, type QueryCtx } from './_generated/server.js'
|
|
5
|
+
import { vDeliveryOutcome } from './schema.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Webhook delivery log — never a source of truth. Every request on
|
|
@@ -50,16 +51,6 @@ const NOTE_LIMIT = 500
|
|
|
50
51
|
/** Rows `listRecent` serves when no limit is given. */
|
|
51
52
|
const DEFAULT_FEED_SIZE = 50
|
|
52
53
|
|
|
53
|
-
export const vDeliveryOutcome = v.union(
|
|
54
|
-
v.literal('ok'),
|
|
55
|
-
v.literal('invalid_signature'),
|
|
56
|
-
v.literal('unknown_type'),
|
|
57
|
-
v.literal('handler_error'),
|
|
58
|
-
v.literal('duplicate'),
|
|
59
|
-
v.literal('oversized'),
|
|
60
|
-
v.literal('missing_secret'),
|
|
61
|
-
)
|
|
62
|
-
|
|
63
54
|
type DeliveryOutcome = Doc<'webhookDeliveries'>['outcome']
|
|
64
55
|
type TalliedOutcome = Doc<'webhookTallies'>['outcome']
|
|
65
56
|
|
|
@@ -66,9 +66,6 @@ export function requiredKinds(consents: ConsentDeclarations | undefined): string
|
|
|
66
66
|
return Object.entries(consents ?? {}).filter(([, declaration]) => declaration.required).map(([kind]) => kind)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
/** Where a decision came from, kept with each row. */
|
|
70
|
-
export type ConsentSource = 'sign-up' | 'prompt' | 'settings' | 'waitlist' | 'topic'
|
|
71
|
-
|
|
72
69
|
/** A kind's latest decision of one person. */
|
|
73
70
|
export interface ConsentDecision {
|
|
74
71
|
version: string
|
package/src/convex/constants.ts
CHANGED
|
@@ -67,7 +67,6 @@ export const RESERVED_CLAIMS: readonly string[] = [
|
|
|
67
67
|
* call, and `getBillingAccess` reports it for `useBilling().canManage`.
|
|
68
68
|
*/
|
|
69
69
|
export const BILLING_MANAGER_ROLES: readonly string[] = ['owner', 'admin']
|
|
70
|
-
export const COMPONENT_AUTH_ROUTE = '/'
|
|
71
70
|
/**
|
|
72
71
|
* App page that handles workspace-invitation accept links
|
|
73
72
|
* (`{SITE_URL}{path}?id=<invitationId>`). The Nuxt module registers this page
|
|
@@ -37,7 +37,6 @@ import { baseLanguage, matchLocale, normalizeLocale, textDirection } from './loc
|
|
|
37
37
|
// Convex mutation.
|
|
38
38
|
|
|
39
39
|
export { escapeHtml }
|
|
40
|
-
export { describeOrigin, linkBlocks } from './email-helpers.js'
|
|
41
40
|
export type { EmailBlock }
|
|
42
41
|
export type { EmailColors, EmailFonts, EmailScheme, EmailTheme, ResolvedEmailTheme } from './email-theme.js'
|
|
43
42
|
|
|
@@ -8,7 +8,8 @@ import { createReports, type ReportsApi, type ReportsOptions } from './reports.j
|
|
|
8
8
|
import { type BackendPaths, resolveBackendPaths } from '../paths.js'
|
|
9
9
|
|
|
10
10
|
export { setupWebhooks } from './webhooks.js'
|
|
11
|
-
export type { SetupWebhooksOptions, WebhookDeliveryRow, WebhookOutcome, WebhookReplay, Webhooks, WebhooksApi, WebhooksComponents
|
|
11
|
+
export type { SetupWebhooksOptions, WebhookDeliveryRow, WebhookOutcome, WebhookReplay, Webhooks, WebhooksApi, WebhooksComponents } from './webhooks.js'
|
|
12
|
+
export type { WebhookService } from './webhook-guard.js'
|
|
12
13
|
export type { FunnelBreakdownRow, FunnelCohort, FunnelDimension, FunnelReport, FunnelStep, PersonStep } from '../funnel-rules.js'
|
|
13
14
|
|
|
14
15
|
export type { AppealView, DescribedSubject, NoticeInput, ReportAppeal, ReportedSubject, ReportNotice, ReportReason, ReportsApi, ReportsConsole, ReportsOptions, ReportSubject } from './reports.js'
|
|
@@ -71,6 +71,27 @@ export function retryAfterOf(error: unknown, now = Date.now()): number | undefin
|
|
|
71
71
|
return undefined
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* The provider's own words behind an error, when a gateway answered a
|
|
76
|
+
* failed call with a 200 whose body is an `error` object (the Convex AI
|
|
77
|
+
* Gateway passing on an upstream refusal) or with a body the SDK could not
|
|
78
|
+
* read as an answer: the AI SDK then reports only "Invalid JSON response".
|
|
79
|
+
*/
|
|
80
|
+
export function upstreamErrorOf(error: unknown): string | undefined {
|
|
81
|
+
for (const link of chainOf(error)) {
|
|
82
|
+
if (typeof link.responseBody !== 'string') continue
|
|
83
|
+
try {
|
|
84
|
+
const body = JSON.parse(link.responseBody) as { error?: { message?: unknown } | string }
|
|
85
|
+
const message = typeof body?.error === 'string' ? body.error : body?.error?.message
|
|
86
|
+
if (typeof message === 'string' && message.trim()) return message.trim().slice(0, 500)
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// A body that is not JSON says nothing more than the error does.
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return undefined
|
|
93
|
+
}
|
|
94
|
+
|
|
74
95
|
/** Whether any text of the chain (name, message, type, body) says `pattern`. */
|
|
75
96
|
const says = (chain: readonly ErrorLike[], pattern: RegExp): boolean =>
|
|
76
97
|
chain.some(error => [error.name, error.message, error.type, error.responseBody].some(text => typeof text === 'string' && pattern.test(text)))
|
|
@@ -330,6 +330,28 @@ export function createMetering({ config, billing, rateLimiter, cache, refuseAi,
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
+
/**
|
|
334
|
+
* `prepare` for one call of an action or a stream: its cost estimated
|
|
335
|
+
* from the call's args, the model it must reach, and what the classifier
|
|
336
|
+
* checks.
|
|
337
|
+
*/
|
|
338
|
+
const prepareCall = async (
|
|
339
|
+
ctx: GenericActionCtx<GenericDataModel>,
|
|
340
|
+
definition: { meter: string | false, limit?: string | false, cost?: unknown, allowOverage?: boolean, model?: AiModel, moderate?: (args: never) => ModerationInput },
|
|
341
|
+
args: Record<string, unknown>,
|
|
342
|
+
): Promise<{ cost: number, usage: MeteredUsage, reservation: SpendReservation }> => {
|
|
343
|
+
const cost = estimateCost(definition.cost, args)
|
|
344
|
+
const { usage, reservation } = await prepare(ctx as never, {
|
|
345
|
+
meter: definition.meter,
|
|
346
|
+
limit: definition.limit,
|
|
347
|
+
cost,
|
|
348
|
+
allowOverage: definition.allowOverage,
|
|
349
|
+
model: requiredModel(definition),
|
|
350
|
+
...(definition.moderate ? { moderate: definition.moderate(args as never) } : {}),
|
|
351
|
+
})
|
|
352
|
+
return { cost, usage, reservation }
|
|
353
|
+
}
|
|
354
|
+
|
|
333
355
|
const meteredAction: Ai['meteredAction'] = (definition) => {
|
|
334
356
|
checkDefinition(definition, 'ai.meteredAction')
|
|
335
357
|
return actionGeneric({
|
|
@@ -337,15 +359,7 @@ export function createMetering({ config, billing, rateLimiter, cache, refuseAi,
|
|
|
337
359
|
// Loose internal typing: precise arg types live on MeteredActionConfig;
|
|
338
360
|
// the open `Args` generic fights Convex's conditional args-array types.
|
|
339
361
|
handler: (async (ctx: GenericActionCtx<GenericDataModel>, args: Record<string, unknown>) => {
|
|
340
|
-
const
|
|
341
|
-
const { usage, reservation } = await prepare(ctx as never, {
|
|
342
|
-
meter: definition.meter,
|
|
343
|
-
limit: definition.limit,
|
|
344
|
-
cost,
|
|
345
|
-
allowOverage: definition.allowOverage,
|
|
346
|
-
model: requiredModel(definition),
|
|
347
|
-
...(definition.moderate ? { moderate: definition.moderate(args as never) } : {}),
|
|
348
|
-
})
|
|
362
|
+
const { usage, reservation } = await prepareCall(ctx, definition, args)
|
|
349
363
|
const metered = definition.meter !== false
|
|
350
364
|
const calls: ModelCall[] = []
|
|
351
365
|
const storeImage = imageStore(ctx, config.provenance, requests as unknown as ProvenanceRefs, { owner: usage.entityId, userId: usage.userId, calls, model: modelIdOf(definition.model ?? config.model) })
|
|
@@ -388,7 +402,7 @@ export function createMetering({ config, billing, rateLimiter, cache, refuseAi,
|
|
|
388
402
|
})
|
|
389
403
|
}
|
|
390
404
|
|
|
391
|
-
return { prepare, closeSpend, armRelease, meteredAction, checkDefinition, requiredModel, modelPicker }
|
|
405
|
+
return { prepare, prepareCall, closeSpend, armRelease, meteredAction, checkDefinition, requiredModel, modelPicker }
|
|
392
406
|
}
|
|
393
407
|
|
|
394
408
|
export type AiMetering = ReturnType<typeof createMetering>
|
|
@@ -3,6 +3,7 @@ import { getServiceToken } from 'convex/server'
|
|
|
3
3
|
import { backendError, getBackendError } from '../../errors.js'
|
|
4
4
|
import { logBackend } from '../../log.js'
|
|
5
5
|
import type { AiModel, InferenceRegion, MeteredModel, ModelStatus } from './config.js'
|
|
6
|
+
import { upstreamErrorOf } from './job-errors.js'
|
|
6
7
|
import { MODEL_ID } from './model-id.js'
|
|
7
8
|
import type { TokenUsage } from './pricing.js'
|
|
8
9
|
|
|
@@ -460,6 +461,7 @@ export function failedRun(calls: readonly ModelCall[]): Error | undefined {
|
|
|
460
461
|
if (calls.length === 0 || calls.some(call => call.state === 'finished' || call.state === 'open')) return undefined
|
|
461
462
|
const { model, error } = calls[0]!
|
|
462
463
|
if (getBackendError(error)) return error as Error
|
|
463
|
-
|
|
464
|
+
const upstream = upstreamErrorOf(error)
|
|
465
|
+
logBackend('error', 'ai.model_failed', `Every model call this run made failed (${model} first${upstream ? `: ${upstream}` : ''}): the run is refused and nothing is charged.`, error)
|
|
464
466
|
return backendError('unavailable', { service: 'ai', reason: 'provider_refused' }, `[nuxt-backend] The model call to ${model} failed. Try again shortly.`)
|
|
465
467
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { FunctionReference, GenericActionCtx, GenericDataModel } from 'convex/server'
|
|
2
|
-
import { backendError } from '../../errors.js'
|
|
2
|
+
import { backendError, getBackendError } from '../../errors.js'
|
|
3
3
|
import { sniffContentType } from '../../files.js'
|
|
4
4
|
import { logBackend } from '../../log.js'
|
|
5
5
|
import type { AiModel, InferenceRegion } from './config.js'
|
|
6
6
|
import type { RecordCost } from './costs.js'
|
|
7
|
+
import { upstreamErrorOf } from './job-errors.js'
|
|
7
8
|
import { loadSdk, meteredModel, modelIdOf, type ModelCall, requireModelId, routeModel } from './models.js'
|
|
8
9
|
|
|
9
10
|
// Content safety's check (`ai.moderate`, `ai.requireSafe`, `moderate` on a
|
|
@@ -52,6 +53,17 @@ export interface ModerationConfig {
|
|
|
52
53
|
/** The most images one check reads. */
|
|
53
54
|
export const MODERATION_IMAGES_MAX = 8
|
|
54
55
|
|
|
56
|
+
/** How long a check waits for its classifier: past it, the content is refused as unchecked, and the caller's action goes on. */
|
|
57
|
+
export const MODERATION_TIMEOUT_MS = 30_000
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The words images checked alone go with. Llama Guard 4 behind the Convex AI
|
|
61
|
+
* Gateway refuses a message of images with no text (an upstream `400`,
|
|
62
|
+
* passed on as a `200` with an `error` body), and reads the same images
|
|
63
|
+
* with any text beside them.
|
|
64
|
+
*/
|
|
65
|
+
const IMAGES_ALONE = 'An image to check.'
|
|
66
|
+
|
|
55
67
|
/** The hazard categories a policy-following classifier is given: the MLCommons taxonomy Llama Guard 4 is trained on. */
|
|
56
68
|
const CATEGORIES = [
|
|
57
69
|
'S1: Violent crimes',
|
|
@@ -118,6 +130,14 @@ interface StorageBytesRef {
|
|
|
118
130
|
|
|
119
131
|
let imagesUncheckedNoticed = false
|
|
120
132
|
|
|
133
|
+
/** A classifier call that failed, as the caller reads it: a refusal of the catalog as it is (a model with no route, AI paused), anything else (a timeout, the provider's error) `unavailable` and logged. */
|
|
134
|
+
function checkFailure(id: string, error: unknown): Error {
|
|
135
|
+
if (getBackendError(error)) return error as Error
|
|
136
|
+
const upstream = upstreamErrorOf(error)
|
|
137
|
+
logBackend('error', 'ai.moderation_failed', `The moderation model ${id} did not answer${upstream ? ` (${upstream})` : ''}: the content is refused as unchecked.`, error)
|
|
138
|
+
return backendError('unavailable', { service: 'ai', reason: 'provider_refused' }, `[nuxt-backend] The moderation model ${id} did not answer. Try again shortly.`)
|
|
139
|
+
}
|
|
140
|
+
|
|
121
141
|
/** Refuse a check with images its classifier cannot read: passing them unread would call them safe. */
|
|
122
142
|
function refuseUnreadImages(id: string): never {
|
|
123
143
|
if (!imagesUncheckedNoticed) {
|
|
@@ -181,8 +201,9 @@ export function createModeration(config: { moderation?: ModerationConfig, infere
|
|
|
181
201
|
if (!text && imageIds.length === 0) return { flagged: false, categories: [] }
|
|
182
202
|
const parts = await imageParts(ctx, imageIds)
|
|
183
203
|
const llamaGuard = isLlamaGuard(id)
|
|
204
|
+
const words = text || IMAGES_ALONE
|
|
184
205
|
const content = [
|
|
185
|
-
|
|
206
|
+
{ type: 'text' as const, text: llamaGuard ? words : `<content>\n${words}\n</content>` },
|
|
186
207
|
...parts,
|
|
187
208
|
]
|
|
188
209
|
const sdk = await loadSdk()
|
|
@@ -191,15 +212,23 @@ export function createModeration(config: { moderation?: ModerationConfig, infere
|
|
|
191
212
|
const calls: ModelCall[] = []
|
|
192
213
|
const classifier = meteredModel(routeModel(model, undefined, config.inferenceRegion), calls, config.inferenceRegion)
|
|
193
214
|
let result: Awaited<ReturnType<typeof sdk.generateText>>
|
|
215
|
+
// A gateway that hangs must not hold the caller's action until it times out.
|
|
216
|
+
const deadline = new AbortController()
|
|
217
|
+
const timer = setTimeout(() => deadline.abort(new Error(`The moderation model ${id} did not answer within ${MODERATION_TIMEOUT_MS / 1000} s.`)), MODERATION_TIMEOUT_MS)
|
|
194
218
|
try {
|
|
195
219
|
result = await sdk.generateText({
|
|
196
220
|
model: classifier,
|
|
197
221
|
...(llamaGuard ? {} : { system: POLICY }),
|
|
198
222
|
messages: [{ role: 'user', content }],
|
|
199
223
|
...answerBudget(llamaGuard),
|
|
224
|
+
abortSignal: deadline.signal,
|
|
200
225
|
})
|
|
201
226
|
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
throw checkFailure(id, error)
|
|
229
|
+
}
|
|
202
230
|
finally {
|
|
231
|
+
clearTimeout(timer)
|
|
203
232
|
const identity = await ctx.auth?.getUserIdentity()
|
|
204
233
|
await recordCost?.(ctx, { ...(identity ? { userId: identity.subject } : {}), owner: 'app' }, calls)
|
|
205
234
|
}
|
|
@@ -6,7 +6,7 @@ import type { Ai, MeteredStreamConfig, MeteredUsage } from './config.js'
|
|
|
6
6
|
import type { AiContext } from './context.js'
|
|
7
7
|
import type { AiMetering } from './metering.js'
|
|
8
8
|
import { failedRun, type ModelCall } from './models.js'
|
|
9
|
-
import {
|
|
9
|
+
import { finalizeCost } from './pricing.js'
|
|
10
10
|
import { logBackend } from '../../log.js'
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -16,7 +16,7 @@ import { logBackend } from '../../log.js'
|
|
|
16
16
|
*/
|
|
17
17
|
export function createStreams(
|
|
18
18
|
{ billing, pts, requests, corsOrigin, streamRegistry, recordCost }: AiContext,
|
|
19
|
-
{
|
|
19
|
+
{ prepareCall, closeSpend, armRelease, checkDefinition, modelPicker }: AiMetering,
|
|
20
20
|
): Pick<Ai, 'stream' | 'httpHandler'> {
|
|
21
21
|
const stream: Ai['stream'] = (definition) => {
|
|
22
22
|
checkDefinition(definition, 'ai.stream')
|
|
@@ -28,15 +28,7 @@ export function createStreams(
|
|
|
28
28
|
const start = actionGeneric({
|
|
29
29
|
args: definition.args,
|
|
30
30
|
handler: (async (ctx: GenericActionCtx<GenericDataModel>, args: Record<string, unknown>) => {
|
|
31
|
-
const cost =
|
|
32
|
-
const { usage, reservation } = await prepare(ctx as never, {
|
|
33
|
-
meter: definition.meter,
|
|
34
|
-
limit: definition.limit,
|
|
35
|
-
cost,
|
|
36
|
-
allowOverage: definition.allowOverage,
|
|
37
|
-
model: requiredModel(definition),
|
|
38
|
-
...(definition.moderate ? { moderate: definition.moderate(args as never) } : {}),
|
|
39
|
-
})
|
|
31
|
+
const { cost, usage, reservation } = await prepareCall(ctx, definition, args)
|
|
40
32
|
const streamId = await pts.createStream(ctx as never)
|
|
41
33
|
await ctx.runMutation(requests.createRequest, {
|
|
42
34
|
streamId,
|
|
@@ -8,19 +8,11 @@ import { syncProviderProducts } from './provider-events.js'
|
|
|
8
8
|
import type { ProviderCtx, RunQueryCtx, RunWriteCtx } from './types/base.js'
|
|
9
9
|
import type { BillingCatalogIds, CreditMeterConfig, SpendCreditsEvent } from './types/records.js'
|
|
10
10
|
import type { BillingAccessRule, BillingComponents, BillingEntity, BillingEntityCtx, ProviderLibRefs, SetupBillingConfig } from './types/setup.js'
|
|
11
|
-
import { backendEnvironment } from '../../delivery.js'
|
|
11
|
+
import { backendEnvironment, readEnv } from '../../delivery.js'
|
|
12
12
|
import { billingEnvironment } from '../../environment.js'
|
|
13
13
|
import { backendError, getBackendError } from '../../errors.js'
|
|
14
14
|
import { logBackend } from '../../log.js'
|
|
15
15
|
|
|
16
|
-
type EnvHost = typeof globalThis & {
|
|
17
|
-
process?: { env?: Record<string, string | undefined> }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function readEnv(name: string) {
|
|
21
|
-
return (globalThis as EnvHost).process?.env?.[name]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
16
|
/** The refusals that say who the caller is, which a resolver of the app's own may answer with. */
|
|
25
17
|
const CALLER_REFUSALS = new Set(['unauthenticated', 'forbidden', 'no_workspace'])
|
|
26
18
|
|
|
@@ -35,12 +35,24 @@ const EMAIL_TAKEN = 'Your email already pays for another account. Check out with
|
|
|
35
35
|
/** What a checkout says for an entity the component maps onto a customer another entity is keyed to. */
|
|
36
36
|
const MAPPING_TAKEN = 'This billing account is tied to another account\'s billing profile, from before billing gave each its own. Ask the app\'s operator to reset it.'
|
|
37
37
|
|
|
38
|
+
/** What a billing call says for an entity the component maps onto a customer the provider does not know. */
|
|
39
|
+
const MAPPING_STALE = 'Billing for this account points at a billing profile the provider no longer has, from another billing organization. Ask the app\'s operator to reset it.'
|
|
40
|
+
|
|
38
41
|
/**
|
|
39
42
|
* How long a checkout that may start the owner's trial holds it: a provider
|
|
40
43
|
* checkout session expires within it, so a hold this old was abandoned.
|
|
41
44
|
*/
|
|
42
45
|
const TRIAL_HOLD_MS = 60 * 60 * 1000
|
|
43
46
|
|
|
47
|
+
/** The refusals of a mapping the package will not use, as `code/reason`: keyed to another entity, or unknown to the provider. */
|
|
48
|
+
const UNUSABLE_MAPPINGS = new Set(['forbidden/customer_taken', 'unavailable/customer_unknown'])
|
|
49
|
+
|
|
50
|
+
/** Whether an error refuses a mapping the package will not use. */
|
|
51
|
+
function isUnusableMapping(error: unknown): boolean {
|
|
52
|
+
const refusal = getBackendError(error)
|
|
53
|
+
return UNUSABLE_MAPPINGS.has(`${refusal?.code}/${(refusal?.data as { reason?: string } | undefined)?.reason}`)
|
|
54
|
+
}
|
|
55
|
+
|
|
44
56
|
/** A provider refusal of a create that another request may have won: a 4xx other than "not found". */
|
|
45
57
|
function isConflict(error: unknown): boolean {
|
|
46
58
|
const status = (typeof error === 'object' && error !== null ? (error as { statusCode?: unknown }).statusCode : undefined)
|
|
@@ -192,10 +204,20 @@ export function createCustomers(
|
|
|
192
204
|
* created before 0.2 carries no external id, and every live read goes by
|
|
193
205
|
* it. One already keyed to another entity was shared between the two by
|
|
194
206
|
* the old email lookup, and is refused (`forbidden`, reason
|
|
195
|
-
* `customer_taken`) until the operator resets it.
|
|
207
|
+
* `customer_taken`) until the operator resets it. One the provider does
|
|
208
|
+
* not know is a mapping from another organization, made before
|
|
209
|
+
* `BILLING_ACCESS_TOKEN` moved: the synced subscriptions are that
|
|
210
|
+
* organization's too, and the provider's component has no way to forget a
|
|
211
|
+
* mapping, so it is refused (`unavailable`, reason `customer_unknown`)
|
|
212
|
+
* until the operator resets the billing data.
|
|
196
213
|
*/
|
|
197
214
|
const keyMapped = async (customerId: string, entityId: string, operation: string): Promise<string> => {
|
|
198
|
-
const
|
|
215
|
+
const found = await customersGet(provider.polar, { id: customerId })
|
|
216
|
+
if (!found.ok && isProviderNotFound(found.error)) {
|
|
217
|
+
logBackend('error', 'billing.customer_mapping_stale', 'A billing entity is mapped onto a customer the billing provider does not know: BILLING_ACCESS_TOKEN names another organization than the one the mapping was made in. It is refused until the deployment\'s billing data is reset.')
|
|
218
|
+
throw backendError('unavailable', { service: 'billing', reason: 'customer_unknown', message: MAPPING_STALE }, MAPPING_STALE)
|
|
219
|
+
}
|
|
220
|
+
const customer = unwrapProvider(found, operation)
|
|
199
221
|
if (customer.externalId === entityId) return customerId
|
|
200
222
|
if (customer.externalId) {
|
|
201
223
|
logBackend('error', 'billing.customer_mapping_shared', 'A billing entity is mapped onto a customer keyed to another entity; it is refused until the deployment\'s billing data is reset.')
|
|
@@ -211,8 +233,9 @@ export function createCustomers(
|
|
|
211
233
|
/**
|
|
212
234
|
* Whether an entity has a customer its live reads find by its id: the one
|
|
213
235
|
* the component maps it to, keyed now when it predates 0.2. `false` when
|
|
214
|
-
* it has none,
|
|
215
|
-
* the old email lookup), so a read shows nothing of another entity's
|
|
236
|
+
* it has none, when that customer is keyed to another entity (shared by
|
|
237
|
+
* the old email lookup), so a read shows nothing of another entity's, or
|
|
238
|
+
* when the provider does not know it (a mapping of another organization).
|
|
216
239
|
*/
|
|
217
240
|
const keyedCustomer = async (ctx: RunQueryCtx, entityId: string, operation: string): Promise<boolean> => {
|
|
218
241
|
const mapped = await mappedCustomer(ctx, entityId)
|
|
@@ -222,7 +245,7 @@ export function createCustomers(
|
|
|
222
245
|
return true
|
|
223
246
|
}
|
|
224
247
|
catch (error) {
|
|
225
|
-
if (
|
|
248
|
+
if (isUnusableMapping(error)) return false
|
|
226
249
|
throw error
|
|
227
250
|
}
|
|
228
251
|
}
|
|
@@ -32,8 +32,24 @@ const START_RETRIES = { maxAttempts: 5, initialBackoffMs: 2000, base: 2 }
|
|
|
32
32
|
/** A context that can queue work: a mutation's or an action's. */
|
|
33
33
|
export type QueueCtx = RunWriteCtx & { scheduler: Scheduler }
|
|
34
34
|
|
|
35
|
+
/** The refusals a start stops at, as `code/reason`, and the outcome each answers. */
|
|
36
|
+
const START_STOPS = new Map<string, 'customer_taken' | 'customer_unknown'>([['forbidden/customer_taken', 'customer_taken'], ['unavailable/customer_unknown', 'customer_unknown']])
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Where a start stops when its customer is refused: an account whose email
|
|
40
|
+
* another account's customer holds, or a mapping of another organization,
|
|
41
|
+
* neither of which a retry heals. `null` for a failure the workpool retries.
|
|
42
|
+
*/
|
|
43
|
+
function refusedStart(error: unknown): 'customer_taken' | 'customer_unknown' | null {
|
|
44
|
+
const refusal = getBackendError(error)
|
|
45
|
+
const outcome = START_STOPS.get(`${refusal?.code}/${(refusal?.data as { reason?: string } | undefined)?.reason}`) ?? null
|
|
46
|
+
// A stale mapping was logged where it was refused, as `billing.customer_mapping_stale`.
|
|
47
|
+
if (outcome === 'customer_taken') logBackend('warn', 'billing.free_plan_customer_taken', 'An account was not put on the free plan: its email belongs to another account\'s billing customer at the provider.')
|
|
48
|
+
return outcome
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
/** What one start did, as the internal action answers it. */
|
|
36
|
-
export type FreePlanStart = 'started' | 'subscribed' | 'gone' | 'not_billed' | 'customer_taken' | 'no_plan' | 'not_configured'
|
|
52
|
+
export type FreePlanStart = 'started' | 'subscribed' | 'gone' | 'not_billed' | 'customer_taken' | 'customer_unknown' | 'no_plan' | 'not_configured'
|
|
37
53
|
|
|
38
54
|
/** The kind of billing entity the auth layer made: one billing does not bill is no entity of it. */
|
|
39
55
|
export type CreatedEntityKind = 'workspace' | 'user'
|
|
@@ -162,10 +178,9 @@ export function createFreePlan(
|
|
|
162
178
|
await ensureCustomer(ctx, found.entity, found.profile, 'free plan', found.account)
|
|
163
179
|
}
|
|
164
180
|
catch (error) {
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
return 'customer_taken'
|
|
181
|
+
const outcome = refusedStart(error)
|
|
182
|
+
if (!outcome) throw error
|
|
183
|
+
return outcome
|
|
169
184
|
}
|
|
170
185
|
if (await holdsProviderSubscription(entityId)) return 'subscribed'
|
|
171
186
|
// Its first subscription ever: none was synced for it, ended or not.
|
|
@@ -39,7 +39,7 @@ const LIVE_SUBSCRIPTION_STATUSES = new Set(['active', 'trialing', 'past_due', 'p
|
|
|
39
39
|
|
|
40
40
|
/** The registered queries and actions `setupBilling` hands the app in `billing.api`. */
|
|
41
41
|
export function createBillingFunctions(
|
|
42
|
-
{ components, config, products, meterNameById, provider, cache, allowedEntity, requireEntity, throttle, requireAdmin, requireProviderAccess, syncProducts: syncProductsTable }: BillingContext,
|
|
42
|
+
{ components, config, products, creditMeters, meterNameById, provider, cache, allowedEntity, requireEntity, throttle, requireAdmin, requireProviderAccess, syncProducts: syncProductsTable }: BillingContext,
|
|
43
43
|
{ refreshEntitlements }: BillingEntitlements,
|
|
44
44
|
{ withChanges, updateSubscription, uncancelSubscription, cancelPendingChange, pauseSubscription, resumeSubscription }: BillingSubscriptions,
|
|
45
45
|
{ getOrders, getInvoiceUrl, getUsageHistory, refundOrder }: BillingHistory,
|
|
@@ -186,10 +186,12 @@ export function createBillingFunctions(
|
|
|
186
186
|
// catalog included — and a client asking for "the balance" (no meter
|
|
187
187
|
// name) takes the first. Ordering here means that is always a meter
|
|
188
188
|
// this app declares, whatever order the provider lists them in.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
name
|
|
192
|
-
|
|
189
|
+
// And the unit the catalog names, which the packaged labels say.
|
|
190
|
+
const meters = (resolved.row?.meters ?? []).map((meter) => {
|
|
191
|
+
const name = meterNameById.get(meter.meterId)
|
|
192
|
+
const unit = name === undefined ? undefined : creditMeters[name]?.unit
|
|
193
|
+
return { ...meter, name, ...(unit ? { unit } : {}) }
|
|
194
|
+
})
|
|
193
195
|
return {
|
|
194
196
|
meters: [...meters.filter(meter => meter.name !== undefined), ...meters.filter(meter => meter.name === undefined)],
|
|
195
197
|
}
|
|
@@ -347,6 +349,15 @@ export function createBillingFunctions(
|
|
|
347
349
|
handler: (ctx, args) => lifecycle.cancel(ctx, args),
|
|
348
350
|
})
|
|
349
351
|
|
|
352
|
+
// What the cancel flow reads before it asks: whether a save offer could
|
|
353
|
+
// stand, and for which reasons, by the rules `cancelSubscription` applies.
|
|
354
|
+
// Without one, the flow's "Continue" reads "Cancel my plan" and confirms.
|
|
355
|
+
const getCancelFlow = queryGeneric({
|
|
356
|
+
args: subscriptionTargetArgs,
|
|
357
|
+
returns: v.union(v.null(), v.object({ offers: v.boolean(), reasons: v.array(vReason) })),
|
|
358
|
+
handler: (ctx, args) => lifecycle.getCancelFlow(ctx, args),
|
|
359
|
+
})
|
|
360
|
+
|
|
350
361
|
// The cancel flow's offer, taken: the server finds what it made by the id.
|
|
351
362
|
const acceptSaveOfferFn = actionGeneric({
|
|
352
363
|
args: { offerId: v.string() },
|
|
@@ -478,6 +489,7 @@ export function createBillingFunctions(
|
|
|
478
489
|
startFreePlan,
|
|
479
490
|
updateSubscriptionFn,
|
|
480
491
|
cancelSubscriptionFn,
|
|
492
|
+
getCancelFlow,
|
|
481
493
|
acceptSaveOfferFn,
|
|
482
494
|
getWithdrawal,
|
|
483
495
|
withdrawFn,
|
|
@@ -9,7 +9,8 @@ import { v } from 'convex/values'
|
|
|
9
9
|
import { BILLING_MANAGER_ROLES, RUN_GIFT_SWEEP_FUNCTION } from '../../constants.js'
|
|
10
10
|
import { hasAnyRole } from '../access.js'
|
|
11
11
|
import { mintClaimDiscount, voidClaimDiscount } from './claim-discount.js'
|
|
12
|
-
import { type BillingContext, isProviderNotFound
|
|
12
|
+
import { type BillingContext, isProviderNotFound } from './context.js'
|
|
13
|
+
import { readEnv, UNDELIVERABLE_CAUSES, undeliverableReason } from '../../delivery.js'
|
|
13
14
|
import type { BillingCustomers } from './customers.js'
|
|
14
15
|
import { withCheckoutReturn } from './checkout.js'
|
|
15
16
|
import type { BillingFreePlan } from './free-plan.js'
|
|
@@ -21,7 +22,6 @@ import type { PurchaseRules } from './purchase.js'
|
|
|
21
22
|
import type { CheckoutCreateInput, ProviderCtx, RunQueryCtx, RunWriteCtx } from './types/base.js'
|
|
22
23
|
import type { GiftRecord } from './types/records.js'
|
|
23
24
|
import type { BillingAccessRule } from './types/setup.js'
|
|
24
|
-
import { UNDELIVERABLE_CAUSES, undeliverableReason } from '../../delivery.js'
|
|
25
25
|
import { backendError } from '../../errors.js'
|
|
26
26
|
import { logBackend } from '../../log.js'
|
|
27
27
|
import { normalizeEmail } from '../../tokens.js'
|
|
@@ -171,7 +171,8 @@ export function createHistory(
|
|
|
171
171
|
items: items.map((event) => {
|
|
172
172
|
const normalized = toConvexValue(event) as unknown as UsageEvent
|
|
173
173
|
const units = meterUnits(meter, event.metadata as Record<string, unknown> | undefined)
|
|
174
|
-
|
|
174
|
+
if (units === undefined) return normalized
|
|
175
|
+
return meter?.unit ? { ...normalized, units, unit: meter.unit } : { ...normalized, units }
|
|
175
176
|
}),
|
|
176
177
|
pagination: totals,
|
|
177
178
|
...(page < totals.maxPage ? { nextCursor: String(page + 1) } : {}),
|