@hisaabo/cli 0.3.2 → 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 +1 -1
- package/dist/bin/{audit-trail-2YGXGUXW.js → audit-trail-5LOCJ7XZ.js} +4 -4
- package/dist/bin/{categories-P5VFWD5F.js → categories-64WWZTND.js} +3 -3
- package/dist/bin/{check-slug-4TMOTWUJ.js → check-slug-FLHHUDYS.js} +3 -3
- package/dist/bin/{chunk-FTOBDKMO.js → chunk-4MEL44QX.js} +54 -10
- package/dist/bin/chunk-FIMJZAS4.js +84 -0
- package/dist/bin/{chunk-EYNDY7RB.js → chunk-NO4FIFMS.js} +2 -1
- package/dist/bin/{chunk-FFBG6RU4.js → chunk-T63VQXNM.js} +1 -1
- package/dist/bin/{client-QNJ2H5CW.js → client-5NZ23GML.js} +1 -1
- package/dist/bin/{collection-efficiency-WMKEGS6U.js → collection-efficiency-U56XNVEE.js} +4 -4
- package/dist/bin/{config-UKVQYPPR.js → config-335MN4I7.js} +2 -2
- package/dist/bin/{create-Y22FAVOW.js → create-RPDEORDD.js} +3 -3
- package/dist/bin/{default-account-SA56M66A.js → default-account-AE6EXZZR.js} +3 -3
- package/dist/bin/{expenses-VZAOLYUW.js → expenses-5N2QSG54.js} +4 -4
- package/dist/bin/{export-QZ6WT6PJ.js → export-QICOQK34.js} +3 -3
- package/dist/bin/{factory-2DCU3B5T.js → factory-KOCW2AQM.js} +4 -4
- package/dist/bin/{get-EXL44I2X.js → get-A43QCI2S.js} +3 -3
- package/dist/bin/{get-6UYP6UVD.js → get-GWH6S5SJ.js} +4 -4
- package/dist/bin/hisaabo.js +280 -67
- package/dist/bin/invitations-P3EEN5WI.js +66 -0
- package/dist/bin/{invite-O26SAL72.js → invite-T3CKX53E.js} +3 -3
- package/dist/bin/{invoice-breakdown-XEATXVMR.js → invoice-breakdown-FN5BEFJD.js} +4 -4
- package/dist/bin/{items-3U5USBVG.js → items-2OOCQKVF.js} +4 -4
- package/dist/bin/{items-toggle-YEKMI2CM.js → items-toggle-SKZWCGJH.js} +3 -3
- package/dist/bin/{list-VBAHY72W.js → list-A2RKI3ZG.js} +4 -4
- package/dist/bin/list-NRMBMKMI.js +90 -0
- package/dist/bin/{list-FX2C3NCL.js → list-T74SN6IR.js} +3 -3
- package/dist/bin/{members-5FPRUAB6.js → members-W2GW3ODT.js} +4 -4
- package/dist/bin/{monthly-comparison-JEJ3TTY2.js → monthly-comparison-T34ZFOHL.js} +4 -4
- package/dist/bin/{order-cancel-XI2LKYXV.js → order-cancel-TI27JYYD.js} +3 -3
- package/dist/bin/{order-confirm-HUFCU6MO.js → order-confirm-VMRAMNTD.js} +3 -3
- package/dist/bin/{order-get-NSDMPUZR.js → order-get-C2RBUR4O.js} +4 -4
- package/dist/bin/{order-update-C7QYSD5R.js → order-update-RE3HATNF.js} +4 -4
- package/dist/bin/{output-QFLEKG5W.js → output-NUOL7KJW.js} +1 -1
- package/dist/bin/{payment-modes-WI3AWSES.js → payment-modes-WOOT22I7.js} +4 -4
- package/dist/bin/{profit-loss-5RIEOBKP.js → profit-loss-T4RESJ32.js} +4 -4
- package/dist/bin/{receivables-aging-L6DIQCNE.js → receivables-aging-6XMENEWS.js} +4 -4
- package/dist/bin/{remove-M2B4TZ37.js → remove-6QZI4JCY.js} +3 -3
- package/dist/bin/revoke-AVEMPAC7.js +40 -0
- package/dist/bin/{revoke-H3V2GNCD.js → revoke-YUCFZFNR.js} +3 -3
- package/dist/bin/revoke-all-LFW5WBHO.js +33 -0
- package/dist/bin/revoke-invitation-DTGQRJR4.js +40 -0
- package/dist/bin/{sales-trend-TICB3KGF.js → sales-trend-ZYBRUDUU.js} +4 -4
- package/dist/bin/{sequence-XUD6FAKY.js → sequence-FPOJTI2P.js} +3 -3
- package/dist/bin/{store-UQ2DDQ5I.js → store-IOB4Y67C.js} +4 -4
- package/dist/bin/{summary-BPNFC7I2.js → summary-5KYBA4ZO.js} +4 -4
- package/dist/bin/{top-customers-WGGJWKCN.js → top-customers-WSQ2UEJL.js} +4 -4
- package/dist/bin/{top-items-C7ZDDJMR.js → top-items-RWQPDGLN.js} +4 -4
- package/dist/bin/{top-outstanding-MOGWJIQS.js → top-outstanding-QAMO2E7Y.js} +4 -4
- package/dist/bin/{unpaid-invoices-ZUPNMQJP.js → unpaid-invoices-WB3TK5B4.js} +4 -4
- package/dist/bin/{untracked-BCJEVDW4.js → untracked-H733MYJL.js} +4 -4
- package/dist/bin/{update-IG565YIN.js → update-H6LPO2Z4.js} +3 -3
- package/dist/bin/{update-HIU4PANX.js → update-JU2X3XU5.js} +4 -4
- package/dist/bin/{update-PVLAX7T3.js → update-TLBUIC5J.js} +4 -4
- package/dist/bin/{update-role-Q4ZYJRYT.js → update-role-QST7BVFX.js} +3 -3
- package/dist/bin/{update-settings-XPC6L5WM.js → update-settings-Q2EGRLKZ.js} +3 -3
- package/package.json +2 -6
- package/src/auth.ts +12 -3
- package/src/bin/hisaabo.ts +6 -1
- package/src/bin/registrars/auth.ts +79 -10
- package/src/bin/registrars/bank.ts +34 -0
- package/src/bin/registrars/session.ts +32 -0
- package/src/bin/registrars/tenant.ts +18 -0
- package/src/client.ts +94 -11
- package/src/commands/bank/gateway-config.ts +61 -0
- package/src/commands/bank/update-gateway.ts +84 -0
- 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/tenant/invitations.ts +62 -0
- package/src/commands/tenant/revoke-invitation.ts +32 -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/dist/bin/chunk-2P35S2C3.js +0 -46
- 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,32 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
|
|
3
|
+
export function registerSessionCommands(program: Command): void {
|
|
4
|
+
const session = program.command("session").description("Manage active sessions");
|
|
5
|
+
|
|
6
|
+
session
|
|
7
|
+
.command("list")
|
|
8
|
+
.description("List active sessions")
|
|
9
|
+
.option("--expired", "Show expired sessions instead")
|
|
10
|
+
.option("--json", "JSON output")
|
|
11
|
+
.action(async (opts) => {
|
|
12
|
+
const { listSessionsCommand } = await import("../../commands/session/list.js");
|
|
13
|
+
await listSessionsCommand(opts);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
session
|
|
17
|
+
.command("revoke <sessionId>")
|
|
18
|
+
.description("Revoke a specific session")
|
|
19
|
+
.option("--json", "JSON output")
|
|
20
|
+
.action(async (sessionId, opts) => {
|
|
21
|
+
const { revokeSessionCommand } = await import("../../commands/session/revoke.js");
|
|
22
|
+
await revokeSessionCommand(sessionId, opts);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
session
|
|
26
|
+
.command("revoke-all")
|
|
27
|
+
.description("Sign out from all devices")
|
|
28
|
+
.action(async () => {
|
|
29
|
+
const { revokeAllSessionsCommand } = await import("../../commands/session/revoke-all.js");
|
|
30
|
+
await revokeAllSessionsCommand();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -52,4 +52,22 @@ export function registerTenantCommands(program: Command): void {
|
|
|
52
52
|
const { tenantUpdateRoleCommand } = await import("../../commands/tenant/update-role.js");
|
|
53
53
|
await tenantUpdateRoleCommand(userId, role, { json: opts.json });
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
tenant
|
|
57
|
+
.command("invitations")
|
|
58
|
+
.description("List pending invitations")
|
|
59
|
+
.option("--json", "JSON output")
|
|
60
|
+
.action(async (opts) => {
|
|
61
|
+
const { listInvitationsCommand } = await import("../../commands/tenant/invitations.js");
|
|
62
|
+
await listInvitationsCommand(opts);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
tenant
|
|
66
|
+
.command("revoke-invitation <invitationId>")
|
|
67
|
+
.description("Revoke a pending invitation")
|
|
68
|
+
.option("--json", "JSON output")
|
|
69
|
+
.action(async (invitationId, opts) => {
|
|
70
|
+
const { revokeInvitationCommand } = await import("../../commands/tenant/revoke-invitation.js");
|
|
71
|
+
await revokeInvitationCommand(invitationId, opts);
|
|
72
|
+
});
|
|
55
73
|
}
|
package/src/client.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type HisaaboError =
|
|
|
20
20
|
| { code: "not_found"; resource: string }
|
|
21
21
|
| { code: "validation_failed"; fields: Record<string, string[]> }
|
|
22
22
|
| { code: "network_error"; message: string }
|
|
23
|
+
| { code: "rate_limited"; retryAfterMs: number; message: string }
|
|
23
24
|
| { code: "api_error"; message: string };
|
|
24
25
|
|
|
25
26
|
export class HisaaboApiError extends Error {
|
|
@@ -44,6 +45,8 @@ export function formatHisaaboError(err: HisaaboError): string {
|
|
|
44
45
|
.map(([field, msgs]) => ` ${field}: ${msgs.join(", ")}`)
|
|
45
46
|
.join("\n")
|
|
46
47
|
);
|
|
48
|
+
case "rate_limited":
|
|
49
|
+
return `Rate limited: ${err.message}`;
|
|
47
50
|
case "network_error":
|
|
48
51
|
return `Network error: ${err.message}`;
|
|
49
52
|
case "api_error":
|
|
@@ -94,6 +97,23 @@ export class HisaaboClient {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
private async unwrap<T>(res: Response): Promise<T> {
|
|
100
|
+
// Detect rate limiting before tRPC error parsing
|
|
101
|
+
if (res.status === 429) {
|
|
102
|
+
const retryAfter = res.headers.get("retry-after");
|
|
103
|
+
let retryMs = 60_000;
|
|
104
|
+
if (retryAfter) {
|
|
105
|
+
const parsed = Number(retryAfter);
|
|
106
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
107
|
+
retryMs = Math.min(parsed * 1000, 120_000); // cap at 2 minutes
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw new HisaaboApiError({
|
|
111
|
+
code: "rate_limited",
|
|
112
|
+
retryAfterMs: retryMs,
|
|
113
|
+
message: `Rate limited. Try again in ${Math.ceil(retryMs / 1000)}s.`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
97
117
|
const body = await res.json() as unknown;
|
|
98
118
|
|
|
99
119
|
if (typeof body !== "object" || body === null) {
|
|
@@ -116,17 +136,27 @@ export class HisaaboClient {
|
|
|
116
136
|
}
|
|
117
137
|
|
|
118
138
|
async query<T>(path: string, input?: unknown): Promise<T> {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
const maxRetries = 2;
|
|
140
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
141
|
+
try {
|
|
142
|
+
const url = new URL(`${this.config.apiUrl}/api/trpc/${path}`);
|
|
143
|
+
if (input !== undefined) {
|
|
144
|
+
url.searchParams.set("input", JSON.stringify(superjson.serialize(input)));
|
|
145
|
+
}
|
|
146
|
+
const res = await fetch(url.toString(), { headers: this.buildHeaders() });
|
|
147
|
+
return await this.unwrap<T>(res);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
// Auto-retry on rate limit for idempotent reads
|
|
150
|
+
if (e instanceof HisaaboApiError && e.hisaaboError.code === "rate_limited" && attempt < maxRetries) {
|
|
151
|
+
const waitMs = Math.min((e.hisaaboError as { retryAfterMs: number }).retryAfterMs, 10_000);
|
|
152
|
+
await new Promise((r) => setTimeout(r, waitMs));
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (e instanceof HisaaboApiError) throw e;
|
|
156
|
+
throw new HisaaboApiError({ code: "network_error", message: String(e instanceof Error ? e.message : e) });
|
|
157
|
+
}
|
|
129
158
|
}
|
|
159
|
+
throw new HisaaboApiError({ code: "api_error", message: "Max retries exceeded" });
|
|
130
160
|
}
|
|
131
161
|
|
|
132
162
|
async mutate<T>(path: string, input: unknown): Promise<T> {
|
|
@@ -169,6 +199,12 @@ export class HisaaboClient {
|
|
|
169
199
|
updateName(input: { name: string }) {
|
|
170
200
|
return c.mutate<any>("auth.updateName", input);
|
|
171
201
|
},
|
|
202
|
+
listSessions(input: { expired: boolean }) {
|
|
203
|
+
return c.query<any>("auth.listSessions", input);
|
|
204
|
+
},
|
|
205
|
+
revokeSession(input: { sessionId: string }) {
|
|
206
|
+
return c.mutate<any>("auth.revokeSession", input);
|
|
207
|
+
},
|
|
172
208
|
};
|
|
173
209
|
}
|
|
174
210
|
|
|
@@ -504,6 +540,12 @@ export class HisaaboClient {
|
|
|
504
540
|
summary() {
|
|
505
541
|
return c.query<BankSummary>("bankAccount.summary");
|
|
506
542
|
},
|
|
543
|
+
getGatewayConfig(bankAccountId: string) {
|
|
544
|
+
return c.query<GatewayConfig | null>("bankAccount.getGatewayConfig", { bankAccountId });
|
|
545
|
+
},
|
|
546
|
+
upsertGatewayConfig(input: UpsertGatewayConfigInput) {
|
|
547
|
+
return c.mutate<GatewayConfig>("bankAccount.upsertGatewayConfig", input);
|
|
548
|
+
},
|
|
507
549
|
};
|
|
508
550
|
}
|
|
509
551
|
|
|
@@ -635,6 +677,12 @@ export class HisaaboClient {
|
|
|
635
677
|
updateMemberRole(input: any) {
|
|
636
678
|
return c.mutate<any>("tenant.updateMemberRole", input);
|
|
637
679
|
},
|
|
680
|
+
pendingInvitations() {
|
|
681
|
+
return c.query<any>("tenant.pendingInvitations");
|
|
682
|
+
},
|
|
683
|
+
revokeInvitation(input: { invitationId: string }) {
|
|
684
|
+
return c.mutate<any>("tenant.revokeInvitation", input);
|
|
685
|
+
},
|
|
638
686
|
};
|
|
639
687
|
}
|
|
640
688
|
|
|
@@ -1358,7 +1406,42 @@ export interface ShipmentUpdateInput {
|
|
|
1358
1406
|
notes?: string;
|
|
1359
1407
|
}
|
|
1360
1408
|
|
|
1361
|
-
export type BankAccountType = "savings" | "current" | "cash" | "credit" | "other";
|
|
1409
|
+
export type BankAccountType = "savings" | "current" | "cash" | "credit" | "other" | "payment_gateway";
|
|
1410
|
+
|
|
1411
|
+
export interface GatewayChargeRate {
|
|
1412
|
+
type: "percentage" | "flat";
|
|
1413
|
+
value: string;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
export interface GatewayChargeConfig {
|
|
1417
|
+
credit_card?: GatewayChargeRate;
|
|
1418
|
+
debit_card?: GatewayChargeRate;
|
|
1419
|
+
upi?: GatewayChargeRate;
|
|
1420
|
+
net_banking?: GatewayChargeRate;
|
|
1421
|
+
wallet?: GatewayChargeRate;
|
|
1422
|
+
default?: GatewayChargeRate;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
export interface GatewayConfig {
|
|
1426
|
+
id: string;
|
|
1427
|
+
businessId: string;
|
|
1428
|
+
bankAccountId: string;
|
|
1429
|
+
settlementAccountId: string;
|
|
1430
|
+
chargeConfig: GatewayChargeConfig;
|
|
1431
|
+
expenseCategory: string;
|
|
1432
|
+
autoSettle: boolean;
|
|
1433
|
+
isActive: boolean;
|
|
1434
|
+
createdAt: string;
|
|
1435
|
+
updatedAt: string;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
export interface UpsertGatewayConfigInput {
|
|
1439
|
+
bankAccountId: string;
|
|
1440
|
+
settlementAccountId: string;
|
|
1441
|
+
chargeConfig: GatewayChargeConfig;
|
|
1442
|
+
expenseCategory?: string;
|
|
1443
|
+
autoSettle?: boolean;
|
|
1444
|
+
}
|
|
1362
1445
|
|
|
1363
1446
|
export interface BankAccountSummary {
|
|
1364
1447
|
id: string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type GatewayChargeRate } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, outputTable, EXIT, type ColumnDef } from "../../output.js";
|
|
4
|
+
|
|
5
|
+
function formatChargeRate(rate: GatewayChargeRate | undefined): string {
|
|
6
|
+
if (!rate) return "-";
|
|
7
|
+
return rate.type === "percentage" ? `${rate.value}%` : `Flat ${rate.value}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function bankGatewayConfigCommand(
|
|
11
|
+
accountId: string,
|
|
12
|
+
opts: { json?: boolean },
|
|
13
|
+
): Promise<void> {
|
|
14
|
+
const cfg = requireAuth();
|
|
15
|
+
const client = new HisaaboClient(cfg);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const config = await client.bankAccount.getGatewayConfig(accountId);
|
|
19
|
+
|
|
20
|
+
if (!config) {
|
|
21
|
+
fatalError(`No gateway configuration found for account: ${accountId}`, EXIT.NOT_FOUND);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (opts.json) {
|
|
25
|
+
outputJSON(config);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log(`\n Gateway Configuration`);
|
|
30
|
+
console.log(" " + "\u2500".repeat(45));
|
|
31
|
+
console.log(` Account: ${accountId}`);
|
|
32
|
+
console.log(` Settlement Account: ${config.settlementAccountId}`);
|
|
33
|
+
console.log(` Expense Category: ${config.expenseCategory}`);
|
|
34
|
+
console.log(` Auto Settle: ${config.autoSettle ? "Yes" : "No"}`);
|
|
35
|
+
console.log(` Active: ${config.isActive ? "Yes" : "No"}`);
|
|
36
|
+
console.log();
|
|
37
|
+
|
|
38
|
+
const modes = ["credit_card", "debit_card", "upi", "net_banking", "wallet", "default"] as const;
|
|
39
|
+
const rows = modes.map((mode) => ({
|
|
40
|
+
mode,
|
|
41
|
+
rate: formatChargeRate(config.chargeConfig[mode]),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
const cols: ColumnDef<{ mode: string; rate: string }>[] = [
|
|
45
|
+
{ key: "mode", header: "Payment Mode", width: 18 },
|
|
46
|
+
{ key: "rate", header: "Charge Rate", width: 16 },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
console.log(" Charge Rates:\n");
|
|
50
|
+
outputTable(rows, cols);
|
|
51
|
+
console.log();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (e instanceof HisaaboApiError) {
|
|
54
|
+
const err = e.hisaaboError;
|
|
55
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
56
|
+
if (err.code === "not_found") fatalError(`Bank account not found: ${accountId}`, EXIT.NOT_FOUND);
|
|
57
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
58
|
+
}
|
|
59
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError, type GatewayChargeConfig } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, outputJSON, EXIT, success } from "../../output.js";
|
|
4
|
+
|
|
5
|
+
export interface UpdateGatewayOpts {
|
|
6
|
+
json?: boolean;
|
|
7
|
+
chargeCreditCard?: string;
|
|
8
|
+
chargeDebitCard?: string;
|
|
9
|
+
chargeUpi?: string;
|
|
10
|
+
chargeNetBanking?: string;
|
|
11
|
+
chargeWallet?: string;
|
|
12
|
+
chargeDefault?: string;
|
|
13
|
+
settlementAccount?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseChargeRate(value: string): { type: "percentage" | "flat"; value: string } {
|
|
17
|
+
// If value starts with "flat:" treat as flat amount, otherwise percentage
|
|
18
|
+
if (value.toLowerCase().startsWith("flat:")) {
|
|
19
|
+
return { type: "flat", value: value.slice(5) };
|
|
20
|
+
}
|
|
21
|
+
return { type: "percentage", value };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function bankUpdateGatewayCommand(
|
|
25
|
+
accountId: string,
|
|
26
|
+
opts: UpdateGatewayOpts,
|
|
27
|
+
): Promise<void> {
|
|
28
|
+
const cfg = requireAuth();
|
|
29
|
+
const client = new HisaaboClient(cfg);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Fetch existing config to merge with updates
|
|
33
|
+
const existing = await client.bankAccount.getGatewayConfig(accountId);
|
|
34
|
+
|
|
35
|
+
const chargeConfig: GatewayChargeConfig = existing?.chargeConfig ?? {};
|
|
36
|
+
|
|
37
|
+
if (opts.chargeCreditCard !== undefined) {
|
|
38
|
+
chargeConfig.credit_card = parseChargeRate(opts.chargeCreditCard);
|
|
39
|
+
}
|
|
40
|
+
if (opts.chargeDebitCard !== undefined) {
|
|
41
|
+
chargeConfig.debit_card = parseChargeRate(opts.chargeDebitCard);
|
|
42
|
+
}
|
|
43
|
+
if (opts.chargeUpi !== undefined) {
|
|
44
|
+
chargeConfig.upi = parseChargeRate(opts.chargeUpi);
|
|
45
|
+
}
|
|
46
|
+
if (opts.chargeNetBanking !== undefined) {
|
|
47
|
+
chargeConfig.net_banking = parseChargeRate(opts.chargeNetBanking);
|
|
48
|
+
}
|
|
49
|
+
if (opts.chargeWallet !== undefined) {
|
|
50
|
+
chargeConfig.wallet = parseChargeRate(opts.chargeWallet);
|
|
51
|
+
}
|
|
52
|
+
if (opts.chargeDefault !== undefined) {
|
|
53
|
+
chargeConfig.default = parseChargeRate(opts.chargeDefault);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const settlementAccountId = opts.settlementAccount ?? existing?.settlementAccountId;
|
|
57
|
+
if (!settlementAccountId) {
|
|
58
|
+
fatalError("--settlement-account is required when creating a new gateway config", EXIT.USAGE);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const result = await client.bankAccount.upsertGatewayConfig({
|
|
62
|
+
bankAccountId: accountId,
|
|
63
|
+
settlementAccountId,
|
|
64
|
+
chargeConfig,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (opts.json) {
|
|
68
|
+
outputJSON(result);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
success(`Gateway configuration updated for account: ${accountId}`);
|
|
73
|
+
console.log(` Settlement Account: ${result.settlementAccountId}\n`);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (e instanceof HisaaboApiError) {
|
|
76
|
+
const err = e.hisaaboError;
|
|
77
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
78
|
+
if (err.code === "validation_failed") fatalError(e.message, EXIT.VALIDATION);
|
|
79
|
+
if (err.code === "not_found") fatalError(`Bank account not found: ${accountId}`, EXIT.NOT_FOUND);
|
|
80
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
81
|
+
}
|
|
82
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 ListSessionsOpts {
|
|
8
|
+
expired?: boolean;
|
|
9
|
+
json?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function listSessionsCommand(opts: ListSessionsOpts): Promise<void> {
|
|
13
|
+
const cfg = requireAuth();
|
|
14
|
+
const client = new HisaaboClient(cfg);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const sessions = await client.auth.listSessions({ expired: opts.expired ?? false });
|
|
18
|
+
|
|
19
|
+
if (opts.json) {
|
|
20
|
+
outputJSON(sessions);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const items: unknown[] = Array.isArray(sessions) ? sessions : (sessions?.items ?? sessions?.data ?? []);
|
|
25
|
+
|
|
26
|
+
if (items.length === 0) {
|
|
27
|
+
console.log(opts.expired ? "No expired sessions." : "No active sessions.");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const rows = items.map((item: unknown) => {
|
|
32
|
+
const s = item as Record<string, unknown>;
|
|
33
|
+
return {
|
|
34
|
+
id: String(s["id"] ?? "").slice(0, 12) + "...",
|
|
35
|
+
device: s["userAgent"] ? parseUA(String(s["userAgent"])) : "Unknown",
|
|
36
|
+
ip: String(s["ipAddress"] ?? "\u2014"),
|
|
37
|
+
lastUsed: s["lastUsedAt"] ? timeAgo(String(s["lastUsedAt"])) : "\u2014",
|
|
38
|
+
created: s["createdAt"] ? new Date(String(s["createdAt"])).toLocaleDateString() : "\u2014",
|
|
39
|
+
current: s["isCurrent"] ? "\u2713" : "",
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const columns: ColumnDef<typeof rows[number]>[] = [
|
|
44
|
+
{ key: "id", header: "ID", align: "left" },
|
|
45
|
+
{ key: "device", header: "Device", align: "left" },
|
|
46
|
+
{ key: "ip", header: "IP", align: "left" },
|
|
47
|
+
{ key: "lastUsed", header: "Last Used", align: "left" },
|
|
48
|
+
{ key: "created", header: "Created", align: "left" },
|
|
49
|
+
{ key: "current", header: "Current", align: "left" },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
if (hasColor()) process.stdout.write("\n" + chalk.bold(" Sessions\n") + "\n");
|
|
53
|
+
else process.stdout.write("\n Sessions\n\n");
|
|
54
|
+
outputTable(rows, columns);
|
|
55
|
+
process.stdout.write("\n");
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e instanceof HisaaboApiError) {
|
|
58
|
+
const err = e.hisaaboError;
|
|
59
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
60
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
61
|
+
}
|
|
62
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseUA(ua: string): string {
|
|
67
|
+
let browser = "Unknown";
|
|
68
|
+
if (ua.includes("Edg/")) browser = "Edge";
|
|
69
|
+
else if (ua.includes("Chrome/")) browser = "Chrome";
|
|
70
|
+
else if (ua.includes("Firefox/")) browser = "Firefox";
|
|
71
|
+
else if (ua.includes("Safari/")) browser = "Safari";
|
|
72
|
+
|
|
73
|
+
let os = "";
|
|
74
|
+
if (ua.includes("Windows")) os = "Windows";
|
|
75
|
+
else if (ua.includes("Mac OS")) os = "macOS";
|
|
76
|
+
else if (ua.includes("Linux")) os = "Linux";
|
|
77
|
+
else if (ua.includes("Android")) os = "Android";
|
|
78
|
+
else if (ua.includes("iPhone") || ua.includes("iPad")) os = "iOS";
|
|
79
|
+
|
|
80
|
+
return os ? `${browser} / ${os}` : browser;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function timeAgo(date: string): string {
|
|
84
|
+
const diff = Date.now() - new Date(date).getTime();
|
|
85
|
+
const mins = Math.floor(diff / 60000);
|
|
86
|
+
if (mins < 1) return "now";
|
|
87
|
+
if (mins < 60) return `${mins}m ago`;
|
|
88
|
+
const hrs = Math.floor(mins / 60);
|
|
89
|
+
if (hrs < 24) return `${hrs}h ago`;
|
|
90
|
+
return `${Math.floor(hrs / 24)}d ago`;
|
|
91
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HisaaboClient, HisaaboApiError } from "../../client.js";
|
|
2
|
+
import { requireAuth } from "../../config.js";
|
|
3
|
+
import { fatalError, success, EXIT } from "../../output.js";
|
|
4
|
+
|
|
5
|
+
export async function revokeAllSessionsCommand(): Promise<void> {
|
|
6
|
+
const cfg = requireAuth();
|
|
7
|
+
const client = new HisaaboClient(cfg);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
await client.auth.logoutAll();
|
|
11
|
+
success("Signed out from all devices.");
|
|
12
|
+
} catch (e) {
|
|
13
|
+
if (e instanceof HisaaboApiError) {
|
|
14
|
+
const err = e.hisaaboError;
|
|
15
|
+
if (err.code === "unauthorized") fatalError("Session expired. Run: hisaabo login", EXIT.AUTH);
|
|
16
|
+
if (err.code === "network_error") fatalError(err.message, EXIT.NETWORK);
|
|
17
|
+
}
|
|
18
|
+
fatalError(String(e instanceof Error ? e.message : e));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 RevokeSessionOpts {
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function revokeSessionCommand(sessionId: string, opts: RevokeSessionOpts): Promise<void> {
|
|
10
|
+
const cfg = requireAuth();
|
|
11
|
+
const client = new HisaaboClient(cfg);
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const result = await client.auth.revokeSession({ sessionId });
|
|
15
|
+
|
|
16
|
+
if (opts.json) {
|
|
17
|
+
outputJSON(result);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
success("Session revoked successfully.");
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof HisaaboApiError) {
|
|
24
|
+
const err = e.hisaaboError;
|
|
25
|
+
if (err.code === "not_found") fatalError(`Session not found: ${sessionId}`, 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
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|