@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,10 +1,11 @@
|
|
|
1
1
|
import { Decimal } from "decimal.js";
|
|
2
|
+
import { PricingDecimal } from "../../../pricing-decimal.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { StoreError } from "../../../errors.js";
|
|
4
5
|
import { postgresUuid, safeParse, unwrapJsonb } from "../../../shared/postgres-validation.js";
|
|
5
6
|
const PositiveDecimalSchema = z
|
|
6
7
|
.union([z.string(), z.number(), z.instanceof(Decimal)])
|
|
7
|
-
.transform((value) => new
|
|
8
|
+
.transform((value) => new PricingDecimal(value))
|
|
8
9
|
.refine((value) => value.isFinite() && value.gt(0), "expected a finite positive decimal");
|
|
9
10
|
const SafeMinorUnitsSchema = z
|
|
10
11
|
.union([z.string().regex(/^\d+$/), z.number().int().nonnegative().safe()])
|
|
@@ -17,6 +18,7 @@ const BillingTopupRowSchema = z
|
|
|
17
18
|
credits_per_unit: PositiveDecimalSchema,
|
|
18
19
|
bucket_key: z.string().min(1),
|
|
19
20
|
amount_minor: SafeMinorUnitsSchema,
|
|
21
|
+
tax_behavior: z.enum(["inclusive", "exclusive", "unspecified"]),
|
|
20
22
|
currency: z.string().regex(/^[A-Z]{3}$/),
|
|
21
23
|
min_quantity: z.number().int().positive(),
|
|
22
24
|
max_quantity: z.number().int().positive(),
|
|
@@ -25,7 +27,10 @@ const BillingTopupRowSchema = z
|
|
|
25
27
|
.strict()
|
|
26
28
|
.superRefine((row, ctx) => {
|
|
27
29
|
if (row.max_quantity < row.min_quantity) {
|
|
28
|
-
ctx.addIssue({
|
|
30
|
+
ctx.addIssue({
|
|
31
|
+
code: z.ZodIssueCode.custom,
|
|
32
|
+
message: "max_quantity is below min_quantity",
|
|
33
|
+
});
|
|
29
34
|
}
|
|
30
35
|
if (row.default_quantity < row.min_quantity || row.default_quantity > row.max_quantity) {
|
|
31
36
|
ctx.addIssue({
|
|
@@ -40,24 +45,35 @@ export class BillingTopupRepository {
|
|
|
40
45
|
constructor(query) {
|
|
41
46
|
this.query = query;
|
|
42
47
|
}
|
|
43
|
-
async resolveByPrice(provider, priceId, productId) {
|
|
48
|
+
async resolveByPrice(provider, priceId, productId, checkoutIntentId, subjectId, providerPaymentId, rechargeAttemptId, billingEventId) {
|
|
44
49
|
const lookupType = priceId !== null ? "price_id" : "product_id";
|
|
45
|
-
return this.resolve(provider, lookupType, priceId ?? productId, "resolveByPrice");
|
|
50
|
+
return this.resolve(provider, lookupType, priceId ?? productId, "resolveByPrice", checkoutIntentId, subjectId, providerPaymentId, rechargeAttemptId, billingEventId);
|
|
46
51
|
}
|
|
47
52
|
async resolveByLookup(provider, lookupKey) {
|
|
48
53
|
return this.resolve(provider, "external_id", lookupKey, "resolveByLookup");
|
|
49
54
|
}
|
|
50
|
-
async resolve(provider, lookupType, lookupValue, operation) {
|
|
55
|
+
async resolve(provider, lookupType, lookupValue, operation, checkoutIntentId, subjectId, providerPaymentId, rechargeAttemptId, billingEventId) {
|
|
51
56
|
if (!provider.trim())
|
|
52
57
|
throw new TypeError("provider must not be empty");
|
|
53
58
|
if (!lookupValue?.trim())
|
|
54
59
|
return null;
|
|
55
60
|
const context = `BillingTopupRepository.${operation}`;
|
|
56
|
-
const rows =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
const rows = providerPaymentId && subjectId
|
|
62
|
+
? await this.query("SELECT * FROM bursar.resolve_purchase_catalog_topup($1::uuid, $2, $3, $4, $5, $6::uuid, $7::uuid, $8::uuid)", [
|
|
63
|
+
subjectId,
|
|
64
|
+
provider,
|
|
65
|
+
providerPaymentId,
|
|
66
|
+
lookupType,
|
|
67
|
+
lookupValue,
|
|
68
|
+
checkoutIntentId ?? null,
|
|
69
|
+
rechargeAttemptId ?? null,
|
|
70
|
+
billingEventId ?? null,
|
|
71
|
+
])
|
|
72
|
+
: await this.query("SELECT * FROM bursar.resolve_catalog_topup($1, $2, $3)", [
|
|
73
|
+
provider,
|
|
74
|
+
lookupType,
|
|
75
|
+
lookupValue,
|
|
76
|
+
]);
|
|
61
77
|
if (rows.length > 1) {
|
|
62
78
|
throw new StoreError(`${context}: expected at most one top-up`, {
|
|
63
79
|
details: { rowCount: rows.length },
|
|
@@ -72,6 +88,7 @@ export class BillingTopupRepository {
|
|
|
72
88
|
credits_per_unit: raw.credits_per_unit,
|
|
73
89
|
bucket_key: raw.bucket_key,
|
|
74
90
|
amount_minor: raw.amount_minor,
|
|
91
|
+
tax_behavior: raw.tax_behavior,
|
|
75
92
|
currency: raw.currency,
|
|
76
93
|
min_quantity: raw.min_quantity,
|
|
77
94
|
max_quantity: raw.max_quantity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topup.js","sourceRoot":"","sources":["../../../../src/billing/postgres/repositories/topup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAE9F,MAAM,qBAAqB,GAAG,CAAC;KAC5B,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;KACtD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"topup.js","sourceRoot":"","sources":["../../../../src/billing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AC,EAAE,CAAC;YACpB,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,+BAA+B,EAAE;gBAC9D,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;aACnC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,GAAG,EAAE,EAAE,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;QACjC,OAAO,SAAS,CACd,qBAAqB,EACrB;YACE,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;YACtC,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;SACvC,EACD,OAAO,CACR,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Decimal } from \"decimal.js\";\nimport { PricingDecimal } from \"../../../pricing-decimal.js\";\nimport { z } from \"zod\";\nimport { StoreError } from \"../../../errors.js\";\nimport type { QueryFn } from \"../../../shared/postgres-types.js\";\nimport { postgresUuid, safeParse, unwrapJsonb } from \"../../../shared/postgres-validation.js\";\n\nconst PositiveDecimalSchema = z\n .union([z.string(), z.number(), z.instanceof(Decimal)])\n .transform((value) => new PricingDecimal(value))\n .refine((value) => value.isFinite() && value.gt(0), \"expected a finite positive decimal\");\n\nconst SafeMinorUnitsSchema = z\n .union([z.string().regex(/^\\d+$/), z.number().int().nonnegative().safe()])\n .transform(Number)\n .refine(Number.isSafeInteger, \"minor-unit amount exceeds JavaScript's safe integer range\");\n\nconst BillingTopupRowSchema = z\n .object({\n id: postgresUuid,\n topup_key: z.string().min(1),\n credits_per_unit: PositiveDecimalSchema,\n bucket_key: z.string().min(1),\n amount_minor: SafeMinorUnitsSchema,\n tax_behavior: z.enum([\"inclusive\", \"exclusive\", \"unspecified\"]),\n currency: z.string().regex(/^[A-Z]{3}$/),\n min_quantity: z.number().int().positive(),\n max_quantity: z.number().int().positive(),\n default_quantity: z.number().int().positive(),\n })\n .strict()\n .superRefine((row, ctx) => {\n if (row.max_quantity < row.min_quantity) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"max_quantity is below min_quantity\",\n });\n }\n if (row.default_quantity < row.min_quantity || row.default_quantity > row.max_quantity) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"default_quantity is outside the configured range\",\n });\n }\n });\n\nexport type BillingTopupRow = z.infer<typeof BillingTopupRowSchema>;\n\n/** Repository for credit top-up resolution. */\nexport class BillingTopupRepository {\n constructor(private readonly query: QueryFn) {}\n\n async resolveByPrice(\n provider: string,\n priceId: string | null,\n productId: string | null,\n checkoutIntentId?: string | null,\n subjectId?: string | null,\n providerPaymentId?: string | null,\n rechargeAttemptId?: string | null,\n billingEventId?: string | null,\n ): Promise<BillingTopupRow | null> {\n const lookupType = priceId !== null ? \"price_id\" : \"product_id\";\n return this.resolve(\n provider,\n lookupType,\n priceId ?? productId,\n \"resolveByPrice\",\n checkoutIntentId,\n subjectId,\n providerPaymentId,\n rechargeAttemptId,\n billingEventId,\n );\n }\n\n async resolveByLookup(provider: string, lookupKey: string): Promise<BillingTopupRow | null> {\n return this.resolve(provider, \"external_id\", lookupKey, \"resolveByLookup\");\n }\n\n private async resolve(\n provider: string,\n lookupType: \"price_id\" | \"product_id\" | \"external_id\",\n lookupValue: string | null,\n operation: string,\n checkoutIntentId?: string | null,\n subjectId?: string | null,\n providerPaymentId?: string | null,\n rechargeAttemptId?: string | null,\n billingEventId?: string | null,\n ): Promise<BillingTopupRow | null> {\n if (!provider.trim()) throw new TypeError(\"provider must not be empty\");\n if (!lookupValue?.trim()) return null;\n\n const context = `BillingTopupRepository.${operation}`;\n const rows =\n providerPaymentId && subjectId\n ? await this.query(\n \"SELECT * FROM bursar.resolve_purchase_catalog_topup($1::uuid, $2, $3, $4, $5, $6::uuid, $7::uuid, $8::uuid)\",\n [\n subjectId,\n provider,\n providerPaymentId,\n lookupType,\n lookupValue,\n checkoutIntentId ?? null,\n rechargeAttemptId ?? null,\n billingEventId ?? null,\n ],\n )\n : await this.query(\"SELECT * FROM bursar.resolve_catalog_topup($1, $2, $3)\", [\n provider,\n lookupType,\n lookupValue,\n ]);\n if (rows.length > 1) {\n throw new StoreError(`${context}: expected at most one top-up`, {\n details: { rowCount: rows.length },\n });\n }\n const raw = unwrapJsonb(rows);\n if (raw?.id == null) return null;\n return safeParse(\n BillingTopupRowSchema,\n {\n id: raw.id,\n topup_key: raw.topup_key,\n credits_per_unit: raw.credits_per_unit,\n bucket_key: raw.bucket_key,\n amount_minor: raw.amount_minor,\n tax_behavior: raw.tax_behavior,\n currency: raw.currency,\n min_quantity: raw.min_quantity,\n max_quantity: raw.max_quantity,\n default_quantity: raw.default_quantity,\n },\n context,\n );\n }\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Decimal } from "decimal.js";
|
|
2
1
|
import type { JsonObject } from "../../shared/json.js";
|
|
3
|
-
import type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile, BillingCreditPostingResult, BillingCustomerRecord, BillingEventClaim, BillingOfferResult, BillingPaymentRecord, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, BillingSubscriptionStatus, SubscriptionEntitlementOutcome, CheckoutIntent, BillingTopupResult } from "../types/index.js";
|
|
2
|
+
import type { BillingAutoRechargeAttempt, BillingAutoRechargeProfile, BillingCreditPostingResult, BillingCustomerRecord, BillingEventClaim, BillingOfferResult, BillingPaymentRecord, BillingPreferences, BillingSubscriptionChange, BillingSubscriptionChangeInput, BillingSubscriptionState, BillingSubscriptionStatus, SubscriptionEntitlementOutcome, CheckoutIntent, BillingTopupResult, ListBillingInvoicesOptions } from "../types/index.js";
|
|
4
3
|
import { BillingStore } from "../billing-store.js";
|
|
5
4
|
import type { AutoRechargeAttemptClaim, AutoRechargeAttemptUpdate, AutoRechargeProviderPaymentUpdate, BillingCreditGrantCreate, BillingDisputeUpsert, BillingInvoiceUpsert, BillingPaymentUpsert, BillingRefundUpsert, BillingSubscriptionChangeUpdate, BillingSubscriptionConflictCreate, CheckoutIntentCreate, CheckoutIntentUpdate } from "../contracts.js";
|
|
6
5
|
import { type PostgresConnectionOptions, type PostgresPool, type PostgresPoolConstructor } from "../../shared/postgres-client.js";
|
|
@@ -17,41 +16,42 @@ export interface PostgresBillingStoreOptions extends Omit<PostgresConnectionOpti
|
|
|
17
16
|
billingPayloadBackend?: "postgres" | "s3";
|
|
18
17
|
}
|
|
19
18
|
export declare class PostgresBillingStore extends BillingStore {
|
|
19
|
+
readonly tenantId: string;
|
|
20
20
|
private readonly postgres;
|
|
21
|
+
private readonly scoped;
|
|
22
|
+
private readonly options;
|
|
21
23
|
readonly providerEnvironment: ProviderEnvironment;
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
27
|
-
private
|
|
28
|
-
private
|
|
29
|
-
private
|
|
30
|
-
private
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
private
|
|
24
|
+
private readonly queryFn;
|
|
25
|
+
private readonly billingOffer;
|
|
26
|
+
private readonly billingTopup;
|
|
27
|
+
private readonly billingCustomer;
|
|
28
|
+
private readonly billingSubscription;
|
|
29
|
+
private readonly billingEvent;
|
|
30
|
+
private readonly billingPayment;
|
|
31
|
+
private readonly billingRefund;
|
|
32
|
+
private readonly billingInvoice;
|
|
33
|
+
private readonly billingDispute;
|
|
34
|
+
private readonly billingPreferences;
|
|
35
|
+
private readonly billingAutoRecharge;
|
|
36
|
+
private readonly billingSubscriptionChange;
|
|
34
37
|
constructor(options: PostgresBillingStoreOptions);
|
|
38
|
+
withBillingEventTransaction<T>(action: (store: BillingStore) => Promise<T>): Promise<T>;
|
|
39
|
+
observeBillingInvoiceOutcome(provider: string, invoiceId: string, outcome: "paid" | "failed"): Promise<boolean>;
|
|
35
40
|
close(): Promise<void>;
|
|
36
|
-
private get queryFn();
|
|
37
|
-
private get billingOffer();
|
|
38
|
-
private get billingTopup();
|
|
39
|
-
private get billingCustomer();
|
|
40
|
-
private get billingSubscription();
|
|
41
|
-
private get billingEvent();
|
|
42
|
-
private get billingPayment();
|
|
43
|
-
private get billingRefund();
|
|
44
|
-
private get billingInvoice();
|
|
45
|
-
private get billingDispute();
|
|
46
|
-
private get billingPreferences();
|
|
47
|
-
private get billingAutoRecharge();
|
|
48
|
-
private get billingSubscriptionChange();
|
|
49
41
|
createOrGetCheckoutIntent(input: CheckoutIntentCreate): Promise<CheckoutIntent>;
|
|
50
42
|
updateCheckoutIntent(id: string, update: CheckoutIntentUpdate): Promise<void>;
|
|
43
|
+
findCheckoutIntent(subjectId: string, operationKey: string, provider?: string): Promise<{
|
|
44
|
+
intent: CheckoutIntent;
|
|
45
|
+
catalog: JsonObject;
|
|
46
|
+
} | null>;
|
|
51
47
|
getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;
|
|
52
48
|
private rowToCheckoutIntent;
|
|
53
49
|
private rowToOffer;
|
|
54
|
-
resolveBillingOffer(provider: string, productId?: string | null, priceId?: string | null
|
|
50
|
+
resolveBillingOffer(provider: string, productId?: string | null, priceId?: string | null, checkout?: {
|
|
51
|
+
accountId: string;
|
|
52
|
+
intentId: string;
|
|
53
|
+
lookupKey?: string | null;
|
|
54
|
+
}): Promise<BillingOfferResult | null>;
|
|
55
55
|
resolveBillingOfferByLookup(provider: string, lookupKey: string): Promise<BillingOfferResult | null>;
|
|
56
56
|
claimBillingEvent(provider: string, eventId: string, eventType: string, envelope?: JsonObject): Promise<BillingEventClaim>;
|
|
57
57
|
completeBillingEvent(provider: string, eventId: string, claimToken: string): Promise<boolean>;
|
|
@@ -61,18 +61,18 @@ export declare class PostgresBillingStore extends BillingStore {
|
|
|
61
61
|
getBillingCustomer(provider: string, providerCustomerId: string): Promise<string | null>;
|
|
62
62
|
getBillingSubscription(provider: string, providerSubscriptionId: string): Promise<BillingSubscriptionState | null>;
|
|
63
63
|
createBillingSubscriptionChange(input: BillingSubscriptionChangeInput): Promise<BillingSubscriptionChange>;
|
|
64
|
+
findBillingSubscriptionChange(provider: string, subscriptionId: string, operationKey: string): Promise<BillingSubscriptionChange | null>;
|
|
64
65
|
getOpenBillingSubscriptionChange(provider: string, providerSubscriptionId: string): Promise<BillingSubscriptionChange | null>;
|
|
65
66
|
listExpiredGraceSubscriptions(now: string, limit?: number): Promise<BillingSubscriptionState[]>;
|
|
66
|
-
reconcileSubscriptionEntitlement(subjectId: string, subscriptionId: string, billingEventId: string, expectedStatus: BillingSubscriptionStatus, expectedProviderUpdatedAt: string, planAssignedAt: Date | string | null, applyEntitlement: boolean,
|
|
67
|
-
expireSubscriptionGracePeriod(subjectId: string, subscriptionId: string, expectedGraceEndsAt: string, expiredAt: string
|
|
67
|
+
reconcileSubscriptionEntitlement(subjectId: string, subscriptionId: string, billingEventId: string, expectedStatus: BillingSubscriptionStatus, expectedProviderUpdatedAt: string, planAssignedAt: Date | string | null, applyEntitlement: boolean, reason: string): Promise<SubscriptionEntitlementOutcome>;
|
|
68
|
+
expireSubscriptionGracePeriod(subjectId: string, subscriptionId: string, expectedGraceEndsAt: string, expiredAt: string): Promise<boolean>;
|
|
68
69
|
updateBillingSubscriptionChange(id: string, update: BillingSubscriptionChangeUpdate): Promise<void>;
|
|
69
70
|
getUserSubscription(userId: string, statuses?: string[]): Promise<BillingSubscriptionState | null>;
|
|
70
71
|
getUserSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;
|
|
71
72
|
recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void>;
|
|
72
73
|
private rowToTopup;
|
|
73
|
-
resolveCreditTopup(provider: string, productId?: string | null, priceId?: string | null): Promise<BillingTopupResult | null>;
|
|
74
|
+
resolveCreditTopup(provider: string, productId?: string | null, priceId?: string | null, checkoutIntentId?: string | null, subjectId?: string | null, providerPaymentId?: string | null, rechargeAttemptId?: string | null, billingEventId?: string | null): Promise<BillingTopupResult | null>;
|
|
74
75
|
resolveCreditTopupByLookup(provider: string, lookupKey: string): Promise<BillingTopupResult | null>;
|
|
75
|
-
computeTopupCredits(amountMinor: number, topupConfig: BillingTopupResult): Promise<Decimal>;
|
|
76
76
|
upsertBillingPayment(options: BillingPaymentUpsert): Promise<string>;
|
|
77
77
|
createBillingCreditGrant(input: BillingCreditGrantCreate): Promise<string>;
|
|
78
78
|
grantBillingCredit(grantId: string, idempotencyKey: string): Promise<BillingCreditPostingResult>;
|
|
@@ -80,10 +80,15 @@ export declare class PostgresBillingStore extends BillingStore {
|
|
|
80
80
|
postBillingRefund(refundId: string, grantId: string, amountMinor: number, idempotencyKey: string): Promise<BillingCreditPostingResult>;
|
|
81
81
|
upsertBillingRefund(options: BillingRefundUpsert): Promise<string>;
|
|
82
82
|
upsertBillingInvoice(options: BillingInvoiceUpsert): Promise<void>;
|
|
83
|
-
listBillingInvoices(userId: string): Promise<import("../
|
|
83
|
+
listBillingInvoices(userId: string, options?: ListBillingInvoicesOptions): Promise<import("../index.js").BillingInvoicePage>;
|
|
84
|
+
hasBillingInvoice(userId: string, provider: string, providerInvoiceId: string): Promise<boolean>;
|
|
84
85
|
upsertBillingDispute(options: BillingDisputeUpsert): Promise<void>;
|
|
85
86
|
getBillingPayment(provider: string, providerPaymentId: string): Promise<BillingPaymentRecord | null>;
|
|
86
87
|
private rowToSubscriptionState;
|
|
88
|
+
getActiveCatalogRevision(): Promise<{
|
|
89
|
+
id: string;
|
|
90
|
+
config: JsonObject;
|
|
91
|
+
} | null>;
|
|
87
92
|
getActiveCatalogDocument(): Promise<JsonObject | null>;
|
|
88
93
|
pseudonymizeFinancialSubject(userId: string): Promise<boolean>;
|
|
89
94
|
getBillingPreferences(userId: string): Promise<BillingPreferences | null>;
|
|
@@ -92,9 +97,16 @@ export declare class PostgresBillingStore extends BillingStore {
|
|
|
92
97
|
upsertAutoRechargeProfile(profile: BillingAutoRechargeProfile, options?: {
|
|
93
98
|
resetCooldown?: boolean;
|
|
94
99
|
}): Promise<void>;
|
|
100
|
+
resumeAutoRechargeProfile(profile: BillingAutoRechargeProfile): Promise<boolean>;
|
|
95
101
|
claimAutoRechargeAttempt(input: AutoRechargeAttemptClaim): Promise<BillingAutoRechargeAttempt | null>;
|
|
96
102
|
updateAutoRechargeAttempt(input: AutoRechargeAttemptUpdate): Promise<void>;
|
|
97
|
-
updateAutoRechargeAttemptByProviderPayment(input: AutoRechargeProviderPaymentUpdate): Promise<
|
|
103
|
+
updateAutoRechargeAttemptByProviderPayment(input: AutoRechargeProviderPaymentUpdate): Promise<boolean>;
|
|
104
|
+
getAutoRechargeOperationalWindow(userId: string): Promise<{
|
|
105
|
+
maxRecharges: number;
|
|
106
|
+
windowStart: string;
|
|
107
|
+
windowEnd: string;
|
|
108
|
+
count: number;
|
|
109
|
+
} | null>;
|
|
98
110
|
countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number>;
|
|
99
111
|
getBillingCustomerByUserId(userId: string, provider?: string | null): Promise<BillingCustomerRecord | null>;
|
|
100
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/billing/postgres/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/billing/postgres/store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAk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