mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 23:41:18 +02:00
Vite to bundle insomnia plugin
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,100 +0,0 @@
|
|||||||
{
|
|
||||||
"_type": "export",
|
|
||||||
"__export_format": 4,
|
|
||||||
"__export_date": "2023-11-01T23:41:02.844Z",
|
|
||||||
"__export_source": "insomnia.desktop.app:v8.3.0",
|
|
||||||
"resources": [
|
|
||||||
{
|
|
||||||
"_id": "req_c8ae891b0fe549a4a530a75da59b6e34",
|
|
||||||
"parentId": "wrk_ea69a78d6a0540f583d2ec80666a1724",
|
|
||||||
"modified": 1698767088880,
|
|
||||||
"created": 1698767077168,
|
|
||||||
"url": "https://schier.co",
|
|
||||||
"name": "My Request",
|
|
||||||
"description": "",
|
|
||||||
"method": "GET",
|
|
||||||
"body": {},
|
|
||||||
"parameters": [],
|
|
||||||
"headers": [{ "name": "User-Agent", "value": "insomnia/8.3.0" }],
|
|
||||||
"authentication": {},
|
|
||||||
"metaSortKey": -1698767077168,
|
|
||||||
"isPrivate": false,
|
|
||||||
"settingStoreCookies": true,
|
|
||||||
"settingSendCookies": true,
|
|
||||||
"settingDisableRenderRequestBody": false,
|
|
||||||
"settingEncodeUrl": true,
|
|
||||||
"settingRebuildPath": true,
|
|
||||||
"settingFollowRedirects": "global",
|
|
||||||
"_type": "request"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"_id": "wrk_ea69a78d6a0540f583d2ec80666a1724",
|
|
||||||
"parentId": null,
|
|
||||||
"modified": 1698767073768,
|
|
||||||
"created": 1698767068649,
|
|
||||||
"name": "Hello World",
|
|
||||||
"description": "",
|
|
||||||
"scope": "collection",
|
|
||||||
"_type": "workspace"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"_id": "env_90b3abd7ed857fd535396167018da33932100672",
|
|
||||||
"parentId": "wrk_ea69a78d6a0540f583d2ec80666a1724",
|
|
||||||
"modified": 1698881852559,
|
|
||||||
"created": 1698767068650,
|
|
||||||
"name": "Base Environment",
|
|
||||||
"data": { "base": true },
|
|
||||||
"dataPropertyOrder": { "&": ["base"] },
|
|
||||||
"color": null,
|
|
||||||
"isPrivate": false,
|
|
||||||
"metaSortKey": 1698767068650,
|
|
||||||
"_type": "environment"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"_id": "jar_90b3abd7ed857fd535396167018da33932100672",
|
|
||||||
"parentId": "wrk_ea69a78d6a0540f583d2ec80666a1724",
|
|
||||||
"modified": 1698767090390,
|
|
||||||
"created": 1698767068651,
|
|
||||||
"name": "Default Jar",
|
|
||||||
"cookies": [
|
|
||||||
{
|
|
||||||
"key": "_gorilla_csrf",
|
|
||||||
"value": "MTY5ODc2NzA5MHxJa1Z1U0RCVVMzcDJhbEJFWkd0Q09WVkllbXBMVlhSd1VtaGFkVlpsVVhobVNVNDVTV2hDWmpFd1JtTTlJZ289fPkab2rsnQwWmJi-pCbg5Wz4O_6csc29ZcYOdB0tOLtD",
|
|
||||||
"expires": "2023-11-07T15:44:50.000Z",
|
|
||||||
"maxAge": 604800,
|
|
||||||
"domain": "schier.co",
|
|
||||||
"path": "/",
|
|
||||||
"httpOnly": true,
|
|
||||||
"hostOnly": true,
|
|
||||||
"creation": "2023-10-31T15:44:50.390Z",
|
|
||||||
"lastAccessed": "2023-10-31T15:44:50.390Z",
|
|
||||||
"sameSite": "lax",
|
|
||||||
"id": "672286917061701"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"_type": "cookie_jar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"_id": "env_d04deba50c2f44b0b9bd01c53efebff4",
|
|
||||||
"parentId": "env_90b3abd7ed857fd535396167018da33932100672",
|
|
||||||
"modified": 1698882026143,
|
|
||||||
"created": 1698881855600,
|
|
||||||
"name": "Sub Environment",
|
|
||||||
"data": {
|
|
||||||
"string": "string",
|
|
||||||
"bool": true,
|
|
||||||
"number": 123,
|
|
||||||
"object": { "foo": "bar" },
|
|
||||||
"array": [1, 2, 3]
|
|
||||||
},
|
|
||||||
"dataPropertyOrder": {
|
|
||||||
"&": ["string", "bool", "number", "object", "array"],
|
|
||||||
"&~|object": ["foo"]
|
|
||||||
},
|
|
||||||
"color": null,
|
|
||||||
"isPrivate": false,
|
|
||||||
"metaSortKey": 1698881855600,
|
|
||||||
"_type": "environment"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
export function parseVariables(data) {
|
|
||||||
return Object.entries(data).map(([name, value]) => ({
|
|
||||||
enabled: true,
|
|
||||||
name,
|
|
||||||
value: `${value}`,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
@@ -17,3 +17,7 @@ export function isEnvironment(obj) {
|
|||||||
export function isJSObject(obj) {
|
export function isJSObject(obj) {
|
||||||
return Object.prototype.toString.call(obj) === '[object Object]';
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isJSString(obj) {
|
||||||
|
return Object.prototype.toString.call(obj) === '[object String]';
|
||||||
|
}
|
||||||
18
src-tauri/plugins/insomnia-importer/src/helpers/variables.js
Normal file
18
src-tauri/plugins/insomnia-importer/src/helpers/variables.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { isJSString } from './types.js';
|
||||||
|
|
||||||
|
export function parseVariables(data) {
|
||||||
|
return Object.entries(data).map(([name, value]) => ({
|
||||||
|
enabled: true,
|
||||||
|
name,
|
||||||
|
value: `${value}`,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Insomnia syntax to Yaak syntax
|
||||||
|
* @param {string} variable - Text to convert
|
||||||
|
*/
|
||||||
|
export function convertSyntax(variable) {
|
||||||
|
if (!isJSString(variable)) return variable;
|
||||||
|
return variable.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, '${[$2]}');
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { convertSyntax } from '../helpers/variables.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import an Insomnia request object.
|
* Import an Insomnia request object.
|
||||||
* @param {Object} r - The request object to import.
|
* @param {Object} r - The request object to import.
|
||||||
@@ -6,20 +8,32 @@
|
|||||||
*/
|
*/
|
||||||
export function importRequest(r, workspaceId, sortPriority = 0) {
|
export function importRequest(r, workspaceId, sortPriority = 0) {
|
||||||
console.log('IMPORTING REQUEST', r._id, r.name, JSON.stringify(r, null, 2));
|
console.log('IMPORTING REQUEST', r._id, r.name, JSON.stringify(r, null, 2));
|
||||||
|
|
||||||
let bodyType = null;
|
let bodyType = null;
|
||||||
let body = null;
|
let body = null;
|
||||||
if (r.body?.mimeType === 'application/graphql') {
|
if (r.body?.mimeType === 'application/graphql') {
|
||||||
bodyType = 'graphql';
|
bodyType = 'graphql';
|
||||||
body = r.body.text;
|
body = convertSyntax(r.body.text);
|
||||||
|
} else if (r.body?.mimeType === 'application/json') {
|
||||||
|
bodyType = 'application/json';
|
||||||
|
body = convertSyntax(r.body.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
let authenticationType = null;
|
let authenticationType = null;
|
||||||
let authentication = {};
|
let authentication = {};
|
||||||
if (r.authentication.type === 'bearer') {
|
if (r.authentication.type === 'bearer') {
|
||||||
authenticationType = 'bearer';
|
authenticationType = 'bearer';
|
||||||
authentication = {
|
authentication = {
|
||||||
token: r.authentication.token,
|
token: convertSyntax(r.authentication.token),
|
||||||
|
};
|
||||||
|
} else if (r.authentication.type === 'basic') {
|
||||||
|
authenticationType = 'basic';
|
||||||
|
authentication = {
|
||||||
|
username: convertSyntax(r.authentication.username),
|
||||||
|
password: convertSyntax(r.authentication.password),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: r._id,
|
id: r._id,
|
||||||
createdAt: new Date(r.created ?? Date.now()).toISOString().replace('Z', ''),
|
createdAt: new Date(r.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
@@ -29,7 +43,7 @@ export function importRequest(r, workspaceId, sortPriority = 0) {
|
|||||||
model: 'http_request',
|
model: 'http_request',
|
||||||
sortPriority,
|
sortPriority,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
url: r.url,
|
url: convertSyntax(r.url),
|
||||||
body,
|
body,
|
||||||
bodyType,
|
bodyType,
|
||||||
authentication,
|
authentication,
|
||||||
12
src-tauri/plugins/insomnia-importer/vite.config.js
Normal file
12
src-tauri/plugins/insomnia-importer/vite.config.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { resolve } from 'path';
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
build: {
|
||||||
|
lib: {
|
||||||
|
entry: resolve(__dirname, 'src/index.js'),
|
||||||
|
fileName: 'index',
|
||||||
|
formats: ['es'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -97,7 +97,7 @@ fn run_plugin(
|
|||||||
.resolve_resource("plugins")
|
.resolve_resource("plugins")
|
||||||
.expect("failed to resolve plugin directory resource")
|
.expect("failed to resolve plugin directory resource")
|
||||||
.join(plugin_name);
|
.join(plugin_name);
|
||||||
let plugin_index_file = plugin_dir.join("index.js");
|
let plugin_index_file = plugin_dir.join("dist/index.js");
|
||||||
|
|
||||||
println!("Plugin dir={:?} file={:?}", plugin_dir, plugin_index_file);
|
println!("Plugin dir={:?} file={:?}", plugin_dir, plugin_index_file);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user