import type { PntHttpLike } from "../config"; /** * 归一化后的 COS 临时凭证 * @description 各后端接口字段命名不统一(snake/camel),组件库内部统一为 camelCase */ export interface NormalizedCosCredential { /** COS 存储桶 */ bucket: string; /** COS 地域 */ region: string; /** 临时密钥 ID */ secretId: string; /** 临时密钥 Key */ secretKey: string; /** 临时会话令牌 */ sessionToken: string; /** 凭证生效时间(秒) */ startTime: number; /** 凭证过期时间(秒) */ expiredTime: number; /** * 业务路径映射 * @description 后端按业务类型返回的可写路径 map;消费方按 pathKey 选取 */ path?: Record; /** * 受控目录前缀(SDK 定制场景返回) * @description 前端在该前缀下自行拼接文件名;可与 pathKey 继续拼接子目录 */ filePath?: string; /** * CDN 访问域名(不含尾斜杠) * @description SDK 定制场景返回 cdn_url;通用场景无此字段时组件按 COS Location 拼接 */ cosHost?: string; } /** * 通用 COS 凭证响应(snake_case,pnt-tools / account-business) */ interface SnakeCosCredential { bucket: string; region: string; secret_id: string; secret_key: string; token: string; start_time: number; expired_time: number; path?: Record; } /** * 内置业务场景 * @description 决定走哪个后端凭证接口 * - default: 通用上传(GET /v2/business/operation/get-cos-temp-token) * - default_download: 通用下载/上传(POST /v2/business/operation/get-download-cos-temp-token,snake_case) * - sdk_customize: SDK 定制服务(POST /internal/sdk_customize/upload_token,含 cdn_url/file_path) * - ai_translate: AI 翻译服务(POST /business/aiTranslate/import/cosToken,camelCase) */ export type CosScene = 'default' | 'default_download' | 'sdk_customize' | 'ai_translate' | (string & Record); /** * 凭证获取参数 */ export interface GetCosCredentialParams { /** 业务场景 */ scene: CosScene; /** 业务类型路径 key(透传到后端 path map 选取;sdk_customize 场景作为受控目录下的子目录) */ pathKey?: string; /** * 业务上下文参数(gameId/env/updType 等,按 scene 不同传递) * @description default/default_download 场景下 gameId 会自动映射到请求头 x-service-type, * 其余字段透传到 query/body;ai_translate 场景整体透传到 body */ context?: Record; /** 文件大小(字节),后端用于校验配额 */ contentLength?: number; /** 已上传文件 URL/Key(下载场景使用) */ fileUrl?: string; /** * 网关 audience * @default '/player-network' * @description 账号管理等子系统需覆盖为对应 audience(如 '/laas-pnt'); * 消费方注入的 http 实例若已统一追加 audience,URL 上存在该参数时拦截器不会重复追加 */ audience?: string; } /** * 自定义原始响应归一化函数 * @description 后端返回字段不符合内置 scene 约定时使用;入参为后端响应的原始 data */ export type NormalizeCredential = (raw: unknown) => NormalizedCosCredential; /** * snake_case 凭证归一化(导出供 getCredential 自定义逃生舱复用) * @description 消费方自行请求凭证(如项目 http 实例为非标准签名)时, * 可在 getCredential 内调用本函数把后端 data 转为组件库统一结构 */ export declare const normalizeSnakeCredential: (raw: SnakeCosCredential) => NormalizedCosCredential; /** * 获取 COS 临时凭证(按 scene 路由到不同后端接口,内部归一化字段命名) * @param http 由 PntProvider 注入的 axios 实例 * @param params 凭证获取参数 * @param customNormalize 可选的原始响应自定义归一化 */ export declare const fetchCosCredential: (http: PntHttpLike, params: GetCosCredentialParams, customNormalize?: NormalizeCredential) => Promise; export {};