@hisaabo/cli 0.6.1 → 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-4AMEFQGB.js → audit-trail-IJ6SKACR.js} +3 -3
- package/dist/bin/{categories-CLCBRNWC.js → categories-O6TODPAH.js} +2 -2
- package/dist/bin/{check-slug-OKW7KDYG.js → check-slug-P7RFU6OP.js} +2 -2
- package/dist/bin/chunk-NO4FIFMS.js +0 -0
- package/dist/bin/{chunk-FIMJZAS4.js → chunk-QUITS2FE.js} +46 -1
- package/dist/bin/{chunk-GXRLFDZW.js → chunk-WDN7RIE3.js} +32 -2
- package/dist/bin/{chunk-T63VQXNM.js → chunk-ZPYC767N.js} +1 -0
- package/dist/bin/{client-2ZKMLWI6.js → client-36JX5MR3.js} +1 -1
- package/dist/bin/{collection-efficiency-TECE6PVQ.js → collection-efficiency-DA5RWG3V.js} +3 -3
- package/dist/bin/{config-335MN4I7.js → config-4LLNT4SH.js} +5 -1
- package/dist/bin/{create-AS2YVGRA.js → create-C5INBPQO.js} +2 -2
- package/dist/bin/{default-account-3RVSU7RF.js → default-account-2GMQ7ZA4.js} +2 -2
- package/dist/bin/{expenses-KXFQJKD6.js → expenses-S2YVA5UT.js} +3 -3
- package/dist/bin/{export-UHZISG7H.js → export-YOOODNVX.js} +2 -2
- package/dist/bin/export-ZA43MLWO.js +191 -0
- package/dist/bin/{factory-OBESY2LG.js → factory-6MUCSXTL.js} +3 -3
- package/dist/bin/{get-WUSYEMG4.js → get-GMQRROK2.js} +2 -2
- package/dist/bin/{get-GTL556HL.js → get-ZV3SC2VY.js} +3 -3
- package/dist/bin/hisaabo.js +107 -59
- package/dist/bin/import-UUHMLCKX.js +267 -0
- package/dist/bin/{invitations-U4ZNYWY7.js → invitations-OVORTTMF.js} +2 -2
- package/dist/bin/{invite-5S4GJKRF.js → invite-GGHBZY4U.js} +2 -2
- package/dist/bin/{invoice-breakdown-PP3BZQLG.js → invoice-breakdown-32XXAZDP.js} +3 -3
- package/dist/bin/{items-CHEFLI7C.js → items-6NOIMH6B.js} +3 -3
- package/dist/bin/{items-toggle-ETVCDCU6.js → items-toggle-L6W6QKQD.js} +2 -2
- package/dist/bin/{list-3FO4UJKC.js → list-FC5JHKHD.js} +3 -3
- package/dist/bin/{list-RJ34MFPR.js → list-OXAVDXH7.js} +2 -2
- package/dist/bin/{list-LQJGTZB4.js → list-RAR56EMQ.js} +2 -2
- package/dist/bin/{members-TE5K5NQC.js → members-Y6XJVHHR.js} +3 -3
- package/dist/bin/{monthly-comparison-Q6KPMTPS.js → monthly-comparison-IAUZ6SBJ.js} +3 -3
- package/dist/bin/{order-cancel-NOQDBL2N.js → order-cancel-QRTCNART.js} +2 -2
- package/dist/bin/{order-confirm-6WMKTGPV.js → order-confirm-LGQOMC4O.js} +2 -2
- package/dist/bin/{order-get-ONWR4GTW.js → order-get-4XAQCRYV.js} +3 -3
- package/dist/bin/{order-update-IVO4AFGV.js → order-update-KZY4H2UR.js} +3 -3
- package/dist/bin/output-NUOL7KJW.js +0 -0
- package/dist/bin/{payment-modes-FXB2G6WP.js → payment-modes-DY2ZEMK7.js} +3 -3
- package/dist/bin/{profit-loss-XPYELDTH.js → profit-loss-5GJBG3PL.js} +3 -3
- package/dist/bin/{receivables-aging-MU6Q3DZ4.js → receivables-aging-6A7XJKDT.js} +3 -3
- package/dist/bin/{remove-DJBOOOR4.js → remove-ZBX34TIQ.js} +2 -2
- package/dist/bin/{revoke-WRIK7HLY.js → revoke-XDNOA2GJ.js} +2 -2
- package/dist/bin/{revoke-5L5GZ4ZZ.js → revoke-ZTAMW2Q2.js} +2 -2
- package/dist/bin/{revoke-all-QARW2G6R.js → revoke-all-365NRBOA.js} +2 -2
- package/dist/bin/{revoke-invitation-ZGLJHYNB.js → revoke-invitation-PQH7XNYA.js} +2 -2
- package/dist/bin/{sales-trend-P5HOZJSX.js → sales-trend-D6PQ7MHY.js} +3 -3
- package/dist/bin/{sequence-LK6QLSI5.js → sequence-KZWADVD7.js} +2 -2
- package/dist/bin/{store-FU7CEILC.js → store-SVRZBUFO.js} +3 -3
- package/dist/bin/{summary-XONLN72I.js → summary-H6U7O5GJ.js} +3 -3
- package/dist/bin/{top-customers-U6HQW2GH.js → top-customers-ATBN6RDI.js} +3 -3
- package/dist/bin/{top-items-EAOIVZ4P.js → top-items-XXU6KYTC.js} +3 -3
- package/dist/bin/{top-outstanding-4546FJDH.js → top-outstanding-JTQNGGW4.js} +3 -3
- package/dist/bin/{unpaid-invoices-AED55PLC.js → unpaid-invoices-BTNQFWCH.js} +3 -3
- package/dist/bin/{untracked-ZEM2CDHC.js → untracked-PAMEDJ6Y.js} +3 -3
- package/dist/bin/{update-FO7AAXF5.js → update-6ZMX2OYX.js} +3 -3
- package/dist/bin/{update-OZPBIBME.js → update-EGHPFXLK.js} +2 -2
- package/dist/bin/{update-QCK32XAG.js → update-EK4NJWU4.js} +3 -3
- package/dist/bin/{update-role-RB35QIA5.js → update-role-24PDTNFK.js} +2 -2
- package/dist/bin/{update-settings-EUC2FJQJ.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 -2051
- 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 -105
- 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 -96
- package/src/error-handler.ts +0 -53
- package/src/format.ts +0 -180
- package/src/output.ts +0 -228
- package/src/spinner.ts +0 -39
- package/tsconfig.json +0 -22
- package/tsup.config.ts +0 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
The O'Saasy License (v1.0)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hisaabo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to use,
|
|
7
|
+
copy, modify, merge, publish, and distribute the Software, subject to the
|
|
8
|
+
following conditions:
|
|
9
|
+
|
|
10
|
+
1. NON-COMPETE CLAUSE: You may not use the Software, or any derivative work
|
|
11
|
+
based on the Software, to offer a hosted or managed service that competes
|
|
12
|
+
with the original Software as a commercial SaaS (Software as a Service)
|
|
13
|
+
product. Self-hosting for your own business use is explicitly permitted
|
|
14
|
+
and encouraged.
|
|
15
|
+
|
|
16
|
+
2. The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
3. You may freely use this Software for:
|
|
20
|
+
- Personal or internal business use (self-hosted)
|
|
21
|
+
- Educational and research purposes
|
|
22
|
+
- Building products that are not substantially similar hosted services
|
|
23
|
+
- Contributing improvements back to the original project
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -182,6 +182,15 @@ hisaabo whoami
|
|
|
182
182
|
| `import parties <file>` | Bulk import parties from JSON or CSV |
|
|
183
183
|
| `import items <file>` | Bulk import items from JSON or CSV |
|
|
184
184
|
|
|
185
|
+
### Backup & Restore
|
|
186
|
+
|
|
187
|
+
| Command | Description |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `export --tenant <slug> -o <file>` | Download full tenant backup as `.tar.gz` |
|
|
190
|
+
| `restore --tenant <slug> -i <file>` | Restore backup into an empty tenant |
|
|
191
|
+
|
|
192
|
+
These are tenant-level commands -- they don't require a business to be selected. Only tenant owners can use them. See [full docs](https://docs.hisaabo.in/ai/cli/#hisaabo-export) for details.
|
|
193
|
+
|
|
185
194
|
---
|
|
186
195
|
|
|
187
196
|
## Terminal Examples
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
formatDate
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ZPYC767N.js";
|
|
5
5
|
import {
|
|
6
6
|
HisaaboApiError,
|
|
7
7
|
HisaaboClient
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-WDN7RIE3.js";
|
|
9
9
|
import {
|
|
10
10
|
requireAuth
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QUITS2FE.js";
|
|
12
12
|
import {
|
|
13
13
|
EXIT,
|
|
14
14
|
fatalError,
|
|
File without changes
|
|
@@ -70,9 +70,52 @@ function requireAuth() {
|
|
|
70
70
|
}
|
|
71
71
|
return cfg;
|
|
72
72
|
}
|
|
73
|
+
function requireTenantAuth() {
|
|
74
|
+
const envToken = process.env["HISAABO_TOKEN"];
|
|
75
|
+
const envUrl = process.env["HISAABO_API_URL"];
|
|
76
|
+
if (envToken && envUrl) {
|
|
77
|
+
return {
|
|
78
|
+
apiUrl: envUrl,
|
|
79
|
+
token: envToken,
|
|
80
|
+
tenantId: process.env["HISAABO_TENANT_ID"] ?? "",
|
|
81
|
+
businessId: process.env["HISAABO_BUSINESS_ID"] ?? "",
|
|
82
|
+
businessName: process.env["HISAABO_BUSINESS_NAME"] ?? "",
|
|
83
|
+
tokenCreatedAt: Date.now()
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const cfg = getConfig();
|
|
87
|
+
if (!cfg.token || !cfg.apiUrl || !cfg.tenantId) {
|
|
88
|
+
fatalError("Not authenticated. Run: hisaabo login", 3);
|
|
89
|
+
}
|
|
90
|
+
const isApiKey = cfg.token.startsWith("hisaabo_key_");
|
|
91
|
+
if (!isApiKey && cfg.tokenCreatedAt) {
|
|
92
|
+
const ageMs = Date.now() - cfg.tokenCreatedAt;
|
|
93
|
+
const TWENTY_FIVE_DAYS = 25 * 24 * 60 * 60 * 1e3;
|
|
94
|
+
if (ageMs > TWENTY_FIVE_DAYS) {
|
|
95
|
+
warn("Session expires soon. Run: hisaabo login");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return cfg;
|
|
99
|
+
}
|
|
73
100
|
function getConfigPath() {
|
|
74
101
|
return conf.path;
|
|
75
102
|
}
|
|
103
|
+
async function checkMaintenance(client) {
|
|
104
|
+
try {
|
|
105
|
+
const status = await client.system.maintenanceStatus();
|
|
106
|
+
if (status.enabled) {
|
|
107
|
+
warn(`System is under maintenance: ${status.message || "Please try again later."}`);
|
|
108
|
+
if (status.endsAt) {
|
|
109
|
+
const end = new Date(status.endsAt).toLocaleString();
|
|
110
|
+
warn(`Estimated end: ${end}`);
|
|
111
|
+
}
|
|
112
|
+
} else if (status.startsAt && new Date(status.startsAt) > /* @__PURE__ */ new Date()) {
|
|
113
|
+
const start = new Date(status.startsAt).toLocaleString();
|
|
114
|
+
warn(`Scheduled maintenance: ${start}${status.message ? ` \u2014 ${status.message}` : ""}`);
|
|
115
|
+
}
|
|
116
|
+
} catch {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
76
119
|
|
|
77
120
|
export {
|
|
78
121
|
getConfig,
|
|
@@ -80,5 +123,7 @@ export {
|
|
|
80
123
|
clearConfig,
|
|
81
124
|
isAuthenticated,
|
|
82
125
|
requireAuth,
|
|
83
|
-
|
|
126
|
+
requireTenantAuth,
|
|
127
|
+
getConfigPath,
|
|
128
|
+
checkMaintenance
|
|
84
129
|
};
|
|
@@ -55,12 +55,15 @@ var HisaaboClient = class {
|
|
|
55
55
|
}
|
|
56
56
|
apiUrl;
|
|
57
57
|
buildHeaders() {
|
|
58
|
-
|
|
58
|
+
const headers = {
|
|
59
59
|
"Authorization": `Bearer ${this.config.token}`,
|
|
60
|
-
"x-business-id": this.config.businessId,
|
|
61
60
|
"x-tenant-id": this.config.tenantId,
|
|
62
61
|
"x-client-type": "cli"
|
|
63
62
|
};
|
|
63
|
+
if (this.config.businessId) {
|
|
64
|
+
headers["x-business-id"] = this.config.businessId;
|
|
65
|
+
}
|
|
66
|
+
return headers;
|
|
64
67
|
}
|
|
65
68
|
async unwrap(res) {
|
|
66
69
|
if (res.status === 429) {
|
|
@@ -1073,6 +1076,33 @@ var HisaaboClient = class {
|
|
|
1073
1076
|
}
|
|
1074
1077
|
};
|
|
1075
1078
|
}
|
|
1079
|
+
// ── System ──────────────────────────────────────────────────────
|
|
1080
|
+
get system() {
|
|
1081
|
+
const c = this;
|
|
1082
|
+
return {
|
|
1083
|
+
maintenanceStatus() {
|
|
1084
|
+
return c.query("system.maintenanceStatus");
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
// ── Self Export ──────────────────────────────────────────────────
|
|
1089
|
+
get selfExport() {
|
|
1090
|
+
const c = this;
|
|
1091
|
+
return {
|
|
1092
|
+
request(input) {
|
|
1093
|
+
return c.mutate("selfExport.request", input);
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
// ── Self Import ──────────────────────────────────────────────────
|
|
1098
|
+
get selfImport() {
|
|
1099
|
+
const c = this;
|
|
1100
|
+
return {
|
|
1101
|
+
request(input) {
|
|
1102
|
+
return c.mutate("selfImport.request", input);
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1076
1106
|
};
|
|
1077
1107
|
|
|
1078
1108
|
export {
|
|
@@ -74,6 +74,7 @@ var STATUS_CONFIG = {
|
|
|
74
74
|
partial: { label: "PARTIAL", color: (s) => chalk.yellow(s) },
|
|
75
75
|
overdue: { label: "OVERDUE", color: (s) => chalk.red(s) },
|
|
76
76
|
cancelled: { label: "CANCEL", color: (s) => chalk.dim(chalk.strikethrough(s)) },
|
|
77
|
+
adjusted: { label: "ADJUST", color: (s) => chalk.magenta(s) },
|
|
77
78
|
unfulfilled: { label: "UNFUL", color: (s) => chalk.blue(s) },
|
|
78
79
|
pending: { label: "PEND", color: (s) => chalk.yellow(s) },
|
|
79
80
|
confirmed: { label: "CONF", color: (s) => chalk.blue(s) },
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
monthEnd,
|
|
6
6
|
monthStart,
|
|
7
7
|
todayISO
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZPYC767N.js";
|
|
9
9
|
import {
|
|
10
10
|
HisaaboApiError,
|
|
11
11
|
HisaaboClient
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-WDN7RIE3.js";
|
|
13
13
|
import {
|
|
14
14
|
requireAuth
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-QUITS2FE.js";
|
|
16
16
|
import {
|
|
17
17
|
EXIT,
|
|
18
18
|
fatalError,
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
checkMaintenance,
|
|
3
4
|
clearConfig,
|
|
4
5
|
getConfig,
|
|
5
6
|
getConfigPath,
|
|
6
7
|
isAuthenticated,
|
|
7
8
|
requireAuth,
|
|
9
|
+
requireTenantAuth,
|
|
8
10
|
setConfig
|
|
9
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QUITS2FE.js";
|
|
10
12
|
import "./chunk-NO4FIFMS.js";
|
|
11
13
|
export {
|
|
14
|
+
checkMaintenance,
|
|
12
15
|
clearConfig,
|
|
13
16
|
getConfig,
|
|
14
17
|
getConfigPath,
|
|
15
18
|
isAuthenticated,
|
|
16
19
|
requireAuth,
|
|
20
|
+
requireTenantAuth,
|
|
17
21
|
setConfig
|
|
18
22
|
};
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
monthEnd,
|
|
6
6
|
monthStart,
|
|
7
7
|
todayISO
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZPYC767N.js";
|
|
9
9
|
import {
|
|
10
10
|
HisaaboApiError,
|
|
11
11
|
HisaaboClient
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-WDN7RIE3.js";
|
|
13
13
|
import {
|
|
14
14
|
requireAuth
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-QUITS2FE.js";
|
|
16
16
|
import {
|
|
17
17
|
EXIT,
|
|
18
18
|
fatalError,
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
HisaaboApiError,
|
|
4
|
+
HisaaboClient
|
|
5
|
+
} from "./chunk-WDN7RIE3.js";
|
|
6
|
+
import {
|
|
7
|
+
requireTenantAuth
|
|
8
|
+
} from "./chunk-QUITS2FE.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT,
|
|
11
|
+
fatalError,
|
|
12
|
+
hasColor,
|
|
13
|
+
isInteractive,
|
|
14
|
+
success
|
|
15
|
+
} from "./chunk-NO4FIFMS.js";
|
|
16
|
+
|
|
17
|
+
// src/commands/backup/export.ts
|
|
18
|
+
import { createWriteStream } from "fs";
|
|
19
|
+
import { stat, unlink } from "fs/promises";
|
|
20
|
+
import { createHash } from "crypto";
|
|
21
|
+
import chalk from "chalk";
|
|
22
|
+
var EXIT_AUTH = 1;
|
|
23
|
+
var EXIT_RATE_LIMITED = 2;
|
|
24
|
+
var EXIT_SERVER_ERROR = 5;
|
|
25
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
26
|
+
function isUuid(value) {
|
|
27
|
+
return UUID_RE.test(value);
|
|
28
|
+
}
|
|
29
|
+
async function resolveTenantId(client, slugOrId) {
|
|
30
|
+
if (isUuid(slugOrId)) {
|
|
31
|
+
return slugOrId;
|
|
32
|
+
}
|
|
33
|
+
const tenants = await client.tenant.list();
|
|
34
|
+
const match = tenants.find((t) => t.slug === slugOrId);
|
|
35
|
+
if (!match) {
|
|
36
|
+
fatalError(`Tenant "${slugOrId}" not found. Run: hisaabo tenant list`, EXIT.NOT_FOUND);
|
|
37
|
+
}
|
|
38
|
+
return match.id;
|
|
39
|
+
}
|
|
40
|
+
function formatBytes(bytes) {
|
|
41
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
42
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
43
|
+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
44
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
45
|
+
}
|
|
46
|
+
function formatSpeed(bytesPerSec) {
|
|
47
|
+
return `${formatBytes(bytesPerSec)}/s`;
|
|
48
|
+
}
|
|
49
|
+
function printProgress(bytes, elapsed) {
|
|
50
|
+
if (!isInteractive()) return;
|
|
51
|
+
const speed = elapsed > 0 ? bytes / (elapsed / 1e3) : 0;
|
|
52
|
+
const msg = ` ${formatBytes(bytes)} downloaded ${formatSpeed(speed)} (${(elapsed / 1e3).toFixed(1)}s)`;
|
|
53
|
+
process.stdout.write(`\r${msg} `);
|
|
54
|
+
}
|
|
55
|
+
function clearProgress() {
|
|
56
|
+
if (!isInteractive()) return;
|
|
57
|
+
process.stdout.write("\r" + " ".repeat(72) + "\r");
|
|
58
|
+
}
|
|
59
|
+
async function exportCommand(opts) {
|
|
60
|
+
const cfg = requireTenantAuth();
|
|
61
|
+
const client = new HisaaboClient(cfg);
|
|
62
|
+
let tenantId;
|
|
63
|
+
try {
|
|
64
|
+
tenantId = await resolveTenantId(client, opts.tenant);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (e instanceof HisaaboApiError) {
|
|
67
|
+
const err = e.hisaaboError;
|
|
68
|
+
if (err.code === "unauthorized") {
|
|
69
|
+
fatalError("Not authenticated. Run `hisaabo login` first.", EXIT_AUTH);
|
|
70
|
+
}
|
|
71
|
+
if (err.code === "network_error") {
|
|
72
|
+
fatalError(err.message, EXIT_SERVER_ERROR);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
let exportUrl;
|
|
78
|
+
try {
|
|
79
|
+
const result = await client.selfExport.request({ tenantId });
|
|
80
|
+
exportUrl = result.url;
|
|
81
|
+
if (exportUrl.startsWith("/")) {
|
|
82
|
+
exportUrl = `${cfg.apiUrl}${exportUrl}`;
|
|
83
|
+
}
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (e instanceof HisaaboApiError) {
|
|
86
|
+
const err = e.hisaaboError;
|
|
87
|
+
if (err.code === "unauthorized") {
|
|
88
|
+
fatalError("Not authenticated. Run `hisaabo login` first.", EXIT_AUTH);
|
|
89
|
+
}
|
|
90
|
+
if (err.code === "forbidden") {
|
|
91
|
+
fatalError("You must be the tenant owner to export data.", EXIT_AUTH);
|
|
92
|
+
}
|
|
93
|
+
if (err.code === "rate_limited") {
|
|
94
|
+
fatalError("Export limit reached (2/day). Try again tomorrow.", EXIT_RATE_LIMITED);
|
|
95
|
+
}
|
|
96
|
+
if (err.code === "network_error") {
|
|
97
|
+
fatalError(err.message, EXIT_SERVER_ERROR);
|
|
98
|
+
}
|
|
99
|
+
fatalError(e.message, EXIT_SERVER_ERROR);
|
|
100
|
+
}
|
|
101
|
+
fatalError(String(e instanceof Error ? e.message : e), EXIT_SERVER_ERROR);
|
|
102
|
+
}
|
|
103
|
+
const outPath = opts.output;
|
|
104
|
+
let fileSize = 0;
|
|
105
|
+
const sha256 = createHash("sha256");
|
|
106
|
+
const startTime = Date.now();
|
|
107
|
+
let progressInterval;
|
|
108
|
+
if (hasColor()) {
|
|
109
|
+
process.stdout.write(chalk.dim(` Downloading backup to ${outPath}...
|
|
110
|
+
`));
|
|
111
|
+
} else {
|
|
112
|
+
process.stdout.write(` Downloading backup to ${outPath}...
|
|
113
|
+
`);
|
|
114
|
+
}
|
|
115
|
+
const writeStream = createWriteStream(outPath);
|
|
116
|
+
try {
|
|
117
|
+
const response = await fetch(exportUrl, {
|
|
118
|
+
headers: {
|
|
119
|
+
"Authorization": `Bearer ${cfg.token}`,
|
|
120
|
+
"x-client-type": "cli"
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
writeStream.close();
|
|
125
|
+
await unlink(outPath).catch(() => void 0);
|
|
126
|
+
fatalError(`Download failed: HTTP ${response.status}`, EXIT_SERVER_ERROR);
|
|
127
|
+
}
|
|
128
|
+
if (!response.body) {
|
|
129
|
+
writeStream.close();
|
|
130
|
+
await unlink(outPath).catch(() => void 0);
|
|
131
|
+
fatalError("Download failed: empty response body", EXIT_SERVER_ERROR);
|
|
132
|
+
}
|
|
133
|
+
progressInterval = setInterval(() => {
|
|
134
|
+
printProgress(fileSize, Date.now() - startTime);
|
|
135
|
+
}, 250);
|
|
136
|
+
const reader = response.body.getReader();
|
|
137
|
+
await new Promise((resolve, reject) => {
|
|
138
|
+
writeStream.on("error", reject);
|
|
139
|
+
const pump = () => {
|
|
140
|
+
reader.read().then(({ done, value }) => {
|
|
141
|
+
if (done) {
|
|
142
|
+
writeStream.end(() => resolve());
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
sha256.update(value);
|
|
146
|
+
fileSize += value.length;
|
|
147
|
+
if (!writeStream.write(value)) {
|
|
148
|
+
writeStream.once("drain", pump);
|
|
149
|
+
} else {
|
|
150
|
+
pump();
|
|
151
|
+
}
|
|
152
|
+
}).catch(reject);
|
|
153
|
+
};
|
|
154
|
+
pump();
|
|
155
|
+
});
|
|
156
|
+
} catch (e) {
|
|
157
|
+
if (progressInterval !== void 0) {
|
|
158
|
+
clearInterval(progressInterval);
|
|
159
|
+
}
|
|
160
|
+
clearProgress();
|
|
161
|
+
writeStream.destroy();
|
|
162
|
+
await unlink(outPath).catch(() => void 0);
|
|
163
|
+
if (e instanceof HisaaboApiError && e.hisaaboError.code === "network_error") {
|
|
164
|
+
fatalError(`Download failed: ${e.hisaaboError.message}`, EXIT_SERVER_ERROR);
|
|
165
|
+
}
|
|
166
|
+
fatalError(`Download failed: ${String(e instanceof Error ? e.message : e)}`, EXIT_SERVER_ERROR);
|
|
167
|
+
}
|
|
168
|
+
if (progressInterval !== void 0) {
|
|
169
|
+
clearInterval(progressInterval);
|
|
170
|
+
}
|
|
171
|
+
clearProgress();
|
|
172
|
+
const digest = sha256.digest("hex");
|
|
173
|
+
let writtenSize;
|
|
174
|
+
try {
|
|
175
|
+
const info = await stat(outPath);
|
|
176
|
+
writtenSize = info.size;
|
|
177
|
+
} catch {
|
|
178
|
+
fatalError("Failed to read output file after download", EXIT_SERVER_ERROR);
|
|
179
|
+
}
|
|
180
|
+
if (writtenSize === 0) {
|
|
181
|
+
await unlink(outPath).catch(() => void 0);
|
|
182
|
+
fatalError("Download produced an empty file", EXIT_SERVER_ERROR);
|
|
183
|
+
}
|
|
184
|
+
success(`Backup saved to ${outPath}`);
|
|
185
|
+
console.log(` Size: ${formatBytes(writtenSize)}`);
|
|
186
|
+
console.log(` SHA256: ${digest}`);
|
|
187
|
+
console.log(` Time: ${((Date.now() - startTime) / 1e3).toFixed(1)}s`);
|
|
188
|
+
}
|
|
189
|
+
export {
|
|
190
|
+
exportCommand
|
|
191
|
+
};
|
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
monthEnd,
|
|
10
10
|
monthStart,
|
|
11
11
|
todayISO
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ZPYC767N.js";
|
|
13
13
|
import {
|
|
14
14
|
HisaaboApiError,
|
|
15
15
|
HisaaboClient
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-WDN7RIE3.js";
|
|
17
17
|
import {
|
|
18
18
|
requireAuth
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-QUITS2FE.js";
|
|
20
20
|
import {
|
|
21
21
|
EXIT,
|
|
22
22
|
fatalError,
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
formatDate,
|
|
4
4
|
formatINR
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZPYC767N.js";
|
|
6
6
|
import {
|
|
7
7
|
HisaaboApiError,
|
|
8
8
|
HisaaboClient
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-WDN7RIE3.js";
|
|
10
10
|
import {
|
|
11
11
|
requireAuth
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QUITS2FE.js";
|
|
13
13
|
import {
|
|
14
14
|
EXIT,
|
|
15
15
|
fatalError,
|