@baseworks/invoice 1.2.3 → 2.0.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 +37 -27
- package/dist/{chunk-JS6GUXCC.js → chunk-3MXVPVAV.js} +55 -17
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +45 -26
- package/dist/client.d.ts +93 -45
- package/dist/client.js +20 -10
- package/dist/events.d.ts +131 -19
- package/dist/events.js +1 -1
- package/dist/graphql.d.ts +5 -2
- package/dist/graphql.js +4 -2
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +54 -23
- package/dist/projections.js +25 -10
- package/package.json +2 -1
- package/src/__tests__/cli.test.ts +43 -6
- package/src/__tests__/client.test.ts +36 -2
- package/src/__tests__/mcp.test.ts +51 -8
- package/src/cli.ts +69 -33
- package/src/client.ts +31 -12
- package/src/compat.ts +2 -3
- package/src/events.ts +45 -14
- package/src/graphql.ts +4 -2
- package/src/mcp.ts +62 -33
- package/src/projections.ts +21 -7
- package/src/types.ts +76 -26
package/src/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { DocumentDate } from '@baseworks/core/document-date'
|
|
1
2
|
import type { FiscalStatus, InvoiceSource, InvoiceStatus } from './events.js'
|
|
3
|
+
export type { DocumentDate } from '@baseworks/core/document-date'
|
|
2
4
|
export type { FiscalStatus, InvoiceSource, InvoiceStatus } from './events.js'
|
|
3
5
|
|
|
4
6
|
// ── read-model row (snake_case — foldbase read_invoices table) ────────────────
|
|
@@ -15,8 +17,9 @@ export interface InvoiceRow {
|
|
|
15
17
|
subtotal_cents: number
|
|
16
18
|
total_cents: number
|
|
17
19
|
amount_paid_cents: number
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// Before 2.0 (epoch millis): what rows folded from old events hold. Newer rows hold the days below.
|
|
21
|
+
issued_at: number | null // 0 while draft
|
|
22
|
+
due_at: number | null // 0 = none
|
|
20
23
|
created_at: number
|
|
21
24
|
updated_at: number
|
|
22
25
|
// 1.1.0: NULL on rows written before it (read as `local`, no refs, `{}`, no tax, no fiscal state).
|
|
@@ -37,6 +40,12 @@ export interface InvoiceRow {
|
|
|
37
40
|
number_text: string | null
|
|
38
41
|
series_key: string | null
|
|
39
42
|
external_number: string | null
|
|
43
|
+
// 2.0: calendar days `YYYY-MM-DD`
|
|
44
|
+
document_date: string | null
|
|
45
|
+
due_date: string | null
|
|
46
|
+
paid_date: string | null
|
|
47
|
+
void_date: string | null
|
|
48
|
+
void_reason: string | null
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
// ── REST DTOs (snake_case, as every service in the realm speaks: ADR-0003) ───
|
|
@@ -100,7 +109,10 @@ export interface InvoicePayment {
|
|
|
100
109
|
currency: string
|
|
101
110
|
method: string | null
|
|
102
111
|
reference: string | null
|
|
103
|
-
|
|
112
|
+
/** The day of the payment. */
|
|
113
|
+
document_date: DocumentDate
|
|
114
|
+
/** When it was recorded (epoch millis): audit and the order inside one day. */
|
|
115
|
+
created_at: number
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
export interface InvoiceDto {
|
|
@@ -118,8 +130,13 @@ export interface InvoiceDto {
|
|
|
118
130
|
amount_paid_cents: number
|
|
119
131
|
/** total_cents − amount_paid_cents (0 for draft/void semantics aside). */
|
|
120
132
|
balance_cents: number
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
/** The invoice date (calendar day); `null` while a draft. Every period, number and list window follows it. */
|
|
134
|
+
document_date: DocumentDate | null
|
|
135
|
+
due_date: DocumentDate | null
|
|
136
|
+
/** The day of the payment that settled it; `null` unless paid (and for a mirror paid with no date and no payment). */
|
|
137
|
+
paid_date: DocumentDate | null
|
|
138
|
+
void_date: DocumentDate | null
|
|
139
|
+
void_reason: string | null
|
|
123
140
|
created_at: number
|
|
124
141
|
updated_at: number
|
|
125
142
|
/** `local` (made here), `stripe`, `manual` (entered from a document issued elsewhere). Old invoices are `local`. */
|
|
@@ -130,12 +147,15 @@ export interface InvoiceDto {
|
|
|
130
147
|
payment_status: PaymentStatus
|
|
131
148
|
fiscal: Fiscal | null
|
|
132
149
|
/**
|
|
133
|
-
* The number as printed: `BSF2026000000148` in a series, `7` without one
|
|
134
|
-
*
|
|
150
|
+
* The internal number as printed: `BSF2026000000148` in a series, `7` without one. `null` while a draft and for a
|
|
151
|
+
* mirror. (An invoice finalized with an external number before 2.0 took no internal one: `number` is `null` and this
|
|
152
|
+
* holds that external number.)
|
|
135
153
|
*/
|
|
136
154
|
number_text: string | null
|
|
137
|
-
/** A number given by another system (an e-Fatura portal, say), up to 64 characters. Unique among
|
|
155
|
+
/** A number given by another system (an e-Fatura portal, say), up to 64 characters. Unique among the invoices that hold one. */
|
|
138
156
|
external_number: string | null
|
|
157
|
+
/** Read only: `external_number` if there is one, else `number_text`. */
|
|
158
|
+
display_number: string | null
|
|
139
159
|
/** Only `GET /invoices/:ref` includes the payments. */
|
|
140
160
|
payments?: InvoicePayment[]
|
|
141
161
|
}
|
|
@@ -155,10 +175,6 @@ export interface InvoiceDeprecated {
|
|
|
155
175
|
amountPaidCents: number
|
|
156
176
|
/** @deprecated Read `balance_cents`. */
|
|
157
177
|
balanceCents: number
|
|
158
|
-
/** @deprecated Read `issued_at`. */
|
|
159
|
-
issuedAt: number | null
|
|
160
|
-
/** @deprecated Read `due_at`. */
|
|
161
|
-
dueAt: number | null
|
|
162
178
|
/** @deprecated Read `created_at`. */
|
|
163
179
|
createdAt: number
|
|
164
180
|
/** @deprecated Read `updated_at`. */
|
|
@@ -185,7 +201,7 @@ export interface CreateInvoiceInput {
|
|
|
185
201
|
currency: string
|
|
186
202
|
lines: InvoiceLineInput[]
|
|
187
203
|
metadata?: Metadata
|
|
188
|
-
/** A number from another system; the invoice keeps it
|
|
204
|
+
/** A number from another system; the invoice keeps it beside the internal number it gets at finalize. */
|
|
189
205
|
external_number?: string
|
|
190
206
|
/** @deprecated Send `customer_id`. */
|
|
191
207
|
customerId?: string
|
|
@@ -203,15 +219,19 @@ export interface UpdateInvoiceInput {
|
|
|
203
219
|
}
|
|
204
220
|
|
|
205
221
|
export interface FinalizeInvoiceInput {
|
|
206
|
-
/**
|
|
222
|
+
/** `YYYY-MM-DD`; defaults to today (UTC) server-side; a future date is refused. */
|
|
223
|
+
document_date?: DocumentDate | string
|
|
224
|
+
/** `YYYY-MM-DD`; omitted = no due date. */
|
|
225
|
+
due_date?: DocumentDate | string
|
|
226
|
+
/** The number another system gave it, kept beside the internal number. */
|
|
227
|
+
external_number?: string
|
|
228
|
+
/** @deprecated Send `document_date`. Epoch millis, read as its UTC day; not together with `document_date`. */
|
|
207
229
|
issued_at?: number
|
|
208
|
-
/** Epoch millis
|
|
230
|
+
/** @deprecated Send `due_date`. Epoch millis, read as its UTC day (0 = none); not together with `due_date`. */
|
|
209
231
|
due_at?: number
|
|
210
|
-
/**
|
|
211
|
-
external_number?: string
|
|
212
|
-
/** @deprecated Send `issued_at`. */
|
|
232
|
+
/** @deprecated Send `document_date`. */
|
|
213
233
|
issuedAt?: number
|
|
214
|
-
/** @deprecated Send `
|
|
234
|
+
/** @deprecated Send `due_date`. */
|
|
215
235
|
dueAt?: number
|
|
216
236
|
}
|
|
217
237
|
|
|
@@ -221,17 +241,34 @@ export interface RecordPaymentInput {
|
|
|
221
241
|
reference?: string
|
|
222
242
|
/** The pay record this settles. Idempotency key: the same id twice changes nothing. */
|
|
223
243
|
payment_id?: string
|
|
244
|
+
/** The day of the payment, `YYYY-MM-DD`; defaults to today (UTC); a future date is refused. */
|
|
245
|
+
document_date?: DocumentDate | string
|
|
224
246
|
/** @deprecated Send `amount_cents`. */
|
|
225
247
|
amountCents?: number
|
|
226
248
|
}
|
|
227
249
|
|
|
250
|
+
export interface VoidInvoiceInput {
|
|
251
|
+
/** `YYYY-MM-DD`; defaults to today (UTC); a future date is refused. */
|
|
252
|
+
void_date?: DocumentDate | string
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** The `from` / `to` window of a list: calendar days, both included, compared with `document_date`. */
|
|
256
|
+
export interface DocumentDateRangeInput {
|
|
257
|
+
from?: DocumentDate | string
|
|
258
|
+
to?: DocumentDate | string
|
|
259
|
+
}
|
|
260
|
+
|
|
228
261
|
export interface ListInvoicesOptions {
|
|
262
|
+
/** Only invoices dated this day or later (`document_date`); drafts have no date and are left out. */
|
|
263
|
+
from?: DocumentDate | string
|
|
264
|
+
/** Only invoices dated this day or earlier. */
|
|
265
|
+
to?: DocumentDate | string
|
|
229
266
|
limit?: number
|
|
230
267
|
offset?: number
|
|
231
268
|
status?: string
|
|
232
269
|
/** One or several (an array is sent comma-separated). */
|
|
233
270
|
payment_status?: PaymentStatus | PaymentStatus[]
|
|
234
|
-
/** Unpaid or partially paid, with a due date
|
|
271
|
+
/** Unpaid or partially paid, with a due date before today (UTC). */
|
|
235
272
|
overdue?: boolean
|
|
236
273
|
source?: InvoiceSource
|
|
237
274
|
fiscal_status?: FiscalStatus
|
|
@@ -251,9 +288,18 @@ export interface MirrorInvoiceInput {
|
|
|
251
288
|
tax_cents: number
|
|
252
289
|
total_cents: number
|
|
253
290
|
status: 'finalized' | 'paid' | 'void'
|
|
254
|
-
issued_at
|
|
291
|
+
/** The provider's invoice date, `YYYY-MM-DD`. Required (unless the deprecated `issued_at` is sent). */
|
|
292
|
+
document_date?: DocumentDate | string
|
|
293
|
+
due_date?: DocumentDate | string
|
|
294
|
+
paid_date?: DocumentDate | string
|
|
295
|
+
void_date?: DocumentDate | string
|
|
296
|
+
/** @deprecated Send `document_date`. Epoch millis, read as its UTC day; never together with the new name. */
|
|
297
|
+
issued_at?: number
|
|
298
|
+
/** @deprecated Send `due_date`. */
|
|
255
299
|
due_at?: number
|
|
300
|
+
/** @deprecated Send `paid_date`. */
|
|
256
301
|
paid_at?: number
|
|
302
|
+
/** @deprecated Send `void_date`. */
|
|
257
303
|
voided_at?: number
|
|
258
304
|
/** The provider's own "updated" time: an upsert older than what is stored is ignored. */
|
|
259
305
|
provider_updated_at: number
|
|
@@ -268,13 +314,11 @@ export interface MirrorResult {
|
|
|
268
314
|
stale?: boolean
|
|
269
315
|
}
|
|
270
316
|
|
|
271
|
-
/** An organization's numbering series. `number_text` is `${prefix}${
|
|
317
|
+
/** An organization's numbering series. `number_text` is `${prefix}${year of document_date}${counter, zero-padded to digits}`. */
|
|
272
318
|
export interface Numbering {
|
|
273
319
|
prefix: string
|
|
274
320
|
digits: number
|
|
275
321
|
yearly: boolean
|
|
276
|
-
/** IANA name (`Europe/Istanbul`); `UTC` when none is set. The year in the number and the yearly reset follow the issue date in it. */
|
|
277
|
-
time_zone: string
|
|
278
322
|
/** The counter the next invoice finalized now would get. */
|
|
279
323
|
next: number
|
|
280
324
|
/** What that number would read, for the current year. */
|
|
@@ -287,12 +331,14 @@ export interface NumberingInput {
|
|
|
287
331
|
prefix: string
|
|
288
332
|
/** 1 to 12; 9 for e-Fatura. */
|
|
289
333
|
digits: number
|
|
290
|
-
/** true: the counter restarts each calendar year (of
|
|
334
|
+
/** true: the counter restarts each calendar year (of `document_date`). */
|
|
291
335
|
yearly: boolean
|
|
292
|
-
/**
|
|
336
|
+
/** @deprecated Accepted and ignored in 2.0, to be removed: the year is that of `document_date`, a calendar day. */
|
|
293
337
|
time_zone?: string
|
|
294
338
|
/** The counter to continue from (this year's, when yearly). Omitted: the series continues where it is. It can only go forward. */
|
|
295
339
|
next?: number
|
|
340
|
+
/** Which year's series `next` applies to, for a yearly series. Default: the current year (UTC). */
|
|
341
|
+
year?: number
|
|
296
342
|
}
|
|
297
343
|
|
|
298
344
|
export interface FiscalInput {
|
|
@@ -316,6 +362,8 @@ export interface TransactionRow {
|
|
|
316
362
|
method: string
|
|
317
363
|
reference: string
|
|
318
364
|
payment_id: string | null
|
|
365
|
+
/** 2.0; NULL on rows folded from older events (the day of `created_at`). */
|
|
366
|
+
document_date: string | null
|
|
319
367
|
created_at: number
|
|
320
368
|
updated_at: number
|
|
321
369
|
}
|
|
@@ -332,6 +380,8 @@ export interface TransactionDto {
|
|
|
332
380
|
method: string | null
|
|
333
381
|
reference: string | null
|
|
334
382
|
payment_id: string | null
|
|
383
|
+
/** The day of the payment. */
|
|
384
|
+
document_date: DocumentDate
|
|
335
385
|
created_at: number
|
|
336
386
|
}
|
|
337
387
|
|