@pithy-sh/payments 0.1.1 → 0.1.3
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/dist/admin/coverage.d.ts +35 -0
- package/dist/admin/coverage.d.ts.map +1 -0
- package/dist/admin/coverage.js +56 -0
- package/dist/admin/read.d.ts +222 -0
- package/dist/admin/read.d.ts.map +1 -0
- package/dist/admin/read.js +159 -0
- package/dist/audit/actions.d.ts +211 -0
- package/dist/audit/actions.d.ts.map +1 -0
- package/dist/audit/actions.js +211 -0
- package/dist/capability.d.ts +72 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +228 -0
- package/dist/client/api.d.ts +435 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +415 -0
- package/dist/client/checkout.d.ts +144 -0
- package/dist/client/checkout.d.ts.map +1 -0
- package/dist/client/checkout.js +173 -0
- package/dist/client/fixtures/price-preview-de.js +89 -0
- package/dist/client/fixtures/price-preview-gb.js +89 -0
- package/dist/client/fixtures/price-preview-jp-yen.js +89 -0
- package/dist/client/fixtures/price-preview-us-country-only.js +89 -0
- package/dist/client/fixtures/price-preview-us-new-york.js +89 -0
- package/dist/client/fixtures/pricePreview.d.ts +54 -0
- package/dist/client/fixtures/pricePreview.d.ts.map +1 -0
- package/dist/client/fixtures/pricePreview.js +61 -0
- package/dist/client/hooks.d.ts +235 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +428 -0
- package/dist/client/paddle.d.ts +433 -0
- package/dist/client/paddle.d.ts.map +1 -0
- package/dist/client/paddle.js +391 -0
- package/dist/client/paddleCache.d.ts +123 -0
- package/dist/client/paddleCache.d.ts.map +1 -0
- package/dist/client/paddleCache.js +159 -0
- package/dist/client/paddlePrices.d.ts +94 -0
- package/dist/client/paddlePrices.d.ts.map +1 -0
- package/dist/client/paddlePrices.js +55 -0
- package/dist/client/paddlePricesTag.d.ts +127 -0
- package/dist/client/paddlePricesTag.d.ts.map +1 -0
- package/dist/client/paddlePricesTag.js +207 -0
- package/dist/client/projection.d.ts +128 -0
- package/dist/client/projection.d.ts.map +1 -0
- package/dist/client/projection.js +0 -0
- package/dist/client/test-utils/cacheStore.d.ts +18 -0
- package/dist/client/test-utils/cacheStore.d.ts.map +1 -0
- package/dist/client/test-utils/cacheStore.js +42 -0
- package/dist/client/wholeUnits.d.ts +18 -0
- package/dist/client/wholeUnits.d.ts.map +1 -0
- package/dist/client/wholeUnits.js +120 -0
- package/dist/config/config.d.ts +238 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +249 -0
- package/dist/data/discount.d.ts +127 -0
- package/dist/data/discount.d.ts.map +1 -0
- package/dist/data/discount.js +91 -0
- package/dist/data/entitlement.d.ts +43 -0
- package/dist/data/entitlement.d.ts.map +1 -0
- package/dist/data/entitlement.js +43 -0
- package/dist/data/money.d.ts +15 -0
- package/dist/data/money.d.ts.map +1 -0
- package/dist/data/money.js +76 -0
- package/dist/data/pause.d.ts +133 -0
- package/dist/data/pause.d.ts.map +1 -0
- package/dist/data/pause.js +63 -0
- package/dist/data/providerAccount.d.ts +40 -0
- package/dist/data/providerAccount.d.ts.map +1 -0
- package/dist/data/providerAccount.js +34 -0
- package/dist/data/purchase.d.ts +107 -0
- package/dist/data/purchase.d.ts.map +1 -0
- package/dist/data/purchase.js +77 -0
- package/dist/data/rail.d.ts +74 -0
- package/dist/data/rail.d.ts.map +1 -0
- package/dist/data/rail.js +74 -0
- package/dist/data/reconcileRun.d.ts +120 -0
- package/dist/data/reconcileRun.d.ts.map +1 -0
- package/dist/data/reconcileRun.js +120 -0
- package/dist/data/renderMoney.d.ts +85 -0
- package/dist/data/renderMoney.d.ts.map +1 -0
- package/dist/data/renderMoney.js +146 -0
- package/dist/data/status.d.ts +58 -0
- package/dist/data/status.d.ts.map +1 -0
- package/dist/data/status.js +68 -0
- package/dist/data/subject.d.ts +111 -0
- package/dist/data/subject.d.ts.map +1 -0
- package/dist/data/subject.js +125 -0
- package/dist/data/subscription.d.ts +624 -0
- package/dist/data/subscription.d.ts.map +1 -0
- package/dist/data/subscription.js +497 -0
- package/dist/data/syncCursor.d.ts +33 -0
- package/dist/data/syncCursor.d.ts.map +1 -0
- package/dist/data/syncCursor.js +29 -0
- package/dist/data/tables.d.ts +37 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/data/tables.js +44 -0
- package/dist/data/webhookEvent.d.ts +134 -0
- package/dist/data/webhookEvent.d.ts.map +1 -0
- package/dist/data/webhookEvent.js +128 -0
- package/dist/entitlement/manual.d.ts +101 -0
- package/dist/entitlement/manual.d.ts.map +1 -0
- package/dist/entitlement/manual.js +84 -0
- package/dist/entitlement/resolver.d.ts +60 -0
- package/dist/entitlement/resolver.d.ts.map +1 -0
- package/dist/entitlement/resolver.js +101 -0
- package/dist/entitlement/subjectSeam.d.ts +102 -0
- package/dist/entitlement/subjectSeam.d.ts.map +1 -0
- package/dist/entitlement/subjectSeam.js +85 -0
- package/dist/error/errors.d.ts +247 -0
- package/dist/error/errors.d.ts.map +1 -0
- package/dist/error/errors.js +326 -0
- package/dist/grants/apply.d.ts +74 -0
- package/dist/grants/apply.d.ts.map +1 -0
- package/dist/grants/apply.js +148 -0
- package/dist/grants/clawback.d.ts +43 -0
- package/dist/grants/clawback.d.ts.map +1 -0
- package/dist/grants/clawback.js +71 -0
- package/dist/grants/ledgerSeam.d.ts +89 -0
- package/dist/grants/ledgerSeam.d.ts.map +1 -0
- package/dist/grants/ledgerSeam.js +66 -0
- package/dist/http/dispatch.d.ts +35 -0
- package/dist/http/dispatch.d.ts.map +1 -0
- package/dist/http/dispatch.js +40 -0
- package/dist/http/guards.d.ts +43 -0
- package/dist/http/guards.d.ts.map +1 -0
- package/dist/http/guards.js +52 -0
- package/dist/http/manifestConfig.d.ts +38 -0
- package/dist/http/manifestConfig.d.ts.map +1 -0
- package/dist/http/manifestConfig.js +49 -0
- package/dist/http/responses.d.ts +1455 -0
- package/dist/http/responses.d.ts.map +1 -0
- package/dist/http/responses.js +728 -0
- package/dist/http/routes.d.ts +315 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/routes.js +1966 -0
- package/dist/http/schemas.d.ts +404 -0
- package/dist/http/schemas.d.ts.map +1 -0
- package/dist/http/schemas.js +359 -0
- package/dist/http/scopes.d.ts +160 -0
- package/dist/http/scopes.d.ts.map +1 -0
- package/dist/http/scopes.js +240 -0
- package/dist/http/view.d.ts +96 -0
- package/dist/http/view.d.ts.map +1 -0
- package/dist/http/view.js +170 -0
- package/dist/http/webhookGuard.d.ts +109 -0
- package/dist/http/webhookGuard.d.ts.map +1 -0
- package/dist/http/webhookGuard.js +206 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/migrations/0001_purchases.d.ts +35 -0
- package/dist/migrations/0001_purchases.d.ts.map +1 -0
- package/dist/migrations/0001_purchases.js +80 -0
- package/dist/pricing/location.d.ts +138 -0
- package/dist/pricing/location.d.ts.map +1 -0
- package/dist/pricing/location.js +81 -0
- package/dist/pricing/visitor.d.ts +56 -0
- package/dist/pricing/visitor.d.ts.map +1 -0
- package/dist/pricing/visitor.js +35 -0
- package/dist/projection/event.d.ts +66 -0
- package/dist/projection/event.d.ts.map +1 -0
- package/dist/projection/event.js +45 -0
- package/dist/projection/orphans.d.ts +114 -0
- package/dist/projection/orphans.d.ts.map +1 -0
- package/dist/projection/orphans.js +162 -0
- package/dist/projection/owner.d.ts +121 -0
- package/dist/projection/owner.d.ts.map +1 -0
- package/dist/projection/owner.js +114 -0
- package/dist/projection/resolve.d.ts +30 -0
- package/dist/projection/resolve.d.ts.map +1 -0
- package/dist/projection/resolve.js +42 -0
- package/dist/projection/writer.d.ts +103 -0
- package/dist/projection/writer.d.ts.map +1 -0
- package/dist/projection/writer.js +280 -0
- package/dist/provision/resolvePaymentsConfig.d.ts +48 -0
- package/dist/provision/resolvePaymentsConfig.d.ts.map +1 -0
- package/dist/provision/resolvePaymentsConfig.js +41 -0
- package/dist/rails/apple/certs.d.ts +7 -0
- package/dist/rails/apple/certs.d.ts.map +1 -0
- package/dist/rails/apple/certs.js +8 -0
- package/dist/rails/apple/der.d.ts +107 -0
- package/dist/rails/apple/der.d.ts.map +1 -0
- package/dist/rails/apple/der.js +217 -0
- package/dist/rails/apple/fixtures/chain.d.ts +117 -0
- package/dist/rails/apple/fixtures/chain.d.ts.map +1 -0
- package/dist/rails/apple/fixtures/chain.js +289 -0
- package/dist/rails/apple/http.d.ts +74 -0
- package/dist/rails/apple/http.d.ts.map +1 -0
- package/dist/rails/apple/http.js +32 -0
- package/dist/rails/apple/jws.d.ts +17 -0
- package/dist/rails/apple/jws.d.ts.map +1 -0
- package/dist/rails/apple/jws.js +75 -0
- package/dist/rails/apple/notification.d.ts +116 -0
- package/dist/rails/apple/notification.d.ts.map +1 -0
- package/dist/rails/apple/notification.js +199 -0
- package/dist/rails/apple/rail.d.ts +25 -0
- package/dist/rails/apple/rail.d.ts.map +1 -0
- package/dist/rails/apple/rail.js +68 -0
- package/dist/rails/apple/serverApi.d.ts +120 -0
- package/dist/rails/apple/serverApi.d.ts.map +1 -0
- package/dist/rails/apple/serverApi.js +244 -0
- package/dist/rails/apple/verify.d.ts +36 -0
- package/dist/rails/apple/verify.d.ts.map +1 -0
- package/dist/rails/apple/verify.js +46 -0
- package/dist/rails/apple/x509.d.ts +85 -0
- package/dist/rails/apple/x509.d.ts.map +1 -0
- package/dist/rails/apple/x509.js +273 -0
- package/dist/rails/contract.d.ts +871 -0
- package/dist/rails/contract.d.ts.map +1 -0
- package/dist/rails/contract.js +60 -0
- package/dist/rails/google/fixtures/push.d.ts +71 -0
- package/dist/rails/google/fixtures/push.d.ts.map +1 -0
- package/dist/rails/google/fixtures/push.js +107 -0
- package/dist/rails/google/http.d.ts +77 -0
- package/dist/rails/google/http.d.ts.map +1 -0
- package/dist/rails/google/http.js +39 -0
- package/dist/rails/google/jwt.d.ts +53 -0
- package/dist/rails/google/jwt.d.ts.map +1 -0
- package/dist/rails/google/jwt.js +94 -0
- package/dist/rails/google/oidc.d.ts +112 -0
- package/dist/rails/google/oidc.d.ts.map +1 -0
- package/dist/rails/google/oidc.js +179 -0
- package/dist/rails/google/playApi.d.ts +188 -0
- package/dist/rails/google/playApi.d.ts.map +1 -0
- package/dist/rails/google/playApi.js +350 -0
- package/dist/rails/google/rail.d.ts +57 -0
- package/dist/rails/google/rail.d.ts.map +1 -0
- package/dist/rails/google/rail.js +70 -0
- package/dist/rails/google/rtdn.d.ts +105 -0
- package/dist/rails/google/rtdn.d.ts.map +1 -0
- package/dist/rails/google/rtdn.js +179 -0
- package/dist/rails/google/verify.d.ts +20 -0
- package/dist/rails/google/verify.d.ts.map +1 -0
- package/dist/rails/google/verify.js +76 -0
- package/dist/rails/lemonSqueezy/api.d.ts +92 -0
- package/dist/rails/lemonSqueezy/api.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/api.js +121 -0
- package/dist/rails/lemonSqueezy/checkout.d.ts +52 -0
- package/dist/rails/lemonSqueezy/checkout.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/checkout.js +84 -0
- package/dist/rails/lemonSqueezy/discounts.d.ts +50 -0
- package/dist/rails/lemonSqueezy/discounts.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/discounts.js +75 -0
- package/dist/rails/lemonSqueezy/fixtures/events.d.ts +56 -0
- package/dist/rails/lemonSqueezy/fixtures/events.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/fixtures/events.js +144 -0
- package/dist/rails/lemonSqueezy/objects.d.ts +229 -0
- package/dist/rails/lemonSqueezy/objects.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/objects.js +379 -0
- package/dist/rails/lemonSqueezy/portal.d.ts +35 -0
- package/dist/rails/lemonSqueezy/portal.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/portal.js +18 -0
- package/dist/rails/lemonSqueezy/pricing.d.ts +25 -0
- package/dist/rails/lemonSqueezy/pricing.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/pricing.js +54 -0
- package/dist/rails/lemonSqueezy/rail.d.ts +41 -0
- package/dist/rails/lemonSqueezy/rail.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/rail.js +67 -0
- package/dist/rails/lemonSqueezy/read.d.ts +28 -0
- package/dist/rails/lemonSqueezy/read.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/read.js +37 -0
- package/dist/rails/lemonSqueezy/refresh.d.ts +42 -0
- package/dist/rails/lemonSqueezy/refresh.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/refresh.js +40 -0
- package/dist/rails/lemonSqueezy/signature.d.ts +56 -0
- package/dist/rails/lemonSqueezy/signature.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/signature.js +92 -0
- package/dist/rails/lemonSqueezy/verify.d.ts +33 -0
- package/dist/rails/lemonSqueezy/verify.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/verify.js +41 -0
- package/dist/rails/lemonSqueezy/webhook.d.ts +53 -0
- package/dist/rails/lemonSqueezy/webhook.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/webhook.js +179 -0
- package/dist/rails/paddle/adjustments.d.ts +60 -0
- package/dist/rails/paddle/adjustments.d.ts.map +1 -0
- package/dist/rails/paddle/adjustments.js +66 -0
- package/dist/rails/paddle/api.d.ts +138 -0
- package/dist/rails/paddle/api.d.ts.map +1 -0
- package/dist/rails/paddle/api.js +152 -0
- package/dist/rails/paddle/checkout.d.ts +69 -0
- package/dist/rails/paddle/checkout.d.ts.map +1 -0
- package/dist/rails/paddle/checkout.js +100 -0
- package/dist/rails/paddle/discounts.d.ts +67 -0
- package/dist/rails/paddle/discounts.d.ts.map +1 -0
- package/dist/rails/paddle/discounts.js +73 -0
- package/dist/rails/paddle/events.d.ts +140 -0
- package/dist/rails/paddle/events.d.ts.map +1 -0
- package/dist/rails/paddle/events.js +183 -0
- package/dist/rails/paddle/fixtures/browserForged.d.ts +42 -0
- package/dist/rails/paddle/fixtures/browserForged.d.ts.map +1 -0
- package/dist/rails/paddle/fixtures/browserForged.js +52 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.d.ts +78 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.d.ts.map +1 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.js +76 -0
- package/dist/rails/paddle/objects.d.ts +519 -0
- package/dist/rails/paddle/objects.d.ts.map +1 -0
- package/dist/rails/paddle/objects.js +588 -0
- package/dist/rails/paddle/portal.d.ts +45 -0
- package/dist/rails/paddle/portal.d.ts.map +1 -0
- package/dist/rails/paddle/portal.js +42 -0
- package/dist/rails/paddle/rail.d.ts +55 -0
- package/dist/rails/paddle/rail.d.ts.map +1 -0
- package/dist/rails/paddle/rail.js +117 -0
- package/dist/rails/paddle/read.d.ts +53 -0
- package/dist/rails/paddle/read.d.ts.map +1 -0
- package/dist/rails/paddle/read.js +66 -0
- package/dist/rails/paddle/recorded.d.ts +49 -0
- package/dist/rails/paddle/recorded.d.ts.map +1 -0
- package/dist/rails/paddle/recorded.js +79 -0
- package/dist/rails/paddle/refresh.d.ts +54 -0
- package/dist/rails/paddle/refresh.d.ts.map +1 -0
- package/dist/rails/paddle/refresh.js +94 -0
- package/dist/rails/paddle/refund.d.ts +82 -0
- package/dist/rails/paddle/refund.d.ts.map +1 -0
- package/dist/rails/paddle/refund.js +175 -0
- package/dist/rails/paddle/signature.d.ts +83 -0
- package/dist/rails/paddle/signature.d.ts.map +1 -0
- package/dist/rails/paddle/signature.js +163 -0
- package/dist/rails/paddle/subscription.d.ts +137 -0
- package/dist/rails/paddle/subscription.d.ts.map +1 -0
- package/dist/rails/paddle/subscription.js +538 -0
- package/dist/rails/paddle/verify.d.ts +46 -0
- package/dist/rails/paddle/verify.d.ts.map +1 -0
- package/dist/rails/paddle/verify.js +43 -0
- package/dist/rails/paddle/webhook.d.ts +98 -0
- package/dist/rails/paddle/webhook.d.ts.map +1 -0
- package/dist/rails/paddle/webhook.js +181 -0
- package/dist/rails/providers.d.ts +73 -0
- package/dist/rails/providers.d.ts.map +1 -0
- package/dist/rails/providers.js +62 -0
- package/dist/rails/stripe/api.d.ts +118 -0
- package/dist/rails/stripe/api.d.ts.map +1 -0
- package/dist/rails/stripe/api.js +153 -0
- package/dist/rails/stripe/checkout.d.ts +60 -0
- package/dist/rails/stripe/checkout.d.ts.map +1 -0
- package/dist/rails/stripe/checkout.js +86 -0
- package/dist/rails/stripe/discounts.d.ts +50 -0
- package/dist/rails/stripe/discounts.d.ts.map +1 -0
- package/dist/rails/stripe/discounts.js +87 -0
- package/dist/rails/stripe/fixtures/events.d.ts +64 -0
- package/dist/rails/stripe/fixtures/events.d.ts.map +1 -0
- package/dist/rails/stripe/fixtures/events.js +67 -0
- package/dist/rails/stripe/objects.d.ts +237 -0
- package/dist/rails/stripe/objects.d.ts.map +1 -0
- package/dist/rails/stripe/objects.js +389 -0
- package/dist/rails/stripe/portal.d.ts +29 -0
- package/dist/rails/stripe/portal.d.ts.map +1 -0
- package/dist/rails/stripe/portal.js +41 -0
- package/dist/rails/stripe/pricing.d.ts +25 -0
- package/dist/rails/stripe/pricing.d.ts.map +1 -0
- package/dist/rails/stripe/pricing.js +68 -0
- package/dist/rails/stripe/rail.d.ts +28 -0
- package/dist/rails/stripe/rail.d.ts.map +1 -0
- package/dist/rails/stripe/rail.js +81 -0
- package/dist/rails/stripe/refresh.d.ts +33 -0
- package/dist/rails/stripe/refresh.d.ts.map +1 -0
- package/dist/rails/stripe/refresh.js +21 -0
- package/dist/rails/stripe/signature.d.ts +71 -0
- package/dist/rails/stripe/signature.d.ts.map +1 -0
- package/dist/rails/stripe/signature.js +92 -0
- package/dist/rails/stripe/verify.d.ts +15 -0
- package/dist/rails/stripe/verify.d.ts.map +1 -0
- package/dist/rails/stripe/verify.js +63 -0
- package/dist/rails/stripe/webhook.d.ts +26 -0
- package/dist/rails/stripe/webhook.d.ts.map +1 -0
- package/dist/rails/stripe/webhook.js +31 -0
- package/dist/secret/registry.d.ts +192 -0
- package/dist/secret/registry.d.ts.map +1 -0
- package/dist/secret/registry.js +154 -0
- package/dist/seeds/example.d.ts +3 -0
- package/dist/seeds/example.d.ts.map +1 -0
- package/dist/seeds/example.js +171 -0
- package/dist/version.generated.d.ts +5 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/version.generated.js +7 -0
- package/dist/workflows/paddleSweep.d.ts +175 -0
- package/dist/workflows/paddleSweep.d.ts.map +1 -0
- package/dist/workflows/paddleSweep.js +433 -0
- package/dist/workflows/railAccess.d.ts +48 -0
- package/dist/workflows/railAccess.d.ts.map +1 -0
- package/dist/workflows/railAccess.js +36 -0
- package/dist/workflows/reconcile.d.ts +161 -0
- package/dist/workflows/reconcile.d.ts.map +1 -0
- package/dist/workflows/reconcile.js +352 -0
- package/dist/workflows/report.d.ts +28 -0
- package/dist/workflows/report.d.ts.map +1 -0
- package/dist/workflows/report.js +54 -0
- package/dist/workflows/retryPolicy.d.ts +29 -0
- package/dist/workflows/retryPolicy.d.ts.map +1 -0
- package/dist/workflows/retryPolicy.js +37 -0
- package/dist/workflows/specs.d.ts +102 -0
- package/dist/workflows/specs.d.ts.map +1 -0
- package/dist/workflows/specs.js +84 -0
- package/dist/workflows/worker.d.ts +62 -0
- package/dist/workflows/worker.d.ts.map +1 -0
- package/dist/workflows/worker.js +92 -0
- package/dist/workflows/workerConfig.d.ts +46 -0
- package/dist/workflows/workerConfig.d.ts.map +1 -0
- package/dist/workflows/workerConfig.js +38 -0
- package/package.json +22 -13
- package/pithy.manifest.json +19 -13
- package/src/version.generated.ts +1 -1
- package/src/client/paddlePrices.iife.ts +0 -43
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { PaymentsPaddleCredentials } from "../../secret/registry";
|
|
2
|
+
import type { VerifiedNotification, WebhookDelivery } from "../contract";
|
|
3
|
+
import type { PaddleEnvironment } from "./api";
|
|
4
|
+
import { PaddleEvent, PaddleTransaction } from "./objects";
|
|
5
|
+
/**
|
|
6
|
+
* Verify and read one Paddle delivery, and the event map that decides what it projects.
|
|
7
|
+
*
|
|
8
|
+
* ## The event id is Paddle's own, and it is the key both paths share
|
|
9
|
+
*
|
|
10
|
+
* `evt_…`, straight off the envelope and inside the signed bytes. `UNIQUE (rail, providerEventId)` in the
|
|
11
|
+
* webhook guard is what makes a redelivery recognized rather than reprocessed, and Paddle retries — three
|
|
12
|
+
* times over fifteen minutes in sandbox, sixty times over three days live, confirmed in the docs.
|
|
13
|
+
*
|
|
14
|
+
* It is deliberately the same id the **events sweep** reads. Paddle's `/events` stream carries `event_id`
|
|
15
|
+
* and no `notification_id`, so the id a swept event reports and the id its webhook reported are the same
|
|
16
|
+
* string — which is what makes the sweep a repair rather than a second source of duplicate rows.
|
|
17
|
+
*
|
|
18
|
+
* A **replay** through Paddle's own replay endpoint creates a new *notification* against the same
|
|
19
|
+
* `event_id`, so it collides here too, which is correct: it is the same event.
|
|
20
|
+
*
|
|
21
|
+
* ## Recording is not projecting
|
|
22
|
+
*
|
|
23
|
+
* Every authentic delivery is recorded, whatever it is. What differs is what it projects, and the answer
|
|
24
|
+
* for most event types is nothing. An event type Paddle ships after this package did is authentic,
|
|
25
|
+
* recorded, projects nothing, and returns 200 — never a throw, because Paddle would redeliver it for
|
|
26
|
+
* three days.
|
|
27
|
+
*
|
|
28
|
+
* ## Adjustments, and why this rail is different
|
|
29
|
+
*
|
|
30
|
+
* As merchant of record Paddle issues refunds on its own account — for a chargeback, a tax dispute, or
|
|
31
|
+
* its own support decision. A refund therefore arrives **unsolicited**, with no local write preceding it.
|
|
32
|
+
* Every other rail in this package but Lemon Squeezy only ever sees refunds it initiated.
|
|
33
|
+
*
|
|
34
|
+
* A full refund revokes; a **partial** one records a note and revokes nothing, because a customer who got
|
|
35
|
+
* half their money back has not lost what they bought. That comparison is against the transaction's own
|
|
36
|
+
* grand total, which the adjustment does not carry — so an adjustment costs one read of the transaction,
|
|
37
|
+
* and a read that fails is `payments/provider_unavailable`, which the guard passes through so Paddle
|
|
38
|
+
* redelivers rather than the operator hunting for a rotated key.
|
|
39
|
+
*
|
|
40
|
+
* **Full means every approved adjustment summed, not this one's own total.** Paddle raises an adjustment
|
|
41
|
+
* per refund, so 99.00 refunded in two goes is two approved adjustments of 49.50 and neither reaches the
|
|
42
|
+
* grand total on its own. See `adjustments.ts`.
|
|
43
|
+
*
|
|
44
|
+
* The read is not optional, and a caller that omits it is refused rather than answered. It was optional
|
|
45
|
+
* once, and the events sweep duly forgot it: every swept adjustment then reported "this deployment cannot
|
|
46
|
+
* read the transaction", recorded itself as handled, and made the webhook redelivery of the same event a
|
|
47
|
+
* duplicate the guard skipped. A seam that silently degrades is a seam that hides a defect twice over.
|
|
48
|
+
*
|
|
49
|
+
* ## Recording is not storing whatever arrives
|
|
50
|
+
*
|
|
51
|
+
* Every payload written here goes through {@link recordedPayload}. A destination subscribed to `*` — or a
|
|
52
|
+
* sweep whose query filter was not honored — carries `client_token.created`, whose `token` Paddle does
|
|
53
|
+
* not redact. See `recorded.ts` for why the control is an allowlist here rather than a filter upstream.
|
|
54
|
+
*/
|
|
55
|
+
/** What the parser needs: the credentials, the deployment asking, the account, and the freshness window. */
|
|
56
|
+
export interface ParsePaddleNotificationOptions {
|
|
57
|
+
/** The rail's credentials. The signing secret is read from here and never logged. */
|
|
58
|
+
credentials: PaymentsPaddleCredentials;
|
|
59
|
+
/** Which Paddle account this deployment sells through. Decides every purchase's `environment`. */
|
|
60
|
+
environment: PaddleEnvironment;
|
|
61
|
+
/** The clock, for the signature's freshness window. */
|
|
62
|
+
now: Date;
|
|
63
|
+
/** This deployment's `ENVIRONMENT`, for the shared-sandbox fence. */
|
|
64
|
+
deployment?: string;
|
|
65
|
+
/** How many seconds either side of `now` a delivery may be dated. Undefined uses the rail's default. */
|
|
66
|
+
freshnessSeconds?: number;
|
|
67
|
+
/**
|
|
68
|
+
* The transaction this adjustment adjusts, or `undefined` when Paddle no longer knows it.
|
|
69
|
+
*
|
|
70
|
+
* Supplied by the rail, which owns the transport. It exists because an adjustment says how much came
|
|
71
|
+
* off and never what the original was, and "full refund" is a comparison against the original.
|
|
72
|
+
*/
|
|
73
|
+
readTransaction?: (transactionId: string) => Promise<PaddleTransaction | undefined>;
|
|
74
|
+
}
|
|
75
|
+
/** Every transaction-domain event this build maps, and whether it says anything about money. */
|
|
76
|
+
export declare const PADDLE_TRANSACTION_EVENTS: ReadonlySet<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Transaction events that project nothing at all, however well-formed.
|
|
79
|
+
*
|
|
80
|
+
* `transaction.created` and `transaction.ready` describe a transaction that exists and has taken no
|
|
81
|
+
* money. Projecting one would write an `on_hold` row for every abandoned checkout — noise the reconcile
|
|
82
|
+
* pass then re-reads forever.
|
|
83
|
+
*/
|
|
84
|
+
export declare const PADDLE_TRANSACTION_EVENTS_WITHOUT_STATE: ReadonlySet<string>;
|
|
85
|
+
/** Every subscription-domain event: the standing changed, and no money moved. */
|
|
86
|
+
export declare const PADDLE_SUBSCRIPTION_EVENTS: ReadonlySet<string>;
|
|
87
|
+
/** Every adjustment-domain event: money going back, on Paddle's own initiative. */
|
|
88
|
+
export declare const PADDLE_ADJUSTMENT_EVENTS: ReadonlySet<string>;
|
|
89
|
+
/** Verify a delivery's signature and read what it says. */
|
|
90
|
+
export declare function parsePaddleNotification(delivery: WebhookDelivery, options: ParsePaddleNotificationOptions): Promise<VerifiedNotification>;
|
|
91
|
+
/**
|
|
92
|
+
* Read one authentic event — the whole map, shared by the webhook path and the events sweep.
|
|
93
|
+
*
|
|
94
|
+
* Shared deliberately. A sweep that projected through a second code path would be a second answer to
|
|
95
|
+
* "what does this event mean", and the two would drift the first time a status was added.
|
|
96
|
+
*/
|
|
97
|
+
export declare function readPaddleEvent(event: PaddleEvent, options: ParsePaddleNotificationOptions): Promise<VerifiedNotification>;
|
|
98
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/webhook.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAA0C,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEjH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAKL,WAAW,EAEX,iBAAiB,EAGlB,MAAM,WAAW,CAAC;AAInB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,4GAA4G;AAC5G,MAAM,WAAW,8BAA8B;IAC7C,qFAAqF;IACrF,WAAW,EAAE,yBAAyB,CAAC;IACvC,kGAAkG;IAClG,WAAW,EAAE,iBAAiB,CAAC;IAC/B,uDAAuD;IACvD,GAAG,EAAE,IAAI,CAAC;IACV,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wGAAwG;IACxG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAC;CACrF;AAeD,gGAAgG;AAChG,eAAO,MAAM,yBAAyB,EAAE,WAAW,CAAC,MAAM,CASxD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,uCAAuC,EAAE,WAAW,CAAC,MAAM,CAGtE,CAAC;AAEH,iFAAiF;AACjF,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CAUzD,CAAC;AAEH,mFAAmF;AACnF,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAAyD,CAAC;AAgBnH,2DAA2D;AAC3D,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,oBAAoB,CAAC,CAqB/B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,oBAAoB,CAAC,CAqB/B"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { PaymentsRailNotConfiguredError, PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
2
|
+
import { PaddleAdjustment, PaddleEvent, PaddleSubscription, PaddleTransaction, accountReferenceOf, at, fencedOut, subscriptionEvent, transactionEvent } from "./objects.js";
|
|
3
|
+
import { RESTORING_ACTIONS, REVOKING_ACTIONS, tallyAdjustments } from "./adjustments.js";
|
|
4
|
+
import { recordedPayload } from "./recorded.js";
|
|
5
|
+
import { PADDLE_SIGNATURE_HEADER, verifyPaddleSignature } from "./signature.js";
|
|
6
|
+
//#region src/rails/paddle/webhook.ts
|
|
7
|
+
/**
|
|
8
|
+
* Which environment a purchase belongs to.
|
|
9
|
+
*
|
|
10
|
+
* The **account**, not a field on the payload. Paddle Billing partitions sandbox from live by account —
|
|
11
|
+
* separate host, separate key, separate destinations — so there is nothing in a delivery that could
|
|
12
|
+
* contradict this, and the issue's `data.mode` does not exist (on a discount, `mode` means
|
|
13
|
+
* `standard`/`custom`). A sandbox-configured deployment therefore never writes a production row, and the
|
|
14
|
+
* projection writer's own environment check does the rest.
|
|
15
|
+
*/
|
|
16
|
+
function environmentOf(account) {
|
|
17
|
+
return account === "production" ? "production" : "sandbox";
|
|
18
|
+
}
|
|
19
|
+
/** Every transaction-domain event this build maps, and whether it says anything about money. */
|
|
20
|
+
const PADDLE_TRANSACTION_EVENTS = /* @__PURE__ */ new Set([
|
|
21
|
+
"transaction.paid",
|
|
22
|
+
"transaction.completed",
|
|
23
|
+
"transaction.payment_failed",
|
|
24
|
+
"transaction.past_due",
|
|
25
|
+
"transaction.canceled",
|
|
26
|
+
"transaction.updated",
|
|
27
|
+
"transaction.revised",
|
|
28
|
+
"transaction.billed"
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* Transaction events that project nothing at all, however well-formed.
|
|
32
|
+
*
|
|
33
|
+
* `transaction.created` and `transaction.ready` describe a transaction that exists and has taken no
|
|
34
|
+
* money. Projecting one would write an `on_hold` row for every abandoned checkout — noise the reconcile
|
|
35
|
+
* pass then re-reads forever.
|
|
36
|
+
*/
|
|
37
|
+
const PADDLE_TRANSACTION_EVENTS_WITHOUT_STATE = /* @__PURE__ */ new Set(["transaction.created", "transaction.ready"]);
|
|
38
|
+
/** Every subscription-domain event: the standing changed, and no money moved. */
|
|
39
|
+
const PADDLE_SUBSCRIPTION_EVENTS = /* @__PURE__ */ new Set([
|
|
40
|
+
"subscription.created",
|
|
41
|
+
"subscription.activated",
|
|
42
|
+
"subscription.resumed",
|
|
43
|
+
"subscription.trialing",
|
|
44
|
+
"subscription.past_due",
|
|
45
|
+
"subscription.paused",
|
|
46
|
+
"subscription.canceled",
|
|
47
|
+
"subscription.updated",
|
|
48
|
+
"subscription.imported"
|
|
49
|
+
]);
|
|
50
|
+
/** Every adjustment-domain event: money going back, on Paddle's own initiative. */
|
|
51
|
+
const PADDLE_ADJUSTMENT_EVENTS = /* @__PURE__ */ new Set(["adjustment.created", "adjustment.updated"]);
|
|
52
|
+
/** Nothing at all was learned, but the delivery was authentic. */
|
|
53
|
+
function nothing(event, note) {
|
|
54
|
+
return {
|
|
55
|
+
providerEventId: event.event_id,
|
|
56
|
+
payload: recordedPayload(event),
|
|
57
|
+
event: null,
|
|
58
|
+
providerAccountId: null,
|
|
59
|
+
accountReference: null,
|
|
60
|
+
note: note ?? null
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Verify a delivery's signature and read what it says. */
|
|
64
|
+
async function parsePaddleNotification(delivery, options) {
|
|
65
|
+
await verifyPaddleSignature(delivery.body, delivery.headers.get(PADDLE_SIGNATURE_HEADER), {
|
|
66
|
+
secret: options.credentials.webhookSecret,
|
|
67
|
+
now: options.now,
|
|
68
|
+
toleranceSeconds: options.freshnessSeconds
|
|
69
|
+
});
|
|
70
|
+
let parsed;
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(delivery.body);
|
|
73
|
+
} catch (cause) {
|
|
74
|
+
throw new PaymentsVerificationFailedError({ detail: "Paddle: the delivery body is not JSON." }, { cause });
|
|
75
|
+
}
|
|
76
|
+
const envelope = PaddleEvent.safeParse(parsed);
|
|
77
|
+
if (!envelope.success) throw new PaymentsVerificationFailedError({ detail: "Paddle: the delivery is not an event envelope — no event_id, event_type, occurred_at, or data." });
|
|
78
|
+
return await readPaddleEvent(envelope.data, options);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Read one authentic event — the whole map, shared by the webhook path and the events sweep.
|
|
82
|
+
*
|
|
83
|
+
* Shared deliberately. A sweep that projected through a second code path would be a second answer to
|
|
84
|
+
* "what does this event mean", and the two would drift the first time a status was added.
|
|
85
|
+
*/
|
|
86
|
+
async function readPaddleEvent(event, options) {
|
|
87
|
+
const occurredAt = at(event.occurred_at, "an event's occurred_at");
|
|
88
|
+
const environment = environmentOf(options.environment);
|
|
89
|
+
const type = event.event_type;
|
|
90
|
+
if (PADDLE_TRANSACTION_EVENTS_WITHOUT_STATE.has(type)) return nothing(event);
|
|
91
|
+
if (PADDLE_TRANSACTION_EVENTS.has(type)) return await transactionNotification(event, occurredAt, environment, options);
|
|
92
|
+
if (PADDLE_SUBSCRIPTION_EVENTS.has(type)) return await subscriptionNotification(event, occurredAt, environment, options);
|
|
93
|
+
if (PADDLE_ADJUSTMENT_EVENTS.has(type)) return await adjustmentNotification(event, occurredAt, environment, options);
|
|
94
|
+
return nothing(event);
|
|
95
|
+
}
|
|
96
|
+
/** A transaction-domain delivery: one money row. */
|
|
97
|
+
async function transactionNotification(event, occurredAt, environment, options) {
|
|
98
|
+
const transaction = PaddleTransaction.parse(event.data);
|
|
99
|
+
if (fencedOut(transaction.custom_data, options.deployment)) return nothing(event);
|
|
100
|
+
return {
|
|
101
|
+
providerEventId: event.event_id,
|
|
102
|
+
payload: recordedPayload(event),
|
|
103
|
+
event: transactionEvent(transaction, occurredAt, environment),
|
|
104
|
+
providerAccountId: transaction.customer_id ?? null,
|
|
105
|
+
accountReference: await accountReferenceOf(transaction.custom_data, options.deployment, options.credentials.webhookSecret)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** A subscription-domain delivery: one state row. */
|
|
109
|
+
async function subscriptionNotification(event, occurredAt, environment, options) {
|
|
110
|
+
const subscription = PaddleSubscription.parse(event.data);
|
|
111
|
+
if (fencedOut(subscription.custom_data, options.deployment)) return nothing(event);
|
|
112
|
+
return {
|
|
113
|
+
providerEventId: event.event_id,
|
|
114
|
+
payload: recordedPayload(event),
|
|
115
|
+
event: subscriptionEvent(subscription, occurredAt, environment),
|
|
116
|
+
providerAccountId: subscription.customer_id ?? null,
|
|
117
|
+
accountReference: await accountReferenceOf(subscription.custom_data, options.deployment, options.credentials.webhookSecret)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* An adjustment-domain delivery — a refund, a credit, or a chargeback.
|
|
122
|
+
*
|
|
123
|
+
* **The fence here is ownership of the row, not a stamp.** An adjustment carries no `custom_data` of
|
|
124
|
+
* ours: Paddle raises it against a transaction, and the transaction is what this deployment either holds
|
|
125
|
+
* or does not. So the transaction is read back, and one it cannot read is one this deployment has no
|
|
126
|
+
* business acting on — recorded with a note, projecting nothing, on exactly the same path.
|
|
127
|
+
*/
|
|
128
|
+
async function adjustmentNotification(event, occurredAt, environment, options) {
|
|
129
|
+
const adjustment = PaddleAdjustment.parse(event.data);
|
|
130
|
+
if (adjustment.status !== "approved") return nothing(event);
|
|
131
|
+
const revoking = REVOKING_ACTIONS.has(adjustment.action);
|
|
132
|
+
const restoring = RESTORING_ACTIONS.has(adjustment.action);
|
|
133
|
+
if (!revoking && !restoring) return nothing(event);
|
|
134
|
+
if (options.readTransaction === void 0) throw new PaymentsRailNotConfiguredError({ detail: `Paddle adjustment ${adjustment.id} needs transaction ${adjustment.transaction_id} to tell a full refund from a partial one, and this caller supplied no transaction reader.` });
|
|
135
|
+
const transaction = await options.readTransaction(adjustment.transaction_id);
|
|
136
|
+
if (transaction === void 0) return nothing(event, { read: `Paddle adjustment ${adjustment.id} names transaction ${adjustment.transaction_id}, which this deployment cannot read.` });
|
|
137
|
+
if (fencedOut(transaction.custom_data, options.deployment)) return nothing(event);
|
|
138
|
+
const base = transactionEvent(transaction, occurredAt, environment);
|
|
139
|
+
if (restoring) return projected(event, {
|
|
140
|
+
...base,
|
|
141
|
+
revokedAt: null
|
|
142
|
+
}, transaction.customer_id ?? null);
|
|
143
|
+
const tally = tallyAdjustments(adjustment, transaction);
|
|
144
|
+
if (!tally.full) return nothing(event, { stated: `Paddle adjustment ${adjustment.id} (${adjustment.action}) brings transaction ${adjustment.transaction_id} to ${tally.revokedMinor ?? "an unreadable amount"} adjusted across ${tally.counted} adjustment(s), of a ${tally.totalMinor ?? "unreadable"} total. Recorded; the entitlement stands.` });
|
|
145
|
+
return projected(event, {
|
|
146
|
+
...base,
|
|
147
|
+
status: "refunded",
|
|
148
|
+
revokedAt: occurredAt,
|
|
149
|
+
expiresAt: occurredAt
|
|
150
|
+
}, transaction.customer_id ?? null, revocationOf(base, occurredAt));
|
|
151
|
+
}
|
|
152
|
+
/** The state event a full refund of a subscription's transaction implies, or null for a one-off. */
|
|
153
|
+
function revocationOf(charge, occurredAt) {
|
|
154
|
+
const subscriptionId = charge.originalTransactionId;
|
|
155
|
+
if (subscriptionId === null || subscriptionId === void 0) return null;
|
|
156
|
+
return {
|
|
157
|
+
...charge,
|
|
158
|
+
providerTransactionId: subscriptionId,
|
|
159
|
+
originalTransactionId: subscriptionId,
|
|
160
|
+
role: "state",
|
|
161
|
+
status: "revoked",
|
|
162
|
+
revokedAt: occurredAt,
|
|
163
|
+
expiresAt: occurredAt,
|
|
164
|
+
amountMinor: null,
|
|
165
|
+
currency: null,
|
|
166
|
+
providerEventAt: occurredAt
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** One projected notification, with the reference read off the transaction that carried the stamp. */
|
|
170
|
+
function projected(event, projection, customerId, stateEvent = null) {
|
|
171
|
+
return {
|
|
172
|
+
providerEventId: event.event_id,
|
|
173
|
+
payload: recordedPayload(event),
|
|
174
|
+
event: projection,
|
|
175
|
+
providerAccountId: customerId,
|
|
176
|
+
accountReference: null,
|
|
177
|
+
stateEvent
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
export { PADDLE_ADJUSTMENT_EVENTS, PADDLE_SUBSCRIPTION_EVENTS, PADDLE_TRANSACTION_EVENTS, PADDLE_TRANSACTION_EVENTS_WITHOUT_STATE, parsePaddleNotification, readPaddleEvent };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { PaymentsConfig } from "../config/config";
|
|
2
|
+
import type { PaymentsRail } from "../data/rail";
|
|
3
|
+
import { type PaymentsProviderCredentials } from "../secret/registry";
|
|
4
|
+
import type { AppleHttpFetch } from "./apple/http";
|
|
5
|
+
import type { PaymentsRailProvider } from "./contract";
|
|
6
|
+
import type { GoogleHttpFetch } from "./google/http";
|
|
7
|
+
import type { GoogleJwk } from "./google/oidc";
|
|
8
|
+
import type { LemonSqueezyHttpFetch } from "./lemonSqueezy/api";
|
|
9
|
+
import type { PaddleHttpFetch } from "./paddle/api";
|
|
10
|
+
import type { StripeHttpFetch } from "./stripe/api";
|
|
11
|
+
/**
|
|
12
|
+
* Which rails this build can speak to, and how one is resolved for a request.
|
|
13
|
+
*
|
|
14
|
+
* This is the single composition point. A rail arrives as one entry here plus its module — nothing else in
|
|
15
|
+
* the package counts rails, and nothing branches on how many there are.
|
|
16
|
+
*
|
|
17
|
+
* **Two independent conditions, one answer.** A rail may be off in `pithy.config.ts`, or its credentials may
|
|
18
|
+
* never have been provisioned, or this build may not implement it yet. All three are
|
|
19
|
+
* `payments/rail_not_configured` (404), because from the caller's side they are the same statement — that
|
|
20
|
+
* payment method is not available here — and distinguishing them in a response would describe our deployment
|
|
21
|
+
* to a stranger. `detail` distinguishes them for the operator, which is where the distinction is useful.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The per-rail verification seams a caller may supply. Two kinds, and both are narrow on purpose.
|
|
25
|
+
*
|
|
26
|
+
* **Trust is additive only**, so nothing here can narrow production's trust: extra roots and extra keys are
|
|
27
|
+
* *added* to each rail's pinned set, and a payload the extras do not cover is still checked against the store's
|
|
28
|
+
* own. Each exists for callers with genuinely non-store signing material — the tests, which mint their own so
|
|
29
|
+
* verification is exercised for real rather than stubbed, and the local development tools that do the same:
|
|
30
|
+
* Xcode's StoreKit testing signs with a per-machine root, and a Pub/Sub emulator signs with a key Google never
|
|
31
|
+
* saw.
|
|
32
|
+
*
|
|
33
|
+
* **Transport is a seam rather than a policy.** Google's rail cannot verify offline — Play hands out pointers,
|
|
34
|
+
* not signed state — so it must reach the network, and a network call that could not be substituted could only be
|
|
35
|
+
* tested through a stub of the module under test. One explicit parameter, defaulting to the runtime's `fetch`.
|
|
36
|
+
* Every rail now has one, because every rail reaches its store on the reconciliation path even where it verifies
|
|
37
|
+
* offline: a subscription nobody was notified about can only be learned by asking.
|
|
38
|
+
*
|
|
39
|
+
* **The two batch tokens are a cost seam, not a trust one.** Apple's API token and Google's OAuth token are each
|
|
40
|
+
* bought with a signature and a round-trip, so a reconciliation pass over hundreds of purchases mints one and
|
|
41
|
+
* passes it down rather than paying twice per purchase. They are parameters rather than a module cache because a
|
|
42
|
+
* bearer credential derived from a secret is exactly what CLAUDE.md forbids caching in a module variable.
|
|
43
|
+
*/
|
|
44
|
+
export interface RailTrustOptions {
|
|
45
|
+
/** Roots the Apple rail accepts in addition to Apple's pinned ones, base64 DER. */
|
|
46
|
+
appleTrustedRoots?: readonly string[];
|
|
47
|
+
/** The HTTP transport the Apple rail reaches the App Store Server API through. Defaults to `fetch`. */
|
|
48
|
+
appleTransport?: AppleHttpFetch;
|
|
49
|
+
/** An App Store Connect token already minted, so a batch of Apple refreshes pays for one. */
|
|
50
|
+
appleApiToken?: string;
|
|
51
|
+
/** Keys the Google rail accepts in addition to Google's published set, matched by `kid`. */
|
|
52
|
+
googleTrustedKeys?: readonly GoogleJwk[];
|
|
53
|
+
/** The HTTP transport the Google rail reaches Google's endpoints through. Defaults to `fetch`. */
|
|
54
|
+
googleTransport?: GoogleHttpFetch;
|
|
55
|
+
/** A Play access token already minted, so a batch of Google refreshes pays for one. */
|
|
56
|
+
googleAccessToken?: string;
|
|
57
|
+
/** The HTTP transport the Stripe rail reaches Stripe's API through. Defaults to `fetch`. */
|
|
58
|
+
stripeTransport?: StripeHttpFetch;
|
|
59
|
+
/** The HTTP transport the Lemon Squeezy rail reaches its API through. Defaults to `fetch`. */
|
|
60
|
+
lemonSqueezyTransport?: LemonSqueezyHttpFetch;
|
|
61
|
+
/** The HTTP transport the Paddle rail reaches its API through. Defaults to `fetch`. */
|
|
62
|
+
paddleTransport?: PaddleHttpFetch;
|
|
63
|
+
}
|
|
64
|
+
/** The rails this build can serve at all, whatever a project's config says. */
|
|
65
|
+
export declare function implementedRails(): readonly PaymentsRail[];
|
|
66
|
+
/**
|
|
67
|
+
* The provider for one rail, or a 404.
|
|
68
|
+
*
|
|
69
|
+
* Config is checked before credentials, so a project that has not enabled a rail never triggers a credential
|
|
70
|
+
* read for it — a read is a Secrets Store round-trip, and a disabled rail should not cost one.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveRailProvider(rail: PaymentsRail, config: PaymentsConfig, credentials: PaymentsProviderCredentials, trust?: RailTrustOptions): PaymentsRailProvider;
|
|
73
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/rails/providers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,KAAK,2BAA2B,EAAmB,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,uGAAuG;IACvG,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,6FAA6F;IAC7F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,iBAAiB,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACzC,kGAAkG;IAClG,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4FAA4F;IAC5F,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,8FAA8F;IAC9F,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,uFAAuF;IACvF,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAgED,+EAA+E;AAC/E,wBAAgB,gBAAgB,IAAI,SAAS,YAAY,EAAE,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,cAAc,EACtB,WAAW,EAAE,2BAA2B,EACxC,KAAK,GAAE,gBAAqB,GAC3B,oBAAoB,CAatB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { productForProviderSku, railEnabled } from "../config/config.js";
|
|
2
|
+
import { PaymentsRailNotConfiguredError } from "../error/errors.js";
|
|
3
|
+
import { railCredentials } from "../secret/registry.js";
|
|
4
|
+
import { appleRail } from "./apple/rail.js";
|
|
5
|
+
import { googleRail } from "./google/rail.js";
|
|
6
|
+
import { lemonSqueezyRail } from "./lemonSqueezy/rail.js";
|
|
7
|
+
import { paddleRail } from "./paddle/rail.js";
|
|
8
|
+
import { stripeRail } from "./stripe/rail.js";
|
|
9
|
+
//#region src/rails/providers.ts
|
|
10
|
+
/**
|
|
11
|
+
* Every rail this build implements. A rail arrives as one entry here plus its module; an entry with no module
|
|
12
|
+
* behind it would be a rail that reports itself available and then fails, which is worse than one that reports
|
|
13
|
+
* itself absent.
|
|
14
|
+
*/
|
|
15
|
+
const RAIL_FACTORIES = {
|
|
16
|
+
apple: (credentials, trust) => appleRail(railCredentials(credentials, "apple"), {
|
|
17
|
+
trustedRoots: trust.appleTrustedRoots,
|
|
18
|
+
transport: trust.appleTransport,
|
|
19
|
+
apiToken: trust.appleApiToken
|
|
20
|
+
}),
|
|
21
|
+
google: (credentials, trust) => googleRail(railCredentials(credentials, "google"), {
|
|
22
|
+
trustedKeys: trust.googleTrustedKeys,
|
|
23
|
+
transport: trust.googleTransport,
|
|
24
|
+
accessToken: trust.googleAccessToken
|
|
25
|
+
}),
|
|
26
|
+
stripe: (credentials, trust) => stripeRail(railCredentials(credentials, "stripe"), { transport: trust.stripeTransport }),
|
|
27
|
+
lemonSqueezy: (credentials, trust, config) => lemonSqueezyRail(railCredentials(credentials, "lemonSqueezy"), {
|
|
28
|
+
transport: trust.lemonSqueezyTransport,
|
|
29
|
+
sellsSubscription: (variantId) => productForProviderSku(config, "lemonSqueezy", variantId)?.product.type === "subscription",
|
|
30
|
+
storeCurrency: config.lemonSqueezy?.storeCurrency
|
|
31
|
+
}),
|
|
32
|
+
paddle: (credentials, trust, config) => {
|
|
33
|
+
const settings = config.paddle;
|
|
34
|
+
if (settings === void 0) throw new PaymentsRailNotConfiguredError({ detail: "The paddle rail is on with no `paddle` settings block. Declare `clientToken`, `environment`, and `successUrl`." });
|
|
35
|
+
return paddleRail(railCredentials(credentials, "paddle"), {
|
|
36
|
+
environment: settings.environment,
|
|
37
|
+
clientToken: settings.clientToken,
|
|
38
|
+
checkout: settings.checkout,
|
|
39
|
+
freshnessSeconds: settings.webhookFreshnessSeconds,
|
|
40
|
+
storeCurrency: settings.storeCurrency,
|
|
41
|
+
transport: trust.paddleTransport
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/** The rails this build can serve at all, whatever a project's config says. */
|
|
46
|
+
function implementedRails() {
|
|
47
|
+
return Object.keys(RAIL_FACTORIES);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The provider for one rail, or a 404.
|
|
51
|
+
*
|
|
52
|
+
* Config is checked before credentials, so a project that has not enabled a rail never triggers a credential
|
|
53
|
+
* read for it — a read is a Secrets Store round-trip, and a disabled rail should not cost one.
|
|
54
|
+
*/
|
|
55
|
+
function resolveRailProvider(rail, config, credentials, trust = {}) {
|
|
56
|
+
if (!railEnabled(config, rail)) throw new PaymentsRailNotConfiguredError({ detail: `The ${rail} rail is off in this project's config. Set \`rails.${rail}: true\` and redeploy.` });
|
|
57
|
+
const factory = RAIL_FACTORIES[rail];
|
|
58
|
+
if (!factory) throw new PaymentsRailNotConfiguredError({ detail: `This build of @pithy-sh/payments implements ${implementedRails().join(", ")}, not ${rail}.` });
|
|
59
|
+
return factory(credentials, trust, config);
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { implementedRails, resolveRailProvider };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one door out to Stripe, and the mapping from how it answered to what that means.
|
|
3
|
+
*
|
|
4
|
+
* Stripe is reached with `fetch` and form encoding rather than through the `stripe` npm package, deliberately.
|
|
5
|
+
* Three calls are needed for hosted-only payments — create a Checkout Session, create a Billing Portal session,
|
|
6
|
+
* retrieve a Checkout Session — and each is one form POST or GET. The SDK would add a dependency with its own
|
|
7
|
+
* runtime shims, its own retry policy, and its own idea of what an error is, to save perhaps forty lines. Every
|
|
8
|
+
* other third-party API in this repo is spoken to the same way: `fetch` out, Zod in.
|
|
9
|
+
*
|
|
10
|
+
* **The API version is pinned.** Stripe decides response shapes from the *account's* default version unless a
|
|
11
|
+
* request names one, so an account upgraded in the dashboard would silently change what this code parses. Pinning
|
|
12
|
+
* it here means an upgrade is a deliberate edit with a test run behind it. Webhook payload shapes are a separate
|
|
13
|
+
* matter — those follow the endpoint's own configured version, which is why `objects.ts` accepts both spellings of
|
|
14
|
+
* the fields Stripe has moved.
|
|
15
|
+
*
|
|
16
|
+
* ## How an answer is read
|
|
17
|
+
*
|
|
18
|
+
* **A 5xx or a 429 is `payments/provider_unavailable` (503).** Stripe is up but not answering, or is asking us to
|
|
19
|
+
* slow down. The caller retries and the reconciliation pass covers whatever a retry never fixes.
|
|
20
|
+
*
|
|
21
|
+
* **Every other 4xx is `payments/rail_not_configured` (404), and that is the deliberate part.** A 4xx from Stripe
|
|
22
|
+
* is never the buyer's fault — we build these requests entirely from config and from rows we wrote, so "No such
|
|
23
|
+
* price", "No such customer", a rejected key, and a missing Billing Portal configuration are all one statement:
|
|
24
|
+
* this project's Stripe rail is not set up to do what it was asked. 503 would tell a caller to retry something
|
|
25
|
+
* that will never succeed; 400 would blame a request the caller did not make. 404 says the payment method is not
|
|
26
|
+
* available here, which is true, and `detail` carries Stripe's own sentence for the operator who can fix it.
|
|
27
|
+
*
|
|
28
|
+
* **A 404 is an absent resource only for a caller that said it was probing.** `absentOn404` is how a Checkout
|
|
29
|
+
* Session retrieve distinguishes "no such session" from "our Stripe account is wrong", and only a caller that
|
|
30
|
+
* knows the difference may claim it.
|
|
31
|
+
*
|
|
32
|
+
* **Nothing in a refusal carries the secret key.** Stripe redacts keys in its own messages, but `detail` is
|
|
33
|
+
* written to an operator's logs, so anything key-shaped in a message is redacted again here before it gets there.
|
|
34
|
+
*/
|
|
35
|
+
/** Stripe's REST base. Public and stable, so it is pinned rather than configured. */
|
|
36
|
+
export declare const STRIPE_API_BASE = "https://api.stripe.com/v1";
|
|
37
|
+
/**
|
|
38
|
+
* The API version every request pins.
|
|
39
|
+
*
|
|
40
|
+
* To move it: read Stripe's changelog for the shape changes between the two, adjust `objects.ts`, run the suite,
|
|
41
|
+
* and change this line. Never bump it to match an account — the point of pinning is that the account cannot
|
|
42
|
+
* decide what this code parses.
|
|
43
|
+
*/
|
|
44
|
+
export declare const STRIPE_API_VERSION = "2025-04-30.basil";
|
|
45
|
+
/** One outbound request, narrowed to what Stripe's three endpoints need. */
|
|
46
|
+
export interface StripeHttpRequest {
|
|
47
|
+
/** The HTTP method. */
|
|
48
|
+
method?: string;
|
|
49
|
+
/** Request headers — the bearer key, the pinned version, and a form content type on a POST. */
|
|
50
|
+
headers?: Record<string, string>;
|
|
51
|
+
/** The form-encoded body, on a POST. */
|
|
52
|
+
body?: string;
|
|
53
|
+
}
|
|
54
|
+
/** The response shape this module reads. Structural, so a test's transport need not be a whole `Response`. */
|
|
55
|
+
export interface StripeHttpResponse {
|
|
56
|
+
/** Whether the status is 2xx. */
|
|
57
|
+
ok: boolean;
|
|
58
|
+
/** The status code, which is what decides the mapping. */
|
|
59
|
+
status: number;
|
|
60
|
+
/** The body as text. Read as text rather than JSON so a non-JSON answer is a diagnosis, not a throw. */
|
|
61
|
+
text(): Promise<string>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The HTTP seam for Stripe's endpoints.
|
|
65
|
+
*
|
|
66
|
+
* Injectable for one reason: **no test may reach a live Stripe account**, and a rail whose network call could not
|
|
67
|
+
* be substituted would have to be tested through a stub of itself. One explicit parameter beats reassigning a
|
|
68
|
+
* global, which leaks between suites and hides which module was exercised.
|
|
69
|
+
*/
|
|
70
|
+
export type StripeHttpFetch = (url: string, init?: StripeHttpRequest) => Promise<StripeHttpResponse>;
|
|
71
|
+
/** The default transport: the runtime's own `fetch`. */
|
|
72
|
+
export declare const stripeHttpFetch: StripeHttpFetch;
|
|
73
|
+
/** A value Stripe's form encoding can carry. Nested objects and arrays become bracketed keys. */
|
|
74
|
+
export type StripeFormValue = string | number | boolean | null | undefined | StripeFormObject | StripeFormValue[];
|
|
75
|
+
/** One level of a Stripe form body. */
|
|
76
|
+
export interface StripeFormObject {
|
|
77
|
+
[key: string]: StripeFormValue;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Encode a nested object the way Stripe's API reads a form body: `line_items[0][price]=price_1`.
|
|
81
|
+
*
|
|
82
|
+
* `URLSearchParams` alone cannot produce that, which is the whole reason this exists. `undefined` and `null` are
|
|
83
|
+
* dropped rather than sent empty, because Stripe reads an empty value as "unset this field" — so omitting an
|
|
84
|
+
* optional parameter and sending it blank are two different requests.
|
|
85
|
+
*/
|
|
86
|
+
export declare function stripeForm(input: StripeFormObject): string;
|
|
87
|
+
/** What one request is for, and how its answers should be read. */
|
|
88
|
+
export interface StripeJsonOptions {
|
|
89
|
+
/** What is being fetched, in a `detail` line: "a Checkout Session". Never the URL, never the body. */
|
|
90
|
+
what: string;
|
|
91
|
+
/** The Stripe secret key. Read through the secrets store by the caller, never off an env binding. */
|
|
92
|
+
secretKey: string;
|
|
93
|
+
/** The form body. Its presence is what makes the request a POST. */
|
|
94
|
+
form?: StripeFormObject;
|
|
95
|
+
/** Query parameters, encoded in Stripe's own bracket notation — `expand[0]=subscription`. */
|
|
96
|
+
query?: StripeFormObject;
|
|
97
|
+
/**
|
|
98
|
+
* Whether a 404 means "no such resource" rather than a misconfigured account. Set only by a caller that is
|
|
99
|
+
* deliberately probing for something that may legitimately not exist.
|
|
100
|
+
*/
|
|
101
|
+
absentOn404?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* One request to Stripe, and its parsed JSON body — or `undefined` when a 404 was a legitimate answer.
|
|
105
|
+
*
|
|
106
|
+
* The body comes back as `unknown`. Reaching an endpoint proves who answered, never what they said, so every
|
|
107
|
+
* caller Zod-parses its own shape.
|
|
108
|
+
*/
|
|
109
|
+
export declare function stripeJson(transport: StripeHttpFetch, path: string, options: StripeJsonOptions): Promise<unknown | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* Blank out anything key-shaped in text bound for a log.
|
|
112
|
+
*
|
|
113
|
+
* Stripe already redacts keys in its messages, so this is belt and braces — but `detail` is written to an
|
|
114
|
+
* operator's logs and read by whoever has them, and a credential that reaches one has to be rotated. Cheap
|
|
115
|
+
* insurance against a message format changing.
|
|
116
|
+
*/
|
|
117
|
+
export declare function redactStripeSecrets(text: string): string;
|
|
118
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/api.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,qFAAqF;AACrF,eAAO,MAAM,eAAe,8BAA8B,CAAC;AAE3D;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AAErD,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,8GAA8G;AAC9G,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,EAAE,EAAE,OAAO,CAAC;IACZ,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,wGAAwG;IACxG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAErG,wDAAwD;AACxD,eAAO,MAAM,eAAe,EAAE,eAC8B,CAAC;AAE7D,iGAAiG;AACjG,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,gBAAgB,GAAG,eAAe,EAAE,CAAC;AAElH,uCAAuC;AACvC,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAI1D;AAED,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,sGAAsG;IACtG,IAAI,EAAE,MAAM,CAAC;IACb,qGAAqG;IACrG,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,6FAA6F;IAC7F,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAkBD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAsC9B;AAiCD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKxD"}
|