@baseworks/invoice 1.1.0 → 1.2.1
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 +33 -2
- package/dist/{chunk-335MPCTE.js → chunk-JS6GUXCC.js} +37 -0
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +46 -10
- package/dist/client.d.ts +56 -1
- package/dist/client.js +22 -0
- package/dist/events.d.ts +109 -1
- package/dist/events.js +3 -1
- package/dist/mcp.js +43 -6
- package/dist/projections.js +11 -3
- package/package.json +1 -1
- package/src/__tests__/cli.test.ts +52 -1
- package/src/__tests__/client.test.ts +27 -0
- package/src/__tests__/mcp.test.ts +59 -7
- package/src/cli.ts +69 -10
- package/src/client.ts +26 -0
- package/src/events.ts +36 -0
- package/src/mcp.ts +57 -8
- package/src/projections.ts +8 -0
- package/src/types.ts +46 -0
package/README.md
CHANGED
|
@@ -76,6 +76,34 @@ The CLI lists with `--payment-status unpaid,partially_paid`, `--overdue`, `--sou
|
|
|
76
76
|
a PAYMENT column. A mirror (`source: stripe | manual`) is read-only except through `mirror`: `update`, `finalize` and `void`
|
|
77
77
|
throw `InvoiceError` `409 mirrored`.
|
|
78
78
|
|
|
79
|
+
### 1.2.0: numbering series and external numbers
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
await invoices.getNumbering() // null (plain 1, 2, 3) or { prefix, digits, yearly, next, next_text, updated_at }
|
|
83
|
+
await invoices.setNumbering({ prefix: 'BSF', digits: 9, yearly: true, next: 148, time_zone: 'Europe/Istanbul' }) // needs invoice.configure; never renumbers
|
|
84
|
+
// time_zone: the year in the number and the yearly restart follow the issue date there (UTC when never set; kept when omitted)
|
|
85
|
+
await invoices.clearNumbering()
|
|
86
|
+
|
|
87
|
+
await invoices.create({ customer_id, currency, lines, external_number: 'PORTAL-77' }) // another system's number
|
|
88
|
+
await invoices.finalize(id, { external_number: 'PORTAL-77' }) // it becomes the number; the series does not advance
|
|
89
|
+
await invoices.list({ external_number: 'PORTAL-77' }) // exact
|
|
90
|
+
// invoice.number (the counter), invoice.number_text ('BSF2026000000148'), invoice.external_number
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
CLI: `invoices numbering`, `invoices numbering set --prefix BSF --digits 9 --yearly --time-zone Europe/Istanbul --next 148`, `invoices numbering clear`;
|
|
94
|
+
`invoices create|finalize --number <external>`; `invoices --external-number <n>`; the NO column shows the printed number.
|
|
95
|
+
|
|
96
|
+
### 1.2.1: the number of an invoice already issued
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// once, on a finalized or paid invoice (the e-Arşiv / GİB portal's number); needs invoice.fiscal_update
|
|
100
|
+
await invoices.setExternalNumber(id, 'GIB2026000000001')
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
CLI: `invoices set-external-number <ref> <number>`. A draft is `409 use_update`, a void invoice `409 void`, a Stripe mirror
|
|
104
|
+
`409 mirrored`, another number `409 external_number_set`; the same one changes nothing. A wrong number is not corrected:
|
|
105
|
+
void and re-issue. Needs **invoice-service 1.2.1**.
|
|
106
|
+
|
|
79
107
|
### Deprecated names
|
|
80
108
|
|
|
81
109
|
Until 0.3.0 the client and the service spoke camelCase. A caller that has not moved (billing-service, stripe-service, apps)
|
|
@@ -121,11 +149,14 @@ optional peer.
|
|
|
121
149
|
| `invoice_list`, `invoice_get`, `invoice_transactions` | read | `invoice.read` |
|
|
122
150
|
| `invoice_create`, `invoice_update` (drafts only) | write | `invoice.write` |
|
|
123
151
|
| `invoice_finalize` (irreversible) | write | `invoice.finalize` |
|
|
152
|
+
| `invoice_set_external_number` (one-time) | write | `invoice.fiscal_update` |
|
|
153
|
+
| `invoice_numbering` | read | `invoice.read` |
|
|
154
|
+
| `invoice_configure_numbering` | write | `invoice.configure` |
|
|
124
155
|
| `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.
|
|
127
156
|
| `invoice_void` (irreversible) | write | `invoice.void` |
|
|
128
157
|
|
|
158
|
+
`invoice_create` and `invoice_finalize` take `external_number`; `invoice_list` takes the same filters as the client (`external_number` too); `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. `invoice_set_external_number` takes the fiscal permission, as that is fiscal identity.
|
|
159
|
+
|
|
129
160
|
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
|
|
130
161
|
the service registered with org-service, used to hide a tool from somebody who may not use it. Money is integer cents; a
|
|
131
162
|
finalized invoice is never edited.
|
|
@@ -19,6 +19,8 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
19
19
|
source: z.string().optional(),
|
|
20
20
|
metadata: z.string().optional(),
|
|
21
21
|
// JSON object, serialized
|
|
22
|
+
external_number: z.string().optional(),
|
|
23
|
+
// 1.2.0: a number given by another system ('' = none)
|
|
22
24
|
at: z.number().int()
|
|
23
25
|
}),
|
|
24
26
|
// Draft edited (customer / lines). Only valid while status = draft.
|
|
@@ -30,6 +32,8 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
30
32
|
total_cents: z.number().int(),
|
|
31
33
|
metadata: z.string().optional(),
|
|
32
34
|
// 1.1.0
|
|
35
|
+
external_number: z.string().optional(),
|
|
36
|
+
// 1.2.0
|
|
33
37
|
at: z.number().int()
|
|
34
38
|
}),
|
|
35
39
|
// Finalize: assign the per-org number, freeze lines + totals, set issue/due.
|
|
@@ -41,6 +45,11 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
41
45
|
issued_at: z.number().int(),
|
|
42
46
|
due_at: z.number().int(),
|
|
43
47
|
// 0 = no due date
|
|
48
|
+
// 1.2.0. `number` is the counter of the series (0 when the number is the external one); `number_text` is the number as
|
|
49
|
+
// printed (`BSF2026000000148`, `7`, or the external number); `series_key` says which counter `number` belongs to.
|
|
50
|
+
number_text: z.string().optional(),
|
|
51
|
+
series_key: z.string().optional(),
|
|
52
|
+
external_number: z.string().optional(),
|
|
44
53
|
at: z.number().int()
|
|
45
54
|
}),
|
|
46
55
|
// A payment applied to a finalized invoice. `amount_paid_cents` is the new running
|
|
@@ -60,6 +69,12 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
60
69
|
reason: z.string(),
|
|
61
70
|
at: z.number().int()
|
|
62
71
|
}),
|
|
72
|
+
// 1.2.1. The number another system gave an invoice that was already issued (the e-Arşiv / GİB portal's), set once.
|
|
73
|
+
// `number`, `number_text` and the series are not touched.
|
|
74
|
+
InvoiceExternalNumberSet: z.object({
|
|
75
|
+
external_number: z.string().min(1),
|
|
76
|
+
at: z.number().int()
|
|
77
|
+
}),
|
|
63
78
|
// 1.1.0. The provider's document, whole (absolute values like every event here), by (system, external id): the
|
|
64
79
|
// first one creates the invoice, the next ones replace it. A mirror never takes a number: `number` stays 0.
|
|
65
80
|
InvoiceMirrored: z.object({
|
|
@@ -102,6 +117,27 @@ var InvoiceEvents = defineAggregate("invoice", {
|
|
|
102
117
|
at: z.number().int()
|
|
103
118
|
})
|
|
104
119
|
});
|
|
120
|
+
var NumberingEvents = defineAggregate("numbering", {
|
|
121
|
+
NumberingConfigured: z.object({
|
|
122
|
+
prefix: z.string(),
|
|
123
|
+
// 3 characters, A-Z 0-9
|
|
124
|
+
digits: z.number().int(),
|
|
125
|
+
yearly: z.boolean(),
|
|
126
|
+
next: z.number().int(),
|
|
127
|
+
// the counter `next_key` starts from
|
|
128
|
+
next_key: z.string(),
|
|
129
|
+
// the series key `next` applies to (prefix + year when yearly)
|
|
130
|
+
time_zone: z.string().optional(),
|
|
131
|
+
// IANA name; absent = UTC. The year in the number and the yearly reset follow it
|
|
132
|
+
at: z.number().int()
|
|
133
|
+
}),
|
|
134
|
+
NumberingCleared: z.object({ at: z.number().int() }),
|
|
135
|
+
NumberClaimed: z.object({ invoice_id: z.string().min(1), series_key: z.string(), number: z.number().int(), at: z.number().int() }),
|
|
136
|
+
NumberReleased: z.object({ invoice_id: z.string().min(1), at: z.number().int() }),
|
|
137
|
+
// `invoice_version` (1.2.1): the version of the invoice's stream the claiming write emits at. While the stream is still
|
|
138
|
+
// there, that write is in flight. Absent from claims written before.
|
|
139
|
+
ExternalNumberClaimed: z.object({ external_number: z.string().min(1), invoice_id: z.string().min(1), invoice_version: z.number().int().optional(), at: z.number().int() })
|
|
140
|
+
});
|
|
105
141
|
var FISCAL_STATUSES = ["not_submitted", "queued", "submitted", "accepted", "rejected", "cancelled"];
|
|
106
142
|
var INVOICE_SOURCES = ["local", "stripe", "manual"];
|
|
107
143
|
var TransactionKind = z.enum(["payment", "refund", "adjustment"]);
|
|
@@ -126,6 +162,7 @@ var TransactionEvents = defineAggregate("transaction", {
|
|
|
126
162
|
export {
|
|
127
163
|
InvoiceStatus,
|
|
128
164
|
InvoiceEvents,
|
|
165
|
+
NumberingEvents,
|
|
129
166
|
FISCAL_STATUSES,
|
|
130
167
|
INVOICE_SOURCES,
|
|
131
168
|
TransactionKind,
|
package/dist/cli.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { ApiClient } from '@baseworks/cli/client';
|
|
|
10
10
|
*
|
|
11
11
|
* Usage: `dtab invoices` (list) · `inv` alias · `invoices create --customer <ref>
|
|
12
12
|
* --currency USD --line "Consulting|10|150.00"` · `invoices get <ref>` ·
|
|
13
|
-
* `invoices finalize <ref>` · `invoices
|
|
14
|
-
* `invoices void <ref>`
|
|
13
|
+
* `invoices finalize <ref>` · `invoices set-external-number <ref> <number>` ·
|
|
14
|
+
* `invoices pay <ref> --amount 150.00` · `invoices void <ref>`
|
|
15
15
|
*/
|
|
16
16
|
interface InvoiceCliDeps {
|
|
17
17
|
http: ApiClient;
|
package/dist/cli.js
CHANGED
|
@@ -22,8 +22,8 @@ function parseLine(spec) {
|
|
|
22
22
|
if (!Number.isFinite(quantity) || quantity <= 0) fatal(`--line qty must be > 0 in '${spec}'`);
|
|
23
23
|
return { description, quantity, unit_price_cents: toCents(parts[2].trim(), "--line unitPrice") };
|
|
24
24
|
}
|
|
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)");
|
|
25
|
+
var NUMBER_COL = (v) => v ? /^\d+$/.test(String(v)) ? `#${v}` : String(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)").option("--external-number <number>", "Only the invoice with this external number (exact)");
|
|
27
27
|
function buildInvoiceCommand(deps) {
|
|
28
28
|
const { http } = deps;
|
|
29
29
|
const cli = deps.cliName ?? "cli";
|
|
@@ -35,12 +35,13 @@ function buildInvoiceCommand(deps) {
|
|
|
35
35
|
if (opts.source) params.set("source", opts.source);
|
|
36
36
|
if (opts.fiscalStatus) params.set("fiscal_status", opts.fiscalStatus);
|
|
37
37
|
if (opts.customerId) params.set("customer_id", opts.customerId);
|
|
38
|
+
if (opts.externalNumber) params.set("external_number", opts.externalNumber);
|
|
38
39
|
const q = params.toString() ? `?${params}` : "";
|
|
39
40
|
const res = await http.get(`/invoices${q}`).catch(die);
|
|
40
41
|
printOutput(res.invoices, opts.output, (wide) => {
|
|
41
42
|
table(res.invoices, [
|
|
42
43
|
{ key: "short_id", label: "ID" },
|
|
43
|
-
{ key: "
|
|
44
|
+
{ key: "number_text", label: "NO", fmt: NUMBER_COL },
|
|
44
45
|
{ key: "status", label: "STATUS" },
|
|
45
46
|
{ key: "payment_status", label: "PAYMENT", fmt: (v) => v ?? "" },
|
|
46
47
|
{ key: "customer_name", label: "CUSTOMER", fmt: (v, r) => v ?? r.customer_id },
|
|
@@ -66,17 +67,19 @@ function buildInvoiceCommand(deps) {
|
|
|
66
67
|
...self.overdue ?? parent.overdue ? { overdue: true } : {},
|
|
67
68
|
...self.source ?? parent.source ? { source: self.source ?? parent.source } : {},
|
|
68
69
|
...self.fiscalStatus ?? parent.fiscalStatus ? { fiscalStatus: self.fiscalStatus ?? parent.fiscalStatus } : {},
|
|
69
|
-
...self.customerId ?? parent.customerId ? { customerId: self.customerId ?? parent.customerId } : {}
|
|
70
|
+
...self.customerId ?? parent.customerId ? { customerId: self.customerId ?? parent.customerId } : {},
|
|
71
|
+
...self.externalNumber ?? parent.externalNumber ? { externalNumber: self.externalNumber ?? parent.externalNumber } : {}
|
|
70
72
|
});
|
|
71
73
|
})
|
|
72
74
|
);
|
|
73
75
|
cmd.addCommand(
|
|
74
|
-
new Command("create").description("Create a draft invoice").requiredOption("--customer <ref>", "Customer id, short_id, or external_id").requiredOption("--currency <cur>", "ISO-4217 currency (e.g. USD)").requiredOption("--line <spec...>", 'Line "description|qty|unitPrice" (repeatable)').action(async (opts) => {
|
|
76
|
+
new Command("create").description("Create a draft invoice").requiredOption("--customer <ref>", "Customer id, short_id, or external_id").requiredOption("--currency <cur>", "ISO-4217 currency (e.g. USD)").requiredOption("--line <spec...>", 'Line "description|qty|unitPrice" (repeatable)').option("--number <external>", "A number another system gave it (up to 64 characters): the invoice keeps it and takes none from the series").action(async (opts) => {
|
|
75
77
|
const lines = opts.line.map(parseLine);
|
|
76
78
|
const res = await http.post("/invoices", {
|
|
77
79
|
customer_id: opts.customer,
|
|
78
80
|
currency: opts.currency,
|
|
79
|
-
lines
|
|
81
|
+
lines,
|
|
82
|
+
...opts.number ? { external_number: opts.number } : {}
|
|
80
83
|
}).catch(die);
|
|
81
84
|
success(`Draft invoice created for ${res.invoice.customer_name ?? res.invoice.customer_id}`);
|
|
82
85
|
kv([["id", res.invoice.short_id], ["status", res.invoice.status], ["total", fmtMoney(res.invoice.total_cents, res.invoice.currency)]]);
|
|
@@ -90,7 +93,8 @@ function buildInvoiceCommand(deps) {
|
|
|
90
93
|
printOutput(inv, opts.output, () => {
|
|
91
94
|
kv([
|
|
92
95
|
["id", String(inv["short_id"])],
|
|
93
|
-
["number", inv["
|
|
96
|
+
["number", inv["number_text"] ? NUMBER_COL(inv["number_text"]) : "\u2014 (draft)"],
|
|
97
|
+
...inv["external_number"] ? [["external_number", String(inv["external_number"])]] : [],
|
|
94
98
|
["status", String(inv["status"])],
|
|
95
99
|
["customer", String(inv["customer_name"] ?? inv["customer_id"])],
|
|
96
100
|
["issued", inv["issued_at"] ? fmtDate(inv["issued_at"]) : "\u2014"],
|
|
@@ -128,16 +132,24 @@ function buildInvoiceCommand(deps) {
|
|
|
128
132
|
})
|
|
129
133
|
);
|
|
130
134
|
cmd.addCommand(
|
|
131
|
-
new Command("finalize").argument("<ref>").description("Finalize a draft \u2014 assigns a number, freezes it (immutable)").option("--due <date>", "Due date YYYY-MM-DD").action(async (ref, opts) => {
|
|
135
|
+
new Command("finalize").argument("<ref>").description("Finalize a draft \u2014 assigns a number, freezes it (immutable)").option("--due <date>", "Due date YYYY-MM-DD").option("--number <external>", "A number another system gave it: it becomes the invoice's number and the series does not advance").action(async (ref, opts) => {
|
|
132
136
|
const body = {};
|
|
137
|
+
if (opts.number) body["external_number"] = opts.number;
|
|
133
138
|
if (opts.due) {
|
|
134
139
|
const ms = Date.parse(opts.due);
|
|
135
140
|
if (Number.isNaN(ms)) fatal(`--due is not a valid date: '${opts.due}'`);
|
|
136
141
|
body["due_at"] = ms;
|
|
137
142
|
}
|
|
138
143
|
const res = await http.post(`/invoices/${ref}/finalize`, body).catch(die);
|
|
139
|
-
success(`Invoice finalized:
|
|
140
|
-
kv([["id", res.invoice.short_id], ["number",
|
|
144
|
+
success(`Invoice finalized: ${NUMBER_COL(res.invoice.number_text)}`);
|
|
145
|
+
kv([["id", res.invoice.short_id], ["number", NUMBER_COL(res.invoice.number_text)], ["total", fmtMoney(res.invoice.total_cents, res.invoice.currency)], ["balance", fmtMoney(res.invoice.balance_cents, res.invoice.currency)]]);
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
cmd.addCommand(
|
|
149
|
+
new Command("set-external-number").argument("<ref>", "id or short_id").argument("<number>", "the number the other system gave it (up to 64 characters)").description("Record the portal number of an already finalized or paid invoice, ONCE (needs `invoice.fiscal_update`). A wrong one is not corrected: void and re-issue.").action(async (ref, number) => {
|
|
150
|
+
const res = await http.api("PUT", `/invoices/${ref}/external-number`, { external_number: number }).catch(die);
|
|
151
|
+
success(`External number set: ${res.invoice.external_number}`);
|
|
152
|
+
kv([["id", res.invoice.short_id], ["status", res.invoice.status], ["number", NUMBER_COL(res.invoice.number_text)], ["external_number", res.invoice.external_number ?? ""]]);
|
|
141
153
|
})
|
|
142
154
|
);
|
|
143
155
|
cmd.addCommand(
|
|
@@ -157,6 +169,30 @@ function buildInvoiceCommand(deps) {
|
|
|
157
169
|
success(`Invoice voided: ${res.invoice.short_id}`);
|
|
158
170
|
})
|
|
159
171
|
);
|
|
172
|
+
const showNumbering = (n) => n ? kv([["prefix", n.prefix], ["digits", String(n.digits)], ["yearly", n.yearly ? "yes (the counter restarts each year)" : "no"], ["time_zone", n.time_zone], ["next", `${n.next} \u2192 ${n.next_text}`]]) : console.log("No series: invoices are numbered 1, 2, 3.");
|
|
173
|
+
cmd.addCommand(
|
|
174
|
+
new Command("numbering").description("Show the organization's numbering series (needs `invoice.read`)").option(...outputOption()).action(async (opts) => {
|
|
175
|
+
const res = await http.get("/settings/numbering").catch(die);
|
|
176
|
+
printOutput(res.numbering ?? {}, opts.output, () => showNumbering(res.numbering), "prefix");
|
|
177
|
+
}).addCommand(
|
|
178
|
+
new Command("set").description("Set the series: PREFIX (3 uppercase letters or digits) + the issue year + a counter of --digits. Never renumbers a finalized invoice. Needs `invoice.configure`.").requiredOption("--prefix <prefix>", "3 uppercase letters or digits, e.g. BSF").requiredOption("--digits <n>", "Counter width, 1 to 12 (9 for e-Fatura)").option("--yearly", "The counter restarts each calendar year").option("--time-zone <zone>", "IANA name, e.g. Europe/Istanbul: the year follows the issue date there (kept when omitted; UTC if never set)").option("--next <n>", "Continue from this counter (this year's, when yearly); it can only go forward").action(async (opts) => {
|
|
179
|
+
const res = await http.api("PUT", "/settings/numbering", {
|
|
180
|
+
prefix: opts.prefix,
|
|
181
|
+
digits: Number(opts.digits),
|
|
182
|
+
yearly: !!opts.yearly,
|
|
183
|
+
...opts.next ? { next: Number(opts.next) } : {},
|
|
184
|
+
...opts.timeZone ? { time_zone: opts.timeZone } : {}
|
|
185
|
+
}).catch(die);
|
|
186
|
+
success("Numbering series set.");
|
|
187
|
+
showNumbering(res.numbering);
|
|
188
|
+
})
|
|
189
|
+
).addCommand(
|
|
190
|
+
new Command("clear").description("Back to plain 1, 2, 3 for what is finalized from now on. Needs `invoice.configure`.").action(async () => {
|
|
191
|
+
await http.del("/settings/numbering").catch(die);
|
|
192
|
+
success("No series: invoices are numbered 1, 2, 3.");
|
|
193
|
+
})
|
|
194
|
+
)
|
|
195
|
+
);
|
|
160
196
|
cmd.addCommand(
|
|
161
197
|
new Command("payments").alias("transactions").argument("[ref]", "invoice id/short_id (omit for all org transactions)").description("List payments / transactions (the money ledger)").option(...outputOption()).action(async (ref, opts) => {
|
|
162
198
|
const path = ref ? `/invoices/${ref}/payments` : "/transactions";
|
package/dist/client.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ interface InvoiceRow {
|
|
|
31
31
|
fiscal_external_id: string | null;
|
|
32
32
|
fiscal_message: string | null;
|
|
33
33
|
fiscal_updated_at: number | null;
|
|
34
|
+
number_text: string | null;
|
|
35
|
+
series_key: string | null;
|
|
36
|
+
external_number: string | null;
|
|
34
37
|
}
|
|
35
38
|
interface InvoiceLineDto {
|
|
36
39
|
description: string;
|
|
@@ -107,6 +110,13 @@ interface InvoiceDto {
|
|
|
107
110
|
tax_cents: number;
|
|
108
111
|
payment_status: PaymentStatus;
|
|
109
112
|
fiscal: Fiscal | null;
|
|
113
|
+
/**
|
|
114
|
+
* The number as printed: `BSF2026000000148` in a series, `7` without one, the external number when the invoice has one.
|
|
115
|
+
* `null` while a draft. `number` is the series' counter (`null` when the number is the external one).
|
|
116
|
+
*/
|
|
117
|
+
number_text: string | null;
|
|
118
|
+
/** A number given by another system (an e-Fatura portal, say), up to 64 characters. Unique among non-void invoices. */
|
|
119
|
+
external_number: string | null;
|
|
110
120
|
/** Only `GET /invoices/:ref` includes the payments. */
|
|
111
121
|
payments?: InvoicePayment[];
|
|
112
122
|
}
|
|
@@ -155,6 +165,8 @@ interface CreateInvoiceInput {
|
|
|
155
165
|
currency: string;
|
|
156
166
|
lines: InvoiceLineInput[];
|
|
157
167
|
metadata?: Metadata;
|
|
168
|
+
/** A number from another system; the invoice keeps it and takes none from the series at finalize. */
|
|
169
|
+
external_number?: string;
|
|
158
170
|
/** @deprecated Send `customer_id`. */
|
|
159
171
|
customerId?: string;
|
|
160
172
|
}
|
|
@@ -163,6 +175,8 @@ interface UpdateInvoiceInput {
|
|
|
163
175
|
lines?: InvoiceLineInput[];
|
|
164
176
|
/** Replaces the invoice's metadata. */
|
|
165
177
|
metadata?: Metadata;
|
|
178
|
+
/** Sets (or, with null, clears) the external number of a draft. */
|
|
179
|
+
external_number?: string | null;
|
|
166
180
|
/** @deprecated Send `customer_id`. */
|
|
167
181
|
customerId?: string;
|
|
168
182
|
}
|
|
@@ -171,6 +185,8 @@ interface FinalizeInvoiceInput {
|
|
|
171
185
|
issued_at?: number;
|
|
172
186
|
/** Epoch millis; 0/omitted = no due date. */
|
|
173
187
|
due_at?: number;
|
|
188
|
+
/** The number another system gave it. Then it is the invoice's number and the series does not advance. */
|
|
189
|
+
external_number?: string;
|
|
174
190
|
/** @deprecated Send `issued_at`. */
|
|
175
191
|
issuedAt?: number;
|
|
176
192
|
/** @deprecated Send `due_at`. */
|
|
@@ -196,6 +212,8 @@ interface ListInvoicesOptions {
|
|
|
196
212
|
source?: InvoiceSource;
|
|
197
213
|
fiscal_status?: FiscalStatus;
|
|
198
214
|
customer_id?: string;
|
|
215
|
+
/** Exact. */
|
|
216
|
+
external_number?: string;
|
|
199
217
|
}
|
|
200
218
|
/** The provider's whole document, for `PUT /invoices/mirror`. */
|
|
201
219
|
interface MirrorInvoiceInput {
|
|
@@ -229,6 +247,31 @@ interface MirrorResult {
|
|
|
229
247
|
/** True when the document was older than the one stored and was ignored. */
|
|
230
248
|
stale?: boolean;
|
|
231
249
|
}
|
|
250
|
+
/** An organization's numbering series. `number_text` is `${prefix}${issue year}${counter, zero-padded to digits}`. */
|
|
251
|
+
interface Numbering {
|
|
252
|
+
prefix: string;
|
|
253
|
+
digits: number;
|
|
254
|
+
yearly: boolean;
|
|
255
|
+
/** IANA name (`Europe/Istanbul`); `UTC` when none is set. The year in the number and the yearly reset follow the issue date in it. */
|
|
256
|
+
time_zone: string;
|
|
257
|
+
/** The counter the next invoice finalized now would get. */
|
|
258
|
+
next: number;
|
|
259
|
+
/** What that number would read, for the current year. */
|
|
260
|
+
next_text: string;
|
|
261
|
+
updated_at: number;
|
|
262
|
+
}
|
|
263
|
+
interface NumberingInput {
|
|
264
|
+
/** 3 uppercase letters or digits. */
|
|
265
|
+
prefix: string;
|
|
266
|
+
/** 1 to 12; 9 for e-Fatura. */
|
|
267
|
+
digits: number;
|
|
268
|
+
/** true: the counter restarts each calendar year (of the issue date). */
|
|
269
|
+
yearly: boolean;
|
|
270
|
+
/** IANA name. Omitted: stays as it was (UTC if never set). */
|
|
271
|
+
time_zone?: string;
|
|
272
|
+
/** The counter to continue from (this year's, when yearly). Omitted: the series continues where it is. It can only go forward. */
|
|
273
|
+
next?: number;
|
|
274
|
+
}
|
|
232
275
|
interface FiscalInput {
|
|
233
276
|
status: FiscalStatus;
|
|
234
277
|
system?: string;
|
|
@@ -337,8 +380,20 @@ declare class InvoiceClient {
|
|
|
337
380
|
* `external_ref` (system + id). An older document than the one stored is ignored (`stale`). Needs `invoice.mirror`.
|
|
338
381
|
*/
|
|
339
382
|
mirror(input: MirrorInvoiceInput): Promise<MirrorResult>;
|
|
383
|
+
/** The organization's numbering series; `null` while it has none (invoices are numbered 1, 2, 3). */
|
|
384
|
+
getNumbering(): Promise<Numbering | null>;
|
|
385
|
+
/** Set the series (`BSF` + issue year + a counter of `digits`). Needs `invoice.configure`. Never renumbers a finalized invoice. */
|
|
386
|
+
setNumbering(input: NumberingInput): Promise<Numbering>;
|
|
387
|
+
/** Back to 1, 2, 3 for what is finalized from now on. Needs `invoice.configure`. */
|
|
388
|
+
clearNumbering(): Promise<void>;
|
|
340
389
|
/** Record where the invoice stands with a tax system. Needs `invoice.fiscal_update`; nothing is sent to any tax system. */
|
|
341
390
|
setFiscal(ref: string, input: FiscalInput): Promise<Invoice>;
|
|
391
|
+
/**
|
|
392
|
+
* Record the number another system gave an invoice that is already finalized or paid (the e-Arşiv / GİB portal's).
|
|
393
|
+
* Once: the same number again changes nothing, another one is `409 external_number_set`. Needs `invoice.fiscal_update`.
|
|
394
|
+
* A draft is `409 use_update`.
|
|
395
|
+
*/
|
|
396
|
+
setExternalNumber(ref: string, external_number: string): Promise<Invoice>;
|
|
342
397
|
finalize(ref: string, input?: FinalizeInvoiceInput): Promise<Invoice>;
|
|
343
398
|
recordPayment(ref: string, input: RecordPaymentInput): Promise<Invoice>;
|
|
344
399
|
void(ref: string, reason?: string): Promise<Invoice>;
|
|
@@ -353,4 +408,4 @@ declare class InvoiceClient {
|
|
|
353
408
|
/** Factory used by the SDK capability registry. */
|
|
354
409
|
declare function createInvoiceClient(opts: InvoiceClientOptions): InvoiceClient;
|
|
355
410
|
|
|
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 };
|
|
411
|
+
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 Numbering, type NumberingInput, type PaymentStatus, type RecordPaymentInput, type Transaction, type TransactionDeprecated, type TransactionDto, type TransactionRow, type UpdateInvoiceInput, createInvoiceClient };
|
package/dist/client.js
CHANGED
|
@@ -124,6 +124,7 @@ var InvoiceClient = class _InvoiceClient {
|
|
|
124
124
|
if (opts.source) q.set("source", opts.source);
|
|
125
125
|
if (opts.fiscal_status) q.set("fiscal_status", opts.fiscal_status);
|
|
126
126
|
if (opts.customer_id) q.set("customer_id", opts.customer_id);
|
|
127
|
+
if (opts.external_number) q.set("external_number", opts.external_number);
|
|
127
128
|
const qs = q.toString();
|
|
128
129
|
const { invoices } = await this.api("GET", `/invoices${qs ? `?${qs}` : ""}`);
|
|
129
130
|
return invoices.map(oldNamesOnInvoice);
|
|
@@ -148,11 +149,32 @@ var InvoiceClient = class _InvoiceClient {
|
|
|
148
149
|
const r = await this.api("PUT", "/invoices/mirror", input);
|
|
149
150
|
return { ...r, invoice: oldNamesOnInvoice(r.invoice) };
|
|
150
151
|
}
|
|
152
|
+
/** The organization's numbering series; `null` while it has none (invoices are numbered 1, 2, 3). */
|
|
153
|
+
async getNumbering() {
|
|
154
|
+
return (await this.api("GET", "/settings/numbering")).numbering;
|
|
155
|
+
}
|
|
156
|
+
/** Set the series (`BSF` + issue year + a counter of `digits`). Needs `invoice.configure`. Never renumbers a finalized invoice. */
|
|
157
|
+
async setNumbering(input) {
|
|
158
|
+
return (await this.api("PUT", "/settings/numbering", input)).numbering;
|
|
159
|
+
}
|
|
160
|
+
/** Back to 1, 2, 3 for what is finalized from now on. Needs `invoice.configure`. */
|
|
161
|
+
async clearNumbering() {
|
|
162
|
+
await this.api("DELETE", "/settings/numbering");
|
|
163
|
+
}
|
|
151
164
|
/** Record where the invoice stands with a tax system. Needs `invoice.fiscal_update`; nothing is sent to any tax system. */
|
|
152
165
|
async setFiscal(ref, input) {
|
|
153
166
|
const { invoice } = await this.api("PUT", `/invoices/${ref}/fiscal`, input);
|
|
154
167
|
return oldNamesOnInvoice(invoice);
|
|
155
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Record the number another system gave an invoice that is already finalized or paid (the e-Arşiv / GİB portal's).
|
|
171
|
+
* Once: the same number again changes nothing, another one is `409 external_number_set`. Needs `invoice.fiscal_update`.
|
|
172
|
+
* A draft is `409 use_update`.
|
|
173
|
+
*/
|
|
174
|
+
async setExternalNumber(ref, external_number) {
|
|
175
|
+
const { invoice } = await this.api("PUT", `/invoices/${ref}/external-number`, { external_number });
|
|
176
|
+
return oldNamesOnInvoice(invoice);
|
|
177
|
+
}
|
|
156
178
|
async finalize(ref, input = {}) {
|
|
157
179
|
const { invoice } = await this.api("POST", `/invoices/${ref}/finalize`, newNamesOnFinalize(input));
|
|
158
180
|
return oldNamesOnInvoice(invoice);
|
package/dist/events.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
35
35
|
short_id: z.ZodString;
|
|
36
36
|
source: z.ZodOptional<z.ZodString>;
|
|
37
37
|
metadata: z.ZodOptional<z.ZodString>;
|
|
38
|
+
external_number: z.ZodOptional<z.ZodString>;
|
|
38
39
|
at: z.ZodNumber;
|
|
39
40
|
}, "strip", z.ZodTypeAny, {
|
|
40
41
|
at: number;
|
|
@@ -47,6 +48,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
47
48
|
total_cents: number;
|
|
48
49
|
source?: string | undefined;
|
|
49
50
|
metadata?: string | undefined;
|
|
51
|
+
external_number?: string | undefined;
|
|
50
52
|
}, {
|
|
51
53
|
at: number;
|
|
52
54
|
lines: string;
|
|
@@ -58,6 +60,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
58
60
|
total_cents: number;
|
|
59
61
|
source?: string | undefined;
|
|
60
62
|
metadata?: string | undefined;
|
|
63
|
+
external_number?: string | undefined;
|
|
61
64
|
}>;
|
|
62
65
|
InvoiceUpdated: z.ZodObject<{
|
|
63
66
|
customer_id: z.ZodString;
|
|
@@ -66,6 +69,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
66
69
|
subtotal_cents: z.ZodNumber;
|
|
67
70
|
total_cents: z.ZodNumber;
|
|
68
71
|
metadata: z.ZodOptional<z.ZodString>;
|
|
72
|
+
external_number: z.ZodOptional<z.ZodString>;
|
|
69
73
|
at: z.ZodNumber;
|
|
70
74
|
}, "strip", z.ZodTypeAny, {
|
|
71
75
|
at: number;
|
|
@@ -75,6 +79,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
75
79
|
subtotal_cents: number;
|
|
76
80
|
total_cents: number;
|
|
77
81
|
metadata?: string | undefined;
|
|
82
|
+
external_number?: string | undefined;
|
|
78
83
|
}, {
|
|
79
84
|
at: number;
|
|
80
85
|
lines: string;
|
|
@@ -83,6 +88,7 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
83
88
|
subtotal_cents: number;
|
|
84
89
|
total_cents: number;
|
|
85
90
|
metadata?: string | undefined;
|
|
91
|
+
external_number?: string | undefined;
|
|
86
92
|
}>;
|
|
87
93
|
InvoiceFinalized: z.ZodObject<{
|
|
88
94
|
number: z.ZodNumber;
|
|
@@ -91,6 +97,9 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
91
97
|
total_cents: z.ZodNumber;
|
|
92
98
|
issued_at: z.ZodNumber;
|
|
93
99
|
due_at: z.ZodNumber;
|
|
100
|
+
number_text: z.ZodOptional<z.ZodString>;
|
|
101
|
+
series_key: z.ZodOptional<z.ZodString>;
|
|
102
|
+
external_number: z.ZodOptional<z.ZodString>;
|
|
94
103
|
at: z.ZodNumber;
|
|
95
104
|
}, "strip", z.ZodTypeAny, {
|
|
96
105
|
number: number;
|
|
@@ -100,6 +109,9 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
100
109
|
total_cents: number;
|
|
101
110
|
issued_at: number;
|
|
102
111
|
due_at: number;
|
|
112
|
+
number_text?: string | undefined;
|
|
113
|
+
external_number?: string | undefined;
|
|
114
|
+
series_key?: string | undefined;
|
|
103
115
|
}, {
|
|
104
116
|
number: number;
|
|
105
117
|
at: number;
|
|
@@ -108,6 +120,9 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
108
120
|
total_cents: number;
|
|
109
121
|
issued_at: number;
|
|
110
122
|
due_at: number;
|
|
123
|
+
number_text?: string | undefined;
|
|
124
|
+
external_number?: string | undefined;
|
|
125
|
+
series_key?: string | undefined;
|
|
111
126
|
}>;
|
|
112
127
|
PaymentRecorded: z.ZodObject<{
|
|
113
128
|
amount_cents: z.ZodNumber;
|
|
@@ -144,6 +159,16 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
144
159
|
at: number;
|
|
145
160
|
reason: string;
|
|
146
161
|
}>;
|
|
162
|
+
InvoiceExternalNumberSet: z.ZodObject<{
|
|
163
|
+
external_number: z.ZodString;
|
|
164
|
+
at: z.ZodNumber;
|
|
165
|
+
}, "strip", z.ZodTypeAny, {
|
|
166
|
+
at: number;
|
|
167
|
+
external_number: string;
|
|
168
|
+
}, {
|
|
169
|
+
at: number;
|
|
170
|
+
external_number: string;
|
|
171
|
+
}>;
|
|
147
172
|
InvoiceMirrored: z.ZodObject<{
|
|
148
173
|
source: z.ZodString;
|
|
149
174
|
mirror_key: z.ZodString;
|
|
@@ -233,6 +258,89 @@ declare const InvoiceEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
233
258
|
}> & {
|
|
234
259
|
newId(): string;
|
|
235
260
|
};
|
|
261
|
+
/**
|
|
262
|
+
* 1.2.0. An organization's numbering series, and the claims that keep numbers unique. One aggregate, many streams:
|
|
263
|
+
* `numbering-settings` holds the series; one stream per (series key, counter) serializes who takes that number; one per
|
|
264
|
+
* external number serializes who holds it.
|
|
265
|
+
*/
|
|
266
|
+
declare const NumberingEvents: _baseworks_foldbase.EventCatalog<{
|
|
267
|
+
NumberingConfigured: z.ZodObject<{
|
|
268
|
+
prefix: z.ZodString;
|
|
269
|
+
digits: z.ZodNumber;
|
|
270
|
+
yearly: z.ZodBoolean;
|
|
271
|
+
next: z.ZodNumber;
|
|
272
|
+
next_key: z.ZodString;
|
|
273
|
+
time_zone: z.ZodOptional<z.ZodString>;
|
|
274
|
+
at: z.ZodNumber;
|
|
275
|
+
}, "strip", z.ZodTypeAny, {
|
|
276
|
+
at: number;
|
|
277
|
+
prefix: string;
|
|
278
|
+
digits: number;
|
|
279
|
+
yearly: boolean;
|
|
280
|
+
next: number;
|
|
281
|
+
next_key: string;
|
|
282
|
+
time_zone?: string | undefined;
|
|
283
|
+
}, {
|
|
284
|
+
at: number;
|
|
285
|
+
prefix: string;
|
|
286
|
+
digits: number;
|
|
287
|
+
yearly: boolean;
|
|
288
|
+
next: number;
|
|
289
|
+
next_key: string;
|
|
290
|
+
time_zone?: string | undefined;
|
|
291
|
+
}>;
|
|
292
|
+
NumberingCleared: z.ZodObject<{
|
|
293
|
+
at: z.ZodNumber;
|
|
294
|
+
}, "strip", z.ZodTypeAny, {
|
|
295
|
+
at: number;
|
|
296
|
+
}, {
|
|
297
|
+
at: number;
|
|
298
|
+
}>;
|
|
299
|
+
NumberClaimed: z.ZodObject<{
|
|
300
|
+
invoice_id: z.ZodString;
|
|
301
|
+
series_key: z.ZodString;
|
|
302
|
+
number: z.ZodNumber;
|
|
303
|
+
at: z.ZodNumber;
|
|
304
|
+
}, "strip", z.ZodTypeAny, {
|
|
305
|
+
number: number;
|
|
306
|
+
at: number;
|
|
307
|
+
invoice_id: string;
|
|
308
|
+
series_key: string;
|
|
309
|
+
}, {
|
|
310
|
+
number: number;
|
|
311
|
+
at: number;
|
|
312
|
+
invoice_id: string;
|
|
313
|
+
series_key: string;
|
|
314
|
+
}>;
|
|
315
|
+
NumberReleased: z.ZodObject<{
|
|
316
|
+
invoice_id: z.ZodString;
|
|
317
|
+
at: z.ZodNumber;
|
|
318
|
+
}, "strip", z.ZodTypeAny, {
|
|
319
|
+
at: number;
|
|
320
|
+
invoice_id: string;
|
|
321
|
+
}, {
|
|
322
|
+
at: number;
|
|
323
|
+
invoice_id: string;
|
|
324
|
+
}>;
|
|
325
|
+
ExternalNumberClaimed: z.ZodObject<{
|
|
326
|
+
external_number: z.ZodString;
|
|
327
|
+
invoice_id: z.ZodString;
|
|
328
|
+
invoice_version: z.ZodOptional<z.ZodNumber>;
|
|
329
|
+
at: z.ZodNumber;
|
|
330
|
+
}, "strip", z.ZodTypeAny, {
|
|
331
|
+
at: number;
|
|
332
|
+
external_number: string;
|
|
333
|
+
invoice_id: string;
|
|
334
|
+
invoice_version?: number | undefined;
|
|
335
|
+
}, {
|
|
336
|
+
at: number;
|
|
337
|
+
external_number: string;
|
|
338
|
+
invoice_id: string;
|
|
339
|
+
invoice_version?: number | undefined;
|
|
340
|
+
}>;
|
|
341
|
+
}> & {
|
|
342
|
+
newId(): string;
|
|
343
|
+
};
|
|
236
344
|
declare const FISCAL_STATUSES: readonly ["not_submitted", "queued", "submitted", "accepted", "rejected", "cancelled"];
|
|
237
345
|
type FiscalStatus = (typeof FISCAL_STATUSES)[number];
|
|
238
346
|
declare const INVOICE_SOURCES: readonly ["local", "stripe", "manual"];
|
|
@@ -288,4 +396,4 @@ declare const TransactionEvents: _baseworks_foldbase.EventCatalog<{
|
|
|
288
396
|
newId(): string;
|
|
289
397
|
};
|
|
290
398
|
|
|
291
|
-
export { FISCAL_STATUSES, type FiscalStatus, INVOICE_SOURCES, InvoiceEvents, type InvoiceSource, InvoiceStatus, TransactionEvents, TransactionKind };
|
|
399
|
+
export { FISCAL_STATUSES, type FiscalStatus, INVOICE_SOURCES, InvoiceEvents, type InvoiceSource, InvoiceStatus, NumberingEvents, TransactionEvents, TransactionKind };
|
package/dist/events.js
CHANGED
|
@@ -3,14 +3,16 @@ import {
|
|
|
3
3
|
INVOICE_SOURCES,
|
|
4
4
|
InvoiceEvents,
|
|
5
5
|
InvoiceStatus,
|
|
6
|
+
NumberingEvents,
|
|
6
7
|
TransactionEvents,
|
|
7
8
|
TransactionKind
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JS6GUXCC.js";
|
|
9
10
|
export {
|
|
10
11
|
FISCAL_STATUSES,
|
|
11
12
|
INVOICE_SOURCES,
|
|
12
13
|
InvoiceEvents,
|
|
13
14
|
InvoiceStatus,
|
|
15
|
+
NumberingEvents,
|
|
14
16
|
TransactionEvents,
|
|
15
17
|
TransactionKind
|
|
16
18
|
};
|