@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/service.ts
CHANGED
|
@@ -1,35 +1,177 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
1
2
|
import { createService } from '@owlmeans/context'
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
appendPaymentService, DEFAULT_ALIAS as PAYMENT_SERVICE, ENTITLEMENT_GATE, LIMIT_GATE, PaygateError, ProductError,
|
|
5
|
+
} from '@owlmeans/payment'
|
|
3
6
|
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
4
|
-
import {
|
|
5
|
-
|
|
7
|
+
import {
|
|
8
|
+
ENTITLEMENT_SERVICE, GATEWAY_SERVICE, RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT,
|
|
9
|
+
RES_PAYMENT_SUBSCRIPTION, RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK,
|
|
10
|
+
} from './consts.js'
|
|
11
|
+
import { registerConsumerRights } from './consumer/service.js'
|
|
12
|
+
import { makeEntitlementService } from './entitlement.js'
|
|
13
|
+
import { makeCapabilityGate } from './gate.js'
|
|
14
|
+
import { makeLimitGate } from './limit.js'
|
|
6
15
|
import { appendCompletionObserver } from './observer.js'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
import {
|
|
17
|
+
makeFingerprintResource, makeFulfillmentResource, makePaygateCustomerResource, makeSubscriptionResource,
|
|
18
|
+
makeUsageCounterResource, makeUsageResource, makeWebhookResource,
|
|
19
|
+
} from './resource.js'
|
|
20
|
+
import type {
|
|
21
|
+
Config, Context, GatewayService, PaymentGatewayOptions, PaymentPlan, GatewayServiceOptions, StripeBootstrapOptions,
|
|
22
|
+
} from './types.js'
|
|
23
|
+
import { log } from './log.js'
|
|
24
|
+
import { paymentAccessOf } from './access.js'
|
|
25
|
+
import { catalogueOf } from './catalogue.js'
|
|
26
|
+
import { makePlanDeclarationsModel } from './models/declarations.js'
|
|
27
|
+
import { subscriptionCommitOf } from './commit.js'
|
|
28
|
+
import { stripeBootstrapOf } from './bootstrap.js'
|
|
29
|
+
import { productSyncOf } from './sync.js'
|
|
30
|
+
import { estimateOf } from './plugins/estimate.js'
|
|
31
|
+
import { makeEstimateCache } from './plugins/estimate/cache.js'
|
|
32
|
+
import { checkoutPluginsOf } from './plugins/checkout-plugins.js'
|
|
33
|
+
import { makeCheckoutPluginRegistry } from './plugins/checkout-registry.js'
|
|
34
|
+
import { portalOf } from './plugins/portal.js'
|
|
35
|
+
import { webhookOf } from './plugins/webhook-manager.js'
|
|
36
|
+
import { stripeSubscriptionsOf } from './plugins/subscriptions.js'
|
|
37
|
+
import { stripeCheckoutOf } from './plugins/stripe.js'
|
|
11
38
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
39
|
+
const unmanaged = (): never => { throw new PaygateError('unmanaged') }
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Refuse contradictory gateway options: `bootstrap: true` on an unmanaged gateway
|
|
43
|
+
* (`PaygateError('bootstrap:unmanaged')`), an empty `owner` / `webhookService`
|
|
44
|
+
* (`PaygateError('owner' | 'webhook-service')`).
|
|
45
|
+
*/
|
|
46
|
+
export const assertGatewayOptions = (opts: GatewayServiceOptions): void => {
|
|
47
|
+
if (opts.manage === false && opts.bootstrap === true) {
|
|
48
|
+
throw new PaygateError('bootstrap:unmanaged')
|
|
49
|
+
}
|
|
50
|
+
for (const [name, value] of [['owner', opts.owner], ['webhook-service', opts.webhookService]] as const) {
|
|
51
|
+
if (value != null && (typeof value !== 'string' || value.trim() === '')) {
|
|
52
|
+
throw new PaygateError(name)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The gateway service. `manage`, `bootstrap`, `owner`, `webhookService` and `stripe` are
|
|
59
|
+
* `PaymentGatewayOptions`; the options are checked here (`assertGatewayOptions`), and a managed,
|
|
60
|
+
* bootstrapping gateway also refuses to initialize when its webhook service is not declared in
|
|
61
|
+
* `cfg.services` (`WebhookSetupError('service:<alias>')`).
|
|
62
|
+
*/
|
|
63
|
+
export const makeGatewayService = (
|
|
64
|
+
alias: string = GATEWAY_SERVICE, opts: GatewayServiceOptions = {},
|
|
65
|
+
): GatewayService => {
|
|
66
|
+
assertGatewayOptions(opts)
|
|
67
|
+
const managed = opts.manage !== false
|
|
68
|
+
const bootstrap = opts.bootstrap ?? managed
|
|
69
|
+
const stripeOf = opts.stripe
|
|
70
|
+
?? (async (ctx: ApiContext): Promise<Stripe> => await paymentAccessOf(ctx).stripeClient())
|
|
71
|
+
// One estimate cache per gateway SERVICE instance, never module-level: several service
|
|
72
|
+
// instances (several tests, several deployments in one process) must never share hits.
|
|
73
|
+
const estimateCache = makeEstimateCache()
|
|
74
|
+
// Checkout plugins are seated per gateway instance, like the estimate cache.
|
|
75
|
+
const plugins = makeCheckoutPluginRegistry()
|
|
76
|
+
const service: GatewayService = createService<GatewayService>(alias, {
|
|
77
|
+
managed,
|
|
78
|
+
bootstrap,
|
|
79
|
+
get webhookService(): string {
|
|
80
|
+
return opts.webhookService ?? (service.assertCtx() as unknown as ApiContext).cfg.service
|
|
81
|
+
},
|
|
82
|
+
get owner(): string {
|
|
83
|
+
return opts.owner ?? (service.assertCtx() as unknown as ApiContext).cfg.service
|
|
84
|
+
},
|
|
85
|
+
stripe: stripeOf,
|
|
86
|
+
createLink: async (ctx, params) => managed
|
|
87
|
+
? await stripeCheckoutOf(ctx).createCheckoutLink(await stripeOf(ctx), params, plugins.list()) : unmanaged(),
|
|
88
|
+
use: plugin => { plugins.use(plugin) },
|
|
89
|
+
checkoutPlugins: () => plugins.list(),
|
|
90
|
+
amountPolicy: async (ctx, entityId, productSku, planSku) => {
|
|
91
|
+
const { plan } = await catalogueOf(ctx).consumablePlanOf(productSku, planSku)
|
|
92
|
+
if (plan.amountPolicy == null) throw new ProductError(`amount-policy:${plan.sku}`)
|
|
93
|
+
return await checkoutPluginsOf(ctx).narrowAmountFor(plugins.list(), {
|
|
94
|
+
entityId, productSku, planSku: (plan as PaymentPlan).sku, base: plan.amountPolicy, at: new Date(),
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
planPrices: async (ctx, productSku) => await productSyncOf(ctx).syncedPlanPrices(productSku),
|
|
98
|
+
portalLink: async (ctx, entityId, link) => managed
|
|
99
|
+
? await portalOf(ctx).createPortalLink(await stripeOf(ctx), entityId, link) : unmanaged(),
|
|
100
|
+
grantInternalPlan: async (ctx, entityId, planSku, grant) =>
|
|
101
|
+
await subscriptionCommitOf(ctx).grantInternalPlan(entityId, planSku, grant),
|
|
102
|
+
resyncSubscription: async (ctx, ref) => managed
|
|
103
|
+
? await stripeSubscriptionsOf(ctx).resyncStripeSubscription(await stripeOf(ctx), ref) : unmanaged(),
|
|
104
|
+
resyncAll: async ctx => managed
|
|
105
|
+
? await stripeSubscriptionsOf(ctx).resyncStripeSubscriptions(await stripeOf(ctx)) : unmanaged(),
|
|
106
|
+
estimatePrice: async (ctx, params) => managed
|
|
107
|
+
? await estimateOf(ctx).estimateStripePrice(await stripeOf(ctx), params, estimateCache) : unmanaged(),
|
|
16
108
|
}, service => async () => {
|
|
109
|
+
const ctx = service.assertCtx() as unknown as ApiContext
|
|
110
|
+
makePlanDeclarationsModel(ctx.cfg).assertPlans()
|
|
111
|
+
if (bootstrap) {
|
|
112
|
+
// Every boot bootstrap forms the webhook URL on this alias: an undeclared one fails the boot.
|
|
113
|
+
webhookOf(ctx).webhookRouteOf(opts.webhookService ?? ctx.cfg.service)
|
|
114
|
+
}
|
|
17
115
|
service.initialized = true
|
|
18
|
-
|
|
19
|
-
|
|
116
|
+
// The consumer-rights service is lazy (reachable while the application is wired): initialize it
|
|
117
|
+
// with the gateway, so its boot checks run at boot.
|
|
118
|
+
paymentAccessOf(ctx).consumerRightsOf()
|
|
119
|
+
if (bootstrap) {
|
|
120
|
+
void ctx.waitForInitialized().then(async () => {
|
|
121
|
+
await stripeBootstrapOf(ctx).bootstrapStripe(await stripeOf(ctx))
|
|
122
|
+
}).catch(error => { log.error('Stripe bootstrap failed', error) })
|
|
123
|
+
}
|
|
20
124
|
})
|
|
125
|
+
|
|
21
126
|
return service
|
|
22
127
|
}
|
|
23
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Register the payment resources, the catalogue service, the completion observer, the gateway, both
|
|
131
|
+
* gate services, the entitlement service and the consumer-rights records and service — each only
|
|
132
|
+
* when not registered yet.
|
|
133
|
+
*
|
|
134
|
+
* `manage: false` registers the same surface for a process that reads entitlements but never talks
|
|
135
|
+
* to Stripe. Several managed processes of one deployment share the Stripe rows through one `owner`
|
|
136
|
+
* and one `webhookService`; exactly one of them keeps `bootstrap` (the one receiving the webhook).
|
|
137
|
+
*/
|
|
24
138
|
export const appendPaymentGatewayService = <C extends Config, T extends Context<C>>(
|
|
25
|
-
ctx: T, opts?:
|
|
139
|
+
ctx: T, opts?: PaymentGatewayOptions,
|
|
26
140
|
): T => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
141
|
+
const makers = [
|
|
142
|
+
[RES_PAYGATE_CUSTOMER, makePaygateCustomerResource],
|
|
143
|
+
[RES_PAYMENT_SUBSCRIPTION, makeSubscriptionResource],
|
|
144
|
+
[RES_PAYMENT_FULFILLMENT, makeFulfillmentResource],
|
|
145
|
+
[RES_PAYMENT_WEBHOOK, makeWebhookResource],
|
|
146
|
+
[RES_PAYMENT_USAGE, makeUsageResource],
|
|
147
|
+
[RES_PAYMENT_USAGE_COUNTER, makeUsageCounterResource],
|
|
148
|
+
[RES_PAYMENT_FINGERPRINT, makeFingerprintResource],
|
|
149
|
+
] as const
|
|
150
|
+
for (const [alias, maker] of makers) {
|
|
151
|
+
if (!ctx.hasResource(alias)) {
|
|
152
|
+
ctx.registerResource(maker(opts?.dbAlias, opts?.serviceAlias) as never)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
30
155
|
if (!ctx.hasService(PAYMENT_SERVICE)) appendPaymentService(ctx as never)
|
|
31
156
|
appendCompletionObserver(ctx)
|
|
32
|
-
ctx.
|
|
33
|
-
|
|
157
|
+
if (!ctx.hasService(GATEWAY_SERVICE)) {
|
|
158
|
+
ctx.registerService(makeGatewayService(GATEWAY_SERVICE, {
|
|
159
|
+
manage: opts?.manage, bootstrap: opts?.bootstrap, owner: opts?.owner, webhookService: opts?.webhookService,
|
|
160
|
+
stripe: opts?.stripe,
|
|
161
|
+
}))
|
|
162
|
+
}
|
|
163
|
+
if (!ctx.hasService(ENTITLEMENT_GATE)) ctx.registerService(makeCapabilityGate())
|
|
164
|
+
if (!ctx.hasService(LIMIT_GATE)) ctx.registerService(makeLimitGate())
|
|
165
|
+
if (!ctx.hasService(ENTITLEMENT_SERVICE)) ctx.registerService(makeEntitlementService())
|
|
166
|
+
// The consumer-rights records and service, with this gateway's `manage` unless the application
|
|
167
|
+
// gave its own (before or after this call): the webhook writes purchases and locks, and an
|
|
168
|
+
// unmanaged process still reads and asserts consent.
|
|
169
|
+
registerConsumerRights(ctx, { manage: opts?.manage, dbAlias: opts?.dbAlias, serviceAlias: opts?.serviceAlias }, 'gateway')
|
|
170
|
+
|
|
34
171
|
return ctx
|
|
35
172
|
}
|
|
173
|
+
|
|
174
|
+
/** @deprecated compat:factory-refactor — use `stripeBootstrapOf(ctx).bootstrapStripe(…)` */
|
|
175
|
+
export const bootstrapStripe = async (
|
|
176
|
+
ctx: ApiContext, stripe: Stripe, opts: StripeBootstrapOptions = {},
|
|
177
|
+
): Promise<void> => { await stripeBootstrapOf(ctx).bootstrapStripe(stripe, opts) }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CommitOptions, PaymentSubscriptionRecord, PropagatedState, SubscriptionChange } from '../types.js'
|
|
2
|
+
|
|
3
|
+
/** How a subscription row's change is classified and keyed — pure, no store. */
|
|
4
|
+
export interface SubscriptionHelper {
|
|
5
|
+
/** The inputs classification compares. */
|
|
6
|
+
propagatedStateOf: (record: PaymentSubscriptionRecord, renewedInvoiceId?: string) => PropagatedState
|
|
7
|
+
/**
|
|
8
|
+
* What one subscription change means — the first rule that matches:
|
|
9
|
+
* `created` (first entitling state ever propagated), `canceled`, `paused`, `resumed`,
|
|
10
|
+
* `upgraded`/`downgraded` (plan change by rank; equal rank reads as an upgrade),
|
|
11
|
+
* `cancel-scheduled`, `cancel-undone`, `renewed` (once per invoice), `past-due`, `suspended`,
|
|
12
|
+
* `trial-ending`; otherwise nothing an observer is told about.
|
|
13
|
+
*/
|
|
14
|
+
classifySubscriptionChange: (
|
|
15
|
+
previous: PropagatedState | null, current: PaymentSubscriptionRecord, opts?: CommitOptions,
|
|
16
|
+
) => SubscriptionChange | null
|
|
17
|
+
/** The idempotency key a consumer keys the side effect of a change by. */
|
|
18
|
+
subscriptionEventKey: (record: PaymentSubscriptionRecord, change: SubscriptionChange, opts?: CommitOptions) => string
|
|
19
|
+
/** Whether a row's stored state changed in a field that matters. */
|
|
20
|
+
materiallyDiffers: (previous: PaymentSubscriptionRecord, next: PaymentSubscriptionRecord) => boolean
|
|
21
|
+
/** Whether a row's classification inputs differ from what was last propagated. */
|
|
22
|
+
stateDiffers: (state: PropagatedState, record: PaymentSubscriptionRecord) => boolean
|
|
23
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ENTITLING_STATUSES, SubscriptionStatus } from '@owlmeans/payment'
|
|
2
|
+
import type { PaymentSubscriptionRecord, PropagatedState, SubscriptionChange, CommitOptions } from './types.js'
|
|
3
|
+
import { ENDED, MATERIAL } from './consts.local.js'
|
|
4
|
+
import { paymentUtils } from './utils.js'
|
|
5
|
+
import type { SubscriptionHelper } from './subscription/types.js'
|
|
6
|
+
|
|
7
|
+
export const createSubscriptionHelper = (): SubscriptionHelper => {
|
|
8
|
+
const timeOf = (value: Date | null | undefined): number | null => value == null ? null : new Date(value).getTime()
|
|
9
|
+
|
|
10
|
+
const propagatedStateOf = (
|
|
11
|
+
record: PaymentSubscriptionRecord, renewedInvoiceId?: string,
|
|
12
|
+
): PropagatedState => paymentUtils.compact({
|
|
13
|
+
planSku: record.planSku,
|
|
14
|
+
rank: record.rank,
|
|
15
|
+
status: record.status,
|
|
16
|
+
cancelAtPeriodEnd: record.cancelAtPeriodEnd === true,
|
|
17
|
+
pausedAt: record.pausedAt ?? undefined,
|
|
18
|
+
renewedInvoiceId: renewedInvoiceId ?? undefined,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const classifySubscriptionChange = (
|
|
22
|
+
previous: PropagatedState | null, current: PaymentSubscriptionRecord, opts: CommitOptions = {},
|
|
23
|
+
): SubscriptionChange | null => {
|
|
24
|
+
const active = ENTITLING_STATUSES.includes(current.status)
|
|
25
|
+
if (previous == null) {
|
|
26
|
+
return active ? 'created' : null
|
|
27
|
+
}
|
|
28
|
+
if (ENDED.includes(current.status) && !ENDED.includes(previous.status)) {
|
|
29
|
+
return 'canceled'
|
|
30
|
+
}
|
|
31
|
+
if (current.pausedAt != null && previous.pausedAt == null) {
|
|
32
|
+
return 'paused'
|
|
33
|
+
}
|
|
34
|
+
if ((current.pausedAt == null && previous.pausedAt != null)
|
|
35
|
+
|| (previous.status === SubscriptionStatus.Suspended && active)) {
|
|
36
|
+
return 'resumed'
|
|
37
|
+
}
|
|
38
|
+
if (current.planSku !== previous.planSku) {
|
|
39
|
+
return current.rank < previous.rank ? 'downgraded' : 'upgraded'
|
|
40
|
+
}
|
|
41
|
+
if (previous.cancelAtPeriodEnd !== true && current.cancelAtPeriodEnd === true) {
|
|
42
|
+
return 'cancel-scheduled'
|
|
43
|
+
}
|
|
44
|
+
if (previous.cancelAtPeriodEnd === true && current.cancelAtPeriodEnd !== true) {
|
|
45
|
+
return 'cancel-undone'
|
|
46
|
+
}
|
|
47
|
+
if (opts.renewal === true && opts.invoiceId != null && opts.invoiceId !== previous.renewedInvoiceId) {
|
|
48
|
+
return 'renewed'
|
|
49
|
+
}
|
|
50
|
+
if (current.status === SubscriptionStatus.PastDue && previous.status !== SubscriptionStatus.PastDue) {
|
|
51
|
+
return 'past-due'
|
|
52
|
+
}
|
|
53
|
+
if (current.status === SubscriptionStatus.Suspended && previous.status !== SubscriptionStatus.Suspended) {
|
|
54
|
+
return 'suspended'
|
|
55
|
+
}
|
|
56
|
+
if (opts.trialEnding === true) {
|
|
57
|
+
return 'trial-ending'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const subscriptionEventKey = (
|
|
64
|
+
record: PaymentSubscriptionRecord, change: SubscriptionChange, opts: CommitOptions = {},
|
|
65
|
+
): string => {
|
|
66
|
+
const base = `subscription:${record.externalId}:${change}`
|
|
67
|
+
switch (change) {
|
|
68
|
+
case 'created':
|
|
69
|
+
return `${base}:${new Date(record.createdAt).toISOString()}`
|
|
70
|
+
case 'renewed':
|
|
71
|
+
return `${base}:${opts.invoiceId ?? record.latestInvoiceId ?? 'unknown'}`
|
|
72
|
+
case 'upgraded':
|
|
73
|
+
case 'downgraded':
|
|
74
|
+
return `${base}:${record.planSku}`
|
|
75
|
+
case 'trial-ending':
|
|
76
|
+
return `${base}:${record.trialEnd != null ? new Date(record.trialEnd).toISOString() : 'unknown'}`
|
|
77
|
+
default:
|
|
78
|
+
return `${base}:${opts.eventId ?? `sync-${new Date(record.updatedAt ?? Date.now()).toISOString()}`}`
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const sameValue = (left: unknown, right: unknown): boolean => {
|
|
83
|
+
if (left == null || right == null) {
|
|
84
|
+
return left == null && right == null
|
|
85
|
+
}
|
|
86
|
+
if (left instanceof Date || right instanceof Date) {
|
|
87
|
+
return timeOf(left as Date) === timeOf(right as Date)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return left === right
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const materiallyDiffers = (previous: PaymentSubscriptionRecord, next: PaymentSubscriptionRecord): boolean =>
|
|
94
|
+
MATERIAL.some(field => !sameValue(previous[field], next[field]))
|
|
95
|
+
|
|
96
|
+
const stateDiffers = (state: PropagatedState, record: PaymentSubscriptionRecord): boolean =>
|
|
97
|
+
state.planSku !== record.planSku || state.rank !== record.rank || state.status !== record.status
|
|
98
|
+
|| (state.cancelAtPeriodEnd === true) !== (record.cancelAtPeriodEnd === true)
|
|
99
|
+
|| timeOf(state.pausedAt) !== timeOf(record.pausedAt)
|
|
100
|
+
|
|
101
|
+
return { propagatedStateOf, classifySubscriptionChange, subscriptionEventKey, materiallyDiffers, stateDiffers }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const subscriptionHelper = createSubscriptionHelper()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import type { PlanPriceView } from '@owlmeans/payment'
|
|
3
|
+
|
|
4
|
+
/** The catalogue of a context as Stripe products and prices. */
|
|
5
|
+
export interface ProductSyncHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Synchronize every product sold through Stripe, and its Stripe-sold plans, to Stripe products and
|
|
8
|
+
* prices. A product whose declaration fingerprint is unchanged makes no paygate call. Free plans
|
|
9
|
+
* and plans sold through no Stripe gateway are never synchronized.
|
|
10
|
+
*
|
|
11
|
+
* The declared `PricingPolicy.tax.behavior` (absent by default, so a price's `tax_behavior` stays
|
|
12
|
+
* whatever it already was) is applied to a matching price only while it is `unspecified` — Stripe
|
|
13
|
+
* forbids changing a price once set to `exclusive` or `inclusive` — and to a fresh one on creation.
|
|
14
|
+
* A price carrying the OPPOSITE behavior is deactivated and replaced, same as any other mismatch.
|
|
15
|
+
*/
|
|
16
|
+
syncStripeProducts: (stripe: Stripe) => Promise<void>
|
|
17
|
+
/**
|
|
18
|
+
* The prices a product's plans are charged at, per currency, as the last sync stored them — no
|
|
19
|
+
* paygate call, so it works in an unmanaged process. One entry for each Price's default currency
|
|
20
|
+
* (`default: true`) and one per currency option.
|
|
21
|
+
*/
|
|
22
|
+
syncedPlanPrices: (productSku: string) => Promise<PlanPriceView[]>
|
|
23
|
+
/** `syncStripeProducts` with this context's own Stripe client (the gateway's, else the configured secret). */
|
|
24
|
+
syncPaymentProducts: () => Promise<void>
|
|
25
|
+
}
|