@hisaabo/cli 0.7.5 → 0.8.6

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 (210) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +9 -0
  3. package/dist/bin/{audit-trail-DLSSSM4T.js → audit-trail-IJ6SKACR.js} +2 -2
  4. package/dist/bin/{categories-63QR6WCV.js → categories-O6TODPAH.js} +2 -2
  5. package/dist/bin/{check-slug-NXO55WKH.js → check-slug-P7RFU6OP.js} +2 -2
  6. package/dist/bin/chunk-NO4FIFMS.js +0 -0
  7. package/dist/bin/{chunk-7MJDOL6B.js → chunk-QUITS2FE.js} +28 -0
  8. package/dist/bin/{chunk-M42SETRZ.js → chunk-WDN7RIE3.js} +23 -2
  9. package/dist/bin/chunk-ZPYC767N.js +0 -0
  10. package/dist/bin/{client-T32CIZA3.js → client-36JX5MR3.js} +1 -1
  11. package/dist/bin/{collection-efficiency-T6PWNTZO.js → collection-efficiency-DA5RWG3V.js} +2 -2
  12. package/dist/bin/{config-V4QFCONN.js → config-4LLNT4SH.js} +3 -1
  13. package/dist/bin/{create-NUKHDWLK.js → create-C5INBPQO.js} +2 -2
  14. package/dist/bin/{default-account-JWFPHMRF.js → default-account-2GMQ7ZA4.js} +2 -2
  15. package/dist/bin/{expenses-2UWUZVLI.js → expenses-S2YVA5UT.js} +2 -2
  16. package/dist/bin/{export-XSX7WQH7.js → export-YOOODNVX.js} +2 -2
  17. package/dist/bin/export-ZA43MLWO.js +191 -0
  18. package/dist/bin/{factory-BWOKRIP4.js → factory-6MUCSXTL.js} +2 -2
  19. package/dist/bin/{get-CHNTG3IM.js → get-GMQRROK2.js} +2 -2
  20. package/dist/bin/{get-ZSZ6SL3N.js → get-ZV3SC2VY.js} +2 -2
  21. package/dist/bin/hisaabo.js +100 -57
  22. package/dist/bin/import-UUHMLCKX.js +267 -0
  23. package/dist/bin/{invitations-H2SL3XAD.js → invitations-OVORTTMF.js} +2 -2
  24. package/dist/bin/{invite-EW73UIBE.js → invite-GGHBZY4U.js} +2 -2
  25. package/dist/bin/{invoice-breakdown-XP4QATCF.js → invoice-breakdown-32XXAZDP.js} +2 -2
  26. package/dist/bin/{items-DPD6EFTP.js → items-6NOIMH6B.js} +2 -2
  27. package/dist/bin/{items-toggle-R4OPSE4W.js → items-toggle-L6W6QKQD.js} +2 -2
  28. package/dist/bin/{list-PKHBE475.js → list-FC5JHKHD.js} +2 -2
  29. package/dist/bin/{list-KLEHBMQ2.js → list-OXAVDXH7.js} +2 -2
  30. package/dist/bin/{list-UR7OOJVF.js → list-RAR56EMQ.js} +2 -2
  31. package/dist/bin/{members-XA3TF4IQ.js → members-Y6XJVHHR.js} +2 -2
  32. package/dist/bin/{monthly-comparison-OLVS5HEY.js → monthly-comparison-IAUZ6SBJ.js} +2 -2
  33. package/dist/bin/{order-cancel-MXMJFFRR.js → order-cancel-QRTCNART.js} +2 -2
  34. package/dist/bin/{order-confirm-IXU45Q4L.js → order-confirm-LGQOMC4O.js} +2 -2
  35. package/dist/bin/{order-get-RDXMHLJ7.js → order-get-4XAQCRYV.js} +2 -2
  36. package/dist/bin/{order-update-KGIPBEJX.js → order-update-KZY4H2UR.js} +2 -2
  37. package/dist/bin/output-NUOL7KJW.js +0 -0
  38. package/dist/bin/{payment-modes-CZL35SVS.js → payment-modes-DY2ZEMK7.js} +2 -2
  39. package/dist/bin/{profit-loss-M332OSC5.js → profit-loss-5GJBG3PL.js} +2 -2
  40. package/dist/bin/{receivables-aging-OXRHGMBF.js → receivables-aging-6A7XJKDT.js} +2 -2
  41. package/dist/bin/{remove-I5HD2Y4K.js → remove-ZBX34TIQ.js} +2 -2
  42. package/dist/bin/{revoke-OC6AOMIZ.js → revoke-XDNOA2GJ.js} +2 -2
  43. package/dist/bin/{revoke-MFLWGCMP.js → revoke-ZTAMW2Q2.js} +2 -2
  44. package/dist/bin/{revoke-all-FSAPBB3P.js → revoke-all-365NRBOA.js} +2 -2
  45. package/dist/bin/{revoke-invitation-JXDPXTOW.js → revoke-invitation-PQH7XNYA.js} +2 -2
  46. package/dist/bin/{sales-trend-KK63WNDL.js → sales-trend-D6PQ7MHY.js} +2 -2
  47. package/dist/bin/{sequence-IQ4HUJ3W.js → sequence-KZWADVD7.js} +2 -2
  48. package/dist/bin/{store-6QT6HKG2.js → store-SVRZBUFO.js} +2 -2
  49. package/dist/bin/{summary-3FTF5B4A.js → summary-H6U7O5GJ.js} +2 -2
  50. package/dist/bin/{top-customers-HNYGXBQZ.js → top-customers-ATBN6RDI.js} +2 -2
  51. package/dist/bin/{top-items-JUDG3BVW.js → top-items-XXU6KYTC.js} +2 -2
  52. package/dist/bin/{top-outstanding-WK26ZNE5.js → top-outstanding-JTQNGGW4.js} +2 -2
  53. package/dist/bin/{unpaid-invoices-RYFIIIK7.js → unpaid-invoices-BTNQFWCH.js} +2 -2
  54. package/dist/bin/{untracked-FAFS3KCK.js → untracked-PAMEDJ6Y.js} +2 -2
  55. package/dist/bin/{update-5YSPXIWO.js → update-6ZMX2OYX.js} +2 -2
  56. package/dist/bin/{update-I46XLU77.js → update-EGHPFXLK.js} +2 -2
  57. package/dist/bin/{update-NAW2JWZS.js → update-EK4NJWU4.js} +2 -2
  58. package/dist/bin/{update-role-5GV42MSN.js → update-role-24PDTNFK.js} +2 -2
  59. package/dist/bin/{update-settings-KYSQDIEO.js → update-settings-AASI6WZX.js} +2 -2
  60. package/package.json +35 -9
  61. package/.turbo/turbo-build.log +0 -13
  62. package/.turbo/turbo-typecheck.log +0 -4
  63. package/CLI-UX-ARCHITECTURE.md +0 -1269
  64. package/src/auth.ts +0 -221
  65. package/src/bin/hisaabo.ts +0 -74
  66. package/src/bin/registrars/api-key.ts +0 -44
  67. package/src/bin/registrars/auth.ts +0 -222
  68. package/src/bin/registrars/automated-invoice.ts +0 -167
  69. package/src/bin/registrars/bank-recon.ts +0 -34
  70. package/src/bin/registrars/bank.ts +0 -124
  71. package/src/bin/registrars/business.ts +0 -120
  72. package/src/bin/registrars/dashboard.ts +0 -225
  73. package/src/bin/registrars/document.ts +0 -184
  74. package/src/bin/registrars/einvoice.ts +0 -46
  75. package/src/bin/registrars/ewb.ts +0 -37
  76. package/src/bin/registrars/expense.ts +0 -87
  77. package/src/bin/registrars/gst.ts +0 -57
  78. package/src/bin/registrars/import.ts +0 -49
  79. package/src/bin/registrars/invoice.ts +0 -117
  80. package/src/bin/registrars/itc.ts +0 -56
  81. package/src/bin/registrars/item.ts +0 -112
  82. package/src/bin/registrars/journal.ts +0 -47
  83. package/src/bin/registrars/party.ts +0 -81
  84. package/src/bin/registrars/payment.ts +0 -128
  85. package/src/bin/registrars/report.ts +0 -186
  86. package/src/bin/registrars/session.ts +0 -32
  87. package/src/bin/registrars/shipment.ts +0 -74
  88. package/src/bin/registrars/store.ts +0 -128
  89. package/src/bin/registrars/target.ts +0 -46
  90. package/src/bin/registrars/tenant.ts +0 -73
  91. package/src/client.ts +0 -2071
  92. package/src/commands/api-key/create.ts +0 -72
  93. package/src/commands/api-key/list.ts +0 -71
  94. package/src/commands/api-key/revoke.ts +0 -46
  95. package/src/commands/automated-invoice/create.ts +0 -85
  96. package/src/commands/automated-invoice/delete.ts +0 -42
  97. package/src/commands/automated-invoice/get.ts +0 -113
  98. package/src/commands/automated-invoice/history.ts +0 -65
  99. package/src/commands/automated-invoice/index.ts +0 -11
  100. package/src/commands/automated-invoice/list.ts +0 -91
  101. package/src/commands/automated-invoice/pause.ts +0 -29
  102. package/src/commands/automated-invoice/resume.ts +0 -29
  103. package/src/commands/automated-invoice/run-now.ts +0 -29
  104. package/src/commands/automated-invoice/suggestions.ts +0 -68
  105. package/src/commands/automated-invoice/update.ts +0 -54
  106. package/src/commands/automated-invoice/usage.ts +0 -68
  107. package/src/commands/bank/gateway-config.ts +0 -61
  108. package/src/commands/bank/index.ts +0 -244
  109. package/src/commands/bank/update-gateway.ts +0 -84
  110. package/src/commands/bank-recon/index.ts +0 -127
  111. package/src/commands/business/audit-trail.ts +0 -79
  112. package/src/commands/business/export.ts +0 -52
  113. package/src/commands/business/get.ts +0 -55
  114. package/src/commands/business/sequence.ts +0 -65
  115. package/src/commands/business/update.ts +0 -64
  116. package/src/commands/dashboard/collection-efficiency.ts +0 -164
  117. package/src/commands/dashboard/expenses.ts +0 -76
  118. package/src/commands/dashboard/invoice-breakdown.ts +0 -89
  119. package/src/commands/dashboard/monthly-comparison.ts +0 -193
  120. package/src/commands/dashboard/payment-modes.ts +0 -121
  121. package/src/commands/dashboard/profit-loss.ts +0 -146
  122. package/src/commands/dashboard/receivables-aging.ts +0 -169
  123. package/src/commands/dashboard/sales-trend.ts +0 -68
  124. package/src/commands/dashboard/summary.ts +0 -105
  125. package/src/commands/dashboard/top-customers.ts +0 -70
  126. package/src/commands/dashboard/top-items.ts +0 -74
  127. package/src/commands/dashboard/top-outstanding.ts +0 -61
  128. package/src/commands/dashboard.ts +0 -105
  129. package/src/commands/document/factory.ts +0 -590
  130. package/src/commands/einvoice/index.ts +0 -109
  131. package/src/commands/ewb/index.ts +0 -108
  132. package/src/commands/expense/categories.ts +0 -40
  133. package/src/commands/expense/create.ts +0 -51
  134. package/src/commands/expense/delete.ts +0 -45
  135. package/src/commands/expense/list.ts +0 -65
  136. package/src/commands/expense/update.ts +0 -58
  137. package/src/commands/gst/index.ts +0 -194
  138. package/src/commands/import/index.ts +0 -168
  139. package/src/commands/invoice/create.ts +0 -262
  140. package/src/commands/invoice/delete.ts +0 -44
  141. package/src/commands/invoice/get.ts +0 -113
  142. package/src/commands/invoice/list.ts +0 -126
  143. package/src/commands/invoice/pdf.ts +0 -75
  144. package/src/commands/invoice/status.ts +0 -41
  145. package/src/commands/itc/index.ts +0 -163
  146. package/src/commands/item/categories.ts +0 -40
  147. package/src/commands/item/create.ts +0 -98
  148. package/src/commands/item/delete.ts +0 -44
  149. package/src/commands/item/list.ts +0 -81
  150. package/src/commands/item/low-stock-count.ts +0 -32
  151. package/src/commands/item/merge.ts +0 -53
  152. package/src/commands/item/price-history.ts +0 -59
  153. package/src/commands/item/rename-unit.ts +0 -39
  154. package/src/commands/item/sales-stats.ts +0 -44
  155. package/src/commands/item/stock-history.ts +0 -70
  156. package/src/commands/item/stock.ts +0 -46
  157. package/src/commands/item/switch-base-unit.ts +0 -42
  158. package/src/commands/item/update.ts +0 -59
  159. package/src/commands/item/variants-create.ts +0 -58
  160. package/src/commands/item/variants-delete.ts +0 -47
  161. package/src/commands/item/variants-list.ts +0 -63
  162. package/src/commands/item/variants-update.ts +0 -61
  163. package/src/commands/journal/index.ts +0 -156
  164. package/src/commands/party/create.ts +0 -88
  165. package/src/commands/party/delete.ts +0 -44
  166. package/src/commands/party/get.ts +0 -42
  167. package/src/commands/party/ledger-report.ts +0 -81
  168. package/src/commands/party/ledger.ts +0 -63
  169. package/src/commands/party/list.ts +0 -69
  170. package/src/commands/party/merge.ts +0 -50
  171. package/src/commands/party/stats.ts +0 -40
  172. package/src/commands/party/top-items.ts +0 -57
  173. package/src/commands/party/update.ts +0 -65
  174. package/src/commands/payment/create.ts +0 -131
  175. package/src/commands/payment/default-account.ts +0 -56
  176. package/src/commands/payment/delete.ts +0 -46
  177. package/src/commands/payment/get.ts +0 -59
  178. package/src/commands/payment/list.ts +0 -66
  179. package/src/commands/payment/unpaid-invoices.ts +0 -69
  180. package/src/commands/payment/untracked.ts +0 -70
  181. package/src/commands/payment/update.ts +0 -54
  182. package/src/commands/report/index.ts +0 -736
  183. package/src/commands/session/list.ts +0 -91
  184. package/src/commands/session/revoke-all.ts +0 -20
  185. package/src/commands/session/revoke.ts +0 -32
  186. package/src/commands/shipment/index.ts +0 -170
  187. package/src/commands/store/check-slug.ts +0 -48
  188. package/src/commands/store/index.ts +0 -77
  189. package/src/commands/store/items-toggle.ts +0 -41
  190. package/src/commands/store/items.ts +0 -61
  191. package/src/commands/store/order-cancel.ts +0 -48
  192. package/src/commands/store/order-confirm.ts +0 -45
  193. package/src/commands/store/order-get.ts +0 -66
  194. package/src/commands/store/order-update.ts +0 -52
  195. package/src/commands/store/update-settings.ts +0 -52
  196. package/src/commands/target/index.ts +0 -118
  197. package/src/commands/tenant/invitations.ts +0 -62
  198. package/src/commands/tenant/invite.ts +0 -57
  199. package/src/commands/tenant/list.ts +0 -46
  200. package/src/commands/tenant/members.ts +0 -55
  201. package/src/commands/tenant/remove.ts +0 -47
  202. package/src/commands/tenant/revoke-invitation.ts +0 -32
  203. package/src/commands/tenant/update-role.ts +0 -41
  204. package/src/config.ts +0 -120
  205. package/src/error-handler.ts +0 -53
  206. package/src/format.ts +0 -181
  207. package/src/output.ts +0 -228
  208. package/src/spinner.ts +0 -39
  209. package/tsconfig.json +0 -22
  210. package/tsup.config.ts +0 -18
@@ -1,127 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT } from "../../output.js";
4
- import { formatAmount, formatDate } from "../../format.js";
5
-
6
- function handleError(e: unknown): never {
7
- if (e instanceof HisaaboApiError) {
8
- const err = e.hisaaboError;
9
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
10
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
11
- }
12
- fatalError(String(e instanceof Error ? e.message : e));
13
- }
14
-
15
- export async function bankReconImportsCommand(opts: { json?: boolean }): Promise<void> {
16
- const cfg = requireAuth();
17
- const client = new HisaaboClient(cfg);
18
-
19
- try {
20
- const result = await client.bankRecon.importList();
21
-
22
- if (opts.json) {
23
- outputJSON(result);
24
- return;
25
- }
26
-
27
- const imports = Array.isArray(result) ? result
28
- : Array.isArray(result?.data) ? result.data
29
- : [];
30
-
31
- console.log("\n Bank Reconciliation Imports\n");
32
- console.log(` ${"═".repeat(65)}\n`);
33
-
34
- if (imports.length === 0) {
35
- console.log(" No imports found.\n");
36
- return;
37
- }
38
-
39
- for (const imp of imports as Array<Record<string, unknown>>) {
40
- const id = String(imp["id"] ?? "-").slice(0, 8);
41
- const date = formatDate(String(imp["createdAt"] ?? imp["importDate"] ?? ""));
42
- const account = String(imp["accountName"] ?? imp["bankAccount"] ?? "-").padEnd(20);
43
- const lines = String(imp["totalLines"] ?? imp["lineCount"] ?? "-").padStart(6);
44
- const matched = String(imp["matchedLines"] ?? imp["matched"] ?? "-").padStart(8);
45
- const status = String(imp["status"] ?? "-").padEnd(10);
46
- console.log(` ${id} ${date.padEnd(13)} ${account} Lines:${lines} Matched:${matched} ${status}`);
47
- }
48
- console.log();
49
-
50
- } catch (e) {
51
- handleError(e);
52
- }
53
- }
54
-
55
- export async function bankReconSummaryCommand(importId: string, opts: { json?: boolean }): Promise<void> {
56
- const cfg = requireAuth();
57
- const client = new HisaaboClient(cfg);
58
-
59
- try {
60
- const result = await client.bankRecon.summary(importId);
61
-
62
- if (opts.json) {
63
- outputJSON(result);
64
- return;
65
- }
66
-
67
- const r = result as Record<string, unknown>;
68
- console.log(`\n Bank Recon Summary — ${importId}\n`);
69
- console.log(` ${"═".repeat(55)}\n`);
70
-
71
- const total = String(r["totalLines"] ?? r["total"] ?? "0");
72
- const matched = String(r["matchedLines"] ?? r["matched"] ?? "0");
73
- const unmatched = String(r["unmatchedLines"] ?? r["unmatched"] ?? "0");
74
- const ignored = String(r["ignoredLines"] ?? r["ignored"] ?? "0");
75
- const openingBalance = String(r["openingBalance"] ?? "0");
76
- const closingBalance = String(r["closingBalance"] ?? "0");
77
-
78
- console.log(` Total Lines: ${total.padStart(8)}`);
79
- console.log(` Matched: ${matched.padStart(8)}`);
80
- console.log(` Unmatched: ${unmatched.padStart(8)}`);
81
- console.log(` Ignored: ${ignored.padStart(8)}`);
82
- console.log(` Opening Balance: ${formatAmount(openingBalance).padStart(14)}`);
83
- console.log(` Closing Balance: ${formatAmount(closingBalance).padStart(14)}`);
84
- console.log();
85
-
86
- } catch (e) {
87
- handleError(e);
88
- }
89
- }
90
-
91
- export async function bankReconRulesCommand(opts: { json?: boolean }): Promise<void> {
92
- const cfg = requireAuth();
93
- const client = new HisaaboClient(cfg);
94
-
95
- try {
96
- const result = await client.bankRecon.ruleList();
97
-
98
- if (opts.json) {
99
- outputJSON(result);
100
- return;
101
- }
102
-
103
- const rules = Array.isArray(result) ? result
104
- : Array.isArray(result?.data) ? result.data
105
- : [];
106
-
107
- console.log("\n Bank Recon Rules\n");
108
- console.log(` ${"═".repeat(60)}\n`);
109
-
110
- if (rules.length === 0) {
111
- console.log(" No rules configured.\n");
112
- return;
113
- }
114
-
115
- for (const rule of rules as Array<Record<string, unknown>>) {
116
- const id = String(rule["id"] ?? "-").slice(0, 8);
117
- const name = String(rule["name"] ?? "-").padEnd(25);
118
- const condition = String(rule["condition"] ?? rule["matchPattern"] ?? "-").padEnd(20);
119
- const action = String(rule["action"] ?? "-").padEnd(12);
120
- console.log(` ${id} ${name} ${condition} ${action}`);
121
- }
122
- console.log();
123
-
124
- } catch (e) {
125
- handleError(e);
126
- }
127
- }
@@ -1,79 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor, paginationFooter } from "../../output.js";
4
- import { formatDate } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface AuditTrailOpts {
8
- page?: string;
9
- limit?: string;
10
- json?: boolean;
11
- format?: string;
12
- }
13
-
14
- export async function businessAuditTrailCommand(opts: AuditTrailOpts): Promise<void> {
15
- const cfg = requireAuth();
16
- const client = new HisaaboClient(cfg);
17
-
18
- const page = opts.page ? parseInt(opts.page, 10) : 1;
19
- const limit = opts.limit ? parseInt(opts.limit, 10) : 25;
20
-
21
- if (isNaN(page) || page < 1) fatalError("--page must be a positive integer.", EXIT.USAGE);
22
- if (isNaN(limit) || limit < 1 || limit > 100) fatalError("--limit must be between 1 and 100.", EXIT.USAGE);
23
-
24
- try {
25
- const data = await client.business.auditTrail({ page, limit });
26
-
27
- if (opts.json) {
28
- outputJSON(data);
29
- return;
30
- }
31
-
32
- const items: unknown[] = Array.isArray(data)
33
- ? data
34
- : Array.isArray(data?.items)
35
- ? data.items
36
- : Array.isArray(data?.data)
37
- ? data.data
38
- : [];
39
-
40
- const total: number = typeof data?.total === "number" ? data.total : items.length;
41
-
42
- const rows = items.map((item: unknown) => {
43
- const r = item as Record<string, unknown>;
44
- return {
45
- timestamp: formatDate(String(r["createdAt"] ?? r["timestamp"] ?? "")),
46
- user: String(r["userName"] ?? r["user"] ?? r["userEmail"] ?? "-"),
47
- action: String(r["action"] ?? r["event"] ?? "-"),
48
- details: String(r["details"] ?? r["description"] ?? r["meta"] ?? "-"),
49
- };
50
- });
51
-
52
- const columns = [
53
- { key: "timestamp", header: "Date", align: "left" as const },
54
- { key: "user", header: "User", align: "left" as const, width: 28 },
55
- { key: "action", header: "Action", align: "left" as const, width: 24 },
56
- { key: "details", header: "Details", align: "left" as const, width: 40 },
57
- ];
58
-
59
- if (opts.format === "tsv") {
60
- outputTSV(rows, columns);
61
- } else if (opts.format === "csv") {
62
- outputCSV(rows, columns);
63
- } else {
64
- if (hasColor()) process.stdout.write("\n" + chalk.bold(" Audit Trail\n") + "\n");
65
- else process.stdout.write("\n Audit Trail\n\n");
66
- outputTable(rows, columns);
67
- if (total > limit) paginationFooter(page, limit, total);
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 === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
75
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
76
- }
77
- fatalError(String(e instanceof Error ? e.message : e));
78
- }
79
- }
@@ -1,52 +0,0 @@
1
- import * as readline from "readline";
2
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
3
- import { requireAuth } from "../../config.js";
4
- import { fatalError, success, outputJSON, EXIT } from "../../output.js";
5
-
6
- interface BusinessExportOpts {
7
- yes?: boolean;
8
- json?: boolean;
9
- }
10
-
11
- export async function businessExportCommand(opts: BusinessExportOpts): Promise<void> {
12
- const cfg = requireAuth();
13
- const client = new HisaaboClient(cfg);
14
-
15
- if (!opts.yes && process.stdin.isTTY) {
16
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
17
- const answer = await new Promise<string>((resolve) => {
18
- rl.question(" Export all business data? This may take a moment. (y/N): ", resolve);
19
- });
20
- rl.close();
21
- if (answer.trim().toLowerCase() !== "y") {
22
- console.log(" Cancelled.");
23
- process.exit(0);
24
- }
25
- }
26
-
27
- try {
28
- const result = await client.business.exportData();
29
-
30
- if (opts.json) {
31
- outputJSON(result);
32
- return;
33
- }
34
-
35
- if (result?.url) {
36
- success("Export complete.");
37
- process.stdout.write(` Download URL: ${result.url}\n`);
38
- } else if (result?.status === "processing" || result?.queued) {
39
- success("Export queued. You will be notified when the export is ready.");
40
- } else {
41
- success("Export initiated successfully.");
42
- }
43
- } catch (e) {
44
- if (e instanceof HisaaboApiError) {
45
- const err = e.hisaaboError;
46
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
47
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
48
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
49
- }
50
- fatalError(String(e instanceof Error ? e.message : e));
51
- }
52
- }
@@ -1,55 +0,0 @@
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 businessGetCommand(opts: { json?: boolean }): Promise<void> {
7
- const cfg = requireAuth();
8
- const client = new HisaaboClient(cfg);
9
-
10
- try {
11
- const biz = await client.business.get();
12
-
13
- if (opts.json) {
14
- outputJSON(biz);
15
- return;
16
- }
17
-
18
- const sep = "─".repeat(52);
19
- const line = (label: string, value: string | null | undefined) => {
20
- if (!value) return;
21
- const lbl = hasColor() ? chalk.dim(label.padEnd(24)) : label.padEnd(24);
22
- process.stdout.write(` ${lbl}${value}\n`);
23
- };
24
-
25
- process.stdout.write("\n");
26
- if (hasColor()) {
27
- process.stdout.write(" " + chalk.bold(biz.name ?? "") + "\n");
28
- process.stdout.write(" " + chalk.dim(sep) + "\n");
29
- } else {
30
- process.stdout.write(` ${biz.name ?? ""}\n`);
31
- process.stdout.write(" " + sep + "\n");
32
- }
33
-
34
- line("GSTIN", biz.gstin);
35
- line("GST Type", biz.gstRegistrationType);
36
- line("Phone", biz.phone);
37
- line("Email", biz.email);
38
- line("Address", biz.address);
39
- line("City", biz.city);
40
- line("State", biz.state);
41
- line("Pincode", biz.pincode);
42
- line("Financial Year Start", biz.financialYearStart ? `Month ${biz.financialYearStart}` : undefined);
43
- line("Currency", biz.currency);
44
- line("ID", biz.id);
45
-
46
- process.stdout.write("\n");
47
- } catch (e) {
48
- if (e instanceof HisaaboApiError) {
49
- const err = e.hisaaboError;
50
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
51
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
52
- }
53
- fatalError(String(e instanceof Error ? e.message : e));
54
- }
55
- }
@@ -1,65 +0,0 @@
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 BusinessSequenceOpts {
6
- type?: string;
7
- prefix?: string;
8
- nextNumber?: string;
9
- json?: boolean;
10
- }
11
-
12
- export async function businessSequenceCommand(opts: BusinessSequenceOpts): Promise<void> {
13
- const cfg = requireAuth();
14
- const client = new HisaaboClient(cfg);
15
-
16
- if (!opts.type) {
17
- fatalError("--type is required (sale or purchase).", EXIT.USAGE);
18
- }
19
- if (opts.type !== "sale" && opts.type !== "purchase") {
20
- fatalError("--type must be 'sale' or 'purchase'.", EXIT.USAGE);
21
- }
22
-
23
- const payload: Record<string, unknown> = { type: opts.type };
24
- if (opts.prefix !== undefined) payload["prefix"] = opts.prefix;
25
- if (opts.nextNumber !== undefined) {
26
- const n = parseInt(opts.nextNumber, 10);
27
- if (isNaN(n) || n < 1) {
28
- fatalError("--next-number must be a positive integer.", EXIT.USAGE);
29
- }
30
- payload["nextNumber"] = n;
31
- }
32
-
33
- if (Object.keys(payload).length === 1) {
34
- fatalError("Pass at least one of --prefix or --next-number.", EXIT.USAGE);
35
- }
36
-
37
- try {
38
- const result = await client.business.updateSequenceNumber(payload);
39
-
40
- if (opts.json) {
41
- outputJSON(result);
42
- return;
43
- }
44
-
45
- const typeLabel = opts.type === "sale" ? "Sales" : "Purchase";
46
- const parts: string[] = [];
47
- if (opts.prefix !== undefined) parts.push(`prefix → "${opts.prefix}"`);
48
- if (opts.nextNumber !== undefined) parts.push(`next number → ${opts.nextNumber}`);
49
- success(`${typeLabel} invoice sequence updated: ${parts.join(", ")}.`);
50
- } catch (e) {
51
- if (e instanceof HisaaboApiError) {
52
- const err = e.hisaaboError;
53
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
54
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
55
- if (err.code === "validation_failed") {
56
- const msgs = Object.entries(err.fields)
57
- .map(([f, ms]) => ` ${f}: ${ms.join(", ")}`)
58
- .join("\n");
59
- fatalError(`Validation failed:\n${msgs}`, EXIT.VALIDATION);
60
- }
61
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
62
- }
63
- fatalError(String(e instanceof Error ? e.message : e));
64
- }
65
- }
@@ -1,64 +0,0 @@
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 BusinessUpdateOpts {
6
- name?: string;
7
- gstin?: string;
8
- address?: string;
9
- state?: string;
10
- phone?: string;
11
- email?: string;
12
- financialYearStart?: string;
13
- json?: boolean;
14
- }
15
-
16
- export async function businessUpdateCommand(opts: BusinessUpdateOpts): Promise<void> {
17
- const cfg = requireAuth();
18
- const client = new HisaaboClient(cfg);
19
-
20
- // Build update payload — only include provided fields
21
- const payload: Record<string, unknown> = {};
22
- if (opts.name !== undefined) payload["name"] = opts.name;
23
- if (opts.gstin !== undefined) payload["gstin"] = opts.gstin;
24
- if (opts.address !== undefined) payload["address"] = opts.address;
25
- if (opts.state !== undefined) payload["state"] = opts.state;
26
- if (opts.phone !== undefined) payload["phone"] = opts.phone;
27
- if (opts.email !== undefined) payload["email"] = opts.email;
28
- if (opts.financialYearStart !== undefined) {
29
- const month = parseInt(opts.financialYearStart, 10);
30
- if (isNaN(month) || month < 1 || month > 12) {
31
- fatalError("--financial-year-start must be a month number (1–12).", EXIT.USAGE);
32
- }
33
- payload["financialYearStart"] = month;
34
- }
35
-
36
- if (Object.keys(payload).length === 0) {
37
- fatalError("No fields to update. Pass at least one option (--name, --gstin, etc.).", EXIT.USAGE);
38
- }
39
-
40
- try {
41
- const result = await client.business.update(payload);
42
-
43
- if (opts.json) {
44
- outputJSON(result);
45
- return;
46
- }
47
-
48
- success("Business settings updated.");
49
- } catch (e) {
50
- if (e instanceof HisaaboApiError) {
51
- const err = e.hisaaboError;
52
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
53
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
54
- if (err.code === "validation_failed") {
55
- const msgs = Object.entries(err.fields)
56
- .map(([f, ms]) => ` ${f}: ${ms.join(", ")}`)
57
- .join("\n");
58
- fatalError(`Validation failed:\n${msgs}`, EXIT.VALIDATION);
59
- }
60
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
61
- }
62
- fatalError(String(e instanceof Error ? e.message : e));
63
- }
64
- }
@@ -1,164 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor, termWidth } from "../../output.js";
4
- import { formatAmount, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface CollectionEfficiencyOpts {
8
- from?: string;
9
- to?: string;
10
- thisMonth?: boolean;
11
- thisFy?: boolean;
12
- json?: boolean;
13
- format?: string;
14
- }
15
-
16
- function rateBar(rate: number, width: number): string {
17
- const clamped = Math.min(100, Math.max(0, rate));
18
- const filled = Math.round((clamped / 100) * width);
19
- const bar = "█".repeat(filled) + "░".repeat(width - filled);
20
- if (!hasColor()) return bar;
21
- if (clamped >= 80) return chalk.green(bar);
22
- if (clamped >= 50) return chalk.yellow(bar);
23
- return chalk.red(bar);
24
- }
25
-
26
- export async function dashboardCollectionEfficiencyCommand(opts: CollectionEfficiencyOpts): Promise<void> {
27
- const cfg = requireAuth();
28
- const client = new HisaaboClient(cfg);
29
-
30
- let fromDate = opts.from;
31
- let toDate = opts.to;
32
- if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
33
- else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
34
-
35
- try {
36
- const data = await client.dashboard.collectionEfficiency({ fromDate, toDate });
37
-
38
- if (opts.json) {
39
- outputJSON(data);
40
- return;
41
- }
42
-
43
- const d = (data ?? {}) as Record<string, unknown>;
44
-
45
- // Top-level metrics
46
- const totalInvoiced = parseFloat(String(d["totalInvoiced"] ?? d["invoiced"] ?? d["billed"] ?? "0"));
47
- const totalCollected = parseFloat(String(d["totalCollected"] ?? d["collected"] ?? d["received"] ?? "0"));
48
- const outstanding = parseFloat(String(d["outstanding"] ?? d["totalOutstanding"] ?? String(totalInvoiced - totalCollected)));
49
- const collectionRate = parseFloat(String(d["collectionRate"] ?? d["rate"] ?? (totalInvoiced > 0 ? ((totalCollected / totalInvoiced) * 100).toFixed(2) : "0")));
50
- const dso = parseFloat(String(d["dso"] ?? d["daysSalesOutstanding"] ?? "0"));
51
-
52
- // Aging breakdown sub-object
53
- const aging = (d["aging"] ?? d["agingBreakdown"] ?? d["breakdown"] ?? null) as Record<string, unknown> | null;
54
-
55
- if (opts.format === "tsv" || opts.format === "csv") {
56
- const rows: Array<Record<string, string>> = [
57
- { metric: "Total Invoiced", value: formatAmount(totalInvoiced) },
58
- { metric: "Total Collected", value: formatAmount(totalCollected) },
59
- { metric: "Outstanding", value: formatAmount(outstanding) },
60
- { metric: "Collection Rate", value: `${collectionRate.toFixed(1)}%` },
61
- { metric: "DSO (days)", value: dso > 0 ? String(Math.round(dso)) : "-" },
62
- ];
63
- if (aging) {
64
- for (const [k, v] of Object.entries(aging)) {
65
- rows.push({ metric: `Aging: ${k}`, value: formatAmount(String(v)) });
66
- }
67
- }
68
- const columns = [
69
- { key: "metric", header: "Metric", align: "left" as const },
70
- { key: "value", header: "Value", align: "right" as const },
71
- ];
72
- if (opts.format === "tsv") outputTSV(rows, columns);
73
- else outputCSV(rows, columns);
74
- return;
75
- }
76
-
77
- // Pretty display
78
- const width = Math.min(termWidth() - 4, 56);
79
- const innerW = width - 2;
80
- const barW = Math.max(8, innerW - 22);
81
-
82
- const line = (label: string, value: string, opts2: { bold?: boolean; color?: (s: string) => string } = {}): void => {
83
- const lbl = label.padEnd(20).slice(0, 20);
84
- const val = value.padStart(innerW - 22).slice(0, innerW - 22);
85
- let out = ` │ ${lbl} ${val} │`;
86
- if (hasColor()) {
87
- if (opts2.bold) out = ` │ ${chalk.bold(lbl)} ${val} │`;
88
- if (opts2.color) out = ` │ ${opts2.bold ? chalk.bold(lbl) : lbl} ${opts2.color(val)} │`;
89
- }
90
- process.stdout.write(out + "\n");
91
- };
92
-
93
- const sep = (): void => { process.stdout.write(" ├" + "─".repeat(innerW) + "┤\n"); };
94
-
95
- process.stdout.write("\n");
96
- if (hasColor()) process.stdout.write(" " + chalk.bold("Collection Efficiency") + "\n\n");
97
- else process.stdout.write(" Collection Efficiency\n\n");
98
-
99
- process.stdout.write(" ┌" + "─".repeat(innerW) + "┐\n");
100
-
101
- line("Total Invoiced", `₹${formatAmount(totalInvoiced)}`, { bold: true });
102
- line("Total Collected", `₹${formatAmount(totalCollected)}`, {
103
- color: totalCollected >= totalInvoiced * 0.8 ? chalk.green : chalk.yellow,
104
- });
105
- line("Outstanding", `₹${formatAmount(outstanding)}`, {
106
- color: outstanding > 0 ? chalk.red : chalk.green,
107
- });
108
- sep();
109
-
110
- // Collection rate with bar
111
- const rateStr = `${collectionRate.toFixed(1)}%`;
112
- const bar = rateBar(collectionRate, barW);
113
- const rateLabel = "Collection Rate".padEnd(20).slice(0, 20);
114
- process.stdout.write(` │ ${hasColor() ? chalk.bold(rateLabel) : rateLabel} ${bar} ${rateStr.padStart(6)} │\n`);
115
-
116
- if (dso > 0) {
117
- const dsoStr = `${Math.round(dso)} days`;
118
- const dsoLabel = "DSO".padEnd(20).slice(0, 20);
119
- const dsoColor = dso <= 30 ? chalk.green : dso <= 60 ? chalk.yellow : chalk.red;
120
- const dsoVal = hasColor() ? dsoColor(dsoStr) : dsoStr;
121
- process.stdout.write(` │ ${dsoLabel} ${dsoVal.padStart(innerW - 22)} │\n`);
122
- }
123
-
124
- // Aging buckets if available
125
- if (aging && Object.keys(aging).length > 0) {
126
- sep();
127
- process.stdout.write(` │ ${hasColor() ? chalk.bold("Aging Breakdown") : "Aging Breakdown"}${" ".repeat(innerW - 16)} │\n`);
128
- const agingEntries = Object.entries(aging);
129
- for (const [bucket, val] of agingEntries) {
130
- const amt = parseFloat(String(val));
131
- const amtStr = `₹${formatAmount(amt)}`;
132
- const bucketLabel = bucket.padEnd(20).slice(0, 20);
133
- const isOld = /90\+|90_plus/i.test(bucket);
134
- const color = isOld ? chalk.red : /31|61/.test(bucket) ? chalk.yellow : undefined;
135
- const valStr = color && hasColor() ? color(amtStr) : amtStr;
136
- process.stdout.write(` │ ${bucketLabel.slice(0, 18)} ${valStr.padStart(innerW - 22)} │\n`);
137
- }
138
- }
139
-
140
- process.stdout.write(" └" + "─".repeat(innerW) + "┘\n\n");
141
-
142
- // Also show aging as a table for easy reading
143
- if (aging && Object.keys(aging).length > 0) {
144
- const agingRows = Object.entries(aging).map(([bucket, val]) => ({
145
- bucket,
146
- amount: formatAmount(String(val)),
147
- }));
148
- const agingColumns = [
149
- { key: "bucket", header: "Aging Bucket", align: "left" as const },
150
- { key: "amount", header: "Amount ₹", align: "right" as const },
151
- ];
152
- outputTable(agingRows, agingColumns);
153
- process.stdout.write("\n");
154
- }
155
-
156
- } catch (e) {
157
- if (e instanceof HisaaboApiError) {
158
- const err = e.hisaaboError;
159
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
160
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
161
- }
162
- fatalError(String(e instanceof Error ? e.message : e));
163
- }
164
- }
@@ -1,76 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor } from "../../output.js";
4
- import { formatAmount, fyStart, todayISO, monthStart, monthEnd } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface ExpensesOpts {
8
- from?: string;
9
- to?: string;
10
- thisMonth?: boolean;
11
- thisFy?: boolean;
12
- json?: boolean;
13
- format?: string;
14
- }
15
-
16
- export async function dashboardExpensesCommand(opts: ExpensesOpts): Promise<void> {
17
- const cfg = requireAuth();
18
- const client = new HisaaboClient(cfg);
19
-
20
- let fromDate = opts.from;
21
- let toDate = opts.to;
22
- if (opts.thisMonth) { fromDate = monthStart(); toDate = monthEnd(); }
23
- else if (opts.thisFy) { fromDate = fyStart(); toDate = todayISO(); }
24
-
25
- try {
26
- const data = await client.dashboard.expensesByCategory({ fromDate, toDate });
27
-
28
- if (opts.json) {
29
- outputJSON(data);
30
- return;
31
- }
32
-
33
- const items: Array<Record<string, unknown>> = Array.isArray(data) ? data : [];
34
- const total = items.reduce((sum, r) => sum + parseFloat(String(r["totalAmount"] ?? r["amount"] ?? "0")), 0);
35
-
36
- const rows = items.map((r: Record<string, unknown>) => {
37
- const amt = parseFloat(String(r["totalAmount"] ?? r["amount"] ?? "0"));
38
- const pct = total > 0 ? ((amt / total) * 100).toFixed(1) + "%" : "-";
39
- return {
40
- category: String(r["category"] ?? "-"),
41
- amount: formatAmount(String(amt)),
42
- count: String(r["count"] ?? r["expenseCount"] ?? "-"),
43
- pct,
44
- };
45
- });
46
-
47
- const columns = [
48
- { key: "category", header: "Category", align: "left" as const },
49
- { key: "amount", header: "Amount ₹", align: "right" as const },
50
- { key: "count", header: "Count", align: "right" as const },
51
- { key: "pct", header: "% of Total", align: "right" as const },
52
- ];
53
-
54
- if (opts.format === "tsv") {
55
- outputTSV(rows, columns);
56
- } else if (opts.format === "csv") {
57
- outputCSV(rows, columns);
58
- } else {
59
- if (hasColor()) process.stdout.write("\n" + chalk.bold(" Expenses by Category\n") + "\n");
60
- else process.stdout.write("\n Expenses by Category\n\n");
61
- outputTable(rows, columns);
62
- if (total > 0) {
63
- const totalStr = ` Total: ₹${formatAmount(String(total))}`;
64
- process.stdout.write("\n" + (hasColor() ? chalk.bold(totalStr) : totalStr) + "\n");
65
- }
66
- process.stdout.write("\n");
67
- }
68
- } catch (e) {
69
- if (e instanceof HisaaboApiError) {
70
- const err = e.hisaaboError;
71
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
72
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
73
- }
74
- fatalError(String(e instanceof Error ? e.message : e));
75
- }
76
- }