@hisaabo/cli 0.8.6 → 0.10.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 (66) hide show
  1. package/README.md +154 -4
  2. package/dist/bin/{audit-trail-IJ6SKACR.js → audit-trail-RTPTWZAL.js} +12 -15
  3. package/dist/bin/{categories-O6TODPAH.js → categories-JJDTOT5T.js} +3 -3
  4. package/dist/bin/{check-slug-P7RFU6OP.js → check-slug-5L2VDAEN.js} +16 -4
  5. package/dist/bin/chunk-2DDIXPNI.js +1512 -0
  6. package/dist/bin/chunk-ALOHN6GR.js +78 -0
  7. package/dist/bin/{chunk-QUITS2FE.js → chunk-ESX7V56A.js} +95 -20
  8. package/dist/bin/chunk-M7DVLVD5.js +245 -0
  9. package/dist/bin/{chunk-WDN7RIE3.js → chunk-VXEEFNIY.js} +133 -47
  10. package/dist/bin/client-NFYNYEDI.js +17 -0
  11. package/dist/bin/{collection-efficiency-DA5RWG3V.js → collection-efficiency-UF3AJPQB.js} +12 -56
  12. package/dist/bin/{config-4LLNT4SH.js → config-7HVBRHL3.js} +2 -2
  13. package/dist/bin/{create-C5INBPQO.js → create-2BZQLXQA.js} +18 -9
  14. package/dist/bin/{default-account-2GMQ7ZA4.js → default-account-MR6O5LPT.js} +7 -13
  15. package/dist/bin/{expenses-S2YVA5UT.js → expenses-CU6JGDVX.js} +12 -11
  16. package/dist/bin/{export-YOOODNVX.js → export-GFYQIQLT.js} +9 -24
  17. package/dist/bin/{export-ZA43MLWO.js → export-WS24LYNH.js} +47 -14
  18. package/dist/bin/{factory-6MUCSXTL.js → factory-JSEQCPY3.js} +51 -57
  19. package/dist/bin/{get-GMQRROK2.js → get-HGMB7T6Y.js} +5 -4
  20. package/dist/bin/{get-ZV3SC2VY.js → get-KAOGGRJR.js} +4 -4
  21. package/dist/bin/hisaabo.js +2024 -837
  22. package/dist/bin/{import-UUHMLCKX.js → import-6CEMNCTM.js} +30 -33
  23. package/dist/bin/{invitations-OVORTTMF.js → invitations-LASABD2X.js} +11 -14
  24. package/dist/bin/{invite-GGHBZY4U.js → invite-VCBXS7VY.js} +13 -15
  25. package/dist/bin/{invoice-breakdown-32XXAZDP.js → invoice-breakdown-3XXSYA77.js} +12 -37
  26. package/dist/bin/{items-6NOIMH6B.js → items-PJPN6ZX3.js} +11 -10
  27. package/dist/bin/{items-toggle-L6W6QKQD.js → items-toggle-53C35MJU.js} +6 -5
  28. package/dist/bin/{list-RAR56EMQ.js → list-63EKE6DT.js} +13 -16
  29. package/dist/bin/{list-OXAVDXH7.js → list-7OSZX6C7.js} +5 -5
  30. package/dist/bin/{list-FC5JHKHD.js → list-OOROCQR2.js} +11 -12
  31. package/dist/bin/{members-Y6XJVHHR.js → members-SPHU5F4M.js} +7 -7
  32. package/dist/bin/monthly-comparison-3FFJT63K.js +79 -0
  33. package/dist/bin/{order-cancel-QRTCNART.js → order-cancel-RW4NYHKN.js} +8 -18
  34. package/dist/bin/{order-confirm-LGQOMC4O.js → order-confirm-NXFL2EIQ.js} +7 -15
  35. package/dist/bin/{order-get-4XAQCRYV.js → order-get-QPSOY2RT.js} +11 -11
  36. package/dist/bin/{order-update-KZY4H2UR.js → order-update-7DWKEROO.js} +4 -4
  37. package/dist/bin/{output-NUOL7KJW.js → output-XFDIL3A6.js} +5 -1
  38. package/dist/bin/{payment-modes-DY2ZEMK7.js → payment-modes-Z5WV3E3O.js} +12 -27
  39. package/dist/bin/{profit-loss-5GJBG3PL.js → profit-loss-AOISAJ56.js} +14 -13
  40. package/dist/bin/{receivables-aging-6A7XJKDT.js → receivables-aging-5JHFECGB.js} +13 -66
  41. package/dist/bin/{remove-ZBX34TIQ.js → remove-TC4UWMOL.js} +7 -15
  42. package/dist/bin/{revoke-ZTAMW2Q2.js → revoke-QHLNPGI5.js} +7 -3
  43. package/dist/bin/{revoke-XDNOA2GJ.js → revoke-SXVNALYQ.js} +7 -15
  44. package/dist/bin/{revoke-all-365NRBOA.js → revoke-all-CYW6A5UE.js} +8 -4
  45. package/dist/bin/{revoke-invitation-PQH7XNYA.js → revoke-invitation-Z33EUJTS.js} +7 -3
  46. package/dist/bin/safety-TPD2P7I5.js +18 -0
  47. package/dist/bin/{sales-trend-D6PQ7MHY.js → sales-trend-WCW6X5BI.js} +16 -16
  48. package/dist/bin/sequence-HOQ4PQRK.js +56 -0
  49. package/dist/bin/{store-SVRZBUFO.js → store-DDMHTNTO.js} +15 -8
  50. package/dist/bin/{summary-H6U7O5GJ.js → summary-TYAL2D3Q.js} +7 -5
  51. package/dist/bin/{top-customers-ATBN6RDI.js → top-customers-GMIS6GC3.js} +13 -11
  52. package/dist/bin/{top-items-XXU6KYTC.js → top-items-BK54JO3G.js} +16 -14
  53. package/dist/bin/{top-outstanding-JTQNGGW4.js → top-outstanding-L4NRJ6NE.js} +9 -11
  54. package/dist/bin/{unpaid-invoices-BTNQFWCH.js → unpaid-invoices-CEUFEYH7.js} +8 -8
  55. package/dist/bin/{untracked-PAMEDJ6Y.js → untracked-T6DIDMDQ.js} +9 -9
  56. package/dist/bin/{update-EK4NJWU4.js → update-EPNB2U74.js} +4 -4
  57. package/dist/bin/{update-EGHPFXLK.js → update-I2DZRVLR.js} +10 -17
  58. package/dist/bin/{update-6ZMX2OYX.js → update-MFNOVS6D.js} +4 -4
  59. package/dist/bin/{update-role-24PDTNFK.js → update-role-D2ETEL2Q.js} +7 -4
  60. package/dist/bin/{update-settings-AASI6WZX.js → update-settings-UGXLQRYI.js} +15 -9
  61. package/package.json +8 -7
  62. package/dist/bin/chunk-NO4FIFMS.js +0 -176
  63. package/dist/bin/chunk-ZPYC767N.js +0 -157
  64. package/dist/bin/client-36JX5MR3.js +0 -11
  65. package/dist/bin/monthly-comparison-IAUZ6SBJ.js +0 -176
  66. package/dist/bin/sequence-KZWADVD7.js +0 -66
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  formatINR
4
- } from "./chunk-ZPYC767N.js";
4
+ } from "./chunk-M7DVLVD5.js";
5
5
  import {
6
6
  HisaaboApiError,
7
7
  HisaaboClient
8
- } from "./chunk-WDN7RIE3.js";
8
+ } from "./chunk-VXEEFNIY.js";
9
9
  import {
10
10
  requireAuth
11
- } from "./chunk-QUITS2FE.js";
11
+ } from "./chunk-ESX7V56A.js";
12
12
  import {
13
13
  EXIT,
14
14
  fatalError,
15
15
  outputJSON,
16
16
  success
17
- } from "./chunk-NO4FIFMS.js";
17
+ } from "./chunk-2DDIXPNI.js";
18
18
 
19
19
  // src/commands/expense/update.ts
20
20
  async function expenseUpdateCommand(id, opts) {
@@ -2,23 +2,26 @@
2
2
  import {
3
3
  HisaaboApiError,
4
4
  HisaaboClient
5
- } from "./chunk-WDN7RIE3.js";
5
+ } from "./chunk-VXEEFNIY.js";
6
6
  import {
7
7
  requireAuth
8
- } from "./chunk-QUITS2FE.js";
8
+ } from "./chunk-ESX7V56A.js";
9
9
  import {
10
10
  EXIT,
11
11
  fatalError,
12
12
  outputJSON,
13
13
  success
14
- } from "./chunk-NO4FIFMS.js";
14
+ } from "./chunk-2DDIXPNI.js";
15
15
 
16
16
  // src/commands/tenant/update-role.ts
17
17
  var VALID_ROLES = ["admin", "seller_manager", "seller", "accountant"];
18
+ function isTenantRole(v) {
19
+ return VALID_ROLES.includes(v);
20
+ }
18
21
  async function tenantUpdateRoleCommand(userId, role, opts) {
19
22
  const cfg = requireAuth();
20
23
  const client = new HisaaboClient(cfg);
21
- if (!VALID_ROLES.includes(role)) {
24
+ if (!isTenantRole(role)) {
22
25
  fatalError(`Invalid role "${role}". Must be one of: ${VALID_ROLES.join(", ")}`, EXIT.VALIDATION);
23
26
  }
24
27
  try {
@@ -2,32 +2,38 @@
2
2
  import {
3
3
  HisaaboApiError,
4
4
  HisaaboClient
5
- } from "./chunk-WDN7RIE3.js";
5
+ } from "./chunk-VXEEFNIY.js";
6
6
  import {
7
7
  requireAuth
8
- } from "./chunk-QUITS2FE.js";
8
+ } from "./chunk-ESX7V56A.js";
9
9
  import {
10
10
  EXIT,
11
11
  fatalError,
12
12
  outputJSON,
13
13
  success
14
- } from "./chunk-NO4FIFMS.js";
14
+ } from "./chunk-2DDIXPNI.js";
15
15
 
16
16
  // src/commands/store/update-settings.ts
17
17
  async function storeUpdateSettingsCommand(opts) {
18
18
  const cfg = requireAuth();
19
19
  const client = new HisaaboClient(cfg);
20
20
  const data = {};
21
- if (opts.slug !== void 0) data["storeSlug"] = opts.slug;
22
- if (opts.tagline !== void 0) data["storeDescription"] = opts.tagline;
21
+ if (opts.slug !== void 0) data.storeSlug = opts.slug;
22
+ if (opts.tagline !== void 0) data.storeTagline = opts.tagline;
23
23
  if (opts.enabled !== void 0) {
24
24
  if (opts.enabled !== "true" && opts.enabled !== "false") {
25
25
  fatalError("--enabled must be 'true' or 'false'", EXIT.USAGE);
26
26
  }
27
- data["storeEnabled"] = opts.enabled === "true";
27
+ data.storeEnabled = opts.enabled === "true";
28
+ }
29
+ if (opts.requirePhoneOtp !== void 0) {
30
+ if (opts.requirePhoneOtp !== "true" && opts.requirePhoneOtp !== "false") {
31
+ fatalError("--require-phone-otp must be 'true' or 'false'", EXIT.USAGE);
32
+ }
33
+ data.storeRequirePhoneOtp = opts.requirePhoneOtp === "true";
28
34
  }
29
35
  if (Object.keys(data).length === 0) {
30
- fatalError("At least one option is required (--slug, --tagline, --enabled)", EXIT.USAGE);
36
+ fatalError("At least one option is required (--slug, --tagline, --enabled, --require-phone-otp)", EXIT.USAGE);
31
37
  }
32
38
  try {
33
39
  const result = await client.store.updateSettings(data);
@@ -37,9 +43,9 @@ async function storeUpdateSettingsCommand(opts) {
37
43
  }
38
44
  success("Store settings updated");
39
45
  console.log(` Enabled: ${result.storeEnabled ? "Yes" : "No"}`);
46
+ console.log(` SMS OTP: ${result.storeRequirePhoneOtp ? "Required" : "Off"}`);
40
47
  if (result.storeSlug) console.log(` Slug: ${result.storeSlug}`);
41
- if (result.storeName) console.log(` Name: ${result.storeName}`);
42
- if (result.storeDescription) console.log(` About: ${result.storeDescription}`);
48
+ if (result.storeTagline) console.log(` Tagline: ${result.storeTagline}`);
43
49
  console.log();
44
50
  } catch (e) {
45
51
  if (e instanceof HisaaboApiError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hisaabo/cli",
3
- "version": "0.8.6",
3
+ "version": "0.10.0",
4
4
  "description": "Hisaabo command-line interface — manage invoices, parties, items, payments, and reports from your terminal.",
5
5
  "keywords": [
6
6
  "hisaabo",
@@ -40,15 +40,15 @@
40
40
  "conf": "^13.0.0",
41
41
  "open": "^10.1.0",
42
42
  "superjson": "^2.2.0",
43
- "zod": "^3.24.0"
43
+ "zod": "^4.6.6"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "^22.0.0",
46
+ "@types/node": "^22.20.5",
47
47
  "tsup": "^8.3.0",
48
- "tsx": "^4.19.0",
49
- "typescript": "^5.7.0",
50
- "@hisaabo/api": "0.8.6",
51
- "@hisaabo/shared": "0.8.6"
48
+ "tsx": "^4.23.15",
49
+ "typescript": "^5.9.3",
50
+ "@hisaabo/api": "0.10.0",
51
+ "@hisaabo/shared": "0.10.0"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=20"
@@ -56,6 +56,7 @@
56
56
  "scripts": {
57
57
  "build": "tsup",
58
58
  "dev": "tsx src/bin/hisaabo.ts",
59
+ "test": "tsx --test test/*.test.ts",
59
60
  "typecheck": "tsc --noEmit"
60
61
  }
61
62
  }
@@ -1,176 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/output.ts
4
- import chalk from "chalk";
5
- function isInteractive() {
6
- return process.stdout.isTTY === true;
7
- }
8
- function hasColor() {
9
- if (process.env["NO_COLOR"] !== void 0) return false;
10
- if (process.env["FORCE_COLOR"] === "0") return false;
11
- return process.stdout.hasColors?.() ?? isInteractive();
12
- }
13
- function stripAnsi(str) {
14
- return str.replace(/\x1b\[[0-9;]*m/g, "");
15
- }
16
- function getWidthTier() {
17
- const w = process.stdout.columns ?? 80;
18
- if (w < 80) return "narrow";
19
- if (w <= 120) return "standard";
20
- return "wide";
21
- }
22
- function termWidth() {
23
- return process.stdout.columns ?? 80;
24
- }
25
- var EXIT = {
26
- SUCCESS: 0,
27
- GENERAL: 1,
28
- USAGE: 2,
29
- AUTH: 3,
30
- FORBIDDEN: 4,
31
- NOT_FOUND: 5,
32
- VALIDATION: 6,
33
- NETWORK: 7,
34
- CONFLICT: 8,
35
- RATE_LIMITED: 9
36
- };
37
- function fatalError(message, code = 1) {
38
- if (hasColor()) {
39
- process.stderr.write(chalk.red("Error: ") + message + "\n");
40
- } else {
41
- process.stderr.write("Error: " + message + "\n");
42
- }
43
- process.exit(code);
44
- }
45
- function success(message) {
46
- if (hasColor()) {
47
- process.stdout.write(chalk.green("\u2713 ") + message + "\n");
48
- } else {
49
- process.stdout.write("OK: " + message + "\n");
50
- }
51
- }
52
- function warn(message) {
53
- if (hasColor()) {
54
- process.stderr.write(chalk.yellow("Warning: ") + message + "\n");
55
- } else {
56
- process.stderr.write("Warning: " + message + "\n");
57
- }
58
- }
59
- function outputJSON(data) {
60
- process.stdout.write(JSON.stringify(data, null, 2) + "\n");
61
- }
62
- function getNestedValue(obj, key) {
63
- const parts = key.split(".");
64
- let cur = obj;
65
- for (const part of parts) {
66
- if (cur == null || typeof cur !== "object") return void 0;
67
- cur = cur[part];
68
- }
69
- return cur;
70
- }
71
- function padEnd(str, len) {
72
- const visual = stripAnsi(str).length;
73
- const pad = Math.max(0, len - visual);
74
- return str + " ".repeat(pad);
75
- }
76
- function padStart(str, len) {
77
- const visual = stripAnsi(str).length;
78
- const pad = Math.max(0, len - visual);
79
- return " ".repeat(pad) + str;
80
- }
81
- function outputTable(rows, columns) {
82
- if (rows.length === 0) {
83
- process.stdout.write(" (no results)\n");
84
- return;
85
- }
86
- const widths = columns.map((col) => {
87
- let max = stripAnsi(col.header).length;
88
- for (const row of rows) {
89
- const val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
90
- const vis = stripAnsi(val).length;
91
- if (vis > max) max = vis;
92
- }
93
- if (col.width) max = Math.min(max, col.width);
94
- return max;
95
- });
96
- const sep = "\u2500".repeat(widths.reduce((s, w) => s + w + 2, 1));
97
- let header = " ";
98
- for (let i = 0; i < columns.length; i++) {
99
- const col = columns[i];
100
- const h = col.align === "right" ? padStart(col.header, widths[i]) : padEnd(col.header, widths[i]);
101
- header += (hasColor() ? chalk.dim(h) : h) + " ";
102
- }
103
- process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
104
- process.stdout.write(header.trimEnd() + "\n");
105
- process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
106
- for (const row of rows) {
107
- let line = " ";
108
- for (let i = 0; i < columns.length; i++) {
109
- const col = columns[i];
110
- let val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
111
- const vis = stripAnsi(val).length;
112
- if (col.width && vis > col.width) {
113
- val = val.slice(0, col.width - 1) + "\u2026";
114
- }
115
- const cell = col.align === "right" ? padStart(val, widths[i]) : padEnd(val, widths[i]);
116
- line += cell + " ";
117
- }
118
- process.stdout.write(line.trimEnd() + "\n");
119
- }
120
- process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
121
- }
122
- function outputTSV(rows, columns) {
123
- process.stdout.write(columns.map((c) => c.header).join(" ") + "\n");
124
- for (const row of rows) {
125
- const line = columns.map((col) => {
126
- const val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
127
- return stripAnsi(val).replace(/\t/g, " ");
128
- });
129
- process.stdout.write(line.join(" ") + "\n");
130
- }
131
- }
132
- function csvEscape(val) {
133
- if (val.includes(",") || val.includes('"') || val.includes("\n")) {
134
- return `"${val.replace(/"/g, '""')}"`;
135
- }
136
- return val;
137
- }
138
- function outputCSV(rows, columns) {
139
- process.stdout.write(columns.map((c) => csvEscape(c.header)).join(",") + "\n");
140
- for (const row of rows) {
141
- const line = columns.map((col) => {
142
- const val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
143
- return csvEscape(stripAnsi(val));
144
- });
145
- process.stdout.write(line.join(",") + "\n");
146
- }
147
- }
148
- function outputIds(ids) {
149
- for (const id of ids) {
150
- process.stdout.write(id + "\n");
151
- }
152
- }
153
- function paginationFooter(page, limit, total) {
154
- const from = (page - 1) * limit + 1;
155
- const to = Math.min(page * limit, total);
156
- const msg = ` Showing ${from}-${to} of ${total}`;
157
- process.stdout.write("\n" + (hasColor() ? chalk.dim(msg) : msg) + "\n");
158
- }
159
-
160
- export {
161
- isInteractive,
162
- hasColor,
163
- stripAnsi,
164
- getWidthTier,
165
- termWidth,
166
- EXIT,
167
- fatalError,
168
- success,
169
- warn,
170
- outputJSON,
171
- outputTable,
172
- outputTSV,
173
- outputCSV,
174
- outputIds,
175
- paginationFooter
176
- };
@@ -1,157 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- hasColor
4
- } from "./chunk-NO4FIFMS.js";
5
-
6
- // src/format.ts
7
- import chalk from "chalk";
8
- function formatINR(amount) {
9
- const num = typeof amount === "string" ? parseFloat(amount) : amount;
10
- if (isNaN(num)) return "0.00";
11
- const abs = Math.abs(num);
12
- const formatted = new Intl.NumberFormat("en-IN", {
13
- minimumFractionDigits: 2,
14
- maximumFractionDigits: 2
15
- }).format(abs);
16
- return (num < 0 ? "-" : "") + "\u20B9" + formatted;
17
- }
18
- function formatAmount(amount) {
19
- const num = typeof amount === "string" ? parseFloat(amount) : amount;
20
- if (isNaN(num)) return "0.00";
21
- const abs = Math.abs(num);
22
- const formatted = new Intl.NumberFormat("en-IN", {
23
- minimumFractionDigits: 2,
24
- maximumFractionDigits: 2
25
- }).format(abs);
26
- return (num < 0 ? "-" : "") + formatted;
27
- }
28
- var MONTHS = [
29
- "Jan",
30
- "Feb",
31
- "Mar",
32
- "Apr",
33
- "May",
34
- "Jun",
35
- "Jul",
36
- "Aug",
37
- "Sep",
38
- "Oct",
39
- "Nov",
40
- "Dec"
41
- ];
42
- function formatDate(date) {
43
- if (!date) return "-";
44
- try {
45
- const d = new Date(date);
46
- if (isNaN(d.getTime())) return date;
47
- const day = String(d.getDate()).padStart(2, "0");
48
- const month = MONTHS[d.getMonth()];
49
- const year = d.getFullYear();
50
- return `${day} ${month} ${year}`;
51
- } catch {
52
- return date;
53
- }
54
- }
55
- function formatRelativeDate(date) {
56
- if (!date) return "-";
57
- try {
58
- const d = new Date(date);
59
- const now = /* @__PURE__ */ new Date();
60
- const diff = Math.floor((now.getTime() - d.getTime()) / (1e3 * 60 * 60 * 24));
61
- if (diff === 0) return "Today";
62
- if (diff === 1) return "Yesterday";
63
- if (diff < 30) return `${diff}d ago`;
64
- if (diff < 365) return `${Math.floor(diff / 30)}mo ago`;
65
- return `${Math.floor(diff / 365)}y ago`;
66
- } catch {
67
- return date ?? "-";
68
- }
69
- }
70
- var STATUS_CONFIG = {
71
- paid: { label: "PAID", color: (s) => chalk.green(s) },
72
- sent: { label: "SENT", color: (s) => chalk.blue(s) },
73
- draft: { label: "DRAFT", color: (s) => chalk.dim(s) },
74
- partial: { label: "PARTIAL", color: (s) => chalk.yellow(s) },
75
- overdue: { label: "OVERDUE", color: (s) => chalk.red(s) },
76
- cancelled: { label: "CANCEL", color: (s) => chalk.dim(chalk.strikethrough(s)) },
77
- adjusted: { label: "ADJUST", color: (s) => chalk.magenta(s) },
78
- unfulfilled: { label: "UNFUL", color: (s) => chalk.blue(s) },
79
- pending: { label: "PEND", color: (s) => chalk.yellow(s) },
80
- confirmed: { label: "CONF", color: (s) => chalk.blue(s) },
81
- delivered: { label: "DELIV", color: (s) => chalk.green(s) },
82
- shipped: { label: "SHIPPED", color: (s) => chalk.blue(s) },
83
- in_transit: { label: "TRANSIT", color: (s) => chalk.cyan(s) },
84
- returned: { label: "RETURN", color: (s) => chalk.red(s) },
85
- preparing: { label: "PREP", color: (s) => chalk.yellow(s) },
86
- ready: { label: "READY", color: (s) => chalk.cyan(s) }
87
- };
88
- function formatStatus(status) {
89
- const cfg = STATUS_CONFIG[status.toLowerCase()];
90
- const label = cfg ? `[${cfg.label}]` : `[${status.toUpperCase()}]`;
91
- if (!hasColor() || !cfg) return label;
92
- return cfg.color(label);
93
- }
94
- function currentFY() {
95
- const now = /* @__PURE__ */ new Date();
96
- const year = now.getFullYear();
97
- const month = now.getMonth() + 1;
98
- if (month >= 4) {
99
- return `${year}-${String(year + 1).slice(2)}`;
100
- }
101
- return `${year - 1}-${String(year).slice(2)}`;
102
- }
103
- function fyStart() {
104
- const now = /* @__PURE__ */ new Date();
105
- const year = now.getMonth() + 1 >= 4 ? now.getFullYear() : now.getFullYear() - 1;
106
- return `${year}-04-01`;
107
- }
108
- function todayISO() {
109
- return (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "";
110
- }
111
- function monthStart() {
112
- const now = /* @__PURE__ */ new Date();
113
- return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-01`;
114
- }
115
- function monthEnd() {
116
- const now = /* @__PURE__ */ new Date();
117
- const last = new Date(now.getFullYear(), now.getMonth() + 1, 0);
118
- return `${last.getFullYear()}-${String(last.getMonth() + 1).padStart(2, "0")}-${String(last.getDate()).padStart(2, "0")}`;
119
- }
120
- function quarterRange(q) {
121
- const now = /* @__PURE__ */ new Date();
122
- const fyYear = now.getMonth() + 1 >= 4 ? now.getFullYear() : now.getFullYear() - 1;
123
- const ranges = {
124
- Q1: { from: `${fyYear}-04-01`, to: `${fyYear}-06-30`, month: 4, year: fyYear },
125
- Q2: { from: `${fyYear}-07-01`, to: `${fyYear}-09-30`, month: 7, year: fyYear },
126
- Q3: { from: `${fyYear}-10-01`, to: `${fyYear}-12-31`, month: 10, year: fyYear },
127
- Q4: { from: `${fyYear + 1}-01-01`, to: `${fyYear + 1}-03-31`, month: 1, year: fyYear + 1 }
128
- };
129
- const upper = q.toUpperCase();
130
- return ranges[upper] ?? ranges["Q1"];
131
- }
132
- function deliveryMethodLabel(method) {
133
- const map = {
134
- self_pickup: "Self Pickup",
135
- hand_delivery: "Hand Delivery",
136
- courier: "Courier",
137
- bus: "Bus",
138
- transport: "Transport",
139
- post: "Post"
140
- };
141
- return map[method] ?? method;
142
- }
143
-
144
- export {
145
- formatINR,
146
- formatAmount,
147
- formatDate,
148
- formatRelativeDate,
149
- formatStatus,
150
- currentFY,
151
- fyStart,
152
- todayISO,
153
- monthStart,
154
- monthEnd,
155
- quarterRange,
156
- deliveryMethodLabel
157
- };
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- HisaaboApiError,
4
- HisaaboClient,
5
- formatHisaaboError
6
- } from "./chunk-WDN7RIE3.js";
7
- export {
8
- HisaaboApiError,
9
- HisaaboClient,
10
- formatHisaaboError
11
- };
@@ -1,176 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- formatAmount
4
- } from "./chunk-ZPYC767N.js";
5
- import {
6
- HisaaboApiError,
7
- HisaaboClient
8
- } from "./chunk-WDN7RIE3.js";
9
- import {
10
- requireAuth
11
- } from "./chunk-QUITS2FE.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
- };