@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,72 +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
- interface ApiKeyCreateOpts {
7
- name: string;
8
- json?: boolean;
9
- }
10
-
11
- export async function apiKeyCreateCommand(opts: ApiKeyCreateOpts): Promise<void> {
12
- const cfg = requireAuth();
13
- const client = new HisaaboClient(cfg);
14
-
15
- if (!opts.name || opts.name.trim().length === 0) {
16
- fatalError("--name is required.", EXIT.USAGE);
17
- }
18
-
19
- try {
20
- const result = await client.apiKey.create({ name: opts.name.trim() });
21
-
22
- if (opts.json) {
23
- outputJSON(result);
24
- return;
25
- }
26
-
27
- const key = String(result?.key ?? result?.apiKey ?? result?.token ?? "");
28
- const id = String(result?.id ?? "");
29
-
30
- // Security banner — key is shown ONLY ONCE
31
- if (hasColor()) {
32
- process.stdout.write("\n");
33
- process.stdout.write(chalk.bold.green(" ✓ API key created successfully!\n"));
34
- process.stdout.write("\n");
35
- process.stdout.write(chalk.bold.yellow(" ⚠ IMPORTANT: Copy this key now — it will NOT be shown again.\n"));
36
- process.stdout.write("\n");
37
- if (key) {
38
- process.stdout.write(" " + chalk.bold("Your API key:") + "\n");
39
- process.stdout.write("\n");
40
- process.stdout.write(" " + chalk.cyan.bold(key) + "\n");
41
- process.stdout.write("\n");
42
- }
43
- process.stdout.write(chalk.dim(" Use it with: hisaabo login --token <key>\n"));
44
- process.stdout.write(chalk.dim(" Or set env: HISAABO_TOKEN=" + (key ? key : "<key>") + "\n"));
45
- if (id) process.stdout.write(chalk.dim(`\n Key ID: ${id}\n`));
46
- process.stdout.write("\n");
47
- } else {
48
- process.stdout.write("\nAPI key created successfully!\n\n");
49
- process.stdout.write("IMPORTANT: Copy this key now — it will NOT be shown again.\n\n");
50
- if (key) {
51
- process.stdout.write(`Your API key:\n\n ${key}\n\n`);
52
- process.stdout.write(`Usage: hisaabo login --token ${key}\n`);
53
- }
54
- if (id) process.stdout.write(`Key ID: ${id}\n`);
55
- process.stdout.write("\n");
56
- }
57
- } catch (e) {
58
- if (e instanceof HisaaboApiError) {
59
- const err = e.hisaaboError;
60
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
61
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
62
- if (err.code === "validation_failed") {
63
- const msgs = Object.entries(err.fields)
64
- .map(([f, ms]) => ` ${f}: ${ms.join(", ")}`)
65
- .join("\n");
66
- fatalError(`Validation failed:\n${msgs}`, EXIT.VALIDATION);
67
- }
68
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
69
- }
70
- fatalError(String(e instanceof Error ? e.message : e));
71
- }
72
- }
@@ -1,71 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, hasColor } from "../../output.js";
4
- import { formatDate, formatRelativeDate } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- interface ApiKeyListOpts {
8
- json?: boolean;
9
- format?: string;
10
- }
11
-
12
- export async function apiKeyListCommand(opts: ApiKeyListOpts): Promise<void> {
13
- const cfg = requireAuth();
14
- const client = new HisaaboClient(cfg);
15
-
16
- try {
17
- const keys = await client.apiKey.list();
18
-
19
- if (opts.json) {
20
- outputJSON(keys);
21
- return;
22
- }
23
-
24
- const items: unknown[] = Array.isArray(keys) ? keys : (keys?.items ?? keys?.data ?? []);
25
-
26
- if (items.length === 0) {
27
- process.stdout.write("\n No API keys found.\n Use: hisaabo api-key create --name <name>\n\n");
28
- return;
29
- }
30
-
31
- const rows = items.map((item: unknown) => {
32
- const k = item as Record<string, unknown>;
33
- const rawKey = String(k["keyPrefix"] ?? k["prefix"] ?? k["key"] ?? "");
34
- // Show key prefix safely: hisaabo_key_abc... (first 20 chars)
35
- const displayKey = rawKey.length > 20 ? rawKey.slice(0, 20) + "..." : rawKey || "-";
36
- return {
37
- name: String(k["name"] ?? "-"),
38
- prefix: displayKey,
39
- created: formatDate(String(k["createdAt"] ?? "")),
40
- lastUsed: k["lastUsedAt"] ? formatRelativeDate(String(k["lastUsedAt"])) : "Never",
41
- id: String(k["id"] ?? "-"),
42
- };
43
- });
44
-
45
- const columns = [
46
- { key: "name", header: "Name", align: "left" as const },
47
- { key: "prefix", header: "Key Prefix", align: "left" as const },
48
- { key: "created", header: "Created", align: "left" as const },
49
- { key: "lastUsed", header: "Last Used", align: "left" as const },
50
- { key: "id", header: "ID", align: "left" as const, width: 36 },
51
- ];
52
-
53
- if (opts.format === "tsv") {
54
- outputTSV(rows, columns);
55
- } else if (opts.format === "csv") {
56
- outputCSV(rows, columns);
57
- } else {
58
- if (hasColor()) process.stdout.write("\n" + chalk.bold(" API Keys\n") + "\n");
59
- else process.stdout.write("\n API Keys\n\n");
60
- outputTable(rows, columns);
61
- process.stdout.write("\n");
62
- }
63
- } catch (e) {
64
- if (e instanceof HisaaboApiError) {
65
- const err = e.hisaaboError;
66
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
67
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
68
- }
69
- fatalError(String(e instanceof Error ? e.message : e));
70
- }
71
- }
@@ -1,46 +0,0 @@
1
- import * as readline from "readline";
2
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
3
- import { requireAuth } from "../../config.js";
4
- import { fatalError, success, outputJSON, EXIT } from "../../output.js";
5
-
6
- interface ApiKeyRevokeOpts {
7
- yes?: boolean;
8
- json?: boolean;
9
- }
10
-
11
- export async function apiKeyRevokeCommand(id: string, opts: ApiKeyRevokeOpts): Promise<void> {
12
- const cfg = requireAuth();
13
- const client = new HisaaboClient(cfg);
14
-
15
- if (!opts.yes && process.stdin.isTTY) {
16
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
17
- const answer = await new Promise<string>((resolve) => {
18
- rl.question(` Revoke API key ${id}? This cannot be undone. (y/N): `, resolve);
19
- });
20
- rl.close();
21
- if (answer.trim().toLowerCase() !== "y") {
22
- console.log(" Cancelled.");
23
- process.exit(0);
24
- }
25
- }
26
-
27
- try {
28
- const result = await client.apiKey.revoke({ id });
29
-
30
- if (opts.json) {
31
- outputJSON(result);
32
- return;
33
- }
34
-
35
- success(`API key revoked: ${id}`);
36
- } catch (e) {
37
- if (e instanceof HisaaboApiError) {
38
- const err = e.hisaaboError;
39
- if (err.code === "not_found") fatalError(`API key not found: ${id}`, EXIT.NOT_FOUND);
40
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
41
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
42
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
43
- }
44
- fatalError(String(e instanceof Error ? e.message : e));
45
- }
46
- }
@@ -1,85 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- interface CreateOpts {
6
- json?: boolean;
7
- partyId?: string;
8
- name?: string;
9
- type?: string;
10
- frequency?: string;
11
- customIntervalDays?: string;
12
- lineItem?: string[];
13
- qty?: string[];
14
- rate?: string[];
15
- tax?: string[];
16
- discount?: string[];
17
- startDate?: string;
18
- endDate?: string;
19
- maxRuns?: string;
20
- notes?: string;
21
- }
22
-
23
- export async function automatedInvoiceCreateCommand(opts: CreateOpts): Promise<void> {
24
- const cfg = requireAuth();
25
- const client = new HisaaboClient(cfg);
26
-
27
- if (!opts.partyId) fatalError("--party-id is required", EXIT.USAGE);
28
- if (!opts.name) fatalError("--name is required", EXIT.USAGE);
29
- if (!opts.type) fatalError("--type is required (sale or purchase)", EXIT.USAGE);
30
- if (!opts.frequency) fatalError("--frequency is required", EXIT.USAGE);
31
- if (!opts.startDate) fatalError("--start-date is required (YYYY-MM-DD)", EXIT.USAGE);
32
-
33
- const items = opts.lineItem ?? [];
34
- const qtys = opts.qty ?? [];
35
- const rates = opts.rate ?? [];
36
- const taxes = opts.tax ?? [];
37
- const discounts = opts.discount ?? [];
38
-
39
- if (items.length === 0) fatalError("At least one --line-item is required", EXIT.USAGE);
40
-
41
- const frequency = opts.frequency as "weekly" | "biweekly" | "monthly" | "quarterly" | "half_yearly" | "yearly" | "custom";
42
-
43
- if (frequency === "custom" && !opts.customIntervalDays) {
44
- fatalError("--custom-interval-days is required when frequency is 'custom'", EXIT.USAGE);
45
- }
46
-
47
- const lineItems = items.map((desc, i) => ({
48
- description: desc,
49
- quantity: qtys[i] ?? "1",
50
- unitPrice: rates[i] ?? "0",
51
- taxPercent: taxes[i],
52
- discountPercent: discounts[i],
53
- }));
54
-
55
- try {
56
- const result = await client.recurringInvoice.create({
57
- partyId: opts.partyId,
58
- name: opts.name,
59
- type: opts.type as "sale" | "purchase",
60
- frequency,
61
- customIntervalDays: opts.customIntervalDays ? parseInt(opts.customIntervalDays, 10) : undefined,
62
- lineItems,
63
- startDate: opts.startDate,
64
- endDate: opts.endDate,
65
- maxRuns: opts.maxRuns ? parseInt(opts.maxRuns, 10) : undefined,
66
- notes: opts.notes,
67
- });
68
-
69
- if (opts.json) {
70
- outputJSON(result);
71
- return;
72
- }
73
-
74
- success(`Created recurring invoice template: ${result.name} (${result.id})`);
75
-
76
- } catch (e) {
77
- if (e instanceof HisaaboApiError) {
78
- const err = e.hisaaboError;
79
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
80
- if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
81
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
82
- }
83
- fatalError(String(e instanceof Error ? e.message : e));
84
- }
85
- }
@@ -1,42 +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 automatedInvoiceDeleteCommand(id: string, opts: { yes?: boolean; json?: boolean }): Promise<void> {
7
- const cfg = requireAuth();
8
- const client = new HisaaboClient(cfg);
9
-
10
- try {
11
- if (!opts.yes && process.stdin.isTTY) {
12
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
13
- const answer = await new Promise<string>((resolve) => {
14
- rl.question(` Delete recurring invoice template ${id}? (y/N): `, resolve);
15
- });
16
- rl.close();
17
- if (answer.trim().toLowerCase() !== "y") {
18
- console.log(" Cancelled.");
19
- process.exit(0);
20
- }
21
- }
22
-
23
- const result = await client.recurringInvoice.delete(id);
24
-
25
- if (opts.json) {
26
- outputJSON(result);
27
- return;
28
- }
29
-
30
- success(`Deleted recurring invoice template: ${id}`);
31
-
32
- } catch (e) {
33
- if (e instanceof HisaaboApiError) {
34
- const err = e.hisaaboError;
35
- if (err.code === "not_found") fatalError(`Template not found: ${id}`, EXIT.NOT_FOUND);
36
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
37
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
38
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
39
- }
40
- fatalError(String(e instanceof Error ? e.message : e));
41
- }
42
- }
@@ -1,113 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, termWidth, hasColor } from "../../output.js";
4
- import { formatAmount, formatDate } from "../../format.js";
5
- import chalk from "chalk";
6
-
7
- const FREQUENCY_LABELS: Record<string, string> = {
8
- weekly: "Weekly",
9
- biweekly: "Every 2 Weeks",
10
- monthly: "Monthly",
11
- quarterly: "Quarterly",
12
- half_yearly: "Every 6 Months",
13
- yearly: "Yearly",
14
- custom: "Custom",
15
- };
16
-
17
- function statusBadge(status: string): string {
18
- const map: Record<string, (s: string) => string> = {
19
- active: (s) => chalk.green(s),
20
- paused: (s) => chalk.yellow(s),
21
- completed: (s) => chalk.dim(s),
22
- expired: (s) => chalk.red(s),
23
- };
24
- const label = `[${status.toUpperCase()}]`;
25
- if (!hasColor()) return label;
26
- const colorFn = map[status];
27
- return colorFn ? colorFn(label) : label;
28
- }
29
-
30
- export async function automatedInvoiceGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
31
- const cfg = requireAuth();
32
- const client = new HisaaboClient(cfg);
33
-
34
- try {
35
- const tmpl = await client.recurringInvoice.getById(id);
36
-
37
- if (opts.json) {
38
- outputJSON(tmpl);
39
- return;
40
- }
41
-
42
- const w = Math.min(termWidth() - 2, 68);
43
- const inner = w - 2;
44
-
45
- function line(left: string, right?: string): void {
46
- if (right !== undefined) {
47
- const pad = Math.max(1, inner - left.length - right.length - 2);
48
- process.stdout.write(`| ${left}${" ".repeat(pad)}${right} |\n`);
49
- } else {
50
- const vis = left.length;
51
- const pad = Math.max(0, inner - vis);
52
- process.stdout.write(`| ${left}${" ".repeat(pad)} |\n`);
53
- }
54
- }
55
-
56
- function divider(): void {
57
- process.stdout.write(`+${"~".repeat(inner + 2)}+\n`);
58
- }
59
-
60
- const title = `RECURRING INVOICE ${tmpl.name}`;
61
- const badge = statusBadge(tmpl.status);
62
- // eslint-disable-next-line no-control-regex
63
- const topPad = Math.max(1, inner - title.length - badge.replace(/\x1b\[[0-9;]*m/g, "").length);
64
-
65
- process.stdout.write(`\n +${"~".repeat(inner + 2)}+\n`);
66
- process.stdout.write(`| ${hasColor() ? chalk.bold(title) : title}${" ".repeat(topPad)}${badge} |\n`);
67
- divider();
68
- line(`Party: ${tmpl.partyName}`);
69
- line(`Type: ${tmpl.type === "sale" ? "Sale" : "Purchase"}`);
70
- line(`Frequency: ${FREQUENCY_LABELS[tmpl.frequency] ?? tmpl.frequency}`);
71
- if (tmpl.frequency === "custom" && tmpl.customIntervalDays) {
72
- line(`Interval: Every ${tmpl.customIntervalDays} days`);
73
- }
74
- line(`Start: ${formatDate(tmpl.startDate)}`);
75
- if (tmpl.endDate) line(`End: ${formatDate(tmpl.endDate)}`);
76
- if (tmpl.nextRunDate) line(`Next Run: ${formatDate(tmpl.nextRunDate)}`);
77
- if (tmpl.lastRunDate) line(`Last Run: ${formatDate(tmpl.lastRunDate)}`);
78
- line(`Runs: ${tmpl.totalRuns}${tmpl.maxRuns ? ` / ${tmpl.maxRuns}` : ""}`);
79
- divider();
80
-
81
- // Line items
82
- process.stdout.write(`|${"".padEnd(inner + 2)}|\n`);
83
- process.stdout.write(`| # ${"Item".padEnd(18)} ${"Qty".padStart(5)} ${"Rate".padStart(10)} ${"Tax%".padStart(5)} |\n`);
84
- process.stdout.write(`| ${"--".padEnd(2)} ${"~".repeat(18)} ${"~".repeat(5)} ${"~".repeat(10)} ${"~".repeat(5)} |\n`);
85
-
86
- tmpl.lineItems.forEach((item, i) => {
87
- const idx = String(i + 1).padStart(2);
88
- const desc = item.description.slice(0, 18).padEnd(18);
89
- const qty = item.quantity.padStart(5);
90
- const rate = formatAmount(item.unitPrice).padStart(10);
91
- const tax = item.taxPercent ? `${item.taxPercent}%`.padStart(5) : " -";
92
- process.stdout.write(`| ${idx} ${desc} ${qty} ${rate} ${tax} |\n`);
93
- });
94
-
95
- process.stdout.write(`|${"".padEnd(inner + 2)}|\n`);
96
-
97
- if (tmpl.notes) {
98
- divider();
99
- line(`Notes: ${tmpl.notes}`);
100
- }
101
-
102
- process.stdout.write(` +${"~".repeat(inner + 2)}+\n\n`);
103
-
104
- } catch (e) {
105
- if (e instanceof HisaaboApiError) {
106
- const err = e.hisaaboError;
107
- if (err.code === "not_found") fatalError(`Recurring invoice template not found: ${id}`, EXIT.NOT_FOUND);
108
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
109
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
110
- }
111
- fatalError(String(e instanceof Error ? e.message : e));
112
- }
113
- }
@@ -1,65 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError, type RecurringInvoiceExecution } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- fatalError, outputJSON, outputTable, outputTSV, outputCSV,
5
- paginationFooter, EXIT, type ColumnDef,
6
- } from "../../output.js";
7
- import { formatDate } from "../../format.js";
8
- import chalk from "chalk";
9
-
10
- function executionStatusBadge(status: string): string {
11
- const map: Record<string, string> = {
12
- success: chalk.green("success"),
13
- failed: chalk.red("failed"),
14
- skipped: chalk.yellow("skipped"),
15
- };
16
- return map[status] ?? status;
17
- }
18
-
19
- interface HistoryOpts {
20
- json?: boolean;
21
- format?: string;
22
- page?: number;
23
- limit?: number;
24
- }
25
-
26
- export async function automatedInvoiceHistoryCommand(templateId: string, opts: HistoryOpts): Promise<void> {
27
- const cfg = requireAuth();
28
- const client = new HisaaboClient(cfg);
29
- const page = opts.page ?? 1;
30
- const limit = opts.limit ?? 20;
31
-
32
- try {
33
- const result = await client.recurringInvoice.executionHistory(templateId, page, limit);
34
-
35
- if (opts.json) {
36
- outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
37
- return;
38
- }
39
-
40
- console.log(`\n Execution History ${result.total} total\n`);
41
-
42
- const cols: ColumnDef<RecurringInvoiceExecution>[] = [
43
- { key: "executedAt", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
44
- { key: "invoiceNumber", header: "Invoice #", width: 20 },
45
- { key: "status", header: "Status", width: 10, format: (v) => executionStatusBadge(String(v ?? "")) },
46
- { key: "errorMessage", header: "Error", width: 30, format: (v) => (v ? String(v) : "—") },
47
- ];
48
-
49
- if (opts.format === "tsv") outputTSV(result.data, cols);
50
- else if (opts.format === "csv") outputCSV(result.data, cols);
51
- else {
52
- outputTable(result.data, cols);
53
- paginationFooter(result.page, result.limit, result.total);
54
- }
55
-
56
- } catch (e) {
57
- if (e instanceof HisaaboApiError) {
58
- const err = e.hisaaboError;
59
- if (err.code === "not_found") fatalError(`Recurring invoice template not found: ${templateId}`, EXIT.NOT_FOUND);
60
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
61
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
62
- }
63
- fatalError(String(e instanceof Error ? e.message : e));
64
- }
65
- }
@@ -1,11 +0,0 @@
1
- export { automatedInvoiceListCommand } from "./list.js";
2
- export { automatedInvoiceGetCommand } from "./get.js";
3
- export { automatedInvoiceCreateCommand } from "./create.js";
4
- export { automatedInvoiceUpdateCommand } from "./update.js";
5
- export { automatedInvoicePauseCommand } from "./pause.js";
6
- export { automatedInvoiceResumeCommand } from "./resume.js";
7
- export { automatedInvoiceRunNowCommand } from "./run-now.js";
8
- export { automatedInvoiceDeleteCommand } from "./delete.js";
9
- export { automatedInvoiceHistoryCommand } from "./history.js";
10
- export { automatedInvoiceUsageCommand } from "./usage.js";
11
- export { automatedInvoiceSuggestionsCommand } from "./suggestions.js";
@@ -1,91 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError, type RecurringInvoiceSummary } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import {
4
- fatalError, outputJSON, outputTable, outputTSV, outputCSV, outputIds,
5
- paginationFooter, EXIT, type ColumnDef,
6
- } from "../../output.js";
7
- import { formatDate } from "../../format.js";
8
-
9
- const FREQUENCY_LABELS: Record<string, string> = {
10
- weekly: "Weekly",
11
- biweekly: "Every 2 Weeks",
12
- monthly: "Monthly",
13
- quarterly: "Quarterly",
14
- half_yearly: "Every 6 Months",
15
- yearly: "Yearly",
16
- custom: "Custom",
17
- };
18
-
19
- function formatFrequency(freq: string): string {
20
- return FREQUENCY_LABELS[freq] ?? freq;
21
- }
22
-
23
- function formatTemplateStatus(status: string): string {
24
- const map: Record<string, string> = {
25
- active: "Active",
26
- paused: "Paused",
27
- completed: "Completed",
28
- expired: "Expired",
29
- };
30
- return map[status] ?? status;
31
- }
32
-
33
- function formatRuns(totalRuns: number, maxRuns: number | null): string {
34
- if (maxRuns) return `${totalRuns}/${maxRuns}`;
35
- return String(totalRuns);
36
- }
37
-
38
- interface ListOpts {
39
- json?: boolean;
40
- format?: string;
41
- status?: string;
42
- page?: number;
43
- limit?: number;
44
- }
45
-
46
- export async function automatedInvoiceListCommand(opts: ListOpts): Promise<void> {
47
- const cfg = requireAuth();
48
- const client = new HisaaboClient(cfg);
49
- const page = opts.page ?? 1;
50
- const limit = opts.limit ?? 20;
51
-
52
- try {
53
- const result = await client.recurringInvoice.list({
54
- status: opts.status as "active" | "paused" | "completed" | "expired" | undefined,
55
- page,
56
- limit,
57
- });
58
-
59
- if (opts.json) {
60
- outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
61
- return;
62
- }
63
-
64
- console.log(`\n Recurring Invoices ${result.total} total\n`);
65
-
66
- const cols: ColumnDef<RecurringInvoiceSummary>[] = [
67
- { key: "name", header: "Name", width: 20 },
68
- { key: "partyName", header: "Party", width: 18 },
69
- { key: "frequency", header: "Frequency", width: 14, format: (v) => formatFrequency(String(v ?? "")) },
70
- { key: "status", header: "Status", width: 10, format: (v) => formatTemplateStatus(String(v ?? "")) },
71
- { key: "nextRunDate", header: "Next Run", width: 13, format: (v) => formatDate(String(v ?? "")) },
72
- { key: "totalRuns", header: "Runs", width: 8, align: "right", format: (v, row) => formatRuns(Number(v ?? 0), row.maxRuns) },
73
- ];
74
-
75
- if (opts.format === "tsv") outputTSV(result.data, cols);
76
- else if (opts.format === "csv") outputCSV(result.data, cols);
77
- else if (opts.format === "ids") outputIds(result.data.map((r) => r.id));
78
- else {
79
- outputTable(result.data, cols);
80
- paginationFooter(result.page, result.limit, result.total);
81
- }
82
-
83
- } catch (e) {
84
- if (e instanceof HisaaboApiError) {
85
- const err = e.hisaaboError;
86
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
87
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
88
- }
89
- fatalError(String(e instanceof Error ? e.message : e));
90
- }
91
- }
@@ -1,29 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- export async function automatedInvoicePauseCommand(id: string, opts: { json?: boolean }): Promise<void> {
6
- const cfg = requireAuth();
7
- const client = new HisaaboClient(cfg);
8
-
9
- try {
10
- const result = await client.recurringInvoice.pause(id);
11
-
12
- if (opts.json) {
13
- outputJSON(result);
14
- return;
15
- }
16
-
17
- success(`Paused recurring invoice template: ${id}`);
18
-
19
- } catch (e) {
20
- if (e instanceof HisaaboApiError) {
21
- const err = e.hisaaboError;
22
- if (err.code === "not_found") fatalError(`Template not found: ${id}`, EXIT.NOT_FOUND);
23
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
24
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
25
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
26
- }
27
- fatalError(String(e instanceof Error ? e.message : e));
28
- }
29
- }
@@ -1,29 +0,0 @@
1
- import { HisaaboClient, HisaaboApiError } from "../../client.js";
2
- import { requireAuth } from "../../config.js";
3
- import { fatalError, outputJSON, EXIT, success } from "../../output.js";
4
-
5
- export async function automatedInvoiceResumeCommand(id: string, opts: { json?: boolean }): Promise<void> {
6
- const cfg = requireAuth();
7
- const client = new HisaaboClient(cfg);
8
-
9
- try {
10
- const result = await client.recurringInvoice.resume(id);
11
-
12
- if (opts.json) {
13
- outputJSON(result);
14
- return;
15
- }
16
-
17
- success(`Resumed recurring invoice template: ${id}`);
18
-
19
- } catch (e) {
20
- if (e instanceof HisaaboApiError) {
21
- const err = e.hisaaboError;
22
- if (err.code === "not_found") fatalError(`Template not found: ${id}`, EXIT.NOT_FOUND);
23
- if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
24
- if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
25
- if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
26
- }
27
- fatalError(String(e instanceof Error ? e.message : e));
28
- }
29
- }