@hisaabo/cli 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/.turbo/turbo-typecheck.log +1 -1
  2. package/README.md +332 -0
  3. package/dist/bin/audit-trail-5LOCJ7XZ.js +78 -0
  4. package/dist/bin/categories-64WWZTND.js +47 -0
  5. package/dist/bin/check-slug-FLHHUDYS.js +65 -0
  6. package/dist/bin/chunk-4MEL44QX.js +848 -0
  7. package/dist/bin/chunk-FIMJZAS4.js +84 -0
  8. package/dist/bin/chunk-NO4FIFMS.js +176 -0
  9. package/dist/bin/chunk-T63VQXNM.js +156 -0
  10. package/dist/bin/client-5NZ23GML.js +11 -0
  11. package/dist/bin/collection-efficiency-U56XNVEE.js +165 -0
  12. package/dist/bin/config-335MN4I7.js +18 -0
  13. package/dist/bin/create-RPDEORDD.js +83 -0
  14. package/dist/bin/default-account-AE6EXZZR.js +58 -0
  15. package/dist/bin/expenses-5N2QSG54.js +89 -0
  16. package/dist/bin/export-QICOQK34.js +59 -0
  17. package/dist/bin/factory-KOCW2AQM.js +483 -0
  18. package/dist/bin/get-A43QCI2S.js +66 -0
  19. package/dist/bin/get-GWH6S5SJ.js +71 -0
  20. package/dist/bin/hisaabo.js +2302 -1510
  21. package/dist/bin/invitations-P3EEN5WI.js +66 -0
  22. package/dist/bin/invite-T3CKX53E.js +53 -0
  23. package/dist/bin/invoice-breakdown-FN5BEFJD.js +97 -0
  24. package/dist/bin/items-2OOCQKVF.js +62 -0
  25. package/dist/bin/items-toggle-SKZWCGJH.js +46 -0
  26. package/dist/bin/list-A2RKI3ZG.js +79 -0
  27. package/dist/bin/list-NRMBMKMI.js +90 -0
  28. package/dist/bin/list-T74SN6IR.js +46 -0
  29. package/dist/bin/members-W2GW3ODT.js +55 -0
  30. package/dist/bin/monthly-comparison-T34ZFOHL.js +176 -0
  31. package/dist/bin/order-cancel-TI27JYYD.js +55 -0
  32. package/dist/bin/order-confirm-VMRAMNTD.js +53 -0
  33. package/dist/bin/order-get-C2RBUR4O.js +88 -0
  34. package/dist/bin/order-update-RE3HATNF.js +60 -0
  35. package/dist/bin/output-NUOL7KJW.js +35 -0
  36. package/dist/bin/payment-modes-WOOT22I7.js +126 -0
  37. package/dist/bin/profit-loss-T4RESJ32.js +135 -0
  38. package/dist/bin/receivables-aging-6XMENEWS.js +161 -0
  39. package/dist/bin/remove-6QZI4JCY.js +52 -0
  40. package/dist/bin/revoke-AVEMPAC7.js +40 -0
  41. package/dist/bin/revoke-YUCFZFNR.js +52 -0
  42. package/dist/bin/revoke-all-LFW5WBHO.js +33 -0
  43. package/dist/bin/revoke-invitation-DTGQRJR4.js +40 -0
  44. package/dist/bin/sales-trend-ZYBRUDUU.js +71 -0
  45. package/dist/bin/sequence-FPOJTI2P.js +66 -0
  46. package/dist/bin/store-IOB4Y67C.js +82 -0
  47. package/dist/bin/summary-5KYBA4ZO.js +113 -0
  48. package/dist/bin/top-customers-WSQ2UEJL.js +81 -0
  49. package/dist/bin/top-items-RWQPDGLN.js +84 -0
  50. package/dist/bin/top-outstanding-QAMO2E7Y.js +64 -0
  51. package/dist/bin/unpaid-invoices-WB3TK5B4.js +65 -0
  52. package/dist/bin/untracked-H733MYJL.js +67 -0
  53. package/dist/bin/update-H6LPO2Z4.js +61 -0
  54. package/dist/bin/update-JU2X3XU5.js +54 -0
  55. package/dist/bin/update-TLBUIC5J.js +57 -0
  56. package/dist/bin/update-role-QST7BVFX.js +45 -0
  57. package/dist/bin/update-settings-Q2EGRLKZ.js +56 -0
  58. package/package.json +7 -6
  59. package/src/auth.ts +12 -3
  60. package/src/bin/hisaabo.ts +49 -935
  61. package/src/bin/registrars/api-key.ts +44 -0
  62. package/src/bin/registrars/auth.ts +222 -0
  63. package/src/bin/registrars/automated-invoice.ts +167 -0
  64. package/src/bin/registrars/bank.ts +124 -0
  65. package/src/bin/registrars/business.ts +120 -0
  66. package/src/bin/registrars/dashboard.ts +225 -0
  67. package/src/bin/registrars/document.ts +184 -0
  68. package/src/bin/registrars/expense.ts +87 -0
  69. package/src/bin/registrars/gst.ts +41 -0
  70. package/src/bin/registrars/import.ts +49 -0
  71. package/src/bin/registrars/invoice.ts +117 -0
  72. package/src/bin/registrars/item.ts +112 -0
  73. package/src/bin/registrars/party.ts +81 -0
  74. package/src/bin/registrars/payment.ts +128 -0
  75. package/src/bin/registrars/report.ts +142 -0
  76. package/src/bin/registrars/session.ts +32 -0
  77. package/src/bin/registrars/shipment.ts +74 -0
  78. package/src/bin/registrars/store.ts +128 -0
  79. package/src/bin/registrars/target.ts +46 -0
  80. package/src/bin/registrars/tenant.ts +73 -0
  81. package/src/client.ts +589 -15
  82. package/src/commands/api-key/create.ts +72 -0
  83. package/src/commands/api-key/list.ts +71 -0
  84. package/src/commands/api-key/revoke.ts +46 -0
  85. package/src/commands/automated-invoice/create.ts +85 -0
  86. package/src/commands/automated-invoice/delete.ts +42 -0
  87. package/src/commands/automated-invoice/get.ts +113 -0
  88. package/src/commands/automated-invoice/history.ts +65 -0
  89. package/src/commands/automated-invoice/index.ts +11 -0
  90. package/src/commands/automated-invoice/list.ts +91 -0
  91. package/src/commands/automated-invoice/pause.ts +29 -0
  92. package/src/commands/automated-invoice/resume.ts +29 -0
  93. package/src/commands/automated-invoice/run-now.ts +29 -0
  94. package/src/commands/automated-invoice/suggestions.ts +68 -0
  95. package/src/commands/automated-invoice/update.ts +54 -0
  96. package/src/commands/automated-invoice/usage.ts +68 -0
  97. package/src/commands/bank/gateway-config.ts +61 -0
  98. package/src/commands/bank/update-gateway.ts +84 -0
  99. package/src/commands/business/audit-trail.ts +79 -0
  100. package/src/commands/business/export.ts +52 -0
  101. package/src/commands/business/get.ts +55 -0
  102. package/src/commands/business/sequence.ts +65 -0
  103. package/src/commands/business/update.ts +64 -0
  104. package/src/commands/dashboard/collection-efficiency.ts +164 -0
  105. package/src/commands/dashboard/expenses.ts +76 -0
  106. package/src/commands/dashboard/invoice-breakdown.ts +89 -0
  107. package/src/commands/dashboard/monthly-comparison.ts +193 -0
  108. package/src/commands/dashboard/payment-modes.ts +121 -0
  109. package/src/commands/dashboard/profit-loss.ts +146 -0
  110. package/src/commands/dashboard/receivables-aging.ts +169 -0
  111. package/src/commands/dashboard/sales-trend.ts +68 -0
  112. package/src/commands/dashboard/summary.ts +105 -0
  113. package/src/commands/dashboard/top-customers.ts +70 -0
  114. package/src/commands/dashboard/top-items.ts +74 -0
  115. package/src/commands/dashboard/top-outstanding.ts +61 -0
  116. package/src/commands/document/factory.ts +590 -0
  117. package/src/commands/expense/categories.ts +40 -0
  118. package/src/commands/expense/update.ts +58 -0
  119. package/src/commands/import/index.ts +68 -0
  120. package/src/commands/item/categories.ts +40 -0
  121. package/src/commands/item/low-stock-count.ts +32 -0
  122. package/src/commands/item/merge.ts +53 -0
  123. package/src/commands/item/price-history.ts +59 -0
  124. package/src/commands/item/rename-unit.ts +39 -0
  125. package/src/commands/item/sales-stats.ts +44 -0
  126. package/src/commands/item/stock-history.ts +70 -0
  127. package/src/commands/item/switch-base-unit.ts +42 -0
  128. package/src/commands/item/update.ts +59 -0
  129. package/src/commands/item/variants-create.ts +58 -0
  130. package/src/commands/item/variants-delete.ts +47 -0
  131. package/src/commands/item/variants-list.ts +63 -0
  132. package/src/commands/item/variants-update.ts +61 -0
  133. package/src/commands/party/ledger-report.ts +81 -0
  134. package/src/commands/party/merge.ts +50 -0
  135. package/src/commands/party/stats.ts +40 -0
  136. package/src/commands/party/top-items.ts +57 -0
  137. package/src/commands/party/update.ts +65 -0
  138. package/src/commands/payment/default-account.ts +56 -0
  139. package/src/commands/payment/get.ts +59 -0
  140. package/src/commands/payment/unpaid-invoices.ts +69 -0
  141. package/src/commands/payment/untracked.ts +70 -0
  142. package/src/commands/payment/update.ts +54 -0
  143. package/src/commands/report/index.ts +348 -1
  144. package/src/commands/session/list.ts +91 -0
  145. package/src/commands/session/revoke-all.ts +20 -0
  146. package/src/commands/session/revoke.ts +32 -0
  147. package/src/commands/store/check-slug.ts +48 -0
  148. package/src/commands/store/items-toggle.ts +41 -0
  149. package/src/commands/store/items.ts +61 -0
  150. package/src/commands/store/order-cancel.ts +48 -0
  151. package/src/commands/store/order-confirm.ts +45 -0
  152. package/src/commands/store/order-get.ts +66 -0
  153. package/src/commands/store/order-update.ts +52 -0
  154. package/src/commands/store/update-settings.ts +52 -0
  155. package/src/commands/tenant/invitations.ts +62 -0
  156. package/src/commands/tenant/invite.ts +57 -0
  157. package/src/commands/tenant/list.ts +46 -0
  158. package/src/commands/tenant/members.ts +55 -0
  159. package/src/commands/tenant/remove.ts +47 -0
  160. package/src/commands/tenant/revoke-invitation.ts +32 -0
  161. package/src/commands/tenant/update-role.ts +41 -0
  162. package/src/config.ts +51 -2
  163. package/src/error-handler.ts +53 -0
  164. package/src/output.ts +1 -0
  165. package/src/spinner.ts +39 -0
  166. package/tsup.config.ts +6 -1
  167. package/src/components/ErrorDisplay.tsx +0 -16
  168. package/src/components/Header.tsx +0 -26
  169. package/src/components/MoneyCell.tsx +0 -16
  170. package/src/components/Spinner.tsx +0 -12
  171. package/src/components/StatusBadge.tsx +0 -39
  172. package/src/components/Table.tsx +0 -63
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatINR
4
+ } from "./chunk-T63VQXNM.js";
5
+ import {
6
+ HisaaboApiError,
7
+ HisaaboClient
8
+ } from "./chunk-4MEL44QX.js";
9
+ import {
10
+ requireAuth
11
+ } from "./chunk-FIMJZAS4.js";
12
+ import {
13
+ EXIT,
14
+ fatalError,
15
+ outputJSON,
16
+ success
17
+ } from "./chunk-NO4FIFMS.js";
18
+
19
+ // src/commands/expense/update.ts
20
+ async function expenseUpdateCommand(id, opts) {
21
+ const cfg = requireAuth();
22
+ const client = new HisaaboClient(cfg);
23
+ const data = {};
24
+ if (opts.amount !== void 0) data.amount = opts.amount;
25
+ if (opts.category !== void 0) data.category = opts.category;
26
+ if (opts.date !== void 0) data.expenseDate = opts.date;
27
+ if (opts.description !== void 0) data.description = opts.description;
28
+ if (opts.paymentMode !== void 0) data.mode = opts.paymentMode;
29
+ if (opts.reference !== void 0) data.referenceNumber = opts.reference;
30
+ if (Object.keys(data).length === 0) {
31
+ fatalError(
32
+ "No fields to update. Provide at least one option: --amount, --category, --date, --description, --payment-mode, --reference",
33
+ EXIT.USAGE
34
+ );
35
+ }
36
+ try {
37
+ const expense = await client.expense.update(id, data);
38
+ if (opts.json) {
39
+ outputJSON(expense);
40
+ return;
41
+ }
42
+ success(`Updated: ${expense.category} \u2014 ${formatINR(expense.amount)}`);
43
+ } catch (e) {
44
+ if (e instanceof HisaaboApiError) {
45
+ const err = e.hisaaboError;
46
+ if (err.code === "not_found") fatalError(`Expense not found: ${id}`, EXIT.NOT_FOUND);
47
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
48
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
49
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
50
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
51
+ }
52
+ fatalError(String(e instanceof Error ? e.message : e));
53
+ }
54
+ }
55
+ export {
56
+ expenseUpdateCommand
57
+ };
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ HisaaboApiError,
4
+ HisaaboClient
5
+ } from "./chunk-4MEL44QX.js";
6
+ import {
7
+ requireAuth
8
+ } from "./chunk-FIMJZAS4.js";
9
+ import {
10
+ EXIT,
11
+ fatalError,
12
+ outputJSON,
13
+ success
14
+ } from "./chunk-NO4FIFMS.js";
15
+
16
+ // src/commands/tenant/update-role.ts
17
+ var VALID_ROLES = ["admin", "seller_manager", "seller", "accountant"];
18
+ async function tenantUpdateRoleCommand(userId, role, opts) {
19
+ const cfg = requireAuth();
20
+ const client = new HisaaboClient(cfg);
21
+ if (!VALID_ROLES.includes(role)) {
22
+ fatalError(`Invalid role "${role}". Must be one of: ${VALID_ROLES.join(", ")}`, EXIT.VALIDATION);
23
+ }
24
+ try {
25
+ const result = await client.tenant.updateMemberRole({ userId, role });
26
+ if (opts.json) {
27
+ outputJSON(result);
28
+ return;
29
+ }
30
+ success(`Updated role for member ${userId} to ${role}`);
31
+ } catch (e) {
32
+ if (e instanceof HisaaboApiError) {
33
+ const err = e.hisaaboError;
34
+ if (err.code === "not_found") fatalError(`Member not found: ${userId}`, EXIT.NOT_FOUND);
35
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
36
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
37
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
38
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
39
+ }
40
+ fatalError(String(e instanceof Error ? e.message : e));
41
+ }
42
+ }
43
+ export {
44
+ tenantUpdateRoleCommand
45
+ };
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ HisaaboApiError,
4
+ HisaaboClient
5
+ } from "./chunk-4MEL44QX.js";
6
+ import {
7
+ requireAuth
8
+ } from "./chunk-FIMJZAS4.js";
9
+ import {
10
+ EXIT,
11
+ fatalError,
12
+ outputJSON,
13
+ success
14
+ } from "./chunk-NO4FIFMS.js";
15
+
16
+ // src/commands/store/update-settings.ts
17
+ async function storeUpdateSettingsCommand(opts) {
18
+ const cfg = requireAuth();
19
+ const client = new HisaaboClient(cfg);
20
+ const data = {};
21
+ if (opts.slug !== void 0) data["storeSlug"] = opts.slug;
22
+ if (opts.tagline !== void 0) data["storeDescription"] = opts.tagline;
23
+ if (opts.enabled !== void 0) {
24
+ if (opts.enabled !== "true" && opts.enabled !== "false") {
25
+ fatalError("--enabled must be 'true' or 'false'", EXIT.USAGE);
26
+ }
27
+ data["storeEnabled"] = opts.enabled === "true";
28
+ }
29
+ if (Object.keys(data).length === 0) {
30
+ fatalError("At least one option is required (--slug, --tagline, --enabled)", EXIT.USAGE);
31
+ }
32
+ try {
33
+ const result = await client.store.updateSettings(data);
34
+ if (opts.json) {
35
+ outputJSON(result);
36
+ return;
37
+ }
38
+ success("Store settings updated");
39
+ console.log(` Enabled: ${result.storeEnabled ? "Yes" : "No"}`);
40
+ if (result.storeSlug) console.log(` Slug: ${result.storeSlug}`);
41
+ if (result.storeName) console.log(` Name: ${result.storeName}`);
42
+ if (result.storeDescription) console.log(` About: ${result.storeDescription}`);
43
+ console.log();
44
+ } catch (e) {
45
+ if (e instanceof HisaaboApiError) {
46
+ const err = e.hisaaboError;
47
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
48
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
49
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
50
+ }
51
+ fatalError(String(e instanceof Error ? e.message : e));
52
+ }
53
+ }
54
+ export {
55
+ storeUpdateSettingsCommand
56
+ };
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@hisaabo/cli",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/hisaabo/hisaabo.git",
9
+ "directory": "packages/cli"
10
+ },
6
11
  "bin": {
7
12
  "hisaabo": "./dist/bin/hisaabo.js"
8
13
  },
@@ -13,22 +18,18 @@
13
18
  },
14
19
  "dependencies": {
15
20
  "@hisaabo/shared": "workspace:*",
16
- "@inkjs/ui": "^2.0.0",
17
21
  "chalk": "^5.4.0",
18
22
  "commander": "^13.0.0",
19
23
  "conf": "^13.0.0",
20
- "ink": "^5.2.0",
21
24
  "open": "^10.1.0",
22
- "react": "^18.3.1",
23
25
  "superjson": "^2.2.0",
24
26
  "zod": "^3.24.0"
25
27
  },
26
28
  "devDependencies": {
27
29
  "@hisaabo/api": "workspace:*",
28
30
  "@types/node": "^22.0.0",
29
- "@types/react": "^18.3.0",
30
31
  "tsup": "^8.3.0",
31
32
  "tsx": "^4.19.0",
32
33
  "typescript": "^5.7.0"
33
34
  }
34
- }
35
+ }
package/src/auth.ts CHANGED
@@ -2,12 +2,20 @@ import { HisaaboClient, HisaaboApiError } from "./client.js";
2
2
  import { getConfig, setConfig, clearConfig, requireAuth, getConfigPath } from "./config.js";
3
3
  import { fatalError, EXIT, outputJSON, success } from "./output.js";
4
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
+
5
13
  /**
6
14
  * Authenticate using a long-lived API key (hisaabo_key_...).
7
15
  * Validates the token by calling auth.me, then stores it in config.
8
16
  */
9
17
  export async function loginWithToken(apiUrl: string, token: string): Promise<void> {
10
- const base = apiUrl.replace(/\/$/, "");
18
+ const base = validateApiUrl(apiUrl);
11
19
 
12
20
  // Use a temporary client with the token but no business/tenant yet
13
21
  const client = new HisaaboClient({
@@ -81,6 +89,7 @@ export async function loginWithToken(apiUrl: string, token: string): Promise<voi
81
89
  businessId: selected.id,
82
90
  businessName: selected.name,
83
91
  tenantId: selected.id,
92
+ tokenCreatedAt: Date.now(),
84
93
  });
85
94
 
86
95
  success(`Authenticated as ${user.name ?? user.email} (${user.email}) via API key`);
@@ -93,8 +102,7 @@ type AuthUser = { id: string; email: string; name: string | null; role: string }
93
102
  type BusinessSummary = { id: string; name: string; gstin?: string | null; gstRegistrationType?: string | null };
94
103
 
95
104
  export async function login(apiUrl: string, email: string, password: string): Promise<void> {
96
- // Normalize URL
97
- const base = apiUrl.replace(/\/$/, "");
105
+ const base = validateApiUrl(apiUrl);
98
106
 
99
107
  // Use a temporary client without auth for login
100
108
  const client = new HisaaboClient({
@@ -156,6 +164,7 @@ export async function login(apiUrl: string, email: string, password: string): Pr
156
164
  businessId: selected.id,
157
165
  businessName: selected.name,
158
166
  tenantId: selected.id, // fallback; real tenantId may differ
167
+ tokenCreatedAt: Date.now(),
159
168
  });
160
169
 
161
170
  success(`Active business: ${selected.name}`);