mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 16:43:53 +01:00
Tweak plugins
This commit is contained in:
24
package-lock.json
generated
24
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -19,6 +19,6 @@
|
||||
"workspaces-run": "^1.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@yaakapp/api": "^0.2.15"
|
||||
"@yaakapp/api": "^0.2.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@yaakapp/template-function-file",
|
||||
"name": "@yaakapp/template-function-fs",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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<string | null> {
|
||||
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<string | null> {
|
||||
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,
|
||||
}));
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -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<string | null> {
|
||||
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;
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user