@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,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/data/status.ts
|
|
3
|
+
/**
|
|
4
|
+
* The normalized purchase status set. Each rail's events map into these nine, so nothing downstream of
|
|
5
|
+
* a rail module ever sees `DID_RENEW`, `SUBSCRIPTION_ON_HOLD`, or `invoice.payment_failed`.
|
|
6
|
+
*
|
|
7
|
+
* The set is deliberately about *state*, not about the event that produced it: a projection is keyed on a
|
|
8
|
+
* transaction, and a transaction has one current state however many notifications described it.
|
|
9
|
+
*
|
|
10
|
+
* ## Two endings, and the difference between them is the money
|
|
11
|
+
*
|
|
12
|
+
* **`expired` is a period we were paid for, ended.** A subscription that ran its course, a Stripe
|
|
13
|
+
* subscription Stripe closed, an Apple period past its `expiresDate`. It grants no access — the period is
|
|
14
|
+
* over — but it **credits**, because the invoice behind it cleared.
|
|
15
|
+
*
|
|
16
|
+
* **`never_paid` is a purchase that terminated before any money moved.** A delayed-payment checkout whose
|
|
17
|
+
* bank debit bounced, a Stripe subscription abandoned at `incomplete_expired`, a Play deferred purchase
|
|
18
|
+
* canceled before payment. It grants nothing and credits nothing, and no clawback ever follows one, because
|
|
19
|
+
* there is no payment to reverse. Leaning on `expired` for these is how a coin pack gets handed out for money
|
|
20
|
+
* that never arrived — see `UNPAID_STATUSES` in `grants/apply.ts`. Apple maps nothing here: StoreKit issues
|
|
21
|
+
* no transaction until the money moves.
|
|
22
|
+
*/
|
|
23
|
+
const PurchaseStatus = z.enum([
|
|
24
|
+
"active",
|
|
25
|
+
"in_grace",
|
|
26
|
+
"on_hold",
|
|
27
|
+
"canceled",
|
|
28
|
+
"expired",
|
|
29
|
+
"never_paid",
|
|
30
|
+
"refunded",
|
|
31
|
+
"revoked",
|
|
32
|
+
"paused"
|
|
33
|
+
]).describe("The normalized purchase status. `active` is paid and current; `in_grace` is a failed renewal still inside the retry window; `on_hold` is a failed renewal past it; `canceled` is auto-renew turned off with the paid period still running; `expired` is a period we were paid for that has lapsed; `never_paid` terminated before any money cleared, so it credits nothing; `refunded` and `revoked` were taken back; `paused` is a subscription the user suspended.");
|
|
34
|
+
/**
|
|
35
|
+
* The statuses a purchase can grant access from — the candidate set the projection's SQL filters on
|
|
36
|
+
* before the expiry check. `in_grace`'s membership is then narrowed per project by
|
|
37
|
+
* {@link statusGrantsAccess}, so this set and that predicate must stay in step; a test asserts both.
|
|
38
|
+
*
|
|
39
|
+
* **`canceled` still grants**, and it is the member most often got wrong. A user who turns off
|
|
40
|
+
* auto-renew has not lost access — they have declined the *next* period. The period they paid for runs
|
|
41
|
+
* to its end, and `expiresAt` is what ends it.
|
|
42
|
+
*/
|
|
43
|
+
const ACCESS_GRANTING_STATUSES = /* @__PURE__ */ new Set([
|
|
44
|
+
"active",
|
|
45
|
+
"in_grace",
|
|
46
|
+
"canceled"
|
|
47
|
+
]);
|
|
48
|
+
/**
|
|
49
|
+
* Whether a purchase in this status grants its entitlements, given the project's grace policy. The
|
|
50
|
+
* expiry check is separate and applied alongside it — a status says whether the purchase is still
|
|
51
|
+
* standing, `expiresAt` says whether the period it paid for is over.
|
|
52
|
+
*
|
|
53
|
+
* `in_grace` granting access is the point of grace: a failed card should not lock a paying subscriber
|
|
54
|
+
* out mid-period. It is a described config flag rather than hardcoded policy because an app that sells
|
|
55
|
+
* something expensive may reasonably decide otherwise. `on_hold` never grants — by then the retry window
|
|
56
|
+
* is exhausted and the renewal has genuinely failed. `never_paid` never grants either, and never can: it
|
|
57
|
+
* says no money ever moved.
|
|
58
|
+
*/
|
|
59
|
+
function statusGrantsAccess(status, graceGrantsAccess) {
|
|
60
|
+
if (status === "in_grace") return graceGrantsAccess;
|
|
61
|
+
return ACCESS_GRANTING_STATUSES.has(status);
|
|
62
|
+
}
|
|
63
|
+
/** The statuses that grant access under this project's grace policy — what the projection's SQL filters on. */
|
|
64
|
+
function grantingStatuses(graceGrantsAccess) {
|
|
65
|
+
return [...ACCESS_GRANTING_STATUSES].filter((status) => statusGrantsAccess(status, graceGrantsAccess));
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { ACCESS_GRANTING_STATUSES, PurchaseStatus, grantingStatuses, statusGrantsAccess };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Who holds a purchase and the entitlements it grants — a **subject**, which is not always a person.
|
|
4
|
+
*
|
|
5
|
+
* A consumer app sells to people: one buyer, one holder, and a user id is the whole answer. A business
|
|
6
|
+
* selling to businesses has a different fact to record — the organization signs, the organization is
|
|
7
|
+
* invoiced, and everybody in it holds what it bought. Modeling that on a user-keyed table means either
|
|
8
|
+
* fanning a plan out across members (which drifts the moment somebody joins or leaves) or keying it to
|
|
9
|
+
* the owner (which makes the plan theirs, transferable with ownership, and invisible to the colleague
|
|
10
|
+
* their employer is paying for).
|
|
11
|
+
*
|
|
12
|
+
* So the holder is a **pair**: {@link PaymentsSubjectType} and an id. Both halves travel together
|
|
13
|
+
* everywhere — in a row, in a comparison, in a provider reference — because either half alone is
|
|
14
|
+
* ambiguous. Nothing in the kit keeps an organization id from equalling some user's id, so a comparison
|
|
15
|
+
* that read only the id would let one hold the other's subscription.
|
|
16
|
+
*
|
|
17
|
+
* **Which kind a project uses is decided once, in config** (`PaymentsConfig.billingSubject`), not per
|
|
18
|
+
* call. A codebase that could grant to a user on one route and an organization on the next is one where
|
|
19
|
+
* the two eventually disagree about who is entitled, and the disagreement surfaces as somebody being
|
|
20
|
+
* refused something they paid for.
|
|
21
|
+
*
|
|
22
|
+
* **The capability never learns what an organization is.** It has no members table, no roles, and no
|
|
23
|
+
* business acquiring either — memberships belong to the adopter. Under organization billing the
|
|
24
|
+
* capability asks *which subject is this caller acting for* and the adopter answers from its own
|
|
25
|
+
* session. Unanswered is unentitled, which is the direction every gate in the kit already fails.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* The kinds of thing that can hold a purchase.
|
|
29
|
+
*
|
|
30
|
+
* **An enum rather than a free string**, because a free string is a column that ends up holding `org`,
|
|
31
|
+
* `organization` and `Organization` in three adopters, and every gate comparing it is then comparing
|
|
32
|
+
* spellings rather than facts.
|
|
33
|
+
*
|
|
34
|
+
* **Spelled with a `z`, deliberately.** The only realistic way an adopter has organizations at all is
|
|
35
|
+
* Better Auth's `organization()` plugin, which `@pithy-sh/auth` composes verbatim: it ships the
|
|
36
|
+
* `organization`, `member` and `invitation` tables and writes `active_organization_id` onto the session.
|
|
37
|
+
* An adopter wiring the subject seam reads `session.activeOrganizationId` and writes the value below on
|
|
38
|
+
* the next line, so the two must match. This is a stored token in a column and a UNIQUE index — it
|
|
39
|
+
* cannot be respelled later — and it is the one place in this repository where the American spelling is
|
|
40
|
+
* correct: it is an identifier inherited from a dependency, not prose.
|
|
41
|
+
*/
|
|
42
|
+
export declare const PaymentsSubjectType: z.ZodEnum<{
|
|
43
|
+
organization: "organization";
|
|
44
|
+
user: "user";
|
|
45
|
+
}>;
|
|
46
|
+
export type PaymentsSubjectType = z.infer<typeof PaymentsSubjectType>;
|
|
47
|
+
/**
|
|
48
|
+
* The longest a subject id may be.
|
|
49
|
+
*
|
|
50
|
+
* **Derived from the narrowest provider field a reference is written into, not chosen.** A subject
|
|
51
|
+
* crosses to a store as {@link encodeSubjectReference}'s output, and Stripe's `client_reference_id` caps
|
|
52
|
+
* at 200 characters. A provider that silently truncates a longer value would hand back a string that
|
|
53
|
+
* decodes to a *different* id, attributing the purchase to whoever holds it — so the cap is enforced
|
|
54
|
+
* here, at the schema, where it fails on the way out instead of on the way back.
|
|
55
|
+
*
|
|
56
|
+
* 200 less `organization:` (13) leaves 187; 180 is that with room for a longer type member than either
|
|
57
|
+
* of today's, and it is far past any id the kit or Better Auth mints (both are UUIDs).
|
|
58
|
+
*/
|
|
59
|
+
export declare const MAX_SUBJECT_ID_LENGTH = 180;
|
|
60
|
+
/**
|
|
61
|
+
* A subject: the pair, as every row carries it and every function takes it.
|
|
62
|
+
*
|
|
63
|
+
* **Passed as this object rather than two positional strings**, deliberately. Two adjacent `string`
|
|
64
|
+
* parameters are two parameters a call site can transpose, and transposing them typechecks. The object
|
|
65
|
+
* makes the halves nameable and inseparable, which is what keeps the invariant — a subject is read from
|
|
66
|
+
* and written to one row atomically, and no code path pairs a type from config with an id from a row.
|
|
67
|
+
*/
|
|
68
|
+
export declare const PaymentsSubject: z.ZodObject<{
|
|
69
|
+
subjectType: z.ZodEnum<{
|
|
70
|
+
organization: "organization";
|
|
71
|
+
user: "user";
|
|
72
|
+
}>;
|
|
73
|
+
subjectId: z.ZodString;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export type PaymentsSubject = z.infer<typeof PaymentsSubject>;
|
|
76
|
+
/**
|
|
77
|
+
* Whether two subjects are the same holder — **both halves, always**.
|
|
78
|
+
*
|
|
79
|
+
* `undefined` is never equal to anything, including another `undefined`. An unresolved owner compared
|
|
80
|
+
* equal to an unresolved owner is how a webhook nobody could attribute would pass an ownership check,
|
|
81
|
+
* and that check is the only thing standing between one customer's renewal and another's account.
|
|
82
|
+
*/
|
|
83
|
+
export declare function sameSubject(a: PaymentsSubject | undefined, b: PaymentsSubject | undefined): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* A subject as one string, for the single-field slots a store gives us — Apple's `appAccountToken`,
|
|
86
|
+
* Google's `obfuscatedAccountId`, Stripe's `client_reference_id`, Paddle's and Lemon Squeezy's custom
|
|
87
|
+
* data.
|
|
88
|
+
*
|
|
89
|
+
* **One encoding, in one function, with one decoder.** These values leave our control and come back
|
|
90
|
+
* through a webhook, so the format is a wire contract with five providers at once. A second encoding
|
|
91
|
+
* anywhere means a purchase stamped by one code path and read by another resolves to nobody — or, worse,
|
|
92
|
+
* to somebody.
|
|
93
|
+
*
|
|
94
|
+
* The type half leads so the string sorts and greps by kind, and so a value that is *not* this encoding
|
|
95
|
+
* is recognizable at a glance in a provider's dashboard.
|
|
96
|
+
*/
|
|
97
|
+
export declare function encodeSubjectReference(subject: PaymentsSubject): string;
|
|
98
|
+
/**
|
|
99
|
+
* The inverse, and **strict**: anything that is not exactly this encoding is `undefined`, never a guess.
|
|
100
|
+
*
|
|
101
|
+
* The input is a value a client put in a purchase and a store handed back, so it may be anything at all.
|
|
102
|
+
* The dangerous shape is a bare id — the format every pre-subject client sent — which a lenient decoder
|
|
103
|
+
* would read as a user, attributing a stranger's purchase to whoever holds that id. So a reference with
|
|
104
|
+
* no separator does not decode, an unknown type half does not decode, and an empty half does not decode.
|
|
105
|
+
* Every caller treats `undefined` as *orphaned*: the event is recorded and replayable, and nothing is
|
|
106
|
+
* granted.
|
|
107
|
+
*
|
|
108
|
+
* Splits on the **first** separator only, so an adopter whose organization ids contain colons round-trips.
|
|
109
|
+
*/
|
|
110
|
+
export declare function decodeSubjectReference(reference: string): PaymentsSubject | undefined;
|
|
111
|
+
//# sourceMappingURL=subject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject.d.ts","sourceRoot":"","sources":["../../src/data/subject.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB;;;EAI7B,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAiBzC;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;;;;;;iBAK+E,CAAC;AAC5G,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,eAAe,GAAG,SAAS,EAAE,CAAC,EAAE,eAAe,GAAG,SAAS,GAAG,OAAO,CAGnG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAEvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAQrF"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/data/subject.ts
|
|
3
|
+
/**
|
|
4
|
+
* Who holds a purchase and the entitlements it grants — a **subject**, which is not always a person.
|
|
5
|
+
*
|
|
6
|
+
* A consumer app sells to people: one buyer, one holder, and a user id is the whole answer. A business
|
|
7
|
+
* selling to businesses has a different fact to record — the organization signs, the organization is
|
|
8
|
+
* invoiced, and everybody in it holds what it bought. Modeling that on a user-keyed table means either
|
|
9
|
+
* fanning a plan out across members (which drifts the moment somebody joins or leaves) or keying it to
|
|
10
|
+
* the owner (which makes the plan theirs, transferable with ownership, and invisible to the colleague
|
|
11
|
+
* their employer is paying for).
|
|
12
|
+
*
|
|
13
|
+
* So the holder is a **pair**: {@link PaymentsSubjectType} and an id. Both halves travel together
|
|
14
|
+
* everywhere — in a row, in a comparison, in a provider reference — because either half alone is
|
|
15
|
+
* ambiguous. Nothing in the kit keeps an organization id from equalling some user's id, so a comparison
|
|
16
|
+
* that read only the id would let one hold the other's subscription.
|
|
17
|
+
*
|
|
18
|
+
* **Which kind a project uses is decided once, in config** (`PaymentsConfig.billingSubject`), not per
|
|
19
|
+
* call. A codebase that could grant to a user on one route and an organization on the next is one where
|
|
20
|
+
* the two eventually disagree about who is entitled, and the disagreement surfaces as somebody being
|
|
21
|
+
* refused something they paid for.
|
|
22
|
+
*
|
|
23
|
+
* **The capability never learns what an organization is.** It has no members table, no roles, and no
|
|
24
|
+
* business acquiring either — memberships belong to the adopter. Under organization billing the
|
|
25
|
+
* capability asks *which subject is this caller acting for* and the adopter answers from its own
|
|
26
|
+
* session. Unanswered is unentitled, which is the direction every gate in the kit already fails.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* The kinds of thing that can hold a purchase.
|
|
30
|
+
*
|
|
31
|
+
* **An enum rather than a free string**, because a free string is a column that ends up holding `org`,
|
|
32
|
+
* `organization` and `Organization` in three adopters, and every gate comparing it is then comparing
|
|
33
|
+
* spellings rather than facts.
|
|
34
|
+
*
|
|
35
|
+
* **Spelled with a `z`, deliberately.** The only realistic way an adopter has organizations at all is
|
|
36
|
+
* Better Auth's `organization()` plugin, which `@pithy-sh/auth` composes verbatim: it ships the
|
|
37
|
+
* `organization`, `member` and `invitation` tables and writes `active_organization_id` onto the session.
|
|
38
|
+
* An adopter wiring the subject seam reads `session.activeOrganizationId` and writes the value below on
|
|
39
|
+
* the next line, so the two must match. This is a stored token in a column and a UNIQUE index — it
|
|
40
|
+
* cannot be respelled later — and it is the one place in this repository where the American spelling is
|
|
41
|
+
* correct: it is an identifier inherited from a dependency, not prose.
|
|
42
|
+
*/
|
|
43
|
+
const PaymentsSubjectType = z.enum(["user", "organization"]).describe("What kind of thing holds a purchase — one person, or one organization. Spelled to match Better Auth's `organization()` plugin, whose session column an adopter reads to answer the subject seam.");
|
|
44
|
+
/**
|
|
45
|
+
* The longest a subject id may be.
|
|
46
|
+
*
|
|
47
|
+
* **Derived from the narrowest provider field a reference is written into, not chosen.** A subject
|
|
48
|
+
* crosses to a store as {@link encodeSubjectReference}'s output, and Stripe's `client_reference_id` caps
|
|
49
|
+
* at 200 characters. A provider that silently truncates a longer value would hand back a string that
|
|
50
|
+
* decodes to a *different* id, attributing the purchase to whoever holds it — so the cap is enforced
|
|
51
|
+
* here, at the schema, where it fails on the way out instead of on the way back.
|
|
52
|
+
*
|
|
53
|
+
* 200 less `organization:` (13) leaves 187; 180 is that with room for a longer type member than either
|
|
54
|
+
* of today's, and it is far past any id the kit or Better Auth mints (both are UUIDs).
|
|
55
|
+
*/
|
|
56
|
+
const MAX_SUBJECT_ID_LENGTH = 180;
|
|
57
|
+
/** How a subject's two halves are joined in a single string. See {@link encodeSubjectReference}. */
|
|
58
|
+
const SUBJECT_REFERENCE_SEPARATOR = ":";
|
|
59
|
+
/**
|
|
60
|
+
* The id half of a subject — opaque to this package. It is a Pithy user id under `user`, and whatever
|
|
61
|
+
* the adopter's own membership model calls an organization under `organization`.
|
|
62
|
+
*/
|
|
63
|
+
const SubjectId = z.string().min(1).max(180).describe("The subject's own id — a Pithy user id, or the adopter's organization id. Opaque here: payments never resolves it to anything.");
|
|
64
|
+
/**
|
|
65
|
+
* A subject: the pair, as every row carries it and every function takes it.
|
|
66
|
+
*
|
|
67
|
+
* **Passed as this object rather than two positional strings**, deliberately. Two adjacent `string`
|
|
68
|
+
* parameters are two parameters a call site can transpose, and transposing them typechecks. The object
|
|
69
|
+
* makes the halves nameable and inseparable, which is what keeps the invariant — a subject is read from
|
|
70
|
+
* and written to one row atomically, and no code path pairs a type from config with an id from a row.
|
|
71
|
+
*/
|
|
72
|
+
const PaymentsSubject = z.object({
|
|
73
|
+
subjectType: PaymentsSubjectType.describe("Whether `subjectId` names a user or an organization."),
|
|
74
|
+
subjectId: SubjectId
|
|
75
|
+
}).describe("Who holds a purchase and the entitlements it grants — a user or an organization, and its id.");
|
|
76
|
+
/**
|
|
77
|
+
* Whether two subjects are the same holder — **both halves, always**.
|
|
78
|
+
*
|
|
79
|
+
* `undefined` is never equal to anything, including another `undefined`. An unresolved owner compared
|
|
80
|
+
* equal to an unresolved owner is how a webhook nobody could attribute would pass an ownership check,
|
|
81
|
+
* and that check is the only thing standing between one customer's renewal and another's account.
|
|
82
|
+
*/
|
|
83
|
+
function sameSubject(a, b) {
|
|
84
|
+
if (a === void 0 || b === void 0) return false;
|
|
85
|
+
return a.subjectType === b.subjectType && a.subjectId === b.subjectId;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A subject as one string, for the single-field slots a store gives us — Apple's `appAccountToken`,
|
|
89
|
+
* Google's `obfuscatedAccountId`, Stripe's `client_reference_id`, Paddle's and Lemon Squeezy's custom
|
|
90
|
+
* data.
|
|
91
|
+
*
|
|
92
|
+
* **One encoding, in one function, with one decoder.** These values leave our control and come back
|
|
93
|
+
* through a webhook, so the format is a wire contract with five providers at once. A second encoding
|
|
94
|
+
* anywhere means a purchase stamped by one code path and read by another resolves to nobody — or, worse,
|
|
95
|
+
* to somebody.
|
|
96
|
+
*
|
|
97
|
+
* The type half leads so the string sorts and greps by kind, and so a value that is *not* this encoding
|
|
98
|
+
* is recognizable at a glance in a provider's dashboard.
|
|
99
|
+
*/
|
|
100
|
+
function encodeSubjectReference(subject) {
|
|
101
|
+
return `${subject.subjectType}${SUBJECT_REFERENCE_SEPARATOR}${subject.subjectId}`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The inverse, and **strict**: anything that is not exactly this encoding is `undefined`, never a guess.
|
|
105
|
+
*
|
|
106
|
+
* The input is a value a client put in a purchase and a store handed back, so it may be anything at all.
|
|
107
|
+
* The dangerous shape is a bare id — the format every pre-subject client sent — which a lenient decoder
|
|
108
|
+
* would read as a user, attributing a stranger's purchase to whoever holds that id. So a reference with
|
|
109
|
+
* no separator does not decode, an unknown type half does not decode, and an empty half does not decode.
|
|
110
|
+
* Every caller treats `undefined` as *orphaned*: the event is recorded and replayable, and nothing is
|
|
111
|
+
* granted.
|
|
112
|
+
*
|
|
113
|
+
* Splits on the **first** separator only, so an adopter whose organization ids contain colons round-trips.
|
|
114
|
+
*/
|
|
115
|
+
function decodeSubjectReference(reference) {
|
|
116
|
+
const at = reference.indexOf(SUBJECT_REFERENCE_SEPARATOR);
|
|
117
|
+
if (at <= 0) return void 0;
|
|
118
|
+
const parsed = PaymentsSubject.safeParse({
|
|
119
|
+
subjectType: reference.slice(0, at),
|
|
120
|
+
subjectId: reference.slice(at + 1)
|
|
121
|
+
});
|
|
122
|
+
return parsed.success ? parsed.data : void 0;
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { MAX_SUBJECT_ID_LENGTH, PaymentsSubject, PaymentsSubjectType, decodeSubjectReference, encodeSubjectReference, sameSubject };
|