import { Environment } from '../environment'; import { IResponseInfo, ICloudFunction, ICloudFunctionV2, IFunctionLogOptions, ICloudFunctionTrigger, IFunctionInvokeRes, IFunctionLogRes, IFunctionDownloadUrlRes, IFunctionLogDetailOptions, IFunctionLogDetailRes, IFunctionLogOptionsV2, IFunctionLogResV2, IFunctionImageConfig } from '../interfaces'; import { IFunctionInfo, IFunctionCode as IScfFunctionCode } from './types'; export interface IFunctionCode { func: ICloudFunction; functionRootPath?: string; base64Code?: string; functionPath?: string; deployMode?: 'cos' | 'zip' | 'image'; } export interface ICreateFunctionParam { func: ICloudFunction & { path?: string; }; functionRootPath?: string; force?: boolean; base64Code?: string; functionPath?: string; codeSecret?: string; deployMode?: 'cos' | 'zip' | 'image'; code?: IScfFunctionCode; } export interface IUpdateFunctionCodeParam { func: ICloudFunction; functionPath?: string; functionRootPath?: string; base64Code?: string; codeSecret?: string; deployMode?: 'cos' | 'zip' | 'image'; code?: IScfFunctionCode; } export interface IUpdateFunctionIncrementalCodeParam { func: ICloudFunction; functionRootPath: string; deleteFiles?: Array; addFiles?: string; } export interface ICreateFunctionRes { triggerRes: IResponseInfo; configRes: IResponseInfo; codeRes?: IResponseInfo; } export interface IFunctionLayerOptions { contentPath?: string; base64Content?: string; name: string; runtimes: string[]; description?: string; licenseInfo?: string; } export interface ICreateLayerResponse extends IResponseInfo { LayerVersion: number; } export interface ILayerOptions { name: string; version: number; } export interface IVersionListOptions { name: string; runtimes?: string[]; } export interface ILayerListOptions { offset?: number; limit?: number; runtime?: string; searchKey?: string; } export interface ILayerVersionInfo { CompatibleRuntimes: string[]; AddTime: string; Description: string; LicenseInfo: string; LayerVersion: number; LayerName: string; Status: string; } export interface IListLayerVersionsRes extends IResponseInfo { LayerVersions: Array; } export interface IListLayerRes extends IResponseInfo { Layers: Array; TotalCount: number; } export interface IGetLayerVersionRes extends IResponseInfo { CompatibleRuntimes: string[]; CodeSha256: string; Location: string; AddTime: string; Description: string; LicenseInfo: string; LayerVersion: number; LayerName: string; Status: string; } export interface ISetProvisionedConcurrencyConfig { functionName: string; qualifier: string; versionProvisionedConcurrencyNum: number; } export interface IGetProvisionedConcurrencyConfig { functionName: string; qualifier?: string; } export interface IVersionProvisionedConcurrencyInfo { AllocatedProvisionedConcurrencyNum: number; AvailableProvisionedConcurrencyNum: number; Status: string; StatusReason: string; Qualifier: string; } export interface IGetProvisionedConcurrencyRes extends IResponseInfo { UnallocatedConcurrencyNum: number; Allocated: IVersionProvisionedConcurrencyInfo[]; } export interface IPublishVersionParams { functionName: string; description?: string; } export interface IPublishVersionRes extends IResponseInfo { FunctionVersion: string; CodeSize: number; MemorySize: number; Description: string; Handler: string; Timeout: number; Runtime: string; EnvId: string; /** @deprecated 请改用 EnvId */ Namespace?: string; } export interface IListFunctionVersionParams { functionName: string; /** * 兼容 SCF 的搜索字段。 * * 实测仅接受数字型取值(传其它值报 InvalidParameterValue),但服务端**未按它过滤**: * 传存在的版本号与不存在的数字都返回全量版本列表。 */ searchKey?: string; offset?: number; /** 返回数量,默认 20,最大 100(超过报 Offset must be nonnegative and Limit must be between 0 and 100) */ limit?: number; /** 排序方向,仅支持 ASC / DESC(传其它值报 Order must be ASC or DESC) */ order?: 'ASC' | 'DESC'; /** 排序字段,仅支持 AddTime / ModTime(传其它值报 OrderBy must be AddTime or ModTime) */ orderBy?: 'AddTime' | 'ModTime'; } export interface IDeleteFunctionVersionParams { functionName: string; qualifier: string; } export interface IFunctionVersion { Version: string; Description: string; AddTime: string; ModTime: string; Status: string; } export interface IFunctionVersionsRes extends IResponseInfo { FunctionVersion: string[]; Versions: IFunctionVersion[]; TotalCount: number; } export interface IVersionMatch { Version: string; Key: string; Method: string; Expression: string; } export interface IVersionWeight { Version: string; Weight: number; } export interface IRoutingConfig { AdditionalVersionWeights?: IVersionWeight[]; AddtionVersionMatchs?: IVersionMatch[]; } export interface IUpdateFunctionAliasConfig { functionName: string; name: string; functionVersion: string; description?: string; routingConfig?: IRoutingConfig; } export interface IGetFunctionAlias { functionName: string; name: string; } export type IFunctionTrafficType = 'FLOW' | 'HEADERS' | 'UNSUPPORTED'; /** * 可写的流量策略类型:`UNSUPPORTED` 是查询返回的只读兼容态,不可用于 UpdateAlias */ export type IUpdatableFunctionTrafficType = 'FLOW' | 'HEADERS'; export interface IFunctionTrafficRule { Version: string; Weight?: number; Key?: string; Value?: string; } export interface IFunctionTraffic { Type: IFunctionTrafficType | string; DefaultVersion: string; Rules: IFunctionTrafficRule[]; } /** 传入 UpdateAlias 的可写流量策略(`Type` 不含只读的 `UNSUPPORTED`) */ export interface IUpdatableFunctionTraffic extends Omit { Type: IUpdatableFunctionTrafficType; } export interface IFunctionBackendVersionWeight { Version: string; Weight: number; } export interface IFunctionBackendVersionMatch { Version: string; Key: string; Method: string; Expression: string; } export interface IFunctionBackendRoutingConfig { AdditionalVersionWeights: IFunctionBackendVersionWeight[]; AdditionVersionMatches: IFunctionBackendVersionMatch[]; } export type ITrafficRule = IFunctionTrafficRule; export type ITraffic = IFunctionTraffic; export interface IUpdateFunctionAliasConfigV2 { functionName: string; name?: string; traffic: IUpdatableFunctionTraffic; } export interface IGetFunctionAliasV2 { functionName: string; name?: string; } export interface IGetFunctionAliasRes extends IResponseInfo { FunctionVersion: string; Name: string; RoutingConfig: IRoutingConfig; Description: string; AddTime: string; ModTime: string; } export interface IGetFunctionAliasResV2 extends IResponseInfo { Name: string; FunctionVersion: string; Traffic: IFunctionTraffic; TrafficEditable: boolean; TrafficCompatibilityReason: string; BackendRoutingConfig: IFunctionBackendRoutingConfig; } export interface IListFunctionOptions { limit?: number; offset?: number; envId: string; } export interface IFunctionBatchOptions { functions: ICloudFunctionV2[]; envId: string; log?: boolean; } export interface IGetAsyncEventStatusRes extends IResponseInfo { Result: IAsyncEventStatus; RequestId: string; } export interface IAsyncEventStatus { InvokeRequestId: string; Status: string; StatusCode: number; } export interface IFunctionCodeOptions { envId: string; destPath: string; functionName: string; codeSecret?: string; qualifier?: string; } export interface ILayerDownloadOptions { name: string; version: number; destPath: string; force?: boolean; } export interface IAttachOptions { envId: string; layerName: string; layerVersion: number; functionName: string; codeSecret?: string; } export interface ISortOptions { envId: string; functionName: string; layers: ILayer[]; } export interface ILayer { LayerName: string; LayerVersion: number; } /** 企业版 TCR 镜像对 SCF 不可见时的排查指引 */ export declare const ENTERPRISE_IMAGE_REGION_GUIDANCE = "\u8BF7\u786E\u8BA4 TCR \u4F01\u4E1A\u7248\u5B9E\u4F8B\u5DF2\u5728\u5F53\u524D\u51FD\u6570\u5730\u57DF\u63D0\u4F9B\u53EF\u8BBF\u95EE\u7684\u5B9E\u4F8B\u6216\u590D\u5236\u5B9E\u4F8B\uFF0C\u5E76\u68C0\u67E5 RegistryId\u3001\u955C\u50CF\u5730\u5740\u53CA\u62C9\u53D6\u6743\u9650\u3002"; /** * 为企业版镜像的典型不可见错误补充排查指引,同时保留原始错误和 requestId。 * 仅匹配 SCF 已进入 enterprise 镜像查询阶段的错误,避免给普通网络或鉴权错误误导提示。 * * 纯函数:只读入参,**不修改**传进来的错误对象;幂等由 WeakMap 缓存保证。 */ export declare function formatImageDeploymentErrorMessage(error: unknown, imageConfig?: IFunctionImageConfig): string; export declare class FunctionService { private environment; private vpcService; private scfService; private tcbService; private userService; constructor(environment: Environment); /** * 增量更新函数代码 * @param {IUpdateFunctionIncrementalCodeParam} funcParam * @returns {Promise} * @memberof FunctionService */ updateFunctionIncrementalCode(funcParam: IUpdateFunctionIncrementalCodeParam): Promise; /** * 创建云函数 * * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境差异: * - 默认 runtime 为 `Nodejs24.11`(见 `CBF_ALLOWED_RUNTIMES`) * - 不再注入 `Stamp` / `ClsTopicId` / `ClsLogsetId` 与默认 `Role` * - 不支持定时触发器,内部跳过触发器创建 * * 用户显式配置的字段一律原样下发,不支持的字段由服务端报错透传。 * * @param {ICreateFunctionParam} funcParam * @returns {(Promise)} */ createFunction(funcParam: ICreateFunctionParam): Promise; /** * @param {number} [limit=20] * @param {number} [offset=0] * @returns {Promise<{ * Functions: Record[] * RequestId: string * TotalCount: number * }>} * @memberof FunctionService */ getFunctionList(limit?: number, offset?: number): Promise<{ Functions: Record[]; RequestId: string; TotalCount: number; }>; /** * 列出函数 * @param {number} [limit=20] * @param {number} [offset=0] * @returns {Promise[]>} */ listFunctions(limit?: number, offset?: number): Promise[]>; /** * 列出所有函数 * @param {IListFunctionOptions} options * @returns {Promise[]>} */ listAllFunctions(options: IListFunctionOptions): Promise[]>; /** * 删除云函数 * @param {string} name 云函数名称 * @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。 * @returns {Promise} */ deleteFunction(name: string | { name: string; }): Promise; /** * 批量删除云函数 * @param {Object} options * @param {string[]} options.names 云函数名称列表 * @returns {Promise} */ batchDeleteFunctions({ names }: { names: any; }): Promise; /** * 获取云函数详细信息 * * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境差异: * - 不再注入 `ShowCode`(CBF 不接受该参数),因此也拿不到函数代码内容, * 需要代码请使用 `downloadFunction` * - 不转发 `codeSecret`:CBF 不支持代码保护,若在此下发会掩盖 * `CreateFunction` / `UpdateFunctionCode` 的真实报错 * * @param {string} name 云函数名称 * @returns {Promise>} */ getFunctionDetail(name: string, codeSecret?: string): Promise; /** * 批量获取云函数详细信息 * @param {Object} options * @param {string[]} options.names 云函数名称列表 * @param {string} options.envId 环境 ID * @param {string} options.codeSecret * @returns {Promise} */ batchGetFunctionsDetail({ names, envId, codeSecret }: { names: any; envId: any; codeSecret: any; }): Promise; /** * 获取函数日志 * @deprecated 底层 GetFunctionLogs 接口已下线,请使用 env.getLogService().searchClsLog() 查询云函数日志 * @param {{ * name: string * offset: number * limit: number * order: string * orderBy: string * startTime: string * endTime: string * requestId: string * }} options * @returns {Promise} */ getFunctionLogs(_options: IFunctionLogOptions): Promise; /** * 获取函数日志 ID 列表 * @deprecated 底层 GetFunctionLogs 接口已下线,请使用 env.getLogService().searchClsLog() 查询云函数日志 * @param {{ * name: string * offset: number * limit: number * startTime: string * endTime: string * requestId: string * qualifier: string * }} options * @returns {Promise} */ getFunctionLogsV2(_options: IFunctionLogOptionsV2): Promise; /** * 根据函数日志 ID 查询日志详情 * @deprecated 底层 GetFunctionLogDetail 接口已下线,请使用 env.getLogService().searchClsLog() 查询云函数日志 * @param {{ * startTime: string * endTime: string * logRequestId: string * }} options * @returns {Promise} */ getFunctionLogDetail(_options: IFunctionLogDetailOptions): Promise; /** * 获取函数的完整调用日志 * 该方法会自动完成两步操作:1. 获取日志请求ID列表。 2. 根据ID列表获取每条日志的详细内容。 * @deprecated 底层 GetFunctionLogs/GetFunctionLogDetail 接口已下线,请使用 env.getLogService().searchClsLog() 查询云函数日志 * @param {IFunctionLogOptionsV2} options - 查询选项 * @returns {Promise} 返回包含完整日志详情的数组 */ getCompleteFunctionLogs(_options: IFunctionLogOptionsV2): Promise; /** * 更新云函数配置 * * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境差异: * - 不再注入 `ClsTopicId` / `ClsLogsetId`,也不转发 `InstallDependency` * - 环境变量:不传不接受 Key 为空的占位项,清空需提交空数组(传 `envVariables: {}` 即清空) * - 不支持定时触发器:配置里的 `triggers` 会被跳过 * * 用户显式配置的字段一律原样下发,不支持的字段由服务端报错透传。 * * @param {ICloudFunction} func 云函数配置 * @returns {Promise} */ updateFunctionConfig(func: ICloudFunction): Promise; /** * 更新云函数代码 * * `UpdateFunctionCode` 只传 `EnvId` 即可(SCF 与 CBF 均实测支持),不再下发冗余的 `Namespace`。 * * 注意:CBF(云开发云函数)不支持 `codeSecret`(代码保护),传入后会由服务端报错。 * * @param {IUpdateFunctionCodeParam} funcParam * @returns {Promise} * @memberof FunctionService */ updateFunctionCode(funcParam: IUpdateFunctionCodeParam): Promise; /** * 更新函数代码和配置(带进度信息) * 支持同时更新代码和配置,按顺序执行:等待就绪 → 更新代码 → 等待就绪 → 更新配置 → 等待就绪 * @param options 更新选项 * @returns 更新结果,包含耗时信息 */ updateFunctionWithProgress(options: { /** 函数名称 */ name: string; /** 代码相关参数(可选),复用 IUpdateFunctionCodeParam(排除 func,由 name 替代) */ code?: Omit; /** 配置相关参数(可选),复用 ICloudFunction(排除 name,由外层 name 替代) */ config?: Omit; }): Promise<{ /** 总耗时(毫秒) */ elapsedTime: number; /** 结果消息 */ message: string; /** 详细步骤信息 */ details: string[]; }>; /** * 调用云函数 * @param {string} name 云函数名称 * @param {Record} params 调用函数传入参数 * @returns {Promise} */ invokeFunction(name: string, params?: Record): Promise; /** * 批量调用云函数 * @param {IFunctionBatchOptions} options * @returns {Promise} */ batchInvokeFunctions(options: IFunctionBatchOptions): Promise; /** * 复制云函数 * @param {string} name 云函数名称 * @param {string} newFunctionName 新的云函数名称 * @param {string} targetEnvId 目标环境 Id * @param {boolean} [force=false] 是否覆盖同名云函数 * @returns {Promise} */ copyFunction(name: string, newFunctionName: string, targetEnvId?: string, force?: boolean): Promise; /** * 创建云函数触发器 * * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境不支持定时触发器, * 且该接口走 SCF 后端,对 CBF 的函数会返回「未找到指定的函数」这类误导性报错, * 故 CBF 下直接抛错。内部调用点(`createFunction` / `updateFunctionConfig`)会跳过本方法。 * * @param {string} name 云函数名称 * @param {ICloudFunctionTrigger[]} triggers 云函数触发器配置 * @returns {Promise} */ createFunctionTriggers(name: string, triggers?: ICloudFunctionTrigger[]): Promise; batchCreateTriggers(options: IFunctionBatchOptions): Promise; /** * 删除云函数触发器 * * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境不支持定时触发器, * 且该接口走 SCF 后端,对 CBF 的函数会返回「未找到指定的函数」这类误导性报错, * 故 CBF 下直接抛错。 * * @param {string} name 云函数名称 * @param {string} triggerName 云函数触发器名称 * @returns {Promise} */ deleteFunctionTrigger(name: string, triggerName: string): Promise; batchDeleteTriggers(options: IFunctionBatchOptions): Promise; /** * 下载云函数代码 * @param {IFunctionCodeOptions} options * @returns {Promise} */ downloadFunctionCode(options: IFunctionCodeOptions): Promise; /** * 获取云函数代码下载 链接 * @param {string} functionName * @param {string} [codeSecret] * @returns {Promise} * @memberof FunctionService */ getFunctionDownloadUrl(functionName: string, codeSecret?: string): Promise; attachLayer(options: IAttachOptions): Promise; unAttachLayer(options: IAttachOptions): Promise; updateFunctionLayer(options: ISortOptions): Promise; downloadLayer(options: ILayerDownloadOptions): Promise; createLayer(options: IFunctionLayerOptions): Promise; deleteLayerVersion(options: ILayerOptions): Promise; listLayerVersions(options: IVersionListOptions): Promise; listLayers(options: ILayerListOptions): Promise; getLayerVersion(options: ILayerOptions): Promise; waitFunctionActive(funcName: string, codeSecret?: string): Promise; /** * 设置预置并发 * @private * @param {IProvisionedConcurrencyConfig} concurrencyConfig * @returns * @memberof FunctionService */ setProvisionedConcurrencyConfig(concurrencyConfig: ISetProvisionedConcurrencyConfig): Promise; /** * 获取函数预置并发详情 * @private * @param {IGetProvisionedConcurrencyConfig} concurrencyConfig * @returns {Promise} * @memberof FunctionService */ getProvisionedConcurrencyConfig(concurrencyConfig: IGetProvisionedConcurrencyConfig): Promise; /** * 删除预置并发 * @private * @param {IGetProvisionedConcurrencyConfig} concurrencyConfig * @returns {Promise} * @memberof FunctionService */ deleteProvisionedConcurrencyConfig(concurrencyConfig: IGetProvisionedConcurrencyConfig): Promise; /** * 发布新版本 * @param {IPublishVersionParams} publishParams * @returns {Promise} * @memberof FunctionService */ publishVersion(publishParams: IPublishVersionParams): Promise; /** * 查询函数版本详情 * @param {IListFunctionVersionParams} listVersionParams * @returns {Promise} * @memberof FunctionService */ listVersionByFunction(listVersionParams: IListFunctionVersionParams): Promise; /** * 删除函数指定版本 * @param {IDeleteFunctionVersionParams} params * @returns {Promise} * @memberof FunctionService */ deleteFunctionVersion(params: IDeleteFunctionVersionParams): Promise; /** * 更新函数流量配置(旧版 SCF 协议) * @deprecated 请使用 updateFunctionAliasConfigV2 * @param {IUpdateFunctionAliasConfig} updateVersionConfigParams * @returns {Promise} * @memberof FunctionService */ updateFunctionAliasConfig(updateVersionConfigParams: IUpdateFunctionAliasConfig): Promise; /** * 更新函数流量策略(V2,TCB Traffic 协议) * @param {IUpdateFunctionAliasConfigV2} updateVersionConfigParams * @returns {Promise} * @memberof FunctionService */ updateFunctionAliasConfigV2(updateVersionConfigParams: IUpdateFunctionAliasConfigV2): Promise; /** * 查询函数别名详情(旧版 SCF 协议) * @deprecated 请使用 getFunctionAliasV2 * @param {IGetFunctionAlias} params * @returns {Promise} * @memberof FunctionService */ getFunctionAlias(params: IGetFunctionAlias): Promise; /** * 查询函数别名详情(V2,TCB Traffic 协议) * @param {IGetFunctionAliasV2} params * @returns {Promise} * @memberof FunctionService */ getFunctionAliasV2(params: IGetFunctionAliasV2): Promise; /** * COS 上传方式上传函数代码包,返回 { Key } * - CBF(backend=cbf):tcb.GetTempCosInfo 获取 PutUrl 直传,Key = 服务端生成的 ObjectKey * - SCF(backend=scf,默认):scf.GetTempCosInfo + Sign + COS SDK 上传 * Key 由 getCodeParams 格式化为 TempCosObjectName 用于创建/更新函数 */ uploadFunctionZipToCos(options: IFunctionCode, installDependency: 'TRUE' | 'FALSE'): Promise<{ Key: string; }>; /** * 旧的 COS 上传方式(通过 DescribeBuildServiceCosInfo + PUT 上传) * 返回 CosTimestamp 用于创建/更新函数 * @deprecated 请使用 uploadFunctionZipToCos 代替 */ uploadFunctionZipToCosLegacy(options: IFunctionCode, installDependency: 'TRUE' | 'FALSE'): Promise<{ UnixTimestamp: string; }>; getCodeParams(options: IFunctionCode, installDependency: 'TRUE' | 'FALSE'): Promise<{ ZipFile: string; CosBucketRegion?: undefined; TempCosObjectName?: undefined; } | { CosBucketRegion: string; TempCosObjectName: string; ZipFile?: undefined; }>; /** * CBF 环境的临时代码包上传(tcb.GetTempCosInfo + PutUrl 直传) * - 先压缩再取 PutUrl,避免压缩耗时消耗 PutUrl 约 300 秒的有效期 * - PutUrl 过期(403)/ 5xx / 网络错误时重新调用 GetTempCosInfo 刷新地址,不复用旧地址(初始 + 重试共 3 次) * - ObjectKey 由服务端生成,多次调用得到不同上传路径,上传成功后原样返回 * @private */ private uploadFunctionZipViaPutUrl; /** * 对 PutUrl 发起 HTTP PUT 上传 zip 文件(超时 120 秒,支持 http_proxy 代理) * @private */ private putZipFileToUrl; private createAccessPath; private getTempCosInfo; /** * 创建触发器(带重试)。 * * ⚠️ AIP-194:**只重试可重试错误**。旧实现是 catch-all 盲重试 —— 权限不足 / 参数非法这类 * **必然失败**的错误也会被重试 3 次,既浪费时间,又把确定性失败伪装成偶发失败、掩盖真实原因。 */ private retryCreateTrigger; /** * 获取函数配置信息 * @private * @returns * @memberof FunctionService */ private getFunctionConfig; /** * 获取日志cls配置信息 */ private getClsServiceConfig; /** * 获取 vpc 信息 * @returns */ private getVpcs; /** * 获取子网 * @param {string} vpcId * @returns */ private getSubnets; }