Add @yaakapp/api everywhere

This commit is contained in:
Gregory Schier
2024-08-15 06:17:33 -07:00
parent bb3f948596
commit 54efb6ae4e
25 changed files with 258 additions and 1984 deletions

View File

@@ -1,10 +1,17 @@
import { DOMParser } from '@xmldom/xmldom';
import { YaakContext } from '@yaakapp/api';
import xpath from 'xpath';
export function pluginHookResponseFilter(
_ctx: any,
_ctx: YaakContext,
{ filter, body }: { filter: string; body: string },
) {
const doc = new DOMParser().parseFromString(body, 'text/xml');
return `${xpath.select(filter, doc)}`;
const result = xpath.select(filter, doc, false);
if (Array.isArray(result)) {
return result.map(r => String(r)).join('\n');
} else {
// Not sure what cases this happens in (?)
return String(result);
}
}