Updated plugin APIs

This commit is contained in:
Gregory Schier
2024-08-01 07:01:57 -07:00
parent 5639e358bc
commit d6e5bc6df5
7 changed files with 42 additions and 15 deletions

View File

@@ -7,7 +7,8 @@
"lib" "lib"
], ],
"scripts": { "scripts": {
"prepublish": "tsc" "build": "tsc",
"prepublish": "npm run build"
}, },
"dependencies": { "dependencies": {
"@types/node": "^22.0.0" "@types/node": "^22.0.0"

View File

@@ -1,2 +1,2 @@
export type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>; export type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
export type SingleOrArray<T> = T[] | T; export type OneOrMany<T> = T[] | T;

View File

@@ -0,0 +1,13 @@
import { YaakContext } from './context';
export type FilterPluginResponse = string[];
export type FilterPlugin = {
name: string;
description?: string;
canFilter(ctx: YaakContext, args: { mimeType: string }): Promise<boolean>;
onFilter(
ctx: YaakContext,
args: { payload: string; mimeType: string },
): Promise<FilterPluginResponse>;
};

View File

@@ -0,0 +1,8 @@
import { HttpRequest } from '../models';
import { YaakContext } from './context';
export type HttpRequestActionPlugin = {
key: string;
label: string;
onSelect(ctx: YaakContext, args: { httpRequest: HttpRequest }): void;
};

View File

@@ -3,14 +3,14 @@ import { Environment, Folder, HttpRequest, Workspace } from '../models';
import { YaakContext } from './context'; import { YaakContext } from './context';
export type ImportPluginResponse = null | { export type ImportPluginResponse = null | {
resources: Partial<{ workspaces: AtLeast<Workspace, 'name' | 'id' | 'model'>[];
workspaces: AtLeast<Workspace, 'name' | 'id' | 'model'>[]; environments: AtLeast<Environment, 'name' | 'id' | 'model' | 'workspaceId'>[];
environments: AtLeast<Environment, 'name' | 'id' | 'model' | 'workspaceId'>[]; httpRequests: AtLeast<HttpRequest, 'name' | 'id' | 'model' | 'workspaceId'>[];
httpRequests: AtLeast<HttpRequest, 'name' | 'id' | 'model' | 'workspaceId'>[]; folders: AtLeast<Folder, 'name' | 'id' | 'model' | 'workspaceId'>[];
folders: AtLeast<Folder, 'name' | 'id' | 'model' | 'workspaceId'>[];
}>;
}; };
export type ImporterPlugin = { export type ImporterPlugin = {
onImport(ctx: YaakContext, fileContents: string): Promise<ImportPluginResponse>; name: string;
description?: string;
onImport(ctx: YaakContext, args: { text: string }): Promise<ImportPluginResponse>;
}; };

View File

@@ -1,4 +1,6 @@
import { SingleOrArray } from '../helpers'; import { OneOrMany } from '../helpers';
import { FilterPlugin } from './filter';
import { HttpRequestActionPlugin } from './httpRequestAction';
import { ImporterPlugin } from './import'; import { ImporterPlugin } from './import';
import { ThemePlugin } from './theme'; import { ThemePlugin } from './theme';
@@ -6,8 +8,8 @@ import { ThemePlugin } from './theme';
* The global structure of a Yaak plugin * The global structure of a Yaak plugin
*/ */
export type YaakPlugin = { export type YaakPlugin = {
/** One or many plugins to import data into Yaak */ importer?: OneOrMany<ImporterPlugin>;
importers?: SingleOrArray<ImporterPlugin>; theme?: OneOrMany<ThemePlugin>;
/** One or many themes to customize the Yaak UI */ filter?: OneOrMany<FilterPlugin>;
themes?: SingleOrArray<ThemePlugin>; httpRequestAction?: OneOrMany<HttpRequestActionPlugin>;
}; };

View File

@@ -1,5 +1,8 @@
import { Theme } from '../themes'; import { Theme } from '../themes';
import { YaakContext } from './context';
export type ThemePlugin = { export type ThemePlugin = {
theme: Theme; name: string;
description?: string;
getTheme(ctx: YaakContext, fileContents: string): Promise<Theme>;
}; };