More plugins (#4)

This commit is contained in:
Gregory Schier
2025-01-14 10:52:32 -08:00
committed by GitHub
parent a80a25a90e
commit e213c76870
7 changed files with 98 additions and 9 deletions

23
package-lock.json generated
View File

@@ -1042,6 +1042,10 @@
"resolved": "plugins/importer-yaak",
"link": true
},
"node_modules/@yaakapp/template-function-file": {
"resolved": "plugins/template-function-file",
"link": true
},
"node_modules/@yaakapp/template-function-fs": {
"resolved": "plugins/template-function-fs",
"link": true
@@ -1054,6 +1058,14 @@
"resolved": "plugins/template-function-prompt",
"link": true
},
"node_modules/@yaakapp/template-function-request": {
"resolved": "plugins/template-function-request",
"link": true
},
"node_modules/@yaakapp/template-function-response": {
"resolved": "plugins/template-function-response",
"link": true
},
"node_modules/aggregate-error": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz",
@@ -5810,10 +5822,6 @@
"array-includes": "^3.0.3"
}
},
"node_modules/template-function-response": {
"resolved": "plugins/template-function-response",
"link": true
},
"node_modules/through2": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/through2/-/through2-0.5.1.tgz",
@@ -6698,8 +6706,7 @@
},
"plugins/template-function-file": {
"name": "@yaakapp/template-function-file",
"version": "0.0.1",
"extraneous": true
"version": "0.0.1"
},
"plugins/template-function-fs": {
"name": "@yaakapp/template-function-fs",
@@ -6715,10 +6722,10 @@
},
"plugins/template-function-request": {
"name": "@yaakapp/template-function-request",
"version": "0.0.1",
"extraneous": true
"version": "0.0.1"
},
"plugins/template-function-response": {
"name": "@yaakapp/template-function-response",
"version": "0.0.1",
"dependencies": {
"@xmldom/xmldom": "^0.8.10",

View File

@@ -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"
}
}

View File

@@ -0,0 +1,18 @@
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
import fs from 'node:fs';
export const plugin: PluginDefinition = {
templateFunctions: [{
name: 'fs.readFile',
args: [{ title: 'Select File', type: 'file', name: 'path', label: 'File' }],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
if (!args.values.path) return null;
try {
return fs.promises.readFile(args.values.path, 'utf-8');
} catch (err) {
return null;
}
},
}],
};

View File

@@ -6,6 +6,7 @@ export const plugin: PluginDefinition = {
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 },
],

View File

@@ -0,0 +1,9 @@
{
"name": "@yaakapp/template-function-request",
"private": true,
"version": "0.0.1",
"scripts": {
"build": "yaakcli build ./src/index.ts",
"dev": "yaakcli dev ./src/index.js"
}
}

View File

@@ -0,0 +1,45 @@
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,
}));
},
},
],
};

View File

@@ -1,5 +1,5 @@
{
"name": "template-function-response",
"name": "@yaakapp/template-function-response",
"private": true,
"version": "0.0.1",
"scripts": {