@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.
- package/.turbo/turbo-typecheck.log +1 -1
- package/README.md +332 -0
- package/dist/bin/audit-trail-5LOCJ7XZ.js +78 -0
- package/dist/bin/categories-64WWZTND.js +47 -0
- package/dist/bin/check-slug-FLHHUDYS.js +65 -0
- package/dist/bin/chunk-4MEL44QX.js +848 -0
- package/dist/bin/chunk-FIMJZAS4.js +84 -0
- package/dist/bin/chunk-NO4FIFMS.js +176 -0
- package/dist/bin/chunk-T63VQXNM.js +156 -0
- package/dist/bin/client-5NZ23GML.js +11 -0
- package/dist/bin/collection-efficiency-U56XNVEE.js +165 -0
- package/dist/bin/config-335MN4I7.js +18 -0
- package/dist/bin/create-RPDEORDD.js +83 -0
- package/dist/bin/default-account-AE6EXZZR.js +58 -0
- package/dist/bin/expenses-5N2QSG54.js +89 -0
- package/dist/bin/export-QICOQK34.js +59 -0
- package/dist/bin/factory-KOCW2AQM.js +483 -0
- package/dist/bin/get-A43QCI2S.js +66 -0
- package/dist/bin/get-GWH6S5SJ.js +71 -0
- package/dist/bin/hisaabo.js +2302 -1510
- package/dist/bin/invitations-P3EEN5WI.js +66 -0
- package/dist/bin/invite-T3CKX53E.js +53 -0
- package/dist/bin/invoice-breakdown-FN5BEFJD.js +97 -0
- package/dist/bin/items-2OOCQKVF.js +62 -0
- package/dist/bin/items-toggle-SKZWCGJH.js +46 -0
- package/dist/bin/list-A2RKI3ZG.js +79 -0
- package/dist/bin/list-NRMBMKMI.js +90 -0
- package/dist/bin/list-T74SN6IR.js +46 -0
- package/dist/bin/members-W2GW3ODT.js +55 -0
- package/dist/bin/monthly-comparison-T34ZFOHL.js +176 -0
- package/dist/bin/order-cancel-TI27JYYD.js +55 -0
- package/dist/bin/order-confirm-VMRAMNTD.js +53 -0
- package/dist/bin/order-get-C2RBUR4O.js +88 -0
- package/dist/bin/order-update-RE3HATNF.js +60 -0
- package/dist/bin/output-NUOL7KJW.js +35 -0
- package/dist/bin/payment-modes-WOOT22I7.js +126 -0
- package/dist/bin/profit-loss-T4RESJ32.js +135 -0
- package/dist/bin/receivables-aging-6XMENEWS.js +161 -0
- package/dist/bin/remove-6QZI4JCY.js +52 -0
- package/dist/bin/revoke-AVEMPAC7.js +40 -0
- package/dist/bin/revoke-YUCFZFNR.js +52 -0
- package/dist/bin/revoke-all-LFW5WBHO.js +33 -0
- package/dist/bin/revoke-invitation-DTGQRJR4.js +40 -0
- package/dist/bin/sales-trend-ZYBRUDUU.js +71 -0
- package/dist/bin/sequence-FPOJTI2P.js +66 -0
- package/dist/bin/store-IOB4Y67C.js +82 -0
- package/dist/bin/summary-5KYBA4ZO.js +113 -0
- package/dist/bin/top-customers-WSQ2UEJL.js +81 -0
- package/dist/bin/top-items-RWQPDGLN.js +84 -0
- package/dist/bin/top-outstanding-QAMO2E7Y.js +64 -0
- package/dist/bin/unpaid-invoices-WB3TK5B4.js +65 -0
- package/dist/bin/untracked-H733MYJL.js +67 -0
- package/dist/bin/update-H6LPO2Z4.js +61 -0
- package/dist/bin/update-JU2X3XU5.js +54 -0
- package/dist/bin/update-TLBUIC5J.js +57 -0
- package/dist/bin/update-role-QST7BVFX.js +45 -0
- package/dist/bin/update-settings-Q2EGRLKZ.js +56 -0
- package/package.json +7 -6
- package/src/auth.ts +12 -3
- package/src/bin/hisaabo.ts +49 -935
- package/src/bin/registrars/api-key.ts +44 -0
- package/src/bin/registrars/auth.ts +222 -0
- package/src/bin/registrars/automated-invoice.ts +167 -0
- package/src/bin/registrars/bank.ts +124 -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/session.ts +32 -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 +73 -0
- package/src/client.ts +589 -15
- 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/bank/gateway-config.ts +61 -0
- package/src/commands/bank/update-gateway.ts +84 -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/session/list.ts +91 -0
- package/src/commands/session/revoke-all.ts +20 -0
- package/src/commands/session/revoke.ts +32 -0
- 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/invitations.ts +62 -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/revoke-invitation.ts +32 -0
- package/src/commands/tenant/update-role.ts +41 -0
- package/src/config.ts +51 -2
- package/src/error-handler.ts +53 -0
- package/src/output.ts +1 -0
- package/src/spinner.ts +39 -0
- package/tsup.config.ts +6 -1
- package/src/components/ErrorDisplay.tsx +0 -16
- package/src/components/Header.tsx +0 -26
- package/src/components/MoneyCell.tsx +0 -16
- package/src/components/Spinner.tsx +0 -12
- package/src/components/StatusBadge.tsx +0 -39
- package/src/components/Table.tsx +0 -63
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
fatalError,
|
|
4
|
+
warn
|
|
5
|
+
} from "./chunk-NO4FIFMS.js";
|
|
6
|
+
|
|
7
|
+
// src/config.ts
|
|
8
|
+
import Conf from "conf";
|
|
9
|
+
import { hostname, userInfo } from "os";
|
|
10
|
+
import { createHash } from "crypto";
|
|
11
|
+
function deriveEncryptionKey() {
|
|
12
|
+
let uid;
|
|
13
|
+
try {
|
|
14
|
+
uid = String(userInfo().uid);
|
|
15
|
+
} catch {
|
|
16
|
+
uid = String(process.getuid?.() ?? process.pid);
|
|
17
|
+
}
|
|
18
|
+
const raw = `${uid}:${hostname()}:hisaabo-cli`;
|
|
19
|
+
return createHash("sha256").update(raw).digest("hex");
|
|
20
|
+
}
|
|
21
|
+
var conf = new Conf({
|
|
22
|
+
projectName: "hisaabo",
|
|
23
|
+
projectSuffix: "",
|
|
24
|
+
configName: "config",
|
|
25
|
+
encryptionKey: deriveEncryptionKey(),
|
|
26
|
+
configFileMode: 384
|
|
27
|
+
// owner read/write only — prevents credential theft on shared systems
|
|
28
|
+
});
|
|
29
|
+
function getConfig() {
|
|
30
|
+
return conf.store;
|
|
31
|
+
}
|
|
32
|
+
function setConfig(values) {
|
|
33
|
+
for (const [k, v] of Object.entries(values)) {
|
|
34
|
+
if (v !== void 0) {
|
|
35
|
+
conf.set(k, v);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function clearConfig() {
|
|
40
|
+
conf.clear();
|
|
41
|
+
}
|
|
42
|
+
function isAuthenticated() {
|
|
43
|
+
const cfg = getConfig();
|
|
44
|
+
return !!(cfg.token && cfg.apiUrl && cfg.businessId);
|
|
45
|
+
}
|
|
46
|
+
function requireAuth() {
|
|
47
|
+
const envToken = process.env["HISAABO_TOKEN"];
|
|
48
|
+
const envUrl = process.env["HISAABO_API_URL"];
|
|
49
|
+
if (envToken && envUrl) {
|
|
50
|
+
return {
|
|
51
|
+
apiUrl: envUrl,
|
|
52
|
+
token: envToken,
|
|
53
|
+
tenantId: process.env["HISAABO_TENANT_ID"] ?? "",
|
|
54
|
+
businessId: process.env["HISAABO_BUSINESS_ID"] ?? "",
|
|
55
|
+
businessName: process.env["HISAABO_BUSINESS_NAME"] ?? "",
|
|
56
|
+
tokenCreatedAt: Date.now()
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const cfg = getConfig();
|
|
60
|
+
if (!cfg.token || !cfg.apiUrl || !cfg.businessId || !cfg.tenantId) {
|
|
61
|
+
fatalError("Not authenticated. Run: hisaabo login", 3);
|
|
62
|
+
}
|
|
63
|
+
const isApiKey = cfg.token.startsWith("hisaabo_key_");
|
|
64
|
+
if (!isApiKey && cfg.tokenCreatedAt) {
|
|
65
|
+
const ageMs = Date.now() - cfg.tokenCreatedAt;
|
|
66
|
+
const TWENTY_FIVE_DAYS = 25 * 24 * 60 * 60 * 1e3;
|
|
67
|
+
if (ageMs > TWENTY_FIVE_DAYS) {
|
|
68
|
+
warn("Session expires soon. Run: hisaabo login");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return cfg;
|
|
72
|
+
}
|
|
73
|
+
function getConfigPath() {
|
|
74
|
+
return conf.path;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
getConfig,
|
|
79
|
+
setConfig,
|
|
80
|
+
clearConfig,
|
|
81
|
+
isAuthenticated,
|
|
82
|
+
requireAuth,
|
|
83
|
+
getConfigPath
|
|
84
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/output.ts
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
function isInteractive() {
|
|
6
|
+
return process.stdout.isTTY === true;
|
|
7
|
+
}
|
|
8
|
+
function hasColor() {
|
|
9
|
+
if (process.env["NO_COLOR"] !== void 0) return false;
|
|
10
|
+
if (process.env["FORCE_COLOR"] === "0") return false;
|
|
11
|
+
return process.stdout.hasColors?.() ?? isInteractive();
|
|
12
|
+
}
|
|
13
|
+
function stripAnsi(str) {
|
|
14
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
15
|
+
}
|
|
16
|
+
function getWidthTier() {
|
|
17
|
+
const w = process.stdout.columns ?? 80;
|
|
18
|
+
if (w < 80) return "narrow";
|
|
19
|
+
if (w <= 120) return "standard";
|
|
20
|
+
return "wide";
|
|
21
|
+
}
|
|
22
|
+
function termWidth() {
|
|
23
|
+
return process.stdout.columns ?? 80;
|
|
24
|
+
}
|
|
25
|
+
var EXIT = {
|
|
26
|
+
SUCCESS: 0,
|
|
27
|
+
GENERAL: 1,
|
|
28
|
+
USAGE: 2,
|
|
29
|
+
AUTH: 3,
|
|
30
|
+
FORBIDDEN: 4,
|
|
31
|
+
NOT_FOUND: 5,
|
|
32
|
+
VALIDATION: 6,
|
|
33
|
+
NETWORK: 7,
|
|
34
|
+
CONFLICT: 8,
|
|
35
|
+
RATE_LIMITED: 9
|
|
36
|
+
};
|
|
37
|
+
function fatalError(message, code = 1) {
|
|
38
|
+
if (hasColor()) {
|
|
39
|
+
process.stderr.write(chalk.red("Error: ") + message + "\n");
|
|
40
|
+
} else {
|
|
41
|
+
process.stderr.write("Error: " + message + "\n");
|
|
42
|
+
}
|
|
43
|
+
process.exit(code);
|
|
44
|
+
}
|
|
45
|
+
function success(message) {
|
|
46
|
+
if (hasColor()) {
|
|
47
|
+
process.stdout.write(chalk.green("\u2713 ") + message + "\n");
|
|
48
|
+
} else {
|
|
49
|
+
process.stdout.write("OK: " + message + "\n");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function warn(message) {
|
|
53
|
+
if (hasColor()) {
|
|
54
|
+
process.stderr.write(chalk.yellow("Warning: ") + message + "\n");
|
|
55
|
+
} else {
|
|
56
|
+
process.stderr.write("Warning: " + message + "\n");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function outputJSON(data) {
|
|
60
|
+
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
61
|
+
}
|
|
62
|
+
function getNestedValue(obj, key) {
|
|
63
|
+
const parts = key.split(".");
|
|
64
|
+
let cur = obj;
|
|
65
|
+
for (const part of parts) {
|
|
66
|
+
if (cur == null || typeof cur !== "object") return void 0;
|
|
67
|
+
cur = cur[part];
|
|
68
|
+
}
|
|
69
|
+
return cur;
|
|
70
|
+
}
|
|
71
|
+
function padEnd(str, len) {
|
|
72
|
+
const visual = stripAnsi(str).length;
|
|
73
|
+
const pad = Math.max(0, len - visual);
|
|
74
|
+
return str + " ".repeat(pad);
|
|
75
|
+
}
|
|
76
|
+
function padStart(str, len) {
|
|
77
|
+
const visual = stripAnsi(str).length;
|
|
78
|
+
const pad = Math.max(0, len - visual);
|
|
79
|
+
return " ".repeat(pad) + str;
|
|
80
|
+
}
|
|
81
|
+
function outputTable(rows, columns) {
|
|
82
|
+
if (rows.length === 0) {
|
|
83
|
+
process.stdout.write(" (no results)\n");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const widths = columns.map((col) => {
|
|
87
|
+
let max = stripAnsi(col.header).length;
|
|
88
|
+
for (const row of rows) {
|
|
89
|
+
const val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
|
|
90
|
+
const vis = stripAnsi(val).length;
|
|
91
|
+
if (vis > max) max = vis;
|
|
92
|
+
}
|
|
93
|
+
if (col.width) max = Math.min(max, col.width);
|
|
94
|
+
return max;
|
|
95
|
+
});
|
|
96
|
+
const sep = "\u2500".repeat(widths.reduce((s, w) => s + w + 2, 1));
|
|
97
|
+
let header = " ";
|
|
98
|
+
for (let i = 0; i < columns.length; i++) {
|
|
99
|
+
const col = columns[i];
|
|
100
|
+
const h = col.align === "right" ? padStart(col.header, widths[i]) : padEnd(col.header, widths[i]);
|
|
101
|
+
header += (hasColor() ? chalk.dim(h) : h) + " ";
|
|
102
|
+
}
|
|
103
|
+
process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
|
|
104
|
+
process.stdout.write(header.trimEnd() + "\n");
|
|
105
|
+
process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
|
|
106
|
+
for (const row of rows) {
|
|
107
|
+
let line = " ";
|
|
108
|
+
for (let i = 0; i < columns.length; i++) {
|
|
109
|
+
const col = columns[i];
|
|
110
|
+
let val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
|
|
111
|
+
const vis = stripAnsi(val).length;
|
|
112
|
+
if (col.width && vis > col.width) {
|
|
113
|
+
val = val.slice(0, col.width - 1) + "\u2026";
|
|
114
|
+
}
|
|
115
|
+
const cell = col.align === "right" ? padStart(val, widths[i]) : padEnd(val, widths[i]);
|
|
116
|
+
line += cell + " ";
|
|
117
|
+
}
|
|
118
|
+
process.stdout.write(line.trimEnd() + "\n");
|
|
119
|
+
}
|
|
120
|
+
process.stdout.write(" " + (hasColor() ? chalk.dim(sep) : sep) + "\n");
|
|
121
|
+
}
|
|
122
|
+
function outputTSV(rows, columns) {
|
|
123
|
+
process.stdout.write(columns.map((c) => c.header).join(" ") + "\n");
|
|
124
|
+
for (const row of rows) {
|
|
125
|
+
const line = columns.map((col) => {
|
|
126
|
+
const val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
|
|
127
|
+
return stripAnsi(val).replace(/\t/g, " ");
|
|
128
|
+
});
|
|
129
|
+
process.stdout.write(line.join(" ") + "\n");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function csvEscape(val) {
|
|
133
|
+
if (val.includes(",") || val.includes('"') || val.includes("\n")) {
|
|
134
|
+
return `"${val.replace(/"/g, '""')}"`;
|
|
135
|
+
}
|
|
136
|
+
return val;
|
|
137
|
+
}
|
|
138
|
+
function outputCSV(rows, columns) {
|
|
139
|
+
process.stdout.write(columns.map((c) => csvEscape(c.header)).join(",") + "\n");
|
|
140
|
+
for (const row of rows) {
|
|
141
|
+
const line = columns.map((col) => {
|
|
142
|
+
const val = col.format ? col.format(getNestedValue(row, col.key), row) : String(getNestedValue(row, col.key) ?? "");
|
|
143
|
+
return csvEscape(stripAnsi(val));
|
|
144
|
+
});
|
|
145
|
+
process.stdout.write(line.join(",") + "\n");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function outputIds(ids) {
|
|
149
|
+
for (const id of ids) {
|
|
150
|
+
process.stdout.write(id + "\n");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function paginationFooter(page, limit, total) {
|
|
154
|
+
const from = (page - 1) * limit + 1;
|
|
155
|
+
const to = Math.min(page * limit, total);
|
|
156
|
+
const msg = ` Showing ${from}-${to} of ${total}`;
|
|
157
|
+
process.stdout.write("\n" + (hasColor() ? chalk.dim(msg) : msg) + "\n");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export {
|
|
161
|
+
isInteractive,
|
|
162
|
+
hasColor,
|
|
163
|
+
stripAnsi,
|
|
164
|
+
getWidthTier,
|
|
165
|
+
termWidth,
|
|
166
|
+
EXIT,
|
|
167
|
+
fatalError,
|
|
168
|
+
success,
|
|
169
|
+
warn,
|
|
170
|
+
outputJSON,
|
|
171
|
+
outputTable,
|
|
172
|
+
outputTSV,
|
|
173
|
+
outputCSV,
|
|
174
|
+
outputIds,
|
|
175
|
+
paginationFooter
|
|
176
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
hasColor
|
|
4
|
+
} from "./chunk-NO4FIFMS.js";
|
|
5
|
+
|
|
6
|
+
// src/format.ts
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
function formatINR(amount) {
|
|
9
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
10
|
+
if (isNaN(num)) return "0.00";
|
|
11
|
+
const abs = Math.abs(num);
|
|
12
|
+
const formatted = new Intl.NumberFormat("en-IN", {
|
|
13
|
+
minimumFractionDigits: 2,
|
|
14
|
+
maximumFractionDigits: 2
|
|
15
|
+
}).format(abs);
|
|
16
|
+
return (num < 0 ? "-" : "") + "\u20B9" + formatted;
|
|
17
|
+
}
|
|
18
|
+
function formatAmount(amount) {
|
|
19
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
20
|
+
if (isNaN(num)) return "0.00";
|
|
21
|
+
const abs = Math.abs(num);
|
|
22
|
+
const formatted = new Intl.NumberFormat("en-IN", {
|
|
23
|
+
minimumFractionDigits: 2,
|
|
24
|
+
maximumFractionDigits: 2
|
|
25
|
+
}).format(abs);
|
|
26
|
+
return (num < 0 ? "-" : "") + formatted;
|
|
27
|
+
}
|
|
28
|
+
var MONTHS = [
|
|
29
|
+
"Jan",
|
|
30
|
+
"Feb",
|
|
31
|
+
"Mar",
|
|
32
|
+
"Apr",
|
|
33
|
+
"May",
|
|
34
|
+
"Jun",
|
|
35
|
+
"Jul",
|
|
36
|
+
"Aug",
|
|
37
|
+
"Sep",
|
|
38
|
+
"Oct",
|
|
39
|
+
"Nov",
|
|
40
|
+
"Dec"
|
|
41
|
+
];
|
|
42
|
+
function formatDate(date) {
|
|
43
|
+
if (!date) return "-";
|
|
44
|
+
try {
|
|
45
|
+
const d = new Date(date);
|
|
46
|
+
if (isNaN(d.getTime())) return date;
|
|
47
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
48
|
+
const month = MONTHS[d.getMonth()];
|
|
49
|
+
const year = d.getFullYear();
|
|
50
|
+
return `${day} ${month} ${year}`;
|
|
51
|
+
} catch {
|
|
52
|
+
return date;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function formatRelativeDate(date) {
|
|
56
|
+
if (!date) return "-";
|
|
57
|
+
try {
|
|
58
|
+
const d = new Date(date);
|
|
59
|
+
const now = /* @__PURE__ */ new Date();
|
|
60
|
+
const diff = Math.floor((now.getTime() - d.getTime()) / (1e3 * 60 * 60 * 24));
|
|
61
|
+
if (diff === 0) return "Today";
|
|
62
|
+
if (diff === 1) return "Yesterday";
|
|
63
|
+
if (diff < 30) return `${diff}d ago`;
|
|
64
|
+
if (diff < 365) return `${Math.floor(diff / 30)}mo ago`;
|
|
65
|
+
return `${Math.floor(diff / 365)}y ago`;
|
|
66
|
+
} catch {
|
|
67
|
+
return date ?? "-";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
var STATUS_CONFIG = {
|
|
71
|
+
paid: { label: "PAID", color: (s) => chalk.green(s) },
|
|
72
|
+
sent: { label: "SENT", color: (s) => chalk.blue(s) },
|
|
73
|
+
draft: { label: "DRAFT", color: (s) => chalk.dim(s) },
|
|
74
|
+
partial: { label: "PARTIAL", color: (s) => chalk.yellow(s) },
|
|
75
|
+
overdue: { label: "OVERDUE", color: (s) => chalk.red(s) },
|
|
76
|
+
cancelled: { label: "CANCEL", color: (s) => chalk.dim(chalk.strikethrough(s)) },
|
|
77
|
+
unfulfilled: { label: "UNFUL", color: (s) => chalk.blue(s) },
|
|
78
|
+
pending: { label: "PEND", color: (s) => chalk.yellow(s) },
|
|
79
|
+
confirmed: { label: "CONF", color: (s) => chalk.blue(s) },
|
|
80
|
+
delivered: { label: "DELIV", color: (s) => chalk.green(s) },
|
|
81
|
+
shipped: { label: "SHIPPED", color: (s) => chalk.blue(s) },
|
|
82
|
+
in_transit: { label: "TRANSIT", color: (s) => chalk.cyan(s) },
|
|
83
|
+
returned: { label: "RETURN", color: (s) => chalk.red(s) },
|
|
84
|
+
preparing: { label: "PREP", color: (s) => chalk.yellow(s) },
|
|
85
|
+
ready: { label: "READY", color: (s) => chalk.cyan(s) }
|
|
86
|
+
};
|
|
87
|
+
function formatStatus(status) {
|
|
88
|
+
const cfg = STATUS_CONFIG[status.toLowerCase()];
|
|
89
|
+
const label = cfg ? `[${cfg.label}]` : `[${status.toUpperCase()}]`;
|
|
90
|
+
if (!hasColor() || !cfg) return label;
|
|
91
|
+
return cfg.color(label);
|
|
92
|
+
}
|
|
93
|
+
function currentFY() {
|
|
94
|
+
const now = /* @__PURE__ */ new Date();
|
|
95
|
+
const year = now.getFullYear();
|
|
96
|
+
const month = now.getMonth() + 1;
|
|
97
|
+
if (month >= 4) {
|
|
98
|
+
return `${year}-${String(year + 1).slice(2)}`;
|
|
99
|
+
}
|
|
100
|
+
return `${year - 1}-${String(year).slice(2)}`;
|
|
101
|
+
}
|
|
102
|
+
function fyStart() {
|
|
103
|
+
const now = /* @__PURE__ */ new Date();
|
|
104
|
+
const year = now.getMonth() + 1 >= 4 ? now.getFullYear() : now.getFullYear() - 1;
|
|
105
|
+
return `${year}-04-01`;
|
|
106
|
+
}
|
|
107
|
+
function todayISO() {
|
|
108
|
+
return (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "";
|
|
109
|
+
}
|
|
110
|
+
function monthStart() {
|
|
111
|
+
const now = /* @__PURE__ */ new Date();
|
|
112
|
+
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-01`;
|
|
113
|
+
}
|
|
114
|
+
function monthEnd() {
|
|
115
|
+
const now = /* @__PURE__ */ new Date();
|
|
116
|
+
const last = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
|
117
|
+
return `${last.getFullYear()}-${String(last.getMonth() + 1).padStart(2, "0")}-${String(last.getDate()).padStart(2, "0")}`;
|
|
118
|
+
}
|
|
119
|
+
function quarterRange(q) {
|
|
120
|
+
const now = /* @__PURE__ */ new Date();
|
|
121
|
+
const fyYear = now.getMonth() + 1 >= 4 ? now.getFullYear() : now.getFullYear() - 1;
|
|
122
|
+
const ranges = {
|
|
123
|
+
Q1: { from: `${fyYear}-04-01`, to: `${fyYear}-06-30`, month: 4, year: fyYear },
|
|
124
|
+
Q2: { from: `${fyYear}-07-01`, to: `${fyYear}-09-30`, month: 7, year: fyYear },
|
|
125
|
+
Q3: { from: `${fyYear}-10-01`, to: `${fyYear}-12-31`, month: 10, year: fyYear },
|
|
126
|
+
Q4: { from: `${fyYear + 1}-01-01`, to: `${fyYear + 1}-03-31`, month: 1, year: fyYear + 1 }
|
|
127
|
+
};
|
|
128
|
+
const upper = q.toUpperCase();
|
|
129
|
+
return ranges[upper] ?? ranges["Q1"];
|
|
130
|
+
}
|
|
131
|
+
function deliveryMethodLabel(method) {
|
|
132
|
+
const map = {
|
|
133
|
+
self_pickup: "Self Pickup",
|
|
134
|
+
hand_delivery: "Hand Delivery",
|
|
135
|
+
courier: "Courier",
|
|
136
|
+
bus: "Bus",
|
|
137
|
+
transport: "Transport",
|
|
138
|
+
post: "Post"
|
|
139
|
+
};
|
|
140
|
+
return map[method] ?? method;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export {
|
|
144
|
+
formatINR,
|
|
145
|
+
formatAmount,
|
|
146
|
+
formatDate,
|
|
147
|
+
formatRelativeDate,
|
|
148
|
+
formatStatus,
|
|
149
|
+
currentFY,
|
|
150
|
+
fyStart,
|
|
151
|
+
todayISO,
|
|
152
|
+
monthStart,
|
|
153
|
+
monthEnd,
|
|
154
|
+
quarterRange,
|
|
155
|
+
deliveryMethodLabel
|
|
156
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
formatAmount,
|
|
4
|
+
fyStart,
|
|
5
|
+
monthEnd,
|
|
6
|
+
monthStart,
|
|
7
|
+
todayISO
|
|
8
|
+
} from "./chunk-T63VQXNM.js";
|
|
9
|
+
import {
|
|
10
|
+
HisaaboApiError,
|
|
11
|
+
HisaaboClient
|
|
12
|
+
} from "./chunk-4MEL44QX.js";
|
|
13
|
+
import {
|
|
14
|
+
requireAuth
|
|
15
|
+
} from "./chunk-FIMJZAS4.js";
|
|
16
|
+
import {
|
|
17
|
+
EXIT,
|
|
18
|
+
fatalError,
|
|
19
|
+
hasColor,
|
|
20
|
+
outputCSV,
|
|
21
|
+
outputJSON,
|
|
22
|
+
outputTSV,
|
|
23
|
+
outputTable,
|
|
24
|
+
termWidth
|
|
25
|
+
} from "./chunk-NO4FIFMS.js";
|
|
26
|
+
|
|
27
|
+
// src/commands/dashboard/collection-efficiency.ts
|
|
28
|
+
import chalk from "chalk";
|
|
29
|
+
function rateBar(rate, width) {
|
|
30
|
+
const clamped = Math.min(100, Math.max(0, rate));
|
|
31
|
+
const filled = Math.round(clamped / 100 * width);
|
|
32
|
+
const bar = "\u2588".repeat(filled) + "\u2591".repeat(width - filled);
|
|
33
|
+
if (!hasColor()) return bar;
|
|
34
|
+
if (clamped >= 80) return chalk.green(bar);
|
|
35
|
+
if (clamped >= 50) return chalk.yellow(bar);
|
|
36
|
+
return chalk.red(bar);
|
|
37
|
+
}
|
|
38
|
+
async function dashboardCollectionEfficiencyCommand(opts) {
|
|
39
|
+
const cfg = requireAuth();
|
|
40
|
+
const client = new HisaaboClient(cfg);
|
|
41
|
+
let fromDate = opts.from;
|
|
42
|
+
let toDate = opts.to;
|
|
43
|
+
if (opts.thisMonth) {
|
|
44
|
+
fromDate = monthStart();
|
|
45
|
+
toDate = monthEnd();
|
|
46
|
+
} else if (opts.thisFy) {
|
|
47
|
+
fromDate = fyStart();
|
|
48
|
+
toDate = todayISO();
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const data = await client.dashboard.collectionEfficiency({ fromDate, toDate });
|
|
52
|
+
if (opts.json) {
|
|
53
|
+
outputJSON(data);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const d = data ?? {};
|
|
57
|
+
const totalInvoiced = parseFloat(String(d["totalInvoiced"] ?? d["invoiced"] ?? d["billed"] ?? "0"));
|
|
58
|
+
const totalCollected = parseFloat(String(d["totalCollected"] ?? d["collected"] ?? d["received"] ?? "0"));
|
|
59
|
+
const outstanding = parseFloat(String(d["outstanding"] ?? d["totalOutstanding"] ?? String(totalInvoiced - totalCollected)));
|
|
60
|
+
const collectionRate = parseFloat(String(d["collectionRate"] ?? d["rate"] ?? (totalInvoiced > 0 ? (totalCollected / totalInvoiced * 100).toFixed(2) : "0")));
|
|
61
|
+
const dso = parseFloat(String(d["dso"] ?? d["daysSalesOutstanding"] ?? "0"));
|
|
62
|
+
const aging = d["aging"] ?? d["agingBreakdown"] ?? d["breakdown"] ?? null;
|
|
63
|
+
if (opts.format === "tsv" || opts.format === "csv") {
|
|
64
|
+
const rows = [
|
|
65
|
+
{ metric: "Total Invoiced", value: formatAmount(totalInvoiced) },
|
|
66
|
+
{ metric: "Total Collected", value: formatAmount(totalCollected) },
|
|
67
|
+
{ metric: "Outstanding", value: formatAmount(outstanding) },
|
|
68
|
+
{ metric: "Collection Rate", value: `${collectionRate.toFixed(1)}%` },
|
|
69
|
+
{ metric: "DSO (days)", value: dso > 0 ? String(Math.round(dso)) : "-" }
|
|
70
|
+
];
|
|
71
|
+
if (aging) {
|
|
72
|
+
for (const [k, v] of Object.entries(aging)) {
|
|
73
|
+
rows.push({ metric: `Aging: ${k}`, value: formatAmount(String(v)) });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const columns = [
|
|
77
|
+
{ key: "metric", header: "Metric", align: "left" },
|
|
78
|
+
{ key: "value", header: "Value", align: "right" }
|
|
79
|
+
];
|
|
80
|
+
if (opts.format === "tsv") outputTSV(rows, columns);
|
|
81
|
+
else outputCSV(rows, columns);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const width = Math.min(termWidth() - 4, 56);
|
|
85
|
+
const innerW = width - 2;
|
|
86
|
+
const barW = Math.max(8, innerW - 22);
|
|
87
|
+
const line = (label, value, opts2 = {}) => {
|
|
88
|
+
const lbl = label.padEnd(20).slice(0, 20);
|
|
89
|
+
const val = value.padStart(innerW - 22).slice(0, innerW - 22);
|
|
90
|
+
let out = ` \u2502 ${lbl} ${val} \u2502`;
|
|
91
|
+
if (hasColor()) {
|
|
92
|
+
if (opts2.bold) out = ` \u2502 ${chalk.bold(lbl)} ${val} \u2502`;
|
|
93
|
+
if (opts2.color) out = ` \u2502 ${opts2.bold ? chalk.bold(lbl) : lbl} ${opts2.color(val)} \u2502`;
|
|
94
|
+
}
|
|
95
|
+
process.stdout.write(out + "\n");
|
|
96
|
+
};
|
|
97
|
+
const sep = () => {
|
|
98
|
+
process.stdout.write(" \u251C" + "\u2500".repeat(innerW) + "\u2524\n");
|
|
99
|
+
};
|
|
100
|
+
process.stdout.write("\n");
|
|
101
|
+
if (hasColor()) process.stdout.write(" " + chalk.bold("Collection Efficiency") + "\n\n");
|
|
102
|
+
else process.stdout.write(" Collection Efficiency\n\n");
|
|
103
|
+
process.stdout.write(" \u250C" + "\u2500".repeat(innerW) + "\u2510\n");
|
|
104
|
+
line("Total Invoiced", `\u20B9${formatAmount(totalInvoiced)}`, { bold: true });
|
|
105
|
+
line("Total Collected", `\u20B9${formatAmount(totalCollected)}`, {
|
|
106
|
+
color: totalCollected >= totalInvoiced * 0.8 ? chalk.green : chalk.yellow
|
|
107
|
+
});
|
|
108
|
+
line("Outstanding", `\u20B9${formatAmount(outstanding)}`, {
|
|
109
|
+
color: outstanding > 0 ? chalk.red : chalk.green
|
|
110
|
+
});
|
|
111
|
+
sep();
|
|
112
|
+
const rateStr = `${collectionRate.toFixed(1)}%`;
|
|
113
|
+
const bar = rateBar(collectionRate, barW);
|
|
114
|
+
const rateLabel = "Collection Rate".padEnd(20).slice(0, 20);
|
|
115
|
+
process.stdout.write(` \u2502 ${hasColor() ? chalk.bold(rateLabel) : rateLabel} ${bar} ${rateStr.padStart(6)} \u2502
|
|
116
|
+
`);
|
|
117
|
+
if (dso > 0) {
|
|
118
|
+
const dsoStr = `${Math.round(dso)} days`;
|
|
119
|
+
const dsoLabel = "DSO".padEnd(20).slice(0, 20);
|
|
120
|
+
const dsoColor = dso <= 30 ? chalk.green : dso <= 60 ? chalk.yellow : chalk.red;
|
|
121
|
+
const dsoVal = hasColor() ? dsoColor(dsoStr) : dsoStr;
|
|
122
|
+
process.stdout.write(` \u2502 ${dsoLabel} ${dsoVal.padStart(innerW - 22)} \u2502
|
|
123
|
+
`);
|
|
124
|
+
}
|
|
125
|
+
if (aging && Object.keys(aging).length > 0) {
|
|
126
|
+
sep();
|
|
127
|
+
process.stdout.write(` \u2502 ${hasColor() ? chalk.bold("Aging Breakdown") : "Aging Breakdown"}${" ".repeat(innerW - 16)} \u2502
|
|
128
|
+
`);
|
|
129
|
+
const agingEntries = Object.entries(aging);
|
|
130
|
+
for (const [bucket, val] of agingEntries) {
|
|
131
|
+
const amt = parseFloat(String(val));
|
|
132
|
+
const amtStr = `\u20B9${formatAmount(amt)}`;
|
|
133
|
+
const bucketLabel = bucket.padEnd(20).slice(0, 20);
|
|
134
|
+
const isOld = /90\+|90_plus/i.test(bucket);
|
|
135
|
+
const color = isOld ? chalk.red : /31|61/.test(bucket) ? chalk.yellow : void 0;
|
|
136
|
+
const valStr = color && hasColor() ? color(amtStr) : amtStr;
|
|
137
|
+
process.stdout.write(` \u2502 ${bucketLabel.slice(0, 18)} ${valStr.padStart(innerW - 22)} \u2502
|
|
138
|
+
`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
process.stdout.write(" \u2514" + "\u2500".repeat(innerW) + "\u2518\n\n");
|
|
142
|
+
if (aging && Object.keys(aging).length > 0) {
|
|
143
|
+
const agingRows = Object.entries(aging).map(([bucket, val]) => ({
|
|
144
|
+
bucket,
|
|
145
|
+
amount: formatAmount(String(val))
|
|
146
|
+
}));
|
|
147
|
+
const agingColumns = [
|
|
148
|
+
{ key: "bucket", header: "Aging Bucket", align: "left" },
|
|
149
|
+
{ key: "amount", header: "Amount \u20B9", align: "right" }
|
|
150
|
+
];
|
|
151
|
+
outputTable(agingRows, agingColumns);
|
|
152
|
+
process.stdout.write("\n");
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
if (e instanceof HisaaboApiError) {
|
|
156
|
+
const err = e.hisaaboError;
|
|
157
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
158
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
159
|
+
}
|
|
160
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
dashboardCollectionEfficiencyCommand
|
|
165
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
clearConfig,
|
|
4
|
+
getConfig,
|
|
5
|
+
getConfigPath,
|
|
6
|
+
isAuthenticated,
|
|
7
|
+
requireAuth,
|
|
8
|
+
setConfig
|
|
9
|
+
} from "./chunk-FIMJZAS4.js";
|
|
10
|
+
import "./chunk-NO4FIFMS.js";
|
|
11
|
+
export {
|
|
12
|
+
clearConfig,
|
|
13
|
+
getConfig,
|
|
14
|
+
getConfigPath,
|
|
15
|
+
isAuthenticated,
|
|
16
|
+
requireAuth,
|
|
17
|
+
setConfig
|
|
18
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
} from "./chunk-NO4FIFMS.js";
|
|
15
|
+
|
|
16
|
+
// src/commands/api-key/create.ts
|
|
17
|
+
import chalk from "chalk";
|
|
18
|
+
async function apiKeyCreateCommand(opts) {
|
|
19
|
+
const cfg = requireAuth();
|
|
20
|
+
const client = new HisaaboClient(cfg);
|
|
21
|
+
if (!opts.name || opts.name.trim().length === 0) {
|
|
22
|
+
fatalError("--name is required.", EXIT.USAGE);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const result = await client.apiKey.create({ name: opts.name.trim() });
|
|
26
|
+
if (opts.json) {
|
|
27
|
+
outputJSON(result);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const key = String(result?.key ?? result?.apiKey ?? result?.token ?? "");
|
|
31
|
+
const id = String(result?.id ?? "");
|
|
32
|
+
if (hasColor()) {
|
|
33
|
+
process.stdout.write("\n");
|
|
34
|
+
process.stdout.write(chalk.bold.green(" \u2713 API key created successfully!\n"));
|
|
35
|
+
process.stdout.write("\n");
|
|
36
|
+
process.stdout.write(chalk.bold.yellow(" \u26A0 IMPORTANT: Copy this key now \u2014 it will NOT be shown again.\n"));
|
|
37
|
+
process.stdout.write("\n");
|
|
38
|
+
if (key) {
|
|
39
|
+
process.stdout.write(" " + chalk.bold("Your API key:") + "\n");
|
|
40
|
+
process.stdout.write("\n");
|
|
41
|
+
process.stdout.write(" " + chalk.cyan.bold(key) + "\n");
|
|
42
|
+
process.stdout.write("\n");
|
|
43
|
+
}
|
|
44
|
+
process.stdout.write(chalk.dim(" Use it with: hisaabo login --token <key>\n"));
|
|
45
|
+
process.stdout.write(chalk.dim(" Or set env: HISAABO_TOKEN=" + (key ? key : "<key>") + "\n"));
|
|
46
|
+
if (id) process.stdout.write(chalk.dim(`
|
|
47
|
+
Key ID: ${id}
|
|
48
|
+
`));
|
|
49
|
+
process.stdout.write("\n");
|
|
50
|
+
} else {
|
|
51
|
+
process.stdout.write("\nAPI key created successfully!\n\n");
|
|
52
|
+
process.stdout.write("IMPORTANT: Copy this key now \u2014 it will NOT be shown again.\n\n");
|
|
53
|
+
if (key) {
|
|
54
|
+
process.stdout.write(`Your API key:
|
|
55
|
+
|
|
56
|
+
${key}
|
|
57
|
+
|
|
58
|
+
`);
|
|
59
|
+
process.stdout.write(`Usage: hisaabo login --token ${key}
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
if (id) process.stdout.write(`Key ID: ${id}
|
|
63
|
+
`);
|
|
64
|
+
process.stdout.write("\n");
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
if (e instanceof HisaaboApiError) {
|
|
68
|
+
const err = e.hisaaboError;
|
|
69
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
70
|
+
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
71
|
+
if (err.code === "validation_failed") {
|
|
72
|
+
const msgs = Object.entries(err.fields).map(([f, ms]) => ` ${f}: ${ms.join(", ")}`).join("\n");
|
|
73
|
+
fatalError(`Validation failed:
|
|
74
|
+
${msgs}`, EXIT.VALIDATION);
|
|
75
|
+
}
|
|
76
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
77
|
+
}
|
|
78
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
apiKeyCreateCommand
|
|
83
|
+
};
|