@owlmeans/server-payment 0.1.18-rc.9 → 0.1.18
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 +613 -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 +284 -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 +320 -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 +441 -144
- 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 +32 -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 +58 -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 +1258 -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 +321 -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 +330 -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 +466 -132
- 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 +28 -0
- package/src/plugins/session.ts +73 -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 +1365 -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 +209 -93
- package/tests/consumer-events.spec.ts +215 -0
- package/tests/consumer-fixtures.ts +134 -0
- package/tests/consumer-ops.spec.ts +350 -0
- package/tests/consumer-rights.integration.spec.ts +147 -0
- package/tests/consumer-rights.spec.ts +572 -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 +357 -0
- package/tests/fake-stripe.ts +981 -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
package/src/gate.ts
CHANGED
|
@@ -1,51 +1,68 @@
|
|
|
1
1
|
import { createLazyService } from '@owlmeans/context'
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { ENTITLEMENT_GATE,
|
|
2
|
+
import type { GateService, AbstractRequest } from '@owlmeans/entrypoint'
|
|
3
|
+
import type { Auth } from '@owlmeans/auth'
|
|
4
|
+
import { hasPermission } from '@owlmeans/iam'
|
|
5
|
+
import { CapabilityRequired, ENTITLEMENT_GATE, parseEntitlementParam, capabilityOf } from '@owlmeans/payment'
|
|
6
6
|
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
7
|
+
import type { Config, Context, CapabilityGateOptions, EntityResolverOption } from './types.js'
|
|
8
|
+
import { log } from './log.js'
|
|
9
|
+
import { paymentAccessOf } from './access.js'
|
|
10
|
+
import { makeGateRequestScope } from './gate/request.js'
|
|
11
|
+
import type { GateEntity } from './gate/types.js'
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
/** An explicit `false` for the permission in the token denies, whatever the plan grants. */
|
|
14
|
+
const tokenDenies = (auth: Auth, param: string): boolean => {
|
|
15
|
+
const { scope, permission } = parseEntitlementParam(param)
|
|
16
|
+
return auth.permissions?.some(set =>
|
|
17
|
+
(scope == null || set.scope === scope) && set.permissions?.[permission] === false,
|
|
18
|
+
) ?? false
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const { items } = await subscriptions(ctx).list({
|
|
19
|
-
entityId, status: [SubscriptionStatus.Active, SubscriptionStatus.Trial], productSku: productSkus,
|
|
20
|
-
}, { size: 0 })
|
|
21
|
-
return items.flatMap(record => record.capabilities ?? [])
|
|
21
|
+
const tokenGrants = (auth: Auth, param: string): boolean => {
|
|
22
|
+
const { scope, permission } = parseEntitlementParam(param)
|
|
23
|
+
return hasPermission(auth, permission, scope != null ? { scope } : undefined)
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The capability gate (`ENTITLEMENT_GATE`): passes when the effective plan grants ANY of the
|
|
28
|
+
* parameters (`[scope:]permission[>=n]`) and the token does not deny it. Fails closed — an unreadable
|
|
29
|
+
* store refuses. Refuses with `CapabilityRequired`, an `AuthForbidden`.
|
|
30
|
+
*/
|
|
31
|
+
export const makeCapabilityGate = (
|
|
32
|
+
alias: string = ENTITLEMENT_GATE, opts?: CapabilityGateOptions,
|
|
29
33
|
): GateService => {
|
|
30
34
|
const service = createLazyService<GateService>(alias, {
|
|
31
35
|
assert: async (req, _, params) => {
|
|
32
36
|
await service.ready()
|
|
33
37
|
const ctx = service.assertCtx<Config, Context>() as unknown as ApiContext
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
if (entityId == null || entityId === '') throw new AuthForbidden('entity')
|
|
38
|
+
const { auth, entityId } = makeGateRequestScope(req).gateEntityOf(opts)
|
|
39
|
+
const list = (Array.isArray(params) ? params : [params]).filter(param => typeof param === 'string')
|
|
37
40
|
|
|
38
|
-
let
|
|
41
|
+
let view
|
|
39
42
|
try {
|
|
40
|
-
|
|
43
|
+
view = await paymentAccessOf(ctx).entitlements().entitlements(entityId)
|
|
41
44
|
} catch (error) {
|
|
42
|
-
|
|
43
|
-
throw new
|
|
45
|
+
log.error('Capability gate cannot resolve entitlements', { entityId, error })
|
|
46
|
+
throw new CapabilityRequired(list)
|
|
47
|
+
}
|
|
48
|
+
if (opts?.productSkus != null && !opts.productSkus.includes(view.plan.productSku)) {
|
|
49
|
+
throw new CapabilityRequired(list)
|
|
44
50
|
}
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
|
|
52
|
+
const allowed = list.some(param => capabilityOf(view, param) && !tokenDenies(auth, param)
|
|
53
|
+
&& (opts?.requirePermission !== true || tokenGrants(auth, param)))
|
|
54
|
+
if (!allowed) {
|
|
55
|
+
throw new CapabilityRequired(list)
|
|
47
56
|
}
|
|
48
57
|
},
|
|
49
58
|
})
|
|
59
|
+
|
|
50
60
|
return service
|
|
51
61
|
}
|
|
62
|
+
|
|
63
|
+
/** The capability gate under its historical name. */
|
|
64
|
+
export const makeEntitlementGate = makeCapabilityGate
|
|
65
|
+
|
|
66
|
+
/** @deprecated compat:factory-refactor — use `makeGateRequestScope(req).gateEntityOf(…)` */
|
|
67
|
+
export const gateEntityOf = (req: AbstractRequest, opts?: EntityResolverOption): GateEntity =>
|
|
68
|
+
makeGateRequestScope(req).gateEntityOf(opts)
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,65 @@
|
|
|
1
1
|
export type * from './types.js'
|
|
2
2
|
export * from './consts.js'
|
|
3
|
+
export * from './protocol.js'
|
|
3
4
|
export * from './config.js'
|
|
4
5
|
export * from './resource.js'
|
|
6
|
+
export { FingerprintSchema, ConsumerEventSchema } from './schemas.js'
|
|
5
7
|
export * from './observer.js'
|
|
6
8
|
export * from './service.js'
|
|
7
9
|
export * from './gate.js'
|
|
10
|
+
export * from './limit.js'
|
|
11
|
+
export * from './entitlement.js'
|
|
8
12
|
export * from './entrypoints.js'
|
|
9
|
-
|
|
10
|
-
export
|
|
13
|
+
|
|
14
|
+
export type * from './access/types.js'
|
|
15
|
+
export * from './access.js'
|
|
16
|
+
export type * from './plan/types.js'
|
|
17
|
+
export * from './plan.js'
|
|
18
|
+
export type * from './models/declarations/types.js'
|
|
19
|
+
export * from './models/declarations.js'
|
|
20
|
+
export type * from './catalogue/types.js'
|
|
21
|
+
export * from './catalogue.js'
|
|
22
|
+
export type * from './usage/types.js'
|
|
23
|
+
export * from './usage.js'
|
|
24
|
+
export type * from './subscription/types.js'
|
|
25
|
+
export * from './subscription.js'
|
|
26
|
+
export type * from './commit/types.js'
|
|
27
|
+
export * from './commit.js'
|
|
28
|
+
export type * from './sync/types.js'
|
|
29
|
+
export * from './sync.js'
|
|
30
|
+
export type * from './bootstrap/types.js'
|
|
31
|
+
export * from './bootstrap.js'
|
|
32
|
+
export type * from './reconcile/types.js'
|
|
33
|
+
export * from './reconcile.js'
|
|
34
|
+
export type * from './gate/types.js'
|
|
35
|
+
export * from './gate/request.js'
|
|
36
|
+
|
|
37
|
+
export type * from './plugins/session/types.js'
|
|
38
|
+
export * from './plugins/session.js'
|
|
39
|
+
export type * from './plugins/stripe/types.js'
|
|
40
|
+
export * from './plugins/stripe.js'
|
|
41
|
+
export type * from './plugins/checkout-registry/types.js'
|
|
42
|
+
export * from './plugins/checkout-registry.js'
|
|
43
|
+
export type * from './plugins/checkout-plugins/types.js'
|
|
44
|
+
export * from './plugins/checkout-plugins.js'
|
|
45
|
+
export type * from './plugins/checkout-policy/types.js'
|
|
46
|
+
export * from './plugins/checkout-policy.js'
|
|
47
|
+
export type * from './plugins/estimate/types.js'
|
|
48
|
+
export * from './plugins/estimate/cache.js'
|
|
49
|
+
export * from './plugins/estimate.js'
|
|
50
|
+
export type * from './plugins/events/types.js'
|
|
51
|
+
export * from './plugins/events.js'
|
|
52
|
+
export * from './plugins/status.js'
|
|
53
|
+
export type * from './plugins/subscriptions/types.js'
|
|
54
|
+
export * from './plugins/subscriptions.js'
|
|
55
|
+
export type * from './plugins/webhook-manager/types.js'
|
|
56
|
+
export * from './plugins/webhook-manager.js'
|
|
57
|
+
export type * from './plugins/portal/types.js'
|
|
58
|
+
export * from './plugins/portal.js'
|
|
59
|
+
|
|
60
|
+
export * from './consumer/index.js'
|
|
61
|
+
|
|
11
62
|
export {
|
|
12
|
-
|
|
63
|
+
consumerConsents, consumerRightsOf, entitlements, fulfillments, gateway, observer, payment, purchases, stripeClient,
|
|
64
|
+
subscriptions,
|
|
13
65
|
} from './utils.js'
|
package/src/limit.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createLazyService } from '@owlmeans/context'
|
|
2
|
+
import type { GateService } from '@owlmeans/entrypoint'
|
|
3
|
+
import { LIMIT_GATE, LimitExhausted, LimitUnknown, type LimitParam, type LimitView, planLimitHelper } from '@owlmeans/payment'
|
|
4
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
5
|
+
import { makeGateRequestScope } from './gate/request.js'
|
|
6
|
+
import type { Config, Context, LimitGateOptions } from './types.js'
|
|
7
|
+
import { log } from './log.js'
|
|
8
|
+
import { paymentAccessOf } from './access.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The limit gate (`LIMIT_GATE`): passes when ANY `limit:<key>[>=n]` parameter has at least `n` left
|
|
12
|
+
* in its current window. It never consumes — checking room and spending it are different moments,
|
|
13
|
+
* and only the handler knows the work started. Malformed parameters and keys the plan does not
|
|
14
|
+
* declare are skipped; a store error refuses. Refuses with `LimitExhausted` naming the first
|
|
15
|
+
* declared key, an `AuthForbidden`.
|
|
16
|
+
*/
|
|
17
|
+
export const makeLimitGate = (alias: string = LIMIT_GATE, opts?: LimitGateOptions): GateService => {
|
|
18
|
+
const service = createLazyService<GateService>(alias, {
|
|
19
|
+
assert: async (req, _, params) => {
|
|
20
|
+
await service.ready()
|
|
21
|
+
const ctx = service.assertCtx<Config, Context>() as unknown as ApiContext
|
|
22
|
+
const { entityId } = makeGateRequestScope(req).gateEntityOf(opts)
|
|
23
|
+
const list = (Array.isArray(params) ? params : [params]).filter(param => typeof param === 'string')
|
|
24
|
+
|
|
25
|
+
const parsed = list.map(planLimitHelper.parseLimitParam).filter((param): param is LimitParam => param != null)
|
|
26
|
+
if (parsed.length === 0) {
|
|
27
|
+
throw new LimitExhausted({ key: list[0] ?? 'unknown', used: 0, limit: 0 })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let refused: LimitView | null = null
|
|
31
|
+
for (const param of parsed) {
|
|
32
|
+
let state: LimitView
|
|
33
|
+
try {
|
|
34
|
+
state = await paymentAccessOf(ctx).entitlements().limitState(entityId, param.key)
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (!(error instanceof LimitUnknown)) {
|
|
37
|
+
log.error('Limit gate cannot read a limit', { key: param.key, entityId, error })
|
|
38
|
+
}
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
if (state.remaining >= param.atLeast) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
refused ??= state
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw new LimitExhausted(refused != null
|
|
48
|
+
? { key: refused.key, used: refused.used, limit: refused.limit, resetsAt: refused.resetsAt }
|
|
49
|
+
: { key: parsed[0].key, used: 0, limit: 0 })
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return service
|
|
54
|
+
}
|
package/src/log.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Config, PaymentPlan } from '../../types.js'
|
|
2
|
+
|
|
3
|
+
/** The plans a configuration declares, and the rules no single declaration can check. */
|
|
4
|
+
export interface PlanDeclarationsModel {
|
|
5
|
+
readonly record: Config
|
|
6
|
+
/** Every plan declared into the configuration. */
|
|
7
|
+
plans: () => PaymentPlan[]
|
|
8
|
+
/**
|
|
9
|
+
* Cross-plan rules a single declaration cannot see:
|
|
10
|
+
*
|
|
11
|
+
* - at most one free plan per rank;
|
|
12
|
+
* - no two paid plans of one product at the same rank (one-time `consumable` plans are never an
|
|
13
|
+
* entity's plan and are not ranked against each other).
|
|
14
|
+
*
|
|
15
|
+
* A limit key MAY change kind between plans (lifetime on one, a monthly window on another): counters
|
|
16
|
+
* are keyed by `(entity, key, window)` and the window is derived from the kind, so each kind keeps its
|
|
17
|
+
* own counter and a lifetime count still sticks to the entity across plan changes.
|
|
18
|
+
*
|
|
19
|
+
* @throws PlanRankConflict
|
|
20
|
+
*/
|
|
21
|
+
assertPlans: () => void
|
|
22
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PLAN_RECORD_TYPE, PlanDuration, PlanRankConflict } from '@owlmeans/payment'
|
|
2
|
+
import type { Config, PaymentPlan } from '../types.js'
|
|
3
|
+
import type { PlanDeclarationsModel } from './declarations/types.js'
|
|
4
|
+
|
|
5
|
+
export const makePlanDeclarationsModel = (record: Config): PlanDeclarationsModel => {
|
|
6
|
+
const plans = (): PaymentPlan[] =>
|
|
7
|
+
(record.records ?? []).filter(entry => entry.recordType === PLAN_RECORD_TYPE) as unknown as PaymentPlan[]
|
|
8
|
+
|
|
9
|
+
const assertPlans = (): void => {
|
|
10
|
+
const freeRanks = new Set<number>()
|
|
11
|
+
const paidRanks = new Set<string>()
|
|
12
|
+
for (const plan of plans()) {
|
|
13
|
+
const rank = plan.rank ?? 0
|
|
14
|
+
if (plan.free === true) {
|
|
15
|
+
if (freeRanks.has(rank)) {
|
|
16
|
+
throw new PlanRankConflict(`free:${rank}`)
|
|
17
|
+
}
|
|
18
|
+
freeRanks.add(rank)
|
|
19
|
+
} else if (plan.duration !== PlanDuration.Consumable) {
|
|
20
|
+
const key = `${plan.productSku}:${rank}`
|
|
21
|
+
if (paidRanks.has(key)) {
|
|
22
|
+
throw new PlanRankConflict(key)
|
|
23
|
+
}
|
|
24
|
+
paidRanks.add(key)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { record, plans, assertPlans }
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PurchaseView } from '@owlmeans/payment'
|
|
2
|
+
import type { PurchaseRecord, PurchaseRef } from '../../types.js'
|
|
3
|
+
|
|
4
|
+
/** One purchase and its withdrawal window. */
|
|
5
|
+
export interface PurchaseModel {
|
|
6
|
+
readonly record: PurchaseRecord
|
|
7
|
+
/** Inside its window at `at`: in scope, before the deadline, neither withdrawn from nor refunded. */
|
|
8
|
+
windowOpen: (at?: Date) => boolean
|
|
9
|
+
/** The purchase as the wire sees it. */
|
|
10
|
+
view: (withdrawable: boolean) => PurchaseView
|
|
11
|
+
/** What a usage meter is told about the purchase. */
|
|
12
|
+
ref: () => PurchaseRef
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type PurchaseView, withdrawalDeadlineHelper } from '@owlmeans/payment'
|
|
2
|
+
import type { PurchaseRecord, PurchaseRef } from '../types.js'
|
|
3
|
+
import { paymentUtils } from '../utils.js'
|
|
4
|
+
import type { PurchaseModel } from './purchase/types.js'
|
|
5
|
+
|
|
6
|
+
export const makePurchaseModel = (record: PurchaseRecord): PurchaseModel => {
|
|
7
|
+
const windowOpen = (at: Date = new Date()): boolean =>
|
|
8
|
+
record.inScope && withdrawalDeadlineHelper.withdrawalOpen({
|
|
9
|
+
deadline: record.deadline != null ? new Date(record.deadline) : null,
|
|
10
|
+
withdrawnAt: record.withdrawnAt ?? null,
|
|
11
|
+
refundedAt: record.refundedAt ?? null,
|
|
12
|
+
}, at)
|
|
13
|
+
|
|
14
|
+
const view = (withdrawable: boolean): PurchaseView => paymentUtils.compact({
|
|
15
|
+
purchaseId: record.purchaseId,
|
|
16
|
+
contractRef: record.contractRef,
|
|
17
|
+
kind: record.kind,
|
|
18
|
+
purchasedAt: new Date(record.purchasedAt),
|
|
19
|
+
deadline: record.deadline != null ? new Date(record.deadline) : undefined,
|
|
20
|
+
productSku: record.productSku,
|
|
21
|
+
planSku: record.planSku ?? undefined,
|
|
22
|
+
amountTotalMinor: record.amountTotalMinor,
|
|
23
|
+
currency: record.currency,
|
|
24
|
+
consentedAt: record.consentedAt != null ? new Date(record.consentedAt) : undefined,
|
|
25
|
+
withdrawnAt: record.withdrawnAt != null ? new Date(record.withdrawnAt) : undefined,
|
|
26
|
+
withdrawable,
|
|
27
|
+
}) as PurchaseView
|
|
28
|
+
|
|
29
|
+
const ref = (): PurchaseRef => paymentUtils.compact({
|
|
30
|
+
purchaseId: record.purchaseId,
|
|
31
|
+
kind: record.kind,
|
|
32
|
+
entityId: record.entityId,
|
|
33
|
+
contractRef: record.contractRef,
|
|
34
|
+
productSku: record.productSku,
|
|
35
|
+
planSku: record.planSku ?? undefined,
|
|
36
|
+
sessionId: record.sessionId ?? undefined,
|
|
37
|
+
subscriptionId: record.subscriptionId ?? undefined,
|
|
38
|
+
invoiceId: record.invoiceId ?? undefined,
|
|
39
|
+
purchasedAt: new Date(record.purchasedAt),
|
|
40
|
+
}) as PurchaseRef
|
|
41
|
+
|
|
42
|
+
return { record, windowOpen, view, ref }
|
|
43
|
+
}
|
package/src/observer.ts
CHANGED
|
@@ -1,21 +1,54 @@
|
|
|
1
1
|
import { createLazyService } from '@owlmeans/context'
|
|
2
2
|
import { PAYMENT_OBSERVER } from './consts.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
CancellationCallback, CompletionObserver, Config, ConsentCallback, Context, DisputeCallback,
|
|
5
|
+
PaymentFailedCallback, RefundCallback, SubscriptionCallback, TopUpCallback, WithdrawalCallback,
|
|
6
|
+
} from './types.js'
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The application's side of payment completion. Callbacks run sequentially and are awaited; a
|
|
10
|
+
* throw escapes to the webhook so the paygate delivers the event again — every callback must be
|
|
11
|
+
* idempotent by the `eventKey` (`externalId` for a top-up) it is handed.
|
|
12
|
+
*
|
|
13
|
+
* The consumer-rights callbacks (`onConsent`, `onWithdrawal`, `onCancellation`) run after the
|
|
14
|
+
* records and the paygate steps of their act; a throw is recorded as an `observers` event and
|
|
15
|
+
* retried by the consumer-rights `reconcile()` — they, too, are idempotent by `eventKey`.
|
|
16
|
+
*/
|
|
5
17
|
export const makeCompletionObserverService = (
|
|
6
18
|
alias: string = PAYMENT_OBSERVER,
|
|
7
19
|
): CompletionObserver => {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
20
|
+
const topUp: TopUpCallback[] = []
|
|
21
|
+
const subscription: SubscriptionCallback[] = []
|
|
22
|
+
const refund: RefundCallback[] = []
|
|
23
|
+
const dispute: DisputeCallback[] = []
|
|
24
|
+
const paymentFailed: PaymentFailedCallback[] = []
|
|
25
|
+
const consent: ConsentCallback[] = []
|
|
26
|
+
const withdrawal: WithdrawalCallback[] = []
|
|
27
|
+
const cancellation: CancellationCallback[] = []
|
|
28
|
+
|
|
29
|
+
const run = async <E>(callbacks: Array<(event: E, ctx: never) => Promise<void>>, event: E, ctx: unknown) => {
|
|
30
|
+
for (const callback of callbacks) {
|
|
31
|
+
await callback(event, ctx as never)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
10
35
|
return createLazyService<CompletionObserver>(alias, {
|
|
11
|
-
onTopUp: cb => {
|
|
12
|
-
onSubscription: cb => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
36
|
+
onTopUp: cb => { topUp.push(cb) },
|
|
37
|
+
onSubscription: cb => { subscription.push(cb) },
|
|
38
|
+
onRefund: cb => { refund.push(cb) },
|
|
39
|
+
onDispute: cb => { dispute.push(cb) },
|
|
40
|
+
onPaymentFailed: cb => { paymentFailed.push(cb) },
|
|
41
|
+
onConsent: cb => { consent.push(cb) },
|
|
42
|
+
onWithdrawal: cb => { withdrawal.push(cb) },
|
|
43
|
+
onCancellation: cb => { cancellation.push(cb) },
|
|
44
|
+
propagateTopUp: async (completion, ctx) => { await run(topUp, completion, ctx) },
|
|
45
|
+
propagateSubscription: async (event, ctx) => { await run(subscription, event, ctx) },
|
|
46
|
+
propagateRefund: async (event, ctx) => { await run(refund, event, ctx) },
|
|
47
|
+
propagateDispute: async (event, ctx) => { await run(dispute, event, ctx) },
|
|
48
|
+
propagatePaymentFailed: async (event, ctx) => { await run(paymentFailed, event, ctx) },
|
|
49
|
+
propagateConsent: async (event, ctx) => { await run(consent, event, ctx) },
|
|
50
|
+
propagateWithdrawal: async (event, ctx) => { await run(withdrawal, event, ctx) },
|
|
51
|
+
propagateCancellation: async (event, ctx) => { await run(cancellation, event, ctx) },
|
|
19
52
|
}, service => async () => { service.initialized = true })
|
|
20
53
|
}
|
|
21
54
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProductPlan } from '@owlmeans/payment'
|
|
2
|
+
import type { PaymentPlan, PaymentProduct, PaymentSubscriptionRecord } from '../types.js'
|
|
3
|
+
|
|
4
|
+
/** What a plan declaration says on its own — no context, no store. */
|
|
5
|
+
export interface PlanHelper {
|
|
6
|
+
/** A plan's rank; an absent rank reads as `0`. */
|
|
7
|
+
planRank: (plan: Pick<ProductPlan, 'rank'>) => number
|
|
8
|
+
/**
|
|
9
|
+
* A plan as ONE subscription holds it: the row's `overrides` replace the static declaration.
|
|
10
|
+
*
|
|
11
|
+
* A limit override sets the ceiling of a key the plan declares and drops that key's promo, so the
|
|
12
|
+
* ceiling holds whatever the promo says; the kind and the window stay the plan's, because the
|
|
13
|
+
* counters are keyed by them. A key the plan does not declare, or a ceiling that is not a safe
|
|
14
|
+
* integer `>= 0`, is ignored. The override belongs to the row: it follows the subscription through
|
|
15
|
+
* a plan change and ends with it.
|
|
16
|
+
*/
|
|
17
|
+
overriddenPlan: (plan: PaymentPlan, row: Pick<PaymentSubscriptionRecord, 'overrides'> | null | undefined) => PaymentPlan
|
|
18
|
+
planLookupKey: (product: PaymentProduct, plan: PaymentPlan) => string
|
|
19
|
+
/** Whether a plan is sold through a paygate: never a free plan; otherwise its own gateways, else the product's. */
|
|
20
|
+
isSoldThrough: (product: PaymentProduct, plan: PaymentPlan, paygate: string) => boolean
|
|
21
|
+
}
|
package/src/plan.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ProductType, type ProductPlan } from '@owlmeans/payment'
|
|
2
|
+
import type { PaymentPlan, PaymentProduct, PaymentSubscriptionRecord } from './types.js'
|
|
3
|
+
import type { PlanHelper } from './plan/types.js'
|
|
4
|
+
|
|
5
|
+
export const createPlanHelper = (): PlanHelper => {
|
|
6
|
+
const planRank = (plan: Pick<ProductPlan, 'rank'>): number => plan.rank ?? 0
|
|
7
|
+
|
|
8
|
+
const isCeiling = (value: unknown): value is number =>
|
|
9
|
+
typeof value === 'number' && Number.isSafeInteger(value) && value >= 0
|
|
10
|
+
|
|
11
|
+
const overriddenPlan = (
|
|
12
|
+
plan: PaymentPlan, row: Pick<PaymentSubscriptionRecord, 'overrides'> | null | undefined,
|
|
13
|
+
): PaymentPlan => {
|
|
14
|
+
const limits = Object.entries(row?.overrides?.limits ?? {})
|
|
15
|
+
.filter(([key, override]) => plan.limits?.[key] != null && isCeiling(override?.limit))
|
|
16
|
+
if (limits.length === 0) {
|
|
17
|
+
return plan
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...plan,
|
|
22
|
+
limits: {
|
|
23
|
+
...plan.limits,
|
|
24
|
+
...Object.fromEntries(limits.map(([key, override]) => {
|
|
25
|
+
const { promo: _promo, ...declaration } = plan.limits![key]
|
|
26
|
+
return [key, { ...declaration, limit: override.limit }]
|
|
27
|
+
})),
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const planLookupKey = (product: PaymentProduct, plan: PaymentPlan): string =>
|
|
33
|
+
product.type === ProductType.Consumable ? `${product.sku}-consumable` : plan.sku
|
|
34
|
+
|
|
35
|
+
const isSoldThrough = (product: PaymentProduct, plan: PaymentPlan, paygate: string): boolean =>
|
|
36
|
+
plan.free !== true && (plan.gateways ?? product.gateways ?? []).includes(paygate)
|
|
37
|
+
|
|
38
|
+
return { planRank, overriddenPlan, planLookupKey, isSoldThrough }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const planHelper = createPlanHelper()
|
|
42
|
+
|
|
43
|
+
/** @deprecated compat:factory-refactor — use `planHelper.overriddenPlan(…)` */
|
|
44
|
+
export const overriddenPlan = (
|
|
45
|
+
plan: PaymentPlan, row: Pick<PaymentSubscriptionRecord, 'overrides'> | null | undefined,
|
|
46
|
+
): PaymentPlan => planHelper.overriddenPlan(plan, row)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AmountPolicyView } from '@owlmeans/payment'
|
|
2
|
+
import type { CheckoutAttempt, CheckoutNarrowInput, CheckoutPlugin, CheckoutSettled } from '../../types.js'
|
|
3
|
+
import type { Admitted } from '../types.js'
|
|
4
|
+
|
|
5
|
+
/** The checkout plugins' hooks, called in a context. */
|
|
6
|
+
export interface CheckoutPluginsHelper {
|
|
7
|
+
/**
|
|
8
|
+
* An entity's amount policy as every plugin narrows it now — the ONE computation both
|
|
9
|
+
* `gateway.amountPolicy` and checkout enforcement use, so a control and a refusal cannot disagree.
|
|
10
|
+
* A plugin's error propagates: a narrowing that cannot be computed fails closed.
|
|
11
|
+
*/
|
|
12
|
+
narrowAmountFor: (plugins: readonly CheckoutPlugin[], input: CheckoutNarrowInput) => Promise<AmountPolicyView>
|
|
13
|
+
/**
|
|
14
|
+
* Tell plugins how a checkout ended. A plugin's error is logged, never raised: a hold carries its
|
|
15
|
+
* own TTL, and the webhook that reports the outcome must not be redelivered for it.
|
|
16
|
+
*/
|
|
17
|
+
settleCheckout: (plugins: readonly CheckoutPlugin[], settled: CheckoutSettled) => Promise<void>
|
|
18
|
+
/** Release what admitted plugins hold for a checkout that never became usable. */
|
|
19
|
+
releaseAdmitted: (admitted: readonly Admitted[], attempt: CheckoutAttempt, sessionId?: string) => Promise<void>
|
|
20
|
+
/**
|
|
21
|
+
* Ask every plugin to admit the attempt, in order. A veto releases what the earlier plugins
|
|
22
|
+
* admitted and propagates.
|
|
23
|
+
*/
|
|
24
|
+
admitCheckout: (plugins: readonly CheckoutPlugin[], attempt: CheckoutAttempt) => Promise<Admitted[]>
|
|
25
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { narrowAmountPolicy, type AmountNarrowing, type AmountPolicyView } from '@owlmeans/payment'
|
|
2
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
3
|
+
import { memoHelper } from '@owlmeans/context'
|
|
4
|
+
import type { CheckoutAttempt, CheckoutNarrowInput, CheckoutPlugin, CheckoutSettled } from '../types.js'
|
|
5
|
+
import { log } from '../log.js'
|
|
6
|
+
import type { Admitted } from './types.js'
|
|
7
|
+
import type { CheckoutPluginsHelper } from './checkout-plugins/types.js'
|
|
8
|
+
import { checkoutPolicyHelper } from './checkout-policy.js'
|
|
9
|
+
|
|
10
|
+
export const makeCheckoutPluginsHelper = (ctx: ApiContext): CheckoutPluginsHelper => {
|
|
11
|
+
const narrowAmountFor = async (
|
|
12
|
+
plugins: readonly CheckoutPlugin[], input: CheckoutNarrowInput,
|
|
13
|
+
): Promise<AmountPolicyView> => {
|
|
14
|
+
const narrowings: AmountNarrowing[] = []
|
|
15
|
+
for (const plugin of plugins) {
|
|
16
|
+
if (plugin.narrow == null) {
|
|
17
|
+
continue
|
|
18
|
+
}
|
|
19
|
+
const narrowing = await plugin.narrow(ctx, input)
|
|
20
|
+
if (narrowing != null) {
|
|
21
|
+
narrowings.push(narrowing)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return narrowAmountPolicy(input.base, narrowings, {
|
|
26
|
+
productSku: input.productSku, ...(input.planSku != null ? { planSku: input.planSku } : {}),
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const settleCheckout = async (plugins: readonly CheckoutPlugin[], settled: CheckoutSettled): Promise<void> => {
|
|
31
|
+
for (const plugin of plugins) {
|
|
32
|
+
if (plugin.settled == null) {
|
|
33
|
+
continue
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
await plugin.settled(ctx, settled)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
log.error('Checkout plugin failed to settle', { plugin: plugin.alias ?? 'anonymous', error })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const releaseAdmitted = async (
|
|
44
|
+
admitted: readonly Admitted[], attempt: CheckoutAttempt, sessionId?: string,
|
|
45
|
+
): Promise<void> => {
|
|
46
|
+
for (const { plugin, reservationId } of admitted) {
|
|
47
|
+
await settleCheckout([plugin], {
|
|
48
|
+
entityId: attempt.entityId, productSku: attempt.productSku,
|
|
49
|
+
...(attempt.planSku != null ? { planSku: attempt.planSku } : {}),
|
|
50
|
+
...(sessionId != null ? { sessionId } : {}),
|
|
51
|
+
...(reservationId != null ? { reservationId } : {}),
|
|
52
|
+
...(attempt.amountMinor != null ? { amountMinor: attempt.amountMinor } : {}),
|
|
53
|
+
outcome: 'failed', at: new Date(),
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const admitCheckout = async (plugins: readonly CheckoutPlugin[], attempt: CheckoutAttempt): Promise<Admitted[]> => {
|
|
59
|
+
const admitted: Admitted[] = []
|
|
60
|
+
for (const plugin of plugins) {
|
|
61
|
+
if (plugin.admit == null) {
|
|
62
|
+
admitted.push({ plugin })
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const admission = await plugin.admit(ctx, attempt)
|
|
67
|
+
admitted.push({ plugin, ...(admission?.reservationId != null ? { reservationId: admission.reservationId } : {}) })
|
|
68
|
+
} catch (error) {
|
|
69
|
+
await releaseAdmitted(admitted.filter(entry => entry.plugin.admit != null), attempt)
|
|
70
|
+
throw error
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return admitted
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { narrowAmountFor, settleCheckout, releaseAdmitted, admitCheckout }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The checkout plugin calls of a context — one per context. */
|
|
81
|
+
export const checkoutPluginsOf = memoHelper.oncePer(makeCheckoutPluginsHelper)
|
|
82
|
+
|
|
83
|
+
/** @deprecated compat:factory-refactor — use `checkoutPluginsOf(ctx).narrowAmountFor(…)` */
|
|
84
|
+
export const narrowAmountFor = async (
|
|
85
|
+
ctx: ApiContext, plugins: readonly CheckoutPlugin[], input: CheckoutNarrowInput,
|
|
86
|
+
): Promise<AmountPolicyView> => await checkoutPluginsOf(ctx).narrowAmountFor(plugins, input)
|
|
87
|
+
|
|
88
|
+
/** @deprecated compat:factory-refactor — use `checkoutPolicyHelper.assertAmountAllowed(…)` */
|
|
89
|
+
export const assertAmountAllowed = (view: AmountPolicyView, amountMinor: number): void =>
|
|
90
|
+
checkoutPolicyHelper.assertAmountAllowed(view, amountMinor)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AmountPolicyView } from '@owlmeans/payment'
|
|
2
|
+
import type { CheckoutPlugin } from '../../types.js'
|
|
3
|
+
|
|
4
|
+
/** What a narrowed amount policy and the plugins' declarations allow a checkout — pure. */
|
|
5
|
+
export interface CheckoutPolicyHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Refuse an amount the narrowed view does not allow: any amount while `blocked`, else one above
|
|
8
|
+
* the narrowed maximum.
|
|
9
|
+
*
|
|
10
|
+
* @throws CheckoutLimitExceeded (409)
|
|
11
|
+
*/
|
|
12
|
+
assertAmountAllowed: (view: AmountPolicyView, amountMinor: number) => void
|
|
13
|
+
/**
|
|
14
|
+
* The session lifetime: the smallest `sessionTtlSeconds` any plugin declares, clamped to Stripe's
|
|
15
|
+
* 30 minutes – 24 hours; `undefined` when none declares one (Stripe's own default).
|
|
16
|
+
*/
|
|
17
|
+
sessionTtlOf: (plugins: readonly CheckoutPlugin[]) => number | undefined
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CheckoutLimitExceeded, type AmountPolicyView } from '@owlmeans/payment'
|
|
2
|
+
import { STRIPE_SESSION_TTL_MAX_SECONDS, STRIPE_SESSION_TTL_MIN_SECONDS } from '../consts.js'
|
|
3
|
+
import type { CheckoutPlugin } from '../types.js'
|
|
4
|
+
import type { CheckoutPolicyHelper } from './checkout-policy/types.js'
|
|
5
|
+
|
|
6
|
+
export const createCheckoutPolicyHelper = (): CheckoutPolicyHelper => {
|
|
7
|
+
const assertAmountAllowed = (view: AmountPolicyView, amountMinor: number): void => {
|
|
8
|
+
const limit = view.limit
|
|
9
|
+
if (limit == null || (!limit.blocked && amountMinor <= limit.maximumMinor)) {
|
|
10
|
+
return
|
|
11
|
+
}
|
|
12
|
+
throw new CheckoutLimitExceeded({
|
|
13
|
+
reason: limit.reason ?? 'limit', maximumMinor: limit.maximumMinor, currency: limit.currency,
|
|
14
|
+
...(limit.resetsAt != null ? { resetsAt: limit.resetsAt } : {}),
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const sessionTtlOf = (plugins: readonly CheckoutPlugin[]): number | undefined => {
|
|
19
|
+
const declared = plugins
|
|
20
|
+
.map(plugin => plugin.sessionTtlSeconds)
|
|
21
|
+
.filter((ttl): ttl is number => typeof ttl === 'number' && Number.isFinite(ttl))
|
|
22
|
+
if (declared.length === 0) {
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return Math.min(
|
|
27
|
+
STRIPE_SESSION_TTL_MAX_SECONDS, Math.max(STRIPE_SESSION_TTL_MIN_SECONDS, Math.floor(Math.min(...declared))),
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { assertAmountAllowed, sessionTtlOf }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const checkoutPolicyHelper = createCheckoutPolicyHelper()
|