@hisaabo/cli 0.1.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-build.log +13 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CLI-UX-ARCHITECTURE.md +1269 -0
- package/dist/bin/hisaabo.js +3516 -0
- package/package.json +34 -0
- package/src/auth.ts +212 -0
- package/src/bin/hisaabo.ts +950 -0
- package/src/client.ts +1229 -0
- package/src/commands/bank/index.ts +244 -0
- package/src/commands/dashboard.ts +105 -0
- package/src/commands/expense/create.ts +51 -0
- package/src/commands/expense/delete.ts +45 -0
- package/src/commands/expense/list.ts +65 -0
- package/src/commands/gst/index.ts +116 -0
- package/src/commands/import/index.ts +100 -0
- package/src/commands/invoice/create.ts +262 -0
- package/src/commands/invoice/delete.ts +44 -0
- package/src/commands/invoice/get.ts +105 -0
- package/src/commands/invoice/list.ts +126 -0
- package/src/commands/invoice/pdf.ts +75 -0
- package/src/commands/invoice/status.ts +41 -0
- package/src/commands/item/create.ts +98 -0
- package/src/commands/item/delete.ts +44 -0
- package/src/commands/item/list.ts +81 -0
- package/src/commands/item/stock.ts +46 -0
- package/src/commands/party/create.ts +88 -0
- package/src/commands/party/delete.ts +44 -0
- package/src/commands/party/get.ts +42 -0
- package/src/commands/party/ledger.ts +63 -0
- package/src/commands/party/list.ts +69 -0
- package/src/commands/payment/create.ts +133 -0
- package/src/commands/payment/delete.ts +46 -0
- package/src/commands/payment/list.ts +66 -0
- package/src/commands/report/index.ts +218 -0
- package/src/commands/shipment/index.ts +170 -0
- package/src/commands/store/index.ts +77 -0
- package/src/commands/target/index.ts +118 -0
- package/src/components/ErrorDisplay.tsx +16 -0
- package/src/components/Header.tsx +26 -0
- package/src/components/MoneyCell.tsx +16 -0
- package/src/components/Spinner.tsx +12 -0
- package/src/components/StatusBadge.tsx +39 -0
- package/src/components/Table.tsx +63 -0
- package/src/config.ts +47 -0
- package/src/format.ts +180 -0
- package/src/output.ts +227 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type ShipmentSummary } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import {
|
|
4
|
+
fatalError, outputJSON, outputTable, paginationFooter, EXIT, success, type ColumnDef,
|
|
5
|
+
} from "../../output.js";
|
|
6
|
+
import { formatDate, formatStatus } from "../../format.js";
|
|
7
|
+
|
|
8
|
+
interface ListOpts {
|
|
9
|
+
json?: boolean;
|
|
10
|
+
status?: string;
|
|
11
|
+
invoiceId?: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
limit?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function shipmentListCommand(opts: ListOpts): Promise<void> {
|
|
17
|
+
const cfg = requireAuth();
|
|
18
|
+
const client = new HisaaboClient(cfg);
|
|
19
|
+
const page = opts.page ?? 1;
|
|
20
|
+
const limit = opts.limit ?? 20;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const result = await client.shipment.list({
|
|
24
|
+
status: opts.status as ShipmentSummary["status"] | undefined ?? null,
|
|
25
|
+
invoiceId: opts.invoiceId ?? null,
|
|
26
|
+
page,
|
|
27
|
+
limit,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (opts.json) {
|
|
31
|
+
outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log(`\n Shipments ${result.total} total\n`);
|
|
36
|
+
|
|
37
|
+
const cols: ColumnDef<ShipmentSummary>[] = [
|
|
38
|
+
{ key: "invoiceNumber", header: "Invoice", width: 12, format: (v) => String(v ?? "-") },
|
|
39
|
+
{ key: "partyName", header: "Party", width: 18, format: (v) => String(v ?? "-") },
|
|
40
|
+
{ key: "carrier", header: "Carrier", width: 12, format: (v) => String(v ?? "-") },
|
|
41
|
+
{ key: "trackingNumber", header: "Tracking", width: 16, format: (v) => String(v ?? "-") },
|
|
42
|
+
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
43
|
+
{ key: "shipmentDate", header: "Shipped", width: 12, format: (v) => formatDate(v ? String(v) : null) },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
outputTable(result.data, cols);
|
|
47
|
+
paginationFooter(result.page, result.limit, result.total);
|
|
48
|
+
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e instanceof HisaaboApiError) {
|
|
51
|
+
const err = e.hisaaboError;
|
|
52
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
53
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
54
|
+
}
|
|
55
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function shipmentGetCommand(id: string, opts: { json?: boolean }): Promise<void> {
|
|
60
|
+
const cfg = requireAuth();
|
|
61
|
+
const client = new HisaaboClient(cfg);
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const shipment = await client.shipment.get(id);
|
|
65
|
+
if (!shipment) fatalError(`Shipment not found: ${id}`, EXIT.NOT_FOUND);
|
|
66
|
+
|
|
67
|
+
if (opts.json) {
|
|
68
|
+
outputJSON(shipment);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log(`\n Shipment ${id}`);
|
|
73
|
+
console.log(" " + "─".repeat(45));
|
|
74
|
+
if (shipment!.invoiceNumber) console.log(` Invoice: ${shipment!.invoiceNumber}`);
|
|
75
|
+
if (shipment!.partyName) console.log(` Party: ${shipment!.partyName}`);
|
|
76
|
+
if (shipment!.carrier) console.log(` Carrier: ${shipment!.carrier}`);
|
|
77
|
+
if (shipment!.trackingNumber) console.log(` Tracking: ${shipment!.trackingNumber}`);
|
|
78
|
+
if (shipment!.trackingUrl) console.log(` URL: ${shipment!.trackingUrl}`);
|
|
79
|
+
console.log(` Status: ${formatStatus(shipment!.status)}`);
|
|
80
|
+
if (shipment!.shipmentDate) console.log(` Shipped: ${formatDate(shipment!.shipmentDate)}`);
|
|
81
|
+
if (shipment!.estimatedDelivery) console.log(` Est. Del: ${formatDate(shipment!.estimatedDelivery)}`);
|
|
82
|
+
if (shipment!.actualDelivery) console.log(` Delivered:${formatDate(shipment!.actualDelivery)}`);
|
|
83
|
+
console.log();
|
|
84
|
+
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (e instanceof HisaaboApiError) {
|
|
87
|
+
const err = e.hisaaboError;
|
|
88
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
89
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
90
|
+
}
|
|
91
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function shipmentCreateCommand(opts: {
|
|
96
|
+
json?: boolean;
|
|
97
|
+
invoiceId?: string;
|
|
98
|
+
partyId?: string;
|
|
99
|
+
carrier?: string;
|
|
100
|
+
tracking?: string;
|
|
101
|
+
mode?: string;
|
|
102
|
+
date?: string;
|
|
103
|
+
}): Promise<void> {
|
|
104
|
+
const cfg = requireAuth();
|
|
105
|
+
const client = new HisaaboClient(cfg);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const shipment = await client.shipment.create({
|
|
109
|
+
invoiceId: opts.invoiceId,
|
|
110
|
+
partyId: opts.partyId,
|
|
111
|
+
carrier: opts.carrier,
|
|
112
|
+
trackingNumber: opts.tracking,
|
|
113
|
+
mode: opts.mode,
|
|
114
|
+
shipmentDate: opts.date,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (opts.json) {
|
|
118
|
+
outputJSON(shipment);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
success(`Shipment created: ${shipment.id}`);
|
|
123
|
+
if (shipment.trackingNumber) console.log(` Tracking: ${shipment.trackingNumber}`);
|
|
124
|
+
console.log();
|
|
125
|
+
|
|
126
|
+
} catch (e) {
|
|
127
|
+
if (e instanceof HisaaboApiError) {
|
|
128
|
+
const err = e.hisaaboError;
|
|
129
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
130
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
131
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
132
|
+
}
|
|
133
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function shipmentUpdateCommand(id: string, opts: {
|
|
138
|
+
json?: boolean;
|
|
139
|
+
status?: string;
|
|
140
|
+
tracking?: string;
|
|
141
|
+
carrier?: string;
|
|
142
|
+
}): Promise<void> {
|
|
143
|
+
const cfg = requireAuth();
|
|
144
|
+
const client = new HisaaboClient(cfg);
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const shipment = await client.shipment.update({
|
|
148
|
+
id,
|
|
149
|
+
status: opts.status as ShipmentSummary["status"] | undefined,
|
|
150
|
+
trackingNumber: opts.tracking,
|
|
151
|
+
carrier: opts.carrier,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (opts.json) {
|
|
155
|
+
outputJSON(shipment);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
success(`Shipment updated: ${formatStatus(shipment.status)}`);
|
|
160
|
+
|
|
161
|
+
} catch (e) {
|
|
162
|
+
if (e instanceof HisaaboApiError) {
|
|
163
|
+
const err = e.hisaaboError;
|
|
164
|
+
if (err.code === "not_found") fatalError(`Shipment not found: ${id}`, EXIT.NOT_FOUND);
|
|
165
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
166
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
167
|
+
}
|
|
168
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type StoreOrderSummary } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import {
|
|
4
|
+
fatalError, outputJSON, outputTable, paginationFooter, EXIT, type ColumnDef,
|
|
5
|
+
} from "../../output.js";
|
|
6
|
+
import { formatDate, formatAmount, formatStatus } from "../../format.js";
|
|
7
|
+
|
|
8
|
+
export async function storeSettingsCommand(opts: { json?: boolean }): Promise<void> {
|
|
9
|
+
const cfg = requireAuth();
|
|
10
|
+
const client = new HisaaboClient(cfg);
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const settings = await client.store.getSettings();
|
|
14
|
+
|
|
15
|
+
if (opts.json) {
|
|
16
|
+
outputJSON(settings);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
console.log("\n Store Settings\n " + "─".repeat(35));
|
|
21
|
+
console.log(` Enabled: ${settings.storeEnabled ? "Yes" : "No"}`);
|
|
22
|
+
if (settings.storeSlug) console.log(` Slug: ${settings.storeSlug}`);
|
|
23
|
+
if (settings.storeName) console.log(` Name: ${settings.storeName}`);
|
|
24
|
+
if (settings.storeDescription) console.log(` About: ${settings.storeDescription}`);
|
|
25
|
+
console.log();
|
|
26
|
+
|
|
27
|
+
} catch (e) {
|
|
28
|
+
if (e instanceof HisaaboApiError) {
|
|
29
|
+
const err = e.hisaaboError;
|
|
30
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
31
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
32
|
+
}
|
|
33
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function storeOrdersCommand(opts: {
|
|
38
|
+
json?: boolean;
|
|
39
|
+
status?: string;
|
|
40
|
+
page?: number;
|
|
41
|
+
limit?: number;
|
|
42
|
+
}): Promise<void> {
|
|
43
|
+
const cfg = requireAuth();
|
|
44
|
+
const client = new HisaaboClient(cfg);
|
|
45
|
+
const page = opts.page ?? 1;
|
|
46
|
+
const limit = opts.limit ?? 20;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const result = await client.store.listOrders({ status: opts.status ?? null, page, limit });
|
|
50
|
+
|
|
51
|
+
if (opts.json) {
|
|
52
|
+
outputJSON({ data: result.data, pagination: { page: result.page, limit: result.limit, total: result.total } });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log(`\n Store Orders ${result.total} total\n`);
|
|
57
|
+
|
|
58
|
+
const cols: ColumnDef<StoreOrderSummary>[] = [
|
|
59
|
+
{ key: "orderNumber", header: "#", width: 12 },
|
|
60
|
+
{ key: "customerName", header: "Customer", width: 20 },
|
|
61
|
+
{ key: "createdAt", header: "Date", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
62
|
+
{ key: "totalAmount", header: "Amount (₹)", align: "right", width: 13, format: (v) => formatAmount(String(v ?? "0")) },
|
|
63
|
+
{ key: "status", header: "Status", width: 10, format: (v) => formatStatus(String(v ?? "")) },
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
outputTable(result.data, cols);
|
|
67
|
+
paginationFooter(result.page, result.limit, result.total);
|
|
68
|
+
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (e instanceof HisaaboApiError) {
|
|
71
|
+
const err = e.hisaaboError;
|
|
72
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
73
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
74
|
+
}
|
|
75
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type TargetRow } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import {
|
|
4
|
+
fatalError, outputJSON, outputTable, EXIT, success, type ColumnDef,
|
|
5
|
+
} from "../../output.js";
|
|
6
|
+
import { formatDate, formatAmount } from "../../format.js";
|
|
7
|
+
|
|
8
|
+
export async function targetListCommand(opts: { json?: boolean }): Promise<void> {
|
|
9
|
+
const cfg = requireAuth();
|
|
10
|
+
const client = new HisaaboClient(cfg);
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const targets = await client.target.list({});
|
|
14
|
+
|
|
15
|
+
if (opts.json) {
|
|
16
|
+
outputJSON(targets);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
console.log("\n Sales Targets\n");
|
|
21
|
+
|
|
22
|
+
const cols: ColumnDef<TargetRow>[] = [
|
|
23
|
+
{ key: "id", header: "ID", width: 10, format: (v) => String(v ?? "").slice(0, 8) + "..." },
|
|
24
|
+
{ key: "type", header: "Type", width: 14 },
|
|
25
|
+
{ key: "period", header: "Period", width: 12 },
|
|
26
|
+
{ key: "targetValue", header: "Target", align: "right", width: 12, format: (v) => formatAmount(String(v ?? "0")) },
|
|
27
|
+
{ key: "startDate", header: "Start", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
28
|
+
{ key: "endDate", header: "End", width: 13, format: (v) => formatDate(v ? String(v) : null) },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
outputTable(targets, cols);
|
|
32
|
+
|
|
33
|
+
} catch (e) {
|
|
34
|
+
if (e instanceof HisaaboApiError) {
|
|
35
|
+
const err = e.hisaaboError;
|
|
36
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
37
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
38
|
+
}
|
|
39
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function targetMyCommand(opts: { json?: boolean }): Promise<void> {
|
|
44
|
+
const cfg = requireAuth();
|
|
45
|
+
const client = new HisaaboClient(cfg);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const targets = await client.target.myTargets();
|
|
49
|
+
|
|
50
|
+
if (opts.json) {
|
|
51
|
+
outputJSON(targets);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log("\n My Targets\n");
|
|
56
|
+
console.log(" " + "═".repeat(60) + "\n");
|
|
57
|
+
|
|
58
|
+
targets.forEach((t) => {
|
|
59
|
+
const pct = Math.round(t.percentComplete);
|
|
60
|
+
const bar = "█".repeat(Math.floor(pct / 5)) + "░".repeat(20 - Math.floor(pct / 5));
|
|
61
|
+
console.log(` ${t.type} (${t.period})`);
|
|
62
|
+
console.log(` Target: ${formatAmount(t.targetValue)} Current: ${formatAmount(t.currentValue)} ${pct}%`);
|
|
63
|
+
console.log(` [${bar}]\n`);
|
|
64
|
+
});
|
|
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 === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
71
|
+
}
|
|
72
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function targetCreateCommand(opts: {
|
|
77
|
+
json?: boolean;
|
|
78
|
+
type?: string;
|
|
79
|
+
period?: string;
|
|
80
|
+
value?: string;
|
|
81
|
+
startDate?: string;
|
|
82
|
+
endDate?: string;
|
|
83
|
+
notes?: string;
|
|
84
|
+
}): Promise<void> {
|
|
85
|
+
const cfg = requireAuth();
|
|
86
|
+
const client = new HisaaboClient(cfg);
|
|
87
|
+
|
|
88
|
+
if (!opts.type) fatalError("--type is required (order_count/order_value/item_quantity)", EXIT.USAGE);
|
|
89
|
+
if (!opts.value) fatalError("--value is required", EXIT.USAGE);
|
|
90
|
+
if (!opts.startDate) fatalError("--start-date is required", EXIT.USAGE);
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const target = await client.target.create({
|
|
94
|
+
type: opts.type as "order_count" | "order_value" | "item_quantity",
|
|
95
|
+
period: (opts.period ?? "monthly") as "daily" | "weekly" | "monthly" | "quarterly" | "custom",
|
|
96
|
+
targetValue: opts.value,
|
|
97
|
+
startDate: opts.startDate,
|
|
98
|
+
endDate: opts.endDate,
|
|
99
|
+
notes: opts.notes,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (opts.json) {
|
|
103
|
+
outputJSON(target);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
success(`Target created: ${target.type} ${target.period} ${formatAmount(target.targetValue)}`);
|
|
108
|
+
|
|
109
|
+
} catch (e) {
|
|
110
|
+
if (e instanceof HisaaboApiError) {
|
|
111
|
+
const err = e.hisaaboError;
|
|
112
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
113
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
114
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
115
|
+
}
|
|
116
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
message: string;
|
|
6
|
+
detail?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function ErrorDisplay({ message, detail }: Props) {
|
|
10
|
+
return (
|
|
11
|
+
<Box flexDirection="column">
|
|
12
|
+
<Text color="red">Error: {message}</Text>
|
|
13
|
+
{detail && <Text color="gray">{detail}</Text>}
|
|
14
|
+
</Box>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
title: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
right?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Header({ title, subtitle, right }: Props) {
|
|
11
|
+
const width = process.stdout.columns ?? 80;
|
|
12
|
+
return (
|
|
13
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
14
|
+
<Box>
|
|
15
|
+
<Text bold color="white">{" " + title}</Text>
|
|
16
|
+
{right && (
|
|
17
|
+
<Box flexGrow={1} justifyContent="flex-end">
|
|
18
|
+
<Text dimColor>{right + " "}</Text>
|
|
19
|
+
</Box>
|
|
20
|
+
)}
|
|
21
|
+
</Box>
|
|
22
|
+
{subtitle && <Text dimColor>{" " + subtitle}</Text>}
|
|
23
|
+
<Text dimColor>{" " + "═".repeat(Math.min(width - 2, 70))}</Text>
|
|
24
|
+
</Box>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "ink";
|
|
3
|
+
import { formatAmount } from "../format.js";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
amount: string | number;
|
|
7
|
+
colored?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function MoneyCell({ amount, colored = false }: Props) {
|
|
11
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
12
|
+
const formatted = formatAmount(amount);
|
|
13
|
+
if (!colored) return <Text>{formatted}</Text>;
|
|
14
|
+
if (num < 0) return <Text color="red">{formatted}</Text>;
|
|
15
|
+
return <Text color="green">{formatted}</Text>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "ink";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
status: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type StatusColor = "green" | "blue" | "yellow" | "red" | "cyan" | "white" | "gray";
|
|
9
|
+
|
|
10
|
+
const STATUS_MAP: Record<string, { label: string; color: StatusColor; dimColor?: boolean }> = {
|
|
11
|
+
paid: { label: "PAID", color: "green" },
|
|
12
|
+
sent: { label: "SENT", color: "blue" },
|
|
13
|
+
draft: { label: "DRAFT", color: "white", dimColor: true },
|
|
14
|
+
partial: { label: "PARTIAL", color: "yellow" },
|
|
15
|
+
overdue: { label: "OVERDUE", color: "red" },
|
|
16
|
+
cancelled: { label: "CANCEL", color: "white", dimColor: true },
|
|
17
|
+
unfulfilled: { label: "UNFUL", color: "blue" },
|
|
18
|
+
pending: { label: "PEND", color: "yellow" },
|
|
19
|
+
confirmed: { label: "CONF", color: "blue" },
|
|
20
|
+
delivered: { label: "DELIV", color: "green" },
|
|
21
|
+
shipped: { label: "SHIPPED", color: "cyan" },
|
|
22
|
+
in_transit: { label: "TRANSIT", color: "cyan" },
|
|
23
|
+
returned: { label: "RETURN", color: "red" },
|
|
24
|
+
preparing: { label: "PREP", color: "yellow" },
|
|
25
|
+
ready: { label: "READY", color: "cyan" },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function StatusBadge({ status }: Props) {
|
|
29
|
+
const cfg = STATUS_MAP[status.toLowerCase()];
|
|
30
|
+
const label = cfg ? `[${cfg.label}]` : `[${status.toUpperCase()}]`;
|
|
31
|
+
const color = cfg?.color ?? "white";
|
|
32
|
+
const dimColor = cfg?.dimColor ?? false;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Text color={color} dimColor={dimColor}>
|
|
36
|
+
{label}
|
|
37
|
+
</Text>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
|
|
4
|
+
interface Column<T extends object> {
|
|
5
|
+
key: keyof T | string;
|
|
6
|
+
header: string;
|
|
7
|
+
width?: number;
|
|
8
|
+
align?: "left" | "right";
|
|
9
|
+
render?: (value: unknown, row: T) => React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface Props<T extends object> {
|
|
13
|
+
rows: T[];
|
|
14
|
+
columns: Column<T>[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getVal(obj: object, key: string): unknown {
|
|
18
|
+
const parts = key.split(".");
|
|
19
|
+
let cur: unknown = obj;
|
|
20
|
+
for (const p of parts) {
|
|
21
|
+
if (cur == null || typeof cur !== "object") return undefined;
|
|
22
|
+
cur = (cur as Record<string, unknown>)[p];
|
|
23
|
+
}
|
|
24
|
+
return cur;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function Table<T extends object>({ rows, columns }: Props<T>) {
|
|
28
|
+
if (rows.length === 0) {
|
|
29
|
+
return <Text dimColor> (no results)</Text>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const sep = "─".repeat(columns.reduce((s, c) => s + (c.width ?? 12) + 2, 1));
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Box flexDirection="column">
|
|
36
|
+
<Text dimColor>{" " + sep}</Text>
|
|
37
|
+
<Box>
|
|
38
|
+
{columns.map((col, i) => (
|
|
39
|
+
<Box key={i} width={col.width ?? 12} marginRight={2}>
|
|
40
|
+
<Text dimColor>{col.header}</Text>
|
|
41
|
+
</Box>
|
|
42
|
+
))}
|
|
43
|
+
</Box>
|
|
44
|
+
<Text dimColor>{" " + sep}</Text>
|
|
45
|
+
{rows.map((row, ri) => (
|
|
46
|
+
<Box key={ri}>
|
|
47
|
+
{columns.map((col, ci) => {
|
|
48
|
+
const val = getVal(row, col.key as string);
|
|
49
|
+
const node = col.render
|
|
50
|
+
? col.render(val, row)
|
|
51
|
+
: <Text>{String(val ?? "")}</Text>;
|
|
52
|
+
return (
|
|
53
|
+
<Box key={ci} width={col.width ?? 12} marginRight={2} justifyContent={col.align === "right" ? "flex-end" : "flex-start"}>
|
|
54
|
+
{node}
|
|
55
|
+
</Box>
|
|
56
|
+
);
|
|
57
|
+
})}
|
|
58
|
+
</Box>
|
|
59
|
+
))}
|
|
60
|
+
<Text dimColor>{" " + sep}</Text>
|
|
61
|
+
</Box>
|
|
62
|
+
);
|
|
63
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Conf from "conf";
|
|
2
|
+
import { fatalError } from "./output.js";
|
|
3
|
+
|
|
4
|
+
interface ConfigSchema {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
token: string;
|
|
7
|
+
tenantId: string;
|
|
8
|
+
businessId: string;
|
|
9
|
+
businessName: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const conf = new Conf<Partial<ConfigSchema>>({
|
|
13
|
+
projectName: "hisaabo",
|
|
14
|
+
projectSuffix: "",
|
|
15
|
+
configName: "config",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export function getConfig(): Partial<ConfigSchema> {
|
|
19
|
+
return conf.store;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function setConfig(values: Partial<ConfigSchema>): void {
|
|
23
|
+
for (const [k, v] of Object.entries(values)) {
|
|
24
|
+
conf.set(k as keyof ConfigSchema, v as string);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function clearConfig(): void {
|
|
29
|
+
conf.clear();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isAuthenticated(): boolean {
|
|
33
|
+
const cfg = getConfig();
|
|
34
|
+
return !!(cfg.token && cfg.apiUrl && cfg.businessId);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function requireAuth(): ConfigSchema {
|
|
38
|
+
const cfg = getConfig();
|
|
39
|
+
if (!cfg.token || !cfg.apiUrl || !cfg.businessId || !cfg.tenantId) {
|
|
40
|
+
fatalError("Not authenticated. Run: hisaabo login", 3);
|
|
41
|
+
}
|
|
42
|
+
return cfg as ConfigSchema;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getConfigPath(): string {
|
|
46
|
+
return conf.path;
|
|
47
|
+
}
|