@hisaabo/cli 0.1.0 → 0.3.2
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.
- package/README.md +332 -0
- package/dist/bin/audit-trail-2YGXGUXW.js +78 -0
- package/dist/bin/categories-P5VFWD5F.js +47 -0
- package/dist/bin/check-slug-4TMOTWUJ.js +65 -0
- package/dist/bin/chunk-2P35S2C3.js +46 -0
- package/dist/bin/chunk-EYNDY7RB.js +175 -0
- package/dist/bin/chunk-FFBG6RU4.js +156 -0
- package/dist/bin/chunk-FTOBDKMO.js +804 -0
- package/dist/bin/client-QNJ2H5CW.js +11 -0
- package/dist/bin/collection-efficiency-WMKEGS6U.js +165 -0
- package/dist/bin/config-UKVQYPPR.js +18 -0
- package/dist/bin/create-Y22FAVOW.js +83 -0
- package/dist/bin/default-account-SA56M66A.js +58 -0
- package/dist/bin/expenses-VZAOLYUW.js +89 -0
- package/dist/bin/export-QZ6WT6PJ.js +59 -0
- package/dist/bin/factory-2DCU3B5T.js +483 -0
- package/dist/bin/get-6UYP6UVD.js +71 -0
- package/dist/bin/get-EXL44I2X.js +66 -0
- package/dist/bin/hisaabo.js +2029 -1450
- package/dist/bin/invite-O26SAL72.js +53 -0
- package/dist/bin/invoice-breakdown-XEATXVMR.js +97 -0
- package/dist/bin/items-3U5USBVG.js +62 -0
- package/dist/bin/items-toggle-YEKMI2CM.js +46 -0
- package/dist/bin/list-FX2C3NCL.js +46 -0
- package/dist/bin/list-VBAHY72W.js +79 -0
- package/dist/bin/members-5FPRUAB6.js +55 -0
- package/dist/bin/monthly-comparison-JEJ3TTY2.js +176 -0
- package/dist/bin/order-cancel-XI2LKYXV.js +55 -0
- package/dist/bin/order-confirm-HUFCU6MO.js +53 -0
- package/dist/bin/order-get-NSDMPUZR.js +88 -0
- package/dist/bin/order-update-C7QYSD5R.js +60 -0
- package/dist/bin/output-QFLEKG5W.js +35 -0
- package/dist/bin/payment-modes-WI3AWSES.js +126 -0
- package/dist/bin/profit-loss-5RIEOBKP.js +135 -0
- package/dist/bin/receivables-aging-L6DIQCNE.js +161 -0
- package/dist/bin/remove-M2B4TZ37.js +52 -0
- package/dist/bin/revoke-H3V2GNCD.js +52 -0
- package/dist/bin/sales-trend-TICB3KGF.js +71 -0
- package/dist/bin/sequence-XUD6FAKY.js +66 -0
- package/dist/bin/store-UQ2DDQ5I.js +82 -0
- package/dist/bin/summary-BPNFC7I2.js +113 -0
- package/dist/bin/top-customers-WGGJWKCN.js +81 -0
- package/dist/bin/top-items-C7ZDDJMR.js +84 -0
- package/dist/bin/top-outstanding-MOGWJIQS.js +64 -0
- package/dist/bin/unpaid-invoices-ZUPNMQJP.js +65 -0
- package/dist/bin/untracked-BCJEVDW4.js +67 -0
- package/dist/bin/update-HIU4PANX.js +54 -0
- package/dist/bin/update-IG565YIN.js +61 -0
- package/dist/bin/update-PVLAX7T3.js +57 -0
- package/dist/bin/update-role-Q4ZYJRYT.js +45 -0
- package/dist/bin/update-settings-XPC6L5WM.js +56 -0
- package/package.json +6 -1
- package/src/bin/hisaabo.ts +42 -933
- package/src/bin/registrars/api-key.ts +44 -0
- package/src/bin/registrars/auth.ts +153 -0
- package/src/bin/registrars/automated-invoice.ts +167 -0
- package/src/bin/registrars/bank.ts +90 -0
- package/src/bin/registrars/business.ts +120 -0
- package/src/bin/registrars/dashboard.ts +225 -0
- package/src/bin/registrars/document.ts +184 -0
- package/src/bin/registrars/expense.ts +87 -0
- package/src/bin/registrars/gst.ts +41 -0
- package/src/bin/registrars/import.ts +49 -0
- package/src/bin/registrars/invoice.ts +117 -0
- package/src/bin/registrars/item.ts +112 -0
- package/src/bin/registrars/party.ts +81 -0
- package/src/bin/registrars/payment.ts +128 -0
- package/src/bin/registrars/report.ts +142 -0
- package/src/bin/registrars/shipment.ts +74 -0
- package/src/bin/registrars/store.ts +128 -0
- package/src/bin/registrars/target.ts +46 -0
- package/src/bin/registrars/tenant.ts +55 -0
- package/src/client.ts +495 -4
- package/src/commands/api-key/create.ts +72 -0
- package/src/commands/api-key/list.ts +71 -0
- package/src/commands/api-key/revoke.ts +46 -0
- package/src/commands/automated-invoice/create.ts +85 -0
- package/src/commands/automated-invoice/delete.ts +42 -0
- package/src/commands/automated-invoice/get.ts +113 -0
- package/src/commands/automated-invoice/history.ts +65 -0
- package/src/commands/automated-invoice/index.ts +11 -0
- package/src/commands/automated-invoice/list.ts +91 -0
- package/src/commands/automated-invoice/pause.ts +29 -0
- package/src/commands/automated-invoice/resume.ts +29 -0
- package/src/commands/automated-invoice/run-now.ts +29 -0
- package/src/commands/automated-invoice/suggestions.ts +68 -0
- package/src/commands/automated-invoice/update.ts +54 -0
- package/src/commands/automated-invoice/usage.ts +68 -0
- package/src/commands/business/audit-trail.ts +79 -0
- package/src/commands/business/export.ts +52 -0
- package/src/commands/business/get.ts +55 -0
- package/src/commands/business/sequence.ts +65 -0
- package/src/commands/business/update.ts +64 -0
- package/src/commands/dashboard/collection-efficiency.ts +164 -0
- package/src/commands/dashboard/expenses.ts +76 -0
- package/src/commands/dashboard/invoice-breakdown.ts +89 -0
- package/src/commands/dashboard/monthly-comparison.ts +193 -0
- package/src/commands/dashboard/payment-modes.ts +121 -0
- package/src/commands/dashboard/profit-loss.ts +146 -0
- package/src/commands/dashboard/receivables-aging.ts +169 -0
- package/src/commands/dashboard/sales-trend.ts +68 -0
- package/src/commands/dashboard/summary.ts +105 -0
- package/src/commands/dashboard/top-customers.ts +70 -0
- package/src/commands/dashboard/top-items.ts +74 -0
- package/src/commands/dashboard/top-outstanding.ts +61 -0
- package/src/commands/document/factory.ts +590 -0
- package/src/commands/expense/categories.ts +40 -0
- package/src/commands/expense/update.ts +58 -0
- package/src/commands/import/index.ts +68 -0
- package/src/commands/item/categories.ts +40 -0
- package/src/commands/item/low-stock-count.ts +32 -0
- package/src/commands/item/merge.ts +53 -0
- package/src/commands/item/price-history.ts +59 -0
- package/src/commands/item/rename-unit.ts +39 -0
- package/src/commands/item/sales-stats.ts +44 -0
- package/src/commands/item/stock-history.ts +70 -0
- package/src/commands/item/switch-base-unit.ts +42 -0
- package/src/commands/item/update.ts +59 -0
- package/src/commands/item/variants-create.ts +58 -0
- package/src/commands/item/variants-delete.ts +47 -0
- package/src/commands/item/variants-list.ts +63 -0
- package/src/commands/item/variants-update.ts +61 -0
- package/src/commands/party/ledger-report.ts +81 -0
- package/src/commands/party/merge.ts +50 -0
- package/src/commands/party/stats.ts +40 -0
- package/src/commands/party/top-items.ts +57 -0
- package/src/commands/party/update.ts +65 -0
- package/src/commands/payment/default-account.ts +56 -0
- package/src/commands/payment/get.ts +59 -0
- package/src/commands/payment/unpaid-invoices.ts +69 -0
- package/src/commands/payment/untracked.ts +70 -0
- package/src/commands/payment/update.ts +54 -0
- package/src/commands/report/index.ts +348 -1
- package/src/commands/store/check-slug.ts +48 -0
- package/src/commands/store/items-toggle.ts +41 -0
- package/src/commands/store/items.ts +61 -0
- package/src/commands/store/order-cancel.ts +48 -0
- package/src/commands/store/order-confirm.ts +45 -0
- package/src/commands/store/order-get.ts +66 -0
- package/src/commands/store/order-update.ts +52 -0
- package/src/commands/store/update-settings.ts +52 -0
- package/src/commands/tenant/invite.ts +57 -0
- package/src/commands/tenant/list.ts +46 -0
- package/src/commands/tenant/members.ts +55 -0
- package/src/commands/tenant/remove.ts +47 -0
- package/src/commands/tenant/update-role.ts +41 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
|
|
3
|
+
export function registerApiKeyCommands(program: Command): void {
|
|
4
|
+
const apiKey = program
|
|
5
|
+
.command("api-key")
|
|
6
|
+
.alias("key")
|
|
7
|
+
.description("API key management");
|
|
8
|
+
|
|
9
|
+
// ── list ──────────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
apiKey
|
|
12
|
+
.command("list")
|
|
13
|
+
.description("List all API keys")
|
|
14
|
+
.option("--json", "JSON output")
|
|
15
|
+
.option("--format <fmt>", "Output format: table, tsv, csv")
|
|
16
|
+
.action(async (opts) => {
|
|
17
|
+
const { apiKeyListCommand } = await import("../../commands/api-key/list.js");
|
|
18
|
+
await apiKeyListCommand(opts);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// ── create ────────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
apiKey
|
|
24
|
+
.command("create")
|
|
25
|
+
.description("Create a new API key")
|
|
26
|
+
.requiredOption("--name <name>", "Name / label for this key")
|
|
27
|
+
.option("--json", "JSON output")
|
|
28
|
+
.action(async (opts) => {
|
|
29
|
+
const { apiKeyCreateCommand } = await import("../../commands/api-key/create.js");
|
|
30
|
+
await apiKeyCreateCommand(opts);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// ── revoke ────────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
apiKey
|
|
36
|
+
.command("revoke <id>")
|
|
37
|
+
.description("Revoke an API key by ID")
|
|
38
|
+
.option("--yes", "Skip confirmation prompt")
|
|
39
|
+
.option("--json", "JSON output")
|
|
40
|
+
.action(async (id: string, opts) => {
|
|
41
|
+
const { apiKeyRevokeCommand } = await import("../../commands/api-key/revoke.js");
|
|
42
|
+
await apiKeyRevokeCommand(id, opts);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import * as readline from "readline";
|
|
3
|
+
import { login, loginWithToken, logout, whoami } from "../../auth.js";
|
|
4
|
+
import { setConfig, requireAuth } from "../../config.js";
|
|
5
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
6
|
+
import { fatalError, success, EXIT, outputJSON } from "../../output.js";
|
|
7
|
+
|
|
8
|
+
export function registerAuthCommands(program: Command): void {
|
|
9
|
+
// ── login ─────────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.command("login")
|
|
13
|
+
.description("Authenticate and configure your Hisaabo server")
|
|
14
|
+
.option("--api-url <url>", "Server URL")
|
|
15
|
+
.option("--email <email>", "Email address")
|
|
16
|
+
.option("--password <password>", "Password")
|
|
17
|
+
.option("--token <token>", "API key (hisaabo_key_...) for passwordless auth")
|
|
18
|
+
.action(async (opts) => {
|
|
19
|
+
let apiUrl = opts.apiUrl;
|
|
20
|
+
|
|
21
|
+
// ── API key path — skip email/password flow ──
|
|
22
|
+
if (opts.token) {
|
|
23
|
+
if (!apiUrl) {
|
|
24
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
25
|
+
const ask = (q: string) => new Promise<string>((res) => rl.question(q, res));
|
|
26
|
+
console.log("\n Hisaabo CLI\n " + "─".repeat(11) + "\n");
|
|
27
|
+
const u = await ask(" Server URL [http://localhost:3000]: ");
|
|
28
|
+
rl.close();
|
|
29
|
+
apiUrl = u.trim() || "http://localhost:3000";
|
|
30
|
+
}
|
|
31
|
+
await loginWithToken(apiUrl, opts.token);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ── Email/password path ──
|
|
36
|
+
let email = opts.email;
|
|
37
|
+
let password = opts.password;
|
|
38
|
+
|
|
39
|
+
if (!apiUrl || !email || !password) {
|
|
40
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
41
|
+
const ask = (q: string) => new Promise<string>((res) => rl.question(q, res));
|
|
42
|
+
console.log("\n Hisaabo CLI\n " + "─".repeat(11) + "\n");
|
|
43
|
+
if (!apiUrl) {
|
|
44
|
+
const u = await ask(" Server URL [http://localhost:3000]: ");
|
|
45
|
+
apiUrl = u.trim() || "http://localhost:3000";
|
|
46
|
+
}
|
|
47
|
+
if (!email) email = (await ask(" Email: ")).trim();
|
|
48
|
+
if (!password) {
|
|
49
|
+
// Hide password input if possible
|
|
50
|
+
password = (await ask(" Password: ")).trim();
|
|
51
|
+
}
|
|
52
|
+
rl.close();
|
|
53
|
+
console.log("\n Tip: Generate an API key at Settings → API Keys for passwordless CLI access.\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
await login(apiUrl, email, password);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ── logout ────────────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
program
|
|
62
|
+
.command("logout")
|
|
63
|
+
.description("Log out and clear saved credentials")
|
|
64
|
+
.option("--all", "Invalidate all sessions across all devices")
|
|
65
|
+
.action(async (opts) => {
|
|
66
|
+
if (opts.all) {
|
|
67
|
+
const cfg = requireAuth();
|
|
68
|
+
const client = new HisaaboClient(cfg);
|
|
69
|
+
try {
|
|
70
|
+
await client.auth.logoutAll();
|
|
71
|
+
await logout();
|
|
72
|
+
success("Logged out from all sessions.");
|
|
73
|
+
} catch (e) {
|
|
74
|
+
if (e instanceof HisaaboApiError) {
|
|
75
|
+
if (e.hisaaboError.code === "unauthorized") {
|
|
76
|
+
// Session already invalid — still clear local config
|
|
77
|
+
await logout();
|
|
78
|
+
success("Logged out from all sessions.");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
await logout();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// ── whoami ────────────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
program
|
|
92
|
+
.command("whoami")
|
|
93
|
+
.description("Show current user and active business")
|
|
94
|
+
.option("--json", "JSON output")
|
|
95
|
+
.action(async (opts) => {
|
|
96
|
+
await whoami(!!opts.json);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// ── profile ───────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
const profile = program.command("profile").description("Manage your profile");
|
|
102
|
+
|
|
103
|
+
profile
|
|
104
|
+
.command("update-name <name>")
|
|
105
|
+
.description("Update your display name")
|
|
106
|
+
.action(async (name: string) => {
|
|
107
|
+
const cfg = requireAuth();
|
|
108
|
+
const client = new HisaaboClient(cfg);
|
|
109
|
+
try {
|
|
110
|
+
await client.auth.updateName({ name });
|
|
111
|
+
success(`Name updated to: ${name}`);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (e instanceof HisaaboApiError) {
|
|
114
|
+
const err = e.hisaaboError;
|
|
115
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
116
|
+
if (err.code === "validation_failed") fatalError(String(err.fields?.["name"]?.[0] ?? "Validation failed."), EXIT.VALIDATION);
|
|
117
|
+
}
|
|
118
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// ── switch (business) ─────────────────────────────────────────────────────
|
|
123
|
+
|
|
124
|
+
program
|
|
125
|
+
.command("switch")
|
|
126
|
+
.description("Switch active business")
|
|
127
|
+
.option("--json", "JSON output")
|
|
128
|
+
.action(async (opts) => {
|
|
129
|
+
const cfg = requireAuth();
|
|
130
|
+
const client = new HisaaboClient(cfg);
|
|
131
|
+
try {
|
|
132
|
+
const businesses = await client.business.list();
|
|
133
|
+
if (opts.json) { outputJSON(businesses); return; }
|
|
134
|
+
businesses.forEach((b, i) => {
|
|
135
|
+
const active = b.id === cfg.businessId ? " [active]" : "";
|
|
136
|
+
console.log(` ${i + 1} ${b.name.padEnd(28)}${active}`);
|
|
137
|
+
});
|
|
138
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
139
|
+
const answer = await new Promise<string>((res) => rl.question("\n Select: ", res));
|
|
140
|
+
rl.close();
|
|
141
|
+
const idx = parseInt(answer.trim(), 10) - 1;
|
|
142
|
+
const selected = businesses[Math.max(0, Math.min(idx, businesses.length - 1))];
|
|
143
|
+
if (!selected) fatalError("Invalid selection.", EXIT.USAGE);
|
|
144
|
+
setConfig({ businessId: selected.id, businessName: selected.name });
|
|
145
|
+
success(`Switched to: ${selected.name}`);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
if (e instanceof HisaaboApiError) {
|
|
148
|
+
if (e.hisaaboError.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
149
|
+
}
|
|
150
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import {
|
|
3
|
+
automatedInvoiceListCommand, automatedInvoiceGetCommand, automatedInvoiceCreateCommand,
|
|
4
|
+
automatedInvoiceUpdateCommand,
|
|
5
|
+
automatedInvoicePauseCommand, automatedInvoiceResumeCommand, automatedInvoiceRunNowCommand,
|
|
6
|
+
automatedInvoiceDeleteCommand,
|
|
7
|
+
automatedInvoiceHistoryCommand,
|
|
8
|
+
automatedInvoiceUsageCommand,
|
|
9
|
+
automatedInvoiceSuggestionsCommand,
|
|
10
|
+
} from "../../commands/automated-invoice/index.js";
|
|
11
|
+
|
|
12
|
+
export function registerAutomatedInvoiceCommands(program: Command): void {
|
|
13
|
+
// ── automated-invoice ────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
const automatedInvoice = program.command("automated-invoice").alias("auto-inv").description("Recurring / automated invoice management");
|
|
16
|
+
|
|
17
|
+
automatedInvoice
|
|
18
|
+
.command("list")
|
|
19
|
+
.description("List recurring invoice templates")
|
|
20
|
+
.option("--json", "JSON output")
|
|
21
|
+
.option("--format <format>", "Output format: table, tsv, csv, ids")
|
|
22
|
+
.option("--status <status>", "Filter by status: active, paused, completed, expired")
|
|
23
|
+
.option("--page <n>", "Page number", parseInt)
|
|
24
|
+
.option("--limit <n>", "Items per page", parseInt)
|
|
25
|
+
.action(async (opts) => {
|
|
26
|
+
await automatedInvoiceListCommand({
|
|
27
|
+
json: opts.json,
|
|
28
|
+
format: opts.format,
|
|
29
|
+
status: opts.status,
|
|
30
|
+
page: opts.page,
|
|
31
|
+
limit: opts.limit,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
automatedInvoice
|
|
36
|
+
.command("get <id>")
|
|
37
|
+
.description("Get recurring invoice template details")
|
|
38
|
+
.option("--json", "JSON output")
|
|
39
|
+
.action(async (id, opts) => {
|
|
40
|
+
await automatedInvoiceGetCommand(id, { json: opts.json });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
automatedInvoice
|
|
44
|
+
.command("create")
|
|
45
|
+
.description("Create a new recurring invoice template")
|
|
46
|
+
.option("--json", "JSON output")
|
|
47
|
+
.option("--party-id <id>", "Party UUID")
|
|
48
|
+
.option("--name <name>", "Template name")
|
|
49
|
+
.option("--type <type>", "sale or purchase")
|
|
50
|
+
.option("--frequency <freq>", "weekly/biweekly/monthly/quarterly/half_yearly/yearly/custom")
|
|
51
|
+
.option("--custom-interval-days <n>", "Custom interval in days (when frequency is custom)")
|
|
52
|
+
.option("--line-item <desc>", "Line item description (repeatable)", (v: string, a: string[]) => [...a, v], [] as string[])
|
|
53
|
+
.option("--qty <n>", "Quantity (per --line-item)", (v: string, a: string[]) => [...a, v], [] as string[])
|
|
54
|
+
.option("--rate <n>", "Unit price (per --line-item)", (v: string, a: string[]) => [...a, v], [] as string[])
|
|
55
|
+
.option("--tax <n>", "Tax percent (per --line-item)", (v: string, a: string[]) => [...a, v], [] as string[])
|
|
56
|
+
.option("--discount <n>", "Discount percent (per --line-item)", (v: string, a: string[]) => [...a, v], [] as string[])
|
|
57
|
+
.option("--start-date <date>", "Start date (YYYY-MM-DD)")
|
|
58
|
+
.option("--end-date <date>", "End date (YYYY-MM-DD)")
|
|
59
|
+
.option("--max-runs <n>", "Maximum number of runs")
|
|
60
|
+
.option("--notes <text>", "Notes")
|
|
61
|
+
.action(async (opts) => {
|
|
62
|
+
await automatedInvoiceCreateCommand({
|
|
63
|
+
json: opts.json,
|
|
64
|
+
partyId: opts.partyId,
|
|
65
|
+
name: opts.name,
|
|
66
|
+
type: opts.type,
|
|
67
|
+
frequency: opts.frequency,
|
|
68
|
+
customIntervalDays: opts.customIntervalDays,
|
|
69
|
+
lineItem: opts.lineItem,
|
|
70
|
+
qty: opts.qty,
|
|
71
|
+
rate: opts.rate,
|
|
72
|
+
tax: opts.tax,
|
|
73
|
+
discount: opts.discount,
|
|
74
|
+
startDate: opts.startDate,
|
|
75
|
+
endDate: opts.endDate,
|
|
76
|
+
maxRuns: opts.maxRuns,
|
|
77
|
+
notes: opts.notes,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
automatedInvoice
|
|
82
|
+
.command("pause <id>")
|
|
83
|
+
.description("Pause an active recurring invoice template")
|
|
84
|
+
.option("--json", "JSON output")
|
|
85
|
+
.action(async (id, opts) => {
|
|
86
|
+
await automatedInvoicePauseCommand(id, { json: opts.json });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
automatedInvoice
|
|
90
|
+
.command("resume <id>")
|
|
91
|
+
.description("Resume a paused recurring invoice template")
|
|
92
|
+
.option("--json", "JSON output")
|
|
93
|
+
.action(async (id, opts) => {
|
|
94
|
+
await automatedInvoiceResumeCommand(id, { json: opts.json });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
automatedInvoice
|
|
98
|
+
.command("run-now <id>")
|
|
99
|
+
.description("Manually trigger a recurring invoice template execution")
|
|
100
|
+
.option("--json", "JSON output")
|
|
101
|
+
.action(async (id, opts) => {
|
|
102
|
+
await automatedInvoiceRunNowCommand(id, { json: opts.json });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
automatedInvoice
|
|
106
|
+
.command("delete <id>")
|
|
107
|
+
.description("Delete a recurring invoice template")
|
|
108
|
+
.option("-y, --yes", "Skip confirmation")
|
|
109
|
+
.option("--json", "JSON output")
|
|
110
|
+
.action(async (id, opts) => {
|
|
111
|
+
await automatedInvoiceDeleteCommand(id, { yes: opts.yes, json: opts.json });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
automatedInvoice
|
|
115
|
+
.command("update <id>")
|
|
116
|
+
.description("Update a recurring invoice template")
|
|
117
|
+
.option("--name <name>", "Template name")
|
|
118
|
+
.option("--frequency <freq>", "weekly/biweekly/monthly/quarterly/half_yearly/yearly/custom")
|
|
119
|
+
.option("--start-date <date>", "Start date (YYYY-MM-DD)")
|
|
120
|
+
.option("--end-date <date>", "End date (YYYY-MM-DD)")
|
|
121
|
+
.option("--max-runs <n>", "Maximum number of runs")
|
|
122
|
+
.option("--notes <text>", "Notes")
|
|
123
|
+
.option("--json", "JSON output")
|
|
124
|
+
.action(async (id, opts) => {
|
|
125
|
+
await automatedInvoiceUpdateCommand(id, {
|
|
126
|
+
json: opts.json,
|
|
127
|
+
name: opts.name,
|
|
128
|
+
frequency: opts.frequency,
|
|
129
|
+
startDate: opts.startDate,
|
|
130
|
+
endDate: opts.endDate,
|
|
131
|
+
maxRuns: opts.maxRuns,
|
|
132
|
+
notes: opts.notes,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
automatedInvoice
|
|
137
|
+
.command("history <templateId>")
|
|
138
|
+
.description("Show execution history for a recurring invoice template")
|
|
139
|
+
.option("--json", "JSON output")
|
|
140
|
+
.option("--format <format>", "Output format: table, tsv, csv")
|
|
141
|
+
.option("--page <n>", "Page number", parseInt)
|
|
142
|
+
.option("--limit <n>", "Items per page", parseInt)
|
|
143
|
+
.action(async (templateId, opts) => {
|
|
144
|
+
await automatedInvoiceHistoryCommand(templateId, {
|
|
145
|
+
json: opts.json,
|
|
146
|
+
format: opts.format,
|
|
147
|
+
page: opts.page,
|
|
148
|
+
limit: opts.limit,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
automatedInvoice
|
|
153
|
+
.command("usage")
|
|
154
|
+
.description("Show plan usage for recurring invoices")
|
|
155
|
+
.option("--json", "JSON output")
|
|
156
|
+
.action(async (opts) => {
|
|
157
|
+
await automatedInvoiceUsageCommand({ json: opts.json });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
automatedInvoice
|
|
161
|
+
.command("suggestions")
|
|
162
|
+
.description("Show suggested recurring invoice templates based on invoice history")
|
|
163
|
+
.option("--json", "JSON output")
|
|
164
|
+
.action(async (opts) => {
|
|
165
|
+
await automatedInvoiceSuggestionsCommand({ json: opts.json });
|
|
166
|
+
});
|
|
167
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import {
|
|
3
|
+
bankListCommand, bankGetCommand, bankCreateCommand, bankTransferCommand, bankTransactionsCommand,
|
|
4
|
+
} from "../../commands/bank/index.js";
|
|
5
|
+
|
|
6
|
+
export function registerBankCommands(program: Command): void {
|
|
7
|
+
// ── bank ─────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
const bank = program.command("bank").description("Bank account management");
|
|
10
|
+
|
|
11
|
+
bank
|
|
12
|
+
.command("list")
|
|
13
|
+
.description("List bank accounts with balances")
|
|
14
|
+
.option("--json", "JSON output")
|
|
15
|
+
.action(async (opts) => {
|
|
16
|
+
await bankListCommand({ json: opts.json });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
bank
|
|
20
|
+
.command("get <id>")
|
|
21
|
+
.description("Get bank account details")
|
|
22
|
+
.option("--json", "JSON output")
|
|
23
|
+
.action(async (id, opts) => {
|
|
24
|
+
await bankGetCommand(id, { json: opts.json });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
bank
|
|
28
|
+
.command("create")
|
|
29
|
+
.description("Create a new bank account")
|
|
30
|
+
.option("--json", "JSON output")
|
|
31
|
+
.option("--name <name>", "Account name")
|
|
32
|
+
.option("--type <type>", "savings/current/cash/credit/other")
|
|
33
|
+
.option("--bank <name>", "Bank name")
|
|
34
|
+
.option("--account-number <num>", "Account number")
|
|
35
|
+
.option("--ifsc <code>", "IFSC code")
|
|
36
|
+
.option("--opening-balance <amount>", "Opening balance")
|
|
37
|
+
.option("--default", "Set as default account")
|
|
38
|
+
.option("-y, --yes", "Skip prompts")
|
|
39
|
+
.action(async (opts) => {
|
|
40
|
+
await bankCreateCommand({
|
|
41
|
+
json: opts.json,
|
|
42
|
+
name: opts.name,
|
|
43
|
+
type: opts.type,
|
|
44
|
+
bank: opts.bank,
|
|
45
|
+
accountNumber: opts.accountNumber,
|
|
46
|
+
ifsc: opts.ifsc,
|
|
47
|
+
openingBalance: opts.openingBalance,
|
|
48
|
+
default: opts.default,
|
|
49
|
+
yes: opts.yes,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
bank
|
|
54
|
+
.command("transfer")
|
|
55
|
+
.description("Transfer between bank accounts")
|
|
56
|
+
.option("--json", "JSON output")
|
|
57
|
+
.option("--from <id>", "Source account ID")
|
|
58
|
+
.option("--to <id>", "Destination account ID")
|
|
59
|
+
.option("--amount <amount>", "Transfer amount")
|
|
60
|
+
.option("--description <text>", "Description")
|
|
61
|
+
.option("--date <date>", "Transfer date")
|
|
62
|
+
.action(async (opts) => {
|
|
63
|
+
await bankTransferCommand({
|
|
64
|
+
json: opts.json,
|
|
65
|
+
from: opts.from,
|
|
66
|
+
to: opts.to,
|
|
67
|
+
amount: opts.amount,
|
|
68
|
+
description: opts.description,
|
|
69
|
+
date: opts.date,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
bank
|
|
74
|
+
.command("transactions <accountId>")
|
|
75
|
+
.description("List transactions for a bank account")
|
|
76
|
+
.option("--json", "JSON output")
|
|
77
|
+
.option("--from <date>", "From date")
|
|
78
|
+
.option("--to <date>", "To date")
|
|
79
|
+
.option("--page <n>", "Page number", parseInt)
|
|
80
|
+
.option("--limit <n>", "Items per page", parseInt)
|
|
81
|
+
.action(async (accountId, opts) => {
|
|
82
|
+
await bankTransactionsCommand(accountId, {
|
|
83
|
+
json: opts.json,
|
|
84
|
+
from: opts.from,
|
|
85
|
+
to: opts.to,
|
|
86
|
+
page: opts.page,
|
|
87
|
+
limit: opts.limit,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import * as readline from "readline";
|
|
3
|
+
import { setConfig, requireAuth } from "../../config.js";
|
|
4
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
5
|
+
import { fatalError, success, EXIT, outputJSON } from "../../output.js";
|
|
6
|
+
|
|
7
|
+
export function registerBusinessCommands(program: Command): void {
|
|
8
|
+
// ── business (alias) ──────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
const business = program.command("business").description("Business management");
|
|
11
|
+
|
|
12
|
+
business
|
|
13
|
+
.command("list")
|
|
14
|
+
.description("List all businesses")
|
|
15
|
+
.option("--json", "JSON output")
|
|
16
|
+
.action(async (opts) => {
|
|
17
|
+
const cfg = requireAuth();
|
|
18
|
+
const client = new HisaaboClient(cfg);
|
|
19
|
+
try {
|
|
20
|
+
const businesses = await client.business.list();
|
|
21
|
+
if (opts.json) { outputJSON(businesses); return; }
|
|
22
|
+
businesses.forEach((b, i) => {
|
|
23
|
+
const active = b.id === cfg.businessId ? " [active]" : "";
|
|
24
|
+
console.log(` ${i + 1} ${b.name.padEnd(30)} ${(b.gstin ?? "-").padEnd(18)} ${b.gstRegistrationType}${active}`);
|
|
25
|
+
});
|
|
26
|
+
console.log();
|
|
27
|
+
} catch (e) {
|
|
28
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
business
|
|
33
|
+
.command("get")
|
|
34
|
+
.description("Show current business details")
|
|
35
|
+
.option("--json", "JSON output")
|
|
36
|
+
.action(async (opts) => {
|
|
37
|
+
const { businessGetCommand } = await import("../../commands/business/get.js");
|
|
38
|
+
await businessGetCommand(opts);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
business
|
|
42
|
+
.command("update")
|
|
43
|
+
.description("Update business settings")
|
|
44
|
+
.option("--name <name>", "Business name")
|
|
45
|
+
.option("--gstin <gstin>", "GSTIN")
|
|
46
|
+
.option("--address <address>", "Address")
|
|
47
|
+
.option("--state <state>", "State")
|
|
48
|
+
.option("--phone <phone>", "Phone number")
|
|
49
|
+
.option("--email <email>", "Email address")
|
|
50
|
+
.option("--financial-year-start <month>", "Financial year start month (1–12)")
|
|
51
|
+
.option("--json", "JSON output")
|
|
52
|
+
.action(async (opts) => {
|
|
53
|
+
const { businessUpdateCommand } = await import("../../commands/business/update.js");
|
|
54
|
+
await businessUpdateCommand(opts);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
business
|
|
58
|
+
.command("sequence")
|
|
59
|
+
.description("Update invoice sequence number / prefix")
|
|
60
|
+
.requiredOption("--type <type>", "Document type: sale or purchase")
|
|
61
|
+
.option("--prefix <prefix>", "Invoice prefix (e.g. INV-)")
|
|
62
|
+
.option("--next-number <n>", "Next sequence number")
|
|
63
|
+
.option("--json", "JSON output")
|
|
64
|
+
.action(async (opts) => {
|
|
65
|
+
const { businessSequenceCommand } = await import("../../commands/business/sequence.js");
|
|
66
|
+
await businessSequenceCommand(opts);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
business
|
|
70
|
+
.command("audit-trail")
|
|
71
|
+
.description("View audit log for this business")
|
|
72
|
+
.option("--page <n>", "Page number", "1")
|
|
73
|
+
.option("--limit <n>", "Results per page", "25")
|
|
74
|
+
.option("--json", "JSON output")
|
|
75
|
+
.option("--format <fmt>", "Output format: table, tsv, csv")
|
|
76
|
+
.action(async (opts) => {
|
|
77
|
+
const { businessAuditTrailCommand } = await import("../../commands/business/audit-trail.js");
|
|
78
|
+
await businessAuditTrailCommand(opts);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
business
|
|
82
|
+
.command("export")
|
|
83
|
+
.description("Export all business data")
|
|
84
|
+
.option("--yes", "Skip confirmation prompt")
|
|
85
|
+
.option("--json", "JSON output")
|
|
86
|
+
.action(async (opts) => {
|
|
87
|
+
const { businessExportCommand } = await import("../../commands/business/export.js");
|
|
88
|
+
await businessExportCommand(opts);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
business
|
|
92
|
+
.command("switch")
|
|
93
|
+
.description("Switch active business")
|
|
94
|
+
.option("--json", "JSON output")
|
|
95
|
+
.action(async (opts) => {
|
|
96
|
+
const cfg = requireAuth();
|
|
97
|
+
const client = new HisaaboClient(cfg);
|
|
98
|
+
try {
|
|
99
|
+
const businesses = await client.business.list();
|
|
100
|
+
if (opts.json) { outputJSON(businesses); return; }
|
|
101
|
+
businesses.forEach((b, i) => {
|
|
102
|
+
const active = b.id === cfg.businessId ? " [active]" : "";
|
|
103
|
+
console.log(` ${i + 1} ${b.name.padEnd(28)}${active}`);
|
|
104
|
+
});
|
|
105
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
106
|
+
const answer = await new Promise<string>((res) => rl.question("\n Select: ", res));
|
|
107
|
+
rl.close();
|
|
108
|
+
const idx = parseInt(answer.trim(), 10) - 1;
|
|
109
|
+
const selected = businesses[Math.max(0, Math.min(idx, businesses.length - 1))];
|
|
110
|
+
if (!selected) fatalError("Invalid selection.", EXIT.USAGE);
|
|
111
|
+
setConfig({ businessId: selected.id, businessName: selected.name });
|
|
112
|
+
success(`Switched to: ${selected.name}`);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (e instanceof HisaaboApiError) {
|
|
115
|
+
if (e.hisaaboError.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
116
|
+
}
|
|
117
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|