@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,228 @@
|
|
|
1
|
+
import { PaymentsConfig } from "./config/config.js";
|
|
2
|
+
import { paymentsTables } from "./data/tables.js";
|
|
3
|
+
import { installEntitlementResolver } from "./entitlement/resolver.js";
|
|
4
|
+
import { paymentsManifestConfig } from "./http/manifestConfig.js";
|
|
5
|
+
import { paymentsSecretsRegistry } from "./secret/registry.js";
|
|
6
|
+
import { paymentsWorkflows } from "./workflows/specs.js";
|
|
7
|
+
import { paymentsAdminRoutes } from "./http/scopes.js";
|
|
8
|
+
import { registerPaymentsRoutes } from "./http/routes.js";
|
|
9
|
+
import { payments_0001_purchases } from "./migrations/0001_purchases.js";
|
|
10
|
+
import { paymentsExampleSeed } from "./seeds/example.js";
|
|
11
|
+
import { PACKAGE_VERSION } from "./version.generated.js";
|
|
12
|
+
import { defineCapability } from "@pithy-sh/core/src/capability/capability";
|
|
13
|
+
import { ValidationError } from "@pithy-sh/core/src/error/pithyError";
|
|
14
|
+
import { workflowBindings } from "@pithy-sh/core/src/workflow/bindings";
|
|
15
|
+
//#region src/capability.ts
|
|
16
|
+
/**
|
|
17
|
+
* Where payments' migrations sort in the app database. Unique per database; the registry composes keys
|
|
18
|
+
* like `1000_payments_0001_purchases`. Sits after vector (900), and was `NEXT_FREE_ORDER` when it was
|
|
19
|
+
* taken — see `packages/cli/src/migrations/orders.test.ts`, which is the only place an order is allocated.
|
|
20
|
+
*/
|
|
21
|
+
const PAYMENTS_MIGRATION_ORDER = 1e3;
|
|
22
|
+
/** The database name every capability sharing the app D1 coordinates on. `DB` is the binding. */
|
|
23
|
+
const PAYMENTS_DATABASE_NAME = "app";
|
|
24
|
+
/** Whether a composed capability is the ledger, carrying its parsed currency set. */
|
|
25
|
+
function isLedgerPeer(capability) {
|
|
26
|
+
return capability.name === "ledger" && "ledgerConfig" in capability;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validate every `grants.currency` against the composed ledger, at assembly.
|
|
30
|
+
*
|
|
31
|
+
* `openLedger` validates nothing — it is a primitive, and `credit()` on an unconfigured currency happily
|
|
32
|
+
* opens a real account row. Nobody can reach that row: the ledger's own routes resolve a currency from config
|
|
33
|
+
* and 404 an unknown code, so the balance exists, is correct, and is invisible. The player is told their
|
|
34
|
+
* purchase worked. A typo in a currency code is therefore a defect that produces no error anywhere at
|
|
35
|
+
* runtime, which makes the deploy the only place left to catch it.
|
|
36
|
+
*
|
|
37
|
+
* Every mismatch is reported in one message rather than the first, because an operator fixing one typo per
|
|
38
|
+
* deploy is a bad afternoon.
|
|
39
|
+
*/
|
|
40
|
+
function checkLedgerGrants({ capabilities }, config) {
|
|
41
|
+
const granting = Object.entries(config.products).flatMap(([id, product]) => product.grants?.ledger === void 0 ? [] : [{
|
|
42
|
+
id,
|
|
43
|
+
currency: product.grants.ledger.currency
|
|
44
|
+
}]);
|
|
45
|
+
if (granting.length === 0) return;
|
|
46
|
+
if (config.billingSubject !== "user") throw new ValidationError({
|
|
47
|
+
message: "This catalog credits a balance, and this project bills organizations.",
|
|
48
|
+
action: "Set `billingSubject: \"user\"`, or drop the `grants` clause from the products that credit a balance.",
|
|
49
|
+
detail: `@pithy-sh/ledger keys every account on a user id and every route it serves reads one, so there is no account an organization's credit could land in that anything would read. Products with a \`grants.ledger\` clause: ${granting.map((entry) => entry.id).join(", ")}.`
|
|
50
|
+
});
|
|
51
|
+
const peer = capabilities.find(isLedgerPeer);
|
|
52
|
+
if (!peer) throw new ValidationError({
|
|
53
|
+
message: "This catalog credits a balance, and no ledger is composed.",
|
|
54
|
+
action: "Add `ledger(...)` to this Worker's capabilities, or drop the `grants` clause from the product.",
|
|
55
|
+
detail: `Products with a \`grants.ledger\` clause: ${granting.map((entry) => entry.id).join(", ")}. Crediting needs @pithy-sh/ledger composed in the same Worker.`
|
|
56
|
+
});
|
|
57
|
+
const declared = new Set(peer.ledgerConfig.currencies.map((currency) => currency.code));
|
|
58
|
+
const unknown = granting.filter((entry) => !declared.has(entry.currency));
|
|
59
|
+
if (unknown.length === 0) return;
|
|
60
|
+
throw new ValidationError({
|
|
61
|
+
message: "A product grants a currency the ledger does not have.",
|
|
62
|
+
action: "Add the currency to the ledger's `currencies`, or correct the product's `grants.ledger.currency`.",
|
|
63
|
+
detail: `${unknown.map((entry) => `product "${entry.id}" grants "${entry.currency}"`).join("; ")}. The ledger declares: ${[...declared].sort().join(", ") || "nothing"}.`
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Refuse the one composition that can never entitle anybody: organization billing with no resolver.
|
|
68
|
+
*
|
|
69
|
+
* **A throw at assembly, not a `pithy doctor` finding**, and the difference from the entitlement-gap check
|
|
70
|
+
* is where the evidence lives. That check must read the adopter's *route code* to know whether anything
|
|
71
|
+
* gates at all, which is a question no capability can ask about itself — so it belongs to a tool that reads
|
|
72
|
+
* the project. This one needs nothing but the two arguments already in hand: `billingSubject` from the
|
|
73
|
+
* config being parsed on the line above, and `resolveSubject` from the same call. Where a capability can
|
|
74
|
+
* see the whole fault by itself, it says so at the deploy, which is what `checkLedgerGrants` does two
|
|
75
|
+
* functions down and for the same reason.
|
|
76
|
+
*
|
|
77
|
+
* And the fault is total. Under `"organization"` there is no default resolver — deliberately, because a
|
|
78
|
+
* capability that guessed would key a company's plan to whoever logged in first — so with none supplied
|
|
79
|
+
* `resolvePaymentsSubject` answers nobody for every request. Every entitlement gate denies, every write
|
|
80
|
+
* raises `payments/subject_unresolved`, and both look exactly like a customer who has not paid. There is no
|
|
81
|
+
* request that ever works, so there is nothing to lose by refusing to boot, and a Worker that boots into
|
|
82
|
+
* that state is one whose first symptom is a support ticket from a paying company.
|
|
83
|
+
*/
|
|
84
|
+
function requireResolvableSubject(config, resolveSubject) {
|
|
85
|
+
if (config.billingSubject !== "organization" || resolveSubject !== void 0) return;
|
|
86
|
+
throw new ValidationError({
|
|
87
|
+
message: "This project bills organizations, and nothing can say which one a caller is acting for.",
|
|
88
|
+
action: "Pass `resolveSubject` to `payments(...)` in this Worker's pithy.config.ts, or set `billingSubject: \"user\"`.",
|
|
89
|
+
detail: "billingSubject is \"organization\" and no subject resolver was supplied. Payments has no members table and never guesses a holder, so every entitlement gate would deny and every write would raise payments/subject_unresolved, for every caller, forever."
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What a browser may know about this project's payments — the `virtual:pithy/payments` module.
|
|
94
|
+
*
|
|
95
|
+
* The list is short and each entry earns its place. **Enabled rails**, so a paywall can show an Apple-only
|
|
96
|
+
* product as owned-elsewhere rather than offering a buy button nothing on the web can honor. **The base
|
|
97
|
+
* path**, because the client calls these routes. And **per product** its id, type, entitlement keys,
|
|
98
|
+
* display name, and its SKU on each web rail — a price id is publishable by design, since it is the thing
|
|
99
|
+
* a checkout names and the store's own page shows back to the buyer. Plus, for Paddle, the three facts
|
|
100
|
+
* Paddle.js needs to initialize: the publishable client token, the account, and the display mode.
|
|
101
|
+
*
|
|
102
|
+
* **Nothing else can cross, and not merely by discipline.** Apple's issuer id and key, Google's
|
|
103
|
+
* service-account credentials, and Stripe's secret and webhook signing keys live in the secrets store
|
|
104
|
+
* behind `paymentsSecretsRegistry` — they are not in the config this closure can see, so there is no
|
|
105
|
+
* expression here that would reach them. What discipline does cover is the rest of the catalog: a
|
|
106
|
+
* product's Apple and Google SKUs stay server-side because a browser has no use for them, and the
|
|
107
|
+
* `grants` block stays server-side because a currency code and an amount describe the economy.
|
|
108
|
+
* `capability.test.ts` locks the key set and sweeps the serialized result for every credential shape.
|
|
109
|
+
*
|
|
110
|
+
* `?? null`, never `undefined`: the projection is inlined into a bundle with `JSON.stringify`, which
|
|
111
|
+
* drops an undefined value and leaves the screen reading a key that is simply absent.
|
|
112
|
+
*
|
|
113
|
+
* An empty catalog projects `{ enabled: false }`. A screen branches on `enabled` rather than guarding, so
|
|
114
|
+
* "composed with nothing to sell" must read the same as "not composed" — both are a paywall with nothing
|
|
115
|
+
* on it.
|
|
116
|
+
*
|
|
117
|
+
* The return type is {@link PaymentsClientProjection}, and the catalog's element type is
|
|
118
|
+
* {@link PaymentsClientProduct} — **declared, not inferred**. `ClientProjection` is `{ enabled: boolean }`
|
|
119
|
+
* plus a JSON catchall, which accepts anything this function could return. The declared types are what
|
|
120
|
+
* make a dropped field a compile error here rather than a browser's problem, and what make a fourth
|
|
121
|
+
* product kind or a fourth Paddle checkout mode in `PaymentsConfig` a red line here rather than a silent
|
|
122
|
+
* widening of what every adopter's bundle carries. The element type is annotated
|
|
123
|
+
* separately because the `.map` is where inference is weakest: it would take the shape of whatever the
|
|
124
|
+
* first product happened to be.
|
|
125
|
+
*/
|
|
126
|
+
function clientProjection(config, environment) {
|
|
127
|
+
const products = Object.entries(config.products).map(([id, product]) => ({
|
|
128
|
+
id,
|
|
129
|
+
type: product.type,
|
|
130
|
+
entitlements: [...product.entitlements],
|
|
131
|
+
name: product.name,
|
|
132
|
+
skus: {
|
|
133
|
+
stripe: product.stripe?.priceId ?? null,
|
|
134
|
+
lemonSqueezy: product.lemonSqueezy?.variantId ?? null,
|
|
135
|
+
paddle: product.paddle?.priceId ?? null
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
if (products.length === 0) return { enabled: false };
|
|
139
|
+
return {
|
|
140
|
+
enabled: true,
|
|
141
|
+
environment,
|
|
142
|
+
rails: {
|
|
143
|
+
apple: config.rails.apple,
|
|
144
|
+
google: config.rails.google,
|
|
145
|
+
stripe: config.rails.stripe,
|
|
146
|
+
lemonSqueezy: config.rails.lemonSqueezy,
|
|
147
|
+
paddle: config.rails.paddle
|
|
148
|
+
},
|
|
149
|
+
basePath: config.basePath,
|
|
150
|
+
paddle: config.paddle === void 0 ? null : {
|
|
151
|
+
clientToken: config.paddle.clientToken,
|
|
152
|
+
environment: config.paddle.environment,
|
|
153
|
+
checkout: config.paddle.checkout
|
|
154
|
+
},
|
|
155
|
+
products
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Three rails — Apple, Google, Stripe — projecting onto one cross-rail entitlement, in the adopter's own
|
|
160
|
+
* D1. The catalog is config, not rows: a product's entitlement mapping is policy, so it is diffable in
|
|
161
|
+
* git and not mutable at runtime.
|
|
162
|
+
*
|
|
163
|
+
* `providesEntitlements` is what makes payments the seam's provider, and it is read in two places. At
|
|
164
|
+
* runtime the middleware below replaces core's fail-closed `noEntitlementProvider` with the D1-backed
|
|
165
|
+
* resolver. At development time `pithy doctor` and `pithy dev` read the flag to answer a question no
|
|
166
|
+
* amount of runtime care can: a Worker whose routes call `requireEntitlement()` while composing no
|
|
167
|
+
* provider is not broken, it is silently paywalled shut, and the seam's own fail-closed default makes
|
|
168
|
+
* that indistinguishable from a user who has not bought anything.
|
|
169
|
+
*
|
|
170
|
+
* `dependsOn: ["secrets"]` is real. Every rail's credentials are read through the aggregated secret
|
|
171
|
+
* registry, so a project composing payments without `@pithy-sh/secrets` must fail at assembly rather
|
|
172
|
+
* than at the first receipt. Auth is *not* listed — it is a seam: under `billingSubject: "user"` a purchase
|
|
173
|
+
* scopes to the authenticated caller, so with no auth capability composed every route denies, which is the
|
|
174
|
+
* right failure and needs no dependency edge. `@pithy-sh/ledger` is likewise a seam, reached through one
|
|
175
|
+
* guarded dynamic import and only for products whose catalog entry declares `grants`. Both belong in the
|
|
176
|
+
* manifest's `optionalCapabilities`.
|
|
177
|
+
*
|
|
178
|
+
* Under `billingSubject: "organization"` the holder is not the caller and cannot be derived from them, so
|
|
179
|
+
* the adopter supplies `resolveSubject` and a composition without one is refused outright — see
|
|
180
|
+
* {@link requireResolvableSubject}.
|
|
181
|
+
*/
|
|
182
|
+
function payments(options) {
|
|
183
|
+
const { resolveSubject, ...catalog } = options;
|
|
184
|
+
const resolved = PaymentsConfig.parse(catalog);
|
|
185
|
+
requireResolvableSubject(resolved, resolveSubject);
|
|
186
|
+
const subject = {
|
|
187
|
+
billingSubject: resolved.billingSubject,
|
|
188
|
+
...resolveSubject ? { resolveSubject } : {}
|
|
189
|
+
};
|
|
190
|
+
const migrations = { "0001_purchases": payments_0001_purchases };
|
|
191
|
+
const requiredBindings = [{
|
|
192
|
+
type: "d1",
|
|
193
|
+
name: "DB"
|
|
194
|
+
}, ...workflowBindings(paymentsWorkflows)];
|
|
195
|
+
const capability = defineCapability({
|
|
196
|
+
name: "payments",
|
|
197
|
+
version: PACKAGE_VERSION,
|
|
198
|
+
dependsOn: ["secrets"],
|
|
199
|
+
providesEntitlements: true,
|
|
200
|
+
secretRegistry: paymentsSecretsRegistry,
|
|
201
|
+
workflows: paymentsWorkflows,
|
|
202
|
+
compose: (context) => checkLedgerGrants(context, resolved),
|
|
203
|
+
client: ({ environment }) => clientProjection(resolved, environment),
|
|
204
|
+
requiredBindings,
|
|
205
|
+
config: PaymentsConfig,
|
|
206
|
+
databases: { [PAYMENTS_DATABASE_NAME]: {
|
|
207
|
+
binding: "DB",
|
|
208
|
+
tables: paymentsTables(),
|
|
209
|
+
migrationOrder: PAYMENTS_MIGRATION_ORDER,
|
|
210
|
+
migrations
|
|
211
|
+
} },
|
|
212
|
+
middleware: [installEntitlementResolver(PAYMENTS_DATABASE_NAME, subject)],
|
|
213
|
+
adminRoutes: paymentsAdminRoutes(resolved.basePath),
|
|
214
|
+
manifestConfig: paymentsManifestConfig(resolved.billingSubject),
|
|
215
|
+
routes: registerPaymentsRoutes({
|
|
216
|
+
config: resolved,
|
|
217
|
+
subject
|
|
218
|
+
}),
|
|
219
|
+
seeds: [paymentsExampleSeed]
|
|
220
|
+
});
|
|
221
|
+
return Object.assign(capability, { paymentsConfig: resolved });
|
|
222
|
+
}
|
|
223
|
+
/** Whether a capability is the payments capability — carries its resolved catalog. */
|
|
224
|
+
function isPaymentsCapability(capability) {
|
|
225
|
+
return capability.name === "payments" && "paymentsConfig" in capability;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { PAYMENTS_MIGRATION_ORDER, isPaymentsCapability, payments };
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The framework-free half of the client surface: five calls against this project's own payments routes,
|
|
3
|
+
* and the guards that make their answers safe to read.
|
|
4
|
+
*
|
|
5
|
+
* **This module lives in the package on purpose.** `pithy ui add` writes a screen once and may never
|
|
6
|
+
* rewrite it, and a frozen paywall ages badly — store rules move under it, so price-change consent
|
|
7
|
+
* prompts, external purchase link entitlements, and subscription-management requirements all arrive
|
|
8
|
+
* after the file was written. So the calls, the error mapping, and the redirect-and-return dance ship
|
|
9
|
+
* here and upgrade with a minor release; the scaffolded stub renders and styles, and calls these.
|
|
10
|
+
*
|
|
11
|
+
* **Cookie/session, same origin.** Every request carries `credentials: "include"` and nothing else. No
|
|
12
|
+
* token in `localStorage` or `sessionStorage`, no `Authorization` header, no refresh rotation. The SPA
|
|
13
|
+
* and its Worker share an origin, so the session rides an httpOnly cookie that JavaScript cannot read
|
|
14
|
+
* and the server's same-origin check covers CSRF. Bearer is the mobile path — supported by the same
|
|
15
|
+
* routes, documented rather than scaffolded.
|
|
16
|
+
*
|
|
17
|
+
* **Nothing here throws, and nothing here hides a failure either.** An unreachable Worker, an HTML error
|
|
18
|
+
* page from a proxy, a 500 — each becomes a renderable {@link PaymentsFailure} on a `PaymentsResult`, and
|
|
19
|
+
* every reader answers one. Failing shut is a decision for a caller to make and to write down: a route
|
|
20
|
+
* guard does `result.ok && result.value.some(…)`, a screen that names the plan reports the failure
|
|
21
|
+
* instead. A reader that collapsed the two would make the choice for callers that must not have it made
|
|
22
|
+
* for them, which is what `api.test.ts` now holds the module to.
|
|
23
|
+
*
|
|
24
|
+
* The server's `requireEntitlement()` is still the security boundary. Nothing on this side of the wire
|
|
25
|
+
* protects a feature; it only decides what a screen shows.
|
|
26
|
+
*
|
|
27
|
+
* **No absolute URL literals, and no schema library.** Paths are relative, so the calls follow whatever
|
|
28
|
+
* origin the bundle is served from. Answers are narrowed by hand-written `is…(value: unknown): value is T`
|
|
29
|
+
* guards rather than Zod: this file is compiled into a browser bundle, and it must not drag the server's
|
|
30
|
+
* schema graph in behind it.
|
|
31
|
+
*/
|
|
32
|
+
/** Where the payments routes mount by default — the same default `PaymentsConfig.basePath` carries. */
|
|
33
|
+
export declare const PAYMENTS_BASE_PATH = "/payments";
|
|
34
|
+
/**
|
|
35
|
+
* The query parameter a returning Stripe buyer carries the Checkout Session id in.
|
|
36
|
+
*
|
|
37
|
+
* It is a default, not a rule: `config.stripe.successUrl` is the adopter's own URL, and the documented
|
|
38
|
+
* shape puts `{CHECKOUT_SESSION_ID}` in `?session=`. A project that named it something else passes the
|
|
39
|
+
* name to {@link returnedCheckoutSession}.
|
|
40
|
+
*/
|
|
41
|
+
export declare const CHECKOUT_SESSION_PARAM = "session";
|
|
42
|
+
/**
|
|
43
|
+
* The wire unions, declared literally rather than imported from `../data/*`.
|
|
44
|
+
*
|
|
45
|
+
* Those modules pull core's codecs and Zod into whatever TypeScript program typechecks this file, and
|
|
46
|
+
* this file is typechecked inside an adopter's DOM-typed *browser* program, where the Worker's type
|
|
47
|
+
* graph does not belong. `api.test.ts` pins each of these against the schema it mirrors, so the
|
|
48
|
+
* duplication cannot drift.
|
|
49
|
+
*/
|
|
50
|
+
export type PaymentsClientRail = "apple" | "google" | "stripe" | "lemonSqueezy" | "paddle";
|
|
51
|
+
/**
|
|
52
|
+
* The rails that create a hosted checkout a browser can be sent to.
|
|
53
|
+
*
|
|
54
|
+
* A strict subset of {@link PaymentsClientRail}: Apple and Google purchases happen inside a store SDK, so
|
|
55
|
+
* there is no page to send anyone to. Nameable from a browser because a rail decides *who takes the money*,
|
|
56
|
+
* not how much or on whose behalf — a paywall for a product sold on both can put two buttons on the page,
|
|
57
|
+
* and a product sold on one needs no field at all.
|
|
58
|
+
*/
|
|
59
|
+
export type PaymentsHostedRail = "stripe" | "lemonSqueezy" | "paddle";
|
|
60
|
+
/**
|
|
61
|
+
* The runtime mirror of {@link PaymentsHostedRail} — and the one list a screen gates a billing button on.
|
|
62
|
+
*
|
|
63
|
+
* Exported rather than private, because the screens need it. A scaffolded subscription page shows
|
|
64
|
+
* "Manage billing" when any hosted rail is on, and a scaffolded paywall offers to sell on any hosted
|
|
65
|
+
* rail a product is listed on: both are the same question, and both were open-coding the answer. A rail
|
|
66
|
+
* added to the package now reaches a template that was copied into an adopter's repo a year ago,
|
|
67
|
+
* because the template imports this rather than repeating it.
|
|
68
|
+
*
|
|
69
|
+
* Selling and portal-minting are one list, not two that agree — `CheckoutRail` declares both methods
|
|
70
|
+
* together, so a rail cannot have one without the other. `../data/rail.ts` carries the argument in full,
|
|
71
|
+
* and `providers.test.ts` holds this list to the rails that actually implement the interface.
|
|
72
|
+
*/
|
|
73
|
+
export declare const PAYMENTS_HOSTED_RAILS: readonly PaymentsHostedRail[];
|
|
74
|
+
/** Which Paddle account a handoff belongs to. `Paddle.Environment.set` takes it verbatim. */
|
|
75
|
+
export type PaymentsPaddleEnvironment = "sandbox" | "production";
|
|
76
|
+
/** Whether a Paddle checkout opens over the page or inside a container the screen provides. */
|
|
77
|
+
export type PaymentsPaddleDisplayMode = "overlay" | "inline";
|
|
78
|
+
/**
|
|
79
|
+
* How the browser reaches checkout — a page to go to, or a transaction to open in place.
|
|
80
|
+
*
|
|
81
|
+
* A union rather than `{ url }`, because one rail has no URL to give: Paddle's overlay and inline modes
|
|
82
|
+
* never leave this page. A screen narrows on `kind`, which is a compile error where it is missing rather
|
|
83
|
+
* than a runtime navigation to an empty string.
|
|
84
|
+
*/
|
|
85
|
+
export type PaymentsCheckoutHandoff = {
|
|
86
|
+
kind: "redirect";
|
|
87
|
+
url: string;
|
|
88
|
+
} | PaddleCheckoutHandoff;
|
|
89
|
+
/**
|
|
90
|
+
* The handoff a Paddle checkout returns: a transaction, and what a browser needs to open it.
|
|
91
|
+
*
|
|
92
|
+
* Named rather than inlined because a screen holds one — `useCheckout` exposes it, and a `Paddle.Checkout
|
|
93
|
+
* .open` call site needs a type to write against.
|
|
94
|
+
*/
|
|
95
|
+
export interface PaddleCheckoutHandoff {
|
|
96
|
+
/** Discriminates this from a redirect. */
|
|
97
|
+
kind: "paddle";
|
|
98
|
+
/** The transaction the server created — `txn_…`. */
|
|
99
|
+
transactionId: string;
|
|
100
|
+
/** Paddle's publishable client token, which is designed to reach a browser. */
|
|
101
|
+
clientToken: string;
|
|
102
|
+
/** Which Paddle account the token belongs to. */
|
|
103
|
+
environment: PaymentsPaddleEnvironment;
|
|
104
|
+
/** Whether the checkout opens over the page or inside a container. */
|
|
105
|
+
displayMode: PaymentsPaddleDisplayMode;
|
|
106
|
+
/**
|
|
107
|
+
* Where a buyer who paid is sent, from `config.paddle.successUrl`.
|
|
108
|
+
*
|
|
109
|
+
* **On the handoff rather than in the screen's hands, and that is the same rule the redirect rails
|
|
110
|
+
* follow.** `settings.successUrl` is a URL the browser is sent to with a completed purchase behind it;
|
|
111
|
+
* a screen that could name it could send a paying customer to a page it controls. So it comes from the
|
|
112
|
+
* server, on the response, exactly as a Stripe session's return URLs do — and it is checked here as a
|
|
113
|
+
* navigable URL before anything hands it to Paddle.
|
|
114
|
+
*/
|
|
115
|
+
successUrl: string;
|
|
116
|
+
}
|
|
117
|
+
/** One subscription's authenticated portal deep links. */
|
|
118
|
+
export interface PaymentsPortalSubscription {
|
|
119
|
+
/** The store's own subscription id. */
|
|
120
|
+
subscriptionId: string;
|
|
121
|
+
/** Where this subscription is canceled. */
|
|
122
|
+
cancel: string;
|
|
123
|
+
/** Where this subscription's payment method is changed. */
|
|
124
|
+
updatePaymentMethod: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The caller's billing portal: an overview page, and any per-subscription deep links the store minted.
|
|
128
|
+
*
|
|
129
|
+
* **Every URL here is a bearer credential for that customer's billing.** Paddle's overview link carries a
|
|
130
|
+
* token good for 24 hours with scopes covering subscription updates and transaction creation, so a screen
|
|
131
|
+
* navigates to one and never stores it, logs it, or puts it in a query string something else will read.
|
|
132
|
+
*/
|
|
133
|
+
export interface PaymentsPortalHandoff {
|
|
134
|
+
/** The portal's overview page. */
|
|
135
|
+
url: string;
|
|
136
|
+
/** Per-subscription deep links, for the store that offers them. */
|
|
137
|
+
subscriptions?: readonly PaymentsPortalSubscription[];
|
|
138
|
+
}
|
|
139
|
+
/** What kind of thing a product is, as a browser reads it. */
|
|
140
|
+
export type PaymentsClientProductType = "consumable" | "non_consumable" | "subscription";
|
|
141
|
+
/** The normalized purchase status, as a browser reads it. */
|
|
142
|
+
export type PaymentsClientStatus = "active" | "in_grace" | "on_hold" | "canceled" | "expired" | "never_paid" | "refunded" | "revoked" | "paused";
|
|
143
|
+
/** Which store environment a purchase happened in, as a browser reads it. */
|
|
144
|
+
export type PaymentsClientEnvironment = "production" | "sandbox";
|
|
145
|
+
/** One entitlement as `GET /payments/entitlements` returns it. */
|
|
146
|
+
export interface EntitlementView {
|
|
147
|
+
/** The entitlement key gating code names — `pro`, never a SKU. */
|
|
148
|
+
key: string;
|
|
149
|
+
/** Whether it grants access right now. The server rechecks expiry on every read. */
|
|
150
|
+
granted: boolean;
|
|
151
|
+
/** When it lapses, as an ISO string, or null for one that never does. */
|
|
152
|
+
expiresAt: string | null;
|
|
153
|
+
}
|
|
154
|
+
/** One purchase as the write routes return it. Deliberately not the row — a client has no use for its own receipt. */
|
|
155
|
+
export interface PurchaseView {
|
|
156
|
+
/** The purchase's id. */
|
|
157
|
+
id: string;
|
|
158
|
+
/** Which store it came from. */
|
|
159
|
+
rail: PaymentsClientRail;
|
|
160
|
+
/** The logical catalog product id. */
|
|
161
|
+
productId: string;
|
|
162
|
+
/** What kind of product it is. */
|
|
163
|
+
type: PaymentsClientProductType;
|
|
164
|
+
/** The normalized status. */
|
|
165
|
+
status: PaymentsClientStatus;
|
|
166
|
+
/** Which store environment it happened in. */
|
|
167
|
+
environment: PaymentsClientEnvironment;
|
|
168
|
+
/** When the store recorded it, as an ISO string. */
|
|
169
|
+
purchasedAt: string;
|
|
170
|
+
/** When access lapses, as an ISO string, or null. */
|
|
171
|
+
expiresAt: string | null;
|
|
172
|
+
/**
|
|
173
|
+
* When a paused subscription resumes, as an ISO string, or null.
|
|
174
|
+
*
|
|
175
|
+
* Null means two different things and `status` tells them apart: with `paused`, the store put no end on
|
|
176
|
+
* the pause; with anything else, the subscription is not paused. A screen that renders "paused until"
|
|
177
|
+
* has to branch on both.
|
|
178
|
+
*/
|
|
179
|
+
resumesAt: string | null;
|
|
180
|
+
/** What this submission did to the projection. `ignored` is a replay, and a replay is a success. */
|
|
181
|
+
outcome: "created" | "updated" | "ignored";
|
|
182
|
+
}
|
|
183
|
+
/** A refusal a screen can render: the namespaced code, the public message, and what to do next. */
|
|
184
|
+
export interface PaymentsFailure {
|
|
185
|
+
/** The namespaced code — `payments/product_not_found`, or a `client/*` sentinel this module minted. */
|
|
186
|
+
code: string;
|
|
187
|
+
/** The public message. The server's `detail` never crosses the HTTP codec, so this is all there is. */
|
|
188
|
+
message: string;
|
|
189
|
+
/** What to do next, when the server offered one. */
|
|
190
|
+
action: string | null;
|
|
191
|
+
/**
|
|
192
|
+
* The values a translating client interpolates into its own wording for `code`, when the server sent
|
|
193
|
+
* any.
|
|
194
|
+
*
|
|
195
|
+
* **Carried because the documented contract is `t.maybe(code, params) ?? message`**, and a decoder
|
|
196
|
+
* that drops `params` makes the first half of it a lie: `interpolate` leaves an unsupplied
|
|
197
|
+
* placeholder exactly as written, so a screen renders `That board does not exist: {board}.` — worse
|
|
198
|
+
* than the English it was trying to improve on. No kit throw site passes `params` today, which is
|
|
199
|
+
* precisely why this is easy to leave out and expensive to notice later.
|
|
200
|
+
*/
|
|
201
|
+
params?: Record<string, string | number | boolean>;
|
|
202
|
+
}
|
|
203
|
+
/** Either the value, or a failure to render. Never a throw. */
|
|
204
|
+
export type PaymentsResult<T> = {
|
|
205
|
+
ok: true;
|
|
206
|
+
value: T;
|
|
207
|
+
} | {
|
|
208
|
+
ok: false;
|
|
209
|
+
failure: PaymentsFailure;
|
|
210
|
+
};
|
|
211
|
+
/** What `POST /payments/purchases` answers with. */
|
|
212
|
+
export interface PurchaseReceipt {
|
|
213
|
+
/** The purchase as it now stands. */
|
|
214
|
+
purchase: PurchaseView;
|
|
215
|
+
/** The caller's entitlements after the write, so a screen needs no second round trip. */
|
|
216
|
+
entitlements: readonly EntitlementView[];
|
|
217
|
+
}
|
|
218
|
+
/** What `POST /payments/restore` answers with. */
|
|
219
|
+
export interface RestoredPurchases {
|
|
220
|
+
/** Every purchase the batch projected. */
|
|
221
|
+
purchases: readonly PurchaseView[];
|
|
222
|
+
/** The caller's entitlements after the restore. */
|
|
223
|
+
entitlements: readonly EntitlementView[];
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The slice of `fetch` this module uses, declared structurally.
|
|
227
|
+
*
|
|
228
|
+
* Not `typeof fetch`: the package compiles against `@cloudflare/workers-types`, whose `RequestInit` has
|
|
229
|
+
* no `credentials` — and `credentials: "include"` is the entire cookie story. Declaring the shape keeps
|
|
230
|
+
* one signature true in a Worker-typed program, in a browser, and in a test that injects a stub.
|
|
231
|
+
*/
|
|
232
|
+
export interface PaymentsRequestInit {
|
|
233
|
+
/** The HTTP method. Absent means GET. */
|
|
234
|
+
method?: string;
|
|
235
|
+
/** Request headers. */
|
|
236
|
+
headers?: Record<string, string>;
|
|
237
|
+
/** The JSON body, already serialized. */
|
|
238
|
+
body?: string;
|
|
239
|
+
/** Cookie policy. Always `include` here — same-origin, httpOnly session cookie. */
|
|
240
|
+
credentials?: "include" | "same-origin" | "omit";
|
|
241
|
+
}
|
|
242
|
+
/** The slice of `Response` this module reads. */
|
|
243
|
+
export interface PaymentsResponse {
|
|
244
|
+
/** Whether the status was 2xx. */
|
|
245
|
+
ok: boolean;
|
|
246
|
+
/** The HTTP status. */
|
|
247
|
+
status: number;
|
|
248
|
+
/** The parsed body, or a rejection when it was not JSON. */
|
|
249
|
+
json(): Promise<unknown>;
|
|
250
|
+
}
|
|
251
|
+
/** A fetch this module can call. */
|
|
252
|
+
export type PaymentsFetch = (input: string, init?: PaymentsRequestInit) => Promise<PaymentsResponse>;
|
|
253
|
+
/** Leaving the page for a hosted Stripe flow. */
|
|
254
|
+
export type Navigate = (url: string) => void;
|
|
255
|
+
/**
|
|
256
|
+
* The browser globals this module reaches for, as an injectable seam.
|
|
257
|
+
*
|
|
258
|
+
* Reached through an object rather than `window` because the package compiles in a program with no DOM
|
|
259
|
+
* lib, alongside the Worker code — the same collision `@pithy-sh/ui-react` keeps a second tsconfig to
|
|
260
|
+
* avoid. Injecting it is also what lets a test prove the no-browser path without a DOM.
|
|
261
|
+
*/
|
|
262
|
+
export interface PaymentsGlobal {
|
|
263
|
+
/** The browser's fetch. */
|
|
264
|
+
fetch?: PaymentsFetch;
|
|
265
|
+
/** The browser's location — read for the return query string, called to leave for a hosted page. */
|
|
266
|
+
location?: {
|
|
267
|
+
search?: string;
|
|
268
|
+
assign?: (url: string) => void;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/** What every call takes: where the routes are, and the seams a test replaces. */
|
|
272
|
+
export interface PaymentsClientOptions {
|
|
273
|
+
/** Where the payments routes mount. Defaults to {@link PAYMENTS_BASE_PATH}. */
|
|
274
|
+
basePath?: string;
|
|
275
|
+
/** The fetch to use. Defaults to the one on {@link PaymentsClientOptions.global}. */
|
|
276
|
+
fetch?: PaymentsFetch;
|
|
277
|
+
/** How to leave for a hosted page. Defaults to the browser's own `location.assign`. */
|
|
278
|
+
navigate?: Navigate;
|
|
279
|
+
/** The global object the defaults come off. Defaults to `globalThis`. */
|
|
280
|
+
global?: PaymentsGlobal;
|
|
281
|
+
}
|
|
282
|
+
/** The worker could not be reached at all. Offline, or a DNS failure, or a hard CORS refusal. */
|
|
283
|
+
export declare const PAYMENTS_UNREACHABLE: PaymentsFailure;
|
|
284
|
+
/** The worker answered with something this client cannot read. A proxy's HTML page, or a shape change. */
|
|
285
|
+
export declare const PAYMENTS_UNREADABLE: PaymentsFailure;
|
|
286
|
+
/** There is no browser here to send anywhere — server-side rendering, or a test with no DOM. */
|
|
287
|
+
export declare const PAYMENTS_NO_BROWSER: PaymentsFailure;
|
|
288
|
+
/** Whether a value is one entitlement as the route returns it. */
|
|
289
|
+
export declare function isEntitlementView(value: unknown): value is EntitlementView;
|
|
290
|
+
/** Whether a value is one purchase as the write routes return it. */
|
|
291
|
+
export declare function isPurchaseView(value: unknown): value is PurchaseView;
|
|
292
|
+
/**
|
|
293
|
+
* One call: same-origin, cookie-carrying, never throwing. **The only producer of that request.**
|
|
294
|
+
*
|
|
295
|
+
* The body is read before the status is judged, because a refusal's body is the failure a screen renders.
|
|
296
|
+
* A body that will not parse is the generic failure rather than a crash — a corporate proxy's HTML page
|
|
297
|
+
* reaches a browser far more often than anyone expects.
|
|
298
|
+
*
|
|
299
|
+
* **Exported, and that is the point of it.** This was private, so `../pricing/visitor.ts` wrote a second
|
|
300
|
+
* fetch with the same base-path default, the same `credentials: "include"`, and the same three failure
|
|
301
|
+
* directions — two producers of one rule, which is the shape of every recurring defect this kit has
|
|
302
|
+
* shipped. The second producer is always the cheap one to add and the one that drifts. Every browser
|
|
303
|
+
* program that asks this Worker a question calls this, and `sameOrigin.test.ts` fails the build on any
|
|
304
|
+
* module that grows its own (#346).
|
|
305
|
+
*
|
|
306
|
+
* **Zod-free, like everything on this side of the wire.** The answer is narrowed by the hand-written
|
|
307
|
+
* `guard` a caller passes, never by a schema: this compiles into an adopter's browser bundle, and
|
|
308
|
+
* dragging the Worker's schema graph in behind it would break their build.
|
|
309
|
+
*/
|
|
310
|
+
export declare function callPayments<T>(path: string, init: PaymentsRequestInit, options: PaymentsClientOptions | undefined, guard: (value: unknown) => value is T): Promise<PaymentsResult<T>>;
|
|
311
|
+
/**
|
|
312
|
+
* The caller's own entitlements. Always the caller's — the id comes from the session, never from here.
|
|
313
|
+
*
|
|
314
|
+
* **A failure is not an empty list**, and the distinction is the whole point of the return type. Failing
|
|
315
|
+
* shut is still the right default for a *lock*, because a lock is a refusal and the caller can carry an
|
|
316
|
+
* escape route on it. It is wrong for a caller that **names** the plan: free is the floor of every ladder,
|
|
317
|
+
* carrying no entitlement key and matching unconditionally, so `[]` is a positive assertion that this
|
|
318
|
+
* customer is on the cheapest tier. A screen rendering that from a failed read tells an Enterprise
|
|
319
|
+
* customer they are on Free and offers to sell them what they already pay for.
|
|
320
|
+
*
|
|
321
|
+
* So the failure `call` already built travels out intact, and a caller that wants fail-shut writes
|
|
322
|
+
* `result.ok ? result.value : []` — one line, and it reads as the decision it is rather than as the
|
|
323
|
+
* absence of one. {@link useEntitlement} does exactly that; {@link useSubscription} reports the failure.
|
|
324
|
+
*/
|
|
325
|
+
export declare function getEntitlements(options?: PaymentsClientOptions): Promise<PaymentsResult<readonly EntitlementView[]>>;
|
|
326
|
+
/**
|
|
327
|
+
* Submit one receipt for verification, so the buyer sees their entitlement without waiting for the webhook.
|
|
328
|
+
*
|
|
329
|
+
* On the web this is the Stripe return path: `successUrl` carries the Checkout Session id, and posting it
|
|
330
|
+
* here projects the purchase at once. On a native client it is the store SDK's transaction. A replay by
|
|
331
|
+
* its own owner is a 200 with `outcome: "ignored"` — the write path is idempotent, so repeating is free.
|
|
332
|
+
*/
|
|
333
|
+
export declare function submitPurchase(input: {
|
|
334
|
+
rail: PaymentsClientRail;
|
|
335
|
+
receipt: string;
|
|
336
|
+
}, options?: PaymentsClientOptions): Promise<PaymentsResult<PurchaseReceipt>>;
|
|
337
|
+
/**
|
|
338
|
+
* Restore Purchases — rebind a store account's history to the signed-in user.
|
|
339
|
+
*
|
|
340
|
+
* Native only in practice: only the device can enumerate what its store account owns. One bad receipt
|
|
341
|
+
* fails the whole batch by design, and every receipt that did project stays projected.
|
|
342
|
+
*/
|
|
343
|
+
export declare function restorePurchases(input: {
|
|
344
|
+
rail: PaymentsClientRail;
|
|
345
|
+
receipts: readonly string[];
|
|
346
|
+
}, options?: PaymentsClientOptions): Promise<PaymentsResult<RestoredPurchases>>;
|
|
347
|
+
/** Create a checkout for a product, and say how the browser reaches it. */
|
|
348
|
+
export declare function createCheckout(input: {
|
|
349
|
+
productId: string;
|
|
350
|
+
rail?: PaymentsHostedRail;
|
|
351
|
+
discountCode?: string;
|
|
352
|
+
}, options?: PaymentsClientOptions): Promise<PaymentsResult<PaymentsCheckoutHandoff>>;
|
|
353
|
+
/**
|
|
354
|
+
* Create a Billing Portal session for the caller's own store account.
|
|
355
|
+
*
|
|
356
|
+
* No body, and that is the request contract: there is exactly one customer this caller may manage, and
|
|
357
|
+
* the server resolves it from the provider-account map. A `customer` field here would be the whole
|
|
358
|
+
* vulnerability.
|
|
359
|
+
*/
|
|
360
|
+
export declare function createPortal(options?: PaymentsClientOptions): Promise<PaymentsResult<PaymentsPortalHandoff>>;
|
|
361
|
+
/**
|
|
362
|
+
* What starting a checkout did. Three outcomes, and a screen must tell them apart.
|
|
363
|
+
*
|
|
364
|
+
* `left` is a redirect rail: the browser is already going, and there is nothing to render. `paddle` is a
|
|
365
|
+
* rail with nowhere to go — the screen opens the handoff with Paddle.js, over its own page. `refused` is
|
|
366
|
+
* a failure worth showing.
|
|
367
|
+
*
|
|
368
|
+
* Deliberately not `PaymentsFailure | null` any more. That shape could only say "went" or "did not", and
|
|
369
|
+
* a Paddle handoff is neither: collapsing it into `null` would leave a buyer on a paywall whose button
|
|
370
|
+
* silently did nothing.
|
|
371
|
+
*/
|
|
372
|
+
export type PaymentsCheckoutStart = {
|
|
373
|
+
kind: "left";
|
|
374
|
+
} | {
|
|
375
|
+
kind: "paddle";
|
|
376
|
+
handoff: PaddleCheckoutHandoff;
|
|
377
|
+
} | {
|
|
378
|
+
kind: "refused";
|
|
379
|
+
failure: PaymentsFailure;
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Buy a product: create the checkout, and either hand the browser over or hand the caller the handoff.
|
|
383
|
+
*
|
|
384
|
+
* A redirect rail needs no SDK script and no client-side key — the server mints a session and answers
|
|
385
|
+
* with a URL, and a full page load is the whole integration. Paddle's overlay and inline modes need
|
|
386
|
+
* Paddle.js and the publishable token the server returned, and opening it is the screen's job because
|
|
387
|
+
* that is where the container lives. Pithy never owns payment UI, SCA, tax, or proration either way.
|
|
388
|
+
*/
|
|
389
|
+
export declare function startCheckout(input: {
|
|
390
|
+
productId: string;
|
|
391
|
+
rail?: PaymentsHostedRail;
|
|
392
|
+
discountCode?: string;
|
|
393
|
+
}, options?: PaymentsClientOptions): Promise<PaymentsCheckoutStart>;
|
|
394
|
+
/** Open the billing portal — where a subscriber changes a card, or cancels, under the store's own rules. */
|
|
395
|
+
export declare function openBillingPortal(options?: PaymentsClientOptions): Promise<PaymentsFailure | null>;
|
|
396
|
+
/**
|
|
397
|
+
* Where a store sends a subscriber to manage a subscription they bought in an app.
|
|
398
|
+
*
|
|
399
|
+
* These live in the package rather than in a scaffolded screen for the reason the whole client surface
|
|
400
|
+
* does: they are Apple's and Google's URLs, not the adopter's, and when a store moves one the fix should
|
|
401
|
+
* be a minor release rather than an edit to a file Pithy may never rewrite. It is also what keeps the
|
|
402
|
+
* scaffolded templates free of absolute URLs, which the CLI's own scaffold check enforces.
|
|
403
|
+
*
|
|
404
|
+
* There is no Stripe entry. Stripe's equivalent is a *session* the server mints per caller — see
|
|
405
|
+
* {@link openBillingPortal} — and a static URL there would be a link to nobody's account.
|
|
406
|
+
*/
|
|
407
|
+
export declare const STORE_SUBSCRIPTION_URLS: Readonly<Record<"apple" | "google", string>>;
|
|
408
|
+
/**
|
|
409
|
+
* Send the browser to a store's own subscription-management page.
|
|
410
|
+
*
|
|
411
|
+
* Returns false only when there is no browser to send. A web page cannot cancel a StoreKit or Play
|
|
412
|
+
* Billing subscription — the store owns that, by its own rules — so linking there is the whole of what a
|
|
413
|
+
* web screen can honestly offer.
|
|
414
|
+
*/
|
|
415
|
+
export declare function openStoreSubscriptions(rail: "apple" | "google", options?: PaymentsClientOptions): boolean;
|
|
416
|
+
/** What {@link returnedCheckoutSession} reads, and where from. */
|
|
417
|
+
export interface CheckoutReturnOptions {
|
|
418
|
+
/** The query string to read. Defaults to the browser's own `location.search`. */
|
|
419
|
+
search?: string;
|
|
420
|
+
/** The parameter carrying the session id. Defaults to {@link CHECKOUT_SESSION_PARAM}. */
|
|
421
|
+
param?: string;
|
|
422
|
+
/** The global object `location` comes off. Defaults to `globalThis`. */
|
|
423
|
+
global?: PaymentsGlobal;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* The Checkout Session id a returning buyer arrived with, or null.
|
|
427
|
+
*
|
|
428
|
+
* This is the second half of the redirect-and-return dance. Stripe substitutes the real id into the
|
|
429
|
+
* `{CHECKOUT_SESSION_ID}` token in the adopter's `successUrl`, and posting it to `/payments/purchases`
|
|
430
|
+
* projects the purchase immediately instead of waiting for the webhook. The webhook is still
|
|
431
|
+
* authoritative and still arrives — this only decides whether the buyer sees their entitlement now or in
|
|
432
|
+
* a few seconds.
|
|
433
|
+
*/
|
|
434
|
+
export declare function returnedCheckoutSession(options?: CheckoutReturnOptions): string | null;
|
|
435
|
+
//# sourceMappingURL=api.d.ts.map
|