insomnia/packages/insomnia-app/app/templating/extensions/index.js

88 lines
2.1 KiB
JavaScript
Raw Normal View History

// @flow
2018-06-25 17:42:50 +00:00
import type { NunjucksParsedTagArg } from '../utils';
import type { Request } from '../../models/request';
import type { Response } from '../../models/response';
export type PluginArgumentValue = string | number | boolean;
2018-06-25 17:42:50 +00:00
type DisplayName = string | ((args: Array<NunjucksParsedTagArg>) => string);
type PluginArgumentBase = {
displayName: DisplayName,
description?: string,
help?: string,
2018-06-25 17:42:50 +00:00
hide?: (args: Array<NunjucksParsedTagArg>) => boolean
};
export type PluginArgumentEnumOption = {
displayName: DisplayName,
value: PluginArgumentValue,
2017-11-01 11:24:00 +00:00
description?: string,
placeholder?: string
2018-06-25 17:42:50 +00:00
};
export type PluginArgumentEnum = PluginArgumentBase & {
type: 'enum',
options: Array<PluginArgumentEnumOption>,
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 & {
2018-06-25 17:42:50 +00:00
type: 'number',
placeholder?: string,
defaultValue?: number
};
export type PluginArgument =
2018-06-25 17:42:50 +00:00
| PluginArgumentEnum
| PluginArgumentModel
| PluginArgumentString
| PluginArgumentBoolean
| PluginArgumentFile
| PluginArgumentNumber;
export type PluginTemplateTagContext = {
util: {
models: {
request: {
getById: (id: string) => Promise<Request | null>
},
response: {
getLatestForRequestId: (id: string) => Promise<Response | null>,
2018-10-17 16:42:33 +00:00
getBodyBuffer: (response: Response, fallback?: any) => Promise<Buffer | null>
}
}
}
};
export type PluginTemplateTag = {
args: Array<PluginArgument>,
name: string,
displayName: DisplayName,
description: string,
2018-10-17 16:42:33 +00:00
run: (context: PluginTemplateTagContext, ...arg: Array<any>) => Promise<any> | any,
deprecated?: boolean,
validate?: (value: any) => ?string,
priority?: number
};