@hisaabo/cli 0.3.2 → 0.5.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 (85) hide show
  1. package/.turbo/turbo-typecheck.log +1 -1
  2. package/README.md +1 -1
  3. package/dist/bin/{audit-trail-2YGXGUXW.js → audit-trail-5LOCJ7XZ.js} +4 -4
  4. package/dist/bin/{categories-P5VFWD5F.js → categories-64WWZTND.js} +3 -3
  5. package/dist/bin/{check-slug-4TMOTWUJ.js → check-slug-FLHHUDYS.js} +3 -3
  6. package/dist/bin/{chunk-FTOBDKMO.js → chunk-4MEL44QX.js} +54 -10
  7. package/dist/bin/chunk-FIMJZAS4.js +84 -0
  8. package/dist/bin/{chunk-EYNDY7RB.js → chunk-NO4FIFMS.js} +2 -1
  9. package/dist/bin/{chunk-FFBG6RU4.js → chunk-T63VQXNM.js} +1 -1
  10. package/dist/bin/{client-QNJ2H5CW.js → client-5NZ23GML.js} +1 -1
  11. package/dist/bin/{collection-efficiency-WMKEGS6U.js → collection-efficiency-U56XNVEE.js} +4 -4
  12. package/dist/bin/{config-UKVQYPPR.js → config-335MN4I7.js} +2 -2
  13. package/dist/bin/{create-Y22FAVOW.js → create-RPDEORDD.js} +3 -3
  14. package/dist/bin/{default-account-SA56M66A.js → default-account-AE6EXZZR.js} +3 -3
  15. package/dist/bin/{expenses-VZAOLYUW.js → expenses-5N2QSG54.js} +4 -4
  16. package/dist/bin/{export-QZ6WT6PJ.js → export-QICOQK34.js} +3 -3
  17. package/dist/bin/{factory-2DCU3B5T.js → factory-KOCW2AQM.js} +4 -4
  18. package/dist/bin/{get-EXL44I2X.js → get-A43QCI2S.js} +3 -3
  19. package/dist/bin/{get-6UYP6UVD.js → get-GWH6S5SJ.js} +4 -4
  20. package/dist/bin/hisaabo.js +281 -70
  21. package/dist/bin/invitations-P3EEN5WI.js +66 -0
  22. package/dist/bin/{invite-O26SAL72.js → invite-T3CKX53E.js} +3 -3
  23. package/dist/bin/{invoice-breakdown-XEATXVMR.js → invoice-breakdown-FN5BEFJD.js} +4 -4
  24. package/dist/bin/{items-3U5USBVG.js → items-2OOCQKVF.js} +4 -4
  25. package/dist/bin/{items-toggle-YEKMI2CM.js → items-toggle-SKZWCGJH.js} +3 -3
  26. package/dist/bin/{list-VBAHY72W.js → list-A2RKI3ZG.js} +4 -4
  27. package/dist/bin/list-NRMBMKMI.js +90 -0
  28. package/dist/bin/{list-FX2C3NCL.js → list-T74SN6IR.js} +3 -3
  29. package/dist/bin/{members-5FPRUAB6.js → members-W2GW3ODT.js} +4 -4
  30. package/dist/bin/{monthly-comparison-JEJ3TTY2.js → monthly-comparison-T34ZFOHL.js} +4 -4
  31. package/dist/bin/{order-cancel-XI2LKYXV.js → order-cancel-TI27JYYD.js} +3 -3
  32. package/dist/bin/{order-confirm-HUFCU6MO.js → order-confirm-VMRAMNTD.js} +3 -3
  33. package/dist/bin/{order-get-NSDMPUZR.js → order-get-C2RBUR4O.js} +4 -4
  34. package/dist/bin/{order-update-C7QYSD5R.js → order-update-RE3HATNF.js} +4 -4
  35. package/dist/bin/{output-QFLEKG5W.js → output-NUOL7KJW.js} +1 -1
  36. package/dist/bin/{payment-modes-WI3AWSES.js → payment-modes-WOOT22I7.js} +4 -4
  37. package/dist/bin/{profit-loss-5RIEOBKP.js → profit-loss-T4RESJ32.js} +4 -4
  38. package/dist/bin/{receivables-aging-L6DIQCNE.js → receivables-aging-6XMENEWS.js} +4 -4
  39. package/dist/bin/{remove-M2B4TZ37.js → remove-6QZI4JCY.js} +3 -3
  40. package/dist/bin/revoke-AVEMPAC7.js +40 -0
  41. package/dist/bin/{revoke-H3V2GNCD.js → revoke-YUCFZFNR.js} +3 -3
  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-TICB3KGF.js → sales-trend-ZYBRUDUU.js} +4 -4
  45. package/dist/bin/{sequence-XUD6FAKY.js → sequence-FPOJTI2P.js} +3 -3
  46. package/dist/bin/{store-UQ2DDQ5I.js → store-IOB4Y67C.js} +4 -4
  47. package/dist/bin/{summary-BPNFC7I2.js → summary-5KYBA4ZO.js} +4 -4
  48. package/dist/bin/{top-customers-WGGJWKCN.js → top-customers-WSQ2UEJL.js} +4 -4
  49. package/dist/bin/{top-items-C7ZDDJMR.js → top-items-RWQPDGLN.js} +4 -4
  50. package/dist/bin/{top-outstanding-MOGWJIQS.js → top-outstanding-QAMO2E7Y.js} +4 -4
  51. package/dist/bin/{unpaid-invoices-ZUPNMQJP.js → unpaid-invoices-WB3TK5B4.js} +4 -4
  52. package/dist/bin/{untracked-BCJEVDW4.js → untracked-H733MYJL.js} +4 -4
  53. package/dist/bin/{update-IG565YIN.js → update-H6LPO2Z4.js} +3 -3
  54. package/dist/bin/{update-HIU4PANX.js → update-JU2X3XU5.js} +4 -4
  55. package/dist/bin/{update-PVLAX7T3.js → update-TLBUIC5J.js} +4 -4
  56. package/dist/bin/{update-role-Q4ZYJRYT.js → update-role-QST7BVFX.js} +3 -3
  57. package/dist/bin/{update-settings-XPC6L5WM.js → update-settings-Q2EGRLKZ.js} +3 -3
  58. package/package.json +1 -5
  59. package/src/auth.ts +12 -3
  60. package/src/bin/hisaabo.ts +6 -1
  61. package/src/bin/registrars/auth.ts +79 -10
  62. package/src/bin/registrars/bank.ts +34 -0
  63. package/src/bin/registrars/session.ts +32 -0
  64. package/src/bin/registrars/tenant.ts +18 -0
  65. package/src/client.ts +95 -12
  66. package/src/commands/bank/gateway-config.ts +61 -0
  67. package/src/commands/bank/update-gateway.ts +84 -0
  68. package/src/commands/payment/create.ts +1 -3
  69. package/src/commands/session/list.ts +91 -0
  70. package/src/commands/session/revoke-all.ts +20 -0
  71. package/src/commands/session/revoke.ts +32 -0
  72. package/src/commands/tenant/invitations.ts +62 -0
  73. package/src/commands/tenant/revoke-invitation.ts +32 -0
  74. package/src/config.ts +51 -2
  75. package/src/error-handler.ts +53 -0
  76. package/src/output.ts +1 -0
  77. package/src/spinner.ts +39 -0
  78. package/tsup.config.ts +6 -1
  79. package/dist/bin/chunk-2P35S2C3.js +0 -46
  80. package/src/components/ErrorDisplay.tsx +0 -16
  81. package/src/components/Header.tsx +0 -26
  82. package/src/components/MoneyCell.tsx +0 -16
  83. package/src/components/Spinner.tsx +0 -12
  84. package/src/components/StatusBadge.tsx +0 -39
  85. package/src/components/Table.tsx +0 -63
package/src/config.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import Conf from "conf";
2
- import { fatalError } from "./output.js";
2
+ import { hostname, userInfo } from "os";
3
+ import { createHash } from "crypto";
4
+ import { fatalError, warn } from "./output.js";
3
5
 
4
6
  interface ConfigSchema {
5
7
  apiUrl: string;
@@ -7,12 +9,32 @@ interface ConfigSchema {
7
9
  tenantId: string;
8
10
  businessId: string;
9
11
  businessName: string;
12
+ tokenCreatedAt: number;
13
+ }
14
+
15
+ /**
16
+ * Derive a machine+user-specific encryption key. Prevents casual read of
17
+ * the config file and stops accidental credential leaks in screenshots,
18
+ * backups, or `cat` output. Not unbreakable — but the token at rest is
19
+ * no longer plaintext.
20
+ */
21
+ function deriveEncryptionKey(): string {
22
+ let uid: string;
23
+ try {
24
+ uid = String(userInfo().uid);
25
+ } catch {
26
+ uid = String(process.getuid?.() ?? process.pid);
27
+ }
28
+ const raw = `${uid}:${hostname()}:hisaabo-cli`;
29
+ return createHash("sha256").update(raw).digest("hex");
10
30
  }
11
31
 
12
32
  const conf = new Conf<Partial<ConfigSchema>>({
13
33
  projectName: "hisaabo",
14
34
  projectSuffix: "",
15
35
  configName: "config",
36
+ encryptionKey: deriveEncryptionKey(),
37
+ configFileMode: 0o600, // owner read/write only — prevents credential theft on shared systems
16
38
  });
17
39
 
18
40
  export function getConfig(): Partial<ConfigSchema> {
@@ -21,7 +43,9 @@ export function getConfig(): Partial<ConfigSchema> {
21
43
 
22
44
  export function setConfig(values: Partial<ConfigSchema>): void {
23
45
  for (const [k, v] of Object.entries(values)) {
24
- conf.set(k as keyof ConfigSchema, v as string);
46
+ if (v !== undefined) {
47
+ conf.set(k as keyof ConfigSchema, v as string);
48
+ }
25
49
  }
26
50
  }
27
51
 
@@ -35,10 +59,35 @@ export function isAuthenticated(): boolean {
35
59
  }
36
60
 
37
61
  export function requireAuth(): ConfigSchema {
62
+ // Environment variables take priority — never persisted to disk (CI/scripts)
63
+ const envToken = process.env["HISAABO_TOKEN"];
64
+ const envUrl = process.env["HISAABO_API_URL"];
65
+ if (envToken && envUrl) {
66
+ return {
67
+ apiUrl: envUrl,
68
+ token: envToken,
69
+ tenantId: process.env["HISAABO_TENANT_ID"] ?? "",
70
+ businessId: process.env["HISAABO_BUSINESS_ID"] ?? "",
71
+ businessName: process.env["HISAABO_BUSINESS_NAME"] ?? "",
72
+ tokenCreatedAt: Date.now(),
73
+ };
74
+ }
75
+
38
76
  const cfg = getConfig();
39
77
  if (!cfg.token || !cfg.apiUrl || !cfg.businessId || !cfg.tenantId) {
40
78
  fatalError("Not authenticated. Run: hisaabo login", 3);
41
79
  }
80
+
81
+ // Warn about expiring session tokens (not API keys)
82
+ const isApiKey = cfg.token.startsWith("hisaabo_key_");
83
+ if (!isApiKey && cfg.tokenCreatedAt) {
84
+ const ageMs = Date.now() - cfg.tokenCreatedAt;
85
+ const TWENTY_FIVE_DAYS = 25 * 24 * 60 * 60 * 1000;
86
+ if (ageMs > TWENTY_FIVE_DAYS) {
87
+ warn("Session expires soon. Run: hisaabo login");
88
+ }
89
+ }
90
+
42
91
  return cfg as ConfigSchema;
43
92
  }
44
93
 
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Shared error handler for CLI commands.
3
+ *
4
+ * Extracts the repeated try-catch pattern from 100+ command files into a
5
+ * single function. All tRPC error codes are handled with actionable messages
6
+ * and appropriate exit codes.
7
+ */
8
+
9
+ import { HisaaboApiError } from "./client.js";
10
+ import { fatalError, EXIT } from "./output.js";
11
+ import { getConfig } from "./config.js";
12
+
13
+ /**
14
+ * Handle any error thrown during a CLI command. Recognizes HisaaboApiError
15
+ * subtypes and exits with the correct code and message.
16
+ *
17
+ * Usage:
18
+ * try {
19
+ * await doStuff();
20
+ * } catch (e) {
21
+ * handleApiError(e);
22
+ * }
23
+ */
24
+ export function handleApiError(e: unknown): never {
25
+ if (e instanceof HisaaboApiError) {
26
+ const err = e.hisaaboError;
27
+
28
+ if (err.code === "unauthorized") {
29
+ fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
30
+ } else if (err.code === "forbidden") {
31
+ fatalError(err.message, EXIT.FORBIDDEN);
32
+ } else if (err.code === "not_found") {
33
+ fatalError(err.resource, EXIT.NOT_FOUND);
34
+ } else if (err.code === "validation_failed") {
35
+ fatalError(e.message, EXIT.VALIDATION);
36
+ } else if (err.code === "rate_limited") {
37
+ fatalError(err.message, EXIT.RATE_LIMITED);
38
+ } else if (err.code === "network_error") {
39
+ const cfg = getConfig();
40
+ const url = cfg.apiUrl ?? "unknown";
41
+ fatalError(
42
+ `Cannot reach ${url}\n` +
43
+ ` Is the server running? Check: curl ${url}/health\n` +
44
+ ` Wrong URL? Run: hisaabo login`,
45
+ EXIT.NETWORK,
46
+ );
47
+ } else {
48
+ fatalError(e.message, EXIT.GENERAL);
49
+ }
50
+ }
51
+
52
+ fatalError(String(e instanceof Error ? e.message : e), EXIT.GENERAL);
53
+ }
package/src/output.ts CHANGED
@@ -46,6 +46,7 @@ export const EXIT = {
46
46
  VALIDATION: 6,
47
47
  NETWORK: 7,
48
48
  CONFLICT: 8,
49
+ RATE_LIMITED: 9,
49
50
  } as const;
50
51
 
51
52
  // ── Output helpers ────────────────────────────────────────────────────────
package/src/spinner.ts ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Spinner utility for long-running CLI operations.
3
+ *
4
+ * Uses a simple ANSI spinner that works cross-platform. No external deps
5
+ * needed — just stdout.write with cursor control.
6
+ */
7
+
8
+ const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
9
+ const INTERVAL = 80;
10
+
11
+ /**
12
+ * Run an async function with a terminal spinner. The spinner is only shown
13
+ * when stdout is a TTY (skipped in pipes/CI).
14
+ *
15
+ * Usage:
16
+ * const result = await withSpinner("Loading invoices...", () => client.invoice.list(input));
17
+ */
18
+ export async function withSpinner<T>(label: string, fn: () => Promise<T>): Promise<T> {
19
+ // No spinner in non-interactive environments
20
+ if (!process.stdout.isTTY) return fn();
21
+
22
+ let frame = 0;
23
+ const timer = setInterval(() => {
24
+ const spinner = FRAMES[frame % FRAMES.length];
25
+ process.stdout.write(`\r ${spinner} ${label}`);
26
+ frame++;
27
+ }, INTERVAL);
28
+
29
+ try {
30
+ const result = await fn();
31
+ clearInterval(timer);
32
+ process.stdout.write(`\r${" ".repeat(label.length + 6)}\r`); // clear spinner line
33
+ return result;
34
+ } catch (err) {
35
+ clearInterval(timer);
36
+ process.stdout.write(`\r${" ".repeat(label.length + 6)}\r`);
37
+ throw err;
38
+ }
39
+ }
package/tsup.config.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { defineConfig } from "tsup";
2
+ import { readFileSync } from "fs";
3
+
4
+ const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf-8"));
2
5
 
3
6
  export default defineConfig({
4
7
  entry: ["src/bin/hisaabo.ts"],
@@ -7,7 +10,9 @@ export default defineConfig({
7
10
  banner: {
8
11
  js: "#!/usr/bin/env node",
9
12
  },
10
- external: ["react", "ink", "@inkjs/ui"],
13
+ define: {
14
+ __CLI_VERSION__: JSON.stringify(pkg.version),
15
+ },
11
16
  outDir: "dist/bin",
12
17
  clean: true,
13
18
  });
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- fatalError
4
- } from "./chunk-EYNDY7RB.js";
5
-
6
- // src/config.ts
7
- import Conf from "conf";
8
- var conf = new Conf({
9
- projectName: "hisaabo",
10
- projectSuffix: "",
11
- configName: "config"
12
- });
13
- function getConfig() {
14
- return conf.store;
15
- }
16
- function setConfig(values) {
17
- for (const [k, v] of Object.entries(values)) {
18
- conf.set(k, v);
19
- }
20
- }
21
- function clearConfig() {
22
- conf.clear();
23
- }
24
- function isAuthenticated() {
25
- const cfg = getConfig();
26
- return !!(cfg.token && cfg.apiUrl && cfg.businessId);
27
- }
28
- function requireAuth() {
29
- const cfg = getConfig();
30
- if (!cfg.token || !cfg.apiUrl || !cfg.businessId || !cfg.tenantId) {
31
- fatalError("Not authenticated. Run: hisaabo login", 3);
32
- }
33
- return cfg;
34
- }
35
- function getConfigPath() {
36
- return conf.path;
37
- }
38
-
39
- export {
40
- getConfig,
41
- setConfig,
42
- clearConfig,
43
- isAuthenticated,
44
- requireAuth,
45
- getConfigPath
46
- };
@@ -1,16 +0,0 @@
1
- import React from "react";
2
- import { Box, Text } from "ink";
3
-
4
- interface Props {
5
- message: string;
6
- detail?: string;
7
- }
8
-
9
- export function ErrorDisplay({ message, detail }: Props) {
10
- return (
11
- <Box flexDirection="column">
12
- <Text color="red">Error: {message}</Text>
13
- {detail && <Text color="gray">{detail}</Text>}
14
- </Box>
15
- );
16
- }
@@ -1,26 +0,0 @@
1
- import React from "react";
2
- import { Box, Text } from "ink";
3
-
4
- interface Props {
5
- title: string;
6
- subtitle?: string;
7
- right?: string;
8
- }
9
-
10
- export function Header({ title, subtitle, right }: Props) {
11
- const width = process.stdout.columns ?? 80;
12
- return (
13
- <Box flexDirection="column" marginBottom={1}>
14
- <Box>
15
- <Text bold color="white">{" " + title}</Text>
16
- {right && (
17
- <Box flexGrow={1} justifyContent="flex-end">
18
- <Text dimColor>{right + " "}</Text>
19
- </Box>
20
- )}
21
- </Box>
22
- {subtitle && <Text dimColor>{" " + subtitle}</Text>}
23
- <Text dimColor>{" " + "═".repeat(Math.min(width - 2, 70))}</Text>
24
- </Box>
25
- );
26
- }
@@ -1,16 +0,0 @@
1
- import React from "react";
2
- import { Text } from "ink";
3
- import { formatAmount } from "../format.js";
4
-
5
- interface Props {
6
- amount: string | number;
7
- colored?: boolean;
8
- }
9
-
10
- export function MoneyCell({ amount, colored = false }: Props) {
11
- const num = typeof amount === "string" ? parseFloat(amount) : amount;
12
- const formatted = formatAmount(amount);
13
- if (!colored) return <Text>{formatted}</Text>;
14
- if (num < 0) return <Text color="red">{formatted}</Text>;
15
- return <Text color="green">{formatted}</Text>;
16
- }
@@ -1,12 +0,0 @@
1
- import React from "react";
2
- import { Spinner as InkSpinner } from "@inkjs/ui";
3
-
4
- interface Props {
5
- label?: string;
6
- }
7
-
8
- export function Spinner({ label = "Loading..." }: Props) {
9
- return (
10
- <InkSpinner label={label} />
11
- );
12
- }
@@ -1,39 +0,0 @@
1
- import React from "react";
2
- import { Text } from "ink";
3
-
4
- interface Props {
5
- status: string;
6
- }
7
-
8
- type StatusColor = "green" | "blue" | "yellow" | "red" | "cyan" | "white" | "gray";
9
-
10
- const STATUS_MAP: Record<string, { label: string; color: StatusColor; dimColor?: boolean }> = {
11
- paid: { label: "PAID", color: "green" },
12
- sent: { label: "SENT", color: "blue" },
13
- draft: { label: "DRAFT", color: "white", dimColor: true },
14
- partial: { label: "PARTIAL", color: "yellow" },
15
- overdue: { label: "OVERDUE", color: "red" },
16
- cancelled: { label: "CANCEL", color: "white", dimColor: true },
17
- unfulfilled: { label: "UNFUL", color: "blue" },
18
- pending: { label: "PEND", color: "yellow" },
19
- confirmed: { label: "CONF", color: "blue" },
20
- delivered: { label: "DELIV", color: "green" },
21
- shipped: { label: "SHIPPED", color: "cyan" },
22
- in_transit: { label: "TRANSIT", color: "cyan" },
23
- returned: { label: "RETURN", color: "red" },
24
- preparing: { label: "PREP", color: "yellow" },
25
- ready: { label: "READY", color: "cyan" },
26
- };
27
-
28
- export function StatusBadge({ status }: Props) {
29
- const cfg = STATUS_MAP[status.toLowerCase()];
30
- const label = cfg ? `[${cfg.label}]` : `[${status.toUpperCase()}]`;
31
- const color = cfg?.color ?? "white";
32
- const dimColor = cfg?.dimColor ?? false;
33
-
34
- return (
35
- <Text color={color} dimColor={dimColor}>
36
- {label}
37
- </Text>
38
- );
39
- }
@@ -1,63 +0,0 @@
1
- import React from "react";
2
- import { Box, Text } from "ink";
3
-
4
- interface Column<T extends object> {
5
- key: keyof T | string;
6
- header: string;
7
- width?: number;
8
- align?: "left" | "right";
9
- render?: (value: unknown, row: T) => React.ReactNode;
10
- }
11
-
12
- interface Props<T extends object> {
13
- rows: T[];
14
- columns: Column<T>[];
15
- }
16
-
17
- function getVal(obj: object, key: string): unknown {
18
- const parts = key.split(".");
19
- let cur: unknown = obj;
20
- for (const p of parts) {
21
- if (cur == null || typeof cur !== "object") return undefined;
22
- cur = (cur as Record<string, unknown>)[p];
23
- }
24
- return cur;
25
- }
26
-
27
- export function Table<T extends object>({ rows, columns }: Props<T>) {
28
- if (rows.length === 0) {
29
- return <Text dimColor> (no results)</Text>;
30
- }
31
-
32
- const sep = "─".repeat(columns.reduce((s, c) => s + (c.width ?? 12) + 2, 1));
33
-
34
- return (
35
- <Box flexDirection="column">
36
- <Text dimColor>{" " + sep}</Text>
37
- <Box>
38
- {columns.map((col, i) => (
39
- <Box key={i} width={col.width ?? 12} marginRight={2}>
40
- <Text dimColor>{col.header}</Text>
41
- </Box>
42
- ))}
43
- </Box>
44
- <Text dimColor>{" " + sep}</Text>
45
- {rows.map((row, ri) => (
46
- <Box key={ri}>
47
- {columns.map((col, ci) => {
48
- const val = getVal(row, col.key as string);
49
- const node = col.render
50
- ? col.render(val, row)
51
- : <Text>{String(val ?? "")}</Text>;
52
- return (
53
- <Box key={ci} width={col.width ?? 12} marginRight={2} justifyContent={col.align === "right" ? "flex-end" : "flex-start"}>
54
- {node}
55
- </Box>
56
- );
57
- })}
58
- </Box>
59
- ))}
60
- <Text dimColor>{" " + sep}</Text>
61
- </Box>
62
- );
63
- }