@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/protocol.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
|
|
7
|
+
const base = protocol(route(aliases.base, '/payment-gate', backend()), contract())
|
|
8
|
+
|
|
9
|
+
/** Embedded gateway protocol tree; the alias strings are private adapter details. */
|
|
10
|
+
export const paymentGate = {
|
|
11
|
+
base,
|
|
12
|
+
/** Public: Stripe signs the raw body, so no application guard may sit in front of it. */
|
|
13
|
+
webhook: protocol(
|
|
14
|
+
route(aliases.webhook, '/webhook/:paygate', backend({ parent: base, method: RouteMethod.POST })),
|
|
15
|
+
contract.request({ params: PaygateParamsSchema }, typed<undefined>()),
|
|
16
|
+
),
|
|
17
|
+
/** Re-sync products, prices, the portal configuration and the webhook endpoint. */
|
|
18
|
+
resync: protocol(
|
|
19
|
+
route(aliases.resync, '/resync', backend({ parent: base, method: RouteMethod.POST })),
|
|
20
|
+
contract(ResyncResultSchema),
|
|
21
|
+
{ guards: GUARD_ED25519 },
|
|
22
|
+
),
|
|
23
|
+
/** Re-read every live paygate subscription and apply it as a webhook would. */
|
|
24
|
+
resyncSubscriptions: protocol(
|
|
25
|
+
route(aliases.resyncSubscriptions, '/resync-subscriptions', backend({ parent: base, method: RouteMethod.POST })),
|
|
26
|
+
contract(ResyncSubscriptionsResultSchema),
|
|
27
|
+
{ guards: GUARD_ED25519 },
|
|
28
|
+
),
|
|
29
|
+
} as const
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EntitlementView } from '@owlmeans/payment'
|
|
2
|
+
import type { ReconcileAllOptions, ReconcileAllResult, ReconcileEntityOptions } from '../types.js'
|
|
3
|
+
|
|
4
|
+
/** The entitlement repair of a context: subscriptions, the free plan and the limit counters. */
|
|
5
|
+
export interface ReconcileHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Repair one entity: optionally re-read its paygate subscriptions, grant the free plan when it holds
|
|
8
|
+
* nothing entitling, recompute its limit counters from the ledger, and return its view.
|
|
9
|
+
*/
|
|
10
|
+
reconcileEntity: (entityId: string, opts?: ReconcileEntityOptions) => Promise<EntitlementView>
|
|
11
|
+
/**
|
|
12
|
+
* Repair every entity the payment store knows, plus `entities`: counters from the ledger in one
|
|
13
|
+
* pass, then per entity the optional resync and the free-plan backfill. A failing entity is counted
|
|
14
|
+
* and logged, never fatal.
|
|
15
|
+
*/
|
|
16
|
+
reconcileAll: (opts?: ReconcileAllOptions) => Promise<ReconcileAllResult>
|
|
17
|
+
}
|
package/src/reconcile.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { PlanRequired, type EntitlementView } from '@owlmeans/payment'
|
|
2
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
3
|
+
import { memoHelper } from '@owlmeans/context'
|
|
4
|
+
import type { ReconcileAllOptions, ReconcileAllResult, ReconcileEntityOptions } from './types.js'
|
|
5
|
+
import { log } from './log.js'
|
|
6
|
+
import type { Distinct } from './types.local.js'
|
|
7
|
+
import { paymentAccessOf } from './access.js'
|
|
8
|
+
import type { ReconcileHelper } from './reconcile/types.js'
|
|
9
|
+
|
|
10
|
+
export const makeReconcileHelper = (ctx: ApiContext): ReconcileHelper => {
|
|
11
|
+
const access = paymentAccessOf(ctx)
|
|
12
|
+
|
|
13
|
+
/** Grant the free plan when the entity holds no entitling subscription. @returns whether it granted */
|
|
14
|
+
const backfillFreePlan = async (entityId: string, freePlanSku: string): Promise<boolean> => {
|
|
15
|
+
try {
|
|
16
|
+
const { subscription } = await access.entitlements().effectivePlan(entityId)
|
|
17
|
+
if (subscription != null) {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (!(error instanceof PlanRequired)) {
|
|
22
|
+
throw error
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
await access.gateway().grantInternalPlan(ctx, entityId, freePlanSku)
|
|
26
|
+
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const resyncEntity = async (entityId: string): Promise<void> => {
|
|
31
|
+
const service = access.gateway()
|
|
32
|
+
if (!service.managed) {
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
await service.resyncSubscription(ctx, { entityId })
|
|
37
|
+
} catch (error) {
|
|
38
|
+
log.error('Reconcile: subscription resync failed', { entityId, error })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const reconcileEntity = async (entityId: string, opts: ReconcileEntityOptions = {}): Promise<EntitlementView> => {
|
|
43
|
+
if (opts.resync === true) {
|
|
44
|
+
await resyncEntity(entityId)
|
|
45
|
+
}
|
|
46
|
+
if (opts.freePlanSku != null) {
|
|
47
|
+
await backfillFreePlan(entityId, opts.freePlanSku)
|
|
48
|
+
}
|
|
49
|
+
await access.entitlements().reconcileCounters(entityId)
|
|
50
|
+
|
|
51
|
+
return await access.entitlements().entitlements(entityId)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const knownEntities = async (): Promise<Set<string>> => {
|
|
55
|
+
const ids = new Set<string>()
|
|
56
|
+
for (const resource of [access.subscriptions(), access.usageEvents()] as unknown as Distinct[]) {
|
|
57
|
+
for (const id of await resource.collection.distinct('entityId', {})) {
|
|
58
|
+
if (typeof id === 'string' && id !== '') {
|
|
59
|
+
ids.add(id)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return ids
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const reconcileAll = async (opts: ReconcileAllOptions = {}): Promise<ReconcileAllResult> => {
|
|
68
|
+
const ids = await knownEntities()
|
|
69
|
+
if (opts.entities != null) {
|
|
70
|
+
for await (const id of opts.entities) {
|
|
71
|
+
ids.add(id)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const result: ReconcileAllResult = { entities: ids.size, granted: 0, counters: 0, repaired: 0, failed: 0 }
|
|
76
|
+
for (const entityId of ids) {
|
|
77
|
+
try {
|
|
78
|
+
if (opts.resync === true) {
|
|
79
|
+
await resyncEntity(entityId)
|
|
80
|
+
}
|
|
81
|
+
if (opts.freePlanSku != null && await backfillFreePlan(entityId, opts.freePlanSku)) {
|
|
82
|
+
result.granted++
|
|
83
|
+
}
|
|
84
|
+
const counters = await access.entitlements().reconcileCounters(entityId)
|
|
85
|
+
result.counters += counters.counters
|
|
86
|
+
result.repaired += counters.repaired
|
|
87
|
+
} catch (error) {
|
|
88
|
+
result.failed++
|
|
89
|
+
log.error('Reconcile of an entity failed', { entityId, error })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return result
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { reconcileEntity, reconcileAll }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The entitlement repair of a context — one per context. */
|
|
100
|
+
export const reconcileOf = memoHelper.oncePer(makeReconcileHelper)
|
|
101
|
+
|
|
102
|
+
/** @deprecated compat:factory-refactor — use `reconcileOf(ctx).reconcileEntity(…)` */
|
|
103
|
+
export const reconcileEntity = async (
|
|
104
|
+
ctx: ApiContext, entityId: string, opts: ReconcileEntityOptions = {},
|
|
105
|
+
): Promise<EntitlementView> => await reconcileOf(ctx).reconcileEntity(entityId, opts)
|
|
106
|
+
|
|
107
|
+
/** @deprecated compat:factory-refactor — use `reconcileOf(ctx).reconcileAll(…)` */
|
|
108
|
+
export const reconcileAll = async (
|
|
109
|
+
ctx: ApiContext, opts: ReconcileAllOptions = {},
|
|
110
|
+
): Promise<ReconcileAllResult> => await reconcileOf(ctx).reconcileAll(opts)
|
package/src/resource.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import type { ResourceMaker } from '@owlmeans/resource'
|
|
2
2
|
import { makeMongoResource } from '@owlmeans/mongo-resource'
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
RES_BILLING_PROFILE, RES_CONSUMER_CONSENT, RES_CONSUMER_DECLARATION, RES_CONSUMER_EVENT, RES_PAYGATE_CUSTOMER,
|
|
5
|
+
RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT, RES_PAYMENT_PURCHASE, RES_PAYMENT_SUBSCRIPTION,
|
|
6
|
+
RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK,
|
|
7
|
+
} from './consts.js'
|
|
8
|
+
import {
|
|
9
|
+
BillingProfileSchema, ConsumerConsentSchema, ConsumerDeclarationSchema, PaygateCustomerSchema,
|
|
10
|
+
PaymentFulfillmentSchema, PaymentSubscriptionSchema, PaymentUsageCounterSchema, PaymentUsageSchema,
|
|
11
|
+
PaymentWebhookSchema, PurchaseSchema, ConsumerEventSchema, FingerprintSchema,
|
|
12
|
+
} from './schemas.js'
|
|
5
13
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
BillingProfileRecord, BillingProfileResource, ConsumerConsentRecord, ConsumerConsentResource,
|
|
15
|
+
ConsumerDeclarationRecord, ConsumerDeclarationResource, ConsumerEventRecord, ConsumerEventResource,
|
|
16
|
+
FingerprintRecord, FingerprintResource, PaygateCustomerRecord, PaygateCustomerResource, PaymentFulfillmentRecord,
|
|
17
|
+
PaymentFulfillmentResource, PaymentSubscriptionRecord, PaymentSubscriptionResource, PaymentUsageCounterRecord,
|
|
18
|
+
PaymentUsageCounterResource, PaymentUsageRecord, PaymentUsageResource, PaymentWebhookRecord,
|
|
19
|
+
PaymentWebhookResource, PurchaseRecord, PurchaseResource,
|
|
8
20
|
} from './types.js'
|
|
9
21
|
|
|
10
22
|
export const makePaygateCustomerResource: ResourceMaker<PaygateCustomerRecord, PaygateCustomerResource> = (
|
|
11
23
|
dbAlias, serviceAlias,
|
|
12
|
-
) => {
|
|
24
|
+
): PaygateCustomerResource => {
|
|
13
25
|
const resource = makeMongoResource<PaygateCustomerRecord, PaygateCustomerResource>(
|
|
14
26
|
RES_PAYGATE_CUSTOMER, dbAlias, serviceAlias,
|
|
15
27
|
)
|
|
@@ -24,22 +36,76 @@ export const makePaygateCustomerResource: ResourceMaker<PaygateCustomerRecord, P
|
|
|
24
36
|
|
|
25
37
|
export const makeSubscriptionResource: ResourceMaker<PaymentSubscriptionRecord, PaymentSubscriptionResource> = (
|
|
26
38
|
dbAlias, serviceAlias,
|
|
27
|
-
) => {
|
|
39
|
+
): PaymentSubscriptionResource => {
|
|
28
40
|
const resource = makeMongoResource<PaymentSubscriptionRecord, PaymentSubscriptionResource>(
|
|
29
41
|
RES_PAYMENT_SUBSCRIPTION, dbAlias, serviceAlias,
|
|
30
42
|
)
|
|
31
43
|
resource.byExternalId = async (externalId, paygate) => await resource.load({ externalId, paygate })
|
|
44
|
+
resource.byItemId = async (itemId, paygate) => await resource.load({ itemId, paygate })
|
|
32
45
|
resource.schema = PaymentSubscriptionSchema
|
|
33
|
-
resource.index('
|
|
34
|
-
resource.index('
|
|
35
|
-
resource.index('
|
|
36
|
-
resource.index('
|
|
46
|
+
resource.index('external', { paygate: 1, externalId: 1 }, { unique: true })
|
|
47
|
+
resource.index('entityStatusRank', { entityId: 1, status: 1, rank: -1 })
|
|
48
|
+
resource.index('entityPlan', { entityId: 1, planSku: 1 })
|
|
49
|
+
resource.index('customer', { paygate: 1, customerId: 1 })
|
|
50
|
+
resource.index('item', { paygate: 1, itemId: 1 }, { sparse: true })
|
|
51
|
+
resource.index('statusUpdated', { paygate: 1, status: 1, updatedAt: 1 })
|
|
52
|
+
return resource
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const makeFulfillmentResource: ResourceMaker<PaymentFulfillmentRecord, PaymentFulfillmentResource> = (
|
|
56
|
+
dbAlias, serviceAlias,
|
|
57
|
+
): PaymentFulfillmentResource => {
|
|
58
|
+
const resource = makeMongoResource<PaymentFulfillmentRecord, PaymentFulfillmentResource>(
|
|
59
|
+
RES_PAYMENT_FULFILLMENT, dbAlias, serviceAlias,
|
|
60
|
+
)
|
|
61
|
+
resource.byExternalId = async (externalId, paygate) => await resource.load({ externalId, paygate })
|
|
62
|
+
resource.schema = PaymentFulfillmentSchema
|
|
63
|
+
resource.index('external', { paygate: 1, externalId: 1 }, { unique: true })
|
|
64
|
+
resource.index('paymentIntent', { paygate: 1, paymentIntentId: 1 }, { sparse: true })
|
|
65
|
+
resource.index('charge', { paygate: 1, chargeId: 1 }, { sparse: true })
|
|
66
|
+
resource.index('entityCreated', { entityId: 1, createdAt: -1 })
|
|
67
|
+
return resource
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const makeWebhookResource: ResourceMaker<PaymentWebhookRecord, PaymentWebhookResource> = (
|
|
71
|
+
dbAlias, serviceAlias,
|
|
72
|
+
): PaymentWebhookResource => {
|
|
73
|
+
const resource = makeMongoResource<PaymentWebhookRecord, PaymentWebhookResource>(
|
|
74
|
+
RES_PAYMENT_WEBHOOK, dbAlias, serviceAlias,
|
|
75
|
+
)
|
|
76
|
+
resource.schema = PaymentWebhookSchema
|
|
77
|
+
resource.index('endpoint', { paygate: 1, service: 1, url: 1 }, { unique: true })
|
|
78
|
+
return resource
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const makeUsageResource: ResourceMaker<PaymentUsageRecord, PaymentUsageResource> = (
|
|
82
|
+
dbAlias, serviceAlias,
|
|
83
|
+
): PaymentUsageResource => {
|
|
84
|
+
const resource = makeMongoResource<PaymentUsageRecord, PaymentUsageResource>(
|
|
85
|
+
RES_PAYMENT_USAGE, dbAlias, serviceAlias,
|
|
86
|
+
)
|
|
87
|
+
resource.schema = PaymentUsageSchema
|
|
88
|
+
resource.index('event', { entityId: 1, limitKey: 1, eventKey: 1 }, { unique: true })
|
|
89
|
+
resource.index('window', { entityId: 1, limitKey: 1, window: 1 })
|
|
90
|
+
resource.index('ref', { entityId: 1, limitKey: 1, ref: 1 }, { sparse: true })
|
|
91
|
+
resource.index('entityCreated', { entityId: 1, createdAt: -1 })
|
|
92
|
+
return resource
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const makeUsageCounterResource: ResourceMaker<PaymentUsageCounterRecord, PaymentUsageCounterResource> = (
|
|
96
|
+
dbAlias, serviceAlias,
|
|
97
|
+
): PaymentUsageCounterResource => {
|
|
98
|
+
const resource = makeMongoResource<PaymentUsageCounterRecord, PaymentUsageCounterResource>(
|
|
99
|
+
RES_PAYMENT_USAGE_COUNTER, dbAlias, serviceAlias,
|
|
100
|
+
)
|
|
101
|
+
resource.schema = PaymentUsageCounterSchema
|
|
102
|
+
resource.index('window', { entityId: 1, limitKey: 1, window: 1 }, { unique: true })
|
|
37
103
|
return resource
|
|
38
104
|
}
|
|
39
105
|
|
|
40
106
|
export const makeFingerprintResource: ResourceMaker<FingerprintRecord, FingerprintResource> = (
|
|
41
107
|
dbAlias, serviceAlias,
|
|
42
|
-
) => {
|
|
108
|
+
): FingerprintResource => {
|
|
43
109
|
const resource = makeMongoResource<FingerprintRecord, FingerprintResource>(
|
|
44
110
|
RES_PAYMENT_FINGERPRINT, dbAlias, serviceAlias,
|
|
45
111
|
)
|
|
@@ -49,3 +115,84 @@ export const makeFingerprintResource: ResourceMaker<FingerprintRecord, Fingerpri
|
|
|
49
115
|
resource.index('sku', { sku: 1 }, { unique: true })
|
|
50
116
|
return resource
|
|
51
117
|
}
|
|
118
|
+
|
|
119
|
+
export const makeBillingProfileResource: ResourceMaker<BillingProfileRecord, BillingProfileResource> = (
|
|
120
|
+
dbAlias, serviceAlias,
|
|
121
|
+
): BillingProfileResource => {
|
|
122
|
+
const resource = makeMongoResource<BillingProfileRecord, BillingProfileResource>(
|
|
123
|
+
RES_BILLING_PROFILE, dbAlias, serviceAlias,
|
|
124
|
+
)
|
|
125
|
+
resource.byEntity = async entityId => await resource.load({ entityId })
|
|
126
|
+
resource.schema = BillingProfileSchema
|
|
127
|
+
// One profile per organization: the unique index is what makes the first lock the only one.
|
|
128
|
+
resource.index('entity', { entityId: 1 }, { unique: true })
|
|
129
|
+
resource.index('customer', { paygate: 1, customerId: 1 }, { sparse: true })
|
|
130
|
+
return resource
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const makePurchaseResource: ResourceMaker<PurchaseRecord, PurchaseResource> = (
|
|
134
|
+
dbAlias, serviceAlias,
|
|
135
|
+
): PurchaseResource => {
|
|
136
|
+
const resource = makeMongoResource<PurchaseRecord, PurchaseResource>(RES_PAYMENT_PURCHASE, dbAlias, serviceAlias)
|
|
137
|
+
resource.byPurchaseId = async purchaseId => await resource.load({ purchaseId })
|
|
138
|
+
resource.schema = PurchaseSchema
|
|
139
|
+
resource.index('purchase', { purchaseId: 1 }, { unique: true })
|
|
140
|
+
resource.index('contract', { contractRef: 1 }, { unique: true })
|
|
141
|
+
resource.index('entityDeadline', { entityId: 1, deadline: -1 })
|
|
142
|
+
resource.index('entityPurchased', { entityId: 1, purchasedAt: -1 })
|
|
143
|
+
// Single-field on purpose: a compound sparse index still indexes rows missing only `sessionId`
|
|
144
|
+
// (subscription purchases before their checkout is captured), and unique would collide on them.
|
|
145
|
+
resource.index('session', { sessionId: 1 }, { unique: true, sparse: true })
|
|
146
|
+
resource.index('subscription', { paygate: 1, subscriptionId: 1 }, { sparse: true })
|
|
147
|
+
resource.index('invoice', { invoiceId: 1 }, { sparse: true })
|
|
148
|
+
resource.index('invoiceNumber', { invoiceNumber: 1 }, { sparse: true })
|
|
149
|
+
resource.index('paymentIntent', { paygate: 1, paymentIntentId: 1 }, { sparse: true })
|
|
150
|
+
return resource
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const makeConsumerConsentResource: ResourceMaker<ConsumerConsentRecord, ConsumerConsentResource> = (
|
|
154
|
+
dbAlias, serviceAlias,
|
|
155
|
+
): ConsumerConsentResource => {
|
|
156
|
+
const resource = makeMongoResource<ConsumerConsentRecord, ConsumerConsentResource>(
|
|
157
|
+
RES_CONSUMER_CONSENT, dbAlias, serviceAlias,
|
|
158
|
+
)
|
|
159
|
+
resource.schema = ConsumerConsentSchema
|
|
160
|
+
resource.index('entityDecided', { entityId: 1, decidedAt: -1 })
|
|
161
|
+
resource.index('kindPlan', { kind: 1, entityId: 1, planSku: 1, decidedAt: -1 })
|
|
162
|
+
return resource
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export const makeConsumerDeclarationResource: ResourceMaker<ConsumerDeclarationRecord, ConsumerDeclarationResource> = (
|
|
166
|
+
dbAlias, serviceAlias,
|
|
167
|
+
): ConsumerDeclarationResource => {
|
|
168
|
+
const resource = makeMongoResource<ConsumerDeclarationRecord, ConsumerDeclarationResource>(
|
|
169
|
+
RES_CONSUMER_DECLARATION, dbAlias, serviceAlias,
|
|
170
|
+
)
|
|
171
|
+
resource.schema = ConsumerDeclarationSchema
|
|
172
|
+
resource.index('kindReceived', { kind: 1, receivedAt: -1 })
|
|
173
|
+
resource.index('entityReceived', { entityId: 1, receivedAt: -1 }, { sparse: true })
|
|
174
|
+
resource.index('purchase', { purchaseId: 1 }, { sparse: true })
|
|
175
|
+
return resource
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const makeConsumerEventResource: ResourceMaker<ConsumerEventRecord, ConsumerEventResource> = (
|
|
179
|
+
dbAlias, serviceAlias,
|
|
180
|
+
): ConsumerEventResource => {
|
|
181
|
+
const resource = makeMongoResource<ConsumerEventRecord, ConsumerEventResource>(
|
|
182
|
+
RES_CONSUMER_EVENT, dbAlias, serviceAlias,
|
|
183
|
+
)
|
|
184
|
+
resource.schema = ConsumerEventSchema
|
|
185
|
+
resource.index('record', { recordId: 1, at: 1 })
|
|
186
|
+
resource.index('entityAt', { entityId: 1, at: -1 }, { sparse: true })
|
|
187
|
+
resource.index('actionOk', { action: 1, ok: 1, at: 1 })
|
|
188
|
+
return resource
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The consumer-rights resources, alias → maker — registered by the gateway, each only when absent. */
|
|
192
|
+
export const CONSUMER_RIGHTS_RESOURCE_MAKERS = [
|
|
193
|
+
[RES_BILLING_PROFILE, makeBillingProfileResource],
|
|
194
|
+
[RES_PAYMENT_PURCHASE, makePurchaseResource],
|
|
195
|
+
[RES_CONSUMER_CONSENT, makeConsumerConsentResource],
|
|
196
|
+
[RES_CONSUMER_DECLARATION, makeConsumerDeclarationResource],
|
|
197
|
+
[RES_CONSUMER_EVENT, makeConsumerEventResource],
|
|
198
|
+
] as const
|
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import type { JSONSchemaType } from 'ajv'
|
|
2
|
+
import { DateSchema } from '@owlmeans/auth'
|
|
3
|
+
import {
|
|
4
|
+
CancellationKindSchema, CheckoutPricingModeSchema, ConsentKindSchema, ConsumerRegionSchema,
|
|
5
|
+
DeclarationChannelSchema, DeclarationKindSchema, PurchaseKindSchema, SubscriptionStatusSchema,
|
|
6
|
+
} from '@owlmeans/payment'
|
|
7
|
+
import { schema } from '@owlmeans/entrypoint'
|
|
8
|
+
import type {
|
|
9
|
+
BillingProfileRecord, ConsumerConsentRecord, ConsumerDeclarationRecord, PaygateCustomerRecord,
|
|
10
|
+
PaymentFulfillmentRecord, PaymentSubscriptionRecord, PaymentUsageCounterRecord, PaymentUsageRecord,
|
|
11
|
+
PaymentWebhookRecord, PurchaseRecord, ConsumerEventRecord, FingerprintRecord, PaygateParams, ResyncResult,
|
|
12
|
+
ResyncSubscriptionsResult,
|
|
13
|
+
} from './types.js'
|
|
14
|
+
import { date, id, links, num, optBool, optNum, optStr, origin, str } from './consts.local.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Record schemas. Every stored property is declared: the resource coerces a write through its
|
|
18
|
+
* schema, and a property the schema does not know is written as a string. Dates follow the record
|
|
19
|
+
* convention (`DateSchema`). None of these records declares an ObjectId reference — `entityId`
|
|
20
|
+
* is an organization key and every other id is the paygate's.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const optDate = { ...DateSchema, nullable: true }
|
|
24
|
+
|
|
25
|
+
export const PaygateCustomerSchema = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
id, paygate: str, externalId: str, entityId: optStr, profileId: optStr, email: optStr, name: optStr,
|
|
29
|
+
taxId: optStr, country: optStr, currency: optStr, deletedAt: optDate,
|
|
30
|
+
},
|
|
31
|
+
required: ['paygate', 'externalId'],
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
} as unknown as JSONSchemaType<PaygateCustomerRecord>
|
|
34
|
+
|
|
35
|
+
export const PaymentSubscriptionSchema = {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
id, entityId: str, planSku: str, productSku: str, service: str, paygate: str, externalId: str,
|
|
39
|
+
itemId: optStr, priceId: optStr, status: SubscriptionStatusSchema, externalStatus: optStr, rank: num,
|
|
40
|
+
periodStart: optDate, periodEnd: optDate, cancelAtPeriodEnd: optBool, canceledAt: optDate,
|
|
41
|
+
endedAt: optDate, pausedAt: optDate, trialEnd: optDate, latestInvoiceId: optStr, customerId: optStr,
|
|
42
|
+
disputedAt: optDate, disputeStatus: optStr, createdAt: date, updatedAt: optDate, syncedAt: optDate,
|
|
43
|
+
lastEventId: optStr, initialPropagatedAt: optDate, currency: optStr,
|
|
44
|
+
checkoutSessionId: optStr, purchaseId: optStr, firstInvoiceId: optStr, country: optStr, email: optStr,
|
|
45
|
+
amountTotalMinor: optNum, amountTaxMinor: optNum, termsAccepted: optBool, startRequestId: optStr,
|
|
46
|
+
withdrawnAt: optDate,
|
|
47
|
+
overrides: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
nullable: true,
|
|
50
|
+
properties: {
|
|
51
|
+
limits: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
nullable: true,
|
|
54
|
+
additionalProperties: {
|
|
55
|
+
type: 'object', properties: { limit: num }, required: ['limit'], additionalProperties: false,
|
|
56
|
+
},
|
|
57
|
+
required: [],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
},
|
|
62
|
+
propagated: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
nullable: true,
|
|
65
|
+
properties: {
|
|
66
|
+
planSku: str, rank: num, status: SubscriptionStatusSchema, cancelAtPeriodEnd: optBool,
|
|
67
|
+
pausedAt: optDate, renewedInvoiceId: optStr,
|
|
68
|
+
},
|
|
69
|
+
required: ['planSku', 'rank', 'status'],
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: [
|
|
74
|
+
'entityId', 'planSku', 'productSku', 'service', 'paygate', 'externalId', 'status', 'rank', 'createdAt',
|
|
75
|
+
],
|
|
76
|
+
additionalProperties: false,
|
|
77
|
+
} as unknown as JSONSchemaType<PaymentSubscriptionRecord>
|
|
78
|
+
|
|
79
|
+
export const PaymentFulfillmentSchema = {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: {
|
|
82
|
+
id, entityId: str, productSku: str, planSku: optStr, service: str, paygate: str, externalId: str,
|
|
83
|
+
paymentIntentId: optStr, chargeId: optStr, invoiceId: optStr, mode: CheckoutPricingModeSchema,
|
|
84
|
+
units: optNum, amountMinor: optNum, sourceChargeAmountMinor: optNum, amountCurrency: optStr,
|
|
85
|
+
chargeAmountMinor: optNum, currency: optStr, createdAt: date,
|
|
86
|
+
fulfilledAt: optDate, failedAt: optDate, refundedMinor: optNum, refundedAt: optDate,
|
|
87
|
+
disputedAt: optDate, disputeStatus: optStr,
|
|
88
|
+
country: optStr, email: optStr, profileId: optStr, amountTotalMinor: optNum, amountTaxMinor: optNum,
|
|
89
|
+
termsAccepted: optBool, purchaseId: optStr,
|
|
90
|
+
},
|
|
91
|
+
required: ['entityId', 'productSku', 'service', 'paygate', 'externalId', 'mode', 'createdAt'],
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
} as unknown as JSONSchemaType<PaymentFulfillmentRecord>
|
|
94
|
+
|
|
95
|
+
export const PaymentWebhookSchema = {
|
|
96
|
+
type: 'object',
|
|
97
|
+
properties: {
|
|
98
|
+
id, paygate: str, service: str, url: str, externalId: str,
|
|
99
|
+
/** The signing secret: field-encrypted when the database is configured with a key. */
|
|
100
|
+
secret: { type: 'string', secure: true },
|
|
101
|
+
apiVersion: str, events: { type: 'array', items: str }, hash: str, createdAt: date, updatedAt: optDate,
|
|
102
|
+
},
|
|
103
|
+
required: ['paygate', 'service', 'url', 'externalId', 'secret', 'apiVersion', 'events', 'hash', 'createdAt'],
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
} as unknown as JSONSchemaType<PaymentWebhookRecord>
|
|
106
|
+
|
|
107
|
+
export const PaymentUsageSchema = {
|
|
108
|
+
type: 'object',
|
|
109
|
+
properties: {
|
|
110
|
+
id, entityId: str, limitKey: str, window: str, delta: num, eventKey: str, ref: optStr, reason: optStr,
|
|
111
|
+
planSku: optStr, createdAt: date, releasedAt: optDate,
|
|
112
|
+
},
|
|
113
|
+
required: ['entityId', 'limitKey', 'window', 'delta', 'eventKey', 'createdAt'],
|
|
114
|
+
additionalProperties: false,
|
|
115
|
+
} as unknown as JSONSchemaType<PaymentUsageRecord>
|
|
116
|
+
|
|
117
|
+
export const PaymentUsageCounterSchema = {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: {
|
|
120
|
+
id, entityId: str, limitKey: str, window: str, used: num, limit: num, planSku: optStr,
|
|
121
|
+
overSince: optDate, updatedAt: date, reconciledAt: optDate,
|
|
122
|
+
},
|
|
123
|
+
required: ['entityId', 'limitKey', 'window', 'used', 'limit', 'updatedAt'],
|
|
124
|
+
additionalProperties: false,
|
|
125
|
+
} as unknown as JSONSchemaType<PaymentUsageCounterRecord>
|
|
126
|
+
|
|
127
|
+
/** An optional enum: `null` must be listed for a validator to accept it. */
|
|
128
|
+
const nullableEnum = (values: readonly unknown[]) => ({ type: 'string', enum: [...values, null], nullable: true })
|
|
129
|
+
|
|
130
|
+
export const BillingProfileSchema = {
|
|
131
|
+
type: 'object',
|
|
132
|
+
properties: {
|
|
133
|
+
id, entityId: str, country: str, region: ConsumerRegionSchema, currency: str, language: str,
|
|
134
|
+
source: { type: 'string', enum: ['checkout', 'customer', 'manual'] }, paygate: str, customerId: optStr,
|
|
135
|
+
sessionId: optStr, ipCountry: optStr, email: optStr, name: optStr, business: optBool, lockedAt: date,
|
|
136
|
+
createdAt: date, updatedAt: optDate,
|
|
137
|
+
},
|
|
138
|
+
required: ['entityId', 'country', 'region', 'currency', 'language', 'source', 'paygate', 'lockedAt', 'createdAt'],
|
|
139
|
+
additionalProperties: false,
|
|
140
|
+
} as unknown as JSONSchemaType<BillingProfileRecord>
|
|
141
|
+
|
|
142
|
+
export const PurchaseSchema = {
|
|
143
|
+
type: 'object',
|
|
144
|
+
properties: {
|
|
145
|
+
id, purchaseId: str, contractRef: str, entityId: str, kind: PurchaseKindSchema, paygate: str,
|
|
146
|
+
sessionId: optStr, subscriptionId: optStr, paymentIntentId: optStr, invoiceId: optStr, invoiceNumber: optStr,
|
|
147
|
+
invoiceLineId: optStr, productSku: str, planSku: optStr, profileId: optStr, country: optStr,
|
|
148
|
+
region: nullableEnum(ConsumerRegionSchema.enum), ipCountry: optStr, inScope: { type: 'boolean' },
|
|
149
|
+
language: str, email: optStr, name: optStr, business: optBool, currency: str, amountSubtotalMinor: num,
|
|
150
|
+
amountTaxMinor: num, amountTotalMinor: num, presentmentCurrency: optStr, presentmentAmountMinor: optNum,
|
|
151
|
+
netAmountMinor: optNum, amountCurrency: optStr, units: optNum, taxBehavior: optStr, termsAccepted: optBool,
|
|
152
|
+
textVersion: optStr, copyVersion: optStr, startRequestId: optStr, servicesStartedAt: optDate,
|
|
153
|
+
confirmationMailAt: optDate, purchasedAt: date, deadline: optDate, consentId: optStr, consentedAt: optDate,
|
|
154
|
+
withdrawalId: optStr, withdrawnAt: optDate, refundedMinor: optNum, refundedAt: optDate, cancellationId: optStr,
|
|
155
|
+
cancelEffectiveAt: optDate, createdAt: date, updatedAt: optDate,
|
|
156
|
+
},
|
|
157
|
+
required: [
|
|
158
|
+
'purchaseId', 'contractRef', 'entityId', 'kind', 'paygate', 'productSku', 'inScope', 'language', 'currency',
|
|
159
|
+
'amountSubtotalMinor', 'amountTaxMinor', 'amountTotalMinor', 'purchasedAt', 'createdAt',
|
|
160
|
+
],
|
|
161
|
+
additionalProperties: false,
|
|
162
|
+
} as unknown as JSONSchemaType<PurchaseRecord>
|
|
163
|
+
|
|
164
|
+
export const ConsumerConsentSchema = {
|
|
165
|
+
type: 'object',
|
|
166
|
+
properties: {
|
|
167
|
+
id, kind: ConsentKindSchema, entityId: str, profileId: optStr, name: optStr, email: optStr,
|
|
168
|
+
purchaseIds: { type: 'array', items: str },
|
|
169
|
+
planSku: optStr, planName: optStr, textVersion: str, copyVersion: str, language: str, uiLanguage: optStr, trader: str,
|
|
170
|
+
context: optStr,
|
|
171
|
+
text: {
|
|
172
|
+
type: 'object',
|
|
173
|
+
properties: { request: str, acknowledgement: str, checkbox: str },
|
|
174
|
+
required: ['request', 'acknowledgement', 'checkbox'],
|
|
175
|
+
additionalProperties: false,
|
|
176
|
+
},
|
|
177
|
+
links, deadline: optDate, decidedAt: date, expiresAt: optDate, ...origin,
|
|
178
|
+
},
|
|
179
|
+
required: [
|
|
180
|
+
'kind', 'entityId', 'purchaseIds', 'textVersion', 'copyVersion', 'language', 'trader', 'text', 'links',
|
|
181
|
+
'decidedAt',
|
|
182
|
+
],
|
|
183
|
+
additionalProperties: false,
|
|
184
|
+
} as unknown as JSONSchemaType<ConsumerConsentRecord>
|
|
185
|
+
|
|
186
|
+
export const ConsumerDeclarationSchema = {
|
|
187
|
+
type: 'object',
|
|
188
|
+
properties: {
|
|
189
|
+
id, kind: DeclarationKindSchema, channel: DeclarationChannelSchema, entityId: optStr, purchaseId: optStr,
|
|
190
|
+
subscriptionId: optStr, contractRef: optStr, name: str, email: str,
|
|
191
|
+
cancellationKind: nullableEnum(CancellationKindSchema.enum), reason: optStr,
|
|
192
|
+
effective: nullableEnum(['earliest', 'date']), requestedDate: optStr,
|
|
193
|
+
language: str, textVersion: optStr, copyVersion: str, receivedAt: date, matched: { type: 'boolean' },
|
|
194
|
+
profileId: optStr, duplicateOf: optStr, status: str, refundMinor: optNum, currency: optStr,
|
|
195
|
+
effectiveAt: optDate, ...origin,
|
|
196
|
+
},
|
|
197
|
+
required: ['kind', 'channel', 'name', 'email', 'language', 'copyVersion', 'receivedAt', 'matched', 'status'],
|
|
198
|
+
additionalProperties: false,
|
|
199
|
+
} as unknown as JSONSchemaType<ConsumerDeclarationRecord>
|
|
200
|
+
|
|
201
|
+
export const FingerprintSchema = {
|
|
202
|
+
type: 'object',
|
|
203
|
+
properties: {
|
|
204
|
+
id, sku: str, hash: str, productId: optStr, externalId: optStr,
|
|
205
|
+
prices: {
|
|
206
|
+
type: 'array',
|
|
207
|
+
nullable: true,
|
|
208
|
+
items: {
|
|
209
|
+
type: 'object',
|
|
210
|
+
properties: {
|
|
211
|
+
planSku: str, priceId: str, lookupKey: str, currency: str, unitAmount: num,
|
|
212
|
+
// An array, never a currency-keyed map: the resource coerces a map's values to strings.
|
|
213
|
+
options: {
|
|
214
|
+
type: 'array',
|
|
215
|
+
items: {
|
|
216
|
+
type: 'object', properties: { currency: str, unitAmount: num },
|
|
217
|
+
required: ['currency', 'unitAmount'], additionalProperties: false,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
taxBehavior: optStr, interval: optStr, sourceUnitAmount: num, sourceCurrency: str, syncedAt: date,
|
|
221
|
+
},
|
|
222
|
+
required: [
|
|
223
|
+
'planSku', 'priceId', 'lookupKey', 'currency', 'unitAmount', 'options', 'sourceUnitAmount',
|
|
224
|
+
'sourceCurrency', 'syncedAt',
|
|
225
|
+
],
|
|
226
|
+
additionalProperties: false,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
updatedAt: date,
|
|
230
|
+
},
|
|
231
|
+
required: ['sku', 'hash', 'updatedAt'],
|
|
232
|
+
additionalProperties: false,
|
|
233
|
+
} as unknown as JSONSchemaType<FingerprintRecord>
|
|
234
|
+
|
|
235
|
+
export const ConsumerEventSchema = {
|
|
236
|
+
type: 'object',
|
|
237
|
+
properties: {
|
|
238
|
+
id, recordId: str,
|
|
239
|
+
recordKind: { type: 'string', enum: ['purchase', 'consent', 'declaration', 'profile', 'checkout'] },
|
|
240
|
+
entityId: optStr,
|
|
241
|
+
action: {
|
|
242
|
+
type: 'string',
|
|
243
|
+
enum: [
|
|
244
|
+
'mail', 'computed', 'meter', 'refund', 'credit-note', 'subscription-cancel', 'cancel-scheduled', 'observers',
|
|
245
|
+
'lock', 'lock-mismatch', 'relock', 'unlock', 'duplicate', 'checkout-terms-fallback',
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
step: optStr, ok: { type: 'boolean' }, skipped: optBool, externalId: optStr, amountMinor: optNum,
|
|
249
|
+
currency: optStr, detail: optStr, error: optStr, at: date,
|
|
250
|
+
},
|
|
251
|
+
required: ['recordId', 'recordKind', 'action', 'ok', 'at'],
|
|
252
|
+
additionalProperties: false,
|
|
253
|
+
} as unknown as JSONSchemaType<ConsumerEventRecord>
|
|
254
|
+
|
|
255
|
+
/** The payment gate's entrypoint contracts. */
|
|
256
|
+
export const PaygateParamsSchema = schema<PaygateParams>({
|
|
257
|
+
type: 'object', properties: { paygate: { type: 'string' } }, required: ['paygate'],
|
|
258
|
+
additionalProperties: false,
|
|
259
|
+
} as JSONSchemaType<PaygateParams>)
|
|
260
|
+
|
|
261
|
+
export const ResyncResultSchema = schema<ResyncResult>({
|
|
262
|
+
type: 'object', properties: { ok: { type: 'boolean' } }, required: ['ok'],
|
|
263
|
+
additionalProperties: false,
|
|
264
|
+
} as JSONSchemaType<ResyncResult>)
|
|
265
|
+
|
|
266
|
+
export const ResyncSubscriptionsResultSchema = schema<ResyncSubscriptionsResult>({
|
|
267
|
+
type: 'object',
|
|
268
|
+
properties: { scanned: { type: 'number' }, updated: { type: 'number' } },
|
|
269
|
+
required: ['scanned', 'updated'],
|
|
270
|
+
additionalProperties: false,
|
|
271
|
+
} as JSONSchemaType<ResyncSubscriptionsResult>)
|