Fix Insomnia text body imports (#507)

This commit is contained in:
Gregory Schier
2026-07-14 09:13:47 -07:00
committed by GitHub
parent c30f5b767b
commit e59ecce886
4 changed files with 188 additions and 89 deletions
+8 -47
View File
@@ -1,6 +1,12 @@
/* oxlint-disable no-explicit-any */
import type { PartialImportResources } from "@yaakapp/api";
import { convertId, convertTemplateSyntax, isJSObject } from "./common";
import {
convertId,
convertTemplateSyntax,
importHeaders,
importHttpBodyAndHeaders,
isJSObject,
} from "./common";
export function convertInsomniaV5(parsed: any) {
// Assert parsed is object
@@ -82,38 +88,6 @@ function importHttpRequest(
const updated = r.meta?.modified ?? r.updated;
const sortKey = r.meta?.sortKey ?? r.sortKey;
let bodyType: string | null = null;
let body = {};
if (r.body?.mimeType === "application/octet-stream") {
bodyType = "binary";
body = { filePath: r.body.fileName ?? "" };
} else if (r.body?.mimeType === "application/x-www-form-urlencoded") {
bodyType = "application/x-www-form-urlencoded";
body = {
form: (r.body.params ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? "",
value: p.value ?? "",
})),
};
} else if (r.body?.mimeType === "multipart/form-data") {
bodyType = "multipart/form-data";
body = {
form: (r.body.params ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? "",
value: p.value ?? "",
file: p.fileName ?? null,
})),
};
} else if (r.body?.mimeType === "application/graphql") {
bodyType = "graphql";
body = { text: r.body.text ?? "" };
} else if (r.body?.mimeType === "application/json") {
bodyType = "application/json";
body = { text: r.body.text ?? "" };
}
return {
id: convertId(id),
workspaceId: convertId(workspaceId),
@@ -130,10 +104,8 @@ function importHttpRequest(
name: p.name ?? "",
value: p.value ?? "",
})),
body,
bodyType,
...importHttpBodyAndHeaders(r),
method: r.method,
...importHeaders(r),
...importAuthentication(r),
};
}
@@ -203,17 +175,6 @@ function importWebsocketRequest(
};
}
function importHeaders(obj: any) {
const headers = (obj.headers ?? [])
.map((h: any) => ({
enabled: !h.disabled,
name: h.name ?? "",
value: h.value ?? "",
}))
.filter(({ name, value }: any) => name !== "" || value !== "");
return { headers } as const;
}
function importAuthentication(obj: any) {
let authenticationType: string | null = null;
let authentication = {};