Bump plugin deps

This commit is contained in:
Gregory Schier
2024-08-22 11:27:57 -07:00
parent d1871b19ee
commit 5ba11ca788
20 changed files with 66 additions and 55 deletions

View File

@@ -9,7 +9,7 @@
"version": "0.0.1",
"dependencies": {
"@xmldom/xmldom": "^0.8.10",
"@yaakapp/api": "^0.1.9",
"@yaakapp/api": "^0.1.11",
"jsonpath-plus": "^9.0.0",
"xpath": "^0.0.34"
},
@@ -741,9 +741,9 @@
}
},
"node_modules/@yaakapp/api": {
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.9.tgz",
"integrity": "sha512-5mgBoNplXUnNIUpLgGPCjcf6p/BcsU485cH3/MnIzcXIaMfFpZVVwHq5vf9cm+NDcr5hwYmPyIbwmBf9uVoV2Q==",
"version": "0.1.11",
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.11.tgz",
"integrity": "sha512-dRZAXrQpftWygy9nJXiIYPzLA9om6reO/RiEacMe9RKqMjNG6FRF8cGmj7BcdyreizJOkH/DmcOpxn09kDD0XA==",
"dependencies": {
"@types/node": "^22.0.0"
}

View File

@@ -6,7 +6,7 @@
"build": "yaakcli src/index.ts"
},
"dependencies": {
"@yaakapp/api": "^0.1.9",
"@yaakapp/api": "^0.1.11",
"jsonpath-plus": "^9.0.0",
"xpath": "^0.0.34",
"@xmldom/xmldom": "^0.8.10"

View File

@@ -1,5 +1,5 @@
import { DOMParser } from '@xmldom/xmldom';
import { CallTemplateFunctionArgs, Context, Plugin } from '@yaakapp/api';
import { CallTemplateFunctionArgs, Context, HttpResponse, Plugin } from '@yaakapp/api';
import { JSONPath } from 'jsonpath-plus';
import { readFileSync } from 'node:fs';
import xpath from 'xpath';
@@ -17,7 +17,7 @@ export const plugin: Plugin = {
type: 'text',
name: 'path',
label: 'JSONPath or XPath',
placeholder: '$.books[0].id or /books[0]/id'
placeholder: '$.books[0].id or /books[0]/id',
},
{
type: 'select',
@@ -48,9 +48,20 @@ export const plugin: Plugin = {
return null;
}
const response = (args.values.behavior === 'always' || responses[0] == null)
? await ctx.httpRequest.send({ httpRequest: renderedHttpRequest })
: responses[0];
let response: HttpResponse | null = responses[0] ?? null;
// Previews happen a ton, and we don't want to send too many times on "always," so treat
// it as "smart" during preview.
let behavior = args.values.behavior === 'always' && args.purpose === 'preview' ? 'smart' : args.values.behavior;
// Send if no responses and "smart," or "always"
if ((behavior === 'smart' && response == null) || behavior === 'always') {
response = await ctx.httpRequest.send({ httpRequest: renderedHttpRequest });
}
if (response == null) {
return null;
}
if (response.bodyPath == null) {
return null;
@@ -102,7 +113,7 @@ function filterXPath(body: string, path: string): string {
const items = xpath.select(path, doc, false);
if (Array.isArray(items)) {
return String(items[0] ?? '');
return items[0] != null ? String(items[0].firstChild ?? '') : '';
} else {
// Not sure what cases this happens in (?)
return String(items);