@owlmeans/server-payment 0.1.18-rc.8 → 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,245 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { makeSecurityHelper } from '@owlmeans/config';
|
|
3
|
+
import { normalizePath } from '@owlmeans/route';
|
|
4
|
+
import { WebhookSetupError, PaygateSignatureError } from '@owlmeans/payment';
|
|
5
|
+
import { memoHelper } from '@owlmeans/context';
|
|
6
|
+
import { STRIPE_OWNER_KEY, STRIPE_OWNER_VALUE, STRIPE_PAYGATE_ALIAS, WEBHOOK_EVENTS, STRIPE_SIGNATURE, } from '../consts.js';
|
|
7
|
+
import { log } from '../log.js';
|
|
8
|
+
import { paymentAccessOf } from '../access.js';
|
|
9
|
+
import { paymentUtils } from '../utils.js';
|
|
10
|
+
import { paymentGate } from '../protocol.js';
|
|
11
|
+
import { createEventHandler } from './events.js';
|
|
12
|
+
/** The path the webhook route answers for one paygate: `/<base>/webhook/<paygate>`. */
|
|
13
|
+
const webhookPathOf = (paygate) => '/' + normalizePath(normalizePath(paymentGate.base.route.route.path) + '/'
|
|
14
|
+
+ normalizePath(paymentGate.webhook.route.route.path).replace(':paygate', paygate));
|
|
15
|
+
/** A URL a paygate can deliver to: https on a public, dotted host name. */
|
|
16
|
+
const isDeliverableUrl = (url) => {
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = new URL(url);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const host = parsed.hostname.replace(/^\[|\]$/g, '').toLowerCase();
|
|
25
|
+
return parsed.protocol === 'https:' && host !== 'localhost' && host !== '127.0.0.1' && host !== '::1'
|
|
26
|
+
&& !host.endsWith('.local') && host.includes('.');
|
|
27
|
+
};
|
|
28
|
+
/** An operator's label on an endpoint this package created — never evidence of which deployment owns it. */
|
|
29
|
+
const ownerMetadata = (owner) => ({ [STRIPE_OWNER_KEY]: STRIPE_OWNER_VALUE, service: owner });
|
|
30
|
+
const hashOf = (url, apiVersion, events) => createHash('sha256').update(JSON.stringify({ url, apiVersion, events })).digest('hex');
|
|
31
|
+
export const makeWebhookHelper = (ctx) => {
|
|
32
|
+
const access = paymentAccessOf(ctx);
|
|
33
|
+
const webhookServiceOf = () => access.gatewayOf()?.webhookService ?? ctx.cfg.service;
|
|
34
|
+
const gatewayOwnerOf = () => access.gatewayOf()?.owner ?? ctx.cfg.service;
|
|
35
|
+
const webhookRouteOf = (alias = webhookServiceOf()) => {
|
|
36
|
+
const route = ctx.cfg.services?.[alias];
|
|
37
|
+
if (route == null) {
|
|
38
|
+
throw new WebhookSetupError(`service:${alias}`);
|
|
39
|
+
}
|
|
40
|
+
return route;
|
|
41
|
+
};
|
|
42
|
+
const webhookUrlOf = (paygate = STRIPE_PAYGATE_ALIAS) => makeSecurityHelper(ctx).makeUrl(webhookRouteOf(), webhookPathOf(paygate));
|
|
43
|
+
const listEndpoints = async (stripe) => {
|
|
44
|
+
const endpoints = [];
|
|
45
|
+
let startingAfter;
|
|
46
|
+
for (;;) {
|
|
47
|
+
const page = await stripe.webhookEndpoints.list({
|
|
48
|
+
limit: 100, ...(startingAfter != null ? { starting_after: startingAfter } : {}),
|
|
49
|
+
});
|
|
50
|
+
endpoints.push(...page.data);
|
|
51
|
+
if (!page.has_more || page.data.length === 0) {
|
|
52
|
+
return endpoints;
|
|
53
|
+
}
|
|
54
|
+
startingAfter = page.data[page.data.length - 1].id;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const dropEndpoint = async (stripe, id) => {
|
|
58
|
+
try {
|
|
59
|
+
await stripe.webhookEndpoints.del(id);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (!paymentUtils.isMissingObject(error)) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/** Field-encrypt the secret where the database is configured for it; store it plain otherwise. */
|
|
68
|
+
const sealed = async (row) => {
|
|
69
|
+
const resource = access.paymentWebhooks();
|
|
70
|
+
if (typeof resource.lock !== 'function') {
|
|
71
|
+
return row;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return await resource.lock(row, ['secret']);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return row;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const opened = async (row) => {
|
|
81
|
+
const resource = access.paymentWebhooks();
|
|
82
|
+
if (typeof resource.unlock !== 'function') {
|
|
83
|
+
return row.secret;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return (await resource.unlock(row, ['secret'])).secret;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return row.secret;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Delete the endpoints this deployment created at URLs it has left: each `payment-webhook` row of
|
|
94
|
+
* this paygate and owner at another URL drops the endpoint it names (one already gone is fine),
|
|
95
|
+
* then the row itself. `live` — the endpoint just put in place — is never dropped.
|
|
96
|
+
*/
|
|
97
|
+
const pruneFormerUrls = async (stripe, owner, url, live) => {
|
|
98
|
+
const resource = access.paymentWebhooks();
|
|
99
|
+
const { items } = await resource.list({ paygate: STRIPE_PAYGATE_ALIAS, service: owner, url: { $ne: url } }, { size: 0 });
|
|
100
|
+
for (const row of items) {
|
|
101
|
+
if (row.externalId !== live) {
|
|
102
|
+
await dropEndpoint(stripe, row.externalId);
|
|
103
|
+
}
|
|
104
|
+
await resource.delete(row.id);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const ensureWebhookEndpoint = async (stripe, opts = {}) => {
|
|
108
|
+
const url = webhookUrlOf();
|
|
109
|
+
if (!isDeliverableUrl(url)) {
|
|
110
|
+
log.info('Webhook endpoint not managed: not a public https URL', { url }, { event: 'payment.webhook.unmanaged' });
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const owner = gatewayOwnerOf();
|
|
114
|
+
const apiVersion = paymentUtils.apiVersionOf(stripe);
|
|
115
|
+
const events = [...WEBHOOK_EVENTS].sort();
|
|
116
|
+
const hash = hashOf(url, apiVersion, events);
|
|
117
|
+
const resource = access.paymentWebhooks();
|
|
118
|
+
const description = `owlmeans:${owner}`;
|
|
119
|
+
const metadata = ownerMetadata(owner);
|
|
120
|
+
const now = new Date();
|
|
121
|
+
let stored = await resource.load({ paygate: STRIPE_PAYGATE_ALIAS, service: owner, url });
|
|
122
|
+
if (stored != null && opts.force === true) {
|
|
123
|
+
try {
|
|
124
|
+
await stripe.webhookEndpoints.retrieve(stored.externalId);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (!paymentUtils.isMissingObject(error)) {
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
await resource.delete(stored.id);
|
|
131
|
+
stored = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (stored != null && stored.hash === hash && opts.force !== true) {
|
|
135
|
+
return stored;
|
|
136
|
+
}
|
|
137
|
+
let live = null;
|
|
138
|
+
if (stored != null && stored.apiVersion === apiVersion) {
|
|
139
|
+
try {
|
|
140
|
+
await stripe.webhookEndpoints.update(stored.externalId, {
|
|
141
|
+
url, enabled_events: events,
|
|
142
|
+
description, metadata, disabled: false,
|
|
143
|
+
});
|
|
144
|
+
live = await resource.update({ ...stored, events, hash, updatedAt: now });
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (!paymentUtils.isMissingObject(error)) {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (live == null) {
|
|
153
|
+
if (stored != null) {
|
|
154
|
+
await dropEndpoint(stripe, stored.externalId);
|
|
155
|
+
}
|
|
156
|
+
for (const endpoint of await listEndpoints(stripe)) {
|
|
157
|
+
if (endpoint.url === url) {
|
|
158
|
+
await dropEndpoint(stripe, endpoint.id);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const created = await stripe.webhookEndpoints.create({
|
|
162
|
+
url, enabled_events: events,
|
|
163
|
+
api_version: apiVersion, description, metadata,
|
|
164
|
+
});
|
|
165
|
+
if (created.secret == null || created.secret === '') {
|
|
166
|
+
throw new WebhookSetupError('secret-missing');
|
|
167
|
+
}
|
|
168
|
+
const row = await sealed({
|
|
169
|
+
paygate: STRIPE_PAYGATE_ALIAS, service: owner, url, externalId: created.id, secret: created.secret,
|
|
170
|
+
apiVersion, events, hash, createdAt: stored?.createdAt ?? now, updatedAt: now,
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
live = stored != null
|
|
174
|
+
? await resource.update({ ...row, id: stored.id })
|
|
175
|
+
: await resource.create(row);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (!paymentUtils.isDuplicateKey(error)) {
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
// Another replica persisted its endpoint meanwhile; the one created last is the live one.
|
|
182
|
+
const winner = await resource.load({ paygate: STRIPE_PAYGATE_ALIAS, service: owner, url });
|
|
183
|
+
live = await resource.update({ ...row, id: winner?.id });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
await pruneFormerUrls(stripe, owner, url, live.externalId);
|
|
187
|
+
return live;
|
|
188
|
+
};
|
|
189
|
+
const stripeWebhookSecrets = async () => {
|
|
190
|
+
const secrets = [];
|
|
191
|
+
const configured = await access.stripeConfig().then(config => config.webhook, () => undefined);
|
|
192
|
+
if (typeof configured === 'string' && configured.trim() !== '') {
|
|
193
|
+
secrets.push(configured.trim());
|
|
194
|
+
}
|
|
195
|
+
const stored = await access.paymentWebhooks().load({ paygate: STRIPE_PAYGATE_ALIAS, service: gatewayOwnerOf() }, { sort: [{ field: 'updatedAt', order: 'desc' }] });
|
|
196
|
+
if (stored != null) {
|
|
197
|
+
const secret = await opened(stored);
|
|
198
|
+
if (secret !== '' && !secrets.includes(secret)) {
|
|
199
|
+
secrets.push(secret);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return secrets;
|
|
203
|
+
};
|
|
204
|
+
const stripeWebhookSecret = async () => {
|
|
205
|
+
const [secret] = await stripeWebhookSecrets();
|
|
206
|
+
if (secret == null) {
|
|
207
|
+
throw new WebhookSetupError('secret');
|
|
208
|
+
}
|
|
209
|
+
return secret;
|
|
210
|
+
};
|
|
211
|
+
const handleStripeWebhook = async (stripe, request) => {
|
|
212
|
+
const typed = request;
|
|
213
|
+
const rawBody = typed.original?.rawBody ?? typed.rawBody;
|
|
214
|
+
const signature = typed.headers[STRIPE_SIGNATURE.toLowerCase()];
|
|
215
|
+
if (rawBody == null || typeof signature !== 'string')
|
|
216
|
+
throw new PaygateSignatureError();
|
|
217
|
+
const secrets = await stripeWebhookSecrets();
|
|
218
|
+
if (secrets.length === 0) {
|
|
219
|
+
throw new WebhookSetupError('secret');
|
|
220
|
+
}
|
|
221
|
+
let event = null;
|
|
222
|
+
for (const secret of secrets) {
|
|
223
|
+
try {
|
|
224
|
+
event = await stripe.webhooks.constructEventAsync(rawBody, signature, secret);
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
// Try the next secret; a signature none of them verifies is refused below.
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (event == null) {
|
|
232
|
+
throw new PaygateSignatureError();
|
|
233
|
+
}
|
|
234
|
+
await createEventHandler(ctx, stripe).process(event);
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
webhookServiceOf, gatewayOwnerOf, webhookRouteOf, webhookUrlOf, ensureWebhookEndpoint, stripeWebhookSecrets,
|
|
238
|
+
stripeWebhookSecret, handleStripeWebhook,
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
/** The webhook endpoint of a context — one per context. */
|
|
242
|
+
export const webhookOf = memoHelper.oncePer(makeWebhookHelper);
|
|
243
|
+
/** @deprecated compat:factory-refactor — use `webhookOf(ctx).webhookUrlOf(…)` */
|
|
244
|
+
export const webhookUrlOf = (ctx, paygate = STRIPE_PAYGATE_ALIAS) => webhookOf(ctx).webhookUrlOf(paygate);
|
|
245
|
+
//# sourceMappingURL=webhook-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-manager.js","sourceRoot":"","sources":["../../src/plugins/webhook-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAA2B,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EACL,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,cAAc,EAAE,gBAAgB,GAC7F,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD,uFAAuF;AACvF,MAAM,aAAa,GAAG,CAAC,OAAe,EAAU,EAAE,CAChD,GAAG,GAAG,aAAa,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,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EAAU,EAAE,CAC9F,SAAS,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Embedded gateway protocol tree; the alias strings are private adapter details. */
|
|
2
|
+
export declare const paymentGate: {
|
|
3
|
+
readonly base: import("@owlmeans/entrypoint").EntrypointProtocol<{}, undefined>;
|
|
4
|
+
/** Public: Stripe signs the raw body, so no application guard may sit in front of it. */
|
|
5
|
+
readonly webhook: import("@owlmeans/entrypoint").EntrypointProtocol<{
|
|
6
|
+
params: import("./types.js").PaygateParams;
|
|
7
|
+
}, undefined>;
|
|
8
|
+
/** Re-sync products, prices, the portal configuration and the webhook endpoint. */
|
|
9
|
+
readonly resync: import("@owlmeans/entrypoint").EntrypointProtocol<{}, import("./types.js").ResyncResult>;
|
|
10
|
+
/** Re-read every live paygate subscription and apply it as a webhook would. */
|
|
11
|
+
readonly resyncSubscriptions: import("@owlmeans/entrypoint").EntrypointProtocol<{}, import("./types.js").ResyncSubscriptionsResult>;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAQA,qFAAqF;AACrF,eAAO,MAAM,WAAW;;IAEtB,yFAAyF;;;;IAKzF,mFAAmF;;IAMnF,+EAA+E;;CAMvE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { contract, protocol, typed } from '@owlmeans/entrypoint';
|
|
2
|
+
import { backend, route, RouteMethod } from '@owlmeans/route';
|
|
3
|
+
import { GUARD_ED25519 } from '@owlmeans/server-app';
|
|
4
|
+
import { aliases } from './consts.local.js';
|
|
5
|
+
import { PaygateParamsSchema, ResyncResultSchema, ResyncSubscriptionsResultSchema } from './schemas.js';
|
|
6
|
+
const base = protocol(route(aliases.base, '/payment-gate', backend()), contract());
|
|
7
|
+
/** Embedded gateway protocol tree; the alias strings are private adapter details. */
|
|
8
|
+
export const paymentGate = {
|
|
9
|
+
base,
|
|
10
|
+
/** Public: Stripe signs the raw body, so no application guard may sit in front of it. */
|
|
11
|
+
webhook: protocol(route(aliases.webhook, '/webhook/:paygate', backend({ parent: base, method: RouteMethod.POST })), contract.request({ params: PaygateParamsSchema }, typed())),
|
|
12
|
+
/** Re-sync products, prices, the portal configuration and the webhook endpoint. */
|
|
13
|
+
resync: protocol(route(aliases.resync, '/resync', backend({ parent: base, method: RouteMethod.POST })), contract(ResyncResultSchema), { guards: GUARD_ED25519 }),
|
|
14
|
+
/** Re-read every live paygate subscription and apply it as a webhook would. */
|
|
15
|
+
resyncSubscriptions: protocol(route(aliases.resyncSubscriptions, '/resync-subscriptions', backend({ parent: base, method: RouteMethod.POST })), contract(ResyncSubscriptionsResultSchema), { guards: GUARD_ED25519 }),
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAA;AAEvG,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;AAElF,qFAAqF;AACrF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI;IACJ,yFAAyF;IACzF,OAAO,EAAE,QAAQ,CACf,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,EAChG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,mBAAmB,EAAE,EAAE,KAAK,EAAa,CAAC,CACtE;IACD,mFAAmF;IACnF,MAAM,EAAE,QAAQ,CACd,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,EACrF,QAAQ,CAAC,kBAAkB,CAAC,EAC5B,EAAE,MAAM,EAAE,aAAa,EAAE,CAC1B;IACD,+EAA+E;IAC/E,mBAAmB,EAAE,QAAQ,CAC3B,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,EAChH,QAAQ,CAAC,+BAA+B,CAAC,EACzC,EAAE,MAAM,EAAE,aAAa,EAAE,CAC1B;CACO,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EntitlementView } from '@owlmeans/payment';
|
|
2
|
+
import type { ReconcileAllOptions, ReconcileAllResult, ReconcileEntityOptions } from '../types.js';
|
|
3
|
+
/** The entitlement repair of a context: subscriptions, the free plan and the limit counters. */
|
|
4
|
+
export interface ReconcileHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Repair one entity: optionally re-read its paygate subscriptions, grant the free plan when it holds
|
|
7
|
+
* nothing entitling, recompute its limit counters from the ledger, and return its view.
|
|
8
|
+
*/
|
|
9
|
+
reconcileEntity: (entityId: string, opts?: ReconcileEntityOptions) => Promise<EntitlementView>;
|
|
10
|
+
/**
|
|
11
|
+
* Repair every entity the payment store knows, plus `entities`: counters from the ledger in one
|
|
12
|
+
* pass, then per entity the optional resync and the free-plan backfill. A failing entity is counted
|
|
13
|
+
* and logged, never fatal.
|
|
14
|
+
*/
|
|
15
|
+
reconcileAll: (opts?: ReconcileAllOptions) => Promise<ReconcileAllResult>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/reconcile/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAElG,gGAAgG;AAChG,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;IAC9F;;;;OAIG;IACH,YAAY,EAAE,CAAC,IAAI,CAAC,EAAE,mBAAmB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;CAC1E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/reconcile/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EntitlementView } from '@owlmeans/payment';
|
|
2
|
+
import type { Context as ApiContext } from '@owlmeans/server-api';
|
|
3
|
+
import type { ReconcileAllOptions, ReconcileAllResult, ReconcileEntityOptions } from './types.js';
|
|
4
|
+
import type { ReconcileHelper } from './reconcile/types.js';
|
|
5
|
+
export declare const makeReconcileHelper: (ctx: ApiContext) => ReconcileHelper;
|
|
6
|
+
/** The entitlement repair of a context — one per context. */
|
|
7
|
+
export declare const reconcileOf: (target: ApiContext<import("@owlmeans/server-api").Config>) => ReconcileHelper;
|
|
8
|
+
/** @deprecated compat:factory-refactor — use `reconcileOf(ctx).reconcileEntity(…)` */
|
|
9
|
+
export declare const reconcileEntity: (ctx: ApiContext, entityId: string, opts?: ReconcileEntityOptions) => Promise<EntitlementView>;
|
|
10
|
+
/** @deprecated compat:factory-refactor — use `reconcileOf(ctx).reconcileAll(…)` */
|
|
11
|
+
export declare const reconcileAll: (ctx: ApiContext, opts?: ReconcileAllOptions) => Promise<ReconcileAllResult>;
|
|
12
|
+
//# sourceMappingURL=reconcile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../src/reconcile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAIjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,eAAO,MAAM,mBAAmB,QAAS,UAAU,KAAG,eAuFrD,CAAA;AAED,6DAA6D;AAC7D,eAAO,MAAM,WAAW,gFAA0C,CAAA;AAElE,sFAAsF;AACtF,eAAO,MAAM,eAAe,QACrB,UAAU,YAAY,MAAM,SAAQ,sBAAsB,KAC9D,OAAO,CAAC,eAAe,CAA2D,CAAA;AAErF,mFAAmF;AACnF,eAAO,MAAM,YAAY,QAClB,UAAU,SAAQ,mBAAmB,KACzC,OAAO,CAAC,kBAAkB,CAA8C,CAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { PlanRequired } from '@owlmeans/payment';
|
|
2
|
+
import { memoHelper } from '@owlmeans/context';
|
|
3
|
+
import { log } from './log.js';
|
|
4
|
+
import { paymentAccessOf } from './access.js';
|
|
5
|
+
export const makeReconcileHelper = (ctx) => {
|
|
6
|
+
const access = paymentAccessOf(ctx);
|
|
7
|
+
/** Grant the free plan when the entity holds no entitling subscription. @returns whether it granted */
|
|
8
|
+
const backfillFreePlan = async (entityId, freePlanSku) => {
|
|
9
|
+
try {
|
|
10
|
+
const { subscription } = await access.entitlements().effectivePlan(entityId);
|
|
11
|
+
if (subscription != null) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (!(error instanceof PlanRequired)) {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
await access.gateway().grantInternalPlan(ctx, entityId, freePlanSku);
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
const resyncEntity = async (entityId) => {
|
|
24
|
+
const service = access.gateway();
|
|
25
|
+
if (!service.managed) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
await service.resyncSubscription(ctx, { entityId });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
log.error('Reconcile: subscription resync failed', { entityId, error });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const reconcileEntity = async (entityId, opts = {}) => {
|
|
36
|
+
if (opts.resync === true) {
|
|
37
|
+
await resyncEntity(entityId);
|
|
38
|
+
}
|
|
39
|
+
if (opts.freePlanSku != null) {
|
|
40
|
+
await backfillFreePlan(entityId, opts.freePlanSku);
|
|
41
|
+
}
|
|
42
|
+
await access.entitlements().reconcileCounters(entityId);
|
|
43
|
+
return await access.entitlements().entitlements(entityId);
|
|
44
|
+
};
|
|
45
|
+
const knownEntities = async () => {
|
|
46
|
+
const ids = new Set();
|
|
47
|
+
for (const resource of [access.subscriptions(), access.usageEvents()]) {
|
|
48
|
+
for (const id of await resource.collection.distinct('entityId', {})) {
|
|
49
|
+
if (typeof id === 'string' && id !== '') {
|
|
50
|
+
ids.add(id);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return ids;
|
|
55
|
+
};
|
|
56
|
+
const reconcileAll = async (opts = {}) => {
|
|
57
|
+
const ids = await knownEntities();
|
|
58
|
+
if (opts.entities != null) {
|
|
59
|
+
for await (const id of opts.entities) {
|
|
60
|
+
ids.add(id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const result = { entities: ids.size, granted: 0, counters: 0, repaired: 0, failed: 0 };
|
|
64
|
+
for (const entityId of ids) {
|
|
65
|
+
try {
|
|
66
|
+
if (opts.resync === true) {
|
|
67
|
+
await resyncEntity(entityId);
|
|
68
|
+
}
|
|
69
|
+
if (opts.freePlanSku != null && await backfillFreePlan(entityId, opts.freePlanSku)) {
|
|
70
|
+
result.granted++;
|
|
71
|
+
}
|
|
72
|
+
const counters = await access.entitlements().reconcileCounters(entityId);
|
|
73
|
+
result.counters += counters.counters;
|
|
74
|
+
result.repaired += counters.repaired;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
result.failed++;
|
|
78
|
+
log.error('Reconcile of an entity failed', { entityId, error });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
return { reconcileEntity, reconcileAll };
|
|
84
|
+
};
|
|
85
|
+
/** The entitlement repair of a context — one per context. */
|
|
86
|
+
export const reconcileOf = memoHelper.oncePer(makeReconcileHelper);
|
|
87
|
+
/** @deprecated compat:factory-refactor — use `reconcileOf(ctx).reconcileEntity(…)` */
|
|
88
|
+
export const reconcileEntity = async (ctx, entityId, opts = {}) => await reconcileOf(ctx).reconcileEntity(entityId, opts);
|
|
89
|
+
/** @deprecated compat:factory-refactor — use `reconcileOf(ctx).reconcileAll(…)` */
|
|
90
|
+
export const reconcileAll = async (ctx, opts = {}) => await reconcileOf(ctx).reconcileAll(opts);
|
|
91
|
+
//# sourceMappingURL=reconcile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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;IAED,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,CAAA;AAC1C,CAAC,CAAA;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAElE,sFAAsF;AACtF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,GAAe,EAAE,QAAgB,EAAE,IAAI,GAA2B,EAAE,EAC1C,EAAE,CAAC,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AAErF,mFAAmF;AACnF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,GAAe,EAAE,IAAI,GAAwB,EAAE,EAClB,EAAE,CAAC,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA"}
|
package/build/resource.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { ResourceMaker } from '@owlmeans/resource';
|
|
2
|
-
import type { FingerprintRecord, FingerprintResource, PaygateCustomerRecord, PaygateCustomerResource, PaymentSubscriptionRecord, PaymentSubscriptionResource } from './types.js';
|
|
2
|
+
import type { BillingProfileRecord, BillingProfileResource, ConsumerConsentRecord, ConsumerConsentResource, ConsumerDeclarationRecord, ConsumerDeclarationResource, ConsumerEventRecord, ConsumerEventResource, FingerprintRecord, FingerprintResource, PaygateCustomerRecord, PaygateCustomerResource, PaymentFulfillmentRecord, PaymentFulfillmentResource, PaymentSubscriptionRecord, PaymentSubscriptionResource, PaymentUsageCounterRecord, PaymentUsageCounterResource, PaymentUsageRecord, PaymentUsageResource, PaymentWebhookRecord, PaymentWebhookResource, PurchaseRecord, PurchaseResource } from './types.js';
|
|
3
3
|
export declare const makePaygateCustomerResource: ResourceMaker<PaygateCustomerRecord, PaygateCustomerResource>;
|
|
4
4
|
export declare const makeSubscriptionResource: ResourceMaker<PaymentSubscriptionRecord, PaymentSubscriptionResource>;
|
|
5
|
+
export declare const makeFulfillmentResource: ResourceMaker<PaymentFulfillmentRecord, PaymentFulfillmentResource>;
|
|
6
|
+
export declare const makeWebhookResource: ResourceMaker<PaymentWebhookRecord, PaymentWebhookResource>;
|
|
7
|
+
export declare const makeUsageResource: ResourceMaker<PaymentUsageRecord, PaymentUsageResource>;
|
|
8
|
+
export declare const makeUsageCounterResource: ResourceMaker<PaymentUsageCounterRecord, PaymentUsageCounterResource>;
|
|
5
9
|
export declare const makeFingerprintResource: ResourceMaker<FingerprintRecord, FingerprintResource>;
|
|
10
|
+
export declare const makeBillingProfileResource: ResourceMaker<BillingProfileRecord, BillingProfileResource>;
|
|
11
|
+
export declare const makePurchaseResource: ResourceMaker<PurchaseRecord, PurchaseResource>;
|
|
12
|
+
export declare const makeConsumerConsentResource: ResourceMaker<ConsumerConsentRecord, ConsumerConsentResource>;
|
|
13
|
+
export declare const makeConsumerDeclarationResource: ResourceMaker<ConsumerDeclarationRecord, ConsumerDeclarationResource>;
|
|
14
|
+
export declare const makeConsumerEventResource: ResourceMaker<ConsumerEventRecord, ConsumerEventResource>;
|
|
15
|
+
/** The consumer-rights resources, alias → maker — registered by the gateway, each only when absent. */
|
|
16
|
+
export declare const CONSUMER_RIGHTS_RESOURCE_MAKERS: readonly [readonly ["payment-billing-profile", ResourceMaker<BillingProfileRecord, BillingProfileResource>], readonly ["payment-purchase", ResourceMaker<PurchaseRecord, PurchaseResource>], readonly ["payment-consumer-consent", ResourceMaker<ConsumerConsentRecord, ConsumerConsentResource>], readonly ["payment-consumer-declaration", ResourceMaker<ConsumerDeclarationRecord, ConsumerDeclarationResource>], readonly ["payment-consumer-event", ResourceMaker<ConsumerEventRecord, ConsumerEventResource>]];
|
|
6
17
|
//# sourceMappingURL=resource.d.ts.map
|
package/build/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA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oB,EAAE,aAAa,CAAC,cAAc,EAAE,gBAAgB,CAkBhF,CAAA;AAED,eAAO,MAAM,2BAA2B,EAAE,aAAa,CAAC,qBAAqB,EAAE,uBAAuB,CAUrG,CAAA;AAED,eAAO,MAAM,+BAA+B,EAAE,aAAa,CAAC,yBAAyB,EAAE,2BAA2B,CAWjH,CAAA;AAED,eAAO,MAAM,yBAAyB,EAAE,aAAa,CAAC,mBAAmB,EAAE,qBAAqB,CAW/F,CAAA;AAED,uGAAuG;AACvG,eAAO,MAAM,+BAA+B,sfAMlC,CAAA"}
|
package/build/resource.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeMongoResource } from '@owlmeans/mongo-resource';
|
|
2
|
-
import { RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_SUBSCRIPTION } from './consts.js';
|
|
3
|
-
import {
|
|
2
|
+
import { RES_BILLING_PROFILE, RES_CONSUMER_CONSENT, RES_CONSUMER_DECLARATION, RES_CONSUMER_EVENT, RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT, RES_PAYMENT_PURCHASE, RES_PAYMENT_SUBSCRIPTION, RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK, } from './consts.js';
|
|
3
|
+
import { BillingProfileSchema, ConsumerConsentSchema, ConsumerDeclarationSchema, PaygateCustomerSchema, PaymentFulfillmentSchema, PaymentSubscriptionSchema, PaymentUsageCounterSchema, PaymentUsageSchema, PaymentWebhookSchema, PurchaseSchema, ConsumerEventSchema, FingerprintSchema, } from './schemas.js';
|
|
4
4
|
export const makePaygateCustomerResource = (dbAlias, serviceAlias) => {
|
|
5
5
|
const resource = makeMongoResource(RES_PAYGATE_CUSTOMER, dbAlias, serviceAlias);
|
|
6
6
|
resource.loadByPgId = async (externalId, paygate) => await resource.load({ externalId, paygate });
|
|
@@ -14,11 +14,45 @@ export const makePaygateCustomerResource = (dbAlias, serviceAlias) => {
|
|
|
14
14
|
export const makeSubscriptionResource = (dbAlias, serviceAlias) => {
|
|
15
15
|
const resource = makeMongoResource(RES_PAYMENT_SUBSCRIPTION, dbAlias, serviceAlias);
|
|
16
16
|
resource.byExternalId = async (externalId, paygate) => await resource.load({ externalId, paygate });
|
|
17
|
+
resource.byItemId = async (itemId, paygate) => await resource.load({ itemId, paygate });
|
|
17
18
|
resource.schema = PaymentSubscriptionSchema;
|
|
18
|
-
resource.index('
|
|
19
|
-
resource.index('
|
|
20
|
-
resource.index('
|
|
21
|
-
resource.index('
|
|
19
|
+
resource.index('external', { paygate: 1, externalId: 1 }, { unique: true });
|
|
20
|
+
resource.index('entityStatusRank', { entityId: 1, status: 1, rank: -1 });
|
|
21
|
+
resource.index('entityPlan', { entityId: 1, planSku: 1 });
|
|
22
|
+
resource.index('customer', { paygate: 1, customerId: 1 });
|
|
23
|
+
resource.index('item', { paygate: 1, itemId: 1 }, { sparse: true });
|
|
24
|
+
resource.index('statusUpdated', { paygate: 1, status: 1, updatedAt: 1 });
|
|
25
|
+
return resource;
|
|
26
|
+
};
|
|
27
|
+
export const makeFulfillmentResource = (dbAlias, serviceAlias) => {
|
|
28
|
+
const resource = makeMongoResource(RES_PAYMENT_FULFILLMENT, dbAlias, serviceAlias);
|
|
29
|
+
resource.byExternalId = async (externalId, paygate) => await resource.load({ externalId, paygate });
|
|
30
|
+
resource.schema = PaymentFulfillmentSchema;
|
|
31
|
+
resource.index('external', { paygate: 1, externalId: 1 }, { unique: true });
|
|
32
|
+
resource.index('paymentIntent', { paygate: 1, paymentIntentId: 1 }, { sparse: true });
|
|
33
|
+
resource.index('charge', { paygate: 1, chargeId: 1 }, { sparse: true });
|
|
34
|
+
resource.index('entityCreated', { entityId: 1, createdAt: -1 });
|
|
35
|
+
return resource;
|
|
36
|
+
};
|
|
37
|
+
export const makeWebhookResource = (dbAlias, serviceAlias) => {
|
|
38
|
+
const resource = makeMongoResource(RES_PAYMENT_WEBHOOK, dbAlias, serviceAlias);
|
|
39
|
+
resource.schema = PaymentWebhookSchema;
|
|
40
|
+
resource.index('endpoint', { paygate: 1, service: 1, url: 1 }, { unique: true });
|
|
41
|
+
return resource;
|
|
42
|
+
};
|
|
43
|
+
export const makeUsageResource = (dbAlias, serviceAlias) => {
|
|
44
|
+
const resource = makeMongoResource(RES_PAYMENT_USAGE, dbAlias, serviceAlias);
|
|
45
|
+
resource.schema = PaymentUsageSchema;
|
|
46
|
+
resource.index('event', { entityId: 1, limitKey: 1, eventKey: 1 }, { unique: true });
|
|
47
|
+
resource.index('window', { entityId: 1, limitKey: 1, window: 1 });
|
|
48
|
+
resource.index('ref', { entityId: 1, limitKey: 1, ref: 1 }, { sparse: true });
|
|
49
|
+
resource.index('entityCreated', { entityId: 1, createdAt: -1 });
|
|
50
|
+
return resource;
|
|
51
|
+
};
|
|
52
|
+
export const makeUsageCounterResource = (dbAlias, serviceAlias) => {
|
|
53
|
+
const resource = makeMongoResource(RES_PAYMENT_USAGE_COUNTER, dbAlias, serviceAlias);
|
|
54
|
+
resource.schema = PaymentUsageCounterSchema;
|
|
55
|
+
resource.index('window', { entityId: 1, limitKey: 1, window: 1 }, { unique: true });
|
|
22
56
|
return resource;
|
|
23
57
|
};
|
|
24
58
|
export const makeFingerprintResource = (dbAlias, serviceAlias) => {
|
|
@@ -29,4 +63,61 @@ export const makeFingerprintResource = (dbAlias, serviceAlias) => {
|
|
|
29
63
|
resource.index('sku', { sku: 1 }, { unique: true });
|
|
30
64
|
return resource;
|
|
31
65
|
};
|
|
66
|
+
export const makeBillingProfileResource = (dbAlias, serviceAlias) => {
|
|
67
|
+
const resource = makeMongoResource(RES_BILLING_PROFILE, dbAlias, serviceAlias);
|
|
68
|
+
resource.byEntity = async (entityId) => await resource.load({ entityId });
|
|
69
|
+
resource.schema = BillingProfileSchema;
|
|
70
|
+
// One profile per organization: the unique index is what makes the first lock the only one.
|
|
71
|
+
resource.index('entity', { entityId: 1 }, { unique: true });
|
|
72
|
+
resource.index('customer', { paygate: 1, customerId: 1 }, { sparse: true });
|
|
73
|
+
return resource;
|
|
74
|
+
};
|
|
75
|
+
export const makePurchaseResource = (dbAlias, serviceAlias) => {
|
|
76
|
+
const resource = makeMongoResource(RES_PAYMENT_PURCHASE, dbAlias, serviceAlias);
|
|
77
|
+
resource.byPurchaseId = async (purchaseId) => await resource.load({ purchaseId });
|
|
78
|
+
resource.schema = PurchaseSchema;
|
|
79
|
+
resource.index('purchase', { purchaseId: 1 }, { unique: true });
|
|
80
|
+
resource.index('contract', { contractRef: 1 }, { unique: true });
|
|
81
|
+
resource.index('entityDeadline', { entityId: 1, deadline: -1 });
|
|
82
|
+
resource.index('entityPurchased', { entityId: 1, purchasedAt: -1 });
|
|
83
|
+
// Single-field on purpose: a compound sparse index still indexes rows missing only `sessionId`
|
|
84
|
+
// (subscription purchases before their checkout is captured), and unique would collide on them.
|
|
85
|
+
resource.index('session', { sessionId: 1 }, { unique: true, sparse: true });
|
|
86
|
+
resource.index('subscription', { paygate: 1, subscriptionId: 1 }, { sparse: true });
|
|
87
|
+
resource.index('invoice', { invoiceId: 1 }, { sparse: true });
|
|
88
|
+
resource.index('invoiceNumber', { invoiceNumber: 1 }, { sparse: true });
|
|
89
|
+
resource.index('paymentIntent', { paygate: 1, paymentIntentId: 1 }, { sparse: true });
|
|
90
|
+
return resource;
|
|
91
|
+
};
|
|
92
|
+
export const makeConsumerConsentResource = (dbAlias, serviceAlias) => {
|
|
93
|
+
const resource = makeMongoResource(RES_CONSUMER_CONSENT, dbAlias, serviceAlias);
|
|
94
|
+
resource.schema = ConsumerConsentSchema;
|
|
95
|
+
resource.index('entityDecided', { entityId: 1, decidedAt: -1 });
|
|
96
|
+
resource.index('kindPlan', { kind: 1, entityId: 1, planSku: 1, decidedAt: -1 });
|
|
97
|
+
return resource;
|
|
98
|
+
};
|
|
99
|
+
export const makeConsumerDeclarationResource = (dbAlias, serviceAlias) => {
|
|
100
|
+
const resource = makeMongoResource(RES_CONSUMER_DECLARATION, dbAlias, serviceAlias);
|
|
101
|
+
resource.schema = ConsumerDeclarationSchema;
|
|
102
|
+
resource.index('kindReceived', { kind: 1, receivedAt: -1 });
|
|
103
|
+
resource.index('entityReceived', { entityId: 1, receivedAt: -1 }, { sparse: true });
|
|
104
|
+
resource.index('purchase', { purchaseId: 1 }, { sparse: true });
|
|
105
|
+
return resource;
|
|
106
|
+
};
|
|
107
|
+
export const makeConsumerEventResource = (dbAlias, serviceAlias) => {
|
|
108
|
+
const resource = makeMongoResource(RES_CONSUMER_EVENT, dbAlias, serviceAlias);
|
|
109
|
+
resource.schema = ConsumerEventSchema;
|
|
110
|
+
resource.index('record', { recordId: 1, at: 1 });
|
|
111
|
+
resource.index('entityAt', { entityId: 1, at: -1 }, { sparse: true });
|
|
112
|
+
resource.index('actionOk', { action: 1, ok: 1, at: 1 });
|
|
113
|
+
return resource;
|
|
114
|
+
};
|
|
115
|
+
/** The consumer-rights resources, alias → maker — registered by the gateway, each only when absent. */
|
|
116
|
+
export const CONSUMER_RIGHTS_RESOURCE_MAKERS = [
|
|
117
|
+
[RES_BILLING_PROFILE, makeBillingProfileResource],
|
|
118
|
+
[RES_PAYMENT_PURCHASE, makePurchaseResource],
|
|
119
|
+
[RES_CONSUMER_CONSENT, makeConsumerConsentResource],
|
|
120
|
+
[RES_CONSUMER_DECLARATION, makeConsumerDeclarationResource],
|
|
121
|
+
[RES_CONSUMER_EVENT, makeConsumerEventResource],
|
|
122
|
+
];
|
|
32
123
|
//# sourceMappingURL=resource.js.map
|