@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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { contract, protocol } from '@owlmeans/entrypoint'
|
|
3
|
+
import type { EntrypointProtocol } from '@owlmeans/entrypoint'
|
|
4
|
+
import { PaygateError, UnknownPaygate } from '@owlmeans/payment'
|
|
5
|
+
import { backend, route, RouteMethod } from '@owlmeans/route'
|
|
6
|
+
import { GUARD_ED25519 } from '@owlmeans/server-app'
|
|
7
|
+
import { bind, bindAll } from '@owlmeans/server-entrypoint'
|
|
8
|
+
import type { ServerEntrypoint } from '@owlmeans/server-entrypoint'
|
|
9
|
+
import { paymentGate, paymentGateEntrypoints, paymentGateHandlers, webhookOf } from '../src/index.js'
|
|
10
|
+
import type { PaygateParams, ResyncResult, ResyncSubscriptionsResult } from '../src/index.js'
|
|
11
|
+
import { makeFakeContext } from './fake-stripe.js'
|
|
12
|
+
import type { FakeContext } from './fake-stripe.js'
|
|
13
|
+
|
|
14
|
+
const HOOKS = 'app-hooks'
|
|
15
|
+
const HOOKS_HOST = 'hooks.example.com'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The gate as an application re-declares it: its OWN aliases, every route pinned to its own
|
|
19
|
+
* service, and the library's paths, contracts and guards — typed with the library's own request and
|
|
20
|
+
* reply shapes, so a handler bound to it type-checks exactly as it does on `paymentGate`.
|
|
21
|
+
*/
|
|
22
|
+
const ownBase = protocol(route('app-hooks:gate', '/payment-gate', backend({ service: HOOKS })), contract())
|
|
23
|
+
const own = {
|
|
24
|
+
base: ownBase,
|
|
25
|
+
webhook: protocol(
|
|
26
|
+
route('app-hooks:gate:webhook', '/webhook/:paygate', backend({ parent: ownBase, method: RouteMethod.POST, service: HOOKS })),
|
|
27
|
+
paymentGate.webhook.contract!,
|
|
28
|
+
) as EntrypointProtocol<{ params: PaygateParams }, undefined>,
|
|
29
|
+
resync: protocol(
|
|
30
|
+
route('app-hooks:gate:resync', '/resync', backend({ parent: ownBase, method: RouteMethod.POST, service: HOOKS })),
|
|
31
|
+
paymentGate.resync.contract!, { guards: GUARD_ED25519 },
|
|
32
|
+
) as EntrypointProtocol<{}, ResyncResult>,
|
|
33
|
+
resyncSubscriptions: protocol(
|
|
34
|
+
route('app-hooks:gate:resync-subscriptions', '/resync-subscriptions', backend({ parent: ownBase, method: RouteMethod.POST, service: HOOKS })),
|
|
35
|
+
paymentGate.resyncSubscriptions.contract!, { guards: GUARD_ED25519 },
|
|
36
|
+
) as EntrypointProtocol<{}, ResyncSubscriptionsResult>,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ownEntrypoints = (): ServerEntrypoint<object>[] => [
|
|
40
|
+
bind(own.base),
|
|
41
|
+
bind(own.webhook, paymentGateHandlers.webhook),
|
|
42
|
+
bind(own.resync, paymentGateHandlers.resync),
|
|
43
|
+
bind(own.resyncSubscriptions, paymentGateHandlers.resyncSubscriptions),
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
/** The hook receiver: a process whose `cfg.service` is the application's own hook service. */
|
|
47
|
+
const hookProcess = async (manage: boolean): Promise<FakeContext> => await makeFakeContext({
|
|
48
|
+
service: HOOKS, host: HOOKS_HOST, gateway: { manage, bootstrap: false },
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
/** Run a bound route the way the transport does. */
|
|
52
|
+
const run = async (entrypoint: ServerEntrypoint<object>, params: Record<string, string> = {}): Promise<{ value?: unknown, error?: Error }> => {
|
|
53
|
+
const response: { value?: unknown, error?: Error, resolve: (value: unknown) => void, reject: (error: Error) => void } = {
|
|
54
|
+
resolve: value => { response.value = value },
|
|
55
|
+
reject: error => { response.error = error },
|
|
56
|
+
}
|
|
57
|
+
await entrypoint.handle({ alias: entrypoint.alias, params, query: {}, body: {}, headers: {}, path: '/' } as never, response as never)
|
|
58
|
+
|
|
59
|
+
return response
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe('@owlmeans/server-payment — the payment gate handlers', () => {
|
|
63
|
+
test('are exported once, frozen, and are the implementations the library\'s own bindings use', () => {
|
|
64
|
+
expect(Object.keys(paymentGateHandlers).sort()).toEqual(['resync', 'resyncSubscriptions', 'webhook'])
|
|
65
|
+
expect(Object.isFrozen(paymentGateHandlers)).toBe(true)
|
|
66
|
+
for (const handler of Object.values(paymentGateHandlers)) {
|
|
67
|
+
expect(typeof handler.bind).toBe('function')
|
|
68
|
+
}
|
|
69
|
+
expect(paymentGateEntrypoints.map(entrypoint => [entrypoint.alias, typeof entrypoint.handle])).toEqual([
|
|
70
|
+
[paymentGate.base.alias, 'undefined'],
|
|
71
|
+
[paymentGate.webhook.alias, 'function'],
|
|
72
|
+
[paymentGate.resync.alias, 'function'],
|
|
73
|
+
[paymentGate.resyncSubscriptions.alias, 'function'],
|
|
74
|
+
])
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('bind onto an application\'s own pinned declarations, which keep their aliases, service and guards', () => {
|
|
78
|
+
const bound = ownEntrypoints()
|
|
79
|
+
|
|
80
|
+
expect(bound.map(entrypoint => entrypoint.alias)).toEqual(
|
|
81
|
+
[own.base, own.webhook, own.resync, own.resyncSubscriptions].map(declaration => declaration.alias))
|
|
82
|
+
expect(bound.every(entrypoint => entrypoint.route.route.service === HOOKS)).toBe(true)
|
|
83
|
+
expect(bound.map(entrypoint => typeof entrypoint.handle)).toEqual(['undefined', 'function', 'function', 'function'])
|
|
84
|
+
expect(bound[1]!.guards).toEqual([])
|
|
85
|
+
expect(bound[2]!.guards).toEqual([GUARD_ED25519])
|
|
86
|
+
expect(bound[3]!.guards).toEqual([GUARD_ED25519])
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('bindAll pairs by object identity: it leaves another declaration without a handler', () => {
|
|
90
|
+
const paired = bindAll([own.webhook], [paymentGateHandlers.webhook])
|
|
91
|
+
|
|
92
|
+
expect(paired[0]!.handle).toBeUndefined()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('run in the context of the entrypoint they are bound to — the library\'s own is never registered', async () => {
|
|
96
|
+
const unmanaged = await hookProcess(false)
|
|
97
|
+
const [, webhook, resync] = ownEntrypoints()
|
|
98
|
+
unmanaged.ctx.registerEntrypoints([ownEntrypoints()[0]!, webhook!, resync!] as never)
|
|
99
|
+
|
|
100
|
+
expect(unmanaged.ctx.hasEntrypoint(paymentGate.webhook.alias)).toBe(false)
|
|
101
|
+
expect((await run(webhook!, { paygate: 'paypal' })).error).toBeInstanceOf(UnknownPaygate)
|
|
102
|
+
// Reached this process's gateway: unmanaged here, so a Stripe delivery and a resync are refused.
|
|
103
|
+
expect((await run(webhook!, { paygate: 'stripe' })).error).toBeInstanceOf(PaygateError)
|
|
104
|
+
expect((await run(resync!)).error).toBeInstanceOf(PaygateError)
|
|
105
|
+
|
|
106
|
+
const managed = await hookProcess(true)
|
|
107
|
+
const [base, , , resyncSubscriptions] = ownEntrypoints()
|
|
108
|
+
managed.ctx.registerEntrypoints([base!, resyncSubscriptions!] as never)
|
|
109
|
+
|
|
110
|
+
expect(await run(resyncSubscriptions!)).toEqual(expect.objectContaining({ value: { scanned: 0, updated: 0 } }))
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('the application\'s webhook path is the one Stripe is pointed at — a re-declaration keeps the library\'s path', async () => {
|
|
114
|
+
const hooks = await hookProcess(false)
|
|
115
|
+
|
|
116
|
+
expect(webhookOf(hooks.ctx).webhookUrlOf()).toBe(`https://${HOOKS_HOST}/payment-gate/webhook/stripe`)
|
|
117
|
+
expect([own.base.route.route.path, own.webhook.route.route.path])
|
|
118
|
+
.toEqual([paymentGate.base.route.route.path, paymentGate.webhook.route.route.path])
|
|
119
|
+
})
|
|
120
|
+
})
|
package/tests/gate.spec.ts
CHANGED
|
@@ -1,97 +1,88 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { AppType, makeBasicContext } from '@owlmeans/context'
|
|
3
|
-
import type { BasicConfig } from '@owlmeans/context'
|
|
4
2
|
import type { AbstractRequest, AbstractResponse, GateService } from '@owlmeans/entrypoint'
|
|
5
|
-
import type { Auth } from '@owlmeans/auth'
|
|
3
|
+
import type { Auth, PermissionSet } from '@owlmeans/auth'
|
|
6
4
|
import { AuthForbidden, AuthRole } from '@owlmeans/auth'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import type {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
const record = (status: SubscriptionStatus, capabilities?: unknown[]) => ({
|
|
15
|
-
entityId: 'entity-1',
|
|
16
|
-
productSku: 'pro',
|
|
17
|
-
status,
|
|
18
|
-
capabilities: capabilities ?? [
|
|
19
|
-
{ scope: 'renewable', permissions: { production: 1 } },
|
|
20
|
-
{ scope: CAPABILITY_FEATURE_SCOPE, permissions: { 'branding--whitelabel': true } },
|
|
21
|
-
],
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
/** The gate must fail closed, including when its subscription store is unreadable. */
|
|
25
|
-
const makeGate = async (answer: () => unknown): Promise<GateService> => {
|
|
26
|
-
const ctx = makeBasicContext<BasicConfig>({
|
|
27
|
-
ready: false,
|
|
28
|
-
service: 'server-payment-tests',
|
|
29
|
-
type: AppType.Backend,
|
|
30
|
-
})
|
|
31
|
-
const resource = {
|
|
32
|
-
alias: RES_PAYMENT_SUBSCRIPTION,
|
|
33
|
-
list: async (where?: Criteria<ResourceRecord>) => {
|
|
34
|
-
const items = filterRecords(answer() as ResourceRecord[], where)
|
|
35
|
-
return { items, total: items.length }
|
|
36
|
-
},
|
|
37
|
-
registerContext: () => resource,
|
|
38
|
-
init: async () => undefined,
|
|
39
|
-
ready: async () => true,
|
|
40
|
-
}
|
|
41
|
-
ctx.registerResource(resource as never)
|
|
42
|
-
ctx.registerService(makeEntitlementGate())
|
|
43
|
-
ctx.configure()
|
|
44
|
-
await ctx.init()
|
|
45
|
-
|
|
46
|
-
return ctx.service<GateService>(ENTITLEMENT_GATE)
|
|
47
|
-
}
|
|
5
|
+
import { CapabilityRequired, ENTITLEMENT_GATE, SubscriptionStatus } from '@owlmeans/payment'
|
|
6
|
+
import { makeCapabilityGate } from '../src/gate.js'
|
|
7
|
+
import { CAP_BASIC, CAP_PREVIEW, CAP_WHITELABEL, makeFakeContext, past, PRO } from './fake-stripe.js'
|
|
8
|
+
import type { FakeContext } from './fake-stripe.js'
|
|
9
|
+
import { paymentAccessOf } from '../src/access.js'
|
|
10
|
+
import { catalogueOf } from '../src/catalogue.js'
|
|
48
11
|
|
|
49
12
|
const request = (auth: Partial<Auth> | null = {}): AbstractRequest => ({
|
|
50
13
|
alias: 'test', headers: {}, params: {}, query: {}, body: {}, path: '/',
|
|
51
14
|
...(auth != null ? {
|
|
52
15
|
auth: {
|
|
53
16
|
type: 'ed25519-basic-token', token: 't', userId: 'u', role: AuthRole.User,
|
|
54
|
-
scopes: [], entitySlug: 'entity-1', isUser: true, createdAt: new Date(), ...auth,
|
|
17
|
+
scopes: ['*'], entitySlug: 'entity-1', isUser: true, createdAt: new Date(), ...auth,
|
|
55
18
|
} satisfies Auth,
|
|
56
19
|
} : {}),
|
|
57
20
|
}) as unknown as AbstractRequest
|
|
58
21
|
|
|
59
22
|
const res = {} as AbstractResponse<unknown>
|
|
60
23
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
24
|
+
const withPro = async (status: SubscriptionStatus = SubscriptionStatus.Active): Promise<FakeContext> => {
|
|
25
|
+
const fake = await makeFakeContext()
|
|
26
|
+
await paymentAccessOf(fake.ctx).gateway().grantInternalPlan(fake.ctx, 'entity-1', PRO, { force: true })
|
|
27
|
+
fake.stores['payment-subscription'].rows[0].status = status
|
|
28
|
+
return fake
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const gateOf = (fake: FakeContext, alias: string = ENTITLEMENT_GATE): GateService => fake.ctx.service<GateService>(alias)
|
|
32
|
+
|
|
33
|
+
describe('@owlmeans/server-payment — the capability gate', () => {
|
|
34
|
+
test('passes a capability of an active, trial or past-due plan; parameters are any-of', async () => {
|
|
35
|
+
for (const status of [SubscriptionStatus.Active, SubscriptionStatus.Trial, SubscriptionStatus.PastDue]) {
|
|
36
|
+
const fake = await withPro(status)
|
|
37
|
+
await gateOf(fake).assert(request(), res, [CAP_WHITELABEL])
|
|
38
|
+
await gateOf(fake).assert(request(), res, ['feature:nothing--here', CAP_WHITELABEL])
|
|
66
39
|
}
|
|
67
40
|
})
|
|
68
41
|
|
|
69
|
-
test('refuses
|
|
70
|
-
const canceled = await
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
})
|
|
42
|
+
test('refuses a canceled plan, an unrelated capability and a lapsed promo with CapabilityRequired (a 403)', async () => {
|
|
43
|
+
const canceled = await withPro(SubscriptionStatus.Canceled)
|
|
44
|
+
const refusal = await gateOf(canceled).assert(request(), res, [CAP_WHITELABEL]).catch(error => error)
|
|
45
|
+
expect(refusal).toBeInstanceOf(CapabilityRequired)
|
|
46
|
+
expect(refusal).toBeInstanceOf(AuthForbidden)
|
|
47
|
+
expect(refusal.params).toEqual([CAP_WHITELABEL])
|
|
48
|
+
await gateOf(canceled).assert(request(), res, [CAP_BASIC])
|
|
77
49
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
50
|
+
const unrelated = await withPro()
|
|
51
|
+
await expect(gateOf(unrelated).assert(request(), res, ['feature:domain--custom'])).rejects.toBeInstanceOf(CapabilityRequired)
|
|
52
|
+
|
|
53
|
+
const lapsed = await makeFakeContext({ catalogue: { previewUntil: past(1) } })
|
|
54
|
+
await expect(gateOf(lapsed).assert(request(), res, [CAP_PREVIEW])).rejects.toBeInstanceOf(CapabilityRequired)
|
|
55
|
+
expect((await catalogueOf(lapsed.ctx).entitlementsOf('entity-1')).some(set => set.permissions.preview != null)).toBe(false)
|
|
81
56
|
})
|
|
82
57
|
|
|
83
|
-
test('refuses missing authentication or organization before reading storage', async () => {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
58
|
+
test('refuses a missing authentication or organization before reading storage, and an unreadable store', async () => {
|
|
59
|
+
const fake = await withPro()
|
|
60
|
+
fake.stores['payment-subscription'].failing.add('list')
|
|
61
|
+
const noAuth = await gateOf(fake).assert(request(null), res, [CAP_WHITELABEL]).catch(error => error)
|
|
62
|
+
expect(noAuth).toBeInstanceOf(AuthForbidden)
|
|
63
|
+
expect(noAuth).not.toBeInstanceOf(CapabilityRequired)
|
|
64
|
+
const noEntity = await gateOf(fake).assert(request({ entitySlug: undefined }), res, [CAP_WHITELABEL]).catch(error => error)
|
|
65
|
+
expect(noEntity).not.toBeInstanceOf(CapabilityRequired)
|
|
66
|
+
expect(noEntity).toBeInstanceOf(AuthForbidden)
|
|
67
|
+
|
|
68
|
+
await expect(gateOf(fake).assert(request(), res, [CAP_WHITELABEL])).rejects.toBeInstanceOf(CapabilityRequired)
|
|
90
69
|
})
|
|
91
70
|
|
|
92
|
-
test('
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
71
|
+
test('the plan is the authority: a token false denies, a token grant alone never allows, requirePermission is opt-in', async () => {
|
|
72
|
+
const deny: PermissionSet[] = [{ scope: 'feature', permissions: { whitelabel: false } }]
|
|
73
|
+
const grant: PermissionSet[] = [{ scope: 'feature', permissions: { whitelabel: true } }]
|
|
74
|
+
|
|
75
|
+
const fake = await withPro()
|
|
76
|
+
await expect(gateOf(fake).assert(request({ permissions: deny }), res, [CAP_WHITELABEL]))
|
|
77
|
+
.rejects.toBeInstanceOf(CapabilityRequired)
|
|
78
|
+
|
|
79
|
+
const free = await makeFakeContext()
|
|
80
|
+
await expect(gateOf(free).assert(request({ permissions: grant }), res, [CAP_WHITELABEL]))
|
|
81
|
+
.rejects.toBeInstanceOf(CapabilityRequired)
|
|
82
|
+
|
|
83
|
+
fake.ctx.registerService(makeCapabilityGate('strict-gate', { requirePermission: true }))
|
|
84
|
+
await expect(gateOf(fake, 'strict-gate').assert(request(), res, [CAP_WHITELABEL]))
|
|
85
|
+
.rejects.toBeInstanceOf(CapabilityRequired)
|
|
86
|
+
await gateOf(fake, 'strict-gate').assert(request({ permissions: grant }), res, [CAP_WHITELABEL])
|
|
96
87
|
})
|
|
97
88
|
})
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { PaygateError, PortalFlow, WebhookSetupError } from '@owlmeans/payment'
|
|
3
|
+
import { RES_PAYMENT_FINGERPRINT, RES_PAYMENT_WEBHOOK } from '../src/consts.js'
|
|
4
|
+
import { makeGatewayService } from '../src/service.js'
|
|
5
|
+
import { makeFakeContext, SERVICE, type FakeContext, type FakeContextOptions } from './fake-stripe.js'
|
|
6
|
+
import type { GatewayServiceOptions } from '../src/types.js'
|
|
7
|
+
import { paymentAccessOf } from '../src/access.js'
|
|
8
|
+
import { stripeBootstrapOf } from '../src/bootstrap.js'
|
|
9
|
+
import { portalOf } from '../src/plugins/portal.js'
|
|
10
|
+
import { webhookOf } from '../src/plugins/webhook-manager.js'
|
|
11
|
+
|
|
12
|
+
const WEB = 'app.example.com'
|
|
13
|
+
const HOOKS = 'hooks.example.com'
|
|
14
|
+
const HOOK_SERVICE = 'hooks'
|
|
15
|
+
const WEB_URL = `https://${WEB}/api/payment-gate/webhook/stripe`
|
|
16
|
+
const HOOK_URL = `https://${HOOKS}/payment-gate/webhook/stripe`
|
|
17
|
+
const PORTAL = { returnUrl: `https://${WEB}/billing` }
|
|
18
|
+
const labelOf = (owner: string) => ({ owlmeans: 'payment', service: owner })
|
|
19
|
+
|
|
20
|
+
/** Poll until `ready` holds — a boot bootstrap runs once the context is initialized, unawaited. */
|
|
21
|
+
const until = async (ready: () => boolean, ms = 3000): Promise<void> => {
|
|
22
|
+
const deadline = Date.now() + ms
|
|
23
|
+
while (!ready()) {
|
|
24
|
+
if (Date.now() > deadline) throw new Error('condition not reached')
|
|
25
|
+
await Bun.sleep(5)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The two managed processes of one deployment sharing a database and a Stripe account: the manager
|
|
31
|
+
* (`cfg.service` = SERVICE, on the web host under `/api`) and the hook receiver (its own host) — both
|
|
32
|
+
* with `owner` SERVICE and `webhookService` the hook receiver.
|
|
33
|
+
*/
|
|
34
|
+
const managerProcess = async (gatewayOpts: GatewayServiceOptions = {}, extra: FakeContextOptions = {}): Promise<FakeContext> =>
|
|
35
|
+
await makeFakeContext({
|
|
36
|
+
service: SERVICE, host: WEB, base: 'api', services: { [HOOK_SERVICE]: { host: HOOKS } }, portal: PORTAL,
|
|
37
|
+
...extra, gateway: { owner: SERVICE, webhookService: HOOK_SERVICE, ...gatewayOpts },
|
|
38
|
+
})
|
|
39
|
+
const hookProcess = async (gatewayOpts: GatewayServiceOptions = {}, extra: FakeContextOptions = {}): Promise<FakeContext> =>
|
|
40
|
+
await makeFakeContext({
|
|
41
|
+
service: HOOK_SERVICE, host: HOOKS, services: { [SERVICE]: { host: WEB, base: 'api' } }, portal: PORTAL,
|
|
42
|
+
...extra, gateway: { manage: true, owner: SERVICE, webhookService: HOOK_SERVICE, ...gatewayOpts },
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
/** A boot bootstrap is done once the webhook step has left exactly one endpoint and one row. */
|
|
46
|
+
const bootstrapped = (fake: FakeContext, url: string) => (): boolean =>
|
|
47
|
+
fake.state.webhookEndpoints.length === 1 && fake.state.webhookEndpoints[0].url === url
|
|
48
|
+
&& fake.stores[RES_PAYMENT_WEBHOOK].rows.length === 1 && fake.stores[RES_PAYMENT_WEBHOOK].rows[0].url === url
|
|
49
|
+
|
|
50
|
+
describe('@owlmeans/server-payment — gateway options: defaults', () => {
|
|
51
|
+
test('without options the URL, the row key and the portal key are this service\'s own, and bootstrap follows manage', async () => {
|
|
52
|
+
const reader = await makeFakeContext({ host: WEB, base: 'api' })
|
|
53
|
+
expect(paymentAccessOf(reader.ctx).gateway()).toEqual(expect.objectContaining({
|
|
54
|
+
managed: false, bootstrap: false, owner: SERVICE, webhookService: SERVICE,
|
|
55
|
+
}))
|
|
56
|
+
expect(webhookOf(reader.ctx).webhookUrlOf()).toBe(WEB_URL)
|
|
57
|
+
|
|
58
|
+
const owner = await makeFakeContext({ host: WEB, base: 'api', portal: PORTAL, gateway: { manage: true } })
|
|
59
|
+
expect(paymentAccessOf(owner.ctx).gateway().bootstrap).toBe(true)
|
|
60
|
+
await until(bootstrapped(owner, WEB_URL))
|
|
61
|
+
expect(owner.state.webhookEndpoints[0]).toEqual(expect.objectContaining({
|
|
62
|
+
metadata: labelOf(SERVICE), description: `owlmeans:${SERVICE}`,
|
|
63
|
+
}))
|
|
64
|
+
expect(owner.stores[RES_PAYMENT_WEBHOOK].rows).toEqual([expect.objectContaining({ service: SERVICE, url: WEB_URL })])
|
|
65
|
+
expect(owner.stores[RES_PAYMENT_FINGERPRINT].rows).toContainEqual(expect.objectContaining({ sku: `portal:${SERVICE}` }))
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('@owlmeans/server-payment — gateway options: webhookService and owner', () => {
|
|
70
|
+
test('webhookService forms the URL on its own host; owner keys the rows, the secret, the labels and the portal', async () => {
|
|
71
|
+
const hook = await hookProcess({ bootstrap: false })
|
|
72
|
+
expect(webhookOf(hook.ctx).webhookServiceOf()).toBe(HOOK_SERVICE)
|
|
73
|
+
expect(webhookOf(hook.ctx).gatewayOwnerOf()).toBe(SERVICE)
|
|
74
|
+
expect(webhookOf(hook.ctx).webhookUrlOf()).toBe(HOOK_URL)
|
|
75
|
+
|
|
76
|
+
const row = await webhookOf(hook.ctx).ensureWebhookEndpoint(hook.stripe)
|
|
77
|
+
const [endpoint] = hook.state.webhookEndpoints
|
|
78
|
+
expect(endpoint).toEqual(expect.objectContaining({
|
|
79
|
+
url: HOOK_URL, metadata: labelOf(SERVICE), description: `owlmeans:${SERVICE}`,
|
|
80
|
+
}))
|
|
81
|
+
expect(row).toEqual(expect.objectContaining({ service: SERVICE, url: HOOK_URL, externalId: endpoint.id }))
|
|
82
|
+
expect(await webhookOf(hook.ctx).stripeWebhookSecret()).toBe(endpoint.secret)
|
|
83
|
+
|
|
84
|
+
const configuration = await portalOf(hook.ctx).ensurePortalConfiguration(hook.stripe)
|
|
85
|
+
expect(hook.state.portalConfigurations[0]).toEqual(expect.objectContaining({
|
|
86
|
+
id: configuration, metadata: { ...labelOf(SERVICE), deployment: HOOK_URL },
|
|
87
|
+
}))
|
|
88
|
+
expect(hook.stores[RES_PAYMENT_FINGERPRINT].rows).toContainEqual(
|
|
89
|
+
expect.objectContaining({ sku: `portal:${SERVICE}`, externalId: configuration }),
|
|
90
|
+
)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('the manager and the hook process share the rows: one URL, one secret, and a forced run from the manager creates nothing', async () => {
|
|
94
|
+
const hook = await hookProcess({ bootstrap: false })
|
|
95
|
+
const manager = await managerProcess({ manage: true, bootstrap: false })
|
|
96
|
+
expect(webhookOf(manager.ctx).webhookUrlOf()).toBe(webhookOf(hook.ctx).webhookUrlOf())
|
|
97
|
+
|
|
98
|
+
await stripeBootstrapOf(hook.ctx).bootstrapStripe(hook.stripe)
|
|
99
|
+
for (const alias of [RES_PAYMENT_WEBHOOK, RES_PAYMENT_FINGERPRINT]) {
|
|
100
|
+
manager.stores[alias].rows.push(...structuredClone(hook.stores[alias].rows))
|
|
101
|
+
}
|
|
102
|
+
expect(await webhookOf(manager.ctx).stripeWebhookSecret()).toBe(hook.state.webhookEndpoints[0].secret)
|
|
103
|
+
|
|
104
|
+
hook.state.calls.length = 0
|
|
105
|
+
await stripeBootstrapOf(manager.ctx).bootstrapStripe(hook.stripe, { force: true })
|
|
106
|
+
expect(hook.state.calls).not.toContain('webhookEndpoints.create')
|
|
107
|
+
expect(hook.state.calls).not.toContain('webhookEndpoints.del')
|
|
108
|
+
expect(hook.state.calls).not.toContain('billingPortal.configurations.create')
|
|
109
|
+
expect(hook.state.webhookEndpoints.map(({ url }) => url)).toEqual([HOOK_URL])
|
|
110
|
+
expect(hook.state.portalConfigurations).toHaveLength(1)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('a process booting with a new webhookService moves the owner\'s endpoint and re-creates the portal for the new key', async () => {
|
|
114
|
+
const before = await makeFakeContext({ host: WEB, base: 'api', portal: PORTAL })
|
|
115
|
+
const former = await webhookOf(before.ctx).ensureWebhookEndpoint(before.stripe)
|
|
116
|
+
const formerPortal = await portalOf(before.ctx).ensurePortalConfiguration(before.stripe)
|
|
117
|
+
expect(former?.url).toBe(WEB_URL)
|
|
118
|
+
|
|
119
|
+
const hook = await hookProcess({}, {
|
|
120
|
+
seed: {
|
|
121
|
+
[RES_PAYMENT_WEBHOOK]: before.stores[RES_PAYMENT_WEBHOOK].rows,
|
|
122
|
+
[RES_PAYMENT_FINGERPRINT]: before.stores[RES_PAYMENT_FINGERPRINT].rows,
|
|
123
|
+
},
|
|
124
|
+
stripe: {
|
|
125
|
+
seq: before.state.seq,
|
|
126
|
+
webhookEndpoints: structuredClone(before.state.webhookEndpoints),
|
|
127
|
+
portalConfigurations: structuredClone(before.state.portalConfigurations),
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
await until(bootstrapped(hook, HOOK_URL))
|
|
131
|
+
|
|
132
|
+
expect(hook.state.webhookEndpoints).toEqual([expect.objectContaining({ url: HOOK_URL, metadata: labelOf(SERVICE) })])
|
|
133
|
+
expect(hook.state.webhookEndpoints[0].id).not.toBe(former?.externalId)
|
|
134
|
+
expect(hook.stores[RES_PAYMENT_WEBHOOK].rows).toEqual([expect.objectContaining({ service: SERVICE, url: HOOK_URL })])
|
|
135
|
+
expect(await webhookOf(hook.ctx).stripeWebhookSecret()).toBe(hook.state.webhookEndpoints[0].secret)
|
|
136
|
+
|
|
137
|
+
const portal = hook.stores[RES_PAYMENT_FINGERPRINT].rows.find(row => row.sku === `portal:${SERVICE}`)
|
|
138
|
+
expect(portal?.externalId).not.toBe(formerPortal)
|
|
139
|
+
expect(hook.state.portalConfigurations.map(({ id, metadata }) => ({ id, metadata }))).toEqual([
|
|
140
|
+
{ id: formerPortal, metadata: { ...labelOf(SERVICE), deployment: WEB_URL } },
|
|
141
|
+
{ id: portal?.externalId, metadata: { ...labelOf(SERVICE), deployment: HOOK_URL } },
|
|
142
|
+
])
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('@owlmeans/server-payment — gateway options: bootstrap', () => {
|
|
147
|
+
test('bootstrap: false skips the boot bootstrap, serves the portal, and still runs a forced bootstrap', async () => {
|
|
148
|
+
const manager = await managerProcess({ manage: true, bootstrap: false })
|
|
149
|
+
expect(paymentAccessOf(manager.ctx).gateway()).toEqual(expect.objectContaining({ managed: true, bootstrap: false }))
|
|
150
|
+
// A bootstrapping process booted after it is the clock: once it is done, the manager's would be too.
|
|
151
|
+
const clock = await hookProcess()
|
|
152
|
+
await until(bootstrapped(clock, HOOK_URL))
|
|
153
|
+
expect(manager.state.calls).toEqual([])
|
|
154
|
+
|
|
155
|
+
await paymentAccessOf(manager.ctx).paygateCustomers().create({ paygate: 'stripe', externalId: 'cus_1', entityId: 'entity-1' })
|
|
156
|
+
const link = await paymentAccessOf(manager.ctx).gateway().portalLink(manager.ctx, 'entity-1', {
|
|
157
|
+
flow: PortalFlow.Manage, returnUrl: PORTAL.returnUrl,
|
|
158
|
+
})
|
|
159
|
+
expect(link).toStartWith('https://billing.example.test/')
|
|
160
|
+
expect(manager.state.portalConfigurations[0].metadata).toEqual({ ...labelOf(SERVICE), deployment: HOOK_URL })
|
|
161
|
+
|
|
162
|
+
await stripeBootstrapOf(manager.ctx).bootstrapStripe(await paymentAccessOf(manager.ctx).gateway().stripe(manager.ctx), { force: true })
|
|
163
|
+
expect(manager.state.webhookEndpoints).toEqual([expect.objectContaining({ url: HOOK_URL, metadata: labelOf(SERVICE) })])
|
|
164
|
+
expect(manager.stores[RES_PAYMENT_WEBHOOK].rows).toEqual([expect.objectContaining({ service: SERVICE, url: HOOK_URL })])
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('refuses contradictory options at construction, and an undeclared webhook service only when bootstrapping', async () => {
|
|
168
|
+
expect(() => makeGatewayService(undefined, { manage: false, bootstrap: true })).toThrow(PaygateError)
|
|
169
|
+
expect(() => makeGatewayService(undefined, { owner: '' })).toThrow(PaygateError)
|
|
170
|
+
expect(() => makeGatewayService(undefined, { webhookService: ' ' })).toThrow(PaygateError)
|
|
171
|
+
|
|
172
|
+
await expect(makeFakeContext({ gateway: { manage: true, webhookService: HOOK_SERVICE } }))
|
|
173
|
+
.rejects.toBeInstanceOf(WebhookSetupError)
|
|
174
|
+
|
|
175
|
+
const quiet = await makeFakeContext({ gateway: { manage: true, bootstrap: false, webhookService: HOOK_SERVICE } })
|
|
176
|
+
expect(() => webhookOf(quiet.ctx).webhookUrlOf()).toThrow(WebhookSetupError)
|
|
177
|
+
const reader = await makeFakeContext({ gateway: { webhookService: HOOK_SERVICE } })
|
|
178
|
+
expect(paymentAccessOf(reader.ctx).gateway().webhookService).toBe(HOOK_SERVICE)
|
|
179
|
+
})
|
|
180
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import type { AbstractRequest, AbstractResponse, GateService } from '@owlmeans/entrypoint'
|
|
3
|
+
import type { Auth } from '@owlmeans/auth'
|
|
4
|
+
import { AuthForbidden, AuthRole } from '@owlmeans/auth'
|
|
5
|
+
import { LIMIT_GATE, LimitExhausted, LimitWindow, planLimitHelper } from '@owlmeans/payment'
|
|
6
|
+
import { makeFakeContext, PRO } from './fake-stripe.js'
|
|
7
|
+
import type { FakeContext } from './fake-stripe.js'
|
|
8
|
+
import { paymentAccessOf } from '../src/access.js'
|
|
9
|
+
|
|
10
|
+
const request = (auth: Partial<Auth> | null = {}): AbstractRequest => ({
|
|
11
|
+
alias: 'test', headers: {}, params: {}, query: {}, body: {}, path: '/',
|
|
12
|
+
...(auth != null ? {
|
|
13
|
+
auth: {
|
|
14
|
+
type: 'ed25519-basic-token', token: 't', userId: 'u', role: AuthRole.User,
|
|
15
|
+
scopes: ['*'], entitySlug: 'entity-1', isUser: true, createdAt: new Date(), ...auth,
|
|
16
|
+
} satisfies Auth,
|
|
17
|
+
} : {}),
|
|
18
|
+
}) as unknown as AbstractRequest
|
|
19
|
+
|
|
20
|
+
const res = {} as AbstractResponse<unknown>
|
|
21
|
+
const gateOf = (fake: FakeContext): GateService => fake.ctx.service<GateService>(LIMIT_GATE)
|
|
22
|
+
|
|
23
|
+
describe('@owlmeans/server-payment — the limit gate', () => {
|
|
24
|
+
test('passes with room and consumes nothing', async () => {
|
|
25
|
+
const fake = await makeFakeContext()
|
|
26
|
+
await gateOf(fake).assert(request(), res, [planLimitHelper.formatLimitParam('exports')])
|
|
27
|
+
await gateOf(fake).assert(request(), res, [planLimitHelper.formatLimitParam('exports')])
|
|
28
|
+
|
|
29
|
+
expect(fake.stores['payment-usage'].rows).toHaveLength(0)
|
|
30
|
+
expect(fake.stores['payment-usage-counter'].rows).toHaveLength(0)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('refuses at the ceiling with the limit, the usage and the reset date', async () => {
|
|
34
|
+
const fake = await makeFakeContext()
|
|
35
|
+
await paymentAccessOf(fake.ctx).entitlements().consume({ entityId: 'entity-1', limitKey: 'exports', eventKey: 'export:1' })
|
|
36
|
+
|
|
37
|
+
const refusal = await gateOf(fake).assert(request(), res, [planLimitHelper.formatLimitParam('exports')]).catch(error => error)
|
|
38
|
+
expect(refusal).toBeInstanceOf(LimitExhausted)
|
|
39
|
+
expect(refusal).toBeInstanceOf(AuthForbidden)
|
|
40
|
+
expect(refusal).toEqual(expect.objectContaining({
|
|
41
|
+
limitKey: 'exports', used: 1, limit: 1, resetsAt: planLimitHelper.windowBoundsOf(LimitWindow.Month).resetsAt,
|
|
42
|
+
}))
|
|
43
|
+
await expect(gateOf(fake).assert(request(), res, [planLimitHelper.formatLimitParam('reports', 2)])).rejects.toBeInstanceOf(LimitExhausted)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('skips malformed and undeclared parameters, ORs the rest, and refuses when none is left', async () => {
|
|
47
|
+
const fake = await makeFakeContext()
|
|
48
|
+
await paymentAccessOf(fake.ctx).gateway().grantInternalPlan(fake.ctx, 'entity-1', PRO, { force: true })
|
|
49
|
+
await gateOf(fake).assert(request(), res, ['feature:exports', 'limit:', planLimitHelper.formatLimitParam('nope'), planLimitHelper.formatLimitParam('seats')])
|
|
50
|
+
|
|
51
|
+
const seats = await gateOf(fake).assert(request(), res, [planLimitHelper.formatLimitParam('seats', 3), planLimitHelper.formatLimitParam('exports')])
|
|
52
|
+
expect(seats).toBeUndefined()
|
|
53
|
+
|
|
54
|
+
const malformed = await gateOf(fake).assert(request(), res, ['garbage', 'feature:x']).catch(error => error)
|
|
55
|
+
expect(malformed).toBeInstanceOf(LimitExhausted)
|
|
56
|
+
expect(malformed.limitKey).toBe('garbage')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('refuses when authentication is missing or the store cannot be read', async () => {
|
|
60
|
+
const fake = await makeFakeContext()
|
|
61
|
+
await expect(gateOf(fake).assert(request(null), res, [planLimitHelper.formatLimitParam('exports')])).rejects.toBeInstanceOf(AuthForbidden)
|
|
62
|
+
|
|
63
|
+
fake.stores['payment-usage-counter'].failing.add('load')
|
|
64
|
+
await expect(gateOf(fake).assert(request(), res, [planLimitHelper.formatLimitParam('exports')])).rejects.toBeInstanceOf(LimitExhausted)
|
|
65
|
+
})
|
|
66
|
+
})
|