feat(12-02): add listAllInvoices and listAllInvoiceItems to Pax8Client

- listAllInvoices() pages the flat /invoices header list via paginateAll
- listAllInvoiceItems(invoiceId) pages the nested per-invoice
  /invoices/{id}/items child resource
- Both GET-only, reusing the existing paginateAll helper (PAX8-08)
- Note: no /orders call added (12-RESEARCH.md Pitfall 3 — unreliable/504s)
- Log pre-existing unrelated sync-scheduler.ts TS2307 errors to
  deferred-items.md (appgate-factory/appgate-sync-service not in this
  worktree's git history)
This commit is contained in:
lorentz 2026-07-10 22:45:40 -04:00
parent acf01de133
commit 0920ef8e43
2 changed files with 40 additions and 1 deletions

View file

@ -15,3 +15,9 @@ Out-of-scope issues discovered during execution but not fixed (per Scope Boundar
`lib/types/pax8.ts` reverted to its pre-plan state. Not touched by
migrations/093 or lib/types/pax8.ts. Someone completing the appgate feature
branch/commit should resolve this; out of scope for Phase 12.
## Plan 02
- Same pre-existing `sync-scheduler.ts:446`/`:450` TS2307 errors reproduce
unchanged after Task 1's `pax8-client.ts` edits (`listAllInvoices` /
`listAllInvoiceItems`). Confirmed unrelated to this plan's files.

View file

@ -4,7 +4,14 @@
* https://devx.pax8.com
*/
import type { Pax8Company, Pax8PageEnvelope, Pax8Subscription, Pax8Product } from '@/lib/types/pax8';
import type {
Pax8Company,
Pax8PageEnvelope,
Pax8Subscription,
Pax8Product,
Pax8Invoice,
Pax8InvoiceItem,
} from '@/lib/types/pax8';
export interface Pax8ClientConfig {
clientId: string;
@ -120,4 +127,30 @@ export class Pax8Client {
this.fetchJson<Pax8PageEnvelope<Pax8Product>>(`/products?page=${page}&size=${size}`),
);
}
/**
* Read-only: page through every invoice header (PAX8-08 GET only).
* `/invoices` is the partner's own consolidated monthly bill one row per
* billing period, not per end-customer (12-RESEARCH.md Pitfall 1). Do NOT
* add an orders-endpoint call it is unreliable (504s) for this account
* (12-RESEARCH.md Pitfall 3).
*/
async listAllInvoices(): Promise<Pax8Invoice[]> {
return this.paginateAll<Pax8Invoice>((page, size) =>
this.fetchJson<Pax8PageEnvelope<Pax8Invoice>>(`/invoices?page=${page}&size=${size}`),
);
}
/**
* Read-only: page through every line item of a single invoice
* (PAX8-08 GET only). Invoice items are a per-invoice child resource
* there is no flat `/invoice-items` endpoint (12-RESEARCH.md Pitfall 2).
*/
async listAllInvoiceItems(invoiceId: string): Promise<Pax8InvoiceItem[]> {
return this.paginateAll<Pax8InvoiceItem>((page, size) =>
this.fetchJson<Pax8PageEnvelope<Pax8InvoiceItem>>(
`/invoices/${invoiceId}/items?page=${page}&size=${size}`,
),
);
}
}