@baseworks/invoice 0.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/src/types.ts ADDED
@@ -0,0 +1,120 @@
1
+ import type { InvoiceStatus } from './events.js'
2
+ export type { InvoiceStatus } from './events.js'
3
+
4
+ // ── read-model row (snake_case — foldbase read_invoices table) ────────────────
5
+
6
+ export interface InvoiceRow {
7
+ id: string
8
+ short_id: string
9
+ number: number // 0 while draft
10
+ status: InvoiceStatus
11
+ customer_id: string
12
+ customer_name: string
13
+ currency: string
14
+ lines: string // JSON string
15
+ subtotal_cents: number
16
+ total_cents: number
17
+ amount_paid_cents: number
18
+ issued_at: number // 0 while draft
19
+ due_at: number // 0 = none
20
+ created_at: number
21
+ updated_at: number
22
+ }
23
+
24
+ // ── REST DTOs (camelCase) ─────────────────────────────────────────────────────
25
+
26
+ export interface InvoiceLine {
27
+ description: string
28
+ /** May be fractional (e.g. hours). */
29
+ quantity: number
30
+ /** Unit price in integer cents. */
31
+ unitPriceCents: number
32
+ /** quantity × unitPriceCents, rounded to cents. */
33
+ amountCents: number
34
+ /** Optional catalog product reference. */
35
+ productId: string | null
36
+ }
37
+
38
+ export interface Invoice {
39
+ id: string
40
+ shortId: string
41
+ /** Per-org invoice number; `null` while draft. */
42
+ number: number | null
43
+ status: InvoiceStatus
44
+ customerId: string
45
+ customerName: string | null
46
+ currency: string
47
+ lines: InvoiceLine[]
48
+ subtotalCents: number
49
+ totalCents: number
50
+ amountPaidCents: number
51
+ /** totalCents − amountPaidCents (0 for draft/void semantics aside). */
52
+ balanceCents: number
53
+ issuedAt: number | null
54
+ dueAt: number | null
55
+ createdAt: number
56
+ updatedAt: number
57
+ }
58
+
59
+ /** A line as supplied by the caller (amountCents is computed server-side). */
60
+ export interface InvoiceLineInput {
61
+ description: string
62
+ quantity: number
63
+ unitPriceCents: number
64
+ productId?: string
65
+ }
66
+
67
+ export interface CreateInvoiceInput {
68
+ customerId: string
69
+ currency: string
70
+ lines: InvoiceLineInput[]
71
+ }
72
+
73
+ export interface UpdateInvoiceInput {
74
+ customerId?: string
75
+ lines?: InvoiceLineInput[]
76
+ }
77
+
78
+ export interface FinalizeInvoiceInput {
79
+ /** Epoch millis; defaults to now server-side. */
80
+ issuedAt?: number
81
+ /** Epoch millis; 0/omitted = no due date. */
82
+ dueAt?: number
83
+ }
84
+
85
+ export interface RecordPaymentInput {
86
+ amountCents: number
87
+ method?: string
88
+ reference?: string
89
+ }
90
+
91
+ // ── transactions (the ledger) ─────────────────────────────────────────────────
92
+
93
+ export interface TransactionRow {
94
+ id: string
95
+ invoice_id: string
96
+ invoice_number: number
97
+ customer_id: string
98
+ customer_name: string
99
+ kind: string
100
+ amount_cents: number
101
+ currency: string
102
+ method: string
103
+ reference: string
104
+ created_at: number
105
+ updated_at: number
106
+ }
107
+
108
+ export interface Transaction {
109
+ id: string
110
+ invoiceId: string
111
+ invoiceNumber: number
112
+ customerId: string
113
+ customerName: string | null
114
+ kind: string
115
+ amountCents: number
116
+ currency: string
117
+ method: string | null
118
+ reference: string | null
119
+ createdAt: number
120
+ }