@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,176 @@
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/monthly-comparison.ts
23
+ import chalk from "chalk";
24
+ function changeArrow(pct) {
25
+ if (!hasColor()) return pct >= 0 ? `+${pct.toFixed(1)}%` : `${pct.toFixed(1)}%`;
26
+ if (pct > 0) return chalk.green(`\u25B2 +${pct.toFixed(1)}%`);
27
+ if (pct < 0) return chalk.red(`\u25BC ${pct.toFixed(1)}%`);
28
+ return chalk.dim("\u2500 0.0%");
29
+ }
30
+ function pctChange(current, previous) {
31
+ if (previous === 0) return current > 0 ? 100 : 0;
32
+ return (current - previous) / Math.abs(previous) * 100;
33
+ }
34
+ async function dashboardMonthlyComparisonCommand(opts) {
35
+ const cfg = requireAuth();
36
+ const client = new HisaaboClient(cfg);
37
+ try {
38
+ const data = await client.dashboard.monthlyComparison();
39
+ if (opts.json) {
40
+ outputJSON(data);
41
+ return;
42
+ }
43
+ let months = [];
44
+ if (Array.isArray(data)) {
45
+ months = data.map((r) => {
46
+ const month = String(r["month"] ?? r["period"] ?? r["label"] ?? "-");
47
+ const year = r["year"] ? String(r["year"]) : "";
48
+ const period = year ? `${month} ${year}` : month;
49
+ return {
50
+ period,
51
+ sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
52
+ expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
53
+ profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
54
+ collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0"))
55
+ };
56
+ });
57
+ } else if (data && typeof data === "object") {
58
+ const obj = data;
59
+ if ("current" in obj || "previous" in obj) {
60
+ const cur = obj["current"] ?? {};
61
+ const prev = obj["previous"] ?? {};
62
+ months = [
63
+ {
64
+ period: "Previous Month",
65
+ sales: parseFloat(String(prev["sales"] ?? prev["totalSales"] ?? "0")),
66
+ expenses: parseFloat(String(prev["expenses"] ?? prev["totalExpenses"] ?? "0")),
67
+ profit: parseFloat(String(prev["profit"] ?? prev["netProfit"] ?? "0")),
68
+ collections: parseFloat(String(prev["collections"] ?? prev["totalCollections"] ?? "0"))
69
+ },
70
+ {
71
+ period: "Current Month",
72
+ sales: parseFloat(String(cur["sales"] ?? cur["totalSales"] ?? "0")),
73
+ expenses: parseFloat(String(cur["expenses"] ?? cur["totalExpenses"] ?? "0")),
74
+ profit: parseFloat(String(cur["profit"] ?? cur["netProfit"] ?? "0")),
75
+ collections: parseFloat(String(cur["collections"] ?? cur["totalCollections"] ?? "0"))
76
+ }
77
+ ];
78
+ } else {
79
+ const entries = Object.entries(obj).sort(([a], [b]) => a.localeCompare(b));
80
+ months = entries.map(([period, val]) => {
81
+ const r = val ?? {};
82
+ return {
83
+ period,
84
+ sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
85
+ expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
86
+ profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
87
+ collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0"))
88
+ };
89
+ });
90
+ }
91
+ }
92
+ if (opts.format === "tsv" || opts.format === "csv") {
93
+ const rows2 = months.map((m, i) => {
94
+ const prev = months[i - 1];
95
+ return {
96
+ period: m.period,
97
+ sales: formatAmount(m.sales),
98
+ salesChg: prev ? `${pctChange(m.sales, prev.sales).toFixed(1)}%` : "-",
99
+ expenses: formatAmount(m.expenses),
100
+ profit: formatAmount(m.profit),
101
+ collections: formatAmount(m.collections)
102
+ };
103
+ });
104
+ const columns2 = [
105
+ { key: "period", header: "Month", align: "left" },
106
+ { key: "sales", header: "Sales \u20B9", align: "right" },
107
+ { key: "salesChg", header: "Sales \u0394%", align: "right" },
108
+ { key: "expenses", header: "Expenses \u20B9", align: "right" },
109
+ { key: "profit", header: "Profit \u20B9", align: "right" },
110
+ { key: "collections", header: "Collections \u20B9", align: "right" }
111
+ ];
112
+ if (opts.format === "tsv") outputTSV(rows2, columns2);
113
+ else outputCSV(rows2, columns2);
114
+ return;
115
+ }
116
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" Monthly Comparison\n") + "\n");
117
+ else process.stdout.write("\n Monthly Comparison\n\n");
118
+ if (months.length >= 2) {
119
+ const last = months[months.length - 1];
120
+ const prev = months[months.length - 2];
121
+ const salesPct = pctChange(last.sales, prev.sales);
122
+ const expPct = pctChange(last.expenses, prev.expenses);
123
+ const profitPct = pctChange(last.profit, prev.profit);
124
+ const collPct = pctChange(last.collections, prev.collections);
125
+ process.stdout.write(` ${hasColor() ? chalk.dim("Month-over-month (latest vs previous)") : "Month-over-month (latest vs previous)"}
126
+
127
+ `);
128
+ const summaryRows = [
129
+ { metric: "Sales", current: formatAmount(last.sales), change: changeArrow(salesPct) },
130
+ { metric: "Collections", current: formatAmount(last.collections), change: changeArrow(collPct) },
131
+ { metric: "Expenses", current: formatAmount(last.expenses), change: changeArrow(-expPct) },
132
+ { metric: "Profit", current: formatAmount(last.profit), change: changeArrow(profitPct) }
133
+ ];
134
+ const summaryColumns = [
135
+ { key: "metric", header: "Metric", align: "left" },
136
+ { key: "current", header: "Latest \u20B9", align: "right" },
137
+ { key: "change", header: "vs Prev", align: "right" }
138
+ ];
139
+ outputTable(summaryRows, summaryColumns);
140
+ process.stdout.write("\n");
141
+ }
142
+ const rows = months.map((m, i) => {
143
+ const prev = months[i - 1];
144
+ const salesChg = prev ? changeArrow(pctChange(m.sales, prev.sales)) : "-";
145
+ const profitColor = m.profit >= 0 ? hasColor() ? chalk.green(formatAmount(m.profit)) : formatAmount(m.profit) : hasColor() ? chalk.red(formatAmount(m.profit)) : formatAmount(m.profit);
146
+ return {
147
+ period: m.period,
148
+ sales: formatAmount(m.sales),
149
+ salesChg,
150
+ expenses: formatAmount(m.expenses),
151
+ profit: profitColor,
152
+ collections: formatAmount(m.collections)
153
+ };
154
+ });
155
+ const columns = [
156
+ { key: "period", header: "Month", align: "left" },
157
+ { key: "sales", header: "Sales \u20B9", align: "right" },
158
+ { key: "salesChg", header: "\u0394%", align: "right" },
159
+ { key: "expenses", header: "Expenses \u20B9", align: "right" },
160
+ { key: "profit", header: "Profit \u20B9", align: "right" },
161
+ { key: "collections", header: "Collections \u20B9", align: "right" }
162
+ ];
163
+ outputTable(rows, columns);
164
+ process.stdout.write("\n");
165
+ } catch (e) {
166
+ if (e instanceof HisaaboApiError) {
167
+ const err = e.hisaaboError;
168
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
169
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
170
+ }
171
+ fatalError(String(e instanceof Error ? e.message : e));
172
+ }
173
+ }
174
+ export {
175
+ dashboardMonthlyComparisonCommand
176
+ };
@@ -0,0 +1,55 @@
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/store/order-cancel.ts
17
+ import * as readline from "readline";
18
+ async function storeOrderCancelCommand(id, opts) {
19
+ const cfg = requireAuth();
20
+ const client = new HisaaboClient(cfg);
21
+ if (!opts.yes && process.stdin.isTTY) {
22
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
23
+ const answer = await new Promise((resolve) => {
24
+ rl.question(` Cancel order ${id}? This cannot be undone. (y/n): `, resolve);
25
+ });
26
+ rl.close();
27
+ if (answer.trim().toLowerCase() !== "y") {
28
+ console.log(" Cancelled.");
29
+ process.exit(0);
30
+ }
31
+ }
32
+ try {
33
+ const input = { orderId: id };
34
+ if (opts.reason) input["reason"] = opts.reason;
35
+ const result = await client.store.cancelOrder(input);
36
+ if (opts.json) {
37
+ outputJSON(result);
38
+ return;
39
+ }
40
+ success(`Order ${id} cancelled`);
41
+ console.log();
42
+ } catch (e) {
43
+ if (e instanceof HisaaboApiError) {
44
+ const err = e.hisaaboError;
45
+ if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
46
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
47
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
48
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
49
+ }
50
+ fatalError(String(e instanceof Error ? e.message : e));
51
+ }
52
+ }
53
+ export {
54
+ storeOrderCancelCommand
55
+ };
@@ -0,0 +1,53 @@
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/store/order-confirm.ts
17
+ import * as readline from "readline";
18
+ async function storeOrderConfirmCommand(id, opts) {
19
+ const cfg = requireAuth();
20
+ const client = new HisaaboClient(cfg);
21
+ if (!opts.yes && process.stdin.isTTY) {
22
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
23
+ const answer = await new Promise((resolve) => {
24
+ rl.question(` Confirm order ${id}? (y/n): `, resolve);
25
+ });
26
+ rl.close();
27
+ if (answer.trim().toLowerCase() !== "y") {
28
+ console.log(" Cancelled.");
29
+ process.exit(0);
30
+ }
31
+ }
32
+ try {
33
+ const result = await client.store.confirmOrder({ orderId: id });
34
+ if (opts.json) {
35
+ outputJSON(result);
36
+ return;
37
+ }
38
+ success(`Order ${id} confirmed`);
39
+ console.log();
40
+ } catch (e) {
41
+ if (e instanceof HisaaboApiError) {
42
+ const err = e.hisaaboError;
43
+ if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
44
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
45
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
46
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
47
+ }
48
+ fatalError(String(e instanceof Error ? e.message : e));
49
+ }
50
+ }
51
+ export {
52
+ storeOrderConfirmCommand
53
+ };
@@ -0,0 +1,88 @@
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
+ hasColor,
18
+ outputJSON
19
+ } from "./chunk-NO4FIFMS.js";
20
+
21
+ // src/commands/store/order-get.ts
22
+ import chalk from "chalk";
23
+ async function storeOrderGetCommand(id, opts) {
24
+ const cfg = requireAuth();
25
+ const client = new HisaaboClient(cfg);
26
+ try {
27
+ const order = await client.store.getOrder(id);
28
+ if (!order) {
29
+ fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
30
+ }
31
+ if (opts.json) {
32
+ outputJSON(order);
33
+ return;
34
+ }
35
+ const sep = "\u2500".repeat(40);
36
+ const title = `Order #${order.orderNumber}`;
37
+ if (hasColor()) {
38
+ process.stdout.write(`
39
+ ${chalk.bold(title)}
40
+ `);
41
+ } else {
42
+ process.stdout.write(`
43
+ ${title}
44
+ `);
45
+ }
46
+ process.stdout.write(` ${sep}
47
+ `);
48
+ process.stdout.write(` Customer: ${order.customerName}
49
+ `);
50
+ process.stdout.write(` Date: ${formatDate(order.createdAt)}
51
+ `);
52
+ process.stdout.write(` Status: ${formatStatus(order.status)}
53
+ `);
54
+ process.stdout.write(` Total: \u20B9${formatAmount(order.totalAmount)}
55
+ `);
56
+ if (order.shippingAddress) {
57
+ process.stdout.write(` Address: ${order.shippingAddress}
58
+ `);
59
+ }
60
+ if (order.notes) {
61
+ process.stdout.write(` Notes: ${order.notes}
62
+ `);
63
+ }
64
+ if (order.items && order.items.length > 0) {
65
+ process.stdout.write(`
66
+ Items:
67
+ `);
68
+ for (const item of order.items) {
69
+ process.stdout.write(
70
+ ` \u2022 ${item.name} qty: ${item.quantity} \u20B9${formatAmount(item.price)}
71
+ `
72
+ );
73
+ }
74
+ }
75
+ process.stdout.write("\n");
76
+ } catch (e) {
77
+ if (e instanceof HisaaboApiError) {
78
+ const err = e.hisaaboError;
79
+ if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
80
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
81
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
82
+ }
83
+ fatalError(String(e instanceof Error ? e.message : e));
84
+ }
85
+ }
86
+ export {
87
+ storeOrderGetCommand
88
+ };
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatStatus
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/store/order-update.ts
20
+ var VALID_STATUSES = ["preparing", "ready", "delivered"];
21
+ async function storeOrderUpdateCommand(id, opts) {
22
+ const cfg = requireAuth();
23
+ const client = new HisaaboClient(cfg);
24
+ if (!opts.status) {
25
+ fatalError(
26
+ `--status is required. Valid values: ${VALID_STATUSES.join(", ")}`,
27
+ EXIT.USAGE
28
+ );
29
+ }
30
+ if (!VALID_STATUSES.includes(opts.status)) {
31
+ fatalError(
32
+ `Invalid status "${opts.status}". Valid values: ${VALID_STATUSES.join(", ")}`,
33
+ EXIT.VALIDATION
34
+ );
35
+ }
36
+ try {
37
+ const result = await client.store.updateOrder({
38
+ orderId: id,
39
+ status: opts.status
40
+ });
41
+ if (opts.json) {
42
+ outputJSON(result);
43
+ return;
44
+ }
45
+ success(`Order ${id} status updated to ${formatStatus(result.status ?? opts.status)}`);
46
+ console.log();
47
+ } catch (e) {
48
+ if (e instanceof HisaaboApiError) {
49
+ const err = e.hisaaboError;
50
+ if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
51
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
52
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
53
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
54
+ }
55
+ fatalError(String(e instanceof Error ? e.message : e));
56
+ }
57
+ }
58
+ export {
59
+ storeOrderUpdateCommand
60
+ };
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ EXIT,
4
+ fatalError,
5
+ getWidthTier,
6
+ hasColor,
7
+ isInteractive,
8
+ outputCSV,
9
+ outputIds,
10
+ outputJSON,
11
+ outputTSV,
12
+ outputTable,
13
+ paginationFooter,
14
+ stripAnsi,
15
+ success,
16
+ termWidth,
17
+ warn
18
+ } from "./chunk-NO4FIFMS.js";
19
+ export {
20
+ EXIT,
21
+ fatalError,
22
+ getWidthTier,
23
+ hasColor,
24
+ isInteractive,
25
+ outputCSV,
26
+ outputIds,
27
+ outputJSON,
28
+ outputTSV,
29
+ outputTable,
30
+ paginationFooter,
31
+ stripAnsi,
32
+ success,
33
+ termWidth,
34
+ warn
35
+ };
@@ -0,0 +1,126 @@
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/payment-modes.ts
27
+ import chalk from "chalk";
28
+ var MODE_LABELS = {
29
+ cash: "Cash",
30
+ upi: "UPI",
31
+ bank_transfer: "Bank Transfer",
32
+ cheque: "Cheque",
33
+ card: "Card",
34
+ neft: "NEFT",
35
+ rtgs: "RTGS",
36
+ imps: "IMPS",
37
+ dd: "Demand Draft",
38
+ credit: "Credit",
39
+ other: "Other"
40
+ };
41
+ function modeLabel(raw) {
42
+ return MODE_LABELS[raw.toLowerCase()] ?? raw;
43
+ }
44
+ async function dashboardPaymentModesCommand(opts) {
45
+ const cfg = requireAuth();
46
+ const client = new HisaaboClient(cfg);
47
+ let fromDate = opts.from;
48
+ let toDate = opts.to;
49
+ if (opts.thisMonth) {
50
+ fromDate = monthStart();
51
+ toDate = monthEnd();
52
+ } else if (opts.thisFy) {
53
+ fromDate = fyStart();
54
+ toDate = todayISO();
55
+ }
56
+ try {
57
+ const data = await client.dashboard.paymentModeBreakdown({ fromDate, toDate });
58
+ if (opts.json) {
59
+ outputJSON(data);
60
+ return;
61
+ }
62
+ let modes = [];
63
+ if (Array.isArray(data)) {
64
+ modes = data.map((r) => ({
65
+ mode: String(r["mode"] ?? r["paymentMode"] ?? r["method"] ?? "-"),
66
+ amount: parseFloat(String(r["amount"] ?? r["totalAmount"] ?? "0")),
67
+ count: parseInt(String(r["count"] ?? r["paymentCount"] ?? "0"), 10)
68
+ }));
69
+ } else if (data && typeof data === "object") {
70
+ const obj = data;
71
+ for (const [key, val] of Object.entries(obj)) {
72
+ if (typeof val === "object" && val !== null) {
73
+ const entry = val;
74
+ modes.push({
75
+ mode: key,
76
+ amount: parseFloat(String(entry["amount"] ?? entry["totalAmount"] ?? "0")),
77
+ count: parseInt(String(entry["count"] ?? "0"), 10)
78
+ });
79
+ } else if (typeof val === "string" || typeof val === "number") {
80
+ modes.push({ mode: key, amount: parseFloat(String(val)), count: 0 });
81
+ }
82
+ }
83
+ }
84
+ modes.sort((a, b) => b.amount - a.amount);
85
+ const total = modes.reduce((s, r) => s + r.amount, 0);
86
+ const rows = modes.map((r) => {
87
+ const pct = total > 0 ? (r.amount / total * 100).toFixed(1) + "%" : "-";
88
+ return {
89
+ mode: modeLabel(r.mode),
90
+ amount: formatAmount(r.amount),
91
+ count: r.count > 0 ? String(r.count) : "-",
92
+ pct
93
+ };
94
+ });
95
+ const columns = [
96
+ { key: "mode", header: "Payment Mode", align: "left" },
97
+ { key: "amount", header: "Amount \u20B9", align: "right" },
98
+ { key: "count", header: "Count", align: "right" },
99
+ { key: "pct", header: "% of Total", align: "right" }
100
+ ];
101
+ if (opts.format === "tsv") {
102
+ outputTSV(rows, columns);
103
+ } else if (opts.format === "csv") {
104
+ outputCSV(rows, columns);
105
+ } else {
106
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" Payment Mode Breakdown\n") + "\n");
107
+ else process.stdout.write("\n Payment Mode Breakdown\n\n");
108
+ outputTable(rows, columns);
109
+ if (total > 0) {
110
+ const totalStr = ` Total: \u20B9${formatAmount(total)}`;
111
+ process.stdout.write("\n" + (hasColor() ? chalk.bold(totalStr) : totalStr) + "\n");
112
+ }
113
+ process.stdout.write("\n");
114
+ }
115
+ } catch (e) {
116
+ if (e instanceof HisaaboApiError) {
117
+ const err = e.hisaaboError;
118
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
119
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
120
+ }
121
+ fatalError(String(e instanceof Error ? e.message : e));
122
+ }
123
+ }
124
+ export {
125
+ dashboardPaymentModesCommand
126
+ };