tencentcloud-sdk-nodejs-intl-en 3.0.683 → 3.0.690

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tencentcloud-sdk-nodejs-intl-en",
3
- "version": "3.0.683",
3
+ "version": "3.0.690",
4
4
  "description": "腾讯云 API NODEJS SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,7 +20,11 @@
20
20
  "author": "tencentcloudapi",
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "request": "^2.85.0"
23
+ "form-data": "^2.3.3",
24
+ "get-stream": "^4.1.0",
25
+ "https-proxy-agent": "^2.2.1",
26
+ "is-stream": "^1.1.0",
27
+ "node-fetch": "^2.2.0"
24
28
  },
25
29
  "directories": {
26
30
  "example": "examples",
@@ -68,43 +68,80 @@ class AbstractClient {
68
68
  /**
69
69
  * @inner
70
70
  */
71
- request(action, req, resp, cb) {
72
- this.doRequest(action, req).then(data => this.succRequest(resp, cb, data), error => this.failRequest(error, cb));
71
+ request(action, req, resp, options, cb) {
72
+ if (typeof options === 'function') {
73
+ cb = options
74
+ options = {}
75
+ }
76
+ if (this.profile.signMethod === 'TC3-HMAC-SHA256') {
77
+ this.doRequestWithSign3(action, req, options).then(data => this.succRequest(resp, cb, data), error => this.failRequest(error, cb));
78
+ } else {
79
+ this.doRequest(action, req).then(data => this.succRequest(resp, cb, data), error => this.failRequest(error, cb));
80
+ }
73
81
  }
74
82
 
75
83
  /**
76
84
  * @inner
77
85
  */
78
- doRequest(action, req) {
86
+ async doRequest(action, req) {
79
87
  let params = this.mergeData(req);
80
88
  params = this.formatRequestData(action, params);
81
- let optional = {
82
- timeout: this.profile.httpProfile.reqTimeout * 1000
83
- };
84
- return new Promise(
85
- (resolve, reject) => {
86
- HttpConnection.doRequest(this.profile.httpProfile.reqMethod,
87
- this.profile.httpProfile.protocol + this.getEndpoint() + this.path,
88
- params, (error, response, data) => {
89
- if (error) {
90
- reject(new TencentCloudSDKHttpException(error.message));
91
- } else if (response.statusCode !== 200) {
92
- const tcError = new TencentCloudSDKHttpException(response.statusMessage)
93
- tcError.httpCode = response.statusCode
94
- reject(tcError);
95
- } else {
96
- data = JSON.parse(data);
97
- if (data.Response.Error) {
98
- const tcError = new TencentCloudSDKHttpException(data.Response.Error.Message, data.Response.RequestId)
99
- tcError.code = data.Response.Error.Code
100
- reject(tcError);
101
- } else {
102
- resolve(data.Response);
103
- }
104
- }
105
- }, // callback
106
- optional) // doRequest
107
- ;})
89
+ let res;
90
+ try {
91
+ res = await HttpConnection.doRequest({
92
+ method: this.profile.httpProfile.reqMethod,
93
+ url: this.profile.httpProfile.protocol + this.getEndpoint() + this.path,
94
+ data: params,
95
+ timeout: this.profile.httpProfile.reqTimeout * 1000
96
+ });
97
+ } catch (error) {
98
+ throw new TencentCloudSDKHttpException(error.message);
99
+ }
100
+ return await this.parseResponse(res)
101
+ }
102
+
103
+ /**
104
+ * @inner
105
+ */
106
+ async doRequestWithSign3(action, params, options) {
107
+ let res;
108
+ try {
109
+ res = await HttpConnection.doRequestWithSign3({
110
+ method: this.profile.httpProfile.reqMethod,
111
+ url: this.profile.httpProfile.protocol + this.getEndpoint() + this.path,
112
+ secretId: this.credential.secretId,
113
+ secretKey: this.credential.secretKey,
114
+ region: this.region,
115
+ data: params,
116
+ service: this.getEndpoint().split('.')[0],
117
+ action: action,
118
+ version: this.apiVersion,
119
+ multipart: options.multipart,
120
+ timeout: this.profile.httpProfile.reqTimeout * 1000,
121
+ token: this.credential.token,
122
+ requestClient: this.sdkVersion
123
+ })
124
+ } catch (e) {
125
+ throw new TencentCloudSDKHttpException(e.message)
126
+ }
127
+ return await this.parseResponse(res)
128
+ }
129
+
130
+ async parseResponse(res) {
131
+ if (res.status !== 200) {
132
+ const tcError = new TencentCloudSDKHttpException(res.statusText)
133
+ tcError.httpCode = res.status
134
+ throw tcError;
135
+ } else {
136
+ const data = await res.json();
137
+ if (data.Response.Error) {
138
+ const tcError = new TencentCloudSDKHttpException(data.Response.Error.Message, data.Response.RequestId)
139
+ tcError.code = data.Response.Error.Code
140
+ throw tcError;
141
+ } else {
142
+ return data.Response;
143
+ }
144
+ }
108
145
  }
109
146
 
110
147
  /**
@@ -0,0 +1,12 @@
1
+ const fetch = require('node-fetch');
2
+ const HttpsProxyAgent = require('https-proxy-agent');
3
+
4
+ module.exports = (url, options) => {
5
+ const instanceOptions = options || {};
6
+
7
+ if (!options.agent && process.env.http_proxy) {
8
+ instanceOptions.agent = new HttpsProxyAgent(process.env.http_proxy);
9
+ }
10
+
11
+ return fetch(url, instanceOptions);
12
+ };
@@ -1,32 +1,170 @@
1
- const request = require('request');
2
1
  const QueryString = require("querystring");
2
+ const { URL } = require('url');
3
+ const isStream = require('is-stream');
4
+ const getStream = require('get-stream');
5
+ const FormData = require('form-data');
6
+ const Sign = require('../sign');
7
+ const fetch = require('./fetch');
3
8
 
4
9
  /**
5
10
  * @inner
6
11
  */
7
12
  class HttpConnection {
8
- static doRequest(method, url, data, callback, opt={}) {
9
- let req = {
13
+ static async doRequest({ method, url, data, timeout }) {
14
+ let config = {
10
15
  method: method,
11
- url: url,
16
+ headers: {},
17
+ timeout
12
18
  };
13
19
  if (method === "GET") {
14
- req.url += "?" + QueryString.stringify(data);
20
+ url += "?" + QueryString.stringify(data);
15
21
  } else {
16
- req.form = data;
17
- }
18
- Object.assign(req, opt);
19
- request(req, function (error, response, body) {
20
- /**
21
- * callback of `.request`
22
- * @callback requestCallback
23
- * @param {Error} error Error of the request.
24
- * @param {Object} response Response of the request.
25
- * @param {String} body Result of the API request.
26
- */
27
-
28
- callback(error, response, body);
22
+ config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
23
+ config.body = QueryString.stringify(data);
24
+ }
25
+ return await fetch(url, config)
26
+ }
27
+
28
+ static async doRequestWithSign3({
29
+ method,
30
+ url,
31
+ data,
32
+ service,
33
+ action,
34
+ region,
35
+ version,
36
+ secretId,
37
+ secretKey,
38
+ multipart = false,
39
+ timeout = 60000,
40
+ token,
41
+ requestClient
42
+ }) {
43
+ // data 中可能带有 readStream,由于需要计算整个 body 的 hash,
44
+ // 所以这里把 readStream 转为 Buffer
45
+ await convertReadStreamToBuffer(data)
46
+
47
+ data = deepRemoveNull(data)
48
+
49
+ const timestamp = parseInt(new Date().getTime() / 1000)
50
+ method = method.toUpperCase()
51
+
52
+ let payload = ''
53
+ if (method === 'GET') {
54
+ data = mergeData(data)
55
+ url += '?' + QueryString.stringify(data)
56
+ }
57
+ if (method === 'POST') {
58
+ payload = data
59
+ }
60
+
61
+ const config = {
62
+ method,
63
+ timeout,
64
+ headers: {
65
+ 'Host': new URL(url).host,
66
+ 'X-TC-Action': action,
67
+ 'X-TC-Region': region,
68
+ 'X-TC-Timestamp': timestamp,
69
+ 'X-TC-Version': version,
70
+ 'X-TC-Token': token,
71
+ 'X-TC-RequestClient': requestClient
72
+ }
73
+ }
74
+
75
+ if (token === null) {
76
+ delete config.headers["X-TC-Token"]
77
+ }
78
+
79
+ let form
80
+ if (method === 'GET') {
81
+ config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
82
+ }
83
+ if (method === 'POST' && !multipart) {
84
+ config.body = JSON.stringify(data)
85
+ config.headers['Content-Type'] = 'application/json'
86
+ }
87
+ if (method === 'POST' && multipart) {
88
+ form = new FormData();
89
+ for (var key in data) {
90
+ form.append(key, data[key])
91
+ }
92
+ config.body = form
93
+ config.headers = Object.assign({}, config.headers, form.getHeaders())
94
+ }
95
+
96
+ const signature = Sign.sign3({
97
+ method,
98
+ url,
99
+ payload,
100
+ timestamp,
101
+ service,
102
+ secretId,
103
+ secretKey,
104
+ multipart,
105
+ boundary: form ? form.getBoundary() : undefined
29
106
  })
107
+
108
+ config.headers['Authorization'] = signature
109
+
110
+ return await fetch(url, config)
111
+ }
112
+ }
113
+
114
+ async function convertReadStreamToBuffer(data) {
115
+ for (let key in data) {
116
+ if (isStream(data[key])) {
117
+ data[key] = await getStream.buffer(data[key])
118
+ }
30
119
  }
31
120
  }
121
+
122
+ function mergeData(data, prefix = "") {
123
+ let ret = {};
124
+ for (let k in data) {
125
+ if (data[k] === null) {
126
+ continue;
127
+ }
128
+ if (data[k] instanceof Array || data[k] instanceof Object) {
129
+ Object.assign(ret, mergeData(data[k], prefix + k + "."));
130
+ } else {
131
+ ret[prefix + k] = data[k];
132
+ }
133
+ }
134
+ return ret;
135
+ }
136
+
137
+ function deepRemoveNull(obj) {
138
+ if (isArray(obj)) {
139
+ return obj.map(deepRemoveNull)
140
+ } else if (isObject(obj)) {
141
+ let result = {}
142
+ for (let key in obj) {
143
+ const value = obj[key]
144
+ if (!isNull(value)) {
145
+ result[key] = deepRemoveNull(value)
146
+ }
147
+ }
148
+ return result
149
+ } else {
150
+ return obj
151
+ }
152
+ }
153
+
154
+ function isBuffer(x) {
155
+ return Buffer.isBuffer(x)
156
+ }
157
+
158
+ function isArray(x) {
159
+ return Array.isArray(x)
160
+ }
161
+
162
+ function isObject(x) {
163
+ return typeof x === 'object' && !isArray(x) && !isStream(x) && !isBuffer(x) && x !== null
164
+ }
165
+
166
+ function isNull(x) {
167
+ return x === null
168
+ }
169
+
32
170
  module.exports = HttpConnection;
@@ -1,2 +1,2 @@
1
- const sdkVersion = "3.0.683";
1
+ const sdkVersion = "3.0.690";
2
2
  module.exports = sdkVersion
@@ -1,5 +1,6 @@
1
1
  const TencentCloudSDKHttpException = require("./exception/tencent_cloud_sdk_exception");
2
2
  const crypto = require('crypto');
3
+ const { URL } = require('url')
3
4
 
4
5
  /**
5
6
  * @inner
@@ -18,5 +19,103 @@ class Sign {
18
19
  let hmac = crypto.createHmac(signMethodMap[signMethod], secretKey || "");
19
20
  return hmac.update(Buffer.from(signStr, 'utf8')).digest('base64')
20
21
  }
22
+
23
+ static sign3({
24
+ method = 'POST',
25
+ url = '',
26
+ payload,
27
+ timestamp,
28
+ service,
29
+ secretId,
30
+ secretKey,
31
+ multipart,
32
+ boundary
33
+ }) {
34
+ const urlObj = new URL(url)
35
+
36
+ // 通用头部
37
+ let headers = ''
38
+ let signedHeaders = ''
39
+ if (method === 'GET') {
40
+ signedHeaders = 'content-type'
41
+ headers = 'content-type:application/x-www-form-urlencoded\n'
42
+ } else if (method === 'POST') {
43
+ signedHeaders = 'content-type'
44
+ if (multipart) {
45
+ headers = `content-type:multipart/form-data; boundary=${boundary}\n`
46
+ } else {
47
+ headers = 'content-type:application/json\n'
48
+ }
49
+ }
50
+ headers += `host:${urlObj.hostname}\n`
51
+ signedHeaders += ';host'
52
+
53
+ const path = urlObj.pathname
54
+ const querystring = urlObj.search.slice(1)
55
+
56
+ let payload_hash = ''
57
+ if (multipart) {
58
+ const hash = crypto.createHash('sha256')
59
+ hash.update(`--${boundary}`)
60
+ for (let key in payload) {
61
+ const content = payload[key]
62
+ if (Buffer.isBuffer(content)) {
63
+ hash.update(`\r\nContent-Disposition: form-data; name="${key}"\r\nContent-Type: application/octet-stream\r\n\r\n`)
64
+ hash.update(content)
65
+ hash.update('\r\n')
66
+ } else if (typeof content === 'string') {
67
+ hash.update(`\r\nContent-Disposition: form-data; name="${key}"\r\n\r\n`)
68
+ hash.update(`${content}\r\n`)
69
+ }
70
+ hash.update(`--${boundary}`)
71
+ }
72
+ hash.update(`--\r\n`)
73
+ payload_hash = hash.digest('hex')
74
+ } else {
75
+ payload_hash = payload ? getHash(JSON.stringify(payload)) : getHash('')
76
+ }
77
+
78
+ const canonicalRequest =
79
+ method + '\n' +
80
+ path + '\n' +
81
+ querystring + '\n' +
82
+ headers + '\n' +
83
+ signedHeaders + '\n' +
84
+ payload_hash
85
+ const date = getDate(timestamp)
86
+
87
+ const StringToSign =
88
+ 'TC3-HMAC-SHA256' + '\n' +
89
+ timestamp + '\n' +
90
+ `${date}/${service}/tc3_request` + '\n' +
91
+ getHash(canonicalRequest)
92
+
93
+ const kDate = sha256(date, 'TC3' + secretKey)
94
+ const kService = sha256(service, kDate)
95
+ const kSigning = sha256('tc3_request', kService)
96
+ const signature = sha256(StringToSign, kSigning, 'hex')
97
+
98
+ return `TC3-HMAC-SHA256 Credential=${secretId}/${date}/${service}/tc3_request, SignedHeaders=${signedHeaders}, Signature=${signature}`
99
+ }
100
+ }
101
+
102
+
103
+ function sha256(message, secret = '', encoding) {
104
+ const hmac = crypto.createHmac('sha256', secret)
105
+ return hmac.update(message).digest(encoding)
106
+ }
107
+
108
+ function getHash(message, encoding = 'hex') {
109
+ const hash = crypto.createHash('sha256')
110
+ return hash.update(message).digest(encoding)
21
111
  }
112
+
113
+ function getDate(timestamp) {
114
+ const date = new Date(timestamp * 1000)
115
+ const year = date.getUTCFullYear()
116
+ const month = ('0' + (date.getUTCMonth() + 1)).slice(-2)
117
+ const day = ('0' + date.getUTCDate()).slice(-2)
118
+ return `${year}-${month}-${day}`
119
+ }
120
+
22
121
  module.exports = Sign;
@@ -1226,13 +1226,13 @@ Default value: `4`.
1226
1226
  this.SecureLevel = null;
1227
1227
 
1228
1228
  /**
1229
- * The image for comparison in the `compare` (liveness detection and face comparison) mode. This parameter is required when the value of `CheckMode` is `compare`.
1229
+ * The photo (in Base64) to compare. This parameter is required when the value of `CheckMode` is `compare`.
1230
1230
  * @type {string || null}
1231
1231
  */
1232
1232
  this.Image = null;
1233
1233
 
1234
1234
  /**
1235
- * The pass-through parameter.
1235
+ * The pass-through parameter, which can be omitted if there are no special requirements.
1236
1236
  * @type {string || null}
1237
1237
  */
1238
1238
  this.Extra = null;
@@ -17,9 +17,10 @@
17
17
  const models = require("./models");
18
18
  const AbstractClient = require('../../common/abstract_client')
19
19
  const CreateLiveSnapshotRuleRequest = models.CreateLiveSnapshotRuleRequest;
20
- const TimeShiftBillData = models.TimeShiftBillData;
20
+ const BillDataInfo = models.BillDataInfo;
21
21
  const EnableLiveDomainResponse = models.EnableLiveDomainResponse;
22
22
  const DescribeUploadStreamNumsResponse = models.DescribeUploadStreamNumsResponse;
23
+ const HlsSpecialParam = models.HlsSpecialParam;
23
24
  const TranscodeTotalInfo = models.TranscodeTotalInfo;
24
25
  const StopRecordTaskResponse = models.StopRecordTaskResponse;
25
26
  const DescribeDeliverBandwidthListResponse = models.DescribeDeliverBandwidthListResponse;
@@ -27,6 +28,7 @@ const DeleteLiveRecordRuleRequest = models.DeleteLiveRecordRuleRequest;
27
28
  const ResumeLiveStreamRequest = models.ResumeLiveStreamRequest;
28
29
  const DeleteLiveTranscodeTemplateResponse = models.DeleteLiveTranscodeTemplateResponse;
29
30
  const FlvSpecialParam = models.FlvSpecialParam;
31
+ const DescribeBillBandwidthAndFluxListResponse = models.DescribeBillBandwidthAndFluxListResponse;
30
32
  const CreateScreenshotTaskResponse = models.CreateScreenshotTaskResponse;
31
33
  const DeleteLiveCallbackRuleResponse = models.DeleteLiveCallbackRuleResponse;
32
34
  const ResumeDelayLiveStreamRequest = models.ResumeDelayLiveStreamRequest;
@@ -117,6 +119,7 @@ const DescribeConcurrentRecordStreamNumResponse = models.DescribeConcurrentRecor
117
119
  const DescribeLiveTimeShiftBillInfoListRequest = models.DescribeLiveTimeShiftBillInfoListRequest;
118
120
  const DescribeLiveCertsResponse = models.DescribeLiveCertsResponse;
119
121
  const CommonMixInputParam = models.CommonMixInputParam;
122
+ const WatermarkInfo = models.WatermarkInfo;
120
123
  const DescribeLiveWatermarkRulesResponse = models.DescribeLiveWatermarkRulesResponse;
121
124
  const DescribeLiveRecordTemplatesResponse = models.DescribeLiveRecordTemplatesResponse;
122
125
  const PlayDataInfoByStream = models.PlayDataInfoByStream;
@@ -176,7 +179,7 @@ const DescribeStreamPushInfoListResponse = models.DescribeStreamPushInfoListResp
176
179
  const DescribeLiveStreamPushInfoListRequest = models.DescribeLiveStreamPushInfoListRequest;
177
180
  const StopLiveRecordResponse = models.StopLiveRecordResponse;
178
181
  const DescribeLiveWatermarksResponse = models.DescribeLiveWatermarksResponse;
179
- const WatermarkInfo = models.WatermarkInfo;
182
+ const TimeShiftBillData = models.TimeShiftBillData;
180
183
  const DescribeLiveForbidStreamListRequest = models.DescribeLiveForbidStreamListRequest;
181
184
  const DescribeTopClientIpSumInfoListRequest = models.DescribeTopClientIpSumInfoListRequest;
182
185
  const CreateLiveCallbackRuleRequest = models.CreateLiveCallbackRuleRequest;
@@ -253,7 +256,7 @@ const DescribeVisitTopSumInfoListResponse = models.DescribeVisitTopSumInfoListRe
253
256
  const CallBackRuleInfo = models.CallBackRuleInfo;
254
257
  const PlaySumStatInfo = models.PlaySumStatInfo;
255
258
  const DescribeLiveTranscodeTemplatesRequest = models.DescribeLiveTranscodeTemplatesRequest;
256
- const HlsSpecialParam = models.HlsSpecialParam;
259
+ const DescribeBillBandwidthAndFluxListRequest = models.DescribeBillBandwidthAndFluxListRequest;
257
260
  const DescribeLiveRecordRulesResponse = models.DescribeLiveRecordRulesResponse;
258
261
  const CreateLiveSnapshotTemplateRequest = models.CreateLiveSnapshotTemplateRequest;
259
262
  const TemplateInfo = models.TemplateInfo;
@@ -1387,6 +1390,17 @@ Note:
1387
1390
  this.request("CreateLiveRecordTemplate", req, resp, cb);
1388
1391
  }
1389
1392
 
1393
+ /**
1394
+ * This API is used to query the data of billable LVB bandwidth and traffic.
1395
+ * @param {DescribeBillBandwidthAndFluxListRequest} req
1396
+ * @param {function(string, DescribeBillBandwidthAndFluxListResponse):void} cb
1397
+ * @public
1398
+ */
1399
+ DescribeBillBandwidthAndFluxList(req, cb) {
1400
+ let resp = new DescribeBillBandwidthAndFluxListResponse();
1401
+ this.request("DescribeBillBandwidthAndFluxList", req, resp, cb);
1402
+ }
1403
+
1390
1404
  /**
1391
1405
  * This API is used to disable an LVB domain name.
1392
1406
  * @param {ForbidLiveDomainRequest} req