@zonastery/bursar 2.0.6 → 2.2.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 +33 -4
- package/dist/billing/auto-recharge-port.d.ts +11 -0
- package/dist/billing/auto-recharge-port.d.ts.map +1 -1
- package/dist/billing/auto-recharge-port.js.map +1 -1
- package/dist/billing/auto-recharge-service.d.ts.map +1 -1
- package/dist/billing/auto-recharge-service.js +53 -26
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.d.ts +38 -3
- package/dist/billing/billing-service.d.ts.map +1 -1
- package/dist/billing/billing-service.js +51 -7
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +34 -9
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js +2 -0
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +35 -3
- package/dist/billing/contracts.d.ts.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-handlers.d.ts +1 -2
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +69 -29
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +2 -2
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +82 -19
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/financial-event-handlers.d.ts +2 -0
- package/dist/billing/financial-event-handlers.d.ts.map +1 -1
- package/dist/billing/financial-event-handlers.js +168 -44
- package/dist/billing/financial-event-handlers.js.map +1 -1
- package/dist/billing/index.d.ts +1 -1
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +16 -3
- package/dist/billing/management.d.ts.map +1 -1
- package/dist/billing/management.js +11 -2
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +13 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +71 -12
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/invoice.d.ts +3 -2
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/invoice.js +33 -3
- package/dist/billing/postgres/repositories/invoice.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts +5 -1
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +7 -10
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/payment.d.ts +6 -1
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/payment.js +25 -16
- package/dist/billing/postgres/repositories/payment.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.d.ts +1 -0
- package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.js +25 -4
- package/dist/billing/postgres/repositories/subscription-change.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription.d.ts +3 -2
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js +44 -48
- package/dist/billing/postgres/repositories/subscription.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts +6 -1
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/topup.js +27 -10
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +46 -34
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +152 -126
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/service-types.d.ts +0 -1
- package/dist/billing/service-types.d.ts.map +1 -1
- package/dist/billing/service-types.js.map +1 -1
- package/dist/billing/types/auto-recharge.d.ts +2 -0
- package/dist/billing/types/auto-recharge.d.ts.map +1 -1
- package/dist/billing/types/auto-recharge.js.map +1 -1
- package/dist/billing/types/catalog.d.ts +1 -0
- package/dist/billing/types/catalog.d.ts.map +1 -1
- package/dist/billing/types/catalog.js.map +1 -1
- package/dist/billing/types/documents.d.ts +15 -1
- package/dist/billing/types/documents.d.ts.map +1 -1
- package/dist/billing/types/documents.js.map +1 -1
- package/dist/billing/types/events.d.ts +2 -0
- package/dist/billing/types/events.d.ts.map +1 -1
- package/dist/billing/types/events.js +15 -0
- package/dist/billing/types/events.js.map +1 -1
- package/dist/billing/types/subscriptions.d.ts +12 -0
- package/dist/billing/types/subscriptions.d.ts.map +1 -1
- package/dist/billing/types/subscriptions.js.map +1 -1
- package/dist/breakdown.d.ts +2 -24
- package/dist/breakdown.d.ts.map +1 -1
- package/dist/breakdown.js +1 -29
- package/dist/breakdown.js.map +1 -1
- package/dist/bursar.d.ts +13 -21
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +44 -50
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +21 -2
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +27 -4
- package/dist/catalog.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +147 -0
- package/dist/cli.js.map +1 -0
- package/dist/commerce/plan-change.d.ts +3 -3
- package/dist/commerce/plan-change.d.ts.map +1 -1
- package/dist/commerce/plan-change.js +14 -7
- package/dist/commerce/plan-change.js.map +1 -1
- package/dist/commerce/provider-registry.d.ts.map +1 -1
- package/dist/commerce/provider-registry.js +8 -2
- package/dist/commerce/provider-registry.js.map +1 -1
- package/dist/commerce/service.d.ts +2 -0
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +330 -76
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +12 -3
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/availability.d.ts +4 -0
- package/dist/config/availability.d.ts.map +1 -0
- package/dist/config/availability.js +10 -0
- package/dist/config/availability.js.map +1 -0
- package/dist/config/normalize.d.ts +7 -0
- package/dist/config/normalize.d.ts.map +1 -0
- package/dist/config/normalize.js +119 -0
- package/dist/config/normalize.js.map +1 -0
- package/dist/config/parse-access.d.ts.map +1 -1
- package/dist/config/parse-access.js +4 -1
- package/dist/config/parse-access.js.map +1 -1
- package/dist/config/parse-commerce.d.ts +5 -1
- package/dist/config/parse-commerce.d.ts.map +1 -1
- package/dist/config/parse-commerce.js +79 -22
- package/dist/config/parse-commerce.js.map +1 -1
- package/dist/config/parse-credits.d.ts.map +1 -1
- package/dist/config/parse-credits.js +10 -7
- package/dist/config/parse-credits.js.map +1 -1
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +31 -15
- package/dist/config/parse-plans.js.map +1 -1
- package/dist/config/parse-pricing.d.ts.map +1 -1
- package/dist/config/parse-pricing.js +42 -27
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.d.ts +4 -0
- package/dist/config/parse-utils.d.ts.map +1 -1
- package/dist/config/parse-utils.js +26 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +8 -4
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.d.ts +5 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +118 -70
- package/dist/config.js.map +1 -1
- package/dist/credits/amount.d.ts.map +1 -1
- package/dist/credits/amount.js +5 -4
- package/dist/credits/amount.js.map +1 -1
- package/dist/credits/catalog-runtime.d.ts +15 -2
- package/dist/credits/catalog-runtime.d.ts.map +1 -1
- package/dist/credits/catalog-runtime.js +77 -21
- package/dist/credits/catalog-runtime.js.map +1 -1
- package/dist/credits/lease-workflow.d.ts +3 -1
- package/dist/credits/lease-workflow.d.ts.map +1 -1
- package/dist/credits/lease-workflow.js +47 -38
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.d.ts +2 -7
- package/dist/credits/low-balance-monitor.d.ts.map +1 -1
- package/dist/credits/low-balance-monitor.js +6 -57
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/analytics.d.ts +3 -3
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +25 -7
- package/dist/credits/postgres/repositories/analytics.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.d.ts +28 -0
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/balance.js +33 -14
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js +2 -2
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/catalog.d.ts +2 -2
- package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/catalog.js +2 -12
- package/dist/credits/postgres/repositories/catalog.js.map +1 -1
- package/dist/credits/postgres/repositories/deduction.d.ts +2 -0
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +9 -2
- package/dist/credits/postgres/repositories/deduction.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.d.ts +3 -0
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/lease.js +46 -12
- package/dist/credits/postgres/repositories/lease.js.map +1 -1
- package/dist/credits/postgres/repositories/plan.d.ts +6 -1
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +13 -3
- package/dist/credits/postgres/repositories/plan.js.map +1 -1
- package/dist/credits/postgres/repositories/team.d.ts +1 -1
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/team.js +9 -5
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +30 -20
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +335 -251
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +4 -4
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/rated-wire.d.ts +7 -0
- package/dist/credits/rated-wire.d.ts.map +1 -0
- package/dist/credits/rated-wire.js +70 -0
- package/dist/credits/rated-wire.js.map +1 -0
- package/dist/credits/service-errors.d.ts.map +1 -1
- package/dist/credits/service-errors.js +8 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.d.ts +5 -7
- package/dist/credits/service-types.d.ts.map +1 -1
- package/dist/credits/service-types.js.map +1 -1
- package/dist/credits/service.d.ts +12 -9
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +161 -138
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +11 -3
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +9 -0
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +9 -1
- package/dist/credits/types/account.d.ts.map +1 -1
- package/dist/credits/types/account.js.map +1 -1
- package/dist/credits/types/admission.d.ts +1 -0
- package/dist/credits/types/admission.d.ts.map +1 -1
- package/dist/credits/types/admission.js.map +1 -1
- package/dist/credits/types/catalog.d.ts +1 -0
- package/dist/credits/types/catalog.d.ts.map +1 -1
- package/dist/credits/types/catalog.js.map +1 -1
- package/dist/credits/types/grants.d.ts +12 -0
- package/dist/credits/types/grants.d.ts.map +1 -1
- package/dist/credits/types/grants.js.map +1 -1
- package/dist/credits/types/ledger.d.ts +13 -0
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.js.map +1 -1
- package/dist/credits/types/quotas.d.ts +2 -1
- package/dist/credits/types/quotas.d.ts.map +1 -1
- package/dist/credits/types/quotas.js.map +1 -1
- package/dist/engine.d.ts +4 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +59 -36
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +12 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -1
- package/dist/expr/evaluator.d.ts.map +1 -1
- package/dist/expr/evaluator.js +29 -9
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr/language.js +1 -1
- package/dist/expr/language.js.map +1 -1
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +5 -6
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +272 -228
- package/dist/generated/pricing-config.types.d.ts +128 -79
- package/dist/generated/pricing-config.types.d.ts.map +1 -1
- package/dist/generated/pricing-config.types.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/load-config-file.d.ts +5 -1
- package/dist/load-config-file.d.ts.map +1 -1
- package/dist/load-config-file.js +56 -17
- package/dist/load-config-file.js.map +1 -1
- package/dist/metrics.d.ts +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -1
- package/dist/node.js.map +1 -1
- package/dist/pricing-decimal.d.ts +7 -0
- package/dist/pricing-decimal.d.ts.map +1 -0
- package/dist/pricing-decimal.js +43 -0
- package/dist/pricing-decimal.js.map +1 -0
- package/dist/providers/dodo/better-auth-core.d.ts +1 -1
- package/dist/providers/dodo/better-auth-core.d.ts.map +1 -1
- package/dist/providers/dodo/better-auth-core.js +2 -2
- package/dist/providers/dodo/better-auth-core.js.map +1 -1
- package/dist/providers/dodo/better-auth.d.ts.map +1 -1
- package/dist/providers/dodo/better-auth.js +16 -2
- package/dist/providers/dodo/better-auth.js.map +1 -1
- package/dist/providers/dodo/event-mapper.d.ts +1 -1
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +124 -18
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/nextjs-core.d.ts +1 -1
- package/dist/providers/dodo/nextjs-core.d.ts.map +1 -1
- package/dist/providers/dodo/nextjs-core.js +2 -2
- package/dist/providers/dodo/nextjs-core.js.map +1 -1
- package/dist/providers/dodo/nextjs.d.ts.map +1 -1
- package/dist/providers/dodo/nextjs.js +16 -6
- package/dist/providers/dodo/nextjs.js.map +1 -1
- package/dist/providers/dodo/provider.d.ts +5 -2
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +46 -7
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/dodo/verified-payment-payload.d.ts +6 -0
- package/dist/providers/dodo/verified-payment-payload.d.ts.map +1 -0
- package/dist/providers/dodo/verified-payment-payload.js +42 -0
- package/dist/providers/dodo/verified-payment-payload.js.map +1 -0
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +4 -1
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +3 -1
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.d.ts.map +1 -1
- package/dist/providers/stripe/event-mapper.js +51 -24
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +4 -1
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +118 -34
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +16 -2
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +9 -0
- package/dist/providers/types.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +5 -0
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +72 -11
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/postgres-errors.d.ts.map +1 -1
- package/dist/shared/postgres-errors.js +6 -0
- package/dist/shared/postgres-errors.js.map +1 -1
- package/dist/shared/provider-rejection.d.ts +3 -0
- package/dist/shared/provider-rejection.d.ts.map +1 -0
- package/dist/shared/provider-rejection.js +17 -0
- package/dist/shared/provider-rejection.js.map +1 -0
- package/dist/shared/timestamp.d.ts +5 -0
- package/dist/shared/timestamp.d.ts.map +1 -0
- package/dist/shared/timestamp.js +21 -0
- package/dist/shared/timestamp.js.map +1 -0
- package/dist/starter.yaml +17 -0
- package/dist/storage/adapters/clickhouse.d.ts +1 -1
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +42 -37
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.d.ts +5 -0
- package/dist/storage/adapters/s3.d.ts.map +1 -1
- package/dist/storage/adapters/s3.js +46 -14
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/diagnostics.d.ts +3 -7
- package/dist/storage/diagnostics.d.ts.map +1 -1
- package/dist/storage/diagnostics.js +6 -15
- package/dist/storage/diagnostics.js.map +1 -1
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +4 -3
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +8 -0
- package/dist/storage/ports.d.ts.map +1 -1
- package/dist/storage/ports.js.map +1 -1
- package/dist/storage/postgres-repository.d.ts +1 -3
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +34 -12
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/raw-json.d.ts +10 -0
- package/dist/storage/raw-json.d.ts.map +1 -0
- package/dist/storage/raw-json.js +19 -0
- package/dist/storage/raw-json.js.map +1 -0
- package/dist/storage/runtime.d.ts +15 -10
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +97 -68
- package/dist/storage/runtime.js.map +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/index.js.map +1 -1
- package/package.json +78 -71
- package/dist/credits/queries.d.ts +0 -33
- package/dist/credits/queries.d.ts.map +0 -1
- package/dist/credits/queries.js +0 -71
- package/dist/credits/queries.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/commerce/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\n\nimport type {\n BillingAutoRechargeStatus,\n BillingInvoiceRecord,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n} from \"../billing/types/index.js\";\nimport type {\n BucketBalance,\n GetUserPlanResult,\n LedgerEntry,\n UsageCharge,\n} from \"../credits/types/index.js\";\nimport type {\n ChangePlanPreview,\n PaymentMethodInfo,\n PaymentProvider,\n SavedPaymentChargeResult,\n WebhookResult,\n} from \"../providers/types.js\";\nimport type { BillingEventSink } from \"../billing/contracts.js\";\nimport type { AutoRechargeOutcome } from \"../billing/auto-recharge-service.js\";\nimport type { Logger } from \"../shared/logger.js\";\nimport type { ProviderEnvironment } from \"../providers/environment.js\";\n\nexport interface CommerceProviderFactoryContext {\n tenantId?: string;\n providerEnvironment: ProviderEnvironment;\n eventSink: BillingEventSink;\n}\n\nexport type CommerceProviderFactory = (\n context: CommerceProviderFactoryContext,\n) => PaymentProvider | Promise<PaymentProvider>;\n\nexport interface CommercePreferenceDefaults {\n autoRecharge: boolean;\n overageProtection: boolean;\n emailNotifications: boolean;\n usageAlerts: boolean;\n invoiceReminders: boolean;\n}\n\nexport interface CommerceOptions {\n tenantId?: string;\n /** Explicit financial namespace shared with billing persistence. */\n providerEnvironment: ProviderEnvironment;\n providers: Record<string, CommerceProviderFactory>;\n defaultProvider?: string;\n checkoutIntentTtlMs?: number;\n preferenceDefaults?: Partial<CommercePreferenceDefaults>;\n logger?: Logger | null;\n}\n\nexport type CommerceCheckoutKind = \"subscription\" | \"credit_pack\";\n\nexport interface CreateCheckoutInput {\n /** Authenticated actor that owns and may inspect the checkout intent. */\n subjectId: string;\n /** Financial subject that receives the subscription or purchased credits. */\n accountId: string;\n email?: string;\n offerKey: string;\n provider?: string;\n type?: CommerceCheckoutKind;\n quantity?: number;\n returnUrl: string;\n cancelUrl: string;\n operationKey: string;\n metadata?: Record<string, string>;\n}\n\nexport interface CreateCheckoutResult {\n intentId: string;\n url: string;\n provider: string;\n offerKey: string;\n}\n\nexport type CommerceCheckoutStatus = \"pending\" | \"succeeded\" | \"failed\" | \"expired\";\n\nexport interface CheckoutStatusResult {\n intentId: string;\n status: CommerceCheckoutStatus;\n}\n\nexport interface PreferencePatch {\n autoRecharge?: boolean;\n overageProtection?: boolean;\n emailNotifications?: boolean;\n usageAlerts?: boolean;\n invoiceReminders?: boolean;\n}\n\nexport interface SubscriptionCommandResult {\n ok: true;\n pending?: boolean;\n}\n\nexport type SubscriptionAccessState = \"entitled\" | \"grace\" | \"blocked\" | \"none\";\n\nexport interface NormalizedPendingPlanChange {\n planKey: string;\n interval: \"month\" | \"year\";\n effectiveAt: string;\n scheduled: boolean;\n providerOperationId: string | null;\n}\n\nexport interface AccountSubscriptionSummary {\n accountId: string;\n planKey: string | null;\n status: BillingSubscriptionStatus | null;\n lifecycleState: BillingSubscriptionStatus | \"none\";\n accessState: SubscriptionAccessState;\n isCurrent: boolean;\n isEntitled: boolean;\n isBlockingCheckout: boolean;\n isCancellable: boolean;\n isTerminal: boolean;\n subscription: BillingSubscriptionState | null;\n pendingChange: NormalizedPendingPlanChange | null;\n}\n\nexport interface CancelSubscriptionResult {\n provider: string;\n providerSubscriptionId: string;\n canceled: boolean;\n error: string | null;\n}\n\nexport interface CancelAllSubscriptionsResult {\n accountId: string;\n canceledCount: number;\n subscriptions: CancelSubscriptionResult[];\n}\n\nexport type PlanChangeClassification =\n | \"unchanged\"\n | \"upgrade\"\n | \"downgrade\"\n | \"lateral\"\n | \"cadence_change\";\n\ninterface PlanChangePreviewResultBase {\n planId: string;\n interval: \"month\" | \"year\";\n}\n\n/**\n * A plan-change preview. The discriminant makes it impossible to confirm an\n * unchanged plan or accidentally omit the provider quote from a real change.\n */\nexport type PlanChangePreviewResult =\n | (PlanChangePreviewResultBase & {\n unchanged: true;\n classification: \"unchanged\";\n scheduled: false;\n })\n | (PlanChangePreviewResultBase & {\n unchanged: false;\n classification: Exclude<PlanChangeClassification, \"unchanged\">;\n scheduled: boolean;\n preview: ChangePlanPreview;\n quoteFingerprint: string;\n });\n\nexport interface PreviewPlanChangeInput {\n accountId: string;\n offerKey: string;\n}\n\nexport interface ConfirmPlanChangeInput extends PreviewPlanChangeInput {\n quoteFingerprint: string;\n operationKey: string;\n}\n\nexport interface ConfirmPlanChangeResult {\n success: true;\n unchanged?: boolean;\n pending?: boolean;\n scheduled?: boolean;\n effectiveAt?: string;\n planId: string;\n interval: \"month\" | \"year\";\n}\n\nexport interface PortalSessionInput {\n accountId: string;\n purpose?: \"billing\" | \"payment-method\";\n returnUrl: string;\n cancelUrl?: string;\n}\n\nexport interface BillingDocumentInvoiceRef {\n kind: \"provider_invoice\";\n provider: string;\n providerDocumentId: string;\n status?: string | null;\n amountPaidMinor?: number | null;\n amountDueMinor?: number | null;\n currency?: string | null;\n periodStart?: string | null;\n periodEnd?: string | null;\n}\n\nexport interface BillingDocumentLedgerRef {\n kind: \"ledger_entry\";\n ledgerEntryId: string;\n provider?: string | null;\n providerDocumentId?: string | null;\n createdAt: string;\n entryType: string;\n amount: Decimal;\n}\n\nexport type BillingDocumentRef = BillingDocumentInvoiceRef | BillingDocumentLedgerRef;\n\nexport type BillingDocumentLocator =\n | Pick<BillingDocumentInvoiceRef, \"kind\" | \"provider\" | \"providerDocumentId\">\n | Pick<BillingDocumentLedgerRef, \"kind\" | \"ledgerEntryId\">;\n\nexport interface CommerceSectionAvailability {\n paymentMethods: boolean;\n documents: boolean;\n providerInvoices: boolean;\n transactions: boolean;\n usage: boolean;\n autoRecharge: boolean;\n}\n\nexport interface CreditSpendSource {\n type: \"allowance\" | \"bucket\";\n key: string;\n label: string;\n priority: number;\n}\n\nexport interface AccountCreditDisplay {\n currency: string;\n unitsPerMajor: Decimal;\n}\n\nexport interface AccountCommerceOverview {\n accountId: string;\n credits: {\n ledgerBalance: Decimal;\n effectiveSpendableBalance: Decimal;\n lifetimePurchases: Decimal;\n allowance: {\n remaining: Decimal;\n limit: Decimal | null;\n periodStart: string | null;\n periodEnd: string | null;\n };\n buckets: BucketBalance[];\n bucketsByKey: Record<string, Decimal>;\n spendOrder: CreditSpendSource[];\n display: AccountCreditDisplay | null;\n };\n entitlement: GetUserPlanResult;\n subscriptionSummary: AccountSubscriptionSummary;\n subscription: BillingSubscriptionState | null;\n pendingChange: BillingSubscriptionChange | null;\n preferences: BillingPreferences;\n paymentMethods: PaymentMethodInfo[];\n documents: BillingDocumentRef[];\n providerInvoices: BillingInvoiceRecord[];\n transactions: LedgerEntry[];\n usage: UsageCharge[];\n autoRecharge: BillingAutoRechargeStatus | null;\n availability: CommerceSectionAvailability;\n}\n\nexport interface GetInvoiceLinkInput {\n accountId: string;\n document: BillingDocumentLocator;\n}\n\nexport interface CommerceWebhookInput {\n provider?: string;\n rawBody: string;\n headers: Record<string, string>;\n}\n\nexport type CommerceWebhookResult = WebhookResult;\n\nexport interface AutoRechargeInput {\n accountId: string;\n returnUrl?: string;\n}\n\nexport interface CommerceAutoRecharge {\n getStatus(input: Pick<AutoRechargeInput, \"accountId\">): Promise<BillingAutoRechargeStatus | null>;\n enable(input: AutoRechargeInput): Promise<BillingAutoRechargeStatus | null>;\n disable(input: Pick<AutoRechargeInput, \"accountId\">): Promise<void>;\n retry(input: AutoRechargeInput): Promise<BillingAutoRechargeStatus | null>;\n processIfNeeded(input: AutoRechargeInput): Promise<{\n outcome: AutoRechargeOutcome;\n charge?: SavedPaymentChargeResult | null;\n }>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/commerce/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\n\nimport type {\n BillingAutoRechargeStatus,\n BillingInvoiceRecord,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionState,\n BillingSubscriptionStatus,\n} from \"../billing/types/index.js\";\nimport type {\n BucketBalance,\n GetUserPlanResult,\n LedgerEntry,\n UsageCharge,\n} from \"../credits/types/index.js\";\nimport type {\n ChangePlanPreview,\n PaymentMethodInfo,\n PaymentProvider,\n SavedPaymentChargeResult,\n WebhookResult,\n} from \"../providers/types.js\";\nimport type { BillingEventSink } from \"../billing/contracts.js\";\nimport type { AutoRechargeOutcome } from \"../billing/auto-recharge-service.js\";\nimport type { Logger } from \"../shared/logger.js\";\nimport type { ProviderEnvironment } from \"../providers/environment.js\";\n\nexport interface CommerceProviderFactoryContext {\n tenantId?: string;\n providerEnvironment: ProviderEnvironment;\n eventSink: BillingEventSink;\n}\n\nexport type CommerceProviderFactory = (\n context: CommerceProviderFactoryContext,\n) => PaymentProvider | Promise<PaymentProvider>;\n\nexport interface CommercePreferenceDefaults {\n autoRecharge: boolean;\n overageProtection: boolean;\n emailNotifications: boolean;\n usageAlerts: boolean;\n invoiceReminders: boolean;\n}\n\nexport interface CommerceOptions {\n tenantId?: string;\n /** Explicit financial namespace shared with billing persistence. */\n providerEnvironment: ProviderEnvironment;\n providers: Record<string, CommerceProviderFactory>;\n defaultProvider?: string;\n checkoutIntentTtlMs?: number;\n preferenceDefaults?: Partial<CommercePreferenceDefaults>;\n logger?: Logger | null;\n}\n\nexport type CommerceCheckoutKind = \"subscription\" | \"credit_pack\";\n\nexport interface CreateCheckoutInput {\n /** Authenticated actor that owns and may inspect the checkout intent. */\n subjectId: string;\n /** Financial subject that receives the subscription or purchased credits. */\n accountId: string;\n email?: string;\n offerKey: string;\n /** Trusted ISO region for availability checks. */\n region?: string;\n provider?: string;\n type?: CommerceCheckoutKind;\n quantity?: number;\n returnUrl: string;\n cancelUrl: string;\n operationKey: string;\n metadata?: Record<string, string>;\n}\n\nexport interface CreateCheckoutResult {\n intentId: string;\n url: string;\n provider: string;\n offerKey: string;\n}\n\nexport type CommerceCheckoutStatus = \"pending\" | \"succeeded\" | \"failed\" | \"expired\";\n\nexport interface CheckoutStatusResult {\n intentId: string;\n status: CommerceCheckoutStatus;\n}\n\nexport interface PreferencePatch {\n autoRecharge?: boolean;\n overageProtection?: boolean;\n emailNotifications?: boolean;\n usageAlerts?: boolean;\n invoiceReminders?: boolean;\n}\n\nexport interface SubscriptionCommandResult {\n ok: true;\n pending?: boolean;\n}\n\nexport type SubscriptionAccessState = \"entitled\" | \"grace\" | \"blocked\" | \"none\";\n\nexport interface NormalizedPendingPlanChange {\n planKey: string;\n interval: \"day\" | \"week\" | \"month\" | \"year\";\n intervalCount: number;\n effectiveAt: string;\n scheduled: boolean;\n providerOutcomeUnknown?: boolean;\n providerOperationId: string | null;\n}\n\nexport interface AccountSubscriptionSummary {\n accountId: string;\n planKey: string | null;\n status: BillingSubscriptionStatus | null;\n lifecycleState: BillingSubscriptionStatus | \"none\";\n accessState: SubscriptionAccessState;\n isCurrent: boolean;\n isEntitled: boolean;\n isBlockingCheckout: boolean;\n isCancellable: boolean;\n isTerminal: boolean;\n subscription: BillingSubscriptionState | null;\n pendingChange: NormalizedPendingPlanChange | null;\n}\n\nexport interface CancelSubscriptionResult {\n provider: string;\n providerSubscriptionId: string;\n canceled: boolean;\n error: string | null;\n}\n\nexport interface CancelAllSubscriptionsResult {\n accountId: string;\n canceledCount: number;\n subscriptions: CancelSubscriptionResult[];\n}\n\nexport type PlanChangeClassification =\n | \"unchanged\"\n | \"upgrade\"\n | \"downgrade\"\n | \"lateral\"\n | \"cadence_change\";\n\ninterface PlanChangePreviewResultBase {\n planId: string;\n interval: \"day\" | \"week\" | \"month\" | \"year\";\n intervalCount: number;\n}\n\n/**\n * A plan-change preview. The discriminant makes it impossible to confirm an\n * unchanged plan or accidentally omit the provider quote from a real change.\n */\nexport type PlanChangePreviewResult =\n | (PlanChangePreviewResultBase & {\n unchanged: true;\n classification: \"unchanged\";\n scheduled: false;\n })\n | (PlanChangePreviewResultBase & {\n unchanged: false;\n classification: Exclude<PlanChangeClassification, \"unchanged\">;\n scheduled: boolean;\n preview: ChangePlanPreview;\n quoteFingerprint: string;\n });\n\nexport interface PreviewPlanChangeInput {\n accountId: string;\n offerKey: string;\n /** Trusted ISO region for availability checks. */\n region?: string;\n}\n\nexport interface ConfirmPlanChangeInput extends PreviewPlanChangeInput {\n quoteFingerprint: string;\n operationKey: string;\n}\n\nexport interface ConfirmPlanChangeResult {\n success: true;\n unchanged?: boolean;\n pending?: boolean;\n scheduled?: boolean;\n providerOutcomeUnknown?: boolean;\n effectiveAt?: string;\n planId: string;\n interval: \"day\" | \"week\" | \"month\" | \"year\";\n intervalCount: number;\n}\n\nexport interface PortalSessionInput {\n accountId: string;\n purpose?: \"billing\" | \"payment-method\";\n returnUrl: string;\n cancelUrl?: string;\n}\n\nexport interface BillingDocumentInvoiceRef {\n kind: \"provider_invoice\";\n provider: string;\n providerDocumentId: string;\n status?: string | null;\n amountPaidMinor?: number | null;\n amountDueMinor?: number | null;\n currency?: string | null;\n periodStart?: string | null;\n periodEnd?: string | null;\n}\n\nexport interface BillingDocumentLedgerRef {\n kind: \"ledger_entry\";\n ledgerEntryId: string;\n provider?: string | null;\n providerDocumentId?: string | null;\n createdAt: string;\n entryType: string;\n amount: Decimal;\n}\n\nexport type BillingDocumentRef = BillingDocumentInvoiceRef | BillingDocumentLedgerRef;\n\nexport type BillingDocumentLocator =\n | Pick<BillingDocumentInvoiceRef, \"kind\" | \"provider\" | \"providerDocumentId\">\n | Pick<BillingDocumentLedgerRef, \"kind\" | \"ledgerEntryId\">;\n\nexport interface CommerceSectionAvailability {\n paymentMethods: boolean;\n documents: boolean;\n providerInvoices: boolean;\n transactions: boolean;\n usage: boolean;\n autoRecharge: boolean;\n}\n\nexport interface CreditSpendSource {\n type: \"allowance\" | \"bucket\";\n key: string;\n label: string;\n priority: number;\n}\n\nexport interface AccountCreditDisplay {\n currency: string;\n unitsPerMajor: Decimal;\n}\n\nexport interface AccountCommerceOverview {\n accountId: string;\n credits: {\n ledgerBalance: Decimal;\n effectiveSpendableBalance: Decimal;\n lifetimePurchases: Decimal;\n allowance: {\n remaining: Decimal;\n limit: Decimal | null;\n periodStart: string | null;\n periodEnd: string | null;\n };\n buckets: BucketBalance[];\n bucketsByKey: Record<string, Decimal>;\n spendOrder: CreditSpendSource[];\n display: AccountCreditDisplay | null;\n };\n entitlement: GetUserPlanResult;\n subscriptionSummary: AccountSubscriptionSummary;\n subscription: BillingSubscriptionState | null;\n pendingChange: BillingSubscriptionChange | null;\n preferences: BillingPreferences;\n paymentMethods: PaymentMethodInfo[];\n documents: BillingDocumentRef[];\n providerInvoices: BillingInvoiceRecord[];\n transactions: LedgerEntry[];\n usage: UsageCharge[];\n autoRecharge: BillingAutoRechargeStatus | null;\n availability: CommerceSectionAvailability;\n}\n\nexport interface GetInvoiceLinkInput {\n accountId: string;\n document: BillingDocumentLocator;\n}\n\nexport interface CommerceWebhookInput {\n provider?: string;\n rawBody: string;\n headers: Record<string, string>;\n}\n\nexport type CommerceWebhookResult = WebhookResult;\n\nexport interface AutoRechargeInput {\n accountId: string;\n returnUrl?: string;\n}\n\nexport interface CommerceAutoRecharge {\n getStatus(input: Pick<AutoRechargeInput, \"accountId\">): Promise<BillingAutoRechargeStatus | null>;\n enable(input: AutoRechargeInput): Promise<BillingAutoRechargeStatus | null>;\n disable(input: Pick<AutoRechargeInput, \"accountId\">): Promise<void>;\n retry(input: AutoRechargeInput): Promise<BillingAutoRechargeStatus | null>;\n processIfNeeded(input: AutoRechargeInput): Promise<{\n outcome: AutoRechargeOutcome;\n charge?: SavedPaymentChargeResult | null;\n }>;\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Availability } from "./types.js";
|
|
2
|
+
/** Evaluate catalog availability against a trusted region and current time. */
|
|
3
|
+
export declare function offerIsAvailable(availability: Availability | undefined, region?: string, now?: Date): boolean;
|
|
4
|
+
//# sourceMappingURL=availability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"availability.d.ts","sourceRoot":"","sources":["../../src/config/availability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,MAAM,CAAC,EAAE,MAAM,EACf,GAAG,GAAE,IAAiB,GACrB,OAAO,CAQT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Evaluate catalog availability against a trusted region and current time. */
|
|
2
|
+
export function offerIsAvailable(availability, region, now = new Date()) {
|
|
3
|
+
if (!availability)
|
|
4
|
+
return true;
|
|
5
|
+
const timestamp = now.getTime();
|
|
6
|
+
return !((availability.startsAt && Date.parse(availability.startsAt) > timestamp) ||
|
|
7
|
+
(availability.endsAt && Date.parse(availability.endsAt) <= timestamp) ||
|
|
8
|
+
(availability.regions.length > 0 && (!region || !availability.regions.includes(region))));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=availability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"availability.js","sourceRoot":"","sources":["../../src/config/availability.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAC9B,YAAsC,EACtC,MAAe,EACf,GAAG,GAAS,IAAI,IAAI,EAAE;IAEtB,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAChC,OAAO,CAAC,CACN,CAAC,YAAY,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;QACxE,CAAC,YAAY,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;QACrE,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CACzF,CAAC;AACJ,CAAC","sourcesContent":["import type { Availability } from \"./types.js\";\n\n/** Evaluate catalog availability against a trusted region and current time. */\nexport function offerIsAvailable(\n availability: Availability | undefined,\n region?: string,\n now: Date = new Date(),\n): boolean {\n if (!availability) return true;\n const timestamp = now.getTime();\n return !(\n (availability.startsAt && Date.parse(availability.startsAt) > timestamp) ||\n (availability.endsAt && Date.parse(availability.endsAt) <= timestamp) ||\n (availability.regions.length > 0 && (!region || !availability.regions.includes(region)))\n );\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JsonObject } from "../shared/json.js";
|
|
2
|
+
import { type ProviderEnvironment } from "../providers/environment.js";
|
|
3
|
+
/** Resolve shorthand and provider bindings for the validated wire configuration. */
|
|
4
|
+
export declare function normalizeConfig(data: JsonObject, environment?: ProviderEnvironment): JsonObject;
|
|
5
|
+
/** Normalize a validated JSON value owned by the caller. */
|
|
6
|
+
export declare function normalizeValidatedConfig(result: JsonObject, environment?: ProviderEnvironment): JsonObject;
|
|
7
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/config/normalize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAO9F,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,mBAAmB,GAAG,UAAU,CAE/F;AAED,4DAA4D;AAC5D,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,UAAU,EAClB,WAAW,CAAC,EAAE,mBAAmB,GAChC,UAAU,CAmGZ"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ConfigError } from "../errors.js";
|
|
2
|
+
import { PROVIDER_ENVIRONMENTS } from "../providers/environment.js";
|
|
3
|
+
function object(value) {
|
|
4
|
+
// Input was validated as JSON before this shape check.
|
|
5
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof
|
|
6
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
/** Resolve shorthand and provider bindings for the validated wire configuration. */
|
|
9
|
+
export function normalizeConfig(data, environment) {
|
|
10
|
+
return normalizeValidatedConfig(structuredClone(data), environment);
|
|
11
|
+
}
|
|
12
|
+
/** Normalize a validated JSON value owned by the caller. */
|
|
13
|
+
export function normalizeValidatedConfig(result, environment) {
|
|
14
|
+
if (environment != null && !PROVIDER_ENVIRONMENTS.includes(environment))
|
|
15
|
+
throw new ConfigError("invalid provider environment");
|
|
16
|
+
const credits = (result.credits ??= {});
|
|
17
|
+
if (!object(credits))
|
|
18
|
+
throw new ConfigError("credits must be an object");
|
|
19
|
+
const hasSignup = "on_signup" in credits;
|
|
20
|
+
const signup = credits.on_signup;
|
|
21
|
+
delete credits.on_signup;
|
|
22
|
+
if (!("buckets" in credits)) {
|
|
23
|
+
credits.buckets = { default: { priority: 0 } };
|
|
24
|
+
if (!("default_bucket" in credits))
|
|
25
|
+
credits.default_bucket = "default";
|
|
26
|
+
}
|
|
27
|
+
if (hasSignup && signup != null) {
|
|
28
|
+
if (typeof credits.default_bucket !== "string")
|
|
29
|
+
throw new ConfigError("credits.on_signup requires credits.default_bucket");
|
|
30
|
+
const programs = (credits.grant_programs ??= {});
|
|
31
|
+
if (!object(programs) ||
|
|
32
|
+
"signup" in programs ||
|
|
33
|
+
Object.values(programs).some((program) => object(program) && program.trigger === "account_created"))
|
|
34
|
+
throw new ConfigError("credits.on_signup conflicts with an account_created grant program");
|
|
35
|
+
programs.signup = {
|
|
36
|
+
trigger: "account_created",
|
|
37
|
+
awards: [{ amount: signup, bucket: credits.default_bucket }],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const pricing = result.pricing;
|
|
41
|
+
if (object(pricing) && object(pricing.operations)) {
|
|
42
|
+
const cards = (pricing.rate_cards ??= {});
|
|
43
|
+
if (!object(cards))
|
|
44
|
+
throw new ConfigError("pricing.rate_cards must be an object");
|
|
45
|
+
const shorthand = {};
|
|
46
|
+
for (const [key, operation] of Object.entries(pricing.operations)) {
|
|
47
|
+
if (!object(operation))
|
|
48
|
+
continue;
|
|
49
|
+
if ("charge" in operation) {
|
|
50
|
+
if (operation.charge != null)
|
|
51
|
+
shorthand[key] = { unmatched: { action: "charge", charge: operation.charge } };
|
|
52
|
+
delete operation.charge;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (Object.keys(shorthand).length) {
|
|
56
|
+
if (!Object.keys(cards).length)
|
|
57
|
+
cards.standard = { operations: {} };
|
|
58
|
+
for (const [cardKey, card] of Object.entries(cards)) {
|
|
59
|
+
if (!object(card))
|
|
60
|
+
throw new ConfigError(`pricing.rate_cards.${cardKey} must be an object`);
|
|
61
|
+
if (card.extends != null)
|
|
62
|
+
continue;
|
|
63
|
+
const operations = (card.operations ??= {});
|
|
64
|
+
if (!object(operations))
|
|
65
|
+
throw new ConfigError(`pricing.rate_cards.${cardKey}.operations must be an object`);
|
|
66
|
+
for (const [key, value] of Object.entries(shorthand)) {
|
|
67
|
+
if (Object.hasOwn(operations, key))
|
|
68
|
+
throw new ConfigError(`pricing.operations.${key}.charge conflicts with pricing.rate_cards.${cardKey}.operations.${key}`);
|
|
69
|
+
operations[key] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (object(result.plans))
|
|
75
|
+
for (const plan of Object.values(result.plans)) {
|
|
76
|
+
if (!object(plan))
|
|
77
|
+
continue;
|
|
78
|
+
if (object(pricing) && object(pricing.rate_cards)) {
|
|
79
|
+
const keys = Object.keys(pricing.rate_cards);
|
|
80
|
+
if (keys.length === 1 && keys[0] !== undefined && plan.rate_card == null)
|
|
81
|
+
plan.rate_card = keys[0];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (object(result.commerce) &&
|
|
85
|
+
object(result.commerce.providers) &&
|
|
86
|
+
object(result.commerce.offers)) {
|
|
87
|
+
const definitions = result.commerce.providers;
|
|
88
|
+
for (const offer of Object.values(result.commerce.offers)) {
|
|
89
|
+
if (!object(offer) || !object(offer.providers))
|
|
90
|
+
continue;
|
|
91
|
+
for (const [key, reference] of Object.entries(offer.providers)) {
|
|
92
|
+
const provider = definitions[key];
|
|
93
|
+
if (!object(reference) || !object(provider) || "type" in reference)
|
|
94
|
+
continue;
|
|
95
|
+
if (provider.type === "stripe")
|
|
96
|
+
reference.type = "stripe_price";
|
|
97
|
+
if (provider.type === "dodo")
|
|
98
|
+
reference.type = "dodo_product";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (environment != null && object(result.commerce) && object(result.commerce.offers)) {
|
|
103
|
+
for (const offer of Object.values(result.commerce.offers)) {
|
|
104
|
+
if (!object(offer) || !object(offer.providers))
|
|
105
|
+
continue;
|
|
106
|
+
for (const reference of Object.values(offer.providers)) {
|
|
107
|
+
if (!object(reference))
|
|
108
|
+
continue;
|
|
109
|
+
for (const field of ["price_id", "product_id", "external_id"]) {
|
|
110
|
+
const value = reference[field];
|
|
111
|
+
if (typeof value === "string")
|
|
112
|
+
reference[field] = { [environment]: value };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=normalize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C","sourcesContent":["import { ConfigError } from \"../errors.js\";\nimport type { JsonObject, JsonValue } from \"../shared/json.js\";\n\nimport { PROVIDER_ENVIRONMENTS, type ProviderEnvironment } from \"../providers/environment.js\";\nfunction object(value: JsonValue | undefined): value is JsonObject {\n // Input was validated as JSON before this shape check.\n // oxlint-disable-next-line anti-slop/no-runtime-typeof\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/** Resolve shorthand and provider bindings for the validated wire configuration. */\nexport function normalizeConfig(data: JsonObject, environment?: ProviderEnvironment): JsonObject {\n return normalizeValidatedConfig(structuredClone(data), environment);\n}\n\n/** Normalize a validated JSON value owned by the caller. */\nexport function normalizeValidatedConfig(\n result: JsonObject,\n environment?: ProviderEnvironment,\n): JsonObject {\n if (environment != null && !PROVIDER_ENVIRONMENTS.includes(environment))\n throw new ConfigError(\"invalid provider environment\");\n const credits = (result.credits ??= {});\n if (!object(credits)) throw new ConfigError(\"credits must be an object\");\n const hasSignup = \"on_signup\" in credits;\n const signup = credits.on_signup;\n delete credits.on_signup;\n if (!(\"buckets\" in credits)) {\n credits.buckets = { default: { priority: 0 } };\n if (!(\"default_bucket\" in credits)) credits.default_bucket = \"default\";\n }\n if (hasSignup && signup != null) {\n if (typeof credits.default_bucket !== \"string\")\n throw new ConfigError(\"credits.on_signup requires credits.default_bucket\");\n const programs = (credits.grant_programs ??= {});\n if (\n !object(programs) ||\n \"signup\" in programs ||\n Object.values(programs).some(\n (program) => object(program) && program.trigger === \"account_created\",\n )\n )\n throw new ConfigError(\"credits.on_signup conflicts with an account_created grant program\");\n programs.signup = {\n trigger: \"account_created\",\n awards: [{ amount: signup, bucket: credits.default_bucket }],\n };\n }\n const pricing = result.pricing;\n if (object(pricing) && object(pricing.operations)) {\n const cards = (pricing.rate_cards ??= {});\n if (!object(cards)) throw new ConfigError(\"pricing.rate_cards must be an object\");\n const shorthand: JsonObject = {};\n for (const [key, operation] of Object.entries(pricing.operations)) {\n if (!object(operation)) continue;\n if (\"charge\" in operation) {\n if (operation.charge != null)\n shorthand[key] = { unmatched: { action: \"charge\", charge: operation.charge } };\n delete operation.charge;\n }\n }\n if (Object.keys(shorthand).length) {\n if (!Object.keys(cards).length) cards.standard = { operations: {} };\n for (const [cardKey, card] of Object.entries(cards)) {\n if (!object(card)) throw new ConfigError(`pricing.rate_cards.${cardKey} must be an object`);\n if (card.extends != null) continue;\n const operations = (card.operations ??= {});\n if (!object(operations))\n throw new ConfigError(`pricing.rate_cards.${cardKey}.operations must be an object`);\n for (const [key, value] of Object.entries(shorthand)) {\n if (Object.hasOwn(operations, key))\n throw new ConfigError(\n `pricing.operations.${key}.charge conflicts with pricing.rate_cards.${cardKey}.operations.${key}`,\n );\n operations[key] = value;\n }\n }\n }\n }\n if (object(result.plans))\n for (const plan of Object.values(result.plans)) {\n if (!object(plan)) continue;\n if (object(pricing) && object(pricing.rate_cards)) {\n const keys = Object.keys(pricing.rate_cards);\n if (keys.length === 1 && keys[0] !== undefined && plan.rate_card == null)\n plan.rate_card = keys[0];\n }\n }\n if (\n object(result.commerce) &&\n object(result.commerce.providers) &&\n object(result.commerce.offers)\n ) {\n const definitions = result.commerce.providers;\n for (const offer of Object.values(result.commerce.offers)) {\n if (!object(offer) || !object(offer.providers)) continue;\n for (const [key, reference] of Object.entries(offer.providers)) {\n const provider = definitions[key];\n if (!object(reference) || !object(provider) || \"type\" in reference) continue;\n if (provider.type === \"stripe\") reference.type = \"stripe_price\";\n if (provider.type === \"dodo\") reference.type = \"dodo_product\";\n }\n }\n }\n\n if (environment != null && object(result.commerce) && object(result.commerce.offers)) {\n for (const offer of Object.values(result.commerce.offers)) {\n if (!object(offer) || !object(offer.providers)) continue;\n for (const reference of Object.values(offer.providers)) {\n if (!object(reference)) continue;\n for (const field of [\"price_id\", \"product_id\", \"external_id\"]) {\n const value = reference[field];\n if (typeof value === \"string\") reference[field] = { [environment]: value };\n }\n }\n }\n }\n return result;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-access.d.ts","sourceRoot":"","sources":["../../src/config/parse-access.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAqB,MAAM,YAAY,CAAC;AAEzF,KAAK,eAAe,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"parse-access.d.ts","sourceRoot":"","sources":["../../src/config/parse-access.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAqB,MAAM,YAAY,CAAC;AAEzF,KAAK,eAAe,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAAE,CAAC;AAyDrE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,kBAAkB,CAYlF;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,eAAe,CAyB5E"}
|
|
@@ -40,12 +40,15 @@ function parseFeatureDefinition(value, path) {
|
|
|
40
40
|
const defaultValue = asString(feature.default, `${path}.default`);
|
|
41
41
|
const pattern = feature.pattern == null ? undefined : asString(feature.pattern, `${path}.pattern`);
|
|
42
42
|
if (pattern != null) {
|
|
43
|
+
let expression;
|
|
43
44
|
try {
|
|
44
|
-
new RegExp(pattern);
|
|
45
|
+
expression = new RegExp(pattern);
|
|
45
46
|
}
|
|
46
47
|
catch {
|
|
47
48
|
semanticError(`${path}.pattern must be a valid regular expression`);
|
|
48
49
|
}
|
|
50
|
+
if (!expression.test(defaultValue))
|
|
51
|
+
semanticError(`${path}.default must match pattern`);
|
|
49
52
|
}
|
|
50
53
|
return pattern == null
|
|
51
54
|
? { type, default: defa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GAAG,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAClC,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IACjD,mBAAmB,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;IACvD,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,WAAW,CAC1B,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/B,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;YACxD,mBAAmB,CAAC,aAAa,EAAE,sBAAsB,GAAG,aAAa,CAAC,CAAC;YAC3E,MAAM,YAAY,GAAoB;gBACpC,UAAU,EAAE,MAAM,CAAC,WAAW,CAC5B,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC;oBAC7D,SAAS;oBACT,EAAE,WAAW,EAAE,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC,EAAE;iBAC/D,CAAC,CACH;aACF,CAAC;YACF,IAAI,MAAM,CAAC,aAAa,IAAI,IAAI,EAAE,CAAC;gBACjC,YAAY,CAAC,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAC7D,CAAC;YACD,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC7B,CAAC,CAAC,CACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n asBoolean,\n asInteger,\n asObject,\n asString,\n asStringArray,\n semanticError,\n validateIdentifiers,\n} from \"./parse-utils.js\";\nimport type { JsonValue } from \"../shared/json.js\";\nimport type { AdmissionPolicy, EntitlementsConfig, FeatureDefinition } from \"./types.js\";\n\ntype ParsedAdmission = { policies: Record<string, AdmissionPolicy> };\n\nfunction parseFeatureDefinition(value: JsonValue, path: string): FeatureDefinition {\n const feature = asObject(value);\n const type = asString(feature.type, `${path}.type`);\n switch (type) {\n case \"boolean\":\n return { type, default: asBoolean(feature.default, `${path}.default`) };\n case \"enum\": {\n const values = asStringArray(feature.values, `${path}.values`);\n if (new Set(values).size !== values.length) semanticError(`${path}.values must be unique`);\n const defaultValue = asString(feature.default, `${path}.default`);\n if (!values.includes(defaultValue)) semanticError(`${path}.default must be one of values`);\n return { type, values, default: defaultValue };\n }\n case \"integer\": {\n const defaultValue = asInteger(feature.default, `${path}.default`);\n const minimum = feature.minimum == null ? undefined : asInteger(feature.minimum);\n const maximum = feature.maximum == null ? undefined : asInteger(feature.maximum);\n if (minimum != null && maximum != null && minimum > maximum) {\n semanticError(`${path}.minimum cannot exceed maximum`);\n }\n if (minimum != null && defaultValue < minimum)\n semanticError(`${path}.default is below minimum`);\n if (maximum != null && defaultValue > maximum) {\n semanticError(`${path}.default exceeds maximum`);\n }\n const result: Extract<FeatureDefinition, { type: \"integer\" }> = {\n type,\n default: defaultValue,\n };\n if (minimum != null) result.minimum = minimum;\n if (maximum != null) result.maximum = maximum;\n return result;\n }\n case \"string\": {\n const defaultValue = asString(feature.default, `${path}.default`);\n const pattern =\n feature.pattern == null ? undefined : asString(feature.pattern, `${path}.pattern`);\n if (pattern != null) {\n let expression: RegExp;\n try {\n expression = new RegExp(pattern);\n } catch {\n semanticError(`${path}.pattern must be a valid regular expression`);\n }\n if (!expression.test(defaultValue)) semanticError(`${path}.default must match pattern`);\n }\n return pattern == null\n ? { type, default: defaultValue }\n : { type, default: defaultValue, pattern };\n }\n default:\n semanticError(`${path}.type must be a supported feature type`);\n }\n}\n\nexport function parseEntitlements(value: JsonValue | undefined): EntitlementsConfig {\n const raw = asObject(value ?? {});\n const featuresRaw = asObject(raw.features ?? {});\n validateIdentifiers(featuresRaw, \"entitlements.features\");\n return {\n features: Object.fromEntries(\n Object.entries(featuresRaw).map(([key, input]) => [\n key,\n parseFeatureDefinition(input, `entitlements.features.${key}`),\n ]),\n ),\n };\n}\n\nexport function parseAdmission(value: JsonValue | undefined): ParsedAdmission {\n const raw = asObject(value ?? {});\n const policiesRaw = asObject(raw.policies ?? {});\n validateIdentifiers(policiesRaw, \"admission.policies\");\n return {\n policies: Object.fromEntries(\n Object.entries(policiesRaw).map(([key, input]) => {\n const policy = asObject(input);\n const operationsRaw = asObject(policy.operations ?? {});\n validateIdentifiers(operationsRaw, `admission.policies.${key}.operations`);\n const parsedPolicy: AdmissionPolicy = {\n operations: Object.fromEntries(\n Object.entries(operationsRaw).map(([operation, definition]) => [\n operation,\n { maxInFlight: asInteger(asObject(definition).max_in_flight) },\n ]),\n ),\n };\n if (policy.max_in_flight != null) {\n parsedPolicy.maxInFlight = asInteger(policy.max_in_flight);\n }\n return [key, parsedPolicy];\n }),\n ),\n };\n}\n"]}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { JsonValue } from "../shared/json.js";
|
|
2
|
-
import type { CommerceConfig, CreditsConfig } from "./types.js";
|
|
2
|
+
import type { CommerceConfig, CreditsConfig, ProviderReference, ProviderId } from "./types.js";
|
|
3
|
+
import type { ProviderEnvironment } from "../providers/environment.js";
|
|
4
|
+
/** Whether a provider reference is bound in the selected environment. */
|
|
5
|
+
export declare function hasProviderBinding(reference: ProviderReference, environment: ProviderEnvironment): boolean;
|
|
6
|
+
export declare function resolveProviderId(value: ProviderId, environment?: ProviderEnvironment): string;
|
|
3
7
|
export declare function parseCommerce(value: JsonValue | undefined, credits: CreditsConfig): CommerceConfig;
|
|
4
8
|
//# sourceMappingURL=parse-commerce.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-commerce.d.ts","sourceRoot":"","sources":["../../src/config/parse-commerce.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAEV,cAAc,EAEd,aAAa,
|
|
1
|
+
{"version":3,"file":"parse-commerce.d.ts","sourceRoot":"","sources":["../../src/config/parse-commerce.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAEV,cAAc,EAEd,aAAa,EAGb,iBAAiB,EACjB,UAAU,EAIX,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,yEAAyE;AACzE,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,iBAAiB,EAC5B,WAAW,EAAE,mBAAmB,GAC/B,OAAO,CAGT;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAO9F;AAgFD,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,OAAO,EAAE,aAAa,GACrB,cAAc,CAsKhB"}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { storedCredit, asInteger, asObject, asString, asStringArray, parseAvailability, parseBillingInterval, parseDuration, parseExpiry, parseWindow, semanticError, validateIdentifiers, } from "./parse-utils.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { ConfigError } from "../errors.js";
|
|
4
|
+
/** Whether a provider reference is bound in the selected environment. */
|
|
5
|
+
export function hasProviderBinding(reference, environment) {
|
|
6
|
+
const id = providerExternalId(reference);
|
|
7
|
+
return typeof id === "string" || id[environment] !== undefined;
|
|
8
|
+
}
|
|
9
|
+
export function resolveProviderId(value, environment) {
|
|
10
|
+
if (typeof value === "string")
|
|
11
|
+
return value;
|
|
12
|
+
if (!environment || !value[environment])
|
|
13
|
+
throw new ConfigError(`provider ID has no binding for environment ${environment ?? "<unspecified>"}`);
|
|
14
|
+
return value[environment];
|
|
15
|
+
}
|
|
16
|
+
function parseProviderId(value) {
|
|
17
|
+
if (typeof value === "string")
|
|
18
|
+
return value;
|
|
19
|
+
const mapping = asObject(value);
|
|
20
|
+
return z
|
|
21
|
+
.object({
|
|
22
|
+
test: z.string().optional(),
|
|
23
|
+
live: z.string().optional(),
|
|
24
|
+
sandbox: z.string().optional(),
|
|
25
|
+
})
|
|
26
|
+
.strict()
|
|
27
|
+
.parse(mapping);
|
|
28
|
+
}
|
|
3
29
|
const customObjectKindSchema = z.enum(["subscription", "one_time"]);
|
|
4
30
|
const taxBehaviorSchema = z.enum(["inclusive", "exclusive", "unspecified"]);
|
|
5
31
|
const renewalSchema = z.enum(["replace_previous", "accumulate"]);
|
|
@@ -10,15 +36,15 @@ const changePaymentFailureSchema = z.enum(["prevent_change", "apply_change"]);
|
|
|
10
36
|
function parseProviderReference(value) {
|
|
11
37
|
const raw = asObject(value);
|
|
12
38
|
if (raw.type === "stripe_price") {
|
|
13
|
-
return { type: "stripe_price", priceId:
|
|
39
|
+
return { type: "stripe_price", priceId: parseProviderId(raw.price_id) };
|
|
14
40
|
}
|
|
15
41
|
if (raw.type === "dodo_product") {
|
|
16
|
-
return { type: "dodo_product", productId:
|
|
42
|
+
return { type: "dodo_product", productId: parseProviderId(raw.product_id) };
|
|
17
43
|
}
|
|
18
44
|
return {
|
|
19
45
|
type: "custom_object",
|
|
20
46
|
objectKind: customObjectKindSchema.parse(raw.object_kind),
|
|
21
|
-
externalId:
|
|
47
|
+
externalId: parseProviderId(raw.external_id),
|
|
22
48
|
};
|
|
23
49
|
}
|
|
24
50
|
function providerExternalId(reference) {
|
|
@@ -63,11 +89,11 @@ export function parseCommerce(value, credits) {
|
|
|
63
89
|
return [key, parsedProvider];
|
|
64
90
|
}));
|
|
65
91
|
const offers = {};
|
|
66
|
-
const seenProviderObjects = new
|
|
92
|
+
const seenProviderObjects = new Map();
|
|
67
93
|
for (const [offerKey, input] of Object.entries(offersRaw)) {
|
|
68
94
|
const offer = asObject(input);
|
|
69
95
|
const references = Object.fromEntries(Object.entries(asObject(offer.providers)).map(([providerKey, inputReference]) => {
|
|
70
|
-
const provider = providers[providerKey];
|
|
96
|
+
const provider = Object.hasOwn(providers, providerKey) ? providers[providerKey] : undefined;
|
|
71
97
|
if (!provider) {
|
|
72
98
|
semanticError(`commerce.offers.${offerKey} references unknown provider`);
|
|
73
99
|
}
|
|
@@ -75,11 +101,18 @@ export function parseCommerce(value, credits) {
|
|
|
75
101
|
if (!providerReferenceIsCompatible(provider, reference)) {
|
|
76
102
|
semanticError(`commerce.offers.${offerKey} has incompatible provider reference`);
|
|
77
103
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
const id = providerExternalId(reference);
|
|
105
|
+
const bindings = typeof id === "string" ? [["*", id]] : Object.entries(id);
|
|
106
|
+
for (const [environment, value] of bindings) {
|
|
107
|
+
const key = JSON.stringify([providerKey, value]);
|
|
108
|
+
const environments = seenProviderObjects.get(key) ?? new Set();
|
|
109
|
+
if (environments.has(environment) ||
|
|
110
|
+
environments.has("*") ||
|
|
111
|
+
(environment === "*" && environments.size > 0))
|
|
112
|
+
semanticError(`duplicate provider object reference ${providerKey}/${environment}/${value}`);
|
|
113
|
+
environments.add(environment);
|
|
114
|
+
seenProviderObjects.set(key, environments);
|
|
81
115
|
}
|
|
82
|
-
seenProviderObjects.add(uniqueKey);
|
|
83
116
|
return [providerKey, reference];
|
|
84
117
|
}));
|
|
85
118
|
const common = {
|
|
@@ -101,12 +134,12 @@ export function parseCommerce(value, credits) {
|
|
|
101
134
|
const cycleGrant = cycleRaw == null
|
|
102
135
|
? undefined
|
|
103
136
|
: {
|
|
104
|
-
amount:
|
|
137
|
+
amount: storedCredit(cycleRaw.amount, `commerce.offers.${offerKey}.cycle_grant.amount`, true),
|
|
105
138
|
bucket: asString(cycleRaw.bucket),
|
|
106
139
|
renewal: renewalSchema.parse(cycleRaw.renewal),
|
|
107
140
|
expiry: parseExpiry(cycleRaw.expiry ?? { type: "subscription_end" }, `commerce.offers.${offerKey}.cycle_grant.expiry`),
|
|
108
141
|
};
|
|
109
|
-
if (cycleGrant != null && !credits.buckets
|
|
142
|
+
if (cycleGrant != null && !Object.hasOwn(credits.buckets, cycleGrant.bucket)) {
|
|
110
143
|
semanticError(`commerce.offers.${offerKey}.cycle_grant references unknown bucket`);
|
|
111
144
|
}
|
|
112
145
|
const subscriptionOffer = {
|
|
@@ -115,15 +148,28 @@ export function parseCommerce(value, credits) {
|
|
|
115
148
|
plan: asString(offer.plan),
|
|
116
149
|
billingInterval: parseBillingInterval(offer.billing_interval),
|
|
117
150
|
};
|
|
118
|
-
if (offer.trial != null)
|
|
119
|
-
|
|
151
|
+
if (offer.trial != null) {
|
|
152
|
+
const trial = parseBillingInterval(offer.trial);
|
|
153
|
+
const providerTypes = Object.keys(references).map((key) => providers[key]?.type);
|
|
154
|
+
if (providerTypes.some((type) => type === "stripe" || type === "dodo")) {
|
|
155
|
+
if (trial.unit !== "day" && trial.unit !== "week")
|
|
156
|
+
semanticError(`commerce.offers.${offerKey}.trial requires day or week units for Stripe and Dodo`);
|
|
157
|
+
const days = trial.count * (trial.unit === "week" ? 7 : 1);
|
|
158
|
+
if (!Number.isSafeInteger(days) ||
|
|
159
|
+
days < 1 ||
|
|
160
|
+
(providerTypes.includes("stripe") && days > 730) ||
|
|
161
|
+
(providerTypes.includes("dodo") && days > 10000))
|
|
162
|
+
semanticError(`commerce.offers.${offerKey}.trial is outside the supported provider range`);
|
|
163
|
+
}
|
|
164
|
+
subscriptionOffer.trial = trial;
|
|
165
|
+
}
|
|
120
166
|
if (cycleGrant != null)
|
|
121
167
|
subscriptionOffer.cycleGrant = cycleGrant;
|
|
122
168
|
offers[offerKey] = subscriptionOffer;
|
|
123
169
|
continue;
|
|
124
170
|
}
|
|
125
171
|
const bucket = asString(offer.bucket);
|
|
126
|
-
if (!credits.buckets
|
|
172
|
+
if (!Object.hasOwn(credits.buckets, bucket)) {
|
|
127
173
|
semanticError(`commerce.offers.${offerKey}.bucket references unknown bucket`);
|
|
128
174
|
}
|
|
129
175
|
const quantityRaw = asObject(offer.quantity ?? {});
|
|
@@ -142,7 +188,7 @@ export function parseCommerce(value, credits) {
|
|
|
142
188
|
const topupOffer = {
|
|
143
189
|
...common,
|
|
144
190
|
type: "topup",
|
|
145
|
-
creditsPerUnit:
|
|
191
|
+
creditsPerUnit: storedCredit(offer.credits_per_unit, `commerce.offers.${offerKey}.credits_per_unit`, true),
|
|
146
192
|
quantity: parsedQuantity,
|
|
147
193
|
bucket,
|
|
148
194
|
lotBehavior: lotBehaviorSchema.parse(offer.lot_behavior ?? "separate_lots"),
|
|
@@ -208,9 +254,9 @@ function parseAutoRecharge(value, offers) {
|
|
|
208
254
|
default: asInteger(quantity.default),
|
|
209
255
|
};
|
|
210
256
|
validateIntegerRange(parsedQuantity, "commerce.auto_recharge.quantity");
|
|
211
|
-
const parsedMinimum =
|
|
212
|
-
const parsedMaximum =
|
|
213
|
-
const parsedDefault =
|
|
257
|
+
const parsedMinimum = storedCredit(threshold.minimum, "commerce.auto_recharge.balance_below.minimum");
|
|
258
|
+
const parsedMaximum = storedCredit(threshold.maximum, "commerce.auto_recharge.balance_below.maximum");
|
|
259
|
+
const parsedDefault = storedCredit(threshold.default, "commerce.auto_recharge.balance_below.default");
|
|
214
260
|
if (parsedMinimum.gt(parsedMaximum) ||
|
|
215
261
|
parsedDefault.lt(parsedMinimum) ||
|
|
216
262
|
parsedDefault.gt(parsedMaximum)) {
|
|
@@ -226,14 +272,25 @@ function parseAutoRecharge(value, offers) {
|
|
|
226
272
|
semanticError(`commerce.auto_recharge.quantity must fit commerce.offers.${key}.quantity`);
|
|
227
273
|
}
|
|
228
274
|
}
|
|
229
|
-
const parsedRearmAbove =
|
|
230
|
-
if (parsedRearmAbove.lte(parsedMaximum)) {
|
|
275
|
+
const parsedRearmAbove = storedCredit(auto.rearm_above, "commerce.auto_recharge.rearm_above", true);
|
|
276
|
+
if (parsedRearmAbove.toDecimalPlaces(6).lte(parsedMaximum.toDecimalPlaces(6))) {
|
|
231
277
|
semanticError("commerce.auto_recharge.rearm_above must exceed balance_below.maximum");
|
|
232
278
|
}
|
|
233
279
|
const window = parseWindow(limits.window, "commerce.auto_recharge.limits.window");
|
|
234
280
|
if (window.type !== "calendar" && window.type !== "rolling") {
|
|
235
281
|
semanticError("commerce.auto_recharge.limits.window must be calendar or rolling");
|
|
236
282
|
}
|
|
283
|
+
const cooldown = parseDuration(limits.cooldown);
|
|
284
|
+
const multiplier = {
|
|
285
|
+
second: 1,
|
|
286
|
+
minute: 60,
|
|
287
|
+
hour: 3600,
|
|
288
|
+
day: 86400,
|
|
289
|
+
week: 604800,
|
|
290
|
+
}[cooldown.unit];
|
|
291
|
+
if (cooldown.count * multiplier > 2147483647) {
|
|
292
|
+
semanticError("commerce.auto_recharge.limits.cooldown exceeds the stored seconds range");
|
|
293
|
+
}
|
|
237
294
|
return {
|
|
238
295
|
eligibleTopups,
|
|
239
296
|
balanceBelow: {
|
|
@@ -247,7 +304,7 @@ function parseAutoRecharge(value, offers) {
|
|
|
247
304
|
maxPurchases: asInteger(limits.max_purchases),
|
|
248
305
|
window,
|
|
249
306
|
maxChargeMinor: asInteger(limits.max_charge_minor),
|
|
250
|
-
cooldown
|
|
307
|
+
cooldown,
|
|
251
308
|
maxConsecutiveFailures: asInteger(limits.max_consecutive_failures ?? 3),
|
|
252
309
|
failureAction: "pause",
|
|
253
310
|
},
|