@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,7 +1,8 @@
|
|
|
1
|
+
import { PricingDecimal } from "../../pricing-decimal.js";
|
|
1
2
|
import { Decimal } from "decimal.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { BillingStore } from "../billing-store.js";
|
|
4
|
-
import { PostgresClient, } from "../../shared/postgres-client.js";
|
|
5
|
+
import { PostgresClient, normalizeTenantId, } from "../../shared/postgres-client.js";
|
|
5
6
|
import { normalizeProviderEnvironment, } from "../../providers/environment.js";
|
|
6
7
|
import { StoreClosedError, StoreError } from "../../errors.js";
|
|
7
8
|
import { optionalBoundedDiagnosticMessage } from "../../shared/diagnostics.js";
|
|
@@ -29,7 +30,7 @@ const BillingCreditPostingRowSchema = z
|
|
|
29
30
|
balance_after: z
|
|
30
31
|
.union([z.string(), z.number(), z.instanceof(Decimal)])
|
|
31
32
|
.nullable()
|
|
32
|
-
.transform((value) => (value === null ? null : new
|
|
33
|
+
.transform((value) => (value === null ? null : new PricingDecimal(value))),
|
|
33
34
|
replayed: pgBoolean,
|
|
34
35
|
error_code: z.string().min(1).nullable(),
|
|
35
36
|
})
|
|
@@ -52,6 +53,7 @@ const CheckoutIntentRowSchema = z
|
|
|
52
53
|
request_digest: z.instanceof(Uint8Array).refine((value) => value.byteLength === 32),
|
|
53
54
|
status: z.enum(["open", "completed", "failed", "expired"]),
|
|
54
55
|
provider_session_id: z.string().min(1).nullable(),
|
|
56
|
+
provider_customer_id: z.string().min(1).nullable(),
|
|
55
57
|
checkout_url: z.string().min(1).nullable(),
|
|
56
58
|
expires_at: z.union([z.string().datetime({ offset: true }), z.date()]),
|
|
57
59
|
})
|
|
@@ -71,120 +73,110 @@ function billingCreditPostingResult(rows, context) {
|
|
|
71
73
|
errorCode: row.error_code,
|
|
72
74
|
};
|
|
73
75
|
}
|
|
76
|
+
const transactionScope = Symbol("billing transaction scope");
|
|
74
77
|
export class PostgresBillingStore extends BillingStore {
|
|
78
|
+
tenantId;
|
|
75
79
|
postgres;
|
|
80
|
+
scoped;
|
|
81
|
+
options;
|
|
76
82
|
providerEnvironment;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
queryFn;
|
|
84
|
+
billingOffer;
|
|
85
|
+
billingTopup;
|
|
86
|
+
billingCustomer;
|
|
87
|
+
billingSubscription;
|
|
88
|
+
billingEvent;
|
|
89
|
+
billingPayment;
|
|
90
|
+
billingRefund;
|
|
91
|
+
billingInvoice;
|
|
92
|
+
billingDispute;
|
|
93
|
+
billingPreferences;
|
|
94
|
+
billingAutoRecharge;
|
|
95
|
+
billingSubscriptionChange;
|
|
89
96
|
constructor(options) {
|
|
90
97
|
super();
|
|
98
|
+
// SAFETY: Only this module can attach the private transaction scope symbol.
|
|
99
|
+
const scope = options[transactionScope];
|
|
100
|
+
this.options = { ...options };
|
|
101
|
+
this.scoped = scope !== undefined;
|
|
91
102
|
if (!z.object({}).safeParse(options).success) {
|
|
92
103
|
throw new TypeError("PostgresBillingStore options are required");
|
|
93
104
|
}
|
|
94
105
|
if (!z.string().safeParse(options.postgres).success && options.poolConstructor !== undefined) {
|
|
95
106
|
throw new TypeError("poolConstructor cannot be used with an existing PostgreSQL pool");
|
|
96
107
|
}
|
|
97
|
-
|
|
98
|
-
this.providerEnvironment = providerEnvironment;
|
|
99
|
-
this.postgres =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
this.tenantId = normalizeTenantId(options.tenantId);
|
|
109
|
+
this.providerEnvironment = normalizeProviderEnvironment(options.providerEnvironment);
|
|
110
|
+
this.postgres =
|
|
111
|
+
scope?.postgres ??
|
|
112
|
+
new PostgresClient(options.postgres, {
|
|
113
|
+
tenantId: this.tenantId,
|
|
114
|
+
providerEnvironment: this.providerEnvironment,
|
|
115
|
+
poolConstructor: options.poolConstructor,
|
|
116
|
+
billingPayloadBackend: options.billingPayloadBackend,
|
|
117
|
+
connectionTimeoutMs: options.connectionTimeoutMs,
|
|
118
|
+
statementTimeoutMs: options.statementTimeoutMs,
|
|
119
|
+
idleTransactionTimeoutMs: options.idleTransactionTimeoutMs,
|
|
120
|
+
idleTimeoutMs: options.idleTimeoutMs,
|
|
121
|
+
maxConnections: options.maxConnections,
|
|
122
|
+
applicationName: options.applicationName,
|
|
123
|
+
onPoolError: options.onPoolError,
|
|
124
|
+
instrumentation: options.instrumentation,
|
|
125
|
+
closedError: () => new StoreClosedError("Billing store has been closed"),
|
|
126
|
+
});
|
|
127
|
+
this.queryFn = scope?.query ?? this.postgres.query;
|
|
128
|
+
this.billingOffer = new BillingOfferRepository(this.queryFn);
|
|
129
|
+
this.billingTopup = new BillingTopupRepository(this.queryFn);
|
|
130
|
+
this.billingCustomer = new BillingCustomerRepository(this.queryFn);
|
|
131
|
+
this.billingSubscription = new BillingSubscriptionRepository(this.queryFn);
|
|
132
|
+
this.billingEvent = new BillingEventRepository(this.queryFn);
|
|
133
|
+
this.billingPayment = new BillingPaymentRepository(this.queryFn);
|
|
134
|
+
this.billingRefund = new BillingRefundRepository(this.queryFn);
|
|
135
|
+
this.billingInvoice = new BillingInvoiceRepository(this.queryFn);
|
|
136
|
+
this.billingDispute = new BillingDisputeRepository(this.queryFn);
|
|
137
|
+
this.billingPreferences = new BillingPreferencesRepository(this.queryFn);
|
|
138
|
+
this.billingAutoRecharge = new BillingAutoRechargeRepository(this.queryFn);
|
|
139
|
+
this.billingSubscriptionChange = new BillingSubscriptionChangeRepository(this.queryFn);
|
|
140
|
+
}
|
|
141
|
+
async withBillingEventTransaction(action) {
|
|
142
|
+
if (this.scoped)
|
|
143
|
+
throw new TypeError("Nested billing event transactions are not supported");
|
|
144
|
+
return this.postgres.withTransaction(async (transactionQuery) => {
|
|
145
|
+
let active = true;
|
|
146
|
+
const queryFn = (text, params) => {
|
|
147
|
+
if (!active)
|
|
148
|
+
throw new StoreClosedError("Billing transaction has ended");
|
|
149
|
+
return transactionQuery(text, params);
|
|
150
|
+
};
|
|
151
|
+
const options = {
|
|
152
|
+
...this.options,
|
|
153
|
+
[transactionScope]: { postgres: this.postgres, query: queryFn },
|
|
154
|
+
};
|
|
155
|
+
const scoped = new PostgresBillingStore(options);
|
|
156
|
+
try {
|
|
157
|
+
return await action(scoped);
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
active = false;
|
|
161
|
+
}
|
|
112
162
|
});
|
|
113
163
|
}
|
|
164
|
+
async observeBillingInvoiceOutcome(provider, invoiceId, outcome) {
|
|
165
|
+
const rows = await this.queryFn("SELECT bursar.observe_billing_invoice_outcome($1, $2, $3) AS accepted", [provider, invoiceId, outcome]);
|
|
166
|
+
return requireResultField(rows, "accepted", pgBoolean, "observeBillingInvoiceOutcome");
|
|
167
|
+
}
|
|
114
168
|
async close() {
|
|
169
|
+
if (this.scoped)
|
|
170
|
+
throw new TypeError("Cannot close a scoped billing store");
|
|
115
171
|
await this.postgres.close();
|
|
116
172
|
}
|
|
117
|
-
get queryFn() {
|
|
118
|
-
return this.postgres.query;
|
|
119
|
-
}
|
|
120
|
-
get billingOffer() {
|
|
121
|
-
if (!this._offer)
|
|
122
|
-
this._offer = new BillingOfferRepository(this.queryFn);
|
|
123
|
-
return this._offer;
|
|
124
|
-
}
|
|
125
|
-
get billingTopup() {
|
|
126
|
-
if (!this._topup)
|
|
127
|
-
this._topup = new BillingTopupRepository(this.queryFn);
|
|
128
|
-
return this._topup;
|
|
129
|
-
}
|
|
130
|
-
get billingCustomer() {
|
|
131
|
-
if (!this._customer)
|
|
132
|
-
this._customer = new BillingCustomerRepository(this.queryFn);
|
|
133
|
-
return this._customer;
|
|
134
|
-
}
|
|
135
|
-
get billingSubscription() {
|
|
136
|
-
if (!this._subscription)
|
|
137
|
-
this._subscription = new BillingSubscriptionRepository(this.queryFn);
|
|
138
|
-
return this._subscription;
|
|
139
|
-
}
|
|
140
|
-
get billingEvent() {
|
|
141
|
-
if (!this._event)
|
|
142
|
-
this._event = new BillingEventRepository(this.queryFn);
|
|
143
|
-
return this._event;
|
|
144
|
-
}
|
|
145
|
-
get billingPayment() {
|
|
146
|
-
if (!this._payment)
|
|
147
|
-
this._payment = new BillingPaymentRepository(this.queryFn);
|
|
148
|
-
return this._payment;
|
|
149
|
-
}
|
|
150
|
-
get billingRefund() {
|
|
151
|
-
if (!this._refund)
|
|
152
|
-
this._refund = new BillingRefundRepository(this.queryFn);
|
|
153
|
-
return this._refund;
|
|
154
|
-
}
|
|
155
|
-
get billingInvoice() {
|
|
156
|
-
if (!this._invoice)
|
|
157
|
-
this._invoice = new BillingInvoiceRepository(this.queryFn);
|
|
158
|
-
return this._invoice;
|
|
159
|
-
}
|
|
160
|
-
get billingDispute() {
|
|
161
|
-
if (!this._dispute)
|
|
162
|
-
this._dispute = new BillingDisputeRepository(this.queryFn);
|
|
163
|
-
return this._dispute;
|
|
164
|
-
}
|
|
165
|
-
get billingPreferences() {
|
|
166
|
-
if (!this._preferences)
|
|
167
|
-
this._preferences = new BillingPreferencesRepository(this.queryFn);
|
|
168
|
-
return this._preferences;
|
|
169
|
-
}
|
|
170
|
-
get billingAutoRecharge() {
|
|
171
|
-
if (!this._autoRecharge)
|
|
172
|
-
this._autoRecharge = new BillingAutoRechargeRepository(this.queryFn);
|
|
173
|
-
return this._autoRecharge;
|
|
174
|
-
}
|
|
175
|
-
get billingSubscriptionChange() {
|
|
176
|
-
if (!this._subscriptionChange) {
|
|
177
|
-
this._subscriptionChange = new BillingSubscriptionChangeRepository(this.queryFn);
|
|
178
|
-
}
|
|
179
|
-
return this._subscriptionChange;
|
|
180
|
-
}
|
|
181
173
|
async createOrGetCheckoutIntent(input) {
|
|
182
174
|
const operationKey = requireStableKey(input.operationKey, "operationKey");
|
|
183
175
|
if (!/^[0-9a-fA-F]{64}$/.test(input.requestDigest)) {
|
|
184
176
|
throw new TypeError("requestDigest must be a 32-byte hex string");
|
|
185
177
|
}
|
|
186
178
|
const rows = await this.queryFn(`SELECT bursar.create_checkout_intent(
|
|
187
|
-
$1::uuid, $2, $3, $4, $5, decode($6, 'hex'), $7::timestamptz
|
|
179
|
+
$1::uuid, $2, $3, $4, $5, decode($6, 'hex'), $7::timestamptz, NULL, NULL, $8, $9::uuid, $10::uuid, $11
|
|
188
180
|
) AS id`, [
|
|
189
181
|
input.subjectId,
|
|
190
182
|
input.provider,
|
|
@@ -193,6 +185,10 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
193
185
|
input.productKey,
|
|
194
186
|
input.requestDigest,
|
|
195
187
|
input.expiresAt,
|
|
188
|
+
input.region ?? null,
|
|
189
|
+
input.expectedRevisionId ?? null,
|
|
190
|
+
input.accountId ?? input.subjectId,
|
|
191
|
+
input.providerCustomerId ?? null,
|
|
196
192
|
]);
|
|
197
193
|
const id = requireResultField(rows, "id", postgresUuid, "PostgresBillingStore.createOrGetCheckoutIntent");
|
|
198
194
|
const intent = await this.getCheckoutIntent(id, input.subjectId);
|
|
@@ -205,13 +201,38 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
205
201
|
return intent;
|
|
206
202
|
}
|
|
207
203
|
async updateCheckoutIntent(id, update) {
|
|
208
|
-
const rows = await this.queryFn(`SELECT bursar.advance_checkout_intent($1::uuid, $2, $3, $4) AS advanced`, [
|
|
204
|
+
const rows = await this.queryFn(`SELECT bursar.advance_checkout_intent($1::uuid, $2, $3, $4, $5, $6::uuid) AS advanced`, [
|
|
205
|
+
id,
|
|
206
|
+
update.status ?? null,
|
|
207
|
+
update.providerSessionId ?? null,
|
|
208
|
+
update.checkoutUrl ?? null,
|
|
209
|
+
update.expectedOwner?.provider ?? null,
|
|
210
|
+
update.expectedOwner?.accountId ?? null,
|
|
211
|
+
]);
|
|
209
212
|
if (!requireResultField(rows, "advanced", pgBoolean, "PostgresBillingStore.updateCheckoutIntent")) {
|
|
210
213
|
throw new StoreError(`checkout intent transition rejected: ${id}`, {
|
|
211
214
|
details: { checkoutIntentId: id },
|
|
212
215
|
});
|
|
213
216
|
}
|
|
214
217
|
}
|
|
218
|
+
async findCheckoutIntent(subjectId, operationKey, provider) {
|
|
219
|
+
const rows = await this.queryFn("SELECT * FROM bursar.find_checkout_intent($1::uuid, $2, $3)", [
|
|
220
|
+
subjectId,
|
|
221
|
+
operationKey,
|
|
222
|
+
provider ?? null,
|
|
223
|
+
]);
|
|
224
|
+
if (rows.length === 0)
|
|
225
|
+
return null;
|
|
226
|
+
if (rows.length !== 1)
|
|
227
|
+
throw new StoreError("checkout operation key matches multiple providers");
|
|
228
|
+
const row = rows[0];
|
|
229
|
+
const id = safeParse(postgresUuid, row.intent_id, "findCheckoutIntent.id");
|
|
230
|
+
const catalog = safeParse(z.record(z.string(), z.json()), row.source_document, "findCheckoutIntent.catalog");
|
|
231
|
+
const intent = await this.getCheckoutIntent(id, subjectId);
|
|
232
|
+
if (!intent)
|
|
233
|
+
throw new StoreError("checkout intent disappeared");
|
|
234
|
+
return { intent, catalog };
|
|
235
|
+
}
|
|
215
236
|
async getCheckoutIntent(id, subjectId) {
|
|
216
237
|
const rows = await this.queryFn(`SELECT * FROM bursar.get_checkout_intent($1::uuid, $2::uuid)`, [id, subjectId]);
|
|
217
238
|
if (rows.length === 0)
|
|
@@ -233,6 +254,7 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
233
254
|
request_digest: row.request_digest,
|
|
234
255
|
status: row.status,
|
|
235
256
|
provider_session_id: row.provider_session_id,
|
|
257
|
+
provider_customer_id: row.provider_customer_id,
|
|
236
258
|
checkout_url: row.checkout_url,
|
|
237
259
|
expires_at: row.expires_at,
|
|
238
260
|
}, "PostgresBillingStore.getCheckoutIntent"));
|
|
@@ -247,6 +269,7 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
247
269
|
requestDigest: Buffer.from(row.request_digest).toString("hex"),
|
|
248
270
|
status: row.status,
|
|
249
271
|
providerSessionId: row.provider_session_id,
|
|
272
|
+
providerCustomerId: row.provider_customer_id,
|
|
250
273
|
checkoutUrl: row.checkout_url,
|
|
251
274
|
expiresAt: row.expires_at instanceof Date ? row.expires_at.toISOString() : row.expires_at,
|
|
252
275
|
};
|
|
@@ -271,8 +294,8 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
271
294
|
},
|
|
272
295
|
};
|
|
273
296
|
}
|
|
274
|
-
async resolveBillingOffer(provider, productId, priceId) {
|
|
275
|
-
const r = await this.billingOffer.resolveByPrice(provider, priceId ?? null, productId ?? null);
|
|
297
|
+
async resolveBillingOffer(provider, productId, priceId, checkout) {
|
|
298
|
+
const r = await this.billingOffer.resolveByPrice(provider, priceId ?? null, productId ?? null, checkout);
|
|
276
299
|
return this.rowToOffer(r);
|
|
277
300
|
}
|
|
278
301
|
async resolveBillingOfferByLookup(provider, lookupKey) {
|
|
@@ -345,6 +368,9 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
345
368
|
}
|
|
346
369
|
return this.billingSubscriptionChange.create(subscription.id, input);
|
|
347
370
|
}
|
|
371
|
+
async findBillingSubscriptionChange(provider, subscriptionId, operationKey) {
|
|
372
|
+
return this.billingSubscriptionChange.find(provider, subscriptionId, operationKey);
|
|
373
|
+
}
|
|
348
374
|
async getOpenBillingSubscriptionChange(provider, providerSubscriptionId) {
|
|
349
375
|
return this.billingSubscriptionChange.getOpen(provider, providerSubscriptionId);
|
|
350
376
|
}
|
|
@@ -352,11 +378,11 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
352
378
|
const rows = await this.billingSubscription.listExpiredGraceSubscriptions(now, limit);
|
|
353
379
|
return rows.map((row) => this.rowToSubscriptionState(row));
|
|
354
380
|
}
|
|
355
|
-
async reconcileSubscriptionEntitlement(subjectId, subscriptionId, billingEventId, expectedStatus, expectedProviderUpdatedAt, planAssignedAt, applyEntitlement,
|
|
356
|
-
return this.billingSubscription.reconcileEntitlement(subjectId, subscriptionId, billingEventId, expectedStatus, expectedProviderUpdatedAt, planAssignedAt, applyEntitlement,
|
|
381
|
+
async reconcileSubscriptionEntitlement(subjectId, subscriptionId, billingEventId, expectedStatus, expectedProviderUpdatedAt, planAssignedAt, applyEntitlement, reason) {
|
|
382
|
+
return this.billingSubscription.reconcileEntitlement(subjectId, subscriptionId, billingEventId, expectedStatus, expectedProviderUpdatedAt, planAssignedAt, applyEntitlement, reason);
|
|
357
383
|
}
|
|
358
|
-
async expireSubscriptionGracePeriod(subjectId, subscriptionId, expectedGraceEndsAt, expiredAt
|
|
359
|
-
return this.billingSubscription.expireGracePeriod(subjectId, subscriptionId, expectedGraceEndsAt, expiredAt
|
|
384
|
+
async expireSubscriptionGracePeriod(subjectId, subscriptionId, expectedGraceEndsAt, expiredAt) {
|
|
385
|
+
return this.billingSubscription.expireGracePeriod(subjectId, subscriptionId, expectedGraceEndsAt, expiredAt);
|
|
360
386
|
}
|
|
361
387
|
async updateBillingSubscriptionChange(id, update) {
|
|
362
388
|
await this.billingSubscriptionChange.update(id, update);
|
|
@@ -385,6 +411,7 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
385
411
|
creditsPerUnit: r.credits_per_unit,
|
|
386
412
|
depositTo: r.bucket_key,
|
|
387
413
|
amountMinor: r.amount_minor,
|
|
414
|
+
taxBehavior: r.tax_behavior,
|
|
388
415
|
currency: r.currency,
|
|
389
416
|
minQuantity: r.min_quantity,
|
|
390
417
|
maxQuantity: r.max_quantity,
|
|
@@ -393,29 +420,16 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
393
420
|
maxAmountMinor,
|
|
394
421
|
};
|
|
395
422
|
}
|
|
396
|
-
async resolveCreditTopup(provider, productId, priceId) {
|
|
397
|
-
const r = await this.billingTopup.resolveByPrice(provider, priceId ?? null, productId ?? null);
|
|
423
|
+
async resolveCreditTopup(provider, productId, priceId, checkoutIntentId, subjectId, providerPaymentId, rechargeAttemptId, billingEventId) {
|
|
424
|
+
const r = await this.billingTopup.resolveByPrice(provider, priceId ?? null, productId ?? null, checkoutIntentId, subjectId, providerPaymentId, rechargeAttemptId, billingEventId);
|
|
398
425
|
return this.rowToTopup(r);
|
|
399
426
|
}
|
|
400
427
|
async resolveCreditTopupByLookup(provider, lookupKey) {
|
|
401
428
|
const r = await this.billingTopup.resolveByLookup(provider, lookupKey);
|
|
402
429
|
return this.rowToTopup(r);
|
|
403
430
|
}
|
|
404
|
-
async computeTopupCredits(amountMinor, topupConfig) {
|
|
405
|
-
if (!Number.isSafeInteger(amountMinor) || amountMinor < 0) {
|
|
406
|
-
throw new TypeError("amountMinor must be a non-negative safe integer");
|
|
407
|
-
}
|
|
408
|
-
const unitAmount = topupConfig.amountMinor;
|
|
409
|
-
if (unitAmount <= 0 || amountMinor % unitAmount !== 0)
|
|
410
|
-
return new Decimal(0);
|
|
411
|
-
const quantity = amountMinor / unitAmount;
|
|
412
|
-
if (quantity < topupConfig.minQuantity || quantity > topupConfig.maxQuantity) {
|
|
413
|
-
return new Decimal(0);
|
|
414
|
-
}
|
|
415
|
-
return topupConfig.creditsPerUnit.mul(quantity);
|
|
416
|
-
}
|
|
417
431
|
async upsertBillingPayment(options) {
|
|
418
|
-
return this.billingPayment.upsert(options
|
|
432
|
+
return this.billingPayment.upsert(options);
|
|
419
433
|
}
|
|
420
434
|
async createBillingCreditGrant(input) {
|
|
421
435
|
const rows = await this.queryFn("SELECT bursar.create_billing_credit_grant($1::uuid, $2::uuid, $3::uuid, $4, $5, $6::uuid) AS id", [
|
|
@@ -465,8 +479,11 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
465
479
|
}
|
|
466
480
|
await this.billingInvoice.upsert(options.userId, options.provider, options.providerInvoiceId, subscription?.id ? String(subscription.id) : null, options.status, options.amountDueMinor, options.amountPaidMinor, options.currency, options.periodStart ?? null, options.periodEnd ?? null, options.metadata ?? {}, options.providerUpdatedAt);
|
|
467
481
|
}
|
|
468
|
-
async listBillingInvoices(userId) {
|
|
469
|
-
return this.billingInvoice.listForUser(userId);
|
|
482
|
+
async listBillingInvoices(userId, options) {
|
|
483
|
+
return this.billingInvoice.listForUser(userId, options);
|
|
484
|
+
}
|
|
485
|
+
async hasBillingInvoice(userId, provider, providerInvoiceId) {
|
|
486
|
+
return this.billingInvoice.hasForUser(userId, provider, providerInvoiceId);
|
|
470
487
|
}
|
|
471
488
|
async upsertBillingDispute(options) {
|
|
472
489
|
const payment = await this.billingPayment.getForRefund(options.provider, options.providerPaymentId);
|
|
@@ -505,6 +522,7 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
505
522
|
}
|
|
506
523
|
rowToSubscriptionState(r) {
|
|
507
524
|
return {
|
|
525
|
+
cycleGrantCredits: r.cycle_grant_amount == null ? null : new PricingDecimal(r.cycle_grant_amount),
|
|
508
526
|
subscriptionId: r.id,
|
|
509
527
|
userId: r.user_id,
|
|
510
528
|
provider: r.provider,
|
|
@@ -529,16 +547,18 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
529
547
|
metadata: r.metadata,
|
|
530
548
|
};
|
|
531
549
|
}
|
|
532
|
-
async
|
|
550
|
+
async getActiveCatalogRevision() {
|
|
533
551
|
const rows = await this.queryFn("SELECT * FROM bursar.active_catalog_revision()", []);
|
|
534
|
-
const row = optionalRecordRow(rows, "PostgresBillingStore.
|
|
552
|
+
const row = optionalRecordRow(rows, "PostgresBillingStore.getActiveCatalogRevision");
|
|
535
553
|
if (row === null)
|
|
536
554
|
return null;
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
|
|
555
|
+
return {
|
|
556
|
+
id: safeParse(postgresUuid, row.id, "PostgresBillingStore.getActiveCatalogRevision.id"),
|
|
557
|
+
config: safeParse(z.record(z.string(), z.json()), row.source_document, "PostgresBillingStore.getActiveCatalogRevision.config"),
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
async getActiveCatalogDocument() {
|
|
561
|
+
return (await this.getActiveCatalogRevision())?.config ?? null;
|
|
542
562
|
}
|
|
543
563
|
async pseudonymizeFinancialSubject(userId) {
|
|
544
564
|
const rows = await this.queryFn(`SELECT bursar.pseudonymize_financial_subject($1::uuid) AS pseudonymized`, [userId]);
|
|
@@ -556,6 +576,9 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
556
576
|
async upsertAutoRechargeProfile(profile, options) {
|
|
557
577
|
return this.billingAutoRecharge.upsertProfile(profile, options);
|
|
558
578
|
}
|
|
579
|
+
async resumeAutoRechargeProfile(profile) {
|
|
580
|
+
return this.billingAutoRecharge.resumeProfile(profile);
|
|
581
|
+
}
|
|
559
582
|
async claimAutoRechargeAttempt(input) {
|
|
560
583
|
return this.billingAutoRecharge.claimAttempt(input);
|
|
561
584
|
}
|
|
@@ -565,6 +588,9 @@ export class PostgresBillingStore extends BillingStore {
|
|
|
565
588
|
async updateAutoRechargeAttemptByProviderPayment(input) {
|
|
566
589
|
return this.billingAutoRecharge.updateAttemptByProviderPayment(input);
|
|
567
590
|
}
|
|
591
|
+
async getAutoRechargeOperationalWindow(userId) {
|
|
592
|
+
return this.billingAutoRecharge.operationalWindow(userId);
|
|
593
|
+
}
|
|
568
594
|
async countAutoRechargeAttempts(userId, since) {
|
|
569
595
|
return this.billingAutoRecharge.countAttempts(userId, since);
|
|
570
596
|
}
|