2021-05-12 06:35:00 +00:00
|
|
|
import type { Request } from '../../models/request';
|
|
|
|
import type { Response } from '../../models/response';
|
|
|
|
import type { PluginStore } from '../../plugins/context';
|
2021-07-22 23:04:56 +00:00
|
|
|
import type { NunjucksParsedTagArg } from '../utils';
|
2021-05-12 06:35:00 +00:00
|
|
|
|
|
|
|
export type PluginArgumentValue = string | number | boolean;
|
|
|
|
|
2021-05-18 20:32:18 +00:00
|
|
|
type DisplayName = string | ((args: NunjucksParsedTagArg[]) => string);
|
2021-05-12 06:35:00 +00:00
|
|
|
|
|
|
|
interface PluginArgumentBase {
|
|
|
|
displayName: DisplayName;
|
|
|
|
description?: string;
|
|
|
|
help?: string;
|
2021-05-18 20:32:18 +00:00
|
|
|
hide?: (args: NunjucksParsedTagArg[]) => boolean;
|
2021-05-12 06:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface PluginArgumentEnumOption {
|
|
|
|
displayName: DisplayName;
|
|
|
|
value: PluginArgumentValue;
|
|
|
|
description?: string;
|
|
|
|
placeholder?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type PluginArgumentEnum = PluginArgumentBase & {
|
|
|
|
type: 'enum';
|
2021-05-18 20:32:18 +00:00
|
|
|
options: PluginArgumentEnumOption[];
|
2021-05-12 06:35:00 +00:00
|
|
|
defaultValue?: PluginArgumentValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginArgumentModel = PluginArgumentBase & {
|
|
|
|
type: 'model';
|
|
|
|
model: string;
|
|
|
|
defaultValue?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginArgumentString = PluginArgumentBase & {
|
|
|
|
type: 'string';
|
|
|
|
placeholder?: string;
|
|
|
|
defaultValue?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginArgumentBoolean = PluginArgumentBase & {
|
|
|
|
type: 'boolean';
|
|
|
|
defaultValue?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginArgumentFile = PluginArgumentBase & {
|
|
|
|
type: 'file';
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginArgumentNumber = PluginArgumentBase & {
|
|
|
|
type: 'number';
|
|
|
|
placeholder?: string;
|
|
|
|
defaultValue?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PluginArgument =
|
|
|
|
| PluginArgumentEnum
|
|
|
|
| PluginArgumentModel
|
|
|
|
| PluginArgumentString
|
|
|
|
| PluginArgumentBoolean
|
|
|
|
| PluginArgumentFile
|
|
|
|
| PluginArgumentNumber;
|
|
|
|
|
2021-05-27 18:00:32 +00:00
|
|
|
export interface PluginTemplateTagContext {
|
2021-05-12 06:35:00 +00:00
|
|
|
util: {
|
|
|
|
models: {
|
|
|
|
request: {
|
|
|
|
getById: (id: string) => Promise<Request | null>;
|
|
|
|
};
|
|
|
|
response: {
|
|
|
|
getLatestForRequestId: (id: string) => Promise<Response | null>;
|
|
|
|
getBodyBuffer: (response: Response, fallback?: any) => Promise<Buffer | null>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PluginTemplateTagActionContext {
|
|
|
|
store: PluginStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PluginTemplateTagAction {
|
|
|
|
name: string;
|
|
|
|
icon?: string;
|
|
|
|
run: (context: PluginTemplateTagActionContext) => Promise<void>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PluginTemplateTag {
|
2021-05-18 20:32:18 +00:00
|
|
|
args: PluginArgument[];
|
2021-05-12 06:35:00 +00:00
|
|
|
name: string;
|
|
|
|
displayName: DisplayName;
|
|
|
|
disablePreview: () => boolean;
|
|
|
|
description: string;
|
2021-05-18 20:32:18 +00:00
|
|
|
actions: PluginTemplateTagAction[];
|
|
|
|
run: (context: PluginTemplateTagContext, ...arg: any[]) => Promise<any> | any;
|
2021-05-12 06:35:00 +00:00
|
|
|
deprecated?: boolean;
|
|
|
|
validate?: (value: any) => string | null;
|
|
|
|
priority?: number;
|
|
|
|
}
|