bonbox 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/README.md +89 -0
- package/dist/cli.js +1456 -0
- package/dist/cli.js.map +1 -0
- package/package.json +35 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1456 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { defineCommand as defineCommand6, runCommand, showUsage } from "citty";
|
|
5
|
+
|
|
6
|
+
// src/commands/account.ts
|
|
7
|
+
import { defineCommand } from "citty";
|
|
8
|
+
|
|
9
|
+
// src/auth.ts
|
|
10
|
+
import { createClient } from "@supabase/supabase-js";
|
|
11
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
12
|
+
import { homedir } from "os";
|
|
13
|
+
import { dirname, join } from "path";
|
|
14
|
+
|
|
15
|
+
// src/config.ts
|
|
16
|
+
var SUPABASE_URL = "https://gaxsaareqnpthuyjfwrz.supabase.co";
|
|
17
|
+
var SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImdheHNhYXJlcW5wdGh1eWpmd3J6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzU3NDkxMjcsImV4cCI6MjA1MTMyNTEyN30.iUiUnilZnLlLLoGam4hC5qcmhC4oDtB2sZDGz0xHU8k";
|
|
18
|
+
var APP_URL = "https://app.bonbox.io";
|
|
19
|
+
var DEFAULT_API_BASE = "https://app.bonbox.io/api/v1";
|
|
20
|
+
var SCAN_BASE = `${SUPABASE_URL}/functions/v1/api-v1`;
|
|
21
|
+
function resolveBase(env, fallback) {
|
|
22
|
+
const raw = env.BONBOX_API_URL?.trim();
|
|
23
|
+
return (raw && raw.length > 0 ? raw : fallback).replace(/\/+$/, "");
|
|
24
|
+
}
|
|
25
|
+
function apiBase(env = process.env) {
|
|
26
|
+
return resolveBase(env, DEFAULT_API_BASE);
|
|
27
|
+
}
|
|
28
|
+
function scanBase(env = process.env) {
|
|
29
|
+
return resolveBase(env, SCAN_BASE);
|
|
30
|
+
}
|
|
31
|
+
var CALLBACK_PORTS = [51823, 51824, 51825];
|
|
32
|
+
|
|
33
|
+
// src/i18n/en.json
|
|
34
|
+
var en_default = {
|
|
35
|
+
cli_app_description: "Manage your bonbox receipts, invoices and customers from the terminal.",
|
|
36
|
+
cli_cmd_login: "Sign in to your bonbox account",
|
|
37
|
+
cli_cmd_logout: "Sign out on this machine",
|
|
38
|
+
cli_cmd_whoami: "Show the account you are signed in with",
|
|
39
|
+
cli_cmd_customers: "Work with your customers",
|
|
40
|
+
cli_cmd_customers_ls: "List your customers",
|
|
41
|
+
cli_cmd_invoices: "Work with your invoices and quotes",
|
|
42
|
+
cli_cmd_invoices_ls: "List invoices and quotes",
|
|
43
|
+
cli_cmd_invoices_create: "Create an invoice or a quote",
|
|
44
|
+
cli_cmd_invoices_pdf: "Download the PDF of an invoice or quote",
|
|
45
|
+
cli_cmd_invoices_paid: "Mark an invoice as paid",
|
|
46
|
+
cli_cmd_invoices_unpaid: "Mark an invoice as unpaid again",
|
|
47
|
+
cli_cmd_receipts: "Work with your receipts",
|
|
48
|
+
cli_cmd_receipts_ls: "List your receipts",
|
|
49
|
+
cli_cmd_receipts_add: "Add a receipt by hand",
|
|
50
|
+
cli_cmd_receipts_scan: "Upload a receipt and let bonbox read it",
|
|
51
|
+
cli_flag_json: "Print the raw API response as JSON",
|
|
52
|
+
cli_flag_lang: "Output language (en, de, fr, it)",
|
|
53
|
+
cli_flag_provider: "Sign-in provider: google or apple",
|
|
54
|
+
cli_flag_archived: "Include archived customers",
|
|
55
|
+
cli_flag_status: "Filter by status: created or paid",
|
|
56
|
+
cli_flag_quotes: "Show quotes instead of invoices",
|
|
57
|
+
cli_flag_customer_ref: "Customer name or ID",
|
|
58
|
+
cli_flag_item: "Line item as description:quantity:unitPrice[:discount%], can be repeated",
|
|
59
|
+
cli_flag_quote: "Create a quote instead of an invoice",
|
|
60
|
+
cli_flag_invoice_date: "Invoice date (YYYY-MM-DD), today by default",
|
|
61
|
+
cli_flag_payment_days: "Payment term in days",
|
|
62
|
+
cli_flag_currency: "Currency code, for example CHF",
|
|
63
|
+
cli_flag_language: "Document language: de, en, fr or it",
|
|
64
|
+
cli_flag_subtitle: "Subtitle shown on the document",
|
|
65
|
+
cli_flag_reference: "Your reference for this document",
|
|
66
|
+
cli_flag_pdf: "Also save the PDF to this file",
|
|
67
|
+
cli_flag_output: "Save the PDF to this file",
|
|
68
|
+
cli_flag_paid_date: "Payment date (YYYY-MM-DD), today by default",
|
|
69
|
+
cli_flag_no_receipt: "Do not book the payment as income",
|
|
70
|
+
cli_flag_month: "Limit to one month (YYYY-MM)",
|
|
71
|
+
cli_flag_from: "Start date (YYYY-MM-DD)",
|
|
72
|
+
cli_flag_to: "End date (YYYY-MM-DD)",
|
|
73
|
+
cli_flag_project: "Project ID",
|
|
74
|
+
cli_flag_seller: "Seller, or the customer for income",
|
|
75
|
+
cli_flag_price: "Amount, for example 23.50",
|
|
76
|
+
cli_flag_receipt_date: "Receipt date (YYYY-MM-DD), today by default",
|
|
77
|
+
cli_flag_category: "Category",
|
|
78
|
+
cli_flag_tax_category: "Tax category",
|
|
79
|
+
cli_flag_booking_text: "Booking text",
|
|
80
|
+
cli_arg_invoice_ref: "Invoice number or ID",
|
|
81
|
+
cli_arg_scan_files: "Image or PDF files, all pages of one receipt",
|
|
82
|
+
cli_error_unauthorized: "You are not signed in. Run: bonbox login",
|
|
83
|
+
cli_error_pro_required: "This needs bonbox Pro. You can upgrade at %1$s",
|
|
84
|
+
cli_error_quota: "You have reached the limit of your plan. You can upgrade at %1$s",
|
|
85
|
+
cli_error_network: "Could not reach bonbox: %1$s",
|
|
86
|
+
cli_error_unexpected_response: "Unexpected answer from bonbox (HTTP %1$s)",
|
|
87
|
+
cli_error_item_format: 'Invalid item "%1$s". Expected description:quantity:unitPrice[:discount%]',
|
|
88
|
+
cli_error_item_number: 'Invalid number in item "%1$s"',
|
|
89
|
+
cli_error_items_required: "Add at least one line item with --item",
|
|
90
|
+
cli_error_customer_required: "Name a customer with --customer",
|
|
91
|
+
cli_error_price_required: "Give an amount with --price",
|
|
92
|
+
cli_error_seller_required: "Give a seller with --seller",
|
|
93
|
+
cli_error_price_invalid: "Invalid amount: %1$s",
|
|
94
|
+
cli_error_date_invalid: "Invalid date: %1$s. Expected YYYY-MM-DD",
|
|
95
|
+
cli_error_month_invalid: "Invalid month: %1$s. Expected YYYY-MM",
|
|
96
|
+
cli_error_customer_not_found: 'No customer matches "%1$s"',
|
|
97
|
+
cli_error_customer_ambiguous: '"%1$s" matches several customers:',
|
|
98
|
+
cli_error_files_required: "Name at least one file to scan",
|
|
99
|
+
cli_error_file_missing: "File not found: %1$s",
|
|
100
|
+
cli_login_opening: "Opening your browser to sign in ...",
|
|
101
|
+
cli_login_manual: "If your browser does not open, visit:\n%1$s",
|
|
102
|
+
cli_login_waiting: "Waiting for you to finish signing in ...",
|
|
103
|
+
cli_login_success: "Signed in as %1$s",
|
|
104
|
+
cli_login_failed: "Sign-in failed: %1$s",
|
|
105
|
+
cli_login_timeout: "Sign-in timed out. Please try again.",
|
|
106
|
+
cli_login_no_port: "No free port for the sign-in callback (tried %1$s).",
|
|
107
|
+
cli_callback_title: "Signed in to bonbox",
|
|
108
|
+
cli_callback_heading: "You are signed in",
|
|
109
|
+
cli_callback_body: "You can close this tab and go back to the terminal.",
|
|
110
|
+
cli_callback_error_heading: "Sign-in failed",
|
|
111
|
+
cli_callback_error_body: "Go back to the terminal and try again.",
|
|
112
|
+
cli_logout_done: "Signed out.",
|
|
113
|
+
cli_logout_none: "You were not signed in.",
|
|
114
|
+
cli_label_email: "Email",
|
|
115
|
+
cli_label_plan: "Plan",
|
|
116
|
+
cli_label_company: "Company",
|
|
117
|
+
cli_label_currency: "Currency",
|
|
118
|
+
cli_plan_pro: "Pro",
|
|
119
|
+
cli_plan_free: "Free",
|
|
120
|
+
cli_col_number: "Number",
|
|
121
|
+
cli_col_date: "Date",
|
|
122
|
+
cli_col_status: "Status",
|
|
123
|
+
cli_col_customer: "Customer",
|
|
124
|
+
cli_col_total: "Total",
|
|
125
|
+
cli_col_name: "Name",
|
|
126
|
+
cli_col_city: "City",
|
|
127
|
+
cli_col_id: "ID",
|
|
128
|
+
cli_col_seller: "Seller",
|
|
129
|
+
cli_col_amount: "Amount",
|
|
130
|
+
cli_col_category: "Category",
|
|
131
|
+
cli_col_archived: "Archived",
|
|
132
|
+
cli_status_created: "Open",
|
|
133
|
+
cli_status_paid: "Paid",
|
|
134
|
+
cli_yes: "yes",
|
|
135
|
+
cli_no: "no",
|
|
136
|
+
cli_empty_customers: "No customers yet.",
|
|
137
|
+
cli_empty_invoices: "No invoices yet.",
|
|
138
|
+
cli_empty_quotes: "No quotes yet.",
|
|
139
|
+
cli_empty_receipts: "No receipts found.",
|
|
140
|
+
cli_invoice_created: "Invoice %1$s created, %2$s",
|
|
141
|
+
cli_quote_created: "Quote %1$s created, %2$s",
|
|
142
|
+
cli_pdf_saved: "Saved to %1$s",
|
|
143
|
+
cli_invoice_paid: "%1$s marked as paid.",
|
|
144
|
+
cli_invoice_unpaid: "%1$s marked as unpaid.",
|
|
145
|
+
cli_receipt_added: "Receipt saved: %1$s, %2$s",
|
|
146
|
+
cli_scan_uploading: "Uploading %1$s file(s) ...",
|
|
147
|
+
cli_receipt_scanned: "Receipt saved: %1$s, %2$s (extracted automatically)"
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/i18n/de.json
|
|
151
|
+
var de_default = {
|
|
152
|
+
cli_app_description: "Belege, Rechnungen und Kunden von bonbox direkt im Terminal verwalten.",
|
|
153
|
+
cli_cmd_login: "Beim bonbox-Konto anmelden",
|
|
154
|
+
cli_cmd_logout: "Auf diesem Ger\xE4t abmelden",
|
|
155
|
+
cli_cmd_whoami: "Zeigt das angemeldete Konto",
|
|
156
|
+
cli_cmd_customers: "Kunden verwalten",
|
|
157
|
+
cli_cmd_customers_ls: "Kunden auflisten",
|
|
158
|
+
cli_cmd_invoices: "Rechnungen und Offerten verwalten",
|
|
159
|
+
cli_cmd_invoices_ls: "Rechnungen und Offerten auflisten",
|
|
160
|
+
cli_cmd_invoices_create: "Rechnung oder Offerte erstellen",
|
|
161
|
+
cli_cmd_invoices_pdf: "PDF einer Rechnung oder Offerte herunterladen",
|
|
162
|
+
cli_cmd_invoices_paid: "Rechnung als bezahlt markieren",
|
|
163
|
+
cli_cmd_invoices_unpaid: "Rechnung wieder als offen markieren",
|
|
164
|
+
cli_cmd_receipts: "Belege verwalten",
|
|
165
|
+
cli_cmd_receipts_ls: "Belege auflisten",
|
|
166
|
+
cli_cmd_receipts_add: "Beleg von Hand erfassen",
|
|
167
|
+
cli_cmd_receipts_scan: "Beleg hochladen und von bonbox auslesen lassen",
|
|
168
|
+
cli_flag_json: "Antwort der API als reines JSON ausgeben",
|
|
169
|
+
cli_flag_lang: "Sprache der Ausgabe (en, de, fr, it)",
|
|
170
|
+
cli_flag_provider: "Anmeldung \xFCber google oder apple",
|
|
171
|
+
cli_flag_archived: "Archivierte Kunden einschliessen",
|
|
172
|
+
cli_flag_status: "Nach Status filtern: created oder paid",
|
|
173
|
+
cli_flag_quotes: "Offerten statt Rechnungen anzeigen",
|
|
174
|
+
cli_flag_customer_ref: "Kundenname oder Kunden-ID",
|
|
175
|
+
cli_flag_item: "Position als Beschreibung:Menge:Einzelpreis[:Rabatt%], mehrfach m\xF6glich",
|
|
176
|
+
cli_flag_quote: "Offerte statt Rechnung erstellen",
|
|
177
|
+
cli_flag_invoice_date: "Rechnungsdatum (JJJJ-MM-TT), standardm\xE4ssig heute",
|
|
178
|
+
cli_flag_payment_days: "Zahlungsfrist in Tagen",
|
|
179
|
+
cli_flag_currency: "W\xE4hrung, zum Beispiel CHF",
|
|
180
|
+
cli_flag_language: "Sprache des Dokuments: de, en, fr oder it",
|
|
181
|
+
cli_flag_subtitle: "Untertitel auf dem Dokument",
|
|
182
|
+
cli_flag_reference: "Ihre Referenz f\xFCr dieses Dokument",
|
|
183
|
+
cli_flag_pdf: "PDF zus\xE4tzlich in diese Datei speichern",
|
|
184
|
+
cli_flag_output: "PDF in diese Datei speichern",
|
|
185
|
+
cli_flag_paid_date: "Zahlungsdatum (JJJJ-MM-TT), standardm\xE4ssig heute",
|
|
186
|
+
cli_flag_no_receipt: "Zahlung nicht als Einnahme verbuchen",
|
|
187
|
+
cli_flag_month: "Auf einen Monat einschr\xE4nken (JJJJ-MM)",
|
|
188
|
+
cli_flag_from: "Startdatum (JJJJ-MM-TT)",
|
|
189
|
+
cli_flag_to: "Enddatum (JJJJ-MM-TT)",
|
|
190
|
+
cli_flag_project: "Projekt-ID",
|
|
191
|
+
cli_flag_seller: "Anbieter, bei Einnahmen der Kunde",
|
|
192
|
+
cli_flag_price: "Betrag, zum Beispiel 23.50",
|
|
193
|
+
cli_flag_receipt_date: "Belegdatum (JJJJ-MM-TT), standardm\xE4ssig heute",
|
|
194
|
+
cli_flag_category: "Kategorie",
|
|
195
|
+
cli_flag_tax_category: "Steuerkategorie",
|
|
196
|
+
cli_flag_booking_text: "Buchungstext",
|
|
197
|
+
cli_arg_invoice_ref: "Rechnungsnummer oder ID",
|
|
198
|
+
cli_arg_scan_files: "Bild- oder PDF-Dateien, alle Seiten eines Belegs",
|
|
199
|
+
cli_error_unauthorized: "Sie sind nicht angemeldet. F\xFChren Sie aus: bonbox login",
|
|
200
|
+
cli_error_pro_required: "Daf\xFCr wird bonbox Pro ben\xF6tigt. Upgrade unter %1$s",
|
|
201
|
+
cli_error_quota: "Das Limit Ihres Abos ist erreicht. Upgrade unter %1$s",
|
|
202
|
+
cli_error_network: "bonbox ist nicht erreichbar: %1$s",
|
|
203
|
+
cli_error_unexpected_response: "Unerwartete Antwort von bonbox (HTTP %1$s)",
|
|
204
|
+
cli_error_item_format: 'Ung\xFCltige Position "%1$s". Erwartet: Beschreibung:Menge:Einzelpreis[:Rabatt%]',
|
|
205
|
+
cli_error_item_number: 'Ung\xFCltige Zahl in Position "%1$s"',
|
|
206
|
+
cli_error_items_required: "Erfassen Sie mindestens eine Position mit --item",
|
|
207
|
+
cli_error_customer_required: "Geben Sie einen Kunden mit --customer an",
|
|
208
|
+
cli_error_price_required: "Geben Sie einen Betrag mit --price an",
|
|
209
|
+
cli_error_seller_required: "Geben Sie einen Anbieter mit --seller an",
|
|
210
|
+
cli_error_price_invalid: "Ung\xFCltiger Betrag: %1$s",
|
|
211
|
+
cli_error_date_invalid: "Ung\xFCltiges Datum: %1$s. Erwartet: JJJJ-MM-TT",
|
|
212
|
+
cli_error_month_invalid: "Ung\xFCltiger Monat: %1$s. Erwartet: JJJJ-MM",
|
|
213
|
+
cli_error_customer_not_found: 'Kein Kunde passt zu "%1$s"',
|
|
214
|
+
cli_error_customer_ambiguous: '"%1$s" passt auf mehrere Kunden:',
|
|
215
|
+
cli_error_files_required: "Geben Sie mindestens eine Datei zum Scannen an",
|
|
216
|
+
cli_error_file_missing: "Datei nicht gefunden: %1$s",
|
|
217
|
+
cli_login_opening: "Browser wird zur Anmeldung ge\xF6ffnet ...",
|
|
218
|
+
cli_login_manual: "Falls sich der Browser nicht \xF6ffnet, rufen Sie auf:\n%1$s",
|
|
219
|
+
cli_login_waiting: "Warten auf den Abschluss der Anmeldung ...",
|
|
220
|
+
cli_login_success: "Angemeldet als %1$s",
|
|
221
|
+
cli_login_failed: "Anmeldung fehlgeschlagen: %1$s",
|
|
222
|
+
cli_login_timeout: "Zeit\xFCberschreitung bei der Anmeldung. Bitte erneut versuchen.",
|
|
223
|
+
cli_login_no_port: "Kein freier Port f\xFCr die Anmeldung (versucht: %1$s).",
|
|
224
|
+
cli_callback_title: "Bei bonbox angemeldet",
|
|
225
|
+
cli_callback_heading: "Sie sind angemeldet",
|
|
226
|
+
cli_callback_body: "Sie k\xF6nnen diesen Tab schliessen und zum Terminal zur\xFCckkehren.",
|
|
227
|
+
cli_callback_error_heading: "Anmeldung fehlgeschlagen",
|
|
228
|
+
cli_callback_error_body: "Kehren Sie zum Terminal zur\xFCck und versuchen Sie es erneut.",
|
|
229
|
+
cli_logout_done: "Abgemeldet.",
|
|
230
|
+
cli_logout_none: "Sie waren nicht angemeldet.",
|
|
231
|
+
cli_label_email: "E-Mail",
|
|
232
|
+
cli_label_plan: "Abo",
|
|
233
|
+
cli_label_company: "Firma",
|
|
234
|
+
cli_label_currency: "W\xE4hrung",
|
|
235
|
+
cli_plan_pro: "Pro",
|
|
236
|
+
cli_plan_free: "Gratis",
|
|
237
|
+
cli_col_number: "Nummer",
|
|
238
|
+
cli_col_date: "Datum",
|
|
239
|
+
cli_col_status: "Status",
|
|
240
|
+
cli_col_customer: "Kunde",
|
|
241
|
+
cli_col_total: "Total",
|
|
242
|
+
cli_col_name: "Name",
|
|
243
|
+
cli_col_city: "Ort",
|
|
244
|
+
cli_col_id: "ID",
|
|
245
|
+
cli_col_seller: "Anbieter",
|
|
246
|
+
cli_col_amount: "Betrag",
|
|
247
|
+
cli_col_category: "Kategorie",
|
|
248
|
+
cli_col_archived: "Archiviert",
|
|
249
|
+
cli_status_created: "Offen",
|
|
250
|
+
cli_status_paid: "Bezahlt",
|
|
251
|
+
cli_yes: "ja",
|
|
252
|
+
cli_no: "nein",
|
|
253
|
+
cli_empty_customers: "Noch keine Kunden.",
|
|
254
|
+
cli_empty_invoices: "Noch keine Rechnungen.",
|
|
255
|
+
cli_empty_quotes: "Noch keine Offerten.",
|
|
256
|
+
cli_empty_receipts: "Keine Belege gefunden.",
|
|
257
|
+
cli_invoice_created: "Rechnung %1$s erstellt, %2$s",
|
|
258
|
+
cli_quote_created: "Offerte %1$s erstellt, %2$s",
|
|
259
|
+
cli_pdf_saved: "Gespeichert unter %1$s",
|
|
260
|
+
cli_invoice_paid: "%1$s als bezahlt markiert.",
|
|
261
|
+
cli_invoice_unpaid: "%1$s als offen markiert.",
|
|
262
|
+
cli_receipt_added: "Beleg gespeichert: %1$s, %2$s",
|
|
263
|
+
cli_scan_uploading: "%1$s Datei(en) werden hochgeladen ...",
|
|
264
|
+
cli_receipt_scanned: "Beleg gespeichert: %1$s, %2$s (automatisch erkannt)"
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// src/i18n/fr.json
|
|
268
|
+
var fr_default = {
|
|
269
|
+
cli_app_description: "G\xE9rez vos justificatifs, factures et clients bonbox depuis le terminal.",
|
|
270
|
+
cli_cmd_login: "Se connecter \xE0 votre compte bonbox",
|
|
271
|
+
cli_cmd_logout: "Se d\xE9connecter sur cet appareil",
|
|
272
|
+
cli_cmd_whoami: "Afficher le compte connect\xE9",
|
|
273
|
+
cli_cmd_customers: "G\xE9rer vos clients",
|
|
274
|
+
cli_cmd_customers_ls: "Lister vos clients",
|
|
275
|
+
cli_cmd_invoices: "G\xE9rer vos factures et devis",
|
|
276
|
+
cli_cmd_invoices_ls: "Lister les factures et devis",
|
|
277
|
+
cli_cmd_invoices_create: "Cr\xE9er une facture ou un devis",
|
|
278
|
+
cli_cmd_invoices_pdf: "T\xE9l\xE9charger le PDF d'une facture ou d'un devis",
|
|
279
|
+
cli_cmd_invoices_paid: "Marquer une facture comme pay\xE9e",
|
|
280
|
+
cli_cmd_invoices_unpaid: "Remettre une facture en attente de paiement",
|
|
281
|
+
cli_cmd_receipts: "G\xE9rer vos justificatifs",
|
|
282
|
+
cli_cmd_receipts_ls: "Lister vos justificatifs",
|
|
283
|
+
cli_cmd_receipts_add: "Saisir un justificatif manuellement",
|
|
284
|
+
cli_cmd_receipts_scan: "Envoyer un justificatif et le faire lire par bonbox",
|
|
285
|
+
cli_flag_json: "Afficher la r\xE9ponse brute de l'API en JSON",
|
|
286
|
+
cli_flag_lang: "Langue de l'affichage (en, de, fr, it)",
|
|
287
|
+
cli_flag_provider: "Connexion via google ou apple",
|
|
288
|
+
cli_flag_archived: "Inclure les clients archiv\xE9s",
|
|
289
|
+
cli_flag_status: "Filtrer par statut : created ou paid",
|
|
290
|
+
cli_flag_quotes: "Afficher les devis au lieu des factures",
|
|
291
|
+
cli_flag_customer_ref: "Nom ou identifiant du client",
|
|
292
|
+
cli_flag_item: "Poste au format description:quantit\xE9:prix unitaire[:remise%], r\xE9p\xE9table",
|
|
293
|
+
cli_flag_quote: "Cr\xE9er un devis au lieu d'une facture",
|
|
294
|
+
cli_flag_invoice_date: "Date de la facture (AAAA-MM-JJ), aujourd'hui par d\xE9faut",
|
|
295
|
+
cli_flag_payment_days: "D\xE9lai de paiement en jours",
|
|
296
|
+
cli_flag_currency: "Monnaie, par exemple CHF",
|
|
297
|
+
cli_flag_language: "Langue du document : de, en, fr ou it",
|
|
298
|
+
cli_flag_subtitle: "Sous-titre affich\xE9 sur le document",
|
|
299
|
+
cli_flag_reference: "Votre r\xE9f\xE9rence pour ce document",
|
|
300
|
+
cli_flag_pdf: "Enregistrer aussi le PDF dans ce fichier",
|
|
301
|
+
cli_flag_output: "Enregistrer le PDF dans ce fichier",
|
|
302
|
+
cli_flag_paid_date: "Date du paiement (AAAA-MM-JJ), aujourd'hui par d\xE9faut",
|
|
303
|
+
cli_flag_no_receipt: "Ne pas comptabiliser le paiement comme recette",
|
|
304
|
+
cli_flag_month: "Limiter \xE0 un mois (AAAA-MM)",
|
|
305
|
+
cli_flag_from: "Date de d\xE9but (AAAA-MM-JJ)",
|
|
306
|
+
cli_flag_to: "Date de fin (AAAA-MM-JJ)",
|
|
307
|
+
cli_flag_project: "Identifiant du projet",
|
|
308
|
+
cli_flag_seller: "Fournisseur, ou le client pour une recette",
|
|
309
|
+
cli_flag_price: "Montant, par exemple 23.50",
|
|
310
|
+
cli_flag_receipt_date: "Date du justificatif (AAAA-MM-JJ), aujourd'hui par d\xE9faut",
|
|
311
|
+
cli_flag_category: "Cat\xE9gorie",
|
|
312
|
+
cli_flag_tax_category: "Cat\xE9gorie fiscale",
|
|
313
|
+
cli_flag_booking_text: "Libell\xE9 comptable",
|
|
314
|
+
cli_arg_invoice_ref: "Num\xE9ro de facture ou identifiant",
|
|
315
|
+
cli_arg_scan_files: "Fichiers image ou PDF, toutes les pages d'un justificatif",
|
|
316
|
+
cli_error_unauthorized: "Vous n'\xEAtes pas connect\xE9. Ex\xE9cutez : bonbox login",
|
|
317
|
+
cli_error_pro_required: "Cette action n\xE9cessite bonbox Pro. Passez \xE0 Pro sur %1$s",
|
|
318
|
+
cli_error_quota: "Vous avez atteint la limite de votre abonnement. Passez \xE0 Pro sur %1$s",
|
|
319
|
+
cli_error_network: "bonbox est injoignable : %1$s",
|
|
320
|
+
cli_error_unexpected_response: "R\xE9ponse inattendue de bonbox (HTTP %1$s)",
|
|
321
|
+
cli_error_item_format: 'Poste invalide "%1$s". Attendu : description:quantit\xE9:prix unitaire[:remise%]',
|
|
322
|
+
cli_error_item_number: 'Nombre invalide dans le poste "%1$s"',
|
|
323
|
+
cli_error_items_required: "Ajoutez au moins un poste avec --item",
|
|
324
|
+
cli_error_customer_required: "Indiquez un client avec --customer",
|
|
325
|
+
cli_error_price_required: "Indiquez un montant avec --price",
|
|
326
|
+
cli_error_seller_required: "Indiquez un fournisseur avec --seller",
|
|
327
|
+
cli_error_price_invalid: "Montant invalide : %1$s",
|
|
328
|
+
cli_error_date_invalid: "Date invalide : %1$s. Attendu : AAAA-MM-JJ",
|
|
329
|
+
cli_error_month_invalid: "Mois invalide : %1$s. Attendu : AAAA-MM",
|
|
330
|
+
cli_error_customer_not_found: 'Aucun client ne correspond \xE0 "%1$s"',
|
|
331
|
+
cli_error_customer_ambiguous: '"%1$s" correspond \xE0 plusieurs clients :',
|
|
332
|
+
cli_error_files_required: "Indiquez au moins un fichier \xE0 traiter",
|
|
333
|
+
cli_error_file_missing: "Fichier introuvable : %1$s",
|
|
334
|
+
cli_login_opening: "Ouverture du navigateur pour la connexion ...",
|
|
335
|
+
cli_login_manual: "Si le navigateur ne s'ouvre pas, rendez-vous sur :\n%1$s",
|
|
336
|
+
cli_login_waiting: "En attente de la fin de la connexion ...",
|
|
337
|
+
cli_login_success: "Connect\xE9 en tant que %1$s",
|
|
338
|
+
cli_login_failed: "\xC9chec de la connexion : %1$s",
|
|
339
|
+
cli_login_timeout: "D\xE9lai de connexion d\xE9pass\xE9. Veuillez r\xE9essayer.",
|
|
340
|
+
cli_login_no_port: "Aucun port libre pour la connexion (essay\xE9s : %1$s).",
|
|
341
|
+
cli_callback_title: "Connect\xE9 \xE0 bonbox",
|
|
342
|
+
cli_callback_heading: "Vous \xEAtes connect\xE9",
|
|
343
|
+
cli_callback_body: "Vous pouvez fermer cet onglet et revenir au terminal.",
|
|
344
|
+
cli_callback_error_heading: "\xC9chec de la connexion",
|
|
345
|
+
cli_callback_error_body: "Revenez au terminal et r\xE9essayez.",
|
|
346
|
+
cli_logout_done: "D\xE9connect\xE9.",
|
|
347
|
+
cli_logout_none: "Vous n'\xE9tiez pas connect\xE9.",
|
|
348
|
+
cli_label_email: "E-mail",
|
|
349
|
+
cli_label_plan: "Abonnement",
|
|
350
|
+
cli_label_company: "Entreprise",
|
|
351
|
+
cli_label_currency: "Monnaie",
|
|
352
|
+
cli_plan_pro: "Pro",
|
|
353
|
+
cli_plan_free: "Gratuit",
|
|
354
|
+
cli_col_number: "Num\xE9ro",
|
|
355
|
+
cli_col_date: "Date",
|
|
356
|
+
cli_col_status: "Statut",
|
|
357
|
+
cli_col_customer: "Client",
|
|
358
|
+
cli_col_total: "Total",
|
|
359
|
+
cli_col_name: "Nom",
|
|
360
|
+
cli_col_city: "Localit\xE9",
|
|
361
|
+
cli_col_id: "ID",
|
|
362
|
+
cli_col_seller: "Fournisseur",
|
|
363
|
+
cli_col_amount: "Montant",
|
|
364
|
+
cli_col_category: "Cat\xE9gorie",
|
|
365
|
+
cli_col_archived: "Archiv\xE9",
|
|
366
|
+
cli_status_created: "Ouverte",
|
|
367
|
+
cli_status_paid: "Pay\xE9e",
|
|
368
|
+
cli_yes: "oui",
|
|
369
|
+
cli_no: "non",
|
|
370
|
+
cli_empty_customers: "Aucun client pour l'instant.",
|
|
371
|
+
cli_empty_invoices: "Aucune facture pour l'instant.",
|
|
372
|
+
cli_empty_quotes: "Aucun devis pour l'instant.",
|
|
373
|
+
cli_empty_receipts: "Aucun justificatif trouv\xE9.",
|
|
374
|
+
cli_invoice_created: "Facture %1$s cr\xE9\xE9e, %2$s",
|
|
375
|
+
cli_quote_created: "Devis %1$s cr\xE9\xE9, %2$s",
|
|
376
|
+
cli_pdf_saved: "Enregistr\xE9 sous %1$s",
|
|
377
|
+
cli_invoice_paid: "%1$s marqu\xE9e comme pay\xE9e.",
|
|
378
|
+
cli_invoice_unpaid: "%1$s remise en attente de paiement.",
|
|
379
|
+
cli_receipt_added: "Justificatif enregistr\xE9 : %1$s, %2$s",
|
|
380
|
+
cli_scan_uploading: "Envoi de %1$s fichier(s) ...",
|
|
381
|
+
cli_receipt_scanned: "Justificatif enregistr\xE9 : %1$s, %2$s (reconnu automatiquement)"
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
// src/i18n/it.json
|
|
385
|
+
var it_default = {
|
|
386
|
+
cli_app_description: "Gestisci giustificativi, fatture e clienti di bonbox dal terminale.",
|
|
387
|
+
cli_cmd_login: "Accedi al tuo account bonbox",
|
|
388
|
+
cli_cmd_logout: "Esci su questo dispositivo",
|
|
389
|
+
cli_cmd_whoami: "Mostra l'account con cui hai effettuato l'accesso",
|
|
390
|
+
cli_cmd_customers: "Gestisci i tuoi clienti",
|
|
391
|
+
cli_cmd_customers_ls: "Elenca i tuoi clienti",
|
|
392
|
+
cli_cmd_invoices: "Gestisci fatture e preventivi",
|
|
393
|
+
cli_cmd_invoices_ls: "Elenca fatture e preventivi",
|
|
394
|
+
cli_cmd_invoices_create: "Crea una fattura o un preventivo",
|
|
395
|
+
cli_cmd_invoices_pdf: "Scarica il PDF di una fattura o di un preventivo",
|
|
396
|
+
cli_cmd_invoices_paid: "Segna una fattura come pagata",
|
|
397
|
+
cli_cmd_invoices_unpaid: "Riporta una fattura fra quelle aperte",
|
|
398
|
+
cli_cmd_receipts: "Gestisci i tuoi giustificativi",
|
|
399
|
+
cli_cmd_receipts_ls: "Elenca i tuoi giustificativi",
|
|
400
|
+
cli_cmd_receipts_add: "Inserisci un giustificativo manualmente",
|
|
401
|
+
cli_cmd_receipts_scan: "Carica un giustificativo e lascia che bonbox lo legga",
|
|
402
|
+
cli_flag_json: "Stampa la risposta dell'API come JSON grezzo",
|
|
403
|
+
cli_flag_lang: "Lingua dell'output (en, de, fr, it)",
|
|
404
|
+
cli_flag_provider: "Accesso tramite google o apple",
|
|
405
|
+
cli_flag_archived: "Includi i clienti archiviati",
|
|
406
|
+
cli_flag_status: "Filtra per stato: created o paid",
|
|
407
|
+
cli_flag_quotes: "Mostra i preventivi invece delle fatture",
|
|
408
|
+
cli_flag_customer_ref: "Nome o ID del cliente",
|
|
409
|
+
cli_flag_item: "Voce nel formato descrizione:quantit\xE0:prezzo unitario[:sconto%], ripetibile",
|
|
410
|
+
cli_flag_quote: "Crea un preventivo invece di una fattura",
|
|
411
|
+
cli_flag_invoice_date: "Data della fattura (AAAA-MM-GG), per impostazione predefinita oggi",
|
|
412
|
+
cli_flag_payment_days: "Termine di pagamento in giorni",
|
|
413
|
+
cli_flag_currency: "Valuta, ad esempio CHF",
|
|
414
|
+
cli_flag_language: "Lingua del documento: de, en, fr o it",
|
|
415
|
+
cli_flag_subtitle: "Sottotitolo mostrato sul documento",
|
|
416
|
+
cli_flag_reference: "Il tuo riferimento per questo documento",
|
|
417
|
+
cli_flag_pdf: "Salva anche il PDF in questo file",
|
|
418
|
+
cli_flag_output: "Salva il PDF in questo file",
|
|
419
|
+
cli_flag_paid_date: "Data del pagamento (AAAA-MM-GG), per impostazione predefinita oggi",
|
|
420
|
+
cli_flag_no_receipt: "Non registrare il pagamento come entrata",
|
|
421
|
+
cli_flag_month: "Limita a un mese (AAAA-MM)",
|
|
422
|
+
cli_flag_from: "Data di inizio (AAAA-MM-GG)",
|
|
423
|
+
cli_flag_to: "Data di fine (AAAA-MM-GG)",
|
|
424
|
+
cli_flag_project: "ID del progetto",
|
|
425
|
+
cli_flag_seller: "Fornitore, oppure il cliente per le entrate",
|
|
426
|
+
cli_flag_price: "Importo, ad esempio 23.50",
|
|
427
|
+
cli_flag_receipt_date: "Data del giustificativo (AAAA-MM-GG), per impostazione predefinita oggi",
|
|
428
|
+
cli_flag_category: "Categoria",
|
|
429
|
+
cli_flag_tax_category: "Categoria fiscale",
|
|
430
|
+
cli_flag_booking_text: "Testo di registrazione",
|
|
431
|
+
cli_arg_invoice_ref: "Numero della fattura o ID",
|
|
432
|
+
cli_arg_scan_files: "File immagine o PDF, tutte le pagine di un giustificativo",
|
|
433
|
+
cli_error_unauthorized: "Non hai effettuato l'accesso. Esegui: bonbox login",
|
|
434
|
+
cli_error_pro_required: "Serve bonbox Pro. Puoi passare a Pro qui: %1$s",
|
|
435
|
+
cli_error_quota: "Hai raggiunto il limite del tuo abbonamento. Puoi passare a Pro qui: %1$s",
|
|
436
|
+
cli_error_network: "bonbox non \xE8 raggiungibile: %1$s",
|
|
437
|
+
cli_error_unexpected_response: "Risposta inattesa da bonbox (HTTP %1$s)",
|
|
438
|
+
cli_error_item_format: 'Voce non valida "%1$s". Formato atteso: descrizione:quantit\xE0:prezzo unitario[:sconto%]',
|
|
439
|
+
cli_error_item_number: 'Numero non valido nella voce "%1$s"',
|
|
440
|
+
cli_error_items_required: "Aggiungi almeno una voce con --item",
|
|
441
|
+
cli_error_customer_required: "Indica un cliente con --customer",
|
|
442
|
+
cli_error_price_required: "Indica un importo con --price",
|
|
443
|
+
cli_error_seller_required: "Indica un fornitore con --seller",
|
|
444
|
+
cli_error_price_invalid: "Importo non valido: %1$s",
|
|
445
|
+
cli_error_date_invalid: "Data non valida: %1$s. Formato atteso: AAAA-MM-GG",
|
|
446
|
+
cli_error_month_invalid: "Mese non valido: %1$s. Formato atteso: AAAA-MM",
|
|
447
|
+
cli_error_customer_not_found: 'Nessun cliente corrisponde a "%1$s"',
|
|
448
|
+
cli_error_customer_ambiguous: '"%1$s" corrisponde a pi\xF9 clienti:',
|
|
449
|
+
cli_error_files_required: "Indica almeno un file da elaborare",
|
|
450
|
+
cli_error_file_missing: "File non trovato: %1$s",
|
|
451
|
+
cli_login_opening: "Apertura del browser per l'accesso ...",
|
|
452
|
+
cli_login_manual: "Se il browser non si apre, visita:\n%1$s",
|
|
453
|
+
cli_login_waiting: "In attesa del completamento dell'accesso ...",
|
|
454
|
+
cli_login_success: "Accesso effettuato come %1$s",
|
|
455
|
+
cli_login_failed: "Accesso non riuscito: %1$s",
|
|
456
|
+
cli_login_timeout: "Tempo scaduto per l'accesso. Riprova.",
|
|
457
|
+
cli_login_no_port: "Nessuna porta libera per l'accesso (provate: %1$s).",
|
|
458
|
+
cli_callback_title: "Accesso a bonbox effettuato",
|
|
459
|
+
cli_callback_heading: "Hai effettuato l'accesso",
|
|
460
|
+
cli_callback_body: "Puoi chiudere questa scheda e tornare al terminale.",
|
|
461
|
+
cli_callback_error_heading: "Accesso non riuscito",
|
|
462
|
+
cli_callback_error_body: "Torna al terminale e riprova.",
|
|
463
|
+
cli_logout_done: "Disconnesso.",
|
|
464
|
+
cli_logout_none: "Non avevi effettuato l'accesso.",
|
|
465
|
+
cli_label_email: "E-mail",
|
|
466
|
+
cli_label_plan: "Abbonamento",
|
|
467
|
+
cli_label_company: "Azienda",
|
|
468
|
+
cli_label_currency: "Valuta",
|
|
469
|
+
cli_plan_pro: "Pro",
|
|
470
|
+
cli_plan_free: "Gratuito",
|
|
471
|
+
cli_col_number: "Numero",
|
|
472
|
+
cli_col_date: "Data",
|
|
473
|
+
cli_col_status: "Stato",
|
|
474
|
+
cli_col_customer: "Cliente",
|
|
475
|
+
cli_col_total: "Totale",
|
|
476
|
+
cli_col_name: "Nome",
|
|
477
|
+
cli_col_city: "Localit\xE0",
|
|
478
|
+
cli_col_id: "ID",
|
|
479
|
+
cli_col_seller: "Fornitore",
|
|
480
|
+
cli_col_amount: "Importo",
|
|
481
|
+
cli_col_category: "Categoria",
|
|
482
|
+
cli_col_archived: "Archiviato",
|
|
483
|
+
cli_status_created: "Aperta",
|
|
484
|
+
cli_status_paid: "Pagata",
|
|
485
|
+
cli_yes: "s\xEC",
|
|
486
|
+
cli_no: "no",
|
|
487
|
+
cli_empty_customers: "Ancora nessun cliente.",
|
|
488
|
+
cli_empty_invoices: "Ancora nessuna fattura.",
|
|
489
|
+
cli_empty_quotes: "Ancora nessun preventivo.",
|
|
490
|
+
cli_empty_receipts: "Nessun giustificativo trovato.",
|
|
491
|
+
cli_invoice_created: "Fattura %1$s creata, %2$s",
|
|
492
|
+
cli_quote_created: "Preventivo %1$s creato, %2$s",
|
|
493
|
+
cli_pdf_saved: "Salvato in %1$s",
|
|
494
|
+
cli_invoice_paid: "%1$s segnata come pagata.",
|
|
495
|
+
cli_invoice_unpaid: "%1$s riportata fra quelle aperte.",
|
|
496
|
+
cli_receipt_added: "Giustificativo salvato: %1$s, %2$s",
|
|
497
|
+
cli_scan_uploading: "Caricamento di %1$s file ...",
|
|
498
|
+
cli_receipt_scanned: "Giustificativo salvato: %1$s, %2$s (riconosciuto automaticamente)"
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/i18n/index.ts
|
|
502
|
+
var LOCALES = ["en", "de", "fr", "it"];
|
|
503
|
+
var BUNDLES = { en: en_default, de: de_default, fr: fr_default, it: it_default };
|
|
504
|
+
function isLocale(value) {
|
|
505
|
+
return LOCALES.includes(value);
|
|
506
|
+
}
|
|
507
|
+
function resolveLocale(explicit, env = process.env) {
|
|
508
|
+
const candidates = [explicit, env.BONBOX_LANG, env.LC_ALL, env.LANG];
|
|
509
|
+
for (const candidate of candidates) {
|
|
510
|
+
const tag = candidate?.trim().toLowerCase().split(/[._-]/)[0];
|
|
511
|
+
if (tag && isLocale(tag)) return tag;
|
|
512
|
+
}
|
|
513
|
+
return "en";
|
|
514
|
+
}
|
|
515
|
+
function translate(locale, key, ...args) {
|
|
516
|
+
const template = BUNDLES[locale]?.[key] ?? BUNDLES.en[key];
|
|
517
|
+
if (template === void 0) return key;
|
|
518
|
+
return template.replace(/%(\d+)\$s/g, (match, index) => {
|
|
519
|
+
const value = args[Number(index) - 1];
|
|
520
|
+
return value === void 0 ? match : String(value);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
var current = "en";
|
|
524
|
+
function setLocale(locale) {
|
|
525
|
+
current = locale;
|
|
526
|
+
}
|
|
527
|
+
function t(key, ...args) {
|
|
528
|
+
return translate(current, key, ...args);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// src/errors.ts
|
|
532
|
+
var EXIT_ERROR = 1;
|
|
533
|
+
var EXIT_USAGE = 2;
|
|
534
|
+
var CliError = class extends Error {
|
|
535
|
+
exitCode;
|
|
536
|
+
constructor(message, exitCode = EXIT_ERROR) {
|
|
537
|
+
super(message);
|
|
538
|
+
this.name = "CliError";
|
|
539
|
+
this.exitCode = exitCode;
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
var UsageError = class extends CliError {
|
|
543
|
+
constructor(message) {
|
|
544
|
+
super(message, EXIT_USAGE);
|
|
545
|
+
this.name = "UsageError";
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
function envelopeMessage(body) {
|
|
549
|
+
const message = body?.error?.message;
|
|
550
|
+
return typeof message === "string" && message.length > 0 ? message : void 0;
|
|
551
|
+
}
|
|
552
|
+
function mapApiError(status, body) {
|
|
553
|
+
switch (status) {
|
|
554
|
+
case 401:
|
|
555
|
+
return new CliError(t("cli_error_unauthorized"));
|
|
556
|
+
case 402:
|
|
557
|
+
return new CliError(t("cli_error_pro_required", APP_URL));
|
|
558
|
+
case 429:
|
|
559
|
+
return new CliError(t("cli_error_quota", APP_URL));
|
|
560
|
+
default:
|
|
561
|
+
return new CliError(
|
|
562
|
+
envelopeMessage(body) ?? t("cli_error_unexpected_response", status)
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/auth.ts
|
|
568
|
+
function sessionPath(env = process.env) {
|
|
569
|
+
const base = env.XDG_CONFIG_HOME?.trim() || join(homedir(), ".config");
|
|
570
|
+
return join(base, "bonbox", "session.json");
|
|
571
|
+
}
|
|
572
|
+
var FileStorage = class {
|
|
573
|
+
constructor(file) {
|
|
574
|
+
this.file = file;
|
|
575
|
+
}
|
|
576
|
+
file;
|
|
577
|
+
read() {
|
|
578
|
+
if (!existsSync(this.file)) return {};
|
|
579
|
+
try {
|
|
580
|
+
const parsed = JSON.parse(readFileSync(this.file, "utf8"));
|
|
581
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
582
|
+
} catch {
|
|
583
|
+
return {};
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
write(entries) {
|
|
587
|
+
mkdirSync(dirname(this.file), { recursive: true, mode: 448 });
|
|
588
|
+
writeFileSync(this.file, `${JSON.stringify(entries, null, 2)}
|
|
589
|
+
`, { mode: 384 });
|
|
590
|
+
chmodSync(this.file, 384);
|
|
591
|
+
}
|
|
592
|
+
getItem(key) {
|
|
593
|
+
return this.read()[key] ?? null;
|
|
594
|
+
}
|
|
595
|
+
setItem(key, value) {
|
|
596
|
+
this.write({ ...this.read(), [key]: value });
|
|
597
|
+
}
|
|
598
|
+
removeItem(key) {
|
|
599
|
+
const entries = this.read();
|
|
600
|
+
delete entries[key];
|
|
601
|
+
this.write(entries);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
var cached = null;
|
|
605
|
+
function getSupabase() {
|
|
606
|
+
if (!cached) {
|
|
607
|
+
cached = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
|
|
608
|
+
auth: {
|
|
609
|
+
storage: new FileStorage(sessionPath()),
|
|
610
|
+
persistSession: true,
|
|
611
|
+
autoRefreshToken: true,
|
|
612
|
+
detectSessionInUrl: false,
|
|
613
|
+
flowType: "pkce"
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
return cached;
|
|
618
|
+
}
|
|
619
|
+
function clearSessionFile() {
|
|
620
|
+
const file = sessionPath();
|
|
621
|
+
if (!existsSync(file)) return false;
|
|
622
|
+
rmSync(file);
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
async function getAccessToken() {
|
|
626
|
+
const { data } = await getSupabase().auth.getSession();
|
|
627
|
+
const token = data.session?.access_token;
|
|
628
|
+
if (!token) throw new CliError(t("cli_error_unauthorized"));
|
|
629
|
+
return token;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/api.ts
|
|
633
|
+
function buildUrl(baseUrl, path, query) {
|
|
634
|
+
const url = new URL(baseUrl + path);
|
|
635
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
636
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
637
|
+
url.searchParams.set(key, String(value));
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return url.toString();
|
|
641
|
+
}
|
|
642
|
+
function filenameFromDisposition(header) {
|
|
643
|
+
if (!header) return null;
|
|
644
|
+
const match = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i.exec(header);
|
|
645
|
+
return match?.[1] ? decodeURIComponent(match[1]) : null;
|
|
646
|
+
}
|
|
647
|
+
var ApiClient = class {
|
|
648
|
+
constructor(options) {
|
|
649
|
+
this.options = options;
|
|
650
|
+
this.baseUrl = options.baseUrl ?? apiBase();
|
|
651
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
652
|
+
}
|
|
653
|
+
options;
|
|
654
|
+
baseUrl;
|
|
655
|
+
fetchImpl;
|
|
656
|
+
async send(path, init, query) {
|
|
657
|
+
const token = await this.options.getToken();
|
|
658
|
+
const headers = new Headers(init.headers);
|
|
659
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
660
|
+
headers.set("Accept", headers.get("Accept") ?? "application/json");
|
|
661
|
+
let response;
|
|
662
|
+
try {
|
|
663
|
+
response = await this.fetchImpl(buildUrl(this.baseUrl, path, query), {
|
|
664
|
+
...init,
|
|
665
|
+
headers
|
|
666
|
+
});
|
|
667
|
+
} catch (error) {
|
|
668
|
+
throw new CliError(t("cli_error_network", error.message));
|
|
669
|
+
}
|
|
670
|
+
if (!response.ok) {
|
|
671
|
+
const body = await response.json().catch(() => null);
|
|
672
|
+
throw mapApiError(response.status, body);
|
|
673
|
+
}
|
|
674
|
+
return response;
|
|
675
|
+
}
|
|
676
|
+
async parseJson(response) {
|
|
677
|
+
try {
|
|
678
|
+
return await response.json();
|
|
679
|
+
} catch {
|
|
680
|
+
throw new CliError(t("cli_error_unexpected_response", String(response.status)));
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
async get(path, query) {
|
|
684
|
+
const response = await this.send(path, { method: "GET" }, query);
|
|
685
|
+
return await this.parseJson(response);
|
|
686
|
+
}
|
|
687
|
+
async post(path, body) {
|
|
688
|
+
const response = await this.send(path, {
|
|
689
|
+
method: "POST",
|
|
690
|
+
headers: { "Content-Type": "application/json" },
|
|
691
|
+
body: JSON.stringify(body ?? {})
|
|
692
|
+
});
|
|
693
|
+
return await this.parseJson(response);
|
|
694
|
+
}
|
|
695
|
+
async postMultipart(path, form) {
|
|
696
|
+
const response = await this.send(path, { method: "POST", body: form });
|
|
697
|
+
return await this.parseJson(response);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Fetches every page of a list endpoint and returns the concatenated items.
|
|
701
|
+
* Stops once a page comes back short of `limit`, and also honors `total`
|
|
702
|
+
* when the API reports it — but works fine without it.
|
|
703
|
+
*/
|
|
704
|
+
async getAllPages(path, query) {
|
|
705
|
+
const limit = 200;
|
|
706
|
+
let offset = 0;
|
|
707
|
+
const items = [];
|
|
708
|
+
for (; ; ) {
|
|
709
|
+
const page2 = await this.get(path, { ...query, limit, offset });
|
|
710
|
+
items.push(...page2.items);
|
|
711
|
+
offset += limit;
|
|
712
|
+
if (page2.items.length < limit) break;
|
|
713
|
+
if (typeof page2.total === "number" && items.length >= page2.total) break;
|
|
714
|
+
}
|
|
715
|
+
return items;
|
|
716
|
+
}
|
|
717
|
+
async getBinary(path) {
|
|
718
|
+
const response = await this.send(path, { method: "GET", headers: { Accept: "*/*" } });
|
|
719
|
+
const buffer = await response.arrayBuffer();
|
|
720
|
+
return {
|
|
721
|
+
data: new Uint8Array(buffer),
|
|
722
|
+
filename: filenameFromDisposition(response.headers.get("content-disposition"))
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
// src/lib/context.ts
|
|
728
|
+
function commonArgs() {
|
|
729
|
+
return {
|
|
730
|
+
json: { type: "boolean", description: t("cli_flag_json"), default: false },
|
|
731
|
+
lang: { type: "string", description: t("cli_flag_lang") }
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
function langFromArgv(argv2) {
|
|
735
|
+
for (let index = 0; index < argv2.length; index += 1) {
|
|
736
|
+
const entry = argv2[index] ?? "";
|
|
737
|
+
if (entry === "--lang") return argv2[index + 1];
|
|
738
|
+
if (entry.startsWith("--lang=")) return entry.slice("--lang=".length);
|
|
739
|
+
}
|
|
740
|
+
return void 0;
|
|
741
|
+
}
|
|
742
|
+
function client() {
|
|
743
|
+
return new ApiClient({ getToken: getAccessToken });
|
|
744
|
+
}
|
|
745
|
+
function scanClient() {
|
|
746
|
+
return new ApiClient({ getToken: getAccessToken, baseUrl: scanBase() });
|
|
747
|
+
}
|
|
748
|
+
function out(line) {
|
|
749
|
+
process.stdout.write(`${line}
|
|
750
|
+
`);
|
|
751
|
+
}
|
|
752
|
+
function printJson(value) {
|
|
753
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
754
|
+
`);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/commands/account.ts
|
|
758
|
+
function logoutCommand() {
|
|
759
|
+
return defineCommand({
|
|
760
|
+
meta: { name: "logout", description: t("cli_cmd_logout") },
|
|
761
|
+
args: commonArgs(),
|
|
762
|
+
async run({ args }) {
|
|
763
|
+
await getSupabase().auth.signOut({ scope: "local" }).catch(() => void 0);
|
|
764
|
+
const removed = clearSessionFile();
|
|
765
|
+
if (args.json) printJson({ signedOut: removed });
|
|
766
|
+
else out(removed ? t("cli_logout_done") : t("cli_logout_none"));
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
function whoamiCommand() {
|
|
771
|
+
return defineCommand({
|
|
772
|
+
meta: { name: "whoami", description: t("cli_cmd_whoami") },
|
|
773
|
+
args: commonArgs(),
|
|
774
|
+
async run({ args }) {
|
|
775
|
+
const me = await client().get("/me");
|
|
776
|
+
if (args.json) {
|
|
777
|
+
printJson(me);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
const rows = [
|
|
781
|
+
[t("cli_label_email"), me.email ?? me.id],
|
|
782
|
+
[t("cli_label_plan"), me.isPro ? t("cli_plan_pro") : t("cli_plan_free")]
|
|
783
|
+
];
|
|
784
|
+
if (me.companyName) rows.push([t("cli_label_company"), me.companyName]);
|
|
785
|
+
if (me.defaultCurrency) rows.push([t("cli_label_currency"), me.defaultCurrency]);
|
|
786
|
+
const width = Math.max(...rows.map(([label]) => label.length));
|
|
787
|
+
for (const [label, value] of rows) out(`${label.padEnd(width)} ${value}`);
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// src/commands/customers.ts
|
|
793
|
+
import { defineCommand as defineCommand2 } from "citty";
|
|
794
|
+
|
|
795
|
+
// src/format.ts
|
|
796
|
+
function formatDate(value) {
|
|
797
|
+
if (!value) return "";
|
|
798
|
+
const match = /^(\d{4}-\d{2}-\d{2})/.exec(value);
|
|
799
|
+
return match?.[1] ?? value;
|
|
800
|
+
}
|
|
801
|
+
function formatMoney(amount, currency) {
|
|
802
|
+
if (amount === null || amount === void 0 || Number.isNaN(amount)) return "";
|
|
803
|
+
const negative = amount < 0;
|
|
804
|
+
const [whole = "0", fraction = "00"] = Math.abs(amount).toFixed(2).split(".");
|
|
805
|
+
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, "'");
|
|
806
|
+
const number = `${negative ? "-" : ""}${grouped}.${fraction}`;
|
|
807
|
+
return currency ? `${currency} ${number}` : number;
|
|
808
|
+
}
|
|
809
|
+
function pad(value, width, align) {
|
|
810
|
+
const padding = " ".repeat(Math.max(0, width - value.length));
|
|
811
|
+
return align === "right" ? padding + value : value + padding;
|
|
812
|
+
}
|
|
813
|
+
function table(columns, rows) {
|
|
814
|
+
const widths = columns.map(
|
|
815
|
+
(column, index) => Math.max(column.header.length, ...rows.map((row) => (row[index] ?? "").length))
|
|
816
|
+
);
|
|
817
|
+
const render = (cells) => cells.map((cell, index) => {
|
|
818
|
+
const align = columns[index]?.align ?? "left";
|
|
819
|
+
const isLast = index === columns.length - 1;
|
|
820
|
+
return isLast && align === "left" ? cell : pad(cell, widths[index] ?? 0, align);
|
|
821
|
+
}).join(" ").replace(/\s+$/, "");
|
|
822
|
+
return [render(columns.map((column) => column.header)), ...rows.map(render)].join("\n");
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// src/commands/customers.ts
|
|
826
|
+
function listCommand() {
|
|
827
|
+
return defineCommand2({
|
|
828
|
+
meta: { name: "ls", description: t("cli_cmd_customers_ls") },
|
|
829
|
+
args: {
|
|
830
|
+
...commonArgs(),
|
|
831
|
+
archived: { type: "boolean", description: t("cli_flag_archived"), default: false }
|
|
832
|
+
},
|
|
833
|
+
async run({ args }) {
|
|
834
|
+
const items = await client().getAllPages("/customers", {
|
|
835
|
+
includeArchived: args.archived ? "true" : void 0
|
|
836
|
+
});
|
|
837
|
+
if (args.json) {
|
|
838
|
+
printJson({ items });
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (items.length === 0) {
|
|
842
|
+
out(t("cli_empty_customers"));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
const columns = [
|
|
846
|
+
{ header: t("cli_col_name") },
|
|
847
|
+
{ header: t("cli_col_city") },
|
|
848
|
+
...args.archived ? [{ header: t("cli_col_archived") }] : [],
|
|
849
|
+
{ header: t("cli_col_id") }
|
|
850
|
+
];
|
|
851
|
+
const rows = items.map((customer) => [
|
|
852
|
+
customer.name,
|
|
853
|
+
[customer.postalCode, customer.city].filter(Boolean).join(" "),
|
|
854
|
+
...args.archived ? [customer.archived ? t("cli_yes") : t("cli_no")] : [],
|
|
855
|
+
customer.id
|
|
856
|
+
]);
|
|
857
|
+
out(table(columns, rows));
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
function customersCommand() {
|
|
862
|
+
return defineCommand2({
|
|
863
|
+
meta: { name: "customers", description: t("cli_cmd_customers") },
|
|
864
|
+
subCommands: { ls: listCommand() }
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// src/commands/invoices.ts
|
|
869
|
+
import { defineCommand as defineCommand3 } from "citty";
|
|
870
|
+
import { writeFile } from "fs/promises";
|
|
871
|
+
|
|
872
|
+
// src/lib/args.ts
|
|
873
|
+
function toArray(value) {
|
|
874
|
+
if (value === void 0 || value === null || value === false) return [];
|
|
875
|
+
if (Array.isArray(value)) return value.map(String).filter((entry) => entry.length > 0);
|
|
876
|
+
const single = String(value);
|
|
877
|
+
return single.length > 0 ? [single] : [];
|
|
878
|
+
}
|
|
879
|
+
function optional(value) {
|
|
880
|
+
if (value === void 0 || value === null) return void 0;
|
|
881
|
+
const text = String(value).trim();
|
|
882
|
+
return text.length > 0 ? text : void 0;
|
|
883
|
+
}
|
|
884
|
+
function requireDate(value) {
|
|
885
|
+
if (value === void 0) return void 0;
|
|
886
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
887
|
+
throw new UsageError(t("cli_error_date_invalid", value));
|
|
888
|
+
}
|
|
889
|
+
return value;
|
|
890
|
+
}
|
|
891
|
+
function requireNumber(value, messageKey) {
|
|
892
|
+
if (value === void 0) return void 0;
|
|
893
|
+
const parsed = Number(value.replace(",", "."));
|
|
894
|
+
if (!Number.isFinite(parsed)) throw new UsageError(t(messageKey, value));
|
|
895
|
+
return parsed;
|
|
896
|
+
}
|
|
897
|
+
function monthRange(month) {
|
|
898
|
+
const match = /^(\d{4})-(\d{2})$/.exec(month);
|
|
899
|
+
const year = Number(match?.[1]);
|
|
900
|
+
const monthIndex = Number(match?.[2]);
|
|
901
|
+
if (!match || monthIndex < 1 || monthIndex > 12) {
|
|
902
|
+
throw new UsageError(t("cli_error_month_invalid", month));
|
|
903
|
+
}
|
|
904
|
+
const lastDay = new Date(Date.UTC(year, monthIndex, 0)).getUTCDate();
|
|
905
|
+
const padded = String(monthIndex).padStart(2, "0");
|
|
906
|
+
return { from: `${year}-${padded}-01`, to: `${year}-${padded}-${String(lastDay).padStart(2, "0")}` };
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// src/lib/customers.ts
|
|
910
|
+
function matchCustomer(reference, customers) {
|
|
911
|
+
const needle = reference.trim().toLowerCase();
|
|
912
|
+
if (!needle) return { kind: "none" };
|
|
913
|
+
const byId = customers.find((customer) => customer.id.toLowerCase() === needle);
|
|
914
|
+
if (byId) return { kind: "match", customer: byId };
|
|
915
|
+
const exact = customers.filter((customer) => customer.name.trim().toLowerCase() === needle);
|
|
916
|
+
if (exact.length === 1) return { kind: "match", customer: exact[0] };
|
|
917
|
+
if (exact.length > 1) return { kind: "ambiguous", candidates: exact };
|
|
918
|
+
const prefix = customers.filter(
|
|
919
|
+
(customer) => customer.name.trim().toLowerCase().startsWith(needle)
|
|
920
|
+
);
|
|
921
|
+
if (prefix.length === 1) return { kind: "match", customer: prefix[0] };
|
|
922
|
+
if (prefix.length > 1) return { kind: "ambiguous", candidates: prefix };
|
|
923
|
+
return { kind: "none" };
|
|
924
|
+
}
|
|
925
|
+
function resolveCustomer(reference, customers) {
|
|
926
|
+
const result = matchCustomer(reference, customers);
|
|
927
|
+
if (result.kind === "match") return result.customer;
|
|
928
|
+
if (result.kind === "ambiguous") {
|
|
929
|
+
const list = result.candidates.map((customer) => ` ${customer.name} ${customer.id}`).join("\n");
|
|
930
|
+
throw new UsageError(`${t("cli_error_customer_ambiguous", reference)}
|
|
931
|
+
${list}`);
|
|
932
|
+
}
|
|
933
|
+
throw new UsageError(t("cli_error_customer_not_found", reference));
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// src/lib/items.ts
|
|
937
|
+
var NUMBER = /^-?\d+(?:[.,]\d+)?$/;
|
|
938
|
+
function toNumber(raw) {
|
|
939
|
+
const trimmed = raw.trim();
|
|
940
|
+
if (!NUMBER.test(trimmed)) return null;
|
|
941
|
+
return Number(trimmed.replace(",", "."));
|
|
942
|
+
}
|
|
943
|
+
function parseItem(raw) {
|
|
944
|
+
const parts = raw.split(":");
|
|
945
|
+
if (parts.length < 3) throw new UsageError(t("cli_error_item_format", raw));
|
|
946
|
+
let discountPercent;
|
|
947
|
+
const last = parts[parts.length - 1] ?? "";
|
|
948
|
+
if (parts.length >= 4 && last.trim().endsWith("%")) {
|
|
949
|
+
const value = toNumber(last.replace("%", ""));
|
|
950
|
+
if (value === null) throw new UsageError(t("cli_error_item_number", raw));
|
|
951
|
+
discountPercent = value;
|
|
952
|
+
parts.pop();
|
|
953
|
+
}
|
|
954
|
+
const unitPrice = toNumber(parts.pop() ?? "");
|
|
955
|
+
const quantity = toNumber(parts.pop() ?? "");
|
|
956
|
+
if (unitPrice === null || quantity === null) {
|
|
957
|
+
throw new UsageError(t("cli_error_item_number", raw));
|
|
958
|
+
}
|
|
959
|
+
const description = parts.join(":").trim();
|
|
960
|
+
if (!description) throw new UsageError(t("cli_error_item_format", raw));
|
|
961
|
+
return discountPercent === void 0 ? { description, quantity, unitPrice } : { description, quantity, unitPrice, discountPercent };
|
|
962
|
+
}
|
|
963
|
+
function parseItems(raw) {
|
|
964
|
+
if (raw.length === 0) throw new UsageError(t("cli_error_items_required"));
|
|
965
|
+
return raw.map(parseItem);
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// src/commands/invoices.ts
|
|
969
|
+
async function customerNames(api) {
|
|
970
|
+
const customers = await api.getAllPages("/customers", {
|
|
971
|
+
includeArchived: "true"
|
|
972
|
+
});
|
|
973
|
+
return new Map(customers.map((customer) => [customer.id, customer.name]));
|
|
974
|
+
}
|
|
975
|
+
function invoiceTable(invoices, names) {
|
|
976
|
+
const columns = [
|
|
977
|
+
{ header: t("cli_col_number") },
|
|
978
|
+
{ header: t("cli_col_date") },
|
|
979
|
+
{ header: t("cli_col_status") },
|
|
980
|
+
{ header: t("cli_col_total"), align: "right" },
|
|
981
|
+
{ header: t("cli_col_customer") }
|
|
982
|
+
];
|
|
983
|
+
const rows = invoices.map((invoice) => [
|
|
984
|
+
invoice.invoiceNumber,
|
|
985
|
+
formatDate(invoice.invoiceDate),
|
|
986
|
+
invoice.status === "paid" ? t("cli_status_paid") : t("cli_status_created"),
|
|
987
|
+
formatMoney(invoice.total, invoice.currency),
|
|
988
|
+
invoice.customerId && names.get(invoice.customerId) || ""
|
|
989
|
+
]);
|
|
990
|
+
return table(columns, rows);
|
|
991
|
+
}
|
|
992
|
+
function listCommand2() {
|
|
993
|
+
return defineCommand3({
|
|
994
|
+
meta: { name: "ls", description: t("cli_cmd_invoices_ls") },
|
|
995
|
+
args: {
|
|
996
|
+
...commonArgs(),
|
|
997
|
+
status: { type: "string", description: t("cli_flag_status") },
|
|
998
|
+
quotes: { type: "boolean", description: t("cli_flag_quotes"), default: false }
|
|
999
|
+
},
|
|
1000
|
+
async run({ args }) {
|
|
1001
|
+
const status = optional(args.status);
|
|
1002
|
+
if (status && status !== "created" && status !== "paid") {
|
|
1003
|
+
throw new UsageError(t("cli_flag_status"));
|
|
1004
|
+
}
|
|
1005
|
+
const api = client();
|
|
1006
|
+
const items = await api.getAllPages("/invoices", {
|
|
1007
|
+
status,
|
|
1008
|
+
quotes: args.quotes ? "only" : "exclude"
|
|
1009
|
+
});
|
|
1010
|
+
if (args.json) {
|
|
1011
|
+
printJson({ items });
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (items.length === 0) {
|
|
1015
|
+
out(args.quotes ? t("cli_empty_quotes") : t("cli_empty_invoices"));
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
out(invoiceTable(items, await customerNames(api)));
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
async function savePdf(api, reference, target) {
|
|
1023
|
+
const pdf = await api.getBinary(`/invoices/${encodeURIComponent(reference)}/pdf`);
|
|
1024
|
+
const filename = target ?? pdf.filename ?? `Invoice-${reference}.pdf`;
|
|
1025
|
+
await writeFile(filename, pdf.data);
|
|
1026
|
+
return filename;
|
|
1027
|
+
}
|
|
1028
|
+
function createCommand() {
|
|
1029
|
+
return defineCommand3({
|
|
1030
|
+
meta: { name: "create", description: t("cli_cmd_invoices_create") },
|
|
1031
|
+
args: {
|
|
1032
|
+
...commonArgs(),
|
|
1033
|
+
customer: { type: "string", description: t("cli_flag_customer_ref") },
|
|
1034
|
+
item: { type: "string", description: t("cli_flag_item") },
|
|
1035
|
+
quote: { type: "boolean", description: t("cli_flag_quote"), default: false },
|
|
1036
|
+
date: { type: "string", description: t("cli_flag_invoice_date") },
|
|
1037
|
+
"payment-days": { type: "string", description: t("cli_flag_payment_days") },
|
|
1038
|
+
currency: { type: "string", description: t("cli_flag_currency") },
|
|
1039
|
+
language: { type: "string", description: t("cli_flag_language") },
|
|
1040
|
+
subtitle: { type: "string", description: t("cli_flag_subtitle") },
|
|
1041
|
+
reference: { type: "string", description: t("cli_flag_reference") },
|
|
1042
|
+
pdf: { type: "string", description: t("cli_flag_pdf") }
|
|
1043
|
+
},
|
|
1044
|
+
async run({ args }) {
|
|
1045
|
+
const customerRef = optional(args.customer);
|
|
1046
|
+
if (!customerRef) throw new UsageError(t("cli_error_customer_required"));
|
|
1047
|
+
const items = parseItems(toArray(args.item));
|
|
1048
|
+
const api = client();
|
|
1049
|
+
const customers = await api.getAllPages("/customers");
|
|
1050
|
+
const customer = resolveCustomer(customerRef, customers);
|
|
1051
|
+
const invoice = await api.post("/invoices", {
|
|
1052
|
+
customerId: customer.id,
|
|
1053
|
+
items,
|
|
1054
|
+
quote: Boolean(args.quote),
|
|
1055
|
+
date: requireDate(optional(args.date)),
|
|
1056
|
+
paymentDays: requireNumber(optional(args["payment-days"]), "cli_error_price_invalid"),
|
|
1057
|
+
currency: optional(args.currency),
|
|
1058
|
+
language: optional(args.language),
|
|
1059
|
+
subtitle: optional(args.subtitle),
|
|
1060
|
+
reference: optional(args.reference)
|
|
1061
|
+
});
|
|
1062
|
+
const pdfTarget = optional(args.pdf);
|
|
1063
|
+
const savedTo = pdfTarget ? await savePdf(api, invoice.id, pdfTarget) : null;
|
|
1064
|
+
if (args.json) {
|
|
1065
|
+
printJson(invoice);
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
const total = formatMoney(invoice.total, invoice.currency);
|
|
1069
|
+
out(
|
|
1070
|
+
invoice.isQuote ? t("cli_quote_created", invoice.invoiceNumber, total) : t("cli_invoice_created", invoice.invoiceNumber, total)
|
|
1071
|
+
);
|
|
1072
|
+
if (savedTo) out(t("cli_pdf_saved", savedTo));
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
function pdfCommand() {
|
|
1077
|
+
return defineCommand3({
|
|
1078
|
+
meta: { name: "pdf", description: t("cli_cmd_invoices_pdf") },
|
|
1079
|
+
args: {
|
|
1080
|
+
invoice: { type: "positional", description: t("cli_arg_invoice_ref"), required: true },
|
|
1081
|
+
...commonArgs(),
|
|
1082
|
+
output: { type: "string", alias: "o", description: t("cli_flag_output") }
|
|
1083
|
+
},
|
|
1084
|
+
async run({ args }) {
|
|
1085
|
+
const filename = await savePdf(client(), String(args.invoice), optional(args.output));
|
|
1086
|
+
if (args.json) printJson({ file: filename });
|
|
1087
|
+
else out(t("cli_pdf_saved", filename));
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
function paidCommand() {
|
|
1092
|
+
return defineCommand3({
|
|
1093
|
+
meta: { name: "paid", description: t("cli_cmd_invoices_paid") },
|
|
1094
|
+
args: {
|
|
1095
|
+
invoice: { type: "positional", description: t("cli_arg_invoice_ref"), required: true },
|
|
1096
|
+
...commonArgs(),
|
|
1097
|
+
date: { type: "string", description: t("cli_flag_paid_date") },
|
|
1098
|
+
receipt: { type: "boolean", description: t("cli_flag_no_receipt"), default: true }
|
|
1099
|
+
},
|
|
1100
|
+
async run({ args }) {
|
|
1101
|
+
const invoice = await client().post(
|
|
1102
|
+
`/invoices/${encodeURIComponent(String(args.invoice))}/paid`,
|
|
1103
|
+
{
|
|
1104
|
+
paidDate: requireDate(optional(args.date)),
|
|
1105
|
+
createReceipt: args.receipt !== false
|
|
1106
|
+
}
|
|
1107
|
+
);
|
|
1108
|
+
if (args.json) printJson(invoice);
|
|
1109
|
+
else out(t("cli_invoice_paid", invoice.invoiceNumber));
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
function unpaidCommand() {
|
|
1114
|
+
return defineCommand3({
|
|
1115
|
+
meta: { name: "unpaid", description: t("cli_cmd_invoices_unpaid") },
|
|
1116
|
+
args: {
|
|
1117
|
+
invoice: { type: "positional", description: t("cli_arg_invoice_ref"), required: true },
|
|
1118
|
+
...commonArgs()
|
|
1119
|
+
},
|
|
1120
|
+
async run({ args }) {
|
|
1121
|
+
const invoice = await client().post(
|
|
1122
|
+
`/invoices/${encodeURIComponent(String(args.invoice))}/unpaid`
|
|
1123
|
+
);
|
|
1124
|
+
if (args.json) printJson(invoice);
|
|
1125
|
+
else out(t("cli_invoice_unpaid", invoice.invoiceNumber));
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
function invoicesCommand() {
|
|
1130
|
+
return defineCommand3({
|
|
1131
|
+
meta: { name: "invoices", description: t("cli_cmd_invoices") },
|
|
1132
|
+
subCommands: {
|
|
1133
|
+
ls: listCommand2(),
|
|
1134
|
+
create: createCommand(),
|
|
1135
|
+
pdf: pdfCommand(),
|
|
1136
|
+
paid: paidCommand(),
|
|
1137
|
+
unpaid: unpaidCommand()
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// src/commands/login.ts
|
|
1143
|
+
import { defineCommand as defineCommand4 } from "citty";
|
|
1144
|
+
import { createServer } from "http";
|
|
1145
|
+
import open from "open";
|
|
1146
|
+
var TIMEOUT_MS = 5 * 60 * 1e3;
|
|
1147
|
+
function page(heading, body) {
|
|
1148
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8">
|
|
1149
|
+
<title>${t("cli_callback_title")}</title></head>
|
|
1150
|
+
<body style="margin:0;display:flex;min-height:100vh;align-items:center;justify-content:center;
|
|
1151
|
+
font:16px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:#111;background:#faf9f7">
|
|
1152
|
+
<main style="text-align:center;max-width:28rem;padding:2rem">
|
|
1153
|
+
<h1 style="font-size:1.25rem;font-weight:600;margin:0 0 .5rem">${heading}</h1>
|
|
1154
|
+
<p style="margin:0;color:#555">${body}</p>
|
|
1155
|
+
</main></body></html>`;
|
|
1156
|
+
}
|
|
1157
|
+
function listen(port) {
|
|
1158
|
+
return new Promise((resolve) => {
|
|
1159
|
+
const server = createServer();
|
|
1160
|
+
server.once("error", () => resolve(null));
|
|
1161
|
+
server.listen(port, "127.0.0.1", () => resolve(server));
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
async function openListener() {
|
|
1165
|
+
for (const port of CALLBACK_PORTS) {
|
|
1166
|
+
const server = await listen(port);
|
|
1167
|
+
if (server) return { server, port: server.address().port };
|
|
1168
|
+
}
|
|
1169
|
+
throw new CliError(t("cli_login_no_port", CALLBACK_PORTS.join(", ")));
|
|
1170
|
+
}
|
|
1171
|
+
function awaitCode(server) {
|
|
1172
|
+
return new Promise((resolve, reject) => {
|
|
1173
|
+
const timer = setTimeout(() => {
|
|
1174
|
+
reject(new CliError(t("cli_login_timeout")));
|
|
1175
|
+
}, TIMEOUT_MS);
|
|
1176
|
+
server.on("request", (request, response) => {
|
|
1177
|
+
const url = new URL(request.url ?? "/", "http://localhost");
|
|
1178
|
+
if (!url.pathname.startsWith("/callback")) {
|
|
1179
|
+
response.writeHead(404).end();
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
const code = url.searchParams.get("code");
|
|
1183
|
+
const error = url.searchParams.get("error_description") ?? url.searchParams.get("error");
|
|
1184
|
+
const html = code ? page(t("cli_callback_heading"), t("cli_callback_body")) : page(t("cli_callback_error_heading"), t("cli_callback_error_body"));
|
|
1185
|
+
response.writeHead(code ? 200 : 400, { "Content-Type": "text/html; charset=utf-8" });
|
|
1186
|
+
response.end(html);
|
|
1187
|
+
clearTimeout(timer);
|
|
1188
|
+
if (code) resolve(code);
|
|
1189
|
+
else reject(new CliError(t("cli_login_failed", error ?? "")));
|
|
1190
|
+
});
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
function loginCommand() {
|
|
1194
|
+
return defineCommand4({
|
|
1195
|
+
meta: { name: "login", description: t("cli_cmd_login") },
|
|
1196
|
+
args: {
|
|
1197
|
+
...commonArgs(),
|
|
1198
|
+
provider: { type: "string", description: t("cli_flag_provider"), default: "google" }
|
|
1199
|
+
},
|
|
1200
|
+
async run({ args }) {
|
|
1201
|
+
const provider = String(args.provider);
|
|
1202
|
+
if (provider !== "google" && provider !== "apple") {
|
|
1203
|
+
throw new UsageError(t("cli_flag_provider"));
|
|
1204
|
+
}
|
|
1205
|
+
const { server, port } = await openListener();
|
|
1206
|
+
try {
|
|
1207
|
+
const supabase = getSupabase();
|
|
1208
|
+
const { data, error } = await supabase.auth.signInWithOAuth({
|
|
1209
|
+
provider,
|
|
1210
|
+
options: {
|
|
1211
|
+
redirectTo: `http://localhost:${port}/callback`,
|
|
1212
|
+
skipBrowserRedirect: true
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
if (error || !data.url) throw new CliError(t("cli_login_failed", error?.message ?? ""));
|
|
1216
|
+
if (!args.json) {
|
|
1217
|
+
out(t("cli_login_opening"));
|
|
1218
|
+
out(t("cli_login_manual", data.url));
|
|
1219
|
+
out(t("cli_login_waiting"));
|
|
1220
|
+
}
|
|
1221
|
+
await open(data.url).catch(() => void 0);
|
|
1222
|
+
const code = await awaitCode(server);
|
|
1223
|
+
const exchanged = await supabase.auth.exchangeCodeForSession(code);
|
|
1224
|
+
if (exchanged.error) throw new CliError(t("cli_login_failed", exchanged.error.message));
|
|
1225
|
+
const email = exchanged.data.user?.email ?? exchanged.data.user?.id ?? "";
|
|
1226
|
+
if (args.json) printJson({ user: { id: exchanged.data.user?.id, email } });
|
|
1227
|
+
else out(t("cli_login_success", email));
|
|
1228
|
+
} finally {
|
|
1229
|
+
server.close();
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// src/commands/receipts.ts
|
|
1236
|
+
import { defineCommand as defineCommand5 } from "citty";
|
|
1237
|
+
import { existsSync as existsSync2 } from "fs";
|
|
1238
|
+
import { readFile } from "fs/promises";
|
|
1239
|
+
import { basename, extname } from "path";
|
|
1240
|
+
var MIME_TYPES = {
|
|
1241
|
+
".jpg": "image/jpeg",
|
|
1242
|
+
".jpeg": "image/jpeg",
|
|
1243
|
+
".png": "image/png",
|
|
1244
|
+
".webp": "image/webp",
|
|
1245
|
+
".pdf": "application/pdf"
|
|
1246
|
+
};
|
|
1247
|
+
function receiptTable(receipts) {
|
|
1248
|
+
const columns = [
|
|
1249
|
+
{ header: t("cli_col_date") },
|
|
1250
|
+
{ header: t("cli_col_seller") },
|
|
1251
|
+
{ header: t("cli_col_amount"), align: "right" },
|
|
1252
|
+
{ header: t("cli_col_category") },
|
|
1253
|
+
{ header: t("cli_col_id") }
|
|
1254
|
+
];
|
|
1255
|
+
const rows = receipts.map((receipt) => [
|
|
1256
|
+
formatDate(receipt.date),
|
|
1257
|
+
receipt.seller ?? "",
|
|
1258
|
+
formatMoney(receipt.price, receipt.currency),
|
|
1259
|
+
receipt.taxCategory ?? receipt.category ?? "",
|
|
1260
|
+
receipt.id
|
|
1261
|
+
]);
|
|
1262
|
+
return table(columns, rows);
|
|
1263
|
+
}
|
|
1264
|
+
function summarize(receipt) {
|
|
1265
|
+
return `${receipt.seller ?? ""}, ${formatMoney(receipt.price, receipt.currency)}`.replace(
|
|
1266
|
+
/^, /,
|
|
1267
|
+
""
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
function listCommand3() {
|
|
1271
|
+
return defineCommand5({
|
|
1272
|
+
meta: { name: "ls", description: t("cli_cmd_receipts_ls") },
|
|
1273
|
+
args: {
|
|
1274
|
+
...commonArgs(),
|
|
1275
|
+
month: { type: "string", description: t("cli_flag_month") },
|
|
1276
|
+
from: { type: "string", description: t("cli_flag_from") },
|
|
1277
|
+
to: { type: "string", description: t("cli_flag_to") },
|
|
1278
|
+
project: { type: "string", description: t("cli_flag_project") }
|
|
1279
|
+
},
|
|
1280
|
+
async run({ args }) {
|
|
1281
|
+
const month = optional(args.month);
|
|
1282
|
+
const range = month ? monthRange(month) : void 0;
|
|
1283
|
+
const items = await client().getAllPages("/receipts", {
|
|
1284
|
+
from: range?.from ?? requireDate(optional(args.from)),
|
|
1285
|
+
to: range?.to ?? requireDate(optional(args.to)),
|
|
1286
|
+
projectId: optional(args.project)
|
|
1287
|
+
});
|
|
1288
|
+
if (args.json) {
|
|
1289
|
+
printJson({ items });
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
if (items.length === 0) {
|
|
1293
|
+
out(t("cli_empty_receipts"));
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
out(receiptTable(items));
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
function addCommand() {
|
|
1301
|
+
return defineCommand5({
|
|
1302
|
+
meta: { name: "add", description: t("cli_cmd_receipts_add") },
|
|
1303
|
+
args: {
|
|
1304
|
+
...commonArgs(),
|
|
1305
|
+
seller: { type: "string", description: t("cli_flag_seller") },
|
|
1306
|
+
price: { type: "string", description: t("cli_flag_price") },
|
|
1307
|
+
date: { type: "string", description: t("cli_flag_receipt_date") },
|
|
1308
|
+
currency: { type: "string", description: t("cli_flag_currency") },
|
|
1309
|
+
category: { type: "string", description: t("cli_flag_category") },
|
|
1310
|
+
"tax-category": { type: "string", description: t("cli_flag_tax_category") },
|
|
1311
|
+
"booking-text": { type: "string", description: t("cli_flag_booking_text") },
|
|
1312
|
+
project: { type: "string", description: t("cli_flag_project") },
|
|
1313
|
+
customer: { type: "string", description: t("cli_flag_customer_ref") }
|
|
1314
|
+
},
|
|
1315
|
+
async run({ args }) {
|
|
1316
|
+
const seller = optional(args.seller);
|
|
1317
|
+
const rawPrice = optional(args.price);
|
|
1318
|
+
if (!seller) throw new UsageError(t("cli_error_seller_required"));
|
|
1319
|
+
if (!rawPrice) throw new UsageError(t("cli_error_price_required"));
|
|
1320
|
+
const price = requireNumber(rawPrice, "cli_error_price_invalid");
|
|
1321
|
+
const api = client();
|
|
1322
|
+
const customerRef = optional(args.customer);
|
|
1323
|
+
let customerId;
|
|
1324
|
+
if (customerRef) {
|
|
1325
|
+
const customers = await api.getAllPages("/customers");
|
|
1326
|
+
customerId = resolveCustomer(customerRef, customers).id;
|
|
1327
|
+
}
|
|
1328
|
+
const receipt = await api.post("/receipts", {
|
|
1329
|
+
seller,
|
|
1330
|
+
price,
|
|
1331
|
+
date: requireDate(optional(args.date)),
|
|
1332
|
+
currency: optional(args.currency),
|
|
1333
|
+
category: optional(args.category),
|
|
1334
|
+
taxCategory: optional(args["tax-category"]),
|
|
1335
|
+
bookingText: optional(args["booking-text"]),
|
|
1336
|
+
projectId: optional(args.project),
|
|
1337
|
+
customerId
|
|
1338
|
+
});
|
|
1339
|
+
if (args.json) printJson(receipt);
|
|
1340
|
+
else out(t("cli_receipt_added", formatDate(receipt.date), summarize(receipt)));
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
function scanCommand() {
|
|
1345
|
+
return defineCommand5({
|
|
1346
|
+
meta: { name: "scan", description: t("cli_cmd_receipts_scan") },
|
|
1347
|
+
args: {
|
|
1348
|
+
files: { type: "positional", description: t("cli_arg_scan_files"), required: false },
|
|
1349
|
+
...commonArgs(),
|
|
1350
|
+
project: { type: "string", description: t("cli_flag_project") }
|
|
1351
|
+
},
|
|
1352
|
+
async run({ args }) {
|
|
1353
|
+
const files = toArray(args._ ?? args.files);
|
|
1354
|
+
if (files.length === 0) throw new UsageError(t("cli_error_files_required"));
|
|
1355
|
+
const form = new FormData();
|
|
1356
|
+
for (const path of files) {
|
|
1357
|
+
if (!existsSync2(path)) throw new UsageError(t("cli_error_file_missing", path));
|
|
1358
|
+
const content = await readFile(path);
|
|
1359
|
+
const type = MIME_TYPES[extname(path).toLowerCase()] ?? "application/octet-stream";
|
|
1360
|
+
form.append("file", new Blob([new Uint8Array(content)], { type }), basename(path));
|
|
1361
|
+
}
|
|
1362
|
+
const projectId = optional(args.project);
|
|
1363
|
+
if (projectId) form.append("projectId", projectId);
|
|
1364
|
+
if (!args.json) out(t("cli_scan_uploading", files.length));
|
|
1365
|
+
const receipt = await scanClient().postMultipart("/receipts/scan", form);
|
|
1366
|
+
if (args.json) printJson(receipt);
|
|
1367
|
+
else out(t("cli_receipt_scanned", formatDate(receipt.date), summarize(receipt)));
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
function receiptsCommand() {
|
|
1372
|
+
return defineCommand5({
|
|
1373
|
+
meta: { name: "receipts", description: t("cli_cmd_receipts") },
|
|
1374
|
+
subCommands: {
|
|
1375
|
+
ls: listCommand3(),
|
|
1376
|
+
add: addCommand(),
|
|
1377
|
+
scan: scanCommand()
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// src/cli.ts
|
|
1383
|
+
var VERSION = "0.1.0";
|
|
1384
|
+
var argv = process.argv.slice(2);
|
|
1385
|
+
setLocale(resolveLocale(langFromArgv(argv)));
|
|
1386
|
+
function withoutLangFlag(rawArgs) {
|
|
1387
|
+
const kept = [];
|
|
1388
|
+
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
1389
|
+
const entry = rawArgs[index] ?? "";
|
|
1390
|
+
if (entry === "--lang") {
|
|
1391
|
+
index += 1;
|
|
1392
|
+
continue;
|
|
1393
|
+
}
|
|
1394
|
+
if (entry.startsWith("--lang=")) continue;
|
|
1395
|
+
kept.push(entry);
|
|
1396
|
+
}
|
|
1397
|
+
return kept;
|
|
1398
|
+
}
|
|
1399
|
+
var cliArgs = withoutLangFlag(argv);
|
|
1400
|
+
var main = defineCommand6({
|
|
1401
|
+
meta: { name: "bonbox", version: VERSION, description: t("cli_app_description") },
|
|
1402
|
+
subCommands: {
|
|
1403
|
+
login: loginCommand(),
|
|
1404
|
+
logout: logoutCommand(),
|
|
1405
|
+
whoami: whoamiCommand(),
|
|
1406
|
+
customers: customersCommand(),
|
|
1407
|
+
invoices: invoicesCommand(),
|
|
1408
|
+
receipts: receiptsCommand()
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
async function resolveSubCommand(command, rawArgs, parent) {
|
|
1412
|
+
const subCommands = command.subCommands;
|
|
1413
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
1414
|
+
const index = rawArgs.findIndex((arg) => !arg.startsWith("-"));
|
|
1415
|
+
const name = rawArgs[index];
|
|
1416
|
+
const sub = name ? subCommands[name] : void 0;
|
|
1417
|
+
if (sub) return resolveSubCommand(sub, rawArgs.slice(index + 1), command);
|
|
1418
|
+
}
|
|
1419
|
+
return [command, parent];
|
|
1420
|
+
}
|
|
1421
|
+
function isUsageError(error) {
|
|
1422
|
+
const code = error?.code;
|
|
1423
|
+
return code === "E_UNKNOWN_COMMAND" || code === "E_NO_COMMAND";
|
|
1424
|
+
}
|
|
1425
|
+
async function run() {
|
|
1426
|
+
if (argv.includes("--help") || argv.includes("-h") || cliArgs.length === 0) {
|
|
1427
|
+
await showUsage(...await resolveSubCommand(main, cliArgs));
|
|
1428
|
+
return 0;
|
|
1429
|
+
}
|
|
1430
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1431
|
+
process.stdout.write(`${VERSION}
|
|
1432
|
+
`);
|
|
1433
|
+
return 0;
|
|
1434
|
+
}
|
|
1435
|
+
try {
|
|
1436
|
+
await runCommand(main, { rawArgs: cliArgs });
|
|
1437
|
+
return 0;
|
|
1438
|
+
} catch (error) {
|
|
1439
|
+
if (isUsageError(error)) {
|
|
1440
|
+
process.stderr.write(`${error.message}
|
|
1441
|
+
`);
|
|
1442
|
+
await showUsage(...await resolveSubCommand(main, cliArgs));
|
|
1443
|
+
return EXIT_USAGE;
|
|
1444
|
+
}
|
|
1445
|
+
if (error instanceof CliError) {
|
|
1446
|
+
process.stderr.write(`${error.message}
|
|
1447
|
+
`);
|
|
1448
|
+
return error.exitCode;
|
|
1449
|
+
}
|
|
1450
|
+
process.stderr.write(`${error?.message ?? String(error)}
|
|
1451
|
+
`);
|
|
1452
|
+
return EXIT_ERROR;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
process.exit(await run());
|
|
1456
|
+
//# sourceMappingURL=cli.js.map
|