apipost-runtime8
Version:
apipost-runtime 新版本 for apipost8 支持单接口http请求、自动化测试, 使用全新的参数结构
691 lines (665 loc) • 22.3 kB
TypeScript
/**
* Runtime 核心
* @param emitRuntimeEvent - 返回结果回调函数
*/
declare class Runtime {
constructor(emitRuntimeEvent: (...params: any[]) => any);
/**
* 异步运行
* @param [option = {}] - HTTP 运行时选项或者空对象
*/
startRun(definitions: DefinitionItemObject[], option?: HttpRuntimeOption): void;
}
/**
* http 单个请求
* @param option - The options object.
* @param test_events - The test events object.
*/
declare class HttpRuntime {
constructor(option: HttpRuntimeOption, test_events: TestEventItemObject[]);
/**
* 停止发送或断开
*/
stop(): void;
/**
* 执行http请求
* @returns - 通过Promise返回结果
*/
run(): Promise<ApipostResponseBox>;
}
/**
* 自动化请求
* @param option - The options object.
* @param test_events - The test events object.
*/
declare class RunnerRuntime {
constructor(option: HttpRuntimeOption, test_events: TestEventItemObject[]);
/**
* 当有任务执行,主动停止任务
*/
stop(): void;
/**
* 执行http请求
* @param emitRuntimeEvent - 返回结果回调函数
* @returns - 通过Promise返回结果
*/
run(emitRuntimeEvent: (...params: any[]) => any): Promise<{ msg: string; error: null; }>;
}
/**
* http认证配置对象。此对象包含了各种认证方式所需的参数。
* @property type - 认证方式,noauth为此处为无需认证。
* @property kv - 键值对认证方式的参数。
* @property kv.key - 键值对认证的键。
* @property kv.value - 键值对认证的值。
* @property bearer - Bearer Token 认证方式的参数。
* @property bearer.key - Bearer Token 的键。
* @property basic - Basic Auth 认证方式的参数。
* @property basic.username - Basic Auth 的用户名。
* @property basic.password - Basic Auth 的密码。
* @property digest - Digest Auth 认证方式的参数。
* @property digest.username - Digest Auth 的用户名。
* @property digest.password - Digest Auth 的密码。
* @property digest.realm - Digest Auth 的域。
* @property digest.nonce - Digest Auth 的随机数。
* @property digest.algorithm - Digest Auth 的算法。
* @property digest.qop - Digest Auth 的质量保证。
* @property digest.nc - Digest Auth 的序列号。
* @property digest.cnonce - Digest Auth 的客户端随机数。
* @property digest.opaque - Digest Auth 的不透明数据。
* @property hawk - Hawk Auth 认证方式的参数。
* @property hawk.authId - Hawk Auth 的身份验证ID。
* @property hawk.authKey - Hawk Auth 的密钥。
* @property hawk.algorithm - Hawk Auth 的算法。
* @property hawk.user - Hawk Auth 的用户。
* @property hawk.nonce - Hawk Auth 的随机数。
* @property hawk.extraData - Hawk Auth 的额外数据。
* @property hawk.default - Hawk Auth 的默认设置。
* @property hawk.delegation - Hawk Auth 的委托。
* @property hawk.timestamp - Hawk Auth 的时间戳。
* @property hawk.includePayloadHash - 是否包含载荷哈希。
* @property awsv4 - AWS v4 认证方式的参数。
* @property awsv4.accessKey - AWS v4 的访问密钥。
* @property awsv4.secretKey - AWS v4 的秘密密钥。
* @property awsv4.region - AWS v4 的区域。
* @property awsv4.service - AWS v4 的服务。
* @property awsv4.sessionToken - AWS v4 的会话令牌。
* @property awsv4.addAuthDataToQuery - 是否将认证数据添加到查询中。
* @property ntlm - NTLM 认证方式的参数。
* @property ntlm.username - NTLM 的用户名。
* @property ntlm.password - NTLM 的密码。
* @property ntlm.domain - NTLM 的域。
* @property ntlm.workstation - NTLM 的工作站。
* @property ntlm.disableRetryRequest - 禁用重试请求。
* @property edgegrid - EdgeGrid 认证方式的参数。
* @property edgegrid.accessToken - EdgeGrid 的访问令牌。
* @property edgegrid.clientToken - EdgeGrid 的客户端令牌。
* @property edgegrid.clientSecret - EdgeGrid 的客户端密钥。
* @property edgegrid.nonce - EdgeGrid 的随机数。
* @property edgegrid.timestamp - EdgeGrid 的时间戳。
* @property edgegrid.baseURi - EdgeGrid 的基本URI。
* @property edgegrid.headersToSign - EdgeGrid 需要签名的标头。
* @property oauth1 - OAuth1 认证方式的参数。
* @property oauth1.consumerKey - OAuth1 的消费者密钥。
* @property oauth1.consumerSecret - OAuth1 的消费者秘密。
* @property oauth1.signatureMethod - OAuth1 的签名方法。
* @property oauth1.addEmptyParamsToSign - 是否在签名中添加空参数。
* @property oauth1.includeBodyHash - 是否包含主体哈希。
* @property oauth1.addParamsToHeader - 是否将参数添加到标头。
* @property oauth1.realm - OAuth1 的领域。
* @property oauth1.version - OAuth1 的版本。
* @property oauth1.nonce - OAuth1 的随机数。
* @property oauth1.timestamp - OAuth1 的时间戳。
* @property oauth1.verifier - OAuth1 的验证器。
* @property oauth1.callback - OAuth1 的回调。
* @property oauth1.tokenSecret - OAuth1 的令牌秘密。
* @property oauth1.token - OAuth1 的令牌。
*/
declare type HttpAuthConfig = {
type: "string";
kv: {
key: string;
value: string;
};
bearer: {
key: string;
};
basic: {
username: string;
password: string;
};
digest: {
username: string;
password: string;
realm: string;
nonce: string;
algorithm: string;
qop: string;
nc: string;
cnonce: string;
opaque: string;
};
hawk: {
authId: string;
authKey: string;
algorithm: string;
user: string;
nonce: string;
extraData: string;
default: string;
delegation: string;
timestamp: string;
includePayloadHash: number;
};
awsv4: {
accessKey: string;
secretKey: string;
region: string;
service: string;
sessionToken: string;
addAuthDataToQuery: number;
};
ntlm: {
username: string;
password: string;
domain: string;
workstation: string;
disableRetryRequest: number;
};
edgegrid: {
accessToken: string;
clientToken: string;
clientSecret: string;
nonce: string;
timestamp: string;
baseURi: string;
headersToSign: string;
};
oauth1: {
consumerKey: string;
consumerSecret: string;
signatureMethod: string;
addEmptyParamsToSign: number;
includeBodyHash: number;
addParamsToHeader: number;
realm: string;
version: string;
nonce: string;
timestamp: string;
verifier: string;
callback: string;
tokenSecret: string;
token: string;
};
};
/**
* http请求参数定义
* @property description - 描述信息
* @property field_type - 字段类型
* @property is_checked - 是否已检查
* @property key - 键值
* @property content_type - value的content-type 适配 form-data类型参数
* @property [name] - cookie旧数据兼容
* @property value - 值
* @property [file_base64] - 文件类型数据
* @property not_null - 是否不为空
* @property param_id - 参数ID
*/
declare type HttpParam = {
description: string;
field_type: string;
is_checked: number;
key: string;
content_type: string;
name?: string;
value: string;
file_base64?: string;
not_null: number;
param_id: string;
};
/**
* http前后置任务元素对象
* @property type - 任务类型,customScript
* @property id - 任务ID
* @property name - 任务名称
* @property enabled - 是否启用任务,1代表启用
* @property data - 任务具体配置
*/
declare type HttpTask = {
type: string;
id: string;
name: string;
enabled: number;
data: string;
};
/**
* HTTP 系统配置参数配置参数
* @property send_timeout - 发送超时时间(毫秒)
* @property auto_redirect - 自动重定向设置:-1 表示禁用,0 表示遵循协议,1 表示遵循所有
* @property max_redirect_time - 最大重定向次数
* @property auto_gen_mock_url - 是否自动生成模拟 URL
* @property request_param_auto_json - 请求参数是否自动转为 JSON
* @property proxy - 代理配置
* @property proxy.type - 代理类型
* @property proxy.envfirst - 是否首先检查环境变量
* @property proxy.bypass - 代理绕过的协议列表
* @property proxy.protocols - 需要代理的协议列表
* @property proxy.auth - 代理认证信息
* @property proxy.auth.authenticate - 是否需要认证
* @property proxy.auth.host - 认证主机
* @property proxy.auth.username - 认证用户名
* @property proxy.auth.password - 认证密码
* @property ca_cert - CA 证书配置
* @property ca_cert.open - 是否开启 CA 证书验证
* @property ca_cert.path - CA 证书路径
* @property ca_cert.base64 - BASE64 编码的 CA 证书内容
* @property client_cert - 客户端证书配置
*/
declare type HttpSystemConfig = {
send_timeout: number;
auto_redirect: number;
max_redirect_time: number;
auto_gen_mock_url: number;
request_param_auto_json: number;
proxy: {
type: number;
envfirst: number;
bypass: string[];
protocols: string[];
auth: {
authenticate: number;
host: string;
username: string;
password: string;
};
};
ca_cert: {
open: number;
path: string;
base64: string;
};
client_cert: any;
};
/**
* HTTP runtime option结果
* @property scene - 场景,可选参数http_request
* @property globals - 全局参数
* @property project - 项目默认配置
* @property env - 运行环境信息
* @property cookies - cookie 信息
* @property system_configs - 系统配置信息
* @property collection - 运行相关的目录配置
* @property database_configs - 数据库配置信息
* @property [iterationCount] - 循环次数,自动化测试才有
* @property [sleep] - 间隔时间,自动化测试才有
* @property [iterationData] - 自动化测试数据
* @property [ignore_error] - 忽略执行错误
*/
declare type HttpRuntimeOption = {
scene: string;
globals: {
[key: string]: string;
};
project: any;
env: any;
cookies: any;
system_configs: HttpSystemConfig;
collection: object[];
database_configs: any;
iterationCount?: number;
sleep?: number;
iterationData?: any;
ignore_error?: number;
};
/**
* 创建Collection, 是HttpRuntimeOption 子集
* @property [testingID] - 当前测试用例ID,自动化测试才有
* @property [reportID] - 报告ID,自动化测试才有
* @property [reportName] - 报告名称,自动化测试才有
* @property [env] - 环境变量
* @property [globals] - 全局变量
* @property [envID] - 环境ID,自动化测试才有
* @property [envName] - 环境名称,自动化测试才有
* @property [scene] - 场景类型
* @property [iterationCount] - 循环次数,自动化测试才有
* @property [sleep] - 间隔时间,自动化测试才有
* @property [iterationData] - 自动化测试数据,自动化测试才有
*/
declare type HttpRuntimeCollectionOption = {
testingID?: string;
reportID?: string;
reportName?: string;
env?: any;
globals?: any;
envID?: string;
envName?: string;
scene?: string;
iterationCount?: number;
sleep?: number;
iterationData?: any;
};
/**
* 表示一个单任务的对象
* @property parent_id - 父ID
* @property event_id - 事件的ID
* @property testing_id - 测试的ID
* @property project_id - 项目id的ID
* @property [report_id] - 报告ID,自动化测试才有
* @property [report_name] - 报告名称,自动化测试才有
* @property [env_id] - 环境ID,自动化测试才有
* @property [env_name] - 环境名称,自动化测试才有
* @property sleep - 当前步骤延迟时间
* @property init - 是否初始化状态
* @property iterationItemData - 当前的数据变量(指定行)
* @property type - 类型
* @property requestJson - 包含任务数据的对象
* @property postmanJSON - 包含任务数据的对象
* @property data - 包含任务数据的对象
* @property data.limit - 迭代次数限制
* @property data.enable_data - 是否使用测试数据
* @property data.sleep - 内置步骤延迟时间
* @property [data.content] - 数据详细内容
* @property data.iterationData - excel导入的测试数据变量
* @property enabled - 是否启用该任务
* @property [auto_sync] - 是否自动同步,如果不存在为-1
* @property processCurrentCount - 当前运行次数
* @property [processTotalCount] - 运行总次数
* @property children - 子任务数组
*/
declare type DefinitionItemObject = {
parent_id: string;
event_id: string;
testing_id: string;
project_id: string;
report_id?: string;
report_name?: string;
env_id?: string;
env_name?: string;
sleep: number;
init: boolean;
iterationItemData: any;
type: string;
requestJson: any;
postmanJSON: any;
data: {
limit: number;
enable_data: number;
sleep: number;
content?: any;
iterationData: any[];
};
enabled: number;
auto_sync?: number;
processCurrentCount: number;
processTotalCount?: number;
children: DefinitionItemObject[];
};
/**
* Collection声明的Definition 对象
* @property configurable - 是否可配置
* @property writable - 是否可写
* @property value - 数组内容
*/
declare type DefinitionObject = {
configurable: boolean;
writable: boolean;
value: DefinitionItemObject[];
};
/**
* 表示一个Cookie的配置对象。
* @property name - Cookie的名称。
* @property key - Cookie的名称。
* @property value - Cookie的值。
* @property domain - Cookie的域。
* @property expires - Cookie的expires。
* @property [path = "/"] - Cookie的路径。这个属性是可选的,默认为根路径"/"。
* @property [maxAge] - Cookie的最大存活时间(以秒为单位)。这个属性是可选的。
* @property [secure = false] - 是否只通过https传输Cookie。这个属性是可选的,默认为false表示不启用。
* @property [httpOnly = false] - 是否禁止JavaScript访问Cookie。这个属性是可选的,默认为false表示JavaScript可以访问。
* @property [sameSite = "strict"] - Cookie的SameSite设置。可以是"strict"、"lax"或者"none"。如果未指定,默认为"strict"。
*/
declare type CookieItemObject = {
name: string;
key: string;
value: string;
domain: string;
expires: string;
path?: string;
maxAge?: number;
secure?: boolean;
httpOnly?: boolean;
sameSite?: string;
};
/**
* 定义visualizer对象的类型。
* @property processedTemplate - 已处理的模板。
* @property error - 错误信息。
*/
declare type VisualizerObject = {
processedTemplate: string;
error: Error;
};
/**
* runtime 事件对象定义
* @property action - 动作类型。
* @property data - 与事件相关的任意类型数据。
* @property msg - 事件消息。
* @property [error = null] - 可能出现的错误,可以是任意类型,如果没有错误则为null。
*/
declare type RuntimeEventOject = {
action: string;
data: any;
msg: string;
error?: any;
};
/**
* test_events 数据结构
* @property type - 类型,默认是api
* @property [enabled] - 是否启用,自动化测试中使用
* @property [event_id] - 事件的ID,自动化测试中使用
* @property [testing_id] - 测试的ID,自动化测试中使用
* @property [project_id] - 项目id的ID,自动化测试中使用
* @property [sort = 1] - 排序字段,默认值为1,自动化测试中使用
* @property [children] - 下级数据,自动化测试中使用, if loop 类型有
* @property data - 具体数据类型
* @property data.project_id - 项目ID。
* @property data.target_id - 目标ID。
* @property data.parent_id - 父ID。
* @property data.target_type - 目标类型,默认是api
* @property data.name - 接口名称。
* @property data.method - 请求方法(例如 "GET", "POST")。
* @property data.url - 请求的URL地址。
* @property data.request - 请求对象
*/
declare type TestEventItemObject = {
type: string;
enabled?: boolean;
event_id?: string;
testing_id?: string;
project_id?: string;
sort?: number;
children?: TestEventItemObject[];
data: {
project_id: string;
target_id: string;
parent_id: string;
target_type: string;
name: string;
method: string;
url: string;
request: any;
};
};
/**
* 前后置脚本结构
* @property type - 脚本的类型。
* @property id - 脚本的唯一标识符。
* @property name - 脚本的名称。
* @property language - 语言类型。
* @property enabled - 指示脚本是否启用,1表示启用,0表示禁用。
* @property data - 拓展参数
* @property timeout - 超时时间。
*/
declare type TaskScriptObject = {
type: string;
id: string;
name: string;
language: string;
enabled: number;
data: any;
timeout: number;
};
/**
* 提取变量结构
* @property name - 变量的名称。
* @property type - 变量的类型。在这个上下文中,它是"tempVars"。
* @property param_id - 变量的唯一标识符。
* @property expression - 定义变量值的表达式。
*/
declare type PickVarsObject = {
name: string;
type: string;
param_id: string;
expression: string;
};
/**
* 证书配置信息。
* @property [key] - 私钥文件的URL。这是一个可选属性。
* @property [crt] - 证书文件(CRT)的URL。这是一个可选属性。
* @property [pfx] - 包含了证书和私钥的PFX文件的URL。这是一个可选属性。
* @property [password] - 证书的密码。
* @property [passphrase] - 证书密码,可能是上面重复
*/
declare type CertificateItemObject = {
key?: any;
crt?: any;
pfx?: any;
password?: string;
passphrase?: string;
};
/**
* 代理配置信息配置信息。
* @property [authenticate = false] - 是否需要认证。这是一个可选属性,默认为 false。
* @property [username] - 用户名。仅当需要认证时提供,这是一个可选属性。
* @property [password] - 密码。仅当需要认证时提供,这是一个可选属性。
* @property host - 数据库服务器的主机名或IP地址。
* @property [port = 80] - 数据库服务器的端口号。这是一个可选属性,默认为 80
*/
declare type ProxyItemObject = {
authenticate?: boolean;
username?: string;
password?: string;
host: string;
port?: number;
};
/**
* 代表一次迭代的结果。
* @property iteration_id - 迭代ID。
* @property type - 类型。
* @property error - 错误信息,如果有的话。
* @property target_id - 目标ID。
* @property event_id - 事件ID。
* @property project_id - 项目ID。
* @property testing_id - 测试ID。
* @property data - apipost 返回数据
*/
declare type ApipostResponseBox = {
iteration_id: string;
type: string;
error: null;
target_id: string;
event_id: string;
project_id: string;
testing_id: string;
data: ApipostResponseItem;
};
/**
* 包含迭代中所有数据的对象。
* @property variables - 变量集。
* @property variables.from - 来源对象。
* @property variables.environment - 环境变量。
* @property variables.globals - 全局变量。
* @property variables.variables - 附加变量。
* @property request - 请求信息。
* @property response - 响应信息。
* @property visualizer - 可视化信息。
*/
declare type ApipostResponseItem = {
variables: {
from: any;
environment: any;
globals: any;
variables: any;
};
request: PostmanRequestObject;
response: PostmanResponseObject;
visualizer: VisualizerObject;
};
/**
* 表示一个Postman请求对象。
* @property url - 请求URL。
* @property headers - 请求头。
* @property method - 请求方法(如"POST")。
* @property name - 接口名称。
* @property project_id - 项目ID。
* @property querys - 查询参数。
* @property body - 请求体。
* @property cookies - 请求中的Cookie信息。
*/
declare type PostmanRequestObject = {
url: string;
headers: any;
method: string;
name: string;
project_id: string;
querys: any;
body: any | undefined;
cookies: any;
};
/**
* 表示一个Postman响应对象。
* @property id - 响应ID。
* @property status - 响应状态文本。
* @property code - HTTP状态码。
* @property headers - 响应头。
* @property cookies - 响应中的Cookie信息。
* @property responseTime - 响应时间(单位:毫秒)。
* @property responseSize - 响应大小(单位:字节)。
* @property body - 响应体。
* @property mimeType - MIME类型。
* @property fitForShow - 适合展示的类型(如"Monaco")。
* @property proxy - 代理设置。
* @property timings - 请求时间信息。
* @property requestStart - 请求开始时间戳。
*/
declare type PostmanResponseObject = {
id: string;
status: string;
code: number;
headers: any;
cookies: any;
responseTime: number;
responseSize: number;
body: string;
mimeType: any;
fitForShow: string;
proxy: any;
timings: any;
requestStart: number;
};
/**
* @property isProxy - 判断是否使用代理
* @property parentPort - 父进程通信管道。如果不在 Worker 线程中,则为 false
* @property resolveProxy - 解析代理地址的函数
*/
declare type AptProxy = {
isProxy: boolean;
parentPort: boolean | MessagePort;
resolveProxy: (...params: any[]) => any;
};
/**
* Collection 定义
*/
declare class Collection {
constructor(definition: TestEventItemObject[], option: HttpRuntimeCollectionOption);
definition: DefinitionItemObject[];
}