@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,359 @@
|
|
|
1
|
+
import { PaymentsHostedRail, PaymentsRail } from "../data/rail.js";
|
|
2
|
+
import { PaymentsSubject } from "../data/subject.js";
|
|
3
|
+
import { PurchaseStatus } from "../data/status.js";
|
|
4
|
+
import { PurchaseEnvironment } from "../data/purchase.js";
|
|
5
|
+
import { SubscriptionCancelTiming } from "../data/subscription.js";
|
|
6
|
+
import { DiscountCode, DiscountTerms } from "../data/discount.js";
|
|
7
|
+
import { EntitlementKey } from "@pithy-sh/core/src/entitlement/entitlement";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { JsonDate } from "@pithy-sh/core/src/data/codecs";
|
|
10
|
+
import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
|
|
11
|
+
//#region src/http/schemas.ts
|
|
12
|
+
/**
|
|
13
|
+
* Everything a caller may send to a payments route, declared here and parsed on the route line. Reading a
|
|
14
|
+
* route tells you what it accepts without opening the handler, and `c.req.valid()` is the only way a handler
|
|
15
|
+
* can reach a body at all — the Biome plugin bans the raw accessors under `src/http/**`.
|
|
16
|
+
*
|
|
17
|
+
* ## What is deliberately absent
|
|
18
|
+
*
|
|
19
|
+
* **The subject.** Never a field on a route the adopter's own app calls, and this is the security core of
|
|
20
|
+
* subject billing. A purchase belongs to whoever the project bills, resolved on the server — the
|
|
21
|
+
* authenticated caller under `billingSubject: "user"`, and under `"organization"` whatever the adopter's
|
|
22
|
+
* own resolver answers from its own session, because this package never learns what an organization is. A
|
|
23
|
+
* body that could name a `subjectId` would let any signed-in caller buy, restore, or read against a holder
|
|
24
|
+
* they have no membership of, and the capability has nothing to check that claim against: it has no
|
|
25
|
+
* members table, by design. So the claim is never accepted. The control-plane schemas at the bottom are
|
|
26
|
+
* the deliberate exception, and the exception is the feature: support acting on somebody else's account is
|
|
27
|
+
* what they are for, which is why they sit behind a default-denied scoped credential and are audited on
|
|
28
|
+
* every write.
|
|
29
|
+
*
|
|
30
|
+
* **Half a subject.** Where a subject *is* named, both halves are, because nothing keeps an organization
|
|
31
|
+
* id from equalling some user's id — a filter or a grant carrying the id alone addresses whichever holder
|
|
32
|
+
* happens to share it. The halves inherit their bounds from `PaymentsSubject` rather than restating them,
|
|
33
|
+
* so a request can never carry an id a row would refuse.
|
|
34
|
+
*
|
|
35
|
+
* **The product.** Also never a field, and this one is easy to get wrong. The catalog product is resolved from
|
|
36
|
+
* the *verified* payload's SKU, not from anything the client declared: a client-supplied `productId` would let
|
|
37
|
+
* a caller present a cheap receipt as an expensive product. The client sends the store's artifact and nothing
|
|
38
|
+
* about what it thinks it bought.
|
|
39
|
+
*
|
|
40
|
+
* **The environment.** The deployment's own, from `ENVIRONMENT`. A body naming it would be a sandbox purchase
|
|
41
|
+
* asking to be treated as production.
|
|
42
|
+
*
|
|
43
|
+
* The size bounds are not decoration. A receipt is an unauthenticated string that gets base64-decoded and
|
|
44
|
+
* DER-parsed, so bounding it bounds that work; the limits are generous against real StoreKit and Play
|
|
45
|
+
* artifacts and still refuse a megabyte of nonsense before any parsing starts.
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* The longest receipt accepted. A StoreKit 2 signed transaction is a few kilobytes — its certificate chain is
|
|
49
|
+
* most of it — and Google's purchase tokens are shorter. 16 KiB is roomy for both and small enough that a
|
|
50
|
+
* flood of them cannot be a parsing denial of service.
|
|
51
|
+
*/
|
|
52
|
+
const MAX_RECEIPT_LENGTH = 16384;
|
|
53
|
+
/** The most receipts one restore may carry. A store's entitlement list is short; a thousand is not a restore. */
|
|
54
|
+
const MAX_RESTORE_RECEIPTS = 50;
|
|
55
|
+
/** The longest a catalog product id may be, matching the SKU bound the catalog itself uses. */
|
|
56
|
+
const MAX_PRODUCT_ID_LENGTH = 200;
|
|
57
|
+
/** The longest a page cursor may be. Ours are a base64url'd pair; the bound refuses anything that is not. */
|
|
58
|
+
const MAX_CURSOR_LENGTH = 512;
|
|
59
|
+
const PurchaseSubmission = z.object({
|
|
60
|
+
rail: PaymentsRail.describe("Which store the receipt came from. Decides which verifier runs and nothing else."),
|
|
61
|
+
receipt: z.string().min(1).max(MAX_RECEIPT_LENGTH).describe("The store's own artifact, exactly as its SDK returned it — a StoreKit 2 signed transaction, a Play purchase token. Everything about what was bought is read from inside it after it verifies, never from the request.")
|
|
62
|
+
}).describe("A client submitting one purchase for verification. Who holds it is the server's answer, never the request's.");
|
|
63
|
+
const RestoreRequest = z.object({
|
|
64
|
+
rail: PaymentsRail.describe("Which store the history came from."),
|
|
65
|
+
receipts: z.array(z.string().min(1).max(MAX_RECEIPT_LENGTH).describe("One store artifact from the caller's purchase history.")).min(1).max(MAX_RESTORE_RECEIPTS).describe("The caller's current store entitlements, as the store's own artifacts. Restore is client-driven because only the device can enumerate what its store account owns.")
|
|
66
|
+
}).describe("A client re-submitting its store purchase history, to bind it to the subject the server resolves.");
|
|
67
|
+
/**
|
|
68
|
+
* Apple's webhook body. The Apple rail declares the same one field for itself, because it parses the bytes in
|
|
69
|
+
* order to verify them and must not import across the HTTP seam to do it. Change one, change the other.
|
|
70
|
+
*/
|
|
71
|
+
const AppleWebhookNotification = z.object({ signedPayload: z.string().min(1).describe("The App Store Server Notification V2, as a compact JWS. The guard has already verified it against Apple's pinned certificate chain by the time a handler reads this.") }).describe("The body Apple POSTs to the notification endpoint. One field, carrying everything.");
|
|
72
|
+
/**
|
|
73
|
+
* What a caller may ask to buy: a catalog product id, and nothing else.
|
|
74
|
+
*
|
|
75
|
+
* No price, no amount, no currency, no return URL. The price comes from the catalog entry the id resolves to,
|
|
76
|
+
* and the return URLs come from config — a client that could name where hosted Checkout returns to could send a
|
|
77
|
+
* paying customer to a page it controls, and a client that could name a price could buy Pro for the price of a
|
|
78
|
+
* coin pack. The purchaser is the subject the server resolves for the caller, as everywhere else.
|
|
79
|
+
*/
|
|
80
|
+
const CheckoutRequest = z.object({
|
|
81
|
+
productId: z.string().min(1).max(MAX_PRODUCT_ID_LENGTH).describe("The logical catalog product to buy — the key in `products`, never a store SKU. Resolved against config, so an unknown one is a 404 rather than a bad request."),
|
|
82
|
+
rail: PaymentsHostedRail.optional().describe("Which hosted-checkout rail to buy through. Omit it when the product sells on one, which is the common case. A client may name this because a rail is not a price and not a purchaser — it decides who takes the money, not how much or on whose behalf — so a paywall offering more than one can put a button on the page for each."),
|
|
83
|
+
discountCode: DiscountCode.optional().describe("A discount code to apply, passed to the store unchanged. A client may send this because the store decides what it is worth and whether it is valid — Pithy never computes a discounted amount, so a code here can only ever ask the provider a question it was going to answer anyway.")
|
|
84
|
+
}).describe("A caller asking to start hosted checkout for one catalog product.");
|
|
85
|
+
/**
|
|
86
|
+
* ## The subscription lifecycle requests
|
|
87
|
+
*
|
|
88
|
+
* Four routes, and between them they accept two fields. That is the design rather than an accident of
|
|
89
|
+
* scope, and each absence below is load-bearing.
|
|
90
|
+
*
|
|
91
|
+
* **No subscription.** The route resolves it from the caller's own purchase rows, and there is no field
|
|
92
|
+
* a caller could send that would widen that set. A `subscriptionId` here would be a value a client
|
|
93
|
+
* supplies, and a value a client supplies is one they can point at somebody else's subscription — which
|
|
94
|
+
* this capability could not refuse, because it holds no members table and no ownership graph to check
|
|
95
|
+
* the claim against. The refusal has to be structural, exactly as `SubscriptionChangeInput` states it
|
|
96
|
+
* for the rail below.
|
|
97
|
+
*
|
|
98
|
+
* **No price.** {@link SubscriptionChangeRequest} names the *logical catalog product*, as
|
|
99
|
+
* {@link CheckoutRequest} does and for the same reason: a body-named `pri_…` moves a customer onto a
|
|
100
|
+
* plan this project does not sell, at a price it did not set. The catalog resolves the store's own
|
|
101
|
+
* identifier, server-side, after the product is known to exist.
|
|
102
|
+
*
|
|
103
|
+
* **No rail.** {@link CheckoutRequest} may name one because a rail is not a price and not a purchaser —
|
|
104
|
+
* it decides who takes the money on a purchase that has not happened yet. A subscription that already
|
|
105
|
+
* exists lives at exactly one store, and its own row says which. A named rail here could only ever be
|
|
106
|
+
* the wrong store asked about somebody's subscription.
|
|
107
|
+
*
|
|
108
|
+
* **No proration mode, and no `on_payment_failure`.** The rail picks the mode from the direction of the
|
|
109
|
+
* change and always prevents a change that cannot be paid for; `data/subscription.ts` holds the longer
|
|
110
|
+
* argument. Modeling either would make it a field, a field is a thing a client can set, and the value a
|
|
111
|
+
* client would eventually set is Paddle's `do_not_bill` — a free upgrade. It is unreachable because
|
|
112
|
+
* there is nowhere to write it.
|
|
113
|
+
*
|
|
114
|
+
* **No body at all on `keep`.** Withdrawing a scheduled cancellation takes no parameters: which
|
|
115
|
+
* subscription is the server's answer, and there is nothing to say about it but *do not*. So that route
|
|
116
|
+
* declares no schema and no `zValidator("json", …)`, exactly as `POST {base}/portal` does. A
|
|
117
|
+
* `z.object({})` would read as a refusal of everything and be neither — Zod strips rather than refuses —
|
|
118
|
+
* while making a POST with no body at all a 400 on a route that wants nothing.
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* What a caller may move their subscription to: a catalog product id, and nothing else.
|
|
122
|
+
*
|
|
123
|
+
* The same one field {@link CheckoutRequest} leads with, bounded the same way, and meaning the same
|
|
124
|
+
* thing: the key in `products`, never a store SKU and never a price. An unknown one is a 404 on the
|
|
125
|
+
* product rather than a bad request, because whether this project sells something is a config-backed
|
|
126
|
+
* lookup and a schema constrains a string.
|
|
127
|
+
*/
|
|
128
|
+
const SubscriptionChangeRequest = z.object({ productId: z.string().min(1).max(MAX_PRODUCT_ID_LENGTH).describe("The logical catalog product to move to — the key in `products`. The route resolves the store's own price from it, so a caller can only ever ask for a plan this project sells.") }).describe("A caller asking to move their own subscription onto one catalog product.");
|
|
129
|
+
/**
|
|
130
|
+
* What a caller may ask a quote about — {@link SubscriptionChangeRequest} itself, under the name the
|
|
131
|
+
* preview route line reads with.
|
|
132
|
+
*
|
|
133
|
+
* **The same value, not a copy of it.** A preview is the change with the commit removed: it asks the
|
|
134
|
+
* provider what moving to this product would cost and takes nothing. Two objects that must stay
|
|
135
|
+
* identical are two objects that will not — and the shape of that drift is a preview accepting a field
|
|
136
|
+
* the change refuses, quoting a customer a figure the commit then cannot honor. `schemas.test.ts`
|
|
137
|
+
* asserts the identity, so this stays an alias rather than becoming a second declaration.
|
|
138
|
+
*/
|
|
139
|
+
const SubscriptionPreviewRequest = SubscriptionChangeRequest;
|
|
140
|
+
/**
|
|
141
|
+
* When a cancellation takes effect. One field, and it is the customer's word rather than the store's.
|
|
142
|
+
*
|
|
143
|
+
* **Required, with no default.** `at_period_end` is the settled policy, and a default is still the
|
|
144
|
+
* wrong shape for it: the two timings are different things to buy — keep the period already paid for,
|
|
145
|
+
* or lose it today — and a body that omits the field would be choosing one of them by silence. A caller
|
|
146
|
+
* that means `at_period_end` says so, which is also what an audit row then records.
|
|
147
|
+
*
|
|
148
|
+
* The values come from `data/subscription.ts` rather than being spelled again here, so a third timing
|
|
149
|
+
* cannot exist on the wire and not in the rail. Paddle's own `immediately` and `next_billing_period` do
|
|
150
|
+
* not parse: the rail translates, and a request in the store's vocabulary means something upstream
|
|
151
|
+
* stopped translating.
|
|
152
|
+
*/
|
|
153
|
+
const SubscriptionCancelRequest = z.object({ timing: SubscriptionCancelTiming.describe("When the cancellation takes effect — `at_period_end` stops the renewal and lets the paid period run out, `now` ends access today. Stated rather than defaulted: ending somebody's access is not a choice made by omission.") }).describe("A caller ending their own subscription, and when they stop.");
|
|
154
|
+
/**
|
|
155
|
+
* The terms of a discount to mint. The one control-plane write that creates an object costing money.
|
|
156
|
+
*
|
|
157
|
+
* `DiscountTerms` carries the whole shape and its own cross-field rules — a repeating duration must state
|
|
158
|
+
* the plan's billing interval, because Stripe counts months and Lemon Squeezy counts periods. The rail is
|
|
159
|
+
* named here rather than inferred: minting is an administrative act against one store's dashboard, and
|
|
160
|
+
* guessing which one would put a code where nobody was looking for it.
|
|
161
|
+
*/
|
|
162
|
+
const AdminDiscountsQuery = z.object({ rail: PaymentsHostedRail.describe("Which store to list from. Required — a discount exists in one store, and the stores do not merge.") }).describe("A management client listing the discount codes one store holds.");
|
|
163
|
+
const DiscountCreateRequest = z.object({
|
|
164
|
+
rail: PaymentsHostedRail.describe("Which store to mint the discount at. Required — a discount exists in one store's dashboard."),
|
|
165
|
+
terms: DiscountTerms.describe("The discount's terms, in customer-visible units.")
|
|
166
|
+
}).describe("A management client minting one discount code.");
|
|
167
|
+
/**
|
|
168
|
+
* Google's webhook body: a Pub/Sub push, not a Play notification.
|
|
169
|
+
*
|
|
170
|
+
* The Google rail declares the same shape for itself, for the reason Apple's does — it decodes the bytes in order
|
|
171
|
+
* to check them and must not import across the HTTP seam to do it. Change one, change the other.
|
|
172
|
+
*
|
|
173
|
+
* **The proof is not in here.** A Pub/Sub push body carries no signature at all: authenticity is the OIDC token
|
|
174
|
+
* in the `Authorization` header, which the guard has already verified by the time a handler reads this. So this
|
|
175
|
+
* validator's job is only to say the body is shaped like a push, which is what keeps a malformed one a 400 rather
|
|
176
|
+
* than something a handler has to defend against.
|
|
177
|
+
*/
|
|
178
|
+
const GoogleWebhookNotification = z.object({
|
|
179
|
+
message: z.object({
|
|
180
|
+
data: z.string().min(1).describe("The Play developer notification, base64-encoded. Decoded and checked by the guard."),
|
|
181
|
+
messageId: z.string().min(1).describe("Pub/Sub's own message id — stable across redeliveries, which is what makes it the dedupe key."),
|
|
182
|
+
publishTime: z.string().min(1).optional().describe("When Pub/Sub published the message, RFC 3339.")
|
|
183
|
+
}).loose().describe("The Pub/Sub message carrying one Play developer notification."),
|
|
184
|
+
subscription: z.string().min(1).optional().describe("The push subscription's resource name. Recorded for diagnosis; nothing is decided from it.")
|
|
185
|
+
}).loose().describe("The body Pub/Sub POSTs to the Google notification endpoint.");
|
|
186
|
+
/**
|
|
187
|
+
* Stripe's webhook body: an event envelope.
|
|
188
|
+
*
|
|
189
|
+
* Shape-only, like Google's. **The proof is not in here** — it is the HMAC in the `Stripe-Signature` header, which
|
|
190
|
+
* the guard has already checked against the exact received bytes by the time a handler reads this. So this
|
|
191
|
+
* validator's job is to say the body is shaped like an event, which keeps a malformed one a 400 rather than
|
|
192
|
+
* something a handler has to defend against. The Stripe rail declares the same shape for itself, in
|
|
193
|
+
* `rails/stripe/objects.ts`, because it parses the bytes in order to read them and must not import across the
|
|
194
|
+
* HTTP seam. Change one, change the other.
|
|
195
|
+
*/
|
|
196
|
+
const StripeWebhookNotification = z.object({
|
|
197
|
+
id: z.string().min(1).describe("The event id — `evt_…`. The dedupe key, stable across Stripe's retries."),
|
|
198
|
+
type: z.string().min(1).describe("What happened — `customer.subscription.updated`."),
|
|
199
|
+
created: z.number().int().describe("Stripe's own timestamp for the event, in seconds since the epoch."),
|
|
200
|
+
data: z.object({ object: z.record(z.string(), z.unknown()).describe("The object the event is about.") }).loose().describe("The event's payload.")
|
|
201
|
+
}).loose().describe("The body Stripe POSTs to the notification endpoint.");
|
|
202
|
+
/**
|
|
203
|
+
* Lemon Squeezy's webhook body: a JSON:API envelope with the event name in `meta`.
|
|
204
|
+
*
|
|
205
|
+
* The rail declares the same shape for itself, for the reason Apple's and Google's do — it reads the bytes in
|
|
206
|
+
* order to check them and must not import across the HTTP seam to do it. Change one, change the other.
|
|
207
|
+
*
|
|
208
|
+
* **The proof is not in here.** Authenticity is the bare HMAC in `X-Signature`, which the guard has verified
|
|
209
|
+
* over the exact received bytes before this validator parses anything. So this validator's job is only to say
|
|
210
|
+
* the body is shaped like a delivery, which keeps a malformed one a 400 rather than something a handler has to
|
|
211
|
+
* defend against.
|
|
212
|
+
*/
|
|
213
|
+
const LemonSqueezyWebhookNotification = z.object({
|
|
214
|
+
meta: z.object({ event_name: z.string().min(1).describe("What happened — `subscription_payment_success`, `order_created`.") }).loose().describe("The delivery's metadata, including anything this deployment asked to have echoed back."),
|
|
215
|
+
data: z.object({
|
|
216
|
+
id: z.string().min(1).describe("The object's id. An integer as a string, and unique only within its type."),
|
|
217
|
+
type: z.string().min(1).describe("Which type that id belongs to — `orders`, `subscriptions`.")
|
|
218
|
+
}).loose().describe("The object the event is about.")
|
|
219
|
+
}).loose().describe("The body Lemon Squeezy POSTs to the notification endpoint.");
|
|
220
|
+
/**
|
|
221
|
+
* Paddle's webhook body: an event envelope carrying its own id, its type, when it happened, and the entity.
|
|
222
|
+
*
|
|
223
|
+
* The rail declares the same shape for itself, for the reason every other rail's does — it reads the bytes
|
|
224
|
+
* in order to check them and must not import across the HTTP seam to do it. Change one, change the other.
|
|
225
|
+
*
|
|
226
|
+
* **The proof is not in here.** Authenticity is the timestamped HMAC in `Paddle-Signature`, which the guard
|
|
227
|
+
* has verified over the exact received bytes before this validator parses anything. So this validator's job
|
|
228
|
+
* is only to say the body is shaped like a delivery, which keeps a malformed one a 400 rather than something
|
|
229
|
+
* a handler has to defend against.
|
|
230
|
+
*/
|
|
231
|
+
const PaddleWebhookNotification = z.object({
|
|
232
|
+
event_id: z.string().min(1).describe("Paddle's own id for the event — `evt_…`. The dedup key."),
|
|
233
|
+
event_type: z.string().min(1).describe("What happened — `transaction.completed`, `subscription.canceled`."),
|
|
234
|
+
occurred_at: z.string().min(1).describe("When it happened. The watermark, off the envelope and never the entity."),
|
|
235
|
+
data: z.record(z.string(), z.unknown()).describe("The entity the event is about.")
|
|
236
|
+
}).loose().describe("The body Paddle POSTs to a notification destination.");
|
|
237
|
+
/**
|
|
238
|
+
* A control-plane grant: who, which entitlement, and for how long.
|
|
239
|
+
*
|
|
240
|
+
* One of the two places in this package where a subject is a request field, and the only reason it is legal
|
|
241
|
+
* is the gate ahead of it — a manual grant is support acting on somebody else's holding, so naming that
|
|
242
|
+
* holder is the whole point. Every player-facing route resolves the subject on the server precisely because
|
|
243
|
+
* a body that could name one would let any signed-in caller write against another. Here that power *is* the
|
|
244
|
+
* feature, which is why the route requires a default-denied scoped control-plane credential and audits the
|
|
245
|
+
* write.
|
|
246
|
+
*
|
|
247
|
+
* **Both halves, and the type is named rather than assumed.** The row this writes is keyed
|
|
248
|
+
* `(subjectType, subjectId, entitlement)` and is read back by the same pair, so a grant that carried an id
|
|
249
|
+
* alone would land on whichever holder shares it. Whether the named kind is the one this project bills is a
|
|
250
|
+
* config-backed question and stays where the entitlement key's own catalog check is, in the handler: a
|
|
251
|
+
* schema constrains a string, it never replaces a lookup.
|
|
252
|
+
*
|
|
253
|
+
* No product, no rail, no price. A manual grant is not a purchase and must not pretend to be one: it writes
|
|
254
|
+
* the read model directly, with null provenance, and the purchase record stays empty because nothing was
|
|
255
|
+
* bought.
|
|
256
|
+
*/
|
|
257
|
+
const EntitlementGrantRequest = z.object({
|
|
258
|
+
subjectType: PaymentsSubject.shape.subjectType.describe("Which kind of holder to grant — the half that makes the id an address. Named, never assumed from the project's `billingSubject`, so what an audit row records is what a management client asked for."),
|
|
259
|
+
subjectId: PaymentsSubject.shape.subjectId.describe("The subject to grant. Support acts on somebody else's holding, so this is one of the two routes where the subject is a request field rather than the server's own answer."),
|
|
260
|
+
entitlement: EntitlementKey.describe("The entitlement key to grant, as gating code names it. Not a store SKU. It must be one this project defines — a key some product grants, or one the adopter declared in `manualEntitlements` — and anything else is a 400 naming the key. Comping a key nothing sells is still the durable case; declaring it is how a project says so."),
|
|
261
|
+
expiresAt: JsonDate.optional().describe("When the grant lapses, as an ISO 8601 timestamp. Omit for a comp that never ends. A past timestamp writes a row that grants nothing, which is a slower way of revoking.")
|
|
262
|
+
}).describe("A control-plane request to grant one entitlement to one subject, with no purchase behind it.");
|
|
263
|
+
/**
|
|
264
|
+
* A control-plane revoke: who, and which entitlement.
|
|
265
|
+
*
|
|
266
|
+
* No expiry, because a revoke is immediate — the read model is the truth every gate hits, so the subject
|
|
267
|
+
* loses access on the next request rather than at the end of a period. Revoking a key the subject never held
|
|
268
|
+
* is legal and idempotent: the inactive row is itself the record that somebody decided it.
|
|
269
|
+
*/
|
|
270
|
+
const EntitlementRevokeRequest = z.object({
|
|
271
|
+
subjectType: PaymentsSubject.shape.subjectType.describe("Which kind of holder to revoke from. Half the address: a revoke aimed at an id alone would clear whichever holder shares it, which is an outage for somebody who paid."),
|
|
272
|
+
subjectId: PaymentsSubject.shape.subjectId.describe("The subject to revoke. As with the grant, the subject is named because support is acting on somebody else's holding."),
|
|
273
|
+
entitlement: EntitlementKey.describe("The entitlement key to revoke, as gating code names it.")
|
|
274
|
+
}).describe("A control-plane request to revoke one entitlement from one subject, effective immediately.");
|
|
275
|
+
/**
|
|
276
|
+
* ## The management read queries
|
|
277
|
+
*
|
|
278
|
+
* The `Admin*` shapes below belong to the **control-plane reads**, which take no bodies at all: there is
|
|
279
|
+
* nothing for a client to send but filters and a place to resume.
|
|
280
|
+
*
|
|
281
|
+
* **Every filter is a closed enum of payments' own values, not a lookup against the adopter's config**,
|
|
282
|
+
* and that is the deliberate difference from `@pithy-sh/ledger`'s currency filter. A rail, a status and a
|
|
283
|
+
* store environment are the kit's own vocabulary — an unknown one is a *malformed request*, so the
|
|
284
|
+
* validator refuses it with a 400 naming the accepted set. A currency, a product id or an entitlement key
|
|
285
|
+
* is the adopter's, so a value that parses but is not configured is a missing resource and stays the
|
|
286
|
+
* handler's 404. A schema constrains a string; it never replaces a lookup, and it is never built from a
|
|
287
|
+
* configured key set.
|
|
288
|
+
*/
|
|
289
|
+
/** Where a keyset page resumes. Opaque; a malformed one is a first page rather than an error. */
|
|
290
|
+
const Cursor = z.string().max(MAX_CURSOR_LENGTH).optional().describe("Where to resume, from the previous page's `nextCursor`. Opaque; a malformed one is a first page.");
|
|
291
|
+
/** How many rows one page returns. Bounded, because a verified client can still have a bug. */
|
|
292
|
+
const Limit = z.coerce.number().int().min(1).max(MAX_PAGE_SIZE).optional().describe(`How many rows to return, from 1 to ${MAX_PAGE_SIZE}. Defaults to a page a dashboard can render.`);
|
|
293
|
+
/**
|
|
294
|
+
* The owner filter on a management listing: both halves of a subject, or neither.
|
|
295
|
+
*
|
|
296
|
+
* **Two optional fields with a rule, rather than one field.** A query string is flat, so the pair arrives as
|
|
297
|
+
* two values and the rule is what keeps them one fact. An id without a kind is the dangerous half — the
|
|
298
|
+
* listing would narrow on `subject_id` alone and hand back an organization's purchases to a client that
|
|
299
|
+
* asked about a person, whenever an adopter's two id spaces happen to meet on a value. A kind without an id
|
|
300
|
+
* is merely useless, and it is refused with it because "or neither" is a rule somebody can hold in their
|
|
301
|
+
* head and "or neither, unless" is not.
|
|
302
|
+
*
|
|
303
|
+
* Refused rather than ignored. A filter that silently did nothing would render as *this holder bought
|
|
304
|
+
* everything on the page*, which is worse than a 400 naming what to send.
|
|
305
|
+
*/
|
|
306
|
+
const SUBJECT_FILTER = {
|
|
307
|
+
subjectType: PaymentsSubject.shape.subjectType.optional().describe("Which kind of holder to narrow to. Send it with `subjectId` or send neither."),
|
|
308
|
+
subjectId: PaymentsSubject.shape.subjectId.optional().describe("Which holder to narrow to. Send it with `subjectType` or send neither: an id alone names whichever user or organization happens to carry it.")
|
|
309
|
+
};
|
|
310
|
+
/** Both halves of the subject filter, or neither. See {@link SUBJECT_FILTER}. */
|
|
311
|
+
function subjectFilterIsWhole(query) {
|
|
312
|
+
return query.subjectType === void 0 === (query.subjectId === void 0);
|
|
313
|
+
}
|
|
314
|
+
/** What a caller is told when they send one half. Names the remedy, because the remedy is the other field. */
|
|
315
|
+
const SUBJECT_FILTER_RULE = { message: "Send `subjectType` and `subjectId` together, or neither. Half a subject names no holder." };
|
|
316
|
+
const AdminPurchasesQuery = z.object({
|
|
317
|
+
...SUBJECT_FILTER,
|
|
318
|
+
rail: PaymentsRail.optional().describe("Restrict the listing to one store."),
|
|
319
|
+
status: PurchaseStatus.optional().describe("Restrict the listing to one normalized status."),
|
|
320
|
+
environment: PurchaseEnvironment.optional().describe("Restrict the listing to one store environment. Unfiltered by default: hiding sandbox transactions by default would hide the thing an operator most needs to notice."),
|
|
321
|
+
cursor: Cursor,
|
|
322
|
+
limit: Limit
|
|
323
|
+
}).refine(subjectFilterIsWhole, SUBJECT_FILTER_RULE).describe("The purchase-log query: what to narrow it to, and where to resume.");
|
|
324
|
+
const AdminSubscriptionsQuery = z.object({
|
|
325
|
+
...SUBJECT_FILTER,
|
|
326
|
+
status: PurchaseStatus.optional().describe("Restrict the listing to one normalized status — `active` for who is paying now, `in_grace` for whose renewal is failing."),
|
|
327
|
+
cursor: Cursor,
|
|
328
|
+
limit: Limit
|
|
329
|
+
}).refine(subjectFilterIsWhole, SUBJECT_FILTER_RULE).describe("The subscription query: what to narrow it to, and where to resume. No rail — a subscription is read forwards, not by store.");
|
|
330
|
+
const AdminEntitlementsQuery = z.object({
|
|
331
|
+
...SUBJECT_FILTER,
|
|
332
|
+
entitlement: EntitlementKey.optional().describe("Restrict the listing to one entitlement key — the `who holds pro` question. A shape check only: the key set is the adopter's, and one nothing grants is an empty page rather than a refusal."),
|
|
333
|
+
cursor: Cursor,
|
|
334
|
+
limit: Limit
|
|
335
|
+
}).refine(subjectFilterIsWhole, SUBJECT_FILTER_RULE).describe("The entitlement query: what to narrow it to, and where to resume.");
|
|
336
|
+
const AdminReconcileRunsQuery = z.object({
|
|
337
|
+
rail: PaymentsRail.optional().describe("Restrict to the passes narrowed to one store. A scheduled pass runs against every rail and carries no rail, so this never matches one."),
|
|
338
|
+
environment: PurchaseEnvironment.optional().describe("Restrict to one store environment — the sandbox host and the production host each keep their own passes."),
|
|
339
|
+
cursor: Cursor,
|
|
340
|
+
limit: Limit
|
|
341
|
+
}).describe("The reconciliation-run query: what to narrow it to, and where to resume.");
|
|
342
|
+
/**
|
|
343
|
+
* The two path segments on the per-subject management read: `…/entitlements/:subjectType/:subjectId`.
|
|
344
|
+
*
|
|
345
|
+
* **Two segments, not one encoded reference.** `encodeSubjectReference` exists for the single-field slots a
|
|
346
|
+
* store gives us — Apple's `appAccountToken`, Stripe's `client_reference_id` — where there is exactly one
|
|
347
|
+
* string to write and it comes back through a webhook. A URL has as many segments as it needs, and the
|
|
348
|
+
* decoder for that wire format answers `undefined` for anything it does not recognize, which on a path
|
|
349
|
+
* would be a 404 that reads like a missing holder rather than the 400 a malformed address deserves. Two
|
|
350
|
+
* validated segments say which half is wrong.
|
|
351
|
+
*
|
|
352
|
+
* Neither is optional, because half an address is not a narrower read: it is a different holder.
|
|
353
|
+
*/
|
|
354
|
+
const AdminSubjectParam = z.object({
|
|
355
|
+
subjectType: PaymentsSubject.shape.subjectType.describe("Which kind of holder to resolve — the `:subjectType` path segment. A closed enum, so an unknown kind is a 400 naming the two that exist."),
|
|
356
|
+
subjectId: PaymentsSubject.shape.subjectId.describe("Whose entitlements to resolve — the `:subjectId` path segment. Opaque to payments: whatever id the adopter's auth capability or its own membership model issued.")
|
|
357
|
+
}).describe("The `:subjectType/:subjectId` path segments on the per-subject management read.");
|
|
358
|
+
//#endregion
|
|
359
|
+
export { AdminDiscountsQuery, AdminEntitlementsQuery, AdminPurchasesQuery, AdminReconcileRunsQuery, AdminSubjectParam, AdminSubscriptionsQuery, AppleWebhookNotification, CheckoutRequest, DiscountCreateRequest, EntitlementGrantRequest, EntitlementRevokeRequest, GoogleWebhookNotification, LemonSqueezyWebhookNotification, PaddleWebhookNotification, PurchaseSubmission, RestoreRequest, StripeWebhookNotification, SubscriptionCancelRequest, SubscriptionChangeRequest, SubscriptionPreviewRequest };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { AdminRoute } from "@pithy-sh/core/src/controlPlane/discovery/adminRoute";
|
|
2
|
+
import type { ControlPlaneScope } from "@pithy-sh/core/src/controlPlane/scope/scope";
|
|
3
|
+
/**
|
|
4
|
+
* Payments' control-plane scopes, and the admin surface a manifest advertises.
|
|
5
|
+
*
|
|
6
|
+
* **Separate from `guards.ts` because a scope name is a client's business** (#315). A management
|
|
7
|
+
* client reads these to render what a connection may do, and `pithy-sh/dashboard`'s scope builder
|
|
8
|
+
* writes the `pithy dashboard connect --scope …` command from exactly these constants — in a browser
|
|
9
|
+
* program, with the DOM lib and no Workers types. While they sat beside the Hono middleware, naming
|
|
10
|
+
* one compiled `PithyHonoEnv`, which reached core's `capability.ts`, which named Worker globals that
|
|
11
|
+
* program has none of. **This module imports types and nothing else, and a gate holds it there**:
|
|
12
|
+
* `tooling/browser-scopes` compiles a DOM-only program against every scope the kit declares.
|
|
13
|
+
*
|
|
14
|
+
* ## Two scopes, not one admin flag
|
|
15
|
+
*
|
|
16
|
+
* The interim gate checked a single `payments:admin` scope on the `AuthContext`. That string is a valid
|
|
17
|
+
* {@link ControlPlaneScope} — it matches the seam's pattern, so nothing forced this change — but it names a
|
|
18
|
+
* *credential holder*, and the seam's scopes name *operations*. Under that model one flag is wrong on the
|
|
19
|
+
* merits: granting and revoking an entitlement are two operations with different blast radii and different
|
|
20
|
+
* holders. **Grant** mints paid product out of nothing, so a compromised comp tool costs revenue and can
|
|
21
|
+
* escalate itself into anything the catalog sells. **Revoke** takes paid access away from a live customer, so
|
|
22
|
+
* a compromised refund tool is an outage for people who paid. A refund tool needs revoke and never grant; a
|
|
23
|
+
* support-comp tool needs grant and never revoke. One flag makes each of them the other, and an adopter who
|
|
24
|
+
* wanted to hand out only the safer half had no way to say so.
|
|
25
|
+
*
|
|
26
|
+
* The split is real rather than cosmetic because `scopeCovers` matches exactly, with no prefix or wildcard
|
|
27
|
+
* rule: `payments:entitlements` confers neither of these, and holding one confers nothing about the other.
|
|
28
|
+
*
|
|
29
|
+
* The names are constants rather than config, for the reason the old comment gave and which has not changed: a
|
|
30
|
+
* configurable scope name is a way to misconfigure a default-denied gate into a differently-named one, and
|
|
31
|
+
* support tooling that read the docs would then quietly hold a scope nothing checks. They are also the join
|
|
32
|
+
* key with what `pithy dashboard connect` offers an adopter to grant, so they must be the same strings in both
|
|
33
|
+
* places.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Minting a discount — an administrative act with a cost attached, and its own scope for that reason.
|
|
37
|
+
*
|
|
38
|
+
* Deliberately not covered by, and not covering, the entitlement grants. Comping somebody an entitlement and
|
|
39
|
+
* creating a code that reduces what everybody who holds it pays are different powers with different blast
|
|
40
|
+
* radii, and a tool that needs one must not acquire the other. `scopeCovers` matches exactly.
|
|
41
|
+
*/
|
|
42
|
+
export declare const PAYMENTS_DISCOUNT_CREATE_SCOPE: ControlPlaneScope;
|
|
43
|
+
/**
|
|
44
|
+
* Reading the codes this project has issued.
|
|
45
|
+
*
|
|
46
|
+
* Separate from creating one, and strictly narrower: a pane that lists what was minted does not need the
|
|
47
|
+
* power to mint. The read exists because the write does — a management client that can create a code and
|
|
48
|
+
* never see it leaves a pane computing *absent* rather than blocked, which no grant repairs (#247).
|
|
49
|
+
*/
|
|
50
|
+
export declare const PAYMENTS_DISCOUNT_READ_SCOPE: ControlPlaneScope;
|
|
51
|
+
/**
|
|
52
|
+
* Write an entitlement nobody paid for — a comp, or the repair of a purchase that verified and never
|
|
53
|
+
* projected. The more dangerous of the two: a connection holding this can give any account anything the
|
|
54
|
+
* catalog sells.
|
|
55
|
+
*/
|
|
56
|
+
export declare const PAYMENTS_ENTITLEMENT_GRANT_SCOPE: ControlPlaneScope;
|
|
57
|
+
/**
|
|
58
|
+
* Take an entitlement back — a chargeback, an abuse decision, a comp withdrawn. Effective on the account's
|
|
59
|
+
* next request, which is exactly why it is granted separately from the ability to hand one out.
|
|
60
|
+
*/
|
|
61
|
+
export declare const PAYMENTS_ENTITLEMENT_REVOKE_SCOPE: ControlPlaneScope;
|
|
62
|
+
/**
|
|
63
|
+
* Read the purchase log — every verified provider transaction, across every account.
|
|
64
|
+
*
|
|
65
|
+
* Strictly more disclosure than {@link PAYMENTS_SUBSCRIPTIONS_READ_SCOPE}, which is why the two are
|
|
66
|
+
* separate: a renewal monitor needs to know who is still paying and when their period ends, and has no
|
|
67
|
+
* business reading what everybody ever bought. Neither read reaches a stored provider payload.
|
|
68
|
+
*/
|
|
69
|
+
export declare const PAYMENTS_PURCHASES_READ_SCOPE: ControlPlaneScope;
|
|
70
|
+
/**
|
|
71
|
+
* Read the purchases that renew — the same rows as the purchase log, narrowed to `type: subscription`.
|
|
72
|
+
*
|
|
73
|
+
* The narrower of the two grants, and the one a renewal or churn tool should hold on its own. Holding it
|
|
74
|
+
* confers nothing about the rest of the log: `scopeCovers` matches exactly, with no prefix rule.
|
|
75
|
+
*/
|
|
76
|
+
export declare const PAYMENTS_SUBSCRIPTIONS_READ_SCOPE: ControlPlaneScope;
|
|
77
|
+
/**
|
|
78
|
+
* Read the entitlement model — what accounts hold, whether it grants right now, and where it came from.
|
|
79
|
+
*
|
|
80
|
+
* **The read that had to exist for grant and revoke to be honest.** Payments shipped both writes with no
|
|
81
|
+
* read beside them, so a management client could comp an entitlement and take one back while never being
|
|
82
|
+
* able to list one; a console that cannot see what it changed is asking an operator to act blind. It is
|
|
83
|
+
* still granted separately, because seeing what every account is entitled to and deciding what they are
|
|
84
|
+
* entitled to are different operations with different blast radii.
|
|
85
|
+
*/
|
|
86
|
+
export declare const PAYMENTS_ENTITLEMENTS_READ_SCOPE: ControlPlaneScope;
|
|
87
|
+
/**
|
|
88
|
+
* Read what this project **sells** — each product's id, type, display name, and the entitlement keys it
|
|
89
|
+
* grants. Not what anybody bought.
|
|
90
|
+
*
|
|
91
|
+
* **Its own scope, and the reason is that the two disclosures are unrelated.** Every other read here is a
|
|
92
|
+
* page of the adopter's customers: who paid, what they hold, when it lapses. This one names no account and
|
|
93
|
+
* no transaction, and would read identically against a database with no rows in it. A tool that populates a
|
|
94
|
+
* "comp this person an entitlement" list needs exactly this and nothing else, and it should be able to hold
|
|
95
|
+
* exactly this and nothing else — a dropdown is not a reason to hand a client the purchase log.
|
|
96
|
+
*
|
|
97
|
+
* The converse matters as much and is why it is not folded into {@link PAYMENTS_ENTITLEMENTS_READ_SCOPE}: a
|
|
98
|
+
* catalog is a commercial fact — every tier a company sells and every feature it gates — and a connection
|
|
99
|
+
* granted the entitlement model should not acquire it by implication. `scopeCovers` matches exactly, so
|
|
100
|
+
* neither scope confers the other.
|
|
101
|
+
*/
|
|
102
|
+
export declare const PAYMENTS_CATALOG_READ_SCOPE: ControlPlaneScope;
|
|
103
|
+
/**
|
|
104
|
+
* Read what **reconciliation** did — the log of passes, their tallies, and when they last ran.
|
|
105
|
+
*
|
|
106
|
+
* Its own scope because it is operational state rather than anybody's commerce. A run record names no
|
|
107
|
+
* account, no transaction and no amount; it says whether the compensating control for a delivery mechanism
|
|
108
|
+
* that is known to fail has been firing, and how much it had to repair. An adopter should be able to give a
|
|
109
|
+
* health monitor exactly that and nothing else — a "has the cron stopped" alarm has no business holding the
|
|
110
|
+
* purchase log, and `scopeCovers` matches exactly, so neither confers the other.
|
|
111
|
+
*/
|
|
112
|
+
export declare const PAYMENTS_RECONCILE_READ_SCOPE: ControlPlaneScope;
|
|
113
|
+
/**
|
|
114
|
+
* Start a reconciliation pass now.
|
|
115
|
+
*
|
|
116
|
+
* **Separate from the read, and it is the sharpest split in this list.** Reading the run log says whether the
|
|
117
|
+
* nightly repair has been firing; starting one calls the store, walks the catalog, and *writes entitlements* —
|
|
118
|
+
* granting what a dropped webhook never granted and revoking what a missed cancellation left standing. The
|
|
119
|
+
* health monitor that holds `:read` to alarm on a stopped cron must not be able to move somebody's access, and
|
|
120
|
+
* `scopeCovers` matches exactly, so it cannot.
|
|
121
|
+
*
|
|
122
|
+
* **A trigger exists because the cron is not enough.** `pithy payments reconcile` runs the same pass, and it
|
|
123
|
+
* needs a laptop, a checkout, and a Cloudflare API token for the project — so the answer to "my subscription
|
|
124
|
+
* isn't showing up" at 4pm on a Saturday is either this route or nothing until 04:00 UTC. Adopted from
|
|
125
|
+
* `pithy-sh/dashboard#96`, where the operator with the run log open had no way to act on it.
|
|
126
|
+
*
|
|
127
|
+
* Idempotent by construction, so the scope carries no warning about pressing twice: `reconcilePayments` finds
|
|
128
|
+
* a reconciled catalog already matching and writes nothing.
|
|
129
|
+
*/
|
|
130
|
+
export declare const PAYMENTS_RECONCILE_RUN_SCOPE: ControlPlaneScope;
|
|
131
|
+
/**
|
|
132
|
+
* Every control-plane scope payments defines — what `pithy dashboard connect` offers for this capability, and
|
|
133
|
+
* the list a manifest or a doc quotes rather than re-typing. Core's `SEAM_SCOPES` is the same idea for the
|
|
134
|
+
* seam's own routes.
|
|
135
|
+
*
|
|
136
|
+
* Reads first, writes after, because that is the order an adopter should read them in: the reads are the
|
|
137
|
+
* grant most connections want and the smallest one that makes a dashboard useful.
|
|
138
|
+
*/
|
|
139
|
+
export declare const PAYMENTS_CONTROL_PLANE_SCOPES: readonly ControlPlaneScope[];
|
|
140
|
+
/**
|
|
141
|
+
* Payments' management surface, as `GET /control-plane/manifest` reports it.
|
|
142
|
+
*
|
|
143
|
+
* Declared beside the scopes rather than in `routes.ts` so the scope a route demands and the scope a
|
|
144
|
+
* manifest advertises are the same constant, read from one place. `basePath` is a parameter and never a
|
|
145
|
+
* default: an adopter who mounted payments at `/billing` must get a manifest naming
|
|
146
|
+
* `/billing/entitlements/grant`, or a management client composing its calls from it would 404 against
|
|
147
|
+
* exactly the adopters who customized anything.
|
|
148
|
+
*
|
|
149
|
+
* The summaries say what the operation *is for*, not what it does mechanically. A client renders these
|
|
150
|
+
* next to a button somebody is about to press on a paying customer's account.
|
|
151
|
+
*
|
|
152
|
+
* **Everything sits under an `admin/` segment.** The player surface already owns `${basePath}/purchases`
|
|
153
|
+
* and `${basePath}/entitlements`, and the second of those is a `GET` — so a management read mounted at
|
|
154
|
+
* the bare path would either collide outright or sit behind whichever of the two Hono matched first, with
|
|
155
|
+
* a route's gate decided by registration order. The extra segment makes the two sets disjoint by
|
|
156
|
+
* construction rather than by luck. It also keeps the reads at the shape a management client looks for: a
|
|
157
|
+
* `GET`, with a declared scope, no `:` segment, ending in the resource's own noun.
|
|
158
|
+
*/
|
|
159
|
+
export declare function paymentsAdminRoutes(basePath: string): AdminRoute[];
|
|
160
|
+
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../src/http/scopes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sDAAsD,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,EAAE,iBAA+C,CAAC;AAE7F;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,EAAE,iBAA6C,CAAC;AAEzF;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,EAAE,iBAAiD,CAAC;AAEjG;;;GAGG;AACH,eAAO,MAAM,iCAAiC,EAAE,iBAAkD,CAAC;AAEnG;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,EAAE,iBAA6C,CAAC;AAE1F;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,EAAE,iBAAiD,CAAC;AAElG;;;;;;;;GAQG;AACH,eAAO,MAAM,gCAAgC,EAAE,iBAAgD,CAAC;AAEhG;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,2BAA2B,EAAE,iBAA2C,CAAC;AAEtF;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,EAAE,iBAA6C,CAAC;AAE1F;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,4BAA4B,EAAE,iBAA4C,CAAC;AAExF;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,iBAAiB,EAWrE,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE,CA0ElE"}
|