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
+1
View File
@@ -1,3 +1,4 @@
node_modules/ node_modules/
dist/ dist/
out/
.prettierrc.cjs .prettierrc.cjs
@@ -1,79 +1,64 @@
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, id: e._id,
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''), createdAt: new Date(e.created ?? Date.now()).toISOString().replace("Z", ""),
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''), updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace("Z", ""),
workspaceId: t, workspaceId: t,
model: 'environment', model: "environment",
name: e.name, name: e.name,
variables: Object.entries(e.data).map(([n, a]) => ({ variables: Object.entries(e.data).map(([n, a]) => ({
enabled: !0, enabled: !0,
name: n, name: n,
value: `${a}`, 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,
u = {};
return (
e.authentication.type === 'bearer'
? ((i = 'bearer'),
(u = {
token: l(e.authentication.token),
}))
: e.authentication.type === 'basic' &&
((i = 'basic'),
(u = {
username: l(e.authentication.username), username: l(e.authentication.username),
password: l(e.authentication.password), password: l(e.authentication.password)
})), }), {
{
id: e._id, id: e._id,
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''), createdAt: new Date(e.created ?? Date.now()).toISOString().replace("Z", ""),
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''), updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace("Z", ""),
workspaceId: t, workspaceId: t,
folderId: e.parentId === t ? null : e.parentId, folderId: e.parentId === t ? null : e.parentId,
model: 'http_request', model: "http_request",
sortPriority: n, sortPriority: n,
name: e.name, name: e.name,
url: l(e.url), url: l(e.url),
@@ -82,58 +67,58 @@ function h(e, t, n = 0) {
authentication: u, authentication: u,
authenticationType: i, authenticationType: i,
method: e.method, method: e.method,
headers: (e.headers ?? []) headers: (e.headers ?? []).map(({ name: d, value: p, disabled: s }) => ({
.map(({ name: d, value: p, disabled: s }) => ({
enabled: !s, enabled: !s,
name: d, name: d,
value: p, value: p
})) })).filter(({ name: d, value: p }) => d !== "" || 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, id: e._id,
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''), createdAt: new Date(e.created ?? Date.now()).toISOString().replace("Z", ""),
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''), updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace("Z", ""),
folderId: e.parentId === t ? null : e.parentId, folderId: e.parentId === t ? null : e.parentId,
workspaceId: t, workspaceId: t,
model: 'folder', model: "folder",
name: e.name, 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
};
+58 -62
View File
@@ -1,47 +1,44 @@
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 = {
model: 'http_request',
id: `req_${a.requests.length}`, id: `req_${a.requests.length}`,
workspaceId: c.id, workspaceId: c.id,
folderId: l, folderId: l,
name: o.name, name: o.name,
method: n.method || 'GET', method: n.method || "GET",
url: typeof n.url == 'string' ? n.url : s(n.url).raw, url: typeof n.url == "string" ? n.url : s(n.url).raw,
body: i.body, body: i.body,
bodyType: i.bodyType, bodyType: i.bodyType,
authentication: u.authentication, authentication: u.authentication,
@@ -52,79 +49,78 @@ function A(t) {
...h(n.header).map((d) => ({ ...h(n.header).map((d) => ({
name: d.key, name: d.key,
value: d.value, value: d.value,
enabled: !d.disabled, 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', bodyType: "graphql",
body: { body: {
text: JSON.stringify( text: JSON.stringify(
{ query: e.graphql.query, variables: m(e.graphql.variables) }, { query: e.graphql.query, variables: m(e.graphql.variables) },
null, null,
2, 2
), )
},
} }
: 'formdata' in e } : "formdata" in e ? {
? {
headers: [ headers: [
{ {
name: 'Content-Type', name: "Content-Type",
value: 'application/x-www-form-urlencoded', value: "application/x-www-form-urlencoded",
enabled: !0, enabled: !0
}, }
], ],
bodyType: 'application/x-www-form-urlencoded', bodyType: "application/x-www-form-urlencoded",
body: { body: {
form: h(e.formdata).map((r) => ({ form: h(e.formdata).map((r) => ({
enabled: !r.disabled, enabled: !r.disabled,
name: r.key ?? '', name: r.key ?? "",
value: r.value ?? '', value: r.value ?? ""
})), }))
},
} }
: { headers: [], bodyType: null, body: {} }; } : { 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
};
+7 -3
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
};
+2 -2
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);
} }
_ => {} _ => {}
}, },