@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
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
|
|
File without changes
|
|
@@ -70,6 +70,33 @@ 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
|
}
|
|
@@ -96,6 +123,7 @@ export {
|
|
|
96
123
|
clearConfig,
|
|
97
124
|
isAuthenticated,
|
|
98
125
|
requireAuth,
|
|
126
|
+
requireTenantAuth,
|
|
99
127
|
getConfigPath,
|
|
100
128
|
checkMaintenance
|
|
101
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) {
|
|
@@ -1082,6 +1085,24 @@ var HisaaboClient = class {
|
|
|
1082
1085
|
}
|
|
1083
1086
|
};
|
|
1084
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
|
+
}
|
|
1085
1106
|
};
|
|
1086
1107
|
|
|
1087
1108
|
export {
|
|
File without changes
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
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,
|
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
getConfigPath,
|
|
7
7
|
isAuthenticated,
|
|
8
8
|
requireAuth,
|
|
9
|
+
requireTenantAuth,
|
|
9
10
|
setConfig
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QUITS2FE.js";
|
|
11
12
|
import "./chunk-NO4FIFMS.js";
|
|
12
13
|
export {
|
|
13
14
|
checkMaintenance,
|
|
@@ -16,5 +17,6 @@ export {
|
|
|
16
17
|
getConfigPath,
|
|
17
18
|
isAuthenticated,
|
|
18
19
|
requireAuth,
|
|
20
|
+
requireTenantAuth,
|
|
19
21
|
setConfig
|
|
20
22
|
};
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
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
|
+
};
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
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,
|