@zonastery/bursar 1.0.0 → 2.0.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 +189 -62
- package/dist/billing/auto-recharge-port.d.ts +3 -3
- 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 +5 -4
- package/dist/billing/auto-recharge-service.d.ts.map +1 -1
- package/dist/billing/auto-recharge-service.js +64 -34
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.d.ts +5 -5
- package/dist/billing/billing-service.d.ts.map +1 -1
- package/dist/billing/billing-service.js +2 -2
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +10 -9
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.d.ts +31 -31
- package/dist/billing/contracts.d.ts.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +49 -10
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +1 -0
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +37 -10
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/financial-event-handlers.d.ts.map +1 -1
- package/dist/billing/financial-event-handlers.js +69 -72
- package/dist/billing/financial-event-handlers.js.map +1 -1
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.d.ts +5 -5
- package/dist/billing/management.d.ts.map +1 -1
- package/dist/billing/management.js +2 -2
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/policy-window.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts +3 -3
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +205 -60
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/customer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/customer.js +19 -11
- package/dist/billing/postgres/repositories/customer.js.map +1 -1
- package/dist/billing/postgres/repositories/dispute.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/dispute.js +3 -1
- package/dist/billing/postgres/repositories/dispute.js.map +1 -1
- package/dist/billing/postgres/repositories/event.d.ts +14 -7
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +21 -20
- package/dist/billing/postgres/repositories/event.js.map +1 -1
- package/dist/billing/postgres/repositories/invoice.d.ts +3 -3
- package/dist/billing/postgres/repositories/invoice.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/invoice.js +53 -11
- package/dist/billing/postgres/repositories/invoice.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.d.ts +20 -17
- package/dist/billing/postgres/repositories/offer.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/offer.js +123 -57
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/payment.d.ts +23 -20
- package/dist/billing/postgres/repositories/payment.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/payment.js +43 -37
- package/dist/billing/postgres/repositories/payment.js.map +1 -1
- package/dist/billing/postgres/repositories/preferences.d.ts +3 -9
- package/dist/billing/postgres/repositories/preferences.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/preferences.js +45 -7
- package/dist/billing/postgres/repositories/preferences.js.map +1 -1
- package/dist/billing/postgres/repositories/refund.d.ts +1 -1
- package/dist/billing/postgres/repositories/refund.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/refund.js +13 -9
- package/dist/billing/postgres/repositories/refund.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription-change.d.ts +15 -0
- package/dist/billing/postgres/repositories/subscription-change.d.ts.map +1 -0
- package/dist/billing/postgres/repositories/subscription-change.js +234 -0
- package/dist/billing/postgres/repositories/subscription-change.js.map +1 -0
- package/dist/billing/postgres/repositories/subscription.d.ts +38 -17
- package/dist/billing/postgres/repositories/subscription.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js +199 -91
- package/dist/billing/postgres/repositories/subscription.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.d.ts +13 -15
- package/dist/billing/postgres/repositories/topup.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/topup.js +65 -34
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +23 -14
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +265 -228
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/service-types.d.ts +6 -5
- 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 +6 -4
- 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 +18 -35
- package/dist/billing/types/catalog.d.ts.map +1 -1
- package/dist/billing/types/catalog.js.map +1 -1
- package/dist/billing/types/common.d.ts +0 -1
- package/dist/billing/types/common.d.ts.map +1 -1
- package/dist/billing/types/common.js.map +1 -1
- package/dist/billing/types/documents.d.ts +38 -12
- 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 +238 -0
- package/dist/billing/types/events.js.map +1 -1
- package/dist/billing/types/index.js.map +1 -1
- package/dist/billing/types/preferences.js.map +1 -1
- package/dist/billing/types/subscriptions.d.ts +8 -8
- package/dist/billing/types/subscriptions.d.ts.map +1 -1
- package/dist/billing/types/subscriptions.js.map +1 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/bursar.d.ts +33 -11
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +58 -22
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +1 -0
- package/dist/catalog.js.map +1 -1
- package/dist/commerce/errors.d.ts +4 -14
- package/dist/commerce/errors.d.ts.map +1 -1
- package/dist/commerce/errors.js +4 -21
- package/dist/commerce/errors.js.map +1 -1
- package/dist/commerce/index.d.ts +1 -0
- package/dist/commerce/index.d.ts.map +1 -1
- package/dist/commerce/index.js.map +1 -1
- 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 +27 -2
- package/dist/commerce/provider-registry.js.map +1 -1
- package/dist/commerce/service.d.ts +15 -7
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +130 -77
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +33 -13
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-access.js.map +1 -1
- package/dist/config/parse-commerce.js.map +1 -1
- 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 +30 -13
- 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 +16 -5
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +14 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.d.ts +7 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -1
- package/dist/config.js.map +1 -1
- package/dist/credits/{pricing-runtime.d.ts → catalog-runtime.d.ts} +9 -8
- package/dist/credits/catalog-runtime.d.ts.map +1 -0
- package/dist/credits/{pricing-runtime.js → catalog-runtime.js} +58 -38
- package/dist/credits/catalog-runtime.js.map +1 -0
- package/dist/credits/events.d.ts +4 -4
- package/dist/credits/events.d.ts.map +1 -1
- package/dist/credits/events.js +1 -1
- package/dist/credits/events.js.map +1 -1
- package/dist/credits/lease-workflow.d.ts +14 -14
- package/dist/credits/lease-workflow.d.ts.map +1 -1
- package/dist/credits/lease-workflow.js +18 -17
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.d.ts +2 -2
- package/dist/credits/low-balance-monitor.d.ts.map +1 -1
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/analytics.d.ts +39 -35
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +55 -53
- package/dist/credits/postgres/repositories/analytics.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.d.ts +28 -30
- package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/balance.js +100 -59
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.d.ts +14 -8
- package/dist/credits/postgres/repositories/bucket.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js +22 -21
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/catalog.d.ts +31 -0
- package/dist/credits/postgres/repositories/catalog.d.ts.map +1 -0
- package/dist/credits/postgres/repositories/catalog.js +90 -0
- package/dist/credits/postgres/repositories/catalog.js.map +1 -0
- package/dist/credits/postgres/repositories/deduction.d.ts +32 -21
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +171 -62
- package/dist/credits/postgres/repositories/deduction.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.d.ts +21 -18
- package/dist/credits/postgres/repositories/lease.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/lease.js +157 -65
- package/dist/credits/postgres/repositories/lease.js.map +1 -1
- package/dist/credits/postgres/repositories/plan.d.ts +94 -42
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +134 -104
- package/dist/credits/postgres/repositories/plan.js.map +1 -1
- package/dist/credits/postgres/repositories/team.d.ts +36 -27
- package/dist/credits/postgres/repositories/team.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/team.js +96 -52
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +31 -21
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +325 -235
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts +7 -9
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +42 -63
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/queries.d.ts +5 -5
- package/dist/credits/queries.d.ts.map +1 -1
- package/dist/credits/queries.js +4 -4
- package/dist/credits/queries.js.map +1 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.d.ts +42 -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 +51 -58
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +178 -113
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +25 -22
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +9 -5
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +50 -12
- 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 +17 -6
- package/dist/credits/types/admission.d.ts.map +1 -1
- package/dist/credits/types/admission.js.map +1 -1
- package/dist/credits/types/analytics.d.ts +2 -2
- package/dist/credits/types/analytics.d.ts.map +1 -1
- package/dist/credits/types/analytics.js.map +1 -1
- package/dist/credits/types/catalog.d.ts +21 -14
- 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 +22 -8
- package/dist/credits/types/grants.d.ts.map +1 -1
- package/dist/credits/types/grants.js.map +1 -1
- package/dist/credits/types/index.js.map +1 -1
- package/dist/credits/types/ledger.d.ts +19 -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.js.map +1 -1
- package/dist/credits/types/teams.d.ts +18 -6
- package/dist/credits/types/teams.d.ts.map +1 -1
- package/dist/credits/types/teams.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +24 -10
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +105 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +137 -9
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.d.ts.map +1 -1
- package/dist/expr/ast.js.map +1 -1
- package/dist/expr/evaluator.d.ts.map +1 -1
- package/dist/expr/evaluator.js +29 -17
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr/language.js.map +1 -1
- package/dist/expr/parser.d.ts.map +1 -1
- package/dist/expr/parser.js +11 -4
- package/dist/expr/parser.js.map +1 -1
- package/dist/expr/tokenizer.d.ts.map +1 -1
- package/dist/expr/tokenizer.js +17 -13
- package/dist/expr/tokenizer.js.map +1 -1
- package/dist/expr.d.ts +2 -2
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +7 -9
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +30 -9
- package/dist/generated/pricing-config.types.d.ts +14 -3
- 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 +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/better-auth.d.ts +23 -0
- package/dist/integrations/better-auth.d.ts.map +1 -0
- package/dist/integrations/better-auth.js +54 -0
- package/dist/integrations/better-auth.js.map +1 -0
- package/dist/{load-pricing-file.d.ts → load-config-file.d.ts} +4 -4
- package/dist/load-config-file.d.ts.map +1 -0
- package/dist/{load-pricing-file.js → load-config-file.js} +23 -14
- package/dist/load-config-file.js.map +1 -0
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +3 -3
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -2
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts +5 -0
- package/dist/providers/_shared.d.ts.map +1 -1
- package/dist/providers/_shared.js +77 -14
- package/dist/providers/_shared.js.map +1 -1
- package/dist/providers/dodo/better-auth.d.ts +29 -0
- package/dist/providers/dodo/better-auth.d.ts.map +1 -0
- package/dist/providers/dodo/better-auth.js +23 -0
- package/dist/providers/dodo/better-auth.js.map +1 -0
- package/dist/providers/dodo/client-contract.d.ts +32 -70
- package/dist/providers/dodo/client-contract.d.ts.map +1 -1
- package/dist/providers/dodo/client-contract.js.map +1 -1
- package/dist/providers/dodo/event-mapper.d.ts +3 -1
- package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
- package/dist/providers/dodo/event-mapper.js +219 -148
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/index.d.ts +5 -2
- package/dist/providers/dodo/index.d.ts.map +1 -1
- package/dist/providers/dodo/index.js +2 -1
- package/dist/providers/dodo/index.js.map +1 -1
- package/dist/providers/dodo/nextjs.d.ts +16 -0
- package/dist/providers/dodo/nextjs.d.ts.map +1 -0
- package/dist/providers/dodo/nextjs.js +16 -0
- package/dist/providers/dodo/nextjs.js.map +1 -0
- package/dist/providers/dodo/provider.d.ts +30 -11
- package/dist/providers/dodo/provider.d.ts.map +1 -1
- package/dist/providers/dodo/provider.js +192 -122
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/dodo/react-native.d.ts +56 -0
- package/dist/providers/dodo/react-native.d.ts.map +1 -0
- package/dist/providers/dodo/react-native.js +57 -0
- package/dist/providers/dodo/react-native.js.map +1 -0
- package/dist/providers/dodo/webhook-bridge.d.ts +17 -0
- package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -0
- package/dist/providers/dodo/webhook-bridge.js +21 -0
- package/dist/providers/dodo/webhook-bridge.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/index.d.ts +1 -0
- package/dist/providers/mock/index.d.ts.map +1 -1
- package/dist/providers/mock/index.js.map +1 -1
- package/dist/providers/mock/provider.d.ts +8 -8
- package/dist/providers/mock/provider.d.ts.map +1 -1
- package/dist/providers/mock/provider.js +26 -19
- 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 +214 -173
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/index.d.ts +1 -0
- package/dist/providers/stripe/index.d.ts.map +1 -1
- package/dist/providers/stripe/index.js.map +1 -1
- package/dist/providers/stripe/provider.d.ts +13 -11
- package/dist/providers/stripe/provider.d.ts.map +1 -1
- package/dist/providers/stripe/provider.js +287 -107
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.d.ts +1 -2
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts +26 -4
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +65 -23
- package/dist/retry.js.map +1 -1
- package/dist/shared/diagnostics.d.ts +7 -0
- package/dist/shared/diagnostics.d.ts.map +1 -0
- package/dist/shared/diagnostics.js +18 -0
- package/dist/shared/diagnostics.js.map +1 -0
- package/dist/shared/logger.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +43 -5
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +282 -30
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/postgres-errors.d.ts +11 -0
- package/dist/shared/postgres-errors.d.ts.map +1 -0
- package/dist/shared/postgres-errors.js +105 -0
- package/dist/shared/postgres-errors.js.map +1 -0
- package/dist/shared/postgres-types.js.map +1 -1
- package/dist/shared/postgres-validation.d.ts +15 -3
- package/dist/shared/postgres-validation.d.ts.map +1 -1
- package/dist/shared/postgres-validation.js +58 -14
- package/dist/shared/postgres-validation.js.map +1 -1
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +18 -3
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.d.ts +0 -6
- package/dist/storage/adapters/s3.d.ts.map +1 -1
- package/dist/storage/adapters/s3.js +0 -2
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/outbox-worker.d.ts +2 -1
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +17 -3
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +1 -1
- 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 -1
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +13 -3
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +35 -7
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +166 -53
- package/dist/storage/runtime.js.map +1 -1
- package/package.json +62 -7
- package/dist/credits/postgres/repositories/pricing.d.ts +0 -28
- package/dist/credits/postgres/repositories/pricing.d.ts.map +0 -1
- package/dist/credits/postgres/repositories/pricing.js +0 -70
- package/dist/credits/postgres/repositories/pricing.js.map +0 -1
- package/dist/credits/pricing-runtime.d.ts.map +0 -1
- package/dist/credits/pricing-runtime.js.map +0 -1
- package/dist/load-pricing-file.d.ts.map +0 -1
- package/dist/load-pricing-file.js.map +0 -1
|
@@ -1,62 +1,147 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { optionalRecordRow, postgresUuid, requireRow, safeParse, } from "../../../shared/postgres-validation.js";
|
|
3
|
+
const decimal = z.union([z.string().min(1), z.number().finite()]);
|
|
3
4
|
export const DeductionRowSchema = z
|
|
4
5
|
.object({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
allowance_consumed: z
|
|
15
|
-
.union([z.string(), z.number()])
|
|
16
|
-
.nullable()
|
|
17
|
-
.optional(),
|
|
18
|
-
idempotent: pgBoolean.nullable().optional(),
|
|
19
|
-
bucket_breakdown: z
|
|
20
|
-
.record(z.string(), z.union([z.string(), z.number()]))
|
|
21
|
-
.nullable()
|
|
22
|
-
.optional(),
|
|
23
|
-
error: z.string().nullable().optional(),
|
|
24
|
-
user_id: z.string().optional(),
|
|
6
|
+
charge_id: postgresUuid.nullable(),
|
|
7
|
+
entry_id: postgresUuid.nullable(),
|
|
8
|
+
amount: decimal,
|
|
9
|
+
balance_after: decimal.nullable(),
|
|
10
|
+
allowance_consumed: decimal,
|
|
11
|
+
idempotent: z.boolean(),
|
|
12
|
+
bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),
|
|
13
|
+
error: z.string().min(1).nullable(),
|
|
14
|
+
user_id: postgresUuid,
|
|
25
15
|
})
|
|
26
|
-
.
|
|
16
|
+
.strict()
|
|
17
|
+
.superRefine((row, context) => {
|
|
18
|
+
if (row.error === null && (row.charge_id === null || row.balance_after === null)) {
|
|
19
|
+
context.addIssue({
|
|
20
|
+
code: "custom",
|
|
21
|
+
message: "successful usage charges require a receipt and committed balance",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (row.error !== null &&
|
|
25
|
+
(row.charge_id !== null ||
|
|
26
|
+
row.entry_id !== null ||
|
|
27
|
+
row.balance_after !== null ||
|
|
28
|
+
row.idempotent)) {
|
|
29
|
+
context.addIssue({
|
|
30
|
+
code: "custom",
|
|
31
|
+
message: "failed usage charges cannot expose committed fields",
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const ChargeRpcRowSchema = z
|
|
36
|
+
.object({
|
|
37
|
+
charge_id: postgresUuid.nullable(),
|
|
38
|
+
ledger_entry_id: postgresUuid.nullable(),
|
|
39
|
+
charged: decimal,
|
|
40
|
+
allowance_covered: decimal,
|
|
41
|
+
replayed: z.boolean(),
|
|
42
|
+
error_code: z.string().min(1).nullable(),
|
|
43
|
+
})
|
|
44
|
+
.strict()
|
|
45
|
+
.superRefine((row, context) => {
|
|
46
|
+
if (row.error_code === null && row.charge_id === null) {
|
|
47
|
+
context.addIssue({ code: "custom", message: "successful usage charges require a receipt" });
|
|
48
|
+
}
|
|
49
|
+
if (row.error_code !== null &&
|
|
50
|
+
(row.charge_id !== null || row.ledger_entry_id !== null || row.replayed)) {
|
|
51
|
+
context.addIssue({
|
|
52
|
+
code: "custom",
|
|
53
|
+
message: "failed usage charges cannot expose committed fields",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
27
57
|
const RefundRowSchema = z
|
|
28
58
|
.object({
|
|
29
|
-
refund_entry_id:
|
|
30
|
-
user_id:
|
|
31
|
-
amount:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
new_balance: z
|
|
36
|
-
.union([z.string(), z.number()])
|
|
37
|
-
.nullable()
|
|
38
|
-
.optional(),
|
|
39
|
-
bucket_breakdown: z
|
|
40
|
-
.record(z.string(), z.union([z.string(), z.number()]))
|
|
41
|
-
.nullable()
|
|
42
|
-
.optional(),
|
|
43
|
-
error: z.string().nullable().optional(),
|
|
59
|
+
refund_entry_id: postgresUuid.nullable(),
|
|
60
|
+
user_id: postgresUuid.nullable(),
|
|
61
|
+
amount: decimal.nullable(),
|
|
62
|
+
new_balance: decimal.nullable(),
|
|
63
|
+
bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),
|
|
64
|
+
error: z.string().min(1).nullable(),
|
|
44
65
|
})
|
|
45
|
-
.
|
|
66
|
+
.strict()
|
|
67
|
+
.superRefine((row, context) => {
|
|
68
|
+
if (row.error === null &&
|
|
69
|
+
(row.refund_entry_id === null ||
|
|
70
|
+
row.user_id === null ||
|
|
71
|
+
row.amount === null ||
|
|
72
|
+
row.new_balance === null)) {
|
|
73
|
+
context.addIssue({
|
|
74
|
+
code: "custom",
|
|
75
|
+
message: "successful refunds require identity and balance fields",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (row.error !== null && (row.refund_entry_id !== null || row.bucket_breakdown !== null)) {
|
|
79
|
+
context.addIssue({
|
|
80
|
+
code: "custom",
|
|
81
|
+
message: "failed refunds cannot expose committed fields",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const RefundRpcRowSchema = z
|
|
86
|
+
.object({
|
|
87
|
+
entry_id: postgresUuid.nullable(),
|
|
88
|
+
subject_id: postgresUuid.nullable(),
|
|
89
|
+
amount: decimal.nullable(),
|
|
90
|
+
balance_after: decimal.nullable(),
|
|
91
|
+
replayed: z.boolean(),
|
|
92
|
+
error_code: z.string().min(1).nullable(),
|
|
93
|
+
})
|
|
94
|
+
.strict();
|
|
46
95
|
const RevokeRowSchema = z
|
|
47
96
|
.object({
|
|
48
|
-
user_id:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
97
|
+
user_id: postgresUuid,
|
|
98
|
+
entry_type: z.string().min(1),
|
|
99
|
+
revoked: decimal,
|
|
100
|
+
balance_after: decimal.nullable(),
|
|
101
|
+
error_code: z.string().min(1).nullable(),
|
|
102
|
+
})
|
|
103
|
+
.strict()
|
|
104
|
+
.superRefine((row, context) => {
|
|
105
|
+
if (row.error_code === null && row.balance_after === null) {
|
|
106
|
+
context.addIssue({
|
|
107
|
+
code: "custom",
|
|
108
|
+
message: "successful revocations require a committed balance",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const UsageRecordRowSchema = z
|
|
113
|
+
.object({
|
|
114
|
+
charge_id: postgresUuid.nullable(),
|
|
115
|
+
requested: decimal,
|
|
116
|
+
replayed: z.boolean(),
|
|
117
|
+
error_code: z.string().min(1).nullable(),
|
|
118
|
+
})
|
|
119
|
+
.strict()
|
|
120
|
+
.superRefine((row, context) => {
|
|
121
|
+
if (row.error_code === null && row.charge_id === null) {
|
|
122
|
+
context.addIssue({
|
|
123
|
+
code: "custom",
|
|
124
|
+
message: "successful usage records require a charge receipt",
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (row.error_code !== null && (row.charge_id !== null || row.replayed)) {
|
|
128
|
+
context.addIssue({
|
|
129
|
+
code: "custom",
|
|
130
|
+
message: "failed usage records cannot expose committed fields",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const UsageRecordRpcRowSchema = z
|
|
135
|
+
.object({
|
|
136
|
+
charge_id: postgresUuid.nullable(),
|
|
137
|
+
requested: decimal,
|
|
138
|
+
ledger_entry_id: postgresUuid.nullable(),
|
|
139
|
+
charged: decimal,
|
|
140
|
+
allowance_covered: decimal,
|
|
141
|
+
replayed: z.boolean(),
|
|
142
|
+
error_code: z.string().min(1).nullable(),
|
|
58
143
|
})
|
|
59
|
-
.
|
|
144
|
+
.strict();
|
|
60
145
|
/** Repository for credit deduction operations. */
|
|
61
146
|
export class DeductionRepository {
|
|
62
147
|
callproc;
|
|
@@ -77,26 +162,48 @@ export class DeductionRepository {
|
|
|
77
162
|
params.measures,
|
|
78
163
|
params.dimensions,
|
|
79
164
|
]);
|
|
80
|
-
const row = (rows
|
|
165
|
+
const row = safeParse(ChargeRpcRowSchema, requireRow(rows, "DeductionRepository.deductWithAllowance"), "DeductionRepository.deductWithAllowance");
|
|
81
166
|
const details = row.error_code != null
|
|
82
|
-
?
|
|
83
|
-
: (await this.callproc("get_credit_operation_details", [
|
|
167
|
+
? null
|
|
168
|
+
: optionalRecordRow(await this.callproc("get_credit_operation_details", [
|
|
84
169
|
params.userId,
|
|
85
170
|
row.ledger_entry_id ?? null,
|
|
86
171
|
params.idempotencyKey,
|
|
87
|
-
]))
|
|
172
|
+
]), "DeductionRepository.deductWithAllowance.details");
|
|
88
173
|
return safeParse(DeductionRowSchema, {
|
|
89
|
-
|
|
174
|
+
charge_id: row.charge_id,
|
|
90
175
|
user_id: params.userId,
|
|
91
176
|
entry_id: row.ledger_entry_id,
|
|
92
177
|
amount: row.charged,
|
|
93
178
|
allowance_consumed: row.allowance_covered,
|
|
94
|
-
balance_after: details?.balance_after
|
|
95
|
-
bucket_breakdown: details?.bucket_breakdown
|
|
179
|
+
balance_after: row.error_code === null ? details?.balance_after : null,
|
|
180
|
+
bucket_breakdown: row.error_code === null ? details?.bucket_breakdown : null,
|
|
96
181
|
idempotent: row.replayed,
|
|
97
182
|
error: row.error_code,
|
|
98
183
|
}, "DeductionRepository.deductWithAllowance");
|
|
99
184
|
}
|
|
185
|
+
/** Append a priced usage event without creating another balance debit. */
|
|
186
|
+
async recordUsage(params) {
|
|
187
|
+
const rows = await this.callproc("record_usage", [
|
|
188
|
+
params.userId,
|
|
189
|
+
params.operation,
|
|
190
|
+
params.amount,
|
|
191
|
+
params.idempotencyKey,
|
|
192
|
+
params.feature,
|
|
193
|
+
params.model,
|
|
194
|
+
params.region,
|
|
195
|
+
params.metadata,
|
|
196
|
+
params.measures,
|
|
197
|
+
params.dimensions,
|
|
198
|
+
]);
|
|
199
|
+
const row = safeParse(UsageRecordRpcRowSchema, requireRow(rows, "DeductionRepository.recordUsage"), "DeductionRepository.recordUsage");
|
|
200
|
+
return safeParse(UsageRecordRowSchema, {
|
|
201
|
+
charge_id: row.charge_id,
|
|
202
|
+
requested: row.requested,
|
|
203
|
+
replayed: row.replayed,
|
|
204
|
+
error_code: row.error_code,
|
|
205
|
+
}, "DeductionRepository.recordUsage");
|
|
206
|
+
}
|
|
100
207
|
/** Refund a previous credit deduction. */
|
|
101
208
|
async refundCredits(entryId, amount, idempotencyKey, reason, metadata) {
|
|
102
209
|
const rows = await this.callproc("refund_credit_by_entry", [
|
|
@@ -106,24 +213,26 @@ export class DeductionRepository {
|
|
|
106
213
|
reason,
|
|
107
214
|
metadata,
|
|
108
215
|
]);
|
|
109
|
-
const row = (rows
|
|
216
|
+
const row = safeParse(RefundRpcRowSchema, requireRow(rows, "DeductionRepository.refundCredits"), "DeductionRepository.refundCredits");
|
|
110
217
|
return safeParse(RefundRowSchema, {
|
|
111
|
-
...row,
|
|
112
218
|
refund_entry_id: row.entry_id,
|
|
113
219
|
user_id: row.subject_id,
|
|
220
|
+
amount: row.amount,
|
|
114
221
|
new_balance: row.balance_after,
|
|
222
|
+
bucket_breakdown: null,
|
|
115
223
|
error: row.error_code,
|
|
116
224
|
}, "DeductionRepository.refundCredits");
|
|
117
225
|
}
|
|
118
226
|
/** Revoke credits by transaction type. */
|
|
119
227
|
async revokeCreditsByEntryType(userId, entryType) {
|
|
120
228
|
const rows = await this.callproc("revoke_subject_credits_by_operation", [userId, entryType]);
|
|
121
|
-
const row = (rows
|
|
229
|
+
const row = requireRow(rows, "DeductionRepository.revokeCreditsByEntryType");
|
|
122
230
|
return safeParse(RevokeRowSchema, {
|
|
123
231
|
user_id: userId,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
232
|
+
entry_type: entryType,
|
|
233
|
+
revoked: row.revoked,
|
|
234
|
+
balance_after: row.balance_after,
|
|
235
|
+
error_code: row.error_code,
|
|
127
236
|
}, "DeductionRepository.revokeCreditsByEntryType");
|
|
128
237
|
}
|
|
129
238
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deduction.js","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/deduction.ts"],"names":[],"mappings":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AAG,CAAC,QAAQ;YACxB,KAAK,EAAE,GAAG,CAAC,UAAU;SACtB,EACD,yCAAyC,CAC1C,CAAC;IACJ,CAAC;IAED,0CAA0C;IAC1C,KAAK,CAAC,aAAa,CACjB,OAAe,EACf,MAAqB,EACrB,cAAsB,EACtB,MAAqB,EACrB,QAAgB;QAEhB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,wBAAwB,EAAE;YACzD,OAAO;YACP,MAAM;YACN,cAAc;YACd,MAAM;YACN,QAAQ;SACT,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAA4B,CAAC;QACzD,OAAO,SAAS,CACd,eAAe,EACf;YACE,GAAG,GAAG;YACN,eAAe,EAAE,GAAG,CAAC,QAAQ;YAC7B,OAAO,EAAE,GAAG,CAAC,UAAU;YACvB,WAAW,EAAE,GAAG,CAAC,aAAa;YAC9B,KAAK,EAAE,GAAG,CAAC,UAAU;SACtB,EACD,mCAAmC,CACpC,CAAC;IACJ,CAAC;IAED,0CAA0C;IAC1C,KAAK,CAAC,wBAAwB,CAAC,MAAc,EAAE,SAAiB;QAC9D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,qCAAqC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QAC7F,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAA4B,CAAC;QACzD,OAAO,SAAS,CACd,eAAe,EACf;YACE,OAAO,EAAE,MAAM;YACf,MAAM,EAAE,GAAG,CAAC,OAAO;YACnB,WAAW,EAAE,GAAG,CAAC,aAAa;YAC9B,MAAM,EAAE,IAAI;SACb,EACD,8CAA8C,CAC/C,CAAC;IACJ,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"deduction.js","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/deduction.ts"],"names":[],"mappings":"AA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G,MAAM,IAAI,CAAC,QAAQ,CAAC,qCAAqC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QAC7F,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,EAAE,8CAA8C,CAG1E,CAAC;QACF,OAAO,SAAS,CACd,eAAe,EACf;YACE,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B,EACD,8CAA8C,CAC/C,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { CallProc } from \"../../../shared/postgres-types.js\";\nimport {\n optionalRecordRow,\n postgresUuid,\n requireRow,\n safeParse,\n} from \"../../../shared/postgres-validation.js\";\n\nconst decimal = z.union([z.string().min(1), z.number().finite()] as const);\n\nexport const DeductionRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n entry_id: postgresUuid.nullable(),\n amount: decimal,\n balance_after: decimal.nullable(),\n allowance_consumed: decimal,\n idempotent: z.boolean(),\n bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),\n error: z.string().min(1).nullable(),\n user_id: postgresUuid,\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error === null && (row.charge_id === null || row.balance_after === null)) {\n context.addIssue({\n code: \"custom\",\n message: \"successful usage charges require a receipt and committed balance\",\n });\n }\n if (\n row.error !== null &&\n (row.charge_id !== null ||\n row.entry_id !== null ||\n row.balance_after !== null ||\n row.idempotent)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"failed usage charges cannot expose committed fields\",\n });\n }\n });\n\nconst ChargeRpcRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n ledger_entry_id: postgresUuid.nullable(),\n charged: decimal,\n allowance_covered: decimal,\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error_code === null && row.charge_id === null) {\n context.addIssue({ code: \"custom\", message: \"successful usage charges require a receipt\" });\n }\n if (\n row.error_code !== null &&\n (row.charge_id !== null || row.ledger_entry_id !== null || row.replayed)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"failed usage charges cannot expose committed fields\",\n });\n }\n });\n\nconst RefundRowSchema = z\n .object({\n refund_entry_id: postgresUuid.nullable(),\n user_id: postgresUuid.nullable(),\n amount: decimal.nullable(),\n new_balance: decimal.nullable(),\n bucket_breakdown: z.record(z.string().min(1), decimal).nullable(),\n error: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (\n row.error === null &&\n (row.refund_entry_id === null ||\n row.user_id === null ||\n row.amount === null ||\n row.new_balance === null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"successful refunds require identity and balance fields\",\n });\n }\n if (row.error !== null && (row.refund_entry_id !== null || row.bucket_breakdown !== null)) {\n context.addIssue({\n code: \"custom\",\n message: \"failed refunds cannot expose committed fields\",\n });\n }\n });\n\nconst RefundRpcRowSchema = z\n .object({\n entry_id: postgresUuid.nullable(),\n subject_id: postgresUuid.nullable(),\n amount: decimal.nullable(),\n balance_after: decimal.nullable(),\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict();\n\nconst RevokeRowSchema = z\n .object({\n user_id: postgresUuid,\n entry_type: z.string().min(1),\n revoked: decimal,\n balance_after: decimal.nullable(),\n error_code: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error_code === null && row.balance_after === null) {\n context.addIssue({\n code: \"custom\",\n message: \"successful revocations require a committed balance\",\n });\n }\n });\n\nexport type DeductionRow = z.infer<typeof DeductionRowSchema>;\nexport type RefundRow = z.infer<typeof RefundRowSchema>;\nexport type RevokeRow = z.infer<typeof RevokeRowSchema>;\n\nconst UsageRecordRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n requested: decimal,\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict()\n .superRefine((row, context) => {\n if (row.error_code === null && row.charge_id === null) {\n context.addIssue({\n code: \"custom\",\n message: \"successful usage records require a charge receipt\",\n });\n }\n if (row.error_code !== null && (row.charge_id !== null || row.replayed)) {\n context.addIssue({\n code: \"custom\",\n message: \"failed usage records cannot expose committed fields\",\n });\n }\n });\n\nconst UsageRecordRpcRowSchema = z\n .object({\n charge_id: postgresUuid.nullable(),\n requested: decimal,\n ledger_entry_id: postgresUuid.nullable(),\n charged: decimal,\n allowance_covered: decimal,\n replayed: z.boolean(),\n error_code: z.string().min(1).nullable(),\n })\n .strict();\n\nexport type UsageRecordRow = z.infer<typeof UsageRecordRowSchema>;\n\n/** Typed input for the plan-aware operation charge RPC. */\nexport interface DeductParams {\n userId: string;\n operation: string;\n amount: string;\n idempotencyKey: string;\n feature: string | null;\n model: string | null;\n region: string | null;\n measures: string;\n dimensions: string;\n metadata: string;\n}\n\n/** Repository for credit deduction operations. */\nexport class DeductionRepository {\n constructor(private callproc: CallProc) {}\n\n /** Atomically deduct credits with allowance, entitlement, quota, and credit-policy enforcement. */\n async deductWithAllowance(params: DeductParams): Promise<DeductionRow> {\n const rows = await this.callproc(\"charge_usage_for_operation\", [\n params.userId,\n params.operation,\n params.amount,\n params.idempotencyKey,\n params.feature,\n params.model,\n params.region,\n params.metadata,\n params.measures,\n params.dimensions,\n ]);\n const row = safeParse(\n ChargeRpcRowSchema,\n requireRow(rows, \"DeductionRepository.deductWithAllowance\"),\n \"DeductionRepository.deductWithAllowance\",\n );\n const details =\n row.error_code != null\n ? null\n : optionalRecordRow(\n await this.callproc(\"get_credit_operation_details\", [\n params.userId,\n row.ledger_entry_id ?? null,\n params.idempotencyKey,\n ]),\n \"DeductionRepository.deductWithAllowance.details\",\n );\n return safeParse(\n DeductionRowSchema,\n {\n charge_id: row.charge_id,\n user_id: params.userId,\n entry_id: row.ledger_entry_id,\n amount: row.charged,\n allowance_consumed: row.allowance_covered,\n balance_after: row.error_code === null ? details?.balance_after : null,\n bucket_breakdown: row.error_code === null ? details?.bucket_breakdown : null,\n idempotent: row.replayed,\n error: row.error_code,\n },\n \"DeductionRepository.deductWithAllowance\",\n );\n }\n\n /** Append a priced usage event without creating another balance debit. */\n async recordUsage(params: DeductParams): Promise<UsageRecordRow> {\n const rows = await this.callproc(\"record_usage\", [\n params.userId,\n params.operation,\n params.amount,\n params.idempotencyKey,\n params.feature,\n params.model,\n params.region,\n params.metadata,\n params.measures,\n params.dimensions,\n ]);\n const row = safeParse(\n UsageRecordRpcRowSchema,\n requireRow(rows, \"DeductionRepository.recordUsage\"),\n \"DeductionRepository.recordUsage\",\n );\n return safeParse(\n UsageRecordRowSchema,\n {\n charge_id: row.charge_id,\n requested: row.requested,\n replayed: row.replayed,\n error_code: row.error_code,\n },\n \"DeductionRepository.recordUsage\",\n );\n }\n\n /** Refund a previous credit deduction. */\n async refundCredits(\n entryId: string,\n amount: string | null,\n idempotencyKey: string,\n reason: string | null,\n metadata: string,\n ): Promise<RefundRow> {\n const rows = await this.callproc(\"refund_credit_by_entry\", [\n entryId,\n amount,\n idempotencyKey,\n reason,\n metadata,\n ]);\n const row = safeParse(\n RefundRpcRowSchema,\n requireRow(rows, \"DeductionRepository.refundCredits\"),\n \"DeductionRepository.refundCredits\",\n );\n return safeParse(\n RefundRowSchema,\n {\n refund_entry_id: row.entry_id,\n user_id: row.subject_id,\n amount: row.amount,\n new_balance: row.balance_after,\n bucket_breakdown: null,\n error: row.error_code,\n },\n \"DeductionRepository.refundCredits\",\n );\n }\n\n /** Revoke credits by transaction type. */\n async revokeCreditsByEntryType(userId: string, entryType: string): Promise<RevokeRow> {\n const rows = await this.callproc(\"revoke_subject_credits_by_operation\", [userId, entryType]);\n const row = requireRow(rows, \"DeductionRepository.revokeCreditsByEntryType\") as Record<\n string,\n unknown\n >;\n return safeParse(\n RevokeRowSchema,\n {\n user_id: userId,\n entry_type: entryType,\n revoked: row.revoked,\n balance_after: row.balance_after,\n error_code: row.error_code,\n },\n \"DeductionRepository.revokeCreditsByEntryType\",\n );\n }\n}\n"]}
|
|
@@ -2,26 +2,29 @@ import { z } from "zod";
|
|
|
2
2
|
import type { CallProc } from "../../../shared/postgres-types.js";
|
|
3
3
|
import type { DeductionRow } from "./deduction.js";
|
|
4
4
|
declare const LeaseRowSchema: z.ZodObject<{
|
|
5
|
-
lease_id: z.
|
|
6
|
-
user_id: z.
|
|
7
|
-
amount: z.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
expires_at: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>]>>;
|
|
13
|
-
error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
|
-
}, z.core.$loose>;
|
|
5
|
+
lease_id: z.ZodNullable<z.ZodString>;
|
|
6
|
+
user_id: z.ZodString;
|
|
7
|
+
amount: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
8
|
+
minimum_balance: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
9
|
+
expires_at: z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<string, string | Date>>>;
|
|
10
|
+
error: z.ZodNullable<z.ZodString>;
|
|
11
|
+
}, z.core.$strict>;
|
|
15
12
|
declare const ReleaseRowSchema: z.ZodObject<{
|
|
16
|
-
released: z.
|
|
17
|
-
reason: z.
|
|
18
|
-
|
|
13
|
+
released: z.ZodBoolean;
|
|
14
|
+
reason: z.ZodNullable<z.ZodUnion<[z.ZodEnum<{
|
|
15
|
+
active: "active";
|
|
16
|
+
expired: "expired";
|
|
17
|
+
settling: "settling";
|
|
18
|
+
settled: "settled";
|
|
19
|
+
released: "released";
|
|
20
|
+
}>, z.ZodLiteral<"missing_lease">]>>;
|
|
21
|
+
}, z.core.$strict>;
|
|
19
22
|
declare const LeasePricingContextRowSchema: z.ZodObject<{
|
|
20
|
-
catalog_revision_no: z.
|
|
21
|
-
plan_id: z.
|
|
22
|
-
plan_key: z.
|
|
23
|
-
rate_card: z.
|
|
24
|
-
}, z.core.$
|
|
23
|
+
catalog_revision_no: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>;
|
|
24
|
+
plan_id: z.ZodNullable<z.ZodString>;
|
|
25
|
+
plan_key: z.ZodNullable<z.ZodString>;
|
|
26
|
+
rate_card: z.ZodNullable<z.ZodString>;
|
|
27
|
+
}, z.core.$strict>;
|
|
25
28
|
export type LeaseRow = z.infer<typeof LeaseRowSchema>;
|
|
26
29
|
export type ReleaseRow = z.infer<typeof ReleaseRowSchema>;
|
|
27
30
|
export type LeasePricingContextRow = z.infer<typeof LeasePricingContextRowSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lease.d.ts","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/lease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"lease.d.ts","sourceRoot":"","sources":["../../../../src/credits/postgres/repositories/lease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAqEnD,QAAA,MAAM,cAAc;;;;;;;kBAmChB,CAAC;AAEL,QAAA,MAAM,gBAAgB;;;;;;;;;kBAKX,CAAC;AAEZ,QAAA,MAAM,4BAA4B;;;;;kBAY9B,CAAC;AAEL,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,O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