@hisaabo/cli 0.1.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/.turbo/turbo-typecheck.log +1 -1
- package/README.md +332 -0
- package/dist/bin/audit-trail-5LOCJ7XZ.js +78 -0
- package/dist/bin/categories-64WWZTND.js +47 -0
- package/dist/bin/check-slug-FLHHUDYS.js +65 -0
- package/dist/bin/chunk-4MEL44QX.js +848 -0
- package/dist/bin/chunk-FIMJZAS4.js +84 -0
- package/dist/bin/chunk-NO4FIFMS.js +176 -0
- package/dist/bin/chunk-T63VQXNM.js +156 -0
- package/dist/bin/client-5NZ23GML.js +11 -0
- package/dist/bin/collection-efficiency-U56XNVEE.js +165 -0
- package/dist/bin/config-335MN4I7.js +18 -0
- package/dist/bin/create-RPDEORDD.js +83 -0
- package/dist/bin/default-account-AE6EXZZR.js +58 -0
- package/dist/bin/expenses-5N2QSG54.js +89 -0
- package/dist/bin/export-QICOQK34.js +59 -0
- package/dist/bin/factory-KOCW2AQM.js +483 -0
- package/dist/bin/get-A43QCI2S.js +66 -0
- package/dist/bin/get-GWH6S5SJ.js +71 -0
- package/dist/bin/hisaabo.js +2302 -1510
- package/dist/bin/invitations-P3EEN5WI.js +66 -0
- package/dist/bin/invite-T3CKX53E.js +53 -0
- package/dist/bin/invoice-breakdown-FN5BEFJD.js +97 -0
- package/dist/bin/items-2OOCQKVF.js +62 -0
- package/dist/bin/items-toggle-SKZWCGJH.js +46 -0
- package/dist/bin/list-A2RKI3ZG.js +79 -0
- package/dist/bin/list-NRMBMKMI.js +90 -0
- package/dist/bin/list-T74SN6IR.js +46 -0
- package/dist/bin/members-W2GW3ODT.js +55 -0
- package/dist/bin/monthly-comparison-T34ZFOHL.js +176 -0
- package/dist/bin/order-cancel-TI27JYYD.js +55 -0
- package/dist/bin/order-confirm-VMRAMNTD.js +53 -0
- package/dist/bin/order-get-C2RBUR4O.js +88 -0
- package/dist/bin/order-update-RE3HATNF.js +60 -0
- package/dist/bin/output-NUOL7KJW.js +35 -0
- package/dist/bin/payment-modes-WOOT22I7.js +126 -0
- package/dist/bin/profit-loss-T4RESJ32.js +135 -0
- package/dist/bin/receivables-aging-6XMENEWS.js +161 -0
- package/dist/bin/remove-6QZI4JCY.js +52 -0
- package/dist/bin/revoke-AVEMPAC7.js +40 -0
- package/dist/bin/revoke-YUCFZFNR.js +52 -0
- package/dist/bin/revoke-all-LFW5WBHO.js +33 -0
- package/dist/bin/revoke-invitation-DTGQRJR4.js +40 -0
- package/dist/bin/sales-trend-ZYBRUDUU.js +71 -0
- package/dist/bin/sequence-FPOJTI2P.js +66 -0
- package/dist/bin/store-IOB4Y67C.js +82 -0
- package/dist/bin/summary-5KYBA4ZO.js +113 -0
- package/dist/bin/top-customers-WSQ2UEJL.js +81 -0
- package/dist/bin/top-items-RWQPDGLN.js +84 -0
- package/dist/bin/top-outstanding-QAMO2E7Y.js +64 -0
- package/dist/bin/unpaid-invoices-WB3TK5B4.js +65 -0
- package/dist/bin/untracked-H733MYJL.js +67 -0
- package/dist/bin/update-H6LPO2Z4.js +61 -0
- package/dist/bin/update-JU2X3XU5.js +54 -0
- package/dist/bin/update-TLBUIC5J.js +57 -0
- package/dist/bin/update-role-QST7BVFX.js +45 -0
- package/dist/bin/update-settings-Q2EGRLKZ.js +56 -0
- package/package.json +7 -6
- package/src/auth.ts +12 -3
- package/src/bin/hisaabo.ts +49 -935
- package/src/bin/registrars/api-key.ts +44 -0
- package/src/bin/registrars/auth.ts +222 -0
- package/src/bin/registrars/automated-invoice.ts +167 -0
- package/src/bin/registrars/bank.ts +124 -0
- package/src/bin/registrars/business.ts +120 -0
- package/src/bin/registrars/dashboard.ts +225 -0
- package/src/bin/registrars/document.ts +184 -0
- package/src/bin/registrars/expense.ts +87 -0
- package/src/bin/registrars/gst.ts +41 -0
- package/src/bin/registrars/import.ts +49 -0
- package/src/bin/registrars/invoice.ts +117 -0
- package/src/bin/registrars/item.ts +112 -0
- package/src/bin/registrars/party.ts +81 -0
- package/src/bin/registrars/payment.ts +128 -0
- package/src/bin/registrars/report.ts +142 -0
- package/src/bin/registrars/session.ts +32 -0
- package/src/bin/registrars/shipment.ts +74 -0
- package/src/bin/registrars/store.ts +128 -0
- package/src/bin/registrars/target.ts +46 -0
- package/src/bin/registrars/tenant.ts +73 -0
- package/src/client.ts +589 -15
- package/src/commands/api-key/create.ts +72 -0
- package/src/commands/api-key/list.ts +71 -0
- package/src/commands/api-key/revoke.ts +46 -0
- package/src/commands/automated-invoice/create.ts +85 -0
- package/src/commands/automated-invoice/delete.ts +42 -0
- package/src/commands/automated-invoice/get.ts +113 -0
- package/src/commands/automated-invoice/history.ts +65 -0
- package/src/commands/automated-invoice/index.ts +11 -0
- package/src/commands/automated-invoice/list.ts +91 -0
- package/src/commands/automated-invoice/pause.ts +29 -0
- package/src/commands/automated-invoice/resume.ts +29 -0
- package/src/commands/automated-invoice/run-now.ts +29 -0
- package/src/commands/automated-invoice/suggestions.ts +68 -0
- package/src/commands/automated-invoice/update.ts +54 -0
- package/src/commands/automated-invoice/usage.ts +68 -0
- package/src/commands/bank/gateway-config.ts +61 -0
- package/src/commands/bank/update-gateway.ts +84 -0
- package/src/commands/business/audit-trail.ts +79 -0
- package/src/commands/business/export.ts +52 -0
- package/src/commands/business/get.ts +55 -0
- package/src/commands/business/sequence.ts +65 -0
- package/src/commands/business/update.ts +64 -0
- package/src/commands/dashboard/collection-efficiency.ts +164 -0
- package/src/commands/dashboard/expenses.ts +76 -0
- package/src/commands/dashboard/invoice-breakdown.ts +89 -0
- package/src/commands/dashboard/monthly-comparison.ts +193 -0
- package/src/commands/dashboard/payment-modes.ts +121 -0
- package/src/commands/dashboard/profit-loss.ts +146 -0
- package/src/commands/dashboard/receivables-aging.ts +169 -0
- package/src/commands/dashboard/sales-trend.ts +68 -0
- package/src/commands/dashboard/summary.ts +105 -0
- package/src/commands/dashboard/top-customers.ts +70 -0
- package/src/commands/dashboard/top-items.ts +74 -0
- package/src/commands/dashboard/top-outstanding.ts +61 -0
- package/src/commands/document/factory.ts +590 -0
- package/src/commands/expense/categories.ts +40 -0
- package/src/commands/expense/update.ts +58 -0
- package/src/commands/import/index.ts +68 -0
- package/src/commands/item/categories.ts +40 -0
- package/src/commands/item/low-stock-count.ts +32 -0
- package/src/commands/item/merge.ts +53 -0
- package/src/commands/item/price-history.ts +59 -0
- package/src/commands/item/rename-unit.ts +39 -0
- package/src/commands/item/sales-stats.ts +44 -0
- package/src/commands/item/stock-history.ts +70 -0
- package/src/commands/item/switch-base-unit.ts +42 -0
- package/src/commands/item/update.ts +59 -0
- package/src/commands/item/variants-create.ts +58 -0
- package/src/commands/item/variants-delete.ts +47 -0
- package/src/commands/item/variants-list.ts +63 -0
- package/src/commands/item/variants-update.ts +61 -0
- package/src/commands/party/ledger-report.ts +81 -0
- package/src/commands/party/merge.ts +50 -0
- package/src/commands/party/stats.ts +40 -0
- package/src/commands/party/top-items.ts +57 -0
- package/src/commands/party/update.ts +65 -0
- package/src/commands/payment/default-account.ts +56 -0
- package/src/commands/payment/get.ts +59 -0
- package/src/commands/payment/unpaid-invoices.ts +69 -0
- package/src/commands/payment/untracked.ts +70 -0
- package/src/commands/payment/update.ts +54 -0
- package/src/commands/report/index.ts +348 -1
- package/src/commands/session/list.ts +91 -0
- package/src/commands/session/revoke-all.ts +20 -0
- package/src/commands/session/revoke.ts +32 -0
- package/src/commands/store/check-slug.ts +48 -0
- package/src/commands/store/items-toggle.ts +41 -0
- package/src/commands/store/items.ts +61 -0
- package/src/commands/store/order-cancel.ts +48 -0
- package/src/commands/store/order-confirm.ts +45 -0
- package/src/commands/store/order-get.ts +66 -0
- package/src/commands/store/order-update.ts +52 -0
- package/src/commands/store/update-settings.ts +52 -0
- package/src/commands/tenant/invitations.ts +62 -0
- package/src/commands/tenant/invite.ts +57 -0
- package/src/commands/tenant/list.ts +46 -0
- package/src/commands/tenant/members.ts +55 -0
- package/src/commands/tenant/remove.ts +47 -0
- package/src/commands/tenant/revoke-invitation.ts +32 -0
- package/src/commands/tenant/update-role.ts +41 -0
- package/src/config.ts +51 -2
- package/src/error-handler.ts +53 -0
- package/src/output.ts +1 -0
- package/src/spinner.ts +39 -0
- package/tsup.config.ts +6 -1
- package/src/components/ErrorDisplay.tsx +0 -16
- package/src/components/Header.tsx +0 -26
- package/src/components/MoneyCell.tsx +0 -16
- package/src/components/Spinner.tsx +0 -12
- package/src/components/StatusBadge.tsx +0 -39
- package/src/components/Table.tsx +0 -63
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type PaymentUpdateInput } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
4
|
+
import { formatINR } from "../../format.js";
|
|
5
|
+
|
|
6
|
+
interface UpdateOpts {
|
|
7
|
+
json?: boolean;
|
|
8
|
+
amount?: string;
|
|
9
|
+
mode?: string;
|
|
10
|
+
date?: string;
|
|
11
|
+
reference?: string;
|
|
12
|
+
notes?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function paymentUpdateCommand(id: string, opts: UpdateOpts): Promise<void> {
|
|
16
|
+
const cfg = requireAuth();
|
|
17
|
+
const client = new HisaaboClient(cfg);
|
|
18
|
+
|
|
19
|
+
// Build update payload — only send fields explicitly provided
|
|
20
|
+
const input: PaymentUpdateInput = { id };
|
|
21
|
+
|
|
22
|
+
if (opts.amount !== undefined) input.amount = opts.amount;
|
|
23
|
+
if (opts.mode !== undefined) input.mode = opts.mode as PaymentUpdateInput["mode"];
|
|
24
|
+
if (opts.date !== undefined) input.paymentDate = opts.date;
|
|
25
|
+
if (opts.reference !== undefined) input.referenceNumber = opts.reference || null;
|
|
26
|
+
if (opts.notes !== undefined) input.notes = opts.notes || null;
|
|
27
|
+
|
|
28
|
+
const hasUpdates = Object.keys(input).length > 1;
|
|
29
|
+
if (!hasUpdates) {
|
|
30
|
+
fatalError("No fields to update. Provide at least one option: --amount, --mode, --date, --reference, --notes", EXIT.USAGE);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const payment = await client.payment.update(input);
|
|
35
|
+
|
|
36
|
+
if (opts.json) {
|
|
37
|
+
outputJSON(payment);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
success(`Updated: ${payment.paymentNumber} — ${formatINR(payment.amount)}`);
|
|
42
|
+
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (e instanceof HisaaboApiError) {
|
|
45
|
+
const err = e.hisaaboError;
|
|
46
|
+
if (err.code === "not_found") fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
|
|
47
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
48
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
49
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
50
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
51
|
+
}
|
|
52
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -3,7 +3,7 @@ import { requireAuth } from "../../config.js";
|
|
|
3
3
|
import {
|
|
4
4
|
fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, type ColumnDef,
|
|
5
5
|
} from "../../output.js";
|
|
6
|
-
import { formatAmount, formatDate, todayISO, fyStart, monthStart, monthEnd } from "../../format.js";
|
|
6
|
+
import { formatAmount, formatDate, formatStatus, todayISO, fyStart, monthStart, monthEnd } from "../../format.js";
|
|
7
7
|
|
|
8
8
|
interface ReportOpts {
|
|
9
9
|
json?: boolean;
|
|
@@ -216,3 +216,350 @@ export async function reportStockSummaryCommand(opts: { json?: boolean; category
|
|
|
216
216
|
fatalError(String(e instanceof Error ? e.message : e));
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
+
|
|
220
|
+
// ── Sales Register ─────────────────────────────────────────────────────────
|
|
221
|
+
|
|
222
|
+
interface RegisterRow {
|
|
223
|
+
date?: string;
|
|
224
|
+
invoiceDate?: string;
|
|
225
|
+
invoiceNumber?: string;
|
|
226
|
+
number?: string;
|
|
227
|
+
partyName?: string;
|
|
228
|
+
party?: string;
|
|
229
|
+
subtotal?: string;
|
|
230
|
+
taxAmount?: string;
|
|
231
|
+
tax?: string;
|
|
232
|
+
total?: string;
|
|
233
|
+
totalAmount?: string;
|
|
234
|
+
status?: string;
|
|
235
|
+
[key: string]: unknown;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export async function reportSalesRegisterCommand(
|
|
239
|
+
opts: ReportOpts & { partyId?: string },
|
|
240
|
+
): Promise<void> {
|
|
241
|
+
const cfg = requireAuth();
|
|
242
|
+
const client = new HisaaboClient(cfg);
|
|
243
|
+
const { from, to } = resolveRange(opts);
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
const result = await client.reports.salesRegister({ fromDate: from, toDate: to, partyId: opts.partyId });
|
|
247
|
+
|
|
248
|
+
if (opts.json) {
|
|
249
|
+
outputJSON(result);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
console.log(`\n Sales Register ${from} → ${to}\n`);
|
|
254
|
+
console.log(` ${"═".repeat(80)}\n`);
|
|
255
|
+
|
|
256
|
+
const rows: RegisterRow[] = Array.isArray(result) ? result
|
|
257
|
+
: Array.isArray(result.rows) ? result.rows
|
|
258
|
+
: Array.isArray(result.invoices) ? result.invoices
|
|
259
|
+
: [];
|
|
260
|
+
|
|
261
|
+
const cols: ColumnDef<RegisterRow>[] = [
|
|
262
|
+
{ key: "date", header: "Date", width: 13, format: (v, r) => formatDate(String(r.date ?? r.invoiceDate ?? v ?? "")) },
|
|
263
|
+
{ key: "invoiceNumber", header: "Invoice #", width: 14, format: (v, r) => String(r.invoiceNumber ?? r.number ?? v ?? "-") },
|
|
264
|
+
{ key: "partyName", header: "Party", width: 22, format: (v, r) => String(r.partyName ?? r.party ?? v ?? "-") },
|
|
265
|
+
{ key: "subtotal", header: "Subtotal (₹)", align: "right", width: 14, format: (v, r) => formatAmount(String(r.subtotal ?? v ?? "0")) },
|
|
266
|
+
{ key: "taxAmount", header: "Tax (₹)", align: "right", width: 12, format: (v, r) => formatAmount(String(r.taxAmount ?? r.tax ?? v ?? "0")) },
|
|
267
|
+
{ key: "total", header: "Total (₹)", align: "right", width: 14, format: (v, r) => formatAmount(String(r.total ?? r.totalAmount ?? v ?? "0")) },
|
|
268
|
+
{ key: "status", header: "Status", width: 10, format: (v, r) => formatStatus(String(r.status ?? v ?? "")) },
|
|
269
|
+
];
|
|
270
|
+
|
|
271
|
+
if (opts.format === "tsv") outputTSV(rows, cols);
|
|
272
|
+
else if (opts.format === "csv") outputCSV(rows, cols);
|
|
273
|
+
else outputTable(rows, cols);
|
|
274
|
+
|
|
275
|
+
if (rows.length > 0 && opts.format !== "tsv" && opts.format !== "csv") {
|
|
276
|
+
const total = rows.reduce((sum, r) => sum + parseFloat(String(r.total ?? r.totalAmount ?? "0")), 0);
|
|
277
|
+
console.log(`\n Total: ${formatAmount(String(total)).padStart(14)}\n`);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
} catch (e) {
|
|
281
|
+
if (e instanceof HisaaboApiError) {
|
|
282
|
+
const err = e.hisaaboError;
|
|
283
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
284
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
285
|
+
}
|
|
286
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ── Purchase Register ──────────────────────────────────────────────────────
|
|
291
|
+
|
|
292
|
+
export async function reportPurchaseRegisterCommand(
|
|
293
|
+
opts: ReportOpts & { partyId?: string },
|
|
294
|
+
): Promise<void> {
|
|
295
|
+
const cfg = requireAuth();
|
|
296
|
+
const client = new HisaaboClient(cfg);
|
|
297
|
+
const { from, to } = resolveRange(opts);
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
const result = await client.reports.purchaseRegister({ fromDate: from, toDate: to, partyId: opts.partyId });
|
|
301
|
+
|
|
302
|
+
if (opts.json) {
|
|
303
|
+
outputJSON(result);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
console.log(`\n Purchase Register ${from} → ${to}\n`);
|
|
308
|
+
console.log(` ${"═".repeat(80)}\n`);
|
|
309
|
+
|
|
310
|
+
const rows: RegisterRow[] = Array.isArray(result) ? result
|
|
311
|
+
: Array.isArray(result.rows) ? result.rows
|
|
312
|
+
: Array.isArray(result.invoices) ? result.invoices
|
|
313
|
+
: [];
|
|
314
|
+
|
|
315
|
+
const cols: ColumnDef<RegisterRow>[] = [
|
|
316
|
+
{ key: "date", header: "Date", width: 13, format: (v, r) => formatDate(String(r.date ?? r.invoiceDate ?? v ?? "")) },
|
|
317
|
+
{ key: "invoiceNumber", header: "Invoice #", width: 14, format: (v, r) => String(r.invoiceNumber ?? r.number ?? v ?? "-") },
|
|
318
|
+
{ key: "partyName", header: "Party", width: 22, format: (v, r) => String(r.partyName ?? r.party ?? v ?? "-") },
|
|
319
|
+
{ key: "subtotal", header: "Subtotal (₹)", align: "right", width: 14, format: (v, r) => formatAmount(String(r.subtotal ?? v ?? "0")) },
|
|
320
|
+
{ key: "taxAmount", header: "Tax (₹)", align: "right", width: 12, format: (v, r) => formatAmount(String(r.taxAmount ?? r.tax ?? v ?? "0")) },
|
|
321
|
+
{ key: "total", header: "Total (₹)", align: "right", width: 14, format: (v, r) => formatAmount(String(r.total ?? r.totalAmount ?? v ?? "0")) },
|
|
322
|
+
{ key: "status", header: "Status", width: 10, format: (v, r) => formatStatus(String(r.status ?? v ?? "")) },
|
|
323
|
+
];
|
|
324
|
+
|
|
325
|
+
if (opts.format === "tsv") outputTSV(rows, cols);
|
|
326
|
+
else if (opts.format === "csv") outputCSV(rows, cols);
|
|
327
|
+
else outputTable(rows, cols);
|
|
328
|
+
|
|
329
|
+
if (rows.length > 0 && opts.format !== "tsv" && opts.format !== "csv") {
|
|
330
|
+
const total = rows.reduce((sum, r) => sum + parseFloat(String(r.total ?? r.totalAmount ?? "0")), 0);
|
|
331
|
+
console.log(`\n Total: ${formatAmount(String(total)).padStart(14)}\n`);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
} catch (e) {
|
|
335
|
+
if (e instanceof HisaaboApiError) {
|
|
336
|
+
const err = e.hisaaboError;
|
|
337
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
338
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
339
|
+
}
|
|
340
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ── Party Statement ────────────────────────────────────────────────────────
|
|
345
|
+
|
|
346
|
+
interface StatementRow {
|
|
347
|
+
date?: string;
|
|
348
|
+
type?: string;
|
|
349
|
+
entryType?: string;
|
|
350
|
+
number?: string;
|
|
351
|
+
invoiceNumber?: string;
|
|
352
|
+
debit?: string;
|
|
353
|
+
credit?: string;
|
|
354
|
+
balance?: string;
|
|
355
|
+
runningBalance?: string;
|
|
356
|
+
[key: string]: unknown;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export async function reportPartyStatementCommand(
|
|
360
|
+
partyId: string,
|
|
361
|
+
opts: ReportOpts,
|
|
362
|
+
): Promise<void> {
|
|
363
|
+
const cfg = requireAuth();
|
|
364
|
+
const client = new HisaaboClient(cfg);
|
|
365
|
+
const { from, to } = resolveRange(opts);
|
|
366
|
+
|
|
367
|
+
try {
|
|
368
|
+
const result = await client.reports.partyStatement({ partyId, fromDate: from, toDate: to });
|
|
369
|
+
|
|
370
|
+
if (opts.json) {
|
|
371
|
+
outputJSON(result);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const res = result as Record<string, unknown>;
|
|
376
|
+
const partyName = String(res["partyName"] ?? res["party"] ?? partyId);
|
|
377
|
+
console.log(`\n Party Statement — ${partyName} ${from} → ${to}\n`);
|
|
378
|
+
console.log(` ${"═".repeat(75)}\n`);
|
|
379
|
+
|
|
380
|
+
const openingBalance = String(res["openingBalance"] ?? "0");
|
|
381
|
+
console.log(` Opening Balance: ${formatAmount(openingBalance).padStart(14)}\n`);
|
|
382
|
+
|
|
383
|
+
const rows: StatementRow[] = Array.isArray(res["entries"]) ? res["entries"] as StatementRow[]
|
|
384
|
+
: Array.isArray(res["rows"]) ? res["rows"] as StatementRow[]
|
|
385
|
+
: [];
|
|
386
|
+
|
|
387
|
+
const cols: ColumnDef<StatementRow>[] = [
|
|
388
|
+
{ key: "date", header: "Date", width: 13, format: (v, r) => formatDate(String(r.date ?? v ?? "")) },
|
|
389
|
+
{ key: "type", header: "Type", width: 12, format: (v, r) => String(r.type ?? r.entryType ?? v ?? "-") },
|
|
390
|
+
{ key: "number", header: "Number", width: 14, format: (v, r) => String(r.number ?? r.invoiceNumber ?? v ?? "-") },
|
|
391
|
+
{ key: "debit", header: "Debit (₹)", align: "right", width: 13, format: (v, r) => parseFloat(String(r.debit ?? v ?? "0")) !== 0 ? formatAmount(String(r.debit ?? v)) : "-" },
|
|
392
|
+
{ key: "credit", header: "Credit (₹)", align: "right", width: 13, format: (v, r) => parseFloat(String(r.credit ?? v ?? "0")) !== 0 ? formatAmount(String(r.credit ?? v)) : "-" },
|
|
393
|
+
{ key: "balance", header: "Balance (₹)", align: "right", width: 14, format: (v, r) => formatAmount(String(r.balance ?? r.runningBalance ?? v ?? "0")) },
|
|
394
|
+
];
|
|
395
|
+
|
|
396
|
+
if (opts.format === "tsv") outputTSV(rows, cols);
|
|
397
|
+
else if (opts.format === "csv") outputCSV(rows, cols);
|
|
398
|
+
else outputTable(rows, cols);
|
|
399
|
+
|
|
400
|
+
if (opts.format !== "tsv" && opts.format !== "csv") {
|
|
401
|
+
const closingBalance = String(res["closingBalance"] ?? res["balance"] ?? "0");
|
|
402
|
+
console.log(`\n Closing Balance: ${formatAmount(closingBalance).padStart(14)}\n`);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
} catch (e) {
|
|
406
|
+
if (e instanceof HisaaboApiError) {
|
|
407
|
+
const err = e.hisaaboError;
|
|
408
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
409
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
410
|
+
}
|
|
411
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ── Payment Summary ────────────────────────────────────────────────────────
|
|
416
|
+
|
|
417
|
+
export async function reportPaymentSummaryCommand(
|
|
418
|
+
opts: ReportOpts & { type?: string },
|
|
419
|
+
): Promise<void> {
|
|
420
|
+
const cfg = requireAuth();
|
|
421
|
+
const client = new HisaaboClient(cfg);
|
|
422
|
+
const { from, to } = resolveRange(opts);
|
|
423
|
+
|
|
424
|
+
try {
|
|
425
|
+
const result = await client.reports.paymentSummary({
|
|
426
|
+
fromDate: from,
|
|
427
|
+
toDate: to,
|
|
428
|
+
type: opts.type as "received" | "made" | "both" | undefined ?? "both",
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
if (opts.json) {
|
|
432
|
+
outputJSON(result);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const res = result as Record<string, unknown>;
|
|
437
|
+
console.log(`\n Payment Summary ${from} → ${to}\n`);
|
|
438
|
+
console.log(" " + "═".repeat(60) + "\n");
|
|
439
|
+
|
|
440
|
+
const received = String(res["totalReceived"] ?? res["received"] ?? "0");
|
|
441
|
+
const made = String(res["totalMade"] ?? res["made"] ?? "0");
|
|
442
|
+
const net = String(res["net"] ?? res["netCash"] ?? "0");
|
|
443
|
+
|
|
444
|
+
console.log(` Total Received: ${formatAmount(received).padStart(14)}`);
|
|
445
|
+
console.log(` Total Made: ${formatAmount(made).padStart(14)}`);
|
|
446
|
+
console.log(` Net: ${formatAmount(net).padStart(14)}`);
|
|
447
|
+
|
|
448
|
+
const breakdown = res["breakdown"] ?? res["byMode"] ?? res["modes"];
|
|
449
|
+
if (breakdown && Array.isArray(breakdown)) {
|
|
450
|
+
console.log(`\n By Payment Mode:\n`);
|
|
451
|
+
(breakdown as Array<Record<string, unknown>>).forEach((row) => {
|
|
452
|
+
const mode = String(row["mode"] ?? row["paymentMode"] ?? "-").padEnd(18);
|
|
453
|
+
const amount = formatAmount(String(row["amount"] ?? row["total"] ?? "0")).padStart(14);
|
|
454
|
+
console.log(` ${mode} ${amount}`);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
console.log();
|
|
458
|
+
|
|
459
|
+
} catch (e) {
|
|
460
|
+
if (e instanceof HisaaboApiError) {
|
|
461
|
+
const err = e.hisaaboError;
|
|
462
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
463
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
464
|
+
}
|
|
465
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ── Cash Flow Forecast ─────────────────────────────────────────────────────
|
|
470
|
+
|
|
471
|
+
export async function reportCashFlowCommand(opts: { json?: boolean }): Promise<void> {
|
|
472
|
+
const cfg = requireAuth();
|
|
473
|
+
const client = new HisaaboClient(cfg);
|
|
474
|
+
|
|
475
|
+
try {
|
|
476
|
+
const result = await client.reports.cashFlowForecast();
|
|
477
|
+
|
|
478
|
+
if (opts.json) {
|
|
479
|
+
outputJSON(result);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const res = result as Record<string, unknown>;
|
|
484
|
+
console.log("\n Cash Flow Forecast\n");
|
|
485
|
+
console.log(" " + "═".repeat(60) + "\n");
|
|
486
|
+
|
|
487
|
+
const currentBalance = String(res["currentBalance"] ?? res["balance"] ?? "0");
|
|
488
|
+
const avgDailyExpenses = String(res["avgDailyExpenses"] ?? res["dailyBurn"] ?? "0");
|
|
489
|
+
|
|
490
|
+
console.log(` Current Balance: ${formatAmount(currentBalance).padStart(14)}`);
|
|
491
|
+
console.log(` Avg Daily Expenses: ${formatAmount(avgDailyExpenses).padStart(14)}`);
|
|
492
|
+
|
|
493
|
+
const forecasts = res["forecasts"] ?? res["forecast"];
|
|
494
|
+
if (forecasts && Array.isArray(forecasts)) {
|
|
495
|
+
console.log(`\n Forecast:\n`);
|
|
496
|
+
(forecasts as Array<Record<string, unknown>>).forEach((f) => {
|
|
497
|
+
const days = String(f["days"] ?? f["day"] ?? "-");
|
|
498
|
+
const balance = formatAmount(String(f["balance"] ?? f["amount"] ?? "0")).padStart(14);
|
|
499
|
+
console.log(` ${`${days}d`.padEnd(6)} ${balance}`);
|
|
500
|
+
});
|
|
501
|
+
} else {
|
|
502
|
+
// Fall back to computing from balance and daily burn if no forecasts array
|
|
503
|
+
const current = parseFloat(currentBalance);
|
|
504
|
+
const daily = parseFloat(avgDailyExpenses);
|
|
505
|
+
if (!isNaN(current) && !isNaN(daily)) {
|
|
506
|
+
console.log(`\n Forecast:\n`);
|
|
507
|
+
for (const days of [7, 14, 30]) {
|
|
508
|
+
const projected = current - daily * days;
|
|
509
|
+
console.log(` ${`${days}d`.padEnd(6)} ${formatAmount(String(projected)).padStart(14)}`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
console.log();
|
|
514
|
+
|
|
515
|
+
} catch (e) {
|
|
516
|
+
if (e instanceof HisaaboApiError) {
|
|
517
|
+
const err = e.hisaaboError;
|
|
518
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
519
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
520
|
+
}
|
|
521
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// ── Collection Efficiency ──────────────────────────────────────────────────
|
|
526
|
+
|
|
527
|
+
export async function reportCollectionEfficiencyCommand(opts: ReportOpts): Promise<void> {
|
|
528
|
+
const cfg = requireAuth();
|
|
529
|
+
const client = new HisaaboClient(cfg);
|
|
530
|
+
const { from, to } = resolveRange(opts);
|
|
531
|
+
|
|
532
|
+
try {
|
|
533
|
+
const result = await client.reports.collectionEfficiency({ fromDate: from, toDate: to });
|
|
534
|
+
|
|
535
|
+
if (opts.json) {
|
|
536
|
+
outputJSON(result);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const res = result as Record<string, unknown>;
|
|
541
|
+
console.log(`\n Collection Efficiency ${from} → ${to}\n`);
|
|
542
|
+
console.log(" " + "═".repeat(60) + "\n");
|
|
543
|
+
|
|
544
|
+
const rate = String(res["collectionRate"] ?? res["rate"] ?? "0");
|
|
545
|
+
const dso = String(res["dso"] ?? res["daysSalesOutstanding"] ?? "-");
|
|
546
|
+
const paidOnTime = String(res["paidOnTime"] ?? res["onTimeCount"] ?? "-");
|
|
547
|
+
const totalInvoiced = String(res["totalInvoiced"] ?? res["invoiced"] ?? "-");
|
|
548
|
+
|
|
549
|
+
console.log(` Collection Rate: ${(parseFloat(rate)).toFixed(1).padStart(8)}%`);
|
|
550
|
+
console.log(` DSO (Days): ${dso.padStart(8)}`);
|
|
551
|
+
console.log(` Paid On Time: ${paidOnTime.padStart(8)}`);
|
|
552
|
+
if (totalInvoiced !== "-") {
|
|
553
|
+
console.log(` Total Invoiced: ${formatAmount(totalInvoiced).padStart(14)}`);
|
|
554
|
+
}
|
|
555
|
+
console.log();
|
|
556
|
+
|
|
557
|
+
} catch (e) {
|
|
558
|
+
if (e instanceof HisaaboApiError) {
|
|
559
|
+
const err = e.hisaaboError;
|
|
560
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
561
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
562
|
+
}
|
|
563
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, outputTable, EXIT, hasColor } from "../../output.js";
|
|
4
|
+
import type { ColumnDef } from "../../output.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
interface ListSessionsOpts {
|
|
8
|
+
expired?: boolean;
|
|
9
|
+
json?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function listSessionsCommand(opts: ListSessionsOpts): Promise<void> {
|
|
13
|
+
const cfg = requireAuth();
|
|
14
|
+
const client = new HisaaboClient(cfg);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const sessions = await client.auth.listSessions({ expired: opts.expired ?? false });
|
|
18
|
+
|
|
19
|
+
if (opts.json) {
|
|
20
|
+
outputJSON(sessions);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const items: unknown[] = Array.isArray(sessions) ? sessions : (sessions?.items ?? sessions?.data ?? []);
|
|
25
|
+
|
|
26
|
+
if (items.length === 0) {
|
|
27
|
+
console.log(opts.expired ? "No expired sessions." : "No active sessions.");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const rows = items.map((item: unknown) => {
|
|
32
|
+
const s = item as Record<string, unknown>;
|
|
33
|
+
return {
|
|
34
|
+
id: String(s["id"] ?? "").slice(0, 12) + "...",
|
|
35
|
+
device: s["userAgent"] ? parseUA(String(s["userAgent"])) : "Unknown",
|
|
36
|
+
ip: String(s["ipAddress"] ?? "\u2014"),
|
|
37
|
+
lastUsed: s["lastUsedAt"] ? timeAgo(String(s["lastUsedAt"])) : "\u2014",
|
|
38
|
+
created: s["createdAt"] ? new Date(String(s["createdAt"])).toLocaleDateString() : "\u2014",
|
|
39
|
+
current: s["isCurrent"] ? "\u2713" : "",
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const columns: ColumnDef<typeof rows[number]>[] = [
|
|
44
|
+
{ key: "id", header: "ID", align: "left" },
|
|
45
|
+
{ key: "device", header: "Device", align: "left" },
|
|
46
|
+
{ key: "ip", header: "IP", align: "left" },
|
|
47
|
+
{ key: "lastUsed", header: "Last Used", align: "left" },
|
|
48
|
+
{ key: "created", header: "Created", align: "left" },
|
|
49
|
+
{ key: "current", header: "Current", align: "left" },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Sessions\n") + "\n");
|
|
53
|
+
else process.stdout.write("\n Sessions\n\n");
|
|
54
|
+
outputTable(rows, columns);
|
|
55
|
+
process.stdout.write("\n");
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e instanceof HisaaboApiError) {
|
|
58
|
+
const err = e.hisaaboError;
|
|
59
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
60
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
61
|
+
}
|
|
62
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseUA(ua: string): string {
|
|
67
|
+
let browser = "Unknown";
|
|
68
|
+
if (ua.includes("Edg/")) browser = "Edge";
|
|
69
|
+
else if (ua.includes("Chrome/")) browser = "Chrome";
|
|
70
|
+
else if (ua.includes("Firefox/")) browser = "Firefox";
|
|
71
|
+
else if (ua.includes("Safari/")) browser = "Safari";
|
|
72
|
+
|
|
73
|
+
let os = "";
|
|
74
|
+
if (ua.includes("Windows")) os = "Windows";
|
|
75
|
+
else if (ua.includes("Mac OS")) os = "macOS";
|
|
76
|
+
else if (ua.includes("Linux")) os = "Linux";
|
|
77
|
+
else if (ua.includes("Android")) os = "Android";
|
|
78
|
+
else if (ua.includes("iPhone") || ua.includes("iPad")) os = "iOS";
|
|
79
|
+
|
|
80
|
+
return os ? `${browser} / ${os}` : browser;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function timeAgo(date: string): string {
|
|
84
|
+
const diff = Date.now() - new Date(date).getTime();
|
|
85
|
+
const mins = Math.floor(diff / 60000);
|
|
86
|
+
if (mins < 1) return "now";
|
|
87
|
+
if (mins < 60) return `${mins}m ago`;
|
|
88
|
+
const hrs = Math.floor(mins / 60);
|
|
89
|
+
if (hrs < 24) return `${hrs}h ago`;
|
|
90
|
+
return `${Math.floor(hrs / 24)}d ago`;
|
|
91
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, success, EXIT } from "../../output.js";
|
|
4
|
+
|
|
5
|
+
export async function revokeAllSessionsCommand(): Promise<void> {
|
|
6
|
+
const cfg = requireAuth();
|
|
7
|
+
const client = new HisaaboClient(cfg);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
await client.auth.logoutAll();
|
|
11
|
+
success("Signed out from all devices.");
|
|
12
|
+
} catch (e) {
|
|
13
|
+
if (e instanceof HisaaboApiError) {
|
|
14
|
+
const err = e.hisaaboError;
|
|
15
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
16
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
17
|
+
}
|
|
18
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, success, outputJSON, EXIT } from "../../output.js";
|
|
4
|
+
|
|
5
|
+
interface RevokeSessionOpts {
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function revokeSessionCommand(sessionId: string, opts: RevokeSessionOpts): Promise<void> {
|
|
10
|
+
const cfg = requireAuth();
|
|
11
|
+
const client = new HisaaboClient(cfg);
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const result = await client.auth.revokeSession({ sessionId });
|
|
15
|
+
|
|
16
|
+
if (opts.json) {
|
|
17
|
+
outputJSON(result);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
success("Session revoked successfully.");
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof HisaaboApiError) {
|
|
24
|
+
const err = e.hisaaboError;
|
|
25
|
+
if (err.code === "not_found") fatalError(`Session not found: ${sessionId}`, EXIT.NOT_FOUND);
|
|
26
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
27
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
28
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
29
|
+
}
|
|
30
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, EXIT, hasColor } from "../../output.js";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
|
|
6
|
+
export async function storeCheckSlugCommand(
|
|
7
|
+
slug: string,
|
|
8
|
+
opts: { json?: boolean },
|
|
9
|
+
): Promise<void> {
|
|
10
|
+
const cfg = requireAuth();
|
|
11
|
+
const client = new HisaaboClient(cfg);
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const result = await client.store.checkSlug({ slug });
|
|
15
|
+
|
|
16
|
+
if (opts.json) {
|
|
17
|
+
outputJSON(result);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const available =
|
|
22
|
+
typeof result === "object" && result !== null
|
|
23
|
+
? (result as Record<string, unknown>)["available"]
|
|
24
|
+
: result;
|
|
25
|
+
|
|
26
|
+
if (available) {
|
|
27
|
+
if (hasColor()) {
|
|
28
|
+
process.stdout.write(chalk.green(`\n ✓ "${slug}" is available\n\n`));
|
|
29
|
+
} else {
|
|
30
|
+
process.stdout.write(`\n OK: "${slug}" is available\n\n`);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
if (hasColor()) {
|
|
34
|
+
process.stdout.write(chalk.red(`\n ✗ "${slug}" is already taken\n\n`));
|
|
35
|
+
} else {
|
|
36
|
+
process.stdout.write(`\n TAKEN: "${slug}" is already taken\n\n`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (e instanceof HisaaboApiError) {
|
|
41
|
+
const err = e.hisaaboError;
|
|
42
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
43
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
44
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
45
|
+
}
|
|
46
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { outputJSON, EXIT, fatalError, success } from "../../output.js";
|
|
4
|
+
|
|
5
|
+
export async function storeItemsToggleCommand(opts: {
|
|
6
|
+
enable?: string;
|
|
7
|
+
disable?: string;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
}): Promise<void> {
|
|
10
|
+
const cfg = requireAuth();
|
|
11
|
+
const client = new HisaaboClient(cfg);
|
|
12
|
+
|
|
13
|
+
if (!opts.enable && !opts.disable) {
|
|
14
|
+
fatalError("At least one of --enable or --disable is required", EXIT.USAGE);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const enableIds = opts.enable ? opts.enable.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
18
|
+
const disableIds = opts.disable ? opts.disable.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const result = await client.store.bulkToggleItems({ enable: enableIds, disable: disableIds });
|
|
22
|
+
|
|
23
|
+
if (opts.json) {
|
|
24
|
+
outputJSON(result);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (enableIds.length > 0) success(`Enabled ${enableIds.length} item(s)`);
|
|
29
|
+
if (disableIds.length > 0) success(`Disabled ${disableIds.length} item(s)`);
|
|
30
|
+
console.log();
|
|
31
|
+
|
|
32
|
+
} catch (e) {
|
|
33
|
+
if (e instanceof HisaaboApiError) {
|
|
34
|
+
const err = e.hisaaboError;
|
|
35
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
36
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
37
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
38
|
+
}
|
|
39
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
40
|
+
}
|
|
41
|
+
}
|