@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/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InvoiceStatus } from './events.js'
|
|
2
|
-
export type { InvoiceStatus } from './events.js'
|
|
1
|
+
import type { FiscalStatus, InvoiceSource, InvoiceStatus } from './events.js'
|
|
2
|
+
export type { FiscalStatus, InvoiceSource, InvoiceStatus } from './events.js'
|
|
3
3
|
|
|
4
4
|
// ── read-model row (snake_case — foldbase read_invoices table) ────────────────
|
|
5
5
|
|
|
@@ -19,6 +19,20 @@ export interface InvoiceRow {
|
|
|
19
19
|
due_at: number // 0 = none
|
|
20
20
|
created_at: number
|
|
21
21
|
updated_at: number
|
|
22
|
+
// 1.1.0: NULL on rows written before it (read as `local`, no refs, `{}`, no tax, no fiscal state).
|
|
23
|
+
source: string | null
|
|
24
|
+
mirror_key: string | null
|
|
25
|
+
external_refs: string | null // JSON array
|
|
26
|
+
metadata: string | null // JSON object
|
|
27
|
+
tax_cents: number | null
|
|
28
|
+
paid_at: number | null
|
|
29
|
+
voided_at: number | null
|
|
30
|
+
provider_updated_at: number | null
|
|
31
|
+
fiscal_status: string | null
|
|
32
|
+
fiscal_system: string | null
|
|
33
|
+
fiscal_external_id: string | null
|
|
34
|
+
fiscal_message: string | null
|
|
35
|
+
fiscal_updated_at: number | null
|
|
22
36
|
}
|
|
23
37
|
|
|
24
38
|
// ── REST DTOs (snake_case, as every service in the realm speaks: ADR-0003) ───
|
|
@@ -51,6 +65,40 @@ export interface InvoiceLineDeprecated {
|
|
|
51
65
|
}
|
|
52
66
|
export type InvoiceLine = InvoiceLineDto & InvoiceLineDeprecated
|
|
53
67
|
|
|
68
|
+
/** A reference to the same document in another system. At most 10 per invoice. */
|
|
69
|
+
export interface ExternalRef {
|
|
70
|
+
system: string
|
|
71
|
+
id: string
|
|
72
|
+
number?: string
|
|
73
|
+
url?: string
|
|
74
|
+
pdf_url?: string
|
|
75
|
+
account_id?: string
|
|
76
|
+
livemode?: boolean
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type Metadata = Record<string, string | number | boolean | null>
|
|
80
|
+
|
|
81
|
+
/** `unpaid`, `partially_paid`, `paid`; `not_due` for a draft and a void invoice. Derived, never stored. */
|
|
82
|
+
export type PaymentStatus = 'unpaid' | 'partially_paid' | 'paid' | 'not_due'
|
|
83
|
+
|
|
84
|
+
export interface Fiscal {
|
|
85
|
+
status: FiscalStatus
|
|
86
|
+
system: string | null
|
|
87
|
+
external_id: string | null
|
|
88
|
+
message: string | null
|
|
89
|
+
updated_at: number
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One payment on an invoice, as `GET /invoices/:ref` lists them. */
|
|
93
|
+
export interface InvoicePayment {
|
|
94
|
+
payment_id: string
|
|
95
|
+
amount_cents: number
|
|
96
|
+
currency: string
|
|
97
|
+
method: string | null
|
|
98
|
+
reference: string | null
|
|
99
|
+
paid_at: number
|
|
100
|
+
}
|
|
101
|
+
|
|
54
102
|
export interface InvoiceDto {
|
|
55
103
|
id: string
|
|
56
104
|
short_id: string
|
|
@@ -70,6 +118,15 @@ export interface InvoiceDto {
|
|
|
70
118
|
due_at: number | null
|
|
71
119
|
created_at: number
|
|
72
120
|
updated_at: number
|
|
121
|
+
/** `local` (made here), `stripe`, `manual` (entered from a document issued elsewhere). Old invoices are `local`. */
|
|
122
|
+
source: InvoiceSource
|
|
123
|
+
external_refs: ExternalRef[]
|
|
124
|
+
metadata: Metadata
|
|
125
|
+
tax_cents: number
|
|
126
|
+
payment_status: PaymentStatus
|
|
127
|
+
fiscal: Fiscal | null
|
|
128
|
+
/** Only `GET /invoices/:ref` includes the payments. */
|
|
129
|
+
payments?: InvoicePayment[]
|
|
73
130
|
}
|
|
74
131
|
|
|
75
132
|
export interface InvoiceDeprecated {
|
|
@@ -116,6 +173,7 @@ export interface CreateInvoiceInput {
|
|
|
116
173
|
customer_id?: string
|
|
117
174
|
currency: string
|
|
118
175
|
lines: InvoiceLineInput[]
|
|
176
|
+
metadata?: Metadata
|
|
119
177
|
/** @deprecated Send `customer_id`. */
|
|
120
178
|
customerId?: string
|
|
121
179
|
}
|
|
@@ -123,6 +181,8 @@ export interface CreateInvoiceInput {
|
|
|
123
181
|
export interface UpdateInvoiceInput {
|
|
124
182
|
customer_id?: string
|
|
125
183
|
lines?: InvoiceLineInput[]
|
|
184
|
+
/** Replaces the invoice's metadata. */
|
|
185
|
+
metadata?: Metadata
|
|
126
186
|
/** @deprecated Send `customer_id`. */
|
|
127
187
|
customerId?: string
|
|
128
188
|
}
|
|
@@ -142,10 +202,60 @@ export interface RecordPaymentInput {
|
|
|
142
202
|
amount_cents?: number
|
|
143
203
|
method?: string
|
|
144
204
|
reference?: string
|
|
205
|
+
/** The pay record this settles. Idempotency key: the same id twice changes nothing. */
|
|
206
|
+
payment_id?: string
|
|
145
207
|
/** @deprecated Send `amount_cents`. */
|
|
146
208
|
amountCents?: number
|
|
147
209
|
}
|
|
148
210
|
|
|
211
|
+
export interface ListInvoicesOptions {
|
|
212
|
+
limit?: number
|
|
213
|
+
offset?: number
|
|
214
|
+
status?: string
|
|
215
|
+
/** One or several (an array is sent comma-separated). */
|
|
216
|
+
payment_status?: PaymentStatus | PaymentStatus[]
|
|
217
|
+
/** Unpaid or partially paid, with a due date in the past. */
|
|
218
|
+
overdue?: boolean
|
|
219
|
+
source?: InvoiceSource
|
|
220
|
+
fiscal_status?: FiscalStatus
|
|
221
|
+
customer_id?: string
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** The provider's whole document, for `PUT /invoices/mirror`. */
|
|
225
|
+
export interface MirrorInvoiceInput {
|
|
226
|
+
source: 'stripe' | 'manual'
|
|
227
|
+
external_ref: ExternalRef
|
|
228
|
+
customer_id: string
|
|
229
|
+
currency: string
|
|
230
|
+
lines: Array<{ description: string; quantity: number; unit_price_cents: number; amount_cents: number; product_id?: string }>
|
|
231
|
+
subtotal_cents: number
|
|
232
|
+
tax_cents: number
|
|
233
|
+
total_cents: number
|
|
234
|
+
status: 'finalized' | 'paid' | 'void'
|
|
235
|
+
issued_at: number
|
|
236
|
+
due_at?: number
|
|
237
|
+
paid_at?: number
|
|
238
|
+
voided_at?: number
|
|
239
|
+
/** The provider's own "updated" time: an upsert older than what is stored is ignored. */
|
|
240
|
+
provider_updated_at: number
|
|
241
|
+
metadata?: Metadata
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface MirrorResult {
|
|
245
|
+
invoice: Invoice
|
|
246
|
+
/** True when this call created the invoice. */
|
|
247
|
+
created: boolean
|
|
248
|
+
/** True when the document was older than the one stored and was ignored. */
|
|
249
|
+
stale?: boolean
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface FiscalInput {
|
|
253
|
+
status: FiscalStatus
|
|
254
|
+
system?: string
|
|
255
|
+
external_id?: string
|
|
256
|
+
message?: string
|
|
257
|
+
}
|
|
258
|
+
|
|
149
259
|
// ── transactions (the ledger) ─────────────────────────────────────────────────
|
|
150
260
|
|
|
151
261
|
export interface TransactionRow {
|
|
@@ -159,6 +269,7 @@ export interface TransactionRow {
|
|
|
159
269
|
currency: string
|
|
160
270
|
method: string
|
|
161
271
|
reference: string
|
|
272
|
+
payment_id: string | null
|
|
162
273
|
created_at: number
|
|
163
274
|
updated_at: number
|
|
164
275
|
}
|
|
@@ -174,6 +285,7 @@ export interface TransactionDto {
|
|
|
174
285
|
currency: string
|
|
175
286
|
method: string | null
|
|
176
287
|
reference: string | null
|
|
288
|
+
payment_id: string | null
|
|
177
289
|
created_at: number
|
|
178
290
|
}
|
|
179
291
|
|