@verentis/cli 0.2.7 → 0.2.9
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/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { mkdir, stat, writeFile, readFile, readdir, realpath, mkdtemp, rm, glob } from 'fs/promises';
|
|
4
|
-
import { Agent } from 'https';
|
|
5
4
|
import { tmpdir, homedir } from 'os';
|
|
6
5
|
import { resolve, basename, dirname, posix, join, isAbsolute, extname, relative, sep } from 'path';
|
|
7
6
|
import { spawn, spawnSync } from 'child_process';
|
|
@@ -13,9 +12,11 @@ import { pipeline } from 'stream/promises';
|
|
|
13
12
|
import * as tar from 'tar';
|
|
14
13
|
import { fileURLToPath } from 'url';
|
|
15
14
|
|
|
16
|
-
var insecureAgent = new Agent({ rejectUnauthorized: false });
|
|
17
15
|
function insecureFetchOptions(insecure) {
|
|
18
|
-
|
|
16
|
+
if (insecure) {
|
|
17
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
18
|
+
}
|
|
19
|
+
return {};
|
|
19
20
|
}
|
|
20
21
|
var configDir = () => process.env.VERENTIS_CONFIG_DIR ?? join(homedir(), ".verentis");
|
|
21
22
|
var configPath = () => join(configDir(), "config.json");
|
|
@@ -246,15 +247,16 @@ ${truncate(text)}` : ""}`);
|
|
|
246
247
|
}
|
|
247
248
|
const headers = { Authorization: `Bearer ${token}` };
|
|
248
249
|
let body;
|
|
250
|
+
const isFormData = options.rawBody instanceof FormData;
|
|
249
251
|
if (options.rawBody !== void 0) {
|
|
250
252
|
body = options.rawBody;
|
|
251
|
-
headers["Content-Type"] = options.contentType ?? "application/octet-stream";
|
|
253
|
+
if (!isFormData) headers["Content-Type"] = options.contentType ?? "application/octet-stream";
|
|
252
254
|
} else if (options.body !== void 0) {
|
|
253
255
|
body = JSON.stringify(options.body);
|
|
254
256
|
headers["Content-Type"] = "application/json";
|
|
255
257
|
}
|
|
256
258
|
for (const [key, value] of Object.entries(options.headers ?? {})) headers[key] = value;
|
|
257
|
-
const res = await fetch(url, { method, headers, body, ...insecureFetchOptions(insecure), ...options.rawBody !== void 0 ? { duplex: "half" } : {} });
|
|
259
|
+
const res = await fetch(url, { method, headers, body, ...insecureFetchOptions(insecure), ...options.rawBody !== void 0 && !isFormData ? { duplex: "half" } : {} });
|
|
258
260
|
if (!res.ok) {
|
|
259
261
|
const text = await res.text().catch(() => "");
|
|
260
262
|
throw new ApiError(res.status, `${method} ${path} failed (${res.status}). ${hintFor(res.status)}${formatErrorBody(text)}`);
|
|
@@ -1546,15 +1548,15 @@ var normalizeRemote = (path) => {
|
|
|
1546
1548
|
return trimmed;
|
|
1547
1549
|
};
|
|
1548
1550
|
async function uploadWithHeaders(api, workspaceId, remotePath, localPath, options) {
|
|
1549
|
-
const
|
|
1551
|
+
const buffer = await readFile(localPath);
|
|
1552
|
+
const form = new FormData();
|
|
1553
|
+
form.append("file", new Blob([buffer], { type: options.contentType ?? "application/octet-stream" }), basename(localPath));
|
|
1554
|
+
form.append("metadata", JSON.stringify({ branch: options.branch, contentType: options.contentType }));
|
|
1550
1555
|
const res = await api.requestRaw("POST", fillPath(files.upload.path, { path: normalizeRemote(remotePath) }), {
|
|
1551
1556
|
scopes: [...files.upload.scopes],
|
|
1552
1557
|
tokenWorkspaceId: workspaceId,
|
|
1553
|
-
rawBody:
|
|
1554
|
-
contentType: options.contentType ?? "application/octet-stream",
|
|
1558
|
+
rawBody: form,
|
|
1555
1559
|
headers: {
|
|
1556
|
-
"X-Branch": options.branch,
|
|
1557
|
-
"Content-Disposition": `attachment; filename="${basename(localPath)}"`,
|
|
1558
1560
|
...options.autoExtract ? { "X-Auto-Extract": "true" } : {}
|
|
1559
1561
|
}
|
|
1560
1562
|
});
|