@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,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
HisaaboApiError,
|
|
4
|
+
HisaaboClient
|
|
5
|
+
} from "./chunk-FTOBDKMO.js";
|
|
6
|
+
import {
|
|
7
|
+
requireAuth
|
|
8
|
+
} from "./chunk-2P35S2C3.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
outputJSON,
|
|
13
|
+
success
|
|
14
|
+
} from "./chunk-EYNDY7RB.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-FFBG6RU4.js";
|
|
10
|
+
import {
|
|
11
|
+
HisaaboApiError,
|
|
12
|
+
HisaaboClient
|
|
13
|
+
} from "./chunk-FTOBDKMO.js";
|
|
14
|
+
import {
|
|
15
|
+
requireAuth
|
|
16
|
+
} from "./chunk-2P35S2C3.js";
|
|
17
|
+
import {
|
|
18
|
+
EXIT,
|
|
19
|
+
fatalError,
|
|
20
|
+
hasColor,
|
|
21
|
+
outputJSON,
|
|
22
|
+
outputTable
|
|
23
|
+
} from "./chunk-EYNDY7RB.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-FFBG6RU4.js";
|
|
5
|
+
import {
|
|
6
|
+
HisaaboApiError,
|
|
7
|
+
HisaaboClient
|
|
8
|
+
} from "./chunk-FTOBDKMO.js";
|
|
9
|
+
import {
|
|
10
|
+
requireAuth
|
|
11
|
+
} from "./chunk-2P35S2C3.js";
|
|
12
|
+
import {
|
|
13
|
+
EXIT,
|
|
14
|
+
fatalError,
|
|
15
|
+
outputCSV,
|
|
16
|
+
outputJSON,
|
|
17
|
+
outputTSV,
|
|
18
|
+
outputTable
|
|
19
|
+
} from "./chunk-EYNDY7RB.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-FTOBDKMO.js";
|
|
6
|
+
import {
|
|
7
|
+
requireAuth
|
|
8
|
+
} from "./chunk-2P35S2C3.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
outputJSON,
|
|
13
|
+
success
|
|
14
|
+
} from "./chunk-EYNDY7RB.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,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
HisaaboApiError,
|
|
4
|
+
HisaaboClient
|
|
5
|
+
} from "./chunk-FTOBDKMO.js";
|
|
6
|
+
import {
|
|
7
|
+
requireAuth
|
|
8
|
+
} from "./chunk-2P35S2C3.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
outputJSON,
|
|
13
|
+
outputTable
|
|
14
|
+
} from "./chunk-EYNDY7RB.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,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatDate,
|
|
4
|
+
formatRelativeDate
|
|
5
|
+
} from "./chunk-FFBG6RU4.js";
|
|
6
|
+
import {
|
|
7
|
+
HisaaboApiError,
|
|
8
|
+
HisaaboClient
|
|
9
|
+
} from "./chunk-FTOBDKMO.js";
|
|
10
|
+
import {
|
|
11
|
+
requireAuth
|
|
12
|
+
} from "./chunk-2P35S2C3.js";
|
|
13
|
+
import {
|
|
14
|
+
EXIT,
|
|
15
|
+
fatalError,
|
|
16
|
+
hasColor,
|
|
17
|
+
outputCSV,
|
|
18
|
+
outputJSON,
|
|
19
|
+
outputTSV,
|
|
20
|
+
outputTable
|
|
21
|
+
} from "./chunk-EYNDY7RB.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,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatDate
|
|
4
|
+
} from "./chunk-FFBG6RU4.js";
|
|
5
|
+
import {
|
|
6
|
+
HisaaboApiError,
|
|
7
|
+
HisaaboClient
|
|
8
|
+
} from "./chunk-FTOBDKMO.js";
|
|
9
|
+
import {
|
|
10
|
+
requireAuth
|
|
11
|
+
} from "./chunk-2P35S2C3.js";
|
|
12
|
+
import {
|
|
13
|
+
EXIT,
|
|
14
|
+
fatalError,
|
|
15
|
+
outputCSV,
|
|
16
|
+
outputJSON,
|
|
17
|
+
outputTSV,
|
|
18
|
+
outputTable
|
|
19
|
+
} from "./chunk-EYNDY7RB.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
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatAmount
|
|
4
|
+
} from "./chunk-FFBG6RU4.js";
|
|
5
|
+
import {
|
|
6
|
+
HisaaboApiError,
|
|
7
|
+
HisaaboClient
|
|
8
|
+
} from "./chunk-FTOBDKMO.js";
|
|
9
|
+
import {
|
|
10
|
+
requireAuth
|
|
11
|
+
} from "./chunk-2P35S2C3.js";
|
|
12
|
+
import {
|
|
13
|
+
EXIT,
|
|
14
|
+
fatalError,
|
|
15
|
+
hasColor,
|
|
16
|
+
outputCSV,
|
|
17
|
+
outputJSON,
|
|
18
|
+
outputTSV,
|
|
19
|
+
outputTable
|
|
20
|
+
} from "./chunk-EYNDY7RB.js";
|
|
21
|
+
|
|
22
|
+
// src/commands/dashboard/monthly-comparison.ts
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
function changeArrow(pct) {
|
|
25
|
+
if (!hasColor()) return pct >= 0 ? `+${pct.toFixed(1)}%` : `${pct.toFixed(1)}%`;
|
|
26
|
+
if (pct > 0) return chalk.green(`\u25B2 +${pct.toFixed(1)}%`);
|
|
27
|
+
if (pct < 0) return chalk.red(`\u25BC ${pct.toFixed(1)}%`);
|
|
28
|
+
return chalk.dim("\u2500 0.0%");
|
|
29
|
+
}
|
|
30
|
+
function pctChange(current, previous) {
|
|
31
|
+
if (previous === 0) return current > 0 ? 100 : 0;
|
|
32
|
+
return (current - previous) / Math.abs(previous) * 100;
|
|
33
|
+
}
|
|
34
|
+
async function dashboardMonthlyComparisonCommand(opts) {
|
|
35
|
+
const cfg = requireAuth();
|
|
36
|
+
const client = new HisaaboClient(cfg);
|
|
37
|
+
try {
|
|
38
|
+
const data = await client.dashboard.monthlyComparison();
|
|
39
|
+
if (opts.json) {
|
|
40
|
+
outputJSON(data);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let months = [];
|
|
44
|
+
if (Array.isArray(data)) {
|
|
45
|
+
months = data.map((r) => {
|
|
46
|
+
const month = String(r["month"] ?? r["period"] ?? r["label"] ?? "-");
|
|
47
|
+
const year = r["year"] ? String(r["year"]) : "";
|
|
48
|
+
const period = year ? `${month} ${year}` : month;
|
|
49
|
+
return {
|
|
50
|
+
period,
|
|
51
|
+
sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
|
|
52
|
+
expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
|
|
53
|
+
profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
|
|
54
|
+
collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0"))
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
} else if (data && typeof data === "object") {
|
|
58
|
+
const obj = data;
|
|
59
|
+
if ("current" in obj || "previous" in obj) {
|
|
60
|
+
const cur = obj["current"] ?? {};
|
|
61
|
+
const prev = obj["previous"] ?? {};
|
|
62
|
+
months = [
|
|
63
|
+
{
|
|
64
|
+
period: "Previous Month",
|
|
65
|
+
sales: parseFloat(String(prev["sales"] ?? prev["totalSales"] ?? "0")),
|
|
66
|
+
expenses: parseFloat(String(prev["expenses"] ?? prev["totalExpenses"] ?? "0")),
|
|
67
|
+
profit: parseFloat(String(prev["profit"] ?? prev["netProfit"] ?? "0")),
|
|
68
|
+
collections: parseFloat(String(prev["collections"] ?? prev["totalCollections"] ?? "0"))
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
period: "Current Month",
|
|
72
|
+
sales: parseFloat(String(cur["sales"] ?? cur["totalSales"] ?? "0")),
|
|
73
|
+
expenses: parseFloat(String(cur["expenses"] ?? cur["totalExpenses"] ?? "0")),
|
|
74
|
+
profit: parseFloat(String(cur["profit"] ?? cur["netProfit"] ?? "0")),
|
|
75
|
+
collections: parseFloat(String(cur["collections"] ?? cur["totalCollections"] ?? "0"))
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
} else {
|
|
79
|
+
const entries = Object.entries(obj).sort(([a], [b]) => a.localeCompare(b));
|
|
80
|
+
months = entries.map(([period, val]) => {
|
|
81
|
+
const r = val ?? {};
|
|
82
|
+
return {
|
|
83
|
+
period,
|
|
84
|
+
sales: parseFloat(String(r["sales"] ?? r["totalSales"] ?? "0")),
|
|
85
|
+
expenses: parseFloat(String(r["expenses"] ?? r["totalExpenses"] ?? "0")),
|
|
86
|
+
profit: parseFloat(String(r["profit"] ?? r["netProfit"] ?? "0")),
|
|
87
|
+
collections: parseFloat(String(r["collections"] ?? r["totalCollections"] ?? "0"))
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (opts.format === "tsv" || opts.format === "csv") {
|
|
93
|
+
const rows2 = months.map((m, i) => {
|
|
94
|
+
const prev = months[i - 1];
|
|
95
|
+
return {
|
|
96
|
+
period: m.period,
|
|
97
|
+
sales: formatAmount(m.sales),
|
|
98
|
+
salesChg: prev ? `${pctChange(m.sales, prev.sales).toFixed(1)}%` : "-",
|
|
99
|
+
expenses: formatAmount(m.expenses),
|
|
100
|
+
profit: formatAmount(m.profit),
|
|
101
|
+
collections: formatAmount(m.collections)
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
const columns2 = [
|
|
105
|
+
{ key: "period", header: "Month", align: "left" },
|
|
106
|
+
{ key: "sales", header: "Sales \u20B9", align: "right" },
|
|
107
|
+
{ key: "salesChg", header: "Sales \u0394%", align: "right" },
|
|
108
|
+
{ key: "expenses", header: "Expenses \u20B9", align: "right" },
|
|
109
|
+
{ key: "profit", header: "Profit \u20B9", align: "right" },
|
|
110
|
+
{ key: "collections", header: "Collections \u20B9", align: "right" }
|
|
111
|
+
];
|
|
112
|
+
if (opts.format === "tsv") outputTSV(rows2, columns2);
|
|
113
|
+
else outputCSV(rows2, columns2);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Monthly Comparison\n") + "\n");
|
|
117
|
+
else process.stdout.write("\n Monthly Comparison\n\n");
|
|
118
|
+
if (months.length >= 2) {
|
|
119
|
+
const last = months[months.length - 1];
|
|
120
|
+
const prev = months[months.length - 2];
|
|
121
|
+
const salesPct = pctChange(last.sales, prev.sales);
|
|
122
|
+
const expPct = pctChange(last.expenses, prev.expenses);
|
|
123
|
+
const profitPct = pctChange(last.profit, prev.profit);
|
|
124
|
+
const collPct = pctChange(last.collections, prev.collections);
|
|
125
|
+
process.stdout.write(` ${hasColor() ? chalk.dim("Month-over-month (latest vs previous)") : "Month-over-month (latest vs previous)"}
|
|
126
|
+
|
|
127
|
+
`);
|
|
128
|
+
const summaryRows = [
|
|
129
|
+
{ metric: "Sales", current: formatAmount(last.sales), change: changeArrow(salesPct) },
|
|
130
|
+
{ metric: "Collections", current: formatAmount(last.collections), change: changeArrow(collPct) },
|
|
131
|
+
{ metric: "Expenses", current: formatAmount(last.expenses), change: changeArrow(-expPct) },
|
|
132
|
+
{ metric: "Profit", current: formatAmount(last.profit), change: changeArrow(profitPct) }
|
|
133
|
+
];
|
|
134
|
+
const summaryColumns = [
|
|
135
|
+
{ key: "metric", header: "Metric", align: "left" },
|
|
136
|
+
{ key: "current", header: "Latest \u20B9", align: "right" },
|
|
137
|
+
{ key: "change", header: "vs Prev", align: "right" }
|
|
138
|
+
];
|
|
139
|
+
outputTable(summaryRows, summaryColumns);
|
|
140
|
+
process.stdout.write("\n");
|
|
141
|
+
}
|
|
142
|
+
const rows = months.map((m, i) => {
|
|
143
|
+
const prev = months[i - 1];
|
|
144
|
+
const salesChg = prev ? changeArrow(pctChange(m.sales, prev.sales)) : "-";
|
|
145
|
+
const profitColor = m.profit >= 0 ? hasColor() ? chalk.green(formatAmount(m.profit)) : formatAmount(m.profit) : hasColor() ? chalk.red(formatAmount(m.profit)) : formatAmount(m.profit);
|
|
146
|
+
return {
|
|
147
|
+
period: m.period,
|
|
148
|
+
sales: formatAmount(m.sales),
|
|
149
|
+
salesChg,
|
|
150
|
+
expenses: formatAmount(m.expenses),
|
|
151
|
+
profit: profitColor,
|
|
152
|
+
collections: formatAmount(m.collections)
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
const columns = [
|
|
156
|
+
{ key: "period", header: "Month", align: "left" },
|
|
157
|
+
{ key: "sales", header: "Sales \u20B9", align: "right" },
|
|
158
|
+
{ key: "salesChg", header: "\u0394%", align: "right" },
|
|
159
|
+
{ key: "expenses", header: "Expenses \u20B9", align: "right" },
|
|
160
|
+
{ key: "profit", header: "Profit \u20B9", align: "right" },
|
|
161
|
+
{ key: "collections", header: "Collections \u20B9", align: "right" }
|
|
162
|
+
];
|
|
163
|
+
outputTable(rows, columns);
|
|
164
|
+
process.stdout.write("\n");
|
|
165
|
+
} catch (e) {
|
|
166
|
+
if (e instanceof HisaaboApiError) {
|
|
167
|
+
const err = e.hisaaboError;
|
|
168
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
169
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
170
|
+
}
|
|
171
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
dashboardMonthlyComparisonCommand
|
|
176
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
HisaaboApiError,
|
|
4
|
+
HisaaboClient
|
|
5
|
+
} from "./chunk-FTOBDKMO.js";
|
|
6
|
+
import {
|
|
7
|
+
requireAuth
|
|
8
|
+
} from "./chunk-2P35S2C3.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
outputJSON,
|
|
13
|
+
success
|
|
14
|
+
} from "./chunk-EYNDY7RB.js";
|
|
15
|
+
|
|
16
|
+
// src/commands/store/order-cancel.ts
|
|
17
|
+
import * as readline from "readline";
|
|
18
|
+
async function storeOrderCancelCommand(id, opts) {
|
|
19
|
+
const cfg = requireAuth();
|
|
20
|
+
const client = new HisaaboClient(cfg);
|
|
21
|
+
if (!opts.yes && process.stdin.isTTY) {
|
|
22
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
23
|
+
const answer = await new Promise((resolve) => {
|
|
24
|
+
rl.question(` Cancel order ${id}? This cannot be undone. (y/n): `, resolve);
|
|
25
|
+
});
|
|
26
|
+
rl.close();
|
|
27
|
+
if (answer.trim().toLowerCase() !== "y") {
|
|
28
|
+
console.log(" Cancelled.");
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const input = { orderId: id };
|
|
34
|
+
if (opts.reason) input["reason"] = opts.reason;
|
|
35
|
+
const result = await client.store.cancelOrder(input);
|
|
36
|
+
if (opts.json) {
|
|
37
|
+
outputJSON(result);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
success(`Order ${id} cancelled`);
|
|
41
|
+
console.log();
|
|
42
|
+
} catch (e) {
|
|
43
|
+
if (e instanceof HisaaboApiError) {
|
|
44
|
+
const err = e.hisaaboError;
|
|
45
|
+
if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
|
|
46
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
47
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
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
|
+
storeOrderCancelCommand
|
|
55
|
+
};
|