Some postman import improvements

This commit is contained in:
Gregory Schier
2023-11-11 10:43:11 -08:00
parent 8381104302
commit b519bff3d6
9 changed files with 464 additions and 145 deletions

View File

@@ -1,12 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Dev Desktop" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="tauri-dev" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>

299
package-lock.json generated
View File

@@ -67,6 +67,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.21",
"postcss-nesting": "^11.2.1",
"prettier": "^2.8.4",
@@ -4688,6 +4689,12 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"dev": true
},
"node_modules/graphemer": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
@@ -4815,6 +4822,12 @@
"react-is": "^16.7.0"
}
},
"node_modules/hosted-git-info": {
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true
},
"node_modules/human-signals": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz",
@@ -5377,6 +5390,12 @@
"integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==",
"dev": true
},
"node_modules/json-parse-better-errors": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
"integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==",
"dev": true
},
"node_modules/json-parse-even-better-errors": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
@@ -5534,6 +5553,43 @@
"node": ">=16.0.0"
}
},
"node_modules/load-json-file": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz",
"integrity": "sha512-Kx8hMakjX03tiGTLAIdJ+lL0htKnXjEZN6hk/tozf/WOuYGdZBJrZ+rCJRbVCugsjB3jMLn9746NsQIf5VjBMw==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.1.2",
"parse-json": "^4.0.0",
"pify": "^3.0.0",
"strip-bom": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/load-json-file/node_modules/parse-json": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz",
"integrity": "sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==",
"dev": true,
"dependencies": {
"error-ex": "^1.3.1",
"json-parse-better-errors": "^1.0.1"
},
"engines": {
"node": ">=4"
}
},
"node_modules/load-json-file/node_modules/pify": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
"integrity": "sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/local-pkg": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.3.tgz",
@@ -5659,6 +5715,15 @@
"resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.14.tgz",
"integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow=="
},
"node_modules/memorystream": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz",
"integrity": "sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==",
"dev": true,
"engines": {
"node": ">= 0.10.0"
}
},
"node_modules/merge-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
@@ -5793,12 +5858,39 @@
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
"dev": true
},
"node_modules/nice-try": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
"dev": true
},
"node_modules/node-releases": {
"version": "2.0.13",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
"integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==",
"dev": true
},
"node_modules/normalize-package-data": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz",
"integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==",
"dev": true,
"dependencies": {
"hosted-git-info": "^2.1.4",
"resolve": "^1.10.0",
"semver": "2 || 3 || 4 || 5",
"validate-npm-package-license": "^3.0.1"
}
},
"node_modules/normalize-package-data/node_modules/semver": {
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
"integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==",
"dev": true,
"bin": {
"semver": "bin/semver"
}
},
"node_modules/normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
@@ -5816,6 +5908,110 @@
"node": ">=0.10.0"
}
},
"node_modules/npm-run-all": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz",
"integrity": "sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==",
"dev": true,
"dependencies": {
"ansi-styles": "^3.2.1",
"chalk": "^2.4.1",
"cross-spawn": "^6.0.5",
"memorystream": "^0.3.1",
"minimatch": "^3.0.4",
"pidtree": "^0.3.0",
"read-pkg": "^3.0.0",
"shell-quote": "^1.6.1",
"string.prototype.padend": "^3.0.0"
},
"bin": {
"npm-run-all": "bin/npm-run-all/index.js",
"run-p": "bin/run-p/index.js",
"run-s": "bin/run-s/index.js"
},
"engines": {
"node": ">= 4"
}
},
"node_modules/npm-run-all/node_modules/cross-spawn": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
"integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==",
"dev": true,
"dependencies": {
"nice-try": "^1.0.4",
"path-key": "^2.0.1",
"semver": "^5.5.0",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
},
"engines": {
"node": ">=4.8"
}
},
"node_modules/npm-run-all/node_modules/path-key": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz",
"integrity": "sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/npm-run-all/node_modules/pidtree": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.3.1.tgz",
"integrity": "sha512-qQbW94hLHEqCg7nhby4yRC7G2+jYHY4Rguc2bjw7Uug4GIJuu1tvf2uHaZv5Q8zdt+WKJ6qK1FOI6amaWUo5FA==",
"dev": true,
"bin": {
"pidtree": "bin/pidtree.js"
},
"engines": {
"node": ">=0.10"
}
},
"node_modules/npm-run-all/node_modules/semver": {
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
"integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==",
"dev": true,
"bin": {
"semver": "bin/semver"
}
},
"node_modules/npm-run-all/node_modules/shebang-command": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
"integrity": "sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==",
"dev": true,
"dependencies": {
"shebang-regex": "^1.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/npm-run-all/node_modules/shebang-regex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz",
"integrity": "sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/npm-run-all/node_modules/which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"dev": true,
"dependencies": {
"isexe": "^2.0.0"
},
"bin": {
"which": "bin/which"
}
},
"node_modules/npm-run-path": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz",
@@ -6620,6 +6816,41 @@
"pify": "^2.3.0"
}
},
"node_modules/read-pkg": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz",
"integrity": "sha512-BLq/cCO9two+lBgiTYNqD6GdtK8s4NpaWrl6/rCO9w0TUS8oJl7cmToOZfRYllKTISY6nt1U7jQ53brmKqY6BA==",
"dev": true,
"dependencies": {
"load-json-file": "^4.0.0",
"normalize-package-data": "^2.3.2",
"path-type": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/read-pkg/node_modules/path-type": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-3.0.0.tgz",
"integrity": "sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==",
"dev": true,
"dependencies": {
"pify": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/read-pkg/node_modules/pify": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
"integrity": "sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/readdirp": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
@@ -7003,6 +7234,15 @@
"node": ">=8"
}
},
"node_modules/shell-quote": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz",
"integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==",
"dev": true,
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
@@ -7094,6 +7334,38 @@
"integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==",
"deprecated": "Please use @jridgewell/sourcemap-codec instead"
},
"node_modules/spdx-correct": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz",
"integrity": "sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==",
"dev": true,
"dependencies": {
"spdx-expression-parse": "^3.0.0",
"spdx-license-ids": "^3.0.0"
}
},
"node_modules/spdx-exceptions": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz",
"integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==",
"dev": true
},
"node_modules/spdx-expression-parse": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz",
"integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==",
"dev": true,
"dependencies": {
"spdx-exceptions": "^2.1.0",
"spdx-license-ids": "^3.0.0"
}
},
"node_modules/spdx-license-ids": {
"version": "3.0.16",
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.16.tgz",
"integrity": "sha512-eWN+LnM3GR6gPu35WxNgbGl8rmY1AEmoMDvL/QD6zYmPWgywxWqJWNdLGT+ke8dKNWrcYgYjPpG5gbTfghP8rw==",
"dev": true
},
"node_modules/stack-generator": {
"version": "2.0.10",
"resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz",
@@ -7219,6 +7491,23 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/string.prototype.padend": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/string.prototype.padend/-/string.prototype.padend-3.1.5.tgz",
"integrity": "sha512-DOB27b/2UTTD+4myKUFh+/fXWcu/UDyASIXfg+7VzoCNNGOfWvoyU/x5pvVHr++ztyt/oSYI1BcWBBG/hmlNjA==",
"dev": true,
"dependencies": {
"call-bind": "^1.0.2",
"define-properties": "^1.2.0",
"es-abstract": "^1.22.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/string.prototype.trim": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.8.tgz",
@@ -7837,6 +8126,16 @@
"uuid": "dist/bin/uuid"
}
},
"node_modules/validate-npm-package-license": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",
"integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==",
"dev": true,
"dependencies": {
"spdx-correct": "^3.0.0",
"spdx-expression-parse": "^3.0.0"
}
},
"node_modules/vite": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/vite/-/vite-4.5.0.tgz",

View File

@@ -4,6 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "run-s build:plugins tauri-dev",
"tauri-dev": "YAAK_ENV=development tauri dev --no-watch --config src-tauri/tauri-dev.conf.json",
"tauri-build": "tauri build",
"tauri": "tauri",
@@ -13,6 +14,10 @@
"build:icon:release": "tauri icon design/icon.png --output src-tauri/icons/release",
"build:icon:dev": "tauri icon design/icon-dev.png --output src-tauri/icons/dev",
"build:frontend": "vite build",
"build:plugins": "run-p build:plugin:importer-insomnia build:plugin:importer-postman build:plugin:importer-yaak",
"build:plugin:importer-insomnia": "cd src-tauri/plugins/importer-insomnia && vite build",
"build:plugin:importer-postman": "cd src-tauri/plugins/importer-postman && vite build",
"build:plugin:importer-yaak": "cd src-tauri/plugins/importer-yaak && vite build",
"test": "vitest",
"coverage": "vitest run --coverage",
"prepare": "husky install"
@@ -77,6 +82,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.21",
"postcss-nesting": "^11.2.1",
"prettier": "^2.8.4",

View File

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

View File

@@ -1,15 +0,0 @@
/**
* Import an Insomnia workspace object.
* @param {Object} w - The workspace object to import.
*/
export function importWorkspace(w, variables) {
console.log('IMPORTING Workspace', w._id, w.name, JSON.stringify(w, null, 2));
return {
id: w._id,
createdAt: new Date(w.created ?? Date.now()).toISOString().replace('Z', ''),
updatedAt: new Date(w.updated ?? Date.now()).toISOString().replace('Z', ''),
model: 'workspace',
name: w.name,
variables,
};
}

View File

@@ -1,6 +1,5 @@
import { importEnvironment } from './importers/environment.js';
import { importRequest } from './importers/request.js';
import { importWorkspace } from './importers/workspace.js';
import {
isEnvironment,
isJSObject,
@@ -12,16 +11,16 @@ import { parseVariables } from './helpers/variables.js';
import { importFolder } from './importers/folder.js';
export function pluginHookImport(contents) {
console.log('RUNNING INSOMNIA');
let parsed;
try {
parsed = JSON.parse(contents);
} catch (e) {
return undefined;
return;
}
if (!isJSObject(parsed)) {
return undefined;
}
if (!isJSObject(parsed)) return;
if (!Array.isArray(parsed.resources)) return;
const resources = {
workspaces: [],
@@ -36,12 +35,14 @@ export function pluginHookImport(contents) {
const baseEnvironment = parsed.resources.find(
(r) => isEnvironment(r) && r.parentId === workspaceToImport._id,
);
resources.workspaces.push(
importWorkspace(
workspaceToImport,
baseEnvironment ? parseVariables(baseEnvironment.data) : [],
),
);
resources.workspaces.push({
id: workspaceToImport._id,
createdAt: new Date(workspacesToImport.created ?? Date.now()).toISOString().replace('Z', ''),
updatedAt: new Date(workspacesToImport.updated ?? Date.now()).toISOString().replace('Z', ''),
model: 'workspace',
name: workspaceToImport.name,
variables: baseEnvironment ? parseVariables(baseEnvironment.data) : [],
});
const environmentsToImport = parsed.resources.filter(
(r) => isEnvironment(r) && r.parentId === baseEnvironment?._id,
);

View File

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

View File

@@ -1,6 +1,8 @@
import { Environment, Folder, HttpRequest, Workspace } from '../../../../src-web/lib/models';
const POSTMAN_2_1_0_SCHEMA = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json';
const POSTMAN_2_0_0_SCHEMA = 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json';
const VALID_SCHEMAS = [POSTMAN_2_0_0_SCHEMA, POSTMAN_2_1_0_SCHEMA];
type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
@@ -16,7 +18,8 @@ export function pluginHookImport(contents: string): { resources: ExportResources
if (root == null) return;
const info = toRecord(root.info);
if (info.schema !== POSTMAN_2_1_0_SCHEMA || !Array.isArray(root.item)) {
const isValidSchema = VALID_SCHEMAS.includes(info.schema);
if (!isValidSchema || !Array.isArray(root.item)) {
return;
}
@@ -51,6 +54,7 @@ export function pluginHookImport(contents: string): { resources: ExportResources
} else if (typeof v.name === 'string' && 'request' in v) {
const r = toRecord(v.request);
const bodyPatch = importBody(r.body);
const authPatch = importAuth(r.auth);
const request: ExportResources['requests'][0] = {
model: 'http_request',
id: `req_${exportResources.requests.length}`,
@@ -58,13 +62,22 @@ export function pluginHookImport(contents: string): { resources: ExportResources
folderId,
name: v.name,
method: r.method || 'GET',
url: toRecord(r.url).raw,
headers: [...bodyPatch.headers, ...toArray(r.header).map(importHeader)],
url: typeof r.url === 'string' ? r.url : toRecord(r.url).raw,
body: bodyPatch.body,
bodyType: bodyPatch.bodyType,
// TODO: support auth
// ...importAuth(r.auth),
authentication: authPatch.authentication,
authenticationType: authPatch.authenticationType,
headers: [
...bodyPatch.headers,
...authPatch.headers,
...toArray(r.header).map((h) => {
return {
name: h.key,
value: h.value,
enabled: !h.disabled,
};
}),
],
};
exportResources.requests.push(request);
} else {
@@ -79,10 +92,23 @@ export function pluginHookImport(contents: string): { resources: ExportResources
return { resources: exportResources };
}
function importHeader(h: any): HttpRequest['headers'][0] {
const header = toRecord(h);
// TODO: support header
return { name: header.key, value: header.value, enabled: true };
function importAuth(
rawAuth: any,
): Pick<HttpRequest, 'authentication' | 'authenticationType' | 'headers'> {
const auth = toRecord(rawAuth);
if ('basic' in auth) {
return {
headers: [],
authenticationType: 'basic',
authentication: {
username: auth.basic.username || '',
password: auth.basic.password || '',
},
};
} else {
// TODO: support other auth types
return { headers: [], authenticationType: null, authentication: {} };
}
}
function importBody(rawBody: any): Pick<HttpRequest, 'body' | 'bodyType' | 'headers'> {

View File

@@ -1,5 +1,4 @@
import type { CompletionContext } from '@codemirror/autocomplete';
import { w } from '@tauri-apps/api/clipboard-79413165';
const openTag = '${[ ';
const closeTag = ' ]}';
@@ -12,8 +11,8 @@ export interface TwigCompletionConfig {
options: TwigCompletionOption[];
}
const MIN_MATCH_VAR = 2;
const MIN_MATCH_NAME = 1;
const MIN_MATCH_VAR = 1;
const MIN_MATCH_NAME = 2;
export function twigCompletion({ options }: TwigCompletionConfig) {
return function completions(context: CompletionContext) {