Some tweaks

This commit is contained in:
Gregory Schier
2023-11-19 18:13:32 -08:00
parent a7a2608c44
commit af59695a55
5 changed files with 188 additions and 205 deletions

View File

@@ -1,3 +1,4 @@
node_modules/ node_modules/
dist/ dist/
out/
.prettierrc.cjs .prettierrc.cjs

View File

@@ -1,139 +1,124 @@
function S(e, t) { function S(e, t) {
return ( return console.log("IMPORTING Environment", e._id, e.name, JSON.stringify(e, null, 2)), {
console.log('IMPORTING Environment', e._id, e.name, JSON.stringify(e, null, 2)), id: e._id,
{ createdAt: new Date(e.created ?? Date.now()).toISOString().replace("Z", ""),
id: e._id, updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace("Z", ""),
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''), workspaceId: t,
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''), model: "environment",
workspaceId: t, name: e.name,
model: 'environment', variables: Object.entries(e.data).map(([n, a]) => ({
name: e.name, enabled: !0,
variables: Object.entries(e.data).map(([n, a]) => ({ name: n,
enabled: !0, value: `${a}`
name: n, }))
value: `${a}`, };
})),
}
);
} }
function I(e) { function I(e) {
return m(e) && e._type === 'workspace'; return m(e) && e._type === "workspace";
} }
function y(e) { function y(e) {
return m(e) && e._type === 'request_group'; return m(e) && e._type === "request_group";
} }
function g(e) { function g(e) {
return m(e) && e._type === 'request'; return m(e) && e._type === "request";
} }
function f(e) { function f(e) {
return m(e) && e._type === 'environment'; return m(e) && e._type === "environment";
} }
function m(e) { function m(e) {
return Object.prototype.toString.call(e) === '[object Object]'; return Object.prototype.toString.call(e) === "[object Object]";
} }
function w(e) { function w(e) {
return Object.prototype.toString.call(e) === '[object String]'; return Object.prototype.toString.call(e) === "[object String]";
} }
function O(e) { function O(e) {
return Object.entries(e).map(([t, n]) => ({ return Object.entries(e).map(([t, n]) => ({
enabled: !0, enabled: !0,
name: t, name: t,
value: `${n}`, value: `${n}`
})); }));
} }
function l(e) { function l(e) {
return w(e) ? e.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, '${[$2]}') : e; return w(e) ? e.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, "${[$2]}") : e;
} }
function h(e, t, n = 0) { function h(e, t, n = 0) {
var c, o; var c, o;
console.log('IMPORTING REQUEST', e._id, e.name, JSON.stringify(e, null, 2)); console.log("IMPORTING REQUEST", e._id, e.name, JSON.stringify(e, null, 2));
let a = null, let a = null, r = null;
r = null; ((c = e.body) == null ? void 0 : c.mimeType) === "application/graphql" ? (a = "graphql", r = l(e.body.text)) : ((o = e.body) == null ? void 0 : o.mimeType) === "application/json" && (a = "application/json", r = l(e.body.text));
((c = e.body) == null ? void 0 : c.mimeType) === 'application/graphql' let i = null, u = {};
? ((a = 'graphql'), (r = l(e.body.text))) return e.authentication.type === "bearer" ? (i = "bearer", u = {
: ((o = e.body) == null ? void 0 : o.mimeType) === 'application/json' && token: l(e.authentication.token)
((a = 'application/json'), (r = l(e.body.text))); }) : e.authentication.type === "basic" && (i = "basic", u = {
let i = null, username: l(e.authentication.username),
u = {}; password: l(e.authentication.password)
return ( }), {
e.authentication.type === 'bearer' id: e._id,
? ((i = 'bearer'), createdAt: new Date(e.created ?? Date.now()).toISOString().replace("Z", ""),
(u = { updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace("Z", ""),
token: l(e.authentication.token), workspaceId: t,
})) folderId: e.parentId === t ? null : e.parentId,
: e.authentication.type === 'basic' && model: "http_request",
((i = 'basic'), sortPriority: n,
(u = { name: e.name,
username: l(e.authentication.username), url: l(e.url),
password: l(e.authentication.password), body: r,
})), bodyType: a,
{ authentication: u,
id: e._id, authenticationType: i,
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''), method: e.method,
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''), headers: (e.headers ?? []).map(({ name: d, value: p, disabled: s }) => ({
workspaceId: t, enabled: !s,
folderId: e.parentId === t ? null : e.parentId, name: d,
model: 'http_request', value: p
sortPriority: n, })).filter(({ name: d, value: p }) => d !== "" || p !== "")
name: e.name, };
url: l(e.url),
body: r,
bodyType: a,
authentication: u,
authenticationType: i,
method: e.method,
headers: (e.headers ?? [])
.map(({ name: d, value: p, disabled: s }) => ({
enabled: !s,
name: d,
value: p,
}))
.filter(({ name: d, value: p }) => d !== '' || p !== ''),
}
);
} }
function _(e, t) { function _(e, t) {
return ( return console.log("IMPORTING FOLDER", e._id, e.name, JSON.stringify(e, null, 2)), {
console.log('IMPORTING FOLDER', e._id, e.name, JSON.stringify(e, null, 2)), id: e._id,
{ createdAt: new Date(e.created ?? Date.now()).toISOString().replace("Z", ""),
id: e._id, updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace("Z", ""),
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''), folderId: e.parentId === t ? null : e.parentId,
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''), workspaceId: t,
folderId: e.parentId === t ? null : e.parentId, model: "folder",
workspaceId: t, name: e.name
model: 'folder', };
name: e.name,
}
);
} }
function b(e) { function b(e) {
console.log('RUNNING INSOMNIA'); console.log("RUNNING INSOMNIA");
let t; let t;
try { try {
t = JSON.parse(e); t = JSON.parse(e);
} catch { } catch {
return; return;
} }
if (!m(t) || !Array.isArray(t.resources)) return; if (!m(t) || !Array.isArray(t.resources))
return;
const n = { const n = {
workspaces: [], workspaces: [],
requests: [], requests: [],
environments: [], environments: [],
folders: [], folders: []
}, }, a = t.resources.filter(I);
a = t.resources.filter(I);
for (const r of a) { for (const r of a) {
const i = t.resources.find((o) => f(o) && o.parentId === r._id); const i = t.resources.find(
(o) => f(o) && o.parentId === r._id
);
n.workspaces.push({ n.workspaces.push({
id: r._id, id: r._id,
createdAt: new Date(a.created ?? Date.now()).toISOString().replace('Z', ''), createdAt: new Date(a.created ?? Date.now()).toISOString().replace("Z", ""),
updatedAt: new Date(a.updated ?? Date.now()).toISOString().replace('Z', ''), updatedAt: new Date(a.updated ?? Date.now()).toISOString().replace("Z", ""),
model: 'workspace', model: "workspace",
name: r.name, name: r.name,
variables: i ? O(i.data) : [], variables: i ? O(i.data) : []
}); });
const u = t.resources.filter((o) => f(o) && o.parentId === (i == null ? void 0 : i._id)); const u = t.resources.filter(
n.environments.push(...u.map((o) => S(o, r._id))); (o) => f(o) && o.parentId === (i == null ? void 0 : i._id)
);
n.environments.push(
...u.map((o) => S(o, r._id))
);
const c = (o) => { const c = (o) => {
const d = t.resources.filter((s) => s.parentId === o); const d = t.resources.filter((s) => s.parentId === o);
let p = 0; let p = 0;
@@ -142,11 +127,8 @@ function b(e) {
}; };
c(r._id); c(r._id);
} }
return ( return n.requests = n.requests.filter(Boolean), n.environments = n.environments.filter(Boolean), n.workspaces = n.workspaces.filter(Boolean), { resources: n };
(n.requests = n.requests.filter(Boolean)),
(n.environments = n.environments.filter(Boolean)),
(n.workspaces = n.workspaces.filter(Boolean)),
{ resources: n }
);
} }
export { b as pluginHookImport }; export {
b as pluginHookImport
};

View File

@@ -1,130 +1,126 @@
const f = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json', const f = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", b = "https://schema.getpostman.com/json/collection/v2.0.0/collection.json", w = [b, f];
b = 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
w = [b, f];
function A(t) { function A(t) {
const e = m(t); const e = m(t);
if (e == null) return; if (e == null)
return;
const r = s(e.info); const r = s(e.info);
if (!w.includes(r.schema) || !Array.isArray(e.item)) return; if (!w.includes(r.schema) || !Array.isArray(e.item))
return;
const a = { const a = {
workspaces: [], workspaces: [],
environments: [], environments: [],
requests: [], requests: [],
folders: [], folders: []
}, }, c = {
c = { model: "workspace",
model: 'workspace', id: "wrk_0",
id: 'wrk_0', name: r.name || "Postman Import",
name: r.name || 'Postman Import', description: r.description || ""
description: r.description || '', };
};
a.workspaces.push(c); a.workspaces.push(c);
const p = (o, l = null) => { const p = (o, l = null) => {
if (typeof o.name == 'string' && Array.isArray(o.item)) { if (typeof o.name == "string" && Array.isArray(o.item)) {
const n = { const n = {
model: 'folder', model: "folder",
workspaceId: c.id, workspaceId: c.id,
id: `fld_${a.folders.length}`, id: `fld_${a.folders.length}`,
name: o.name, name: o.name,
folderId: l, folderId: l
}; };
a.folders.push(n); a.folders.push(n);
for (const i of o.item) p(i, n.id); for (const i of o.item)
} else if (typeof o.name == 'string' && 'request' in o) { p(i, n.id);
const n = s(o.request), } else if (typeof o.name == "string" && "request" in o) {
i = T(n.body), const n = s(o.request), i = T(n.body), u = g(n.auth), y = {
u = g(n.auth), model: "http_request",
y = { id: `req_${a.requests.length}`,
model: 'http_request', workspaceId: c.id,
id: `req_${a.requests.length}`, folderId: l,
workspaceId: c.id, name: o.name,
folderId: l, method: n.method || "GET",
name: o.name, url: typeof n.url == "string" ? n.url : s(n.url).raw,
method: n.method || 'GET', body: i.body,
url: typeof n.url == 'string' ? n.url : s(n.url).raw, bodyType: i.bodyType,
body: i.body, authentication: u.authentication,
bodyType: i.bodyType, authenticationType: u.authenticationType,
authentication: u.authentication, headers: [
authenticationType: u.authenticationType, ...i.headers,
headers: [ ...u.headers,
...i.headers, ...h(n.header).map((d) => ({
...u.headers, name: d.key,
...h(n.header).map((d) => ({ value: d.value,
name: d.key, enabled: !d.disabled
value: d.value, }))
enabled: !d.disabled, ]
})), };
],
};
a.requests.push(y); a.requests.push(y);
} else console.log('Unknown item', o, l); } else
console.log("Unknown item", o, l);
}; };
for (const o of e.item) p(o); for (const o of e.item)
p(o);
return { resources: a }; return { resources: a };
} }
function g(t) { function g(t) {
const e = s(t); const e = s(t);
return 'basic' in e return "basic" in e ? {
? { headers: [],
headers: [], authenticationType: "basic",
authenticationType: 'basic', authentication: {
authentication: { username: e.basic.username || "",
username: e.basic.username || '', password: e.basic.password || ""
password: e.basic.password || '', }
}, } : { headers: [], authenticationType: null, authentication: {} };
}
: { headers: [], authenticationType: null, authentication: {} };
} }
function T(t) { function T(t) {
const e = s(t); const e = s(t);
return 'graphql' in e return "graphql" in e ? {
? { headers: [
headers: [ {
{ name: "Content-Type",
name: 'Content-Type', value: "application/json",
value: 'application/json', enabled: !0
enabled: !0,
},
],
bodyType: 'graphql',
body: {
text: JSON.stringify(
{ query: e.graphql.query, variables: m(e.graphql.variables) },
null,
2,
),
},
} }
: 'formdata' in e ],
? { bodyType: "graphql",
headers: [ body: {
{ text: JSON.stringify(
name: 'Content-Type', { query: e.graphql.query, variables: m(e.graphql.variables) },
value: 'application/x-www-form-urlencoded', null,
enabled: !0, 2
}, )
], }
bodyType: 'application/x-www-form-urlencoded', } : "formdata" in e ? {
body: { headers: [
form: h(e.formdata).map((r) => ({ {
enabled: !r.disabled, name: "Content-Type",
name: r.key ?? '', value: "application/x-www-form-urlencoded",
value: r.value ?? '', enabled: !0
})),
},
} }
: { headers: [], bodyType: null, body: {} }; ],
bodyType: "application/x-www-form-urlencoded",
body: {
form: h(e.formdata).map((r) => ({
enabled: !r.disabled,
name: r.key ?? "",
value: r.value ?? ""
}))
}
} : { headers: [], bodyType: null, body: {} };
} }
function m(t) { function m(t) {
try { try {
return s(JSON.parse(t)); return s(JSON.parse(t));
} catch {} } catch {
}
return null; return null;
} }
function s(t) { function s(t) {
return Object.prototype.toString.call(t) === '[object Object]' ? t : {}; return Object.prototype.toString.call(t) === "[object Object]" ? t : {};
} }
function h(t) { function h(t) {
return Object.prototype.toString.call(t) === '[object Array]' ? t : []; return Object.prototype.toString.call(t) === "[object Array]" ? t : [];
} }
export { A as pluginHookImport }; export {
A as pluginHookImport
};

View File

@@ -5,9 +5,13 @@ function u(r) {
} catch { } catch {
return; return;
} }
if (t(e) && e.yaakSchema === 1) return { resources: e.resources }; if (t(e) && e.yaakSchema === 1)
return { resources: e.resources };
} }
function t(r) { function t(r) {
return Object.prototype.toString.call(r) === '[object Object]'; return Object.prototype.toString.call(r) === "[object Object]";
} }
export { t as isJSObject, u as pluginHookImport }; export {
t as isJSObject,
u as pluginHookImport
};

View File

@@ -13,7 +13,7 @@ use std::fs::{create_dir_all, File};
use std::process::exit; use std::process::exit;
use fern::colors::ColoredLevelConfig; use fern::colors::ColoredLevelConfig;
use log::{debug, error, info}; use log::{debug, info, warn};
use rand::random; use rand::random;
use serde::Serialize; use serde::Serialize;
use sqlx::{Pool, Sqlite, SqlitePool}; use sqlx::{Pool, Sqlite, SqlitePool};
@@ -749,7 +749,7 @@ fn main() {
debug!("Updater downloaded"); debug!("Updater downloaded");
} }
tauri::UpdaterEvent::Error(e) => { tauri::UpdaterEvent::Error(e) => {
error!("Updater error: {:?}", e); warn!("Updater received error: {:?}", e);
} }
_ => {} _ => {}
}, },