@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
package/src/auth.ts DELETED
@@ -1,221 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "./client.js";
2
- import { getConfig, setConfig, clearConfig, requireAuth, getConfigPath } from "./config.js";
3
- import { fatalError, EXIT, outputJSON, success } from "./output.js";
4
-
5
- function validateApiUrl(url: string): string {
6
- const parsed = new URL(url);
7
- if (!["http:", "https:"].includes(parsed.protocol)) {
8
- fatalError("API URL must use http:// or https://", EXIT.USAGE);
9
- }
10
- return parsed.origin + parsed.pathname.replace(/\/$/, "");
11
- }
12
-
13
- /**
14
- * Authenticate using a long-lived API key (hisaabo_key_...).
15
- * Validates the token by calling auth.me, then stores it in config.
16
- */
17
- export async function loginWithToken(apiUrl: string, token: string): Promise<void> {
18
- const base = validateApiUrl(apiUrl);
19
-
20
- // Use a temporary client with the token but no business/tenant yet
21
- const client = new HisaaboClient({
22
- apiUrl: base,
23
- token,
24
- tenantId: "",
25
- businessId: "",
26
- });
27
-
28
- let user: AuthUser;
29
- try {
30
- user = await client.auth.me();
31
- } catch (e) {
32
- if (e instanceof HisaaboApiError) {
33
- const err = e.hisaaboError;
34
- if (err.code === "unauthorized") fatalError("Invalid or expired API key.", EXIT.AUTH);
35
- if (err.code === "network_error") fatalError("Cannot reach server: " + err.message, EXIT.NETWORK);
36
- }
37
- fatalError(String(e instanceof Error ? e.message : e), EXIT.GENERAL);
38
- return; // unreachable — fatalError throws, but satisfies TS control flow
39
- }
40
-
41
- // Temporarily store the token so business.list() can authenticate
42
- setConfig({ apiUrl: base, token });
43
-
44
- const authedClient = new HisaaboClient({
45
- apiUrl: base,
46
- token,
47
- tenantId: "",
48
- businessId: "",
49
- });
50
-
51
- let businesses: BusinessSummary[];
52
- try {
53
- businesses = await authedClient.business.list();
54
- } catch {
55
- businesses = [];
56
- }
57
-
58
- if (businesses.length === 0) {
59
- fatalError("No businesses found for this account.", EXIT.GENERAL);
60
- }
61
-
62
- console.log("\n You have access to " + businesses.length + " business" + (businesses.length > 1 ? "es" : "") + ":\n");
63
- console.log(" # Business" + " ".repeat(22) + "GSTIN" + " ".repeat(15) + "Role");
64
- console.log(" " + "─".repeat(58));
65
- businesses.forEach((b, i) => {
66
- const name = b.name.padEnd(26);
67
- const gstin = (b.gstin ?? "-").padEnd(19);
68
- console.log(` ${i + 1} ${name} ${gstin} ${b.gstRegistrationType ?? "member"}`);
69
- });
70
- console.log();
71
-
72
- let selected = businesses[0];
73
- if (businesses.length > 1) {
74
- const readline = await import("readline");
75
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
76
- const answer = await new Promise<string>((resolve) => {
77
- rl.question(" Select business [1]: ", resolve);
78
- });
79
- rl.close();
80
- const idx = parseInt(answer.trim() || "1", 10) - 1;
81
- selected = businesses[Math.max(0, Math.min(idx, businesses.length - 1))];
82
- }
83
-
84
- if (!selected) {
85
- fatalError("No business selected.", EXIT.GENERAL);
86
- }
87
-
88
- setConfig({
89
- businessId: selected.id,
90
- businessName: selected.name,
91
- tenantId: selected.id,
92
- tokenCreatedAt: Date.now(),
93
- });
94
-
95
- success(`Authenticated as ${user.name ?? user.email} (${user.email}) via API key`);
96
- console.log(" Active business: " + selected.name);
97
- console.log(" Config saved to " + getConfigPath() + "\n");
98
- }
99
-
100
- // Type aliases used locally (mirrors what the client returns)
101
- type AuthUser = { id: string; email: string; name: string | null; role: string };
102
- type BusinessSummary = { id: string; name: string; gstin?: string | null; gstRegistrationType?: string | null };
103
-
104
- export async function login(apiUrl: string, email: string, password: string): Promise<void> {
105
- const base = validateApiUrl(apiUrl);
106
-
107
- // Use a temporary client without auth for login
108
- const client = new HisaaboClient({
109
- apiUrl: base,
110
- token: "",
111
- tenantId: "",
112
- businessId: "",
113
- });
114
-
115
- try {
116
- const result = await client.auth.login({ email, password });
117
- // After login, fetch businesses
118
- const authedClient = new HisaaboClient({
119
- apiUrl: base,
120
- token: result.sessionId,
121
- tenantId: "",
122
- businessId: "",
123
- });
124
- const businesses = await authedClient.business.list();
125
-
126
- if (businesses.length === 0) {
127
- fatalError("No businesses found for this account.", EXIT.GENERAL);
128
- }
129
-
130
- setConfig({
131
- apiUrl: base,
132
- token: result.sessionId,
133
- });
134
-
135
- // Return businesses for caller to handle selection
136
- console.log("\n You have access to " + businesses.length + " business" + (businesses.length > 1 ? "es" : "") + ":\n");
137
- console.log(" # Business" + " ".repeat(22) + "GSTIN" + " ".repeat(15) + "Role");
138
- console.log(" " + "─".repeat(58));
139
- businesses.forEach((b, i) => {
140
- const name = b.name.padEnd(26);
141
- const gstin = (b.gstin ?? "-").padEnd(19);
142
- console.log(` ${i + 1} ${name} ${gstin} ${b.gstRegistrationType ?? "member"}`);
143
- });
144
- console.log();
145
-
146
- // Default to first if only one
147
- let selected = businesses[0];
148
- if (businesses.length > 1) {
149
- const readline = await import("readline");
150
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
151
- const answer = await new Promise<string>((resolve) => {
152
- rl.question(" Select business [1]: ", resolve);
153
- });
154
- rl.close();
155
- const idx = parseInt(answer.trim() || "1", 10) - 1;
156
- selected = businesses[Math.max(0, Math.min(idx, businesses.length - 1))];
157
- }
158
-
159
- if (!selected) {
160
- fatalError("No business selected.", EXIT.GENERAL);
161
- }
162
-
163
- setConfig({
164
- businessId: selected.id,
165
- businessName: selected.name,
166
- tenantId: selected.id, // fallback; real tenantId may differ
167
- tokenCreatedAt: Date.now(),
168
- });
169
-
170
- success(`Active business: ${selected.name}`);
171
- console.log(" Config saved to " + getConfigPath());
172
- console.log("\n You can switch businesses anytime with:");
173
- console.log(" hisaabo business switch\n");
174
- } catch (e) {
175
- if (e instanceof HisaaboApiError) {
176
- const err = e.hisaaboError;
177
- if (err.code === "unauthorized") fatalError("Invalid email or password.", EXIT.AUTH);
178
- if (err.code === "network_error") fatalError("Cannot reach server: " + err.message, EXIT.NETWORK);
179
- }
180
- fatalError(String(e instanceof Error ? e.message : e), EXIT.GENERAL);
181
- }
182
- }
183
-
184
- export async function logout(): Promise<void> {
185
- if (!getConfig().token) {
186
- console.log("Not logged in.");
187
- return;
188
- }
189
- try {
190
- const cfg = requireAuth();
191
- const client = new HisaaboClient(cfg);
192
- await client.auth.logout();
193
- } catch {
194
- // ignore errors on logout
195
- }
196
- clearConfig();
197
- success("Logged out.");
198
- }
199
-
200
- export async function whoami(jsonMode: boolean): Promise<void> {
201
- const cfg = requireAuth();
202
- const client = new HisaaboClient(cfg);
203
- try {
204
- const user = await client.auth.me();
205
- if (jsonMode) {
206
- outputJSON({ user, business: { id: cfg.businessId, name: cfg.businessName }, apiUrl: cfg.apiUrl });
207
- return;
208
- }
209
- console.log(` User: ${user.name} <${user.email}>`);
210
- console.log(` Role: ${user.role}`);
211
- console.log(` Business: ${cfg.businessName} (${cfg.businessId})`);
212
- console.log(` API: ${cfg.apiUrl}`);
213
- } catch (e) {
214
- if (e instanceof HisaaboApiError) {
215
- const err = e.hisaaboError;
216
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
217
- fatalError(e.message, EXIT.GENERAL);
218
- }
219
- fatalError(String(e instanceof Error ? e.message : e), EXIT.GENERAL);
220
- }
221
- }
@@ -1,74 +0,0 @@
1
- import { Command } from "commander";
2
- import { fatalError } from "../output.js";
3
-
4
- import { registerAuthCommands } from "./registrars/auth.js";
5
- import { registerDashboardCommands } from "./registrars/dashboard.js";
6
- import { registerInvoiceCommands } from "./registrars/invoice.js";
7
- import { registerPartyCommands } from "./registrars/party.js";
8
- import { registerItemCommands } from "./registrars/item.js";
9
- import { registerPaymentCommands } from "./registrars/payment.js";
10
- import { registerExpenseCommands } from "./registrars/expense.js";
11
- import { registerGstCommands } from "./registrars/gst.js";
12
- import { registerReportCommands } from "./registrars/report.js";
13
- import { registerBankCommands } from "./registrars/bank.js";
14
- import { registerShipmentCommands } from "./registrars/shipment.js";
15
- import { registerTargetCommands } from "./registrars/target.js";
16
- import { registerStoreCommands } from "./registrars/store.js";
17
- import { registerImportCommands } from "./registrars/import.js";
18
- import { registerAutomatedInvoiceCommands } from "./registrars/automated-invoice.js";
19
- import { registerBusinessCommands } from "./registrars/business.js";
20
- import { registerDocumentCommands } from "./registrars/document.js";
21
- import { registerTenantCommands } from "./registrars/tenant.js";
22
- import { registerApiKeyCommands } from "./registrars/api-key.js";
23
- import { registerSessionCommands } from "./registrars/session.js";
24
- import { registerJournalCommands } from "./registrars/journal.js";
25
- import { registerItcCommands } from "./registrars/itc.js";
26
- import { registerBankReconCommands } from "./registrars/bank-recon.js";
27
- import { registerEInvoiceCommands } from "./registrars/einvoice.js";
28
- import { registerEwbCommands } from "./registrars/ewb.js";
29
-
30
- // ── Program ───────────────────────────────────────────────────────────────
31
-
32
- const program = new Command();
33
-
34
- declare const __CLI_VERSION__: string | undefined;
35
- const cliVersion = typeof __CLI_VERSION__ !== "undefined" ? __CLI_VERSION__ : "dev";
36
-
37
- program
38
- .name("hisaabo")
39
- .description("Hisaabo CLI — Invoicing and business management")
40
- .version(cliVersion);
41
-
42
- // ── Register all command groups ───────────────────────────────────────────
43
-
44
- registerAuthCommands(program);
45
- registerDashboardCommands(program);
46
- registerInvoiceCommands(program);
47
- registerPartyCommands(program);
48
- registerItemCommands(program);
49
- registerPaymentCommands(program);
50
- registerExpenseCommands(program);
51
- registerGstCommands(program);
52
- registerReportCommands(program);
53
- registerBankCommands(program);
54
- registerShipmentCommands(program);
55
- registerTargetCommands(program);
56
- registerStoreCommands(program);
57
- registerImportCommands(program);
58
- registerAutomatedInvoiceCommands(program);
59
- registerBusinessCommands(program);
60
- registerDocumentCommands(program);
61
- registerTenantCommands(program);
62
- registerApiKeyCommands(program);
63
- registerSessionCommands(program);
64
- registerJournalCommands(program);
65
- registerItcCommands(program);
66
- registerBankReconCommands(program);
67
- registerEInvoiceCommands(program);
68
- registerEwbCommands(program);
69
-
70
- // ── Run ────────────────────────────────────────────────────────────────────
71
-
72
- program.parseAsync(process.argv).catch((err) => {
73
- fatalError(String(err instanceof Error ? err.message : err));
74
- });
@@ -1,44 +0,0 @@
1
- import { Command } from "commander";
2
-
3
- export function registerApiKeyCommands(program: Command): void {
4
- const apiKey = program
5
- .command("api-key")
6
- .alias("key")
7
- .description("API key management");
8
-
9
- // ── list ──────────────────────────────────────────────────────────────────
10
-
11
- apiKey
12
- .command("list")
13
- .description("List all API keys")
14
- .option("--json", "JSON output")
15
- .option("--format <fmt>", "Output format: table, tsv, csv")
16
- .action(async (opts) => {
17
- const { apiKeyListCommand } = await import("../../commands/api-key/list.js");
18
- await apiKeyListCommand(opts);
19
- });
20
-
21
- // ── create ────────────────────────────────────────────────────────────────
22
-
23
- apiKey
24
- .command("create")
25
- .description("Create a new API key")
26
- .requiredOption("--name <name>", "Name / label for this key")
27
- .option("--json", "JSON output")
28
- .action(async (opts) => {
29
- const { apiKeyCreateCommand } = await import("../../commands/api-key/create.js");
30
- await apiKeyCreateCommand(opts);
31
- });
32
-
33
- // ── revoke ────────────────────────────────────────────────────────────────
34
-
35
- apiKey
36
- .command("revoke <id>")
37
- .description("Revoke an API key by ID")
38
- .option("--yes", "Skip confirmation prompt")
39
- .option("--json", "JSON output")
40
- .action(async (id: string, opts) => {
41
- const { apiKeyRevokeCommand } = await import("../../commands/api-key/revoke.js");
42
- await apiKeyRevokeCommand(id, opts);
43
- });
44
- }
@@ -1,222 +0,0 @@
1
- import { Command } from "commander";
2
- import * as readline from "readline";
3
- import { login, loginWithToken, logout, whoami } from "../../auth.js";
4
- import { setConfig, requireAuth } from "../../config.js";
5
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
6
- import { fatalError, success, EXIT, outputJSON } from "../../output.js";
7
-
8
- // ── Helpers ──────────────────────────────────────────────────────────────────
9
-
10
- function ask(rl: readline.Interface, q: string): Promise<string> {
11
- return new Promise<string>((res) => rl.question(q, res));
12
- }
13
-
14
- /**
15
- * Prompt for a secret value (password, API token) with input hidden.
16
- * Characters are replaced with '*' as the user types.
17
- */
18
- function askSecret(prompt: string): Promise<string> {
19
- return new Promise((resolve) => {
20
- const rl = readline.createInterface({ input: process.stdin, terminal: true });
21
- process.stdout.write(prompt);
22
-
23
- const chars: string[] = [];
24
-
25
- const cleanup = () => {
26
- process.stdin.removeListener("data", onData);
27
- process.stdin.setRawMode?.(false);
28
- process.stdin.pause();
29
- };
30
-
31
- // Restore terminal on unexpected signals
32
- const onSignal = () => { cleanup(); process.exit(130); };
33
- process.once("SIGTERM", onSignal);
34
- process.once("SIGHUP", onSignal);
35
-
36
- const onData = (key: Buffer) => {
37
- const ch = key.toString();
38
- if (ch === "\n" || ch === "\r") {
39
- process.removeListener("SIGTERM", onSignal);
40
- process.removeListener("SIGHUP", onSignal);
41
- cleanup();
42
- process.stdout.write("\n");
43
- rl.close();
44
- const result = chars.join("");
45
- chars.length = 0; // clear password from array
46
- resolve(result);
47
- } else if (ch === "\x7f" || ch === "\b") {
48
- // Backspace
49
- if (chars.length > 0) {
50
- chars.pop();
51
- process.stdout.write("\b \b");
52
- }
53
- } else if (ch === "\x03") {
54
- // Ctrl+C
55
- cleanup();
56
- process.stdout.write("\n");
57
- process.exit(130);
58
- } else if (ch.charCodeAt(0) >= 32) {
59
- chars.push(ch);
60
- process.stdout.write("*");
61
- }
62
- };
63
-
64
- if (process.stdin.isTTY) {
65
- process.stdin.setRawMode?.(true);
66
- process.stdin.resume();
67
- process.stdin.on("data", onData);
68
- } else {
69
- // Non-interactive: read line normally (piped input)
70
- rl.question("", (answer) => {
71
- rl.close();
72
- resolve(answer.trim());
73
- });
74
- }
75
- });
76
- }
77
-
78
- // ── Commands ─────────────────────────────────────────────────────────────────
79
-
80
- export function registerAuthCommands(program: Command): void {
81
- // ── login ─────────────────────────────────────────────────────────────────
82
-
83
- program
84
- .command("login")
85
- .description("Authenticate and configure your Hisaabo server")
86
- .option("--api-url <url>", "Server URL")
87
- .option("--email <email>", "Email address")
88
- .option("--password <password>", "Password (visible in shell history — prefer interactive prompt)")
89
- .option("--token <token>", "API key (visible in shell history — prefer HISAABO_TOKEN env var)")
90
- .action(async (opts) => {
91
- let apiUrl = opts.apiUrl;
92
-
93
- // ── API key path — skip email/password flow ──
94
- if (opts.token) {
95
- if (!apiUrl) {
96
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
97
- console.log("\n Hisaabo CLI\n " + "─".repeat(11) + "\n");
98
- const u = await ask(rl, " Server URL [http://localhost:3000]: ");
99
- rl.close();
100
- apiUrl = u.trim() || "http://localhost:3000";
101
- }
102
- await loginWithToken(apiUrl, opts.token);
103
- return;
104
- }
105
-
106
- // ── Email/password path ──
107
- let email = opts.email;
108
- let password = opts.password;
109
-
110
- if (!apiUrl || !email || !password) {
111
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
112
- console.log("\n Hisaabo CLI\n " + "─".repeat(11) + "\n");
113
- if (!apiUrl) {
114
- const u = await ask(rl, " Server URL [http://localhost:3000]: ");
115
- apiUrl = u.trim() || "http://localhost:3000";
116
- }
117
- if (!email) email = (await ask(rl, " Email: ")).trim();
118
- rl.close();
119
- if (!password) {
120
- password = await askSecret(" Password: ");
121
- }
122
- console.log("\n Tip: Generate an API key at Settings → API Keys for passwordless CLI access.\n");
123
- }
124
-
125
- await login(apiUrl, email, password);
126
- });
127
-
128
- // ── logout ────────────────────────────────────────────────────────────────
129
-
130
- program
131
- .command("logout")
132
- .description("Log out and clear saved credentials")
133
- .option("--all", "Invalidate all sessions across all devices")
134
- .action(async (opts) => {
135
- if (opts.all) {
136
- const cfg = requireAuth();
137
- const client = new HisaaboClient(cfg);
138
- try {
139
- await client.auth.logoutAll();
140
- await logout();
141
- success("Logged out from all sessions.");
142
- } catch (e) {
143
- if (e instanceof HisaaboApiError) {
144
- if (e.hisaaboError.code === "unauthorized") {
145
- // Session already invalid — still clear local config
146
- await logout();
147
- success("Logged out from all sessions.");
148
- return;
149
- }
150
- }
151
- fatalError(String(e instanceof Error ? e.message : e));
152
- }
153
- return;
154
- }
155
- await logout();
156
- });
157
-
158
- // ── whoami ────────────────────────────────────────────────────────────────
159
-
160
- program
161
- .command("whoami")
162
- .description("Show current user and active business")
163
- .option("--json", "JSON output")
164
- .action(async (opts) => {
165
- await whoami(!!opts.json);
166
- });
167
-
168
- // ── profile ───────────────────────────────────────────────────────────────
169
-
170
- const profile = program.command("profile").description("Manage your profile");
171
-
172
- profile
173
- .command("update-name <name>")
174
- .description("Update your display name")
175
- .action(async (name: string) => {
176
- const cfg = requireAuth();
177
- const client = new HisaaboClient(cfg);
178
- try {
179
- await client.auth.updateName({ name });
180
- success(`Name updated to: ${name}`);
181
- } catch (e) {
182
- if (e instanceof HisaaboApiError) {
183
- const err = e.hisaaboError;
184
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
185
- if (err.code === "validation_failed") fatalError(String(err.fields?.["name"]?.[0] ?? "Validation failed."), EXIT.VALIDATION);
186
- }
187
- fatalError(String(e instanceof Error ? e.message : e));
188
- }
189
- });
190
-
191
- // ── switch (business) ─────────────────────────────────────────────────────
192
-
193
- program
194
- .command("switch")
195
- .description("Switch active business")
196
- .option("--json", "JSON output")
197
- .action(async (opts) => {
198
- const cfg = requireAuth();
199
- const client = new HisaaboClient(cfg);
200
- try {
201
- const businesses = await client.business.list();
202
- if (opts.json) { outputJSON(businesses); return; }
203
- businesses.forEach((b, i) => {
204
- const active = b.id === cfg.businessId ? " [active]" : "";
205
- console.log(` ${i + 1} ${b.name.padEnd(28)}${active}`);
206
- });
207
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
208
- const answer = await new Promise<string>((res) => rl.question("\n Select: ", res));
209
- rl.close();
210
- const idx = parseInt(answer.trim(), 10) - 1;
211
- const selected = businesses[Math.max(0, Math.min(idx, businesses.length - 1))];
212
- if (!selected) fatalError("Invalid selection.", EXIT.USAGE);
213
- setConfig({ businessId: selected.id, businessName: selected.name });
214
- success(`Switched to: ${selected.name}`);
215
- } catch (e) {
216
- if (e instanceof HisaaboApiError) {
217
- if (e.hisaaboError.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
218
- }
219
- fatalError(String(e instanceof Error ? e.message : e));
220
- }
221
- });
222
- }