diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 1e39adf7..06c44947 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -12,7 +12,7 @@ module.exports = { parserOptions: { project: ["./tsconfig.json"] }, - ignorePatterns: ["src-tauri/**/*"], + ignorePatterns: ["src-tauri/**/*", "plugins/**/*"], settings: { react: { version: "detect" diff --git a/plugins/insomnia-importer/index.js b/plugins/insomnia-importer/index.js deleted file mode 100644 index 6bf1f1e1..00000000 --- a/plugins/insomnia-importer/index.js +++ /dev/null @@ -1,50 +0,0 @@ -import { importEnvironment } from './importers/environment.js'; -import { importRequest } from './importers/request.js'; -import { importWorkspace } from './importers/workspace.js'; - -const TYPES = { - workspace: 'workspace', - request: 'request', - environment: 'environment', -}; - -export function pluginHookImport(contents) { - const parsed = JSON.parse(contents); - if (!isObject(parsed)) { - return; - } - - const { _type, __export_format } = parsed; - if (_type !== 'export' || __export_format !== 4 || !Array.isArray(parsed.resources)) { - return; - } - - const resources = { - workspaces: [], - requests: [], - environments: [], - }; - - for (const v of parsed.resources) { - if (v._type === TYPES.workspace) { - resources.workspaces.push(importWorkspace(v)); - } else if (v._type === TYPES.environment) { - resources.environments.push(importEnvironment(v)); - } else if (v._type === TYPES.request) { - resources.requests.push(importRequest(v)); - } else { - console.log('UNKNOWN TYPE', v._type, JSON.stringify(v, null, 2)); - } - } - - // Filter out any `null` values - resources.requests = resources.requests.filter(Boolean); - resources.environments = resources.environments.filter(Boolean); - resources.workspaces = resources.workspaces.filter(Boolean); - - return resources; -} - -function isObject(obj) { - return Object.prototype.toString.call(obj) === '[object Object]'; -} diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 768dc993..5fdfca15 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -39,7 +39,7 @@ tauri = { version = "1.3", features = [ "shell-open", "system-tray", "updater", - "window-start-dragging", + "window-start-dragging", "dialog-open", ] } tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } diff --git a/plugins/hello-world/greet.js b/src-tauri/plugins/hello-world/greet.js similarity index 100% rename from plugins/hello-world/greet.js rename to src-tauri/plugins/hello-world/greet.js diff --git a/plugins/hello-world/index.js b/src-tauri/plugins/hello-world/index.js similarity index 100% rename from plugins/hello-world/index.js rename to src-tauri/plugins/hello-world/index.js diff --git a/src-tauri/plugins/insomnia-importer/Insomnia_bigger.json b/src-tauri/plugins/insomnia-importer/Insomnia_bigger.json new file mode 100644 index 00000000..fb0168e4 --- /dev/null +++ b/src-tauri/plugins/insomnia-importer/Insomnia_bigger.json @@ -0,0 +1,1133 @@ +{ + "_type": "export", + "__export_format": 4, + "__export_date": "2023-11-05T20:51:37.696Z", + "__export_source": "insomnia.desktop.app:v8.3.0", + "resources": [ + { + "_id": "req_a91c380534a6459ea27c4d30418ab16f", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1699117176571, + "created": 1652981694993, + "url": "{{ _.GRAPHQL_ENDPOINT }}", + "name": "Resource Access", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"{\\n\\tresourceAccess {\\n\\t\\tproject {\\n\\t\\t\\tdisallowed\\n\\t\\t}\\n\\t\\tplugin {\\n\\t\\t\\tdisallowed\\n\\t\\t}\\n\\t}\\n}\\n\",\"variables\":{}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + } + ], + "authentication": {}, + "metaSortKey": -1699117141751, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "parentId": null, + "modified": 1638215181096, + "created": 1638215181096, + "name": "Insomnia", + "description": "", + "scope": "collection", + "_type": "workspace" + }, + { + "_id": "req_8ec4d463e2a1454e8e537a8a6f629979", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1699117178347, + "created": 1652826927278, + "url": "{{ _.GRAPHQL_ENDPOINT }}", + "name": "Create Team", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"mutation {\\n\\tagreeFairUse() {\\n\\t\\tname\\n\\t}\\n}\\n\",\"variables\":{}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + } + ], + "authentication": {}, + "metaSortKey": -1699117141701, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_d1a181e68234451a99c8677c86c0fb2f", + "parentId": "fld_fa4d4d23e5334207899d8ebc2b1b3518", + "modified": 1699117183071, + "created": 1653505877087, + "url": "", + "name": "Get Service Domains", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"query {\\n\\tallCustomDomainsForEnvironment(\\n\\t\\tprojectId: \\\"b7a46032-fe7f-48f2-8a0c-5d7e30b1a6dc\\\"\\n\\t\\tenvironmentId: \\\"5b53202d-f0dd-4aef-ae67-b7dffc9f2664\\\"\\n\\t\\tserviceId: \\\"d5fa85ac-ae49-4108-a7b6-0eca69ca623e\\\"\\n\\t) {\\n\\t\\tserviceDomains {\\n\\t\\t\\tid\\n\\t\\t\\tdomain\\n\\t\\t}\\n\\t}\\n}\\n\",\"variables\":{}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + } + ], + "authentication": {}, + "metaSortKey": -1699117183007, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_fa4d4d23e5334207899d8ebc2b1b3518", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1699117141651, + "created": 1699117141651, + "name": "My Foldertsra", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1699117141651, + "_type": "request_group" + }, + { + "_id": "req_df86bf5272724c5696c45e4e36e0b87c", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1680413502517, + "created": 1679927297821, + "url": "https://spacex-production.up.railway.app", + "name": "New Request", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"query Q($limit: Int!) {\\n capsules(limit: $limit) {\\n id\\n }\\n}\\n\",\"operationName\":\"Operations\",\"variables\":{\"limits\":2}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "authentication": { + "type": "bearer", + "token": "4c1736b6-d63f-4e07-860e-3da77c83dcde" + }, + "metaSortKey": -1679927297821, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_4321f12845724866ae665653dc9013a1", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941918874, + "created": 1651611238329, + "url": "{{ _.GRAPHQL_ENDPOINT }}", + "name": "My Request", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"query DeploymentLogs {\\n\\tdeploymentLogs(\\n\\t\\tprojectId: \\\"d9b7ad7a-0033-4f82-9484-40caa7b77e02\\\"\\n\\t\\tdeploymentId: \\\"bc0de943-45b4-4693-9bae-f335d4b23d3e\\\"\\n\\t\\tfilter: \\\"\\\"\\n\\t\\tlimit: 1000\\n\\t) {\\n\\t\\ttimestamp\\n\\t}\\n}\\n\",\"variables\":{},\"operationName\":\"DeploymentLogs\"}" + }, + "parameters": [ + { + "id": "pair_3e301eeb95ae4ede87929f62f7c995d6", + "name": "", + "value": "", + "description": "" + } + ], + "headers": [ + { + "name": "Accept", + "value": "", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + }, + { + "name": "Content-Type", + "value": "application/json" + } + ], + "authentication": {}, + "metaSortKey": -1653380018282.875, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_63cd07c5ecb34c1b8c9d350be8c22c73", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941919965, + "created": 1652983047395, + "url": "{{ _.GRAPHQL_ENDPOINT }}", + "name": "Project Resource Access", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"{\\n\\tprojectResourceAccess(projectId: \\\"d9b7ad7a-0033-4f82-9484-40caa7b77e02\\\") {\\n\\t\\tenvironment {\\n\\t\\t\\tdisallowed\\n\\t\\t}\\n\\t\\tdeployment {\\n\\t\\t\\tdisallowed\\n\\t\\t}\\n\\t\\tcustomDomain {\\n\\t\\t\\tdisallowed\\n\\t\\t}\\n\\t}\\n}\\n\",\"variables\":{}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + } + ], + "authentication": {}, + "metaSortKey": -1652495108964.9375, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_d4e228c310684efa918141df95047ca5", + "parentId": "fld_981294d5fef54ea8afd1f8ace781e826", + "modified": 1699021088931, + "created": 1680201417381, + "url": "35.230.57.124:6747", + "name": "New Request", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_0a6249504fd04fe29a8457beaf115459", + "name": "", + "value": "", + "description": "" + } + ], + "headers": [ + { + "id": "pair_811f4f1073404a82b43b4998b6558277", + "name": "Host`", + "value": "sports-app-pr-2420.up.railway.app", + "description": "" + } + ], + "authentication": {}, + "metaSortKey": -1699021088896, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_981294d5fef54ea8afd1f8ace781e826", + "parentId": "fld_036eba97da3a442c9e816031c563b7fa", + "modified": 1699042248107, + "created": 1699021081046, + "name": "My Folder", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1699042248028, + "_type": "request_group" + }, + { + "_id": "fld_036eba97da3a442c9e816031c563b7fa", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1699053144611, + "created": 1699021054008, + "name": "My Folder", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1652273881635.4531, + "_type": "request_group" + }, + { + "_id": "req_9765c255e6924e84b9945eb350b22525", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941921008, + "created": 1653501388183, + "url": "{{ _.GRAPHQL_ENDPOINT }}", + "name": "Create Service Domain", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"mutation {\\n\\tserviceDomainCreate(\\n\\t\\tprojectId: \\\"b7a46032-fe7f-48f2-8a0c-5d7e30b1a6dc\\\"\\n\\t\\tenvironmentId: \\\"5b53202d-f0dd-4aef-ae67-b7dffc9f2664\\\"\\n\\t\\tserviceId: \\\"d5fa85ac-ae49-4108-a7b6-0eca69ca623e\\\"\\n\\t) \\n}\\n\",\"variables\":{}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + }, + { + "id": "pair_3bcf5e459c2c438c86d5d3d5e52354fb", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_4f1cee0bbdf24b6390b9c464ec410250", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_9a9cf4c4a63b4fce922673fddb43d43d", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_908a2035a894438baebeb1b6ac1afee2", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_0ec5bbc7f6c145fa9cd9de906cc29379", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_8aba6dd1ca5a41cca0c24786b0cbb039", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_0e6fcf74ddb443819019a91e802d04af", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_f42e6cd545a04cd6800f70268008ba05", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_695d148107424526984ec543af507456", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_eda2b0d7b0a3455497e5cdee276c77c6", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_d15467f809b64c328fbb7201e1294ddd", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_69abe7b3af7141b7bea4cfb67b477a52", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_48c897a1a83d4de6ac102ea8434e2ad4", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_e6e8b5eec90e4f6d9766969afca33d84", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_bb25438825094a8e8ef6ec0f6e27cdd4", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_358743874d8c48b19bbb8af259d4a45d", + "name": "", + "value": "", + "description": "" + } + ], + "authentication": {}, + "metaSortKey": -1652052654305.9688, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_5741a3ea53e7403f956c44543cb98793", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941922124, + "created": 1653506166429, + "url": "{{ _.GRAPHQL_ENDPOINT }}", + "name": "Delete Service Domain", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"mutation ($serviceDomainId: ID!) {\\n\\tserviceDomainDelete(\\n\\t\\tprojectId: \\\"b7a46032-fe7f-48f2-8a0c-5d7e30b1a6dc\\\"\\n\\t\\tenvironmentId: \\\"5b53202d-f0dd-4aef-ae67-b7dffc9f2664\\\"\\n\\t\\tid: $serviceDomainId\\n\\t)\\n}\\n\",\"variables\":{\"serviceDomainId\":\"{% response 'body', 'req_9765c255e6924e84b9945eb350b22525', 'b64::JC4uaWQ=::46b', 'never', 60 %}\"}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + } + ], + "authentication": {}, + "metaSortKey": -1651831426976.4844, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_2ca47b965a3a456fa82d91799b1bb672", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941923984, + "created": 1653522891907, + "url": "{{ _.GRAPHQL_ENDPOINT }}", + "name": "Get Deployments", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"query {\\n\\tdeployments(where: {projectId: \\\"b7a46032-fe7f-48f2-8a0c-5d7e30b1a6dc\\\"}) {\\n\\t\\tnodes {\\n\\t\\t\\tid\\n\\t\\t\\tstaticUrl\\n\\t\\t}\\n\\t}\\n}\\n\",\"variables\":{}}" + }, + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json", + "id": "pair_a547d82bc2684b7595ab676d2668bbac" + }, + { + "id": "pair_619347adbf6c47c98965adc8a616bedf", + "name": "", + "value": "", + "description": "" + }, + { + "id": "pair_0806f4c53d97487da52deac558b9a714", + "name": "", + "value": "", + "description": "" + } + ], + "authentication": {}, + "metaSortKey": -1651720813311.7422, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_342c6ea8a6e44ee79146f658bbccbc37", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941925316, + "created": 1664387180476, + "url": "https://backboard.railway-develop.app/graphql/v2", + "name": "Variables", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/graphql", + "text": "{\"query\":\"query VariablesForDeploy {\\n\\tvariablesForServiceDeployment(\\n\\t\\tenvironmentId: \\\"e12b44cd-2f44-4213-918a-c6b2b2da1119\\\"\\n\\t\\tserviceId: \\\"1fb71daf-a16f-4908-bc9a-edf5eb17ff55\\\"\\n\\t\\tprojectId: \\\"0f65ff5f-66c8-4768-9efe-151c5fb0c67e\\\"\\n\\t)\\n}\\n\",\"operationName\":\"VariablesForDeploy\"}" + }, + "parameters": [ + { + "name": "q", + "value": "project", + "disabled": false, + "id": "pair_22881d63794c4a30bde5ebde1acfd6e7" + } + ], + "headers": [ + { + "name": "Cookie", + "value": "__stripe_mid=9edfc0bb-44b7-4578-9891-79fc8186bd8d21bd04; rw.session=rw_Fe26.2**59c48bdf92c61ccc01305240c75c68bec817014d417a8491d8b00452308052f8*xndzMd6R6DfmF7gVMgqB6A*f1kHhYV1qfls1RNnf25ZaTJIVziG448bozcrI014mb7heWWbtYxuj-HaUieCd2krFmhW6YEtlBq1_tn38BTzjQ*1666553259403*51eef82f4bb9607e184b4b577c5ca1c73bb2a23eb1c724f1435230ab2f4553a4*DHOs3UtBSPZFv3tmx-hIfP93MFHNH37z945vZHCuFFc; rw.session.sig=qDAXZPk6-xyOrqIyCxucXO208B0", + "id": "pair_a0828f267f4f490a8f3571b8fda99c77" + }, + { + "id": "pair_149b1a50185c4f3b8ae8f9c83477b0d9", + "name": "Content-Type", + "value": "application/json", + "description": "" + } + ], + "authentication": {}, + "metaSortKey": -1651665506479.371, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_b78c4a006dda4a8bacd2d5e6860cc418", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941930038, + "created": 1661542784701, + "url": "en", + "name": "New Request", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "metaSortKey": -1651610151969.5, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_c88f176ac17c441ca702b644898e2d20", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941931162, + "created": 1655414519907, + "url": "newworld-server-status-production.up.railway.app", + "name": "Test", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "metaSortKey": -1651610128130.75, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_aceafe72950f4818bcb74eab4b79d3f5", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941932133, + "created": 1647458250539, + "url": "https://health.up.railway.app", + "name": "Production Health", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "metaSortKey": -1651610116211.375, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_6c99ccd2c0b64897be2c148506315105", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941933294, + "created": 1647463574333, + "url": "https://35.227.136.140", + "name": "Production Go Server (SP 0)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "go-server.schier.dev", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610110251.6875, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_5ef4cd8d591d4f97b55360ec38f9bcf7", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941935909, + "created": 1647463586661, + "url": "https://34.82.254.200", + "name": "Production Go Server (SP 1)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "go-server.schier.dev", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610107271.8438, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_5d976ede609e4c76b8e8d33d7c3c90c5", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941936827, + "created": 1648507862472, + "url": "https://34.127.19.80", + "name": "Production Go Server (SP 2)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "go-server.schier.dev", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610105781.9219, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_4070af182e2c4414b5e9cecf04b39c21", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941937902, + "created": 1648509308934, + "url": "https://35.227.136.140", + "name": "Production Health (SP 0)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "health.up.railway.app", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610105036.961, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_d090114065924f849d5d70983c1a9445", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941938930, + "created": 1648509727183, + "url": "https://34.82.254.200", + "name": "Production Health (SP 1)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "health.up.railway.app", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610104664.4805, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_3b4f8d4cf5c0403cbacc20cfa0d0909e", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941940665, + "created": 1648507992005, + "url": "https://34.127.19.80", + "name": "Production Health (SP 2)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "health.up.railway.app", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610104478.2402, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_0abf3b152fef4e2b809b3eca7fa8c5ed", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941941575, + "created": 1661495542931, + "url": "https://35.230.52.169", + "name": "Production Health (SP 3)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "health.up.railway.app", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610104385.12, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_86bc2a68db064d3394d61d5012685d88", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941942602, + "created": 1661536011852, + "url": "https://34.83.190.231", + "name": "Production Health (SP 4)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "health.up.railway.app", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610104338.56, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_2a1a47392f71465abedf1605878bd8b7", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941946272, + "created": 1661536017974, + "url": "https://35.203.130.181", + "name": "Production Health (SP 5)", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [ + { + "id": "pair_eaf08227988d4d5cae6c56956383bcfd", + "name": "Host", + "value": "health.up.railway.app", + "description": "", + "disabled": false + } + ], + "authentication": {}, + "metaSortKey": -1651610104315.28, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_b78b921a543442f6ad26cffd79134a71", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941947284, + "created": 1650998377419, + "url": "https://fastapi-test-production-cfb9.up.railway.app/", + "name": "Fallback 503", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "metaSortKey": -1651610104303.6401, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_ce1409130bbd470b82ee234986055732", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1698941948315, + "created": 1650998482383, + "url": "https://b44574691bf9.up.railway.app/", + "name": "Fallback 404", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "metaSortKey": -1651610104297.82, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "env_396b20e683679d3405b86836c3479da41cef2434", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1683571883292, + "created": 1638215181110, + "name": "Base Environment", + "data": { + "RAILWAY_ACCESS_TOKEN": "rw_Fe26.2**557bd70c2da1b3b5e813fa42b699411c9f2d064d9d5603dfbb5e0841db9b4f7a*vXewN7CK4n5peW6rlzckeA*8VpqzYubeRNkUo8x8_cl4ntF9ZaghYNJ71hz9JjQO467QFh_QKTioNf8PiYEXbmgcWafDLzkCGrPkXVXLeVIdA*1685304002539*11d28aa3a3a8ae825c4369ba902984c4026d7344b7f915786b3d35c5feced643*rxI5aagcD-K9qfg52IkJMRNv6KAk4CUPSpN9ltQXPzs", + "STAGING_LB_IP": "34.127.110.157", + "PROD_LB_IP": "104.196.232.237", + "GRAPHQL_ENDPOINT": "https://backboard.{{ _.HOST }}/graphql" + }, + "dataPropertyOrder": { + "&": [ + "RAILWAY_ACCESS_TOKEN", + "STAGING_LB_IP", + "PROD_LB_IP", + "GRAPHQL_ENDPOINT" + ] + }, + "color": null, + "isPrivate": false, + "metaSortKey": 1638215181110, + "_type": "environment" + }, + { + "_id": "jar_396b20e683679d3405b86836c3479da41cef2434", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1693580294408, + "created": 1638215181112, + "name": "Default Jar", + "cookies": [ + { + "key": "rw.session", + "expires": "1970-01-01T00:00:00.000Z", + "domain": "backboard.railway-develop.app", + "path": "/", + "secure": true, + "httpOnly": true, + "hostOnly": true, + "creation": "2022-02-01T21:33:31.879Z", + "lastAccessed": "2022-02-16T23:22:54.152Z", + "id": "9050134658712923" + }, + { + "key": "rw.session.sig", + "value": "H0r-8iMOgmbraYpjf_Op_fw49mE", + "expires": "1970-01-01T00:00:00.000Z", + "domain": "backboard.railway-develop.app", + "path": "/", + "secure": true, + "httpOnly": true, + "hostOnly": true, + "creation": "2022-02-01T21:33:31.880Z", + "lastAccessed": "2022-02-16T23:22:54.153Z", + "id": "0663233020552414" + }, + { + "key": "_gorilla_csrf", + "value": "MTY0NzA0NzkwNHxJa3c1Y1hreU1teHhOMGN2Um10dFJEZEdaRGt5YlRkMmRrRldVRkZZYVVreGMzUjRheTlqZFRSRE5GazlJZ289fCzayrzfSoKAAcPZ8vfm0kn7eGRApjK71geRFcDahtld", + "expires": "2022-03-19T01:18:24.000Z", + "maxAge": 604800, + "domain": "35.230.25.114", + "path": "/", + "httpOnly": true, + "hostOnly": true, + "creation": "2022-03-12T01:18:24.341Z", + "lastAccessed": "2022-03-12T01:18:24.341Z", + "id": "6352363032251931" + }, + { + "key": "_gorilla_csrf", + "value": "MTY0NzUzMDA5N3xJa0Z4YjBkUFFrSkRXR1k0V1djMlpEZEhia1YxUWxreFp6RXJlbmhZVGtGU2MyZEdPVmRGVEhJdlIyODlJZ289fBpHkkGv6WwWXzizLjlHTV70EOdn5-KsR7a8MBRkXSQZ", + "expires": "2022-03-24T15:14:57.000Z", + "maxAge": 604800, + "domain": "104.196.232.237", + "path": "/", + "httpOnly": true, + "hostOnly": true, + "creation": "2022-03-17T15:14:57.151Z", + "lastAccessed": "2022-03-17T15:14:57.151Z", + "id": "8971506766096926" + }, + { + "key": "csrftoken", + "value": "MTY0NzUzMDEwMXxJbFZPZUhkTFNEbE1SSHB0VHpWelZYSllhV0ozWmtOQlZqZDVjWGxwUVhoVmNVNU5iblp1VkVKbFpUQTlJZ289fFzVHN-3QwsPlSTcehuNLfvEYJreiBBsGI_TAIrhAGG4", + "expires": "2022-03-18T03:15:01.000Z", + "maxAge": 43200, + "domain": "104.196.232.237", + "path": "/", + "secure": true, + "httpOnly": true, + "extensions": [ + "SameSite=Lax" + ], + "hostOnly": true, + "creation": "2022-03-17T15:15:01.387Z", + "lastAccessed": "2022-03-17T15:15:01.387Z", + "id": "97506639298924" + }, + { + "key": "_gorilla_csrf", + "value": "MTY1NTg0MjA0MnxJbUZZVUdwcmVFUnNkV3R4T1hSUE1HNUNVVWhpYkRjdlJsRTJUVVJwYkdGV2RTOUtSMXBtTjNsU1ZGVTlJZ289fN3w7ZeZzNgsUqRq8XTuLLX0yb8xWIb_U54NzN1MCoXj", + "expires": "2022-06-28T20:07:22.000Z", + "maxAge": 604800, + "domain": "34.127.19.80", + "path": "/", + "httpOnly": true, + "hostOnly": true, + "creation": "2022-03-28T23:04:41.781Z", + "lastAccessed": "2022-06-21T20:07:21.961Z", + "id": "9250420261993928" + }, + { + "key": "_gorilla_csrf", + "value": "MTY1NTg0MjA1MnxJbmhUVmt4bVF6VkZNM2RVU2tocU0wRjJiSGRxWTJGNWNVeHdPV3hGUkZwclExaGhTa0phVW5WbWQxVTlJZ289fGfMeQWOBmPJZ--qB8Q8XQOJdLc4O68zvFMFm3TUFTY8", + "expires": "2022-06-28T20:07:32.000Z", + "maxAge": 604800, + "domain": "34.82.254.200", + "path": "/", + "httpOnly": true, + "hostOnly": true, + "creation": "2022-06-21T20:07:32.204Z", + "lastAccessed": "2022-06-21T20:07:32.204Z", + "id": "44160105356955115" + }, + { + "key": "_gorilla_csrf", + "value": "MTY1NTg0MjA1OXxJa1ZsV21Kd01URkdkMDFDVVhWdU9WVXpPQzlxV0dOeWNrSjViR3MwVmxrelpEUjVVQ3R3TlRST1FtODlJZ289fMVPNCzPJeQFaif1Ea73Oc9P1J7yP8m02BCO9nqzYO8g", + "expires": "2022-06-28T20:07:39.000Z", + "maxAge": 604800, + "domain": "35.227.136.140", + "path": "/", + "httpOnly": true, + "hostOnly": true, + "creation": "2022-06-21T20:07:38.917Z", + "lastAccessed": "2022-06-21T20:07:38.917Z", + "id": "5712105390385236" + }, + { + "key": "_gorilla_csrf", + "value": "MTY3ODcyNjc0MHxJbnByWlVZdlowOTZObk13V0dVMWVFNHlZbXRSTldjMlRYZGFha2RYZG5obFNsVlFOV2hxUkZjdk1VazlJZ289fJyKGNqXFGQRVhPh_M8tQQAvuKcODVJALz1vP2s6Jyho", + "expires": "2023-03-20T16:59:00.000Z", + "maxAge": 604800, + "domain": "schier.co", + "path": "/", + "httpOnly": true, + "hostOnly": true, + "creation": "2023-03-13T16:59:00.443Z", + "lastAccessed": "2023-03-13T16:59:00.443Z", + "id": "577324323818015" + }, + { + "key": "experiments", + "value": "%7B%22ydugo4GHROOp8qOy9fuAXg%22%3A3%7D", + "domain": "35.230.57.124", + "path": "/", + "hostOnly": true, + "creation": "2023-09-01T14:58:14.408Z", + "lastAccessed": "2023-09-01T14:58:14.408Z", + "id": "17611565296231624" + } + ], + "_type": "cookie_jar" + }, + { + "_id": "spc_2f5ed07b6b544d3fb83b6f622ccf4fa6", + "parentId": "wrk_cd2351f82a134dec87cb74c0bc9e3e7c", + "modified": 1638215181101, + "created": 1638215181101, + "fileName": "Insomnia", + "contents": "", + "contentType": "yaml", + "_type": "api_spec" + }, + { + "_id": "env_40037f13ae3e4f15bc7ae4863b207b8d", + "parentId": "env_396b20e683679d3405b86836c3479da41cef2434", + "modified": 1698513742673, + "created": 1651610110792, + "name": "Development", + "data": { + "HOST": "railway-develop.app" + }, + "dataPropertyOrder": { + "&": [ + "HOST" + ] + }, + "color": "#20cf4c", + "isPrivate": false, + "metaSortKey": 1651610110792, + "_type": "environment" + } + ] +} diff --git a/plugins/insomnia-importer/Insomnia_hello-world.json b/src-tauri/plugins/insomnia-importer/Insomnia_hello-world.json similarity index 100% rename from plugins/insomnia-importer/Insomnia_hello-world.json rename to src-tauri/plugins/insomnia-importer/Insomnia_hello-world.json diff --git a/src-tauri/plugins/insomnia-importer/helpers/types.js b/src-tauri/plugins/insomnia-importer/helpers/types.js new file mode 100644 index 00000000..bb78f67c --- /dev/null +++ b/src-tauri/plugins/insomnia-importer/helpers/types.js @@ -0,0 +1,19 @@ +export function isWorkspace(obj) { + return isJSObject(obj) && obj._type === 'workspace'; +} + +export function isRequestGroup(obj) { + return isJSObject(obj) && obj._type === 'request_group'; +} + +export function isRequest(obj) { + return isJSObject(obj) && obj._type === 'request'; +} + +export function isEnvironment(obj) { + return isJSObject(obj) && obj._type === 'environment'; +} + +export function isJSObject(obj) { + return Object.prototype.toString.call(obj) === '[object Object]'; +} diff --git a/src-tauri/plugins/insomnia-importer/helpers/variables.js b/src-tauri/plugins/insomnia-importer/helpers/variables.js new file mode 100644 index 00000000..660664ae --- /dev/null +++ b/src-tauri/plugins/insomnia-importer/helpers/variables.js @@ -0,0 +1,7 @@ +export function parseVariables(data) { + return Object.entries(data).map(([name, value]) => ({ + enabled: true, + name, + value: `${value}`, + })); +} diff --git a/plugins/insomnia-importer/importers/environment.js b/src-tauri/plugins/insomnia-importer/importers/environment.js similarity index 81% rename from plugins/insomnia-importer/importers/environment.js rename to src-tauri/plugins/insomnia-importer/importers/environment.js index f22a3f48..51feaf37 100644 --- a/plugins/insomnia-importer/importers/environment.js +++ b/src-tauri/plugins/insomnia-importer/importers/environment.js @@ -1,17 +1,15 @@ /** * Import an Insomnia environment object. * @param {Object} e - The environment object to import. + * @param workspaceId - Workspace to import into. */ -export function importEnvironment(e) { - if (e.parentId.startsWith('env_')) { - return null; - } +export function importEnvironment(e, workspaceId) { console.log('IMPORTING Environment', e._id, e.name, JSON.stringify(e, null, 2)); return { id: e._id, createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''), updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''), - workspaceId: e.parentId, + workspaceId, model: 'environment', name: e.name, variables: Object.entries(e.data).map(([name, value]) => ({ diff --git a/src-tauri/plugins/insomnia-importer/importers/folder.js b/src-tauri/plugins/insomnia-importer/importers/folder.js new file mode 100644 index 00000000..3ae7adda --- /dev/null +++ b/src-tauri/plugins/insomnia-importer/importers/folder.js @@ -0,0 +1,17 @@ +/** + * Import an Insomnia folder object. + * @param {Object} f - The environment object to import. + * @param workspaceId - Workspace to import into. + */ +export function importFolder(f, workspaceId) { + console.log('IMPORTING FOLDER', f._id, f.name, JSON.stringify(f, null, 2)); + return { + id: f._id, + createdAt: new Date(f.created ?? Date.now()).toISOString().replace('Z', ''), + updatedAt: new Date(f.updated ?? Date.now()).toISOString().replace('Z', ''), + folderId: f.parentId === workspaceId ? null : f.parentId, + workspaceId, + model: 'folder', + name: f.name, + }; +} diff --git a/plugins/insomnia-importer/importers/request.js b/src-tauri/plugins/insomnia-importer/importers/request.js similarity index 79% rename from plugins/insomnia-importer/importers/request.js rename to src-tauri/plugins/insomnia-importer/importers/request.js index 4393db61..c8c4a666 100644 --- a/plugins/insomnia-importer/importers/request.js +++ b/src-tauri/plugins/insomnia-importer/importers/request.js @@ -1,15 +1,17 @@ /** * Import an Insomnia request object. * @param {Object} r - The request object to import. + * @param workspaceId - The workspace ID to use for the request. * @param {number} sortPriority - The sort priority to use for the request. */ -export function importRequest(r, sortPriority = 0) { +export function importRequest(r, workspaceId, sortPriority = 0) { console.log('IMPORTING REQUEST', r._id, r.name, JSON.stringify(r, null, 2)); return { id: r._id, createdAt: new Date(r.created ?? Date.now()).toISOString().replace('Z', ''), updatedAt: new Date(r.updated ?? Date.now()).toISOString().replace('Z', ''), - workspaceId: r.parentId, + workspaceId, + folderId: r.parentId === workspaceId ? null : r.parentId, model: 'http_request', sortPriority, name: r.name, diff --git a/plugins/insomnia-importer/importers/workspace.js b/src-tauri/plugins/insomnia-importer/importers/workspace.js similarity index 70% rename from plugins/insomnia-importer/importers/workspace.js rename to src-tauri/plugins/insomnia-importer/importers/workspace.js index 8ff73f7a..7d759127 100644 --- a/plugins/insomnia-importer/importers/workspace.js +++ b/src-tauri/plugins/insomnia-importer/importers/workspace.js @@ -2,13 +2,14 @@ * Import an Insomnia workspace object. * @param {Object} w - The workspace object to import. */ -export function importWorkspace(w) { - console.log('IMPORTING Workpace', w._id, w.name, JSON.stringify(w, null, 2)); +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, }; } diff --git a/src-tauri/plugins/insomnia-importer/index.js b/src-tauri/plugins/insomnia-importer/index.js new file mode 100644 index 00000000..375b04c2 --- /dev/null +++ b/src-tauri/plugins/insomnia-importer/index.js @@ -0,0 +1,78 @@ +import { importEnvironment } from './importers/environment.js'; +import { importRequest } from './importers/request.js'; +import { importWorkspace } from './importers/workspace.js'; +import { + isEnvironment, + isJSObject, + isRequest, + isRequestGroup, + isWorkspace, +} from './helpers/types.js'; +import { parseVariables } from './helpers/variables.js'; +import { importFolder } from './importers/folder.js'; + +export function pluginHookImport(contents) { + const parsed = JSON.parse(contents); + if (!isJSObject(parsed)) { + return; + } + + const { _type, __export_format } = parsed; + if (_type !== 'export' || __export_format !== 4 || !Array.isArray(parsed.resources)) { + return; + } + + const resources = { + workspaces: [], + requests: [], + environments: [], + folders: [], + }; + + // Import workspaces + const workspacesToImport = parsed.resources.filter(isWorkspace); + for (const workspaceToImport of workspacesToImport) { + console.log('IMPORTING WORKSPACE', workspaceToImport.name); + const baseEnvironment = parsed.resources.find( + (r) => isEnvironment(r) && r.parentId === workspaceToImport._id, + ); + console.log('FOUND BASE ENV', baseEnvironment.name); + resources.workspaces.push( + importWorkspace( + workspaceToImport, + baseEnvironment ? parseVariables(baseEnvironment.data) : [], + ), + ); + console.log('IMPORTING ENVIRONMENTS', baseEnvironment.name); + const environmentsToImport = parsed.resources.filter( + (r) => isEnvironment(r) && r.parentId === baseEnvironment?._id, + ); + console.log('FOUND', environmentsToImport.length, 'ENVIRONMENTS'); + resources.environments.push( + ...environmentsToImport.map((r) => importEnvironment(r, workspaceToImport._id)), + ); + + const nextFolder = (parentId) => { + const children = parsed.resources.filter((r) => r.parentId === parentId); + let sortPriority = 0; + for (const child of children) { + if (isRequestGroup(child)) { + resources.folders.push(importFolder(child, workspaceToImport._id)); + nextFolder(child._id); + } else if (isRequest(child)) { + resources.requests.push(importRequest(child, workspaceToImport._id, sortPriority++)); + } + } + }; + + // Import folders + nextFolder(workspaceToImport._id); + } + + // Filter out any `null` values + resources.requests = resources.requests.filter(Boolean); + resources.environments = resources.environments.filter(Boolean); + resources.workspaces = resources.workspaces.filter(Boolean); + + return resources; +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3dcf7492..bbc37ce1 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -32,11 +32,11 @@ use tokio::sync::Mutex; use window_ext::TrafficLightWindowExt; -mod menu; mod models; mod plugin; mod render; mod window_ext; +mod window_menu; #[derive(serde::Serialize)] pub struct CustomResponse { @@ -266,16 +266,13 @@ async fn import_data( window: Window, db_instance: State<'_, Mutex>>, file_paths: Vec<&str>, - workspace_id: Option<&str>, ) -> Result { let pool = &*db_instance.lock().await; - let workspace_id2 = workspace_id.unwrap_or_default(); let imported = plugin::run_plugin_import( &window.app_handle(), pool, "insomnia-importer", file_paths.first().unwrap(), - workspace_id2, ) .await; Ok(imported) @@ -764,7 +761,6 @@ fn main() { &pool, "insomnia-importer", arg_file, - "wk_WN8Nrm2Awm", ) .await; exit(0); @@ -834,7 +830,7 @@ fn is_dev() -> bool { } fn create_window(handle: &AppHandle, url: Option<&str>) -> Window { - let mut app_menu = menu::os_default("Yaak".to_string().as_str()); + let mut app_menu = window_menu::os_default("Yaak".to_string().as_str()); if is_dev() { let submenu = Submenu::new( "Developer", diff --git a/src-tauri/src/plugin.rs b/src-tauri/src/plugin.rs index 27c67cfc..da74d081 100644 --- a/src-tauri/src/plugin.rs +++ b/src-tauri/src/plugin.rs @@ -1,5 +1,6 @@ use std::fs; +use boa_engine::builtins::promise::PromiseState; use boa_engine::{ js_string, module::{ModuleLoader, SimpleModuleLoader}, @@ -12,7 +13,7 @@ use serde_json::json; use sqlx::{Pool, Sqlite}; use tauri::AppHandle; -use crate::models::{self, Environment, HttpRequest, Workspace}; +use crate::models::{self, Environment, Folder, HttpRequest, Workspace}; pub fn run_plugin_hello(app_handle: &AppHandle, plugin_name: &str) { run_plugin(app_handle, plugin_name, "hello", &[]); @@ -20,9 +21,10 @@ pub fn run_plugin_hello(app_handle: &AppHandle, plugin_name: &str) { #[derive(Default, Debug, Deserialize, Serialize)] pub struct ImportedResources { - requests: Vec, - environments: Vec, workspaces: Vec, + environments: Vec, + folders: Vec, + requests: Vec, } pub async fn run_plugin_import( @@ -30,9 +32,9 @@ pub async fn run_plugin_import( pool: &Pool, plugin_name: &str, file_path: &str, - workspace_id: &str, ) -> ImportedResources { - let file = fs::read_to_string(file_path).expect("Unable to read file"); + let file = fs::read_to_string(file_path) + .expect(format!("Unable to read file {}", file_path.to_string()).as_str()); let file_contents = file.as_str(); let result_json = run_plugin( app_handle, @@ -44,34 +46,35 @@ pub async fn run_plugin_import( serde_json::from_value(result_json).expect("failed to parse result json"); let mut imported_resources = ImportedResources::default(); - println!("Importing resources: {}", workspace_id.is_empty()); - if workspace_id.is_empty() { - for w in resources.workspaces { - println!("Importing workspace: {:?}", w); - let x = models::upsert_workspace(&pool, w) - .await - .expect("Failed to create workspace"); - imported_resources.workspaces.push(x.clone()); - println!("Imported workspace: {}", x.name); - } + println!("Importing resources"); + for w in resources.workspaces { + println!("Importing workspace: {:?}", w); + let x = models::upsert_workspace(&pool, w) + .await + .expect("Failed to create workspace"); + imported_resources.workspaces.push(x.clone()); + println!("Imported workspace: {}", x.name); } - for mut e in resources.environments { - if !workspace_id.is_empty() { - e.workspace_id = workspace_id.to_string(); - } + for e in resources.environments { println!("Importing environment: {:?}", e); let x = models::upsert_environment(&pool, e) .await .expect("Failed to create environment"); - imported_resources.environments.push(x.clone()); + imported_resources.environments.push(x.clone()); println!("Imported environment: {}", x.name); } - for mut r in resources.requests { - if !workspace_id.is_empty() { - r.workspace_id = workspace_id.to_string(); - } + for f in resources.folders { + println!("Importing folder: {:?}", f); + let x = models::upsert_folder(&pool, f) + .await + .expect("Failed to create folder"); + imported_resources.folders.push(x.clone()); + println!("Imported folder: {}", x.name); + } + + for r in resources.requests { println!("Importing request: {:?}", r); let x = models::upsert_request(&pool, r) .await @@ -91,12 +94,12 @@ fn run_plugin( ) -> serde_json::Value { let plugin_dir = app_handle .path_resolver() - .resolve_resource("../plugins") + .resolve_resource("plugins") .expect("failed to resolve plugin directory resource") .join(plugin_name); let plugin_index_file = plugin_dir.join("index.js"); - println!("Plugin dir: {:?}", plugin_dir); + println!("Plugin dir={:?} file={:?}", plugin_dir, plugin_index_file); // Module loader for the specific plugin let loader = &SimpleModuleLoader::new(plugin_dir).expect("failed to create module loader"); @@ -119,23 +122,25 @@ fn run_plugin( // TODO: Is this needed if loaded from file already? loader.insert(plugin_index_file, module.clone()); - let _promise_result = module + let promise_result = module .load_link_evaluate(context) .expect("failed to evaluate module"); // Very important to push forward the job queue after queueing promises. context.run_jobs(); - // // Checking if the final promise didn't return an error. - // match promise_result.state() { - // PromiseState::Pending => return Err("module didn't execute!".into()), - // PromiseState::Fulfilled(v) => { - // assert_eq!(v, JsValue::undefined()) - // } - // PromiseState::Rejected(err) => { - // return Err(JsError::from_opaque(err).try_native(context)?.into()) - // } - // } + // Checking if the final promise didn't return an error. + match promise_result.state().expect("failed to get promise state") { + PromiseState::Pending => { + panic!("Promise was pending"); + } + PromiseState::Fulfilled(v) => { + assert_eq!(v, JsValue::undefined()) + } + PromiseState::Rejected(err) => { + panic!("Failed to link: {}", err.display()); + } + } let namespace = module.namespace(context); diff --git a/src-tauri/src/menu.rs b/src-tauri/src/window_menu.rs similarity index 100% rename from src-tauri/src/menu.rs rename to src-tauri/src/window_menu.rs diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 2707a57b..865c09f6 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -13,11 +13,11 @@ "tauri": { "windows": [], "cli": { - "description": "Yaak CLI", - "longDescription": "This is the Yaak CLI, yo", + "description": "Yaak CLI", + "longDescription": "This is the Yaak CLI, yo", "beforeHelp": "u can use it to build, develop and manage your Yaak application.", "afterHelp": "Have fun!", - "args": [], + "args": [], "subcommands": { "import": { "args": [{ @@ -75,7 +75,7 @@ "longDescription": "The best cross-platform visual API client", "resources": [ "migrations/*", - "../plugins/*" + "plugins/*" ], "shortDescription": "The best API client", "targets": [ diff --git a/src-web/components/EnvironmentActionsDropdown.tsx b/src-web/components/EnvironmentActionsDropdown.tsx index 4eb439c4..14b75fd1 100644 --- a/src-web/components/EnvironmentActionsDropdown.tsx +++ b/src-web/components/EnvironmentActionsDropdown.tsx @@ -1,15 +1,14 @@ import classNames from 'classnames'; import { memo, useCallback, useMemo } from 'react'; +import { useActiveEnvironment } from '../hooks/useActiveEnvironment'; +import { useAppRoutes } from '../hooks/useAppRoutes'; +import { useEnvironments } from '../hooks/useEnvironments'; import { Button } from './core/Button'; import type { DropdownItem } from './core/Dropdown'; import { Dropdown } from './core/Dropdown'; import { Icon } from './core/Icon'; -import { useEnvironments } from '../hooks/useEnvironments'; -import { useActiveEnvironment } from '../hooks/useActiveEnvironment'; import { useDialog } from './DialogContext'; import { EnvironmentEditDialog } from './EnvironmentEditDialog'; -import { useAppRoutes } from '../hooks/useAppRoutes'; -import { useCreateEnvironment } from '../hooks/useCreateEnvironment'; type Props = { className?: string; @@ -20,7 +19,6 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo }: Props) { const environments = useEnvironments(); const activeEnvironment = useActiveEnvironment(); - const createEnvironment = useCreateEnvironment(); const dialog = useDialog(); const routes = useAppRoutes(); @@ -32,44 +30,33 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo }, [dialog, activeEnvironment]); const items: DropdownItem[] = useMemo( - () => - environments.length === 0 - ? [ - { - key: 'create', - label: 'Create Environment', - leftSlot: , - onSelect: async () => { - await createEnvironment.mutateAsync(); - showEnvironmentDialog(); - }, - }, - ] - : [ - ...environments.map( - (e) => ({ - key: e.id, - label: e.name, - rightSlot: e.id === activeEnvironment?.id ? : undefined, - onSelect: async () => { - if (e.id !== activeEnvironment?.id) { - routes.setEnvironment(e); - } else { - routes.setEnvironment(null); - } - }, - }), - [activeEnvironment?.id], - ), - { type: 'separator', label: 'Environments' }, - { - key: 'edit', - label: 'Manage Environments', - leftSlot: , - onSelect: showEnvironmentDialog, - }, - ], - [activeEnvironment, environments, routes, createEnvironment, showEnvironmentDialog], + () => [ + ...environments.map( + (e) => ({ + key: e.id, + label: e.name, + rightSlot: e.id === activeEnvironment?.id ? : undefined, + onSelect: async () => { + if (e.id !== activeEnvironment?.id) { + routes.setEnvironment(e); + } else { + routes.setEnvironment(null); + } + }, + }), + [activeEnvironment?.id], + ), + ...((environments.length > 0 + ? [{ type: 'separator', label: 'Environments' }] + : []) as DropdownItem[]), + { + key: 'edit', + label: 'Manage Environments', + leftSlot: , + onSelect: showEnvironmentDialog, + }, + ], + [activeEnvironment, environments, routes, showEnvironmentDialog], ); return ( diff --git a/src-web/components/RequestActionsDropdown.tsx b/src-web/components/RequestActionsDropdown.tsx index c48e4398..bbc91d02 100644 --- a/src-web/components/RequestActionsDropdown.tsx +++ b/src-web/components/RequestActionsDropdown.tsx @@ -1,18 +1,18 @@ import { invoke } from '@tauri-apps/api'; -import { useCallback, useRef } from 'react'; import { open } from '@tauri-apps/api/dialog'; +import { useCallback, useRef } from 'react'; +import { useAppRoutes } from '../hooks/useAppRoutes'; import { useDeleteRequest } from '../hooks/useDeleteRequest'; import { useDuplicateRequest } from '../hooks/useDuplicateRequest'; +import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent'; import { useTheme } from '../hooks/useTheme'; +import type { Environment, Folder, HttpRequest, Workspace } from '../lib/models'; +import { pluralize } from '../lib/pluralize'; import type { DropdownItem, DropdownProps, DropdownRef } from './core/Dropdown'; import { Dropdown } from './core/Dropdown'; import { HotKey } from './core/HotKey'; import { Icon } from './core/Icon'; -import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent'; -import { useAppRoutes } from '../hooks/useAppRoutes'; -import type { Environment, HttpRequest, Workspace } from '../lib/models'; import { useDialog } from './DialogContext'; -import { pluralize } from '../lib/pluralize'; interface Props { requestId: string | null; @@ -50,10 +50,10 @@ export function RequestActionsDropdown({ requestId, children }: Props) { const imported: { workspaces: Workspace[]; environments: Environment[]; + folders: Folder[]; requests: HttpRequest[]; } = await invoke('import_data', { filePaths: selected, - workspaceId: null, }); const importedWorkspace = imported.workspaces[0]; @@ -62,7 +62,7 @@ export function RequestActionsDropdown({ requestId, children }: Props) { description: 'Imported the following:', size: 'dynamic', render: () => { - const { workspaces, environments, requests } = imported; + const { workspaces, environments, folders, requests } = imported; return (
    @@ -72,6 +72,9 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
  • {environments.length} {pluralize('Environment', environments.length)}
  • +
  • + {folders.length} {pluralize('Folder', folders.length)} +
  • {requests.length} {pluralize('Request', requests.length)}
  • diff --git a/src-web/components/Sidebar.tsx b/src-web/components/Sidebar.tsx index 22fe33fb..9fe7d6bf 100644 --- a/src-web/components/Sidebar.tsx +++ b/src-web/components/Sidebar.tsx @@ -403,7 +403,6 @@ function SidebarItems({ > {tree.children.map((child, i) => ( - {hoveredIndex === i && hoveredTree?.item.id === tree.item.id && } {hoveredIndex === i && hoveredTree?.item.id === tree.item.id && }