@pithy-sh/payments 0.3.10 → 0.5.0

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.
Files changed (215) hide show
  1. package/README.md +11 -3
  2. package/dist/admin/coverage.d.ts.map +1 -1
  3. package/dist/admin/coverage.js +26 -2
  4. package/dist/admin/read.d.ts +48 -1
  5. package/dist/admin/read.d.ts.map +1 -1
  6. package/dist/admin/read.js +89 -2
  7. package/dist/audit/actions.d.ts +13 -0
  8. package/dist/audit/actions.d.ts.map +1 -1
  9. package/dist/audit/actions.js +14 -1
  10. package/dist/capability.d.ts +33 -2
  11. package/dist/capability.d.ts.map +1 -1
  12. package/dist/capability.js +52 -9
  13. package/dist/client/api.d.ts +38 -0
  14. package/dist/client/api.d.ts.map +1 -1
  15. package/dist/client/api.js +59 -1
  16. package/dist/client/hooks.d.ts +63 -1
  17. package/dist/client/hooks.d.ts.map +1 -1
  18. package/dist/client/hooks.js +96 -2
  19. package/dist/client/paddleLink.d.ts +31 -0
  20. package/dist/client/paddleLink.d.ts.map +1 -0
  21. package/dist/client/paddleLink.js +37 -0
  22. package/dist/client/projection.d.ts +29 -0
  23. package/dist/client/projection.d.ts.map +1 -1
  24. package/dist/config/allowances.d.ts +71 -0
  25. package/dist/config/allowances.d.ts.map +1 -0
  26. package/dist/config/allowances.js +115 -0
  27. package/dist/config/config.d.ts +155 -9
  28. package/dist/config/config.d.ts.map +1 -1
  29. package/dist/config/config.js +164 -14
  30. package/dist/data/meterCounter.d.ts +34 -0
  31. package/dist/data/meterCounter.d.ts.map +1 -0
  32. package/dist/data/meterCounter.js +33 -0
  33. package/dist/data/override.d.ts +56 -0
  34. package/dist/data/override.d.ts.map +1 -0
  35. package/dist/data/override.js +58 -0
  36. package/dist/data/paddleIds.d.ts +28 -0
  37. package/dist/data/paddleIds.d.ts.map +1 -0
  38. package/dist/data/paddleIds.js +73 -0
  39. package/dist/data/period.d.ts +10 -0
  40. package/dist/data/period.d.ts.map +1 -0
  41. package/dist/data/period.js +37 -0
  42. package/dist/data/purchase.d.ts +1 -0
  43. package/dist/data/purchase.d.ts.map +1 -1
  44. package/dist/data/purchase.js +1 -0
  45. package/dist/data/tables.d.ts +17 -1
  46. package/dist/data/tables.d.ts.map +1 -1
  47. package/dist/data/tables.js +24 -4
  48. package/dist/data/usageReport.d.ts +68 -0
  49. package/dist/data/usageReport.d.ts.map +1 -0
  50. package/dist/data/usageReport.js +55 -0
  51. package/dist/data/usageRun.d.ts +93 -0
  52. package/dist/data/usageRun.d.ts.map +1 -0
  53. package/dist/data/usageRun.js +50 -0
  54. package/dist/entitlement/allowance.d.ts +100 -0
  55. package/dist/entitlement/allowance.d.ts.map +1 -0
  56. package/dist/entitlement/allowance.js +171 -0
  57. package/dist/entitlement/manual.d.ts +5 -5
  58. package/dist/entitlement/manual.js +3 -3
  59. package/dist/entitlement/meter.d.ts +98 -0
  60. package/dist/entitlement/meter.d.ts.map +1 -0
  61. package/dist/entitlement/meter.js +177 -0
  62. package/dist/entitlement/override.d.ts +119 -0
  63. package/dist/entitlement/override.d.ts.map +1 -0
  64. package/dist/entitlement/override.js +256 -0
  65. package/dist/entitlement/resolver.d.ts +2 -1
  66. package/dist/entitlement/resolver.d.ts.map +1 -1
  67. package/dist/entitlement/resolver.js +32 -1
  68. package/dist/entitlement/unimplementedSubject.d.ts.map +1 -1
  69. package/dist/entitlement/unimplementedSubject.js +3 -2
  70. package/dist/error/errors.d.ts +19 -0
  71. package/dist/error/errors.d.ts.map +1 -1
  72. package/dist/error/errors.js +35 -2
  73. package/dist/http/responses.d.ts +390 -5
  74. package/dist/http/responses.d.ts.map +1 -1
  75. package/dist/http/responses.js +169 -13
  76. package/dist/http/routes.d.ts +6 -2
  77. package/dist/http/routes.d.ts.map +1 -1
  78. package/dist/http/routes.js +478 -52
  79. package/dist/http/schemas.d.ts +75 -1
  80. package/dist/http/schemas.d.ts.map +1 -1
  81. package/dist/http/schemas.js +80 -3
  82. package/dist/http/scopes.d.ts +25 -0
  83. package/dist/http/scopes.d.ts.map +1 -1
  84. package/dist/http/scopes.js +60 -1
  85. package/dist/http/view.d.ts +22 -4
  86. package/dist/http/view.d.ts.map +1 -1
  87. package/dist/http/view.js +88 -7
  88. package/dist/http/webhookGuard.d.ts.map +1 -1
  89. package/dist/http/webhookGuard.js +1 -1
  90. package/dist/index.d.ts +2 -1
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +3 -2
  93. package/dist/migrations/0002_allowances.d.ts +26 -0
  94. package/dist/migrations/0002_allowances.d.ts.map +1 -0
  95. package/dist/migrations/0002_allowances.js +62 -0
  96. package/dist/peer.d.ts +1 -0
  97. package/dist/peer.d.ts.map +1 -1
  98. package/dist/projection/event.d.ts +1 -0
  99. package/dist/projection/event.d.ts.map +1 -1
  100. package/dist/projection/event.js +1 -0
  101. package/dist/projection/writer.d.ts.map +1 -1
  102. package/dist/projection/writer.js +3 -1
  103. package/dist/rails/contract.d.ts +6 -0
  104. package/dist/rails/contract.d.ts.map +1 -1
  105. package/dist/rails/google/playApi.d.ts.map +1 -1
  106. package/dist/rails/google/playApi.js +2 -0
  107. package/dist/rails/paddle/events.d.ts.map +1 -1
  108. package/dist/rails/paddle/events.js +2 -1
  109. package/dist/rails/paddle/objects.d.ts +2 -0
  110. package/dist/rails/paddle/objects.d.ts.map +1 -1
  111. package/dist/rails/paddle/objects.js +7 -2
  112. package/dist/rails/paddle/refresh.d.ts +10 -5
  113. package/dist/rails/paddle/refresh.d.ts.map +1 -1
  114. package/dist/rails/paddle/refresh.js +8 -5
  115. package/dist/rails/paddle/refund.d.ts.map +1 -1
  116. package/dist/rails/paddle/refund.js +10 -2
  117. package/dist/rails/paddle/subscription.d.ts.map +1 -1
  118. package/dist/rails/paddle/subscription.js +8 -3
  119. package/dist/rails/paddle/usage.d.ts +11 -0
  120. package/dist/rails/paddle/usage.d.ts.map +1 -0
  121. package/dist/rails/paddle/usage.js +49 -0
  122. package/dist/rails/paddle/verify.d.ts.map +1 -1
  123. package/dist/rails/paddle/verify.js +2 -3
  124. package/dist/rails/quantity.d.ts +12 -0
  125. package/dist/rails/quantity.d.ts.map +1 -0
  126. package/dist/rails/quantity.js +16 -0
  127. package/dist/rails/stripe/checkout.d.ts.map +1 -1
  128. package/dist/rails/stripe/checkout.js +1 -1
  129. package/dist/rails/stripe/objects.d.ts.map +1 -1
  130. package/dist/rails/stripe/objects.js +3 -0
  131. package/dist/rails/stripe/usage.d.ts +10 -0
  132. package/dist/rails/stripe/usage.d.ts.map +1 -0
  133. package/dist/rails/stripe/usage.js +49 -0
  134. package/dist/secret/registry.d.ts.map +1 -1
  135. package/dist/secret/registry.js +3 -2
  136. package/dist/usage/pass.d.ts +120 -0
  137. package/dist/usage/pass.d.ts.map +1 -0
  138. package/dist/usage/pass.js +363 -0
  139. package/dist/usage/reporter.d.ts +36 -0
  140. package/dist/usage/reporter.d.ts.map +1 -0
  141. package/dist/usage/reporter.js +2 -0
  142. package/dist/version.generated.d.ts +1 -1
  143. package/dist/version.generated.d.ts.map +1 -1
  144. package/dist/version.generated.js +1 -1
  145. package/dist/workflows/specs.d.ts +28 -0
  146. package/dist/workflows/specs.d.ts.map +1 -1
  147. package/dist/workflows/specs.js +26 -1
  148. package/dist/workflows/usage.d.ts +38 -0
  149. package/dist/workflows/usage.d.ts.map +1 -0
  150. package/dist/workflows/usage.js +77 -0
  151. package/dist/workflows/worker.js +2 -2
  152. package/dist/workflows/workerConfig.d.ts.map +1 -1
  153. package/dist/workflows/workerConfig.js +8 -2
  154. package/docs/entitlements.md +249 -0
  155. package/docs/lemon-squeezy.md +1 -0
  156. package/docs/paddle.md +18 -2
  157. package/package.json +7 -7
  158. package/pithy.manifest.json +3 -8
  159. package/src/admin/coverage.ts +28 -0
  160. package/src/admin/read.ts +173 -1
  161. package/src/audit/actions.ts +13 -0
  162. package/src/capability.ts +87 -9
  163. package/src/client/api.ts +79 -0
  164. package/src/client/hooks.ts +122 -0
  165. package/src/client/paddleLink.ts +41 -0
  166. package/src/client/projection.ts +31 -0
  167. package/src/config/allowances.ts +211 -0
  168. package/src/config/config.ts +283 -15
  169. package/src/data/meterCounter.ts +38 -0
  170. package/src/data/override.ts +74 -0
  171. package/src/data/paddleIds.ts +74 -0
  172. package/src/data/period.ts +53 -0
  173. package/src/data/purchase.ts +9 -0
  174. package/src/data/tables.ts +25 -1
  175. package/src/data/usageReport.ts +64 -0
  176. package/src/data/usageRun.ts +66 -0
  177. package/src/entitlement/allowance.ts +213 -0
  178. package/src/entitlement/manual.ts +6 -6
  179. package/src/entitlement/meter.ts +252 -0
  180. package/src/entitlement/override.ts +381 -0
  181. package/src/entitlement/resolver.ts +43 -2
  182. package/src/entitlement/unimplementedSubject.ts +3 -4
  183. package/src/error/errors.ts +44 -1
  184. package/src/http/responses.ts +338 -10
  185. package/src/http/routes.ts +1089 -460
  186. package/src/http/schemas.ts +171 -2
  187. package/src/http/scopes.ts +68 -0
  188. package/src/http/view.ts +112 -7
  189. package/src/http/webhookGuard.ts +3 -2
  190. package/src/index.ts +18 -0
  191. package/src/migrations/0002_allowances.ts +149 -0
  192. package/src/projection/event.ts +9 -0
  193. package/src/projection/writer.ts +4 -0
  194. package/src/rails/contract.ts +6 -0
  195. package/src/rails/google/playApi.ts +2 -0
  196. package/src/rails/paddle/events.ts +2 -1
  197. package/src/rails/paddle/fixtures/subscription-charge.json +19 -0
  198. package/src/rails/paddle/objects.ts +6 -0
  199. package/src/rails/paddle/refresh.ts +17 -10
  200. package/src/rails/paddle/refund.ts +10 -2
  201. package/src/rails/paddle/subscription.ts +8 -3
  202. package/src/rails/paddle/usage.ts +66 -0
  203. package/src/rails/paddle/verify.ts +6 -4
  204. package/src/rails/quantity.ts +14 -0
  205. package/src/rails/stripe/checkout.ts +3 -1
  206. package/src/rails/stripe/fixtures/meter-event-created.json +12 -0
  207. package/src/rails/stripe/objects.ts +4 -0
  208. package/src/rails/stripe/usage.ts +61 -0
  209. package/src/secret/registry.ts +3 -2
  210. package/src/usage/pass.ts +539 -0
  211. package/src/usage/reporter.ts +38 -0
  212. package/src/version.generated.ts +1 -1
  213. package/src/workflows/specs.ts +34 -0
  214. package/src/workflows/usage.ts +97 -0
  215. package/src/workflows/workerConfig.ts +9 -3
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,uGAAuG;AACvG,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,cAAc,GAAG,QAAQ,CAAC;AAE3F;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,cAAc,GAAG,QAAQ,CAAC;AAEtE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,kBAAkB,EAAyC,CAAC;AAEzG,6FAA6F;AAC7F,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,YAAY,CAAC;AAEjE,+FAA+F;AAC/F,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAM7D;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,CAAC;AAEhG;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,IAAI,EAAE,QAAQ,CAAC;IACf,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,WAAW,EAAE,yBAAyB,CAAC;IACvC,sEAAsE;IACtE,WAAW,EAAE,yBAAyB,CAAC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,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAGxG;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,EAAE,MAAM,CAAC,CAGhF,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAKzG;AAED,kEAAkE;AAClE,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,IAAI,CAKtF"}
@@ -266,6 +266,39 @@ function jsonPost(body) {
266
266
  function isEntitlementsBody(value) {
267
267
  return isRecord(value) && isArrayOf(value.entitlements, isEntitlementView);
268
268
  }
269
+ /** Whether a value is a map whose every value passes `guard`. */
270
+ function isMapOf(value, guard) {
271
+ return isRecord(value) && Object.values(value).every(guard);
272
+ }
273
+ /** A quota on the wire: a whole number from 0, or null. */
274
+ function isQuota(value) {
275
+ return value === null || typeof value === "number" && Number.isInteger(value) && value >= 0;
276
+ }
277
+ /** A feature on the wire. */
278
+ function isSwitch(value) {
279
+ return typeof value === "boolean";
280
+ }
281
+ /** Whether a value is the entitlements envelope from a Worker that resolves allowances. */
282
+ function isAllowancesBody(value) {
283
+ return isRecord(value) && isMapOf(value.quotas, isQuota) && isMapOf(value.features, isSwitch);
284
+ }
285
+ /**
286
+ * The caller's resolved allowances. The client-side reading of `quota(c, name)` and `feature(c, name)`, for a
287
+ * paywall screen — never the enforcement, which the server does.
288
+ *
289
+ * A Worker that predates declarations answers no allowances, and that is a failure here rather than an empty
290
+ * map: an empty map reads as *zero of everything*, and a screen would tell a paying customer they have none.
291
+ */
292
+ async function getAllowances(options) {
293
+ const result = await callPayments("/entitlements", {}, options, isAllowancesBody);
294
+ return result.ok ? {
295
+ ok: true,
296
+ value: {
297
+ quotas: result.value.quotas,
298
+ features: result.value.features
299
+ }
300
+ } : result;
301
+ }
269
302
  /** Whether a value is the purchase envelope both write routes' single-purchase form returns. */
270
303
  function isPurchaseBody(value) {
271
304
  return isRecord(value) && isPurchaseView(value.purchase) && isArrayOf(value.entitlements, isEntitlementView);
@@ -318,6 +351,31 @@ function restorePurchases(input, options) {
318
351
  function createCheckout(input, options) {
319
352
  return callPayments("/checkout", jsonPost(input), options, isCheckoutHandoff);
320
353
  }
354
+ /** Whether a value is a Paddle handoff specifically — the only shape the resume read answers with. */
355
+ function isPaddleResumeHandoff(value) {
356
+ return isCheckoutHandoff(value) && value.kind === "paddle";
357
+ }
358
+ /**
359
+ * What a page needs to open the transaction a Paddle payment link arrived for.
360
+ *
361
+ * **The transaction already exists, which is the whole difference from {@link createCheckout}.** Paddle
362
+ * created it before mailing the link — a past-due retry, a manually-collected invoice, a payment-method
363
+ * update — and appended `?_ptxn=<id>` to this project's Default payment link. So nothing is minted here;
364
+ * the id is read off the URL by `readPaddleLinkTransaction` in `./paddleLink` and this asks the server for
365
+ * the account and presentation that go with it.
366
+ *
367
+ * **Why a round trip at all, when the browser already holds the id.** Because `successUrl` is not the
368
+ * browser's to name. The handoff carries where a paying buyer is sent, and a page that could choose it
369
+ * could send a paying customer somewhere it controls — the same rule the minted path states on the field
370
+ * itself. The client token and the display mode travel with it for the same reason they do there: one
371
+ * source of truth for which Paddle account this project sells through.
372
+ *
373
+ * Sends no credentials of consequence and needs none: the route is unauthenticated, because the buyer
374
+ * following a dunning link days later is usually signed out.
375
+ */
376
+ function resumeCheckout(transactionId, options) {
377
+ return callPayments(`/checkout/resume?transaction=${encodeURIComponent(transactionId)}`, {}, options, isPaddleResumeHandoff);
378
+ }
321
379
  /**
322
380
  * Create a Billing Portal session for the caller's own store account.
323
381
  *
@@ -414,4 +472,4 @@ function returnedCheckoutSession(options) {
414
472
  return value === null || value === "" ? null : value;
415
473
  }
416
474
  //#endregion
417
- export { CHECKOUT_SESSION_PARAM, PAYMENTS_BASE_PATH, PAYMENTS_HOSTED_RAILS, PAYMENTS_NO_BROWSER, PAYMENTS_UNREACHABLE, PAYMENTS_UNREADABLE, STORE_SUBSCRIPTION_URLS, callPayments, createCheckout, createPortal, getEntitlements, isEntitlementView, isPurchaseView, openBillingPortal, openStoreSubscriptions, restorePurchases, returnedCheckoutSession, startCheckout, submitPurchase };
475
+ export { CHECKOUT_SESSION_PARAM, PAYMENTS_BASE_PATH, PAYMENTS_HOSTED_RAILS, PAYMENTS_NO_BROWSER, PAYMENTS_UNREACHABLE, PAYMENTS_UNREADABLE, STORE_SUBSCRIPTION_URLS, callPayments, createCheckout, createPortal, getAllowances, getEntitlements, isEntitlementView, isPurchaseView, openBillingPortal, openStoreSubscriptions, restorePurchases, resumeCheckout, returnedCheckoutSession, startCheckout, submitPurchase };
@@ -1,6 +1,6 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
- import { type EntitlementView, type PaddleCheckoutHandoff, type PaymentsClientOptions, type PaymentsClientRail, type PaymentsFailure, type PaymentsHostedRail, type PurchaseView } from "./api";
3
+ import { type AllowancesView, type EntitlementView, type PaddleCheckoutHandoff, type PaymentsClientOptions, type PaymentsClientRail, type PaymentsFailure, type PaymentsHostedRail, type PurchaseView } from "./api";
4
4
  import { type PaddleCheckoutOptions } from "./checkout";
5
5
  import { type PaddleJs, type PaddleOptions, type PaddlePriceQuery, type PaddleSetup, type PricePreview } from "./paddle";
6
6
  /** What {@link useEntitlement} gives a screen. */
@@ -32,6 +32,25 @@ export interface UseEntitlement {
32
32
  * plan instead of locking it must not inherit this choice; see {@link useSubscription}.
33
33
  */
34
34
  export declare function useEntitlement(key: string, options?: PaymentsClientOptions): UseEntitlement;
35
+ /** What {@link useAllowances} gives a paywall screen. */
36
+ export interface UseAllowances {
37
+ /** The caller's resolved quotas and features, or null until a read has landed. Never guessed. */
38
+ allowances: AllowancesView | null;
39
+ /** Whether a read is in flight. */
40
+ loading: boolean;
41
+ /** Why the last read could not be made, or null. `allowances` keeps its last answer while this is set. */
42
+ readFailure: PaymentsFailure | null;
43
+ /** Re-read. Call it after a purchase or an upgrade completes. */
44
+ refresh: () => void;
45
+ }
46
+ /**
47
+ * What the caller's holder may have — "3 of 10 seats", "SSO included" — for a screen to show.
48
+ *
49
+ * **Null until it knows, never zero.** A paywall that rendered `0 of 0` from a read still in flight would tell
50
+ * a paying customer they have nothing. And it is a UX affordance, never a boundary: the server's `quota()` and
51
+ * the kit's meters are what refuse.
52
+ */
53
+ export declare function useAllowances(options?: PaymentsClientOptions): UseAllowances;
35
54
  /** What {@link useSubscription} gives a subscription screen. */
36
55
  export interface UseSubscription {
37
56
  /** Every entitlement the caller holds, as the server resolved it. */
@@ -141,6 +160,49 @@ export interface UsePaddleCheckout {
141
160
  * overlay and clicked Buy again arrives with a new transaction, and that one must open.
142
161
  */
143
162
  export declare function usePaddleCheckout(handoff: PaddleCheckoutHandoff | null, options?: PaddleCheckoutOptions): UsePaddleCheckout;
163
+ /** What {@link usePaddleLink} gives the screen a Paddle payment link lands on. */
164
+ export interface UsePaddleLink {
165
+ /**
166
+ * The handoff to open, or null.
167
+ *
168
+ * Null covers three different facts and deliberately reads as one: there was no `_ptxn` in the URL, there
169
+ * was one and it was not a transaction id, or the server has not answered yet. A screen renders its
170
+ * ordinary state for all three, which is what it was already rendering before this hook existed.
171
+ */
172
+ handoff: PaddleCheckoutHandoff | null;
173
+ /** Whether the resume read is in flight. A screen with nothing to show need not read it. */
174
+ loading: boolean;
175
+ /** The refusal, or null. A rail that is off, or a mode that cannot resume. */
176
+ failure: PaymentsFailure | null;
177
+ }
178
+ /**
179
+ * Resume the checkout a Paddle payment link arrived for.
180
+ *
181
+ * **The inbound half of Paddle's *Default payment link*.** Paddle appends `?_ptxn=<transaction_id>` to it
182
+ * and expects this page to open a checkout for that transaction. Those are the links Paddle sends rather
183
+ * than ones this kit opened: a past-due dunning mail, a manually-collected invoice, the payment-method
184
+ * update link minted for a subscription. `useCheckout` cannot serve them — it mints a transaction, and here
185
+ * one already exists.
186
+ *
187
+ * **Pass the result to {@link usePaddleCheckout}, which opens it.** Nothing about opening is reimplemented
188
+ * here, and that is the point: the one-open-per-transaction guard, the `StrictMode` second pass, and the
189
+ * `PADDLE_NO_CONTAINER` refusal when an inline container is missing are all inherited by going through the
190
+ * same hook the minted path goes through.
191
+ *
192
+ * **In inline mode the page must already render the container.** Paddle finds it by class name when `open`
193
+ * is called, so a Default payment link pointing at a page that does not render one produces a refusal
194
+ * rather than a checkout — which makes the choice of landing page part of configuring this, not a detail.
195
+ * `docs/paddle.md` says so where an adopter sets the link.
196
+ *
197
+ * Reads `location.search` once, on mount. A link is a navigation, so there is no later arrival to watch for.
198
+ *
199
+ * **One read per transaction, remembered rather than assumed.** The same rule {@link usePaddleCheckout}
200
+ * states and for the same reason: `StrictMode` runs every effect, cleans it up and runs it again, and that
201
+ * is the mode `pithy ui add` scaffolds. Without the ref this asked the server twice on every mount — not
202
+ * harmful, since the route only echoes config, and still two requests where the file beside it had already
203
+ * solved the problem.
204
+ */
205
+ export declare function usePaddleLink(options?: PaymentsClientOptions): UsePaddleLink;
144
206
  /** What {@link usePurchase} gives the screen that submits receipts. */
145
207
  export interface UsePurchase {
146
208
  /** Submit one receipt for verification. */
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/client/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,eAAe,EAIpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAA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;AAED,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,8FAA8F;IAC9F,OAAO,EAAE,OAAO,CAAC;IACjB,qDAAqD;IACrD,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IAChC,iBAAiB;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,GAAG,IAAI,EACzB,KAAK,EAAE,gBAAgB,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,eAAe,CA+CjB"}
@@ -1,8 +1,9 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
- import { getEntitlements, openBillingPortal, openStoreSubscriptions, restorePurchases, startCheckout, submitPurchase } from "./api.js";
3
+ import { getAllowances, getEntitlements, openBillingPortal, openStoreSubscriptions, restorePurchases, resumeCheckout, startCheckout, submitPurchase } from "./api.js";
4
4
  import { loadPaddle, previewPrices, priceQueryKey } from "./paddle.js";
5
5
  import { openPaddleCheckout } from "./checkout.js";
6
+ import { readPaddleLinkTransaction } from "./paddleLink.js";
6
7
  import { useCallback, useEffect, useRef, useState } from "react";
7
8
  //#region src/client/hooks.ts
8
9
  /**
@@ -102,6 +103,44 @@ function useEntitlement(key, options) {
102
103
  };
103
104
  }
104
105
  /**
106
+ * What the caller's holder may have — "3 of 10 seats", "SSO included" — for a screen to show.
107
+ *
108
+ * **Null until it knows, never zero.** A paywall that rendered `0 of 0` from a read still in flight would tell
109
+ * a paying customer they have nothing. And it is a UX affordance, never a boundary: the server's `quota()` and
110
+ * the kit's meters are what refuse.
111
+ */
112
+ function useAllowances(options) {
113
+ const [allowances, setAllowances] = useState(null);
114
+ const [loading, setLoading] = useState(true);
115
+ const [readFailure, setReadFailure] = useState(null);
116
+ const latest = useLatest(options);
117
+ const live = useLive();
118
+ const basePath = options?.basePath;
119
+ const refresh = useCallback(() => {
120
+ setLoading(true);
121
+ getAllowances({
122
+ ...latest.current,
123
+ basePath
124
+ }).then((result) => {
125
+ if (!live.current) return;
126
+ if (result.ok) setAllowances(result.value);
127
+ setReadFailure(result.ok ? null : result.failure);
128
+ setLoading(false);
129
+ });
130
+ }, [
131
+ basePath,
132
+ latest,
133
+ live
134
+ ]);
135
+ useEffect(refresh, [refresh]);
136
+ return {
137
+ allowances,
138
+ loading,
139
+ readFailure,
140
+ refresh
141
+ };
142
+ }
143
+ /**
105
144
  * The caller's standing entitlements, and the one action a subscriber needs.
106
145
  *
107
146
  * Managing a subscription is the store's job, not Pithy's — Stripe's Billing Portal owns cancellation,
@@ -247,6 +286,61 @@ function usePaddleCheckout(handoff, options) {
247
286
  };
248
287
  }
249
288
  /**
289
+ * Resume the checkout a Paddle payment link arrived for.
290
+ *
291
+ * **The inbound half of Paddle's *Default payment link*.** Paddle appends `?_ptxn=<transaction_id>` to it
292
+ * and expects this page to open a checkout for that transaction. Those are the links Paddle sends rather
293
+ * than ones this kit opened: a past-due dunning mail, a manually-collected invoice, the payment-method
294
+ * update link minted for a subscription. `useCheckout` cannot serve them — it mints a transaction, and here
295
+ * one already exists.
296
+ *
297
+ * **Pass the result to {@link usePaddleCheckout}, which opens it.** Nothing about opening is reimplemented
298
+ * here, and that is the point: the one-open-per-transaction guard, the `StrictMode` second pass, and the
299
+ * `PADDLE_NO_CONTAINER` refusal when an inline container is missing are all inherited by going through the
300
+ * same hook the minted path goes through.
301
+ *
302
+ * **In inline mode the page must already render the container.** Paddle finds it by class name when `open`
303
+ * is called, so a Default payment link pointing at a page that does not render one produces a refusal
304
+ * rather than a checkout — which makes the choice of landing page part of configuring this, not a detail.
305
+ * `docs/paddle.md` says so where an adopter sets the link.
306
+ *
307
+ * Reads `location.search` once, on mount. A link is a navigation, so there is no later arrival to watch for.
308
+ *
309
+ * **One read per transaction, remembered rather than assumed.** The same rule {@link usePaddleCheckout}
310
+ * states and for the same reason: `StrictMode` runs every effect, cleans it up and runs it again, and that
311
+ * is the mode `pithy ui add` scaffolds. Without the ref this asked the server twice on every mount — not
312
+ * harmful, since the route only echoes config, and still two requests where the file beside it had already
313
+ * solved the problem.
314
+ */
315
+ function usePaddleLink(options) {
316
+ const [handoff, setHandoff] = useState(null);
317
+ const [loading, setLoading] = useState(false);
318
+ const [failure, setFailure] = useState(null);
319
+ const latest = useLatest(options);
320
+ const live = useLive();
321
+ /** The transaction this hook has already asked about, so a second effect pass asks nothing. */
322
+ const asked = useRef(null);
323
+ useEffect(() => {
324
+ const search = globalThis.location?.search;
325
+ const transactionId = search === void 0 ? null : readPaddleLinkTransaction(search);
326
+ if (transactionId === null) return;
327
+ if (asked.current === transactionId) return;
328
+ asked.current = transactionId;
329
+ setLoading(true);
330
+ resumeCheckout(transactionId, latest.current).then((outcome) => {
331
+ if (!live.current) return;
332
+ setLoading(false);
333
+ if (outcome.ok) setHandoff(outcome.value);
334
+ else setFailure(outcome.failure);
335
+ });
336
+ }, [latest, live]);
337
+ return {
338
+ handoff,
339
+ loading,
340
+ failure
341
+ };
342
+ }
343
+ /**
250
344
  * Submitting receipts — the path that exists so a buyer sees their entitlement now rather than when the
251
345
  * webhook lands.
252
346
  *
@@ -427,4 +521,4 @@ function usePricePreview(setup, query, options) {
427
521
  };
428
522
  }
429
523
  //#endregion
430
- export { useCheckout, useEntitlement, usePaddle, usePaddleCheckout, usePricePreview, usePurchase, useSubscription };
524
+ export { useAllowances, useCheckout, useEntitlement, usePaddle, usePaddleCheckout, usePaddleLink, usePricePreview, usePurchase, useSubscription };
@@ -0,0 +1,31 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * The query parameter Paddle appends to a seller's **Default payment link**.
5
+ *
6
+ * Named once, because Paddle does not document it as stable and a literal at two call sites is how one of
7
+ * them survives a rename. This is the thing to grep for if it ever moves.
8
+ */
9
+ export declare const PADDLE_LINK_PARAM = "_ptxn";
10
+ /**
11
+ * The transaction Paddle put in this page's URL, or null.
12
+ *
13
+ * **Paddle's own links are the ones that arrive here**, not any this kit opened: a past-due dunning mail,
14
+ * a manually-collected invoice's pay link, the payment-method-update link Paddle mints for a subscription.
15
+ * Each is the seller's *Default payment link* with `?_ptxn=<transaction_id>` on the end, and the contract
16
+ * is that the page it lands on opens a checkout for that transaction.
17
+ *
18
+ * **Null is the ordinary answer and is not a failure.** Every page this is called on is loaded without a
19
+ * `_ptxn` almost every time, so an absent parameter reads as "nothing to resume" and a screen renders
20
+ * exactly as it did before this existed. A malformed one reads the same way, which is the second half of
21
+ * the point: the value comes from outside, from a URL, from somebody who may not be signed in, and it is
22
+ * about to be sent to a route and then handed to `Paddle.Checkout.open`. The only thing that makes it safe
23
+ * to pass on is that it is shaped like a transaction id — so anything else is null rather than an error
24
+ * worth telling a buyer about, because a buyer cannot act on it and an attacker already knows.
25
+ *
26
+ * The shape check is {@link isPaddleTransactionId}, which is the rail's own and is shared rather than
27
+ * copied. Takes a search string rather than reading `location` itself, so this is a pure function and the
28
+ * hook that owns the browser is the only thing that needs one.
29
+ */
30
+ export declare function readPaddleLinkTransaction(search: string): string | null;
31
+ //# sourceMappingURL=paddleLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paddleLink.d.ts","sourceRoot":"","sources":["../../src/client/paddleLink.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOvE"}
@@ -0,0 +1,37 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { isPaddleTransactionId } from "../data/paddleIds.js";
4
+ //#region src/client/paddleLink.ts
5
+ /**
6
+ * The query parameter Paddle appends to a seller's **Default payment link**.
7
+ *
8
+ * Named once, because Paddle does not document it as stable and a literal at two call sites is how one of
9
+ * them survives a rename. This is the thing to grep for if it ever moves.
10
+ */
11
+ const PADDLE_LINK_PARAM = "_ptxn";
12
+ /**
13
+ * The transaction Paddle put in this page's URL, or null.
14
+ *
15
+ * **Paddle's own links are the ones that arrive here**, not any this kit opened: a past-due dunning mail,
16
+ * a manually-collected invoice's pay link, the payment-method-update link Paddle mints for a subscription.
17
+ * Each is the seller's *Default payment link* with `?_ptxn=<transaction_id>` on the end, and the contract
18
+ * is that the page it lands on opens a checkout for that transaction.
19
+ *
20
+ * **Null is the ordinary answer and is not a failure.** Every page this is called on is loaded without a
21
+ * `_ptxn` almost every time, so an absent parameter reads as "nothing to resume" and a screen renders
22
+ * exactly as it did before this existed. A malformed one reads the same way, which is the second half of
23
+ * the point: the value comes from outside, from a URL, from somebody who may not be signed in, and it is
24
+ * about to be sent to a route and then handed to `Paddle.Checkout.open`. The only thing that makes it safe
25
+ * to pass on is that it is shaped like a transaction id — so anything else is null rather than an error
26
+ * worth telling a buyer about, because a buyer cannot act on it and an attacker already knows.
27
+ *
28
+ * The shape check is {@link isPaddleTransactionId}, which is the rail's own and is shared rather than
29
+ * copied. Takes a search string rather than reading `location` itself, so this is a pure function and the
30
+ * hook that owns the browser is the only thing that needs one.
31
+ */
32
+ function readPaddleLinkTransaction(search) {
33
+ const value = new URLSearchParams(search).get(PADDLE_LINK_PARAM);
34
+ return value !== null && isPaddleTransactionId(value) ? value : null;
35
+ }
36
+ //#endregion
37
+ export { PADDLE_LINK_PARAM, readPaddleLinkTransaction };
@@ -38,6 +38,22 @@ export type PaymentsClientProduct = {
38
38
  paddle: string | null;
39
39
  };
40
40
  };
41
+ /** Numbered allowances and switches, as a browser reads them. */
42
+ export type PaymentsClientAllowances = {
43
+ /** Quotas by name: a whole number, or null for unlimited. */
44
+ quotas: Record<string, number | null>;
45
+ /** Features by name. */
46
+ features: Record<string, boolean>;
47
+ };
48
+ /** One declared entitlement key, browser-safe: what it is called and what it buys. */
49
+ export type PaymentsClientEntitlement = {
50
+ /** The tier's display name — `Growth`. Not translated: it is a product name. */
51
+ name: string;
52
+ /** Quotas by name: a whole number, or null for unlimited. */
53
+ quotas: Record<string, number | null>;
54
+ /** Features by name. */
55
+ features: Record<string, boolean>;
56
+ };
41
57
  /**
42
58
  * What a browser may know about this project's payments — the shape of `virtual:pithy/payments`.
43
59
  *
@@ -126,5 +142,18 @@ export type PaymentsClientProjection = {
126
142
  * purchase fulfills beyond its entitlements, stay server-side.
127
143
  */
128
144
  products: PaymentsClientProduct[];
145
+ /**
146
+ * What each entitlement key buys, keyed by the key — its display name, its quotas (a whole number,
147
+ * or null for unlimited) and its features — so a paywall can lay tiers side by side. What the
148
+ * caller's own holder resolves to is `GET {basePath}/entitlements`. A UX affordance, never a
149
+ * security boundary: the server enforces every number here. The ceilings an operator's override is
150
+ * bounded by stay server-side.
151
+ */
152
+ entitlements: {
153
+ /** One declared key, by the key. */
154
+ [key: string]: PaymentsClientEntitlement;
155
+ };
156
+ /** What a caller holding no key gets — the free floor — or null when none is declared. */
157
+ defaults: PaymentsClientAllowances | null;
129
158
  };
130
159
  //# sourceMappingURL=projection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/client/projection.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,cAAc,CAAC;IACvD,kFAAkF;IAClF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,IAAI,EAAE;QACJ,2BAA2B;QAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,oCAAoC;QACpC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,2BAA2B;QAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,wBAAwB,GAChC;IACE;;;;OAIG;IACH,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,0EAA0E;IAC1E,OAAO,EAAE,IAAI,CAAC;IACd,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,KAAK,EAAE;QACL,mEAAmE;QACnE,KAAK,EAAE,OAAO,CAAC;QACf,oEAAoE;QACpE,MAAM,EAAE,OAAO,CAAC;QAChB,qCAAqC;QACrC,MAAM,EAAE,OAAO,CAAC;QAChB,4CAA4C;QAC5C,YAAY,EAAE,OAAO,CAAC;QACtB,qCAAqC;QACrC,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;IACF;;;;OAIG;IACH,MAAM,EAAE;QACN,+DAA+D;QAC/D,WAAW,EAAE,MAAM,CAAC;QACpB,iDAAiD;QACjD,WAAW,EAAE,SAAS,GAAG,YAAY,CAAC;QACtC;;;;;;;WAOG;QACH,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;KAC3C,GAAG,IAAI,CAAC;IACT,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,EAAE,qBAAqB,EAAE,CAAC;CACnC,CAAC"}
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/client/projection.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,cAAc,CAAC;IACvD,kFAAkF;IAClF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB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C;KACjB,CAAC;IACF;;;;OAIG;IACH,MAAM,EAAE;QACN,+DAA+D;QAC/D,WAAW,EAAE,MAAM,CAAC;QACpB,iDAAiD;QACjD,WAAW,EAAE,SAAS,GAAG,YAAY,CAAC;QACtC;;;;;;;WAOG;QACH,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;KAC3C,GAAG,IAAI,CAAC;IACT,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAClC;;;;;;OAMG;IACH,YAAY,EAAE;QACZ,oCAAoC;QACpC,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAAC;KAC1C,CAAC;IACF,0FAA0F;IAC1F,QAAQ,EAAE,wBAAwB,GAAG,IAAI,CAAC;CAC3C,CAAC"}
@@ -0,0 +1,71 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ /**
5
+ * A quota or feature name — `emails`, `seats`, `auditExport`. camelCase or snake_case, starting with a
6
+ * lowercase letter, because it is an identifier code names and never copy a screen renders.
7
+ */
8
+ export declare const AllowanceName: z.ZodString;
9
+ export type AllowanceName = z.infer<typeof AllowanceName>;
10
+ /**
11
+ * One quota's value: a whole number of things, or `null` for unlimited. Never a float, never negative,
12
+ * never a string — a number that costs money to serve is not something to coerce.
13
+ */
14
+ export declare const QuotaValue: z.ZodNullable<z.ZodNumber>;
15
+ export type QuotaValue = z.infer<typeof QuotaValue>;
16
+ /** A ceiling an operator's override may not pass. A whole number, and never unlimited — that is not a ceiling. */
17
+ export declare const OverrideCeiling: z.ZodNumber;
18
+ export type OverrideCeiling = z.infer<typeof OverrideCeiling>;
19
+ /** A quota map: name → whole number or unlimited. */
20
+ export declare const QuotaMap: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodNumber>>;
21
+ export type QuotaMap = z.infer<typeof QuotaMap>;
22
+ /** A feature map: name → on or off. */
23
+ export declare const FeatureMap: z.ZodRecord<z.ZodString, z.ZodBoolean>;
24
+ export type FeatureMap = z.infer<typeof FeatureMap>;
25
+ export declare const PaymentsEntitlementDeclaration: z.ZodObject<{
26
+ name: z.ZodString;
27
+ quotas: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodNumber>>>;
28
+ features: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
29
+ overrideMax: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
30
+ }, z.core.$strip>;
31
+ export type PaymentsEntitlementDeclaration = z.output<typeof PaymentsEntitlementDeclaration>;
32
+ export type PaymentsEntitlementDeclarationInput = z.input<typeof PaymentsEntitlementDeclaration>;
33
+ export declare const PaymentsAllowanceDefaults: z.ZodObject<{
34
+ quotas: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodNumber>>>;
35
+ features: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
36
+ }, z.core.$strip>;
37
+ export type PaymentsAllowanceDefaults = z.output<typeof PaymentsAllowanceDefaults>;
38
+ /** The slice of a parsed config the derivations below read. Structural, so a test needs no full catalog. */
39
+ export interface AllowanceDeclarations {
40
+ /** Every declared entitlement key and what it buys. */
41
+ entitlements: Readonly<Record<string, PaymentsEntitlementDeclaration>>;
42
+ /** The free floor, when declared. */
43
+ defaults?: PaymentsAllowanceDefaults | undefined;
44
+ }
45
+ /**
46
+ * Every quota name this project declares, on any key or on the floor, sorted.
47
+ *
48
+ * Derived, never written down, the way the set of grantable keys is derived from the products — a second
49
+ * list of names would be a list that disagrees with the declarations the first time one is added.
50
+ */
51
+ export declare function declaredQuotaNames(declarations: AllowanceDeclarations): string[];
52
+ /** Every feature name this project declares, on any key or on the floor, sorted. */
53
+ export declare function declaredFeatureNames(declarations: AllowanceDeclarations): string[];
54
+ /**
55
+ * The problems with a set of declarations, as sentences, each with the path it belongs at.
56
+ *
57
+ * Separate from the schema so `PaymentsConfig`'s check can report every one at once, beside the catalog
58
+ * problems it already reports, and so each rule is testable on its own.
59
+ */
60
+ export interface DeclarationProblem {
61
+ /** Where in the config the problem is. */
62
+ path: (string | number)[];
63
+ /** The sentence. Names the key and the name. */
64
+ message: string;
65
+ }
66
+ /**
67
+ * Check the rules a schema cannot state field by field: a name that is a quota on one key and a feature on
68
+ * another, and an `overrideMax` that names an undeclared quota or sits below the quota it bounds.
69
+ */
70
+ export declare function declarationProblems(declarations: AllowanceDeclarations): DeclarationProblem[];
71
+ //# sourceMappingURL=allowances.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowances.d.ts","sourceRoot":"","sources":["../../src/config/allowances.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+BxB;;;GAGG;AACH,eAAO,MAAM,aAAa,aAUvB,CAAC;AACJ,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,UAAU,4BAKsE,CAAC;AAC9F,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD,kHAAkH;AAClH,eAAO,MAAM,eAAe,aAMzB,CAAC;AACJ,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D,qDAAqD;AACrD,eAAO,MAAM,QAAQ,sDAEoE,CAAC;AAC1F,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD,uCAAuC;AACvC,eAAO,MAAM,UAAU,wCAE+E,CAAC;AACvG,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD,eAAO,MAAM,8BAA8B;;;;;iBAwBxC,CAAC;AACJ,MAAM,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