@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,66 @@
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
+ hasColor,
13
+ outputJSON,
14
+ outputTable
15
+ } from "./chunk-NO4FIFMS.js";
16
+
17
+ // src/commands/tenant/invitations.ts
18
+ import chalk from "chalk";
19
+ async function listInvitationsCommand(opts) {
20
+ const cfg = requireAuth();
21
+ const client = new HisaaboClient(cfg);
22
+ try {
23
+ const invitations = await client.tenant.pendingInvitations();
24
+ if (opts.json) {
25
+ outputJSON(invitations);
26
+ return;
27
+ }
28
+ const items = Array.isArray(invitations) ? invitations : invitations?.items ?? invitations?.data ?? [];
29
+ if (items.length === 0) {
30
+ console.log("No pending invitations.");
31
+ return;
32
+ }
33
+ const rows = items.map((item) => {
34
+ const inv = item;
35
+ return {
36
+ id: String(inv["id"] ?? "").slice(0, 8) + "...",
37
+ email: String(inv["email"] ?? "\u2014"),
38
+ role: String(inv["role"] ?? "\u2014"),
39
+ invitedBy: String(inv["invitedByName"] ?? "\u2014"),
40
+ expires: inv["expiresAt"] ? new Date(String(inv["expiresAt"])).toLocaleDateString() : "\u2014"
41
+ };
42
+ });
43
+ const columns = [
44
+ { key: "id", header: "ID", align: "left" },
45
+ { key: "email", header: "Email", align: "left" },
46
+ { key: "role", header: "Role", align: "left" },
47
+ { key: "invitedBy", header: "Invited By", align: "left" },
48
+ { key: "expires", header: "Expires", align: "left" }
49
+ ];
50
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" Pending Invitations\n") + "\n");
51
+ else process.stdout.write("\n Pending Invitations\n\n");
52
+ outputTable(rows, columns);
53
+ process.stdout.write("\n");
54
+ } catch (e) {
55
+ if (e instanceof HisaaboApiError) {
56
+ const err = e.hisaaboError;
57
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
58
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
59
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
60
+ }
61
+ fatalError(String(e instanceof Error ? e.message : e));
62
+ }
63
+ }
64
+ export {
65
+ listInvitationsCommand
66
+ };
@@ -0,0 +1,53 @@
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/invite.ts
17
+ var VALID_ROLES = ["admin", "seller_manager", "seller", "accountant"];
18
+ async function tenantInviteCommand(email, opts) {
19
+ const cfg = requireAuth();
20
+ const client = new HisaaboClient(cfg);
21
+ const role = opts.role ?? "seller";
22
+ if (!VALID_ROLES.includes(role)) {
23
+ fatalError(`Invalid role "${role}". Must be one of: ${VALID_ROLES.join(", ")}`, EXIT.VALIDATION);
24
+ }
25
+ try {
26
+ const result = await client.tenant.inviteMember({ email, role });
27
+ if (opts.json) {
28
+ outputJSON(result);
29
+ return;
30
+ }
31
+ success(`Invited ${email} as ${role}`);
32
+ if (result.inviteLink) {
33
+ console.log(` Invite link: ${result.inviteLink}`);
34
+ } else if (result.inviteToken) {
35
+ console.log(` Invite token: ${result.inviteToken}`);
36
+ }
37
+ if (result.message) {
38
+ console.log(` ${result.message}`);
39
+ }
40
+ } catch (e) {
41
+ if (e instanceof HisaaboApiError) {
42
+ const err = e.hisaaboError;
43
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
44
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
45
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
46
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
47
+ }
48
+ fatalError(String(e instanceof Error ? e.message : e));
49
+ }
50
+ }
51
+ export {
52
+ tenantInviteCommand
53
+ };
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount,
4
+ formatStatus,
5
+ fyStart,
6
+ monthEnd,
7
+ monthStart,
8
+ todayISO
9
+ } from "./chunk-T63VQXNM.js";
10
+ import {
11
+ HisaaboApiError,
12
+ HisaaboClient
13
+ } from "./chunk-4MEL44QX.js";
14
+ import {
15
+ requireAuth
16
+ } from "./chunk-FIMJZAS4.js";
17
+ import {
18
+ EXIT,
19
+ fatalError,
20
+ hasColor,
21
+ outputJSON,
22
+ outputTable
23
+ } from "./chunk-NO4FIFMS.js";
24
+
25
+ // src/commands/dashboard/invoice-breakdown.ts
26
+ import chalk from "chalk";
27
+ async function dashboardInvoiceBreakdownCommand(opts) {
28
+ const cfg = requireAuth();
29
+ const client = new HisaaboClient(cfg);
30
+ let fromDate = opts.from;
31
+ let toDate = opts.to;
32
+ if (opts.thisMonth) {
33
+ fromDate = monthStart();
34
+ toDate = monthEnd();
35
+ } else if (opts.thisFy) {
36
+ fromDate = fyStart();
37
+ toDate = todayISO();
38
+ }
39
+ try {
40
+ const data = await client.dashboard.invoiceStatusBreakdown({ fromDate, toDate });
41
+ if (opts.json) {
42
+ outputJSON(data);
43
+ return;
44
+ }
45
+ const ORDER = ["draft", "sent", "partial", "paid", "overdue", "cancelled"];
46
+ let rows;
47
+ if (Array.isArray(data)) {
48
+ rows = data.map((r) => ({
49
+ status: formatStatus(String(r["status"] ?? "-")),
50
+ count: String(r["count"] ?? "-"),
51
+ amount: formatAmount(String(r["totalAmount"] ?? r["amount"] ?? "0"))
52
+ }));
53
+ } else if (data && typeof data === "object") {
54
+ const obj = data;
55
+ rows = ORDER.flatMap((status) => {
56
+ const entry = obj[status];
57
+ if (!entry) return [];
58
+ return [{
59
+ status: formatStatus(status),
60
+ count: String(entry["count"] ?? "-"),
61
+ amount: formatAmount(String(entry["totalAmount"] ?? entry["amount"] ?? "0"))
62
+ }];
63
+ });
64
+ for (const key of Object.keys(obj)) {
65
+ if (!ORDER.includes(key)) {
66
+ const entry = obj[key];
67
+ rows.push({
68
+ status: formatStatus(key),
69
+ count: String(entry["count"] ?? "-"),
70
+ amount: formatAmount(String(entry["totalAmount"] ?? entry["amount"] ?? "0"))
71
+ });
72
+ }
73
+ }
74
+ } else {
75
+ rows = [];
76
+ }
77
+ const columns = [
78
+ { key: "status", header: "Status", align: "left" },
79
+ { key: "count", header: "Count", align: "right" },
80
+ { key: "amount", header: "Amount \u20B9", align: "right" }
81
+ ];
82
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" Invoice Status Breakdown\n") + "\n");
83
+ else process.stdout.write("\n Invoice Status Breakdown\n\n");
84
+ outputTable(rows, columns);
85
+ process.stdout.write("\n");
86
+ } catch (e) {
87
+ if (e instanceof HisaaboApiError) {
88
+ const err = e.hisaaboError;
89
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
90
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
91
+ }
92
+ fatalError(String(e instanceof Error ? e.message : e));
93
+ }
94
+ }
95
+ export {
96
+ dashboardInvoiceBreakdownCommand
97
+ };
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatAmount
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
+ outputCSV,
16
+ outputJSON,
17
+ outputTSV,
18
+ outputTable
19
+ } from "./chunk-NO4FIFMS.js";
20
+
21
+ // src/commands/store/items.ts
22
+ async function storeItemsCommand(opts) {
23
+ const cfg = requireAuth();
24
+ const client = new HisaaboClient(cfg);
25
+ try {
26
+ const items = await client.store.listStoreItems({});
27
+ if (opts.json) {
28
+ outputJSON(items);
29
+ return;
30
+ }
31
+ const cols = [
32
+ { key: "id", header: "ID", width: 36 },
33
+ { key: "name", header: "Name", width: 30 },
34
+ { key: "price", header: "Price (\u20B9)", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
35
+ { key: "enabled", header: "Status", width: 10, format: (v) => v ? "Enabled" : "Disabled" },
36
+ { key: "stock", header: "Stock", align: "right", width: 8, format: (v) => v == null ? "-" : String(v) }
37
+ ];
38
+ if (opts.format === "tsv") {
39
+ outputTSV(items, cols);
40
+ return;
41
+ }
42
+ if (opts.format === "csv") {
43
+ outputCSV(items, cols);
44
+ return;
45
+ }
46
+ console.log(`
47
+ Store Items (${items.length} total)
48
+ `);
49
+ outputTable(items, cols);
50
+ console.log();
51
+ } catch (e) {
52
+ if (e instanceof HisaaboApiError) {
53
+ const err = e.hisaaboError;
54
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
55
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
56
+ }
57
+ fatalError(String(e instanceof Error ? e.message : e));
58
+ }
59
+ }
60
+ export {
61
+ storeItemsCommand
62
+ };
@@ -0,0 +1,46 @@
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/items-toggle.ts
17
+ async function storeItemsToggleCommand(opts) {
18
+ const cfg = requireAuth();
19
+ const client = new HisaaboClient(cfg);
20
+ if (!opts.enable && !opts.disable) {
21
+ fatalError("At least one of --enable or --disable is required", EXIT.USAGE);
22
+ }
23
+ const enableIds = opts.enable ? opts.enable.split(",").map((s) => s.trim()).filter(Boolean) : [];
24
+ const disableIds = opts.disable ? opts.disable.split(",").map((s) => s.trim()).filter(Boolean) : [];
25
+ try {
26
+ const result = await client.store.bulkToggleItems({ enable: enableIds, disable: disableIds });
27
+ if (opts.json) {
28
+ outputJSON(result);
29
+ return;
30
+ }
31
+ if (enableIds.length > 0) success(`Enabled ${enableIds.length} item(s)`);
32
+ if (disableIds.length > 0) success(`Disabled ${disableIds.length} item(s)`);
33
+ console.log();
34
+ } catch (e) {
35
+ if (e instanceof HisaaboApiError) {
36
+ const err = e.hisaaboError;
37
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
38
+ if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
39
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
40
+ }
41
+ fatalError(String(e instanceof Error ? e.message : e));
42
+ }
43
+ }
44
+ export {
45
+ storeItemsToggleCommand
46
+ };
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatDate,
4
+ formatRelativeDate
5
+ } from "./chunk-T63VQXNM.js";
6
+ import {
7
+ HisaaboApiError,
8
+ HisaaboClient
9
+ } from "./chunk-4MEL44QX.js";
10
+ import {
11
+ requireAuth
12
+ } from "./chunk-FIMJZAS4.js";
13
+ import {
14
+ EXIT,
15
+ fatalError,
16
+ hasColor,
17
+ outputCSV,
18
+ outputJSON,
19
+ outputTSV,
20
+ outputTable
21
+ } from "./chunk-NO4FIFMS.js";
22
+
23
+ // src/commands/api-key/list.ts
24
+ import chalk from "chalk";
25
+ async function apiKeyListCommand(opts) {
26
+ const cfg = requireAuth();
27
+ const client = new HisaaboClient(cfg);
28
+ try {
29
+ const keys = await client.apiKey.list();
30
+ if (opts.json) {
31
+ outputJSON(keys);
32
+ return;
33
+ }
34
+ const items = Array.isArray(keys) ? keys : keys?.items ?? keys?.data ?? [];
35
+ if (items.length === 0) {
36
+ process.stdout.write("\n No API keys found.\n Use: hisaabo api-key create --name <name>\n\n");
37
+ return;
38
+ }
39
+ const rows = items.map((item) => {
40
+ const k = item;
41
+ const rawKey = String(k["keyPrefix"] ?? k["prefix"] ?? k["key"] ?? "");
42
+ const displayKey = rawKey.length > 20 ? rawKey.slice(0, 20) + "..." : rawKey || "-";
43
+ return {
44
+ name: String(k["name"] ?? "-"),
45
+ prefix: displayKey,
46
+ created: formatDate(String(k["createdAt"] ?? "")),
47
+ lastUsed: k["lastUsedAt"] ? formatRelativeDate(String(k["lastUsedAt"])) : "Never",
48
+ id: String(k["id"] ?? "-")
49
+ };
50
+ });
51
+ const columns = [
52
+ { key: "name", header: "Name", align: "left" },
53
+ { key: "prefix", header: "Key Prefix", align: "left" },
54
+ { key: "created", header: "Created", align: "left" },
55
+ { key: "lastUsed", header: "Last Used", align: "left" },
56
+ { key: "id", header: "ID", align: "left", width: 36 }
57
+ ];
58
+ if (opts.format === "tsv") {
59
+ outputTSV(rows, columns);
60
+ } else if (opts.format === "csv") {
61
+ outputCSV(rows, columns);
62
+ } else {
63
+ if (hasColor()) process.stdout.write("\n" + chalk.bold(" API Keys\n") + "\n");
64
+ else process.stdout.write("\n API Keys\n\n");
65
+ outputTable(rows, columns);
66
+ process.stdout.write("\n");
67
+ }
68
+ } catch (e) {
69
+ if (e instanceof HisaaboApiError) {
70
+ const err = e.hisaaboError;
71
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
72
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
73
+ }
74
+ fatalError(String(e instanceof Error ? e.message : e));
75
+ }
76
+ }
77
+ export {
78
+ apiKeyListCommand
79
+ };
@@ -0,0 +1,90 @@
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
+ hasColor,
13
+ outputJSON,
14
+ outputTable
15
+ } from "./chunk-NO4FIFMS.js";
16
+
17
+ // src/commands/session/list.ts
18
+ import chalk from "chalk";
19
+ async function listSessionsCommand(opts) {
20
+ const cfg = requireAuth();
21
+ const client = new HisaaboClient(cfg);
22
+ try {
23
+ const sessions = await client.auth.listSessions({ expired: opts.expired ?? false });
24
+ if (opts.json) {
25
+ outputJSON(sessions);
26
+ return;
27
+ }
28
+ const items = Array.isArray(sessions) ? sessions : sessions?.items ?? sessions?.data ?? [];
29
+ if (items.length === 0) {
30
+ console.log(opts.expired ? "No expired sessions." : "No active sessions.");
31
+ return;
32
+ }
33
+ const rows = items.map((item) => {
34
+ const s = item;
35
+ return {
36
+ id: String(s["id"] ?? "").slice(0, 12) + "...",
37
+ device: s["userAgent"] ? parseUA(String(s["userAgent"])) : "Unknown",
38
+ ip: String(s["ipAddress"] ?? "\u2014"),
39
+ lastUsed: s["lastUsedAt"] ? timeAgo(String(s["lastUsedAt"])) : "\u2014",
40
+ created: s["createdAt"] ? new Date(String(s["createdAt"])).toLocaleDateString() : "\u2014",
41
+ current: s["isCurrent"] ? "\u2713" : ""
42
+ };
43
+ });
44
+ const columns = [
45
+ { key: "id", header: "ID", align: "left" },
46
+ { key: "device", header: "Device", align: "left" },
47
+ { key: "ip", header: "IP", align: "left" },
48
+ { key: "lastUsed", header: "Last Used", align: "left" },
49
+ { key: "created", header: "Created", align: "left" },
50
+ { key: "current", header: "Current", align: "left" }
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
+ function parseUA(ua) {
66
+ let browser = "Unknown";
67
+ if (ua.includes("Edg/")) browser = "Edge";
68
+ else if (ua.includes("Chrome/")) browser = "Chrome";
69
+ else if (ua.includes("Firefox/")) browser = "Firefox";
70
+ else if (ua.includes("Safari/")) browser = "Safari";
71
+ let os = "";
72
+ if (ua.includes("Windows")) os = "Windows";
73
+ else if (ua.includes("Mac OS")) os = "macOS";
74
+ else if (ua.includes("Linux")) os = "Linux";
75
+ else if (ua.includes("Android")) os = "Android";
76
+ else if (ua.includes("iPhone") || ua.includes("iPad")) os = "iOS";
77
+ return os ? `${browser} / ${os}` : browser;
78
+ }
79
+ function timeAgo(date) {
80
+ const diff = Date.now() - new Date(date).getTime();
81
+ const mins = Math.floor(diff / 6e4);
82
+ if (mins < 1) return "now";
83
+ if (mins < 60) return `${mins}m ago`;
84
+ const hrs = Math.floor(mins / 60);
85
+ if (hrs < 24) return `${hrs}h ago`;
86
+ return `${Math.floor(hrs / 24)}d ago`;
87
+ }
88
+ export {
89
+ listSessionsCommand
90
+ };
@@ -0,0 +1,46 @@
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
+ outputTable
14
+ } from "./chunk-NO4FIFMS.js";
15
+
16
+ // src/commands/tenant/list.ts
17
+ async function tenantListCommand(opts) {
18
+ const cfg = requireAuth();
19
+ const client = new HisaaboClient(cfg);
20
+ try {
21
+ const result = await client.tenant.list();
22
+ if (opts.json) {
23
+ outputJSON(result);
24
+ return;
25
+ }
26
+ console.log(`
27
+ Organizations ${result.length} total
28
+ `);
29
+ const cols = [
30
+ { key: "name", header: "Name", width: 30 },
31
+ { key: "slug", header: "Slug", width: 24 },
32
+ { key: "role", header: "Role", width: 16 }
33
+ ];
34
+ outputTable(result, cols);
35
+ } catch (e) {
36
+ if (e instanceof HisaaboApiError) {
37
+ const err = e.hisaaboError;
38
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
39
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
40
+ }
41
+ fatalError(String(e instanceof Error ? e.message : e));
42
+ }
43
+ }
44
+ export {
45
+ tenantListCommand
46
+ };
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ formatDate
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
+ outputCSV,
16
+ outputJSON,
17
+ outputTSV,
18
+ outputTable
19
+ } from "./chunk-NO4FIFMS.js";
20
+
21
+ // src/commands/tenant/members.ts
22
+ async function tenantMembersCommand(opts) {
23
+ const cfg = requireAuth();
24
+ const client = new HisaaboClient(cfg);
25
+ try {
26
+ const result = await client.tenant.members();
27
+ if (opts.json) {
28
+ outputJSON(result);
29
+ return;
30
+ }
31
+ console.log(`
32
+ Team Members ${result.length} total
33
+ `);
34
+ const cols = [
35
+ { key: "name", header: "Name", width: 24 },
36
+ { key: "email", header: "Email", width: 30 },
37
+ { key: "role", header: "Role", width: 18 },
38
+ { key: "joinedAt", header: "Joined", width: 13, format: (v) => formatDate(String(v ?? "")) }
39
+ ];
40
+ if (opts.format === "tsv") outputTSV(result, cols);
41
+ else if (opts.format === "csv") outputCSV(result, cols);
42
+ else outputTable(result, cols);
43
+ } catch (e) {
44
+ if (e instanceof HisaaboApiError) {
45
+ const err = e.hisaaboError;
46
+ if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
47
+ if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
48
+ if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
49
+ }
50
+ fatalError(String(e instanceof Error ? e.message : e));
51
+ }
52
+ }
53
+ export {
54
+ tenantMembersCommand
55
+ };