UNPKG

betaflow-sdk

Version:

BetaFlow SDK for web applications - A powerful tool for managing beta testing campaigns and user feedback

267 lines (239 loc) 5.64 kB
export interface FormFieldOption { /** 选项值 */ value: string; /** 选项标签 */ label: string; } export interface FormField { /** 字段类型 */ type: 'text' | 'email' | 'tel' | 'url' | 'textarea' | 'select' | 'radio' | 'checkbox'; /** 字段标签 */ label: string; /** 字段名称 */ name?: string; /** 是否必填 */ required?: boolean; /** 占位符文本 */ placeholder?: string; /** 文本域行数 */ rows?: number; /** 选项列表(用于select、radio类型) */ options?: FormFieldOption[] | string[]; } export interface BetaFlowConfig { /** 活动ID */ campaignId: string; /** API密钥 */ apiKey: string; /** API端点地址 */ apiEndpoint?: string; /** 语言设置 */ language?: 'zh-CN' | 'en-US'; /** 主题设置 */ theme?: 'light' | 'dark'; /** 浮动按钮位置 */ position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'; /** 是否开启调试模式 */ debug?: boolean; /** 是否自动显示浮动按钮 */ autoShow?: boolean; /** 浮动按钮文本 */ buttonText?: string; /** 表单标题 */ formTitle?: string; /** 自定义样式 */ customStyles?: string; /** 回调函数 */ onFormSubmit?: (data: any) => void; onFormClose?: () => void; onError?: (error: Error) => void; } export interface ApplicationData { /** 用户姓名 */ name: string; /** 用户邮箱 */ email: string; /** 用户手机号 */ phone?: string; /** 申请理由 */ reason?: string; /** 用户角色 */ role?: string; /** 公司名称 */ company?: string; /** 其他自定义字段 */ [key: string]: any; } export interface BetaFlowResponse { /** 响应状态 */ success: boolean; /** 响应消息 */ message: string; /** 响应数据 */ data?: CampaignInfo; /** 错误代码 */ errorCode?: string; } export interface CampaignInfo { /** 项目ID */ id: string; /** 项目名称 */ name: string; /** 项目描述 */ description?: string; /** 表单标题 */ formTitle?: string; /** 表单字段配置 */ formFields?: FormField[]; /** 表单头部信息 */ formHeader?: FormHeader; /** 项目状态 */ status?: 'ACTIVE' | 'INACTIVE' | 'DRAFT'; /** 其他配置 */ [key: string]: any; } export interface FormField { /** 字段名称 */ name: string; /** 字段标签 */ label: string; /** 字段类型 */ type: 'text' | 'email' | 'tel' | 'url' | 'textarea' | 'select' | 'radio' | 'checkbox' | 'number' | 'date'; /** 是否必填 */ required?: boolean; /** 占位符文本 */ placeholder?: string; /** 选项列表(用于select、radio类型) */ options?: FormFieldOption[]; /** 文本域行数(用于textarea类型) */ rows?: number; /** 字段验证规则 */ validation?: { /** 最小长度 */ minLength?: number; /** 最大长度 */ maxLength?: number; /** 正则表达式 */ pattern?: string; /** 自定义验证消息 */ message?: string; }; /** 字段默认值 */ defaultValue?: string; /** 字段描述或帮助文本 */ description?: string; } export interface FormFieldOption { /** 选项值 */ value: string; /** 选项标签 */ label: string; } export interface FormHeader { /** 头部标题 */ title?: string; /** 头部副标题 */ subtitle?: string; /** 头部描述 */ description?: string; /** 头部图标URL */ iconUrl?: string; /** 头部背景色 */ backgroundColor?: string; /** 头部文字颜色 */ textColor?: string; /** 自定义CSS类名 */ className?: string; } export interface UserVerificationRequest { /** 用户邮箱 */ email?: string; /** 用户手机号 */ phone?: string; } export interface UserVerificationResponse { /** 验证状态 */ success: boolean; /** 响应消息 */ message: string; /** 用户申请状态 */ status?: 'NOT_APPLIED' | 'PENDING' | 'APPROVED' | 'REJECTED'; /** 错误代码 */ errorCode?: 'USER_NOT_APPLIED' | 'USER_NOT_APPROVED' | 'INVALID_PARAMS' | 'NETWORK_ERROR' | 'MISSING_API_KEY'; /** 申请数据 */ applicationData?: any; } /** * BetaFlow SDK 主类 */ export declare class BetaFlow { /** SDK配置 */ config: BetaFlowConfig; /** * 构造函数 * @param config SDK配置 */ constructor(config: BetaFlowConfig); /** * 显示申请表单 */ showApplicationForm(): void; /** * 隐藏申请表单 */ hideApplicationForm(): void; /** * 显示浮动按钮 */ showFloatingButton(): void; /** * 隐藏浮动按钮 */ hideFloatingButton(): void; /** * 提交申请数据 * @param data 申请数据 */ submitApplication(data: ApplicationData): Promise<BetaFlowResponse>; /** * 获取活动信息 */ getCampaignInfo(): Promise<BetaFlowResponse>; /** * 验证用户申请状态 * @param request 验证请求参数(邮箱或手机号) */ verifyUserApplication(request: UserVerificationRequest): Promise<UserVerificationResponse>; /** * 销毁SDK实例 */ destroy(): void; /** * 更新配置 * @param newConfig 新配置 */ updateConfig(newConfig: Partial<BetaFlowConfig>): void; /** * 设置语言 * @param language 语言代码 */ setLanguage(language: 'zh-CN' | 'en-US'): void; /** * 设置主题 * @param theme 主题 */ setTheme(theme: 'light' | 'dark'): void; } /** * 默认导出BetaFlow类 */ export default BetaFlow; /** * 全局声明 */ declare global { interface Window { BetaFlow: typeof BetaFlow; betaflowInstance?: BetaFlow; } }