From d28100d68230a26c8a14ce4f4d69305b71f2b511 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 9 Oct 2024 09:54:15 -0700 Subject: [PATCH] Add new plugins --- .../plugins/exporter-curl/package.json | 2 +- .../plugins/filter-jsonpath/package.json | 2 +- .../plugins/filter-xpath/package.json | 2 +- .../plugins/importer-curl/package.json | 5 +- .../plugins/importer-insomnia/package.json | 2 +- .../plugins/importer-openapi/package.json | 5 +- .../plugins/importer-postman/package.json | 2 +- .../plugins/importer-yaak/package.json | 2 +- .../template-function-file/build/index.js | 54 ++++++ .../template-function-file/package.json | 9 + .../template-function-hash/build/index.js | 48 ++++++ .../template-function-hash/package.json | 9 + .../template-function-prompt/build/index.js | 53 ++++++ .../template-function-prompt/package.json | 9 + .../template-function-request/build/index.js | 21 ++- .../template-function-request/package.json | 10 +- .../template-function-response/build/index.js | 160 +++++++++++------- .../hooks/useActiveWorkspaceChangedToast.tsx | 5 +- 18 files changed, 313 insertions(+), 87 deletions(-) create mode 100644 src-tauri/vendored/plugins/template-function-file/build/index.js create mode 100644 src-tauri/vendored/plugins/template-function-file/package.json create mode 100644 src-tauri/vendored/plugins/template-function-hash/build/index.js create mode 100755 src-tauri/vendored/plugins/template-function-hash/package.json create mode 100644 src-tauri/vendored/plugins/template-function-prompt/build/index.js create mode 100644 src-tauri/vendored/plugins/template-function-prompt/package.json diff --git a/src-tauri/vendored/plugins/exporter-curl/package.json b/src-tauri/vendored/plugins/exporter-curl/package.json index 60ae346b..283c3c5d 100644 --- a/src-tauri/vendored/plugins/exporter-curl/package.json +++ b/src-tauri/vendored/plugins/exporter-curl/package.json @@ -1,5 +1,5 @@ { - "name": "exporter-curl", + "name": "@yaakapp/exporter-curl", "private": true, "version": "0.0.1", "scripts": { diff --git a/src-tauri/vendored/plugins/filter-jsonpath/package.json b/src-tauri/vendored/plugins/filter-jsonpath/package.json index 80115b31..4d1a1c5a 100644 --- a/src-tauri/vendored/plugins/filter-jsonpath/package.json +++ b/src-tauri/vendored/plugins/filter-jsonpath/package.json @@ -1,5 +1,5 @@ { - "name": "filter-jsonpath", + "name": "@yaakapp/filter-jsonpath", "private": true, "version": "0.0.1", "scripts": { diff --git a/src-tauri/vendored/plugins/filter-xpath/package.json b/src-tauri/vendored/plugins/filter-xpath/package.json index 89b9e26d..4ca5c711 100644 --- a/src-tauri/vendored/plugins/filter-xpath/package.json +++ b/src-tauri/vendored/plugins/filter-xpath/package.json @@ -1,5 +1,5 @@ { - "name": "filter-xpath", + "name": "@yaakapp/filter-xpath", "private": true, "version": "0.0.1", "scripts": { diff --git a/src-tauri/vendored/plugins/importer-curl/package.json b/src-tauri/vendored/plugins/importer-curl/package.json index 154ebf56..53ef8d3b 100644 --- a/src-tauri/vendored/plugins/importer-curl/package.json +++ b/src-tauri/vendored/plugins/importer-curl/package.json @@ -1,5 +1,5 @@ { - "name": "importer-curl", + "name": "@yaakapp/importer-curl", "private": true, "version": "0.0.1", "scripts": { @@ -8,5 +8,8 @@ }, "dependencies": { "shell-quote": "^1.8.1" + }, + "devDependencies": { + "@types/shell-quote": "^1.7.5" } } diff --git a/src-tauri/vendored/plugins/importer-insomnia/package.json b/src-tauri/vendored/plugins/importer-insomnia/package.json index 18b80f09..d0764c8c 100644 --- a/src-tauri/vendored/plugins/importer-insomnia/package.json +++ b/src-tauri/vendored/plugins/importer-insomnia/package.json @@ -1,5 +1,5 @@ { - "name": "importer-insomnia", + "name": "@yaakapp/importer-insomnia", "private": true, "version": "0.0.1", "scripts": { diff --git a/src-tauri/vendored/plugins/importer-openapi/package.json b/src-tauri/vendored/plugins/importer-openapi/package.json index 575b0433..9ea28dd1 100644 --- a/src-tauri/vendored/plugins/importer-openapi/package.json +++ b/src-tauri/vendored/plugins/importer-openapi/package.json @@ -1,5 +1,5 @@ { - "name": "importer-openapi", + "name": "@yaakapp/importer-openapi", "private": true, "version": "0.0.1", "scripts": { @@ -9,5 +9,8 @@ "dependencies": { "openapi-to-postmanv2": "^4.23.1", "yaml": "^2.4.2" + }, + "devDependencies": { + "@types/openapi-to-postmanv2": "^3.2.4" } } diff --git a/src-tauri/vendored/plugins/importer-postman/package.json b/src-tauri/vendored/plugins/importer-postman/package.json index a2b5d02a..10f0a1a1 100644 --- a/src-tauri/vendored/plugins/importer-postman/package.json +++ b/src-tauri/vendored/plugins/importer-postman/package.json @@ -1,5 +1,5 @@ { - "name": "importer-postman", + "name": "@yaakapp/importer-postman", "private": true, "version": "0.0.1", "main": "./build/index.js", diff --git a/src-tauri/vendored/plugins/importer-yaak/package.json b/src-tauri/vendored/plugins/importer-yaak/package.json index e44fbae5..f22d8bee 100644 --- a/src-tauri/vendored/plugins/importer-yaak/package.json +++ b/src-tauri/vendored/plugins/importer-yaak/package.json @@ -1,5 +1,5 @@ { - "name": "importer-yaak", + "name": "@yaakapp/importer-yaak", "private": true, "version": "0.0.1", "scripts": { diff --git a/src-tauri/vendored/plugins/template-function-file/build/index.js b/src-tauri/vendored/plugins/template-function-file/build/index.js new file mode 100644 index 00000000..f1d054df --- /dev/null +++ b/src-tauri/vendored/plugins/template-function-file/build/index.js @@ -0,0 +1,54 @@ +"use strict"; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + plugin: () => plugin +}); +module.exports = __toCommonJS(src_exports); +var import_node_fs = __toESM(require("node:fs")); +var plugin = { + templateFunctions: [{ + name: "fs.readFile", + args: [{ title: "Select File", type: "file", name: "path", label: "File" }], + async onRender(_ctx, args) { + if (!args.values.path) return null; + try { + return import_node_fs.default.promises.readFile(args.values.path, "utf-8"); + } catch (err) { + return null; + } + } + }] +}; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + plugin +}); diff --git a/src-tauri/vendored/plugins/template-function-file/package.json b/src-tauri/vendored/plugins/template-function-file/package.json new file mode 100644 index 00000000..59aea7ab --- /dev/null +++ b/src-tauri/vendored/plugins/template-function-file/package.json @@ -0,0 +1,9 @@ +{ + "name": "@yaakapp/template-function-file", + "private": true, + "version": "0.0.1", + "scripts": { + "build": "yaakcli build ./src/index.ts", + "dev": "yaakcli dev ./src/index.js" + } +} diff --git a/src-tauri/vendored/plugins/template-function-hash/build/index.js b/src-tauri/vendored/plugins/template-function-hash/build/index.js new file mode 100644 index 00000000..5e222f6d --- /dev/null +++ b/src-tauri/vendored/plugins/template-function-hash/build/index.js @@ -0,0 +1,48 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + plugin: () => plugin +}); +module.exports = __toCommonJS(src_exports); +var import_node_crypto = require("node:crypto"); +var algorithms = ["md5", "sha1", "sha256", "sha512"]; +var plugin = { + templateFunctions: algorithms.map((algorithm) => ({ + name: `hash.${algorithm}`, + args: [ + { + name: "input", + label: "Input", + placeholder: "input text", + type: "text" + } + ], + async onRender(_ctx, args) { + if (!args.values.input) return ""; + return (0, import_node_crypto.createHash)(algorithm).update(args.values.input, "utf-8").digest("hex"); + } + })) +}; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + plugin +}); diff --git a/src-tauri/vendored/plugins/template-function-hash/package.json b/src-tauri/vendored/plugins/template-function-hash/package.json new file mode 100755 index 00000000..5dbcb0d2 --- /dev/null +++ b/src-tauri/vendored/plugins/template-function-hash/package.json @@ -0,0 +1,9 @@ +{ + "name": "@yaakapp/template-function-hash", + "private": true, + "version": "0.0.1", + "scripts": { + "build": "yaakcli build ./src/index.ts", + "dev": "yaakcli dev ./src/index.js" + } +} diff --git a/src-tauri/vendored/plugins/template-function-prompt/build/index.js b/src-tauri/vendored/plugins/template-function-prompt/build/index.js new file mode 100644 index 00000000..26e833b0 --- /dev/null +++ b/src-tauri/vendored/plugins/template-function-prompt/build/index.js @@ -0,0 +1,53 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + plugin: () => plugin +}); +module.exports = __toCommonJS(src_exports); +var plugin = { + templateFunctions: [{ + name: "prompt.text", + args: [ + { type: "text", name: "title", label: "Title" }, + { type: "text", name: "label", label: "Label", optional: true }, + { type: "text", name: "defaultValue", label: "Default Value", optional: true }, + { type: "text", name: "placeholder", label: "Placeholder", optional: true } + ], + async onRender(ctx, args) { + console.log("PROMPT", args); + if (args.purpose !== "send") return null; + const value = await ctx.prompt.text({ + id: `prompt-${args.values.label}`, + label: args.values.label ?? "", + title: args.values.title ?? "", + defaultValue: args.values.defaultValue, + placeholder: args.values.placeholder + }); + console.log("VALUE", value); + return value; + } + }] +}; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + plugin +}); diff --git a/src-tauri/vendored/plugins/template-function-prompt/package.json b/src-tauri/vendored/plugins/template-function-prompt/package.json new file mode 100644 index 00000000..26a09dfd --- /dev/null +++ b/src-tauri/vendored/plugins/template-function-prompt/package.json @@ -0,0 +1,9 @@ +{ + "name": "@yaakapp/template-function-prompt", + "private": true, + "version": "0.0.1", + "scripts": { + "build": "yaakcli build ./src/index.ts", + "dev": "yaakcli dev ./src/index.js" + } +} diff --git a/src-tauri/vendored/plugins/template-function-request/build/index.js b/src-tauri/vendored/plugins/template-function-request/build/index.js index 7481e297..79166082 100644 --- a/src-tauri/vendored/plugins/template-function-request/build/index.js +++ b/src-tauri/vendored/plugins/template-function-request/build/index.js @@ -27,12 +27,18 @@ var plugin = { templateFunctions: [ { name: "request.body", - args: [], + args: [{ + name: "requestId", + label: "Http Request", + type: "http_request" + }], async onRender(ctx, args) { - const httpRequest = await ctx.httpRequest.getById({ id: args.values.request ?? "n/a" }); + const httpRequest = await ctx.httpRequest.getById({ id: args.values.requestId ?? "n/a" }); if (httpRequest == null) return null; - const rendered = await ctx.httpRequest.render({ httpRequest, purpose: args.purpose }); - return rendered.body.text ?? ""; + return String(await ctx.templates.render({ + data: httpRequest.body?.text ?? "", + purpose: args.purpose + })); } }, { @@ -52,8 +58,11 @@ var plugin = { async onRender(ctx, args) { const httpRequest = await ctx.httpRequest.getById({ id: args.values.requestId ?? "n/a" }); if (httpRequest == null) return null; - const rendered = await ctx.httpRequest.render({ httpRequest, purpose: args.purpose }); - return rendered.headers.find((h) => h.name.toLowerCase() === args.values.header?.toLowerCase())?.value ?? ""; + const header = httpRequest.headers.find((h) => h.name.toLowerCase() === args.values.header?.toLowerCase()); + return String(await ctx.templates.render({ + data: header?.value ?? "", + purpose: args.purpose + })); } } ] diff --git a/src-tauri/vendored/plugins/template-function-request/package.json b/src-tauri/vendored/plugins/template-function-request/package.json index 021fe43e..a3ebb038 100755 --- a/src-tauri/vendored/plugins/template-function-request/package.json +++ b/src-tauri/vendored/plugins/template-function-request/package.json @@ -1,17 +1,9 @@ { - "name": "template-function-request", + "name": "@yaakapp/template-function-request", "private": true, "version": "0.0.1", "scripts": { "build": "yaakcli build ./src/index.ts", "dev": "yaakcli dev ./src/index.js" - }, - "dependencies": { - "jsonpath-plus": "^9.0.0", - "xpath": "^0.0.34", - "@xmldom/xmldom": "^0.8.10" - }, - "devDependencies": { - "@types/jsonpath": "^0.2.4" } } diff --git a/src-tauri/vendored/plugins/template-function-response/build/index.js b/src-tauri/vendored/plugins/template-function-response/build/index.js index 7a1685e7..2dec37e4 100644 --- a/src-tauri/vendored/plugins/template-function-response/build/index.js +++ b/src-tauri/vendored/plugins/template-function-response/build/index.js @@ -8818,73 +8818,91 @@ var SafeScript = import_vm.default.Script; // src/index.ts var import_node_fs = require("node:fs"); var import_xpath = __toESM(require_xpath()); +var behaviorArg = { + type: "select", + name: "behavior", + label: "Sending Behavior", + defaultValue: "smart", + options: [ + { label: "When no responses", value: "smart" }, + { label: "Always", value: "always" } + ] +}; +var requestArg = { + type: "http_request", + name: "request", + label: "Request" +}; var plugin = { - templateFunctions: [{ - name: "response", - args: [ - { - type: "http_request", - name: "request", - label: "Request" - }, - { - type: "text", - name: "path", - label: "JSONPath or XPath", - placeholder: "$.books[0].id or /books[0]/id" - }, - { - type: "select", - name: "behavior", - label: "Sending Behavior", - defaultValue: "smart", - options: [ - { name: "When no responses", value: "smart" }, - { name: "Always", value: "always" } - ] + templateFunctions: [ + { + name: "response.header", + args: [ + requestArg, + { + type: "text", + name: "header", + label: "Header Name", + placeholder: "Content-Type" + }, + behaviorArg + ], + async onRender(ctx, args) { + if (!args.values.request || !args.values.header) return null; + const response = await getResponse(ctx, { + requestId: args.values.request, + purpose: args.purpose, + behavior: args.values.behavior ?? null + }); + if (response == null) return null; + const header = response.headers.find( + (h) => h.name.toLowerCase() === String(args.values.header ?? "").toLowerCase() + ); + return header?.value ?? null; } - ], - async onRender(ctx, args) { - if (!args.values.request || !args.values.path) { + }, + { + name: "response.body.path", + aliases: ["response"], + args: [ + requestArg, + { + type: "text", + name: "path", + label: "JSONPath or XPath", + placeholder: "$.books[0].id or /books[0]/id" + }, + behaviorArg + ], + async onRender(ctx, args) { + if (!args.values.request || !args.values.path) return null; + const response = await getResponse(ctx, { + requestId: args.values.request, + purpose: args.purpose, + behavior: args.values.behavior ?? null + }); + if (response == null) return null; + if (response.bodyPath == null) { + return null; + } + let body; + try { + body = (0, import_node_fs.readFileSync)(response.bodyPath, "utf-8"); + } catch (_) { + return null; + } + try { + return filterJSONPath(body, args.values.path); + } catch (err) { + } + try { + return filterXPath(body, args.values.path); + } catch (err) { + } return null; } - const httpRequest = await ctx.httpRequest.getById({ id: args.values.request ?? "n/a" }); - if (httpRequest == null) { - return null; - } - const responses = await ctx.httpResponse.find({ requestId: httpRequest.id, limit: 1 }); - if (args.values.behavior === "never" && responses.length === 0) { - return null; - } - let response = responses[0] ?? null; - let behavior = args.values.behavior === "always" && args.purpose === "preview" ? "smart" : args.values.behavior; - if (behavior === "smart" && response == null || behavior === "always") { - const renderedHttpRequest = await ctx.httpRequest.render({ httpRequest, purpose: args.purpose }); - response = await ctx.httpRequest.send({ httpRequest: renderedHttpRequest }); - } - if (response == null) { - return null; - } - if (response.bodyPath == null) { - return null; - } - let body; - try { - body = (0, import_node_fs.readFileSync)(response.bodyPath, "utf-8"); - } catch (_) { - return null; - } - try { - return filterJSONPath(body, args.values.path); - } catch (err) { - } - try { - return filterXPath(body, args.values.path); - } catch (err) { - } - return null; } - }] + ] }; function filterJSONPath(body, path) { const parsed = JSON.parse(body); @@ -8907,6 +8925,24 @@ function filterXPath(body, path) { return String(items); } } +async function getResponse(ctx, { requestId, behavior, purpose }) { + if (!requestId) return null; + const httpRequest = await ctx.httpRequest.getById({ id: requestId ?? "n/a" }); + if (httpRequest == null) { + return null; + } + const responses = await ctx.httpResponse.find({ requestId: httpRequest.id, limit: 1 }); + if (behavior === "never" && responses.length === 0) { + return null; + } + let response = responses[0] ?? null; + let finalBehavior = behavior === "always" && purpose === "preview" ? "smart" : behavior; + if (finalBehavior === "smart" && response == null || finalBehavior === "always") { + const renderedHttpRequest = await ctx.httpRequest.render({ httpRequest, purpose }); + response = await ctx.httpRequest.send({ httpRequest: renderedHttpRequest }); + } + return response; +} // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { plugin diff --git a/src-web/hooks/useActiveWorkspaceChangedToast.tsx b/src-web/hooks/useActiveWorkspaceChangedToast.tsx index 16a8eec9..af0df810 100644 --- a/src-web/hooks/useActiveWorkspaceChangedToast.tsx +++ b/src-web/hooks/useActiveWorkspaceChangedToast.tsx @@ -18,11 +18,12 @@ export function useActiveWorkspaceChangedToast() { if (id === null) return; toast.show({ - id: 'workspace-changed', + id: `workspace-changed-${activeWorkspace.id}`, timeout: 3000, message: ( <> - Switched workspace to {activeWorkspace.name} + Activated workspace{' '} + {activeWorkspace.name} ), });