@hisaabo/cli 0.7.5 → 0.8.4
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/LICENSE +31 -0
- package/README.md +9 -0
- package/dist/bin/{audit-trail-DLSSSM4T.js → audit-trail-IJ6SKACR.js} +2 -2
- package/dist/bin/{categories-63QR6WCV.js → categories-O6TODPAH.js} +2 -2
- package/dist/bin/{check-slug-NXO55WKH.js → check-slug-P7RFU6OP.js} +2 -2
- package/dist/bin/chunk-NO4FIFMS.js +0 -0
- package/dist/bin/{chunk-7MJDOL6B.js → chunk-QUITS2FE.js} +28 -0
- package/dist/bin/{chunk-M42SETRZ.js → chunk-WDN7RIE3.js} +23 -2
- package/dist/bin/chunk-ZPYC767N.js +0 -0
- package/dist/bin/{client-T32CIZA3.js → client-36JX5MR3.js} +1 -1
- package/dist/bin/{collection-efficiency-T6PWNTZO.js → collection-efficiency-DA5RWG3V.js} +2 -2
- package/dist/bin/{config-V4QFCONN.js → config-4LLNT4SH.js} +3 -1
- package/dist/bin/{create-NUKHDWLK.js → create-C5INBPQO.js} +2 -2
- package/dist/bin/{default-account-JWFPHMRF.js → default-account-2GMQ7ZA4.js} +2 -2
- package/dist/bin/{expenses-2UWUZVLI.js → expenses-S2YVA5UT.js} +2 -2
- package/dist/bin/{export-XSX7WQH7.js → export-YOOODNVX.js} +2 -2
- package/dist/bin/export-ZA43MLWO.js +191 -0
- package/dist/bin/{factory-BWOKRIP4.js → factory-6MUCSXTL.js} +2 -2
- package/dist/bin/{get-CHNTG3IM.js → get-GMQRROK2.js} +2 -2
- package/dist/bin/{get-ZSZ6SL3N.js → get-ZV3SC2VY.js} +2 -2
- package/dist/bin/hisaabo.js +100 -57
- package/dist/bin/import-UUHMLCKX.js +267 -0
- package/dist/bin/{invitations-H2SL3XAD.js → invitations-OVORTTMF.js} +2 -2
- package/dist/bin/{invite-EW73UIBE.js → invite-GGHBZY4U.js} +2 -2
- package/dist/bin/{invoice-breakdown-XP4QATCF.js → invoice-breakdown-32XXAZDP.js} +2 -2
- package/dist/bin/{items-DPD6EFTP.js → items-6NOIMH6B.js} +2 -2
- package/dist/bin/{items-toggle-R4OPSE4W.js → items-toggle-L6W6QKQD.js} +2 -2
- package/dist/bin/{list-PKHBE475.js → list-FC5JHKHD.js} +2 -2
- package/dist/bin/{list-KLEHBMQ2.js → list-OXAVDXH7.js} +2 -2
- package/dist/bin/{list-UR7OOJVF.js → list-RAR56EMQ.js} +2 -2
- package/dist/bin/{members-XA3TF4IQ.js → members-Y6XJVHHR.js} +2 -2
- package/dist/bin/{monthly-comparison-OLVS5HEY.js → monthly-comparison-IAUZ6SBJ.js} +2 -2
- package/dist/bin/{order-cancel-MXMJFFRR.js → order-cancel-QRTCNART.js} +2 -2
- package/dist/bin/{order-confirm-IXU45Q4L.js → order-confirm-LGQOMC4O.js} +2 -2
- package/dist/bin/{order-get-RDXMHLJ7.js → order-get-4XAQCRYV.js} +2 -2
- package/dist/bin/{order-update-KGIPBEJX.js → order-update-KZY4H2UR.js} +2 -2
- package/dist/bin/output-NUOL7KJW.js +0 -0
- package/dist/bin/{payment-modes-CZL35SVS.js → payment-modes-DY2ZEMK7.js} +2 -2
- package/dist/bin/{profit-loss-M332OSC5.js → profit-loss-5GJBG3PL.js} +2 -2
- package/dist/bin/{receivables-aging-OXRHGMBF.js → receivables-aging-6A7XJKDT.js} +2 -2
- package/dist/bin/{remove-I5HD2Y4K.js → remove-ZBX34TIQ.js} +2 -2
- package/dist/bin/{revoke-OC6AOMIZ.js → revoke-XDNOA2GJ.js} +2 -2
- package/dist/bin/{revoke-MFLWGCMP.js → revoke-ZTAMW2Q2.js} +2 -2
- package/dist/bin/{revoke-all-FSAPBB3P.js → revoke-all-365NRBOA.js} +2 -2
- package/dist/bin/{revoke-invitation-JXDPXTOW.js → revoke-invitation-PQH7XNYA.js} +2 -2
- package/dist/bin/{sales-trend-KK63WNDL.js → sales-trend-D6PQ7MHY.js} +2 -2
- package/dist/bin/{sequence-IQ4HUJ3W.js → sequence-KZWADVD7.js} +2 -2
- package/dist/bin/{store-6QT6HKG2.js → store-SVRZBUFO.js} +2 -2
- package/dist/bin/{summary-3FTF5B4A.js → summary-H6U7O5GJ.js} +2 -2
- package/dist/bin/{top-customers-HNYGXBQZ.js → top-customers-ATBN6RDI.js} +2 -2
- package/dist/bin/{top-items-JUDG3BVW.js → top-items-XXU6KYTC.js} +2 -2
- package/dist/bin/{top-outstanding-WK26ZNE5.js → top-outstanding-JTQNGGW4.js} +2 -2
- package/dist/bin/{unpaid-invoices-RYFIIIK7.js → unpaid-invoices-BTNQFWCH.js} +2 -2
- package/dist/bin/{untracked-FAFS3KCK.js → untracked-PAMEDJ6Y.js} +2 -2
- package/dist/bin/{update-5YSPXIWO.js → update-6ZMX2OYX.js} +2 -2
- package/dist/bin/{update-I46XLU77.js → update-EGHPFXLK.js} +2 -2
- package/dist/bin/{update-NAW2JWZS.js → update-EK4NJWU4.js} +2 -2
- package/dist/bin/{update-role-5GV42MSN.js → update-role-24PDTNFK.js} +2 -2
- package/dist/bin/{update-settings-KYSQDIEO.js → update-settings-AASI6WZX.js} +2 -2
- package/package.json +35 -9
- package/.turbo/turbo-build.log +0 -13
- package/.turbo/turbo-typecheck.log +0 -4
- package/CLI-UX-ARCHITECTURE.md +0 -1269
- package/src/auth.ts +0 -221
- package/src/bin/hisaabo.ts +0 -74
- package/src/bin/registrars/api-key.ts +0 -44
- package/src/bin/registrars/auth.ts +0 -222
- package/src/bin/registrars/automated-invoice.ts +0 -167
- package/src/bin/registrars/bank-recon.ts +0 -34
- package/src/bin/registrars/bank.ts +0 -124
- package/src/bin/registrars/business.ts +0 -120
- package/src/bin/registrars/dashboard.ts +0 -225
- package/src/bin/registrars/document.ts +0 -184
- package/src/bin/registrars/einvoice.ts +0 -46
- package/src/bin/registrars/ewb.ts +0 -37
- package/src/bin/registrars/expense.ts +0 -87
- package/src/bin/registrars/gst.ts +0 -57
- package/src/bin/registrars/import.ts +0 -49
- package/src/bin/registrars/invoice.ts +0 -117
- package/src/bin/registrars/itc.ts +0 -56
- package/src/bin/registrars/item.ts +0 -112
- package/src/bin/registrars/journal.ts +0 -47
- package/src/bin/registrars/party.ts +0 -81
- package/src/bin/registrars/payment.ts +0 -128
- package/src/bin/registrars/report.ts +0 -186
- package/src/bin/registrars/session.ts +0 -32
- package/src/bin/registrars/shipment.ts +0 -74
- package/src/bin/registrars/store.ts +0 -128
- package/src/bin/registrars/target.ts +0 -46
- package/src/bin/registrars/tenant.ts +0 -73
- package/src/client.ts +0 -2071
- package/src/commands/api-key/create.ts +0 -72
- package/src/commands/api-key/list.ts +0 -71
- package/src/commands/api-key/revoke.ts +0 -46
- package/src/commands/automated-invoice/create.ts +0 -85
- package/src/commands/automated-invoice/delete.ts +0 -42
- package/src/commands/automated-invoice/get.ts +0 -113
- package/src/commands/automated-invoice/history.ts +0 -65
- package/src/commands/automated-invoice/index.ts +0 -11
- package/src/commands/automated-invoice/list.ts +0 -91
- package/src/commands/automated-invoice/pause.ts +0 -29
- package/src/commands/automated-invoice/resume.ts +0 -29
- package/src/commands/automated-invoice/run-now.ts +0 -29
- package/src/commands/automated-invoice/suggestions.ts +0 -68
- package/src/commands/automated-invoice/update.ts +0 -54
- package/src/commands/automated-invoice/usage.ts +0 -68
- package/src/commands/bank/gateway-config.ts +0 -61
- package/src/commands/bank/index.ts +0 -244
- package/src/commands/bank/update-gateway.ts +0 -84
- package/src/commands/bank-recon/index.ts +0 -127
- package/src/commands/business/audit-trail.ts +0 -79
- package/src/commands/business/export.ts +0 -52
- package/src/commands/business/get.ts +0 -55
- package/src/commands/business/sequence.ts +0 -65
- package/src/commands/business/update.ts +0 -64
- package/src/commands/dashboard/collection-efficiency.ts +0 -164
- package/src/commands/dashboard/expenses.ts +0 -76
- package/src/commands/dashboard/invoice-breakdown.ts +0 -89
- package/src/commands/dashboard/monthly-comparison.ts +0 -193
- package/src/commands/dashboard/payment-modes.ts +0 -121
- package/src/commands/dashboard/profit-loss.ts +0 -146
- package/src/commands/dashboard/receivables-aging.ts +0 -169
- package/src/commands/dashboard/sales-trend.ts +0 -68
- package/src/commands/dashboard/summary.ts +0 -105
- package/src/commands/dashboard/top-customers.ts +0 -70
- package/src/commands/dashboard/top-items.ts +0 -74
- package/src/commands/dashboard/top-outstanding.ts +0 -61
- package/src/commands/dashboard.ts +0 -105
- package/src/commands/document/factory.ts +0 -590
- package/src/commands/einvoice/index.ts +0 -109
- package/src/commands/ewb/index.ts +0 -108
- package/src/commands/expense/categories.ts +0 -40
- package/src/commands/expense/create.ts +0 -51
- package/src/commands/expense/delete.ts +0 -45
- package/src/commands/expense/list.ts +0 -65
- package/src/commands/expense/update.ts +0 -58
- package/src/commands/gst/index.ts +0 -194
- package/src/commands/import/index.ts +0 -168
- package/src/commands/invoice/create.ts +0 -262
- package/src/commands/invoice/delete.ts +0 -44
- package/src/commands/invoice/get.ts +0 -113
- package/src/commands/invoice/list.ts +0 -126
- package/src/commands/invoice/pdf.ts +0 -75
- package/src/commands/invoice/status.ts +0 -41
- package/src/commands/itc/index.ts +0 -163
- package/src/commands/item/categories.ts +0 -40
- package/src/commands/item/create.ts +0 -98
- package/src/commands/item/delete.ts +0 -44
- package/src/commands/item/list.ts +0 -81
- package/src/commands/item/low-stock-count.ts +0 -32
- package/src/commands/item/merge.ts +0 -53
- package/src/commands/item/price-history.ts +0 -59
- package/src/commands/item/rename-unit.ts +0 -39
- package/src/commands/item/sales-stats.ts +0 -44
- package/src/commands/item/stock-history.ts +0 -70
- package/src/commands/item/stock.ts +0 -46
- package/src/commands/item/switch-base-unit.ts +0 -42
- package/src/commands/item/update.ts +0 -59
- package/src/commands/item/variants-create.ts +0 -58
- package/src/commands/item/variants-delete.ts +0 -47
- package/src/commands/item/variants-list.ts +0 -63
- package/src/commands/item/variants-update.ts +0 -61
- package/src/commands/journal/index.ts +0 -156
- package/src/commands/party/create.ts +0 -88
- package/src/commands/party/delete.ts +0 -44
- package/src/commands/party/get.ts +0 -42
- package/src/commands/party/ledger-report.ts +0 -81
- package/src/commands/party/ledger.ts +0 -63
- package/src/commands/party/list.ts +0 -69
- package/src/commands/party/merge.ts +0 -50
- package/src/commands/party/stats.ts +0 -40
- package/src/commands/party/top-items.ts +0 -57
- package/src/commands/party/update.ts +0 -65
- package/src/commands/payment/create.ts +0 -131
- package/src/commands/payment/default-account.ts +0 -56
- package/src/commands/payment/delete.ts +0 -46
- package/src/commands/payment/get.ts +0 -59
- package/src/commands/payment/list.ts +0 -66
- package/src/commands/payment/unpaid-invoices.ts +0 -69
- package/src/commands/payment/untracked.ts +0 -70
- package/src/commands/payment/update.ts +0 -54
- package/src/commands/report/index.ts +0 -736
- package/src/commands/session/list.ts +0 -91
- package/src/commands/session/revoke-all.ts +0 -20
- package/src/commands/session/revoke.ts +0 -32
- package/src/commands/shipment/index.ts +0 -170
- package/src/commands/store/check-slug.ts +0 -48
- package/src/commands/store/index.ts +0 -77
- package/src/commands/store/items-toggle.ts +0 -41
- package/src/commands/store/items.ts +0 -61
- package/src/commands/store/order-cancel.ts +0 -48
- package/src/commands/store/order-confirm.ts +0 -45
- package/src/commands/store/order-get.ts +0 -66
- package/src/commands/store/order-update.ts +0 -52
- package/src/commands/store/update-settings.ts +0 -52
- package/src/commands/target/index.ts +0 -118
- package/src/commands/tenant/invitations.ts +0 -62
- package/src/commands/tenant/invite.ts +0 -57
- package/src/commands/tenant/list.ts +0 -46
- package/src/commands/tenant/members.ts +0 -55
- package/src/commands/tenant/remove.ts +0 -47
- package/src/commands/tenant/revoke-invitation.ts +0 -32
- package/src/commands/tenant/update-role.ts +0 -41
- package/src/config.ts +0 -120
- package/src/error-handler.ts +0 -53
- package/src/format.ts +0 -181
- package/src/output.ts +0 -228
- package/src/spinner.ts +0 -39
- package/tsconfig.json +0 -22
- package/tsup.config.ts +0 -18
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT, hasColor } from "../../output.js";
|
|
4
|
-
import { formatDate, formatAmount, formatStatus } from "../../format.js";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
export async function storeOrderGetCommand(
|
|
8
|
-
id: string,
|
|
9
|
-
opts: { json?: boolean },
|
|
10
|
-
): Promise<void> {
|
|
11
|
-
const cfg = requireAuth();
|
|
12
|
-
const client = new HisaaboClient(cfg);
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
const order = await client.store.getOrder(id);
|
|
16
|
-
|
|
17
|
-
if (!order) {
|
|
18
|
-
fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (opts.json) {
|
|
22
|
-
outputJSON(order);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const sep = "─".repeat(40);
|
|
27
|
-
const title = `Order #${order.orderNumber}`;
|
|
28
|
-
|
|
29
|
-
if (hasColor()) {
|
|
30
|
-
process.stdout.write(`\n ${chalk.bold(title)}\n`);
|
|
31
|
-
} else {
|
|
32
|
-
process.stdout.write(`\n ${title}\n`);
|
|
33
|
-
}
|
|
34
|
-
process.stdout.write(` ${sep}\n`);
|
|
35
|
-
process.stdout.write(` Customer: ${order.customerName}\n`);
|
|
36
|
-
process.stdout.write(` Date: ${formatDate(order.createdAt)}\n`);
|
|
37
|
-
process.stdout.write(` Status: ${formatStatus(order.status)}\n`);
|
|
38
|
-
process.stdout.write(` Total: ₹${formatAmount(order.totalAmount)}\n`);
|
|
39
|
-
|
|
40
|
-
if (order.shippingAddress) {
|
|
41
|
-
process.stdout.write(` Address: ${order.shippingAddress}\n`);
|
|
42
|
-
}
|
|
43
|
-
if (order.notes) {
|
|
44
|
-
process.stdout.write(` Notes: ${order.notes}\n`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (order.items && order.items.length > 0) {
|
|
48
|
-
process.stdout.write(`\n Items:\n`);
|
|
49
|
-
for (const item of order.items) {
|
|
50
|
-
process.stdout.write(
|
|
51
|
-
` • ${item.name} qty: ${item.quantity} ₹${formatAmount(item.price)}\n`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
process.stdout.write("\n");
|
|
57
|
-
} catch (e) {
|
|
58
|
-
if (e instanceof HisaaboApiError) {
|
|
59
|
-
const err = e.hisaaboError;
|
|
60
|
-
if (err.code === "not_found") fatalError(`Order not found: ${id}`, EXIT.NOT_FOUND);
|
|
61
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
62
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
63
|
-
}
|
|
64
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
4
|
-
import { formatStatus } from "../../format.js";
|
|
5
|
-
|
|
6
|
-
const VALID_STATUSES = ["preparing", "ready", "delivered"];
|
|
7
|
-
|
|
8
|
-
export async function storeOrderUpdateCommand(
|
|
9
|
-
id: string,
|
|
10
|
-
opts: { json?: boolean; status?: string },
|
|
11
|
-
): Promise<void> {
|
|
12
|
-
const cfg = requireAuth();
|
|
13
|
-
const client = new HisaaboClient(cfg);
|
|
14
|
-
|
|
15
|
-
if (!opts.status) {
|
|
16
|
-
fatalError(
|
|
17
|
-
`--status is required. Valid values: ${VALID_STATUSES.join(", ")}`,
|
|
18
|
-
EXIT.USAGE,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!VALID_STATUSES.includes(opts.status)) {
|
|
23
|
-
fatalError(
|
|
24
|
-
`Invalid status "${opts.status}". Valid values: ${VALID_STATUSES.join(", ")}`,
|
|
25
|
-
EXIT.VALIDATION,
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const result = await client.store.updateOrder({
|
|
31
|
-
orderId: id,
|
|
32
|
-
status: opts.status as "preparing" | "ready" | "delivered",
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (opts.json) {
|
|
36
|
-
outputJSON(result);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
success(`Order ${id} status updated to ${formatStatus(result.status ?? opts.status)}`);
|
|
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
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { outputJSON, EXIT, fatalError, success } from "../../output.js";
|
|
4
|
-
|
|
5
|
-
export async function storeUpdateSettingsCommand(opts: {
|
|
6
|
-
slug?: string;
|
|
7
|
-
tagline?: string;
|
|
8
|
-
enabled?: string;
|
|
9
|
-
json?: boolean;
|
|
10
|
-
}): Promise<void> {
|
|
11
|
-
const cfg = requireAuth();
|
|
12
|
-
const client = new HisaaboClient(cfg);
|
|
13
|
-
|
|
14
|
-
const data: Record<string, unknown> = {};
|
|
15
|
-
if (opts.slug !== undefined) data["storeSlug"] = opts.slug;
|
|
16
|
-
if (opts.tagline !== undefined) data["storeDescription"] = opts.tagline;
|
|
17
|
-
if (opts.enabled !== undefined) {
|
|
18
|
-
if (opts.enabled !== "true" && opts.enabled !== "false") {
|
|
19
|
-
fatalError("--enabled must be 'true' or 'false'", EXIT.USAGE);
|
|
20
|
-
}
|
|
21
|
-
data["storeEnabled"] = opts.enabled === "true";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (Object.keys(data).length === 0) {
|
|
25
|
-
fatalError("At least one option is required (--slug, --tagline, --enabled)", EXIT.USAGE);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const result = await client.store.updateSettings(data);
|
|
30
|
-
|
|
31
|
-
if (opts.json) {
|
|
32
|
-
outputJSON(result);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
success("Store settings updated");
|
|
37
|
-
console.log(` Enabled: ${result.storeEnabled ? "Yes" : "No"}`);
|
|
38
|
-
if (result.storeSlug) console.log(` Slug: ${result.storeSlug}`);
|
|
39
|
-
if (result.storeName) console.log(` Name: ${result.storeName}`);
|
|
40
|
-
if (result.storeDescription) console.log(` About: ${result.storeDescription}`);
|
|
41
|
-
console.log();
|
|
42
|
-
|
|
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 === "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
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, outputTable, EXIT, hasColor } from "../../output.js";
|
|
4
|
-
import type { ColumnDef } from "../../output.js";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
interface ListInvitationsOpts {
|
|
8
|
-
json?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function listInvitationsCommand(opts: ListInvitationsOpts): Promise<void> {
|
|
12
|
-
const cfg = requireAuth();
|
|
13
|
-
const client = new HisaaboClient(cfg);
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const invitations = await client.tenant.pendingInvitations();
|
|
17
|
-
|
|
18
|
-
if (opts.json) {
|
|
19
|
-
outputJSON(invitations);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const items: unknown[] = Array.isArray(invitations) ? invitations : (invitations?.items ?? invitations?.data ?? []);
|
|
24
|
-
|
|
25
|
-
if (items.length === 0) {
|
|
26
|
-
console.log("No pending invitations.");
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const rows = items.map((item: unknown) => {
|
|
31
|
-
const inv = item as Record<string, unknown>;
|
|
32
|
-
return {
|
|
33
|
-
id: String(inv["id"] ?? "").slice(0, 8) + "...",
|
|
34
|
-
email: String(inv["email"] ?? "\u2014"),
|
|
35
|
-
role: String(inv["role"] ?? "\u2014"),
|
|
36
|
-
invitedBy: String(inv["invitedByName"] ?? "\u2014"),
|
|
37
|
-
expires: inv["expiresAt"] ? new Date(String(inv["expiresAt"])).toLocaleDateString() : "\u2014",
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const columns: ColumnDef<typeof rows[number]>[] = [
|
|
42
|
-
{ key: "id", header: "ID", align: "left" },
|
|
43
|
-
{ key: "email", header: "Email", align: "left" },
|
|
44
|
-
{ key: "role", header: "Role", align: "left" },
|
|
45
|
-
{ key: "invitedBy", header: "Invited By", align: "left" },
|
|
46
|
-
{ key: "expires", header: "Expires", align: "left" },
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Pending Invitations\n") + "\n");
|
|
50
|
-
else process.stdout.write("\n Pending Invitations\n\n");
|
|
51
|
-
outputTable(rows, columns);
|
|
52
|
-
process.stdout.write("\n");
|
|
53
|
-
} catch (e) {
|
|
54
|
-
if (e instanceof HisaaboApiError) {
|
|
55
|
-
const err = e.hisaaboError;
|
|
56
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
57
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
58
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
59
|
-
}
|
|
60
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
4
|
-
|
|
5
|
-
const VALID_ROLES = ["admin", "seller_manager", "seller", "accountant"] as const;
|
|
6
|
-
type TenantRole = typeof VALID_ROLES[number];
|
|
7
|
-
|
|
8
|
-
interface InviteResult {
|
|
9
|
-
inviteToken?: string;
|
|
10
|
-
inviteLink?: string;
|
|
11
|
-
message?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface InviteOpts {
|
|
15
|
-
role?: string;
|
|
16
|
-
json?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function tenantInviteCommand(email: string, opts: InviteOpts): Promise<void> {
|
|
20
|
-
const cfg = requireAuth();
|
|
21
|
-
const client = new HisaaboClient(cfg);
|
|
22
|
-
|
|
23
|
-
const role: TenantRole = (opts.role as TenantRole) ?? "seller";
|
|
24
|
-
|
|
25
|
-
if (!VALID_ROLES.includes(role)) {
|
|
26
|
-
fatalError(`Invalid role "${role}". Must be one of: ${VALID_ROLES.join(", ")}`, EXIT.VALIDATION);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const result = await client.tenant.inviteMember({ email, role }) as InviteResult;
|
|
31
|
-
|
|
32
|
-
if (opts.json) {
|
|
33
|
-
outputJSON(result);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
success(`Invited ${email} as ${role}`);
|
|
38
|
-
if (result.inviteLink) {
|
|
39
|
-
console.log(` Invite link: ${result.inviteLink}`);
|
|
40
|
-
} else if (result.inviteToken) {
|
|
41
|
-
console.log(` Invite token: ${result.inviteToken}`);
|
|
42
|
-
}
|
|
43
|
-
if (result.message) {
|
|
44
|
-
console.log(` ${result.message}`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
} catch (e) {
|
|
48
|
-
if (e instanceof HisaaboApiError) {
|
|
49
|
-
const err = e.hisaaboError;
|
|
50
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
51
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
52
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
53
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
54
|
-
}
|
|
55
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, outputTable, EXIT, type ColumnDef } from "../../output.js";
|
|
4
|
-
|
|
5
|
-
interface TenantEntry {
|
|
6
|
-
id: string;
|
|
7
|
-
name: string;
|
|
8
|
-
slug: string;
|
|
9
|
-
role: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface ListOpts {
|
|
13
|
-
json?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function tenantListCommand(opts: ListOpts): Promise<void> {
|
|
17
|
-
const cfg = requireAuth();
|
|
18
|
-
const client = new HisaaboClient(cfg);
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const result = await client.tenant.list() as TenantEntry[];
|
|
22
|
-
|
|
23
|
-
if (opts.json) {
|
|
24
|
-
outputJSON(result);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
console.log(`\n Organizations ${result.length} total\n`);
|
|
29
|
-
|
|
30
|
-
const cols: ColumnDef<TenantEntry>[] = [
|
|
31
|
-
{ key: "name", header: "Name", width: 30 },
|
|
32
|
-
{ key: "slug", header: "Slug", width: 24 },
|
|
33
|
-
{ key: "role", header: "Role", width: 16 },
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
outputTable(result, cols);
|
|
37
|
-
|
|
38
|
-
} catch (e) {
|
|
39
|
-
if (e instanceof HisaaboApiError) {
|
|
40
|
-
const err = e.hisaaboError;
|
|
41
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
42
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
43
|
-
}
|
|
44
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import {
|
|
4
|
-
fatalError, outputJSON, outputTable, outputTSV, outputCSV, EXIT, type ColumnDef,
|
|
5
|
-
} from "../../output.js";
|
|
6
|
-
import { formatDate } from "../../format.js";
|
|
7
|
-
|
|
8
|
-
interface TenantMember {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
email: string;
|
|
12
|
-
role: string;
|
|
13
|
-
joinedAt: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface MembersOpts {
|
|
17
|
-
json?: boolean;
|
|
18
|
-
format?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function tenantMembersCommand(opts: MembersOpts): Promise<void> {
|
|
22
|
-
const cfg = requireAuth();
|
|
23
|
-
const client = new HisaaboClient(cfg);
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const result = await client.tenant.members() as TenantMember[];
|
|
27
|
-
|
|
28
|
-
if (opts.json) {
|
|
29
|
-
outputJSON(result);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
console.log(`\n Team Members ${result.length} total\n`);
|
|
34
|
-
|
|
35
|
-
const cols: ColumnDef<TenantMember>[] = [
|
|
36
|
-
{ key: "name", header: "Name", width: 24 },
|
|
37
|
-
{ key: "email", header: "Email", width: 30 },
|
|
38
|
-
{ key: "role", header: "Role", width: 18 },
|
|
39
|
-
{ key: "joinedAt", header: "Joined", width: 13, format: (v) => formatDate(String(v ?? "")) },
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
if (opts.format === "tsv") outputTSV(result, cols);
|
|
43
|
-
else if (opts.format === "csv") outputCSV(result, cols);
|
|
44
|
-
else outputTable(result, cols);
|
|
45
|
-
|
|
46
|
-
} catch (e) {
|
|
47
|
-
if (e instanceof HisaaboApiError) {
|
|
48
|
-
const err = e.hisaaboError;
|
|
49
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
50
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
51
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
52
|
-
}
|
|
53
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as readline from "readline";
|
|
2
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
3
|
-
import { requireAuth } from "../../config.js";
|
|
4
|
-
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
5
|
-
|
|
6
|
-
interface RemoveOpts {
|
|
7
|
-
yes?: boolean;
|
|
8
|
-
json?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function tenantRemoveCommand(userId: string, opts: RemoveOpts): Promise<void> {
|
|
12
|
-
const cfg = requireAuth();
|
|
13
|
-
const client = new HisaaboClient(cfg);
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
if (!opts.yes && process.stdin.isTTY) {
|
|
17
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
18
|
-
const answer = await new Promise<string>((resolve) => {
|
|
19
|
-
rl.question(` Remove member ${userId} from the organization? (y/N): `, resolve);
|
|
20
|
-
});
|
|
21
|
-
rl.close();
|
|
22
|
-
if (answer.trim().toLowerCase() !== "y") {
|
|
23
|
-
console.log(" Cancelled.");
|
|
24
|
-
process.exit(0);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const result = await client.tenant.removeMember({ userId });
|
|
29
|
-
|
|
30
|
-
if (opts.json) {
|
|
31
|
-
outputJSON(result);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
success(`Removed member: ${userId}`);
|
|
36
|
-
|
|
37
|
-
} catch (e) {
|
|
38
|
-
if (e instanceof HisaaboApiError) {
|
|
39
|
-
const err = e.hisaaboError;
|
|
40
|
-
if (err.code === "not_found") fatalError(`Member not found: ${userId}`, EXIT.NOT_FOUND);
|
|
41
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
42
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
43
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
44
|
-
}
|
|
45
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, success, outputJSON, EXIT } from "../../output.js";
|
|
4
|
-
|
|
5
|
-
interface RevokeInvitationOpts {
|
|
6
|
-
json?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function revokeInvitationCommand(invitationId: string, opts: RevokeInvitationOpts): Promise<void> {
|
|
10
|
-
const cfg = requireAuth();
|
|
11
|
-
const client = new HisaaboClient(cfg);
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const result = await client.tenant.revokeInvitation({ invitationId });
|
|
15
|
-
|
|
16
|
-
if (opts.json) {
|
|
17
|
-
outputJSON(result);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
success("Invitation revoked successfully.");
|
|
22
|
-
} catch (e) {
|
|
23
|
-
if (e instanceof HisaaboApiError) {
|
|
24
|
-
const err = e.hisaaboError;
|
|
25
|
-
if (err.code === "not_found") fatalError(`Invitation not found: ${invitationId}`, EXIT.NOT_FOUND);
|
|
26
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
27
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
28
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
29
|
-
}
|
|
30
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
-
import { requireAuth } from "../../config.js";
|
|
3
|
-
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
4
|
-
|
|
5
|
-
const VALID_ROLES = ["admin", "seller_manager", "seller", "accountant"] as const;
|
|
6
|
-
type TenantRole = typeof VALID_ROLES[number];
|
|
7
|
-
|
|
8
|
-
interface UpdateRoleOpts {
|
|
9
|
-
json?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function tenantUpdateRoleCommand(userId: string, role: string, opts: UpdateRoleOpts): Promise<void> {
|
|
13
|
-
const cfg = requireAuth();
|
|
14
|
-
const client = new HisaaboClient(cfg);
|
|
15
|
-
|
|
16
|
-
if (!VALID_ROLES.includes(role as TenantRole)) {
|
|
17
|
-
fatalError(`Invalid role "${role}". Must be one of: ${VALID_ROLES.join(", ")}`, EXIT.VALIDATION);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const result = await client.tenant.updateMemberRole({ userId, role });
|
|
22
|
-
|
|
23
|
-
if (opts.json) {
|
|
24
|
-
outputJSON(result);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
success(`Updated role for member ${userId} to ${role}`);
|
|
29
|
-
|
|
30
|
-
} catch (e) {
|
|
31
|
-
if (e instanceof HisaaboApiError) {
|
|
32
|
-
const err = e.hisaaboError;
|
|
33
|
-
if (err.code === "not_found") fatalError(`Member not found: ${userId}`, EXIT.NOT_FOUND);
|
|
34
|
-
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
35
|
-
if (err.code === "forbidden") fatalError(err.message, EXIT.FORBIDDEN);
|
|
36
|
-
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
37
|
-
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
38
|
-
}
|
|
39
|
-
fatalError(String(e instanceof Error ? e.message : e));
|
|
40
|
-
}
|
|
41
|
-
}
|