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

@@ -7,11 +7,12 @@
"": {
"name": "exporter-curl",
"version": "0.0.1",
"dependencies": {
"@yaakapp/api": "^0.1.6"
},
"devDependencies": {
"@types/node": "^20.14.9",
"esbuild": "^0.21.5",
"typescript": "^5.5.2",
"vite": "^5.3.2",
"vitest": "^1.4.0"
}
},
@@ -699,6 +700,27 @@
"url": "https://opencollective.com/vitest"
}
},
"node_modules/@yaakapp/api": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.6.tgz",
"integrity": "sha512-5lYXKcOVmLzVUrkfU4JOCbz+CBV5Dm/cALoZvfbelvZWOVu3sTrBxS9cbNVQQq2B6WwLInSevk7pMq58GqIj5Q==",
"dependencies": {
"@types/node": "^22.0.0"
}
},
"node_modules/@yaakapp/api/node_modules/@types/node": {
"version": "22.2.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.2.0.tgz",
"integrity": "sha512-bm6EG6/pCpkxDf/0gDNDdtDILMOHgaQBVOJGdwsqClnxA3xL6jtMv76rLBc006RVMWbmaf0xbmom4Z/5o2nRkQ==",
"dependencies": {
"undici-types": "~6.13.0"
}
},
"node_modules/@yaakapp/api/node_modules/undici-types": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz",
"integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg=="
},
"node_modules/acorn": {
"version": "8.11.3",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",

View File

@@ -8,5 +8,8 @@
"@types/node": "^20.14.9",
"typescript": "^5.5.2",
"vitest": "^1.4.0"
},
"dependencies": {
"@yaakapp/api": "^0.1.6"
}
}

View File

@@ -1,8 +1,22 @@
import { HttpRequest } from '../../../src-web/lib/models';
import { HttpRequest, YaakContext, YaakPlugin } from '@yaakapp/api';
const NEWLINE = '\\\n ';
export function pluginHookExport(_: any, request: Partial<HttpRequest>) {
export const plugin: YaakPlugin = {
httpRequestActions: [{
key: 'export-curl',
label: 'Copy as Curl',
icon: 'copy',
async onSelect(ctx, args) {
const rendered_request = await ctx.httpRequest.render({ httpRequest: args.httpRequest });
const data = await pluginHookExport(ctx, rendered_request);
ctx.clipboard.copyText(data);
ctx.toast.show({ variant: 'copied', message: 'Curl copied to clipboard' });
},
}],
};
export async function pluginHookExport(_ctx: YaakContext, request: Partial<HttpRequest>) {
const xs = ['curl'];
// Add method and URL all on first line
@@ -67,7 +81,7 @@ export function pluginHookExport(_: any, request: Partial<HttpRequest>) {
}
function quote(arg: string): string {
const escaped = arg.replace(/'/g, "\\'");
const escaped = arg.replace(/'/g, '\\\'');
return `'${escaped}'`;
}