@owlmeans/server-payment 0.1.18-rc.9 → 0.1.19-rc.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 +157 -26
- package/agent-meta/manifest.json +30 -4
- package/agent-meta/skills/server-payment/SKILL.md +639 -54
- package/agent-meta/skills/server-payment/parts/reference.md +174 -0
- package/build/access/types.d.ts +46 -0
- package/build/access/types.d.ts.map +1 -0
- package/build/access/types.js +2 -0
- package/build/access/types.js.map +1 -0
- package/build/access.d.ts +6 -0
- package/build/access.d.ts.map +1 -0
- package/build/access.js +45 -0
- package/build/access.js.map +1 -0
- package/build/actions/index.d.ts +1 -0
- package/build/actions/index.d.ts.map +1 -1
- package/build/actions/index.js +1 -0
- package/build/actions/index.js.map +1 -1
- package/build/actions/resync-subscriptions.d.ts +3 -0
- package/build/actions/resync-subscriptions.d.ts.map +1 -0
- package/build/actions/resync-subscriptions.js +7 -0
- package/build/actions/resync-subscriptions.js.map +1 -0
- package/build/actions/resync.d.ts +6 -1
- package/build/actions/resync.d.ts.map +1 -1
- package/build/actions/resync.js +15 -5
- package/build/actions/resync.js.map +1 -1
- package/build/actions/webhook.d.ts +2 -1
- package/build/actions/webhook.d.ts.map +1 -1
- package/build/actions/webhook.js +10 -4
- package/build/actions/webhook.js.map +1 -1
- package/build/bootstrap/types.d.ts +16 -0
- package/build/bootstrap/types.d.ts.map +1 -0
- package/build/bootstrap/types.js +2 -0
- package/build/bootstrap/types.js.map +1 -0
- package/build/bootstrap.d.ts +6 -0
- package/build/bootstrap.d.ts.map +1 -0
- package/build/bootstrap.js +26 -0
- package/build/bootstrap.js.map +1 -0
- package/build/catalogue/types.d.ts +38 -0
- package/build/catalogue/types.d.ts.map +1 -0
- package/build/catalogue/types.js +2 -0
- package/build/catalogue/types.js.map +1 -0
- package/build/catalogue.d.ts +6 -0
- package/build/catalogue.d.ts.map +1 -0
- package/build/catalogue.js +110 -0
- package/build/catalogue.js.map +1 -0
- package/build/commit/types.d.ts +22 -0
- package/build/commit/types.d.ts.map +1 -0
- package/build/commit/types.js +2 -0
- package/build/commit/types.js.map +1 -0
- package/build/commit.d.ts +6 -0
- package/build/commit.d.ts.map +1 -0
- package/build/commit.js +125 -0
- package/build/commit.js.map +1 -0
- package/build/config.d.ts +44 -5
- package/build/config.d.ts.map +1 -1
- package/build/config.js +216 -10
- package/build/config.js.map +1 -1
- package/build/consts.d.ts +74 -16
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +86 -23
- package/build/consts.js.map +1 -1
- package/build/consts.local.d.ts +94 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +44 -0
- package/build/consts.local.js.map +1 -0
- package/build/consumer/cancellation/types.d.ts +11 -0
- package/build/consumer/cancellation/types.d.ts.map +1 -0
- package/build/consumer/cancellation/types.js +2 -0
- package/build/consumer/cancellation/types.js.map +1 -0
- package/build/consumer/cancellation.d.ts +6 -0
- package/build/consumer/cancellation.d.ts.map +1 -0
- package/build/consumer/cancellation.js +33 -0
- package/build/consumer/cancellation.js.map +1 -0
- package/build/consumer/capture/types.d.ts +50 -0
- package/build/consumer/capture/types.d.ts.map +1 -0
- package/build/consumer/capture/types.js +2 -0
- package/build/consumer/capture/types.js.map +1 -0
- package/build/consumer/capture.d.ts +6 -0
- package/build/consumer/capture.d.ts.map +1 -0
- package/build/consumer/capture.js +285 -0
- package/build/consumer/capture.js.map +1 -0
- package/build/consumer/consts.local.d.ts +10 -0
- package/build/consumer/consts.local.d.ts.map +1 -0
- package/build/consumer/consts.local.js +11 -0
- package/build/consumer/consts.local.js.map +1 -0
- package/build/consumer/format/types.d.ts +30 -0
- package/build/consumer/format/types.d.ts.map +1 -0
- package/build/consumer/format/types.js +2 -0
- package/build/consumer/format/types.js.map +1 -0
- package/build/consumer/format.d.ts +4 -0
- package/build/consumer/format.d.ts.map +1 -0
- package/build/consumer/format.js +73 -0
- package/build/consumer/format.js.map +1 -0
- package/build/consumer/handlers.d.ts +21 -0
- package/build/consumer/handlers.d.ts.map +1 -0
- package/build/consumer/handlers.js +174 -0
- package/build/consumer/handlers.js.map +1 -0
- package/build/consumer/index.d.ts +10 -0
- package/build/consumer/index.d.ts.map +1 -0
- package/build/consumer/index.js +6 -0
- package/build/consumer/index.js.map +1 -0
- package/build/consumer/mail/types.d.ts +29 -0
- package/build/consumer/mail/types.d.ts.map +1 -0
- package/build/consumer/mail/types.js +2 -0
- package/build/consumer/mail/types.js.map +1 -0
- package/build/consumer/mail.d.ts +6 -0
- package/build/consumer/mail.d.ts.map +1 -0
- package/build/consumer/mail.js +313 -0
- package/build/consumer/mail.js.map +1 -0
- package/build/consumer/observers/types.d.ts +15 -0
- package/build/consumer/observers/types.d.ts.map +1 -0
- package/build/consumer/observers/types.js +2 -0
- package/build/consumer/observers/types.js.map +1 -0
- package/build/consumer/observers.d.ts +6 -0
- package/build/consumer/observers.d.ts.map +1 -0
- package/build/consumer/observers.js +74 -0
- package/build/consumer/observers.js.map +1 -0
- package/build/consumer/origin/types.d.ts +17 -0
- package/build/consumer/origin/types.d.ts.map +1 -0
- package/build/consumer/origin/types.js +2 -0
- package/build/consumer/origin/types.js.map +1 -0
- package/build/consumer/origin.d.ts +8 -0
- package/build/consumer/origin.d.ts.map +1 -0
- package/build/consumer/origin.js +43 -0
- package/build/consumer/origin.js.map +1 -0
- package/build/consumer/reconcile/types.d.ts +13 -0
- package/build/consumer/reconcile/types.d.ts.map +1 -0
- package/build/consumer/reconcile/types.js +2 -0
- package/build/consumer/reconcile/types.js.map +1 -0
- package/build/consumer/reconcile.d.ts +5 -0
- package/build/consumer/reconcile.d.ts.map +1 -0
- package/build/consumer/reconcile.js +321 -0
- package/build/consumer/reconcile.js.map +1 -0
- package/build/consumer/records/types.d.ts +66 -0
- package/build/consumer/records/types.d.ts.map +1 -0
- package/build/consumer/records/types.js +2 -0
- package/build/consumer/records/types.js.map +1 -0
- package/build/consumer/records.d.ts +6 -0
- package/build/consumer/records.d.ts.map +1 -0
- package/build/consumer/records.js +243 -0
- package/build/consumer/records.js.map +1 -0
- package/build/consumer/service.d.ts +28 -0
- package/build/consumer/service.d.ts.map +1 -0
- package/build/consumer/service.js +706 -0
- package/build/consumer/service.js.map +1 -0
- package/build/consumer/types.d.ts +84 -0
- package/build/consumer/types.d.ts.map +1 -0
- package/build/consumer/types.js +2 -0
- package/build/consumer/types.js.map +1 -0
- package/build/consumer/types.local.d.ts +26 -0
- package/build/consumer/types.local.d.ts.map +1 -0
- package/build/consumer/types.local.js +2 -0
- package/build/consumer/types.local.js.map +1 -0
- package/build/consumer/withdrawal/types.d.ts +36 -0
- package/build/consumer/withdrawal/types.d.ts.map +1 -0
- package/build/consumer/withdrawal/types.js +2 -0
- package/build/consumer/withdrawal/types.js.map +1 -0
- package/build/consumer/withdrawal.d.ts +6 -0
- package/build/consumer/withdrawal.d.ts.map +1 -0
- package/build/consumer/withdrawal.js +237 -0
- package/build/consumer/withdrawal.js.map +1 -0
- package/build/entitlement.d.ts +4 -0
- package/build/entitlement.d.ts.map +1 -0
- package/build/entitlement.js +72 -0
- package/build/entitlement.js.map +1 -0
- package/build/entrypoints.d.ts +19 -2
- package/build/entrypoints.d.ts.map +1 -1
- package/build/entrypoints.js +16 -4
- package/build/entrypoints.js.map +1 -1
- package/build/gate/request.d.ts +4 -0
- package/build/gate/request.d.ts.map +1 -0
- package/build/gate/request.js +17 -0
- package/build/gate/request.js.map +1 -0
- package/build/gate/types.d.ts +15 -0
- package/build/gate/types.d.ts.map +1 -0
- package/build/gate/types.js +2 -0
- package/build/gate/types.js.map +1 -0
- package/build/gate.d.ts +13 -9
- package/build/gate.d.ts.map +1 -1
- package/build/gate.js +36 -21
- package/build/gate.js.map +1 -1
- package/build/index.d.ts +50 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +29 -3
- package/build/index.js.map +1 -1
- package/build/limit.d.ts +11 -0
- package/build/limit.d.ts.map +1 -0
- package/build/limit.js +48 -0
- package/build/limit.js.map +1 -0
- package/build/log.d.ts +3 -0
- package/build/log.d.ts.map +1 -0
- package/build/log.js +4 -0
- package/build/log.js.map +1 -0
- package/build/models/declarations/types.d.ts +22 -0
- package/build/models/declarations/types.d.ts.map +1 -0
- package/build/models/declarations/types.js +2 -0
- package/build/models/declarations/types.js.map +1 -0
- package/build/models/declarations.d.ts +4 -0
- package/build/models/declarations.d.ts.map +1 -0
- package/build/models/declarations.js +26 -0
- package/build/models/declarations.js.map +1 -0
- package/build/models/purchase/types.d.ts +13 -0
- package/build/models/purchase/types.d.ts.map +1 -0
- package/build/models/purchase/types.js +2 -0
- package/build/models/purchase/types.js.map +1 -0
- package/build/models/purchase.d.ts +4 -0
- package/build/models/purchase.d.ts.map +1 -0
- package/build/models/purchase.js +37 -0
- package/build/models/purchase.js.map +1 -0
- package/build/observer.d.ts +9 -0
- package/build/observer.d.ts.map +1 -1
- package/build/observer.js +38 -12
- package/build/observer.js.map +1 -1
- package/build/plan/types.d.ts +21 -0
- package/build/plan/types.d.ts.map +1 -0
- package/build/plan/types.js +2 -0
- package/build/plan/types.js.map +1 -0
- package/build/plan.d.ts +7 -0
- package/build/plan.d.ts.map +1 -0
- package/build/plan.js +29 -0
- package/build/plan.js.map +1 -0
- package/build/plugins/checkout-plugins/types.d.ts +25 -0
- package/build/plugins/checkout-plugins/types.d.ts.map +1 -0
- package/build/plugins/checkout-plugins/types.js +2 -0
- package/build/plugins/checkout-plugins/types.js.map +1 -0
- package/build/plugins/checkout-plugins.d.ts +12 -0
- package/build/plugins/checkout-plugins.d.ts.map +1 -0
- package/build/plugins/checkout-plugins.js +72 -0
- package/build/plugins/checkout-plugins.js.map +1 -0
- package/build/plugins/checkout-policy/types.d.ts +18 -0
- package/build/plugins/checkout-policy/types.d.ts.map +1 -0
- package/build/plugins/checkout-policy/types.js +2 -0
- package/build/plugins/checkout-policy/types.js.map +1 -0
- package/build/plugins/checkout-policy.d.ts +4 -0
- package/build/plugins/checkout-policy.d.ts.map +1 -0
- package/build/plugins/checkout-policy.js +26 -0
- package/build/plugins/checkout-policy.js.map +1 -0
- package/build/plugins/checkout-registry/types.d.ts +7 -0
- package/build/plugins/checkout-registry/types.d.ts.map +1 -0
- package/build/plugins/checkout-registry/types.js +2 -0
- package/build/plugins/checkout-registry/types.js.map +1 -0
- package/build/plugins/checkout-registry.d.ts +8 -0
- package/build/plugins/checkout-registry.d.ts.map +1 -0
- package/build/plugins/checkout-registry.js +21 -0
- package/build/plugins/checkout-registry.js.map +1 -0
- package/build/plugins/consts.local.d.ts +13 -0
- package/build/plugins/consts.local.d.ts.map +1 -0
- package/build/plugins/consts.local.js +22 -0
- package/build/plugins/consts.local.js.map +1 -0
- package/build/plugins/customer-lock/types.d.ts +6 -0
- package/build/plugins/customer-lock/types.d.ts.map +1 -0
- package/build/plugins/customer-lock/types.js +2 -0
- package/build/plugins/customer-lock/types.js.map +1 -0
- package/build/plugins/customer-lock.d.ts +5 -0
- package/build/plugins/customer-lock.d.ts.map +1 -0
- package/build/plugins/customer-lock.js +22 -0
- package/build/plugins/customer-lock.js.map +1 -0
- package/build/plugins/estimate/cache.d.ts +4 -0
- package/build/plugins/estimate/cache.d.ts.map +1 -0
- package/build/plugins/estimate/cache.js +7 -0
- package/build/plugins/estimate/cache.js.map +1 -0
- package/build/plugins/estimate/types.d.ts +27 -0
- package/build/plugins/estimate/types.d.ts.map +1 -0
- package/build/plugins/estimate/types.js +2 -0
- package/build/plugins/estimate/types.js.map +1 -0
- package/build/plugins/estimate.d.ts +6 -0
- package/build/plugins/estimate.d.ts.map +1 -0
- package/build/plugins/estimate.js +271 -0
- package/build/plugins/estimate.js.map +1 -0
- package/build/plugins/events/types.d.ts +12 -0
- package/build/plugins/events/types.d.ts.map +1 -0
- package/build/plugins/events/types.js +2 -0
- package/build/plugins/events/types.js.map +1 -0
- package/build/plugins/events.d.ts +6 -13
- package/build/plugins/events.d.ts.map +1 -1
- package/build/plugins/events.js +445 -145
- package/build/plugins/events.js.map +1 -1
- package/build/plugins/fx/types.d.ts +33 -0
- package/build/plugins/fx/types.d.ts.map +1 -0
- package/build/plugins/fx/types.js +2 -0
- package/build/plugins/fx/types.js.map +1 -0
- package/build/plugins/fx.d.ts +6 -0
- package/build/plugins/fx.d.ts.map +1 -0
- package/build/plugins/fx.js +83 -0
- package/build/plugins/fx.js.map +1 -0
- package/build/plugins/portal/types.d.ts +44 -0
- package/build/plugins/portal/types.d.ts.map +1 -0
- package/build/plugins/portal/types.js +2 -0
- package/build/plugins/portal/types.js.map +1 -0
- package/build/plugins/portal.d.ts +6 -0
- package/build/plugins/portal.d.ts.map +1 -0
- package/build/plugins/portal.js +255 -0
- package/build/plugins/portal.js.map +1 -0
- package/build/plugins/refunds/types.d.ts +35 -0
- package/build/plugins/refunds/types.d.ts.map +1 -0
- package/build/plugins/refunds/types.js +2 -0
- package/build/plugins/refunds/types.js.map +1 -0
- package/build/plugins/refunds.d.ts +6 -0
- package/build/plugins/refunds.d.ts.map +1 -0
- package/build/plugins/refunds.js +81 -0
- package/build/plugins/refunds.js.map +1 -0
- package/build/plugins/session/types.d.ts +34 -0
- package/build/plugins/session/types.d.ts.map +1 -0
- package/build/plugins/session/types.js +2 -0
- package/build/plugins/session/types.js.map +1 -0
- package/build/plugins/session.d.ts +4 -0
- package/build/plugins/session.d.ts.map +1 -0
- package/build/plugins/session.js +71 -0
- package/build/plugins/session.js.map +1 -0
- package/build/plugins/status.d.ts +8 -0
- package/build/plugins/status.d.ts.map +1 -0
- package/build/plugins/status.js +21 -0
- package/build/plugins/status.js.map +1 -0
- package/build/plugins/stripe/types.d.ts +20 -0
- package/build/plugins/stripe/types.d.ts.map +1 -0
- package/build/plugins/stripe/types.js +2 -0
- package/build/plugins/stripe/types.js.map +1 -0
- package/build/plugins/stripe.d.ts +5 -13
- package/build/plugins/stripe.d.ts.map +1 -1
- package/build/plugins/stripe.js +481 -129
- package/build/plugins/stripe.js.map +1 -1
- package/build/plugins/subscriptions/types.d.ts +41 -0
- package/build/plugins/subscriptions/types.d.ts.map +1 -0
- package/build/plugins/subscriptions/types.js +2 -0
- package/build/plugins/subscriptions/types.js.map +1 -0
- package/build/plugins/subscriptions.d.ts +6 -0
- package/build/plugins/subscriptions.d.ts.map +1 -0
- package/build/plugins/subscriptions.js +169 -0
- package/build/plugins/subscriptions.js.map +1 -0
- package/build/plugins/types.d.ts +7 -0
- package/build/plugins/types.d.ts.map +1 -0
- package/build/plugins/types.js +2 -0
- package/build/plugins/types.js.map +1 -0
- package/build/plugins/types.local.d.ts +75 -0
- package/build/plugins/types.local.d.ts.map +1 -0
- package/build/plugins/types.local.js +2 -0
- package/build/plugins/types.local.js.map +1 -0
- package/build/plugins/webhook-manager/types.d.ts +62 -0
- package/build/plugins/webhook-manager/types.d.ts.map +1 -0
- package/build/plugins/webhook-manager/types.js +2 -0
- package/build/plugins/webhook-manager/types.js.map +1 -0
- package/build/plugins/webhook-manager.d.ts +8 -0
- package/build/plugins/webhook-manager.d.ts.map +1 -0
- package/build/plugins/webhook-manager.js +245 -0
- package/build/plugins/webhook-manager.js.map +1 -0
- package/build/protocol.d.ts +13 -0
- package/build/protocol.d.ts.map +1 -0
- package/build/protocol.js +17 -0
- package/build/protocol.js.map +1 -0
- package/build/reconcile/types.d.ts +17 -0
- package/build/reconcile/types.d.ts.map +1 -0
- package/build/reconcile/types.js +2 -0
- package/build/reconcile/types.js.map +1 -0
- package/build/reconcile.d.ts +12 -0
- package/build/reconcile.d.ts.map +1 -0
- package/build/reconcile.js +91 -0
- package/build/reconcile.js.map +1 -0
- package/build/resource.d.ts +12 -1
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +97 -6
- package/build/resource.js.map +1 -1
- package/build/schemas.d.ts +19 -0
- package/build/schemas.d.ts.map +1 -0
- package/build/schemas.js +244 -0
- package/build/schemas.js.map +1 -0
- package/build/service.d.ts +28 -3
- package/build/service.d.ts.map +1 -1
- package/build/service.js +140 -19
- package/build/service.js.map +1 -1
- package/build/subscription/types.d.ts +21 -0
- package/build/subscription/types.d.ts.map +1 -0
- package/build/subscription/types.js +2 -0
- package/build/subscription/types.js.map +1 -0
- package/build/subscription.d.ts +4 -0
- package/build/subscription.d.ts.map +1 -0
- package/build/subscription.js +84 -0
- package/build/subscription.js.map +1 -0
- package/build/sync/types.d.ts +25 -0
- package/build/sync/types.d.ts.map +1 -0
- package/build/sync/types.js +2 -0
- package/build/sync/types.js.map +1 -0
- package/build/sync.d.ts +4 -3
- package/build/sync.d.ts.map +1 -1
- package/build/sync.js +231 -79
- package/build/sync.js.map +1 -1
- package/build/types.d.ts +1262 -36
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +22 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/usage/types.d.ts +56 -0
- package/build/usage/types.d.ts.map +1 -0
- package/build/usage/types.js +2 -0
- package/build/usage/types.js.map +1 -0
- package/build/usage.d.ts +6 -0
- package/build/usage.d.ts.map +1 -0
- package/build/usage.js +365 -0
- package/build/usage.js.map +1 -0
- package/build/utils/types.d.ts +31 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils.d.ts +21 -7
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +56 -17
- package/build/utils.js.map +1 -1
- package/package.json +22 -17
- package/src/access/types.ts +52 -0
- package/src/access.ts +86 -0
- package/src/actions/index.ts +1 -0
- package/src/actions/resync-subscriptions.ts +10 -0
- package/src/actions/resync.ts +14 -5
- package/src/actions/webhook.ts +9 -4
- package/src/bootstrap/types.ts +16 -0
- package/src/bootstrap.ts +31 -0
- package/src/catalogue/types.ts +32 -0
- package/src/catalogue.ts +135 -0
- package/src/commit/types.ts +27 -0
- package/src/commit.ts +152 -0
- package/src/config.ts +234 -14
- package/src/consts.local.ts +62 -0
- package/src/consts.ts +100 -36
- package/src/consumer/cancellation/types.ts +13 -0
- package/src/consumer/cancellation.ts +43 -0
- package/src/consumer/capture/types.ts +53 -0
- package/src/consumer/capture.ts +322 -0
- package/src/consumer/consts.local.ts +18 -0
- package/src/consumer/format/types.ts +29 -0
- package/src/consumer/format.ts +85 -0
- package/src/consumer/handlers.ts +204 -0
- package/src/consumer/index.ts +9 -0
- package/src/consumer/mail/types.ts +31 -0
- package/src/consumer/mail.ts +353 -0
- package/src/consumer/observers/types.ts +22 -0
- package/src/consumer/observers.ts +97 -0
- package/src/consumer/origin/types.ts +17 -0
- package/src/consumer/origin.ts +61 -0
- package/src/consumer/reconcile/types.ts +13 -0
- package/src/consumer/reconcile.ts +331 -0
- package/src/consumer/records/types.ts +64 -0
- package/src/consumer/records.ts +288 -0
- package/src/consumer/service.ts +768 -0
- package/src/consumer/types.local.ts +22 -0
- package/src/consumer/types.ts +96 -0
- package/src/consumer/withdrawal/types.ts +37 -0
- package/src/consumer/withdrawal.ts +268 -0
- package/src/entitlement.ts +85 -0
- package/src/entrypoints.ts +17 -4
- package/src/gate/request.ts +24 -0
- package/src/gate/types.ts +13 -0
- package/src/gate.ts +47 -30
- package/src/index.ts +55 -3
- package/src/limit.ts +54 -0
- package/src/log.ts +4 -0
- package/src/models/declarations/types.ts +22 -0
- package/src/models/declarations.ts +30 -0
- package/src/models/purchase/types.ts +13 -0
- package/src/models/purchase.ts +43 -0
- package/src/observer.ts +44 -11
- package/src/plan/types.ts +21 -0
- package/src/plan.ts +46 -0
- package/src/plugins/checkout-plugins/types.ts +25 -0
- package/src/plugins/checkout-plugins.ts +90 -0
- package/src/plugins/checkout-policy/types.ts +18 -0
- package/src/plugins/checkout-policy.ts +34 -0
- package/src/plugins/checkout-registry/types.ts +7 -0
- package/src/plugins/checkout-registry.ts +23 -0
- package/src/plugins/consts.local.ts +30 -0
- package/src/plugins/customer-lock/types.ts +5 -0
- package/src/plugins/customer-lock.ts +25 -0
- package/src/plugins/estimate/cache.ts +12 -0
- package/src/plugins/estimate/types.ts +28 -0
- package/src/plugins/estimate.ts +305 -0
- package/src/plugins/events/types.ts +11 -0
- package/src/plugins/events.ts +470 -133
- package/src/plugins/fx/types.ts +40 -0
- package/src/plugins/fx.ts +101 -0
- package/src/plugins/portal/types.ts +45 -0
- package/src/plugins/portal.ts +284 -0
- package/src/plugins/refunds/types.ts +31 -0
- package/src/plugins/refunds.ts +95 -0
- package/src/plugins/session/types.ts +30 -0
- package/src/plugins/session.ts +86 -0
- package/src/plugins/status.ts +22 -0
- package/src/plugins/stripe/types.ts +20 -0
- package/src/plugins/stripe.ts +523 -135
- package/src/plugins/subscriptions/types.ts +39 -0
- package/src/plugins/subscriptions.ts +195 -0
- package/src/plugins/types.local.ts +61 -0
- package/src/plugins/types.ts +7 -0
- package/src/plugins/webhook-manager/types.ts +63 -0
- package/src/plugins/webhook-manager.ts +288 -0
- package/src/protocol.ts +29 -0
- package/src/reconcile/types.ts +17 -0
- package/src/reconcile.ts +110 -0
- package/src/resource.ts +158 -11
- package/src/schemas.ts +271 -0
- package/src/service.ts +161 -19
- package/src/subscription/types.ts +23 -0
- package/src/subscription.ts +104 -0
- package/src/sync/types.ts +25 -0
- package/src/sync.ts +255 -72
- package/src/types.local.ts +18 -0
- package/src/types.ts +1369 -32
- package/src/usage/types.ts +51 -0
- package/src/usage.ts +432 -0
- package/src/utils/types.ts +30 -0
- package/src/utils.ts +94 -29
- package/tests/checkout-consumer.spec.ts +366 -0
- package/tests/checkout-locks.spec.ts +161 -0
- package/tests/checkout-plugins.spec.ts +164 -0
- package/tests/checkout.spec.ts +271 -93
- package/tests/consumer-events.spec.ts +215 -0
- package/tests/consumer-fixtures.ts +141 -0
- package/tests/consumer-ops.spec.ts +361 -0
- package/tests/consumer-rights.integration.spec.ts +147 -0
- package/tests/consumer-rights.spec.ts +606 -0
- package/tests/context.ts +110 -0
- package/tests/entitlement.spec.ts +139 -0
- package/tests/estimate.spec.ts +350 -0
- package/tests/events.spec.ts +367 -0
- package/tests/fake-stripe.ts +987 -0
- package/tests/gate-handlers.spec.ts +120 -0
- package/tests/gate.spec.ts +63 -72
- package/tests/gateway-options.spec.ts +180 -0
- package/tests/limit-gate.spec.ts +66 -0
- package/tests/portal.spec.ts +202 -0
- package/tests/protocol.spec.ts +17 -3
- package/tests/sync.spec.ts +114 -0
- package/tests/usage.integration.spec.ts +133 -0
- package/tests/usage.spec.ts +169 -0
- package/tests/webhook-manager.spec.ts +149 -0
- package/build/model.d.ts +0 -6
- package/build/model.d.ts.map +0 -1
- package/build/model.js +0 -33
- package/build/model.js.map +0 -1
- package/src/model.ts +0 -37
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import { MAILER_SERVICE } from '@owlmeans/mailer'
|
|
3
|
+
import {
|
|
4
|
+
CancellationStatus, DeclarationKind, ENTITLING_STATUSES, PurchaseKind, WithdrawalStatus,
|
|
5
|
+
} from '@owlmeans/payment'
|
|
6
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
7
|
+
import { PURCHASE_BACKFILL_DAYS, STRIPE_PAYGATE_ALIAS } from '../consts.js'
|
|
8
|
+
import type { ConsumerRightsInternals, WithdrawalComputation } from './types.js'
|
|
9
|
+
import type {
|
|
10
|
+
ConsumerEventRecord, ConsumerMailKind, ConsumerReconcileOptions, ConsumerReconcileResult, UsageReading,
|
|
11
|
+
} from '../types.js'
|
|
12
|
+
import { log } from '../log.js'
|
|
13
|
+
import { DAY_MS, MAX_ATTEMPTS } from './consts.local.js'
|
|
14
|
+
import { paymentAccessOf } from '../access.js'
|
|
15
|
+
import { paymentUtils } from '../utils.js'
|
|
16
|
+
import { consumerRecordsOf } from './records.js'
|
|
17
|
+
import { captureOf } from './capture.js'
|
|
18
|
+
import { stripeSessionHelper } from '../plugins/session.js'
|
|
19
|
+
import { consumerMailOf } from './mail.js'
|
|
20
|
+
import { consumerObserversOf } from './observers.js'
|
|
21
|
+
import { cancellationOf } from './cancellation.js'
|
|
22
|
+
import { withdrawalOf } from './withdrawal.js'
|
|
23
|
+
import type { ConsumerReconcileHelper } from './reconcile/types.js'
|
|
24
|
+
|
|
25
|
+
export const makeConsumerReconcileHelper = (
|
|
26
|
+
ctx: ApiContext, internals: ConsumerRightsInternals,
|
|
27
|
+
): ConsumerReconcileHelper => {
|
|
28
|
+
const access = paymentAccessOf(ctx)
|
|
29
|
+
const records = consumerRecordsOf(ctx)
|
|
30
|
+
|
|
31
|
+
/** What `withdraw` computed for a declaration, read back from its `computed` event. */
|
|
32
|
+
const computedOf = async (
|
|
33
|
+
withdrawalId: string,
|
|
34
|
+
): Promise<Pick<WithdrawalComputation, 'reading' | 'deducted' | 'unitsReturned' | 'netMinor' | 'refundMinor'> | null> => {
|
|
35
|
+
const event = await access.consumerEvents().load({ recordId: withdrawalId, action: 'computed', ok: true })
|
|
36
|
+
if (event == null) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
const detail = JSON.parse(event.detail ?? '{}') as {
|
|
40
|
+
reading?: UsageReading, deducted?: number, netMinor?: number, unitsReturned?: number,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
reading: detail.reading ?? { granted: 0, used: 0, usedAfter: 0 },
|
|
45
|
+
deducted: detail.deducted ?? 0,
|
|
46
|
+
unitsReturned: detail.unitsReturned ?? 0,
|
|
47
|
+
netMinor: detail.netMinor ?? 0,
|
|
48
|
+
refundMinor: event.amountMinor ?? 0,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const failures = async (recordId: string, action: ConsumerEventRecord['action']): Promise<number> =>
|
|
53
|
+
await access.consumerEvents().count({ recordId, action, ok: false })
|
|
54
|
+
|
|
55
|
+
/** Every distinct (record, step) with a failed event since `since` and no success after all. */
|
|
56
|
+
const pendingSteps = async (
|
|
57
|
+
action: ConsumerEventRecord['action'], since: Date, limit: number,
|
|
58
|
+
): Promise<ConsumerEventRecord[]> => {
|
|
59
|
+
const { items } = await access.consumerEvents().list({ action, ok: false, at: { $gte: since } }, {
|
|
60
|
+
size: limit * 4, sort: [{ field: 'at', order: 'desc' }],
|
|
61
|
+
})
|
|
62
|
+
const seen = new Set<string>()
|
|
63
|
+
const pending: ConsumerEventRecord[] = []
|
|
64
|
+
for (const event of items) {
|
|
65
|
+
const key = `${event.recordId}:${event.step ?? ''}`
|
|
66
|
+
if (seen.has(key)) continue
|
|
67
|
+
seen.add(key)
|
|
68
|
+
if (!await records.hasEvent(event.recordId, action, event.step ?? undefined, true)) {
|
|
69
|
+
pending.push(event)
|
|
70
|
+
}
|
|
71
|
+
if (pending.length >= limit) break
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return pending
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const retryWithdrawals = async (
|
|
78
|
+
stripe: Stripe, since: Date, limit: number, result: ConsumerReconcileResult,
|
|
79
|
+
): Promise<void> => {
|
|
80
|
+
const { items } = await access.consumerDeclarations().list({
|
|
81
|
+
kind: DeclarationKind.Withdrawal, status: WithdrawalStatus.Processing, matched: true, receivedAt: { $gte: since },
|
|
82
|
+
}, { size: limit * 2, sort: [{ field: 'receivedAt', order: 'asc' }] })
|
|
83
|
+
let handled = 0
|
|
84
|
+
for (const declaration of items) {
|
|
85
|
+
if (handled >= limit) break
|
|
86
|
+
const id = declaration.id as string
|
|
87
|
+
const purchase = declaration.purchaseId != null ? await access.purchases().byPurchaseId(declaration.purchaseId) : null
|
|
88
|
+
// A declaration that lost the race for its purchase is a duplicate — never executed.
|
|
89
|
+
if (purchase == null || purchase.withdrawalId !== id) continue
|
|
90
|
+
const computed = await computedOf(id)
|
|
91
|
+
const refundDone = (declaration.refundMinor ?? 0) <= 0 || await records.hasEvent(id, 'refund', undefined, true)
|
|
92
|
+
const cancelDone = purchase.kind !== PurchaseKind.Subscription
|
|
93
|
+
|| await records.hasEvent(id, 'subscription-cancel', undefined, true)
|
|
94
|
+
if (refundDone && cancelDone) {
|
|
95
|
+
const refundEvent = await access.consumerEvents().load({ recordId: id, action: 'refund', ok: true })
|
|
96
|
+
const noteFailed = await access.consumerEvents().load({ recordId: id, action: 'credit-note', ok: false, step: null })
|
|
97
|
+
if (refundEvent?.externalId != null && noteFailed != null && computed != null
|
|
98
|
+
&& !await records.hasEvent(id, 'credit-note', undefined, true)) {
|
|
99
|
+
const attempt = await failures(id, 'credit-note')
|
|
100
|
+
if (attempt < MAX_ATTEMPTS) {
|
|
101
|
+
handled++
|
|
102
|
+
result.retried++
|
|
103
|
+
if (!await withdrawalOf(ctx).retryCreditNote(stripe, declaration, purchase, computed.netMinor, refundEvent.externalId, attempt)) {
|
|
104
|
+
result.failed++
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
continue
|
|
109
|
+
}
|
|
110
|
+
const attempt = Math.max(await failures(id, 'refund'), await failures(id, 'subscription-cancel'))
|
|
111
|
+
if (attempt >= MAX_ATTEMPTS) continue
|
|
112
|
+
handled++
|
|
113
|
+
result.retried++
|
|
114
|
+
try {
|
|
115
|
+
const execution = await withdrawalOf(ctx).executeWithdrawal(stripe, declaration, purchase, {
|
|
116
|
+
refundMinor: declaration.refundMinor ?? computed?.refundMinor ?? 0, netMinor: computed?.netMinor ?? 0,
|
|
117
|
+
}, { attempt })
|
|
118
|
+
if (!execution.ok) {
|
|
119
|
+
result.failed++
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
if (!await records.hasEvent(id, 'observers', 'withdrawal')) {
|
|
123
|
+
await consumerObserversOf(ctx).notifyWithdrawal(declaration, purchase, WithdrawalStatus.Refunded, computed, execution)
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
result.failed++
|
|
127
|
+
log.error('Reconcile: withdrawal failed', { id, error })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const retryCancellations = async (
|
|
133
|
+
stripe: Stripe, since: Date, limit: number, result: ConsumerReconcileResult,
|
|
134
|
+
): Promise<void> => {
|
|
135
|
+
const { items } = await access.consumerDeclarations().list({
|
|
136
|
+
kind: DeclarationKind.Cancellation, status: CancellationStatus.Scheduled, matched: true, receivedAt: { $gte: since },
|
|
137
|
+
}, { size: limit * 2, sort: [{ field: 'receivedAt', order: 'asc' }] })
|
|
138
|
+
let handled = 0
|
|
139
|
+
for (const declaration of items) {
|
|
140
|
+
if (handled >= limit) break
|
|
141
|
+
const id = declaration.id as string
|
|
142
|
+
if (declaration.subscriptionId == null
|
|
143
|
+
|| await records.hasEvent(id, 'cancel-scheduled', undefined, true)) continue
|
|
144
|
+
const attempt = await failures(id, 'cancel-scheduled')
|
|
145
|
+
const row = await access.subscriptions().byExternalId(declaration.subscriptionId, STRIPE_PAYGATE_ALIAS)
|
|
146
|
+
if (row == null || attempt >= MAX_ATTEMPTS) continue
|
|
147
|
+
handled++
|
|
148
|
+
result.retried++
|
|
149
|
+
if (!await cancellationOf(ctx).scheduleCancellation(stripe, declaration, row, attempt)) {
|
|
150
|
+
result.failed++
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const retryMails = async (since: Date, limit: number, result: ConsumerReconcileResult): Promise<void> => {
|
|
156
|
+
const policy = await access.payment().consumerRightsPolicy()
|
|
157
|
+
const alias = (await access.consumerMailConfig())?.alias ?? MAILER_SERVICE
|
|
158
|
+
if (policy == null || (ctx as unknown as { hasService?: (alias: string) => boolean }).hasService?.(alias) !== true) {
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
for (const event of await pendingSteps('mail', since, limit)) {
|
|
162
|
+
if (event.step == null) continue
|
|
163
|
+
if (await consumerMailOf(ctx).sendConsumerMail(policy, event.step as ConsumerMailKind, event.recordId)) {
|
|
164
|
+
result.mailed++
|
|
165
|
+
} else if (!await records.hasEvent(event.recordId, 'mail', event.step, true)) {
|
|
166
|
+
result.failed++
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const retryObservers = async (since: Date, limit: number, result: ConsumerReconcileResult): Promise<void> => {
|
|
172
|
+
for (const event of await pendingSteps('observers', since, limit)) {
|
|
173
|
+
let told = false
|
|
174
|
+
try {
|
|
175
|
+
if (event.step === 'consent') {
|
|
176
|
+
const consent = await access.consumerConsents().load(event.recordId)
|
|
177
|
+
told = consent != null && await consumerObserversOf(ctx).notifyConsent(consent)
|
|
178
|
+
} else if (event.step === 'withdrawal') {
|
|
179
|
+
const declaration = await access.consumerDeclarations().load(event.recordId)
|
|
180
|
+
const purchase = declaration?.purchaseId != null ? await access.purchases().byPurchaseId(declaration.purchaseId) : null
|
|
181
|
+
if (declaration != null && purchase != null) {
|
|
182
|
+
const refunded = await records.hasEvent(event.recordId, 'refund', undefined, true)
|
|
183
|
+
|| (declaration.refundMinor ?? 0) <= 0
|
|
184
|
+
const refund = await access.consumerEvents().load({ recordId: event.recordId, action: 'refund', ok: true })
|
|
185
|
+
const note = await access.consumerEvents().load({ recordId: event.recordId, action: 'credit-note', ok: true })
|
|
186
|
+
told = await consumerObserversOf(ctx).notifyWithdrawal(
|
|
187
|
+
declaration, purchase,
|
|
188
|
+
declaration.status === WithdrawalStatus.Processing && refunded ? WithdrawalStatus.Refunded : WithdrawalStatus.Review,
|
|
189
|
+
await computedOf(event.recordId),
|
|
190
|
+
refund != null ? {
|
|
191
|
+
ok: true, refundId: refund.externalId ?? undefined, creditNoteId: note?.externalId ?? undefined,
|
|
192
|
+
refundedMinor: refund.amountMinor ?? 0, needsReview: false,
|
|
193
|
+
subscriptionCanceled: await records.hasEvent(event.recordId, 'subscription-cancel', undefined, true),
|
|
194
|
+
} : null,
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
} else if (event.step === 'cancellation') {
|
|
198
|
+
const declaration = await access.consumerDeclarations().load(event.recordId)
|
|
199
|
+
if (declaration != null) {
|
|
200
|
+
const scheduled = await records.hasEvent(event.recordId, 'cancel-scheduled', undefined, true)
|
|
201
|
+
told = await consumerObserversOf(ctx).notifyCancellation(declaration,
|
|
202
|
+
declaration.status === CancellationStatus.Scheduled && !scheduled
|
|
203
|
+
? CancellationStatus.Received : declaration.status as CancellationStatus)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
log.error('Reconcile: observers failed', { recordId: event.recordId, error })
|
|
208
|
+
}
|
|
209
|
+
if (told) {
|
|
210
|
+
result.observed++
|
|
211
|
+
} else {
|
|
212
|
+
result.failed++
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Completed checkouts of the last days that have no purchase row (records only — no mail). */
|
|
218
|
+
const backfillPurchases = async (stripe: Stripe, limit: number, result: ConsumerReconcileResult): Promise<void> => {
|
|
219
|
+
const from = Math.floor((Date.now() - PURCHASE_BACKFILL_DAYS * DAY_MS) / 1000)
|
|
220
|
+
let startingAfter: string | undefined
|
|
221
|
+
let scanned = 0
|
|
222
|
+
for (;;) {
|
|
223
|
+
const page = await stripe.checkout.sessions.list({
|
|
224
|
+
created: { gte: from }, status: 'complete', limit: 100,
|
|
225
|
+
...(startingAfter != null ? { starting_after: startingAfter } : {}),
|
|
226
|
+
})
|
|
227
|
+
for (const session of page.data) {
|
|
228
|
+
scanned++
|
|
229
|
+
if (result.backfilled >= limit) return
|
|
230
|
+
const metadata = session.metadata ?? {}
|
|
231
|
+
if (metadata.entityId == null || metadata.productSku == null) continue
|
|
232
|
+
try {
|
|
233
|
+
if (stripeSessionHelper.canFulfillPayment(session)) {
|
|
234
|
+
if (await access.purchases().load({ sessionId: session.id }) != null) continue
|
|
235
|
+
const amount = Number(metadata.amountMinor)
|
|
236
|
+
const captured = await captureOf(ctx).capturePaymentPurchase(stripe, session, {
|
|
237
|
+
...(Number.isSafeInteger(amount) && amount > 0 ? { netAmountMinor: amount } : {}),
|
|
238
|
+
...(metadata.amountCurrency != null ? { amountCurrency: metadata.amountCurrency } : {}),
|
|
239
|
+
at: new Date(session.created * 1000),
|
|
240
|
+
}, { mail: false })
|
|
241
|
+
if (captured?.created === true) result.backfilled++
|
|
242
|
+
} else if (session.mode === 'subscription') {
|
|
243
|
+
const subscriptionId = paymentUtils.idOf(session.subscription)
|
|
244
|
+
if (subscriptionId == null
|
|
245
|
+
|| await access.purchases().byPurchaseId(records.purchaseIdOf(subscriptionId)) != null) continue
|
|
246
|
+
const row = await access.subscriptions().byExternalId(subscriptionId, STRIPE_PAYGATE_ALIAS)
|
|
247
|
+
if (row == null || !ENTITLING_STATUSES.includes(row.status)) continue
|
|
248
|
+
const subscription = await stripe.subscriptions.retrieve(subscriptionId)
|
|
249
|
+
const captured = await captureOf(ctx).captureSubscriptionPurchase(stripe, subscription, row)
|
|
250
|
+
if (captured != null) {
|
|
251
|
+
await captureOf(ctx).completeSubscriptionPurchase(stripe, session, captured.purchase, { mail: false })
|
|
252
|
+
if (captured.created) result.backfilled++
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
result.failed++
|
|
257
|
+
log.error('Reconcile: purchase backfill failed', { sessionId: session.id, error })
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (!page.has_more || page.data.length === 0 || scanned >= limit * 20) return
|
|
261
|
+
startingAfter = page.data[page.data.length - 1].id
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Organizations that paid before countries were locked: locked from their paygate customer's
|
|
267
|
+
* address — never one an operator unlocked (its next completed purchase locks it).
|
|
268
|
+
*/
|
|
269
|
+
const lockLegacy = async (stripe: Stripe, limit: number, result: ConsumerReconcileResult): Promise<void> => {
|
|
270
|
+
const policy = await access.payment().consumerRightsPolicy()
|
|
271
|
+
if (policy?.mechanisms.countryLock !== true) {
|
|
272
|
+
return
|
|
273
|
+
}
|
|
274
|
+
const { items } = await access.paygateCustomers().list({ paygate: STRIPE_PAYGATE_ALIAS, deletedAt: null }, { size: limit * 4 })
|
|
275
|
+
for (const customer of items) {
|
|
276
|
+
if (result.locked >= limit) return
|
|
277
|
+
if (customer.entityId == null || await access.billingProfiles().byEntity(customer.entityId) != null) continue
|
|
278
|
+
if (!await records.hasPaid(customer.entityId) || await records.wasUnlocked(customer.entityId)) continue
|
|
279
|
+
try {
|
|
280
|
+
let country = customer.country
|
|
281
|
+
if (country == null) {
|
|
282
|
+
const retrieved = await stripe.customers.retrieve(customer.externalId)
|
|
283
|
+
country = (retrieved as Stripe.DeletedCustomer).deleted ? undefined : (retrieved as Stripe.Customer).address?.country ?? undefined
|
|
284
|
+
}
|
|
285
|
+
if (country == null) continue
|
|
286
|
+
const { created } = await records.lockProfile(policy, {
|
|
287
|
+
entityId: customer.entityId, country, source: 'customer', customerId: customer.externalId,
|
|
288
|
+
email: customer.email ?? undefined,
|
|
289
|
+
})
|
|
290
|
+
if (created) result.locked++
|
|
291
|
+
} catch (error) {
|
|
292
|
+
result.failed++
|
|
293
|
+
log.error('Reconcile: legacy billing-country lock failed', { entityId: customer.entityId, error })
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const reconcile = async (opts: ConsumerReconcileOptions = {}): Promise<ConsumerReconcileResult> => {
|
|
299
|
+
const result: ConsumerReconcileResult = { retried: 0, mailed: 0, observed: 0, backfilled: 0, locked: 0, failed: 0 }
|
|
300
|
+
if (await access.payment().consumerRightsPolicy() == null) {
|
|
301
|
+
return result
|
|
302
|
+
}
|
|
303
|
+
const limit = Math.max(1, opts.limit ?? 50)
|
|
304
|
+
const since = opts.since ?? new Date(Date.now() - 30 * DAY_MS)
|
|
305
|
+
const stripe = internals.managed ? await internals.stripe(ctx) : null
|
|
306
|
+
const steps: Array<[string, () => Promise<void>]> = [
|
|
307
|
+
...(stripe != null ? [
|
|
308
|
+
['withdrawals', async () => { await retryWithdrawals(stripe, since, limit, result) }],
|
|
309
|
+
['cancellations', async () => { await retryCancellations(stripe, since, limit, result) }],
|
|
310
|
+
] as Array<[string, () => Promise<void>]> : []),
|
|
311
|
+
['mails', async () => { await retryMails(since, limit, result) }],
|
|
312
|
+
['observers', async () => { await retryObservers(since, limit, result) }],
|
|
313
|
+
...(stripe != null ? [
|
|
314
|
+
['backfill', async () => { await backfillPurchases(stripe, limit, result) }],
|
|
315
|
+
['legacy locks', async () => { await lockLegacy(stripe, limit, result) }],
|
|
316
|
+
] as Array<[string, () => Promise<void>]> : []),
|
|
317
|
+
]
|
|
318
|
+
for (const [name, step] of steps) {
|
|
319
|
+
try {
|
|
320
|
+
await step()
|
|
321
|
+
} catch (error) {
|
|
322
|
+
result.failed++
|
|
323
|
+
log.error('Consumer-rights reconcile step failed', { step: name, error })
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return result
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return { reconcile }
|
|
331
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { BillingProfileView, ConsumerRightsPolicy } from '@owlmeans/payment'
|
|
2
|
+
import type {
|
|
3
|
+
BillingProfileRecord, ConsumerEventRecord, PaymentSubscriptionRecord, PurchaseRecord, UnlockOptions,
|
|
4
|
+
} from '../../types.js'
|
|
5
|
+
import type { LockInput, LockResult, PurchaseDraft } from '../types.js'
|
|
6
|
+
|
|
7
|
+
/** One audit step as it is appended — `at` defaults to now. */
|
|
8
|
+
export interface ConsumerEventDraft extends Omit<ConsumerEventRecord, 'at' | 'id'> { at?: Date }
|
|
9
|
+
|
|
10
|
+
/** The consumer-rights records of a context: purchases, billing profiles and the audit trail. */
|
|
11
|
+
export interface ConsumerRecords {
|
|
12
|
+
/** The purchase id of a paygate checkout session or subscription: `stripe:<id>`. */
|
|
13
|
+
purchaseIdOf: (externalId: string) => string
|
|
14
|
+
/** A locked profile as the wire sees it. */
|
|
15
|
+
profileViewOf: (record: BillingProfileRecord, policy: ConsumerRightsPolicy | null) => BillingProfileView
|
|
16
|
+
/** No profile yet: nothing locked, the default legal language, an unknown buyer (protected by default). */
|
|
17
|
+
unlockedProfileView: (policy: ConsumerRightsPolicy | null) => BillingProfileView
|
|
18
|
+
/**
|
|
19
|
+
* Append one audit step. A failure to write it is logged and never fails the act it describes —
|
|
20
|
+
* the act's own record (consent, declaration, purchase) is already written.
|
|
21
|
+
*/
|
|
22
|
+
recordEvent: (event: ConsumerEventDraft) => Promise<void>
|
|
23
|
+
/** Whether a step already succeeded (or a mail was deliberately skipped) for a record. */
|
|
24
|
+
hasEvent: (recordId: string, action: ConsumerEventRecord['action'], step?: string, ok?: boolean) => Promise<boolean>
|
|
25
|
+
/** The entity's highest-ranked entitling Stripe subscription, or `null`. */
|
|
26
|
+
entitlingStripeSubscription: (entityId: string) => Promise<PaymentSubscriptionRecord | null>
|
|
27
|
+
/** Whether the entity ever paid through the paygate (a fulfilled checkout or a propagated subscription). */
|
|
28
|
+
hasPaid: (entityId: string) => Promise<boolean>
|
|
29
|
+
/**
|
|
30
|
+
* Fix an entity's billing country — the FIRST write wins (a unique index on `entityId` settles a
|
|
31
|
+
* race). A later, different country is only a `lock-mismatch` event; only a `manual` lock with
|
|
32
|
+
* `force` replaces the country, audited as `relock`. The charge currency is fixed with it: the
|
|
33
|
+
* currency of an entitling paygate subscription when one exists (a customer's subscriptions share
|
|
34
|
+
* one currency), else the region's (`policy.currencies`), else the given one.
|
|
35
|
+
*/
|
|
36
|
+
lockProfile: (policy: ConsumerRightsPolicy | null, input: LockInput) => Promise<LockResult>
|
|
37
|
+
/**
|
|
38
|
+
* An operator removes an entity's lock: the profile row is deleted (only while it still holds the
|
|
39
|
+
* country read — a concurrent relock survives) and an `unlock` event keeps the whole row, `by` and
|
|
40
|
+
* `reason`. `null` when nothing was locked.
|
|
41
|
+
*/
|
|
42
|
+
unlockProfile: (entityId: string, opts?: UnlockOptions) => Promise<BillingProfileRecord | null>
|
|
43
|
+
/**
|
|
44
|
+
* Whether an operator unlocked the entity — then no lock is taken from its paygate customer's saved
|
|
45
|
+
* address (at checkout or in reconcile): its next completed purchase locks it.
|
|
46
|
+
*/
|
|
47
|
+
wasUnlocked: (entityId: string) => Promise<boolean>
|
|
48
|
+
/** The open, unconsented top-up windows of an entity — what a performance consent covers. */
|
|
49
|
+
unconsentedWindows: (entityId: string, at?: Date) => Promise<PurchaseRecord[]>
|
|
50
|
+
/**
|
|
51
|
+
* Write a purchase once: an existing row for the same purchase (or the same checkout session) is
|
|
52
|
+
* returned as it is. A contract-reference collision retries with a fresh reference.
|
|
53
|
+
*/
|
|
54
|
+
createPurchase: (draft: PurchaseDraft) => Promise<{ record: PurchaseRecord, created: boolean }>
|
|
55
|
+
/** Set fields on a purchase without replacing it (a concurrent conditional write survives). */
|
|
56
|
+
patchPurchase: (purchaseId: string, fields: Partial<PurchaseRecord>) => Promise<void>
|
|
57
|
+
/** The e-mail a consumer-rights mail reaches the organization at when no person named one. */
|
|
58
|
+
contactEmailOf: (entityId: string) => Promise<string | undefined>
|
|
59
|
+
/**
|
|
60
|
+
* Whether an e-mail address belongs to a purchase: its checkout e-mail, the organization's
|
|
61
|
+
* profile e-mail or its paygate customer's — compared case-insensitively.
|
|
62
|
+
*/
|
|
63
|
+
emailMatches: (purchase: PurchaseRecord, email: string) => Promise<boolean>
|
|
64
|
+
}
|