This commit is contained in:
Gregory Schier
2024-04-02 10:11:37 +02:00
parent ba5bfd07f7
commit 91fdbe4d33

View File

@@ -1,73 +1,73 @@
const q = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", S = "https://schema.getpostman.com/json/collection/v2.0.0/collection.json", _ = [S, q]; const q = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", S = "https://schema.getpostman.com/json/collection/v2.0.0/collection.json", _ = [S, q];
function v(t) { function j(t) {
var b; var g;
const e = w(t); const e = A(t);
if (e == null) if (e == null)
return; return;
const n = o(e.info); const a = l(e.info);
if (!_.includes(n.schema) || !Array.isArray(e.item)) if (!_.includes(a.schema) || !Array.isArray(e.item))
return; return;
const A = g(e.auth), i = { const c = w(e.auth), s = {
workspaces: [], workspaces: [],
environments: [], environments: [],
httpRequests: [], httpRequests: [],
folders: [] folders: []
}, c = { }, n = {
model: "workspace", model: "workspace",
id: m("wk"), id: y("wk"),
name: n.name || "Postman Import", name: a.name || "Postman Import",
description: n.description || "", description: a.description || "",
variables: ((b = e.variable) == null ? void 0 : b.map((r) => ({ variables: ((g = e.variable) == null ? void 0 : g.map((r) => ({
name: r.key, name: r.key,
value: r.value value: r.value
}))) ?? [] }))) ?? []
}; };
i.workspaces.push(c); s.workspaces.push(n);
const f = (r, u = null) => { const f = (r, d = null) => {
if (typeof r.name == "string" && Array.isArray(r.item)) { if (typeof r.name == "string" && Array.isArray(r.item)) {
const a = { const o = {
model: "folder", model: "folder",
workspaceId: c.id, workspaceId: n.id,
id: m("fl"), id: y("fl"),
name: r.name, name: r.name,
folderId: u folderId: d
}; };
i.folders.push(a); s.folders.push(o);
for (const s of r.item) for (const u of r.item)
f(s, a.id); f(u, o.id);
} else if (typeof r.name == "string" && "request" in r) { } else if (typeof r.name == "string" && "request" in r) {
const a = o(r.request), s = O(a.body), T = g(a.auth), d = T.authenticationType == null ? A : T, k = { const o = l(r.request), u = O(o.body), T = w(o.auth), p = T.authenticationType == null ? c : T, k = {
model: "http_request", model: "http_request",
id: m("rq"), id: y("rq"),
workspaceId: c.id, workspaceId: n.id,
folderId: u, folderId: d,
name: r.name, name: r.name,
method: a.method || "GET", method: o.method || "GET",
url: typeof a.url == "string" ? a.url : o(a.url).raw, url: typeof o.url == "string" ? o.url : l(o.url).raw,
body: s.body, body: u.body,
bodyType: s.bodyType, bodyType: u.bodyType,
authentication: d.authentication, authentication: p.authentication,
authenticationType: d.authenticationType, authenticationType: p.authenticationType,
headers: [ headers: [
...s.headers, ...u.headers,
...d.headers, ...p.headers,
...y(a.header).map((p) => ({ ...h(o.header).map((m) => ({
name: p.key, name: m.key,
value: p.value, value: m.value,
enabled: !p.disabled enabled: !m.disabled
})) }))
] ]
}; };
i.httpRequests.push(k); s.httpRequests.push(k);
} else } else
console.log("Unknown item", r, u); console.log("Unknown item", r, d);
}; };
for (const r of e.item) for (const r of e.item)
f(r); f(r);
return { resources: h(i) }; return { resources: b(s) };
} }
function g(t) { function w(t) {
const e = o(t); const e = l(t);
return "basic" in e ? { return "basic" in e ? {
headers: [], headers: [],
authenticationType: "basic", authenticationType: "basic",
@@ -84,7 +84,8 @@ function g(t) {
} : { headers: [], authenticationType: null, authentication: {} }; } : { headers: [], authenticationType: null, authentication: {} };
} }
function O(t) { function O(t) {
const e = o(t); var a, i, c, s;
const e = l(t);
return "graphql" in e ? { return "graphql" in e ? {
headers: [ headers: [
{ {
@@ -96,7 +97,7 @@ function O(t) {
bodyType: "graphql", bodyType: "graphql",
body: { body: {
text: JSON.stringify( text: JSON.stringify(
{ query: e.graphql.query, variables: w(e.graphql.variables) }, { query: e.graphql.query, variables: A(e.graphql.variables) },
null, null,
2 2
) )
@@ -111,7 +112,7 @@ function O(t) {
], ],
bodyType: "application/x-www-form-urlencoded", bodyType: "application/x-www-form-urlencoded",
body: { body: {
form: y(e.urlencoded).map((n) => ({ form: h(e.urlencoded).map((n) => ({
enabled: !n.disabled, enabled: !n.disabled,
name: n.key ?? "", name: n.key ?? "",
value: n.value ?? "" value: n.value ?? ""
@@ -127,7 +128,7 @@ function O(t) {
], ],
bodyType: "multipart/form-data", bodyType: "multipart/form-data",
body: { body: {
form: y(e.formdata).map( form: h(e.formdata).map(
(n) => n.src != null ? { (n) => n.src != null ? {
enabled: !n.disabled, enabled: !n.disabled,
name: n.key ?? "", name: n.key ?? "",
@@ -139,34 +140,46 @@ function O(t) {
} }
) )
} }
} : "raw" in e ? {
headers: [
{
name: "Content-Type",
value: ((i = (a = e.options) == null ? void 0 : a.raw) == null ? void 0 : i.language) === "json" ? "application/json" : "",
enabled: !0
}
],
bodyType: ((s = (c = e.options) == null ? void 0 : c.raw) == null ? void 0 : s.language) === "json" ? "application/json" : "other",
body: {
text: e.raw ?? ""
}
} : { headers: [], bodyType: null, body: {} }; } : { headers: [], bodyType: null, body: {} };
} }
function w(t) { function A(t) {
try { try {
return o(JSON.parse(t)); return l(JSON.parse(t));
} catch { } catch {
} }
return null; return null;
} }
function o(t) { function l(t) {
return Object.prototype.toString.call(t) === "[object Object]" ? t : {}; return Object.prototype.toString.call(t) === "[object Object]" ? t : {};
} }
function y(t) { function h(t) {
return Object.prototype.toString.call(t) === "[object Array]" ? t : []; return Object.prototype.toString.call(t) === "[object Array]" ? t : [];
} }
function h(t) { function b(t) {
return typeof t == "string" ? t.replace(/{{\s*(_\.)?([^}]+)\s*}}/g, "${[$2]}") : Array.isArray(t) && t != null ? t.map(h) : typeof t == "object" && t != null ? Object.fromEntries( return typeof t == "string" ? t.replace(/{{\s*(_\.)?([^}]+)\s*}}/g, "${[$2]}") : Array.isArray(t) && t != null ? t.map(b) : typeof t == "object" && t != null ? Object.fromEntries(
Object.entries(t).map(([e, n]) => [e, h(n)]) Object.entries(t).map(([e, a]) => [e, b(a)])
) : t; ) : t;
} }
function m(t) { function y(t) {
const e = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; const e = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
let n = `${t}_`; let a = `${t}_`;
for (let l = 0; l < 10; l++) for (let i = 0; i < 10; i++)
n += e[Math.floor(Math.random() * e.length)]; a += e[Math.floor(Math.random() * e.length)];
return n; return a;
} }
export { export {
m as generateId, y as generateId,
v as pluginHookImport j as pluginHookImport
}; };