import { SelectOption } from 'star-horse-lowcode'; /** HTTP 方法 */ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; /** 参数值类型 */ export type ParamValueType = "static" | "dynamic"; /** 通用请求参数项(请求头 / 查询参数共用) */ export interface HttpParam { /** 参数名(header 名 或 query 参数名) */ paramName: string; /** 参数值(static 模式填原始值,dynamic 模式填表单字段名) */ paramValue: string; /** 值类型 */ valueType: ParamValueType; } /** 认证类型 */ export type AuthType = "none" | "login" | "basic" | "bearer" | "custom"; /** 认证配置 */ export interface HttpAuthConfig { /** 认证类型 */ authType: AuthType; /** 登录地址(login) */ loginUrl?: string; /** 登录方法(login) */ loginMethod?: HttpMethod; /** 登录账号(login) */ loginAccount?: string; /** 登录密码(login) */ loginPassword?: string; /** Token 提取路径(login) */ loginTokenPath?: string; /** Token 请求头名称(login) */ loginHeaderName?: string; /** Basic 用户名(basic) */ basicUsername?: string; /** Basic 密码(basic) */ basicPassword?: string; /** Bearer Token 值(bearer) */ bearerToken?: string; /** 自定义请求头 JSON 字符串(custom) */ customHeaders?: string; } /** HTTP 请求配置 */ export interface HttpRequestConfig { /** 请求地址(支持 ${fieldName} 模板) */ url: string; /** HTTP 方法,默认 GET */ httpMethod?: HttpMethod; /** 请求头列表 */ headers?: HttpParam[]; /** 查询参数列表 */ requestParams?: HttpParam[]; /** 请求体(JSON 字符串或对象,支持 ${fieldName} 模板) */ body?: string | Record; /** 超时时间(毫秒),默认 10000 */ timeout?: number; /** 重试次数,默认 0 */ retryCount?: number; /** 认证配置 */ auth?: HttpAuthConfig; /** 是否走代理转发,默认 true */ proxyEnabled?: boolean; /** 代理接口地址,默认 /system-config/redirect/apiLinkage */ proxyUrl?: string; } /** HTTP 响应配置 */ export interface HttpResponseConfig { /** 成功状态码(数字或字符串),默认 "200" */ successCode?: string | number; /** 状态码路径(用于从响应体中提取 code),默认 "code" */ codePath?: string; /** 消息路径,默认 "message" */ messagePath?: string; /** 数据提取路径(用于从响应体中提取 data),默认 "data" */ dataPath?: string; /** 字段映射列表(联动/规则引擎用) */ fieldMappings?: FieldMapping[]; /** 数据源模式:标签字段名 */ labelField?: string; /** 数据源模式:值字段名 */ valueField?: string; } /** 字段映射 */ export interface FieldMapping { /** 响应数据中的源字段名 */ sourceField: string; /** 目标字段名(表单字段名 / 上下文变量名) */ targetField: string; /** 类型转换 */ typeConvert?: "string" | "number" | "boolean" | "array"; } /** 执行上下文(模板解析用) */ export interface HttpCallContext { /** 表单数据(用于模板解析 & 动态参数替换) */ formData?: Record; /** 额外上下文(规则引擎执行时的变量等) */ extraContext?: Record; } /** 统一 HTTP 调用结果 */ export interface HttpCallResult { /** 调用是否成功(网络可达 + 状态码匹配) */ success: boolean; /** 业务状态码 */ code: string | number; /** 响应消息 */ message: string; /** 按 dataPath 提取后的数据 */ data: T; /** 原始响应体 */ raw: any; /** 数据源模式:按 labelField/valueField 转换的选项列表 */ options?: SelectOption[]; /** 联动 / 规则引擎模式:按 fieldMappings 映射后的字段值 */ mappedFields?: Record; } /** * 统一 HTTP 客户端 */ export declare const httpClient: { /** 执行 HTTP 调用(代理模式,通过后端统一转发) */ execute: (reqConfig: HttpRequestConfig, respConfig?: HttpResponseConfig, context?: HttpCallContext) => Promise; /** 解析 ${field} 模板 */ resolveTemplate: (template: string, ctx: Record) => string; /** 按点路径从对象中提取值 */ resolveByPath: (obj: any, path: string) => any; /** 将 data 数组转为 SelectOption[](数据源模式) */ buildOptions: (data: any, labelField: string, valueField: string) => SelectOption[]; /** 对提取的 data 做字段映射(联动模式) */ applyFieldMappings: (data: any, mappings: FieldMapping[]) => Record; }; export default httpClient;