@hisaabo/cli 0.7.5 → 0.8.6
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
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
warn
|
|
16
|
+
} from "./chunk-NO4FIFMS.js";
|
|
17
|
+
|
|
18
|
+
// src/commands/backup/import.ts
|
|
19
|
+
import { createReadStream } from "fs";
|
|
20
|
+
import { stat } from "fs/promises";
|
|
21
|
+
import * as readline from "readline";
|
|
22
|
+
import chalk from "chalk";
|
|
23
|
+
var EXIT_AUTH = 1;
|
|
24
|
+
var EXIT_TARGET_NOT_EMPTY = 3;
|
|
25
|
+
var EXIT_FILE_ERROR = 4;
|
|
26
|
+
var EXIT_SERVER_ERROR = 5;
|
|
27
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
28
|
+
function isUuid(value) {
|
|
29
|
+
return UUID_RE.test(value);
|
|
30
|
+
}
|
|
31
|
+
async function resolveTenant(client, slugOrId) {
|
|
32
|
+
if (isUuid(slugOrId)) {
|
|
33
|
+
return { id: slugOrId, slug: slugOrId };
|
|
34
|
+
}
|
|
35
|
+
const tenants = await client.tenant.list();
|
|
36
|
+
const match = tenants.find((t) => t.slug === slugOrId);
|
|
37
|
+
if (!match) {
|
|
38
|
+
fatalError(`Tenant "${slugOrId}" not found. Run: hisaabo tenant list`, EXIT.NOT_FOUND);
|
|
39
|
+
}
|
|
40
|
+
return { id: match.id, slug: match.slug };
|
|
41
|
+
}
|
|
42
|
+
function formatBytes(bytes) {
|
|
43
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
44
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
45
|
+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
46
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
47
|
+
}
|
|
48
|
+
function formatSpeed(bytesPerSec) {
|
|
49
|
+
return `${formatBytes(bytesPerSec)}/s`;
|
|
50
|
+
}
|
|
51
|
+
function printUploadProgress(uploaded, total, elapsed) {
|
|
52
|
+
if (!isInteractive()) return;
|
|
53
|
+
const speed = elapsed > 0 ? uploaded / (elapsed / 1e3) : 0;
|
|
54
|
+
const pct = total > 0 ? Math.min(100, Math.round(uploaded / total * 100)) : 0;
|
|
55
|
+
const msg = ` ${formatBytes(uploaded)} / ${formatBytes(total)} ${pct}% ${formatSpeed(speed)} (${(elapsed / 1e3).toFixed(1)}s)`;
|
|
56
|
+
process.stdout.write(`\r${msg} `);
|
|
57
|
+
}
|
|
58
|
+
function clearProgress() {
|
|
59
|
+
if (!isInteractive()) return;
|
|
60
|
+
process.stdout.write("\r" + " ".repeat(80) + "\r");
|
|
61
|
+
}
|
|
62
|
+
async function confirm(question) {
|
|
63
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
rl.question(question, (answer) => {
|
|
66
|
+
rl.close();
|
|
67
|
+
resolve(answer.trim().toLowerCase() === "y");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function printCompatibility(compat) {
|
|
72
|
+
if (!compat) return;
|
|
73
|
+
if (compat.appVersionMatch && compat.schemaChecksumMatch) return;
|
|
74
|
+
const label = hasColor() ? chalk.yellow("Best-effort restore") : "Best-effort restore";
|
|
75
|
+
console.log(` ${label}: backup was produced against a different build.`);
|
|
76
|
+
if (!compat.appVersionMatch) {
|
|
77
|
+
console.log(
|
|
78
|
+
` App version: backup ${compat.sourceAppVersion} \u2192 server ${compat.targetAppVersion}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (!compat.schemaChecksumMatch) {
|
|
82
|
+
console.log(
|
|
83
|
+
` Schema fingerprint differs \u2014 table shape has changed since this backup was taken.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
console.log(` Spot-check a few invoices and reports before relying on the data.`);
|
|
87
|
+
}
|
|
88
|
+
async function restoreCommand(opts) {
|
|
89
|
+
const cfg = requireTenantAuth();
|
|
90
|
+
const client = new HisaaboClient(cfg);
|
|
91
|
+
let fileStats;
|
|
92
|
+
try {
|
|
93
|
+
fileStats = await stat(opts.input);
|
|
94
|
+
} catch {
|
|
95
|
+
fatalError(`File not found or not readable: ${opts.input}`, EXIT_FILE_ERROR);
|
|
96
|
+
}
|
|
97
|
+
if (fileStats.size === 0) {
|
|
98
|
+
fatalError(`File is empty: ${opts.input}`, EXIT_FILE_ERROR);
|
|
99
|
+
}
|
|
100
|
+
let tenantId;
|
|
101
|
+
let tenantSlug;
|
|
102
|
+
try {
|
|
103
|
+
const resolved = await resolveTenant(client, opts.tenant);
|
|
104
|
+
tenantId = resolved.id;
|
|
105
|
+
tenantSlug = resolved.slug;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e instanceof HisaaboApiError) {
|
|
108
|
+
const err = e.hisaaboError;
|
|
109
|
+
if (err.code === "unauthorized") {
|
|
110
|
+
fatalError("Not authenticated. Run `hisaabo login` first.", EXIT_AUTH);
|
|
111
|
+
}
|
|
112
|
+
if (err.code === "network_error") {
|
|
113
|
+
fatalError(err.message, EXIT_SERVER_ERROR);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
if (!opts.yes) {
|
|
119
|
+
if (process.stdin.isTTY) {
|
|
120
|
+
const proceed = await confirm(
|
|
121
|
+
` This will import all data from \`${opts.input}\` into tenant \`${tenantSlug}\`.
|
|
122
|
+
Target tenant must be empty. Proceed? [y/N]: `
|
|
123
|
+
);
|
|
124
|
+
if (!proceed) {
|
|
125
|
+
console.log(" Cancelled.");
|
|
126
|
+
process.exit(0);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
warn("Non-interactive mode: pass --yes to skip confirmation.");
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
let uploadUrl;
|
|
134
|
+
try {
|
|
135
|
+
const result = await client.selfImport.request({ tenantId });
|
|
136
|
+
uploadUrl = result.url.startsWith("/") ? `${cfg.apiUrl}${result.url}` : result.url;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
if (e instanceof HisaaboApiError) {
|
|
139
|
+
const err = e.hisaaboError;
|
|
140
|
+
if (err.code === "unauthorized") {
|
|
141
|
+
fatalError("Not authenticated. Run `hisaabo login` first.", EXIT_AUTH);
|
|
142
|
+
}
|
|
143
|
+
if (err.code === "forbidden") {
|
|
144
|
+
fatalError("You must be the tenant owner to import data.", EXIT_AUTH);
|
|
145
|
+
}
|
|
146
|
+
if (err.code === "api_error" && err.message.includes("TARGET_NOT_EMPTY")) {
|
|
147
|
+
fatalError(
|
|
148
|
+
"Target tenant is not empty. Restore only works on an empty tenant.",
|
|
149
|
+
EXIT_TARGET_NOT_EMPTY
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (err.code === "network_error") {
|
|
153
|
+
fatalError(err.message, EXIT_SERVER_ERROR);
|
|
154
|
+
}
|
|
155
|
+
fatalError(e.message, EXIT_SERVER_ERROR);
|
|
156
|
+
}
|
|
157
|
+
fatalError(String(e instanceof Error ? e.message : e), EXIT_SERVER_ERROR);
|
|
158
|
+
}
|
|
159
|
+
if (hasColor()) {
|
|
160
|
+
process.stdout.write(chalk.dim(` Uploading ${opts.input} (${formatBytes(fileStats.size)})...
|
|
161
|
+
`));
|
|
162
|
+
} else {
|
|
163
|
+
process.stdout.write(` Uploading ${opts.input} (${formatBytes(fileStats.size)})...
|
|
164
|
+
`);
|
|
165
|
+
}
|
|
166
|
+
const startTime = Date.now();
|
|
167
|
+
let uploaded = 0;
|
|
168
|
+
let progressInterval;
|
|
169
|
+
progressInterval = setInterval(() => {
|
|
170
|
+
printUploadProgress(uploaded, fileStats.size, Date.now() - startTime);
|
|
171
|
+
}, 250);
|
|
172
|
+
let responseBody;
|
|
173
|
+
try {
|
|
174
|
+
const nodeReadStream = createReadStream(opts.input);
|
|
175
|
+
const webReadable = new ReadableStream({
|
|
176
|
+
start(controller) {
|
|
177
|
+
nodeReadStream.on("data", (chunk) => {
|
|
178
|
+
const buf = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
179
|
+
uploaded += buf.length;
|
|
180
|
+
controller.enqueue(new Uint8Array(buf));
|
|
181
|
+
});
|
|
182
|
+
nodeReadStream.on("end", () => controller.close());
|
|
183
|
+
nodeReadStream.on("error", (err) => controller.error(err));
|
|
184
|
+
},
|
|
185
|
+
cancel() {
|
|
186
|
+
nodeReadStream.destroy();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
const response = await fetch(uploadUrl, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: {
|
|
192
|
+
"Authorization": `Bearer ${cfg.token}`,
|
|
193
|
+
"x-client-type": "cli",
|
|
194
|
+
"Content-Type": "application/gzip",
|
|
195
|
+
"Content-Length": String(fileStats.size)
|
|
196
|
+
},
|
|
197
|
+
body: webReadable,
|
|
198
|
+
// @ts-expect-error -- Node 18+ fetch needs duplex for request body streaming
|
|
199
|
+
duplex: "half"
|
|
200
|
+
});
|
|
201
|
+
clearInterval(progressInterval);
|
|
202
|
+
progressInterval = void 0;
|
|
203
|
+
clearProgress();
|
|
204
|
+
const raw = await response.json();
|
|
205
|
+
if (!response.ok) {
|
|
206
|
+
if (response.status === 409) {
|
|
207
|
+
const body = raw;
|
|
208
|
+
if (typeof body["error"] === "string" && body["error"].includes("TARGET_NOT_EMPTY")) {
|
|
209
|
+
fatalError(
|
|
210
|
+
"Target tenant is not empty. Restore only works on an empty tenant.",
|
|
211
|
+
EXIT_TARGET_NOT_EMPTY
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const errBody = raw;
|
|
216
|
+
const errMsg = String(errBody["error"] ?? errBody["message"] ?? `HTTP ${response.status}`);
|
|
217
|
+
fatalError(`Upload failed: ${errMsg}`, EXIT_SERVER_ERROR);
|
|
218
|
+
}
|
|
219
|
+
responseBody = raw;
|
|
220
|
+
} catch (e) {
|
|
221
|
+
if (progressInterval !== void 0) {
|
|
222
|
+
clearInterval(progressInterval);
|
|
223
|
+
}
|
|
224
|
+
clearProgress();
|
|
225
|
+
if (e instanceof HisaaboApiError && e.hisaaboError.code === "network_error") {
|
|
226
|
+
fatalError(`Upload failed: ${e.hisaaboError.message}`, EXIT_SERVER_ERROR);
|
|
227
|
+
}
|
|
228
|
+
if (e instanceof Error && e.message === "process.exit") throw e;
|
|
229
|
+
fatalError(`Upload failed: ${String(e instanceof Error ? e.message : e)}`, EXIT_SERVER_ERROR);
|
|
230
|
+
}
|
|
231
|
+
if (!responseBody.ok) {
|
|
232
|
+
const failed = responseBody;
|
|
233
|
+
process.stderr.write("\nImport failed:\n");
|
|
234
|
+
for (const err of failed.errors) {
|
|
235
|
+
process.stderr.write(` - ${err}
|
|
236
|
+
`);
|
|
237
|
+
}
|
|
238
|
+
printCompatibility(failed.compatibility);
|
|
239
|
+
process.exit(EXIT_SERVER_ERROR);
|
|
240
|
+
}
|
|
241
|
+
const done = responseBody;
|
|
242
|
+
success(`Import completed in ${(done.durationMs / 1e3).toFixed(1)}s`);
|
|
243
|
+
printCompatibility(done.compatibility);
|
|
244
|
+
const tables = Object.entries(done.rowsInserted).filter(([, n]) => n > 0);
|
|
245
|
+
if (tables.length > 0) {
|
|
246
|
+
console.log(" Rows inserted:");
|
|
247
|
+
for (const [table, count] of tables) {
|
|
248
|
+
console.log(` ${table}: ${count}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const skippedTables = Object.entries(done.rowsSkipped ?? {}).filter(([, n]) => n > 0);
|
|
252
|
+
if (skippedTables.length > 0) {
|
|
253
|
+
console.log(" Rows skipped:");
|
|
254
|
+
for (const [table, count] of skippedTables) {
|
|
255
|
+
console.log(` ${table}: ${count}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (done.warnings && done.warnings.length > 0) {
|
|
259
|
+
console.log(` Warnings (${done.warnings.length}):`);
|
|
260
|
+
for (const w of done.warnings) {
|
|
261
|
+
warn(w);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
export {
|
|
266
|
+
restoreCommand
|
|
267
|
+
};
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
HisaaboApiError,
|
|
12
12
|
HisaaboClient
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-WDN7RIE3.js";
|
|
14
14
|
import {
|
|
15
15
|
requireAuth
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-QUITS2FE.js";
|
|
17
17
|
import {
|
|
18
18
|
EXIT,
|
|
19
19
|
fatalError,
|
|
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,
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
HisaaboApiError,
|
|
12
12
|
HisaaboClient
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-WDN7RIE3.js";
|
|
14
14
|
import {
|
|
15
15
|
requireAuth
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-QUITS2FE.js";
|
|
17
17
|
import {
|
|
18
18
|
EXIT,
|
|
19
19
|
fatalError,
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
HisaaboApiError,
|
|
12
12
|
HisaaboClient
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-WDN7RIE3.js";
|
|
14
14
|
import {
|
|
15
15
|
requireAuth
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-QUITS2FE.js";
|
|
17
17
|
import {
|
|
18
18
|
EXIT,
|
|
19
19
|
fatalError,
|
|
@@ -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,
|
|
@@ -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,
|