@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 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/rails/contract.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5F,OAAO,KAAK,EAAE,gBAAgB,EAA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AAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAC7G;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACvG;;;;;;;;;OASG;IACH,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC/G;;;;;;;;;;;;;;;;;OAiBG;IACH,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC1G;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,oBAAoB,GAC7B,QAAQ,IAAI,oBAAoB,GAAG,gBAAgB,CASrD;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;OASG;IACH,SAAS,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACvC;;;;;;;;OAQG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;OAOG;IACH,cAAc,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAChG;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,oBAAoB,GAAG,QAAQ,IAAI,oBAAoB,GAAG,UAAU,CAE1G"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region src/rails/contract.ts
|
|
2
|
+
/** The note's text, whichever kind it is. An operator reads the two the same way; the row does not. */
|
|
3
|
+
function noteText(note) {
|
|
4
|
+
if (note === null || note === void 0) return void 0;
|
|
5
|
+
return "stated" in note ? note.stated : note.read;
|
|
6
|
+
}
|
|
7
|
+
/** Whether this note leaves the delivery repairable — true only for one a read produced. */
|
|
8
|
+
function noteIsRepairable(note) {
|
|
9
|
+
return note !== null && note !== void 0 && "read" in note;
|
|
10
|
+
}
|
|
11
|
+
/** Whether a rail provider also initiates purchases. The one narrowing `/checkout` and `/portal` need. */
|
|
12
|
+
function isCheckoutRail(provider) {
|
|
13
|
+
return typeof provider.createCheckoutSession === "function" && typeof provider.createPortalSession === "function";
|
|
14
|
+
}
|
|
15
|
+
/** Whether a rail reports pricing. Structural, like the others. */
|
|
16
|
+
function isPricingRail(provider) {
|
|
17
|
+
return typeof provider.readPricing === "function";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether a rail can mint **and** list discounts. Structural, so a rail gains the ability without an edit here.
|
|
21
|
+
*
|
|
22
|
+
* **It ANDs both methods, and until #465 it did not.** {@link DiscountRail} declares two, and a guard probing
|
|
23
|
+
* `createDiscount` alone narrowed a rail that could mint and not list into a type promising both — so
|
|
24
|
+
* `GET {base}/admin/discounts` passed its own guard and then called a method that was not there. That is a
|
|
25
|
+
* `TypeError` inside a handler, which reaches a management pane as a 500, where a rail that plainly cannot
|
|
26
|
+
* mint gets `rail_not_configured` and a pane that can say so. No rail ever hit it: all three hosted rails
|
|
27
|
+
* declare both. It was a defect waiting for the fourth, and it is the one every other guard here is written
|
|
28
|
+
* against by name.
|
|
29
|
+
*/
|
|
30
|
+
function isDiscountRail(provider) {
|
|
31
|
+
const rail = provider;
|
|
32
|
+
return typeof rail.createDiscount === "function" && typeof rail.listDiscounts === "function";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether a rail can manage a subscription from the server. Structural, like the others — and **it ANDs all
|
|
36
|
+
* five methods**, which the others do not all do.
|
|
37
|
+
*
|
|
38
|
+
* Every guard in this file ANDs its whole interface now, which was not true when this one was written — see
|
|
39
|
+
* {@link isDiscountRail} for the shape and what it cost. A guard that probes one method narrows a
|
|
40
|
+
* partially-implemented rail into a type promising the rest, and the first thing anybody learns about the gap
|
|
41
|
+
* is a `TypeError` thrown mid-cancellation, on a route that has already written an audit row. Here a rail
|
|
42
|
+
* missing any one verb is simply not a subscription rail, and the route answers `rail_not_configured` — which
|
|
43
|
+
* is true, and which is a refusal rather than a half-applied change.
|
|
44
|
+
*/
|
|
45
|
+
function isSubscriptionRail(provider) {
|
|
46
|
+
const rail = provider;
|
|
47
|
+
return typeof rail.readStanding === "function" && typeof rail.previewChange === "function" && typeof rail.changePlan === "function" && typeof rail.cancelSubscription === "function" && typeof rail.keepSubscription === "function";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether a rail can refund at its store. Structural, like the others.
|
|
51
|
+
*
|
|
52
|
+
* One method, so probing it *is* ANDing all of them — {@link isSubscriptionRail}'s rule, satisfied by
|
|
53
|
+
* arithmetic rather than by care. Stated because that stops being true the moment a second method is added
|
|
54
|
+
* here, and a guard left probing one of two is what {@link isDiscountRail} did until #465.
|
|
55
|
+
*/
|
|
56
|
+
function isRefundRail(provider) {
|
|
57
|
+
return typeof provider.requestRefunds === "function";
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { isCheckoutRail, isDiscountRail, isPricingRail, isRefundRail, isSubscriptionRail, noteIsRepairable, noteText };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { GoogleJwk } from "../oidc";
|
|
2
|
+
/**
|
|
3
|
+
* Test material for Google's rail: a real RSA key, real RS256 signatures, and the Pub/Sub push envelope
|
|
4
|
+
* Google wraps a Real-time Developer Notification in.
|
|
5
|
+
*
|
|
6
|
+
* The OIDC token on a push is the authenticity boundary for the Google webhook, so its tests have to exercise
|
|
7
|
+
* genuine cryptography — a stubbed verifier proves only that a mock refuses when told to. And no test may
|
|
8
|
+
* reach Google. So the suites mint their own signing key here, publish it as a JWK the verifier is given, and
|
|
9
|
+
* sign real tokens with it: the same arrangement as the Apple rail's minted certificate chain, one layer
|
|
10
|
+
* simpler because Google publishes bare keys rather than a chain.
|
|
11
|
+
*
|
|
12
|
+
* That makes the negative cases real too. A token signed by the wrong key is a second minted key. An expired
|
|
13
|
+
* token is a real signature over a past `exp`. An algorithm-confused token is a genuine RSA signature under a
|
|
14
|
+
* header that lies about it. None of them is a refusal on command.
|
|
15
|
+
*
|
|
16
|
+
* This module signs and encodes; the shipped code only verifies and decodes. It lives under `fixtures/` for
|
|
17
|
+
* that reason, next to the recorded notification payloads.
|
|
18
|
+
*/
|
|
19
|
+
/** A minted signing key: the JWK a verifier is given, and the private half a test signs with. */
|
|
20
|
+
export interface MintedOidcKey {
|
|
21
|
+
/** The key id, matched against a token header's `kid`. */
|
|
22
|
+
kid: string;
|
|
23
|
+
/** The public key as a JWK, in the shape Google's own key endpoint publishes. */
|
|
24
|
+
jwk: GoogleJwk;
|
|
25
|
+
/** The private half. What signs a token. */
|
|
26
|
+
privateKey: CryptoKey;
|
|
27
|
+
}
|
|
28
|
+
/** Mint one RSA key pair and publish its public half as a JWK. */
|
|
29
|
+
export declare function mintOidcKey(kid?: string): Promise<MintedOidcKey>;
|
|
30
|
+
/** A minted service-account key: the PEM a credential bundle carries, and the public half to check it with. */
|
|
31
|
+
export interface MintedServiceAccountKey {
|
|
32
|
+
/** The PKCS#8 PEM, exactly as the `private_key` field of a downloaded Google key file holds it. */
|
|
33
|
+
pem: string;
|
|
34
|
+
/** The public half, so a test can verify the assertion the shipped code signed rather than trusting it. */
|
|
35
|
+
publicKey: CryptoKey;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Mint an RSA key pair and armour the private half as the PKCS#8 PEM a Google service-account key file carries.
|
|
39
|
+
*
|
|
40
|
+
* The public half comes back so a suite can **verify** the assertion the shipped signer produced. That is the
|
|
41
|
+
* difference between asserting we posted something to the token endpoint and asserting we posted a signature
|
|
42
|
+
* Google would accept.
|
|
43
|
+
*/
|
|
44
|
+
export declare function mintServiceAccountKey(): Promise<MintedServiceAccountKey>;
|
|
45
|
+
/**
|
|
46
|
+
* Sign a compact JWT the way Google signs a push token: an `RS256` header naming the key, the claims, and an
|
|
47
|
+
* RSASSA-PKCS1-v1_5 signature over `header.payload`.
|
|
48
|
+
*
|
|
49
|
+
* `header` overrides let a test present a header Google never would — `alg: "none"`, `alg: "HS256"`, a `kid`
|
|
50
|
+
* nobody published — which is how algorithm confusion is proved rejected rather than assumed impossible.
|
|
51
|
+
*/
|
|
52
|
+
export declare function signOidcToken(claims: unknown, key: MintedOidcKey, header?: Record<string, unknown>): Promise<string>;
|
|
53
|
+
/** A compact JWT with its claims swapped for others, keeping the original signature. The tamper case. */
|
|
54
|
+
export declare function tamperClaims(token: string, claims: unknown): string;
|
|
55
|
+
/** What a test varies about the envelope around a notification. */
|
|
56
|
+
export interface PushEnvelopeOptions {
|
|
57
|
+
/** Pub/Sub's own message id — the dedupe key, stable across redeliveries of one message. */
|
|
58
|
+
messageId?: string;
|
|
59
|
+
/** When Pub/Sub published it, RFC 3339. */
|
|
60
|
+
publishTime?: string;
|
|
61
|
+
/** The push subscription's resource name. Informational; nothing is decided from it. */
|
|
62
|
+
subscription?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Wrap a decoded Developer Notification in the Pub/Sub push envelope Google POSTs.
|
|
66
|
+
*
|
|
67
|
+
* `data` is **standard** base64 with padding, which is what Pub/Sub emits — deliberately not base64url, so the
|
|
68
|
+
* decoder under test is exercised against the alphabet it will really receive.
|
|
69
|
+
*/
|
|
70
|
+
export declare function pushBody(notification: unknown, options?: PushEnvelopeOptions): string;
|
|
71
|
+
//# sourceMappingURL=push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../../../src/rails/google/fixtures/push.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;;;;;;;;;;GAgBG;AAEH,iGAAiG;AACjG,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,iFAAiF;IACjF,GAAG,EAAE,SAAS,CAAC;IACf,4CAA4C;IAC5C,UAAU,EAAE,SAAS,CAAC;CACvB;AAKD,kEAAkE;AAClE,wBAAsB,WAAW,CAAC,GAAG,SAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,CAoB9E;AAED,+GAA+G;AAC/G,MAAM,WAAW,uBAAuB;IACtC,mGAAmG;IACnG,GAAG,EAAE,MAAM,CAAC;IACZ,2GAA2G;IAC3G,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAc9E;AASD;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,aAAa,EAClB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAGnE;AAED,mEAAmE;AACnE,MAAM,WAAW,mBAAmB;IAClC,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wFAAwF;IACxF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAWzF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//#region src/rails/google/fixtures/push.ts
|
|
2
|
+
/** RS256, which is the only algorithm Google signs a Pub/Sub push token with. */
|
|
3
|
+
const RS256 = {
|
|
4
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
5
|
+
hash: "SHA-256"
|
|
6
|
+
};
|
|
7
|
+
/** Mint one RSA key pair and publish its public half as a JWK. */
|
|
8
|
+
async function mintOidcKey(kid = "pithy-test-1") {
|
|
9
|
+
const pair = await crypto.subtle.generateKey({
|
|
10
|
+
...RS256,
|
|
11
|
+
modulusLength: 2048,
|
|
12
|
+
publicExponent: new Uint8Array([
|
|
13
|
+
1,
|
|
14
|
+
0,
|
|
15
|
+
1
|
|
16
|
+
])
|
|
17
|
+
}, true, ["sign", "verify"]);
|
|
18
|
+
const exported = await crypto.subtle.exportKey("jwk", pair.publicKey);
|
|
19
|
+
if (exported.kty === void 0 || exported.n === void 0 || exported.e === void 0) throw new Error("WebCrypto exported an RSA public key with no kty, n, or e.");
|
|
20
|
+
return {
|
|
21
|
+
kid,
|
|
22
|
+
jwk: {
|
|
23
|
+
...exported,
|
|
24
|
+
kty: exported.kty,
|
|
25
|
+
n: exported.n,
|
|
26
|
+
e: exported.e,
|
|
27
|
+
kid,
|
|
28
|
+
alg: "RS256",
|
|
29
|
+
use: "sig"
|
|
30
|
+
},
|
|
31
|
+
privateKey: pair.privateKey
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Mint an RSA key pair and armour the private half as the PKCS#8 PEM a Google service-account key file carries.
|
|
36
|
+
*
|
|
37
|
+
* The public half comes back so a suite can **verify** the assertion the shipped signer produced. That is the
|
|
38
|
+
* difference between asserting we posted something to the token endpoint and asserting we posted a signature
|
|
39
|
+
* Google would accept.
|
|
40
|
+
*/
|
|
41
|
+
async function mintServiceAccountKey() {
|
|
42
|
+
const pair = await crypto.subtle.generateKey({
|
|
43
|
+
...RS256,
|
|
44
|
+
modulusLength: 2048,
|
|
45
|
+
publicExponent: new Uint8Array([
|
|
46
|
+
1,
|
|
47
|
+
0,
|
|
48
|
+
1
|
|
49
|
+
])
|
|
50
|
+
}, true, ["sign", "verify"]);
|
|
51
|
+
const pkcs8 = new Uint8Array(await crypto.subtle.exportKey("pkcs8", pair.privateKey));
|
|
52
|
+
let binary = "";
|
|
53
|
+
for (const byte of pkcs8) binary += String.fromCharCode(byte);
|
|
54
|
+
return {
|
|
55
|
+
pem: `-----BEGIN PRIVATE KEY-----\n${(btoa(binary).match(/.{1,64}/g) ?? []).join("\n")}\n-----END PRIVATE KEY-----\n`,
|
|
56
|
+
publicKey: pair.publicKey
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** base64url without padding — how every segment of a JWS is encoded. */
|
|
60
|
+
function base64Url(bytes) {
|
|
61
|
+
let binary = "";
|
|
62
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
63
|
+
return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sign a compact JWT the way Google signs a push token: an `RS256` header naming the key, the claims, and an
|
|
67
|
+
* RSASSA-PKCS1-v1_5 signature over `header.payload`.
|
|
68
|
+
*
|
|
69
|
+
* `header` overrides let a test present a header Google never would — `alg: "none"`, `alg: "HS256"`, a `kid`
|
|
70
|
+
* nobody published — which is how algorithm confusion is proved rejected rather than assumed impossible.
|
|
71
|
+
*/
|
|
72
|
+
async function signOidcToken(claims, key, header = {}) {
|
|
73
|
+
const encoder = new TextEncoder();
|
|
74
|
+
const head = base64Url(encoder.encode(JSON.stringify({
|
|
75
|
+
alg: "RS256",
|
|
76
|
+
typ: "JWT",
|
|
77
|
+
kid: key.kid,
|
|
78
|
+
...header
|
|
79
|
+
})));
|
|
80
|
+
const body = base64Url(encoder.encode(JSON.stringify(claims)));
|
|
81
|
+
return `${head}.${body}.${base64Url(new Uint8Array(await crypto.subtle.sign(RS256.name, key.privateKey, encoder.encode(`${head}.${body}`))))}`;
|
|
82
|
+
}
|
|
83
|
+
/** A compact JWT with its claims swapped for others, keeping the original signature. The tamper case. */
|
|
84
|
+
function tamperClaims(token, claims) {
|
|
85
|
+
const [head, , signature] = token.split(".");
|
|
86
|
+
return `${head}.${base64Url(new TextEncoder().encode(JSON.stringify(claims)))}.${signature}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Wrap a decoded Developer Notification in the Pub/Sub push envelope Google POSTs.
|
|
90
|
+
*
|
|
91
|
+
* `data` is **standard** base64 with padding, which is what Pub/Sub emits — deliberately not base64url, so the
|
|
92
|
+
* decoder under test is exercised against the alphabet it will really receive.
|
|
93
|
+
*/
|
|
94
|
+
function pushBody(notification, options = {}) {
|
|
95
|
+
let binary = "";
|
|
96
|
+
for (const byte of new TextEncoder().encode(JSON.stringify(notification))) binary += String.fromCharCode(byte);
|
|
97
|
+
return JSON.stringify({
|
|
98
|
+
message: {
|
|
99
|
+
data: btoa(binary),
|
|
100
|
+
messageId: options.messageId ?? "6714080000000001",
|
|
101
|
+
publishTime: options.publishTime ?? "2026-01-15T00:00:00.000Z"
|
|
102
|
+
},
|
|
103
|
+
subscription: options.subscription ?? "projects/acme-42/subscriptions/pithy-payments-rtdn"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { mintOidcKey, mintServiceAccountKey, pushBody, signOidcToken, tamperClaims };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one door out to Google, and the mapping from how it answered to what that means.
|
|
3
|
+
*
|
|
4
|
+
* **Why the Google rail reaches the network at all.** Apple hands us a signed transaction that verifies
|
|
5
|
+
* offline; Play hands us a purchase token, which is a pointer and nothing more. So Google's rail has two
|
|
6
|
+
* unavoidable round-trips — the JWKS that verifies a push token, and the Play Developer API that turns a
|
|
7
|
+
* pointer into a state — and every failure mode of those round-trips has to land somewhere deliberate.
|
|
8
|
+
*
|
|
9
|
+
* **Every failure but one is `payments/provider_unavailable` (503).** A timeout, a 5xx, a rate limit, a
|
|
10
|
+
* revoked service-account grant, an HTML error page from a proxy: from payments' side these are one
|
|
11
|
+
* statement — *we could not learn the state* — and the correct response to not knowing is to say so and let
|
|
12
|
+
* the caller retry. A silent skip would be the alternative, and a silent skip on a renewal notification
|
|
13
|
+
* revokes a paying subscriber. The webhook route rethrows a 503 so Pub/Sub redelivers, and the
|
|
14
|
+
* reconciliation Workflow repairs whatever redelivery never fixes.
|
|
15
|
+
*
|
|
16
|
+
* **The exception is a 404 the caller asked for.** Play has no "what kind of purchase is this token" call, so
|
|
17
|
+
* a 404 from the subscription endpoint is how a one-time purchase identifies itself. That is a fact about the
|
|
18
|
+
* purchase rather than a failure to reach the store, and only a caller that knows it is probing may treat it
|
|
19
|
+
* as one — hence `absentOn404` rather than a blanket rule.
|
|
20
|
+
*
|
|
21
|
+
* **No refusal carries the URL or the response body.** A Play request URL ends in the purchase token, and
|
|
22
|
+
* Google's error bodies quote the request. `detail` reaches an operator's logs, and a purchase token is a
|
|
23
|
+
* bearer artifact — the same rule as a receipt.
|
|
24
|
+
*/
|
|
25
|
+
/** One outbound request, narrowed to what Google's two endpoints need. */
|
|
26
|
+
export interface GoogleHttpRequest {
|
|
27
|
+
/** The HTTP method. Defaults to GET. */
|
|
28
|
+
method?: string;
|
|
29
|
+
/** Request headers — the bearer token, or the token endpoint's form content type. */
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
/** The request body, already encoded. */
|
|
32
|
+
body?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The response shape this module reads. Structural, so a test's transport need not be a whole `Response`. */
|
|
35
|
+
export interface GoogleHttpResponse {
|
|
36
|
+
/** Whether the status is 2xx. */
|
|
37
|
+
ok: boolean;
|
|
38
|
+
/** The status code, which is what decides the mapping. */
|
|
39
|
+
status: number;
|
|
40
|
+
/** The body as text. Read as text rather than JSON so a non-JSON answer is a diagnosis, not a throw. */
|
|
41
|
+
text(): Promise<string>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The HTTP seam for Google's endpoints.
|
|
45
|
+
*
|
|
46
|
+
* Injectable for exactly one reason: **no test may reach a live store**, and a rail whose network call could
|
|
47
|
+
* not be substituted would have to be tested through a stub of itself, which proves nothing. One explicit
|
|
48
|
+
* parameter is better than reassigning a global — a global stub leaks between suites and hides which module
|
|
49
|
+
* was actually exercised.
|
|
50
|
+
*/
|
|
51
|
+
export type GoogleHttpFetch = (url: string, init?: GoogleHttpRequest) => Promise<GoogleHttpResponse>;
|
|
52
|
+
/** The default transport: the runtime's own `fetch`. */
|
|
53
|
+
export declare const googleHttpFetch: GoogleHttpFetch;
|
|
54
|
+
/** What one request is for, and how its answers should be read. */
|
|
55
|
+
export interface GoogleJsonOptions {
|
|
56
|
+
/** What is being fetched, in a `detail` line: "the subscription", "an access token". Never the URL. */
|
|
57
|
+
what: string;
|
|
58
|
+
/** The HTTP method. Defaults to GET. */
|
|
59
|
+
method?: string;
|
|
60
|
+
/** Request headers. */
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
/** The request body, already encoded. */
|
|
63
|
+
body?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Whether a 404 means "no such purchase" rather than a failure. Set only by a caller that is deliberately
|
|
66
|
+
* probing — Play's subscription endpoint answering 404 is how a one-time purchase is recognized.
|
|
67
|
+
*/
|
|
68
|
+
absentOn404?: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* One request to Google, and its parsed JSON body — or `undefined` when a 404 was a legitimate answer.
|
|
72
|
+
*
|
|
73
|
+
* The body comes back as `unknown`. Reaching an endpoint proves who answered, never what they said, so every
|
|
74
|
+
* caller Zod-parses its own shape.
|
|
75
|
+
*/
|
|
76
|
+
export declare function googleJson(transport: GoogleHttpFetch, url: string, options: GoogleJsonOptions): Promise<unknown | undefined>;
|
|
77
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/rails/google/http.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,8GAA8G;AAC9G,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,EAAE,EAAE,OAAO,CAAC;IACZ,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,wGAAwG;IACxG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAErG,wDAAwD;AACxD,eAAO,MAAM,eAAe,EAAE,eAC8B,CAAC;AAE7D,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,uGAAuG;IACvG,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,eAAe,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CA2B9B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PaymentsProviderUnavailableError } from "../../error/errors.js";
|
|
2
|
+
//#region src/rails/google/http.ts
|
|
3
|
+
/** The default transport: the runtime's own `fetch`. */
|
|
4
|
+
const googleHttpFetch = (url, init) => fetch(url, init);
|
|
5
|
+
/**
|
|
6
|
+
* One request to Google, and its parsed JSON body — or `undefined` when a 404 was a legitimate answer.
|
|
7
|
+
*
|
|
8
|
+
* The body comes back as `unknown`. Reaching an endpoint proves who answered, never what they said, so every
|
|
9
|
+
* caller Zod-parses its own shape.
|
|
10
|
+
*/
|
|
11
|
+
async function googleJson(transport, url, options) {
|
|
12
|
+
let response;
|
|
13
|
+
try {
|
|
14
|
+
response = await transport(url, {
|
|
15
|
+
method: options.method,
|
|
16
|
+
headers: options.headers,
|
|
17
|
+
body: options.body
|
|
18
|
+
});
|
|
19
|
+
} catch (cause) {
|
|
20
|
+
throw unavailable(`Google did not answer when asked for ${options.what}.`, cause);
|
|
21
|
+
}
|
|
22
|
+
if (response.status === 404 && options.absentOn404) return void 0;
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
const hint = response.status === 401 || response.status === 403 ? " Check that the service account is linked in the Play Console under Users and permissions with financial-data access, and that the Google Play Android Developer API is enabled for its project." : "";
|
|
25
|
+
throw unavailable(`Google answered ${response.status} when asked for ${options.what}.${hint}`);
|
|
26
|
+
}
|
|
27
|
+
const text = await response.text();
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(text);
|
|
30
|
+
} catch (cause) {
|
|
31
|
+
throw unavailable(`Google answered with a non-JSON body when asked for ${options.what}.`, cause);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** The 503, with the operator's context in `detail` and nothing about the request in either field. */
|
|
35
|
+
function unavailable(detail, cause) {
|
|
36
|
+
return new PaymentsProviderUnavailableError({ detail }, cause === void 0 ? void 0 : { cause });
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { googleHttpFetch, googleJson };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JWT primitives Google's two token jobs share.
|
|
3
|
+
*
|
|
4
|
+
* Google's rail is the only one that both **verifies** a JWT and **signs** one. It verifies the OIDC token a
|
|
5
|
+
* Pub/Sub push carries, which is what proves a notification came from Google; it signs a service-account
|
|
6
|
+
* assertion, which is what buys the access token the Play Developer API demands. Both are compact JWS, so
|
|
7
|
+
* both need base64url in both directions — and the shipped Apple modules need it in one direction only,
|
|
8
|
+
* because Apple hands us signed data and never asks us to sign any.
|
|
9
|
+
*
|
|
10
|
+
* That is why these live here rather than being taken from `rails/apple/der.ts`: that module is an ASN.1
|
|
11
|
+
* reader whose refusals carry DER offsets, it has no encoder, and a Google module reaching into an Apple one
|
|
12
|
+
* would make the rails depend on each other rather than on the shared contract. Small, local, and named for
|
|
13
|
+
* the rail that uses it.
|
|
14
|
+
*
|
|
15
|
+
* **Every input here is hostile.** A push token arrives in an unauthenticated request — verifying it is the
|
|
16
|
+
* whole point — so a malformed segment is refused rather than coerced, and no refusal echoes the bytes it
|
|
17
|
+
* refused. A token is a bearer artifact and `detail` reaches logs.
|
|
18
|
+
*/
|
|
19
|
+
/** Bytes from one base64url segment. `label` names the segment, so a refusal says which one failed. */
|
|
20
|
+
export declare function base64UrlDecode(value: string, label: string): Uint8Array;
|
|
21
|
+
/** One base64url segment from bytes — the unpadded URL alphabet a JWS is assembled from. */
|
|
22
|
+
export declare function base64UrlEncode(bytes: Uint8Array): string;
|
|
23
|
+
/** The three segments of a compact JWT, as received. Kept as strings: a signature covers the exact bytes. */
|
|
24
|
+
export interface JwtSegments {
|
|
25
|
+
/** The base64url header, still encoded. */
|
|
26
|
+
head: string;
|
|
27
|
+
/** The base64url claim set, still encoded. */
|
|
28
|
+
body: string;
|
|
29
|
+
/** The base64url signature, still encoded. */
|
|
30
|
+
mac: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Split a compact JWT, refusing anything that is not three non-empty segments.
|
|
34
|
+
*
|
|
35
|
+
* The empty-segment check is the structural half of the algorithm pin: `alg: none` produces a header, a
|
|
36
|
+
* payload, and nothing after the final dot, so it is refused here before any header is even decoded.
|
|
37
|
+
*/
|
|
38
|
+
export declare function splitJwt(token: string): JwtSegments;
|
|
39
|
+
/** One base64url JSON segment. `unknown` out — decoded bytes are not yet a known shape. */
|
|
40
|
+
export declare function decodeJwtJson(segment: string, label: string): unknown;
|
|
41
|
+
/**
|
|
42
|
+
* PKCS#8 DER from the PEM a Google service-account key file carries.
|
|
43
|
+
*
|
|
44
|
+
* Two accommodations, both earned. Escaped `\n` sequences are honored because the key lives inside the
|
|
45
|
+
* downloaded JSON as a single line and arrives that way whenever a credential is moved by hand — refusing it
|
|
46
|
+
* would read as a bug in us. And a PKCS#1 body (`BEGIN RSA PRIVATE KEY`) is named rather than passed on,
|
|
47
|
+
* because WebCrypto's answer to one is an opaque `DataError` with nothing an operator can act on.
|
|
48
|
+
*
|
|
49
|
+
* A bad key is `payments/rail_not_configured`: from a caller's side the rail genuinely is not available, and
|
|
50
|
+
* a credential that cannot be read is a provisioning failure rather than a store outage.
|
|
51
|
+
*/
|
|
52
|
+
export declare function pemPrivateKey(pem: string): Uint8Array;
|
|
53
|
+
//# sourceMappingURL=jwt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../src/rails/google/jwt.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;GAiBG;AAEH,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAaxE;AAED,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIzD;AAED,6GAA6G;AAC7G,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAQnD;AAED,2FAA2F;AAC3F,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQrE;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAuBrD"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { PaymentsInvalidReceiptError, PaymentsRailNotConfiguredError } from "../../error/errors.js";
|
|
2
|
+
//#region src/rails/google/jwt.ts
|
|
3
|
+
/**
|
|
4
|
+
* The JWT primitives Google's two token jobs share.
|
|
5
|
+
*
|
|
6
|
+
* Google's rail is the only one that both **verifies** a JWT and **signs** one. It verifies the OIDC token a
|
|
7
|
+
* Pub/Sub push carries, which is what proves a notification came from Google; it signs a service-account
|
|
8
|
+
* assertion, which is what buys the access token the Play Developer API demands. Both are compact JWS, so
|
|
9
|
+
* both need base64url in both directions — and the shipped Apple modules need it in one direction only,
|
|
10
|
+
* because Apple hands us signed data and never asks us to sign any.
|
|
11
|
+
*
|
|
12
|
+
* That is why these live here rather than being taken from `rails/apple/der.ts`: that module is an ASN.1
|
|
13
|
+
* reader whose refusals carry DER offsets, it has no encoder, and a Google module reaching into an Apple one
|
|
14
|
+
* would make the rails depend on each other rather than on the shared contract. Small, local, and named for
|
|
15
|
+
* the rail that uses it.
|
|
16
|
+
*
|
|
17
|
+
* **Every input here is hostile.** A push token arrives in an unauthenticated request — verifying it is the
|
|
18
|
+
* whole point — so a malformed segment is refused rather than coerced, and no refusal echoes the bytes it
|
|
19
|
+
* refused. A token is a bearer artifact and `detail` reaches logs.
|
|
20
|
+
*/
|
|
21
|
+
/** Bytes from one base64url segment. `label` names the segment, so a refusal says which one failed. */
|
|
22
|
+
function base64UrlDecode(value, label) {
|
|
23
|
+
if (value.length === 0) throw malformed(`${label} is empty; an unsigned token is not accepted.`);
|
|
24
|
+
const standard = value.replaceAll("-", "+").replaceAll("_", "/");
|
|
25
|
+
const padded = standard.padEnd(standard.length + (4 - standard.length % 4) % 4, "=");
|
|
26
|
+
let binary;
|
|
27
|
+
try {
|
|
28
|
+
binary = atob(padded);
|
|
29
|
+
} catch (cause) {
|
|
30
|
+
throw malformed(`${label} is not valid base64url.`, cause);
|
|
31
|
+
}
|
|
32
|
+
return Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
33
|
+
}
|
|
34
|
+
/** One base64url segment from bytes — the unpadded URL alphabet a JWS is assembled from. */
|
|
35
|
+
function base64UrlEncode(bytes) {
|
|
36
|
+
let binary = "";
|
|
37
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
38
|
+
return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Split a compact JWT, refusing anything that is not three non-empty segments.
|
|
42
|
+
*
|
|
43
|
+
* The empty-segment check is the structural half of the algorithm pin: `alg: none` produces a header, a
|
|
44
|
+
* payload, and nothing after the final dot, so it is refused here before any header is even decoded.
|
|
45
|
+
*/
|
|
46
|
+
function splitJwt(token) {
|
|
47
|
+
const segments = token.split(".");
|
|
48
|
+
if (segments.length !== 3) throw malformed(`the token has ${segments.length} segments, expected 3.`);
|
|
49
|
+
const [head, body, mac] = segments;
|
|
50
|
+
if (head.length === 0 || body.length === 0 || mac.length === 0) throw malformed("a token segment is empty; an unsigned token is not accepted.");
|
|
51
|
+
return {
|
|
52
|
+
head,
|
|
53
|
+
body,
|
|
54
|
+
mac
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** One base64url JSON segment. `unknown` out — decoded bytes are not yet a known shape. */
|
|
58
|
+
function decodeJwtJson(segment, label) {
|
|
59
|
+
const text = new TextDecoder().decode(base64UrlDecode(segment, label));
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(text);
|
|
62
|
+
} catch (cause) {
|
|
63
|
+
throw malformed(`${label} is not JSON.`, cause);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The PEM armour of a PKCS#8 private key — the only form `crypto.subtle.importKey("pkcs8", …)` reads. */
|
|
67
|
+
const PKCS8_HEADER = "-----BEGIN PRIVATE KEY-----";
|
|
68
|
+
/**
|
|
69
|
+
* PKCS#8 DER from the PEM a Google service-account key file carries.
|
|
70
|
+
*
|
|
71
|
+
* Two accommodations, both earned. Escaped `\n` sequences are honored because the key lives inside the
|
|
72
|
+
* downloaded JSON as a single line and arrives that way whenever a credential is moved by hand — refusing it
|
|
73
|
+
* would read as a bug in us. And a PKCS#1 body (`BEGIN RSA PRIVATE KEY`) is named rather than passed on,
|
|
74
|
+
* because WebCrypto's answer to one is an opaque `DataError` with nothing an operator can act on.
|
|
75
|
+
*
|
|
76
|
+
* A bad key is `payments/rail_not_configured`: from a caller's side the rail genuinely is not available, and
|
|
77
|
+
* a credential that cannot be read is a provisioning failure rather than a store outage.
|
|
78
|
+
*/
|
|
79
|
+
function pemPrivateKey(pem) {
|
|
80
|
+
const text = pem.replaceAll("\\n", "\n");
|
|
81
|
+
if (!text.includes(PKCS8_HEADER)) throw new PaymentsRailNotConfiguredError({ detail: text.includes("PRIVATE KEY") ? "Google: the service-account private key is not PKCS#8. Use the `private_key` field of the downloaded JSON key file, which begins `-----BEGIN PRIVATE KEY-----`." : "Google: the service-account private key carries no PEM armour. Store the `private_key` field of the downloaded JSON key file verbatim." });
|
|
82
|
+
const body = text.slice(text.indexOf(PKCS8_HEADER) + 27).replace(/-----END PRIVATE KEY-----[\s\S]*$/, "").replaceAll(/\s+/g, "");
|
|
83
|
+
try {
|
|
84
|
+
return base64UrlDecode(body, "the service-account private key");
|
|
85
|
+
} catch (cause) {
|
|
86
|
+
throw new PaymentsRailNotConfiguredError({ detail: "Google: the service-account private key's PEM body is not valid base64." }, { cause });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** A structural refusal. `Google:` prefixed so a log line says which rail failed to read something. */
|
|
90
|
+
function malformed(detail, cause) {
|
|
91
|
+
return new PaymentsInvalidReceiptError({ detail: `Google: ${detail}` }, cause === void 0 ? void 0 : { cause });
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { base64UrlDecode, base64UrlEncode, decodeJwtJson, pemPrivateKey, splitJwt };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type GoogleHttpFetch } from "./http";
|
|
3
|
+
/**
|
|
4
|
+
* The authenticity boundary on Google's webhook: the OIDC token a Pub/Sub push carries.
|
|
5
|
+
*
|
|
6
|
+
* Play's Real-time Developer Notifications do not arrive from Google Play. They arrive from **Pub/Sub**, which
|
|
7
|
+
* POSTs to a URL an operator configured, carrying a Google-signed OIDC token in the `Authorization` header.
|
|
8
|
+
* So there is no signature over the body the way Apple signs a notification — the token is the proof, and what
|
|
9
|
+
* it proves is narrow.
|
|
10
|
+
*
|
|
11
|
+
* **The audience check is the actual boundary.** Google signs these tokens with the same handful of keys for
|
|
12
|
+
* every push subscription on the planet. A valid signature therefore says only *Google minted this*, which
|
|
13
|
+
* anyone can arrange for themselves in thirty seconds. What makes a token ours is the `aud` claim: Pub/Sub sets
|
|
14
|
+
* it to the audience configured on the push subscription, and that value is the endpoint the token was minted
|
|
15
|
+
* for. Verify the signature and skip the audience and you have built an endpoint that accepts notifications
|
|
16
|
+
* from any Google customer who points a subscription at it.
|
|
17
|
+
*
|
|
18
|
+
* Four checks, in this order, and the order is deliberate:
|
|
19
|
+
*
|
|
20
|
+
* 1. **Pin the algorithm before touching a key.** `alg` arrives in a header nobody has verified, so it is
|
|
21
|
+
* parsed against a literal `RS256` rather than looked up. That is what makes the two published confusions
|
|
22
|
+
* unreachable — `none`, which asks for the signature to be skipped, and `HS256`, which asks the verifier to
|
|
23
|
+
* HMAC with the public key as if it were a shared secret. Neither survives a literal.
|
|
24
|
+
* 2. **Resolve the key by `kid` from Google's published set.** Never from the token, which is why there is no
|
|
25
|
+
* `jwk`/`x5u` handling here: a token that carries its own key is a token that verifies itself.
|
|
26
|
+
* 3. **Verify the signature over the exact received segments** — `header.claims` as encoded.
|
|
27
|
+
* 4. **Then read the claims,** and only then, because a claim from an unverified token means nothing.
|
|
28
|
+
*
|
|
29
|
+
* A failure to *read* the token is `payments/invalid_receipt`; a token that is well-formed and does not check
|
|
30
|
+
* out is `payments/verification_failed`. On the webhook path the guard maps either to
|
|
31
|
+
* `payments/webhook_unverified` (401), so the distinction serves the operator reading `detail` rather than the
|
|
32
|
+
* caller — and a forger is told nothing about how close it got.
|
|
33
|
+
*/
|
|
34
|
+
/** Where Google publishes the keys that sign an OIDC token. Public, so it is pinned here rather than stored. */
|
|
35
|
+
export declare const GOOGLE_JWKS_URL = "https://www.googleapis.com/oauth2/v3/certs";
|
|
36
|
+
/**
|
|
37
|
+
* The two spellings Google issues an OIDC token under. Both are current, and which one arrives is not ours to
|
|
38
|
+
* decide, so both are accepted and nothing else is.
|
|
39
|
+
*/
|
|
40
|
+
export declare const GOOGLE_OIDC_ISSUERS: readonly string[];
|
|
41
|
+
/**
|
|
42
|
+
* One published RSA verification key, in the shape Google's key endpoint returns. `.loose()` because Google
|
|
43
|
+
* adds fields and a key set must not be rejected for carrying something new.
|
|
44
|
+
*/
|
|
45
|
+
export declare const GoogleJwk: z.ZodObject<{
|
|
46
|
+
kid: z.ZodString;
|
|
47
|
+
kty: z.ZodString;
|
|
48
|
+
n: z.ZodString;
|
|
49
|
+
e: z.ZodString;
|
|
50
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
51
|
+
use: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, z.core.$loose>;
|
|
53
|
+
export type GoogleJwk = z.infer<typeof GoogleJwk>;
|
|
54
|
+
/** Google's published key set. At least one key: an empty set is an endpoint that is not answering properly. */
|
|
55
|
+
export declare const GoogleJwks: z.ZodObject<{
|
|
56
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
57
|
+
kid: z.ZodString;
|
|
58
|
+
kty: z.ZodString;
|
|
59
|
+
n: z.ZodString;
|
|
60
|
+
e: z.ZodString;
|
|
61
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
62
|
+
use: z.ZodOptional<z.ZodString>;
|
|
63
|
+
}, z.core.$loose>>;
|
|
64
|
+
}, z.core.$loose>;
|
|
65
|
+
export type GoogleJwks = z.infer<typeof GoogleJwks>;
|
|
66
|
+
/**
|
|
67
|
+
* The claims a Pub/Sub push token carries, narrowed to the ones that decide anything. `.loose()` keeps the
|
|
68
|
+
* rest — the whole token is never stored, but a claim set must not be refused for being richer than expected.
|
|
69
|
+
*/
|
|
70
|
+
export declare const GoogleOidcClaims: z.ZodObject<{
|
|
71
|
+
iss: z.ZodString;
|
|
72
|
+
aud: z.ZodString;
|
|
73
|
+
exp: z.ZodNumber;
|
|
74
|
+
iat: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
email: z.ZodOptional<z.ZodString>;
|
|
76
|
+
email_verified: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
sub: z.ZodOptional<z.ZodString>;
|
|
78
|
+
}, z.core.$loose>;
|
|
79
|
+
export type GoogleOidcClaims = z.infer<typeof GoogleOidcClaims>;
|
|
80
|
+
/** What verifying a push token needs. Everything is explicit, so verification is deterministic in a test. */
|
|
81
|
+
export interface VerifyGoogleOidcOptions {
|
|
82
|
+
/** The audience the token must claim — the push subscription's configured audience. The real boundary. */
|
|
83
|
+
audience: string;
|
|
84
|
+
/** The service account the token must have been minted by. Google's own recommended second check. */
|
|
85
|
+
serviceAccountEmail: string;
|
|
86
|
+
/** The clock. Injected so an expiry refusal is deterministic. */
|
|
87
|
+
now: Date;
|
|
88
|
+
/** The HTTP seam Google's key endpoint is reached through. Defaults to the runtime's `fetch`. */
|
|
89
|
+
transport?: GoogleHttpFetch;
|
|
90
|
+
/**
|
|
91
|
+
* Keys accepted **in addition to** Google's published set, matched by `kid`.
|
|
92
|
+
*
|
|
93
|
+
* Additive, so nothing can narrow production's trust: a token whose `kid` these do not cover still resolves
|
|
94
|
+
* against Google. Two callers have a real reason — the tests, which mint their own key so the signature check
|
|
95
|
+
* is exercised for real, and a local Pub/Sub emulator, whose tokens are signed by a key Google never saw.
|
|
96
|
+
*/
|
|
97
|
+
trustedKeys?: readonly GoogleJwk[];
|
|
98
|
+
/** Tolerance on `exp` and `iat`, in seconds. Defaults to a minute. */
|
|
99
|
+
clockSkewSeconds?: number;
|
|
100
|
+
}
|
|
101
|
+
/** Drop the cached key set. For tests, which must not inherit another suite's keys. */
|
|
102
|
+
export declare function resetGoogleJwksCache(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Verify one Pub/Sub push OIDC token and return its claims.
|
|
105
|
+
*
|
|
106
|
+
* @throws {@link PaymentsInvalidReceiptError} when the token cannot be read — wrong segment count, a header
|
|
107
|
+
* Google would never send, a non-JSON segment.
|
|
108
|
+
* @throws {@link PaymentsVerificationFailedError} when it is well-formed and does not check out — an unknown
|
|
109
|
+
* key, a bad signature, the wrong audience, the wrong issuer, an expiry, the wrong service account.
|
|
110
|
+
*/
|
|
111
|
+
export declare function verifyGoogleOidcToken(token: string, options: VerifyGoogleOidcOptions): Promise<GoogleOidcClaims>;
|
|
112
|
+
//# sourceMappingURL=oidc.d.ts.map
|