diff --git a/package-lock.json b/package-lock.json index b488ea6c..6be73c28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "plugins/*" ], "dependencies": { - "@yaakapp/api": "^0.2.15" + "@yaakapp/api": "^0.2.16" }, "devDependencies": { "@types/node": "^22.7.4", @@ -1003,9 +1003,9 @@ } }, "node_modules/@yaakapp/api": { - "version": "0.2.15", - "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.2.15.tgz", - "integrity": "sha512-SW5S3Ca00Qo8Z/IhzCWrSQU0CZHHHCZwuDZtJkjTbfVL5Lv0DAaZsORNEIaeHyuqeQU9xRoi+Wr/WHoA3bG6+A==", + "version": "0.2.16", + "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.2.16.tgz", + "integrity": "sha512-rooweCKOMsqbTdSlb4vxe3wL19PpkVualZrtWvRelnUhIPgcJR8EMVNn/K2tZfLGKOXnthZi9xgFBeARnOyuSw==", "dependencies": { "@types/node": "^22.5.4" } @@ -1042,8 +1042,8 @@ "resolved": "plugins/importer-yaak", "link": true }, - "node_modules/@yaakapp/template-function-file": { - "resolved": "plugins/template-function-file", + "node_modules/@yaakapp/template-function-fs": { + "resolved": "plugins/template-function-fs", "link": true }, "node_modules/@yaakapp/template-function-hash": { @@ -1054,10 +1054,6 @@ "resolved": "plugins/template-function-prompt", "link": true }, - "node_modules/@yaakapp/template-function-request": { - "resolved": "plugins/template-function-request", - "link": true - }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -6702,6 +6698,11 @@ }, "plugins/template-function-file": { "name": "@yaakapp/template-function-file", + "version": "0.0.1", + "extraneous": true + }, + "plugins/template-function-fs": { + "name": "@yaakapp/template-function-fs", "version": "0.0.1" }, "plugins/template-function-hash": { @@ -6714,7 +6715,8 @@ }, "plugins/template-function-request": { "name": "@yaakapp/template-function-request", - "version": "0.0.1" + "version": "0.0.1", + "extraneous": true }, "plugins/template-function-response": { "version": "0.0.1", diff --git a/package.json b/package.json index 1633ca27..e6bc3ade 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "workspaces-run": "^1.0.2" }, "dependencies": { - "@yaakapp/api": "^0.2.15" + "@yaakapp/api": "^0.2.16" } } diff --git a/plugins/template-function-file/package.json b/plugins/template-function-fs/package.json similarity index 76% rename from plugins/template-function-file/package.json rename to plugins/template-function-fs/package.json index 59aea7ab..44e59600 100644 --- a/plugins/template-function-file/package.json +++ b/plugins/template-function-fs/package.json @@ -1,5 +1,5 @@ { - "name": "@yaakapp/template-function-file", + "name": "@yaakapp/template-function-fs", "private": true, "version": "0.0.1", "scripts": { diff --git a/plugins/template-function-file/src/index.ts b/plugins/template-function-fs/src/index.ts similarity index 100% rename from plugins/template-function-file/src/index.ts rename to plugins/template-function-fs/src/index.ts diff --git a/plugins/template-function-prompt/src/index.ts b/plugins/template-function-prompt/src/index.ts index 4941253f..957bc8ff 100644 --- a/plugins/template-function-prompt/src/index.ts +++ b/plugins/template-function-prompt/src/index.ts @@ -3,9 +3,9 @@ import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/ap export const plugin: PluginDefinition = { templateFunctions: [{ name: 'prompt.text', + description: 'Prompt the user for input when sending a request', 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 }, ], @@ -14,7 +14,7 @@ export const plugin: PluginDefinition = { return await ctx.prompt.text({ id: `prompt-${args.values.label}`, - label: args.values.label ?? '', + label: args.values.title ?? '', title: args.values.title ?? '', defaultValue: args.values.defaultValue, placeholder: args.values.placeholder, diff --git a/plugins/template-function-request/package.json b/plugins/template-function-request/package.json deleted file mode 100755 index a3ebb038..00000000 --- a/plugins/template-function-request/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@yaakapp/template-function-request", - "private": true, - "version": "0.0.1", - "scripts": { - "build": "yaakcli build ./src/index.ts", - "dev": "yaakcli dev ./src/index.js" - } -} diff --git a/plugins/template-function-request/src/index.ts b/plugins/template-function-request/src/index.ts deleted file mode 100755 index 0567d587..00000000 --- a/plugins/template-function-request/src/index.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api'; - -export const plugin: PluginDefinition = { - templateFunctions: [ - { - name: 'request.body', - args: [{ - name: 'requestId', - label: 'Http Request', - type: 'http_request', - }], - async onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise { - const httpRequest = await ctx.httpRequest.getById({ id: args.values.requestId ?? 'n/a' }); - if (httpRequest == null) return null; - return String(await ctx.templates.render({ - data: httpRequest.body?.text ?? '', - purpose: args.purpose, - })); - }, - }, - { - name: 'request.header', - args: [ - { - name: 'requestId', - label: 'Http Request', - type: 'http_request', - }, - { - name: 'header', - label: 'Header Name', - type: 'text', - }], - async onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise { - const httpRequest = await ctx.httpRequest.getById({ id: args.values.requestId ?? 'n/a' }); - if (httpRequest == null) return null; - 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/plugins/template-function-response/src/index.ts b/plugins/template-function-response/src/index.ts index ae5018a8..2080cd98 100644 --- a/plugins/template-function-response/src/index.ts +++ b/plugins/template-function-response/src/index.ts @@ -61,6 +61,7 @@ export const plugin: PluginDefinition = { }, { name: 'response.body.path', + description: 'Access a field of the response body using JsonPath or XPath', aliases: ['response'], args: [ requestArg, @@ -108,6 +109,38 @@ export const plugin: PluginDefinition = { return null; // Bail out }, }, + { + name: 'response.body.raw', + description: 'Access the entire response body, as text', + aliases: ['response'], + args: [ + requestArg, + behaviorArg, + ], + async onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise { + if (!args.values.request) 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 = readFileSync(response.bodyPath, 'utf-8'); + } catch (_) { + return null; + } + + return body; + }, + }, ], };