mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:13:51 +01:00
Updated plugin APIs
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"prepublish": "tsc"
|
||||
"build": "tsc",
|
||||
"prepublish": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^22.0.0"
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
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;
|
||||
|
||||
13
plugin-runtime-types/src/plugins/filter.ts
Normal file
13
plugin-runtime-types/src/plugins/filter.ts
Normal 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>;
|
||||
};
|
||||
8
plugin-runtime-types/src/plugins/httpRequestAction.ts
Normal file
8
plugin-runtime-types/src/plugins/httpRequestAction.ts
Normal 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;
|
||||
};
|
||||
@@ -3,14 +3,14 @@ import { Environment, Folder, HttpRequest, Workspace } from '../models';
|
||||
import { YaakContext } from './context';
|
||||
|
||||
export type ImportPluginResponse = null | {
|
||||
resources: Partial<{
|
||||
workspaces: AtLeast<Workspace, 'name' | 'id' | 'model'>[];
|
||||
environments: AtLeast<Environment, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
httpRequests: AtLeast<HttpRequest, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
folders: AtLeast<Folder, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
}>;
|
||||
workspaces: AtLeast<Workspace, 'name' | 'id' | 'model'>[];
|
||||
environments: AtLeast<Environment, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
httpRequests: AtLeast<HttpRequest, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
folders: AtLeast<Folder, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
};
|
||||
|
||||
export type ImporterPlugin = {
|
||||
onImport(ctx: YaakContext, fileContents: string): Promise<ImportPluginResponse>;
|
||||
name: string;
|
||||
description?: string;
|
||||
onImport(ctx: YaakContext, args: { text: string }): Promise<ImportPluginResponse>;
|
||||
};
|
||||
|
||||
@@ -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 { ThemePlugin } from './theme';
|
||||
|
||||
@@ -6,8 +8,8 @@ import { ThemePlugin } from './theme';
|
||||
* The global structure of a Yaak plugin
|
||||
*/
|
||||
export type YaakPlugin = {
|
||||
/** One or many plugins to import data into Yaak */
|
||||
importers?: SingleOrArray<ImporterPlugin>;
|
||||
/** One or many themes to customize the Yaak UI */
|
||||
themes?: SingleOrArray<ThemePlugin>;
|
||||
importer?: OneOrMany<ImporterPlugin>;
|
||||
theme?: OneOrMany<ThemePlugin>;
|
||||
filter?: OneOrMany<FilterPlugin>;
|
||||
httpRequestAction?: OneOrMany<HttpRequestActionPlugin>;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Theme } from '../themes';
|
||||
import { YaakContext } from './context';
|
||||
|
||||
export type ThemePlugin = {
|
||||
theme: Theme;
|
||||
name: string;
|
||||
description?: string;
|
||||
getTheme(ctx: YaakContext, fileContents: string): Promise<Theme>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user