@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,249 @@
|
|
|
1
|
+
import { PAYMENTS_RAILS } from "../data/rail.js";
|
|
2
|
+
import { PaymentsSubjectType } from "../data/subject.js";
|
|
3
|
+
import { EntitlementKey } from "@pithy-sh/core/src/entitlement/entitlement";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/config/config.ts
|
|
6
|
+
/**
|
|
7
|
+
* The payments capability's config — the catalog, and the thin surface an adopter owns in
|
|
8
|
+
* `pithy.config.ts`. Every field is `.describe()`d: the descriptions feed the self-documenting CLI
|
|
9
|
+
* (CLAUDE.md §Config).
|
|
10
|
+
*
|
|
11
|
+
* **The catalog lives here, not in D1.** A product's entitlement mapping is policy: it should be
|
|
12
|
+
* diffable in git and it should not be mutable at runtime. The cost is that a new SKU requires a
|
|
13
|
+
* deploy, which is the correct trade — a table an attacker or a mis-click can edit decides who is
|
|
14
|
+
* entitled to what.
|
|
15
|
+
*
|
|
16
|
+
* The load-bearing distinction the shape encodes is that **a product is not an entitlement**.
|
|
17
|
+
* `pro_monthly` and `pro_annual` are two products, in three rails' catalogs, granting one entitlement —
|
|
18
|
+
* `pro`. Gating code names the entitlement; only this file ever names a SKU.
|
|
19
|
+
*
|
|
20
|
+
* A product declares rails selectively. `remove_ads` shipping on mobile only is expressed by omitting
|
|
21
|
+
* the `stripe` block, not by a flag — so the config reads as the catalog it is.
|
|
22
|
+
*/
|
|
23
|
+
/** The longest a display name may be. Long enough for a real product title, short enough to render. */
|
|
24
|
+
const MAX_NAME_LENGTH = 120;
|
|
25
|
+
/** The longest a provider SKU or price id may be. Apple's reverse-DNS ids are the long end of this. */
|
|
26
|
+
const MAX_SKU_LENGTH = 200;
|
|
27
|
+
/** A ledger currency code, matching `@pithy-sh/ledger`'s own: lowercase, digits, and dashes. */
|
|
28
|
+
const CURRENCY_CODE_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
29
|
+
/** A page in the adopter's own app that a hosted Stripe flow returns a browser to. */
|
|
30
|
+
const ReturnUrl = z.url({ protocol: /^https?$/ }).max(2048);
|
|
31
|
+
const PaymentsRailToggles = z.object({
|
|
32
|
+
apple: z.boolean().default(false).describe("Whether App Store purchases are accepted. Credentials come from the secrets store, never config."),
|
|
33
|
+
google: z.boolean().default(false).describe("Whether Google Play purchases are accepted. Credentials come from the secrets store, never config."),
|
|
34
|
+
stripe: z.boolean().default(false).describe("Whether Stripe purchases are accepted, through hosted Checkout and the Billing Portal. Pithy never owns payment UI, SCA, tax, or proration."),
|
|
35
|
+
lemonSqueezy: z.boolean().default(false).describe("Whether Lemon Squeezy purchases are accepted, through hosted checkout and the customer portal. Lemon Squeezy is the merchant of record: it handles global sales tax, EU VAT, invoicing and dunning, and it issues refunds on its own. Credentials come from the secrets store, never config."),
|
|
36
|
+
paddle: z.boolean().default(false).describe("Whether Paddle purchases are accepted, through an overlay, an inline frame, or Paddle's hosted page. Paddle is the merchant of record: it handles global sales tax, EU VAT, invoicing and dunning, and it issues refunds on its own. The API key and the webhook secret come from the secrets store; the publishable client token is config, because it is designed to reach a browser.")
|
|
37
|
+
}).describe("Which payment rails this project accepts. A rail that is off refuses its routes and its webhook.");
|
|
38
|
+
const PaymentsProductType = z.enum([
|
|
39
|
+
"consumable",
|
|
40
|
+
"non_consumable",
|
|
41
|
+
"subscription"
|
|
42
|
+
]).describe("What kind of thing the product is: a consumable spent after purchase, a non-consumable owned forever and restorable, or a subscription that renews and can lapse.");
|
|
43
|
+
const PaymentsAppleProduct = z.object({ productId: z.string().min(1).max(MAX_SKU_LENGTH).describe("The App Store Connect product identifier, usually reverse-DNS — `com.acme.pro.monthly`.") }).describe("How this product is listed on the App Store. Omit the block to ship without the Apple rail.");
|
|
44
|
+
const PaymentsGoogleProduct = z.object({ productId: z.string().min(1).max(MAX_SKU_LENGTH).describe("The Play Console product or base-plan id — `pro_monthly`.") }).describe("How this product is listed on Google Play. Omit the block to ship without the Google rail.");
|
|
45
|
+
const PaymentsStripeProduct = z.object({ priceId: z.string().min(1).max(MAX_SKU_LENGTH).describe("The Stripe Price id — `price_1Abc`. Publishable by design: it is what a Checkout Session names, so it may reach a browser.") }).describe("How this product is priced in Stripe. Omit the block to ship without the Stripe rail.");
|
|
46
|
+
const PaymentsLemonSqueezyProduct = z.object({ variantId: z.string().min(1).max(MAX_SKU_LENGTH).describe("The Lemon Squeezy variant id — `123456`. A variant is Lemon Squeezy's price-equivalent, so this sits exactly where Stripe's `priceId` does. Publishable by design: it is what a hosted checkout names.") }).describe("How this product is sold through Lemon Squeezy. Omit the block to ship without that rail.");
|
|
47
|
+
const PaymentsLemonSqueezySettings = z.object({
|
|
48
|
+
successUrl: ReturnUrl.describe("Where hosted checkout returns a buyer who paid. Unlike Stripe there is no session token to substitute — a Lemon Squeezy purchase is only ever heard about through its webhook, so this page shows a pending state rather than posting a receipt."),
|
|
49
|
+
storeCurrency: z.string().regex(CURRENCY_CODE_PATTERN, "A currency code is lowercase, digits, and dashes.").optional().describe("The currency this Lemon Squeezy store sells in, lowercase ISO 4217 — `usd`. Optional, and the only thing it does is let a fixed-amount discount in another currency be refused when it is created rather than when a customer redeems it. Lemon Squeezy accepts the mismatched object and fails at redemption, so without this the error arrives at the buyer instead of at you.")
|
|
50
|
+
}).describe("Where Lemon Squeezy's hosted checkout sends a browser back to. Config, not request input: a client that could name a return URL could send a paying customer to a page it controls. Build it on `PUBLIC_ORIGIN` and never on a literal. One URL, where Stripe takes three, and both absences are the store's rather than an omission here: Lemon Squeezy's checkout has no cancel destination — a buyer who backs out closes the tab or uses the back button — and its customer portal is a signed, expiring link with nowhere to return to.");
|
|
51
|
+
const PaymentsPaddleProduct = z.object({ priceId: z.string().min(1).max(MAX_SKU_LENGTH).describe("The Paddle Price id — `pri_01hv8w…`. Publishable by design: it is what a transaction and `Paddle.Checkout.open` both name, so it may reach a browser.") }).describe("How this product is priced in Paddle. Omit the block to ship without the Paddle rail.");
|
|
52
|
+
const PaymentsPaddleSettings = z.strictObject({
|
|
53
|
+
checkout: z.enum([
|
|
54
|
+
"overlay",
|
|
55
|
+
"inline",
|
|
56
|
+
"hosted"
|
|
57
|
+
]).default("overlay").describe("How checkout is presented. `overlay` opens Paddle.js over your own page; `inline` renders it in a container the screen provides; `hosted` redirects to Paddle's own page and **requires a default payment link set in the Paddle dashboard** — without one Paddle refuses to create the transaction at all, account-wide, so `pithy doctor` asks before a buyer finds out."),
|
|
58
|
+
clientToken: z.string().min(1).describe("Paddle's publishable client token — `live_…` or `test_…`. Config and not a secret, the same call `stripe.priceId` gets and for the same reason: it is designed to reach a browser, and putting it behind the secrets store would suggest verification depended on its secrecy. The API key and the webhook signing secret are secrets and are not here."),
|
|
59
|
+
environment: z.enum(["sandbox", "production"]).describe("Which Paddle account this project sells through. Paddle Billing partitions sandbox from live by account — separate host, separate key, separate notification destinations — so this decides both the API host and every purchase's recorded environment. There is no `mode` field on a Paddle payload that could contradict it."),
|
|
60
|
+
successUrl: ReturnUrl.describe("Where a buyer lands after paying. Used as `settings.successUrl` for Paddle.js and as the redirect target in `hosted` mode. Build it on `PUBLIC_ORIGIN`, never on a literal."),
|
|
61
|
+
cancelUrl: ReturnUrl.optional().describe("Where a buyer who backs out lands, in `hosted` mode. Optional, because an overlay a buyer closes leaves them exactly where they were."),
|
|
62
|
+
webhookFreshnessSeconds: z.number().int().positive().optional().describe("How many seconds either side of now a delivery's `ts` may be dated. Omitted uses 300, deliberately not the 5 Paddle's own SDKs use: replay protection here is the webhook table's `UNIQUE (rail, providerEventId)`, which is absolute, and a five-second window adds nothing to that while turning ordinary clock skew into a dropped renewal."),
|
|
63
|
+
storeCurrency: z.string().regex(CURRENCY_CODE_PATTERN, "A currency code is lowercase, digits, and dashes.").optional().describe("The currency this Paddle catalog prices in, lowercase ISO 4217 — `usd`. Optional, and the only thing it does is let a fixed-amount discount in another currency be refused when it is created rather than when a customer redeems it. Paddle accepts the mismatched object and fails at redemption, so without this the error arrives at the buyer instead of at you.")
|
|
64
|
+
}).describe("How this project sells through Paddle. `strictObject`, and that is what refuses `portalReturnUrl`: Paddle's customer portal takes no return parameter, so accepting one and dropping it would leave a URL an adopter wrote and believed in that nothing ever reads — a lie in a file they trust.");
|
|
65
|
+
const PaymentsStripeSettings = z.object({
|
|
66
|
+
successUrl: ReturnUrl.describe("Where hosted Checkout returns a buyer who paid. Put `{CHECKOUT_SESSION_ID}` in the query and Stripe fills it in, so the page can post it to /payments/purchases and show the entitlement at once instead of waiting for the webhook."),
|
|
67
|
+
cancelUrl: ReturnUrl.describe("Where hosted Checkout returns a buyer who backed out. Usually the paywall."),
|
|
68
|
+
portalReturnUrl: ReturnUrl.describe("Where the Billing Portal returns a subscriber who is done managing.")
|
|
69
|
+
}).describe("Where Stripe's hosted pages send a browser back to. Config, not request input: a client that could name a return URL could send a paying customer to a page it controls. Build all three on `PUBLIC_ORIGIN` — the constant the scaffolded pithy.config.ts derives from `domains` — and never on a literal: an origin written down is production's origin written into staging, which lands a staging payer in production on an account that has bought nothing (#256).");
|
|
70
|
+
const PaymentsLedgerGrant = z.object({
|
|
71
|
+
currency: z.string().regex(CURRENCY_CODE_PATTERN, "A currency code is lowercase, digits, and dashes.").describe("The `@pithy-sh/ledger` currency to credit — must be one that capability's config declares."),
|
|
72
|
+
amount: z.number().int().positive().describe("How much to credit, as an integer in the currency's minor unit. Never a float, never zero.")
|
|
73
|
+
}).describe("A balance credit performed on fulfillment, once per provider transaction.");
|
|
74
|
+
const PaymentsGrants = z.object({ ledger: PaymentsLedgerGrant.optional().describe("Credit a `@pithy-sh/ledger` balance when this product is fulfilled. The only point of contact between the two capabilities, and opt-in — most products never touch a balance.") }).describe("What a purchase fulfills beyond its entitlements. Absent for the products that only unlock a feature.");
|
|
75
|
+
const PaymentsProduct = z.object({
|
|
76
|
+
type: PaymentsProductType.describe("What kind of product this is. Decides how a renewal and a restore behave."),
|
|
77
|
+
name: z.string().min(1).max(MAX_NAME_LENGTH).describe("The display name a paywall renders — `Pro`, `Remove ads`. Required: it is the one product field a browser is given, and a paywall with no copy renders nothing."),
|
|
78
|
+
entitlements: z.array(EntitlementKey).default([]).describe("The entitlement keys this product grants. Many products across many rails may grant one key, which is the whole point — gating code names the key, never this product. Empty for a product that only credits a balance."),
|
|
79
|
+
apple: PaymentsAppleProduct.optional().describe("The Apple listing, if this product ships on the App Store."),
|
|
80
|
+
google: PaymentsGoogleProduct.optional().describe("The Google listing, if this product ships on Google Play."),
|
|
81
|
+
stripe: PaymentsStripeProduct.optional().describe("The Stripe price, if this product is sold through Stripe."),
|
|
82
|
+
lemonSqueezy: PaymentsLemonSqueezyProduct.optional().describe("The Lemon Squeezy variant, if this product is sold through Lemon Squeezy."),
|
|
83
|
+
paddle: PaymentsPaddleProduct.optional().describe("The Paddle price, if this product is sold through Paddle."),
|
|
84
|
+
grants: PaymentsGrants.optional().describe("What this purchase fulfills beyond its entitlements. Opt-in per product; a subscription's grant fires once per billing period, since each renewal is a distinct provider transaction."),
|
|
85
|
+
clawback: z.boolean().default(false).describe("Whether a refund attempts to debit back what `grants` credited. Off by default: the user may already have spent it, and a clawback that would overdraw is refused by the ledger rather than routed around. A failed clawback is recorded and queryable, not an exception.")
|
|
86
|
+
}).describe("One logical catalog product — what it is, what it grants, and how each store lists it.");
|
|
87
|
+
const PaymentsConfig = z.object({
|
|
88
|
+
billingSubject: PaymentsSubjectType.describe("Who a purchase belongs to, and who its entitlements reach. `user` is one person buying for themselves: they pay, they are entitled, nobody else is. `organization` is a company buying for its people: the company is invoiced, and everybody the adopter counts as a member holds what it bought — so a colleague who joined this morning is entitled and one who left this afternoon is not, with no row rewritten either time. Required, and decided once for the project: a codebase that could grant to a user on one route and an organization on the next eventually disagrees with itself about who is entitled, and the disagreement surfaces as somebody being refused what they paid for. Changing it later is a migration of every entitlement, purchase, and store link, so it is worth the minute now."),
|
|
89
|
+
rails: PaymentsRailToggles.default({
|
|
90
|
+
apple: false,
|
|
91
|
+
google: false,
|
|
92
|
+
stripe: false,
|
|
93
|
+
lemonSqueezy: false,
|
|
94
|
+
paddle: false
|
|
95
|
+
}).describe("Which stores this project sells through. Every rail is off until named."),
|
|
96
|
+
products: z.record(z.string(), PaymentsProduct).default({}).describe("The catalog, keyed by logical product id — the id that lands in every purchase row. Keys are yours and outlive any store's SKU, so renaming a SKU in a console never rewrites history."),
|
|
97
|
+
manualEntitlements: z.array(EntitlementKey).default([]).describe("Entitlement keys the control plane may grant that no product sells — a beta flag, an internal tier, a key that exists only to be comped. Declared, because the alternative to declaring is not checking: with this empty, a grant of any key outside the catalog is refused, which is what turns `pr` for `pro` into a 400 instead of a row nobody notices. Only grants are constrained; a revoke of a key the catalog has since dropped stays legal, or a catalog edit would be irreversible for everyone still holding it."),
|
|
98
|
+
stripe: PaymentsStripeSettings.optional().describe("Where Stripe's hosted Checkout and Billing Portal return the browser. Required when the Stripe rail is on — the two routes cannot create a session without them."),
|
|
99
|
+
lemonSqueezy: PaymentsLemonSqueezySettings.optional().describe("Where Lemon Squeezy's hosted checkout returns the browser. Required when that rail is on — the checkout route cannot create a session without it."),
|
|
100
|
+
paddle: PaymentsPaddleSettings.optional().describe("How this project sells through Paddle: the account, the publishable client token, the checkout mode, and where a buyer lands. Required when the Paddle rail is on — the rail cannot initialize Paddle.js or create a transaction without it."),
|
|
101
|
+
basePath: z.string().default("/payments").describe("Where the payments routes mount, webhooks included. Register the webhook URLs to match."),
|
|
102
|
+
graceGrantsAccess: z.boolean().default(true).describe("Whether a subscription in its billing-retry grace period still grants its entitlements. True, because that is the point of grace — a failed card should not lock a paying subscriber out mid-period. Once grace is exhausted the purchase moves to on_hold, which never grants.")
|
|
103
|
+
}).describe("Configuration for the payments capability — the cross-rail product catalog and where it mounts.").check((ctx) => {
|
|
104
|
+
const config = ctx.value;
|
|
105
|
+
const entries = Object.entries(config.products);
|
|
106
|
+
if (config.rails.stripe && config.stripe === void 0) ctx.issues.push({
|
|
107
|
+
code: "custom",
|
|
108
|
+
input: ctx.value,
|
|
109
|
+
path: ["stripe"],
|
|
110
|
+
message: "The Stripe rail is on, so `stripe` must declare `successUrl`, `cancelUrl`, and `portalReturnUrl`. Hosted Checkout and the Billing Portal have nowhere to return a browser without them."
|
|
111
|
+
});
|
|
112
|
+
if (!config.rails.stripe && config.stripe !== void 0) ctx.issues.push({
|
|
113
|
+
code: "custom",
|
|
114
|
+
input: ctx.value,
|
|
115
|
+
path: ["stripe"],
|
|
116
|
+
message: "`stripe` declares return URLs, but `rails.stripe` is off. Enable the rail, or drop the block."
|
|
117
|
+
});
|
|
118
|
+
if (config.rails.lemonSqueezy && config.lemonSqueezy === void 0) ctx.issues.push({
|
|
119
|
+
code: "custom",
|
|
120
|
+
input: ctx.value,
|
|
121
|
+
path: ["lemonSqueezy"],
|
|
122
|
+
message: "The Lemon Squeezy rail is on, so `lemonSqueezy` must declare a `successUrl`. Hosted checkout has nowhere to return a browser without it."
|
|
123
|
+
});
|
|
124
|
+
if (!config.rails.lemonSqueezy && config.lemonSqueezy !== void 0) ctx.issues.push({
|
|
125
|
+
code: "custom",
|
|
126
|
+
input: ctx.value,
|
|
127
|
+
path: ["lemonSqueezy"],
|
|
128
|
+
message: "`lemonSqueezy` declares a return URL, but `rails.lemonSqueezy` is off. Enable the rail, or drop the block."
|
|
129
|
+
});
|
|
130
|
+
if (config.rails.paddle && config.paddle === void 0) ctx.issues.push({
|
|
131
|
+
code: "custom",
|
|
132
|
+
input: ctx.value,
|
|
133
|
+
path: ["paddle"],
|
|
134
|
+
message: "The Paddle rail is on, so `paddle` must declare `clientToken`, `environment`, and `successUrl`. Paddle.js cannot initialize and no transaction can be created without them."
|
|
135
|
+
});
|
|
136
|
+
if (!config.rails.paddle && config.paddle !== void 0) ctx.issues.push({
|
|
137
|
+
code: "custom",
|
|
138
|
+
input: ctx.value,
|
|
139
|
+
path: ["paddle"],
|
|
140
|
+
message: "`paddle` declares settings, but `rails.paddle` is off. Enable the rail, or drop the block."
|
|
141
|
+
});
|
|
142
|
+
for (const [id, product] of entries) {
|
|
143
|
+
for (const rail of PAYMENTS_RAILS) if (product[rail] !== void 0 && !config.rails[rail]) ctx.issues.push({
|
|
144
|
+
code: "custom",
|
|
145
|
+
input: ctx.value,
|
|
146
|
+
path: [
|
|
147
|
+
"products",
|
|
148
|
+
id,
|
|
149
|
+
rail
|
|
150
|
+
],
|
|
151
|
+
message: `Product "${id}" declares a ${rail} SKU, but \`rails.${rail}\` is off. Enable the rail, or drop the block — a product ships without a rail by omission.`
|
|
152
|
+
});
|
|
153
|
+
if (!PAYMENTS_RAILS.some((rail) => product[rail] !== void 0)) ctx.issues.push({
|
|
154
|
+
code: "custom",
|
|
155
|
+
input: ctx.value,
|
|
156
|
+
path: ["products", id],
|
|
157
|
+
message: `Product "${id}" declares no rail. Give it an \`apple\`, \`google\`, \`stripe\`, \`lemonSqueezy\`, or \`paddle\` block — nothing could buy it otherwise.`
|
|
158
|
+
});
|
|
159
|
+
if (product.entitlements.length === 0 && product.grants?.ledger === void 0) ctx.issues.push({
|
|
160
|
+
code: "custom",
|
|
161
|
+
input: ctx.value,
|
|
162
|
+
path: ["products", id],
|
|
163
|
+
message: `Product "${id}" grants nothing. Give it \`entitlements\`, a \`grants\` clause, or both.`
|
|
164
|
+
});
|
|
165
|
+
if (product.type === "non_consumable" && product.grants !== void 0) ctx.issues.push({
|
|
166
|
+
code: "custom",
|
|
167
|
+
input: ctx.value,
|
|
168
|
+
path: [
|
|
169
|
+
"products",
|
|
170
|
+
id,
|
|
171
|
+
"grants"
|
|
172
|
+
],
|
|
173
|
+
message: `Product "${id}" is a non_consumable with a \`grants\` clause. A non-consumable is bought once and restored forever, so a balance credit would fire again on every restore. Make it a consumable, or drop the grant.`
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
for (const rail of PAYMENTS_RAILS) {
|
|
177
|
+
const owners = /* @__PURE__ */ new Map();
|
|
178
|
+
for (const [id, product] of entries) {
|
|
179
|
+
const sku = providerProductId(product, rail);
|
|
180
|
+
if (sku === void 0) continue;
|
|
181
|
+
owners.set(sku, [...owners.get(sku) ?? [], id]);
|
|
182
|
+
}
|
|
183
|
+
for (const [sku, claimants] of owners) {
|
|
184
|
+
if (claimants.length < 2) continue;
|
|
185
|
+
ctx.issues.push({
|
|
186
|
+
code: "custom",
|
|
187
|
+
input: ctx.value,
|
|
188
|
+
path: ["products"],
|
|
189
|
+
message: `Two products claim the ${rail} SKU "${sku}": ${claimants.sort().join(", ")}. A webhook resolves a product by its rail SKU, so a duplicate makes that resolution ambiguous.`
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
/** The provider SKU this product is listed under on `rail`, or undefined when it does not ship there. */
|
|
195
|
+
function providerProductId(product, rail) {
|
|
196
|
+
switch (rail) {
|
|
197
|
+
case "stripe": return product.stripe?.priceId;
|
|
198
|
+
case "lemonSqueezy": return product.lemonSqueezy?.variantId;
|
|
199
|
+
case "paddle": return product.paddle?.priceId;
|
|
200
|
+
case "apple": return product.apple?.productId;
|
|
201
|
+
case "google": return product.google?.productId;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** The product with this logical id, or undefined. Ids come from config, so an unknown one is a 404. */
|
|
205
|
+
function resolveProduct(config, id) {
|
|
206
|
+
const product = config.products[id];
|
|
207
|
+
return product === void 0 ? void 0 : {
|
|
208
|
+
id,
|
|
209
|
+
product
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The product a rail's own SKU maps to — the lookup every provider event needs, since a webhook carries
|
|
214
|
+
* the store's identifier and never a Pithy product id. Scoped to one rail: the same string can be a
|
|
215
|
+
* different product on a different store, and `PaymentsConfig`'s duplicate check is what guarantees the
|
|
216
|
+
* answer is unique within a rail.
|
|
217
|
+
*/
|
|
218
|
+
function productForProviderSku(config, rail, sku) {
|
|
219
|
+
for (const [id, product] of Object.entries(config.products)) if (providerProductId(product, rail) === sku) return {
|
|
220
|
+
id,
|
|
221
|
+
product
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Every entitlement key this project defines — what the catalog's products grant, plus what the adopter
|
|
226
|
+
* declared grantable with no sale behind it.
|
|
227
|
+
*
|
|
228
|
+
* The set a manual grant is checked against, and the set the control-plane catalog read publishes the first
|
|
229
|
+
* half of. Computed once per composition: the catalog is config, so it cannot change under a running Worker.
|
|
230
|
+
*
|
|
231
|
+
* **Empty is a real answer.** A project composing payments with nothing to sell and nothing declared defines
|
|
232
|
+
* no keys, and every grant against it is refused — which is correct, because there is no vocabulary to grant
|
|
233
|
+
* in. It is the same statement `clientProjection` makes as `{ enabled: false }`.
|
|
234
|
+
*/
|
|
235
|
+
function grantableEntitlements(config) {
|
|
236
|
+
const keys = new Set(config.manualEntitlements);
|
|
237
|
+
for (const product of Object.values(config.products)) for (const key of product.entitlements) keys.add(key);
|
|
238
|
+
return keys;
|
|
239
|
+
}
|
|
240
|
+
/** The entitlement keys a product grants, or an empty list for an unknown product or one that grants none. */
|
|
241
|
+
function entitlementsForProduct(config, id) {
|
|
242
|
+
return config.products[id]?.entitlements ?? [];
|
|
243
|
+
}
|
|
244
|
+
/** Whether a rail is enabled for this project. A disabled rail refuses its routes and its webhook. */
|
|
245
|
+
function railEnabled(config, rail) {
|
|
246
|
+
return config.rails[rail];
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
export { PaymentsAppleProduct, PaymentsConfig, PaymentsGoogleProduct, PaymentsGrants, PaymentsLedgerGrant, PaymentsLemonSqueezyProduct, PaymentsLemonSqueezySettings, PaymentsPaddleProduct, PaymentsPaddleSettings, PaymentsProduct, PaymentsProductType, PaymentsRailToggles, PaymentsStripeProduct, PaymentsStripeSettings, entitlementsForProduct, grantableEntitlements, productForProviderSku, providerProductId, railEnabled, resolveProduct };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** A discount code, as a customer types it. Case is preserved — both providers match case-insensitively. */
|
|
3
|
+
export declare const DiscountCode: z.ZodString;
|
|
4
|
+
export type DiscountCode = z.infer<typeof DiscountCode>;
|
|
5
|
+
/**
|
|
6
|
+
* How much comes off — a percentage, or a fixed amount in a named currency.
|
|
7
|
+
*
|
|
8
|
+
* Discriminated rather than two optional fields, because the currency is meaningful for exactly one of them
|
|
9
|
+
* and meaningless for the other. A percentage with a currency would be a value nothing could act on.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DiscountAmount: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
12
|
+
kind: z.ZodLiteral<"percent">;
|
|
13
|
+
percent: z.ZodNumber;
|
|
14
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
15
|
+
kind: z.ZodLiteral<"fixed">;
|
|
16
|
+
amountMinor: z.ZodNumber;
|
|
17
|
+
currency: z.ZodString;
|
|
18
|
+
}, z.core.$strict>], "kind">;
|
|
19
|
+
export type DiscountAmount = z.infer<typeof DiscountAmount>;
|
|
20
|
+
/**
|
|
21
|
+
* How long the discount lasts, in **billing periods** — the unit the customer experiences.
|
|
22
|
+
*
|
|
23
|
+
* Periods rather than months, because a period is what a customer sees on their statement: "the first twelve
|
|
24
|
+
* renewals are cheaper" means the same thing on a monthly plan and an annual one. Months are Stripe's
|
|
25
|
+
* internal unit and mean something different on an annual plan; translating into them is the Stripe rail's
|
|
26
|
+
* job, and {@link DiscountTerms.billingInterval} is what makes that translation possible rather than a guess.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DiscountDuration: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
29
|
+
kind: z.ZodLiteral<"once">;
|
|
30
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
31
|
+
kind: z.ZodLiteral<"forever">;
|
|
32
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
33
|
+
kind: z.ZodLiteral<"repeating">;
|
|
34
|
+
billingPeriods: z.ZodNumber;
|
|
35
|
+
}, z.core.$strip>], "kind">;
|
|
36
|
+
export type DiscountDuration = z.infer<typeof DiscountDuration>;
|
|
37
|
+
/** How often the plan this discount is for renews. Required only to translate a repeating duration. */
|
|
38
|
+
export declare const BillingInterval: z.ZodEnum<{
|
|
39
|
+
month: "month";
|
|
40
|
+
year: "year";
|
|
41
|
+
}>;
|
|
42
|
+
export type BillingInterval = z.infer<typeof BillingInterval>;
|
|
43
|
+
/**
|
|
44
|
+
* Everything that decides what a discount does. The shape both rails are created from.
|
|
45
|
+
*
|
|
46
|
+
* Deliberately not a mirror of either provider's create body: the fields it does not have are as considered
|
|
47
|
+
* as the ones it does. There is no "applies to these products" — that is a commercial policy an adopter owns
|
|
48
|
+
* — and no "first-time customers only", which the two stores model incompatibly enough that supporting it
|
|
49
|
+
* would mean promising behavior on one rail we could not deliver on the other.
|
|
50
|
+
*/
|
|
51
|
+
export declare const DiscountTerms: z.ZodObject<{
|
|
52
|
+
code: z.ZodOptional<z.ZodString>;
|
|
53
|
+
amount: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
54
|
+
kind: z.ZodLiteral<"percent">;
|
|
55
|
+
percent: z.ZodNumber;
|
|
56
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"fixed">;
|
|
58
|
+
amountMinor: z.ZodNumber;
|
|
59
|
+
currency: z.ZodString;
|
|
60
|
+
}, z.core.$strict>], "kind">;
|
|
61
|
+
duration: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
62
|
+
kind: z.ZodLiteral<"once">;
|
|
63
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
64
|
+
kind: z.ZodLiteral<"forever">;
|
|
65
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
66
|
+
kind: z.ZodLiteral<"repeating">;
|
|
67
|
+
billingPeriods: z.ZodNumber;
|
|
68
|
+
}, z.core.$strip>], "kind">;
|
|
69
|
+
billingInterval: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
month: "month";
|
|
71
|
+
year: "year";
|
|
72
|
+
}>>;
|
|
73
|
+
maxRedemptions: z.ZodOptional<z.ZodNumber>;
|
|
74
|
+
redeemableUntil: z.ZodOptional<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
export type DiscountTerms = z.output<typeof DiscountTerms>;
|
|
77
|
+
export type DiscountTermsInput = z.input<typeof DiscountTerms>;
|
|
78
|
+
/** A discount as a store created it: the terms we asked for, plus what the store decided. */
|
|
79
|
+
export declare const CreatedDiscount: z.ZodObject<{
|
|
80
|
+
code: z.ZodString;
|
|
81
|
+
providerDiscountId: z.ZodString;
|
|
82
|
+
terms: z.ZodObject<{
|
|
83
|
+
code: z.ZodOptional<z.ZodString>;
|
|
84
|
+
amount: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
85
|
+
kind: z.ZodLiteral<"percent">;
|
|
86
|
+
percent: z.ZodNumber;
|
|
87
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
88
|
+
kind: z.ZodLiteral<"fixed">;
|
|
89
|
+
amountMinor: z.ZodNumber;
|
|
90
|
+
currency: z.ZodString;
|
|
91
|
+
}, z.core.$strict>], "kind">;
|
|
92
|
+
duration: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
93
|
+
kind: z.ZodLiteral<"once">;
|
|
94
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
95
|
+
kind: z.ZodLiteral<"forever">;
|
|
96
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
97
|
+
kind: z.ZodLiteral<"repeating">;
|
|
98
|
+
billingPeriods: z.ZodNumber;
|
|
99
|
+
}, z.core.$strip>], "kind">;
|
|
100
|
+
billingInterval: z.ZodOptional<z.ZodEnum<{
|
|
101
|
+
month: "month";
|
|
102
|
+
year: "year";
|
|
103
|
+
}>>;
|
|
104
|
+
maxRedemptions: z.ZodOptional<z.ZodNumber>;
|
|
105
|
+
redeemableUntil: z.ZodOptional<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
export type CreatedDiscount = z.output<typeof CreatedDiscount>;
|
|
109
|
+
/**
|
|
110
|
+
* What a subscription is paying now, what it becomes, and when — the half that stops a bill changing
|
|
111
|
+
* unannounced.
|
|
112
|
+
*
|
|
113
|
+
* A capability that can apply a discount but not report its end date has shipped the half that creates the
|
|
114
|
+
* surprise: a discount that silently lapses is a customer's bill changing on a Tuesday with nothing having
|
|
115
|
+
* told them, and from where they sit that is indistinguishable from a billing error.
|
|
116
|
+
*
|
|
117
|
+
* Every amount here comes from the provider. Nothing in this package multiplies a price by a percentage.
|
|
118
|
+
*/
|
|
119
|
+
export declare const SubscriptionPricing: z.ZodObject<{
|
|
120
|
+
currency: z.ZodNullable<z.ZodString>;
|
|
121
|
+
currentAmountMinor: z.ZodNullable<z.ZodNumber>;
|
|
122
|
+
listAmountMinor: z.ZodNullable<z.ZodNumber>;
|
|
123
|
+
discountCode: z.ZodNullable<z.ZodString>;
|
|
124
|
+
discountEndsAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
export type SubscriptionPricing = z.output<typeof SubscriptionPricing>;
|
|
127
|
+
//# sourceMappingURL=discount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discount.d.ts","sourceRoot":"","sources":["../../src/data/discount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiCxB,4GAA4G;AAC5G,eAAO,MAAM,YAAY,aAOtB,CAAC;AACJ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD;;;;;GAKG;AACH,eAAO,MAAM,cAAc;;;;;;;4BA+BxB,CAAC;AACJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;;;;;;;2BAqBgC,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,uGAAuG;AACvG,eAAO,MAAM,eAAe;;;EAIzB,CAAC;AACJ,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;iBA8CtB,CAAC;AACL,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAC3D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE/D,6FAA6F;AAC7F,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBASyB,CAAC;AACtD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE/D;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB;;;;;;iBA2BqD,CAAC;AACtF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { JsonDate } from "@pithy-sh/core/src/data/codecs";
|
|
3
|
+
/** A discount code, as a customer types it. Case is preserved — both providers match case-insensitively. */
|
|
4
|
+
const DiscountCode = z.string().min(1).max(64).regex(/^[A-Za-z0-9_-]+$/, "A discount code is letters, digits, underscores and dashes.").describe("The code a customer enters at checkout. Constrained to what both stores accept, so a code this project mints is redeemable on either rail.");
|
|
5
|
+
/**
|
|
6
|
+
* How much comes off — a percentage, or a fixed amount in a named currency.
|
|
7
|
+
*
|
|
8
|
+
* Discriminated rather than two optional fields, because the currency is meaningful for exactly one of them
|
|
9
|
+
* and meaningless for the other. A percentage with a currency would be a value nothing could act on.
|
|
10
|
+
*/
|
|
11
|
+
const DiscountAmount = z.discriminatedUnion("kind", [z.strictObject({
|
|
12
|
+
kind: z.literal("percent").describe("A percentage off, which carries no currency."),
|
|
13
|
+
percent: z.number().positive().max(100).describe("How many percent off, 0 exclusive to 100 inclusive. 100 is a comped period, which is legal.")
|
|
14
|
+
}).describe("A percentage off — the portable kind, which works whatever a subscription is priced in."), z.strictObject({
|
|
15
|
+
kind: z.literal("fixed").describe("A fixed amount off, which is only meaningful in a stated currency."),
|
|
16
|
+
amountMinor: z.number().int().positive().describe("How much off, as an integer in the currency's minor unit. Never a float."),
|
|
17
|
+
currency: z.string().regex(/^[a-z]{3}$/, "An ISO 4217 currency code is three lowercase letters.").describe("The currency the amount is in. A fixed amount against a subscription priced in another currency is refused before creation, because at the provider it would fail at redemption — in front of the customer.")
|
|
18
|
+
}).describe("A fixed amount off, in one currency and no other.")]).describe("How much a discount takes off a bill. Strict on both members: a currency on a percentage is a value nothing can act on, and silently dropping it would leave an adopter believing they had set something.");
|
|
19
|
+
/**
|
|
20
|
+
* How long the discount lasts, in **billing periods** — the unit the customer experiences.
|
|
21
|
+
*
|
|
22
|
+
* Periods rather than months, because a period is what a customer sees on their statement: "the first twelve
|
|
23
|
+
* renewals are cheaper" means the same thing on a monthly plan and an annual one. Months are Stripe's
|
|
24
|
+
* internal unit and mean something different on an annual plan; translating into them is the Stripe rail's
|
|
25
|
+
* job, and {@link DiscountTerms.billingInterval} is what makes that translation possible rather than a guess.
|
|
26
|
+
*/
|
|
27
|
+
const DiscountDuration = z.discriminatedUnion("kind", [
|
|
28
|
+
z.object({ kind: z.literal("once").describe("One billing period, then list price.") }).describe("A single period's discount — a launch offer on the first invoice."),
|
|
29
|
+
z.object({ kind: z.literal("forever").describe("Every period, for as long as the subscription runs.") }).describe("A permanent rate. Nothing lapses, so nothing surprises anyone later."),
|
|
30
|
+
z.object({
|
|
31
|
+
kind: z.literal("repeating").describe("A fixed number of billing periods, then list price."),
|
|
32
|
+
billingPeriods: z.number().int().positive().describe("How many billing periods the discount applies to, counted the way a customer counts renewals. Twelve on a monthly plan is a year; twelve on an annual plan is twelve years.")
|
|
33
|
+
}).describe("A rate that lapses — the one whose end date a customer must be told about.")
|
|
34
|
+
]).describe("How long a discount lasts, in billing periods.");
|
|
35
|
+
/** How often the plan this discount is for renews. Required only to translate a repeating duration. */
|
|
36
|
+
const BillingInterval = z.enum(["month", "year"]).describe("How often the subscription this discount is meant for renews. Required for a repeating discount, because Stripe counts its duration in months and Lemon Squeezy counts it in periods — so without it, `12` on an annual plan is a year on one rail and twelve years on the other.");
|
|
37
|
+
/**
|
|
38
|
+
* Everything that decides what a discount does. The shape both rails are created from.
|
|
39
|
+
*
|
|
40
|
+
* Deliberately not a mirror of either provider's create body: the fields it does not have are as considered
|
|
41
|
+
* as the ones it does. There is no "applies to these products" — that is a commercial policy an adopter owns
|
|
42
|
+
* — and no "first-time customers only", which the two stores model incompatibly enough that supporting it
|
|
43
|
+
* would mean promising behavior on one rail we could not deliver on the other.
|
|
44
|
+
*/
|
|
45
|
+
const DiscountTerms = z.object({
|
|
46
|
+
code: DiscountCode.optional().describe("The code to mint, or omit it and let the store generate one. Supplying it is what lets an adopter mint one code per applicant against their own record of who was offered it."),
|
|
47
|
+
amount: DiscountAmount.describe("How much comes off."),
|
|
48
|
+
duration: DiscountDuration.describe("How long it lasts, in billing periods."),
|
|
49
|
+
billingInterval: BillingInterval.optional().describe("How often the plan renews. Required when `duration` is `repeating`, and refused otherwise — a duration that does not lapse has nothing to count."),
|
|
50
|
+
maxRedemptions: z.number().int().positive().optional().describe("How many times the code may be claimed in total, or omit for unlimited. It guards the customer path and only the customer path: the store counts a redemption when a checkout or a transaction uses the code and refuses the next one past the limit, and it holds when a webhook never arrives because the count is the store's rather than ours. It does not guard an administrative application against an existing subscription. Measured against the Paddle sandbox on 2026-08-14: a code with `usage_limit: 1` was applied to two subscriptions with `times_used` still `0`, went to `1` only when a transaction billed under it completed, and refused the next transaction after that. Stripe and Lemon Squeezy are unmeasured, so assume the same of them. So a staff comp applied by updating a subscription is not stopped here, and an adopter's own record of who was offered a code is the only thing that would stop it."),
|
|
51
|
+
redeemableUntil: JsonDate.optional().describe("After this moment the code can no longer be *claimed*. It does not end a discount already applied: a customer who redeemed it yesterday keeps their rate for its full duration. Named for that meaning because the providers' own fields do not agree on it, and a fixture pins each rail against a code already redeemed.")
|
|
52
|
+
}).describe("The terms of a discount, in customer-visible units, from which either rail can create one.").check((ctx) => {
|
|
53
|
+
const terms = ctx.value;
|
|
54
|
+
if (terms.duration.kind === "repeating" && terms.billingInterval === void 0) ctx.issues.push({
|
|
55
|
+
code: "custom",
|
|
56
|
+
input: ctx.value,
|
|
57
|
+
path: ["billingInterval"],
|
|
58
|
+
message: "A repeating discount must state the plan's `billingInterval`. Stripe counts a duration in months and Lemon Squeezy counts it in billing periods, so without it the same number means a year on one rail and twelve years on the other."
|
|
59
|
+
});
|
|
60
|
+
if (terms.duration.kind !== "repeating" && terms.billingInterval !== void 0) ctx.issues.push({
|
|
61
|
+
code: "custom",
|
|
62
|
+
input: ctx.value,
|
|
63
|
+
path: ["billingInterval"],
|
|
64
|
+
message: "`billingInterval` is only meaningful for a `repeating` duration. A discount that runs once or forever has no periods to count."
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
/** A discount as a store created it: the terms we asked for, plus what the store decided. */
|
|
68
|
+
const CreatedDiscount = z.object({
|
|
69
|
+
code: DiscountCode.describe("The code a customer enters — the one supplied, or the one the store generated."),
|
|
70
|
+
providerDiscountId: z.string().min(1).describe("The store's own id for the object, so an adopter can find it in their dashboard."),
|
|
71
|
+
terms: DiscountTerms.describe("The terms it was created with, echoed back as this package models them.")
|
|
72
|
+
}).describe("A discount that now exists at a store.");
|
|
73
|
+
/**
|
|
74
|
+
* What a subscription is paying now, what it becomes, and when — the half that stops a bill changing
|
|
75
|
+
* unannounced.
|
|
76
|
+
*
|
|
77
|
+
* A capability that can apply a discount but not report its end date has shipped the half that creates the
|
|
78
|
+
* surprise: a discount that silently lapses is a customer's bill changing on a Tuesday with nothing having
|
|
79
|
+
* told them, and from where they sit that is indistinguishable from a billing error.
|
|
80
|
+
*
|
|
81
|
+
* Every amount here comes from the provider. Nothing in this package multiplies a price by a percentage.
|
|
82
|
+
*/
|
|
83
|
+
const SubscriptionPricing = z.object({
|
|
84
|
+
currency: z.string().nullable().describe("The currency both amounts are in, or null when the store did not report one."),
|
|
85
|
+
currentAmountMinor: z.number().int().nonnegative().nullable().describe("What the next invoice comes to under any discount in force, as the store computed it."),
|
|
86
|
+
listAmountMinor: z.number().int().nonnegative().nullable().describe("What it comes to once the discount ends — the list price. Equal to `currentAmountMinor` when no discount is in force."),
|
|
87
|
+
discountCode: DiscountCode.nullable().describe("The code in force, or null when the subscription is at list price."),
|
|
88
|
+
discountEndsAt: JsonDate.nullable().describe("When the current discount stops applying, or null — which means either no discount or one that runs forever. A screen must say which, so read it beside `discountCode`.")
|
|
89
|
+
}).describe("What a subscription pays now, what it will pay, and when that changes.");
|
|
90
|
+
//#endregion
|
|
91
|
+
export { BillingInterval, CreatedDiscount, DiscountAmount, DiscountCode, DiscountDuration, DiscountTerms, SubscriptionPricing };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* One entitlement a subject holds — the row in `pithy_payments_entitlements`, and the materialized read
|
|
4
|
+
* model `requireEntitlement()` hits. `UNIQUE (subjectType, subjectId, entitlement)`: one row per subject
|
|
5
|
+
* per key, whichever purchase currently grants it.
|
|
6
|
+
*
|
|
7
|
+
* **The holder is the pair, never the id alone.** Nothing in the kit keeps an organization id from
|
|
8
|
+
* equalling some user's id, so a key of `(subjectId, entitlement)` would let one holder read the other's
|
|
9
|
+
* grant. Both subject columns lead the unique, ahead of the key, so the per-subject read — every
|
|
10
|
+
* entitlement one holder has — is a covering prefix of the same index rather than an index of its own.
|
|
11
|
+
* The two columns are written together and compared together; see `data/subject.ts` for why.
|
|
12
|
+
*
|
|
13
|
+
* They are `PaymentsSubject`'s own fields rather than a second pair spelled the same way, so a row cannot
|
|
14
|
+
* carry an id the pair itself would refuse.
|
|
15
|
+
*
|
|
16
|
+
* The row **is** stored (issue #79 decision 5) — resolving entitlements per request from a KV cache or a
|
|
17
|
+
* token claim would make a revocation eventually-consistent, and a revocation must be immediate. What it
|
|
18
|
+
* is never stored *independently of* is the purchase state that produced it: only the projection writes
|
|
19
|
+
* this table, and it re-derives every affected row inside the same transaction as the purchase write.
|
|
20
|
+
*
|
|
21
|
+
* `active` and `expiresAt` are both here, and both matter. The flag is an optimization the projection
|
|
22
|
+
* wrote; the timestamp is the truth. A subscription can lapse with no notification arriving at all, so the
|
|
23
|
+
* read path evaluates `expiresAt` itself rather than trusting the flag — and a read never writes, because
|
|
24
|
+
* repairing a stale row is the reconciliation Workflow's job and the hot path stays a pure read.
|
|
25
|
+
*/
|
|
26
|
+
export declare const PaymentsEntitlement: z.ZodObject<{
|
|
27
|
+
id: z.ZodString;
|
|
28
|
+
subjectType: z.ZodEnum<{
|
|
29
|
+
organization: "organization";
|
|
30
|
+
user: "user";
|
|
31
|
+
}>;
|
|
32
|
+
subjectId: z.ZodString;
|
|
33
|
+
entitlement: z.ZodString;
|
|
34
|
+
active: z.ZodCodec<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodBoolean, z.ZodString]>, z.ZodBoolean>;
|
|
35
|
+
expiresAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>;
|
|
36
|
+
sourcePurchaseId: z.ZodNullable<z.ZodString>;
|
|
37
|
+
manual: z.ZodCodec<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodBoolean, z.ZodString]>, z.ZodBoolean>;
|
|
38
|
+
createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
|
|
39
|
+
updatedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export type PaymentsEntitlement = z.output<typeof PaymentsEntitlement>;
|
|
42
|
+
export type PaymentsEntitlementRow = z.input<typeof PaymentsEntitlement>;
|
|
43
|
+
//# sourceMappingURL=entitlement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement.d.ts","sourceRoot":"","sources":["../../src/data/entitlement.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;iBAgCoF,CAAC;AACrH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACvE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PaymentsSubject } from "./subject.js";
|
|
2
|
+
import { EntitlementKey } from "@pithy-sh/core/src/entitlement/entitlement";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { SQLiteBoolean, SQLiteDate } from "@pithy-sh/core/src/data/codecs";
|
|
5
|
+
//#region src/data/entitlement.ts
|
|
6
|
+
/**
|
|
7
|
+
* One entitlement a subject holds — the row in `pithy_payments_entitlements`, and the materialized read
|
|
8
|
+
* model `requireEntitlement()` hits. `UNIQUE (subjectType, subjectId, entitlement)`: one row per subject
|
|
9
|
+
* per key, whichever purchase currently grants it.
|
|
10
|
+
*
|
|
11
|
+
* **The holder is the pair, never the id alone.** Nothing in the kit keeps an organization id from
|
|
12
|
+
* equalling some user's id, so a key of `(subjectId, entitlement)` would let one holder read the other's
|
|
13
|
+
* grant. Both subject columns lead the unique, ahead of the key, so the per-subject read — every
|
|
14
|
+
* entitlement one holder has — is a covering prefix of the same index rather than an index of its own.
|
|
15
|
+
* The two columns are written together and compared together; see `data/subject.ts` for why.
|
|
16
|
+
*
|
|
17
|
+
* They are `PaymentsSubject`'s own fields rather than a second pair spelled the same way, so a row cannot
|
|
18
|
+
* carry an id the pair itself would refuse.
|
|
19
|
+
*
|
|
20
|
+
* The row **is** stored (issue #79 decision 5) — resolving entitlements per request from a KV cache or a
|
|
21
|
+
* token claim would make a revocation eventually-consistent, and a revocation must be immediate. What it
|
|
22
|
+
* is never stored *independently of* is the purchase state that produced it: only the projection writes
|
|
23
|
+
* this table, and it re-derives every affected row inside the same transaction as the purchase write.
|
|
24
|
+
*
|
|
25
|
+
* `active` and `expiresAt` are both here, and both matter. The flag is an optimization the projection
|
|
26
|
+
* wrote; the timestamp is the truth. A subscription can lapse with no notification arriving at all, so the
|
|
27
|
+
* read path evaluates `expiresAt` itself rather than trusting the flag — and a read never writes, because
|
|
28
|
+
* repairing a stale row is the reconciliation Workflow's job and the hot path stays a pure read.
|
|
29
|
+
*/
|
|
30
|
+
const PaymentsEntitlement = z.object({
|
|
31
|
+
id: z.string().describe("The row's UUID. Text, like every id payments mints, so nothing about volume is inferable."),
|
|
32
|
+
subjectType: PaymentsSubject.shape.subjectType.describe("Whether `subjectId` names a user or an organization. Half the key — the id alone is ambiguous, so the two columns travel together."),
|
|
33
|
+
subjectId: PaymentsSubject.shape.subjectId.describe("The subject holding the entitlement — a Pithy user id, or the adopter's organization id."),
|
|
34
|
+
entitlement: EntitlementKey.describe("The entitlement key — what gating code names. `UNIQUE (subjectType, subjectId, entitlement)` is what makes this a read model rather than a log."),
|
|
35
|
+
active: SQLiteBoolean.describe("Whether the granting purchase was in an access-granting status when the projection last wrote this row. An optimization, not the truth — `expiresAt` is rechecked on every read."),
|
|
36
|
+
expiresAt: SQLiteDate.nullable().describe("When the grant lapses, or null for one that never does. The truth: a read applies it even when `active` still says 1."),
|
|
37
|
+
sourcePurchaseId: z.string().nullable().describe("Provenance — the purchase currently granting this entitlement, or null when nothing does. Answers 'why is this subject entitled' without a scan."),
|
|
38
|
+
manual: SQLiteBoolean.describe("Whether a human wrote this row rather than the projection deriving it. A manual grant is held: the projection skips a row carrying it, so a support comp survives the subject's next renewal instead of being erased by it. A revoke clears the hold, handing the key back to the purchases that support it."),
|
|
39
|
+
createdAt: SQLiteDate.describe("When this entitlement row first appeared for this subject."),
|
|
40
|
+
updatedAt: SQLiteDate.describe("When the projection last re-derived it.")
|
|
41
|
+
}).describe("One entitlement a subject holds — the row in `pithy_payments_entitlements`, the read model gates hit.");
|
|
42
|
+
//#endregion
|
|
43
|
+
export { PaymentsEntitlement };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** How many digits the currency's minor unit occupies. Two unless ISO 4217 says otherwise. */
|
|
2
|
+
export declare function minorUnitDigits(currency: string): number;
|
|
3
|
+
/**
|
|
4
|
+
* Convert a rail-reported amount into minor units, or null when it cannot be trusted.
|
|
5
|
+
*
|
|
6
|
+
* `scale` is what one currency unit is worth in the rail's own integer — 1000 for Apple's milliunits,
|
|
7
|
+
* 1_000_000 for Google's micros, 10 ** `minorUnitDigits` for a rail already reporting minor units.
|
|
8
|
+
*
|
|
9
|
+
* Null is returned rather than an approximation for a missing price, a missing currency, a non-finite
|
|
10
|
+
* number, or a negative amount. The last matters: `pithy_payments_purchases` refuses a negative
|
|
11
|
+
* `amountMinor` by CHECK constraint, so a rail reporting one would abort the whole projection batch and
|
|
12
|
+
* lose the purchase. An absent amount costs a reporting figure; a lost purchase costs a subscriber.
|
|
13
|
+
*/
|
|
14
|
+
export declare function minorUnitsFromScaled(scaled: number | null, scale: number, currency: string | null): number | null;
|
|
15
|
+
//# sourceMappingURL=money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/data/money.ts"],"names":[],"mappings":"AAgDA,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAOjH"}
|