@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,280 @@
|
|
|
1
|
+
import { encodeSubjectReference, sameSubject } from "../data/subject.js";
|
|
2
|
+
import { entitlementsForProduct, productForProviderSku } from "../config/config.js";
|
|
3
|
+
import { PaymentsEntitlement } from "../data/entitlement.js";
|
|
4
|
+
import { grantingStatuses } from "../data/status.js";
|
|
5
|
+
import { PaymentsPurchase } from "../data/purchase.js";
|
|
6
|
+
import { PAYMENTS_ENTITLEMENTS_TABLE, PAYMENTS_PURCHASES_TABLE, paymentsDatabase } from "../data/tables.js";
|
|
7
|
+
import { PaymentsEnvironmentMismatchError, PaymentsProductNotFoundError, PaymentsReceiptAlreadyOwnedError } from "../error/errors.js";
|
|
8
|
+
import { ProviderEvent } from "./event.js";
|
|
9
|
+
import { InternalError } from "@pithy-sh/core/src/error/pithyError";
|
|
10
|
+
import { withD1Retry } from "@pithy-sh/core/src/data/withD1Retry";
|
|
11
|
+
import { chunkByBoundParameters } from "@pithy-sh/core/src/data/boundParameters";
|
|
12
|
+
import { sql } from "kysely";
|
|
13
|
+
//#region src/projection/writer.ts
|
|
14
|
+
/**
|
|
15
|
+
* Project one normalized provider event. Returns what changed; throws only the three refusals above and
|
|
16
|
+
* whatever D1 raises that is not a constraint we expect.
|
|
17
|
+
*/
|
|
18
|
+
async function projectPurchase(d1, input, options) {
|
|
19
|
+
const event = ProviderEvent.parse(input);
|
|
20
|
+
const subject = {
|
|
21
|
+
subjectType: event.subjectType,
|
|
22
|
+
subjectId: event.subjectId
|
|
23
|
+
};
|
|
24
|
+
const { config } = options;
|
|
25
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
26
|
+
const newId = options.newId ?? (() => crypto.randomUUID());
|
|
27
|
+
if (event.environment !== options.environment) throw new PaymentsEnvironmentMismatchError({ detail: `${event.rail} transaction ${event.providerTransactionId} is ${event.environment}; this deployment is ${options.environment}.` });
|
|
28
|
+
const entry = productForProviderSku(config, event.rail, event.providerProductId);
|
|
29
|
+
if (entry === void 0) throw new PaymentsProductNotFoundError({ detail: `No catalog product maps the ${event.rail} SKU "${event.providerProductId}".` });
|
|
30
|
+
const db = paymentsDatabase(d1);
|
|
31
|
+
const existing = await readPurchase(db, event);
|
|
32
|
+
if (existing !== void 0) {
|
|
33
|
+
if (!sameSubject(existing, subject)) throw alreadyOwned(event, existing);
|
|
34
|
+
if (existing.providerEventAt.getTime() >= event.providerEventAt.getTime()) {
|
|
35
|
+
const keys = affectedKeys(config, entry.product, existing.productId);
|
|
36
|
+
return {
|
|
37
|
+
outcome: "ignored",
|
|
38
|
+
purchase: existing,
|
|
39
|
+
product: {
|
|
40
|
+
id: existing.productId,
|
|
41
|
+
entitlements: entitlementsForProduct(config, existing.productId)
|
|
42
|
+
},
|
|
43
|
+
entitlements: await readEntitlements(db, subject, keys)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const keys = await keysToDerive(db, config, entry.product, existing?.productId, subject);
|
|
48
|
+
const row = PaymentsPurchase.encode({
|
|
49
|
+
id: existing?.id ?? newId(),
|
|
50
|
+
...subject,
|
|
51
|
+
rail: event.rail,
|
|
52
|
+
providerTransactionId: event.providerTransactionId,
|
|
53
|
+
productId: entry.id,
|
|
54
|
+
providerProductId: event.providerProductId,
|
|
55
|
+
type: entry.product.type,
|
|
56
|
+
status: event.status,
|
|
57
|
+
role: event.role,
|
|
58
|
+
environment: event.environment,
|
|
59
|
+
purchasedAt: event.purchasedAt,
|
|
60
|
+
expiresAt: event.expiresAt,
|
|
61
|
+
revokedAt: event.revokedAt,
|
|
62
|
+
resumesAt: event.resumesAt,
|
|
63
|
+
originalTransactionId: event.originalTransactionId,
|
|
64
|
+
amountMinor: event.amountMinor,
|
|
65
|
+
currency: event.currency,
|
|
66
|
+
providerEventAt: event.providerEventAt,
|
|
67
|
+
payload: event.payload,
|
|
68
|
+
createdAt: existing?.createdAt ?? now,
|
|
69
|
+
updatedAt: now
|
|
70
|
+
});
|
|
71
|
+
const at = now.getTime();
|
|
72
|
+
const statements = [upsertPurchaseStatement(d1, row)];
|
|
73
|
+
for (const key of keys) {
|
|
74
|
+
statements.push(compile(d1, ensureEntitlement(db, newId(), subject, key, at)));
|
|
75
|
+
statements.push(compile(d1, deriveEntitlement(db, config, subject, key, at)));
|
|
76
|
+
}
|
|
77
|
+
await withD1Retry(() => d1.batch(statements));
|
|
78
|
+
const projected = await readPurchase(db, event);
|
|
79
|
+
if (projected === void 0) throw new InternalError({
|
|
80
|
+
message: "The purchase could not be recorded.",
|
|
81
|
+
action: "Retry. If it persists, check the app database for the pithy_payments_* tables.",
|
|
82
|
+
detail: `Projected ${event.rail} transaction ${event.providerTransactionId} but could not read it back.`
|
|
83
|
+
});
|
|
84
|
+
if (!sameSubject(projected, subject)) throw alreadyOwned(event, projected);
|
|
85
|
+
return {
|
|
86
|
+
outcome: projected.providerEventAt.getTime() !== event.providerEventAt.getTime() ? "ignored" : existing === void 0 ? "created" : "updated",
|
|
87
|
+
purchase: projected,
|
|
88
|
+
product: {
|
|
89
|
+
id: entry.id,
|
|
90
|
+
entitlements: entry.product.entitlements
|
|
91
|
+
},
|
|
92
|
+
entitlements: await readEntitlements(db, subject, keys)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The 409, with the throw-site context in `detail` where an operator sees it and a client never does.
|
|
97
|
+
*
|
|
98
|
+
* Both subjects are rendered through `encodeSubjectReference`, so the line names the *kind* as well as the
|
|
99
|
+
* id. The interesting refusal is the one where the two ids read identically and only the kind differs, and
|
|
100
|
+
* a log printing bare ids would render that as a machine refusing `acme` on behalf of `acme`.
|
|
101
|
+
*/
|
|
102
|
+
function alreadyOwned(event, owner) {
|
|
103
|
+
return new PaymentsReceiptAlreadyOwnedError({ detail: `${event.rail} transaction ${event.providerTransactionId} is owned by ${encodeSubjectReference(owner)}; ${encodeSubjectReference(event)} submitted it.` });
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The entitlement keys the catalog says this event touches: the ones its product grants, plus the ones the
|
|
107
|
+
* row's previous product granted when a catalog edit re-mapped the SKU. Sorted, so a batch's statement order
|
|
108
|
+
* is deterministic and two concurrent projections for one subject cannot deadlock on opposite orders.
|
|
109
|
+
*/
|
|
110
|
+
function affectedKeys(config, product, previousProductId) {
|
|
111
|
+
const keys = new Set(product.entitlements);
|
|
112
|
+
if (previousProductId !== void 0) for (const key of entitlementsForProduct(config, previousProductId)) keys.add(key);
|
|
113
|
+
return [...keys].sort();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Every key a write must re-derive: what {@link affectedKeys} reads out of the catalog, **plus the keys this
|
|
117
|
+
* subject still holds that no current product grants at all**.
|
|
118
|
+
*
|
|
119
|
+
* That second set cannot come from the config, because it is precisely what the config no longer mentions.
|
|
120
|
+
* Drop `beta` from a product's `entitlements` and ship, and every subject holding it holds it forever
|
|
121
|
+
* otherwise: no purchase for that key will ever arrive again, the read path only lapses a row carrying a
|
|
122
|
+
* dated expiry, and the reconciliation pass re-asks about subscriptions. A catalog edit is a deploy, so the
|
|
123
|
+
* repair is one indexed read per projection and lands on this subject's next purchase event, whatever it
|
|
124
|
+
* was about.
|
|
125
|
+
*
|
|
126
|
+
* Held rows are excluded, and the `active` filter keeps the set to rows that still claim something — a
|
|
127
|
+
* support comp of a key the catalog never sold is a human's decision, and an already-cleared row needs no
|
|
128
|
+
* second clearing. Sorted for the same reason as above.
|
|
129
|
+
*/
|
|
130
|
+
async function keysToDerive(db, config, product, previousProductId, subject) {
|
|
131
|
+
const keys = new Set(affectedKeys(config, product, previousProductId));
|
|
132
|
+
const granted = /* @__PURE__ */ new Set();
|
|
133
|
+
for (const candidate of Object.values(config.products)) for (const key of candidate.entitlements) granted.add(key);
|
|
134
|
+
const held = await db.selectFrom(PAYMENTS_ENTITLEMENTS_TABLE).select("entitlement").where("subjectType", "=", subject.subjectType).where("subjectId", "=", subject.subjectId).where("active", "=", 1).where("manual", "=", 0).execute();
|
|
135
|
+
for (const row of held) if (!granted.has(row.entitlement)) keys.add(row.entitlement);
|
|
136
|
+
return [...keys].sort();
|
|
137
|
+
}
|
|
138
|
+
/** The purchase row for this `(rail, providerTransactionId)`, decoded, or undefined. */
|
|
139
|
+
async function readPurchase(db, event) {
|
|
140
|
+
const row = await db.selectFrom(PAYMENTS_PURCHASES_TABLE).selectAll().where("rail", "=", event.rail).where("providerTransactionId", "=", event.providerTransactionId).executeTakeFirst();
|
|
141
|
+
return row === void 0 ? void 0 : PaymentsPurchase.parse(row);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The entitlement rows for these keys, decoded, in key order. Empty when the product grants none.
|
|
145
|
+
*
|
|
146
|
+
* Chunked, because `keys` is no longer bounded by one product: {@link keysToDerive} adds every key this
|
|
147
|
+
* subject holds that the catalog dropped, and a long-lived account collects them. One statement binds a
|
|
148
|
+
* parameter per key **plus both halves of the subject** — hence `fixed` of 2, where an owner that was one
|
|
149
|
+
* column wanted 1.
|
|
150
|
+
*
|
|
151
|
+
* That number is the whole safety of this loop, and getting it wrong is silent until it is not: left at 1
|
|
152
|
+
* the chunker hands back 100 keys, the statement binds 102, and D1 refuses the statement outright rather
|
|
153
|
+
* than truncating the list. The write has already committed by then, so the failure lands on the read-back
|
|
154
|
+
* of a purchase that was recorded perfectly — and only on the long-lived accounts the chunking exists for.
|
|
155
|
+
*/
|
|
156
|
+
async function readEntitlements(db, subject, keys) {
|
|
157
|
+
const entitlements = [];
|
|
158
|
+
for (const chunk of chunkByBoundParameters(keys, 2)) {
|
|
159
|
+
const rows = await db.selectFrom(PAYMENTS_ENTITLEMENTS_TABLE).selectAll().where("subjectType", "=", subject.subjectType).where("subjectId", "=", subject.subjectId).where("entitlement", "in", chunk).execute();
|
|
160
|
+
for (const row of rows) entitlements.push(PaymentsEntitlement.parse(row));
|
|
161
|
+
}
|
|
162
|
+
return entitlements.sort((left, right) => left.entitlement < right.entitlement ? -1 : 1);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The purchase upsert, compiled to the statement that joins the batch. **The only place either commit-time
|
|
166
|
+
* guard is expressed**, and exported for that reason: a test can compile it, let the table move underneath
|
|
167
|
+
* the compiled statement, and execute it — which is the one way to reach the `ON CONFLICT` predicate.
|
|
168
|
+
* Driving `projectPurchase` cannot do it, because its pre-read and post-batch checks serialize around the
|
|
169
|
+
* predicate and cover the same outcomes, so a test at that level passes with the predicate deleted.
|
|
170
|
+
*/
|
|
171
|
+
function upsertPurchaseStatement(d1, row) {
|
|
172
|
+
return compile(d1, upsertPurchase(paymentsDatabase(d1), row));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The purchase upsert. Both guards live on the `ON CONFLICT` branch rather than only in the pre-read,
|
|
176
|
+
* because a pre-read cannot see a concurrent writer: SQLite evaluates them against the row as it stands at
|
|
177
|
+
* commit, so a stale event and a receipt lifted from another account are both refused by the database.
|
|
178
|
+
*
|
|
179
|
+
* `id`, `subjectType`, `subjectId`, and `createdAt` are absent from the update set on purpose — a
|
|
180
|
+
* transaction's identity, its owner, and when it was first projected are immutable.
|
|
181
|
+
*/
|
|
182
|
+
function upsertPurchase(db, row) {
|
|
183
|
+
return db.insertInto(PAYMENTS_PURCHASES_TABLE).values(row).onConflict((oc) => oc.columns(["rail", "providerTransactionId"]).doUpdateSet({
|
|
184
|
+
productId: row.productId,
|
|
185
|
+
providerProductId: row.providerProductId,
|
|
186
|
+
type: row.type,
|
|
187
|
+
status: row.status,
|
|
188
|
+
environment: row.environment,
|
|
189
|
+
purchasedAt: row.purchasedAt,
|
|
190
|
+
expiresAt: row.expiresAt,
|
|
191
|
+
revokedAt: row.revokedAt,
|
|
192
|
+
resumesAt: row.resumesAt,
|
|
193
|
+
originalTransactionId: row.originalTransactionId,
|
|
194
|
+
amountMinor: row.amountMinor,
|
|
195
|
+
currency: row.currency,
|
|
196
|
+
providerEventAt: row.providerEventAt,
|
|
197
|
+
payload: row.payload,
|
|
198
|
+
updatedAt: row.updatedAt
|
|
199
|
+
}).where((eb) => eb.and([
|
|
200
|
+
eb(eb.ref(`${PAYMENTS_PURCHASES_TABLE}.providerEventAt`), "<", row.providerEventAt),
|
|
201
|
+
eb(eb.ref(`${PAYMENTS_PURCHASES_TABLE}.subjectType`), "=", row.subjectType),
|
|
202
|
+
eb(eb.ref(`${PAYMENTS_PURCHASES_TABLE}.subjectId`), "=", row.subjectId)
|
|
203
|
+
])));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The entitlement row's existence. Cleared, so a project that grants nothing still leaves provenance.
|
|
207
|
+
*
|
|
208
|
+
* **The conflict target is the whole unique, all three columns.** SQLite resolves `ON CONFLICT` against an
|
|
209
|
+
* index rather than against a prefix of one, so a target naming `(subjectId, entitlement)` matches
|
|
210
|
+
* `UNIQUE (subjectType, subjectId, entitlement)` not at all and raises `ON CONFLICT clause does not match
|
|
211
|
+
* any PRIMARY KEY or UNIQUE constraint`. That throw happens inside the batch, which is the whole purchase
|
|
212
|
+
* write — so a target one column short does not cost an entitlement, it costs the sale.
|
|
213
|
+
*/
|
|
214
|
+
function ensureEntitlement(db, id, subject, key, at) {
|
|
215
|
+
const row = {
|
|
216
|
+
id,
|
|
217
|
+
...subject,
|
|
218
|
+
entitlement: key,
|
|
219
|
+
active: 0,
|
|
220
|
+
expiresAt: null,
|
|
221
|
+
sourcePurchaseId: null,
|
|
222
|
+
manual: 0,
|
|
223
|
+
createdAt: at,
|
|
224
|
+
updatedAt: at
|
|
225
|
+
};
|
|
226
|
+
return db.insertInto(PAYMENTS_ENTITLEMENTS_TABLE).values(row).onConflict((oc) => oc.columns([
|
|
227
|
+
"subjectType",
|
|
228
|
+
"subjectId",
|
|
229
|
+
"entitlement"
|
|
230
|
+
]).doNothing());
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Re-derive one entitlement row from the purchases table. The candidate set is named **once**, as a CTE, and
|
|
234
|
+
* read three times: is anything granting, when does the winner lapse, and which purchase is it.
|
|
235
|
+
*
|
|
236
|
+
* The winner is the purchase whose access runs longest — `NULLS FIRST` on a descending expiry puts a
|
|
237
|
+
* never-expiring purchase ahead of every dated one, which is right: owning `remove_ads` outright is not
|
|
238
|
+
* beaten by a subscription that ends. `providerEventAt` breaks a tie so the choice is deterministic.
|
|
239
|
+
*
|
|
240
|
+
* Written as a derivation rather than as values this function computed, because that is the difference
|
|
241
|
+
* between "the read model agrees with what I read a moment ago" and "the read model agrees with the
|
|
242
|
+
* purchases". Only the second survives a concurrent write.
|
|
243
|
+
*
|
|
244
|
+
* **The two subject predicates are the join, and they are the same pair.** The CTE reads the purchases
|
|
245
|
+
* table and the UPDATE writes the entitlements table, so those `where`s are the only thing tying one
|
|
246
|
+
* holder's money to one holder's row. Key them differently — one half here, both halves there, a type from
|
|
247
|
+
* config beside an id from a row — and the derivation reads one subject's purchases and writes another
|
|
248
|
+
* subject's entitlement. That is a grant nobody bought, and nothing downstream can tell.
|
|
249
|
+
*
|
|
250
|
+
* ## Two shapes here are about D1's bound-parameter cap, not about style
|
|
251
|
+
*
|
|
252
|
+
* D1 refuses a statement carrying more than 100 bound parameters (see `@pithy-sh/core`'s
|
|
253
|
+
* `boundParameters`), and this statement's list of granting products is the one part of it a *catalog* can
|
|
254
|
+
* grow. So the CTE names the candidate set once instead of inlining the subquery per column — three copies
|
|
255
|
+
* tripled every parameter — and the product ids travel as **one** JSON parameter that SQLite's `json_each`
|
|
256
|
+
* expands back into rows, so the count no longer depends on the catalog at all. Twenty-seven products
|
|
257
|
+
* granting one key used to throw `too many SQL variables`, and because the derivation shares the purchase
|
|
258
|
+
* write's batch, the throw meant no purchase touching that key could be recorded — a project with a few
|
|
259
|
+
* grandfathered prices could not sell.
|
|
260
|
+
*
|
|
261
|
+
* An empty list is the honest ordinary case, not a branch: `json_each('[]')` yields no rows, so no purchase
|
|
262
|
+
* qualifies and the row is cleared — which is exactly right when a catalog edit stops granting a key.
|
|
263
|
+
*/
|
|
264
|
+
function deriveEntitlement(db, config, subject, key, at) {
|
|
265
|
+
const grantingProducts = JSON.stringify(Object.entries(config.products).filter(([, product]) => product.entitlements.includes(key)).map(([id]) => id));
|
|
266
|
+
const statuses = grantingStatuses(config.graceGrantsAccess);
|
|
267
|
+
return db.with("winner", (cb) => cb.selectFrom(PAYMENTS_PURCHASES_TABLE).select(["id", "expiresAt"]).where("subjectType", "=", subject.subjectType).where("subjectId", "=", subject.subjectId).where(sql`${sql.ref("productId")} in (select value from json_each(${grantingProducts}))`).where("status", "in", statuses).where((inner) => inner.or([inner("expiresAt", "is", null), inner("expiresAt", ">", at)])).orderBy("expiresAt", (ob) => ob.desc().nullsFirst()).orderBy("providerEventAt", "desc").limit(1)).updateTable(PAYMENTS_ENTITLEMENTS_TABLE).set((eb) => ({
|
|
268
|
+
active: eb.exists(eb.selectFrom("winner").select("id")),
|
|
269
|
+
expiresAt: eb.selectFrom("winner").select("expiresAt"),
|
|
270
|
+
sourcePurchaseId: eb.selectFrom("winner").select("id"),
|
|
271
|
+
updatedAt: at
|
|
272
|
+
})).where("subjectType", "=", subject.subjectType).where("subjectId", "=", subject.subjectId).where("entitlement", "=", key).where("manual", "=", 0);
|
|
273
|
+
}
|
|
274
|
+
/** Compile a Kysely query to a D1 prepared statement, so it can join a `DB.batch` transaction. */
|
|
275
|
+
function compile(d1, query) {
|
|
276
|
+
const compiled = query.compile();
|
|
277
|
+
return d1.prepare(compiled.sql).bind(...compiled.parameters);
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
export { projectPurchase, upsertPurchaseStatement };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type WorkflowHostTemplate } from "@pithy-sh/core/src/workflow/host";
|
|
2
|
+
import type { ManagedEnvironment } from "@pithy-sh/secrets/src/scope";
|
|
3
|
+
import type { PaymentsConfig } from "../config/config";
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the reconcile worker's committed `wrangler.jsonc` template into one environment's standalone config.
|
|
6
|
+
* Every per-environment decision lives here; everything static — the compatibility date, the binding names —
|
|
7
|
+
* stays as the template committed it.
|
|
8
|
+
*
|
|
9
|
+
* Thin over core's {@link resolveWorkflowHost}, which owns the mechanics (clone, fill by binding name, stamp
|
|
10
|
+
* `ENVIRONMENT`). What this file adds is the one thing the generic resolver deliberately does not do: it
|
|
11
|
+
* **rewrites `workflows` and `triggers.crons` from the capability's specs** rather than from the template's own
|
|
12
|
+
* block. The template carries both so it reads as a complete, deployable config, but `workflows/specs.ts` is
|
|
13
|
+
* the single source of the binding name, the class name, and the schedule — so moving the pass off 04:00 is a
|
|
14
|
+
* one-line spec edit rather than a spec edit plus a JSONC edit that nothing checks agree.
|
|
15
|
+
*
|
|
16
|
+
* Pure: the caller parses the template and writes the result.
|
|
17
|
+
*/
|
|
18
|
+
/** The resolved ids and per-env values for one environment's reconcile-worker deploy. */
|
|
19
|
+
export interface PaymentsConfigParams {
|
|
20
|
+
/**
|
|
21
|
+
* The project name — the `<project>` segment the deployed worker and its reconcile Workflow lead
|
|
22
|
+
* with. The root `pithy.config.ts` `name`, resolved by `requireProjectName` and never guessed:
|
|
23
|
+
* Worker script and Workflow names are account-scoped, so a wrong value overwrites another project's
|
|
24
|
+
* running reconcile host rather than colliding with it.
|
|
25
|
+
*/
|
|
26
|
+
project: string;
|
|
27
|
+
/** The target environment. */
|
|
28
|
+
env: ManagedEnvironment;
|
|
29
|
+
/** The app database id for this environment — where the `pithy_payments_*` tables live. */
|
|
30
|
+
appDatabaseId: string;
|
|
31
|
+
/** This environment's secrets database id (`<project>-<env>-secrets`) — holds the rails' credentials. */
|
|
32
|
+
secretsDatabaseId: string;
|
|
33
|
+
/** The CF Secrets Store id holding the per-env master key. */
|
|
34
|
+
storeId: string;
|
|
35
|
+
/** The app's resolved payments config — serialized into the worker's `PAYMENTS_CONFIG` var. */
|
|
36
|
+
paymentsConfig: PaymentsConfig;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The deployed reconcile-worker name for a project's environment — also its resolved config's basename.
|
|
40
|
+
*
|
|
41
|
+
* Through core's naming facade under the **`worker`** namespace, so the name is held to a Worker
|
|
42
|
+
* script's 63 (not the generic composer's one-size 63 that happened to agree) and the environment is
|
|
43
|
+
* validated where it is bound rather than at the deploy that would have used it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function paymentsWorkerName(project: string, env: ManagedEnvironment): string;
|
|
46
|
+
/** Fill the template for one environment. */
|
|
47
|
+
export declare function resolvePaymentsConfig(template: WorkflowHostTemplate, params: PaymentsConfigParams): WorkflowHostTemplate;
|
|
48
|
+
//# sourceMappingURL=resolvePaymentsConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePaymentsConfig.d.ts","sourceRoot":"","sources":["../../src/provision/resolvePaymentsConfig.ts"],"names":[],"mappings":"AAIA,OAAO,EAAyC,KAAK,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAEpH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD;;;;;;;;;;;;;GAaG;AAEH,yFAAyF;AACzF,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,GAAG,EAAE,kBAAkB,CAAC;IACxB,2FAA2F;IAC3F,aAAa,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,iBAAiB,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,cAAc,EAAE,cAAc,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAEnF;AAED,6CAA6C;AAC7C,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,EAAE,oBAAoB,GAC3B,oBAAoB,CA6BtB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PAYMENTS_CAPABILITY, paymentsWorkflowRegistry } from "../workflows/specs.js";
|
|
2
|
+
import { resourceNames } from "@pithy-sh/core/src/naming/resourceNames";
|
|
3
|
+
import { hostWorkflowsFor, resolveWorkflowHost } from "@pithy-sh/core/src/workflow/host";
|
|
4
|
+
import { masterKeySecretName } from "@pithy-sh/secrets/src/provision/provisionSecrets";
|
|
5
|
+
//#region src/provision/resolvePaymentsConfig.ts
|
|
6
|
+
/**
|
|
7
|
+
* The deployed reconcile-worker name for a project's environment — also its resolved config's basename.
|
|
8
|
+
*
|
|
9
|
+
* Through core's naming facade under the **`worker`** namespace, so the name is held to a Worker
|
|
10
|
+
* script's 63 (not the generic composer's one-size 63 that happened to agree) and the environment is
|
|
11
|
+
* validated where it is bound rather than at the deploy that would have used it.
|
|
12
|
+
*/
|
|
13
|
+
function paymentsWorkerName(project, env) {
|
|
14
|
+
return resourceNames(project).env(env).worker(PAYMENTS_CAPABILITY);
|
|
15
|
+
}
|
|
16
|
+
/** Fill the template for one environment. */
|
|
17
|
+
function resolvePaymentsConfig(template, params) {
|
|
18
|
+
const { project, env, appDatabaseId, secretsDatabaseId, storeId, paymentsConfig } = params;
|
|
19
|
+
const derived = hostWorkflowsFor(paymentsWorkflowRegistry, {
|
|
20
|
+
project,
|
|
21
|
+
capability: PAYMENTS_CAPABILITY,
|
|
22
|
+
env
|
|
23
|
+
});
|
|
24
|
+
const resolved = resolveWorkflowHost(template, {
|
|
25
|
+
project,
|
|
26
|
+
capability: PAYMENTS_CAPABILITY,
|
|
27
|
+
env,
|
|
28
|
+
databaseIds: {
|
|
29
|
+
DB: appDatabaseId,
|
|
30
|
+
SECRETS: secretsDatabaseId
|
|
31
|
+
},
|
|
32
|
+
secretsStoreId: storeId,
|
|
33
|
+
masterKeySecretName: masterKeySecretName(project, env),
|
|
34
|
+
workflows: derived.workflows,
|
|
35
|
+
vars: { PAYMENTS_CONFIG: JSON.stringify(paymentsConfig) }
|
|
36
|
+
});
|
|
37
|
+
resolved.triggers = derived.crons.length > 0 ? { crons: derived.crons } : void 0;
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { paymentsWorkerName, resolvePaymentsConfig };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every Apple root a chain may terminate in, base64 DER. The last certificate in a JWS `x5c` must be
|
|
3
|
+
* byte-identical to one of these — a stronger check than re-verifying a self-signature, which only proves
|
|
4
|
+
* the root vouches for itself.
|
|
5
|
+
*/
|
|
6
|
+
export declare const APPLE_ROOT_CERTIFICATES: readonly string[];
|
|
7
|
+
//# sourceMappingURL=certs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"certs.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/certs.ts"],"names":[],"mappings":"AA4DA;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAAuB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every Apple root a chain may terminate in, base64 DER. The last certificate in a JWS `x5c` must be
|
|
3
|
+
* byte-identical to one of these — a stronger check than re-verifying a self-signature, which only proves
|
|
4
|
+
* the root vouches for itself.
|
|
5
|
+
*/
|
|
6
|
+
const APPLE_ROOT_CERTIFICATES = ["MIICQzCCAcmgAwIBAgIILcX8iNLFS5UwCgYIKoZIzj0EAwMwZzEbMBkGA1UEAwwSQXBwbGUgUm9vdCBDQSAtIEczMSYwJAYDVQQLDB1BcHBsZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTETMBEGA1UECgwKQXBwbGUgSW5jLjELMAkGA1UEBhMCVVMwHhcNMTQwNDMwMTgxOTA2WhcNMzkwNDMwMTgxOTA2WjBnMRswGQYDVQQDDBJBcHBsZSBSb290IENBIC0gRzMxJjAkBgNVBAsMHUFwcGxlIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRMwEQYDVQQKDApBcHBsZSBJbmMuMQswCQYDVQQGEwJVUzB2MBAGByqGSM49AgEGBSuBBAAiA2IABJjpLz1AcqTtkyJygRMc3RCV8cWjTnHcFBbZDuWmBSp3ZHtfTjjTuxxEtX/1H7YyYl3J6YRbTzBPEVoA/VhYDKX1DyxNB0cTddqXl5dvMVztK517IDvYuVTZXpmkOlEKMaNCMEAwHQYDVR0OBBYEFLuw3qFYM4iapIqZ3r6966/ayySrMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMAoGCCqGSM49BAMDA2gAMGUCMQCD6cHEFl4aXTQY2e3v9GwOAEZLuN+yRhHFD/3meoyhpmvOwgPUnPWTxnS4at+qIxUCMG1mihDK1A3UT82NQz60imOlM27jbdoXt2QfyFMm+YhidDkLF1vLUagM6BgD56KyKA=="];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { APPLE_ROOT_CERTIFICATES };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The byte encodings Apple's signed data is built from: base64 and base64url, and just enough ASN.1 DER
|
|
3
|
+
* to walk an X.509 certificate.
|
|
4
|
+
*
|
|
5
|
+
* **Why this exists at all.** Verifying an App Store Server Notification means verifying a JWS against a
|
|
6
|
+
* certificate chain, and there is no certificate parser in the Workers runtime — `crypto.subtle` imports a
|
|
7
|
+
* SubjectPublicKeyInfo but will not open a certificate to find one. Node's `X509Certificate` is not
|
|
8
|
+
* available here. So the parts of DER the chain needs are read directly, and nothing more: this is a
|
|
9
|
+
* reader, never a general ASN.1 library, and it has no encoder.
|
|
10
|
+
*
|
|
11
|
+
* **Every parse is hostile-input parsing.** These bytes arrive in an unauthenticated HTTP request, which
|
|
12
|
+
* is the whole point of verifying them, so every length is checked against the buffer it claims to live in
|
|
13
|
+
* before it is trusted. A length that overruns its buffer or its parent is refused rather than clamped —
|
|
14
|
+
* clamping would let a crafted certificate present bytes that were never inside it. Indefinite lengths are
|
|
15
|
+
* refused outright: DER forbids them, and honoring BER's end-of-contents marker is how a parser is made
|
|
16
|
+
* to disagree with the verifier about where a structure ends.
|
|
17
|
+
*
|
|
18
|
+
* Failures throw `payments/invalid_receipt` — malformed, not merely unverified. A caller on the webhook
|
|
19
|
+
* path maps that to `payments/webhook_unverified`, so one implementation serves both paths with the right
|
|
20
|
+
* code on each.
|
|
21
|
+
*/
|
|
22
|
+
/** DER tag for a constructed SEQUENCE. */
|
|
23
|
+
export declare const ASN1_SEQUENCE = 48;
|
|
24
|
+
/** DER tag for an INTEGER. */
|
|
25
|
+
export declare const ASN1_INTEGER = 2;
|
|
26
|
+
/** DER tag for a BIT STRING. */
|
|
27
|
+
export declare const ASN1_BIT_STRING = 3;
|
|
28
|
+
/** DER tag for an OBJECT IDENTIFIER. */
|
|
29
|
+
export declare const ASN1_OID = 6;
|
|
30
|
+
/** DER tag for a UTCTime. */
|
|
31
|
+
export declare const ASN1_UTC_TIME = 23;
|
|
32
|
+
/** DER tag for a GeneralizedTime. */
|
|
33
|
+
export declare const ASN1_GENERALIZED_TIME = 24;
|
|
34
|
+
/** DER tag for a BOOLEAN — how an extension states `critical`, and how basicConstraints states `cA`. */
|
|
35
|
+
export declare const ASN1_BOOLEAN = 1;
|
|
36
|
+
/** DER tag for an OCTET STRING — an X.509 extension's value is one, wrapping the extension's own DER. */
|
|
37
|
+
export declare const ASN1_OCTET_STRING = 4;
|
|
38
|
+
/** One ASN.1 node: its tag, the whole encoding, and the contents. */
|
|
39
|
+
export interface Asn1Node {
|
|
40
|
+
/** The tag byte, context-specific tags included (`0xa0` for `[0]`). */
|
|
41
|
+
tag: number;
|
|
42
|
+
/**
|
|
43
|
+
* The node's whole DER encoding, tag and length bytes included. This is the field a signature covers —
|
|
44
|
+
* a certificate's `tbsCertificate` is signed as encoded, not as contents — so it is kept rather than
|
|
45
|
+
* reconstructed.
|
|
46
|
+
*/
|
|
47
|
+
der: Uint8Array;
|
|
48
|
+
/** The contents octets, without the tag or length. */
|
|
49
|
+
value: Uint8Array;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read one DER node at `offset`. Returns the node and the offset just past it, so a caller walks a
|
|
53
|
+
* sequence by feeding the returned `end` back in.
|
|
54
|
+
*/
|
|
55
|
+
export declare function readAsn1(bytes: Uint8Array, offset?: number): {
|
|
56
|
+
node: Asn1Node;
|
|
57
|
+
end: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The members of a constructed node, in order. Each member is read from the parent's contents, so a member
|
|
61
|
+
* that overruns the parent is refused — the check the parent's own length would otherwise not enforce.
|
|
62
|
+
*/
|
|
63
|
+
export declare function asn1Children(node: Asn1Node): Asn1Node[];
|
|
64
|
+
/**
|
|
65
|
+
* An OBJECT IDENTIFIER as dotted decimal. Algorithm and curve identities are compared as strings rather
|
|
66
|
+
* than as byte patterns, so the comparison sites read as the names they mean.
|
|
67
|
+
*/
|
|
68
|
+
export declare function readOid(node: Asn1Node): string;
|
|
69
|
+
/**
|
|
70
|
+
* An X.509 ECDSA signature (`SEQUENCE { INTEGER r, INTEGER s }`) as the fixed-width `r || s` WebCrypto
|
|
71
|
+
* verifies. `size` is the curve's coordinate size — 32 bytes for P-256, 48 for P-384.
|
|
72
|
+
*
|
|
73
|
+
* The two encodings differ in exactly the way that trips people up. DER writes each integer with the
|
|
74
|
+
* fewest bytes that keep it positive, so a coordinate whose top bit is set gains a leading zero and a
|
|
75
|
+
* small one loses leading bytes. WebCrypto wants both coordinates at full width. So the padding byte is
|
|
76
|
+
* stripped and the remainder right-aligned; a value still wider than the curve after stripping is refused
|
|
77
|
+
* rather than truncated, because truncating a signature makes a forgery verify.
|
|
78
|
+
*/
|
|
79
|
+
export declare function derSignatureToRaw(der: Uint8Array, size: number): Uint8Array;
|
|
80
|
+
/**
|
|
81
|
+
* A DER BOOLEAN. DER admits exactly two encodings — `0x00` false, `0xff` true — and anything else is
|
|
82
|
+
* refused rather than coerced. A parser that read any non-zero byte as true would disagree with an encoder
|
|
83
|
+
* that wrote `0x01`, and for `basicConstraints.cA` that disagreement is the difference between a
|
|
84
|
+
* certificate authority and a leaf.
|
|
85
|
+
*/
|
|
86
|
+
export declare function readBoolean(node: Asn1Node): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* A non-negative INTEGER, as a number. Only used for small constrained values (`pathLenConstraint`), so a
|
|
89
|
+
* value wider than is plausible is refused rather than silently losing precision past 2^53.
|
|
90
|
+
*/
|
|
91
|
+
export declare function readInteger(node: Asn1Node): number;
|
|
92
|
+
/**
|
|
93
|
+
* A BIT STRING's bits, most-significant first, as booleans. The first contents byte counts the unused
|
|
94
|
+
* trailing bits of the last byte, and those are dropped — a `keyUsage` with padding read as data would
|
|
95
|
+
* report permissions the certificate never granted.
|
|
96
|
+
*/
|
|
97
|
+
export declare function readBits(node: Asn1Node): boolean[];
|
|
98
|
+
/** Bytes from a base64 string, standard alphabet — how a JWS header's `x5c` carries a certificate. */
|
|
99
|
+
export declare function decodeBase64(encoded: string): Uint8Array;
|
|
100
|
+
/**
|
|
101
|
+
* Bytes from a base64url string — how a JWS carries its header, payload, and signature. The URL alphabet
|
|
102
|
+
* substitutes `-` and `_`, and drops the padding, so both are restored before decoding.
|
|
103
|
+
*/
|
|
104
|
+
export declare function decodeBase64Url(encoded: string): Uint8Array;
|
|
105
|
+
/** Whether two byte strings have identical contents. Used to match a pinned root and to link a chain. */
|
|
106
|
+
export declare function bytesEqual(left: Uint8Array, right: Uint8Array): boolean;
|
|
107
|
+
//# sourceMappingURL=der.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"der.d.ts","sourceRoot":"","sources":["../../../src/rails/apple/der.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,0CAA0C;AAC1C,eAAO,MAAM,aAAa,KAAO,CAAC;AAClC,8BAA8B;AAC9B,eAAO,MAAM,YAAY,IAAO,CAAC;AACjC,gCAAgC;AAChC,eAAO,MAAM,eAAe,IAAO,CAAC;AACpC,wCAAwC;AACxC,eAAO,MAAM,QAAQ,IAAO,CAAC;AAC7B,6BAA6B;AAC7B,eAAO,MAAM,aAAa,KAAO,CAAC;AAClC,qCAAqC;AACrC,eAAO,MAAM,qBAAqB,KAAO,CAAC;AAC1C,wGAAwG;AACxG,eAAO,MAAM,YAAY,IAAO,CAAC;AACjC,yGAAyG;AACzG,eAAO,MAAM,iBAAiB,IAAO,CAAC;AAKtC,qEAAqE;AACrE,MAAM,WAAW,QAAQ;IACvB,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,GAAG,EAAE,UAAU,CAAC;IAChB,sDAAsD;IACtD,KAAK,EAAE,UAAU,CAAC;CACnB;AAWD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CA4BvF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAUvD;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAmB9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAc3E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAOnD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAQlD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,EAAE,CAclD;AAED,sGAAsG;AACtG,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CASxD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAI3D;AAED,yGAAyG;AACzG,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAIvE"}
|