snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
This commit is contained in:
15
plugins/filter-xpath/package.json
Normal file
15
plugins/filter-xpath/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@yaak/filter-xpath",
|
||||
"displayName": "XPath Filter",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Filter response XML data using XPath expressions",
|
||||
"scripts": {
|
||||
"build": "yaakcli build",
|
||||
"dev": "yaakcli dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"@xmldom/xmldom": "^0.9.12",
|
||||
"xpath": "^0.0.34"
|
||||
}
|
||||
}
|
||||
28
plugins/filter-xpath/src/index.ts
Normal file
28
plugins/filter-xpath/src/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/* oxlint-disable no-base-to-string */
|
||||
import { DOMParser } from "@xmldom/xmldom";
|
||||
import type { PluginDefinition } from "@yaakapp/api";
|
||||
import xpath from "xpath";
|
||||
|
||||
export const plugin: PluginDefinition = {
|
||||
filter: {
|
||||
name: "XPath",
|
||||
description: "Filter XPath",
|
||||
onFilter(_ctx, args) {
|
||||
// oxlint-disable-next-line no-explicit-any
|
||||
const doc: any = new DOMParser().parseFromString(args.payload, "text/xml");
|
||||
try {
|
||||
const result = xpath.select(args.filter, doc, false);
|
||||
if (Array.isArray(result)) {
|
||||
return { content: result.map((r) => String(r)).join("\n") };
|
||||
}
|
||||
// Not sure what cases this happens in (?)
|
||||
return { content: String(result) };
|
||||
} catch (err) {
|
||||
return {
|
||||
content: "",
|
||||
error: `Invalid filter: ${err instanceof Error ? err.message : String(err)}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
3
plugins/filter-xpath/tsconfig.json
Normal file
3
plugins/filter-xpath/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json"
|
||||
}
|
||||
Reference in New Issue
Block a user