@pithy-sh/payments 0.3.6 → 0.3.7

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 (42) hide show
  1. package/dist/capability.d.ts +11 -3
  2. package/dist/capability.d.ts.map +1 -1
  3. package/dist/capability.js +33 -8
  4. package/dist/grants/apply.d.ts +11 -5
  5. package/dist/grants/apply.d.ts.map +1 -1
  6. package/dist/grants/apply.js +9 -6
  7. package/dist/grants/ledgerSeam.d.ts +34 -14
  8. package/dist/grants/ledgerSeam.d.ts.map +1 -1
  9. package/dist/grants/ledgerSeam.js +8 -16
  10. package/dist/http/routes.d.ts +8 -0
  11. package/dist/http/routes.d.ts.map +1 -1
  12. package/dist/http/routes.js +9 -8
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/peer.d.ts +78 -0
  16. package/dist/peer.d.ts.map +1 -0
  17. package/dist/peer.js +27 -0
  18. package/dist/version.generated.d.ts +1 -1
  19. package/dist/version.generated.js +1 -1
  20. package/dist/workflows/hostPeers.d.ts +37 -0
  21. package/dist/workflows/hostPeers.d.ts.map +1 -0
  22. package/dist/workflows/hostPeers.js +17 -0
  23. package/dist/workflows/paddleSweep.d.ts +3 -0
  24. package/dist/workflows/paddleSweep.d.ts.map +1 -1
  25. package/dist/workflows/paddleSweep.js +2 -0
  26. package/dist/workflows/reconcile.d.ts +6 -0
  27. package/dist/workflows/reconcile.d.ts.map +1 -1
  28. package/dist/workflows/reconcile.js +1 -0
  29. package/dist/workflows/worker.d.ts.map +1 -1
  30. package/dist/workflows/worker.js +3 -0
  31. package/package.json +2 -2
  32. package/src/capability.ts +60 -16
  33. package/src/grants/apply.ts +14 -8
  34. package/src/grants/ledgerSeam.ts +43 -33
  35. package/src/http/routes.ts +17 -8
  36. package/src/index.ts +2 -1
  37. package/src/peer.ts +29 -0
  38. package/src/version.generated.ts +1 -1
  39. package/src/workflows/hostPeers.ts +41 -0
  40. package/src/workflows/paddleSweep.ts +9 -2
  41. package/src/workflows/reconcile.ts +12 -1
  42. package/src/workflows/worker.ts +5 -0
@@ -5,6 +5,7 @@ import type { DatabaseSpecMap } from "@pithy-sh/core/src/data/databases";
5
5
  import type { KvNamespaceSpecMap } from "@pithy-sh/core/src/kv/namespaces";
6
6
  import { PaymentsConfig, type PaymentsConfigInput } from "./config/config";
7
7
  import type { PaymentsSubjectResolver } from "./entitlement/subjectSeam";
8
+ import { type PaymentsPeer } from "./peer";
8
9
  import { paymentsWorkflows } from "./workflows/specs";
9
10
  /**
10
11
  * Where payments' migrations sort in the app database. Unique per database; the registry composes keys
@@ -43,6 +44,12 @@ export type PaymentsOptions = PaymentsConfigInput & {
43
44
  export interface PaymentsCapability extends Capability<DatabaseSpecMap, KvNamespaceSpecMap, "payments", typeof paymentsWorkflows> {
44
45
  /** The resolved catalog. */
45
46
  paymentsConfig: PaymentsConfig;
47
+ /**
48
+ * What a capability composed beside this one reads purchases through — `support`, showing an operator what a
49
+ * sender bought. Found in its `compose` hook, so it never imports this package and a project without
50
+ * payments bundles it (#645). See `peer.ts`.
51
+ */
52
+ paymentsPeer: PaymentsPeer;
46
53
  }
47
54
  /**
48
55
  * Three rails — Apple, Google, Stripe — projecting onto one cross-rail entitlement, in the adopter's own
@@ -60,9 +67,10 @@ export interface PaymentsCapability extends Capability<DatabaseSpecMap, KvNamesp
60
67
  * registry, so a project composing payments without `@pithy-sh/secrets` must fail at assembly rather
61
68
  * than at the first receipt. Auth is *not* listed — it is a seam: under `billingSubject: "user"` a purchase
62
69
  * scopes to the authenticated caller, so with no auth capability composed every route denies, which is the
63
- * right failure and needs no dependency edge. `@pithy-sh/ledger` is likewise a seam, reached through one
64
- * guarded dynamic import and only for products whose catalog entry declares `grants`. Both belong in the
65
- * manifest's `optionalCapabilities`.
70
+ * right failure and needs no dependency edge. `@pithy-sh/ledger` is likewise a seam: `compose` finds it among
71
+ * the composed capabilities and hands its `ledgerPeer` to the routes, and nothing in this package imports it
72
+ * (#645). Only a product whose catalog entry declares `grants` ever calls it. Both belong in the manifest's
73
+ * `optionalCapabilities`.
66
74
  *
67
75
  * Under `billingSubject: "organization"` the holder is not the caller and cannot be derived from them, so
68
76
  * the adopter supplies `resolveSubject` and a composition without one is refused outright — see
@@ -1 +1 @@
1
- {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI3E,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,2BAA2B,CAAC;AAU9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAK7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG;IAClD;;;;OAIG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C,CAAC;AAsMF,6FAA6F;AAC7F,MAAM,WAAW,kBACf,SAAQ,UAAU,CAAC,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,iBAAiB,CAAC;IAC7F,4BAA4B;IAC5B,cAAc,EAAE,cAAc,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CAsGrE;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,kBAAkB,CAE7F"}
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI3E,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,2BAA2B,CAAC;AAO9F,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,QAAQ,CAAC;AAKzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAK7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG;IAClD;;;;OAIG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C,CAAC;AAiOF,6FAA6F;AAC7F,MAAM,WAAW,kBACf,SAAQ,UAAU,CAAC,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,iBAAiB,CAAC;IAC7F,4BAA4B;IAC5B,cAAc,EAAE,cAAc,CAAC;IAC/B;;;;OAIG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CA8GrE;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,kBAAkB,CAE7F"}
@@ -10,6 +10,7 @@ import { paymentsWorkflows } from "./workflows/specs.js";
10
10
  import { paymentsAdminRoutes } from "./http/scopes.js";
11
11
  import { registerPaymentsRoutes } from "./http/routes.js";
12
12
  import { payments_0001_purchases } from "./migrations/0001_purchases.js";
13
+ import { paymentsPeer } from "./peer.js";
13
14
  import { paymentsInapplicableSecrets, paymentsSecretBranches } from "./secret/branches.js";
14
15
  import { paymentsExampleSeed } from "./seeds/example.js";
15
16
  import { PACKAGE_NAME, PACKAGE_VERSION } from "./version.generated.js";
@@ -29,6 +30,16 @@ const PAYMENTS_DATABASE_NAME = "app";
29
30
  function isLedgerPeer(capability) {
30
31
  return capability.name === "ledger" && "ledgerConfig" in capability;
31
32
  }
33
+ /** The ledger's peer surface among the composed capabilities, or undefined when no ledger is composed. */
34
+ function composedLedger(capabilities) {
35
+ return capabilities.find(isLedgerPeer)?.ledgerPeer;
36
+ }
37
+ /** Products named for a sentence: `product "coins_100"`, or `products "a" and "b"`. */
38
+ function products(list) {
39
+ const ids = list.map((entry) => `"${entry.id}"`);
40
+ if (ids.length === 1) return `product ${ids[0]}`;
41
+ return `products ${ids.slice(0, -1).join(", ")} and ${ids[ids.length - 1]}`;
42
+ }
32
43
  /**
33
44
  * Validate every `grants.currency` against the composed ledger, at assembly.
34
45
  *
@@ -54,10 +65,15 @@ function checkLedgerGrants({ capabilities }, config) {
54
65
  });
55
66
  const peer = capabilities.find(isLedgerPeer);
56
67
  if (!peer) throw new ValidationError({
57
- message: "This catalog credits a balance, and no ledger is composed.",
58
- action: "Add `ledger(...)` to this Worker's capabilities, or drop the `grants` clause from the product.",
68
+ message: `No ledger is composed in this Worker, and ${products(granting)} ${granting.length === 1 ? "credits" : "credit"} a balance through one.`,
69
+ action: `Compose \`ledger(...)\` in this Worker, or turn crediting off by removing the \`grants.ledger\` clause from ${products(granting)}.`,
59
70
  detail: `Products with a \`grants.ledger\` clause: ${granting.map((entry) => entry.id).join(", ")}. Crediting needs @pithy-sh/ledger composed in the same Worker.`
60
71
  });
72
+ if (typeof peer.ledgerPeer?.openLedger !== "function") throw new ValidationError({
73
+ message: "The composed ledger is too old for payments to credit a balance.",
74
+ action: "Upgrade @pithy-sh/ledger to the version this @pithy-sh/payments peers.",
75
+ detail: `The composed ledger capability carries no \`ledgerPeer\`. Products with a \`grants.ledger\` clause: ${granting.map((entry) => entry.id).join(", ")}.`
76
+ });
61
77
  const declared = new Set(peer.ledgerConfig.currencies.map((currency) => currency.code));
62
78
  const unknown = granting.filter((entry) => !declared.has(entry.currency));
63
79
  if (unknown.length === 0) return;
@@ -185,9 +201,10 @@ function clientProjection(config, environment) {
185
201
  * registry, so a project composing payments without `@pithy-sh/secrets` must fail at assembly rather
186
202
  * than at the first receipt. Auth is *not* listed — it is a seam: under `billingSubject: "user"` a purchase
187
203
  * scopes to the authenticated caller, so with no auth capability composed every route denies, which is the
188
- * right failure and needs no dependency edge. `@pithy-sh/ledger` is likewise a seam, reached through one
189
- * guarded dynamic import and only for products whose catalog entry declares `grants`. Both belong in the
190
- * manifest's `optionalCapabilities`.
204
+ * right failure and needs no dependency edge. `@pithy-sh/ledger` is likewise a seam: `compose` finds it among
205
+ * the composed capabilities and hands its `ledgerPeer` to the routes, and nothing in this package imports it
206
+ * (#645). Only a product whose catalog entry declares `grants` ever calls it. Both belong in the manifest's
207
+ * `optionalCapabilities`.
191
208
  *
192
209
  * Under `billingSubject: "organization"` the holder is not the caller and cannot be derived from them, so
193
210
  * the adopter supplies `resolveSubject` and a composition without one is refused outright — see
@@ -201,6 +218,7 @@ function payments(options) {
201
218
  billingSubject: resolved.billingSubject,
202
219
  ...resolveSubject ? { resolveSubject } : {}
203
220
  };
221
+ const peers = { ledger: void 0 };
204
222
  const migrations = { "0001_purchases": payments_0001_purchases };
205
223
  const requiredBindings = [{
206
224
  type: "d1",
@@ -216,7 +234,10 @@ function payments(options) {
216
234
  secretBranches: paymentsSecretBranches(resolved.rails),
217
235
  inapplicableSecrets: paymentsInapplicableSecrets(resolved.rails),
218
236
  workflows: paymentsWorkflows,
219
- compose: (context) => checkLedgerGrants(context, resolved),
237
+ compose: (context) => {
238
+ checkLedgerGrants(context, resolved);
239
+ peers.ledger = composedLedger(context.capabilities);
240
+ },
220
241
  boot: () => requireImplementedSubject(resolveSubject),
221
242
  client: ({ environment }) => clientProjection(resolved, environment),
222
243
  requiredBindings,
@@ -232,11 +253,15 @@ function payments(options) {
232
253
  manifestConfig: paymentsManifestConfig(resolved.billingSubject),
233
254
  routes: registerPaymentsRoutes({
234
255
  config: resolved,
235
- subject
256
+ subject,
257
+ ledger: () => peers.ledger
236
258
  }),
237
259
  seeds: [paymentsExampleSeed]
238
260
  });
239
- return Object.assign(capability, { paymentsConfig: resolved });
261
+ return Object.assign(capability, {
262
+ paymentsConfig: resolved,
263
+ paymentsPeer
264
+ });
240
265
  }
241
266
  /** Whether a capability is the payments capability — carries its resolved catalog. */
242
267
  function isPaymentsCapability(capability) {
@@ -6,7 +6,7 @@ import type { PaymentsConfig, PaymentsLedgerGrant } from "../config/config";
6
6
  import type { PaymentsPurchase } from "../data/purchase";
7
7
  import type { PurchaseProjection } from "../projection/writer";
8
8
  import { type ClawbackOutcome } from "./clawback";
9
- import { type PaymentsLedger } from "./ledgerSeam";
9
+ import { type PaymentsLedger, type PaymentsLedgerPeer } from "./ledgerSeam";
10
10
  /** One balance credit a purchase produced, with the ref that makes it happen exactly once. */
11
11
  export interface AppliedGrant {
12
12
  /** The ledger currency credited. */
@@ -32,8 +32,14 @@ export interface GrantOptions {
32
32
  export interface FulfillPurchaseOptions extends GrantOptions {
33
33
  /** The audit seam. Defaults to core's no-op, so a caller with no recorder composed needs no branch. */
34
34
  emit?: AuditEmit;
35
- /** An already-open ledger. Absent in production — the guarded import supplies one only when it is needed. */
35
+ /** An already-open ledger. Absent in production, where {@link ledgerPeer} opens one only when it is needed. */
36
36
  ledger?: PaymentsLedger;
37
+ /**
38
+ * The ledger the composition handed over — `ledger()`'s `ledgerPeer`, found by `payments()`'s `compose` hook,
39
+ * or handed to the reconcile host by its generated entry. Undefined when no ledger is composed, which is
40
+ * only a fault for a product that credits one.
41
+ */
42
+ ledgerPeer?: PaymentsLedgerPeer;
37
43
  /** The clock the ledger stamps its rows with. Injected so a fulfillment is deterministic under test. */
38
44
  now?: () => number;
39
45
  }
@@ -64,9 +70,9 @@ export declare function applyGrants(ledger: PaymentsLedger, projection: Purchase
64
70
  * Fulfill one projected purchase in both directions: credit what it bought, and reverse what a refund took
65
71
  * back where the catalog asks for it.
66
72
  *
67
- * The ledger is opened **lazily, and only when the catalog names a currency**. That laziness is the whole
68
- * reason the optional peer stays optional: a project selling nothing but features never resolves the import,
69
- * so it neither installs `@pithy-sh/ledger` nor carries it in a Worker bundle.
73
+ * The ledger is opened **only when the catalog names a currency**, and only from what the composition handed
74
+ * over. A project selling nothing but features never composes one, never installs `@pithy-sh/ledger`, and —
75
+ * because nothing here names the package — never carries a specifier a bundler would have to resolve (#645).
70
76
  *
71
77
  * A refused clawback is recorded here rather than thrown. It is the one fulfillment fact no other table
72
78
  * holds — a successful credit or debit is already a ledger row, keyed by a ref that names the purchase — so
@@ -1 +1 @@
1
- {"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/grants/apply.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,mCAAmC,CAAC;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,YAAY,CAAC;AAClE,OAAO,EAAuC,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAwDxF,8FAA8F;AAC9F,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,8GAA8G;AAC9G,MAAM,WAAW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M,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAEzG;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAC,GAAG,OAAO,CAG3F;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,kBAAkB,EAC9B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,EAAE,CAAC,CAezB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,UAAU,EACd,UAAU,EAAE,kBAAkB,EAC9B,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAoC5B"}
@@ -8,8 +8,8 @@ import { noopEmit } from "@pithy-sh/core/src/audit/recorder";
8
8
  /**
9
9
  * Fulfillment: turning a projected purchase into the balance a `grants` clause promised.
10
10
  *
11
- * This is deliberately **not** in the projection writer. The writer stays pure D1 so its tests resolve no
12
- * optional package, and the credit is a separate step its caller runs on what it returned — a route, or any
11
+ * This is deliberately **not** in the projection writer. The writer stays pure D1 so its tests need no ledger,
12
+ * and the credit is a separate step its caller runs on what it returned — a route, or any
13
13
  * other caller holding a projection. Nothing is lost by the separation, because the credit's idempotency has
14
14
  * never rested on call ordering: it rests on the ledger's `UNIQUE (ref)`.
15
15
  *
@@ -102,9 +102,9 @@ async function applyGrants(ledger, projection, options) {
102
102
  * Fulfill one projected purchase in both directions: credit what it bought, and reverse what a refund took
103
103
  * back where the catalog asks for it.
104
104
  *
105
- * The ledger is opened **lazily, and only when the catalog names a currency**. That laziness is the whole
106
- * reason the optional peer stays optional: a project selling nothing but features never resolves the import,
107
- * so it neither installs `@pithy-sh/ledger` nor carries it in a Worker bundle.
105
+ * The ledger is opened **only when the catalog names a currency**, and only from what the composition handed
106
+ * over. A project selling nothing but features never composes one, never installs `@pithy-sh/ledger`, and —
107
+ * because nothing here names the package — never carries a specifier a bundler would have to resolve (#645).
108
108
  *
109
109
  * A refused clawback is recorded here rather than thrown. It is the one fulfillment fact no other table
110
110
  * holds — a successful credit or debit is already a ledger row, keyed by a ref that names the purchase — so
@@ -116,7 +116,10 @@ async function fulfillPurchase(d1, projection, options) {
116
116
  granted: [],
117
117
  clawedBack: []
118
118
  };
119
- const ledger = options.ledger ?? await openPaymentsLedger(d1, { now: options.now });
119
+ const ledger = options.ledger ?? openPaymentsLedger(d1, {
120
+ peer: options.ledgerPeer,
121
+ now: options.now
122
+ });
120
123
  const granted = await applyGrants(ledger, projection, options);
121
124
  const clawedBack = await clawbackGrants(ledger, projection, options);
122
125
  const emit = options.emit ?? noopEmit;
@@ -3,19 +3,30 @@
3
3
  import type { D1Database } from "@cloudflare/workers-types";
4
4
  import { type PaymentsSubject } from "../data/subject";
5
5
  /**
6
- * The single point of contact between `@pithy-sh/payments` and `@pithy-sh/ledger`.
6
+ * The single point of contact between `@pithy-sh/payments` and `@pithy-sh/ledger` — and it imports nothing
7
+ * from it.
7
8
  *
8
9
  * The ledger is an **optional peer**: most catalogs sell features, not currency, and a project that never
9
- * declares a `grants` clause must neither install the package nor pay for it in its Worker bundle. So the
10
- * import is dynamic and it lives in exactly one file — grep `@pithy-sh/ledger` in this package and you find
11
- * this line and nothing else. Everything downstream depends on {@link PaymentsLedger}, a structural
12
- * two-method view, which is also what keeps the grant modules testable without resolving an optional package.
10
+ * declares a `grants` clause must neither install the package nor carry it in a Worker bundle. This file used
11
+ * to reach it with `import("@pithy-sh/ledger/src/ledger")` behind a `try`, which is optional at runtime and
12
+ * required at bundle time — wrangler's esbuild resolves a literal specifier whether or not the branch holding
13
+ * it ever runs, so every project composing payments without the ledger could not deploy its payments host at
14
+ * all (#645). The unit test here injected a loader, so it proved the runtime half and never met the bundler.
15
+ *
16
+ * **So the ledger is handed to payments, never fetched by it.** `ledger()` carries its peer surface as
17
+ * `ledgerPeer`; `payments()`'s `compose` hook finds it among the composed capabilities and keeps it for the
18
+ * routes, and the reconcile host — which composes nothing — is handed it by the entry `pithy` generates when
19
+ * the catalog credits a balance. Everything downstream depends on {@link PaymentsLedgerPeer} and
20
+ * {@link PaymentsLedger}, structural views, so no module in this package names `@pithy-sh/ledger` at all —
21
+ * not even for a type, which would put an optional package on the typecheck path of every module that touches
22
+ * fulfillment. `optionalPeerImports.test.ts` holds the whole kit to that.
13
23
  *
14
24
  * **An absent ledger is an error, never a skip.** A catalog with a `grants` clause has told us a purchase
15
25
  * credits a balance; quietly not crediting it is a support ticket that arrives weeks later as "I paid and got
16
26
  * no coins". The normal place this is caught is far earlier — `payments()`'s `compose` hook refuses at
17
27
  * assembly when a `grants` product is composed without the ledger, so a deploy fails rather than a purchase.
18
- * This throw is the backstop for a caller that reached fulfillment some other way, and it names the fix.
28
+ * The throw in {@link openPaymentsLedger} is the backstop for a caller that reached fulfillment some other way,
29
+ * and it names the fix.
19
30
  */
20
31
  /**
21
32
  * The ledger operations payments performs: one to fulfill a purchase, one to reverse it.
@@ -68,24 +79,33 @@ export interface PaymentsLedger {
68
79
  * that in one function makes it a property of the code rather than of two edits staying in step.
69
80
  */
70
81
  export declare function ledgerAccountId(subject: PaymentsSubject): string;
71
- /** How the ledger module is reached. Injectable so the absent-package path is a test rather than a hope. */
72
- export type PaymentsLedgerLoader = () => Promise<{
73
- openLedger: (d1: D1Database, now?: () => number) => PaymentsLedger;
74
- }>;
82
+ /** How a ledger is opened over a D1: `@pithy-sh/ledger`'s own `openLedger`, as payments sees it. */
83
+ export type PaymentsLedgerOpener = (d1: D1Database, now?: () => number) => PaymentsLedger;
84
+ /**
85
+ * The slice of `@pithy-sh/ledger`'s peer surface payments calls — its `ledgerPeer`, structurally.
86
+ *
87
+ * Structural for {@link PaymentsLedger}'s reason: a type imported from the optional package would put it on
88
+ * the typecheck path of every module that touches fulfillment. The ledger's own `ledgerPeer` satisfies it, and
89
+ * `capability.test.ts` composes the real one to prove that stays true.
90
+ */
91
+ export interface PaymentsLedgerPeer {
92
+ /** Open the ledger against a D1 binding, stamping rows with `now`. */
93
+ openLedger: PaymentsLedgerOpener;
94
+ }
75
95
  /** What {@link openPaymentsLedger} accepts beyond the binding. */
76
96
  export interface OpenPaymentsLedgerOptions {
77
- /** Override the module loader. Tests only; production always resolves the real package. */
78
- load?: PaymentsLedgerLoader;
97
+ /** The ledger the composition handed over, or undefined when none is composed. */
98
+ peer?: PaymentsLedgerPeer;
79
99
  /** The clock the ledger stamps its rows with. Injected so a fulfillment is deterministic under test. */
80
100
  now?: () => number;
81
101
  }
82
102
  /**
83
- * Open the ledger against the app database, or explain what is missing.
103
+ * Open the ledger the composition handed over against the app database, or explain what is missing.
84
104
  *
85
105
  * The ledger's tables live in the same D1 as payments' own — both capabilities bind `DB` — so there is no
86
106
  * second database to reach and no configuration to resolve. That is also why the two write independently and
87
107
  * a credit is idempotent on its `ref` rather than on being in the purchase's transaction: D1 has no
88
108
  * cross-statement transaction a caller can hold open across two packages.
89
109
  */
90
- export declare function openPaymentsLedger(d1: D1Database, options?: OpenPaymentsLedgerOptions): Promise<PaymentsLedger>;
110
+ export declare function openPaymentsLedger(d1: D1Database, options?: OpenPaymentsLedgerOptions): PaymentsLedger;
91
111
  //# sourceMappingURL=ledgerSeam.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledgerSeam.d.ts","sourceRoot":"","sources":["../../src/grants/ledgerSeam.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE/E;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,iFAAiF;IACjF,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,C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AM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,wGAAwG;IACxG,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAahE;AAED,oGAAoG;AACpG,MAAM,MAAM,oBAAoB,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,MAAM,MAAM,KAAK,cAAc,CAAC;AAE1F;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,UAAU,EAAE,oBAAoB,CAAC;CAClC;AAED,kEAAkE;AAClE,MAAM,WAAW,yBAAyB;IACxC,kFAAkF;IAClF,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,wGAAwG;IACxG,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,GAAE,yBAA8B,GAAG,cAAc,CAW1G"}
@@ -40,29 +40,21 @@ function ledgerAccountId(subject) {
40
40
  });
41
41
  return subject.subjectId;
42
42
  }
43
- /** The real loader — the only `@pithy-sh/ledger` import in the package. */
44
- const loadLedgerModule = () => import("@pithy-sh/ledger/src/ledger");
45
43
  /**
46
- * Open the ledger against the app database, or explain what is missing.
44
+ * Open the ledger the composition handed over against the app database, or explain what is missing.
47
45
  *
48
46
  * The ledger's tables live in the same D1 as payments' own — both capabilities bind `DB` — so there is no
49
47
  * second database to reach and no configuration to resolve. That is also why the two write independently and
50
48
  * a credit is idempotent on its `ref` rather than on being in the purchase's transaction: D1 has no
51
49
  * cross-statement transaction a caller can hold open across two packages.
52
50
  */
53
- async function openPaymentsLedger(d1, options = {}) {
54
- const load = options.load ?? loadLedgerModule;
55
- let module;
56
- try {
57
- module = await load();
58
- } catch (cause) {
59
- throw new InternalError({
60
- message: "This purchase credits a balance, and the ledger is not installed.",
61
- action: "Install @pithy-sh/ledger and compose ledger(...), or drop the `grants` clause from the product.",
62
- detail: `Loading @pithy-sh/ledger failed: ${cause instanceof Error ? cause.message : String(cause)}`
63
- }, { cause });
64
- }
65
- return module.openLedger(d1, options.now);
51
+ function openPaymentsLedger(d1, options = {}) {
52
+ if (options.peer === void 0) throw new InternalError({
53
+ message: "This purchase credits a balance, and no ledger is composed.",
54
+ action: "Add `ledger(...)` to this Worker's capabilities in pithy.config.ts, or drop the `grants` clause from the product.",
55
+ detail: "fulfillPurchase reached a product with a grants.ledger clause and was handed no ledger peer. payments() refuses that composition at assembly, so this caller reached fulfillment some other way, or a host was deployed without the entry that hands it the ledger."
56
+ });
57
+ return options.peer.openLedger(d1, options.now);
66
58
  }
67
59
  //#endregion
68
60
  export { ledgerAccountId, openPaymentsLedger };
@@ -7,6 +7,7 @@ import { type PaymentsConfig } from "../config/config";
7
7
  import { PaymentsPurchase } from "../data/purchase";
8
8
  import { type PaymentsSubject } from "../data/subject";
9
9
  import { type PaymentsSubjectSeam } from "../entitlement/subjectSeam";
10
+ import type { PaymentsLedgerPeer } from "../grants/ledgerSeam";
10
11
  import { type RailTrustOptions } from "../rails/providers";
11
12
  /**
12
13
  * The payments routes, their declared verification strategies, and what each accepts.
@@ -195,6 +196,13 @@ export interface PaymentsRoutesOptions {
195
196
  * compose organization billing without a resolver rather than reaching this state.
196
197
  */
197
198
  subject?: PaymentsSubjectSeam;
199
+ /**
200
+ * The ledger a `grants` product credits through, read per request — `payments()` hands the slot its
201
+ * `compose` hook fills, because `compose` runs after this factory. Undefined when no ledger is composed,
202
+ * which `payments()` refuses at assembly for any catalog that credits one. Never imported: see
203
+ * `grants/ledgerSeam.ts`.
204
+ */
205
+ ledger?: () => PaymentsLedgerPeer | undefined;
198
206
  }
199
207
  /**
200
208
  * Which subscription a change verb may act on — none, exactly one, or more than one.
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAU7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,EAEL,KAAK,cAAc,EAKpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAGL,KAAK,eAAe,EAGrB,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAAE,KAAK,mBAAmB,EAAkD,MAAM,4BAA4B,CAAC;AA0BtH,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,oBAAoB,CAAC;AA2EhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsJG;AACH,MAAM,WAAW,qBAAqB;IACpC,4BAA4B;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oGAAoG;IACpG,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,eAAe,EACxB,GAAG,EAAE,IAAI,GACR,OAAO,CAAC,kBAAkB,CAAC,CA4B7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,gBAAgB,GAC7B,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAmBtC;AAkPD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,qBAAqB,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAk/DxG"}
@@ -718,14 +718,6 @@ function registerPaymentsRoutes(options) {
718
718
  return projection;
719
719
  }
720
720
  /**
721
- * Credit what the purchase bought, and reverse it where a refund and the catalog both ask.
722
- *
723
- * A no-op for every product with no `grants` clause, and it resolves the optional `@pithy-sh/ledger` import
724
- * only when one is present — so a project selling nothing but features never reaches the package. A failure
725
- * here is deliberately left to propagate: the credit's ref is stable, so a retry settles it, and swallowing
726
- * it would lose a purchase's currency with nothing anywhere to read.
727
- */
728
- /**
729
721
  * Project the orphans a link just made resolvable. Never throws: see {@link repairOrphanedEvents}.
730
722
  *
731
723
  * The rail provider is built here rather than passed, because `replay` is the one thing the repair needs
@@ -759,10 +751,19 @@ function registerPaymentsRoutes(options) {
759
751
  }
760
752
  });
761
753
  }
754
+ /**
755
+ * Credit what the purchase bought, and reverse it where a refund and the catalog both ask.
756
+ *
757
+ * A no-op for every product with no `grants` clause, and it calls the ledger the composition handed over
758
+ * only when one is present — so a project selling nothing but features never needs one. A failure here is
759
+ * deliberately left to propagate: the credit's ref is stable, so a retry settles it, and swallowing it would
760
+ * lose a purchase's currency with nothing anywhere to read.
761
+ */
762
762
  async function fulfill(c, projection) {
763
763
  await fulfillPurchase(database(c), projection, {
764
764
  config,
765
765
  emit: c.var.emit,
766
+ ledgerPeer: options.ledger?.(),
766
767
  now: () => clock().getTime()
767
768
  });
768
769
  }
package/dist/index.d.ts CHANGED
@@ -38,7 +38,7 @@ export { authenticatedUserSubject, type PaymentsSubjectResolver, type PaymentsSu
38
38
  export { isUnimplementedSubject, requireImplementedSubject, unimplementedSubject, } from "./entitlement/unimplementedSubject";
39
39
  export { type AppliedGrant, applyGrants, type FulfillmentReport, type FulfillPurchaseOptions, fulfillPurchase, type GrantOptions, grantRef, ledgerGrantFor, purchaseIsPaid, } from "./grants/apply";
40
40
  export { type ClawbackOutcome, clawbackGrants, clawbackRef } from "./grants/clawback";
41
- export { type OpenPaymentsLedgerOptions, openPaymentsLedger, type PaymentsLedger, type PaymentsLedgerLoader, } from "./grants/ledgerSeam";
41
+ export { type OpenPaymentsLedgerOptions, openPaymentsLedger, type PaymentsLedger, type PaymentsLedgerOpener, type PaymentsLedgerPeer, } from "./grants/ledgerSeam";
42
42
  export { PAYMENTS_RECONCILE_KEY, triggerPaymentsReconcile } from "./http/dispatch";
43
43
  export { requireAuth } from "./http/guards";
44
44
  export { type PaymentsRoutesOptions, registerPaymentsRoutes } from "./http/routes";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,KAAK,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,QAAQ,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,cAAc,EACd,KAAK,mBAAmB,EACxB,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB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B,OAAO,EAAE,iCAAiC,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,uBAAuB,EACvB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
package/dist/peer.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { paymentsDatabase } from "./data/tables";
4
+ import { resolveEntitlements } from "./projection/resolve";
5
+ /**
6
+ * **What a capability composed beside payments may read — handed to it, never imported by it** (#645).
7
+ *
8
+ * `@pithy-sh/payments` is an optional peer of `support`, which shows an operator what a sender bought and is
9
+ * entitled to. It used to reach these modules by `import()` behind a `try`, and a literal specifier is one a
10
+ * bundler resolves whether or not the branch holding it ever runs — so a project without payments could not
11
+ * bundle support at all.
12
+ *
13
+ * So `payments()` carries this object as `paymentsPeer`, and a dependent finds it among the composed
14
+ * capabilities in its `compose` hook. The dependent names this package only in a type, which a bundler never
15
+ * sees. Reads only: the purchases table and the schema that decodes it, and the resolver every entitlement
16
+ * gate in the kit already trusts.
17
+ */
18
+ export declare const paymentsPeer: {
19
+ readonly PAYMENTS_PURCHASES_TABLE: "pithyPaymentsPurchases";
20
+ readonly paymentsDatabase: typeof paymentsDatabase;
21
+ readonly PaymentsPurchase: import("zod").ZodObject<{
22
+ id: import("zod").ZodString;
23
+ subjectType: import("zod").ZodEnum<{
24
+ organization: "organization";
25
+ user: "user";
26
+ }>;
27
+ subjectId: import("zod").ZodString;
28
+ rail: import("zod").ZodEnum<{
29
+ apple: "apple";
30
+ google: "google";
31
+ lemonSqueezy: "lemonSqueezy";
32
+ paddle: "paddle";
33
+ stripe: "stripe";
34
+ }>;
35
+ providerTransactionId: import("zod").ZodString;
36
+ productId: import("zod").ZodString;
37
+ providerProductId: import("zod").ZodString;
38
+ type: import("zod").ZodEnum<{
39
+ consumable: "consumable";
40
+ non_consumable: "non_consumable";
41
+ subscription: "subscription";
42
+ }>;
43
+ status: import("zod").ZodEnum<{
44
+ active: "active";
45
+ canceled: "canceled";
46
+ expired: "expired";
47
+ in_grace: "in_grace";
48
+ never_paid: "never_paid";
49
+ on_hold: "on_hold";
50
+ paused: "paused";
51
+ refunded: "refunded";
52
+ revoked: "revoked";
53
+ }>;
54
+ role: import("zod").ZodDefault<import("zod").ZodEnum<{
55
+ charge: "charge";
56
+ state: "state";
57
+ }>>;
58
+ environment: import("zod").ZodEnum<{
59
+ production: "production";
60
+ sandbox: "sandbox";
61
+ }>;
62
+ purchasedAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
63
+ expiresAt: import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>;
64
+ revokedAt: import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>;
65
+ resumesAt: import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>;
66
+ originalTransactionId: import("zod").ZodNullable<import("zod").ZodString>;
67
+ amountMinor: import("zod").ZodNullable<import("zod").ZodNumber>;
68
+ currency: import("zod").ZodNullable<import("zod").ZodString>;
69
+ providerEventAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
70
+ payload: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>]>, import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
71
+ createdAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
72
+ updatedAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
73
+ }, import("zod/v4/core").$strip>;
74
+ readonly resolveEntitlements: typeof resolveEntitlements;
75
+ };
76
+ /** Payments' peer surface, by type — what `paymentsPeer` holds. */
77
+ export type PaymentsPeer = typeof paymentsPeer;
78
+ //# sourceMappingURL=peer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../src/peer.ts"],"names":[],"mappings":"AAIA,OAAO,EAA4B,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAKf,CAAC;AAEX,mEAAmE;AACnE,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC"}
package/dist/peer.js ADDED
@@ -0,0 +1,27 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { PaymentsPurchase } from "./data/purchase.js";
4
+ import { PAYMENTS_PURCHASES_TABLE, paymentsDatabase } from "./data/tables.js";
5
+ import { resolveEntitlements } from "./projection/resolve.js";
6
+ //#region src/peer.ts
7
+ /**
8
+ * **What a capability composed beside payments may read — handed to it, never imported by it** (#645).
9
+ *
10
+ * `@pithy-sh/payments` is an optional peer of `support`, which shows an operator what a sender bought and is
11
+ * entitled to. It used to reach these modules by `import()` behind a `try`, and a literal specifier is one a
12
+ * bundler resolves whether or not the branch holding it ever runs — so a project without payments could not
13
+ * bundle support at all.
14
+ *
15
+ * So `payments()` carries this object as `paymentsPeer`, and a dependent finds it among the composed
16
+ * capabilities in its `compose` hook. The dependent names this package only in a type, which a bundler never
17
+ * sees. Reads only: the purchases table and the schema that decodes it, and the resolver every entitlement
18
+ * gate in the kit already trusts.
19
+ */
20
+ const paymentsPeer = {
21
+ PAYMENTS_PURCHASES_TABLE,
22
+ paymentsDatabase,
23
+ PaymentsPurchase,
24
+ resolveEntitlements
25
+ };
26
+ //#endregion
27
+ export { paymentsPeer };
@@ -3,5 +3,5 @@
3
3
  /** This package's npm name — the join key against a release feed. */
4
4
  export declare const PACKAGE_NAME = "@pithy-sh/payments";
5
5
  /** This package's version, stamped from its own package.json at generation time. */
6
- export declare const PACKAGE_VERSION = "0.3.6";
6
+ export declare const PACKAGE_VERSION = "0.3.7";
7
7
  //# sourceMappingURL=version.generated.d.ts.map
@@ -4,6 +4,6 @@
4
4
  /** This package's npm name — the join key against a release feed. */
5
5
  const PACKAGE_NAME = "@pithy-sh/payments";
6
6
  /** This package's version, stamped from its own package.json at generation time. */
7
- const PACKAGE_VERSION = "0.3.6";
7
+ const PACKAGE_VERSION = "0.3.7";
8
8
  //#endregion
9
9
  export { PACKAGE_NAME, PACKAGE_VERSION };