@hisaabo/cli 0.6.1 → 0.8.4

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-4AMEFQGB.js → audit-trail-IJ6SKACR.js} +3 -3
  4. package/dist/bin/{categories-CLCBRNWC.js → categories-O6TODPAH.js} +2 -2
  5. package/dist/bin/{check-slug-OKW7KDYG.js → check-slug-P7RFU6OP.js} +2 -2
  6. package/dist/bin/chunk-NO4FIFMS.js +0 -0
  7. package/dist/bin/{chunk-FIMJZAS4.js → chunk-QUITS2FE.js} +46 -1
  8. package/dist/bin/{chunk-GXRLFDZW.js → chunk-WDN7RIE3.js} +32 -2
  9. package/dist/bin/{chunk-T63VQXNM.js → chunk-ZPYC767N.js} +1 -0
  10. package/dist/bin/{client-2ZKMLWI6.js → client-36JX5MR3.js} +1 -1
  11. package/dist/bin/{collection-efficiency-TECE6PVQ.js → collection-efficiency-DA5RWG3V.js} +3 -3
  12. package/dist/bin/{config-335MN4I7.js → config-4LLNT4SH.js} +5 -1
  13. package/dist/bin/{create-AS2YVGRA.js → create-C5INBPQO.js} +2 -2
  14. package/dist/bin/{default-account-3RVSU7RF.js → default-account-2GMQ7ZA4.js} +2 -2
  15. package/dist/bin/{expenses-KXFQJKD6.js → expenses-S2YVA5UT.js} +3 -3
  16. package/dist/bin/{export-UHZISG7H.js → export-YOOODNVX.js} +2 -2
  17. package/dist/bin/export-ZA43MLWO.js +191 -0
  18. package/dist/bin/{factory-OBESY2LG.js → factory-6MUCSXTL.js} +3 -3
  19. package/dist/bin/{get-WUSYEMG4.js → get-GMQRROK2.js} +2 -2
  20. package/dist/bin/{get-GTL556HL.js → get-ZV3SC2VY.js} +3 -3
  21. package/dist/bin/hisaabo.js +107 -59
  22. package/dist/bin/import-UUHMLCKX.js +267 -0
  23. package/dist/bin/{invitations-U4ZNYWY7.js → invitations-OVORTTMF.js} +2 -2
  24. package/dist/bin/{invite-5S4GJKRF.js → invite-GGHBZY4U.js} +2 -2
  25. package/dist/bin/{invoice-breakdown-PP3BZQLG.js → invoice-breakdown-32XXAZDP.js} +3 -3
  26. package/dist/bin/{items-CHEFLI7C.js → items-6NOIMH6B.js} +3 -3
  27. package/dist/bin/{items-toggle-ETVCDCU6.js → items-toggle-L6W6QKQD.js} +2 -2
  28. package/dist/bin/{list-3FO4UJKC.js → list-FC5JHKHD.js} +3 -3
  29. package/dist/bin/{list-RJ34MFPR.js → list-OXAVDXH7.js} +2 -2
  30. package/dist/bin/{list-LQJGTZB4.js → list-RAR56EMQ.js} +2 -2
  31. package/dist/bin/{members-TE5K5NQC.js → members-Y6XJVHHR.js} +3 -3
  32. package/dist/bin/{monthly-comparison-Q6KPMTPS.js → monthly-comparison-IAUZ6SBJ.js} +3 -3
  33. package/dist/bin/{order-cancel-NOQDBL2N.js → order-cancel-QRTCNART.js} +2 -2
  34. package/dist/bin/{order-confirm-6WMKTGPV.js → order-confirm-LGQOMC4O.js} +2 -2
  35. package/dist/bin/{order-get-ONWR4GTW.js → order-get-4XAQCRYV.js} +3 -3
  36. package/dist/bin/{order-update-IVO4AFGV.js → order-update-KZY4H2UR.js} +3 -3
  37. package/dist/bin/output-NUOL7KJW.js +0 -0
  38. package/dist/bin/{payment-modes-FXB2G6WP.js → payment-modes-DY2ZEMK7.js} +3 -3
  39. package/dist/bin/{profit-loss-XPYELDTH.js → profit-loss-5GJBG3PL.js} +3 -3
  40. package/dist/bin/{receivables-aging-MU6Q3DZ4.js → receivables-aging-6A7XJKDT.js} +3 -3
  41. package/dist/bin/{remove-DJBOOOR4.js → remove-ZBX34TIQ.js} +2 -2
  42. package/dist/bin/{revoke-WRIK7HLY.js → revoke-XDNOA2GJ.js} +2 -2
  43. package/dist/bin/{revoke-5L5GZ4ZZ.js → revoke-ZTAMW2Q2.js} +2 -2
  44. package/dist/bin/{revoke-all-QARW2G6R.js → revoke-all-365NRBOA.js} +2 -2
  45. package/dist/bin/{revoke-invitation-ZGLJHYNB.js → revoke-invitation-PQH7XNYA.js} +2 -2
  46. package/dist/bin/{sales-trend-P5HOZJSX.js → sales-trend-D6PQ7MHY.js} +3 -3
  47. package/dist/bin/{sequence-LK6QLSI5.js → sequence-KZWADVD7.js} +2 -2
  48. package/dist/bin/{store-FU7CEILC.js → store-SVRZBUFO.js} +3 -3
  49. package/dist/bin/{summary-XONLN72I.js → summary-H6U7O5GJ.js} +3 -3
  50. package/dist/bin/{top-customers-U6HQW2GH.js → top-customers-ATBN6RDI.js} +3 -3
  51. package/dist/bin/{top-items-EAOIVZ4P.js → top-items-XXU6KYTC.js} +3 -3
  52. package/dist/bin/{top-outstanding-4546FJDH.js → top-outstanding-JTQNGGW4.js} +3 -3
  53. package/dist/bin/{unpaid-invoices-AED55PLC.js → unpaid-invoices-BTNQFWCH.js} +3 -3
  54. package/dist/bin/{untracked-ZEM2CDHC.js → untracked-PAMEDJ6Y.js} +3 -3
  55. package/dist/bin/{update-FO7AAXF5.js → update-6ZMX2OYX.js} +3 -3
  56. package/dist/bin/{update-OZPBIBME.js → update-EGHPFXLK.js} +2 -2
  57. package/dist/bin/{update-QCK32XAG.js → update-EK4NJWU4.js} +3 -3
  58. package/dist/bin/{update-role-RB35QIA5.js → update-role-24PDTNFK.js} +2 -2
  59. package/dist/bin/{update-settings-EUC2FJQJ.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 -2051
  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 -105
  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 -96
  205. package/src/error-handler.ts +0 -53
  206. package/src/format.ts +0 -180
  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,32 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT } from "../../output.js";
4
-
5
- interface LowStockCountOpts {
6
- json?: boolean;
7
- }
8
-
9
- export async function itemLowStockCountCommand(opts: LowStockCountOpts): Promise<void> {
10
- const cfg = requireAuth();
11
- const client = new HisaaboClient(cfg);
12
-
13
- try {
14
- const result = await client.item.lowStockCount();
15
-
16
- if (opts.json) {
17
- outputJSON(result);
18
- return;
19
- }
20
-
21
- const count = typeof result === "number" ? result : (result?.count ?? 0);
22
- process.stdout.write(`\n ${count} item${count === 1 ? "" : "s"} below low-stock threshold\n\n`);
23
-
24
- } catch (e) {
25
- if (e instanceof HisaaboApiError) {
26
- const err = e.hisaaboError;
27
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
28
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
29
- }
30
- fatalError(String(e instanceof Error ? e.message : e));
31
- }
32
- }
@@ -1,53 +0,0 @@
1
- import * as readline from "readline";
2
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
3
- import { requireAuth } from "../../config.js";
4
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
5
-
6
- interface MergeOpts {
7
- conversionFactor?: string;
8
- yes?: boolean;
9
- json?: boolean;
10
- }
11
-
12
- export async function itemMergeCommand(sourceId: string, targetId: string, opts: MergeOpts): Promise<void> {
13
- const cfg = requireAuth();
14
- const client = new HisaaboClient(cfg);
15
-
16
- if (!opts.yes && process.stdin.isTTY) {
17
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
18
- const answer = await new Promise<string>((resolve) => {
19
- rl.question(
20
- ` Merge ${sourceId} into ${targetId}? Invoice history will be moved. (y/n): `,
21
- resolve,
22
- );
23
- });
24
- rl.close();
25
- if (answer.trim().toLowerCase() !== "y") {
26
- console.log(" Cancelled.");
27
- process.exit(0);
28
- }
29
- }
30
-
31
- const conversionFactor = opts.conversionFactor ? parseFloat(opts.conversionFactor) : undefined;
32
-
33
- try {
34
- const result = await client.item.merge({ sourceId, targetId, conversionFactor });
35
-
36
- if (opts.json) {
37
- outputJSON(result);
38
- return;
39
- }
40
-
41
- success(`Merged ${sourceId} into ${targetId}`);
42
-
43
- } catch (e) {
44
- if (e instanceof HisaaboApiError) {
45
- const err = e.hisaaboError;
46
- if (err.code === "not_found") fatalError(`Item not found`, EXIT.NOT_FOUND);
47
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
48
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
49
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
50
- }
51
- fatalError(String(e instanceof Error ? e.message : e));
52
- }
53
- }
@@ -1,59 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- fatalError, outputJSON, outputTable, outputTSV, outputCSV,
5
- EXIT, type ColumnDef,
6
- } from "../../output.js";
7
- import { formatAmount, formatDate } from "../../format.js";
8
-
9
- interface PriceHistoryOpts {
10
- json?: boolean;
11
- format?: string;
12
- }
13
-
14
- interface PriceHistoryRow {
15
- date: string;
16
- salePrice: string;
17
- purchasePrice: string;
18
- changedBy: string;
19
- }
20
-
21
- export async function itemPriceHistoryCommand(id: string, opts: PriceHistoryOpts): Promise<void> {
22
- const cfg = requireAuth();
23
- const client = new HisaaboClient(cfg);
24
-
25
- try {
26
- const result = await client.item.priceHistory({ itemId: id });
27
-
28
- if (opts.json) {
29
- outputJSON(result);
30
- return;
31
- }
32
-
33
- const entries: PriceHistoryRow[] = Array.isArray(result?.history) ? result.history : (Array.isArray(result) ? result : []);
34
-
35
- console.log(`\n Price History: ${result?.itemName ?? id}\n`);
36
-
37
- const cols: ColumnDef<PriceHistoryRow>[] = [
38
- { key: "date", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
39
- { key: "salePrice", header: "Sale Price (₹)", align: "right", width: 16, format: (v) => v ? formatAmount(String(v)) : "-" },
40
- { key: "purchasePrice", header: "Purchase (₹)", align: "right", width: 14, format: (v) => v ? formatAmount(String(v)) : "-" },
41
- { key: "changedBy", header: "Changed By", width: 18 },
42
- ];
43
-
44
- if (opts.format === "tsv") outputTSV(entries, cols);
45
- else if (opts.format === "csv") outputCSV(entries, cols);
46
- else outputTable(entries, cols);
47
-
48
- console.log();
49
-
50
- } catch (e) {
51
- if (e instanceof HisaaboApiError) {
52
- const err = e.hisaaboError;
53
- if (err.code === "not_found") fatalError(`Item not found: ${id}`, EXIT.NOT_FOUND);
54
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
55
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
56
- }
57
- fatalError(String(e instanceof Error ? e.message : e));
58
- }
59
- }
@@ -1,39 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- interface RenameUnitOpts {
6
- old?: string;
7
- new?: string;
8
- json?: boolean;
9
- }
10
-
11
- export async function itemRenameUnitCommand(id: string, opts: RenameUnitOpts): Promise<void> {
12
- const cfg = requireAuth();
13
- const client = new HisaaboClient(cfg);
14
-
15
- if (!opts.old) fatalError("--old is required", EXIT.USAGE);
16
- if (!opts.new) fatalError("--new is required", EXIT.USAGE);
17
-
18
- try {
19
- const result = await client.item.renameUnit({ itemId: id, oldUnit: opts.old, newUnit: opts.new });
20
-
21
- if (opts.json) {
22
- outputJSON(result);
23
- return;
24
- }
25
-
26
- success(`Renamed unit '${opts.old}' to '${opts.new}' for item ${id}`);
27
- console.log();
28
-
29
- } catch (e) {
30
- if (e instanceof HisaaboApiError) {
31
- const err = e.hisaaboError;
32
- if (err.code === "not_found") fatalError(`Item not found: ${id}`, EXIT.NOT_FOUND);
33
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
34
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
35
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
36
- }
37
- fatalError(String(e instanceof Error ? e.message : e));
38
- }
39
- }
@@ -1,44 +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 { formatINR, formatAmount } from "../../format.js";
5
-
6
- interface SalesStatsOpts {
7
- json?: boolean;
8
- }
9
-
10
- export async function itemSalesStatsCommand(id: string, opts: SalesStatsOpts): Promise<void> {
11
- const cfg = requireAuth();
12
- const client = new HisaaboClient(cfg);
13
-
14
- try {
15
- const result = await client.item.salesStats({ itemId: id });
16
-
17
- if (opts.json) {
18
- outputJSON(result);
19
- return;
20
- }
21
-
22
- console.log(`\n Sales Stats: ${result?.itemName ?? id}`);
23
- console.log(" " + "─".repeat(40));
24
- console.log(` Total Sold: ${formatAmount(String(result?.totalQuantitySold ?? "0"))} units`);
25
- console.log(` Total Revenue: ${formatINR(String(result?.totalRevenue ?? "0"))}`);
26
- console.log(` Avg Price: ${formatINR(String(result?.avgSalePrice ?? "0"))}`);
27
- if (result?.invoiceCount !== undefined) {
28
- console.log(` Invoices: ${result.invoiceCount}`);
29
- }
30
- if (result?.lastSoldDate) {
31
- console.log(` Last Sold: ${result.lastSoldDate}`);
32
- }
33
- console.log();
34
-
35
- } catch (e) {
36
- if (e instanceof HisaaboApiError) {
37
- const err = e.hisaaboError;
38
- if (err.code === "not_found") fatalError(`Item not found: ${id}`, EXIT.NOT_FOUND);
39
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
40
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
41
- }
42
- fatalError(String(e instanceof Error ? e.message : e));
43
- }
44
- }
@@ -1,70 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- fatalError, outputJSON, outputTable, outputTSV, outputCSV,
5
- paginationFooter, EXIT, type ColumnDef,
6
- } from "../../output.js";
7
- import { formatAmount, formatDate } from "../../format.js";
8
-
9
- interface StockHistoryOpts {
10
- page?: number;
11
- limit?: number;
12
- json?: boolean;
13
- format?: string;
14
- }
15
-
16
- interface StockAdjustmentRow {
17
- date: string;
18
- adjustment: string;
19
- reason: string;
20
- balanceAfter: string;
21
- createdBy: string;
22
- }
23
-
24
- export async function itemStockHistoryCommand(id: string, opts: StockHistoryOpts): Promise<void> {
25
- const cfg = requireAuth();
26
- const client = new HisaaboClient(cfg);
27
-
28
- const page = opts.page ?? 1;
29
- const limit = opts.limit ?? 20;
30
-
31
- try {
32
- const result = await client.item.stockAdjustmentHistory({ itemId: id, page, limit });
33
-
34
- if (opts.json) {
35
- outputJSON(result);
36
- return;
37
- }
38
-
39
- const entries: StockAdjustmentRow[] = Array.isArray(result?.data) ? result.data : (Array.isArray(result) ? result : []);
40
- const total: number = result?.total ?? entries.length;
41
-
42
- console.log(`\n Stock History: ${result?.itemName ?? id}\n`);
43
-
44
- const cols: ColumnDef<StockAdjustmentRow>[] = [
45
- { key: "date", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
46
- { key: "adjustment", header: "Adjustment", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
47
- { key: "balanceAfter", header: "Balance After", align: "right", width: 14, format: (v) => formatAmount(String(v ?? "0")) },
48
- { key: "reason", header: "Reason", width: 25 },
49
- { key: "createdBy", header: "By", width: 16 },
50
- ];
51
-
52
- if (opts.format === "tsv") outputTSV(entries, cols);
53
- else if (opts.format === "csv") outputCSV(entries, cols);
54
- else {
55
- outputTable(entries, cols);
56
- paginationFooter(page, limit, total);
57
- }
58
-
59
- console.log();
60
-
61
- } catch (e) {
62
- if (e instanceof HisaaboApiError) {
63
- const err = e.hisaaboError;
64
- if (err.code === "not_found") fatalError(`Item not found: ${id}`, EXIT.NOT_FOUND);
65
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
66
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
67
- }
68
- fatalError(String(e instanceof Error ? e.message : e));
69
- }
70
- }
@@ -1,46 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
- import { formatAmount } from "../../format.js";
5
-
6
- interface StockOpts {
7
- json?: boolean;
8
- reason?: string;
9
- }
10
-
11
- export async function itemStockCommand(id: string, adjustment: string, opts: StockOpts): Promise<void> {
12
- const cfg = requireAuth();
13
- const client = new HisaaboClient(cfg);
14
-
15
- // Validate adjustment format
16
- if (!/^[+-]?\d+(\.\d+)?$/.test(adjustment)) {
17
- fatalError(`Invalid adjustment: ${adjustment}. Use a number like +10, -5, or 100`, EXIT.USAGE);
18
- }
19
-
20
- try {
21
- const updated = await client.item.adjustStock({
22
- itemId: id,
23
- adjustment,
24
- reason: opts.reason,
25
- });
26
-
27
- if (opts.json) {
28
- outputJSON(updated);
29
- return;
30
- }
31
-
32
- const adj = parseFloat(adjustment);
33
- const dir = adj >= 0 ? "+" : "";
34
- success(`Stock adjusted: ${updated.name} ${dir}${formatAmount(adjustment)} → ${formatAmount(updated.stockQuantity)}`);
35
-
36
- } catch (e) {
37
- if (e instanceof HisaaboApiError) {
38
- const err = e.hisaaboError;
39
- if (err.code === "not_found") fatalError(`Item not found: ${id}`, EXIT.NOT_FOUND);
40
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
41
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
42
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
43
- }
44
- fatalError(String(e instanceof Error ? e.message : e));
45
- }
46
- }
@@ -1,42 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- interface SwitchBaseUnitOpts {
6
- unit?: string;
7
- conversionFactor?: string;
8
- json?: boolean;
9
- }
10
-
11
- export async function itemSwitchBaseUnitCommand(id: string, opts: SwitchBaseUnitOpts): Promise<void> {
12
- const cfg = requireAuth();
13
- const client = new HisaaboClient(cfg);
14
-
15
- if (!opts.unit) {
16
- fatalError("--unit is required", EXIT.USAGE);
17
- }
18
-
19
- const conversionFactor = opts.conversionFactor ? parseFloat(opts.conversionFactor) : undefined;
20
-
21
- try {
22
- const result = await client.item.switchBaseUnit({ itemId: id, unit: opts.unit, conversionFactor });
23
-
24
- if (opts.json) {
25
- outputJSON(result);
26
- return;
27
- }
28
-
29
- success(`Switched base unit for item ${id} to: ${opts.unit}`);
30
- console.log();
31
-
32
- } catch (e) {
33
- if (e instanceof HisaaboApiError) {
34
- const err = e.hisaaboError;
35
- if (err.code === "not_found") fatalError(`Item not found: ${id}`, EXIT.NOT_FOUND);
36
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
37
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
38
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
39
- }
40
- fatalError(String(e instanceof Error ? e.message : e));
41
- }
42
- }
@@ -1,59 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- interface UpdateOpts {
6
- name?: string;
7
- salePrice?: string;
8
- purchasePrice?: string;
9
- taxPercent?: string;
10
- hsn?: string;
11
- unit?: string;
12
- category?: string;
13
- sku?: string;
14
- lowStockAlert?: string;
15
- json?: boolean;
16
- }
17
-
18
- export async function itemUpdateCommand(id: string, opts: UpdateOpts): Promise<void> {
19
- const cfg = requireAuth();
20
- const client = new HisaaboClient(cfg);
21
-
22
- // Only send explicitly provided fields
23
- const data: Record<string, unknown> = {};
24
- if (opts.name !== undefined) data["name"] = opts.name;
25
- if (opts.salePrice !== undefined) data["salePrice"] = opts.salePrice;
26
- if (opts.purchasePrice !== undefined) data["purchasePrice"] = opts.purchasePrice;
27
- if (opts.taxPercent !== undefined) data["taxPercent"] = opts.taxPercent;
28
- if (opts.hsn !== undefined) data["hsn"] = opts.hsn;
29
- if (opts.unit !== undefined) data["unit"] = opts.unit;
30
- if (opts.category !== undefined) data["category"] = opts.category;
31
- if (opts.sku !== undefined) data["sku"] = opts.sku;
32
- if (opts.lowStockAlert !== undefined) data["lowStockAlert"] = opts.lowStockAlert;
33
-
34
- if (Object.keys(data).length === 0) {
35
- fatalError("No fields to update. Provide at least one option.", EXIT.USAGE);
36
- }
37
-
38
- try {
39
- const result = await client.item.update(id, data as Parameters<typeof client.item.update>[1]);
40
-
41
- if (opts.json) {
42
- outputJSON(result);
43
- return;
44
- }
45
-
46
- success(`Updated item: ${result.name}`);
47
- console.log(` ID: ${result.id}\n`);
48
-
49
- } catch (e) {
50
- if (e instanceof HisaaboApiError) {
51
- const err = e.hisaaboError;
52
- if (err.code === "not_found") fatalError(`Item not found: ${id}`, EXIT.NOT_FOUND);
53
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
54
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
55
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
56
- }
57
- fatalError(String(e instanceof Error ? e.message : e));
58
- }
59
- }
@@ -1,58 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- interface VariantsCreateOpts {
6
- sku?: string;
7
- salePrice?: string;
8
- purchasePrice?: string;
9
- stock?: string;
10
- lowStockAlert?: string;
11
- attributes?: string;
12
- json?: boolean;
13
- }
14
-
15
- export async function itemVariantsCreateCommand(itemId: string, opts: VariantsCreateOpts): Promise<void> {
16
- const cfg = requireAuth();
17
- const client = new HisaaboClient(cfg);
18
-
19
- let parsedAttributes: Record<string, unknown> | undefined;
20
- if (opts.attributes) {
21
- try {
22
- parsedAttributes = JSON.parse(opts.attributes) as Record<string, unknown>;
23
- } catch {
24
- fatalError("--attributes must be valid JSON", EXIT.USAGE);
25
- }
26
- }
27
-
28
- const data: Record<string, unknown> = { itemId };
29
- if (opts.sku !== undefined) data["sku"] = opts.sku;
30
- if (opts.salePrice !== undefined) data["salePrice"] = opts.salePrice;
31
- if (opts.purchasePrice !== undefined) data["purchasePrice"] = opts.purchasePrice;
32
- if (opts.stock !== undefined) data["stockQuantity"] = opts.stock;
33
- if (opts.lowStockAlert !== undefined) data["lowStockAlert"] = opts.lowStockAlert;
34
- if (parsedAttributes !== undefined) data["attributes"] = parsedAttributes;
35
-
36
- try {
37
- const result = await client.item.createVariant(data);
38
-
39
- if (opts.json) {
40
- outputJSON(result);
41
- return;
42
- }
43
-
44
- success(`Created variant: ${result?.id ?? "OK"}`);
45
- if (result?.sku) console.log(` SKU: ${result.sku}`);
46
- console.log();
47
-
48
- } catch (e) {
49
- if (e instanceof HisaaboApiError) {
50
- const err = e.hisaaboError;
51
- if (err.code === "not_found") fatalError(`Item not found: ${itemId}`, EXIT.NOT_FOUND);
52
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
53
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
54
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
55
- }
56
- fatalError(String(e instanceof Error ? e.message : e));
57
- }
58
- }
@@ -1,47 +0,0 @@
1
- import * as readline from "readline";
2
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
3
- import { requireAuth } from "../../config.js";
4
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
5
-
6
- interface VariantsDeleteOpts {
7
- yes?: boolean;
8
- json?: boolean;
9
- }
10
-
11
- export async function itemVariantsDeleteCommand(variantId: string, opts: VariantsDeleteOpts): 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(` Delete variant ${variantId}? (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.item.deleteVariant({ variantId });
29
-
30
- if (opts.json) {
31
- outputJSON(result);
32
- return;
33
- }
34
-
35
- success(`Deleted variant: ${variantId}`);
36
-
37
- } catch (e) {
38
- if (e instanceof HisaaboApiError) {
39
- const err = e.hisaaboError;
40
- if (err.code === "not_found") fatalError(`Variant not found: ${variantId}`, EXIT.NOT_FOUND);
41
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
42
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
43
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
44
- }
45
- fatalError(String(e instanceof Error ? e.message : e));
46
- }
47
- }
@@ -1,63 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- fatalError, outputJSON, outputTable, outputTSV, outputCSV,
5
- EXIT, type ColumnDef,
6
- } from "../../output.js";
7
- import { formatAmount } from "../../format.js";
8
-
9
- interface VariantsListOpts {
10
- json?: boolean;
11
- format?: string;
12
- }
13
-
14
- interface VariantRow {
15
- id: string;
16
- sku: string;
17
- salePrice: string;
18
- purchasePrice: string;
19
- stockQuantity: string;
20
- attributes: string;
21
- }
22
-
23
- export async function itemVariantsListCommand(itemId: string, opts: VariantsListOpts): Promise<void> {
24
- const cfg = requireAuth();
25
- const client = new HisaaboClient(cfg);
26
-
27
- try {
28
- const result = await client.item.listVariants({ itemId });
29
-
30
- if (opts.json) {
31
- outputJSON(result);
32
- return;
33
- }
34
-
35
- const variants: VariantRow[] = Array.isArray(result?.variants) ? result.variants : (Array.isArray(result) ? result : []);
36
-
37
- console.log(`\n Variants for item: ${itemId}\n`);
38
-
39
- const cols: ColumnDef<VariantRow>[] = [
40
- { key: "id", header: "ID", width: 12 },
41
- { key: "sku", header: "SKU", width: 14 },
42
- { key: "salePrice", header: "Sale (₹)", align: "right", width: 12, format: (v) => v ? formatAmount(String(v)) : "-" },
43
- { key: "purchasePrice", header: "Purchase (₹)", align: "right", width: 14, format: (v) => v ? formatAmount(String(v)) : "-" },
44
- { key: "stockQuantity", header: "Stock", align: "right", width: 10, format: (v) => formatAmount(String(v ?? "0")) },
45
- { key: "attributes", header: "Attributes", width: 20, format: (v) => v ? JSON.stringify(v) : "-" },
46
- ];
47
-
48
- if (opts.format === "tsv") outputTSV(variants, cols);
49
- else if (opts.format === "csv") outputCSV(variants, cols);
50
- else outputTable(variants, cols);
51
-
52
- console.log();
53
-
54
- } catch (e) {
55
- if (e instanceof HisaaboApiError) {
56
- const err = e.hisaaboError;
57
- if (err.code === "not_found") fatalError(`Item not found: ${itemId}`, EXIT.NOT_FOUND);
58
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
59
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
60
- }
61
- fatalError(String(e instanceof Error ? e.message : e));
62
- }
63
- }
@@ -1,61 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- interface VariantsUpdateOpts {
6
- sku?: string;
7
- salePrice?: string;
8
- purchasePrice?: string;
9
- stock?: string;
10
- lowStockAlert?: string;
11
- attributes?: string;
12
- json?: boolean;
13
- }
14
-
15
- export async function itemVariantsUpdateCommand(variantId: string, opts: VariantsUpdateOpts): Promise<void> {
16
- const cfg = requireAuth();
17
- const client = new HisaaboClient(cfg);
18
-
19
- let parsedAttributes: Record<string, unknown> | undefined;
20
- if (opts.attributes) {
21
- try {
22
- parsedAttributes = JSON.parse(opts.attributes) as Record<string, unknown>;
23
- } catch {
24
- fatalError("--attributes must be valid JSON", EXIT.USAGE);
25
- }
26
- }
27
-
28
- const data: Record<string, unknown> = { variantId };
29
- if (opts.sku !== undefined) data["sku"] = opts.sku;
30
- if (opts.salePrice !== undefined) data["salePrice"] = opts.salePrice;
31
- if (opts.purchasePrice !== undefined) data["purchasePrice"] = opts.purchasePrice;
32
- if (opts.stock !== undefined) data["stockQuantity"] = opts.stock;
33
- if (opts.lowStockAlert !== undefined) data["lowStockAlert"] = opts.lowStockAlert;
34
- if (parsedAttributes !== undefined) data["attributes"] = parsedAttributes;
35
-
36
- if (Object.keys(data).length === 1) {
37
- fatalError("No fields to update. Provide at least one option.", EXIT.USAGE);
38
- }
39
-
40
- try {
41
- const result = await client.item.updateVariant(data);
42
-
43
- if (opts.json) {
44
- outputJSON(result);
45
- return;
46
- }
47
-
48
- success(`Updated variant: ${variantId}`);
49
- console.log();
50
-
51
- } catch (e) {
52
- if (e instanceof HisaaboApiError) {
53
- const err = e.hisaaboError;
54
- if (err.code === "not_found") fatalError(`Variant not found: ${variantId}`, EXIT.NOT_FOUND);
55
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
56
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
57
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
58
- }
59
- fatalError(String(e instanceof Error ? e.message : e));
60
- }
61
- }