@cloudbase/manager-node 4.7.0 → 4.7.2

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.
package/lib/constant.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // static credentail = 'credential'
5
5
  // }
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.COS_SDK_KEEPALIVE = exports.COS_SDK_PROTOCOL = exports.USE_INTERNAL_ENDPOINT = exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
7
+ exports.COS_SDK_KEEPALIVE = exports.COS_SDK_PROTOCOL = exports.INTERNAL_ENDPOINT_REGION = exports.USE_INTERNAL_ENDPOINT = exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
8
8
  exports.ENV_NAME = {
9
9
  ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
10
10
  ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
@@ -56,5 +56,6 @@ exports.SCF_STATUS = {
56
56
  };
57
57
  // 是否使用内网域名
58
58
  exports.USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT" in process.env;
59
+ exports.INTERNAL_ENDPOINT_REGION = process.env.INTERNAL_ENDPOINT_REGION;
59
60
  exports.COS_SDK_PROTOCOL = process.env.COS_SDK_PROTOCOL;
60
61
  exports.COS_SDK_KEEPALIVE = process.env.COS_SDK_KEEPALIVE;
package/lib/context.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CloudBaseContext = void 0;
4
4
  const constant_1 = require("./constant");
5
5
  class CloudBaseContext {
6
- constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined }) {
6
+ constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined, internalEndpointRegion = undefined }) {
7
7
  this.secretId = secretId;
8
8
  this.secretKey = secretKey;
9
9
  this.token = token;
@@ -11,9 +11,13 @@ class CloudBaseContext {
11
11
  this.region = region;
12
12
  this.envType = envType;
13
13
  this.useInternalEndpoint = useInternalEndpoint;
14
+ this.internalEndpointRegion = internalEndpointRegion;
14
15
  }
15
16
  isInternalEndpoint() {
16
17
  return this.useInternalEndpoint !== undefined ? this.useInternalEndpoint : constant_1.USE_INTERNAL_ENDPOINT;
17
18
  }
19
+ getInternalEndpointRegion() {
20
+ return this.internalEndpointRegion || constant_1.INTERNAL_ENDPOINT_REGION;
21
+ }
18
22
  }
19
23
  exports.CloudBaseContext = CloudBaseContext;
@@ -1298,12 +1298,12 @@ class FunctionService {
1298
1298
  }
1299
1299
  async getCodeParams(options, installDependency) {
1300
1300
  const { func, functionPath, functionRootPath, base64Code, deployMode } = options;
1301
- // 更新的时候直接上传的zip包的情况
1302
- // ZIP 包大小上限 20MB,base64 编码后长度约为原始大小的 4/3
1303
- const MAX_ZIP_SIZE = 20 * 1024 * 1024; // 20MB
1304
- const MAX_BASE64_LENGTH = Math.floor(MAX_ZIP_SIZE * 4 / 3); // ≈ 27962026
1301
+ // 直接传入 base64Code 的情况,校验大小
1302
+ // ZipFile 上传大小上限 1.5MB,base64 编码后长度约为原始大小的 4/3
1303
+ const MAX_ZIP_SIZE = 1.5 * 1024 * 1024; // 1.5MB
1304
+ const MAX_BASE64_LENGTH = Math.floor(MAX_ZIP_SIZE * 4 / 3); // ≈ 2097152
1305
1305
  if ((base64Code === null || base64Code === void 0 ? void 0 : base64Code.length) > MAX_BASE64_LENGTH) {
1306
- throw new error_1.CloudBaseError('ZIP 包不能大于 20MB');
1306
+ throw new error_1.CloudBaseError('ZipFile 上传不能大于 1.5MB,请使用 COS 上传方式');
1307
1307
  }
1308
1308
  if (base64Code === null || base64Code === void 0 ? void 0 : base64Code.length) {
1309
1309
  return {
@@ -1323,10 +1323,14 @@ class FunctionService {
1323
1323
  root: functionRootPath
1324
1324
  });
1325
1325
  await packer.build();
1326
- // 如果指定了上传方式,按指定方式上传
1327
- // 判断是否需要走 COS 上传
1326
+ // 判断是否超过 ZipFile 上传大小限制(1.5MB)
1328
1327
  const reachMax = await packer.isReachMaxSize();
1329
- const useCos = deployMode === 'cos' || (deployMode !== 'zip' && reachMax);
1328
+ // 如果指定了 zip 上传方式但超过大小限制,直接报错
1329
+ if (deployMode === 'zip' && reachMax) {
1330
+ throw new error_1.CloudBaseError('ZipFile 上传不能大于 1.5MB,请使用 COS 上传方式(deployMode: "cos")');
1331
+ }
1332
+ // 走 COS 上传:指定 cos 模式,或未指定模式但超过大小限制
1333
+ const useCos = deployMode === 'cos' || reachMax;
1330
1334
  if (useCos) {
1331
1335
  // 先调用scf的 COS 上传方式
1332
1336
  const legacyResult = await this.uploadFunctionZipToCosLegacy(options, installDependency);
@@ -47,7 +47,8 @@ const error_1 = require("../error");
47
47
  const os = __importStar(require("os"));
48
48
  // 10 MB
49
49
  exports.BIG_FILE_SIZE = 10485760;
50
- exports.API_MAX_SIZE = 52428800;
50
+ // ZipFile 上传最大 1.5MB
51
+ exports.API_MAX_SIZE = 1.5 * 1024 * 1024;
51
52
  var CodeType;
52
53
  (function (CodeType) {
53
54
  CodeType[CodeType["File"] = 0] = "File";
@@ -136,7 +137,7 @@ class FunctionPacker {
136
137
  const fileStats = await promiseStat(this.zipFilePath);
137
138
  return fileStats.size > exports.BIG_FILE_SIZE;
138
139
  }
139
- // API 最大 50MB
140
+ // ZipFile 上传最大 1.5MB
140
141
  async isReachMaxSize() {
141
142
  if (!this.zipFilePath) {
142
143
  await this.build();
package/lib/index.js CHANGED
@@ -18,7 +18,7 @@ class CloudBase {
18
18
  }
19
19
  constructor(config = {}) {
20
20
  this.cloudBaseConfig = {};
21
- let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint } = config;
21
+ let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint, internalEndpointRegion } = config;
22
22
  // config 中传入的 secretId secretkey 必须同时存在
23
23
  if ((secretId && !secretKey) || (!secretId && secretKey)) {
24
24
  throw new Error('secretId and secretKey must be a pair');
@@ -31,7 +31,8 @@ class CloudBase {
31
31
  envType,
32
32
  proxy,
33
33
  region,
34
- useInternalEndpoint
34
+ useInternalEndpoint,
35
+ internalEndpointRegion,
35
36
  };
36
37
  // 初始化 context
37
38
  this.context = new context_1.CloudBaseContext(this.cloudBaseConfig);
@@ -62,6 +62,7 @@ class CloudService {
62
62
  }
63
63
  get baseUrl() {
64
64
  const internalEndpoint = this.cloudBaseContext.isInternalEndpoint();
65
+ const internalEndpointRegion = this.cloudBaseContext.getInternalEndpointRegion();
65
66
  const tcb = process.env.TCB_BASE_URL || 'https://tcb.tencentcloudapi.com';
66
67
  const urlMap = {
67
68
  tcb,
@@ -76,6 +77,9 @@ class CloudService {
76
77
  [service]: `https://${service}.internal.tencentcloudapi.com`,
77
78
  })).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
78
79
  if (internalEndpoint) {
80
+ if (internalEndpointRegion) {
81
+ return `https://${this.service}.${internalEndpointRegion}.tencentcloudapi.woa.com`;
82
+ }
79
83
  return intranetUrlMap[this.service] || `https://${this.service}.internal.tencentcloudapi.com`;
80
84
  }
81
85
  if (urlMap[this.service]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "4.7.0",
3
+ "version": "4.7.2",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -41,6 +41,7 @@ export declare const SCF_STATUS: {
41
41
  DELETE_FAILED: string;
42
42
  };
43
43
  export declare const USE_INTERNAL_ENDPOINT: boolean;
44
+ export declare const INTERNAL_ENDPOINT_REGION: string;
44
45
  export declare const enum COS_ENDPOINT {
45
46
  INTERNAL = "{Bucket}.cos-internal.{Region}.tencentcos.cn",
46
47
  PUBLIC = "{Bucket}.cos.{Region}.tencentcos.cn"
@@ -7,7 +7,8 @@ export declare class CloudBaseContext {
7
7
  readonly region: string;
8
8
  readonly envType: string;
9
9
  readonly useInternalEndpoint?: boolean;
10
- constructor({ secretId, secretKey, token, proxy, region, envType, useInternalEndpoint }: {
10
+ readonly internalEndpointRegion?: string;
11
+ constructor({ secretId, secretKey, token, proxy, region, envType, useInternalEndpoint, internalEndpointRegion }: {
11
12
  secretId?: string;
12
13
  secretKey?: string;
13
14
  token?: string;
@@ -15,6 +16,8 @@ export declare class CloudBaseContext {
15
16
  region?: string;
16
17
  envType?: string;
17
18
  useInternalEndpoint?: any;
19
+ internalEndpointRegion?: any;
18
20
  });
19
21
  isInternalEndpoint(): boolean;
22
+ getInternalEndpointRegion(): string;
20
23
  }
@@ -1,5 +1,5 @@
1
1
  export declare const BIG_FILE_SIZE = 10485760;
2
- export declare const API_MAX_SIZE = 52428800;
2
+ export declare const API_MAX_SIZE: number;
3
3
  export declare enum CodeType {
4
4
  File = 0,
5
5
  JavaFile = 1
package/types/index.d.ts CHANGED
@@ -21,6 +21,7 @@ interface CloudBaseConfig {
21
21
  region?: string;
22
22
  envType?: string;
23
23
  useInternalEndpoint?: boolean;
24
+ internalEndpointRegion?: string;
24
25
  }
25
26
  declare class CloudBase {
26
27
  private static cloudBase;