@pithy-sh/payments 0.7.1 → 0.8.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.
package/README.md CHANGED
@@ -42,14 +42,14 @@ _Everything else is on the site. `pithy.sh/docs` is canonical — new prose goes
42
42
  | `POST /payments/entitlements/overrides/unrestricted` | Grant one subject the whole product, or take it back | control-plane: `payments:overrides:unrestricted` |
43
43
  | `POST /payments/entitlements/overrides/clear` | Unpin names for one subject, or clear its override | control-plane: `payments:overrides:clear` |
44
44
  | `GET /payments/admin/catalog` | What this project sells, what each entitlement buys, and the keys it comps by hand | control-plane: `payments:catalog:read` |
45
- | `GET /payments/admin/purchases` | The purchase log, paged | control-plane: `payments:purchases:read` |
45
+ | `GET /payments/admin/purchases` | The purchase log, paged, narrowed by subject, rail, status, environment or `type` (`recurring`, `one_time`) | control-plane: `payments:purchases:read` |
46
46
  | `GET /payments/admin/subscriptions` | The purchases that renew | control-plane: `payments:subscriptions:read` |
47
47
  | `GET /payments/admin/entitlements` | The entitlement model, paged | control-plane: `payments:entitlements:read` |
48
48
  | `GET /payments/admin/entitlements/:subjectType/:subjectId` | One subject's entitlements, override and resolved allowances | control-plane: `payments:entitlements:read` |
49
49
  | `GET /payments/admin/overrides` | Every subject's override, and who is unrestricted | control-plane: `payments:entitlements:read` |
50
50
  | `GET /payments/admin/usage-runs` | The usage-reporting passes this deployment has run | control-plane: `payments:usage:read` |
51
51
  | `GET /payments/admin/webhook-events` | Every notification a store sent — projected, pending with its attempts, or abandoned — and the purchase and subscription rows it changed. Never the payload; an error crosses as its code | control-plane: `payments:webhooks:read` |
52
- | `GET /payments/admin/reconcile-runs` | The reconciliation passes this deployment has run | control-plane: `payments:reconcile:read` |
52
+ | `GET /payments/admin/reconcile-runs` | The reconciliation passes this deployment has run, narrowed by rail, environment or `outcome` | control-plane: `payments:reconcile:read` |
53
53
  | `POST /payments/admin/reconcile-runs` | Start a pass now, rather than waiting for the nightly one | control-plane: `payments:reconcile:run` |
54
54
 
55
55
  **Every route this capability registers is in that table, and a test holds it there.** The management reads shipped without rows for long enough that the next person to add one withheld theirs too — a table missing four peers reads as complete, so one more row would have read as a lie. `routeContract.test.ts` now parses this table and compares it against the real registrations in both directions, which makes the omission a failing build rather than a judgment call.
@@ -130,6 +130,8 @@ export interface PurchasesQuery {
130
130
  status?: PurchaseStatus;
131
131
  /** Restrict to one store environment — the filter that separates real money from test transactions. */
132
132
  environment?: PurchaseEnvironment;
133
+ /** Restrict to the purchases that renew (`subscription`), or to the ones bought once (every other product type). */
134
+ type?: "recurring" | "one_time";
133
135
  /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
134
136
  cursor?: string;
135
137
  /** How many rows to return, clamped by `pageLimit`. */
@@ -168,8 +170,8 @@ export declare function listPurchases(d1: D1Database, query?: PurchasesQuery): P
168
170
  /**
169
171
  * The purchases that renew, newest first.
170
172
  *
171
- * A separate function rather than a `type` filter {@link listPurchases} would accept, because a caller
172
- * that could name the type could hold `payments:subscriptions:read` and read the whole purchase log
173
+ * A separate function rather than the `type` filter {@link listPurchases} takes, because a caller holding
174
+ * only `payments:subscriptions:read` must not be able to name the type and read the whole purchase log
173
175
  * through it. The narrowing is applied here, where no request reaches it.
174
176
  */
175
177
  export declare function listSubscriptions(d1: D1Database, query?: SubscriptionsQuery): Promise<PaymentsPage<PaymentsPurchaseRecord>>;
@@ -252,6 +254,12 @@ export interface ReconcileRunsQuery {
252
254
  rail?: PaymentsRail;
253
255
  /** Restrict to one store environment. */
254
256
  environment?: PurchaseEnvironment;
257
+ /**
258
+ * Restrict to what the pass came to: `failed` — a store refused to answer for at least one purchase;
259
+ * `drifted` — none failed and at least one was repaired; `clean` — neither. A pass that both drifted and
260
+ * failed reads `failed`, because the failure is the part an operator has to act on.
261
+ */
262
+ outcome?: "failed" | "drifted" | "clean";
255
263
  /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
256
264
  cursor?: string;
257
265
  /** How many rows to return, clamped by `pageLimit`. */
@@ -317,7 +325,7 @@ export interface WebhookEventsQuery {
317
325
  limit?: number;
318
326
  }
319
327
  /**
320
- * Every notification a store sent, newest received first (#830).
328
+ * Every notification a store sent, newest received first.
321
329
  *
322
330
  * Ordered on `receivedAt` — when the delivery reached us — with the id as the tiebreak, on the index
323
331
  * `payments_0003_webhook_targets` creates for exactly this. Named columns and never `payload`: the provider's
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/admin/read.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAI5D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAY/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAwB,KAAK,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,oEAAoE;AACpE,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,8BAA8B;IAC9B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,mGAAmG;IACnG,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB;;;;;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B,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,6BAA6B,CAAC;IACtC,yCAAyC;IACzC,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,oCAAoC;IACpC,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,UAAU,EACd,KAAK,GAAE,kBAAuB,GAC7B,OAAO,CAAC,YAAY,CAAC,2BAA2B,CAAC,CAAC,CAwCpD"}
@@ -74,8 +74,8 @@ async function listPurchases(d1, query = {}) {
74
74
  /**
75
75
  * The purchases that renew, newest first.
76
76
  *
77
- * A separate function rather than a `type` filter {@link listPurchases} would accept, because a caller
78
- * that could name the type could hold `payments:subscriptions:read` and read the whole purchase log
77
+ * A separate function rather than the `type` filter {@link listPurchases} takes, because a caller holding
78
+ * only `payments:subscriptions:read` must not be able to name the type and read the whole purchase log
79
79
  * through it. The narrowing is applied here, where no request reaches it.
80
80
  */
81
81
  async function listSubscriptions(d1, query = {}) {
@@ -91,6 +91,7 @@ async function purchasePage(d1, query, type) {
91
91
  if (query.rail !== void 0) selection = selection.where("rail", "=", query.rail);
92
92
  if (query.status !== void 0) selection = selection.where("status", "=", query.status);
93
93
  if (query.environment !== void 0) selection = selection.where("environment", "=", query.environment);
94
+ if (query.type !== void 0) selection = selection.where("type", query.type === "recurring" ? "=" : "!=", "subscription");
94
95
  if (after) selection = selection.where((eb) => eb.or([eb("purchasedAt", "<", after.sort), eb.and([eb("purchasedAt", "=", after.sort), eb("id", "<", after.id)])]));
95
96
  const rows = await selection.execute();
96
97
  return toPage(rows.map((row) => PaymentsPurchaseRecord.parse(row)), limit, (purchase) => ({
@@ -239,6 +240,9 @@ async function listReconcileRuns(d1, query = {}) {
239
240
  let selection = paymentsDatabase(d1).selectFrom(PAYMENTS_RECONCILE_RUNS_TABLE).selectAll().orderBy("startedAt", "desc").orderBy("id", "desc").limit(limit + 1);
240
241
  if (query.rail !== void 0) selection = selection.where("rail", "=", query.rail);
241
242
  if (query.environment !== void 0) selection = selection.where("environment", "=", query.environment);
243
+ if (query.outcome === "failed") selection = selection.where("failed", ">", 0);
244
+ if (query.outcome === "drifted") selection = selection.where("failed", "=", 0).where("drifted", ">", 0);
245
+ if (query.outcome === "clean") selection = selection.where("failed", "=", 0).where("drifted", "=", 0);
242
246
  if (after) selection = selection.where((eb) => eb.or([eb("startedAt", "<", after.sort), eb.and([eb("startedAt", "=", after.sort), eb("id", "<", after.id)])]));
243
247
  const rows = await selection.execute();
244
248
  return toPage(rows.map((row) => PaymentsReconcileRun.parse(row)), limit, (run) => ({
@@ -295,7 +299,7 @@ const EVENT_TYPE_SQL = sql`case when json_valid(${sql.ref("payload")}) then case
295
299
  )
296
300
  end end`;
297
301
  /**
298
- * Every notification a store sent, newest received first (#830).
302
+ * Every notification a store sent, newest received first.
299
303
  *
300
304
  * Ordered on `receivedAt` — when the delivery reached us — with the id as the tiebreak, on the index
301
305
  * `payments_0003_webhook_targets` creates for exactly this. Named columns and never `payload`: the provider's
@@ -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;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAY7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAc1C,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;AAsBzB,OAAO,EAAE,KAAK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
828
828
  subjectId: subject?.subjectId ?? null,
829
829
  rail: query.rail ?? null,
830
830
  status: query.status ?? null,
831
- environment: query.environment ?? null
831
+ environment: query.environment ?? null,
832
+ type: query.type ?? null
832
833
  }
833
834
  });
834
835
  return c.json({
@@ -1027,7 +1028,8 @@ function registerPaymentsRoutes(options) {
1027
1028
  resumed: query.cursor !== void 0,
1028
1029
  filters: {
1029
1030
  rail: query.rail ?? null,
1030
- environment: query.environment ?? null
1031
+ environment: query.environment ?? null,
1032
+ outcome: query.outcome ?? null
1031
1033
  }
1032
1034
  });
1033
1035
  return c.json({
@@ -366,6 +366,10 @@ export declare const AdminPurchasesQuery: z.ZodObject<{
366
366
  production: "production";
367
367
  sandbox: "sandbox";
368
368
  }>>;
369
+ type: z.ZodOptional<z.ZodEnum<{
370
+ one_time: "one_time";
371
+ recurring: "recurring";
372
+ }>>;
369
373
  cursor: z.ZodOptional<z.ZodString>;
370
374
  limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
371
375
  }, z.core.$strip>;
@@ -428,6 +432,11 @@ export declare const AdminReconcileRunsQuery: z.ZodObject<{
428
432
  production: "production";
429
433
  sandbox: "sandbox";
430
434
  }>>;
435
+ outcome: z.ZodOptional<z.ZodEnum<{
436
+ clean: "clean";
437
+ drifted: "drifted";
438
+ failed: "failed";
439
+ }>>;
431
440
  cursor: z.ZodOptional<z.ZodString>;
432
441
  limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
433
442
  }, z.core.$strip>;
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/http/schemas.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8DxB,eAAO,MAAM,kBAAkB;;;;;;;;;iBAa5B,CAAC;AACJ,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,eAAO,MAAM,cAAc;;;;;;;;;iBAa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AAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE/E,eAAO,MAAM,mBAAmB;;;iBAEkC,CAAC;AACnE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB;;;;;;iBASgE,CAAC;AAC/F,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB;;iBAW8D,CAAC;AAC7F,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -370,6 +370,7 @@ const AdminPurchasesQuery = z.object({
370
370
  rail: PaymentsRail.optional().describe("Restrict the listing to one store."),
371
371
  status: PurchaseStatus.optional().describe("Restrict the listing to one normalized status."),
372
372
  environment: PurchaseEnvironment.optional().describe("Restrict the listing to one store environment. Unfiltered by default: hiding sandbox transactions by default would hide the thing an operator most needs to notice."),
373
+ type: z.enum(["recurring", "one_time"]).optional().describe("Restrict the listing to the purchases that renew (`recurring`, a subscription) or to the ones bought once (`one_time`, a consumable or a non-consumable)."),
373
374
  cursor: Cursor,
374
375
  limit: Limit
375
376
  }).refine(subjectFilterIsWhole, SUBJECT_FILTER_RULE).describe("The purchase-log query: what to narrow it to, and where to resume.");
@@ -394,6 +395,11 @@ const AdminOverridesQuery = z.object({
394
395
  const AdminReconcileRunsQuery = z.object({
395
396
  rail: PaymentsRail.optional().describe("Restrict to the passes narrowed to one store. A scheduled pass runs against every rail and carries no rail, so this never matches one."),
396
397
  environment: PurchaseEnvironment.optional().describe("Restrict to one store environment — the sandbox host and the production host each keep their own passes."),
398
+ outcome: z.enum([
399
+ "failed",
400
+ "drifted",
401
+ "clean"
402
+ ]).optional().describe("Restrict to what the pass came to: `failed`, a store refused to answer for at least one purchase; `drifted`, none failed and at least one was repaired; `clean`, neither. A pass that drifted and failed reads `failed`."),
397
403
  cursor: Cursor,
398
404
  limit: Limit
399
405
  }).describe("The reconciliation-run query: what to narrow it to, and where to resume.");
@@ -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.7.1";
6
+ export declare const PACKAGE_VERSION = "0.8.0";
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.7.1";
7
+ const PACKAGE_VERSION = "0.8.0";
8
8
  //#endregion
9
9
  export { PACKAGE_NAME, PACKAGE_VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithy-sh/payments",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,9 +42,9 @@
42
42
  "@paddle/paddle-js": "^1.6.4"
43
43
  },
44
44
  "peerDependencies": {
45
- "@pithy-sh/core": "^0.15.0",
46
- "@pithy-sh/ledger": "^0.6.1",
47
- "@pithy-sh/secrets": "^0.6.3",
45
+ "@pithy-sh/core": "^0.17.0",
46
+ "@pithy-sh/ledger": "^0.6.3",
47
+ "@pithy-sh/secrets": "^0.6.5",
48
48
  "@pithy-sh/ui-core": "^0.1.0",
49
49
  "hono": "^4.13.2",
50
50
  "kysely": "^0.29.0",
package/src/admin/read.ts CHANGED
@@ -126,6 +126,8 @@ export interface PurchasesQuery {
126
126
  status?: PurchaseStatus;
127
127
  /** Restrict to one store environment — the filter that separates real money from test transactions. */
128
128
  environment?: PurchaseEnvironment;
129
+ /** Restrict to the purchases that renew (`subscription`), or to the ones bought once (every other product type). */
130
+ type?: "recurring" | "one_time";
129
131
  /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
130
132
  cursor?: string;
131
133
  /** How many rows to return, clamped by `pageLimit`. */
@@ -187,8 +189,8 @@ export async function listPurchases(
187
189
  /**
188
190
  * The purchases that renew, newest first.
189
191
  *
190
- * A separate function rather than a `type` filter {@link listPurchases} would accept, because a caller
191
- * that could name the type could hold `payments:subscriptions:read` and read the whole purchase log
192
+ * A separate function rather than the `type` filter {@link listPurchases} takes, because a caller holding
193
+ * only `payments:subscriptions:read` must not be able to name the type and read the whole purchase log
192
194
  * through it. The narrowing is applied here, where no request reaches it.
193
195
  */
194
196
  export async function listSubscriptions(
@@ -228,6 +230,9 @@ async function purchasePage(
228
230
  if (query.rail !== undefined) selection = selection.where("rail", "=", query.rail);
229
231
  if (query.status !== undefined) selection = selection.where("status", "=", query.status);
230
232
  if (query.environment !== undefined) selection = selection.where("environment", "=", query.environment);
233
+ if (query.type !== undefined) {
234
+ selection = selection.where("type", query.type === "recurring" ? "=" : "!=", "subscription");
235
+ }
231
236
  if (after) {
232
237
  selection = selection.where((eb) =>
233
238
  eb.or([
@@ -487,6 +492,12 @@ export interface ReconcileRunsQuery {
487
492
  rail?: PaymentsRail;
488
493
  /** Restrict to one store environment. */
489
494
  environment?: PurchaseEnvironment;
495
+ /**
496
+ * Restrict to what the pass came to: `failed` — a store refused to answer for at least one purchase;
497
+ * `drifted` — none failed and at least one was repaired; `clean` — neither. A pass that both drifted and
498
+ * failed reads `failed`, because the failure is the part an operator has to act on.
499
+ */
500
+ outcome?: "failed" | "drifted" | "clean";
490
501
  /** Where to resume, from a previous page's `nextCursor`. A malformed one is a first page. */
491
502
  cursor?: string;
492
503
  /** How many rows to return, clamped by `pageLimit`. */
@@ -520,6 +531,9 @@ export async function listReconcileRuns(
520
531
 
521
532
  if (query.rail !== undefined) selection = selection.where("rail", "=", query.rail);
522
533
  if (query.environment !== undefined) selection = selection.where("environment", "=", query.environment);
534
+ if (query.outcome === "failed") selection = selection.where("failed", ">", 0);
535
+ if (query.outcome === "drifted") selection = selection.where("failed", "=", 0).where("drifted", ">", 0);
536
+ if (query.outcome === "clean") selection = selection.where("failed", "=", 0).where("drifted", "=", 0);
523
537
  if (after) {
524
538
  selection = selection.where((eb) =>
525
539
  eb.or([eb("startedAt", "<", after.sort), eb.and([eb("startedAt", "=", after.sort), eb("id", "<", after.id)])]),
@@ -611,7 +625,7 @@ export interface WebhookEventsQuery {
611
625
  }
612
626
 
613
627
  /**
614
- * Every notification a store sent, newest received first (#830).
628
+ * Every notification a store sent, newest received first.
615
629
  *
616
630
  * Ordered on `receivedAt` — when the delivery reached us — with the id as the tiebreak, on the index
617
631
  * `payments_0003_webhook_targets` creates for exactly this. Named columns and never `payload`: the provider's
@@ -1436,6 +1436,7 @@ export function registerPaymentsRoutes(options: PaymentsRoutesOptions): (app: Ho
1436
1436
  rail: query.rail ?? null,
1437
1437
  status: query.status ?? null,
1438
1438
  environment: query.environment ?? null,
1439
+ type: query.type ?? null,
1439
1440
  },
1440
1441
  },
1441
1442
  );
@@ -1697,7 +1698,7 @@ export function registerPaymentsRoutes(options: PaymentsRoutesOptions): (app: Ho
1697
1698
  await recordRead(c, PaymentsAuditActions.reconcileRunsRead, null, {
1698
1699
  returned: page.items.length,
1699
1700
  resumed: query.cursor !== undefined,
1700
- filters: { rail: query.rail ?? null, environment: query.environment ?? null },
1701
+ filters: { rail: query.rail ?? null, environment: query.environment ?? null, outcome: query.outcome ?? null },
1701
1702
  });
1702
1703
  return c.json(
1703
1704
  {
@@ -623,6 +623,12 @@ export const AdminPurchasesQuery = z
623
623
  environment: PurchaseEnvironment.optional().describe(
624
624
  "Restrict the listing to one store environment. Unfiltered by default: hiding sandbox transactions by default would hide the thing an operator most needs to notice.",
625
625
  ),
626
+ type: z
627
+ .enum(["recurring", "one_time"])
628
+ .optional()
629
+ .describe(
630
+ "Restrict the listing to the purchases that renew (`recurring`, a subscription) or to the ones bought once (`one_time`, a consumable or a non-consumable).",
631
+ ),
626
632
  cursor: Cursor,
627
633
  limit: Limit,
628
634
  })
@@ -680,6 +686,12 @@ export const AdminReconcileRunsQuery = z
680
686
  environment: PurchaseEnvironment.optional().describe(
681
687
  "Restrict to one store environment — the sandbox host and the production host each keep their own passes.",
682
688
  ),
689
+ outcome: z
690
+ .enum(["failed", "drifted", "clean"])
691
+ .optional()
692
+ .describe(
693
+ "Restrict to what the pass came to: `failed`, a store refused to answer for at least one purchase; `drifted`, none failed and at least one was repaired; `clean`, neither. A pass that drifted and failed reads `failed`.",
694
+ ),
683
695
  cursor: Cursor,
684
696
  limit: Limit,
685
697
  })
@@ -13,4 +13,4 @@
13
13
  export const PACKAGE_NAME = "@pithy-sh/payments";
14
14
 
15
15
  /** This package's version, stamped from its own package.json at generation time. */
16
- export const PACKAGE_VERSION = "0.7.1";
16
+ export const PACKAGE_VERSION = "0.8.0";