@zonastery/bursar 1.0.1 → 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 +86 -3
- 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 +8 -7
- 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 +31 -9
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +2 -1
- 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 +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 +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/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 +202 -59
- 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 +12 -5
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +18 -15
- 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 +18 -11
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +260 -238
- 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/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/bursar.d.ts +27 -9
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +48 -20
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/commerce/errors.d.ts +1 -10
- package/dist/commerce/errors.d.ts.map +1 -1
- package/dist/commerce/errors.js +1 -16
- 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/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 +85 -67
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +27 -15
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +16 -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 +16 -5
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/types.d.ts +2 -2
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/credits/{pricing-runtime.d.ts → catalog-runtime.d.ts} +8 -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 +34 -34
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +52 -52
- 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 +28 -26
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +153 -68
- 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 +90 -43
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +126 -108
- 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 +23 -18
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +282 -265
- 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 +36 -61
- 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-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 +42 -62
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +140 -121
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +20 -22
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +5 -5
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +49 -11
- 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 +20 -15
- 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/ledger.d.ts +12 -3
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.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 +52 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +76 -4
- 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/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 +5 -7
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +5 -12
- package/dist/generated/pricing-config.types.d.ts +3 -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 +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- 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} +15 -10
- package/dist/load-config-file.js.map +1 -0
- 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 +36 -0
- 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/shared/postgres-client.d.ts +5 -0
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +23 -7
- package/dist/shared/postgres-client.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 +2 -5
- 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/ports.d.ts +0 -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 +2 -2
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +24 -6
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +87 -30
- package/dist/storage/runtime.js.map +1 -1
- package/package.json +56 -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 -76
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/billing/types/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCnB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAExF,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAC9C,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,C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CAAE,CAAC"}
|
|
@@ -35,4 +35,242 @@ export const BillingEventType = {
|
|
|
35
35
|
PAYMENT_METHOD_UPDATED: "payment_method.updated",
|
|
36
36
|
PAYMENT_METHOD_DETACHED: "payment_method.detached",
|
|
37
37
|
};
|
|
38
|
+
const BILLING_EVENT_TYPES = new Set(Object.values(BillingEventType));
|
|
39
|
+
const SUBSCRIPTION_STATUSES = new Set([
|
|
40
|
+
"incomplete",
|
|
41
|
+
"incomplete_expired",
|
|
42
|
+
"trialing",
|
|
43
|
+
"active",
|
|
44
|
+
"past_due",
|
|
45
|
+
"canceled",
|
|
46
|
+
"unpaid",
|
|
47
|
+
"paused",
|
|
48
|
+
"expired",
|
|
49
|
+
]);
|
|
50
|
+
const BILLING_INTERVALS = new Set(["day", "week", "month", "year"]);
|
|
51
|
+
const INVOICE_STATUSES = new Set(["draft", "open", "paid", "void", "uncollectible"]);
|
|
52
|
+
const PAYMENT_PURPOSES = new Set(["subscription", "credit_topup"]);
|
|
53
|
+
const PAYMENT_STATUSES = new Set(["pending", "succeeded", "failed", "canceled"]);
|
|
54
|
+
const DISPUTE_STATUSES = new Set(["needs_response", "under_review", "won", "lost", "closed"]);
|
|
55
|
+
const ISO_INSTANT_WITH_OFFSET = /(?:Z|[+-]\d{2}:\d{2})$/;
|
|
56
|
+
function requireObject(value, field) {
|
|
57
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
58
|
+
throw new TypeError(`${field} must be an object`);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function rejectUnknownKeys(value, allowed, field) {
|
|
63
|
+
const known = new Set(allowed);
|
|
64
|
+
const unknown = Object.keys(value).filter((key) => !known.has(key));
|
|
65
|
+
if (unknown.length > 0) {
|
|
66
|
+
throw new TypeError(`${field} contains unsupported field${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function requireNonEmptyString(value, field) {
|
|
70
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
71
|
+
throw new TypeError(`${field} must be a non-empty string`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function requireOptionalNonEmptyString(value, field) {
|
|
75
|
+
if (value !== null && value !== undefined)
|
|
76
|
+
requireNonEmptyString(value, field);
|
|
77
|
+
}
|
|
78
|
+
function requireOptionalString(value, field) {
|
|
79
|
+
if (value !== null && value !== undefined && typeof value !== "string") {
|
|
80
|
+
throw new TypeError(`${field} must be a string`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function requireOptionalBoolean(value, field) {
|
|
84
|
+
if (value !== null && value !== undefined && typeof value !== "boolean") {
|
|
85
|
+
throw new TypeError(`${field} must be a boolean`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function requireOneOf(value, allowed, field) {
|
|
89
|
+
if (typeof value !== "string" || !allowed.has(value)) {
|
|
90
|
+
throw new TypeError(`${field} has an unsupported value`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function validateProviderRef(value, field) {
|
|
94
|
+
if (value === null || value === undefined)
|
|
95
|
+
return;
|
|
96
|
+
const reference = requireObject(value, field);
|
|
97
|
+
const keys = ["productId", "priceId", "variantId", "lookupKey"];
|
|
98
|
+
rejectUnknownKeys(reference, keys, field);
|
|
99
|
+
for (const key of keys)
|
|
100
|
+
requireOptionalNonEmptyString(reference[key], `${field}.${key}`);
|
|
101
|
+
if (!keys.some((key) => reference[key] !== null && reference[key] !== undefined)) {
|
|
102
|
+
throw new TypeError(`${field} must contain a provider identifier`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function requireMinorUnits(value, field, positive = false) {
|
|
106
|
+
if (!Number.isSafeInteger(value) || value < (positive ? 1 : 0)) {
|
|
107
|
+
throw new TypeError(`${field} must be a ${positive ? "positive" : "non-negative"} safe integer`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function requireCurrency(value, field) {
|
|
111
|
+
if (typeof value !== "string" || !/^[A-Z]{3}$/.test(value)) {
|
|
112
|
+
throw new TypeError(`${field} must be an uppercase three-letter currency code`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function requireOptionalInstant(value, field) {
|
|
116
|
+
if (value === null || value === undefined)
|
|
117
|
+
return;
|
|
118
|
+
if (typeof value !== "string" ||
|
|
119
|
+
!ISO_INSTANT_WITH_OFFSET.test(value) ||
|
|
120
|
+
Number.isNaN(Date.parse(value))) {
|
|
121
|
+
throw new TypeError(`${field} must be an ISO 8601 instant with an offset`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Validate an event at the public ingestion boundary before claiming it. */
|
|
125
|
+
export function assertBillingEvent(value) {
|
|
126
|
+
const record = requireObject(value, "billing event");
|
|
127
|
+
rejectUnknownKeys(record, [
|
|
128
|
+
"provider",
|
|
129
|
+
"eventId",
|
|
130
|
+
"eventType",
|
|
131
|
+
"occurredAt",
|
|
132
|
+
"userId",
|
|
133
|
+
"customer",
|
|
134
|
+
"subscription",
|
|
135
|
+
"invoice",
|
|
136
|
+
"payment",
|
|
137
|
+
"refund",
|
|
138
|
+
"dispute",
|
|
139
|
+
"metadata",
|
|
140
|
+
"raw",
|
|
141
|
+
"billingEventId",
|
|
142
|
+
], "billing event");
|
|
143
|
+
const event = record;
|
|
144
|
+
requireNonEmptyString(event.provider, "billing event provider");
|
|
145
|
+
requireNonEmptyString(event.eventId, "billing event id");
|
|
146
|
+
requireOptionalNonEmptyString(event.userId, "billing event userId");
|
|
147
|
+
requireOptionalNonEmptyString(event.billingEventId, "billing event billingEventId");
|
|
148
|
+
if (event.metadata !== null && event.metadata !== undefined) {
|
|
149
|
+
requireObject(event.metadata, "billing event metadata");
|
|
150
|
+
}
|
|
151
|
+
if (!BILLING_EVENT_TYPES.has(event.eventType)) {
|
|
152
|
+
throw new TypeError(`unsupported billing event type: ${String(event.eventType)}`);
|
|
153
|
+
}
|
|
154
|
+
if (typeof event.occurredAt !== "string" ||
|
|
155
|
+
!ISO_INSTANT_WITH_OFFSET.test(event.occurredAt) ||
|
|
156
|
+
Number.isNaN(Date.parse(event.occurredAt))) {
|
|
157
|
+
throw new TypeError("billing event occurredAt must be an ISO 8601 instant with an offset");
|
|
158
|
+
}
|
|
159
|
+
const eventName = event.eventType;
|
|
160
|
+
if (event.customer !== null && event.customer !== undefined) {
|
|
161
|
+
const customer = requireObject(event.customer, `${eventName} customer`);
|
|
162
|
+
rejectUnknownKeys(customer, ["providerCustomerId", "email"], `${eventName} customer`);
|
|
163
|
+
requireOptionalNonEmptyString(customer.providerCustomerId, `${eventName} customer.providerCustomerId`);
|
|
164
|
+
requireOptionalNonEmptyString(customer.email, `${eventName} customer.email`);
|
|
165
|
+
if (customer.providerCustomerId == null && customer.email == null) {
|
|
166
|
+
throw new TypeError(`${eventName} customer requires providerCustomerId or email`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (eventName.startsWith("customer.")) {
|
|
170
|
+
throw new TypeError(`${eventName} requires customer data`);
|
|
171
|
+
}
|
|
172
|
+
if (event.subscription !== null && event.subscription !== undefined) {
|
|
173
|
+
const subscription = requireObject(event.subscription, `${eventName} subscription`);
|
|
174
|
+
rejectUnknownKeys(subscription, [
|
|
175
|
+
"providerSubscriptionId",
|
|
176
|
+
"status",
|
|
177
|
+
"cancelAtPeriodEnd",
|
|
178
|
+
"periodStart",
|
|
179
|
+
"periodEnd",
|
|
180
|
+
"trialEnd",
|
|
181
|
+
"cancelAt",
|
|
182
|
+
"endedAt",
|
|
183
|
+
"refs",
|
|
184
|
+
"interval",
|
|
185
|
+
"intervalCount",
|
|
186
|
+
], `${eventName} subscription`);
|
|
187
|
+
requireNonEmptyString(subscription.providerSubscriptionId, `${eventName} subscription.providerSubscriptionId`);
|
|
188
|
+
if (subscription.status != null) {
|
|
189
|
+
requireOneOf(subscription.status, SUBSCRIPTION_STATUSES, `${eventName} subscription.status`);
|
|
190
|
+
}
|
|
191
|
+
requireOptionalBoolean(subscription.cancelAtPeriodEnd, `${eventName} subscription.cancelAtPeriodEnd`);
|
|
192
|
+
for (const [field, value] of [
|
|
193
|
+
["periodStart", subscription.periodStart],
|
|
194
|
+
["periodEnd", subscription.periodEnd],
|
|
195
|
+
["trialEnd", subscription.trialEnd],
|
|
196
|
+
["cancelAt", subscription.cancelAt],
|
|
197
|
+
["endedAt", subscription.endedAt],
|
|
198
|
+
]) {
|
|
199
|
+
requireOptionalInstant(value, `${eventName} subscription.${field}`);
|
|
200
|
+
}
|
|
201
|
+
validateProviderRef(subscription.refs, `${eventName} subscription.refs`);
|
|
202
|
+
if (subscription.interval != null) {
|
|
203
|
+
requireOneOf(subscription.interval, BILLING_INTERVALS, `${eventName} subscription.interval`);
|
|
204
|
+
}
|
|
205
|
+
if (subscription.intervalCount !== null &&
|
|
206
|
+
subscription.intervalCount !== undefined &&
|
|
207
|
+
(!Number.isSafeInteger(subscription.intervalCount) ||
|
|
208
|
+
subscription.intervalCount <= 0)) {
|
|
209
|
+
throw new TypeError(`${eventName} subscription.intervalCount must be a positive safe integer`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (eventName.startsWith("subscription.")) {
|
|
213
|
+
throw new TypeError(`${eventName} requires subscription data`);
|
|
214
|
+
}
|
|
215
|
+
if (event.invoice !== null && event.invoice !== undefined) {
|
|
216
|
+
const invoice = requireObject(event.invoice, `${eventName} invoice`);
|
|
217
|
+
rejectUnknownKeys(invoice, [
|
|
218
|
+
"providerInvoiceId",
|
|
219
|
+
"status",
|
|
220
|
+
"amountPaidMinor",
|
|
221
|
+
"amountDueMinor",
|
|
222
|
+
"currency",
|
|
223
|
+
"periodStart",
|
|
224
|
+
"periodEnd",
|
|
225
|
+
], `${eventName} invoice`);
|
|
226
|
+
requireNonEmptyString(invoice.providerInvoiceId, `${eventName} invoice.providerInvoiceId`);
|
|
227
|
+
requireOneOf(invoice.status, INVOICE_STATUSES, `${eventName} invoice.status`);
|
|
228
|
+
requireMinorUnits(invoice.amountPaidMinor, `${eventName} invoice.amountPaidMinor`);
|
|
229
|
+
requireMinorUnits(invoice.amountDueMinor, `${eventName} invoice.amountDueMinor`);
|
|
230
|
+
requireCurrency(invoice.currency, `${eventName} invoice.currency`);
|
|
231
|
+
requireOptionalInstant(invoice.periodStart, `${eventName} invoice.periodStart`);
|
|
232
|
+
requireOptionalInstant(invoice.periodEnd, `${eventName} invoice.periodEnd`);
|
|
233
|
+
}
|
|
234
|
+
else if (eventName.startsWith("invoice.")) {
|
|
235
|
+
throw new TypeError(`${eventName} requires invoice data`);
|
|
236
|
+
}
|
|
237
|
+
if (event.payment !== null && event.payment !== undefined) {
|
|
238
|
+
const payment = requireObject(event.payment, `${eventName} payment`);
|
|
239
|
+
rejectUnknownKeys(payment, ["providerPaymentId", "amountMinor", "taxMinor", "currency", "refs", "purpose", "status"], `${eventName} payment`);
|
|
240
|
+
requireNonEmptyString(payment.providerPaymentId, `${eventName} payment.providerPaymentId`);
|
|
241
|
+
requireMinorUnits(payment.amountMinor, `${eventName} payment.amountMinor`);
|
|
242
|
+
requireMinorUnits(payment.taxMinor, `${eventName} payment.taxMinor`);
|
|
243
|
+
requireCurrency(payment.currency, `${eventName} payment.currency`);
|
|
244
|
+
validateProviderRef(payment.refs, `${eventName} payment.refs`);
|
|
245
|
+
requireOneOf(payment.purpose, PAYMENT_PURPOSES, `${eventName} payment.purpose`);
|
|
246
|
+
requireOneOf(payment.status, PAYMENT_STATUSES, `${eventName} payment.status`);
|
|
247
|
+
}
|
|
248
|
+
else if (eventName.startsWith("payment.")) {
|
|
249
|
+
throw new TypeError(`${eventName} requires payment data`);
|
|
250
|
+
}
|
|
251
|
+
if (event.refund !== null && event.refund !== undefined) {
|
|
252
|
+
const refund = requireObject(event.refund, `${eventName} refund`);
|
|
253
|
+
rejectUnknownKeys(refund, ["providerRefundId", "providerPaymentId", "amountMinor", "currency", "reason", "status"], `${eventName} refund`);
|
|
254
|
+
requireNonEmptyString(refund.providerRefundId, `${eventName} refund.providerRefundId`);
|
|
255
|
+
requireNonEmptyString(refund.providerPaymentId, `${eventName} refund.providerPaymentId`);
|
|
256
|
+
requireMinorUnits(refund.amountMinor, `${eventName} refund.amountMinor`, true);
|
|
257
|
+
requireCurrency(refund.currency, `${eventName} refund.currency`);
|
|
258
|
+
requireOptionalString(refund.reason, `${eventName} refund.reason`);
|
|
259
|
+
requireOneOf(refund.status, PAYMENT_STATUSES, `${eventName} refund.status`);
|
|
260
|
+
}
|
|
261
|
+
else if (eventName.startsWith("refund.")) {
|
|
262
|
+
throw new TypeError(`${eventName} requires refund data`);
|
|
263
|
+
}
|
|
264
|
+
if (event.dispute !== null && event.dispute !== undefined) {
|
|
265
|
+
const dispute = requireObject(event.dispute, `${eventName} dispute`);
|
|
266
|
+
rejectUnknownKeys(dispute, ["providerDisputeId", "providerPaymentId", "status", "reason"], `${eventName} dispute`);
|
|
267
|
+
requireNonEmptyString(dispute.providerDisputeId, `${eventName} dispute.providerDisputeId`);
|
|
268
|
+
requireNonEmptyString(dispute.providerPaymentId, `${eventName} dispute.providerPaymentId`);
|
|
269
|
+
requireOneOf(dispute.status, DISPUTE_STATUSES, `${eventName} dispute.status`);
|
|
270
|
+
requireOptionalString(dispute.reason, `${eventName} dispute.reason`);
|
|
271
|
+
}
|
|
272
|
+
else if (eventName.startsWith("dispute.")) {
|
|
273
|
+
throw new TypeError(`${eventName} requires dispute data`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
38
276
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/billing/types/events.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,kBAAkB,EAAE,oBAAoB;IACxC,gBAAgB,EAAE,kBAAkB;IACpC,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,oBAAoB,EAAE,sBAAsB;IAC5C,yBAAyB,EAAE,2BAA2B;IACtD,mCAAmC,EAAE,qCAAqC;IAC1E,qCAAqC,EAAE,uCAAuC;IAC9E,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,mBAAmB,EAAE,qBAAqB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,2BAA2B,EAAE,6BAA6B;IAC1D,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,2BAA2B,EAAE,6BAA6B;IAC1D,gBAAgB,EAAE,kBAAkB;IACpC,YAAY,EAAE,cAAc;IAC5B,sBAAsB,EAAE,wBAAwB;IAChD,+BAA+B,EAAE,iCAAiC;IAClE,cAAc,EAAE,gBAAgB;IAChC,iBAAiB,EAAE,mBAAmB;IACtC,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB;IAChC,aAAa,EAAE,eAAe;IAC9B,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;IAChC,uBAAuB,EAAE,yBAAyB;IAClD,sBAAsB,EAAE,wBAAwB;IAChD,uBAAuB,EAAE,yBAAyB;CAC1C,CAAC","sourcesContent":["import type {\n BillingCustomerInfo,\n BillingDisputeInfo,\n BillingInvoiceInfo,\n BillingPaymentInfo,\n BillingRefundInfo,\n} from \"./documents.js\";\nimport type { BillingSubscriptionInfo } from \"./subscriptions.js\";\n\nexport const BillingEventType = {\n CUSTOMER_CREATED: \"customer.created\",\n CUSTOMER_UPDATED: \"customer.updated\",\n CUSTOMER_DELETED: \"customer.deleted\",\n CHECKOUT_COMPLETED: \"checkout.completed\",\n CHECKOUT_EXPIRED: \"checkout.expired\",\n SUBSCRIPTION_CREATED: \"subscription.created\",\n SUBSCRIPTION_UPDATED: \"subscription.updated\",\n SUBSCRIPTION_ACTIVATED: \"subscription.activated\",\n SUBSCRIPTION_RENEWED: \"subscription.renewed\",\n SUBSCRIPTION_PLAN_CHANGED: \"subscription.plan_changed\",\n SUBSCRIPTION_CANCELLATION_SCHEDULED: \"subscription.cancellation_scheduled\",\n SUBSCRIPTION_CANCELLATION_UNSCHEDULED: \"subscription.cancellation_unscheduled\",\n SUBSCRIPTION_CANCELED: \"subscription.canceled\",\n SUBSCRIPTION_EXPIRED: \"subscription.expired\",\n SUBSCRIPTION_PAUSED: \"subscription.paused\",\n SUBSCRIPTION_RESUMED: \"subscription.resumed\",\n SUBSCRIPTION_TRIAL_WILL_END: \"subscription.trial_will_end\",\n INVOICE_CREATED: \"invoice.created\",\n INVOICE_FINALIZED: \"invoice.finalized\",\n INVOICE_FINALIZATION_FAILED: \"invoice.finalization_failed\",\n INVOICE_UPCOMING: \"invoice.upcoming\",\n INVOICE_PAID: \"invoice.paid\",\n INVOICE_PAYMENT_FAILED: \"invoice.payment_failed\",\n INVOICE_PAYMENT_ACTION_REQUIRED: \"invoice.payment_action_required\",\n INVOICE_VOIDED: \"invoice.voided\",\n PAYMENT_SUCCEEDED: \"payment.succeeded\",\n PAYMENT_FAILED: \"payment.failed\",\n REFUND_CREATED: \"refund.created\",\n REFUND_UPDATED: \"refund.updated\",\n REFUND_FAILED: \"refund.failed\",\n DISPUTE_CREATED: \"dispute.created\",\n DISPUTE_CLOSED: \"dispute.closed\",\n PAYMENT_METHOD_ATTACHED: \"payment_method.attached\",\n PAYMENT_METHOD_UPDATED: \"payment_method.updated\",\n PAYMENT_METHOD_DETACHED: \"payment_method.detached\",\n} as const;\n\nexport type BillingEventType = (typeof BillingEventType)[keyof typeof BillingEventType];\n\nexport interface BillingEvent {\n provider: string;\n eventId: string;\n eventType: BillingEventType;\n occurredAt: string;\n userId?: string | null;\n customer?: BillingCustomerInfo | null;\n subscription?: BillingSubscriptionInfo | null;\n invoice?: BillingInvoiceInfo | null;\n payment?: BillingPaymentInfo | null;\n refund?: BillingRefundInfo | null;\n dispute?: BillingDisputeInfo | null;\n metadata?: Record<string, unknown> | null;\n raw?: unknown;\n billingEventId?: string;\n}\n\nexport type BillingEventHandler = (event: BillingEvent, userId: string) => Promise<void>;\n\nexport interface BillingEventResult {\n handled: boolean;\n action?: string | null;\n error?: string | null;\n subscriptionId?: string | null;\n}\n\nexport type BillingEventClaim =\n | { status: \"claimed\"; claimToken: string; billingEventId: string }\n | { status: \"duplicate\" }\n | { status: \"busy\" }\n | { status: \"retry\" };\n"]}
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/billing/types/events.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,kBAAkB,EAAE,oBAAoB;IACxC,gBAAgB,EAAE,kBAAkB;IACpC,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,oBAAoB,EAAE,sBAAsB;IAC5C,yBAAyB,EAAE,2BAA2B;IACtD,mCAAmC,EAAE,qCAAqC;IAC1E,qCAAqC,EAAE,uCAAuC;IAC9E,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,mBAAmB,EAAE,qBAAqB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,2BAA2B,EAAE,6BAA6B;IAC1D,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,2BAA2B,EAAE,6BAA6B;IAC1D,gBAAgB,EAAE,kBAAkB;IACpC,YAAY,EAAE,cAAc;IAC5B,sBAAsB,EAAE,wBAAwB;IAChD,+BAA+B,EAAE,iCAAiC;IAClE,cAAc,EAAE,gBAAgB;IAChC,iBAAiB,EAAE,mBAAmB;IACtC,cAAc,EAAE,gBAAgB;IA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,CAAC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import type {\n BillingCustomerInfo,\n BillingDisputeInfo,\n BillingInvoiceInfo,\n BillingPaymentInfo,\n BillingRefundInfo,\n} from \"./documents.js\";\nimport type { BillingSubscriptionInfo } from \"./subscriptions.js\";\n\nexport const BillingEventType = {\n CUSTOMER_CREATED: \"customer.created\",\n CUSTOMER_UPDATED: \"customer.updated\",\n CUSTOMER_DELETED: \"customer.deleted\",\n CHECKOUT_COMPLETED: \"checkout.completed\",\n CHECKOUT_EXPIRED: \"checkout.expired\",\n SUBSCRIPTION_CREATED: \"subscription.created\",\n SUBSCRIPTION_UPDATED: \"subscription.updated\",\n SUBSCRIPTION_ACTIVATED: \"subscription.activated\",\n SUBSCRIPTION_RENEWED: \"subscription.renewed\",\n SUBSCRIPTION_PLAN_CHANGED: \"subscription.plan_changed\",\n SUBSCRIPTION_CANCELLATION_SCHEDULED: \"subscription.cancellation_scheduled\",\n SUBSCRIPTION_CANCELLATION_UNSCHEDULED: \"subscription.cancellation_unscheduled\",\n SUBSCRIPTION_CANCELED: \"subscription.canceled\",\n SUBSCRIPTION_EXPIRED: \"subscription.expired\",\n SUBSCRIPTION_PAUSED: \"subscription.paused\",\n SUBSCRIPTION_RESUMED: \"subscription.resumed\",\n SUBSCRIPTION_TRIAL_WILL_END: \"subscription.trial_will_end\",\n INVOICE_CREATED: \"invoice.created\",\n INVOICE_FINALIZED: \"invoice.finalized\",\n INVOICE_FINALIZATION_FAILED: \"invoice.finalization_failed\",\n INVOICE_UPCOMING: \"invoice.upcoming\",\n INVOICE_PAID: \"invoice.paid\",\n INVOICE_PAYMENT_FAILED: \"invoice.payment_failed\",\n INVOICE_PAYMENT_ACTION_REQUIRED: \"invoice.payment_action_required\",\n INVOICE_VOIDED: \"invoice.voided\",\n PAYMENT_SUCCEEDED: \"payment.succeeded\",\n PAYMENT_FAILED: \"payment.failed\",\n REFUND_CREATED: \"refund.created\",\n REFUND_UPDATED: \"refund.updated\",\n REFUND_FAILED: \"refund.failed\",\n DISPUTE_CREATED: \"dispute.created\",\n DISPUTE_CLOSED: \"dispute.closed\",\n PAYMENT_METHOD_ATTACHED: \"payment_method.attached\",\n PAYMENT_METHOD_UPDATED: \"payment_method.updated\",\n PAYMENT_METHOD_DETACHED: \"payment_method.detached\",\n} as const;\n\nexport type BillingEventType = (typeof BillingEventType)[keyof typeof BillingEventType];\n\nexport interface BillingEvent {\n provider: string;\n eventId: string;\n eventType: BillingEventType;\n occurredAt: string;\n userId?: string | null;\n customer?: BillingCustomerInfo | null;\n subscription?: BillingSubscriptionInfo | null;\n invoice?: BillingInvoiceInfo | null;\n payment?: BillingPaymentInfo | null;\n refund?: BillingRefundInfo | null;\n dispute?: BillingDisputeInfo | null;\n metadata?: Record<string, unknown> | null;\n raw?: unknown;\n billingEventId?: string;\n}\n\nconst BILLING_EVENT_TYPES = new Set<string>(Object.values(BillingEventType));\nconst SUBSCRIPTION_STATUSES = new Set([\n \"incomplete\",\n \"incomplete_expired\",\n \"trialing\",\n \"active\",\n \"past_due\",\n \"canceled\",\n \"unpaid\",\n \"paused\",\n \"expired\",\n]);\nconst BILLING_INTERVALS = new Set([\"day\", \"week\", \"month\", \"year\"]);\nconst INVOICE_STATUSES = new Set([\"draft\", \"open\", \"paid\", \"void\", \"uncollectible\"]);\nconst PAYMENT_PURPOSES = new Set([\"subscription\", \"credit_topup\"]);\nconst PAYMENT_STATUSES = new Set([\"pending\", \"succeeded\", \"failed\", \"canceled\"]);\nconst DISPUTE_STATUSES = new Set([\"needs_response\", \"under_review\", \"won\", \"lost\", \"closed\"]);\nconst ISO_INSTANT_WITH_OFFSET = /(?:Z|[+-]\\d{2}:\\d{2})$/;\n\nfunction requireObject(value: unknown, field: string): Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(`${field} must be an object`);\n }\n return value as Record<string, unknown>;\n}\n\nfunction rejectUnknownKeys(\n value: Record<string, unknown>,\n allowed: readonly string[],\n field: string,\n) {\n const known = new Set(allowed);\n const unknown = Object.keys(value).filter((key) => !known.has(key));\n if (unknown.length > 0) {\n throw new TypeError(\n `${field} contains unsupported field${unknown.length === 1 ? \"\" : \"s\"}: ${unknown.join(\", \")}`,\n );\n }\n}\n\nfunction requireNonEmptyString(value: unknown, field: string): void {\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(`${field} must be a non-empty string`);\n }\n}\n\nfunction requireOptionalNonEmptyString(value: unknown, field: string): void {\n if (value !== null && value !== undefined) requireNonEmptyString(value, field);\n}\n\nfunction requireOptionalString(value: unknown, field: string): void {\n if (value !== null && value !== undefined && typeof value !== \"string\") {\n throw new TypeError(`${field} must be a string`);\n }\n}\n\nfunction requireOptionalBoolean(value: unknown, field: string): void {\n if (value !== null && value !== undefined && typeof value !== \"boolean\") {\n throw new TypeError(`${field} must be a boolean`);\n }\n}\n\nfunction requireOneOf(value: unknown, allowed: ReadonlySet<string>, field: string): void {\n if (typeof value !== \"string\" || !allowed.has(value)) {\n throw new TypeError(`${field} has an unsupported value`);\n }\n}\n\nfunction validateProviderRef(value: unknown, field: string): void {\n if (value === null || value === undefined) return;\n const reference = requireObject(value, field);\n const keys = [\"productId\", \"priceId\", \"variantId\", \"lookupKey\"] as const;\n rejectUnknownKeys(reference, keys, field);\n for (const key of keys) requireOptionalNonEmptyString(reference[key], `${field}.${key}`);\n if (!keys.some((key) => reference[key] !== null && reference[key] !== undefined)) {\n throw new TypeError(`${field} must contain a provider identifier`);\n }\n}\n\nfunction requireMinorUnits(value: unknown, field: string, positive = false): void {\n if (!Number.isSafeInteger(value) || (value as number) < (positive ? 1 : 0)) {\n throw new TypeError(\n `${field} must be a ${positive ? \"positive\" : \"non-negative\"} safe integer`,\n );\n }\n}\n\nfunction requireCurrency(value: unknown, field: string): void {\n if (typeof value !== \"string\" || !/^[A-Z]{3}$/.test(value)) {\n throw new TypeError(`${field} must be an uppercase three-letter currency code`);\n }\n}\n\nfunction requireOptionalInstant(value: unknown, field: string): void {\n if (value === null || value === undefined) return;\n if (\n typeof value !== \"string\" ||\n !ISO_INSTANT_WITH_OFFSET.test(value) ||\n Number.isNaN(Date.parse(value))\n ) {\n throw new TypeError(`${field} must be an ISO 8601 instant with an offset`);\n }\n}\n\n/** Validate an event at the public ingestion boundary before claiming it. */\nexport function assertBillingEvent(value: unknown): asserts value is BillingEvent {\n const record = requireObject(value, \"billing event\");\n rejectUnknownKeys(\n record,\n [\n \"provider\",\n \"eventId\",\n \"eventType\",\n \"occurredAt\",\n \"userId\",\n \"customer\",\n \"subscription\",\n \"invoice\",\n \"payment\",\n \"refund\",\n \"dispute\",\n \"metadata\",\n \"raw\",\n \"billingEventId\",\n ],\n \"billing event\",\n );\n const event = record as unknown as BillingEvent;\n requireNonEmptyString(event.provider, \"billing event provider\");\n requireNonEmptyString(event.eventId, \"billing event id\");\n requireOptionalNonEmptyString(event.userId, \"billing event userId\");\n requireOptionalNonEmptyString(event.billingEventId, \"billing event billingEventId\");\n if (event.metadata !== null && event.metadata !== undefined) {\n requireObject(event.metadata, \"billing event metadata\");\n }\n if (!BILLING_EVENT_TYPES.has(event.eventType)) {\n throw new TypeError(`unsupported billing event type: ${String(event.eventType)}`);\n }\n if (\n typeof event.occurredAt !== \"string\" ||\n !ISO_INSTANT_WITH_OFFSET.test(event.occurredAt) ||\n Number.isNaN(Date.parse(event.occurredAt))\n ) {\n throw new TypeError(\"billing event occurredAt must be an ISO 8601 instant with an offset\");\n }\n\n const eventName: string = event.eventType;\n if (event.customer !== null && event.customer !== undefined) {\n const customer = requireObject(event.customer, `${eventName} customer`);\n rejectUnknownKeys(customer, [\"providerCustomerId\", \"email\"], `${eventName} customer`);\n requireOptionalNonEmptyString(\n customer.providerCustomerId,\n `${eventName} customer.providerCustomerId`,\n );\n requireOptionalNonEmptyString(customer.email, `${eventName} customer.email`);\n if (customer.providerCustomerId == null && customer.email == null) {\n throw new TypeError(`${eventName} customer requires providerCustomerId or email`);\n }\n } else if (eventName.startsWith(\"customer.\")) {\n throw new TypeError(`${eventName} requires customer data`);\n }\n if (event.subscription !== null && event.subscription !== undefined) {\n const subscription = requireObject(event.subscription, `${eventName} subscription`);\n rejectUnknownKeys(\n subscription,\n [\n \"providerSubscriptionId\",\n \"status\",\n \"cancelAtPeriodEnd\",\n \"periodStart\",\n \"periodEnd\",\n \"trialEnd\",\n \"cancelAt\",\n \"endedAt\",\n \"refs\",\n \"interval\",\n \"intervalCount\",\n ],\n `${eventName} subscription`,\n );\n requireNonEmptyString(\n subscription.providerSubscriptionId,\n `${eventName} subscription.providerSubscriptionId`,\n );\n if (subscription.status != null) {\n requireOneOf(subscription.status, SUBSCRIPTION_STATUSES, `${eventName} subscription.status`);\n }\n requireOptionalBoolean(\n subscription.cancelAtPeriodEnd,\n `${eventName} subscription.cancelAtPeriodEnd`,\n );\n for (const [field, value] of [\n [\"periodStart\", subscription.periodStart],\n [\"periodEnd\", subscription.periodEnd],\n [\"trialEnd\", subscription.trialEnd],\n [\"cancelAt\", subscription.cancelAt],\n [\"endedAt\", subscription.endedAt],\n ] as const) {\n requireOptionalInstant(value, `${eventName} subscription.${field}`);\n }\n validateProviderRef(subscription.refs, `${eventName} subscription.refs`);\n if (subscription.interval != null) {\n requireOneOf(subscription.interval, BILLING_INTERVALS, `${eventName} subscription.interval`);\n }\n if (\n subscription.intervalCount !== null &&\n subscription.intervalCount !== undefined &&\n (!Number.isSafeInteger(subscription.intervalCount) ||\n (subscription.intervalCount as number) <= 0)\n ) {\n throw new TypeError(\n `${eventName} subscription.intervalCount must be a positive safe integer`,\n );\n }\n } else if (eventName.startsWith(\"subscription.\")) {\n throw new TypeError(`${eventName} requires subscription data`);\n }\n if (event.invoice !== null && event.invoice !== undefined) {\n const invoice = requireObject(event.invoice, `${eventName} invoice`);\n rejectUnknownKeys(\n invoice,\n [\n \"providerInvoiceId\",\n \"status\",\n \"amountPaidMinor\",\n \"amountDueMinor\",\n \"currency\",\n \"periodStart\",\n \"periodEnd\",\n ],\n `${eventName} invoice`,\n );\n requireNonEmptyString(invoice.providerInvoiceId, `${eventName} invoice.providerInvoiceId`);\n requireOneOf(invoice.status, INVOICE_STATUSES, `${eventName} invoice.status`);\n requireMinorUnits(invoice.amountPaidMinor, `${eventName} invoice.amountPaidMinor`);\n requireMinorUnits(invoice.amountDueMinor, `${eventName} invoice.amountDueMinor`);\n requireCurrency(invoice.currency, `${eventName} invoice.currency`);\n requireOptionalInstant(invoice.periodStart, `${eventName} invoice.periodStart`);\n requireOptionalInstant(invoice.periodEnd, `${eventName} invoice.periodEnd`);\n } else if (eventName.startsWith(\"invoice.\")) {\n throw new TypeError(`${eventName} requires invoice data`);\n }\n if (event.payment !== null && event.payment !== undefined) {\n const payment = requireObject(event.payment, `${eventName} payment`);\n rejectUnknownKeys(\n payment,\n [\"providerPaymentId\", \"amountMinor\", \"taxMinor\", \"currency\", \"refs\", \"purpose\", \"status\"],\n `${eventName} payment`,\n );\n requireNonEmptyString(payment.providerPaymentId, `${eventName} payment.providerPaymentId`);\n requireMinorUnits(payment.amountMinor, `${eventName} payment.amountMinor`);\n requireMinorUnits(payment.taxMinor, `${eventName} payment.taxMinor`);\n requireCurrency(payment.currency, `${eventName} payment.currency`);\n validateProviderRef(payment.refs, `${eventName} payment.refs`);\n requireOneOf(payment.purpose, PAYMENT_PURPOSES, `${eventName} payment.purpose`);\n requireOneOf(payment.status, PAYMENT_STATUSES, `${eventName} payment.status`);\n } else if (eventName.startsWith(\"payment.\")) {\n throw new TypeError(`${eventName} requires payment data`);\n }\n if (event.refund !== null && event.refund !== undefined) {\n const refund = requireObject(event.refund, `${eventName} refund`);\n rejectUnknownKeys(\n refund,\n [\"providerRefundId\", \"providerPaymentId\", \"amountMinor\", \"currency\", \"reason\", \"status\"],\n `${eventName} refund`,\n );\n requireNonEmptyString(refund.providerRefundId, `${eventName} refund.providerRefundId`);\n requireNonEmptyString(refund.providerPaymentId, `${eventName} refund.providerPaymentId`);\n requireMinorUnits(refund.amountMinor, `${eventName} refund.amountMinor`, true);\n requireCurrency(refund.currency, `${eventName} refund.currency`);\n requireOptionalString(refund.reason, `${eventName} refund.reason`);\n requireOneOf(refund.status, PAYMENT_STATUSES, `${eventName} refund.status`);\n } else if (eventName.startsWith(\"refund.\")) {\n throw new TypeError(`${eventName} requires refund data`);\n }\n if (event.dispute !== null && event.dispute !== undefined) {\n const dispute = requireObject(event.dispute, `${eventName} dispute`);\n rejectUnknownKeys(\n dispute,\n [\"providerDisputeId\", \"providerPaymentId\", \"status\", \"reason\"],\n `${eventName} dispute`,\n );\n requireNonEmptyString(dispute.providerDisputeId, `${eventName} dispute.providerDisputeId`);\n requireNonEmptyString(dispute.providerPaymentId, `${eventName} dispute.providerPaymentId`);\n requireOneOf(dispute.status, DISPUTE_STATUSES, `${eventName} dispute.status`);\n requireOptionalString(dispute.reason, `${eventName} dispute.reason`);\n } else if (eventName.startsWith(\"dispute.\")) {\n throw new TypeError(`${eventName} requires dispute data`);\n }\n}\n\nexport type BillingEventHandler = (event: BillingEvent, userId: string) => Promise<void>;\n\nexport interface BillingEventResult {\n handled: boolean;\n action?: string | null;\n error?: string | null;\n subscriptionId?: string | null;\n}\n\nexport type BillingEventClaim =\n | { status: \"claimed\"; claimToken: string; billingEventId: string }\n | { status: \"duplicate\" }\n | { status: \"busy\" }\n | { status: \"retry\" };\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderRef } from "./common.js";
|
|
1
|
+
import type { BillingOfferInterval, ProviderRef } from "./common.js";
|
|
2
2
|
export type BillingSubscriptionStatus = "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "canceled" | "unpaid" | "paused" | "expired";
|
|
3
3
|
export declare const SUBSCRIPTION_STATUS: {
|
|
4
4
|
readonly ACTIVE: "active";
|
|
@@ -34,7 +34,7 @@ export interface BillingSubscriptionState {
|
|
|
34
34
|
offerKey?: string | null;
|
|
35
35
|
planId?: string | null;
|
|
36
36
|
plan?: string | null;
|
|
37
|
-
status
|
|
37
|
+
status: BillingSubscriptionStatus;
|
|
38
38
|
currentPeriodStart?: string | null;
|
|
39
39
|
currentPeriodEnd?: string | null;
|
|
40
40
|
trialEnd?: string | null;
|
|
@@ -42,8 +42,8 @@ export interface BillingSubscriptionState {
|
|
|
42
42
|
endedAt?: string | null;
|
|
43
43
|
graceEndsAt?: string | null;
|
|
44
44
|
graceExpiredAt?: string | null;
|
|
45
|
-
providerUpdatedAt
|
|
46
|
-
cancelAtPeriodEnd
|
|
45
|
+
providerUpdatedAt: string;
|
|
46
|
+
cancelAtPeriodEnd: boolean;
|
|
47
47
|
interval?: string | null;
|
|
48
48
|
intervalCount?: number | null;
|
|
49
49
|
metadata?: Record<string, unknown> | null;
|
|
@@ -52,10 +52,10 @@ export type BillingSubscriptionChangeState = "awaiting_payment" | "scheduled" |
|
|
|
52
52
|
export interface BillingSubscriptionOfferContext {
|
|
53
53
|
offerId: string;
|
|
54
54
|
offerKey: string;
|
|
55
|
-
planId
|
|
56
|
-
plan
|
|
57
|
-
interval
|
|
58
|
-
intervalCount
|
|
55
|
+
planId: string;
|
|
56
|
+
plan: string;
|
|
57
|
+
interval: BillingOfferInterval;
|
|
58
|
+
intervalCount: number;
|
|
59
59
|
}
|
|
60
60
|
export interface BillingSubscriptionChange {
|
|
61
61
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../../src/billing/types/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../../src/billing/types/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,yBAAyB,GACjC,YAAY,GACZ,oBAAoB,GACpB,UAAU,GACV,QAAQ,GACR,UAAU,GACV,UAAU,GACV,QAAQ,G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;IACpC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,MAAM,CAAC;CACzE;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/E,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,cAAc,GAAG,cAAc,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../../src/billing/types/subscriptions.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,kBAAkB,EAAE,oBAAoB;IACxC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CAC0C,CAAC","sourcesContent":["import type { ProviderRef } from \"./common.js\";\n\nexport type BillingSubscriptionStatus =\n | \"incomplete\"\n | \"incomplete_expired\"\n | \"trialing\"\n | \"active\"\n | \"past_due\"\n | \"canceled\"\n | \"unpaid\"\n | \"paused\"\n | \"expired\";\n\nexport const SUBSCRIPTION_STATUS = {\n ACTIVE: \"active\",\n TRIALING: \"trialing\",\n CANCELED: \"canceled\",\n INCOMPLETE: \"incomplete\",\n PAST_DUE: \"past_due\",\n INCOMPLETE_EXPIRED: \"incomplete_expired\",\n UNPAID: \"unpaid\",\n PAUSED: \"paused\",\n EXPIRED: \"expired\",\n} as const satisfies Record<string, BillingSubscriptionStatus>;\n\nexport interface BillingSubscriptionInfo {\n providerSubscriptionId: string;\n status?: BillingSubscriptionStatus | null;\n cancelAtPeriodEnd?: boolean | null;\n periodStart?: string | null;\n periodEnd?: string | null;\n trialEnd?: string | null;\n cancelAt?: string | null;\n endedAt?: string | null;\n refs?: ProviderRef | null;\n interval?: string | null;\n intervalCount?: number | null;\n}\n\nexport interface BillingSubscriptionState {\n subscriptionId?: string | null;\n userId: string;\n provider: string;\n providerSubscriptionId: string;\n providerCustomerId?: string | null;\n offerId?: string | null;\n offerKey?: string | null;\n planId?: string | null;\n plan?: string | null;\n status
|
|
1
|
+
{"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../../src/billing/types/subscriptions.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,kBAAkB,EAAE,oBAAoB;IACxC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CAC0C,CAAC","sourcesContent":["import type { BillingOfferInterval, ProviderRef } from \"./common.js\";\n\nexport type BillingSubscriptionStatus =\n | \"incomplete\"\n | \"incomplete_expired\"\n | \"trialing\"\n | \"active\"\n | \"past_due\"\n | \"canceled\"\n | \"unpaid\"\n | \"paused\"\n | \"expired\";\n\nexport const SUBSCRIPTION_STATUS = {\n ACTIVE: \"active\",\n TRIALING: \"trialing\",\n CANCELED: \"canceled\",\n INCOMPLETE: \"incomplete\",\n PAST_DUE: \"past_due\",\n INCOMPLETE_EXPIRED: \"incomplete_expired\",\n UNPAID: \"unpaid\",\n PAUSED: \"paused\",\n EXPIRED: \"expired\",\n} as const satisfies Record<string, BillingSubscriptionStatus>;\n\nexport interface BillingSubscriptionInfo {\n providerSubscriptionId: string;\n status?: BillingSubscriptionStatus | null;\n cancelAtPeriodEnd?: boolean | null;\n periodStart?: string | null;\n periodEnd?: string | null;\n trialEnd?: string | null;\n cancelAt?: string | null;\n endedAt?: string | null;\n refs?: ProviderRef | null;\n interval?: string | null;\n intervalCount?: number | null;\n}\n\nexport interface BillingSubscriptionState {\n subscriptionId?: string | null;\n userId: string;\n provider: string;\n providerSubscriptionId: string;\n providerCustomerId?: string | null;\n offerId?: string | null;\n offerKey?: string | null;\n planId?: string | null;\n plan?: string | null;\n status: BillingSubscriptionStatus;\n currentPeriodStart?: string | null;\n currentPeriodEnd?: string | null;\n trialEnd?: string | null;\n cancelAt?: string | null;\n endedAt?: string | null;\n graceEndsAt?: string | null;\n graceExpiredAt?: string | null;\n providerUpdatedAt: string;\n cancelAtPeriodEnd: boolean;\n interval?: string | null;\n intervalCount?: number | null;\n metadata?: Record<string, unknown> | null;\n}\n\nexport type BillingSubscriptionChangeState =\n | \"awaiting_payment\"\n | \"scheduled\"\n | \"applied\"\n | \"failed\"\n | \"canceled\";\n\nexport interface BillingSubscriptionOfferContext {\n offerId: string;\n offerKey: string;\n planId: string;\n plan: string;\n interval: BillingOfferInterval;\n intervalCount: number;\n}\n\nexport interface BillingSubscriptionChange {\n id: string;\n subscriptionId: string;\n fromOfferId: string;\n toOfferId: string;\n fromOffer: BillingSubscriptionOfferContext;\n toOffer: BillingSubscriptionOfferContext;\n effectiveAt: string | null;\n effective: \"immediate\" | \"renewal\";\n state: BillingSubscriptionChangeState;\n prorationBehavior: \"provider_default\" | \"invoice_immediately\" | \"none\";\n idempotencyKey: string;\n providerOperationId?: string | null;\n errorMessage?: string | null;\n}\n\nexport interface BillingSubscriptionChangeInput {\n provider: string;\n providerSubscriptionId: string;\n toOfferId: string;\n effectiveAt: string;\n effective: \"immediate\" | \"renewal\";\n idempotencyKey: string;\n prorationBehavior?: \"provider_default\" | \"invoice_immediately\" | \"none\";\n}\n\nexport type CheckoutIntentStatus = \"open\" | \"completed\" | \"failed\" | \"expired\";\n\nexport interface CheckoutIntent {\n id: string;\n subjectId: string;\n provider: string;\n checkoutKind: \"subscription\" | \"credit_topup\";\n productKey: string;\n requestDigest: string;\n status: CheckoutIntentStatus;\n providerSessionId?: string | null;\n checkoutUrl?: string | null;\n expiresAt: string;\n}\n"]}
|
package/dist/bursar.d.ts
CHANGED
|
@@ -4,21 +4,26 @@ import { CreditsService as CreditsServiceImpl, type CreditsServiceOptions } from
|
|
|
4
4
|
import type { CreditStore } from "./credits/store.js";
|
|
5
5
|
import type { CreditEventEmitter } from "./credits/events.js";
|
|
6
6
|
import type { BillingEvent, BillingEventResult } from "./billing/types/index.js";
|
|
7
|
-
import type { BillingCapability
|
|
7
|
+
import type { BillingCapability, BillingEventSink } from "./billing/contracts.js";
|
|
8
8
|
import { CommerceService as CommerceServiceImpl } from "./commerce/service.js";
|
|
9
9
|
import type { CommerceOptions } from "./commerce/types.js";
|
|
10
10
|
import type { CatalogRollout, ParsedBursarConfig } from "./config/types.js";
|
|
11
11
|
import { type PublicCatalog } from "./catalog.js";
|
|
12
12
|
import type { CreditMetadata, GrantProgramAwardResult } from "./credits/types/index.js";
|
|
13
|
-
export type { BillingCapability
|
|
13
|
+
export type { BillingCapability, BillingEventSink } from "./billing/contracts.js";
|
|
14
14
|
export type { CommerceOptions } from "./commerce/types.js";
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Stable public credit capability exposed by {@link Bursar}.
|
|
17
|
+
*
|
|
18
|
+
* The explicit method list prevents implementation helpers added to
|
|
19
|
+
* `CreditsServiceImpl` from silently becoming public API.
|
|
20
|
+
*/
|
|
21
|
+
export type CreditsService = Pick<CreditsServiceImpl, "getUserPlan" | "checkFeature" | "getQuotaState" | "listQuotaEvents" | "startPlanMigration" | "migratePlanBatch" | "revokeCreditsByEntryType" | "executeGrantProgram" | "getLedgerEntry" | "getAvailable" | "aggregateStats" | "spendByUser" | "spendByModel" | "listLedgerEntries" | "listUsageEntries" | "listUsageCharges" | "topUsers" | "dailySpend" | "setUserPlan" | "unsetUserPlan" | "getBalance" | "addCredits" | "deductCredits" | "grantSubscriptionCycle" | "reserve" | "settle" | "release" | "renew" | "canAfford" | "getBucketBalances" | "checkAllowance" | "runBilled" | "beginBilledOperation" | "deduct" | "recordUsage" | "deductFlatJob" | "refundCredits" | "deductTeam" | "sweepExpiredCredits">;
|
|
22
|
+
type CatalogCreditsService = Pick<CreditsServiceImpl, "getActiveCatalog" | "loadCatalogFromStore" | "refreshCatalogIfStale" | "invalidateCatalog" | "publishAndActivateCatalog" | "publishCatalogDraft" | "activateCatalogRevision" | "pricingEngine" | "setPlanRevisionPin" | "applyDuePlanChanges">;
|
|
17
23
|
/** Options for constructing the single application-facing Bursar service. */
|
|
18
24
|
export interface BursarOptions {
|
|
19
25
|
creditStore: CreditStore;
|
|
20
26
|
billingStore?: BillingStore | null;
|
|
21
|
-
credits?: CreditsService | null;
|
|
22
27
|
creditsOptions?: CreditsServiceOptions | null;
|
|
23
28
|
billingOptions?: BillingServiceOptions | null;
|
|
24
29
|
commerceOptions?: CommerceOptions | null;
|
|
@@ -27,13 +32,22 @@ export interface BursarOptions {
|
|
|
27
32
|
/** Catalog operations. Configuration writes live here, never in BillingService. */
|
|
28
33
|
export declare class CatalogService {
|
|
29
34
|
private readonly credits;
|
|
30
|
-
constructor(credits:
|
|
31
|
-
|
|
35
|
+
constructor(credits: CatalogCreditsService);
|
|
36
|
+
/** Return the active persisted catalog revision, if one exists. */
|
|
37
|
+
getActive(): Promise<import("./index.js").CatalogRevision | null>;
|
|
38
|
+
/** Whether this process currently has a pricing engine loaded. */
|
|
39
|
+
get isLoaded(): boolean;
|
|
40
|
+
/** Load the active persisted catalog into this process. */
|
|
41
|
+
load(): Promise<void>;
|
|
42
|
+
/** Block until a stale in-process catalog has been refreshed. */
|
|
43
|
+
refresh(): Promise<void>;
|
|
44
|
+
/** Force the next refresh to reload the active catalog. */
|
|
45
|
+
invalidate(): void;
|
|
32
46
|
getConfig(): Promise<ParsedBursarConfig>;
|
|
33
47
|
publicView(): Promise<PublicCatalog>;
|
|
34
48
|
publishDraft(config: Record<string, unknown>, label?: string | null): Promise<string>;
|
|
35
49
|
activate(version: number, rollout?: CatalogRollout | Record<string, unknown> | null): Promise<string>;
|
|
36
|
-
publishAndActivate(config: Record<string, unknown>, label?: string | null, rollout?: CatalogRollout | Record<string, unknown> | null): Promise<
|
|
50
|
+
publishAndActivate(config: Record<string, unknown>, label?: string | null, rollout?: CatalogRollout | Record<string, unknown> | null): Promise<string>;
|
|
37
51
|
/** Pin or unpin one current assignment from automatic catalog rollout. */
|
|
38
52
|
setRevisionPin(userId: string, pinned: boolean): Promise<boolean>;
|
|
39
53
|
/** Apply one bounded batch of renewal-effective plan changes. */
|
|
@@ -68,13 +82,17 @@ export declare class AccountService {
|
|
|
68
82
|
*/
|
|
69
83
|
export declare class Bursar implements BillingEventSink {
|
|
70
84
|
readonly credits: CreditsService;
|
|
71
|
-
readonly billing:
|
|
85
|
+
readonly billing: BillingCapability | null;
|
|
72
86
|
readonly commerce: CommerceServiceImpl | null;
|
|
73
87
|
readonly catalog: CatalogService;
|
|
74
88
|
readonly accounts: AccountService;
|
|
75
89
|
constructor(options: BursarOptions);
|
|
76
90
|
/** Load the active catalog into the pricing engine. */
|
|
77
91
|
loadCatalog(): Promise<void>;
|
|
92
|
+
/** Return billing or raise the SDK's typed configuration error. */
|
|
93
|
+
requireBilling(): BillingCapability;
|
|
94
|
+
/** Return commerce or raise the SDK's typed configuration error. */
|
|
95
|
+
requireCommerce(): CommerceServiceImpl;
|
|
78
96
|
/**
|
|
79
97
|
* Ingest a normalized provider event through the facade-owned billing
|
|
80
98
|
* lifecycle. Providers must not depend on BillingService directly.
|
package/dist/bursar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bursar.d.ts","sourceRoot":"","sources":["../src/bursar.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,KAAK,qBAAqB,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"bursar.d.ts","sourceRoot":"","sources":["../src/bursar.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,KAAK,qBAAqB,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACj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,IAAI,CAAC;IAIlC,mEAAmE;IACnE,cAAc,IAAI,iBAAiB;IAOnC,oEAAoE;IACpE,eAAe,IAAI,mBAAmB;IAOtC;;;OAGG;IACG,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAG3E"}
|
package/dist/bursar.js
CHANGED
|
@@ -3,7 +3,7 @@ import { CreditsService as CreditsServiceImpl, } from "./credits/service.js";
|
|
|
3
3
|
import { CommerceService as CommerceServiceImpl } from "./commerce/service.js";
|
|
4
4
|
import { CommerceNotConfiguredError } from "./commerce/errors.js";
|
|
5
5
|
import { loadConfigFromDict } from "./config.js";
|
|
6
|
-
import { ConfigError,
|
|
6
|
+
import { CapabilityNotConfiguredError, ConfigError, CatalogNotLoadedError } from "./errors.js";
|
|
7
7
|
import { projectPublicCatalog } from "./catalog.js";
|
|
8
8
|
import { retryBursarOperation } from "./retry.js";
|
|
9
9
|
/** Catalog operations. Configuration writes live here, never in BillingService. */
|
|
@@ -12,26 +12,43 @@ export class CatalogService {
|
|
|
12
12
|
constructor(credits) {
|
|
13
13
|
this.credits = credits;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/** Return the active persisted catalog revision, if one exists. */
|
|
16
|
+
getActive() {
|
|
17
|
+
return this.credits.getActiveCatalog();
|
|
18
|
+
}
|
|
19
|
+
/** Whether this process currently has a pricing engine loaded. */
|
|
20
|
+
get isLoaded() {
|
|
21
|
+
return this.credits.pricingEngine !== null;
|
|
22
|
+
}
|
|
23
|
+
/** Load the active persisted catalog into this process. */
|
|
24
|
+
load() {
|
|
25
|
+
return this.credits.loadCatalogFromStore();
|
|
26
|
+
}
|
|
27
|
+
/** Block until a stale in-process catalog has been refreshed. */
|
|
28
|
+
refresh() {
|
|
29
|
+
return this.credits.refreshCatalogIfStale();
|
|
30
|
+
}
|
|
31
|
+
/** Force the next refresh to reload the active catalog. */
|
|
32
|
+
invalidate() {
|
|
33
|
+
this.credits.invalidateCatalog();
|
|
17
34
|
}
|
|
18
35
|
async getConfig() {
|
|
19
|
-
const active = await this.
|
|
36
|
+
const active = await this.getActive();
|
|
20
37
|
if (!active)
|
|
21
|
-
throw new
|
|
38
|
+
throw new CatalogNotLoadedError("No active Bursar catalog is available");
|
|
22
39
|
return loadConfigFromDict(active.config);
|
|
23
40
|
}
|
|
24
41
|
async publicView() {
|
|
25
42
|
return projectPublicCatalog(await this.getConfig());
|
|
26
43
|
}
|
|
27
44
|
publishDraft(config, label) {
|
|
28
|
-
return this.credits.
|
|
45
|
+
return this.credits.publishCatalogDraft(config, label);
|
|
29
46
|
}
|
|
30
47
|
activate(version, rollout) {
|
|
31
|
-
return this.credits.
|
|
48
|
+
return this.credits.activateCatalogRevision(version, rollout);
|
|
32
49
|
}
|
|
33
50
|
publishAndActivate(config, label, rollout) {
|
|
34
|
-
return this.credits.
|
|
51
|
+
return this.credits.publishAndActivateCatalog(config, label, rollout);
|
|
35
52
|
}
|
|
36
53
|
/** Pin or unpin one current assignment from automatic catalog rollout. */
|
|
37
54
|
setRevisionPin(userId, pinned) {
|
|
@@ -99,39 +116,50 @@ export class Bursar {
|
|
|
99
116
|
catalog;
|
|
100
117
|
accounts;
|
|
101
118
|
constructor(options) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
this.accounts = new AccountService(this.credits, this.catalog);
|
|
119
|
+
const credits = new CreditsServiceImpl(options.creditStore, undefined, options.emitter ?? undefined, options.creditsOptions ?? undefined);
|
|
120
|
+
this.credits = credits;
|
|
121
|
+
this.catalog = new CatalogService(credits);
|
|
122
|
+
this.accounts = new AccountService(credits, this.catalog);
|
|
107
123
|
this.billing = options.billingStore
|
|
108
124
|
? new BillingEventService(options.billingStore, {
|
|
109
125
|
...(options.billingOptions ?? {}),
|
|
110
|
-
provisioning:
|
|
126
|
+
provisioning: credits,
|
|
111
127
|
})
|
|
112
128
|
: null;
|
|
113
129
|
this.commerce =
|
|
114
130
|
this.billing && options.commerceOptions
|
|
115
|
-
? new CommerceServiceImpl(this.billing,
|
|
131
|
+
? new CommerceServiceImpl(this.billing, credits, this, options.commerceOptions)
|
|
116
132
|
: null;
|
|
117
133
|
if (this.commerce) {
|
|
118
|
-
|
|
134
|
+
credits.addPostDeductionHook(async ({ userId }) => {
|
|
119
135
|
await this.commerce.autoRecharge.processIfNeeded({ accountId: userId });
|
|
120
136
|
});
|
|
121
137
|
}
|
|
122
138
|
}
|
|
123
139
|
/** Load the active catalog into the pricing engine. */
|
|
124
140
|
async loadCatalog() {
|
|
125
|
-
await this.
|
|
141
|
+
await this.catalog.load();
|
|
142
|
+
}
|
|
143
|
+
/** Return billing or raise the SDK's typed configuration error. */
|
|
144
|
+
requireBilling() {
|
|
145
|
+
if (!this.billing) {
|
|
146
|
+
throw new CapabilityNotConfiguredError("billing");
|
|
147
|
+
}
|
|
148
|
+
return this.billing;
|
|
149
|
+
}
|
|
150
|
+
/** Return commerce or raise the SDK's typed configuration error. */
|
|
151
|
+
requireCommerce() {
|
|
152
|
+
if (!this.commerce) {
|
|
153
|
+
throw new CommerceNotConfiguredError("Bursar commerce capability is not configured");
|
|
154
|
+
}
|
|
155
|
+
return this.commerce;
|
|
126
156
|
}
|
|
127
157
|
/**
|
|
128
158
|
* Ingest a normalized provider event through the facade-owned billing
|
|
129
159
|
* lifecycle. Providers must not depend on BillingService directly.
|
|
130
160
|
*/
|
|
131
161
|
async ingestBillingEvent(event) {
|
|
132
|
-
|
|
133
|
-
throw new CommerceNotConfiguredError("Bursar billing capability is not configured");
|
|
134
|
-
return this.billing.ingestBillingEvent(event);
|
|
162
|
+
return this.requireBilling().ingestBillingEvent(event);
|
|
135
163
|
}
|
|
136
164
|
}
|
|
137
165
|
//# sourceMappingURL=bursar.js.map
|