import type { PntHighSecurityConfig } from "../config"; /** 单个解锁项 */ export interface HighSecurityParamItem { /** 字段标识(与后端约定) */ key: string; /** 参数密文(_high_security_: 前缀) */ value: string; /** * 缓存别名(可选) * @description 当后端 key 相同但密文不同时(如两组 SDK 密钥), * 用 cacheKey 区分缓存,请求体仍用 key。默认 cacheKey=key */ cacheKey?: string; } /** 单次请求的接口配置覆盖(优先级 > PntProvider 全局配置) */ export type HighSecurityApiConfig = PntHighSecurityConfig; /** * 高敏接口变体 * - 'business'(默认):业务级,走 /api/v3/business/game_info/high-security-decrypt * - 'platform':平台级(发布记录页场景),走 /api/v3/business/game_info/plat-high-security-decrypt */ export type HighSecurityScope = 'business' | 'platform'; /** 高敏数据解锁请求参数(组件层友好命名,库内部转换为后端 snake_case) */ export interface HighSecurityRequestParams { /** 业务 ID */ gameId: string | number; /** 环境标识(可缺省,默认 0;以各业务现有约定为准) */ env?: string | number; /** 页面 ID(不传则默认取 location.pathname),用于操作日志和权限校验 */ pageId?: string; /** 需要解锁的参数列表,支持批量 */ param: HighSecurityParamItem[]; /** 强制刷新:忽略缓存,每次都调接口(默认 false) */ forceRefresh?: boolean; /** 本次请求的接口配置覆盖(可选) */ apiConfig?: HighSecurityApiConfig; /** 本次请求的接口变体,覆盖 hook 初始化时的 scope */ scope?: HighSecurityScope; } /** hook 初始化 scope:传入后 securityData/isUnlocked 自动按该业务+环境过滤 */ export interface UseHighSecurityOptions { /** 当前业务 ID */ gameId?: string | number; /** 当前环境(可缺省,默认 0) */ env?: string | number; /** 接口变体(默认 'business');发布记录页等平台级场景传 'platform' */ scope?: HighSecurityScope; } /** 清缓存过滤条件 */ export interface ClearSecurityDataFilter { gameId?: string | number; env?: string | number; } export interface UseHighSecurityResult { /** * 当前 scope 下已解锁的明文;未传 scope 时为空对象 * @description key 为请求时入参的 cacheKey(未传 cacheKey 时为字段名) */ securityData: Record; /** * 发起解锁 * @description * - 已缓存的 key 直接返回缓存值,不再请求 * - 同一参数的在途请求自动去重 * - 成功:写入模块缓存并返回当次解密数组(含已缓存项) * - 失败/部分失败:仅返回拿到的项(可能为空数组),不抛错 */ requestSecurityData: (params: HighSecurityRequestParams) => Promise; /** * 清缓存:不传参清空全部;传 gameId 清空该业务所有环境; * 同时传 gameId+env 只清空该业务指定环境;仅传 env 清空所有业务该环境 */ clearSecurityData: (filter?: ClearSecurityDataFilter) => void; /** 当前 scope 下某字段是否已解锁(两步式"查看 → 复制"UI 用) */ isUnlocked: (key: string) => boolean; } /** * 高敏数据解锁 Hook(PntSecureBox 内部依赖,同时对外导出供"复制"等非展示场景使用) * * @example * ```tsx * // 展示场景请直接用 PntSecureBox;两步式"查看 → 复制": * const { isUnlocked, requestSecurityData, securityData } = useHighSecurity({ gameId, env }); * const res = await requestSecurityData({ gameId, env, param: [{ key: 'SDK_KEY', value }] }); * if (res.length) copy(securityData.SDK_KEY); * ``` */ export declare const useHighSecurity: (options?: UseHighSecurityOptions) => UseHighSecurityResult;