@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,353 @@
|
|
|
1
|
+
import { MAILER_SERVICE, type MailerService, type MailMessage } from '@owlmeans/mailer'
|
|
2
|
+
import { CancellationStatus, PurchaseKind, WithdrawalStatus, type ConsumerRightsLinks, type ConsumerRightsPolicy, type CopyValues, consumerCopyHelper, consumerRightsPolicyHelper } from '@owlmeans/payment'
|
|
3
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
4
|
+
import { memoHelper } from '@owlmeans/context'
|
|
5
|
+
import type {
|
|
6
|
+
ConsumerConsentRecord, ConsumerDeclarationRecord, ConsumerMailData, ConsumerMailKind, ConsumerMailPluginConfig,
|
|
7
|
+
PurchaseRecord, TraderDef,
|
|
8
|
+
} from '../types.js'
|
|
9
|
+
import { log } from '../log.js'
|
|
10
|
+
import { RECORD_KIND } from './consts.local.js'
|
|
11
|
+
import type { Block, Rendered } from './types.local.js'
|
|
12
|
+
import { paymentAccessOf } from '../access.js'
|
|
13
|
+
import { paymentUtils } from '../utils.js'
|
|
14
|
+
import { catalogueOf } from '../catalogue.js'
|
|
15
|
+
import { consumerFormatHelper } from './format.js'
|
|
16
|
+
import { consumerRecordsOf } from './records.js'
|
|
17
|
+
import type { ConsumerMailHelper } from './mail/types.js'
|
|
18
|
+
|
|
19
|
+
const text = (lng: string, path: string, vars: CopyValues = {}, context?: string): string =>
|
|
20
|
+
consumerCopyHelper.consumerText(lng, path, vars, context)
|
|
21
|
+
|
|
22
|
+
const textOf = (blocks: Block[], lng: string): string => blocks
|
|
23
|
+
.map(block => 'text' in block ? block.text : text(lng, 'email.common.link', { label: block.label, url: block.url }))
|
|
24
|
+
.join('\n\n')
|
|
25
|
+
|
|
26
|
+
const htmlOf = (blocks: Block[]): string => blocks.map(block => 'text' in block
|
|
27
|
+
? `<p>${consumerFormatHelper.escapeHtml(block.text).replace(/\n/g, '<br>')}</p>`
|
|
28
|
+
: `<p>${consumerFormatHelper.escapeHtml(block.label)}: `
|
|
29
|
+
+ `<a href="${consumerFormatHelper.escapeHtml(block.url)}">${consumerFormatHelper.escapeHtml(block.url)}</a></p>`,
|
|
30
|
+
).join('\n')
|
|
31
|
+
|
|
32
|
+
const linkBlocks = (lng: string, links: ConsumerRightsLinks, which: Array<keyof ConsumerRightsLinks>): Block[] => {
|
|
33
|
+
const labels: Record<keyof ConsumerRightsLinks, string> = {
|
|
34
|
+
billingTerms: 'links.billing-terms',
|
|
35
|
+
withdrawalInformation: 'links.withdrawal-information',
|
|
36
|
+
withdrawalForm: 'links.withdrawal-form',
|
|
37
|
+
withdrawalFunction: 'links.withdrawal-function',
|
|
38
|
+
cancellation: 'links.cancellation',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return which
|
|
42
|
+
.filter(key => links[key] != null && links[key] !== '')
|
|
43
|
+
.map(key => ({ label: text(lng, labels[key]), url: links[key] as string }))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The trader as the mails and the withdrawal information name it: legal name, address, e-mail. */
|
|
47
|
+
const traderIdentityOf = (trader: TraderDef): string =>
|
|
48
|
+
[trader.legalName, trader.address, trader.email].filter(part => part != null && part.trim() !== '').join(', ')
|
|
49
|
+
|
|
50
|
+
const renderConsent = (data: ConsumerMailData): Rendered => {
|
|
51
|
+
const lng = data.language
|
|
52
|
+
const consent = data.consent as ConsumerConsentRecord
|
|
53
|
+
const lines = (data.purchases ?? []).map(purchase => text(lng, 'email.consent.purchase', {
|
|
54
|
+
contractRef: purchase.contractRef,
|
|
55
|
+
date: consumerFormatHelper.formatDate(new Date(purchase.purchasedAt), lng),
|
|
56
|
+
amount: consumerFormatHelper.formatMoney(purchase.amountTotalMinor, purchase.currency, lng),
|
|
57
|
+
deadline: purchase.deadline != null ? consumerFormatHelper.formatDeadline(new Date(purchase.deadline), lng) : '—',
|
|
58
|
+
}))
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
subject: text(lng, 'email.consent.subject'),
|
|
62
|
+
blocks: [
|
|
63
|
+
{
|
|
64
|
+
text: text(lng, 'email.consent.body', {
|
|
65
|
+
date: consumerFormatHelper.formatDateTime(new Date(consent.decidedAt), lng), statement: consent.text.checkbox,
|
|
66
|
+
purchases: lines.join('\n'),
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
{ text: text(lng, 'email.consent.unused') },
|
|
70
|
+
...linkBlocks(lng, data.links, ['billingTerms', 'withdrawalInformation', 'withdrawalFunction']),
|
|
71
|
+
],
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const renderWithdrawal = (data: ConsumerMailData): Rendered => {
|
|
76
|
+
const lng = data.language
|
|
77
|
+
const declaration = data.declaration as ConsumerDeclarationRecord
|
|
78
|
+
const blocks: Block[] = [{
|
|
79
|
+
text: text(lng, 'email.withdrawal.body', {
|
|
80
|
+
date: consumerFormatHelper.formatDateTime(new Date(declaration.receivedAt), lng), name: declaration.name,
|
|
81
|
+
contract: declaration.contractRef ?? data.purchase?.contractRef ?? '—', email: declaration.email,
|
|
82
|
+
}),
|
|
83
|
+
}]
|
|
84
|
+
const status = declaration.status
|
|
85
|
+
// `received`: nothing is executed on this declaration (no match, or no statutory right) — the
|
|
86
|
+
// receipt says what happens if it does match, exactly as for an unknown contract.
|
|
87
|
+
if (!declaration.matched || declaration.duplicateOf != null || status === WithdrawalStatus.Received) {
|
|
88
|
+
blocks.push({ text: text(lng, 'email.withdrawal.unmatched') })
|
|
89
|
+
} else if (status === WithdrawalStatus.Expired) {
|
|
90
|
+
const deadline = data.purchase?.deadline
|
|
91
|
+
blocks.push({
|
|
92
|
+
text: text(lng, 'email.withdrawal.expired', {
|
|
93
|
+
deadline: deadline != null ? consumerFormatHelper.formatDeadline(new Date(deadline), lng) : '—',
|
|
94
|
+
}),
|
|
95
|
+
})
|
|
96
|
+
} else if (
|
|
97
|
+
(status === WithdrawalStatus.Processing || status === WithdrawalStatus.Refunded)
|
|
98
|
+
&& declaration.refundMinor != null && declaration.currency != null
|
|
99
|
+
) {
|
|
100
|
+
blocks.push({ text: text(lng, 'email.withdrawal.refund', { amount: consumerFormatHelper.formatMoney(declaration.refundMinor, declaration.currency, lng) }) })
|
|
101
|
+
} else {
|
|
102
|
+
blocks.push({ text: text(lng, 'email.withdrawal.review') })
|
|
103
|
+
}
|
|
104
|
+
blocks.push(...linkBlocks(lng, data.links, ['billingTerms', 'withdrawalInformation']))
|
|
105
|
+
|
|
106
|
+
return { subject: text(lng, 'email.withdrawal.subject'), blocks }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const renderCancellation = (data: ConsumerMailData): Rendered => {
|
|
110
|
+
const lng = data.language
|
|
111
|
+
const declaration = data.declaration as ConsumerDeclarationRecord
|
|
112
|
+
const requested = declaration.effective === 'date' && declaration.requestedDate != null
|
|
113
|
+
? consumerFormatHelper.formatDate(new Date(`${declaration.requestedDate}T00:00:00Z`), lng)
|
|
114
|
+
: text(lng, 'cancellation.effective-earliest')
|
|
115
|
+
const blocks: Block[] = [{
|
|
116
|
+
text: text(lng, 'email.cancellation.body', {
|
|
117
|
+
date: consumerFormatHelper.formatDateTime(new Date(declaration.receivedAt), lng), name: declaration.name,
|
|
118
|
+
contract: declaration.contractRef ?? declaration.subscriptionId ?? '—',
|
|
119
|
+
kind: text(lng, `cancellation.kind-${declaration.cancellationKind ?? 'ordinary'}`),
|
|
120
|
+
requested, email: declaration.email,
|
|
121
|
+
}),
|
|
122
|
+
}]
|
|
123
|
+
if (declaration.status === CancellationStatus.Review) {
|
|
124
|
+
blocks.push({ text: text(lng, 'email.cancellation.review') })
|
|
125
|
+
} else if (declaration.matched && declaration.effectiveAt != null) {
|
|
126
|
+
blocks.push({ text: text(lng, 'email.cancellation.effective', { effectiveAt: consumerFormatHelper.formatDate(new Date(declaration.effectiveAt), lng) }) })
|
|
127
|
+
} else {
|
|
128
|
+
blocks.push({ text: text(lng, 'email.cancellation.unmatched') })
|
|
129
|
+
}
|
|
130
|
+
blocks.push(...linkBlocks(lng, data.links, ['billingTerms']))
|
|
131
|
+
|
|
132
|
+
return { subject: text(lng, 'email.cancellation.subject'), blocks }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const makeConsumerMailHelper = (ctx: ApiContext): ConsumerMailHelper => {
|
|
136
|
+
const access = paymentAccessOf(ctx)
|
|
137
|
+
const records = consumerRecordsOf(ctx)
|
|
138
|
+
|
|
139
|
+
const traderOf = (mail: ConsumerMailPluginConfig | null): TraderDef =>
|
|
140
|
+
mail?.trader ?? { name: ctx.cfg.service, legalName: ctx.cfg.service }
|
|
141
|
+
|
|
142
|
+
const planTitleOf = async (planSku: string | undefined, lng: string): Promise<string> => {
|
|
143
|
+
if (planSku == null) {
|
|
144
|
+
return ''
|
|
145
|
+
}
|
|
146
|
+
const plan = await catalogueOf(ctx).findPlan(planSku)
|
|
147
|
+
const localized = plan != null ? await access.payment().localize(lng, plan).catch(() => null) : null
|
|
148
|
+
|
|
149
|
+
return localized?.title ?? plan?.title ?? planSku
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const productTitleOf = async (purchase: PurchaseRecord, lng: string): Promise<string> => {
|
|
153
|
+
const plan = purchase.planSku != null ? await catalogueOf(ctx).findPlan(purchase.planSku) : null
|
|
154
|
+
const product = await catalogueOf(ctx).findProduct(purchase.productSku)
|
|
155
|
+
const entity = plan ?? product
|
|
156
|
+
const localized = entity != null ? await access.payment().localize(lng, entity).catch(() => null) : null
|
|
157
|
+
|
|
158
|
+
return localized?.title ?? plan?.title ?? product?.title ?? purchase.productSku
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const renderPurchase = async (data: ConsumerMailData): Promise<Rendered> => {
|
|
162
|
+
const lng = data.language
|
|
163
|
+
const purchase = data.purchase as PurchaseRecord
|
|
164
|
+
const blocks: Block[] = [{
|
|
165
|
+
text: text(lng, 'email.purchase.body', {
|
|
166
|
+
contractRef: purchase.contractRef,
|
|
167
|
+
date: consumerFormatHelper.formatDateTime(new Date(purchase.purchasedAt), lng),
|
|
168
|
+
product: await productTitleOf(purchase, lng),
|
|
169
|
+
total: consumerFormatHelper.formatMoney(purchase.amountTotalMinor, purchase.currency, lng),
|
|
170
|
+
tax: consumerFormatHelper.formatMoney(purchase.amountTaxMinor, purchase.currency, lng),
|
|
171
|
+
}),
|
|
172
|
+
}]
|
|
173
|
+
if (data.consent != null) {
|
|
174
|
+
blocks.push({ text: text(lng, 'email.purchase.start-request', { statement: data.consent.text.checkbox }) })
|
|
175
|
+
}
|
|
176
|
+
const identity = traderIdentityOf(data.trader)
|
|
177
|
+
blocks.push({
|
|
178
|
+
text: text(lng, 'email.purchase.withdrawal-information', {
|
|
179
|
+
trader: identity,
|
|
180
|
+
withdrawalFunction: data.links.withdrawalFunction ?? data.links.withdrawalInformation ?? data.links.billingTerms,
|
|
181
|
+
}),
|
|
182
|
+
})
|
|
183
|
+
blocks.push({ text: text(lng, 'email.purchase.model-form', { trader: identity }) })
|
|
184
|
+
blocks.push(...linkBlocks(lng, data.links, [
|
|
185
|
+
'billingTerms', 'withdrawalInformation', 'withdrawalForm', 'withdrawalFunction',
|
|
186
|
+
...(purchase.kind === PurchaseKind.Subscription ? ['cancellation' as const] : []),
|
|
187
|
+
]))
|
|
188
|
+
|
|
189
|
+
return { subject: text(lng, 'email.purchase.subject', { contractRef: purchase.contractRef }), blocks }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const renderStart = async (data: ConsumerMailData): Promise<Rendered> => {
|
|
193
|
+
const lng = data.language
|
|
194
|
+
const consent = data.consent as ConsumerConsentRecord
|
|
195
|
+
const title = consent.planName ?? await planTitleOf(consent.planSku, lng)
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
subject: text(lng, 'email.start.subject', { plan: title }),
|
|
199
|
+
blocks: [
|
|
200
|
+
{
|
|
201
|
+
text: text(lng, 'email.start.body', {
|
|
202
|
+
date: consumerFormatHelper.formatDateTime(new Date(consent.decidedAt), lng), plan: title, statement: consent.text.checkbox,
|
|
203
|
+
}),
|
|
204
|
+
},
|
|
205
|
+
// The rule of the variant the statement was recorded in (`_units` for a plan with a units part).
|
|
206
|
+
{ text: text(lng, 'email.start.rule', {}, consent.context) },
|
|
207
|
+
...linkBlocks(lng, data.links, ['billingTerms', 'withdrawalInformation', 'withdrawalFunction']),
|
|
208
|
+
],
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const mailDataOf = async (
|
|
213
|
+
policy: ConsumerRightsPolicy, trader: TraderDef, kind: ConsumerMailKind, recordId: string,
|
|
214
|
+
): Promise<ConsumerMailData | null> => {
|
|
215
|
+
const base = { kind, recordId, trader }
|
|
216
|
+
switch (kind) {
|
|
217
|
+
case 'purchase': {
|
|
218
|
+
const purchase = await access.purchases().byPurchaseId(recordId)
|
|
219
|
+
if (purchase?.email == null || purchase.email === '') return null
|
|
220
|
+
const consent = purchase.startRequestId != null
|
|
221
|
+
? await access.consumerConsents().load(purchase.startRequestId).catch(() => null) : null
|
|
222
|
+
|
|
223
|
+
return paymentUtils.compact({
|
|
224
|
+
...base, entityId: purchase.entityId, language: purchase.language, to: purchase.email,
|
|
225
|
+
name: purchase.name ?? undefined, links: consumerRightsPolicyHelper.linksOf(policy, purchase.language), purchase,
|
|
226
|
+
consent: consent ?? undefined,
|
|
227
|
+
}) as ConsumerMailData
|
|
228
|
+
}
|
|
229
|
+
case 'consent':
|
|
230
|
+
case 'start': {
|
|
231
|
+
const consent = await access.consumerConsents().load(recordId)
|
|
232
|
+
if (consent == null) return null
|
|
233
|
+
const to = consent.email ?? await records.contactEmailOf(consent.entityId)
|
|
234
|
+
if (to == null) return null
|
|
235
|
+
const covered = consent.purchaseIds.length > 0
|
|
236
|
+
? (await access.purchases().list({ purchaseId: consent.purchaseIds }, { size: 0 })).items : []
|
|
237
|
+
|
|
238
|
+
return paymentUtils.compact({
|
|
239
|
+
...base, entityId: consent.entityId, language: consent.language, to, name: consent.name ?? undefined,
|
|
240
|
+
links: consent.links, consent, purchases: covered,
|
|
241
|
+
}) as ConsumerMailData
|
|
242
|
+
}
|
|
243
|
+
default: {
|
|
244
|
+
const declaration = await access.consumerDeclarations().load(recordId)
|
|
245
|
+
if (declaration == null) return null
|
|
246
|
+
const purchase = declaration.purchaseId != null ? await access.purchases().byPurchaseId(declaration.purchaseId) : null
|
|
247
|
+
|
|
248
|
+
return paymentUtils.compact({
|
|
249
|
+
...base, entityId: declaration.entityId ?? undefined, language: declaration.language, to: declaration.email,
|
|
250
|
+
name: declaration.name, links: consumerRightsPolicyHelper.linksOf(policy, declaration.language), declaration,
|
|
251
|
+
purchase: purchase ?? undefined,
|
|
252
|
+
}) as ConsumerMailData
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const render = async (data: ConsumerMailData, mail: ConsumerMailPluginConfig | null): Promise<MailMessage> => {
|
|
258
|
+
const lng = data.language
|
|
259
|
+
const body = data.kind === 'purchase' ? await renderPurchase(data)
|
|
260
|
+
: data.kind === 'consent' ? renderConsent(data)
|
|
261
|
+
: data.kind === 'start' ? await renderStart(data)
|
|
262
|
+
: data.kind === 'withdrawal' ? renderWithdrawal(data)
|
|
263
|
+
: renderCancellation(data)
|
|
264
|
+
const blocks: Block[] = [
|
|
265
|
+
{ text: data.name != null && data.name !== '' ? text(lng, 'email.common.greeting-named', { name: data.name }) : text(lng, 'email.common.greeting') },
|
|
266
|
+
...body.blocks,
|
|
267
|
+
{ text: text(lng, 'email.common.trader', { trader: traderIdentityOf(data.trader) }) },
|
|
268
|
+
{ text: text(lng, 'email.common.footer') },
|
|
269
|
+
]
|
|
270
|
+
|
|
271
|
+
return paymentUtils.compact({
|
|
272
|
+
to: data.to,
|
|
273
|
+
subject: body.subject,
|
|
274
|
+
text: textOf(blocks, lng),
|
|
275
|
+
html: htmlOf(blocks),
|
|
276
|
+
from: mail?.from,
|
|
277
|
+
replyTo: mail?.replyTo,
|
|
278
|
+
}) as MailMessage
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const mailerOf = (alias: string): MailerService | null =>
|
|
282
|
+
(ctx as unknown as { hasService?: (alias: string) => boolean }).hasService?.(alias) === true
|
|
283
|
+
? ctx.service<MailerService>(alias) : null
|
|
284
|
+
|
|
285
|
+
const sendConsumerMail = async (
|
|
286
|
+
policy: ConsumerRightsPolicy, kind: ConsumerMailKind, recordId: string,
|
|
287
|
+
): Promise<boolean> => {
|
|
288
|
+
const recordKind = RECORD_KIND[kind]
|
|
289
|
+
let entityId: string | undefined
|
|
290
|
+
try {
|
|
291
|
+
const mail = await access.consumerMailConfig()
|
|
292
|
+
const data = await mailDataOf(policy, traderOf(mail), kind, recordId)
|
|
293
|
+
entityId = data?.entityId
|
|
294
|
+
if (data == null) {
|
|
295
|
+
await records.recordEvent({
|
|
296
|
+
recordId, recordKind, action: 'mail', step: kind, ok: true, skipped: true, detail: '{"reason":"no-recipient"}',
|
|
297
|
+
})
|
|
298
|
+
return false
|
|
299
|
+
}
|
|
300
|
+
if (consumerFormatHelper.isReservedAddress(data.to)) {
|
|
301
|
+
await records.recordEvent({
|
|
302
|
+
recordId, recordKind, entityId, action: 'mail', step: kind, ok: true, skipped: true,
|
|
303
|
+
detail: JSON.stringify({ reason: 'reserved-domain', to: data.to }),
|
|
304
|
+
})
|
|
305
|
+
return false
|
|
306
|
+
}
|
|
307
|
+
const rendered = await render(data, mail)
|
|
308
|
+
const renderer = access.consumerRightsOf()?.mailRenderer() ?? null
|
|
309
|
+
const replaced = renderer != null ? await renderer(kind, data, rendered) : undefined
|
|
310
|
+
if (replaced === null) {
|
|
311
|
+
await records.recordEvent({
|
|
312
|
+
recordId, recordKind, entityId, action: 'mail', step: kind, ok: true, skipped: true, detail: '{"reason":"renderer"}',
|
|
313
|
+
})
|
|
314
|
+
return false
|
|
315
|
+
}
|
|
316
|
+
const message = replaced ?? rendered
|
|
317
|
+
const mailer = mailerOf(mail?.alias ?? MAILER_SERVICE)
|
|
318
|
+
if (mailer == null) {
|
|
319
|
+
await records.recordEvent({
|
|
320
|
+
recordId, recordKind, entityId, action: 'mail', step: kind, ok: false, error: 'mailer:absent',
|
|
321
|
+
})
|
|
322
|
+
return false
|
|
323
|
+
}
|
|
324
|
+
await mailer.send(message)
|
|
325
|
+
const archive: string[] = []
|
|
326
|
+
for (const address of mail?.bcc ?? []) {
|
|
327
|
+
try {
|
|
328
|
+
await mailer.send({ ...message, to: address })
|
|
329
|
+
} catch (error) {
|
|
330
|
+
archive.push(`${address}: ${paymentUtils.errorText(error)}`)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
await records.recordEvent({
|
|
334
|
+
recordId, recordKind, entityId, action: 'mail', step: kind, ok: true,
|
|
335
|
+
detail: JSON.stringify(paymentUtils.compact({ to: message.to, subject: message.subject, archiveFailures: archive.length > 0 ? archive : undefined })),
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
return true
|
|
339
|
+
} catch (error) {
|
|
340
|
+
log.error('Consumer mail failed', { kind, recordId, error })
|
|
341
|
+
await records.recordEvent({
|
|
342
|
+
recordId, recordKind, entityId, action: 'mail', step: kind, ok: false, error: paymentUtils.errorText(error),
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
return false
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return { traderIdentityOf, traderOf, planTitleOf, mailDataOf, sendConsumerMail }
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** The consumer-rights mails of a context — one per context. */
|
|
353
|
+
export const consumerMailOf = memoHelper.oncePer(makeConsumerMailHelper)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CancellationStatus, WithdrawalStatus } from '@owlmeans/payment'
|
|
2
|
+
import type { ConsumerConsentRecord, ConsumerDeclarationRecord, PurchaseRecord } from '../../types.js'
|
|
3
|
+
import type { WithdrawalComputation, WithdrawalExecution } from '../types.js'
|
|
4
|
+
|
|
5
|
+
/** The consumer-rights observers of a context, told after the records and the paygate steps of an act. */
|
|
6
|
+
export interface ConsumerObserversHelper {
|
|
7
|
+
/** Run the consumer-rights observers of one act; a throw is recorded for `reconcile` to retry. */
|
|
8
|
+
runConsumerObservers: (
|
|
9
|
+
family: 'consent' | 'withdrawal' | 'cancellation', recordId: string, entityId: string | undefined,
|
|
10
|
+
run: () => Promise<void>,
|
|
11
|
+
) => Promise<boolean>
|
|
12
|
+
/** Tell the withdrawal observers — after the records and the paygate steps. */
|
|
13
|
+
notifyWithdrawal: (
|
|
14
|
+
declaration: ConsumerDeclarationRecord, purchase: PurchaseRecord, status: WithdrawalStatus,
|
|
15
|
+
computation: Pick<WithdrawalComputation, 'reading' | 'deducted' | 'unitsReturned' | 'netMinor' | 'refundMinor'> | null,
|
|
16
|
+
execution: WithdrawalExecution | null,
|
|
17
|
+
) => Promise<boolean>
|
|
18
|
+
/** Tell the cancellation observers. */
|
|
19
|
+
notifyCancellation: (declaration: ConsumerDeclarationRecord, status: CancellationStatus) => Promise<boolean>
|
|
20
|
+
/** Tell the consent observers. */
|
|
21
|
+
notifyConsent: (consent: ConsumerConsentRecord) => Promise<boolean>
|
|
22
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { CancellationKind, CancellationStatus, WithdrawalStatus } from '@owlmeans/payment'
|
|
2
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
3
|
+
import { memoHelper } from '@owlmeans/context'
|
|
4
|
+
import type { WithdrawalComputation, WithdrawalExecution } from './types.js'
|
|
5
|
+
import type {
|
|
6
|
+
CancellationEvent, ConsentEvent, ConsumerConsentRecord, ConsumerDeclarationRecord, PurchaseRecord,
|
|
7
|
+
} from '../types.js'
|
|
8
|
+
import { log } from '../log.js'
|
|
9
|
+
import { paymentAccessOf } from '../access.js'
|
|
10
|
+
import { paymentUtils } from '../utils.js'
|
|
11
|
+
import { consumerRecordsOf } from './records.js'
|
|
12
|
+
import { makePurchaseModel } from '../models/purchase.js'
|
|
13
|
+
import type { ConsumerObserversHelper } from './observers/types.js'
|
|
14
|
+
|
|
15
|
+
export const makeConsumerObserversHelper = (ctx: ApiContext): ConsumerObserversHelper => {
|
|
16
|
+
const access = paymentAccessOf(ctx)
|
|
17
|
+
const records = consumerRecordsOf(ctx)
|
|
18
|
+
|
|
19
|
+
const runConsumerObservers = async (
|
|
20
|
+
family: 'consent' | 'withdrawal' | 'cancellation', recordId: string, entityId: string | undefined,
|
|
21
|
+
run: () => Promise<void>,
|
|
22
|
+
): Promise<boolean> => {
|
|
23
|
+
const recordKind = family === 'consent' ? 'consent' as const : 'declaration' as const
|
|
24
|
+
try {
|
|
25
|
+
await run()
|
|
26
|
+
await records.recordEvent({ recordId, recordKind, entityId, action: 'observers', step: family, ok: true })
|
|
27
|
+
|
|
28
|
+
return true
|
|
29
|
+
} catch (error) {
|
|
30
|
+
log.error('Consumer-rights observers failed; reconcile retries them', { family, recordId, error })
|
|
31
|
+
await records.recordEvent({
|
|
32
|
+
recordId, recordKind, entityId, action: 'observers', step: family, ok: false, error: paymentUtils.errorText(error),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const notifyWithdrawal = async (
|
|
40
|
+
declaration: ConsumerDeclarationRecord, purchase: PurchaseRecord, status: WithdrawalStatus,
|
|
41
|
+
computation: Pick<WithdrawalComputation, 'reading' | 'deducted' | 'unitsReturned' | 'netMinor' | 'refundMinor'> | null,
|
|
42
|
+
execution: WithdrawalExecution | null,
|
|
43
|
+
): Promise<boolean> => await runConsumerObservers('withdrawal', declaration.id as string, purchase.entityId, async () => {
|
|
44
|
+
await access.observer().propagateWithdrawal({
|
|
45
|
+
withdrawalId: declaration.id as string,
|
|
46
|
+
eventKey: `withdrawal:${declaration.id as string}`,
|
|
47
|
+
entityId: purchase.entityId,
|
|
48
|
+
channel: declaration.channel,
|
|
49
|
+
purchase: makePurchaseModel(purchase).ref(),
|
|
50
|
+
declaredAt: new Date(declaration.receivedAt),
|
|
51
|
+
status,
|
|
52
|
+
refund: paymentUtils.compact({
|
|
53
|
+
amountMinor: execution?.refundedMinor ?? 0,
|
|
54
|
+
currency: purchase.currency,
|
|
55
|
+
netMinor: computation?.netMinor,
|
|
56
|
+
refundId: execution?.refundId,
|
|
57
|
+
creditNoteId: execution?.creditNoteId,
|
|
58
|
+
}) as { amountMinor: number, currency: string },
|
|
59
|
+
units: computation != null
|
|
60
|
+
? { granted: computation.reading.granted, used: computation.deducted, returned: computation.unitsReturned } : null,
|
|
61
|
+
subscriptionCanceled: execution?.subscriptionCanceled === true,
|
|
62
|
+
}, ctx)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const notifyCancellation = async (
|
|
66
|
+
declaration: ConsumerDeclarationRecord, status: CancellationStatus,
|
|
67
|
+
): Promise<boolean> => await runConsumerObservers('cancellation', declaration.id as string, declaration.entityId ?? undefined, async () => {
|
|
68
|
+
await access.observer().propagateCancellation(paymentUtils.compact({
|
|
69
|
+
cancellationId: declaration.id as string,
|
|
70
|
+
eventKey: `cancellation:${declaration.id as string}`,
|
|
71
|
+
entityId: declaration.entityId ?? undefined,
|
|
72
|
+
matched: declaration.matched,
|
|
73
|
+
channel: declaration.channel,
|
|
74
|
+
kind: declaration.cancellationKind ?? CancellationKind.Ordinary,
|
|
75
|
+
status,
|
|
76
|
+
subscriptionId: declaration.subscriptionId ?? undefined,
|
|
77
|
+
effectiveAt: declaration.effectiveAt != null ? new Date(declaration.effectiveAt) : undefined,
|
|
78
|
+
declaredAt: new Date(declaration.receivedAt),
|
|
79
|
+
}) as CancellationEvent, ctx)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const notifyConsent = async (consent: ConsumerConsentRecord): Promise<boolean> =>
|
|
83
|
+
await runConsumerObservers('consent', consent.id as string, consent.entityId, async () => {
|
|
84
|
+
await access.observer().propagateConsent(paymentUtils.compact({
|
|
85
|
+
kind: consent.kind, consentId: consent.id as string, entityId: consent.entityId, profileId: consent.profileId,
|
|
86
|
+
purchaseIds: [...consent.purchaseIds], planSku: consent.planSku, textVersion: consent.textVersion,
|
|
87
|
+
language: consent.language, decidedAt: new Date(consent.decidedAt),
|
|
88
|
+
expiresAt: consent.expiresAt != null ? new Date(consent.expiresAt) : undefined,
|
|
89
|
+
eventKey: `consent:${consent.id as string}`,
|
|
90
|
+
}) as ConsentEvent, ctx)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return { runConsumerObservers, notifyWithdrawal, notifyCancellation, notifyConsent }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The consumer-rights observers of a context — one per context. */
|
|
97
|
+
export const consumerObserversOf = memoHelper.oncePer(makeConsumerObserversHelper)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
2
|
+
import type { RequestOrigin } from '../../types.js'
|
|
3
|
+
|
|
4
|
+
/** The request evidence a consumer act is recorded with. */
|
|
5
|
+
export interface OriginHelper {
|
|
6
|
+
/**
|
|
7
|
+
* The evidence a consumer act is recorded with. `ip` is `cf-connecting-ip` (a Cloudflare edge
|
|
8
|
+
* sets it and strips a client's own), else the LAST `x-forwarded-for` entry (the one the nearest
|
|
9
|
+
* proxy appended — the first is whatever the client claimed), else `x-real-ip`, else the socket
|
|
10
|
+
* peer. The raw `x-forwarded-for`, the `user-agent` (at most 512 characters), `cf-ipcountry`
|
|
11
|
+
* (the geolocated country — second location evidence for VAT) and `accept-language` are kept as
|
|
12
|
+
* they arrived. The default `metaOf` of the consumer-rights handlers.
|
|
13
|
+
*/
|
|
14
|
+
requestOriginOf: (req: AbstractRequest) => RequestOrigin
|
|
15
|
+
/** The origin fields of a record: only those with a value. */
|
|
16
|
+
originFields: (origin: RequestOrigin | undefined) => RequestOrigin
|
|
17
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
2
|
+
import type { RequestOrigin } from '../types.js'
|
|
3
|
+
import { HEADER_MAX, USER_AGENT_MAX } from './consts.local.js'
|
|
4
|
+
import type { Headers } from './types.local.js'
|
|
5
|
+
import type { OriginHelper } from './origin/types.js'
|
|
6
|
+
|
|
7
|
+
export const createOriginHelper = (): OriginHelper => {
|
|
8
|
+
/** A header's first value (Fastify lower-cases names; a repeated header arrives as an array). */
|
|
9
|
+
const headerOf = (headers: Headers | undefined, name: string): string | undefined => {
|
|
10
|
+
const raw = headers?.[name]
|
|
11
|
+
const value = Array.isArray(raw) ? raw[0] : raw
|
|
12
|
+
if (typeof value !== 'string') {
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
15
|
+
const trimmed = value.trim()
|
|
16
|
+
|
|
17
|
+
return trimmed === '' ? undefined : trimmed
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The socket peer of the original server request, when the transport exposes one. */
|
|
21
|
+
const socketOf = (req: AbstractRequest): string | undefined => {
|
|
22
|
+
const original = req.original as {
|
|
23
|
+
socket?: { remoteAddress?: string }, raw?: { socket?: { remoteAddress?: string } }, ip?: string,
|
|
24
|
+
} | undefined
|
|
25
|
+
const address = original?.socket?.remoteAddress ?? original?.raw?.socket?.remoteAddress ?? original?.ip
|
|
26
|
+
|
|
27
|
+
return typeof address === 'string' && address !== '' ? address : undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const requestOriginOf = (req: AbstractRequest): RequestOrigin => {
|
|
31
|
+
const headers = req.headers
|
|
32
|
+
const forwardedFor = headerOf(headers, 'x-forwarded-for')
|
|
33
|
+
const forwarded = forwardedFor?.split(',').map(entry => entry.trim()).filter(entry => entry !== '')
|
|
34
|
+
const ip = headerOf(headers, 'cf-connecting-ip') ?? forwarded?.[forwarded.length - 1]
|
|
35
|
+
?? headerOf(headers, 'x-real-ip') ?? socketOf(req)
|
|
36
|
+
const userAgent = headerOf(headers, 'user-agent')
|
|
37
|
+
const ipCountry = headerOf(headers, 'cf-ipcountry')
|
|
38
|
+
const acceptLanguage = headerOf(headers, 'accept-language')
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
...(ip != null ? { ip: ip.slice(0, HEADER_MAX) } : {}),
|
|
42
|
+
...(forwardedFor != null ? { forwardedFor: forwardedFor.slice(0, HEADER_MAX) } : {}),
|
|
43
|
+
...(userAgent != null ? { userAgent: userAgent.slice(0, USER_AGENT_MAX) } : {}),
|
|
44
|
+
...(ipCountry != null && /^[A-Za-z]{2}$/.test(ipCountry) ? { ipCountry: ipCountry.toUpperCase() } : {}),
|
|
45
|
+
...(acceptLanguage != null ? { acceptLanguage: acceptLanguage.slice(0, 256) } : {}),
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const originFields = (origin: RequestOrigin | undefined): RequestOrigin => Object.fromEntries(
|
|
50
|
+
Object.entries(origin ?? {}).filter(([key, value]) =>
|
|
51
|
+
['ip', 'forwardedFor', 'userAgent', 'ipCountry', 'acceptLanguage', 'via'].includes(key)
|
|
52
|
+
&& typeof value === 'string' && value !== ''),
|
|
53
|
+
) as RequestOrigin
|
|
54
|
+
|
|
55
|
+
return { requestOriginOf, originFields }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const originHelper = createOriginHelper()
|
|
59
|
+
|
|
60
|
+
/** @deprecated compat:factory-refactor — use `originHelper.requestOriginOf(…)` */
|
|
61
|
+
export const requestOriginOf = (req: AbstractRequest): RequestOrigin => originHelper.requestOriginOf(req)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ConsumerReconcileOptions, ConsumerReconcileResult } from '../../types.js'
|
|
2
|
+
|
|
3
|
+
/** The consumer-rights repair of one service in a context. */
|
|
4
|
+
export interface ConsumerReconcileHelper {
|
|
5
|
+
/**
|
|
6
|
+
* The consumer-rights repair an application runs nightly: retry the paygate steps of withdrawals
|
|
7
|
+
* (refunds, credit notes, subscription cancels) and scheduled cancellations, failed mails and
|
|
8
|
+
* failed observers; backfill purchases of completed checkouts of the last 16 days that have no
|
|
9
|
+
* row; lock organizations that paid before countries were locked. The paygate steps, the
|
|
10
|
+
* backfill and the legacy locks need a managed service. Each step handles at most `limit` items.
|
|
11
|
+
*/
|
|
12
|
+
reconcile: (opts?: ConsumerReconcileOptions) => Promise<ConsumerReconcileResult>
|
|
13
|
+
}
|