@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.
Files changed (172) hide show
  1. package/.turbo/turbo-typecheck.log +1 -1
  2. package/README.md +332 -0
  3. package/dist/bin/audit-trail-5LOCJ7XZ.js +78 -0
  4. package/dist/bin/categories-64WWZTND.js +47 -0
  5. package/dist/bin/check-slug-FLHHUDYS.js +65 -0
  6. package/dist/bin/chunk-4MEL44QX.js +848 -0
  7. package/dist/bin/chunk-FIMJZAS4.js +84 -0
  8. package/dist/bin/chunk-NO4FIFMS.js +176 -0
  9. package/dist/bin/chunk-T63VQXNM.js +156 -0
  10. package/dist/bin/client-5NZ23GML.js +11 -0
  11. package/dist/bin/collection-efficiency-U56XNVEE.js +165 -0
  12. package/dist/bin/config-335MN4I7.js +18 -0
  13. package/dist/bin/create-RPDEORDD.js +83 -0
  14. package/dist/bin/default-account-AE6EXZZR.js +58 -0
  15. package/dist/bin/expenses-5N2QSG54.js +89 -0
  16. package/dist/bin/export-QICOQK34.js +59 -0
  17. package/dist/bin/factory-KOCW2AQM.js +483 -0
  18. package/dist/bin/get-A43QCI2S.js +66 -0
  19. package/dist/bin/get-GWH6S5SJ.js +71 -0
  20. package/dist/bin/hisaabo.js +2302 -1510
  21. package/dist/bin/invitations-P3EEN5WI.js +66 -0
  22. package/dist/bin/invite-T3CKX53E.js +53 -0
  23. package/dist/bin/invoice-breakdown-FN5BEFJD.js +97 -0
  24. package/dist/bin/items-2OOCQKVF.js +62 -0
  25. package/dist/bin/items-toggle-SKZWCGJH.js +46 -0
  26. package/dist/bin/list-A2RKI3ZG.js +79 -0
  27. package/dist/bin/list-NRMBMKMI.js +90 -0
  28. package/dist/bin/list-T74SN6IR.js +46 -0
  29. package/dist/bin/members-W2GW3ODT.js +55 -0
  30. package/dist/bin/monthly-comparison-T34ZFOHL.js +176 -0
  31. package/dist/bin/order-cancel-TI27JYYD.js +55 -0
  32. package/dist/bin/order-confirm-VMRAMNTD.js +53 -0
  33. package/dist/bin/order-get-C2RBUR4O.js +88 -0
  34. package/dist/bin/order-update-RE3HATNF.js +60 -0
  35. package/dist/bin/output-NUOL7KJW.js +35 -0
  36. package/dist/bin/payment-modes-WOOT22I7.js +126 -0
  37. package/dist/bin/profit-loss-T4RESJ32.js +135 -0
  38. package/dist/bin/receivables-aging-6XMENEWS.js +161 -0
  39. package/dist/bin/remove-6QZI4JCY.js +52 -0
  40. package/dist/bin/revoke-AVEMPAC7.js +40 -0
  41. package/dist/bin/revoke-YUCFZFNR.js +52 -0
  42. package/dist/bin/revoke-all-LFW5WBHO.js +33 -0
  43. package/dist/bin/revoke-invitation-DTGQRJR4.js +40 -0
  44. package/dist/bin/sales-trend-ZYBRUDUU.js +71 -0
  45. package/dist/bin/sequence-FPOJTI2P.js +66 -0
  46. package/dist/bin/store-IOB4Y67C.js +82 -0
  47. package/dist/bin/summary-5KYBA4ZO.js +113 -0
  48. package/dist/bin/top-customers-WSQ2UEJL.js +81 -0
  49. package/dist/bin/top-items-RWQPDGLN.js +84 -0
  50. package/dist/bin/top-outstanding-QAMO2E7Y.js +64 -0
  51. package/dist/bin/unpaid-invoices-WB3TK5B4.js +65 -0
  52. package/dist/bin/untracked-H733MYJL.js +67 -0
  53. package/dist/bin/update-H6LPO2Z4.js +61 -0
  54. package/dist/bin/update-JU2X3XU5.js +54 -0
  55. package/dist/bin/update-TLBUIC5J.js +57 -0
  56. package/dist/bin/update-role-QST7BVFX.js +45 -0
  57. package/dist/bin/update-settings-Q2EGRLKZ.js +56 -0
  58. package/package.json +7 -6
  59. package/src/auth.ts +12 -3
  60. package/src/bin/hisaabo.ts +49 -935
  61. package/src/bin/registrars/api-key.ts +44 -0
  62. package/src/bin/registrars/auth.ts +222 -0
  63. package/src/bin/registrars/automated-invoice.ts +167 -0
  64. package/src/bin/registrars/bank.ts +124 -0
  65. package/src/bin/registrars/business.ts +120 -0
  66. package/src/bin/registrars/dashboard.ts +225 -0
  67. package/src/bin/registrars/document.ts +184 -0
  68. package/src/bin/registrars/expense.ts +87 -0
  69. package/src/bin/registrars/gst.ts +41 -0
  70. package/src/bin/registrars/import.ts +49 -0
  71. package/src/bin/registrars/invoice.ts +117 -0
  72. package/src/bin/registrars/item.ts +112 -0
  73. package/src/bin/registrars/party.ts +81 -0
  74. package/src/bin/registrars/payment.ts +128 -0
  75. package/src/bin/registrars/report.ts +142 -0
  76. package/src/bin/registrars/session.ts +32 -0
  77. package/src/bin/registrars/shipment.ts +74 -0
  78. package/src/bin/registrars/store.ts +128 -0
  79. package/src/bin/registrars/target.ts +46 -0
  80. package/src/bin/registrars/tenant.ts +73 -0
  81. package/src/client.ts +589 -15
  82. package/src/commands/api-key/create.ts +72 -0
  83. package/src/commands/api-key/list.ts +71 -0
  84. package/src/commands/api-key/revoke.ts +46 -0
  85. package/src/commands/automated-invoice/create.ts +85 -0
  86. package/src/commands/automated-invoice/delete.ts +42 -0
  87. package/src/commands/automated-invoice/get.ts +113 -0
  88. package/src/commands/automated-invoice/history.ts +65 -0
  89. package/src/commands/automated-invoice/index.ts +11 -0
  90. package/src/commands/automated-invoice/list.ts +91 -0
  91. package/src/commands/automated-invoice/pause.ts +29 -0
  92. package/src/commands/automated-invoice/resume.ts +29 -0
  93. package/src/commands/automated-invoice/run-now.ts +29 -0
  94. package/src/commands/automated-invoice/suggestions.ts +68 -0
  95. package/src/commands/automated-invoice/update.ts +54 -0
  96. package/src/commands/automated-invoice/usage.ts +68 -0
  97. package/src/commands/bank/gateway-config.ts +61 -0
  98. package/src/commands/bank/update-gateway.ts +84 -0
  99. package/src/commands/business/audit-trail.ts +79 -0
  100. package/src/commands/business/export.ts +52 -0
  101. package/src/commands/business/get.ts +55 -0
  102. package/src/commands/business/sequence.ts +65 -0
  103. package/src/commands/business/update.ts +64 -0
  104. package/src/commands/dashboard/collection-efficiency.ts +164 -0
  105. package/src/commands/dashboard/expenses.ts +76 -0
  106. package/src/commands/dashboard/invoice-breakdown.ts +89 -0
  107. package/src/commands/dashboard/monthly-comparison.ts +193 -0
  108. package/src/commands/dashboard/payment-modes.ts +121 -0
  109. package/src/commands/dashboard/profit-loss.ts +146 -0
  110. package/src/commands/dashboard/receivables-aging.ts +169 -0
  111. package/src/commands/dashboard/sales-trend.ts +68 -0
  112. package/src/commands/dashboard/summary.ts +105 -0
  113. package/src/commands/dashboard/top-customers.ts +70 -0
  114. package/src/commands/dashboard/top-items.ts +74 -0
  115. package/src/commands/dashboard/top-outstanding.ts +61 -0
  116. package/src/commands/document/factory.ts +590 -0
  117. package/src/commands/expense/categories.ts +40 -0
  118. package/src/commands/expense/update.ts +58 -0
  119. package/src/commands/import/index.ts +68 -0
  120. package/src/commands/item/categories.ts +40 -0
  121. package/src/commands/item/low-stock-count.ts +32 -0
  122. package/src/commands/item/merge.ts +53 -0
  123. package/src/commands/item/price-history.ts +59 -0
  124. package/src/commands/item/rename-unit.ts +39 -0
  125. package/src/commands/item/sales-stats.ts +44 -0
  126. package/src/commands/item/stock-history.ts +70 -0
  127. package/src/commands/item/switch-base-unit.ts +42 -0
  128. package/src/commands/item/update.ts +59 -0
  129. package/src/commands/item/variants-create.ts +58 -0
  130. package/src/commands/item/variants-delete.ts +47 -0
  131. package/src/commands/item/variants-list.ts +63 -0
  132. package/src/commands/item/variants-update.ts +61 -0
  133. package/src/commands/party/ledger-report.ts +81 -0
  134. package/src/commands/party/merge.ts +50 -0
  135. package/src/commands/party/stats.ts +40 -0
  136. package/src/commands/party/top-items.ts +57 -0
  137. package/src/commands/party/update.ts +65 -0
  138. package/src/commands/payment/default-account.ts +56 -0
  139. package/src/commands/payment/get.ts +59 -0
  140. package/src/commands/payment/unpaid-invoices.ts +69 -0
  141. package/src/commands/payment/untracked.ts +70 -0
  142. package/src/commands/payment/update.ts +54 -0
  143. package/src/commands/report/index.ts +348 -1
  144. package/src/commands/session/list.ts +91 -0
  145. package/src/commands/session/revoke-all.ts +20 -0
  146. package/src/commands/session/revoke.ts +32 -0
  147. package/src/commands/store/check-slug.ts +48 -0
  148. package/src/commands/store/items-toggle.ts +41 -0
  149. package/src/commands/store/items.ts +61 -0
  150. package/src/commands/store/order-cancel.ts +48 -0
  151. package/src/commands/store/order-confirm.ts +45 -0
  152. package/src/commands/store/order-get.ts +66 -0
  153. package/src/commands/store/order-update.ts +52 -0
  154. package/src/commands/store/update-settings.ts +52 -0
  155. package/src/commands/tenant/invitations.ts +62 -0
  156. package/src/commands/tenant/invite.ts +57 -0
  157. package/src/commands/tenant/list.ts +46 -0
  158. package/src/commands/tenant/members.ts +55 -0
  159. package/src/commands/tenant/remove.ts +47 -0
  160. package/src/commands/tenant/revoke-invitation.ts +32 -0
  161. package/src/commands/tenant/update-role.ts +41 -0
  162. package/src/config.ts +51 -2
  163. package/src/error-handler.ts +53 -0
  164. package/src/output.ts +1 -0
  165. package/src/spinner.ts +39 -0
  166. package/tsup.config.ts +6 -1
  167. package/src/components/ErrorDisplay.tsx +0 -16
  168. package/src/components/Header.tsx +0 -26
  169. package/src/components/MoneyCell.tsx +0 -16
  170. package/src/components/Spinner.tsx +0 -12
  171. package/src/components/StatusBadge.tsx +0 -39
  172. package/src/components/Table.tsx +0 -63
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount,
4
+ formatDate,
5
+ formatStatus
6
+ } from "./chunk-T63VQXNM.js";
7
+ import {
8
+ HisaaboApiError,
9
+ HisaaboClient
10
+ } from "./chunk-4MEL44QX.js";
11
+ import {
12
+ requireAuth
13
+ } from "./chunk-FIMJZAS4.js";
14
+ import {
15
+ EXIT,
16
+ fatalError,
17
+ outputJSON,
18
+ outputTable,
19
+ paginationFooter
20
+ } from "./chunk-NO4FIFMS.js";
21
+
22
+ // src/commands/store/index.ts
23
+ async function storeSettingsCommand(opts) {
24
+ const cfg = requireAuth();
25
+ const client = new HisaaboClient(cfg);
26
+ try {
27
+ const settings = await client.store.getSettings();
28
+ if (opts.json) {
29
+ outputJSON(settings);
30
+ return;
31
+ }
32
+ console.log("\n Store Settings\n " + "\u2500".repeat(35));
33
+ console.log(` Enabled: ${settings.storeEnabled ? "Yes" : "No"}`);
34
+ if (settings.storeSlug) console.log(` Slug: ${settings.storeSlug}`);
35
+ if (settings.storeName) console.log(` Name: ${settings.storeName}`);
36
+ if (settings.storeDescription) console.log(` About: ${settings.storeDescription}`);
37
+ console.log();
38
+ } catch (e) {
39
+ if (e instanceof HisaaboApiError) {
40
+ const err = e.hisaaboError;
41
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
42
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
43
+ }
44
+ fatalError(String(e instanceof Error ? e.message : e));
45
+ }
46
+ }
47
+ async function storeOrdersCommand(opts) {
48
+ const cfg = requireAuth();
49
+ const client = new HisaaboClient(cfg);
50
+ const page = opts.page ?? 1;
51
+ const limit = opts.limit ?? 20;
52
+ try {
53
+ const result = await client.store.listOrders({ status: opts.status ?? null, page, limit });
54
+ if (opts.json) {
55
+ outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
56
+ return;
57
+ }
58
+ console.log(`
59
+ Store Orders ${result.total} total
60
+ `);
61
+ const cols = [
62
+ { key: "orderNumber", header: "#", width: 12 },
63
+ { key: "customerName", header: "Customer", width: 20 },
64
+ { key: "createdAt", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
65
+ { key: "totalAmount", header: "Amount (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
66
+ { key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) }
67
+ ];
68
+ outputTable(result.data, cols);
69
+ paginationFooter(result.page, result.limit, result.total);
70
+ } catch (e) {
71
+ if (e instanceof HisaaboApiError) {
72
+ const err = e.hisaaboError;
73
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
74
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
75
+ }
76
+ fatalError(String(e instanceof Error ? e.message : e));
77
+ }
78
+ }
79
+ export {
80
+ storeOrdersCommand,
81
+ storeSettingsCommand
82
+ };
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ currentFY,
4
+ formatAmount,
5
+ formatRelativeDate,
6
+ formatStatus,
7
+ fyStart,
8
+ todayISO
9
+ } from "./chunk-T63VQXNM.js";
10
+ import {
11
+ HisaaboApiError,
12
+ HisaaboClient
13
+ } from "./chunk-4MEL44QX.js";
14
+ import {
15
+ requireAuth
16
+ } from "./chunk-FIMJZAS4.js";
17
+ import {
18
+ EXIT,
19
+ fatalError,
20
+ hasColor,
21
+ outputJSON,
22
+ termWidth
23
+ } from "./chunk-NO4FIFMS.js";
24
+
25
+ // src/commands/dashboard/summary.ts
26
+ import chalk from "chalk";
27
+ function box(title, lines, width) {
28
+ const innerW = width - 2;
29
+ const titleStr = `\u2500 ${title} `;
30
+ const border = "\u250C" + titleStr + "\u2500".repeat(Math.max(1, innerW - titleStr.length)) + "\u2510";
31
+ const bottom = "\u2514" + "\u2500".repeat(innerW) + "\u2518";
32
+ const padded = lines.map((l) => {
33
+ const vis = l.length;
34
+ const pad = Math.max(0, innerW - vis - 1);
35
+ return "\u2502 " + l + " ".repeat(pad) + "\u2502";
36
+ });
37
+ return [border, ...padded, bottom];
38
+ }
39
+ function colorMoney(amount, good = true) {
40
+ if (!hasColor()) return formatAmount(amount);
41
+ const num = parseFloat(amount);
42
+ if (isNaN(num) || num === 0) return chalk.dim(formatAmount(amount));
43
+ if (good) return chalk.green(formatAmount(amount));
44
+ return chalk.red(formatAmount(amount));
45
+ }
46
+ async function dashboardCommand(opts) {
47
+ const cfg = requireAuth();
48
+ const client = new HisaaboClient(cfg);
49
+ const from = fyStart();
50
+ const to = todayISO();
51
+ try {
52
+ const summary = await client.dashboard.summary({ fromDate: from, toDate: to });
53
+ if (opts.json) {
54
+ outputJSON(summary);
55
+ return;
56
+ }
57
+ const width = Math.min(termWidth() - 2, 70);
58
+ const fy = currentFY();
59
+ console.log();
60
+ console.log(` Hisaabo Dashboard` + " ".repeat(Math.max(2, width - 30)) + (cfg.businessName ?? ""));
61
+ console.log(` FY ${fy} (01 Apr ${fy.split("-")[0]} - 31 Mar 20${fy.split("-")[1]})`);
62
+ console.log(` ${"\u2550".repeat(width)}`);
63
+ console.log();
64
+ const halfW = Math.floor((width - 3) / 2);
65
+ const revLines = [
66
+ `Sales ${formatAmount(summary.totalSales).padStart(12)}`,
67
+ `Cash In ${formatAmount(summary.cashInHand).padStart(12)}`
68
+ ];
69
+ const expLines = [
70
+ `Purchases ${formatAmount(summary.totalPurchases).padStart(11)}`,
71
+ `Expenses ${formatAmount(summary.totalExpenses).padStart(11)}`
72
+ ];
73
+ const revBox = box("Revenue", revLines, halfW);
74
+ const expBox = box("Expenses", expLines, halfW);
75
+ for (let i = 0; i < Math.max(revBox.length, expBox.length); i++) {
76
+ const l = (revBox[i] ?? "").padEnd(halfW);
77
+ const r = expBox[i] ?? "";
78
+ console.log(` ${l} ${r}`);
79
+ }
80
+ console.log();
81
+ const net = parseFloat(summary.receivable) - parseFloat(summary.payable);
82
+ const netLabel = net >= 0 ? "receivable" : "payable";
83
+ const outLines = [
84
+ `Receivable ${colorMoney(summary.receivable)}`,
85
+ `Payable ${colorMoney(summary.payable, false)}`,
86
+ `Net Position ${colorMoney(String(Math.abs(net)))} ${netLabel}`
87
+ ];
88
+ const outBox = box("Outstanding", outLines, width);
89
+ outBox.forEach((l) => console.log(` ${l}`));
90
+ console.log();
91
+ const recentLines = summary.recentInvoices.slice(0, 5).map((inv) => {
92
+ const num = inv.invoiceNumber.padEnd(10);
93
+ const party = inv.partyName.slice(0, 16).padEnd(18);
94
+ const amt = formatAmount(inv.totalAmount).padStart(12);
95
+ const status = formatStatus(inv.status).padEnd(10);
96
+ const rel = formatRelativeDate(inv.invoiceDate).padEnd(7);
97
+ return `${num} ${party} ${amt} ${status} ${rel}`;
98
+ });
99
+ const recentBox = box("Recent Invoices", recentLines, width);
100
+ recentBox.forEach((l) => console.log(` ${l}`));
101
+ console.log();
102
+ } catch (e) {
103
+ if (e instanceof HisaaboApiError) {
104
+ const err = e.hisaaboError;
105
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
106
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
107
+ }
108
+ fatalError(String(e instanceof Error ? e.message : e));
109
+ }
110
+ }
111
+ export {
112
+ dashboardCommand
113
+ };
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount,
4
+ fyStart,
5
+ monthEnd,
6
+ monthStart,
7
+ todayISO
8
+ } from "./chunk-T63VQXNM.js";
9
+ import {
10
+ HisaaboApiError,
11
+ HisaaboClient
12
+ } from "./chunk-4MEL44QX.js";
13
+ import {
14
+ requireAuth
15
+ } from "./chunk-FIMJZAS4.js";
16
+ import {
17
+ EXIT,
18
+ fatalError,
19
+ hasColor,
20
+ outputCSV,
21
+ outputJSON,
22
+ outputTSV,
23
+ outputTable
24
+ } from "./chunk-NO4FIFMS.js";
25
+
26
+ // src/commands/dashboard/top-customers.ts
27
+ import chalk from "chalk";
28
+ async function dashboardTopCustomersCommand(opts) {
29
+ const cfg = requireAuth();
30
+ const client = new HisaaboClient(cfg);
31
+ let fromDate = opts.from;
32
+ let toDate = opts.to;
33
+ if (opts.thisMonth) {
34
+ fromDate = monthStart();
35
+ toDate = monthEnd();
36
+ } else if (opts.thisFy) {
37
+ fromDate = fyStart();
38
+ toDate = todayISO();
39
+ }
40
+ try {
41
+ const data = await client.dashboard.topCustomers({
42
+ limit: opts.limit,
43
+ fromDate,
44
+ toDate
45
+ });
46
+ if (opts.json) {
47
+ outputJSON(data);
48
+ return;
49
+ }
50
+ const rows = Array.isArray(data) ? data.map((r) => ({
51
+ party: String(r["partyName"] ?? r["party"] ?? "-"),
52
+ revenue: formatAmount(String(r["revenue"] ?? r["totalRevenue"] ?? r["totalSales"] ?? "0")),
53
+ invoices: String(r["invoiceCount"] ?? r["invoices"] ?? "-")
54
+ })) : [];
55
+ const columns = [
56
+ { key: "party", header: "Customer", align: "left" },
57
+ { key: "revenue", header: "Revenue \u20B9", align: "right" },
58
+ { key: "invoices", header: "Invoices", align: "right" }
59
+ ];
60
+ if (opts.format === "tsv") {
61
+ outputTSV(rows, columns);
62
+ } else if (opts.format === "csv") {
63
+ outputCSV(rows, columns);
64
+ } else {
65
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Customers by Revenue\n") + "\n");
66
+ else process.stdout.write("\n Top Customers by Revenue\n\n");
67
+ outputTable(rows, columns);
68
+ process.stdout.write("\n");
69
+ }
70
+ } catch (e) {
71
+ if (e instanceof HisaaboApiError) {
72
+ const err = e.hisaaboError;
73
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
74
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
75
+ }
76
+ fatalError(String(e instanceof Error ? e.message : e));
77
+ }
78
+ }
79
+ export {
80
+ dashboardTopCustomersCommand
81
+ };
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount,
4
+ fyStart,
5
+ monthEnd,
6
+ monthStart,
7
+ todayISO
8
+ } from "./chunk-T63VQXNM.js";
9
+ import {
10
+ HisaaboApiError,
11
+ HisaaboClient
12
+ } from "./chunk-4MEL44QX.js";
13
+ import {
14
+ requireAuth
15
+ } from "./chunk-FIMJZAS4.js";
16
+ import {
17
+ EXIT,
18
+ fatalError,
19
+ hasColor,
20
+ outputCSV,
21
+ outputJSON,
22
+ outputTSV,
23
+ outputTable
24
+ } from "./chunk-NO4FIFMS.js";
25
+
26
+ // src/commands/dashboard/top-items.ts
27
+ import chalk from "chalk";
28
+ async function dashboardTopItemsCommand(opts) {
29
+ const cfg = requireAuth();
30
+ const client = new HisaaboClient(cfg);
31
+ let fromDate = opts.from;
32
+ let toDate = opts.to;
33
+ if (opts.thisMonth) {
34
+ fromDate = monthStart();
35
+ toDate = monthEnd();
36
+ } else if (opts.thisFy) {
37
+ fromDate = fyStart();
38
+ toDate = todayISO();
39
+ }
40
+ try {
41
+ const data = await client.dashboard.topSellingItems({
42
+ limit: opts.limit,
43
+ itemType: opts.type,
44
+ fromDate,
45
+ toDate
46
+ });
47
+ if (opts.json) {
48
+ outputJSON(data);
49
+ return;
50
+ }
51
+ const rows = Array.isArray(data) ? data.map((r) => ({
52
+ item: String(r["itemName"] ?? r["name"] ?? "-"),
53
+ qty: String(r["totalQuantity"] ?? r["qty"] ?? r["quantity"] ?? "-"),
54
+ revenue: formatAmount(String(r["totalRevenue"] ?? r["revenue"] ?? "0")),
55
+ type: String(r["itemType"] ?? r["type"] ?? "-")
56
+ })) : [];
57
+ const columns = [
58
+ { key: "item", header: "Item", align: "left" },
59
+ { key: "type", header: "Type", align: "left" },
60
+ { key: "qty", header: "Qty Sold", align: "right" },
61
+ { key: "revenue", header: "Revenue \u20B9", align: "right" }
62
+ ];
63
+ if (opts.format === "tsv") {
64
+ outputTSV(rows, columns);
65
+ } else if (opts.format === "csv") {
66
+ outputCSV(rows, columns);
67
+ } else {
68
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Selling Items\n") + "\n");
69
+ else process.stdout.write("\n Top Selling Items\n\n");
70
+ outputTable(rows, columns);
71
+ process.stdout.write("\n");
72
+ }
73
+ } catch (e) {
74
+ if (e instanceof HisaaboApiError) {
75
+ const err = e.hisaaboError;
76
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
77
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
78
+ }
79
+ fatalError(String(e instanceof Error ? e.message : e));
80
+ }
81
+ }
82
+ export {
83
+ dashboardTopItemsCommand
84
+ };
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount
4
+ } from "./chunk-T63VQXNM.js";
5
+ import {
6
+ HisaaboApiError,
7
+ HisaaboClient
8
+ } from "./chunk-4MEL44QX.js";
9
+ import {
10
+ requireAuth
11
+ } from "./chunk-FIMJZAS4.js";
12
+ import {
13
+ EXIT,
14
+ fatalError,
15
+ hasColor,
16
+ outputCSV,
17
+ outputJSON,
18
+ outputTSV,
19
+ outputTable
20
+ } from "./chunk-NO4FIFMS.js";
21
+
22
+ // src/commands/dashboard/top-outstanding.ts
23
+ import chalk from "chalk";
24
+ async function dashboardTopOutstandingCommand(opts) {
25
+ const cfg = requireAuth();
26
+ const client = new HisaaboClient(cfg);
27
+ try {
28
+ const data = await client.dashboard.topOutstanding({ limit: opts.limit });
29
+ if (opts.json) {
30
+ outputJSON(data);
31
+ return;
32
+ }
33
+ const rows = Array.isArray(data) ? data.map((r) => ({
34
+ party: String(r["partyName"] ?? r["party"] ?? "-"),
35
+ outstanding: formatAmount(String(r["outstanding"] ?? r["outstandingAmount"] ?? "0")),
36
+ oldestAge: r["oldestInvoiceDays"] != null ? `${r["oldestInvoiceDays"]}d` : r["oldestAge"] != null ? `${r["oldestAge"]}d` : "-"
37
+ })) : [];
38
+ const columns = [
39
+ { key: "party", header: "Party", align: "left" },
40
+ { key: "outstanding", header: "Outstanding \u20B9", align: "right" },
41
+ { key: "oldestAge", header: "Oldest Invoice", align: "right" }
42
+ ];
43
+ if (opts.format === "tsv") {
44
+ outputTSV(rows, columns);
45
+ } else if (opts.format === "csv") {
46
+ outputCSV(rows, columns);
47
+ } else {
48
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" Top Outstanding\n") + "\n");
49
+ else process.stdout.write("\n Top Outstanding\n\n");
50
+ outputTable(rows, columns);
51
+ process.stdout.write("\n");
52
+ }
53
+ } catch (e) {
54
+ if (e instanceof HisaaboApiError) {
55
+ const err = e.hisaaboError;
56
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
57
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
58
+ }
59
+ fatalError(String(e instanceof Error ? e.message : e));
60
+ }
61
+ }
62
+ export {
63
+ dashboardTopOutstandingCommand
64
+ };
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount,
4
+ formatDate
5
+ } from "./chunk-T63VQXNM.js";
6
+ import {
7
+ HisaaboApiError,
8
+ HisaaboClient
9
+ } from "./chunk-4MEL44QX.js";
10
+ import {
11
+ requireAuth
12
+ } from "./chunk-FIMJZAS4.js";
13
+ import {
14
+ EXIT,
15
+ fatalError,
16
+ outputCSV,
17
+ outputJSON,
18
+ outputTSV,
19
+ outputTable
20
+ } from "./chunk-NO4FIFMS.js";
21
+
22
+ // src/commands/payment/unpaid-invoices.ts
23
+ async function paymentUnpaidInvoicesCommand(partyId, opts) {
24
+ const cfg = requireAuth();
25
+ const client = new HisaaboClient(cfg);
26
+ try {
27
+ const result = await client.payment.unpaidInvoices({ partyId });
28
+ if (opts.json) {
29
+ outputJSON(result);
30
+ return;
31
+ }
32
+ const invoices = Array.isArray(result) ? result : result?.data ?? [];
33
+ if (invoices.length === 0) {
34
+ console.log("\n No unpaid invoices for this party.\n");
35
+ return;
36
+ }
37
+ console.log(`
38
+ Unpaid Invoices (${invoices.length})
39
+ `);
40
+ const cols = [
41
+ { key: "invoiceNumber", header: "Invoice #", width: 14 },
42
+ { key: "invoiceDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
43
+ { key: "totalAmount", header: "Total (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
44
+ { key: "paidAmount", header: "Paid (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
45
+ { key: "outstandingAmount", header: "Outstanding (\u20B9)", align: "right", width: 16, format: (v) => formatAmount(String(v ?? "0")) },
46
+ { key: "status", header: "Status", width: 10, format: (v) => String(v ?? "").toUpperCase() }
47
+ ];
48
+ if (opts.format === "tsv") outputTSV(invoices, cols);
49
+ else if (opts.format === "csv") outputCSV(invoices, cols);
50
+ else outputTable(invoices, cols);
51
+ console.log();
52
+ } catch (e) {
53
+ if (e instanceof HisaaboApiError) {
54
+ const err = e.hisaaboError;
55
+ if (err.code === "not_found") fatalError(`Party not found: ${partyId}`, EXIT.NOT_FOUND);
56
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
57
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
58
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
59
+ }
60
+ fatalError(String(e instanceof Error ? e.message : e));
61
+ }
62
+ }
63
+ export {
64
+ paymentUnpaidInvoicesCommand
65
+ };
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount,
4
+ formatDate
5
+ } from "./chunk-T63VQXNM.js";
6
+ import {
7
+ HisaaboApiError,
8
+ HisaaboClient
9
+ } from "./chunk-4MEL44QX.js";
10
+ import {
11
+ requireAuth
12
+ } from "./chunk-FIMJZAS4.js";
13
+ import {
14
+ EXIT,
15
+ fatalError,
16
+ outputCSV,
17
+ outputJSON,
18
+ outputTSV,
19
+ outputTable,
20
+ paginationFooter
21
+ } from "./chunk-NO4FIFMS.js";
22
+
23
+ // src/commands/payment/untracked.ts
24
+ async function paymentUntrackedCommand(opts) {
25
+ const cfg = requireAuth();
26
+ const client = new HisaaboClient(cfg);
27
+ const page = opts.page ?? 1;
28
+ const limit = opts.limit ?? 20;
29
+ try {
30
+ const result = await client.payment.untrackedPayments({ page, limit });
31
+ if (opts.json) {
32
+ outputJSON(result);
33
+ return;
34
+ }
35
+ const payments = Array.isArray(result) ? result : result?.data ?? [];
36
+ const total = result?.total ?? payments.length;
37
+ const resultPage = result?.page ?? page;
38
+ const resultLimit = result?.limit ?? limit;
39
+ console.log(`
40
+ Untracked Payments ${total} total
41
+ `);
42
+ const cols = [
43
+ { key: "paymentNumber", header: "#", width: 12 },
44
+ { key: "partyName", header: "Party", width: 22 },
45
+ { key: "paymentDate", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
46
+ { key: "amount", header: "Amount (\u20B9)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
47
+ { key: "mode", header: "Mode", width: 8 },
48
+ { key: "referenceNumber", header: "Ref#", width: 14, format: (v) => String(v ?? "-") }
49
+ ];
50
+ if (opts.format === "tsv") outputTSV(payments, cols);
51
+ else if (opts.format === "csv") outputCSV(payments, cols);
52
+ else {
53
+ outputTable(payments, cols);
54
+ paginationFooter(resultPage, resultLimit, total);
55
+ }
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
+ export {
66
+ paymentUntrackedCommand
67
+ };
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ HisaaboApiError,
4
+ HisaaboClient
5
+ } from "./chunk-4MEL44QX.js";
6
+ import {
7
+ requireAuth
8
+ } from "./chunk-FIMJZAS4.js";
9
+ import {
10
+ EXIT,
11
+ fatalError,
12
+ outputJSON,
13
+ success
14
+ } from "./chunk-NO4FIFMS.js";
15
+
16
+ // src/commands/business/update.ts
17
+ async function businessUpdateCommand(opts) {
18
+ const cfg = requireAuth();
19
+ const client = new HisaaboClient(cfg);
20
+ const payload = {};
21
+ if (opts.name !== void 0) payload["name"] = opts.name;
22
+ if (opts.gstin !== void 0) payload["gstin"] = opts.gstin;
23
+ if (opts.address !== void 0) payload["address"] = opts.address;
24
+ if (opts.state !== void 0) payload["state"] = opts.state;
25
+ if (opts.phone !== void 0) payload["phone"] = opts.phone;
26
+ if (opts.email !== void 0) payload["email"] = opts.email;
27
+ if (opts.financialYearStart !== void 0) {
28
+ const month = parseInt(opts.financialYearStart, 10);
29
+ if (isNaN(month) || month < 1 || month > 12) {
30
+ fatalError("--financial-year-start must be a month number (1\u201312).", EXIT.USAGE);
31
+ }
32
+ payload["financialYearStart"] = month;
33
+ }
34
+ if (Object.keys(payload).length === 0) {
35
+ fatalError("No fields to update. Pass at least one option (--name, --gstin, etc.).", EXIT.USAGE);
36
+ }
37
+ try {
38
+ const result = await client.business.update(payload);
39
+ if (opts.json) {
40
+ outputJSON(result);
41
+ return;
42
+ }
43
+ success("Business settings updated.");
44
+ } catch (e) {
45
+ if (e instanceof HisaaboApiError) {
46
+ const err = e.hisaaboError;
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") {
50
+ const msgs = Object.entries(err.fields).map(([f, ms]) => ` ${f}: ${ms.join(", ")}`).join("\n");
51
+ fatalError(`Validation failed:
52
+ ${msgs}`, EXIT.VALIDATION);
53
+ }
54
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
55
+ }
56
+ fatalError(String(e instanceof Error ? e.message : e));
57
+ }
58
+ }
59
+ export {
60
+ businessUpdateCommand
61
+ };
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatINR
4
+ } from "./chunk-T63VQXNM.js";
5
+ import {
6
+ HisaaboApiError,
7
+ HisaaboClient
8
+ } from "./chunk-4MEL44QX.js";
9
+ import {
10
+ requireAuth
11
+ } from "./chunk-FIMJZAS4.js";
12
+ import {
13
+ EXIT,
14
+ fatalError,
15
+ outputJSON,
16
+ success
17
+ } from "./chunk-NO4FIFMS.js";
18
+
19
+ // src/commands/payment/update.ts
20
+ async function paymentUpdateCommand(id, opts) {
21
+ const cfg = requireAuth();
22
+ const client = new HisaaboClient(cfg);
23
+ const input = { id };
24
+ if (opts.amount !== void 0) input.amount = opts.amount;
25
+ if (opts.mode !== void 0) input.mode = opts.mode;
26
+ if (opts.date !== void 0) input.paymentDate = opts.date;
27
+ if (opts.reference !== void 0) input.referenceNumber = opts.reference || null;
28
+ if (opts.notes !== void 0) input.notes = opts.notes || null;
29
+ const hasUpdates = Object.keys(input).length > 1;
30
+ if (!hasUpdates) {
31
+ fatalError("No fields to update. Provide at least one option: --amount, --mode, --date, --reference, --notes", EXIT.USAGE);
32
+ }
33
+ try {
34
+ const payment = await client.payment.update(input);
35
+ if (opts.json) {
36
+ outputJSON(payment);
37
+ return;
38
+ }
39
+ success(`Updated: ${payment.paymentNumber} \u2014 ${formatINR(payment.amount)}`);
40
+ } catch (e) {
41
+ if (e instanceof HisaaboApiError) {
42
+ const err = e.hisaaboError;
43
+ if (err.code === "not_found") fatalError(`Payment not found: ${id}`, EXIT.NOT_FOUND);
44
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
45
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
46
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
47
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
48
+ }
49
+ fatalError(String(e instanceof Error ? e.message : e));
50
+ }
51
+ }
52
+ export {
53
+ paymentUpdateCommand
54
+ };