financy 0.2.0 → 0.4.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 CHANGED
@@ -36,7 +36,7 @@ The CLI talks to your Open-Finance data through the Financy API, which is a **pa
36
36
  feature**. To use it you must:
37
37
 
38
38
  1. **Register for a Financy account** at [open-finance.ai](https://open-finance.ai).
39
- 2. **Subscribe to a paid plan** (Starter or Pro) — the data API is **not** available
39
+ 2. **Subscribe to any paid plan** (Starter, Pro, or Ultra) — the data API is **not** available
40
40
  on the free plan (every data command returns exit code `4`).
41
41
  3. Copy your `clientId`, `clientSecret`, and `userId` from the Financy app →
42
42
  **Settings → API**.
@@ -80,6 +80,11 @@ financy transactions list|get <id> Transactions with --from/--to/--account/--t
80
80
  financy categories The category taxonomy (English + Hebrew)
81
81
  financy providers list|branches Reference data: banks and branches
82
82
  financy refresh Trigger an on-demand refresh of all connections (20 credits)
83
+ financy integrations list|get <id> Connected business systems (invoicing: Invoice4U)
84
+ financy receivables Who owes you what: open and overdue invoices, aged per customer
85
+ financy documents list|get Invoices, receipts and credit notes in a business system
86
+ financy customers list|get Customers in a business system
87
+ financy proposals list|get|create Document drafts — issued only after you approve them in Financy
83
88
  financy config Show resolved endpoints + credential sources (secret masked)
84
89
  financy skills list|install Agent skills bundled with the CLI
85
90
  financy mcp Run the embedded MCP server (stdio)
@@ -95,6 +100,155 @@ Every command takes `--json` for a stable machine-readable envelope
95
100
  `--all` (auto-paginate). Exit codes: `0` ok · `1` unexpected · `2` usage · `3` auth
96
101
  · `4` plan · `5` credits · `6` not-found · `7` api.
97
102
 
103
+ ## Connect bit (digital wallet) and ask about it
104
+
105
+ bit can now be connected to Financy as a **digital wallet** (ארנק דיגיטלי). The
106
+ connection runs over regulated Open Banking and is **read-only**: Financy reads the
107
+ wallet account, its balance, and its transactions. It cannot send or request
108
+ payments, and there is no savings data.
109
+
110
+ ### 1. Connect bit — from your phone
111
+
112
+ bit approves Open Banking consents **only inside its mobile app**, so start the
113
+ connection on the phone that has bit installed:
114
+
115
+ 1. Open the Financy app at [financy.open-finance.ai](https://financy.open-finance.ai)
116
+ in your phone's browser.
117
+ 2. **Connect account** → the **ארנקים** (wallets) tab → **bit**.
118
+ 3. Approve the consent in the bit app when it opens, then return to Financy.
119
+
120
+ Starting from a desktop browser will not work — the approval step has to land in
121
+ the bit app.
122
+
123
+ ### 2. Ask about it from the CLI
124
+
125
+ bit is a connection like any bank or card, with provider id `bit`. There are no
126
+ wallet-specific commands; filter by its connection id:
127
+
128
+ ```sh
129
+ financy connections list # bit appears with PROVIDER "bit" — copy its ID
130
+ financy status # is the bit data current?
131
+ financy accounts list --connection <bit-connection-id> # the wallet and its balance
132
+ financy transactions list --connection <bit-connection-id> --from 2026-09-01 --all
133
+ financy transactions list --connection <bit-connection-id> --from 2026-09-01 --all --json
134
+ ```
135
+
136
+ Leave out `--connection` and you get every source at once — bit next to your banks
137
+ (e.g. Bank Hapoalim, provider `hapoalim`) and cards (e.g. Isracard, provider
138
+ `isracard`):
139
+
140
+ ```sh
141
+ financy accounts list # bit, bank, and card balances together
142
+ financy transactions list --from 2026-09-01 --all # this month, every source
143
+ financy providers list # resolve any PROVIDER value to its name
144
+ ```
145
+
146
+ ### 3. Ask about it from Claude or ChatGPT
147
+
148
+ Through the MCP server the same data is available as tools: `list_connections`
149
+ and `get_status` to find bit and check freshness, `list_accounts` and
150
+ `list_transactions` (both take a `connection` argument, and `list_transactions`
151
+ takes `from`/`to`) to read it, and `list_providers` to resolve provider ids.
152
+
153
+ - **Claude Code**, with the local server: `claude mcp add financy -- npx financy mcp`
154
+ (see [MCP server](#mcp-server-for-ai-agents)).
155
+ - **Claude or ChatGPT**, with no CLI: add the hosted Financy connector,
156
+ `https://mcp.open-finance.ai/mcp`, as a custom connector and sign in with your
157
+ Financy account.
158
+
159
+ Then ask in plain language. The assistant pulls bit, bank, and card transactions
160
+ and combines them. Questions like "who hasn't paid yet" work by comparing this
161
+ period's incoming bit transfers with earlier ones — give the assistant the list of
162
+ who you expect to pay if you have one.
163
+
164
+ ### Prompts for business owners
165
+
166
+ | Prompt | In English |
167
+ |---|---|
168
+ | «מי עוד לא שילם לי החודש?» | Who hasn't paid me yet this month? |
169
+ | «מי שילם לי פעמיים בטעות?» | Who paid me twice by mistake? |
170
+ | «כמה עשיתי היום?» | How much did I take in today? |
171
+ | «מי מהלקוחות הקבועים נעלם לי?» | Which regular customers have stopped paying? |
172
+ | «כמה כסף שוכב לי בביט ולא עבר לבנק?» | How much is sitting in bit and hasn't moved to the bank? |
173
+ | «איזה יום בשבוע הכי רווחי לי?» | Which day of the week brings in the most? |
174
+ | «כמה נכנס החודש מכל החשבונות — ביט והבנק ביחד?» | How much came in this month across all accounts — bit and the bank together? |
175
+ | «תן לי רשימה של כל מי ששילם לי בביט השבוע, עם סכום ותאריך» | List everyone who paid me on bit this week, with amount and date. |
176
+ | «מה התשלום הממוצע בביט החודש לעומת החודש שעבר?» | What's the average bit payment this month versus last month? |
177
+ | «תבנה לי דאשבורד שאני פותח כל בוקר: הכנסות מביט ומהבנק, הוצאות בישראכרט, ומי עוד לא שילם» | Build me a dashboard I open every morning: income from bit and the bank, Isracard spending, and who still hasn't paid. |
178
+
179
+ ## Invoices (Invoice4U)
180
+
181
+ Connect your invoicing system to Financy and the CLI reads it next to your bank
182
+ data: who owes you what, every invoice and receipt, your customers — and it can
183
+ **draft** documents for you to approve. Invoice4U is supported today; it needs a
184
+ paid plan (Starter and above), and a free account gets exit `4` with the code
185
+ `UPGRADE_REQUIRED`.
186
+
187
+ Connect Invoice4U in the Financy app, on the **Connections** page; the CLI reads
188
+ connections, it does not create them. Then:
189
+
190
+ ```sh
191
+ financy integrations list # copy the integration ID (intg_…)
192
+ financy receivables # open and overdue totals, per customer
193
+ financy receivables --detailed --json # …with each customer's open invoices
194
+ financy documents list <integrationId> --status open --from 2026-09-01
195
+ financy documents list <integrationId> --receivable-only --all --json
196
+ financy documents get <integrationId> <documentId>
197
+ financy customers list <integrationId> --search "סטודיו"
198
+ ```
199
+
200
+ ```
201
+ $ financy receivables
202
+ Receivables as of 2026-10-11
203
+ ILS: ₪2,340.00 open, ₪2,340.00 overdue across 1 documents
204
+
205
+ CUSTOMER OPEN OVERDUE DOCS MAX DAYS LATE CUSTOMER ID
206
+ סטודיו גל ₪2,340.00 ₪2,340.00 1 10 icus_…
207
+ ```
208
+
209
+ Tables show amounts in shekels; under `--json` every amount is an integer in minor
210
+ units (`…Minor`, agorot for ILS) exactly as the API returns it, and record lists
211
+ carry a `freshness` object saying how recent the synced data is. Record lists page
212
+ with `--limit`, `--cursor` and `--all`; `proposals list` takes only `--limit` (max 50).
213
+
214
+ ### Drafting a document
215
+
216
+ `financy proposals create` sends a draft request and creates a **draft** — nothing
217
+ is issued. The document is created in Invoice4U only after you open the returned
218
+ approval link and approve it in Financy:
219
+
220
+ ```sh
221
+ cat > draft.json <<'JSON'
222
+ {
223
+ "action": "create_tax_invoice",
224
+ "items": [{
225
+ "counterpartyId": "icus_…",
226
+ "lines": [{ "description": "עיצוב לוגו", "quantity": 1, "unitPriceMinor": 234000 }],
227
+ "pricesIncludeVat": true
228
+ }]
229
+ }
230
+ JSON
231
+ financy proposals create <integrationId> --file draft.json
232
+ financy proposals get <proposalId> # status: pending_approval → completed
233
+ ```
234
+
235
+ `action` is one of `create_tax_invoice`, `create_invoice_receipt`, `create_receipt`,
236
+ `create_credit_note` or `create_customer`. Each request carries an `Idempotency-Key`
237
+ (a fresh UUID unless you pass `--idempotency-key`), so retrying with the same key
238
+ returns the first draft instead of a second one. The CLI cannot approve or cancel a
239
+ draft — that is always your step in Financy.
240
+
241
+ Integration errors keep the API's code (`UPGRADE_REQUIRED`, `NOT_FOUND`,
242
+ `VALIDATION_FAILED`, `PROPOSAL_INVALID`, `RATE_LIMITED`, …) and exit by class: `4`
243
+ plan or permission, `6` not found, `2` invalid request, `1` conflict or expired
244
+ cursor, `7` rate-limited or unavailable. Under `--json` the error also carries
245
+ `retryable`, `userActionRequired` and, where the API gives one, an `action`.
246
+ `INSUFFICIENT_SCOPE` means the token predates the key's integration access: the CLI
247
+ mints a fresh one and retries once, and if that is refused too, the key has no
248
+ integration access yet (Starter or above; rotate the key in Financy → Settings → API).
249
+ The integrations API lives at `https://api.open-finance.ai/integrations`; override it
250
+ with `FINANCY_INTEGRATIONS_URL` (it otherwise follows `FINANCY_API_URL`'s host).
251
+
98
252
  ## Agent skills
99
253
 
100
254
  Skills ship inside this package, so they can never drift from the CLI version they
@@ -130,6 +284,16 @@ an unconfigured server returns a structured `NOT_CONFIGURED` error from every to
130
284
  `refresh_connections` costs 20 credits — its tool description tells agents to
131
285
  confirm with the user first.
132
286
 
287
+ The local server also serves the invoicing tools — `list_integrations`,
288
+ `get_integration`, `get_receivables`, `list_invoicing_documents`,
289
+ `get_invoicing_document`, `list_invoicing_customers`, `get_invoicing_customer`,
290
+ `list_proposals`, `get_proposal`, and the draft tools `draft_invoice`,
291
+ `draft_invoice_receipt`, `draft_receipt` and `draft_credit_note`. A draft tool only
292
+ creates a draft: its description tells the agent to show the user the approval link,
293
+ and nothing is issued until the user approves it in Financy. These tools are not in
294
+ the importable `TOOLS` table, because hosts that import it (such as the hosted
295
+ Financy connector) serve their own invoicing tools under the same names.
296
+
133
297
  ## Updating
134
298
 
135
299
  ```sh
package/dist/bin.js CHANGED
@@ -4,13 +4,23 @@ import {
4
4
  EXIT,
5
5
  STALE_THRESHOLD_DAYS,
6
6
  VERSION,
7
+ createDraft,
7
8
  fetchAccount,
8
9
  fetchAccounts,
9
10
  fetchBranches,
10
11
  fetchCategories,
11
12
  fetchConnection,
12
13
  fetchConnections,
14
+ fetchIntegration,
15
+ fetchIntegrations,
16
+ fetchInvoicingCustomer,
17
+ fetchInvoicingCustomers,
18
+ fetchInvoicingDocument,
19
+ fetchInvoicingDocuments,
20
+ fetchProposal,
21
+ fetchProposals,
13
22
  fetchProviders,
23
+ fetchReceivables,
14
24
  fetchRefresh,
15
25
  fetchStatus,
16
26
  fetchTransaction,
@@ -23,7 +33,7 @@ import {
23
33
  resolveEndpoints,
24
34
  sanitizeCredential,
25
35
  writeCredentialsFile
26
- } from "./chunk-QYWDNIM2.js";
36
+ } from "./chunk-LZSZIBYL.js";
27
37
 
28
38
  // src/run.ts
29
39
  import { Command, CommanderError } from "commander";
@@ -99,7 +109,7 @@ function renderTable(items, now) {
99
109
 
100
110
  // src/commands/setup.ts
101
111
  import { join } from "path";
102
- var CREDENTIALS_GUIDE = "financy needs your Financy API credentials: clientId, clientSecret, and userId.\nFind them in the Financy app \u2192 Settings \u2192 API.\nThis requires a registered Financy account on a paid plan (Starter or Pro) \u2014\nthe data API is not available on the free plan. Sign up at https://open-finance.ai\n\n";
112
+ var CREDENTIALS_GUIDE = "financy needs your Financy API credentials: clientId, clientSecret, and userId.\nFind them in the Financy app \u2192 Settings \u2192 API.\nThis requires a registered Financy account on a paid plan (Starter, Pro, or Ultra) \u2014\nthe data API is not available on the free plan. Sign up at https://open-finance.ai\n\n";
103
113
  async function setupCommand(ctx) {
104
114
  if (!ctx.noInput) ctx.out(CREDENTIALS_GUIDE);
105
115
  const credentials = ctx.noInput ? credentialsFromEnv(ctx.env) : await credentialsFromPrompts(ctx.prompt);
@@ -177,6 +187,7 @@ async function configCommand(ctx) {
177
187
  authTokenUrl: endpoints.authTokenUrl,
178
188
  apiBaseUrl: endpoints.apiBaseUrl,
179
189
  chatBaseUrl: endpoints.chatBaseUrl,
190
+ integrationsBaseUrl: endpoints.integrationsBaseUrl,
180
191
  clientId: clientId.value ? maskId(clientId.value) : null,
181
192
  clientIdSource: clientId.source,
182
193
  clientSecretSet: clientSecret.source !== "unset",
@@ -201,6 +212,7 @@ async function configCommand(ctx) {
201
212
  ` auth url ${endpoints.authTokenUrl}`,
202
213
  ` api url ${endpoints.apiBaseUrl}`,
203
214
  ` chat url ${endpoints.chatBaseUrl}`,
215
+ ` integrations ${endpoints.integrationsBaseUrl}`,
204
216
  "",
205
217
  ` clientId ${maskId(clientId.value)} (${clientId.source})`,
206
218
  ` clientSecret ${clientSecret.value ? `\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (set, ${clientSecret.value.length} chars)` : "(unset)"} (${clientSecret.source})`,
@@ -285,7 +297,12 @@ function renderList(ctx, envelope, columns) {
285
297
  if (ctx.json) {
286
298
  ctx.out(
287
299
  JSON.stringify(
288
- { data: envelope.data, count: envelope.count, nextPage: envelope.nextPage },
300
+ {
301
+ data: envelope.data,
302
+ count: envelope.count,
303
+ nextPage: envelope.nextPage,
304
+ ...envelope.freshness === void 0 ? {} : { freshness: envelope.freshness }
305
+ },
289
306
  null,
290
307
  2
291
308
  )
@@ -297,7 +314,16 @@ function renderList(ctx, envelope, columns) {
297
314
  }
298
315
  function renderGet(ctx, envelope) {
299
316
  if (ctx.json) {
300
- ctx.out(JSON.stringify({ data: envelope.data }, null, 2));
317
+ ctx.out(
318
+ JSON.stringify(
319
+ {
320
+ data: envelope.data,
321
+ ...envelope.freshness === void 0 ? {} : { freshness: envelope.freshness }
322
+ },
323
+ null,
324
+ 2
325
+ )
326
+ );
301
327
  } else {
302
328
  ctx.out(JSON.stringify(envelope.data, null, 2) + "\n");
303
329
  }
@@ -414,9 +440,192 @@ function registerReadCommands(program, base, setExit) {
414
440
  });
415
441
  }
416
442
 
443
+ // src/commands/integration-commands.ts
444
+ import { readFile } from "fs/promises";
445
+ import { randomUUID } from "crypto";
446
+ var SYMBOLS = { ILS: "\u20AA", USD: "$", EUR: "\u20AC", GBP: "\xA3" };
447
+ var money = (minor, currency = "ILS") => {
448
+ if (typeof minor !== "number" || !Number.isFinite(minor)) return "\u2014";
449
+ const code = typeof currency === "string" ? currency : "ILS";
450
+ const symbol = SYMBOLS[code] ?? `${code} `;
451
+ const major = Math.abs(minor) / 100;
452
+ return (minor < 0 ? "-" : "") + symbol + major.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
453
+ };
454
+ var INTEGRATION_COLUMNS = [
455
+ { header: "ID", value: (i) => i.id },
456
+ { header: "SYSTEM", value: (i) => dash(i.connectorName) },
457
+ { header: "LABEL", value: (i) => dash(i.label) },
458
+ { header: "AUTH", value: (i) => dash(i.auth?.state) },
459
+ { header: "SYNC", value: (i) => dash(i.sync?.documents?.state) },
460
+ { header: "SYNCED AT", value: (i) => dash(i.sync?.documents?.lastSuccessAt) }
461
+ ];
462
+ var DOCUMENT_COLUMNS = [
463
+ { header: "ISSUED", value: (d) => dash(d.issueDate) },
464
+ { header: "TYPE", value: (d) => dash(d.type) },
465
+ { header: "NUMBER", value: (d) => dash(d.number) },
466
+ { header: "CUSTOMER", value: (d) => dash(d.counterparty?.name) },
467
+ { header: "GROSS", value: (d) => money(d.amounts?.grossMinor, d.currency) },
468
+ { header: "OWED", value: (d) => money(d.receivable?.remainingMinor, d.currency) },
469
+ { header: "STATUS", value: (d) => dash(d.status) },
470
+ { header: "ID", value: (d) => d.id }
471
+ ];
472
+ function newestFirst(a, b) {
473
+ const byDate = (b.issueDate ?? "").localeCompare(a.issueDate ?? "");
474
+ if (byDate !== 0) return byDate;
475
+ return (b.number ?? "").localeCompare(a.number ?? "", "en", { numeric: true });
476
+ }
477
+ var CUSTOMER_COLUMNS = [
478
+ { header: "ID", value: (c) => c.id },
479
+ { header: "NAME", value: (c) => dash(c.name) },
480
+ { header: "TAX ID", value: (c) => dash(c.businessTaxId) },
481
+ { header: "ACTIVE", value: (c) => c.active === false ? "no" : "yes" }
482
+ ];
483
+ var PROPOSAL_COLUMNS = [
484
+ { header: "ID", value: (p) => p.id },
485
+ { header: "ACTION", value: (p) => dash(p.action) },
486
+ { header: "STATUS", value: (p) => dash(p.status) },
487
+ { header: "ITEMS", value: (p) => dash(p.totals?.count ?? p.items?.length) },
488
+ { header: "TOTAL", value: (p) => money(p.totals?.grossMinor, p.totals?.currency) },
489
+ { header: "CREATED", value: (p) => dash(p.createdAt) },
490
+ { header: "EXPIRES", value: (p) => dash(p.expiresAt) }
491
+ ];
492
+ var RECEIVABLE_COLUMNS = [
493
+ { header: "CUSTOMER", value: (c) => dash(c.counterparty?.name) },
494
+ { header: "OPEN", value: (c) => money(c.openMinor, c.currency) },
495
+ { header: "OVERDUE", value: (c) => money(c.overdueMinor, c.currency) },
496
+ { header: "DOCS", value: (c) => dash(c.documentCount) },
497
+ { header: "MAX DAYS LATE", value: (c) => dash(c.maxDaysPastDue) },
498
+ { header: "CUSTOMER ID", value: (c) => dash(c.counterparty?.id) }
499
+ ];
500
+ function renderReceivables(r) {
501
+ const lines = [`Receivables as of ${dash(r.asOf)}`];
502
+ for (const c of r.byCurrency ?? []) {
503
+ lines.push(
504
+ ` ${dash(c.currency)}: ${money(c.totals?.openMinor, c.currency)} open, ${money(c.totals?.overdueMinor, c.currency)} overdue across ${dash(c.totals?.documentCount)} documents`
505
+ );
506
+ }
507
+ if ((r.byCurrency ?? []).length === 0) lines.push(" Nothing is owed.");
508
+ let out = lines.join("\n") + "\n";
509
+ const customers = r.customers ?? [];
510
+ if (customers.length > 0) out += "\n" + renderTable2(customers, RECEIVABLE_COLUMNS);
511
+ const shown = r.truncated?.customersShown;
512
+ const total = r.truncated?.customersTotal;
513
+ if (typeof shown === "number" && typeof total === "number" && shown < total) {
514
+ out += `
515
+ Showing ${shown} of ${total} customers \u2014 raise --customer-limit to see more.
516
+ `;
517
+ }
518
+ for (const i of r.integrations ?? []) {
519
+ if (i.ready === "pending") {
520
+ out += `Note: ${dash(i.integrationId)} is still running its first sync \u2014 totals are incomplete.
521
+ `;
522
+ } else if (i.stale) {
523
+ out += `Note: ${dash(i.integrationId)} data is stale (last synced ${dash(i.dataAsOf)}).
524
+ `;
525
+ }
526
+ }
527
+ return out;
528
+ }
529
+ function renderDraft(p, replayed) {
530
+ const count = p.totals?.count ?? p.items?.length;
531
+ return [
532
+ `Draft ${p.id} created${replayed ? " (replayed \u2014 the same draft as the first request)" : ""} \u2014 status ${dash(p.status)}.`,
533
+ ` ${dash(p.action)} \xB7 ${dash(count)} item${count === 1 ? "" : "s"} \xB7 ${money(p.totals?.grossMinor, p.totals?.currency)}`,
534
+ "",
535
+ ` Approve it in Financy: ${dash(p.approvalUrl)}`,
536
+ ` Nothing is issued until you approve it there. The draft expires ${dash(p.expiresAt)}.`
537
+ ].join("\n") + "\n";
538
+ }
539
+ async function readDraftFile(path) {
540
+ let text;
541
+ try {
542
+ text = await readFile(path, "utf8");
543
+ } catch (error) {
544
+ throw new CliError(
545
+ EXIT.USAGE,
546
+ "DRAFT_FILE_UNREADABLE",
547
+ `could not read ${path}: ${error.code ?? String(error)}`
548
+ );
549
+ }
550
+ try {
551
+ return JSON.parse(text.replace(/^\uFEFF/, ""));
552
+ } catch (error) {
553
+ throw new CliError(EXIT.USAGE, "INVALID_DRAFT", `${path} is not valid JSON (${error.message})`);
554
+ }
555
+ }
556
+ function registerIntegrationCommands(program, base, setExit) {
557
+ const ctx = { json: base.json, out: base.out };
558
+ const integrations = program.command("integrations").description("Connected business systems (invoicing: Invoice4U)");
559
+ integrations.command("list").option("--json", "machine-readable output").action(async () => {
560
+ const config = await loadOrThrow(base.env);
561
+ setExit(renderList(ctx, await fetchIntegrations(config, base.now), INTEGRATION_COLUMNS));
562
+ });
563
+ integrations.command("get <integrationId>").option("--json", "machine-readable output").action(async (id) => {
564
+ const config = await loadOrThrow(base.env);
565
+ setExit(renderGet(ctx, await fetchIntegration(config, base.now, id)));
566
+ });
567
+ program.command("receivables").description("Who owes you what: open and overdue invoices, aged per customer").option("--integration <ids>", "limit to these integration ids (comma-separated)").option("--as-of <date>", "age receivables against this date (YYYY-MM-DD, default today)").option("--detailed", "also list each customer's open documents").option("--customer-limit <n>", "how many customers to return (max 200)").option("--include-proforma", "count open proforma invoices too").option("--json", "machine-readable output").action(
568
+ async (opts) => {
569
+ const config = await loadOrThrow(base.env);
570
+ const envelope = await fetchReceivables(config, base.now, {
571
+ integrations: opts.integration ? [opts.integration] : void 0,
572
+ asOf: opts.asOf,
573
+ detailed: opts.detailed,
574
+ customerLimit: opts.customerLimit,
575
+ includeProforma: opts.includeProforma
576
+ });
577
+ base.out(base.json ? JSON.stringify(envelope, null, 2) : renderReceivables(envelope.data));
578
+ setExit(EXIT.OK);
579
+ }
580
+ );
581
+ const documents = program.command("documents").description("Invoices, receipts and credit notes in a connected business system");
582
+ documents.command("list <integrationId>").option("--status <status>", "open|partially_paid|paid|partially_credited|credited|cancelled|closed|unknown").option("--type <type>", "invoice|receipt|invoice_receipt|credit_note|proforma|quote|order|delivery_note|other").option("--customer <customerId>", "filter to one customer (icus_\u2026 from customers list)").option("--from <date>", "issued on or after (YYYY-MM-DD)").option("--to <date>", "issued on or before (YYYY-MM-DD)").option("--receivable-only", "only documents that are still owed money").option("--number <number>", "the document number").option("--limit <n>", "page size (max 200)").option("--cursor <token>", "resume from a nextPage cursor").option("--all", "auto-paginate to the end").option("--json", "machine-readable output").action(async (integrationId, opts) => {
583
+ const config = await loadOrThrow(base.env);
584
+ const envelope = await fetchInvoicingDocuments(config, base.now, integrationId, opts);
585
+ const rows = base.json ? envelope : { ...envelope, data: [...envelope.data].sort(newestFirst) };
586
+ setExit(renderList(ctx, rows, DOCUMENT_COLUMNS));
587
+ });
588
+ documents.command("get <integrationId> <documentId>").option("--json", "machine-readable output").action(async (integrationId, documentId) => {
589
+ const config = await loadOrThrow(base.env);
590
+ setExit(renderGet(ctx, await fetchInvoicingDocument(config, base.now, integrationId, documentId)));
591
+ });
592
+ const customers = program.command("customers").description("Customers in a connected business system");
593
+ customers.command("list <integrationId>").option("--search <text>", "part of the customer name").option("--limit <n>", "page size (max 200)").option("--cursor <token>", "resume from a nextPage cursor").option("--all", "auto-paginate to the end").option("--json", "machine-readable output").action(async (integrationId, opts) => {
594
+ const config = await loadOrThrow(base.env);
595
+ const envelope = await fetchInvoicingCustomers(config, base.now, integrationId, opts);
596
+ setExit(renderList(ctx, envelope, CUSTOMER_COLUMNS));
597
+ });
598
+ customers.command("get <integrationId> <customerId>").option("--json", "machine-readable output").action(async (integrationId, customerId) => {
599
+ const config = await loadOrThrow(base.env);
600
+ setExit(renderGet(ctx, await fetchInvoicingCustomer(config, base.now, integrationId, customerId)));
601
+ });
602
+ const proposals = program.command("proposals").description("Document drafts \u2014 issued only after you approve them in Financy");
603
+ proposals.command("list").option("--integration <id>", "filter to one integration").option("--status <status>", "pending_approval|approved|executing|completed|partially_failed|failed|expired|cancelled").option("--reference <ref>", "filter by the clientReference you sent").option("--limit <n>", "how many (max 50; this list has no cursor)").option("--json", "machine-readable output").action(async (opts) => {
604
+ const config = await loadOrThrow(base.env);
605
+ setExit(renderList(ctx, await fetchProposals(config, base.now, opts), PROPOSAL_COLUMNS));
606
+ });
607
+ proposals.command("get <proposalId>").option("--json", "machine-readable output").action(async (id) => {
608
+ const config = await loadOrThrow(base.env);
609
+ setExit(renderGet(ctx, await fetchProposal(config, base.now, id)));
610
+ });
611
+ proposals.command("create <integrationId>").description("Create a document DRAFT from a JSON file; it is issued only after you approve it in Financy").requiredOption("--file <path>", 'the draft request JSON: {"action": "...", "items": [...]}').option("--idempotency-key <key>", "reuse a key to make a retry return the first draft (default: a new UUID)").option("--json", "machine-readable output").action(async (integrationId, opts) => {
612
+ const config = await loadOrThrow(base.env);
613
+ const body = await readDraftFile(opts.file);
614
+ const envelope = await createDraft(
615
+ config,
616
+ base.now,
617
+ integrationId,
618
+ body,
619
+ opts.idempotencyKey ?? randomUUID()
620
+ );
621
+ base.out(base.json ? JSON.stringify(envelope, null, 2) : renderDraft(envelope.data, envelope.replayed));
622
+ setExit(EXIT.OK);
623
+ });
624
+ }
625
+
417
626
  // src/commands/skills.ts
418
627
  import { existsSync } from "fs";
419
- import { cp, readFile, readdir, stat } from "fs/promises";
628
+ import { cp, readFile as readFile2, readdir, stat } from "fs/promises";
420
629
  import { dirname, join as join2 } from "path";
421
630
  import { fileURLToPath } from "url";
422
631
  var INSTALL_SUBPATH = join2(".claude", "skills");
@@ -462,7 +671,7 @@ async function listSkills(skillsRoot) {
462
671
  for (const name of entries) {
463
672
  const file = join2(skillsRoot, name, "SKILL.md");
464
673
  try {
465
- const front = parseFrontmatter(await readFile(file, "utf8"));
674
+ const front = parseFrontmatter(await readFile2(file, "utf8"));
466
675
  skills.push({ name: front.name ?? name, description: front.description ?? "" });
467
676
  } catch {
468
677
  }
@@ -740,7 +949,7 @@ async function run(argv, io = {}) {
740
949
  exitCode = await configCommand({ env, json, out });
741
950
  });
742
951
  program.command("mcp").description("Run the embedded MCP server (stdio) exposing the CLI as agent tools").action(async () => {
743
- const { startMcpServer } = await import("./server-N5ZPO432.js");
952
+ const { startMcpServer } = await import("./server-WGN36UXM.js");
744
953
  await startMcpServer(env);
745
954
  });
746
955
  const skills = program.command("skills").description("Agent skills bundled with financy (Claude Code and other agents)");
@@ -773,6 +982,9 @@ async function run(argv, io = {}) {
773
982
  registerReadCommands(program, { env, now, json, out }, (code) => {
774
983
  exitCode = code;
775
984
  });
985
+ registerIntegrationCommands(program, { env, now, json, out }, (code) => {
986
+ exitCode = code;
987
+ });
776
988
  if (argv.length === 0) {
777
989
  program.outputHelp();
778
990
  return EXIT.OK;