@cloudbase/node-sdk 3.14.1 → 3.15.0

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/dist/cloudbase.js CHANGED
@@ -115,67 +115,14 @@ class CloudBase {
115
115
  token: (await this.auth().getClientCredential()).access_token
116
116
  });
117
117
  return result.body;
118
- }, (0, tcbopenapiendpoint_1.buildCommonOpenApiUrlWithPath)({ serviceUrl: this.config.serviceUrl, envId, path: '/v1/model', region: this.config.region }), {
119
- sqlBaseUrl: (0, tcbopenapiendpoint_1.buildCommonOpenApiUrlWithPath)({ serviceUrl: this.config.serviceUrl, envId, path: '/v1/sql', region: this.config.region })
118
+ }, (0, tcbopenapiendpoint_1.buildCommonOpenApiUrlWithPath)({ serviceUrl: this.config.serviceUrl, envId, path: '/v1/model' }), {
119
+ sqlBaseUrl: (0, tcbopenapiendpoint_1.buildCommonOpenApiUrlWithPath)({ serviceUrl: this.config.serviceUrl, envId, path: '/v1/sql' })
120
120
  });
121
121
  this.models = httpClient;
122
122
  }
123
123
  catch (e) {
124
124
  // ignore
125
125
  }
126
- try {
127
- const getEntity = (options) => {
128
- const envId = this.config.envName === symbol_1.SYMBOL_CURRENT_ENV
129
- ? openapicommonrequester.getEnvIdFromContext()
130
- : this.config.envName;
131
- const { instance = 'default', database = envId } = options || {};
132
- const mysqlClient = wx_cloud_client_sdk_1.default.generateMySQLClient(this, {
133
- mysqlBaseUrl: (0, tcbopenapiendpoint_1.buildCommonOpenApiUrlWithPath)({
134
- serviceUrl: this.config.serviceUrl,
135
- envId,
136
- path: '/v1/rdb/rest',
137
- region: this.config.region
138
- }),
139
- fetch: async (url, options) => {
140
- var _a;
141
- let headers = {};
142
- if (options.headers instanceof Headers) {
143
- options.headers.forEach((value, key) => {
144
- headers[key] = value;
145
- });
146
- }
147
- else {
148
- headers = options.headers || {};
149
- }
150
- const result = await openapicommonrequester.request({
151
- config: this.config,
152
- data: safeParseJSON(options.body),
153
- method: (_a = options.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
154
- url: url instanceof URL ? url.href : String(url),
155
- headers: Object.assign({ 'Content-Type': 'application/json' }, headersInitToRecord(Object.assign({ 'X-Db-Instance': instance, 'Accept-Profile': database, 'Content-Profile': database }, headers))),
156
- token: (await this.auth().getClientCredential()).access_token
157
- });
158
- const data = result.body;
159
- const res = {
160
- ok: (result === null || result === void 0 ? void 0 : result.statusCode) >= 200 && (result === null || result === void 0 ? void 0 : result.statusCode) < 300,
161
- status: (result === null || result === void 0 ? void 0 : result.statusCode) || 200,
162
- statusText: (result === null || result === void 0 ? void 0 : result.statusMessage) || 'OK',
163
- json: async () => await Promise.resolve(data || {}),
164
- text: async () => await Promise.resolve(typeof data === 'string' ? data : JSON.stringify(data || {})),
165
- headers: new Headers((result === null || result === void 0 ? void 0 : result.headers) || {})
166
- };
167
- return res;
168
- }
169
- });
170
- return mysqlClient;
171
- };
172
- this.mysql = (options) => {
173
- return getEntity(options)(options);
174
- };
175
- }
176
- catch (e) {
177
- // ignore
178
- }
179
126
  }
180
127
  logger() {
181
128
  if (!this.clsLogger) {
@@ -88,8 +88,7 @@ class TcbOpenApiHttpCommonRequester {
88
88
  : args.config.envName;
89
89
  const url = args.url || (0, tcbopenapiendpoint_1.buildCommonOpenApiUrlWithPath)({
90
90
  envId,
91
- path: args.path,
92
- region: config.region
91
+ path: args.path
93
92
  });
94
93
  const timeout = ((_a = this.args.opts) === null || _a === void 0 ? void 0 : _a.timeout) || this.config.timeout || this.defaultTimeout;
95
94
  const opts = {
@@ -108,7 +107,7 @@ class TcbOpenApiHttpCommonRequester {
108
107
  opts.keepalive = typeof config.keepalive === 'boolean' && config.keepalive;
109
108
  }
110
109
  if (args.data) {
111
- if (['post', 'put', 'patch', 'delete'].includes(args.method.toLowerCase())) {
110
+ if (['post', 'put'].includes(args.method.toLowerCase())) {
112
111
  if (args.isFormData) {
113
112
  opts.formData = args.data;
114
113
  opts.encoding = null;
@@ -1,23 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildCommonOpenApiUrlWithPath = exports.buildUrl = void 0;
4
- const ZONE_CHINA = ['ap-shanghai', 'ap-guangzhou', 'ap-shenzhen-fsi', 'ap-shanghai-fsi', 'ap-nanjing', 'ap-beijing', 'ap-chengdu', 'ap-chongqing', 'ap-hongkong'];
5
4
  /* eslint-disable complexity */
6
5
  function buildUrl(options) {
7
- const endpoint = `https://${getGatewayUrl(options)}/v1/cloudrun/${options.name}`;
6
+ const endpoint = `https://${options.envId}.api.tcloudbasegateway.com/v1/cloudrun/${options.name}`;
8
7
  const path = options.path.startsWith('/') ? options.path : `/${options.path}`;
9
8
  return `${endpoint}${path}`;
10
9
  }
11
10
  exports.buildUrl = buildUrl;
12
11
  function buildCommonOpenApiUrlWithPath(options) {
13
- return `${options.protocol || 'https'}://${options.serviceUrl || getGatewayUrl(options)}${options.path}`;
12
+ return `${options.protocol || 'https'}://${options.serviceUrl || `${options.envId}.api.tcloudbasegateway.com`}${options.path}`;
14
13
  }
15
14
  exports.buildCommonOpenApiUrlWithPath = buildCommonOpenApiUrlWithPath;
16
- function getGatewayUrl(options) {
17
- const region = options.region || 'ap-shanghai';
18
- let baseUrl = `${options.envId}.api.tcloudbasegateway.com`;
19
- if (!ZONE_CHINA.includes(region)) {
20
- baseUrl = `${options.envId}.api.intl.tcloudbasegateway.com`;
21
- }
22
- return baseUrl;
23
- }
@@ -88,7 +88,7 @@ class TcbOpenApiHttpRequester {
88
88
  : args.config.envName;
89
89
  const url = (0, tcbopenapiendpoint_1.buildUrl)({
90
90
  envId,
91
- region: this.config.region,
91
+ // region: this.config.region,
92
92
  // protocol: this.config.protocol || 'https',
93
93
  // serviceUrl: this.config.serviceUrl,
94
94
  // seqId: this.tracingInfo.seqId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/node-sdk",
3
- "version": "3.14.1",
3
+ "version": "3.15.0",
4
4
  "description": "tencent cloud base server sdk for node.js",
5
5
  "main": "dist/index.js",
6
6
  "typings": "types/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@cloudbase/database": "1.4.2",
45
- "@cloudbase/signature-nodejs": "2.0.0",
45
+ "@cloudbase/signature-nodejs": "2.2.0",
46
46
  "@cloudbase/wx-cloud-client-sdk": "1.7.1",
47
47
  "agentkeepalive": "^4.3.0",
48
48
  "axios": "0.27.2",
package/src/cloudbase.ts CHANGED
@@ -82,6 +82,7 @@ export class CloudBase {
82
82
  public models: OrmClient & OrmRawQueryClient
83
83
 
84
84
  public mysql: IMySqlClient
85
+ public rdb: IMySqlClient
85
86
 
86
87
  public constructor(config?: ICloudBaseConfig) {
87
88
  this.init(config)
@@ -238,6 +239,9 @@ export class CloudBase {
238
239
  this.mysql = (options: IMySqlOptions) => {
239
240
  return getEntity(options)(options)
240
241
  }
242
+ this.rdb = (options: IMySqlOptions) => {
243
+ return getEntity(options)(options)
244
+ }
241
245
  } catch (e) {
242
246
  // ignore
243
247
  }
@@ -131,6 +131,7 @@ export class TcbOpenApiHttpRequester {
131
131
  }
132
132
  } else {
133
133
  /* istanbul ignore next */
134
+ // 这里 qs 参数暂时并没使用
134
135
  opts.qs = args.data
135
136
  }
136
137
  } else {
@@ -184,13 +185,20 @@ export class TcbOpenApiHttpRequester {
184
185
 
185
186
  requiredHeaders = { ...config.headers, ...args.headers, ...requiredHeaders }
186
187
 
188
+ let params = args.data || ''
189
+
190
+ // GET 方法不支持传 BODY
191
+ if (method.toLowerCase() === 'get') {
192
+ params = ''
193
+ }
194
+
187
195
  // TODO: 升级SDK版本,否则没传 args.data 时会签名失败
188
196
  const { authorization, timestamp } = sign({
189
197
  secretId,
190
198
  secretKey,
191
199
  method,
192
200
  url,
193
- params: args.data || '',
201
+ params,
194
202
  headers: requiredHeaders,
195
203
  timestamp: second() - 1,
196
204
  withSignedParams: false,
package/types/index.d.ts CHANGED
@@ -394,7 +394,7 @@ export interface CallFunctionResult<T> {
394
394
  // https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloud/reference-sdk-api/container/Cloud.callContainer.html
395
395
  export interface ICallContainerOptions<T> {
396
396
  name: string
397
- method?: 'POST'
397
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'
398
398
  path?: string
399
399
  header?: IHeaderOpts & {
400
400
  // 'X-WX-SERVICE': string