@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,29 @@
|
|
|
1
|
+
import type { WorkflowRetryPolicy } from "@pithy-sh/core/src/workflow/faults";
|
|
2
|
+
/**
|
|
3
|
+
* **What the reconciliation pass retries, and what it refuses to.**
|
|
4
|
+
*
|
|
5
|
+
* The pass already draws this line in prose — `reconcile.ts` §"What a failure means" — and the line was
|
|
6
|
+
* the right one: a store that cannot be *reached* fails the page so the step re-drives it, and every
|
|
7
|
+
* other refusal is about one purchase and is counted rather than thrown. What was missing is that the
|
|
8
|
+
* platform never heard it, so anything that did escape a page was retried on the same terms
|
|
9
|
+
* (pithy-sh/pithy#338). This is that paragraph, in the form the step reads.
|
|
10
|
+
*
|
|
11
|
+
* ## Retryable
|
|
12
|
+
*
|
|
13
|
+
* - **`payments/provider_unavailable`** — Apple, Google, Stripe, Paddle or Lemon Squeezy unreachable, out
|
|
14
|
+
* of time, rate-limiting, or answering 5xx; every rail's HTTP layer folds those into this one code. A
|
|
15
|
+
* page is idempotent — it re-asks and re-projects to the same place — so a re-drive costs a request and
|
|
16
|
+
* fixes an outage that has since ended.
|
|
17
|
+
* - **`core/upstream_failed` / `core/upstream_timeout`** — the same fault, raised by a shared client
|
|
18
|
+
* rather than by a rail.
|
|
19
|
+
* - **A transient D1 fault** — classified in core by `withD1Retry`, never restated here.
|
|
20
|
+
*
|
|
21
|
+
* ## Terminal
|
|
22
|
+
*
|
|
23
|
+
* Everything else, and the list is deliberately not enumerated: an unmapped store state, a SKU no longer
|
|
24
|
+
* in the catalog, a rail switched off since the row was written, a receipt that will not verify, a
|
|
25
|
+
* parameter that will not validate. None of them answer differently to the same question an hour later,
|
|
26
|
+
* and a pass that spends its retry budget on one of them is a pass that does not reach page forty-one.
|
|
27
|
+
*/
|
|
28
|
+
export declare const paymentsWorkflowRetry: WorkflowRetryPolicy;
|
|
29
|
+
//# sourceMappingURL=retryPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryPolicy.d.ts","sourceRoot":"","sources":["../../src/workflows/retryPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,qBAAqB,EAAE,mBAQnC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/workflows/retryPolicy.ts
|
|
2
|
+
/**
|
|
3
|
+
* **What the reconciliation pass retries, and what it refuses to.**
|
|
4
|
+
*
|
|
5
|
+
* The pass already draws this line in prose — `reconcile.ts` §"What a failure means" — and the line was
|
|
6
|
+
* the right one: a store that cannot be *reached* fails the page so the step re-drives it, and every
|
|
7
|
+
* other refusal is about one purchase and is counted rather than thrown. What was missing is that the
|
|
8
|
+
* platform never heard it, so anything that did escape a page was retried on the same terms
|
|
9
|
+
* (pithy-sh/pithy#338). This is that paragraph, in the form the step reads.
|
|
10
|
+
*
|
|
11
|
+
* ## Retryable
|
|
12
|
+
*
|
|
13
|
+
* - **`payments/provider_unavailable`** — Apple, Google, Stripe, Paddle or Lemon Squeezy unreachable, out
|
|
14
|
+
* of time, rate-limiting, or answering 5xx; every rail's HTTP layer folds those into this one code. A
|
|
15
|
+
* page is idempotent — it re-asks and re-projects to the same place — so a re-drive costs a request and
|
|
16
|
+
* fixes an outage that has since ended.
|
|
17
|
+
* - **`core/upstream_failed` / `core/upstream_timeout`** — the same fault, raised by a shared client
|
|
18
|
+
* rather than by a rail.
|
|
19
|
+
* - **A transient D1 fault** — classified in core by `withD1Retry`, never restated here.
|
|
20
|
+
*
|
|
21
|
+
* ## Terminal
|
|
22
|
+
*
|
|
23
|
+
* Everything else, and the list is deliberately not enumerated: an unmapped store state, a SKU no longer
|
|
24
|
+
* in the catalog, a rail switched off since the row was written, a receipt that will not verify, a
|
|
25
|
+
* parameter that will not validate. None of them answer differently to the same question an hour later,
|
|
26
|
+
* and a pass that spends its retry budget on one of them is a pass that does not reach page forty-one.
|
|
27
|
+
*/
|
|
28
|
+
const paymentsWorkflowRetry = {
|
|
29
|
+
capability: "payments",
|
|
30
|
+
retryable: {
|
|
31
|
+
"payments/provider_unavailable": "The store could not be reached. A page is idempotent, so re-asking is free and the outage may be over.",
|
|
32
|
+
"core/upstream_failed": "A dependency this pass does not control was unreachable; the next attempt may reach it.",
|
|
33
|
+
"core/upstream_timeout": "A dependency ran out of time rather than refusing; the same page can be asked again."
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { paymentsWorkflowRetry };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { WorkflowRegistry } from "@pithy-sh/core/src/workflow/spec";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* The one durable job payments owns: the reconciliation pass.
|
|
5
|
+
*
|
|
6
|
+
* Declared once, here. `capability.ts` derives its Workflow binding from this map, `provision/` derives the
|
|
7
|
+
* host worker's `workflows` array and its cron from it, and any caller triggers it by the `payments/reconcile`
|
|
8
|
+
* key. There is no second place where the binding name, the class name, or the schedule is written down, so
|
|
9
|
+
* none of them can drift.
|
|
10
|
+
*
|
|
11
|
+
* `optional: true` because the Workflow lives in the prebuilt reconcile worker, which exists only once
|
|
12
|
+
* `pithy payments provision` has run. Until then an app composing payments must still verify receipts, accept
|
|
13
|
+
* webhooks, and resolve entitlements — every one of which works with no Workflow at all. An absent binding
|
|
14
|
+
* degrades to a logged skip rather than a boot failure.
|
|
15
|
+
*/
|
|
16
|
+
/** The capability name — the first segment of the dispatch key and of every deployed resource name. */
|
|
17
|
+
export declare const PAYMENTS_CAPABILITY = "payments";
|
|
18
|
+
/** How far ahead of expiry a subscription is re-verified, when the caller names no window. Two days. */
|
|
19
|
+
export declare const DEFAULT_EXPIRING_WITHIN_SECONDS = 172800;
|
|
20
|
+
/** How long a subscription may go unverified before a pass looks at it anyway. One week. */
|
|
21
|
+
export declare const DEFAULT_STALE_AFTER_SECONDS = 604800;
|
|
22
|
+
/**
|
|
23
|
+
* The pass's parameters. **Every field is optional, and that is a requirement rather than a convenience:** a
|
|
24
|
+
* cron supplies no input, and `createEntrypoint` dispatches a scheduled job with `{}`. A schema that demanded
|
|
25
|
+
* a field could never run on its own schedule.
|
|
26
|
+
*
|
|
27
|
+
* The two windows are the pass's whole selection policy, and they are parameters rather than config because
|
|
28
|
+
* the reason to change one is always a one-off: reproducing a repair in staging without waiting for a
|
|
29
|
+
* subscription to age, or sweeping wider after an outage that ate a day of deliveries.
|
|
30
|
+
*
|
|
31
|
+
* **A holder narrowing is the pair, both halves or neither** — the rule `data/subject.ts` states, applied to
|
|
32
|
+
* the one field a support pass narrows on. Neither half is the cron. Both is *"reconcile this account"*. One
|
|
33
|
+
* half is refused rather than ignored: `subjectId` alone would scan whichever user *or* organization happens
|
|
34
|
+
* to carry that id, and nothing keeps those two ids apart, so the pass would answer about somebody else and
|
|
35
|
+
* report it as the account that was asked about.
|
|
36
|
+
*/
|
|
37
|
+
export declare const PaymentsReconcileParams: z.ZodObject<{
|
|
38
|
+
subjectType: z.ZodOptional<z.ZodEnum<{
|
|
39
|
+
organization: "organization";
|
|
40
|
+
user: "user";
|
|
41
|
+
}>>;
|
|
42
|
+
subjectId: z.ZodOptional<z.ZodString>;
|
|
43
|
+
rail: z.ZodOptional<z.ZodEnum<{
|
|
44
|
+
apple: "apple";
|
|
45
|
+
google: "google";
|
|
46
|
+
lemonSqueezy: "lemonSqueezy";
|
|
47
|
+
paddle: "paddle";
|
|
48
|
+
stripe: "stripe";
|
|
49
|
+
}>>;
|
|
50
|
+
expiringWithinSeconds: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
staleAfterSeconds: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
maxPages: z.ZodOptional<z.ZodNumber>;
|
|
54
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export type PaymentsReconcileParams = z.infer<typeof PaymentsReconcileParams>;
|
|
57
|
+
/**
|
|
58
|
+
* Payments' durable jobs, keyed by job name.
|
|
59
|
+
*
|
|
60
|
+
* The schedule is daily at 04:00 UTC — offset from storage's 03:00 sweep and the secrets rotation, so three
|
|
61
|
+
* hosts in one account do not contend for the same minute. Daily is the right cadence because subscription
|
|
62
|
+
* expiry windows are hours wide rather than minutes wide, and because the client-submission path already gives
|
|
63
|
+
* a purchaser immediate feedback: reconciliation is the repair path, never the primary one.
|
|
64
|
+
*
|
|
65
|
+
* It is a cron **and** a dispatch target. A pass nobody can run on demand cannot be tested in staging, and it
|
|
66
|
+
* could not be the support tool the issue asks for — "my subscription isn't showing up" is answered by running
|
|
67
|
+
* these exact steps for one user.
|
|
68
|
+
*/
|
|
69
|
+
export declare const paymentsWorkflows: {
|
|
70
|
+
readonly reconcile: {
|
|
71
|
+
readonly binding: "PAYMENTS_RECONCILE";
|
|
72
|
+
readonly className: "PaymentsReconcileWorkflow";
|
|
73
|
+
readonly params: z.ZodObject<{
|
|
74
|
+
subjectType: z.ZodOptional<z.ZodEnum<{
|
|
75
|
+
organization: "organization";
|
|
76
|
+
user: "user";
|
|
77
|
+
}>>;
|
|
78
|
+
subjectId: z.ZodOptional<z.ZodString>;
|
|
79
|
+
rail: z.ZodOptional<z.ZodEnum<{
|
|
80
|
+
apple: "apple";
|
|
81
|
+
google: "google";
|
|
82
|
+
lemonSqueezy: "lemonSqueezy";
|
|
83
|
+
paddle: "paddle";
|
|
84
|
+
stripe: "stripe";
|
|
85
|
+
}>>;
|
|
86
|
+
expiringWithinSeconds: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
staleAfterSeconds: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
89
|
+
maxPages: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
readonly schedule: "0 4 * * *";
|
|
93
|
+
readonly optional: true;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Payments' jobs as a dispatch registry, keyed `payments/<job>`. Built here rather than through
|
|
98
|
+
* `composeWorkflows` because the reconcile worker dispatches its own job before any project-wide registry
|
|
99
|
+
* exists — and the key format comes from core's {@link workflowKey} either way, so the two cannot drift.
|
|
100
|
+
*/
|
|
101
|
+
export declare const paymentsWorkflowRegistry: WorkflowRegistry;
|
|
102
|
+
//# sourceMappingURL=specs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"specs.d.ts","sourceRoot":"","sources":["../../src/workflows/specs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,kCAAkC,CAAC;AAC1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;;;GAYG;AAEH,uGAAuG;AACvG,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAE9C,wGAAwG;AACxG,eAAO,MAAM,+BAA+B,SAAU,CAAC;AAEvD,4FAA4F;AAC5F,eAAO,MAAM,2BAA2B,SAAU,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;iBA4D8E,CAAC;AACnH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE9E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB;;iBAE1B,OAAO,EAAE,oBAAoB;iBAC7B,SAAS,EAAE,2BAA2B;iBACtC,MAAM;;;;;;;;;;;;;;;;;;;iBACN,QAAQ,EAAE,WAAW;iBACrB,QAAQ;;CAEwB,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,gBAKtC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { PaymentsRail } from "../data/rail.js";
|
|
2
|
+
import { PaymentsSubject } from "../data/subject.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { workflowKey } from "@pithy-sh/core/src/workflow/naming";
|
|
5
|
+
//#region src/workflows/specs.ts
|
|
6
|
+
/**
|
|
7
|
+
* The one durable job payments owns: the reconciliation pass.
|
|
8
|
+
*
|
|
9
|
+
* Declared once, here. `capability.ts` derives its Workflow binding from this map, `provision/` derives the
|
|
10
|
+
* host worker's `workflows` array and its cron from it, and any caller triggers it by the `payments/reconcile`
|
|
11
|
+
* key. There is no second place where the binding name, the class name, or the schedule is written down, so
|
|
12
|
+
* none of them can drift.
|
|
13
|
+
*
|
|
14
|
+
* `optional: true` because the Workflow lives in the prebuilt reconcile worker, which exists only once
|
|
15
|
+
* `pithy payments provision` has run. Until then an app composing payments must still verify receipts, accept
|
|
16
|
+
* webhooks, and resolve entitlements — every one of which works with no Workflow at all. An absent binding
|
|
17
|
+
* degrades to a logged skip rather than a boot failure.
|
|
18
|
+
*/
|
|
19
|
+
/** The capability name — the first segment of the dispatch key and of every deployed resource name. */
|
|
20
|
+
const PAYMENTS_CAPABILITY = "payments";
|
|
21
|
+
/** How far ahead of expiry a subscription is re-verified, when the caller names no window. Two days. */
|
|
22
|
+
const DEFAULT_EXPIRING_WITHIN_SECONDS = 172800;
|
|
23
|
+
/** How long a subscription may go unverified before a pass looks at it anyway. One week. */
|
|
24
|
+
const DEFAULT_STALE_AFTER_SECONDS = 604800;
|
|
25
|
+
/**
|
|
26
|
+
* The pass's parameters. **Every field is optional, and that is a requirement rather than a convenience:** a
|
|
27
|
+
* cron supplies no input, and `createEntrypoint` dispatches a scheduled job with `{}`. A schema that demanded
|
|
28
|
+
* a field could never run on its own schedule.
|
|
29
|
+
*
|
|
30
|
+
* The two windows are the pass's whole selection policy, and they are parameters rather than config because
|
|
31
|
+
* the reason to change one is always a one-off: reproducing a repair in staging without waiting for a
|
|
32
|
+
* subscription to age, or sweeping wider after an outage that ate a day of deliveries.
|
|
33
|
+
*
|
|
34
|
+
* **A holder narrowing is the pair, both halves or neither** — the rule `data/subject.ts` states, applied to
|
|
35
|
+
* the one field a support pass narrows on. Neither half is the cron. Both is *"reconcile this account"*. One
|
|
36
|
+
* half is refused rather than ignored: `subjectId` alone would scan whichever user *or* organization happens
|
|
37
|
+
* to carry that id, and nothing keeps those two ids apart, so the pass would answer about somebody else and
|
|
38
|
+
* report it as the account that was asked about.
|
|
39
|
+
*/
|
|
40
|
+
const PaymentsReconcileParams = z.object({
|
|
41
|
+
subjectType: PaymentsSubject.shape.subjectType.optional().describe("Which kind of holder to narrow to. Send it with `subjectId` or send neither — half a subject names nobody."),
|
|
42
|
+
subjectId: PaymentsSubject.shape.subjectId.optional().describe("Reconcile one holder's purchases instead of the whole catalog. This is the support tool for \"my subscription isn't showing up\" — the same steps, narrowed, so the answer comes from the same code path the cron runs. Send it with `subjectType`: an id alone names whichever user or organization happens to carry it."),
|
|
43
|
+
rail: PaymentsRail.optional().describe("Reconcile one rail's purchases only. The pass to run when a single store's webhooks were interrupted, rather than paying for the other two."),
|
|
44
|
+
expiringWithinSeconds: z.number().int().positive().optional().describe("How far ahead of its expiry a subscription is re-verified. Omitted uses two days, so a daily cron looks at every subscription at least twice before the period it paid for ends."),
|
|
45
|
+
staleAfterSeconds: z.number().int().positive().optional().describe("How long a subscription may go unverified before a pass looks at it regardless of its expiry. Omitted uses a week. This is what catches a subscription whose state changed nowhere near a renewal — a refund, a pause, a revocation whose notification never arrived."),
|
|
46
|
+
pageSize: z.number().int().positive().optional().describe("Purchases per durable step. Each page is one journalled step, so this is the unit of work a retry repeats. Omitted uses 100, which keeps a page inside the life of the one access token it mints."),
|
|
47
|
+
maxPages: z.number().int().positive().optional().describe("Cap how many pages one run scans. A bound on the work, so a first pass over a very large catalog finishes rather than running until it is killed. The next run resumes from the beginning and reaches what this one did not, because a reconciled row stops matching the selection."),
|
|
48
|
+
dryRun: z.boolean().optional().describe("Ask every store and write nothing. The safe way to answer 'how much drift is there' before letting a pass repair it, and the way to measure whether the webhook path is working at all.")
|
|
49
|
+
}).refine((params) => params.subjectType === void 0 === (params.subjectId === void 0), { message: "Narrow on `subjectType` and `subjectId` together, or neither. Half a subject names no holder." }).describe("What one reconciliation run should cover. Every field optional, because a cron passes none of them.");
|
|
50
|
+
/**
|
|
51
|
+
* Payments' durable jobs, keyed by job name.
|
|
52
|
+
*
|
|
53
|
+
* The schedule is daily at 04:00 UTC — offset from storage's 03:00 sweep and the secrets rotation, so three
|
|
54
|
+
* hosts in one account do not contend for the same minute. Daily is the right cadence because subscription
|
|
55
|
+
* expiry windows are hours wide rather than minutes wide, and because the client-submission path already gives
|
|
56
|
+
* a purchaser immediate feedback: reconciliation is the repair path, never the primary one.
|
|
57
|
+
*
|
|
58
|
+
* It is a cron **and** a dispatch target. A pass nobody can run on demand cannot be tested in staging, and it
|
|
59
|
+
* could not be the support tool the issue asks for — "my subscription isn't showing up" is answered by running
|
|
60
|
+
* these exact steps for one user.
|
|
61
|
+
*/
|
|
62
|
+
const paymentsWorkflows = { reconcile: {
|
|
63
|
+
binding: "PAYMENTS_RECONCILE",
|
|
64
|
+
className: "PaymentsReconcileWorkflow",
|
|
65
|
+
params: PaymentsReconcileParams,
|
|
66
|
+
schedule: "0 4 * * *",
|
|
67
|
+
optional: true
|
|
68
|
+
} };
|
|
69
|
+
/**
|
|
70
|
+
* Payments' jobs as a dispatch registry, keyed `payments/<job>`. Built here rather than through
|
|
71
|
+
* `composeWorkflows` because the reconcile worker dispatches its own job before any project-wide registry
|
|
72
|
+
* exists — and the key format comes from core's {@link workflowKey} either way, so the two cannot drift.
|
|
73
|
+
*/
|
|
74
|
+
const paymentsWorkflowRegistry = Object.fromEntries(Object.entries(paymentsWorkflows).map(([job, spec]) => {
|
|
75
|
+
const key = workflowKey(PAYMENTS_CAPABILITY, job);
|
|
76
|
+
return [key, {
|
|
77
|
+
key,
|
|
78
|
+
capability: PAYMENTS_CAPABILITY,
|
|
79
|
+
job,
|
|
80
|
+
spec
|
|
81
|
+
}];
|
|
82
|
+
}));
|
|
83
|
+
//#endregion
|
|
84
|
+
export { DEFAULT_EXPIRING_WITHIN_SECONDS, DEFAULT_STALE_AFTER_SECONDS, PAYMENTS_CAPABILITY, PaymentsReconcileParams, paymentsWorkflowRegistry, paymentsWorkflows };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep } from "cloudflare:workers";
|
|
2
|
+
import { type ReconcileReport } from "./reconcile";
|
|
3
|
+
import { PaymentsReconcileParams } from "./specs";
|
|
4
|
+
import { type PaymentsWorkerEnv } from "./workerConfig";
|
|
5
|
+
/**
|
|
6
|
+
* The prebuilt payments reconcile worker. `pithy payments provision` deploys one per environment; the adopter
|
|
7
|
+
* authors none of it. It hosts a single Workflow — the reconciliation pass — and fires it on a daily cron.
|
|
8
|
+
*
|
|
9
|
+
* **Why its own worker rather than the app worker's `scheduled()`.** The pass makes hundreds of authenticated
|
|
10
|
+
* calls to three stores and can rewrite any purchase row. Keeping it out of the request-serving deployment
|
|
11
|
+
* means it cannot compete with a checkout for CPU, and the app worker never needs the App Store Connect key
|
|
12
|
+
* or the Play service account on a path that serves a request. It is a Workflow rather than a plain scheduled
|
|
13
|
+
* pass because a Worker invocation is wall-clock bounded while a Workflow step is not: a catalog of ten
|
|
14
|
+
* thousand subscriptions is a hundred pages against rate-limited third-party APIs, and that is work you want
|
|
15
|
+
* journalled rather than restarted.
|
|
16
|
+
*
|
|
17
|
+
* ## A Workflow here runs with **no subject seam**, and that is structural
|
|
18
|
+
*
|
|
19
|
+
* Read this before adding the next Workflow to this worker. Payments splits the "who holds a purchase"
|
|
20
|
+
* decision in two: `billingSubject` is a two-value enum in `PaymentsConfig`, and `resolveSubject` is a
|
|
21
|
+
* **function** on `PaymentsOptions`, the non-config argument to the `payments()` factory. The split follows
|
|
22
|
+
* the round trip this file sits at the end of — `provision/resolvePaymentsConfig.ts` `JSON.stringify`s the
|
|
23
|
+
* config into the `PAYMENTS_CONFIG` var and {@link reconcileWorkerConfig} parses it back, and a function
|
|
24
|
+
* does not survive that.
|
|
25
|
+
*
|
|
26
|
+
* So this worker **always** runs with no adopter resolver, on every project, in every environment. There is
|
|
27
|
+
* nothing to run one against either: `resolvePaymentsSubject` takes a Hono context, and a cron fire has no
|
|
28
|
+
* request, no session, and no caller.
|
|
29
|
+
*
|
|
30
|
+
* **Every subject anything in here touches therefore comes off a row it read** — the pair stored on a
|
|
31
|
+
* purchase, the pair on a provider-account link, or the reference a checkout stamped and the store echoed
|
|
32
|
+
* back. That is not a gap waiting to be closed; it is what a durable repair pass has to do regardless, since
|
|
33
|
+
* the holder of a subscription bought eleven months ago is not whoever happens to be signed in tonight.
|
|
34
|
+
* A Workflow added here that wants to know who holds something reads the row, and if the row cannot say,
|
|
35
|
+
* the honest outcome is an orphan: recorded, replayable, granting nothing.
|
|
36
|
+
*
|
|
37
|
+
* This module imports `cloudflare:workers`, so it runs only in the Workers runtime and is excluded from the
|
|
38
|
+
* node `.describe()` meta-test.
|
|
39
|
+
*/
|
|
40
|
+
export type { PaymentsWorkerEnv } from "./workerConfig";
|
|
41
|
+
/**
|
|
42
|
+
* The reconciliation pass, as a cron-triggered Workflow. One journalled step per page of purchases.
|
|
43
|
+
*
|
|
44
|
+
* Every step runs under {@link paymentsWorkflowRetry}: a store that could not be reached re-drives the
|
|
45
|
+
* page, and anything else fails it at once rather than spending a run's retry budget on an answer that
|
|
46
|
+
* will not change. See `retryPolicy.ts`.
|
|
47
|
+
*/
|
|
48
|
+
export declare class PaymentsReconcileWorkflow extends WorkflowEntrypoint<PaymentsWorkerEnv, PaymentsReconcileParams> {
|
|
49
|
+
run(event: WorkflowEvent<PaymentsReconcileParams>, step: WorkflowStep): Promise<ReconcileReport>;
|
|
50
|
+
}
|
|
51
|
+
declare const _default: {
|
|
52
|
+
/**
|
|
53
|
+
* Cron entry: start one pass per fire, with empty parameters — the defaults are the scheduled behavior.
|
|
54
|
+
*
|
|
55
|
+
* Through the same dispatcher an on-demand pass uses, rather than `env.PAYMENTS_RECONCILE.create()`: the
|
|
56
|
+
* parameters are validated against the job's own schema before the binding is touched, and a host deployed
|
|
57
|
+
* without its binding logs a skip instead of throwing inside a cron nobody is watching.
|
|
58
|
+
*/
|
|
59
|
+
scheduled(_controller: unknown, env: PaymentsWorkerEnv): Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
export default _default;
|
|
62
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/workflows/worker.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAU/F,OAAO,EAAE,KAAK,eAAe,EAAqB,MAAM,aAAa,CAAC;AAGtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,KAAK,iBAAiB,EAAyB,MAAM,gBAAgB,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAiBxD;;;;;;GAMG;AACH,qBAAa,yBAA0B,SAAQ,kBAAkB,CAAC,iBAAiB,EAAE,uBAAuB,CAAC;IAC5F,GAAG,CAAC,KAAK,EAAE,aAAa,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAmE9G;CACF;;IAGC;;;;;;OAMG;IACG,SAAS,cAAc,OAAO,OAAO,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PAYMENTS_PROVIDER_SECRET, paymentsSecretsRegistry, railCredentials } from "../secret/registry.js";
|
|
2
|
+
import { PaymentsReconcileParams } from "./specs.js";
|
|
3
|
+
import { triggerPaymentsReconcile } from "../http/dispatch.js";
|
|
4
|
+
import { batchedRailAccess } from "./railAccess.js";
|
|
5
|
+
import { reconcilePayments } from "./reconcile.js";
|
|
6
|
+
import { sweepPaddle } from "./paddleSweep.js";
|
|
7
|
+
import { auditLogEmit, logReconcileReport } from "./report.js";
|
|
8
|
+
import { paymentsWorkflowRetry } from "./retryPolicy.js";
|
|
9
|
+
import { reconcileWorkerConfig } from "./workerConfig.js";
|
|
10
|
+
import { configureSharedSecrets, sharedSecretsStore } from "@pithy-sh/secrets/src/sharedSecretsStore";
|
|
11
|
+
import { WorkflowEntrypoint } from "cloudflare:workers";
|
|
12
|
+
import { NonRetryableError } from "cloudflare:workflows";
|
|
13
|
+
import { bindWorkflowContext, createWorkerLogger } from "@pithy-sh/core/src/logger/worker";
|
|
14
|
+
import { classifiedSteps } from "@pithy-sh/core/src/workflow/faults";
|
|
15
|
+
//#region src/workflows/worker.ts
|
|
16
|
+
configureSharedSecrets({ registry: paymentsSecretsRegistry });
|
|
17
|
+
/**
|
|
18
|
+
* This deployment's store environment, from the `ENVIRONMENT` var — the same rule the app worker's routes use.
|
|
19
|
+
*
|
|
20
|
+
* Only a worker deployed to `prod` is production. The failure directions are not symmetric: treating
|
|
21
|
+
* production as sandbox refuses a repair that the next pass makes anyway, while treating sandbox as production
|
|
22
|
+
* would let a test transaction rewrite a real entitlement.
|
|
23
|
+
*/
|
|
24
|
+
function deploymentEnvironment(env) {
|
|
25
|
+
return env.ENVIRONMENT === "prod" ? "production" : "sandbox";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The reconciliation pass, as a cron-triggered Workflow. One journalled step per page of purchases.
|
|
29
|
+
*
|
|
30
|
+
* Every step runs under {@link paymentsWorkflowRetry}: a store that could not be reached re-drives the
|
|
31
|
+
* page, and anything else fails it at once rather than spending a run's retry budget on an answer that
|
|
32
|
+
* will not change. See `retryPolicy.ts`.
|
|
33
|
+
*/
|
|
34
|
+
var PaymentsReconcileWorkflow = class extends WorkflowEntrypoint {
|
|
35
|
+
async run(event, step) {
|
|
36
|
+
const params = PaymentsReconcileParams.parse(event.payload ?? {});
|
|
37
|
+
const config = reconcileWorkerConfig(this.env);
|
|
38
|
+
const log = bindWorkflowContext(createWorkerLogger({ name: "payments:reconcile" }), {
|
|
39
|
+
workflow: event.workflowName,
|
|
40
|
+
instance: event.instanceId,
|
|
41
|
+
env: this.env.ENVIRONMENT ?? "unknown"
|
|
42
|
+
});
|
|
43
|
+
const credentials = (await sharedSecretsStore(this.env, paymentsSecretsRegistry)).get(PAYMENTS_PROVIDER_SECRET);
|
|
44
|
+
const report = await reconcilePayments({
|
|
45
|
+
d1: this.env.DB,
|
|
46
|
+
config,
|
|
47
|
+
environment: deploymentEnvironment(this.env),
|
|
48
|
+
railAccess: (now) => batchedRailAccess({
|
|
49
|
+
config,
|
|
50
|
+
credentials,
|
|
51
|
+
now
|
|
52
|
+
}),
|
|
53
|
+
now: () => /* @__PURE__ */ new Date(),
|
|
54
|
+
emit: auditLogEmit(log),
|
|
55
|
+
/**
|
|
56
|
+
* The Paddle events sweep, supplied only when that rail is on.
|
|
57
|
+
*
|
|
58
|
+
* Undefined otherwise, and the difference is a statement rather than an optimization: a rail
|
|
59
|
+
* nobody sells through did not sweep, where a rail that swept and found nothing is a healthy
|
|
60
|
+
* integration. Collapsing the two makes "the webhooks are fine" indistinguishable from "we never
|
|
61
|
+
* looked", which is the exact ambiguity this pass exists to remove.
|
|
62
|
+
*
|
|
63
|
+
* Built here rather than inside `reconcilePayments`, because it needs Paddle's credentials and its
|
|
64
|
+
* own account, and that module deliberately knows nothing about any single rail.
|
|
65
|
+
*/
|
|
66
|
+
...config.rails.paddle && config.paddle !== void 0 ? { sweepPaddle: () => sweepPaddle({
|
|
67
|
+
d1: this.env.DB,
|
|
68
|
+
config,
|
|
69
|
+
environment: deploymentEnvironment(this.env),
|
|
70
|
+
credentials: railCredentials(credentials, "paddle"),
|
|
71
|
+
paddleEnvironment: config.paddle?.environment ?? "sandbox",
|
|
72
|
+
deployment: this.env.ENVIRONMENT,
|
|
73
|
+
now: () => /* @__PURE__ */ new Date()
|
|
74
|
+
}) } : {}
|
|
75
|
+
}, classifiedSteps(step, paymentsWorkflowRetry, NonRetryableError), params);
|
|
76
|
+
logReconcileReport(log, report);
|
|
77
|
+
return report;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var worker_default = {
|
|
81
|
+
/**
|
|
82
|
+
* Cron entry: start one pass per fire, with empty parameters — the defaults are the scheduled behavior.
|
|
83
|
+
*
|
|
84
|
+
* Through the same dispatcher an on-demand pass uses, rather than `env.PAYMENTS_RECONCILE.create()`: the
|
|
85
|
+
* parameters are validated against the job's own schema before the binding is touched, and a host deployed
|
|
86
|
+
* without its binding logs a skip instead of throwing inside a cron nobody is watching.
|
|
87
|
+
*/
|
|
88
|
+
async scheduled(_controller, env) {
|
|
89
|
+
await triggerPaymentsReconcile(env, {}, createWorkerLogger());
|
|
90
|
+
} };
|
|
91
|
+
//#endregion
|
|
92
|
+
export { PaymentsReconcileWorkflow, worker_default as default };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
2
|
+
import type { SecretsStoreEnv } from "@pithy-sh/secrets/src/env/bindings";
|
|
3
|
+
import { PaymentsConfig } from "../config/config";
|
|
4
|
+
/**
|
|
5
|
+
* The reconcile worker's env, and the one function that reads its config out of a var.
|
|
6
|
+
*
|
|
7
|
+
* **A sibling module rather than part of `worker.ts`, and the split is a rule rather than a preference.**
|
|
8
|
+
* `worker.ts` imports `cloudflare:workers`, so it resolves only inside the Workers runtime — and anything it
|
|
9
|
+
* exports is therefore unreachable from a node test, from the CLI, and from every meta-test that walks this
|
|
10
|
+
* repository's exports. `packages/cli/src/capabilities/configEntrypoints.test.ts` fails a runtime module that
|
|
11
|
+
* exports a pure value for exactly that reason (#172), and this function is a pure value: it takes a plain
|
|
12
|
+
* object and returns a parsed config, touching no binding and no runtime API.
|
|
13
|
+
*
|
|
14
|
+
* So it lives here, where anything may import it, and `worker.ts` imports it like any other caller.
|
|
15
|
+
*/
|
|
16
|
+
/** The reconcile worker's env: the app database, the secrets database, the master key, and its config. */
|
|
17
|
+
export interface PaymentsWorkerEnv extends SecretsStoreEnv {
|
|
18
|
+
/** The app database the `pithy_payments_*` tables live in. */
|
|
19
|
+
DB: D1Database;
|
|
20
|
+
/** The resolved payments config as a JSON string, filled at provision. See {@link reconcileWorkerConfig}. */
|
|
21
|
+
PAYMENTS_CONFIG?: string;
|
|
22
|
+
/** This worker's own Workflow binding — how `scheduled()` starts an instance. */
|
|
23
|
+
PAYMENTS_RECONCILE?: {
|
|
24
|
+
create(options?: {
|
|
25
|
+
id?: string;
|
|
26
|
+
params?: unknown;
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The catalog this worker reconciles against, read back out of the `PAYMENTS_CONFIG` var.
|
|
32
|
+
*
|
|
33
|
+
* **A config this does not accept stops the run, and since `billingSubject` became required that includes
|
|
34
|
+
* an absent var.** It used to fall back to `{}` and every default — which was survivable while every field
|
|
35
|
+
* had one, and is not now. The holder kind is the one thing a pass cannot default: `user` is what a
|
|
36
|
+
* defaulted config would produce, and a pass that repaired an organization's subscriptions while believing
|
|
37
|
+
* it was reconciling users would resolve entitlements for the wrong holder and audit the repairs under it.
|
|
38
|
+
* Refusing is the loud version of the same fact, and it fires on the first cron rather than on the first
|
|
39
|
+
* support ticket.
|
|
40
|
+
*
|
|
41
|
+
* Named as a refusal rather than a stack trace, because the reader is an operator: the message says which
|
|
42
|
+
* var, the action says which command rewrites it. Both `PithyError`s, so the Workflow's failure reads the
|
|
43
|
+
* way every other failure in the kit does.
|
|
44
|
+
*/
|
|
45
|
+
export declare function reconcileWorkerConfig(env: PaymentsWorkerEnv): PaymentsConfig;
|
|
46
|
+
//# sourceMappingURL=workerConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerConfig.d.ts","sourceRoot":"","sources":["../../src/workflows/workerConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;;GAWG;AAEH,0GAA0G;AAC1G,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACxD,8DAA8D;IAC9D,EAAE,EAAE,UAAU,CAAC;IACf,6GAA6G;IAC7G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iFAAiF;IACjF,kBAAkB,CAAC,EAAE;QAAE,MAAM,CAAC,OAAO,CAAC,EAAE;YAAE,EAAE,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,OAAO,CAAA;SAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;CAChG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,iBAAiB,GAAG,cAAc,CA0B5E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PaymentsConfig } from "../config/config.js";
|
|
2
|
+
import { InternalError, fromZodError, messageOf } from "@pithy-sh/core/src/error/pithyError";
|
|
3
|
+
//#region src/workflows/workerConfig.ts
|
|
4
|
+
/**
|
|
5
|
+
* The catalog this worker reconciles against, read back out of the `PAYMENTS_CONFIG` var.
|
|
6
|
+
*
|
|
7
|
+
* **A config this does not accept stops the run, and since `billingSubject` became required that includes
|
|
8
|
+
* an absent var.** It used to fall back to `{}` and every default — which was survivable while every field
|
|
9
|
+
* had one, and is not now. The holder kind is the one thing a pass cannot default: `user` is what a
|
|
10
|
+
* defaulted config would produce, and a pass that repaired an organization's subscriptions while believing
|
|
11
|
+
* it was reconciling users would resolve entitlements for the wrong holder and audit the repairs under it.
|
|
12
|
+
* Refusing is the loud version of the same fact, and it fires on the first cron rather than on the first
|
|
13
|
+
* support ticket.
|
|
14
|
+
*
|
|
15
|
+
* Named as a refusal rather than a stack trace, because the reader is an operator: the message says which
|
|
16
|
+
* var, the action says which command rewrites it. Both `PithyError`s, so the Workflow's failure reads the
|
|
17
|
+
* way every other failure in the kit does.
|
|
18
|
+
*/
|
|
19
|
+
function reconcileWorkerConfig(env) {
|
|
20
|
+
let value;
|
|
21
|
+
try {
|
|
22
|
+
value = env.PAYMENTS_CONFIG ? JSON.parse(env.PAYMENTS_CONFIG) : void 0;
|
|
23
|
+
} catch (cause) {
|
|
24
|
+
throw new InternalError({
|
|
25
|
+
message: "The reconcile worker's PAYMENTS_CONFIG var is not valid JSON.",
|
|
26
|
+
action: "Re-run `pithy payments provision` for this environment to rewrite it.",
|
|
27
|
+
detail: messageOf(cause)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const parsed = PaymentsConfig.safeParse(value ?? {});
|
|
31
|
+
if (!parsed.success) throw fromZodError(parsed.error, {
|
|
32
|
+
message: "The reconcile worker's PAYMENTS_CONFIG var is not a payments config this build can run.",
|
|
33
|
+
action: "Set the missing keys in this Worker's pithy.config.ts — `billingSubject` is required — then re-run `pithy payments provision` for this environment."
|
|
34
|
+
});
|
|
35
|
+
return parsed.data;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { reconcileWorkerConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithy-sh/payments",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,18 +12,23 @@
|
|
|
12
12
|
"node": ">=22"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
|
-
"./src/*":
|
|
15
|
+
"./src/*": {
|
|
16
|
+
"types": "./dist/*.d.ts",
|
|
17
|
+
"default": "./dist/*.js"
|
|
18
|
+
},
|
|
16
19
|
"./paddle-prices.iife.js": "./dist/paddle-prices.iife.js"
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
22
|
+
"dist",
|
|
19
23
|
"src",
|
|
20
24
|
"docs",
|
|
21
|
-
"dist/paddle-prices.iife.js",
|
|
22
25
|
"pithy.manifest.json",
|
|
23
|
-
"!src/**/*.test.*"
|
|
26
|
+
"!src/**/*.test.*",
|
|
27
|
+
"!dist/**/*.test.*",
|
|
28
|
+
"!src/client/paddlePrices.iife.ts"
|
|
24
29
|
],
|
|
25
30
|
"scripts": {
|
|
26
|
-
"build": "tsc -p tsconfig.json
|
|
31
|
+
"build": "tsdown && tsc -p tsconfig.build.json && bun scripts/buildPaddlePrices.ts",
|
|
27
32
|
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.client.json",
|
|
28
33
|
"test": "vitest run",
|
|
29
34
|
"test:node": "vitest run --project=node",
|
|
@@ -32,8 +37,11 @@
|
|
|
32
37
|
"reset": "bun run clean && rm -rf node_modules"
|
|
33
38
|
},
|
|
34
39
|
"peerDependencies": {
|
|
35
|
-
"@pithy-sh/ledger": "
|
|
36
|
-
"
|
|
40
|
+
"@pithy-sh/ledger": "^0.1.3",
|
|
41
|
+
"hono": "^4.13.2",
|
|
42
|
+
"kysely": "^0.29.0",
|
|
43
|
+
"react": "^19.0.0",
|
|
44
|
+
"zod": "^4.4.0"
|
|
37
45
|
},
|
|
38
46
|
"peerDependenciesMeta": {
|
|
39
47
|
"@pithy-sh/ledger": {
|
|
@@ -47,11 +55,8 @@
|
|
|
47
55
|
"@cloudflare/workers-types": "^5.20260729.1",
|
|
48
56
|
"@hono/zod-validator": "^0.9.0",
|
|
49
57
|
"@paddle/paddle-js": "^1.6.4",
|
|
50
|
-
"@pithy-sh/core": "
|
|
51
|
-
"@pithy-sh/secrets": "
|
|
52
|
-
"hono": "^4.13.2",
|
|
53
|
-
"kysely": "^0.29.0",
|
|
54
|
-
"zod": "^4.0.0"
|
|
58
|
+
"@pithy-sh/core": "^0.1.3",
|
|
59
|
+
"@pithy-sh/secrets": "^0.1.3"
|
|
55
60
|
},
|
|
56
61
|
"devDependencies": {
|
|
57
62
|
"@cloudflare/vitest-plugin": "^1.0.0",
|
|
@@ -62,12 +67,16 @@
|
|
|
62
67
|
"@types/react-dom": "^19.2.3",
|
|
63
68
|
"@vitest/coverage-v8": "^4.1.0",
|
|
64
69
|
"happy-dom": "^20.11.1",
|
|
70
|
+
"hono": "^4.13.2",
|
|
71
|
+
"kysely": "^0.29.0",
|
|
65
72
|
"kysely-d1": "^0.4.0",
|
|
66
73
|
"react": "^19.2.8",
|
|
67
74
|
"react-dom": "^19.2.8",
|
|
68
75
|
"rolldown": "^1.2.4",
|
|
76
|
+
"tsdown": "^0.23.0",
|
|
69
77
|
"typescript": "^7.0.2",
|
|
70
78
|
"vitest": "^4.1.0",
|
|
71
|
-
"wrangler": "^4.115.0"
|
|
79
|
+
"wrangler": "^4.115.0",
|
|
80
|
+
"zod": "^4.4.0"
|
|
72
81
|
}
|
|
73
82
|
}
|