@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,91 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, EXIT, hasColor } from "../../output.js";
4
- import type { ColumnDef } from "../../output.js";
5
- import chalk from "chalk";
6
-
7
- interface ListSessionsOpts {
8
- expired?: boolean;
9
- json?: boolean;
10
- }
11
-
12
- export async function listSessionsCommand(opts: ListSessionsOpts): Promise<void> {
13
- const cfg = requireAuth();
14
- const client = new HisaaboClient(cfg);
15
-
16
- try {
17
- const sessions = await client.auth.listSessions({ expired: opts.expired ?? false });
18
-
19
- if (opts.json) {
20
- outputJSON(sessions);
21
- return;
22
- }
23
-
24
- const items: unknown[] = Array.isArray(sessions) ? sessions : (sessions?.items ?? sessions?.data ?? []);
25
-
26
- if (items.length === 0) {
27
- console.log(opts.expired ? "No expired sessions." : "No active sessions.");
28
- return;
29
- }
30
-
31
- const rows = items.map((item: unknown) => {
32
- const s = item as Record<string, unknown>;
33
- return {
34
- id: String(s["id"] ?? "").slice(0, 12) + "...",
35
- device: s["userAgent"] ? parseUA(String(s["userAgent"])) : "Unknown",
36
- ip: String(s["ipAddress"] ?? "\u2014"),
37
- lastUsed: s["lastUsedAt"] ? timeAgo(String(s["lastUsedAt"])) : "\u2014",
38
- created: s["createdAt"] ? new Date(String(s["createdAt"])).toLocaleDateString() : "\u2014",
39
- current: s["isCurrent"] ? "\u2713" : "",
40
- };
41
- });
42
-
43
- const columns: ColumnDef<typeof rows[number]>[] = [
44
- { key: "id", header: "ID", align: "left" },
45
- { key: "device", header: "Device", align: "left" },
46
- { key: "ip", header: "IP", align: "left" },
47
- { key: "lastUsed", header: "Last Used", align: "left" },
48
- { key: "created", header: "Created", align: "left" },
49
- { key: "current", header: "Current", align: "left" },
50
- ];
51
-
52
- if (hasColor()) process.stdout.write("\n" + chalk.bold(" Sessions\n") + "\n");
53
- else process.stdout.write("\n Sessions\n\n");
54
- outputTable(rows, columns);
55
- process.stdout.write("\n");
56
- } catch (e) {
57
- if (e instanceof HisaaboApiError) {
58
- const err = e.hisaaboError;
59
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
60
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
61
- }
62
- fatalError(String(e instanceof Error ? e.message : e));
63
- }
64
- }
65
-
66
- function parseUA(ua: string): string {
67
- let browser = "Unknown";
68
- if (ua.includes("Edg/")) browser = "Edge";
69
- else if (ua.includes("Chrome/")) browser = "Chrome";
70
- else if (ua.includes("Firefox/")) browser = "Firefox";
71
- else if (ua.includes("Safari/")) browser = "Safari";
72
-
73
- let os = "";
74
- if (ua.includes("Windows")) os = "Windows";
75
- else if (ua.includes("Mac OS")) os = "macOS";
76
- else if (ua.includes("Linux")) os = "Linux";
77
- else if (ua.includes("Android")) os = "Android";
78
- else if (ua.includes("iPhone") || ua.includes("iPad")) os = "iOS";
79
-
80
- return os ? `${browser} / ${os}` : browser;
81
- }
82
-
83
- function timeAgo(date: string): string {
84
- const diff = Date.now() - new Date(date).getTime();
85
- const mins = Math.floor(diff / 60000);
86
- if (mins < 1) return "now";
87
- if (mins < 60) return `${mins}m ago`;
88
- const hrs = Math.floor(mins / 60);
89
- if (hrs < 24) return `${hrs}h ago`;
90
- return `${Math.floor(hrs / 24)}d ago`;
91
- }
@@ -1,20 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, success, EXIT } from "../../output.js";
4
-
5
- export async function revokeAllSessionsCommand(): Promise<void> {
6
- const cfg = requireAuth();
7
- const client = new HisaaboClient(cfg);
8
-
9
- try {
10
- await client.auth.logoutAll();
11
- success("Signed out from all devices.");
12
- } catch (e) {
13
- if (e instanceof HisaaboApiError) {
14
- const err = e.hisaaboError;
15
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
16
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
17
- }
18
- fatalError(String(e instanceof Error ? e.message : e));
19
- }
20
- }
@@ -1,32 +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 RevokeSessionOpts {
6
- json?: boolean;
7
- }
8
-
9
- export async function revokeSessionCommand(sessionId: string, opts: RevokeSessionOpts): Promise<void> {
10
- const cfg = requireAuth();
11
- const client = new HisaaboClient(cfg);
12
-
13
- try {
14
- const result = await client.auth.revokeSession({ sessionId });
15
-
16
- if (opts.json) {
17
- outputJSON(result);
18
- return;
19
- }
20
-
21
- success("Session revoked successfully.");
22
- } catch (e) {
23
- if (e instanceof HisaaboApiError) {
24
- const err = e.hisaaboError;
25
- if (err.code === "not_found") fatalError(`Session not found: ${sessionId}`, EXIT.NOT_FOUND);
26
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
27
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
28
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
29
- }
30
- fatalError(String(e instanceof Error ? e.message : e));
31
- }
32
- }
@@ -1,170 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError, type ShipmentSummary } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- fatalError, outputJSON, outputTable, paginationFooter, EXIT, success, type ColumnDef,
5
- } from "../../output.js";
6
- import { formatDate, formatStatus } from "../../format.js";
7
-
8
- interface ListOpts {
9
- json?: boolean;
10
- status?: string;
11
- invoiceId?: string;
12
- page?: number;
13
- limit?: number;
14
- }
15
-
16
- export async function shipmentListCommand(opts: ListOpts): Promise<void> {
17
- const cfg = requireAuth();
18
- const client = new HisaaboClient(cfg);
19
- const page = opts.page ?? 1;
20
- const limit = opts.limit ?? 20;
21
-
22
- try {
23
- const result = await client.shipment.list({
24
- status: opts.status as ShipmentSummary["status"] | undefined ?? null,
25
- invoiceId: opts.invoiceId ?? null,
26
- page,
27
- limit,
28
- });
29
-
30
- if (opts.json) {
31
- outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
32
- return;
33
- }
34
-
35
- console.log(`\n Shipments ${result.total} total\n`);
36
-
37
- const cols: ColumnDef<ShipmentSummary>[] = [
38
- { key: "invoiceNumber", header: "Invoice", width: 12, format: (v) => String(v ?? "-") },
39
- { key: "partyName", header: "Party", width: 18, format: (v) => String(v ?? "-") },
40
- { key: "carrier", header: "Carrier", width: 12, format: (v) => String(v ?? "-") },
41
- { key: "trackingNumber", header: "Tracking", width: 16, format: (v) => String(v ?? "-") },
42
- { key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
43
- { key: "shipmentDate", header: "Shipped", width: 12, format: (v) => formatDate(v ? String(v) : null) },
44
- ];
45
-
46
- outputTable(result.data, cols);
47
- paginationFooter(result.page, result.limit, result.total);
48
-
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 === "network_error") fatalError(err.message, EXIT.NETWORK);
54
- }
55
- fatalError(String(e instanceof Error ? e.message : e));
56
- }
57
- }
58
-
59
- export async function shipmentGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
60
- const cfg = requireAuth();
61
- const client = new HisaaboClient(cfg);
62
-
63
- try {
64
- const shipment = await client.shipment.get(id);
65
- if (!shipment) fatalError(`Shipment not found: ${id}`, EXIT.NOT_FOUND);
66
-
67
- if (opts.json) {
68
- outputJSON(shipment);
69
- return;
70
- }
71
-
72
- console.log(`\n Shipment ${id}`);
73
- console.log(" " + "─".repeat(45));
74
- if (shipment!.invoiceNumber) console.log(` Invoice: ${shipment!.invoiceNumber}`);
75
- if (shipment!.partyName) console.log(` Party: ${shipment!.partyName}`);
76
- if (shipment!.carrier) console.log(` Carrier: ${shipment!.carrier}`);
77
- if (shipment!.trackingNumber) console.log(` Tracking: ${shipment!.trackingNumber}`);
78
- if (shipment!.trackingUrl) console.log(` URL: ${shipment!.trackingUrl}`);
79
- console.log(` Status: ${formatStatus(shipment!.status)}`);
80
- if (shipment!.shipmentDate) console.log(` Shipped: ${formatDate(shipment!.shipmentDate)}`);
81
- if (shipment!.estimatedDelivery) console.log(` Est. Del: ${formatDate(shipment!.estimatedDelivery)}`);
82
- if (shipment!.actualDelivery) console.log(` Delivered:${formatDate(shipment!.actualDelivery)}`);
83
- console.log();
84
-
85
- } catch (e) {
86
- if (e instanceof HisaaboApiError) {
87
- const err = e.hisaaboError;
88
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
89
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
90
- }
91
- fatalError(String(e instanceof Error ? e.message : e));
92
- }
93
- }
94
-
95
- export async function shipmentCreateCommand(opts: {
96
- json?: boolean;
97
- invoiceId?: string;
98
- partyId?: string;
99
- carrier?: string;
100
- tracking?: string;
101
- mode?: string;
102
- date?: string;
103
- }): Promise<void> {
104
- const cfg = requireAuth();
105
- const client = new HisaaboClient(cfg);
106
-
107
- try {
108
- const shipment = await client.shipment.create({
109
- invoiceId: opts.invoiceId,
110
- partyId: opts.partyId,
111
- carrier: opts.carrier,
112
- trackingNumber: opts.tracking,
113
- mode: opts.mode,
114
- shipmentDate: opts.date,
115
- });
116
-
117
- if (opts.json) {
118
- outputJSON(shipment);
119
- return;
120
- }
121
-
122
- success(`Shipment created: ${shipment.id}`);
123
- if (shipment.trackingNumber) console.log(` Tracking: ${shipment.trackingNumber}`);
124
- console.log();
125
-
126
- } catch (e) {
127
- if (e instanceof HisaaboApiError) {
128
- const err = e.hisaaboError;
129
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
130
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
131
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
132
- }
133
- fatalError(String(e instanceof Error ? e.message : e));
134
- }
135
- }
136
-
137
- export async function shipmentUpdateCommand(id: string, opts: {
138
- json?: boolean;
139
- status?: string;
140
- tracking?: string;
141
- carrier?: string;
142
- }): Promise<void> {
143
- const cfg = requireAuth();
144
- const client = new HisaaboClient(cfg);
145
-
146
- try {
147
- const shipment = await client.shipment.update({
148
- id,
149
- status: opts.status as ShipmentSummary["status"] | undefined,
150
- trackingNumber: opts.tracking,
151
- carrier: opts.carrier,
152
- });
153
-
154
- if (opts.json) {
155
- outputJSON(shipment);
156
- return;
157
- }
158
-
159
- success(`Shipment updated: ${formatStatus(shipment.status)}`);
160
-
161
- } catch (e) {
162
- if (e instanceof HisaaboApiError) {
163
- const err = e.hisaaboError;
164
- if (err.code === "not_found") fatalError(`Shipment not found: ${id}`, EXIT.NOT_FOUND);
165
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
166
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
167
- }
168
- fatalError(String(e instanceof Error ? e.message : e));
169
- }
170
- }
@@ -1,48 +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 storeCheckSlugCommand(
7
- slug: string,
8
- opts: { json?: boolean },
9
- ): Promise<void> {
10
- const cfg = requireAuth();
11
- const client = new HisaaboClient(cfg);
12
-
13
- try {
14
- const result = await client.store.checkSlug({ slug });
15
-
16
- if (opts.json) {
17
- outputJSON(result);
18
- return;
19
- }
20
-
21
- const available =
22
- typeof result === "object" && result !== null
23
- ? (result as Record<string, unknown>)["available"]
24
- : result;
25
-
26
- if (available) {
27
- if (hasColor()) {
28
- process.stdout.write(chalk.green(`\n ✓ "${slug}" is available\n\n`));
29
- } else {
30
- process.stdout.write(`\n OK: "${slug}" is available\n\n`);
31
- }
32
- } else {
33
- if (hasColor()) {
34
- process.stdout.write(chalk.red(`\n ✗ "${slug}" is already taken\n\n`));
35
- } else {
36
- process.stdout.write(`\n TAKEN: "${slug}" is already taken\n\n`);
37
- }
38
- }
39
- } catch (e) {
40
- if (e instanceof HisaaboApiError) {
41
- const err = e.hisaaboError;
42
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
43
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
44
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
45
- }
46
- fatalError(String(e instanceof Error ? e.message : e));
47
- }
48
- }
@@ -1,77 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError, type StoreOrderSummary } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- fatalError, outputJSON, outputTable, paginationFooter, EXIT, type ColumnDef,
5
- } from "../../output.js";
6
- import { formatDate, formatAmount, formatStatus } from "../../format.js";
7
-
8
- export async function storeSettingsCommand(opts: { json?: boolean }): Promise<void> {
9
- const cfg = requireAuth();
10
- const client = new HisaaboClient(cfg);
11
-
12
- try {
13
- const settings = await client.store.getSettings();
14
-
15
- if (opts.json) {
16
- outputJSON(settings);
17
- return;
18
- }
19
-
20
- console.log("\n Store Settings\n " + "─".repeat(35));
21
- console.log(` Enabled: ${settings.storeEnabled ? "Yes" : "No"}`);
22
- if (settings.storeSlug) console.log(` Slug: ${settings.storeSlug}`);
23
- if (settings.storeName) console.log(` Name: ${settings.storeName}`);
24
- if (settings.storeDescription) console.log(` About: ${settings.storeDescription}`);
25
- console.log();
26
-
27
- } catch (e) {
28
- if (e instanceof HisaaboApiError) {
29
- const err = e.hisaaboError;
30
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
31
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
32
- }
33
- fatalError(String(e instanceof Error ? e.message : e));
34
- }
35
- }
36
-
37
- export async function storeOrdersCommand(opts: {
38
- json?: boolean;
39
- status?: string;
40
- page?: number;
41
- limit?: number;
42
- }): Promise<void> {
43
- const cfg = requireAuth();
44
- const client = new HisaaboClient(cfg);
45
- const page = opts.page ?? 1;
46
- const limit = opts.limit ?? 20;
47
-
48
- try {
49
- const result = await client.store.listOrders({ status: opts.status ?? null, page, limit });
50
-
51
- if (opts.json) {
52
- outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
53
- return;
54
- }
55
-
56
- console.log(`\n Store Orders ${result.total} total\n`);
57
-
58
- const cols: ColumnDef<StoreOrderSummary>[] = [
59
- { key: "orderNumber", header: "#", width: 12 },
60
- { key: "customerName", header: "Customer", width: 20 },
61
- { key: "createdAt", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
62
- { key: "totalAmount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
63
- { key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
64
- ];
65
-
66
- outputTable(result.data, cols);
67
- paginationFooter(result.page, result.limit, result.total);
68
-
69
- } catch (e) {
70
- if (e instanceof HisaaboApiError) {
71
- const err = e.hisaaboError;
72
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
73
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
74
- }
75
- fatalError(String(e instanceof Error ? e.message : e));
76
- }
77
- }
@@ -1,41 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { outputJSON, EXIT, fatalError, success } from "../../output.js";
4
-
5
- export async function storeItemsToggleCommand(opts: {
6
- enable?: string;
7
- disable?: string;
8
- json?: boolean;
9
- }): Promise<void> {
10
- const cfg = requireAuth();
11
- const client = new HisaaboClient(cfg);
12
-
13
- if (!opts.enable && !opts.disable) {
14
- fatalError("At least one of --enable or --disable is required", EXIT.USAGE);
15
- }
16
-
17
- const enableIds = opts.enable ? opts.enable.split(",").map((s) => s.trim()).filter(Boolean) : [];
18
- const disableIds = opts.disable ? opts.disable.split(",").map((s) => s.trim()).filter(Boolean) : [];
19
-
20
- try {
21
- const result = await client.store.bulkToggleItems({ enable: enableIds, disable: disableIds });
22
-
23
- if (opts.json) {
24
- outputJSON(result);
25
- return;
26
- }
27
-
28
- if (enableIds.length > 0) success(`Enabled ${enableIds.length} item(s)`);
29
- if (disableIds.length > 0) success(`Disabled ${disableIds.length} item(s)`);
30
- console.log();
31
-
32
- } catch (e) {
33
- if (e instanceof HisaaboApiError) {
34
- const err = e.hisaaboError;
35
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
36
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
37
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
38
- }
39
- fatalError(String(e instanceof Error ? e.message : e));
40
- }
41
- }
@@ -1,61 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- outputJSON, outputTable, outputTSV, outputCSV, EXIT, fatalError, type ColumnDef,
5
- } from "../../output.js";
6
- import { formatAmount } from "../../format.js";
7
-
8
- interface StoreItem {
9
- id: string;
10
- name: string;
11
- price: string;
12
- enabled: boolean;
13
- stock: number | null;
14
- [key: string]: unknown;
15
- }
16
-
17
- export async function storeItemsCommand(opts: {
18
- json?: boolean;
19
- format?: string;
20
- }): Promise<void> {
21
- const cfg = requireAuth();
22
- const client = new HisaaboClient(cfg);
23
-
24
- try {
25
- const items: StoreItem[] = await client.store.listStoreItems({});
26
-
27
- if (opts.json) {
28
- outputJSON(items);
29
- return;
30
- }
31
-
32
- const cols: ColumnDef<StoreItem>[] = [
33
- { key: "id", header: "ID", width: 36 },
34
- { key: "name", header: "Name", width: 30 },
35
- { key: "price", header: "Price (₹)", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
36
- { key: "enabled", header: "Status", width: 10, format: (v) => v ? "Enabled" : "Disabled" },
37
- { key: "stock", header: "Stock", align: "right", width: 8, format: (v) => v == null ? "-" : String(v) },
38
- ];
39
-
40
- if (opts.format === "tsv") {
41
- outputTSV(items, cols);
42
- return;
43
- }
44
- if (opts.format === "csv") {
45
- outputCSV(items, cols);
46
- return;
47
- }
48
-
49
- console.log(`\n Store Items (${items.length} total)\n`);
50
- outputTable(items, cols);
51
- console.log();
52
-
53
- } catch (e) {
54
- if (e instanceof HisaaboApiError) {
55
- const err = e.hisaaboError;
56
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
57
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
58
- }
59
- fatalError(String(e instanceof Error ? e.message : e));
60
- }
61
- }
@@ -1,48 +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
- export async function storeOrderCancelCommand(
7
- id: string,
8
- opts: { json?: boolean; yes?: boolean; reason?: string },
9
- ): Promise<void> {
10
- const cfg = requireAuth();
11
- const client = new HisaaboClient(cfg);
12
-
13
- if (!opts.yes && process.stdin.isTTY) {
14
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
15
- const answer = await new Promise<string>((resolve) => {
16
- rl.question(` Cancel order ${id}? This cannot be undone. (y/n): `, resolve);
17
- });
18
- rl.close();
19
- if (answer.trim().toLowerCase() !== "y") {
20
- console.log(" Cancelled.");
21
- process.exit(0);
22
- }
23
- }
24
-
25
- try {
26
- const input: Record<string, unknown> = { orderId: id };
27
- if (opts.reason) input["reason"] = opts.reason;
28
-
29
- const result = await client.store.cancelOrder(input);
30
-
31
- if (opts.json) {
32
- outputJSON(result);
33
- return;
34
- }
35
-
36
- success(`Order ${id} cancelled`);
37
- console.log();
38
- } catch (e) {
39
- if (e instanceof HisaaboApiError) {
40
- const err = e.hisaaboError;
41
- if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
42
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
43
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
44
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
45
- }
46
- fatalError(String(e instanceof Error ? e.message : e));
47
- }
48
- }
@@ -1,45 +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
- export async function storeOrderConfirmCommand(
7
- id: string,
8
- opts: { json?: boolean; yes?: boolean },
9
- ): Promise<void> {
10
- const cfg = requireAuth();
11
- const client = new HisaaboClient(cfg);
12
-
13
- if (!opts.yes && process.stdin.isTTY) {
14
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
15
- const answer = await new Promise<string>((resolve) => {
16
- rl.question(` Confirm order ${id}? (y/n): `, resolve);
17
- });
18
- rl.close();
19
- if (answer.trim().toLowerCase() !== "y") {
20
- console.log(" Cancelled.");
21
- process.exit(0);
22
- }
23
- }
24
-
25
- try {
26
- const result = await client.store.confirmOrder({ orderId: id });
27
-
28
- if (opts.json) {
29
- outputJSON(result);
30
- return;
31
- }
32
-
33
- success(`Order ${id} confirmed`);
34
- console.log();
35
- } catch (e) {
36
- if (e instanceof HisaaboApiError) {
37
- const err = e.hisaaboError;
38
- if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
39
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
40
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
41
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
42
- }
43
- fatalError(String(e instanceof Error ? e.message : e));
44
- }
45
- }