@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
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ EXIT,
4
+ fatalError,
5
+ stripControlChars
6
+ } from "./chunk-2DDIXPNI.js";
7
+
8
+ // src/safety.ts
9
+ import * as readline from "readline";
10
+ import * as fs from "fs";
11
+ import * as path from "path";
12
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
13
+ function isUuid(value) {
14
+ return UUID_RE.test(value);
15
+ }
16
+ function requireUuid(value, label = "id") {
17
+ if (!isUuid(value)) {
18
+ fatalError(`Invalid ${label}: expected a UUID`, EXIT.USAGE);
19
+ }
20
+ return value;
21
+ }
22
+ function safeFilename(name, fallback = "download") {
23
+ const base = path.basename(String(name).replace(/\\/g, "/")).replace(/[^A-Za-z0-9._-]/g, "_");
24
+ const trimmed = base.replace(/^\.+/, "");
25
+ return trimmed.length > 0 ? trimmed : fallback;
26
+ }
27
+ var MAX_DOWNLOAD_BYTES = 100 * 1024 * 1024;
28
+ function writeFileSafe(file, data, opts = {}) {
29
+ const bytes = typeof data === "string" ? Buffer.from(data, "utf-8") : Buffer.from(data);
30
+ if (bytes.length > MAX_DOWNLOAD_BYTES) {
31
+ fatalError(`Refusing to write ${Math.round(bytes.length / 1024 / 1024)} MB; max ${MAX_DOWNLOAD_BYTES / 1024 / 1024} MB`, EXIT.USAGE);
32
+ }
33
+ if (opts.magic !== void 0 && bytes.subarray(0, opts.magic.length).toString("latin1") !== opts.magic) {
34
+ fatalError(`Unexpected response: not a ${opts.magic.replace(/[^A-Za-z]/g, "")} file`, EXIT.GENERAL);
35
+ }
36
+ let fd;
37
+ try {
38
+ const noFollow = fs.constants.O_NOFOLLOW ?? 0;
39
+ fd = fs.openSync(file, fs.constants.O_WRONLY | fs.constants.O_CREAT | noFollow, 384);
40
+ } catch (e) {
41
+ const code = e.code;
42
+ if (code === "ELOOP") fatalError(`Refusing to write to a symlink: ${file}`, EXIT.USAGE);
43
+ throw e;
44
+ }
45
+ try {
46
+ if (!fs.fstatSync(fd).isFile()) fatalError(`Refusing to write to a non-regular file: ${file}`, EXIT.USAGE);
47
+ fs.ftruncateSync(fd, 0);
48
+ fs.fchmodSync(fd, 384);
49
+ let off = 0;
50
+ while (off < bytes.length) off += fs.writeSync(fd, bytes, off, bytes.length - off);
51
+ } finally {
52
+ fs.closeSync(fd);
53
+ }
54
+ }
55
+ async function confirmOrExit(message, opts) {
56
+ if (opts.yes) return;
57
+ if (!process.stdin.isTTY) {
58
+ fatalError("Refusing destructive action non-interactively; pass --yes", EXIT.USAGE);
59
+ }
60
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
61
+ const answer = await new Promise((resolve) => {
62
+ rl.question(` ${stripControlChars(message).trimStart()} (y/N): `, resolve);
63
+ });
64
+ rl.close();
65
+ if (answer.trim().toLowerCase() !== "y") {
66
+ console.log(" Cancelled.");
67
+ process.exit(0);
68
+ }
69
+ }
70
+
71
+ export {
72
+ isUuid,
73
+ requireUuid,
74
+ safeFilename,
75
+ MAX_DOWNLOAD_BYTES,
76
+ writeFileSafe,
77
+ confirmOrExit
78
+ };
@@ -1,43 +1,116 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ EXIT,
3
4
  fatalError,
4
5
  warn
5
- } from "./chunk-NO4FIFMS.js";
6
+ } from "./chunk-2DDIXPNI.js";
6
7
 
7
8
  // src/config.ts
8
9
  import Conf from "conf";
9
10
  import { hostname, userInfo } from "os";
11
+ import { chmodSync, existsSync, writeFileSync } from "fs";
12
+ import { dirname } from "path";
10
13
  import { createHash } from "crypto";
11
- function deriveEncryptionKey() {
12
- let uid;
14
+
15
+ // src/url.ts
16
+ function isLoopbackHost(hostname2) {
17
+ const h = hostname2.replace(/^\[|\]$/g, "").toLowerCase();
18
+ if (h === "localhost" || h.endsWith(".localhost") || h === "::1") return true;
19
+ return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h);
20
+ }
21
+ function validateApiUrl(url) {
22
+ let parsed;
13
23
  try {
14
- uid = String(userInfo().uid);
24
+ parsed = new URL(url);
15
25
  } catch {
16
- uid = String(process.getuid?.() ?? process.pid);
26
+ return fatalError("Invalid API URL", EXIT.USAGE);
17
27
  }
18
- const raw = `${uid}:${hostname()}:hisaabo-cli`;
19
- return createHash("sha256").update(raw).digest("hex");
28
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
29
+ fatalError("API URL must use https://", EXIT.USAGE);
30
+ }
31
+ if (parsed.username || parsed.password) {
32
+ fatalError("API URL must not contain credentials", EXIT.USAGE);
33
+ }
34
+ if (parsed.protocol === "http:" && !isLoopbackHost(parsed.hostname) && process.env["HISAABO_ALLOW_INSECURE"] !== "1") {
35
+ fatalError(
36
+ "Refusing to send credentials over plain http://. Use https://, or set HISAABO_ALLOW_INSECURE=1 to override.",
37
+ EXIT.USAGE
38
+ );
39
+ }
40
+ return parsed.origin + parsed.pathname.replace(/\/+$/, "");
20
41
  }
21
- var conf = new Conf({
42
+ function resolveSameOriginUrl(raw, apiUrl) {
43
+ const base = new URL(apiUrl);
44
+ let target;
45
+ try {
46
+ target = raw.startsWith("/") && !raw.startsWith("//") ? new URL(base.pathname.replace(/\/+$/, "") + raw, base.origin) : new URL(raw, base);
47
+ } catch {
48
+ return fatalError("Server returned an invalid URL", EXIT.GENERAL);
49
+ }
50
+ if (target.origin !== base.origin) {
51
+ fatalError("Server returned a URL on a different origin; refusing to send credentials", EXIT.GENERAL);
52
+ }
53
+ return target.toString();
54
+ }
55
+
56
+ // src/config.ts
57
+ var CONF_OPTIONS = {
22
58
  projectName: "hisaabo",
23
59
  projectSuffix: "",
24
60
  configName: "config",
25
- encryptionKey: deriveEncryptionKey(),
26
61
  configFileMode: 384
27
- // owner read/write only — prevents credential theft on shared systems
28
- });
62
+ };
63
+ function legacyEncryptionKey() {
64
+ let uid;
65
+ try {
66
+ uid = String(userInfo().uid);
67
+ } catch {
68
+ uid = String(process.getuid?.() ?? process.pid);
69
+ }
70
+ return createHash("sha256").update(`${uid}:${hostname()}:hisaabo-cli`).digest("hex");
71
+ }
72
+ function hardenPermissions(file) {
73
+ try {
74
+ chmodSync(dirname(file), 448);
75
+ if (existsSync(file)) chmodSync(file, 384);
76
+ } catch {
77
+ }
78
+ }
79
+ function openConf() {
80
+ let c;
81
+ try {
82
+ c = new Conf(CONF_OPTIONS);
83
+ } catch {
84
+ try {
85
+ const legacy = new Conf({ ...CONF_OPTIONS, encryptionKey: legacyEncryptionKey() });
86
+ writeFileSync(legacy.path, JSON.stringify(legacy.store), { mode: 384 });
87
+ } catch {
88
+ new Conf({ ...CONF_OPTIONS, clearInvalidConfig: true });
89
+ warn("Saved credentials could not be read and were discarded. Run: hisaabo login");
90
+ }
91
+ c = new Conf(CONF_OPTIONS);
92
+ }
93
+ hardenPermissions(c.path);
94
+ return c;
95
+ }
96
+ var confInstance;
97
+ function conf() {
98
+ return confInstance ??= openConf();
99
+ }
29
100
  function getConfig() {
30
- return conf.store;
101
+ return conf().store;
31
102
  }
32
103
  function setConfig(values) {
33
104
  for (const [k, v] of Object.entries(values)) {
34
105
  if (v !== void 0) {
35
- conf.set(k, v);
106
+ conf().set(k, v);
36
107
  }
37
108
  }
109
+ hardenPermissions(conf().path);
38
110
  }
39
111
  function clearConfig() {
40
- conf.clear();
112
+ conf().clear();
113
+ hardenPermissions(conf().path);
41
114
  }
42
115
  function isAuthenticated() {
43
116
  const cfg = getConfig();
@@ -48,7 +121,7 @@ function requireAuth() {
48
121
  const envUrl = process.env["HISAABO_API_URL"];
49
122
  if (envToken && envUrl) {
50
123
  return {
51
- apiUrl: envUrl,
124
+ apiUrl: validateApiUrl(envUrl),
52
125
  token: envToken,
53
126
  tenantId: process.env["HISAABO_TENANT_ID"] ?? "",
54
127
  businessId: process.env["HISAABO_BUSINESS_ID"] ?? "",
@@ -57,7 +130,7 @@ function requireAuth() {
57
130
  };
58
131
  }
59
132
  const cfg = getConfig();
60
- if (!cfg.token || !cfg.apiUrl || !cfg.businessId || !cfg.tenantId) {
133
+ if (!cfg.token || !cfg.apiUrl || !cfg.businessId) {
61
134
  fatalError("Not authenticated. Run: hisaabo login", 3);
62
135
  }
63
136
  const isApiKey = cfg.token.startsWith("hisaabo_key_");
@@ -68,14 +141,14 @@ function requireAuth() {
68
141
  warn("Session expires soon. Run: hisaabo login");
69
142
  }
70
143
  }
71
- return cfg;
144
+ return { ...cfg, apiUrl: validateApiUrl(cfg.apiUrl), tenantId: cfg.tenantId ?? "" };
72
145
  }
73
146
  function requireTenantAuth() {
74
147
  const envToken = process.env["HISAABO_TOKEN"];
75
148
  const envUrl = process.env["HISAABO_API_URL"];
76
149
  if (envToken && envUrl) {
77
150
  return {
78
- apiUrl: envUrl,
151
+ apiUrl: validateApiUrl(envUrl),
79
152
  token: envToken,
80
153
  tenantId: process.env["HISAABO_TENANT_ID"] ?? "",
81
154
  businessId: process.env["HISAABO_BUSINESS_ID"] ?? "",
@@ -95,10 +168,10 @@ function requireTenantAuth() {
95
168
  warn("Session expires soon. Run: hisaabo login");
96
169
  }
97
170
  }
98
- return cfg;
171
+ return { ...cfg, apiUrl: validateApiUrl(cfg.apiUrl) };
99
172
  }
100
173
  function getConfigPath() {
101
- return conf.path;
174
+ return conf().path;
102
175
  }
103
176
  async function checkMaintenance(client) {
104
177
  try {
@@ -118,6 +191,8 @@ async function checkMaintenance(client) {
118
191
  }
119
192
 
120
193
  export {
194
+ validateApiUrl,
195
+ resolveSameOriginUrl,
121
196
  getConfig,
122
197
  setConfig,
123
198
  clearConfig,
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ hasColor
4
+ } from "./chunk-2DDIXPNI.js";
5
+
6
+ // src/dates.ts
7
+ var InvalidTimeZoneError = class extends Error {
8
+ constructor(tz, source) {
9
+ super(`Invalid time zone "${tz}" (${source}); expected an IANA name such as Asia/Kolkata or America/New_York`);
10
+ this.name = "InvalidTimeZoneError";
11
+ }
12
+ };
13
+ function assertValidTimeZone(tz, source) {
14
+ try {
15
+ new Intl.DateTimeFormat("en-US", { timeZone: tz });
16
+ } catch {
17
+ throw new InvalidTimeZoneError(tz, source);
18
+ }
19
+ return tz;
20
+ }
21
+ function resolveTimeZone(flag, env = process.env) {
22
+ if (flag !== void 0 && flag !== "") return assertValidTimeZone(flag, "--tz");
23
+ const fromEnv = env["HISAABO_TZ"];
24
+ if (fromEnv !== void 0 && fromEnv !== "") return assertValidTimeZone(fromEnv, "HISAABO_TZ");
25
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
26
+ }
27
+ var activeTimeZone;
28
+ function setTimeZone(flag) {
29
+ activeTimeZone = resolveTimeZone(flag);
30
+ return activeTimeZone;
31
+ }
32
+ function getTimeZone() {
33
+ activeTimeZone ??= resolveTimeZone();
34
+ return activeTimeZone;
35
+ }
36
+ var dtfCache = /* @__PURE__ */ new Map();
37
+ function dtf(tz) {
38
+ let f = dtfCache.get(tz);
39
+ if (!f) {
40
+ f = new Intl.DateTimeFormat("en-US", {
41
+ timeZone: tz,
42
+ hourCycle: "h23",
43
+ year: "numeric",
44
+ month: "numeric",
45
+ day: "numeric",
46
+ hour: "numeric",
47
+ minute: "numeric",
48
+ second: "numeric"
49
+ });
50
+ dtfCache.set(tz, f);
51
+ }
52
+ return f;
53
+ }
54
+ function zonedParts(ms, tz) {
55
+ const p = {};
56
+ for (const part of dtf(tz).formatToParts(new Date(ms))) {
57
+ if (part.type !== "literal") p[part.type] = Number(part.value);
58
+ }
59
+ return p;
60
+ }
61
+ function tzOffsetMs(ms, tz) {
62
+ const p = zonedParts(Math.floor(ms / 1e3) * 1e3, tz);
63
+ return Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) - Math.floor(ms / 1e3) * 1e3;
64
+ }
65
+ function zonedTimeToUtcMs({ year, month, day }, h, mi, s, ms, tz) {
66
+ const wall = Date.UTC(year, month - 1, day, h, mi, s, ms);
67
+ const DAY = 864e5;
68
+ const before = tzOffsetMs(wall - DAY, tz);
69
+ const after = tzOffsetMs(wall + DAY, tz);
70
+ const candidates = [.../* @__PURE__ */ new Set([before, after])].map((o) => wall - o).filter((c) => tzOffsetMs(c, tz) === wall - c).sort((x, y) => x - y);
71
+ return candidates[0] ?? wall - before;
72
+ }
73
+ function todayYmd(now = /* @__PURE__ */ new Date()) {
74
+ const p = zonedParts(now.getTime(), getTimeZone());
75
+ return { year: p.year, month: p.month, day: p.day };
76
+ }
77
+ var pad2 = (n) => String(n).padStart(2, "0");
78
+ var ymdString = ({ year, month, day }) => `${year}-${pad2(month)}-${pad2(day)}`;
79
+ function fyStartYear(now) {
80
+ const t = todayYmd(now);
81
+ return t.month >= 4 ? t.year : t.year - 1;
82
+ }
83
+ function currentFY(now) {
84
+ const y = fyStartYear(now);
85
+ return `${y}-${String(y + 1).slice(2)}`;
86
+ }
87
+ function fyStart(now) {
88
+ return `${fyStartYear(now)}-04-01`;
89
+ }
90
+ function todayISO(now) {
91
+ return ymdString(todayYmd(now));
92
+ }
93
+ function monthStart(now) {
94
+ const t = todayYmd(now);
95
+ return `${t.year}-${pad2(t.month)}-01`;
96
+ }
97
+ function monthEnd(now) {
98
+ const t = todayYmd(now);
99
+ const lastDay = new Date(Date.UTC(t.year, t.month, 0)).getUTCDate();
100
+ return `${t.year}-${pad2(t.month)}-${pad2(lastDay)}`;
101
+ }
102
+ function quarterRange(q, now) {
103
+ const fyYear = fyStartYear(now);
104
+ const ranges = {
105
+ Q1: { from: `${fyYear}-04-01`, to: `${fyYear}-06-30`, month: 4, year: fyYear },
106
+ Q2: { from: `${fyYear}-07-01`, to: `${fyYear}-09-30`, month: 7, year: fyYear },
107
+ Q3: { from: `${fyYear}-10-01`, to: `${fyYear}-12-31`, month: 10, year: fyYear },
108
+ Q4: { from: `${fyYear + 1}-01-01`, to: `${fyYear + 1}-03-31`, month: 1, year: fyYear + 1 }
109
+ };
110
+ const upper = q.toUpperCase();
111
+ return ranges[upper] ?? ranges["Q1"];
112
+ }
113
+ function toApiDateTime(date, edge = "start", tz = getTimeZone()) {
114
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
115
+ if (!m) return date;
116
+ const ymd = { year: Number(m[1]), month: Number(m[2]), day: Number(m[3]) };
117
+ const ms = edge === "start" ? zonedTimeToUtcMs(ymd, 0, 0, 0, 0, tz) : zonedTimeToUtcMs(ymd, 23, 59, 59, 999, tz);
118
+ return new Date(ms).toISOString();
119
+ }
120
+ function apiFrom(date) {
121
+ return date === void 0 ? void 0 : toApiDateTime(date, "start");
122
+ }
123
+ function apiTo(date) {
124
+ return date === void 0 ? void 0 : toApiDateTime(date, "end");
125
+ }
126
+
127
+ // src/format.ts
128
+ import chalk from "chalk";
129
+ function formatINR(amount) {
130
+ const num = typeof amount === "string" ? parseFloat(amount) : amount;
131
+ if (isNaN(num)) return "0.00";
132
+ const abs = Math.abs(num);
133
+ const formatted = new Intl.NumberFormat("en-IN", {
134
+ minimumFractionDigits: 2,
135
+ maximumFractionDigits: 2
136
+ }).format(abs);
137
+ return (num < 0 ? "-" : "") + "\u20B9" + formatted;
138
+ }
139
+ function formatAmount(amount) {
140
+ const num = typeof amount === "string" ? parseFloat(amount) : amount;
141
+ if (isNaN(num)) return "0.00";
142
+ const abs = Math.abs(num);
143
+ const formatted = new Intl.NumberFormat("en-IN", {
144
+ minimumFractionDigits: 2,
145
+ maximumFractionDigits: 2
146
+ }).format(abs);
147
+ return (num < 0 ? "-" : "") + formatted;
148
+ }
149
+ var MONTHS = [
150
+ "Jan",
151
+ "Feb",
152
+ "Mar",
153
+ "Apr",
154
+ "May",
155
+ "Jun",
156
+ "Jul",
157
+ "Aug",
158
+ "Sep",
159
+ "Oct",
160
+ "Nov",
161
+ "Dec"
162
+ ];
163
+ function formatDate(date) {
164
+ if (!date) return "-";
165
+ try {
166
+ const d = new Date(date);
167
+ if (isNaN(d.getTime())) return String(date);
168
+ const day = String(d.getDate()).padStart(2, "0");
169
+ const month = MONTHS[d.getMonth()];
170
+ const year = d.getFullYear();
171
+ return `${day} ${month} ${year}`;
172
+ } catch {
173
+ return String(date);
174
+ }
175
+ }
176
+ function formatRelativeDate(date) {
177
+ if (!date) return "-";
178
+ try {
179
+ const d = new Date(date);
180
+ const now = /* @__PURE__ */ new Date();
181
+ const diff = Math.floor((now.getTime() - d.getTime()) / (1e3 * 60 * 60 * 24));
182
+ if (diff === 0) return "Today";
183
+ if (diff === 1) return "Yesterday";
184
+ if (diff < 30) return `${diff}d ago`;
185
+ if (diff < 365) return `${Math.floor(diff / 30)}mo ago`;
186
+ return `${Math.floor(diff / 365)}y ago`;
187
+ } catch {
188
+ return date ? String(date) : "-";
189
+ }
190
+ }
191
+ var STATUS_CONFIG = {
192
+ paid: { label: "PAID", color: (s) => chalk.green(s) },
193
+ sent: { label: "SENT", color: (s) => chalk.blue(s) },
194
+ draft: { label: "DRAFT", color: (s) => chalk.dim(s) },
195
+ partial: { label: "PARTIAL", color: (s) => chalk.yellow(s) },
196
+ overdue: { label: "OVERDUE", color: (s) => chalk.red(s) },
197
+ cancelled: { label: "CANCEL", color: (s) => chalk.dim(chalk.strikethrough(s)) },
198
+ adjusted: { label: "ADJUST", color: (s) => chalk.magenta(s) },
199
+ unfulfilled: { label: "UNFUL", color: (s) => chalk.blue(s) },
200
+ pending: { label: "PEND", color: (s) => chalk.yellow(s) },
201
+ confirmed: { label: "CONF", color: (s) => chalk.blue(s) },
202
+ delivered: { label: "DELIV", color: (s) => chalk.green(s) },
203
+ shipped: { label: "SHIPPED", color: (s) => chalk.blue(s) },
204
+ in_transit: { label: "TRANSIT", color: (s) => chalk.cyan(s) },
205
+ returned: { label: "RETURN", color: (s) => chalk.red(s) },
206
+ preparing: { label: "PREP", color: (s) => chalk.yellow(s) },
207
+ ready: { label: "READY", color: (s) => chalk.cyan(s) }
208
+ };
209
+ function formatStatus(status) {
210
+ const cfg = STATUS_CONFIG[status.toLowerCase()];
211
+ const label = cfg ? `[${cfg.label}]` : `[${status.toUpperCase()}]`;
212
+ if (!hasColor() || !cfg) return label;
213
+ return cfg.color(label);
214
+ }
215
+ function deliveryMethodLabel(method) {
216
+ const map = {
217
+ self_pickup: "Self Pickup",
218
+ hand_delivery: "Hand Delivery",
219
+ courier: "Courier",
220
+ bus: "Bus",
221
+ transport: "Transport",
222
+ post: "Post"
223
+ };
224
+ return map[method] ?? method;
225
+ }
226
+
227
+ export {
228
+ InvalidTimeZoneError,
229
+ setTimeZone,
230
+ currentFY,
231
+ fyStart,
232
+ todayISO,
233
+ monthStart,
234
+ monthEnd,
235
+ quarterRange,
236
+ toApiDateTime,
237
+ apiFrom,
238
+ apiTo,
239
+ formatINR,
240
+ formatAmount,
241
+ formatDate,
242
+ formatRelativeDate,
243
+ formatStatus,
244
+ deliveryMethodLabel
245
+ };