@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,428 @@
|
|
|
1
|
+
import { getEntitlements, openBillingPortal, openStoreSubscriptions, restorePurchases, startCheckout, submitPurchase } from "./api.js";
|
|
2
|
+
import { loadPaddle, previewPrices, priceQueryKey } from "./paddle.js";
|
|
3
|
+
import { openPaddleCheckout } from "./checkout.js";
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
//#region src/client/hooks.ts
|
|
6
|
+
/**
|
|
7
|
+
* The headless client surface: six hooks a paywall, a pricing page, a subscription screen, and a route
|
|
8
|
+
* guard are built out of.
|
|
9
|
+
*
|
|
10
|
+
* **They live here rather than in a scaffolded `.tsx` on purpose.** `pithy ui add` writes a file once and
|
|
11
|
+
* may never rewrite it, which is the right ownership rule and is exactly why a frozen paywall ages badly:
|
|
12
|
+
* store rules move — price-change consent prompts, external purchase link entitlements, subscription
|
|
13
|
+
* management requirements — and a purchase flow living in the adopter's repo is one Pithy cannot fix for
|
|
14
|
+
* them. So the hook owns the calls, the redirect-and-return dance, the error mapping and the entitlement
|
|
15
|
+
* reads, and upgrades with a minor release; the stub renders and styles, calling these rather than
|
|
16
|
+
* reimplementing them. Principle 3, applied to the client.
|
|
17
|
+
*
|
|
18
|
+
* `react` is an **optional** peer dependency, and this module is reachable only by its own deep path
|
|
19
|
+
* (`@pithy-sh/payments/src/client/hooks`). It is deliberately absent from `src/index.ts` — that is what
|
|
20
|
+
* keeps React out of a Worker bundle that composes payments.
|
|
21
|
+
*
|
|
22
|
+
* Cookie/session throughout, because `./api` is: same-origin, `credentials: "include"`, no token in web
|
|
23
|
+
* storage, no bearer header. Bearer stays the mobile path.
|
|
24
|
+
*
|
|
25
|
+
* **Nothing here throws, and nothing here is a security boundary.** A refusal is a message to render, and
|
|
26
|
+
* the server's `requireEntitlement()` is the gate; these exist so a user is sent to the paywall rather than
|
|
27
|
+
* shown a 403.
|
|
28
|
+
*
|
|
29
|
+
* **A failed read is not an answer, and each hook says so in the way its caller needs.** `useEntitlement`
|
|
30
|
+
* is a lock, so it fails closed — `entitled` stays false — and reports `readFailure` beside it so a screen
|
|
31
|
+
* can tell "you don't have Pro" from "we couldn't check". `useSubscription` *names the plan*, where failing
|
|
32
|
+
* closed would be a lie: an empty entitlement list is a positive claim that the account is on the free
|
|
33
|
+
* floor, so it reports the failure instead of rendering one.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Hold the newest value without making it a dependency.
|
|
37
|
+
*
|
|
38
|
+
* Every hook below takes an options object, and a caller writing `useEntitlement("pro", { basePath })`
|
|
39
|
+
* inline creates a new object every render. Depending on it would re-run the effect forever. So the
|
|
40
|
+
* effects depend on the one thing that can actually change the request — `basePath`, a string — and read
|
|
41
|
+
* the rest through this.
|
|
42
|
+
*/
|
|
43
|
+
function useLatest(value) {
|
|
44
|
+
const ref = useRef(value);
|
|
45
|
+
ref.current = value;
|
|
46
|
+
return ref;
|
|
47
|
+
}
|
|
48
|
+
/** Whether a component is still mounted. Every async completion checks it before setting state. */
|
|
49
|
+
function useLive() {
|
|
50
|
+
const live = useRef(true);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
live.current = true;
|
|
53
|
+
return () => {
|
|
54
|
+
live.current = false;
|
|
55
|
+
};
|
|
56
|
+
}, []);
|
|
57
|
+
return live;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether the caller holds `key`.
|
|
61
|
+
*
|
|
62
|
+
* Starts `false`, always. Starting `true` would flash the paid screen to everyone for one frame, which is
|
|
63
|
+
* both a leak and worse to look at than a spinner. An unreachable Worker reads as not entitled for the
|
|
64
|
+
* same reason: the server check is the boundary, so failing closed here costs nothing.
|
|
65
|
+
*
|
|
66
|
+
* The failing-closed happens *here*, visibly, rather than inside {@link getEntitlements} — a lock is a
|
|
67
|
+
* refusal and can carry an escape route on it, which is what `readFailure` is. A caller that names the
|
|
68
|
+
* plan instead of locking it must not inherit this choice; see {@link useSubscription}.
|
|
69
|
+
*/
|
|
70
|
+
function useEntitlement(key, options) {
|
|
71
|
+
const [entitled, setEntitled] = useState(false);
|
|
72
|
+
const [loading, setLoading] = useState(true);
|
|
73
|
+
const [readFailure, setReadFailure] = useState(null);
|
|
74
|
+
const latest = useLatest(options);
|
|
75
|
+
const live = useLive();
|
|
76
|
+
const basePath = options?.basePath;
|
|
77
|
+
const refresh = useCallback(() => {
|
|
78
|
+
setLoading(true);
|
|
79
|
+
getEntitlements({
|
|
80
|
+
...latest.current,
|
|
81
|
+
basePath
|
|
82
|
+
}).then((result) => {
|
|
83
|
+
if (!live.current) return;
|
|
84
|
+
setEntitled(result.ok && result.value.some((entitlement) => entitlement.key === key && entitlement.granted));
|
|
85
|
+
setReadFailure(result.ok ? null : result.failure);
|
|
86
|
+
setLoading(false);
|
|
87
|
+
});
|
|
88
|
+
}, [
|
|
89
|
+
key,
|
|
90
|
+
basePath,
|
|
91
|
+
latest,
|
|
92
|
+
live
|
|
93
|
+
]);
|
|
94
|
+
useEffect(refresh, [refresh]);
|
|
95
|
+
return {
|
|
96
|
+
entitled,
|
|
97
|
+
loading,
|
|
98
|
+
readFailure,
|
|
99
|
+
refresh
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The caller's standing entitlements, and the one action a subscriber needs.
|
|
104
|
+
*
|
|
105
|
+
* Managing a subscription is the store's job, not Pithy's — Stripe's Billing Portal owns cancellation,
|
|
106
|
+
* card changes and plan moves, under Stripe's own rules and its own compliance. Apple and Google
|
|
107
|
+
* subscriptions are managed in their own apps, which a web screen can only link to.
|
|
108
|
+
*/
|
|
109
|
+
function useSubscription(options) {
|
|
110
|
+
const [entitlements, setEntitlements] = useState([]);
|
|
111
|
+
const [loading, setLoading] = useState(true);
|
|
112
|
+
const [managing, setManaging] = useState(false);
|
|
113
|
+
const [failure, setFailure] = useState(null);
|
|
114
|
+
const [readFailure, setReadFailure] = useState(null);
|
|
115
|
+
const latest = useLatest(options);
|
|
116
|
+
const live = useLive();
|
|
117
|
+
const basePath = options?.basePath;
|
|
118
|
+
const refresh = useCallback(() => {
|
|
119
|
+
setLoading(true);
|
|
120
|
+
getEntitlements({
|
|
121
|
+
...latest.current,
|
|
122
|
+
basePath
|
|
123
|
+
}).then((result) => {
|
|
124
|
+
if (!live.current) return;
|
|
125
|
+
if (result.ok) setEntitlements(result.value);
|
|
126
|
+
setReadFailure(result.ok ? null : result.failure);
|
|
127
|
+
setLoading(false);
|
|
128
|
+
});
|
|
129
|
+
}, [
|
|
130
|
+
basePath,
|
|
131
|
+
latest,
|
|
132
|
+
live
|
|
133
|
+
]);
|
|
134
|
+
useEffect(refresh, [refresh]);
|
|
135
|
+
const manage = useCallback(async () => {
|
|
136
|
+
setManaging(true);
|
|
137
|
+
setFailure(null);
|
|
138
|
+
const refused = await openBillingPortal(latest.current);
|
|
139
|
+
if (!live.current) return;
|
|
140
|
+
setManaging(false);
|
|
141
|
+
if (refused) setFailure(refused);
|
|
142
|
+
}, [latest, live]);
|
|
143
|
+
const manageStore = useCallback((rail) => {
|
|
144
|
+
openStoreSubscriptions(rail, latest.current);
|
|
145
|
+
}, [latest]);
|
|
146
|
+
return {
|
|
147
|
+
entitlements,
|
|
148
|
+
subscribed: entitlements.some((entitlement) => entitlement.granted),
|
|
149
|
+
loading,
|
|
150
|
+
refresh,
|
|
151
|
+
manage,
|
|
152
|
+
manageStore,
|
|
153
|
+
managing,
|
|
154
|
+
failure,
|
|
155
|
+
readFailure
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The web purchase path: start a checkout, and go wherever that rail goes.
|
|
160
|
+
*
|
|
161
|
+
* Apple and Google purchases happen inside a store SDK before any server hears of them, so there is no
|
|
162
|
+
* session for Pithy to create and no browser flow to start — a web paywall lists those products, it does
|
|
163
|
+
* not sell them. Stripe's and Lemon Squeezy's hosted checkouts need no SDK script and no publishable key
|
|
164
|
+
* in the page: the server mints a session, this navigates to it, and the store owns everything in between.
|
|
165
|
+
*
|
|
166
|
+
* Paddle is the one that does not leave. This hook does the same work for it — the server call, the
|
|
167
|
+
* refusal — and stops at the handoff, because opening it belongs where the container is. That is
|
|
168
|
+
* {@link usePaddleCheckout}.
|
|
169
|
+
*/
|
|
170
|
+
function useCheckout(options) {
|
|
171
|
+
const [starting, setStarting] = useState(false);
|
|
172
|
+
const [failure, setFailure] = useState(null);
|
|
173
|
+
const [handoff, setHandoff] = useState(null);
|
|
174
|
+
const latest = useLatest(options);
|
|
175
|
+
const live = useLive();
|
|
176
|
+
return {
|
|
177
|
+
start: useCallback(async (productId, choices) => {
|
|
178
|
+
setStarting(true);
|
|
179
|
+
setFailure(null);
|
|
180
|
+
setHandoff(null);
|
|
181
|
+
const outcome = await startCheckout({
|
|
182
|
+
productId,
|
|
183
|
+
rail: choices?.rail,
|
|
184
|
+
discountCode: choices?.discountCode
|
|
185
|
+
}, latest.current);
|
|
186
|
+
if (!live.current) return;
|
|
187
|
+
setStarting(false);
|
|
188
|
+
if (outcome.kind === "refused") setFailure(outcome.failure);
|
|
189
|
+
else if (outcome.kind === "paddle") setHandoff(outcome.handoff);
|
|
190
|
+
}, [latest, live]),
|
|
191
|
+
starting,
|
|
192
|
+
failure,
|
|
193
|
+
handoff
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Open the handoff {@link useCheckout} produced, with Paddle.js, over this page or inside it.
|
|
198
|
+
*
|
|
199
|
+
* **In an effect, and that is the whole reason this is a hook rather than a line in a click handler.**
|
|
200
|
+
* Inline checkout renders into an element the screen provides, and Paddle finds it by class name at the
|
|
201
|
+
* moment `open` is called. Called from the handler that starts the checkout, the container React is about
|
|
202
|
+
* to render does not exist yet — and what Paddle does then is throw `TypeError: Cannot read properties of
|
|
203
|
+
* undefined (reading 'appendChild')` out of the click, which is not a sentence anyone can act on. An
|
|
204
|
+
* effect runs after the commit that revealed the container, so the element is there.
|
|
205
|
+
*
|
|
206
|
+
* One open per handoff. `start` mints a new transaction on every attempt, so the transaction id is what a
|
|
207
|
+
* fresh attempt looks like; a re-render with the same handoff must not open a second checkout over the
|
|
208
|
+
* first — and neither must a second *mount* of the same one. React's `StrictMode` runs every effect,
|
|
209
|
+
* cleans it up and runs it again, and that is the mode `pithy ui add` scaffolds: `client.tsx` wraps the
|
|
210
|
+
* router in it. So the transaction that has been opened is remembered, rather than the effect trusting
|
|
211
|
+
* that it runs once. The remembered id is the last one opened, not a flag — a buyer who closed the
|
|
212
|
+
* overlay and clicked Buy again arrives with a new transaction, and that one must open.
|
|
213
|
+
*/
|
|
214
|
+
function usePaddleCheckout(handoff, options) {
|
|
215
|
+
const [opening, setOpening] = useState(false);
|
|
216
|
+
const [failure, setFailure] = useState(null);
|
|
217
|
+
const latest = useLatest(options);
|
|
218
|
+
const latestHandoff = useLatest(handoff);
|
|
219
|
+
const live = useLive();
|
|
220
|
+
const transactionId = handoff?.transactionId;
|
|
221
|
+
/** The transaction this hook has already opened, so a second effect pass over it opens nothing. */
|
|
222
|
+
const opened = useRef(null);
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
const current = latestHandoff.current;
|
|
225
|
+
if (transactionId === void 0 || current === null) return;
|
|
226
|
+
if (opened.current === transactionId) return;
|
|
227
|
+
opened.current = transactionId;
|
|
228
|
+
setOpening(true);
|
|
229
|
+
setFailure(null);
|
|
230
|
+
openPaddleCheckout(current, latest.current).then((refused) => {
|
|
231
|
+
if (!live.current) return;
|
|
232
|
+
setOpening(false);
|
|
233
|
+
setFailure(refused);
|
|
234
|
+
});
|
|
235
|
+
}, [
|
|
236
|
+
transactionId,
|
|
237
|
+
latest,
|
|
238
|
+
latestHandoff,
|
|
239
|
+
live
|
|
240
|
+
]);
|
|
241
|
+
return {
|
|
242
|
+
inline: handoff?.displayMode === "inline",
|
|
243
|
+
opening,
|
|
244
|
+
failure
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Submitting receipts — the path that exists so a buyer sees their entitlement now rather than when the
|
|
249
|
+
* webhook lands.
|
|
250
|
+
*
|
|
251
|
+
* On the web that is the Stripe return: the success URL carries the Checkout Session id, and posting it
|
|
252
|
+
* here projects the purchase at once. On a native client it is the store SDK's transaction, and `restore`
|
|
253
|
+
* is Restore Purchases. Dropping either call costs nothing — the webhook produces the identical row, and
|
|
254
|
+
* the write is idempotent on `(rail, providerTransactionId)`.
|
|
255
|
+
*
|
|
256
|
+
* A refusal leaves `purchase` and `entitlements` exactly as they were. Clearing them would flicker a
|
|
257
|
+
* paywall back over a feature the user already owns, on nothing more than a failed second submission.
|
|
258
|
+
*/
|
|
259
|
+
function usePurchase(options) {
|
|
260
|
+
const [purchase, setPurchase] = useState(null);
|
|
261
|
+
const [entitlements, setEntitlements] = useState([]);
|
|
262
|
+
const [busy, setBusy] = useState(false);
|
|
263
|
+
const [failure, setFailure] = useState(null);
|
|
264
|
+
const latest = useLatest(options);
|
|
265
|
+
const live = useLive();
|
|
266
|
+
return {
|
|
267
|
+
submit: useCallback(async (rail, receipt) => {
|
|
268
|
+
setBusy(true);
|
|
269
|
+
setFailure(null);
|
|
270
|
+
const result = await submitPurchase({
|
|
271
|
+
rail,
|
|
272
|
+
receipt
|
|
273
|
+
}, latest.current);
|
|
274
|
+
if (!live.current) return;
|
|
275
|
+
setBusy(false);
|
|
276
|
+
if (!result.ok) {
|
|
277
|
+
setFailure(result.failure);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
setPurchase(result.value.purchase);
|
|
281
|
+
setEntitlements(result.value.entitlements);
|
|
282
|
+
}, [latest, live]),
|
|
283
|
+
restore: useCallback(async (rail, receipts) => {
|
|
284
|
+
setBusy(true);
|
|
285
|
+
setFailure(null);
|
|
286
|
+
const result = await restorePurchases({
|
|
287
|
+
rail,
|
|
288
|
+
receipts
|
|
289
|
+
}, latest.current);
|
|
290
|
+
if (!live.current) return;
|
|
291
|
+
setBusy(false);
|
|
292
|
+
if (!result.ok) {
|
|
293
|
+
setFailure(result.failure);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
setPurchase(result.value.purchases[0] ?? null);
|
|
297
|
+
setEntitlements(result.value.entitlements);
|
|
298
|
+
}, [latest, live]),
|
|
299
|
+
purchase,
|
|
300
|
+
entitlements,
|
|
301
|
+
busy,
|
|
302
|
+
failure
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Paddle.js, loaded once per page.
|
|
307
|
+
*
|
|
308
|
+
* `setup` takes null so a screen never has to guard a hook: `paymentsConfig.paddle` is null when the
|
|
309
|
+
* rail is off, and passing that through reads as "nothing to load" rather than as a failure. A pricing
|
|
310
|
+
* page for a project that does not sell through Paddle renders its own empty state; it does not show an
|
|
311
|
+
* error about a provider it never asked for.
|
|
312
|
+
*
|
|
313
|
+
* Loading is the module's job, not this hook's — mounting two components that both call it produces one
|
|
314
|
+
* script and one `Initialize`, because {@link loadPaddle} remembers the page's one load. This is the
|
|
315
|
+
* React-shaped view of it: a state a screen can render.
|
|
316
|
+
*/
|
|
317
|
+
function usePaddle(setup, options) {
|
|
318
|
+
const [paddle, setPaddle] = useState(null);
|
|
319
|
+
const [loading, setLoading] = useState(setup !== null);
|
|
320
|
+
const [failure, setFailure] = useState(null);
|
|
321
|
+
const latest = useLatest(options);
|
|
322
|
+
const live = useLive();
|
|
323
|
+
const clientToken = setup?.clientToken;
|
|
324
|
+
const environment = setup?.environment;
|
|
325
|
+
useEffect(() => {
|
|
326
|
+
if (clientToken === void 0 || environment === void 0) {
|
|
327
|
+
setLoading(false);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
setLoading(true);
|
|
331
|
+
loadPaddle({
|
|
332
|
+
clientToken,
|
|
333
|
+
environment
|
|
334
|
+
}, latest.current).then((result) => {
|
|
335
|
+
if (!live.current) return;
|
|
336
|
+
setPaddle(result.ok ? result.value : null);
|
|
337
|
+
setFailure(result.ok ? null : result.failure);
|
|
338
|
+
setLoading(false);
|
|
339
|
+
});
|
|
340
|
+
}, [
|
|
341
|
+
clientToken,
|
|
342
|
+
environment,
|
|
343
|
+
latest,
|
|
344
|
+
live
|
|
345
|
+
]);
|
|
346
|
+
return {
|
|
347
|
+
paddle,
|
|
348
|
+
loading,
|
|
349
|
+
failure
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* What this visitor pays, read from Paddle for this visitor.
|
|
354
|
+
*
|
|
355
|
+
* **No price string appears in any screen this kit ships.** That is the whole contract. The figures come
|
|
356
|
+
* from Paddle, rendered by Paddle for the visitor's country — which is the only way one page can quote
|
|
357
|
+
* $5.44 in New York, $5.75 in Chicago, $5.00 in Berlin including €0.80 of VAT, and ¥725 in Tokyo without
|
|
358
|
+
* a table of tax rates aging in somebody's repository.
|
|
359
|
+
*
|
|
360
|
+
* `query` may be written inline. The effect depends on {@link priceQueryKey} rather than on the object,
|
|
361
|
+
* so an object literal re-created on every render re-quotes when the request changed and not before.
|
|
362
|
+
*
|
|
363
|
+
* A failure clears the previous quote rather than leaving it. The other hooks here keep their last good
|
|
364
|
+
* value on a refusal, and this one deliberately does not: a re-quote happens because the *request*
|
|
365
|
+
* changed, so the value it would be keeping is a price for something else.
|
|
366
|
+
*
|
|
367
|
+
* **Only the latest quote is rendered, whichever answers first.** Two previews can be in flight at once —
|
|
368
|
+
* an anonymous visitor's location resolves under the query, or a country picker moves — and the slower
|
|
369
|
+
* one landing last would otherwise win, putting a price for an address the visitor has left on the one
|
|
370
|
+
* screen whose entire job is showing a correct one. Superseded answers are *ignored*, not canceled:
|
|
371
|
+
* Paddle.js's `PricePreview` takes no `AbortSignal` and hands back a bare promise, so there is nothing to
|
|
372
|
+
* cancel and ignoring it is the whole of the fix. A superseded refusal is ignored the same way, which is
|
|
373
|
+
* what stops a dead request blanking a price the visitor is already reading.
|
|
374
|
+
*/
|
|
375
|
+
function usePricePreview(setup, query, options) {
|
|
376
|
+
const [preview, setPreview] = useState(null);
|
|
377
|
+
const [loading, setLoading] = useState(setup !== null);
|
|
378
|
+
const [failure, setFailure] = useState(null);
|
|
379
|
+
const latest = useLatest(options);
|
|
380
|
+
const latestQuery = useLatest(query);
|
|
381
|
+
const live = useLive();
|
|
382
|
+
const clientToken = setup?.clientToken;
|
|
383
|
+
const environment = setup?.environment;
|
|
384
|
+
const queryKey = priceQueryKey(query);
|
|
385
|
+
/**
|
|
386
|
+
* Which quote is the current one.
|
|
387
|
+
*
|
|
388
|
+
* A counter rather than a comparison against `queryKey`, because two quotes for the *same* query race
|
|
389
|
+
* too — a screen calling `refresh` twice is the ordinary way to get there — and a key would read those
|
|
390
|
+
* two as one and let either win. Every ask takes the next number; only the holder of the last one
|
|
391
|
+
* issued may write state.
|
|
392
|
+
*/
|
|
393
|
+
const issued = useRef(0);
|
|
394
|
+
const refresh = useCallback(() => {
|
|
395
|
+
if (clientToken === void 0 || environment === void 0) {
|
|
396
|
+
setLoading(false);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const ticket = ++issued.current;
|
|
400
|
+
setLoading(true);
|
|
401
|
+
previewPrices({
|
|
402
|
+
clientToken,
|
|
403
|
+
environment
|
|
404
|
+
}, latestQuery.current, latest.current).then((result) => {
|
|
405
|
+
if (!live.current) return;
|
|
406
|
+
if (ticket !== issued.current) return;
|
|
407
|
+
setPreview(result.ok ? result.value : null);
|
|
408
|
+
setFailure(result.ok ? null : result.failure);
|
|
409
|
+
setLoading(false);
|
|
410
|
+
});
|
|
411
|
+
}, [
|
|
412
|
+
clientToken,
|
|
413
|
+
environment,
|
|
414
|
+
queryKey,
|
|
415
|
+
latest,
|
|
416
|
+
latestQuery,
|
|
417
|
+
live
|
|
418
|
+
]);
|
|
419
|
+
useEffect(refresh, [refresh]);
|
|
420
|
+
return {
|
|
421
|
+
preview,
|
|
422
|
+
loading,
|
|
423
|
+
failure,
|
|
424
|
+
refresh
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
export { useCheckout, useEntitlement, usePaddle, usePaddleCheckout, usePricePreview, usePurchase, useSubscription };
|