@cloudbase/manager-node 5.8.9-beta.1 → 5.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.codebuddy/rules/error-code-contract.mdc +13 -0
  2. package/.coding-ci-publish-beta.yaml +19 -12
  3. package/CHANGELOG.md +8 -0
  4. package/changelog_content_en.md +16 -0
  5. package/changelog_content_zh.md +16 -0
  6. package/lib/agent/index.js +6 -5
  7. package/lib/aiModel/index.js +21 -9
  8. package/lib/cloudApp/index.js +4 -4
  9. package/lib/cloudrun/index.js +16 -15
  10. package/lib/common/index.js +1 -1
  11. package/lib/database/index.js +23 -23
  12. package/lib/deploy/DatabaseDeployer.js +19 -24
  13. package/lib/deploy/DeployOrchestrator.js +2 -2
  14. package/lib/deploy/FunctionDeployer.js +19 -1
  15. package/lib/deploy/GatewayDeployer.js +5 -5
  16. package/lib/deploy/StaticDeployer.js +2 -2
  17. package/lib/deploy/framework.js +2 -1
  18. package/lib/deploy/function/config-guard.js +23 -3
  19. package/lib/deploy/function/enterprise-tcr.js +18 -2
  20. package/lib/docs/index.js +4 -3
  21. package/lib/env/index.js +16 -16
  22. package/lib/environment.js +4 -4
  23. package/lib/environmentManager.js +5 -1
  24. package/lib/error-docs.js +385 -0
  25. package/lib/error-types.js +21 -0
  26. package/lib/error.js +239 -2
  27. package/lib/function/index.js +454 -90
  28. package/lib/function/packer.js +1 -1
  29. package/lib/hosting/index.js +1 -1
  30. package/lib/index.js +2 -1
  31. package/lib/integration/crypto.js +4 -3
  32. package/lib/integration/index.js +1 -1
  33. package/lib/integration/secretKey.js +4 -4
  34. package/lib/monitor/index.js +1 -1
  35. package/lib/mysql/index.js +2 -1
  36. package/lib/permission/index.js +56 -49
  37. package/lib/platform/index.js +2 -2
  38. package/lib/sandbox/index.js +68 -61
  39. package/lib/storage/index.js +164 -162
  40. package/lib/user/index.js +32 -31
  41. package/lib/utils/cloud-api-request.js +13 -5
  42. package/lib/utils/cloudbase-request.js +21 -0
  43. package/lib/utils/fs.js +3 -3
  44. package/lib/utils/http-request.js +2 -2
  45. package/lib/utils/index.js +4 -3
  46. package/lib/utils/storage-config.js +3 -3
  47. package/package.json +2 -2
  48. package/types/error-docs.d.ts +57 -0
  49. package/types/error-types.d.ts +32 -0
  50. package/types/error.d.ts +148 -2
  51. package/types/function/index.d.ts +166 -8
  52. package/types/utils/cloudbase-request.d.ts +22 -0
@@ -1,5 +1,5 @@
1
1
  import { Environment } from '../environment';
2
- import { IResponseInfo, ICloudFunction, ICloudFunctionV2, IFunctionLogOptions, ICloudFunctionTrigger, IFunctionInvokeRes, IFunctionLogRes, IFunctionDownloadUrlRes, IFunctionLogDetailOptions, IFunctionLogDetailRes, IFunctionLogOptionsV2, IFunctionLogResV2 } from '../interfaces';
2
+ import { IResponseInfo, ICloudFunction, ICloudFunctionV2, IFunctionLogOptions, ICloudFunctionTrigger, IFunctionInvokeRes, IFunctionLogRes, IFunctionDownloadUrlRes, IFunctionLogDetailOptions, IFunctionLogDetailRes, IFunctionLogOptionsV2, IFunctionLogResV2, IFunctionImageConfig } from '../interfaces';
3
3
  import { IFunctionInfo, IFunctionCode as IScfFunctionCode } from './types';
4
4
  export interface IFunctionCode {
5
5
  func: ICloudFunction;
@@ -124,14 +124,30 @@ export interface IPublishVersionRes extends IResponseInfo {
124
124
  Handler: string;
125
125
  Timeout: number;
126
126
  Runtime: string;
127
- Namespace: string;
127
+ EnvId: string;
128
+ /** @deprecated 请改用 EnvId */
129
+ Namespace?: string;
128
130
  }
129
131
  export interface IListFunctionVersionParams {
130
132
  functionName: string;
133
+ /**
134
+ * 兼容 SCF 的搜索字段。
135
+ *
136
+ * 实测仅接受数字型取值(传其它值报 InvalidParameterValue),但服务端**未按它过滤**:
137
+ * 传存在的版本号与不存在的数字都返回全量版本列表。
138
+ */
139
+ searchKey?: string;
131
140
  offset?: number;
141
+ /** 返回数量,默认 20,最大 100(超过报 Offset must be nonnegative and Limit must be between 0 and 100) */
132
142
  limit?: number;
133
- order?: string;
134
- orderBy?: string;
143
+ /** 排序方向,仅支持 ASC / DESC(传其它值报 Order must be ASC or DESC) */
144
+ order?: 'ASC' | 'DESC';
145
+ /** 排序字段,仅支持 AddTime / ModTime(传其它值报 OrderBy must be AddTime or ModTime) */
146
+ orderBy?: 'AddTime' | 'ModTime';
147
+ }
148
+ export interface IDeleteFunctionVersionParams {
149
+ functionName: string;
150
+ qualifier: string;
135
151
  }
136
152
  export interface IFunctionVersion {
137
153
  Version: string;
@@ -170,6 +186,51 @@ export interface IGetFunctionAlias {
170
186
  functionName: string;
171
187
  name: string;
172
188
  }
189
+ export type IFunctionTrafficType = 'FLOW' | 'HEADERS' | 'UNSUPPORTED';
190
+ /**
191
+ * 可写的流量策略类型:`UNSUPPORTED` 是查询返回的只读兼容态,不可用于 UpdateAlias
192
+ */
193
+ export type IUpdatableFunctionTrafficType = 'FLOW' | 'HEADERS';
194
+ export interface IFunctionTrafficRule {
195
+ Version: string;
196
+ Weight?: number;
197
+ Key?: string;
198
+ Value?: string;
199
+ }
200
+ export interface IFunctionTraffic {
201
+ Type: IFunctionTrafficType | string;
202
+ DefaultVersion: string;
203
+ Rules: IFunctionTrafficRule[];
204
+ }
205
+ /** 传入 UpdateAlias 的可写流量策略(`Type` 不含只读的 `UNSUPPORTED`) */
206
+ export interface IUpdatableFunctionTraffic extends Omit<IFunctionTraffic, 'Type'> {
207
+ Type: IUpdatableFunctionTrafficType;
208
+ }
209
+ export interface IFunctionBackendVersionWeight {
210
+ Version: string;
211
+ Weight: number;
212
+ }
213
+ export interface IFunctionBackendVersionMatch {
214
+ Version: string;
215
+ Key: string;
216
+ Method: string;
217
+ Expression: string;
218
+ }
219
+ export interface IFunctionBackendRoutingConfig {
220
+ AdditionalVersionWeights: IFunctionBackendVersionWeight[];
221
+ AdditionVersionMatches: IFunctionBackendVersionMatch[];
222
+ }
223
+ export type ITrafficRule = IFunctionTrafficRule;
224
+ export type ITraffic = IFunctionTraffic;
225
+ export interface IUpdateFunctionAliasConfigV2 {
226
+ functionName: string;
227
+ name?: string;
228
+ traffic: IUpdatableFunctionTraffic;
229
+ }
230
+ export interface IGetFunctionAliasV2 {
231
+ functionName: string;
232
+ name?: string;
233
+ }
173
234
  export interface IGetFunctionAliasRes extends IResponseInfo {
174
235
  FunctionVersion: string;
175
236
  Name: string;
@@ -178,6 +239,14 @@ export interface IGetFunctionAliasRes extends IResponseInfo {
178
239
  AddTime: string;
179
240
  ModTime: string;
180
241
  }
242
+ export interface IGetFunctionAliasResV2 extends IResponseInfo {
243
+ Name: string;
244
+ FunctionVersion: string;
245
+ Traffic: IFunctionTraffic;
246
+ TrafficEditable: boolean;
247
+ TrafficCompatibilityReason: string;
248
+ BackendRoutingConfig: IFunctionBackendRoutingConfig;
249
+ }
181
250
  export interface IListFunctionOptions {
182
251
  limit?: number;
183
252
  offset?: number;
@@ -228,6 +297,13 @@ export interface ILayer {
228
297
  }
229
298
  /** 企业版 TCR 镜像对 SCF 不可见时的排查指引 */
230
299
  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";
300
+ /**
301
+ * 为企业版镜像的典型不可见错误补充排查指引,同时保留原始错误和 requestId。
302
+ * 仅匹配 SCF 已进入 enterprise 镜像查询阶段的错误,避免给普通网络或鉴权错误误导提示。
303
+ *
304
+ * 纯函数:只读入参,**不修改**传进来的错误对象;幂等由 WeakMap 缓存保证。
305
+ */
306
+ export declare function formatImageDeploymentErrorMessage(error: unknown, imageConfig?: IFunctionImageConfig): string;
231
307
  export declare class FunctionService {
232
308
  private environment;
233
309
  private vpcService;
@@ -244,6 +320,14 @@ export declare class FunctionService {
244
320
  updateFunctionIncrementalCode(funcParam: IUpdateFunctionIncrementalCodeParam): Promise<IResponseInfo>;
245
321
  /**
246
322
  * 创建云函数
323
+ *
324
+ * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境差异:
325
+ * - 默认 runtime 为 `Nodejs24.11`(见 `CBF_ALLOWED_RUNTIMES`)
326
+ * - 不再注入 `Stamp` / `ClsTopicId` / `ClsLogsetId` 与默认 `Role`
327
+ * - 不支持定时触发器,内部跳过触发器创建
328
+ *
329
+ * 用户显式配置的字段一律原样下发,不支持的字段由服务端报错透传。
330
+ *
247
331
  * @param {ICreateFunctionParam} funcParam
248
332
  * @returns {(Promise<IResponseInfo | ICreateFunctionRes>)}
249
333
  */
@@ -296,6 +380,13 @@ export declare class FunctionService {
296
380
  }): Promise<void>;
297
381
  /**
298
382
  * 获取云函数详细信息
383
+ *
384
+ * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境差异:
385
+ * - 不再注入 `ShowCode`(CBF 不接受该参数),因此也拿不到函数代码内容,
386
+ * 需要代码请使用 `downloadFunction`
387
+ * - 不转发 `codeSecret`:CBF 不支持代码保护,若在此下发会掩盖
388
+ * `CreateFunction` / `UpdateFunctionCode` 的真实报错
389
+ *
299
390
  * @param {string} name 云函数名称
300
391
  * @returns {Promise<Record<string, string>>}
301
392
  */
@@ -365,11 +456,24 @@ export declare class FunctionService {
365
456
  getCompleteFunctionLogs(_options: IFunctionLogOptionsV2): Promise<IFunctionLogDetailRes[]>;
366
457
  /**
367
458
  * 更新云函数配置
459
+ *
460
+ * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境差异:
461
+ * - 不再注入 `ClsTopicId` / `ClsLogsetId`,也不转发 `InstallDependency`
462
+ * - 环境变量:不传不接受 Key 为空的占位项,清空需提交空数组(传 `envVariables: {}` 即清空)
463
+ * - 不支持定时触发器:配置里的 `triggers` 会被跳过
464
+ *
465
+ * 用户显式配置的字段一律原样下发,不支持的字段由服务端报错透传。
466
+ *
368
467
  * @param {ICloudFunction} func 云函数配置
369
468
  * @returns {Promise<IResponseInfo>}
370
469
  */
371
470
  updateFunctionConfig(func: ICloudFunction): Promise<IResponseInfo>;
372
471
  /**
472
+ * 更新云函数代码
473
+ *
474
+ * `UpdateFunctionCode` 只传 `EnvId` 即可(SCF 与 CBF 均实测支持),不再下发冗余的 `Namespace`。
475
+ *
476
+ * 注意:CBF(云开发云函数)不支持 `codeSecret`(代码保护),传入后会由服务端报错。
373
477
  *
374
478
  * @param {IUpdateFunctionCodeParam} funcParam
375
479
  * @returns {Promise<IResponseInfo>}
@@ -421,6 +525,11 @@ export declare class FunctionService {
421
525
  copyFunction(name: string, newFunctionName: string, targetEnvId?: string, force?: boolean): Promise<IResponseInfo>;
422
526
  /**
423
527
  * 创建云函数触发器
528
+ *
529
+ * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境不支持定时触发器,
530
+ * 且该接口走 SCF 后端,对 CBF 的函数会返回「未找到指定的函数」这类误导性报错,
531
+ * 故 CBF 下直接抛错。内部调用点(`createFunction` / `updateFunctionConfig`)会跳过本方法。
532
+ *
424
533
  * @param {string} name 云函数名称
425
534
  * @param {ICloudFunctionTrigger[]} triggers 云函数触发器配置
426
535
  * @returns {Promise<IResponseInfo>}
@@ -429,6 +538,11 @@ export declare class FunctionService {
429
538
  batchCreateTriggers(options: IFunctionBatchOptions): Promise<void>;
430
539
  /**
431
540
  * 删除云函数触发器
541
+ *
542
+ * CBF(云开发云函数,`Functions[0].Backend === 'cbf'`)环境不支持定时触发器,
543
+ * 且该接口走 SCF 后端,对 CBF 的函数会返回「未找到指定的函数」这类误导性报错,
544
+ * 故 CBF 下直接抛错。
545
+ *
432
546
  * @param {string} name 云函数名称
433
547
  * @param {string} triggerName 云函数触发器名称
434
548
  * @returns {Promise<IResponseInfo>}
@@ -498,22 +612,47 @@ export declare class FunctionService {
498
612
  */
499
613
  listVersionByFunction(listVersionParams: IListFunctionVersionParams): Promise<IFunctionVersionsRes>;
500
614
  /**
501
- *
615
+ * 删除函数指定版本
616
+ * @param {IDeleteFunctionVersionParams} params
617
+ * @returns {Promise<IResponseInfo>}
618
+ * @memberof FunctionService
619
+ */
620
+ deleteFunctionVersion(params: IDeleteFunctionVersionParams): Promise<IResponseInfo>;
621
+ /**
622
+ * 更新函数流量配置(旧版 SCF 协议)
623
+ * @deprecated 请使用 updateFunctionAliasConfigV2
502
624
  * @param {IUpdateFunctionAliasConfig} updateVersionConfigParams
503
625
  * @returns {Promise<IResponseInfo>}
504
626
  * @memberof FunctionService
505
627
  */
506
628
  updateFunctionAliasConfig(updateVersionConfigParams: IUpdateFunctionAliasConfig): Promise<IResponseInfo>;
507
629
  /**
508
- * 查询函数别名详情
630
+ * 更新函数流量策略(V2,TCB Traffic 协议)
631
+ * @param {IUpdateFunctionAliasConfigV2} updateVersionConfigParams
632
+ * @returns {Promise<IResponseInfo>}
633
+ * @memberof FunctionService
634
+ */
635
+ updateFunctionAliasConfigV2(updateVersionConfigParams: IUpdateFunctionAliasConfigV2): Promise<IResponseInfo>;
636
+ /**
637
+ * 查询函数别名详情(旧版 SCF 协议)
638
+ * @deprecated 请使用 getFunctionAliasV2
509
639
  * @param {IGetFunctionAlias} params
510
640
  * @returns {Promise<IGetFunctionAliasRes>}
511
641
  * @memberof FunctionService
512
642
  */
513
643
  getFunctionAlias(params: IGetFunctionAlias): Promise<IGetFunctionAliasRes>;
514
644
  /**
515
- * 通过 SCF COS 上传方式(通过 GetTempCosInfo + COS SDK 上传)
516
- * 返回 TempCosObjectName 用于创建/更新函数
645
+ * 查询函数别名详情(V2,TCB Traffic 协议)
646
+ * @param {IGetFunctionAliasV2} params
647
+ * @returns {Promise<IGetFunctionAliasResV2>}
648
+ * @memberof FunctionService
649
+ */
650
+ getFunctionAliasV2(params: IGetFunctionAliasV2): Promise<IGetFunctionAliasResV2>;
651
+ /**
652
+ * COS 上传方式上传函数代码包,返回 { Key }
653
+ * - CBF(backend=cbf):tcb.GetTempCosInfo 获取 PutUrl 直传,Key = 服务端生成的 ObjectKey
654
+ * - SCF(backend=scf,默认):scf.GetTempCosInfo + Sign + COS SDK 上传
655
+ * Key 由 getCodeParams 格式化为 TempCosObjectName 用于创建/更新函数
517
656
  */
518
657
  uploadFunctionZipToCos(options: IFunctionCode, installDependency: 'TRUE' | 'FALSE'): Promise<{
519
658
  Key: string;
@@ -535,8 +674,27 @@ export declare class FunctionService {
535
674
  TempCosObjectName: string;
536
675
  ZipFile?: undefined;
537
676
  }>;
677
+ /**
678
+ * CBF 环境的临时代码包上传(tcb.GetTempCosInfo + PutUrl 直传)
679
+ * - 先压缩再取 PutUrl,避免压缩耗时消耗 PutUrl 约 300 秒的有效期
680
+ * - PutUrl 过期(403)/ 5xx / 网络错误时重新调用 GetTempCosInfo 刷新地址,不复用旧地址(初始 + 重试共 3 次)
681
+ * - ObjectKey 由服务端生成,多次调用得到不同上传路径,上传成功后原样返回
682
+ * @private
683
+ */
684
+ private uploadFunctionZipViaPutUrl;
685
+ /**
686
+ * 对 PutUrl 发起 HTTP PUT 上传 zip 文件(超时 120 秒,支持 http_proxy 代理)
687
+ * @private
688
+ */
689
+ private putZipFileToUrl;
538
690
  private createAccessPath;
539
691
  private getTempCosInfo;
692
+ /**
693
+ * 创建触发器(带重试)。
694
+ *
695
+ * ⚠️ AIP-194:**只重试可重试错误**。旧实现是 catch-all 盲重试 —— 权限不足 / 参数非法这类
696
+ * **必然失败**的错误也会被重试 3 次,既浪费时间,又把确定性失败伪装成偶发失败、掩盖真实原因。
697
+ */
540
698
  private retryCreateTrigger;
541
699
  /**
542
700
  * 获取函数配置信息
@@ -12,3 +12,25 @@ export declare function cloudBaseRequest(options: {
12
12
  method?: string;
13
13
  headers?: Record<string, any>;
14
14
  }): Promise<any>;
15
+ /**
16
+ * 数据面(/admin)错误响应结构。
17
+ *
18
+ * 来源:`tcblinker/internal/tcberror` 的 `TcbError.ToJSON()`,形如
19
+ * `{ code, message, requestId }`。无 docs 字段——文档链接由 CLI 侧
20
+ * `resolveErrorDoc` 按 code + source 生成(见错误码治理方案 §4.6)。
21
+ */
22
+ export interface IDataPlaneErrorResponse {
23
+ /** 数据面稳定错误码,见 tcblinker/internal/tcberror(如 INVALID_PARAM / STORAGE_FILE_NONEXIST) */
24
+ code?: string;
25
+ message?: string;
26
+ requestId?: string;
27
+ }
28
+ /**
29
+ * 校验数据面(/admin)响应,命中错误时抛出带 code 的 CloudBaseError。
30
+ *
31
+ * 必须把 `res.code` 落到 `CloudBaseError.code` 并标记 `source: 'runtime'`:
32
+ * 否则 CLI 侧 `resolveErrorDoc` 拿不到 code → 文档链接哑火,
33
+ * `resolveExitCode` 也会兜底成 1,灯塔上报退化为 `ERROR`。
34
+ * 这是「错误码治理方案」D11 的修复点。
35
+ */
36
+ export declare function assertDataPlaneOk(res: IDataPlaneErrorResponse | null | undefined, action: string): void;