@verentis/cli 0.2.7 → 0.2.8

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 CHANGED
@@ -246,15 +246,16 @@ ${truncate(text)}` : ""}`);
246
246
  }
247
247
  const headers = { Authorization: `Bearer ${token}` };
248
248
  let body;
249
+ const isFormData = options.rawBody instanceof FormData;
249
250
  if (options.rawBody !== void 0) {
250
251
  body = options.rawBody;
251
- headers["Content-Type"] = options.contentType ?? "application/octet-stream";
252
+ if (!isFormData) headers["Content-Type"] = options.contentType ?? "application/octet-stream";
252
253
  } else if (options.body !== void 0) {
253
254
  body = JSON.stringify(options.body);
254
255
  headers["Content-Type"] = "application/json";
255
256
  }
256
257
  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" } : {} });
258
+ const res = await fetch(url, { method, headers, body, ...insecureFetchOptions(insecure), ...options.rawBody !== void 0 && !isFormData ? { duplex: "half" } : {} });
258
259
  if (!res.ok) {
259
260
  const text = await res.text().catch(() => "");
260
261
  throw new ApiError(res.status, `${method} ${path} failed (${res.status}). ${hintFor(res.status)}${formatErrorBody(text)}`);
@@ -1546,15 +1547,15 @@ var normalizeRemote = (path) => {
1546
1547
  return trimmed;
1547
1548
  };
1548
1549
  async function uploadWithHeaders(api, workspaceId, remotePath, localPath, options) {
1549
- const stream = Readable.toWeb(createReadStream(localPath));
1550
+ const buffer = await readFile(localPath);
1551
+ const form = new FormData();
1552
+ form.append("file", new Blob([buffer], { type: options.contentType ?? "application/octet-stream" }), basename(localPath));
1553
+ form.append("metadata", JSON.stringify({ branch: options.branch, contentType: options.contentType }));
1550
1554
  const res = await api.requestRaw("POST", fillPath(files.upload.path, { path: normalizeRemote(remotePath) }), {
1551
1555
  scopes: [...files.upload.scopes],
1552
1556
  tokenWorkspaceId: workspaceId,
1553
- rawBody: stream,
1554
- contentType: options.contentType ?? "application/octet-stream",
1557
+ rawBody: form,
1555
1558
  headers: {
1556
- "X-Branch": options.branch,
1557
- "Content-Disposition": `attachment; filename="${basename(localPath)}"`,
1558
1559
  ...options.autoExtract ? { "X-Auto-Extract": "true" } : {}
1559
1560
  }
1560
1561
  });