@baseworks/invoice 1.0.0 → 1.1.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 +23 -0
- package/dist/{chunk-ITMZVGLQ.js → chunk-335MPCTE.js} +55 -0
- package/dist/cli.js +20 -4
- package/dist/client.d.ts +118 -7
- package/dist/client.js +18 -0
- package/dist/events.d.ts +108 -3
- package/dist/events.js +5 -1
- package/dist/mcp.js +19 -4
- package/dist/projections.js +37 -2
- package/package.json +1 -1
- package/src/__tests__/cli.test.ts +18 -0
- package/src/__tests__/client.test.ts +40 -1
- package/src/__tests__/mcp.test.ts +13 -0
- package/src/cli.ts +36 -11
- package/src/client.ts +34 -1
- package/src/events.ts +44 -0
- package/src/mcp.ts +18 -6
- package/src/projections.ts +35 -0
- package/src/types.ts +114 -2
package/README.md
CHANGED
|
@@ -55,6 +55,27 @@ await invoices.void(final.id, 'issued in error')
|
|
|
55
55
|
Errors throw `InvoiceError` (`.status`, `.code`): `403 forbidden` (with the missing permission, e.g. `invoice.write`),
|
|
56
56
|
`409 not_draft` (edit a finalized invoice), `409 overpayment` / `409 already_paid`, `404 customer_not_found`.
|
|
57
57
|
|
|
58
|
+
### 1.1.0: sources, payment status, filters, fiscal state
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// what is still owed, and what is late
|
|
62
|
+
await invoices.list({ payment_status: ['unpaid', 'partially_paid'] })
|
|
63
|
+
await invoices.list({ overdue: true, source: 'local', customer_id: 'cus_1' }) // filters combine
|
|
64
|
+
|
|
65
|
+
const inv = await invoices.get(id) // inv.payment_status, inv.source, inv.external_refs, inv.metadata, inv.fiscal, inv.payments
|
|
66
|
+
|
|
67
|
+
// a provider's document, whole: creates or replaces by external_ref (system + id); `created`, `stale`
|
|
68
|
+
await invoices.mirror({ source: 'stripe', external_ref: { system: 'stripe', id: 'in_…', number, url, pdf_url, account_id, livemode },
|
|
69
|
+
customer_id, currency, lines, subtotal_cents, tax_cents, total_cents, status: 'finalized', issued_at, provider_updated_at })
|
|
70
|
+
|
|
71
|
+
await invoices.recordPayment(id, { amount_cents: 990, payment_id: 'pay_…' }) // the same payment_id twice records it once
|
|
72
|
+
await invoices.setFiscal(id, { status: 'submitted', system: 'gib', external_id }) // needs invoice.fiscal_update
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The CLI lists with `--payment-status unpaid,partially_paid`, `--overdue`, `--source`, `--fiscal-status`, `--customer-id`, and shows
|
|
76
|
+
a PAYMENT column. A mirror (`source: stripe | manual`) is read-only except through `mirror`: `update`, `finalize` and `void`
|
|
77
|
+
throw `InvoiceError` `409 mirrored`.
|
|
78
|
+
|
|
58
79
|
### Deprecated names
|
|
59
80
|
|
|
60
81
|
Until 0.3.0 the client and the service spoke camelCase. A caller that has not moved (billing-service, stripe-service, apps)
|
|
@@ -101,6 +122,8 @@ optional peer.
|
|
|
101
122
|
| `invoice_create`, `invoice_update` (drafts only) | write | `invoice.write` |
|
|
102
123
|
| `invoice_finalize` (irreversible) | write | `invoice.finalize` |
|
|
103
124
|
| `invoice_record_payment` | write | `invoice.record_payment` |
|
|
125
|
+
|
|
126
|
+
`invoice_list` takes the same filters as the client; `invoice_record_payment` takes `payment_id`. There is no tool for the mirror upsert or the fiscal state: those are for services and for the tax-system extension.
|
|
104
127
|
| `invoice_void` (irreversible) | write | `invoice.void` |
|
|
105
128
|
|
|
106
129
|
A tool is a thin wrapper over the same client, so it can never do what the API would refuse, and `permission` is the name
|
|
@@ -15,6 +15,10 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
15
15
|
subtotal_cents: z.number().int(),
|
|
16
16
|
total_cents: z.number().int(),
|
|
17
17
|
short_id: z.string().min(1),
|
|
18
|
+
// 1.1.0. Absent from older events: the read model holds NULL, and the service reads that as `local` and `{}`.
|
|
19
|
+
source: z.string().optional(),
|
|
20
|
+
metadata: z.string().optional(),
|
|
21
|
+
// JSON object, serialized
|
|
18
22
|
at: z.number().int()
|
|
19
23
|
}),
|
|
20
24
|
// Draft edited (customer / lines). Only valid while status = draft.
|
|
@@ -24,6 +28,8 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
24
28
|
lines: z.string(),
|
|
25
29
|
subtotal_cents: z.number().int(),
|
|
26
30
|
total_cents: z.number().int(),
|
|
31
|
+
metadata: z.string().optional(),
|
|
32
|
+
// 1.1.0
|
|
27
33
|
at: z.number().int()
|
|
28
34
|
}),
|
|
29
35
|
// Finalize: assign the per-org number, freeze lines + totals, set issue/due.
|
|
@@ -46,13 +52,58 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
46
52
|
status: InvoiceStatus,
|
|
47
53
|
method: z.string(),
|
|
48
54
|
reference: z.string(),
|
|
55
|
+
payment_id: z.string().optional(),
|
|
56
|
+
// 1.1.0: the pay record this settles; the idempotency key when present
|
|
49
57
|
at: z.number().int()
|
|
50
58
|
}),
|
|
51
59
|
InvoiceVoided: z.object({
|
|
52
60
|
reason: z.string(),
|
|
53
61
|
at: z.number().int()
|
|
62
|
+
}),
|
|
63
|
+
// 1.1.0. The provider's document, whole (absolute values like every event here), by (system, external id): the
|
|
64
|
+
// first one creates the invoice, the next ones replace it. A mirror never takes a number: `number` stays 0.
|
|
65
|
+
InvoiceMirrored: z.object({
|
|
66
|
+
source: z.string(),
|
|
67
|
+
// 'stripe' | 'manual'
|
|
68
|
+
mirror_key: z.string().min(1),
|
|
69
|
+
// `${system}:${external_id}`
|
|
70
|
+
external_refs: z.string(),
|
|
71
|
+
// JSON array, serialized
|
|
72
|
+
customer_id: z.string().min(1),
|
|
73
|
+
customer_name: z.string(),
|
|
74
|
+
currency: z.string().length(3),
|
|
75
|
+
lines: z.string(),
|
|
76
|
+
subtotal_cents: z.number().int(),
|
|
77
|
+
tax_cents: z.number().int(),
|
|
78
|
+
total_cents: z.number().int(),
|
|
79
|
+
amount_paid_cents: z.number().int(),
|
|
80
|
+
// from the payment entries, not from the provider
|
|
81
|
+
status: InvoiceStatus,
|
|
82
|
+
issued_at: z.number().int(),
|
|
83
|
+
due_at: z.number().int(),
|
|
84
|
+
// 0 = none
|
|
85
|
+
paid_at: z.number().int(),
|
|
86
|
+
// 0 = none
|
|
87
|
+
voided_at: z.number().int(),
|
|
88
|
+
// 0 = none
|
|
89
|
+
provider_updated_at: z.number().int(),
|
|
90
|
+
metadata: z.string(),
|
|
91
|
+
short_id: z.string().min(1),
|
|
92
|
+
created_at: z.number().int(),
|
|
93
|
+
at: z.number().int()
|
|
94
|
+
}),
|
|
95
|
+
// 1.1.0. Where the invoice stands with a tax system. Only changed through `invoice.fiscal_update`.
|
|
96
|
+
InvoiceFiscalChanged: z.object({
|
|
97
|
+
status: z.string(),
|
|
98
|
+
// FISCAL_STATUSES
|
|
99
|
+
system: z.string(),
|
|
100
|
+
external_id: z.string(),
|
|
101
|
+
message: z.string(),
|
|
102
|
+
at: z.number().int()
|
|
54
103
|
})
|
|
55
104
|
});
|
|
105
|
+
var FISCAL_STATUSES = ["not_submitted", "queued", "submitted", "accepted", "rejected", "cancelled"];
|
|
106
|
+
var INVOICE_SOURCES = ["local", "stripe", "manual"];
|
|
56
107
|
var TransactionKind = z.enum(["payment", "refund", "adjustment"]);
|
|
57
108
|
var TransactionEvents = defineAggregate("transaction", {
|
|
58
109
|
TransactionRecorded: z.object({
|
|
@@ -66,6 +117,8 @@ var TransactionEvents = defineAggregate("transaction", {
|
|
|
66
117
|
currency: z.string().length(3),
|
|
67
118
|
method: z.string(),
|
|
68
119
|
reference: z.string(),
|
|
120
|
+
payment_id: z.string().optional(),
|
|
121
|
+
// 1.1.0
|
|
69
122
|
at: z.number().int()
|
|
70
123
|
})
|
|
71
124
|
});
|
|
@@ -73,6 +126,8 @@ var TransactionEvents = defineAggregate("transaction", {
|
|
|
73
126
|
export {
|
|
74
127
|
InvoiceStatus,
|
|
75
128
|
InvoiceEvents,
|
|
129
|
+
FISCAL_STATUSES,
|
|
130
|
+
INVOICE_SOURCES,
|
|
76
131
|
TransactionKind,
|
|
77
132
|
TransactionEvents
|
|
78
133
|
};
|
package/dist/cli.js
CHANGED
|
@@ -23,34 +23,50 @@ function parseLine(spec) {
|
|
|
23
23
|
return { description, quantity, unit_price_cents: toCents(parts[2].trim(), "--line unitPrice") };
|
|
24
24
|
}
|
|
25
25
|
var NUMBER_COL = (v) => v ? `#${v}` : "\u2014";
|
|
26
|
+
var filterOptions = (c) => c.option("--status <status>", "Filter: draft | finalized | paid | void").option("--payment-status <list>", "unpaid | partially_paid | paid | not_due (comma-separated)").option("--overdue", "Owed, with a due date in the past").option("--source <source>", "local | stripe | manual").option("--fiscal-status <status>", "not_submitted | queued | submitted | accepted | rejected | cancelled").option("--customer-id <id>", "Only this customer (its id)");
|
|
26
27
|
function buildInvoiceCommand(deps) {
|
|
27
28
|
const { http } = deps;
|
|
28
29
|
const cli = deps.cliName ?? "cli";
|
|
29
30
|
const listInvoices = async (opts) => {
|
|
30
|
-
const
|
|
31
|
+
const params = new URLSearchParams();
|
|
32
|
+
if (opts.status) params.set("status", opts.status);
|
|
33
|
+
if (opts.paymentStatus) params.set("payment_status", opts.paymentStatus);
|
|
34
|
+
if (opts.overdue) params.set("overdue", "true");
|
|
35
|
+
if (opts.source) params.set("source", opts.source);
|
|
36
|
+
if (opts.fiscalStatus) params.set("fiscal_status", opts.fiscalStatus);
|
|
37
|
+
if (opts.customerId) params.set("customer_id", opts.customerId);
|
|
38
|
+
const q = params.toString() ? `?${params}` : "";
|
|
31
39
|
const res = await http.get(`/invoices${q}`).catch(die);
|
|
32
40
|
printOutput(res.invoices, opts.output, (wide) => {
|
|
33
41
|
table(res.invoices, [
|
|
34
42
|
{ key: "short_id", label: "ID" },
|
|
35
43
|
{ key: "number", label: "NO", fmt: NUMBER_COL },
|
|
36
44
|
{ key: "status", label: "STATUS" },
|
|
45
|
+
{ key: "payment_status", label: "PAYMENT", fmt: (v) => v ?? "" },
|
|
37
46
|
{ key: "customer_name", label: "CUSTOMER", fmt: (v, r) => v ?? r.customer_id },
|
|
38
47
|
{ key: "total_cents", label: "TOTAL", fmt: (v, r) => fmtMoney(v, r.currency) },
|
|
39
48
|
{ key: "balance_cents", label: "BALANCE", fmt: (v, r) => fmtMoney(v, r.currency) },
|
|
49
|
+
{ key: "source", label: "SOURCE", wide: true, fmt: (v) => v ?? "local" },
|
|
40
50
|
{ key: "created_at", label: "CREATED", wide: true, fmt: (v) => fmtDate(v) },
|
|
41
51
|
{ key: "id", label: "FULL ID", wide: true }
|
|
42
52
|
], { wide, emptyHint: `No invoices yet. Run: ${cli} invoices create --customer <ref> --currency USD --line "<desc>|<qty>|<price>"` });
|
|
43
53
|
summary(`${res.invoices.length} invoice${res.invoices.length !== 1 ? "s" : ""}`);
|
|
44
54
|
}, "id");
|
|
45
55
|
};
|
|
46
|
-
const cmd = new Command("invoices").aliases(["inv", "invoice"]).description("Manage invoices (org-scoped \u2014 run `use <org>` first)").option(...outputOption())
|
|
56
|
+
const cmd = new Command("invoices").aliases(["inv", "invoice"]).description("Manage invoices (org-scoped \u2014 run `use <org>` first)").option(...outputOption());
|
|
57
|
+
filterOptions(cmd).action(listInvoices);
|
|
47
58
|
cmd.addCommand(
|
|
48
|
-
new Command("ls").description("List invoices (alias of the bare command)").option(...outputOption())
|
|
59
|
+
filterOptions(new Command("ls").description("List invoices (alias of the bare command)").option(...outputOption())).action(function() {
|
|
49
60
|
const self = this.opts();
|
|
50
61
|
const parent = this.parent?.opts() ?? {};
|
|
51
62
|
return listInvoices({
|
|
52
63
|
output: self.output && self.output !== "table" ? self.output : parent.output ?? "table",
|
|
53
|
-
status: self.status ?? parent.status
|
|
64
|
+
...self.status ?? parent.status ? { status: self.status ?? parent.status } : {},
|
|
65
|
+
...self.paymentStatus ?? parent.paymentStatus ? { paymentStatus: self.paymentStatus ?? parent.paymentStatus } : {},
|
|
66
|
+
...self.overdue ?? parent.overdue ? { overdue: true } : {},
|
|
67
|
+
...self.source ?? parent.source ? { source: self.source ?? parent.source } : {},
|
|
68
|
+
...self.fiscalStatus ?? parent.fiscalStatus ? { fiscalStatus: self.fiscalStatus ?? parent.fiscalStatus } : {},
|
|
69
|
+
...self.customerId ?? parent.customerId ? { customerId: self.customerId ?? parent.customerId } : {}
|
|
54
70
|
});
|
|
55
71
|
})
|
|
56
72
|
);
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InvoiceStatus } from './events.js';
|
|
1
|
+
import { FiscalStatus, InvoiceStatus, InvoiceSource } from './events.js';
|
|
2
2
|
import '@baseworks/foldbase';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
@@ -18,6 +18,19 @@ interface InvoiceRow {
|
|
|
18
18
|
due_at: number;
|
|
19
19
|
created_at: number;
|
|
20
20
|
updated_at: number;
|
|
21
|
+
source: string | null;
|
|
22
|
+
mirror_key: string | null;
|
|
23
|
+
external_refs: string | null;
|
|
24
|
+
metadata: string | null;
|
|
25
|
+
tax_cents: number | null;
|
|
26
|
+
paid_at: number | null;
|
|
27
|
+
voided_at: number | null;
|
|
28
|
+
provider_updated_at: number | null;
|
|
29
|
+
fiscal_status: string | null;
|
|
30
|
+
fiscal_system: string | null;
|
|
31
|
+
fiscal_external_id: string | null;
|
|
32
|
+
fiscal_message: string | null;
|
|
33
|
+
fiscal_updated_at: number | null;
|
|
21
34
|
}
|
|
22
35
|
interface InvoiceLineDto {
|
|
23
36
|
description: string;
|
|
@@ -39,6 +52,35 @@ interface InvoiceLineDeprecated {
|
|
|
39
52
|
productId: string | null;
|
|
40
53
|
}
|
|
41
54
|
type InvoiceLine = InvoiceLineDto & InvoiceLineDeprecated;
|
|
55
|
+
/** A reference to the same document in another system. At most 10 per invoice. */
|
|
56
|
+
interface ExternalRef {
|
|
57
|
+
system: string;
|
|
58
|
+
id: string;
|
|
59
|
+
number?: string;
|
|
60
|
+
url?: string;
|
|
61
|
+
pdf_url?: string;
|
|
62
|
+
account_id?: string;
|
|
63
|
+
livemode?: boolean;
|
|
64
|
+
}
|
|
65
|
+
type Metadata = Record<string, string | number | boolean | null>;
|
|
66
|
+
/** `unpaid`, `partially_paid`, `paid`; `not_due` for a draft and a void invoice. Derived, never stored. */
|
|
67
|
+
type PaymentStatus = 'unpaid' | 'partially_paid' | 'paid' | 'not_due';
|
|
68
|
+
interface Fiscal {
|
|
69
|
+
status: FiscalStatus;
|
|
70
|
+
system: string | null;
|
|
71
|
+
external_id: string | null;
|
|
72
|
+
message: string | null;
|
|
73
|
+
updated_at: number;
|
|
74
|
+
}
|
|
75
|
+
/** One payment on an invoice, as `GET /invoices/:ref` lists them. */
|
|
76
|
+
interface InvoicePayment {
|
|
77
|
+
payment_id: string;
|
|
78
|
+
amount_cents: number;
|
|
79
|
+
currency: string;
|
|
80
|
+
method: string | null;
|
|
81
|
+
reference: string | null;
|
|
82
|
+
paid_at: number;
|
|
83
|
+
}
|
|
42
84
|
interface InvoiceDto {
|
|
43
85
|
id: string;
|
|
44
86
|
short_id: string;
|
|
@@ -58,6 +100,15 @@ interface InvoiceDto {
|
|
|
58
100
|
due_at: number | null;
|
|
59
101
|
created_at: number;
|
|
60
102
|
updated_at: number;
|
|
103
|
+
/** `local` (made here), `stripe`, `manual` (entered from a document issued elsewhere). Old invoices are `local`. */
|
|
104
|
+
source: InvoiceSource;
|
|
105
|
+
external_refs: ExternalRef[];
|
|
106
|
+
metadata: Metadata;
|
|
107
|
+
tax_cents: number;
|
|
108
|
+
payment_status: PaymentStatus;
|
|
109
|
+
fiscal: Fiscal | null;
|
|
110
|
+
/** Only `GET /invoices/:ref` includes the payments. */
|
|
111
|
+
payments?: InvoicePayment[];
|
|
61
112
|
}
|
|
62
113
|
interface InvoiceDeprecated {
|
|
63
114
|
/** @deprecated Read `short_id`. */
|
|
@@ -103,12 +154,15 @@ interface CreateInvoiceInput {
|
|
|
103
154
|
customer_id?: string;
|
|
104
155
|
currency: string;
|
|
105
156
|
lines: InvoiceLineInput[];
|
|
157
|
+
metadata?: Metadata;
|
|
106
158
|
/** @deprecated Send `customer_id`. */
|
|
107
159
|
customerId?: string;
|
|
108
160
|
}
|
|
109
161
|
interface UpdateInvoiceInput {
|
|
110
162
|
customer_id?: string;
|
|
111
163
|
lines?: InvoiceLineInput[];
|
|
164
|
+
/** Replaces the invoice's metadata. */
|
|
165
|
+
metadata?: Metadata;
|
|
112
166
|
/** @deprecated Send `customer_id`. */
|
|
113
167
|
customerId?: string;
|
|
114
168
|
}
|
|
@@ -126,9 +180,61 @@ interface RecordPaymentInput {
|
|
|
126
180
|
amount_cents?: number;
|
|
127
181
|
method?: string;
|
|
128
182
|
reference?: string;
|
|
183
|
+
/** The pay record this settles. Idempotency key: the same id twice changes nothing. */
|
|
184
|
+
payment_id?: string;
|
|
129
185
|
/** @deprecated Send `amount_cents`. */
|
|
130
186
|
amountCents?: number;
|
|
131
187
|
}
|
|
188
|
+
interface ListInvoicesOptions {
|
|
189
|
+
limit?: number;
|
|
190
|
+
offset?: number;
|
|
191
|
+
status?: string;
|
|
192
|
+
/** One or several (an array is sent comma-separated). */
|
|
193
|
+
payment_status?: PaymentStatus | PaymentStatus[];
|
|
194
|
+
/** Unpaid or partially paid, with a due date in the past. */
|
|
195
|
+
overdue?: boolean;
|
|
196
|
+
source?: InvoiceSource;
|
|
197
|
+
fiscal_status?: FiscalStatus;
|
|
198
|
+
customer_id?: string;
|
|
199
|
+
}
|
|
200
|
+
/** The provider's whole document, for `PUT /invoices/mirror`. */
|
|
201
|
+
interface MirrorInvoiceInput {
|
|
202
|
+
source: 'stripe' | 'manual';
|
|
203
|
+
external_ref: ExternalRef;
|
|
204
|
+
customer_id: string;
|
|
205
|
+
currency: string;
|
|
206
|
+
lines: Array<{
|
|
207
|
+
description: string;
|
|
208
|
+
quantity: number;
|
|
209
|
+
unit_price_cents: number;
|
|
210
|
+
amount_cents: number;
|
|
211
|
+
product_id?: string;
|
|
212
|
+
}>;
|
|
213
|
+
subtotal_cents: number;
|
|
214
|
+
tax_cents: number;
|
|
215
|
+
total_cents: number;
|
|
216
|
+
status: 'finalized' | 'paid' | 'void';
|
|
217
|
+
issued_at: number;
|
|
218
|
+
due_at?: number;
|
|
219
|
+
paid_at?: number;
|
|
220
|
+
voided_at?: number;
|
|
221
|
+
/** The provider's own "updated" time: an upsert older than what is stored is ignored. */
|
|
222
|
+
provider_updated_at: number;
|
|
223
|
+
metadata?: Metadata;
|
|
224
|
+
}
|
|
225
|
+
interface MirrorResult {
|
|
226
|
+
invoice: Invoice;
|
|
227
|
+
/** True when this call created the invoice. */
|
|
228
|
+
created: boolean;
|
|
229
|
+
/** True when the document was older than the one stored and was ignored. */
|
|
230
|
+
stale?: boolean;
|
|
231
|
+
}
|
|
232
|
+
interface FiscalInput {
|
|
233
|
+
status: FiscalStatus;
|
|
234
|
+
system?: string;
|
|
235
|
+
external_id?: string;
|
|
236
|
+
message?: string;
|
|
237
|
+
}
|
|
132
238
|
interface TransactionRow {
|
|
133
239
|
id: string;
|
|
134
240
|
invoice_id: string;
|
|
@@ -140,6 +246,7 @@ interface TransactionRow {
|
|
|
140
246
|
currency: string;
|
|
141
247
|
method: string;
|
|
142
248
|
reference: string;
|
|
249
|
+
payment_id: string | null;
|
|
143
250
|
created_at: number;
|
|
144
251
|
updated_at: number;
|
|
145
252
|
}
|
|
@@ -154,6 +261,7 @@ interface TransactionDto {
|
|
|
154
261
|
currency: string;
|
|
155
262
|
method: string | null;
|
|
156
263
|
reference: string | null;
|
|
264
|
+
payment_id: string | null;
|
|
157
265
|
created_at: number;
|
|
158
266
|
}
|
|
159
267
|
interface TransactionDeprecated {
|
|
@@ -220,14 +328,17 @@ declare class InvoiceClient {
|
|
|
220
328
|
api<T>(method: string, path: string, body?: unknown, extra?: Record<string, string>): Promise<T>;
|
|
221
329
|
/** Generic ApiClient (get/post/patch/del) — used by the CLI plugin. */
|
|
222
330
|
get http(): HttpClient;
|
|
223
|
-
list(opts?:
|
|
224
|
-
limit?: number;
|
|
225
|
-
offset?: number;
|
|
226
|
-
status?: string;
|
|
227
|
-
}): Promise<Invoice[]>;
|
|
331
|
+
list(opts?: ListInvoicesOptions): Promise<Invoice[]>;
|
|
228
332
|
get(ref: string): Promise<Invoice>;
|
|
229
333
|
create(input: CreateInvoiceInput): Promise<Invoice>;
|
|
230
334
|
update(ref: string, input: UpdateInvoiceInput): Promise<Invoice>;
|
|
335
|
+
/**
|
|
336
|
+
* Keep the provider's document (Stripe's invoice, a hand-entered one) as this invoice: creates it or replaces it by
|
|
337
|
+
* `external_ref` (system + id). An older document than the one stored is ignored (`stale`). Needs `invoice.mirror`.
|
|
338
|
+
*/
|
|
339
|
+
mirror(input: MirrorInvoiceInput): Promise<MirrorResult>;
|
|
340
|
+
/** Record where the invoice stands with a tax system. Needs `invoice.fiscal_update`; nothing is sent to any tax system. */
|
|
341
|
+
setFiscal(ref: string, input: FiscalInput): Promise<Invoice>;
|
|
231
342
|
finalize(ref: string, input?: FinalizeInvoiceInput): Promise<Invoice>;
|
|
232
343
|
recordPayment(ref: string, input: RecordPaymentInput): Promise<Invoice>;
|
|
233
344
|
void(ref: string, reason?: string): Promise<Invoice>;
|
|
@@ -242,4 +353,4 @@ declare class InvoiceClient {
|
|
|
242
353
|
/** Factory used by the SDK capability registry. */
|
|
243
354
|
declare function createInvoiceClient(opts: InvoiceClientOptions): InvoiceClient;
|
|
244
355
|
|
|
245
|
-
export { type CreateInvoiceInput, type FinalizeInvoiceInput, type HttpClient, type Invoice, InvoiceClient, type InvoiceClientOptions, type InvoiceDeprecated, type InvoiceDto, InvoiceError, type InvoiceLine, type InvoiceLineDeprecated, type InvoiceLineDto, type InvoiceLineInput, type InvoiceRow, InvoiceStatus, type RecordPaymentInput, type Transaction, type TransactionDeprecated, type TransactionDto, type TransactionRow, type UpdateInvoiceInput, createInvoiceClient };
|
|
356
|
+
export { type CreateInvoiceInput, type ExternalRef, type FinalizeInvoiceInput, type Fiscal, type FiscalInput, FiscalStatus, type HttpClient, type Invoice, InvoiceClient, type InvoiceClientOptions, type InvoiceDeprecated, type InvoiceDto, InvoiceError, type InvoiceLine, type InvoiceLineDeprecated, type InvoiceLineDto, type InvoiceLineInput, type InvoicePayment, type InvoiceRow, InvoiceSource, InvoiceStatus, type ListInvoicesOptions, type Metadata, type MirrorInvoiceInput, type MirrorResult, type PaymentStatus, type RecordPaymentInput, type Transaction, type TransactionDeprecated, type TransactionDto, type TransactionRow, type UpdateInvoiceInput, createInvoiceClient };
|
package/dist/client.js
CHANGED
|
@@ -119,6 +119,11 @@ var InvoiceClient = class _InvoiceClient {
|
|
|
119
119
|
if (opts.limit !== void 0) q.set("limit", String(opts.limit));
|
|
120
120
|
if (opts.offset !== void 0) q.set("offset", String(opts.offset));
|
|
121
121
|
if (opts.status) q.set("status", opts.status);
|
|
122
|
+
if (opts.payment_status) q.set("payment_status", [opts.payment_status].flat().join(","));
|
|
123
|
+
if (opts.overdue !== void 0) q.set("overdue", String(opts.overdue));
|
|
124
|
+
if (opts.source) q.set("source", opts.source);
|
|
125
|
+
if (opts.fiscal_status) q.set("fiscal_status", opts.fiscal_status);
|
|
126
|
+
if (opts.customer_id) q.set("customer_id", opts.customer_id);
|
|
122
127
|
const qs = q.toString();
|
|
123
128
|
const { invoices } = await this.api("GET", `/invoices${qs ? `?${qs}` : ""}`);
|
|
124
129
|
return invoices.map(oldNamesOnInvoice);
|
|
@@ -135,6 +140,19 @@ var InvoiceClient = class _InvoiceClient {
|
|
|
135
140
|
const { invoice } = await this.api("PATCH", `/invoices/${ref}`, newNamesOnLines(input));
|
|
136
141
|
return oldNamesOnInvoice(invoice);
|
|
137
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Keep the provider's document (Stripe's invoice, a hand-entered one) as this invoice: creates it or replaces it by
|
|
145
|
+
* `external_ref` (system + id). An older document than the one stored is ignored (`stale`). Needs `invoice.mirror`.
|
|
146
|
+
*/
|
|
147
|
+
async mirror(input) {
|
|
148
|
+
const r = await this.api("PUT", "/invoices/mirror", input);
|
|
149
|
+
return { ...r, invoice: oldNamesOnInvoice(r.invoice) };
|
|
150
|
+
}
|
|
151
|
+
/** Record where the invoice stands with a tax system. Needs `invoice.fiscal_update`; nothing is sent to any tax system. */
|
|
152
|
+
async setFiscal(ref, input) {
|
|
153
|
+
const { invoice } = await this.api("PUT", `/invoices/${ref}/fiscal`, input);
|
|
154
|
+
return oldNamesOnInvoice(invoice);
|
|
155
|
+
}
|
|
138
156
|
async finalize(ref, input = {}) {
|
|
139
157
|
const { invoice } = await this.api("POST", `/invoices/${ref}/finalize`, newNamesOnFinalize(input));
|
|
140
158
|
return oldNamesOnInvoice(invoice);
|
package/dist/events.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
33
33
|
subtotal_cents: z.ZodNumber;
|
|
34
34
|
total_cents: z.ZodNumber;
|
|
35
35
|
short_id: z.ZodString;
|
|
36
|
+
source: z.ZodOptional<z.ZodString>;
|
|
37
|
+
metadata: z.ZodOptional<z.ZodString>;
|
|
36
38
|
at: z.ZodNumber;
|
|
37
39
|
}, "strip", z.ZodTypeAny, {
|
|
38
40
|
at: number;
|
|
@@ -43,6 +45,8 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
43
45
|
currency: string;
|
|
44
46
|
subtotal_cents: number;
|
|
45
47
|
total_cents: number;
|
|
48
|
+
source?: string | undefined;
|
|
49
|
+
metadata?: string | undefined;
|
|
46
50
|
}, {
|
|
47
51
|
at: number;
|
|
48
52
|
lines: string;
|
|
@@ -52,6 +56,8 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
52
56
|
currency: string;
|
|
53
57
|
subtotal_cents: number;
|
|
54
58
|
total_cents: number;
|
|
59
|
+
source?: string | undefined;
|
|
60
|
+
metadata?: string | undefined;
|
|
55
61
|
}>;
|
|
56
62
|
InvoiceUpdated: z.ZodObject<{
|
|
57
63
|
customer_id: z.ZodString;
|
|
@@ -59,6 +65,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
59
65
|
lines: z.ZodString;
|
|
60
66
|
subtotal_cents: z.ZodNumber;
|
|
61
67
|
total_cents: z.ZodNumber;
|
|
68
|
+
metadata: z.ZodOptional<z.ZodString>;
|
|
62
69
|
at: z.ZodNumber;
|
|
63
70
|
}, "strip", z.ZodTypeAny, {
|
|
64
71
|
at: number;
|
|
@@ -67,6 +74,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
67
74
|
customer_name: string;
|
|
68
75
|
subtotal_cents: number;
|
|
69
76
|
total_cents: number;
|
|
77
|
+
metadata?: string | undefined;
|
|
70
78
|
}, {
|
|
71
79
|
at: number;
|
|
72
80
|
lines: string;
|
|
@@ -74,6 +82,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
74
82
|
customer_name: string;
|
|
75
83
|
subtotal_cents: number;
|
|
76
84
|
total_cents: number;
|
|
85
|
+
metadata?: string | undefined;
|
|
77
86
|
}>;
|
|
78
87
|
InvoiceFinalized: z.ZodObject<{
|
|
79
88
|
number: z.ZodNumber;
|
|
@@ -106,21 +115,24 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
106
115
|
status: z.ZodEnum<["draft", "finalized", "paid", "void"]>;
|
|
107
116
|
method: z.ZodString;
|
|
108
117
|
reference: z.ZodString;
|
|
118
|
+
payment_id: z.ZodOptional<z.ZodString>;
|
|
109
119
|
at: z.ZodNumber;
|
|
110
120
|
}, "strip", z.ZodTypeAny, {
|
|
111
121
|
method: string;
|
|
112
122
|
at: number;
|
|
113
|
-
status: "
|
|
123
|
+
status: "paid" | "draft" | "finalized" | "void";
|
|
114
124
|
amount_paid_cents: number;
|
|
115
125
|
amount_cents: number;
|
|
116
126
|
reference: string;
|
|
127
|
+
payment_id?: string | undefined;
|
|
117
128
|
}, {
|
|
118
129
|
method: string;
|
|
119
130
|
at: number;
|
|
120
|
-
status: "
|
|
131
|
+
status: "paid" | "draft" | "finalized" | "void";
|
|
121
132
|
amount_paid_cents: number;
|
|
122
133
|
amount_cents: number;
|
|
123
134
|
reference: string;
|
|
135
|
+
payment_id?: string | undefined;
|
|
124
136
|
}>;
|
|
125
137
|
InvoiceVoided: z.ZodObject<{
|
|
126
138
|
reason: z.ZodString;
|
|
@@ -132,9 +144,99 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
132
144
|
at: number;
|
|
133
145
|
reason: string;
|
|
134
146
|
}>;
|
|
147
|
+
InvoiceMirrored: z.ZodObject<{
|
|
148
|
+
source: z.ZodString;
|
|
149
|
+
mirror_key: z.ZodString;
|
|
150
|
+
external_refs: z.ZodString;
|
|
151
|
+
customer_id: z.ZodString;
|
|
152
|
+
customer_name: z.ZodString;
|
|
153
|
+
currency: z.ZodString;
|
|
154
|
+
lines: z.ZodString;
|
|
155
|
+
subtotal_cents: z.ZodNumber;
|
|
156
|
+
tax_cents: z.ZodNumber;
|
|
157
|
+
total_cents: z.ZodNumber;
|
|
158
|
+
amount_paid_cents: z.ZodNumber;
|
|
159
|
+
status: z.ZodEnum<["draft", "finalized", "paid", "void"]>;
|
|
160
|
+
issued_at: z.ZodNumber;
|
|
161
|
+
due_at: z.ZodNumber;
|
|
162
|
+
paid_at: z.ZodNumber;
|
|
163
|
+
voided_at: z.ZodNumber;
|
|
164
|
+
provider_updated_at: z.ZodNumber;
|
|
165
|
+
metadata: z.ZodString;
|
|
166
|
+
short_id: z.ZodString;
|
|
167
|
+
created_at: z.ZodNumber;
|
|
168
|
+
at: z.ZodNumber;
|
|
169
|
+
}, "strip", z.ZodTypeAny, {
|
|
170
|
+
at: number;
|
|
171
|
+
lines: string;
|
|
172
|
+
short_id: string;
|
|
173
|
+
status: "paid" | "draft" | "finalized" | "void";
|
|
174
|
+
customer_id: string;
|
|
175
|
+
customer_name: string;
|
|
176
|
+
currency: string;
|
|
177
|
+
subtotal_cents: number;
|
|
178
|
+
total_cents: number;
|
|
179
|
+
amount_paid_cents: number;
|
|
180
|
+
issued_at: number;
|
|
181
|
+
due_at: number;
|
|
182
|
+
created_at: number;
|
|
183
|
+
source: string;
|
|
184
|
+
external_refs: string;
|
|
185
|
+
metadata: string;
|
|
186
|
+
tax_cents: number;
|
|
187
|
+
mirror_key: string;
|
|
188
|
+
paid_at: number;
|
|
189
|
+
voided_at: number;
|
|
190
|
+
provider_updated_at: number;
|
|
191
|
+
}, {
|
|
192
|
+
at: number;
|
|
193
|
+
lines: string;
|
|
194
|
+
short_id: string;
|
|
195
|
+
status: "paid" | "draft" | "finalized" | "void";
|
|
196
|
+
customer_id: string;
|
|
197
|
+
customer_name: string;
|
|
198
|
+
currency: string;
|
|
199
|
+
subtotal_cents: number;
|
|
200
|
+
total_cents: number;
|
|
201
|
+
amount_paid_cents: number;
|
|
202
|
+
issued_at: number;
|
|
203
|
+
due_at: number;
|
|
204
|
+
created_at: number;
|
|
205
|
+
source: string;
|
|
206
|
+
external_refs: string;
|
|
207
|
+
metadata: string;
|
|
208
|
+
tax_cents: number;
|
|
209
|
+
mirror_key: string;
|
|
210
|
+
paid_at: number;
|
|
211
|
+
voided_at: number;
|
|
212
|
+
provider_updated_at: number;
|
|
213
|
+
}>;
|
|
214
|
+
InvoiceFiscalChanged: z.ZodObject<{
|
|
215
|
+
status: z.ZodString;
|
|
216
|
+
system: z.ZodString;
|
|
217
|
+
external_id: z.ZodString;
|
|
218
|
+
message: z.ZodString;
|
|
219
|
+
at: z.ZodNumber;
|
|
220
|
+
}, "strip", z.ZodTypeAny, {
|
|
221
|
+
at: number;
|
|
222
|
+
status: string;
|
|
223
|
+
message: string;
|
|
224
|
+
system: string;
|
|
225
|
+
external_id: string;
|
|
226
|
+
}, {
|
|
227
|
+
at: number;
|
|
228
|
+
status: string;
|
|
229
|
+
message: string;
|
|
230
|
+
system: string;
|
|
231
|
+
external_id: string;
|
|
232
|
+
}>;
|
|
135
233
|
}> & {
|
|
136
234
|
newId(): string;
|
|
137
235
|
};
|
|
236
|
+
declare const FISCAL_STATUSES: readonly ["not_submitted", "queued", "submitted", "accepted", "rejected", "cancelled"];
|
|
237
|
+
type FiscalStatus = (typeof FISCAL_STATUSES)[number];
|
|
238
|
+
declare const INVOICE_SOURCES: readonly ["local", "stripe", "manual"];
|
|
239
|
+
type InvoiceSource = (typeof INVOICE_SOURCES)[number];
|
|
138
240
|
/**
|
|
139
241
|
* The transaction ledger — one stream (and one read-model row) PER money movement,
|
|
140
242
|
* unlike the invoice's cached `amount_paid`. A payment emits BOTH `PaymentRecorded`
|
|
@@ -155,6 +257,7 @@ declare const TransactionEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
155
257
|
currency: z.ZodString;
|
|
156
258
|
method: z.ZodString;
|
|
157
259
|
reference: z.ZodString;
|
|
260
|
+
payment_id: z.ZodOptional<z.ZodString>;
|
|
158
261
|
at: z.ZodNumber;
|
|
159
262
|
}, "strip", z.ZodTypeAny, {
|
|
160
263
|
method: string;
|
|
@@ -167,6 +270,7 @@ declare const TransactionEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
167
270
|
invoice_number: number;
|
|
168
271
|
reference: string;
|
|
169
272
|
kind: "payment" | "refund" | "adjustment";
|
|
273
|
+
payment_id?: string | undefined;
|
|
170
274
|
}, {
|
|
171
275
|
method: string;
|
|
172
276
|
at: number;
|
|
@@ -178,9 +282,10 @@ declare const TransactionEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
178
282
|
invoice_number: number;
|
|
179
283
|
reference: string;
|
|
180
284
|
kind: "payment" | "refund" | "adjustment";
|
|
285
|
+
payment_id?: string | undefined;
|
|
181
286
|
}>;
|
|
182
287
|
}> & {
|
|
183
288
|
newId(): string;
|
|
184
289
|
};
|
|
185
290
|
|
|
186
|
-
export { InvoiceEvents, InvoiceStatus, TransactionEvents, TransactionKind };
|
|
291
|
+
export { FISCAL_STATUSES, type FiscalStatus, INVOICE_SOURCES, InvoiceEvents, type InvoiceSource, InvoiceStatus, TransactionEvents, TransactionKind };
|
package/dist/events.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
FISCAL_STATUSES,
|
|
3
|
+
INVOICE_SOURCES,
|
|
2
4
|
InvoiceEvents,
|
|
3
5
|
InvoiceStatus,
|
|
4
6
|
TransactionEvents,
|
|
5
7
|
TransactionKind
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-335MPCTE.js";
|
|
7
9
|
export {
|
|
10
|
+
FISCAL_STATUSES,
|
|
11
|
+
INVOICE_SOURCES,
|
|
8
12
|
InvoiceEvents,
|
|
9
13
|
InvoiceStatus,
|
|
10
14
|
TransactionEvents,
|