@baiducloud/sdk
Advanced tools
+7
-0
| # CHANGELOG | ||
| ## 1.0.8-beta.3 | ||
| _published on 2025-12-16_ | ||
| - chore: support `AbortController` | ||
| ## 1.0.8-beta.2 | ||
@@ -4,0 +11,0 @@ |
+1
-1
| { | ||
| "name": "@baiducloud/sdk", | ||
| "version": "1.0.8-beta.2", | ||
| "version": "1.0.8-beta.3", | ||
| "description": "Baidu Cloud Engine JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -135,3 +135,7 @@ /** | ||
| BceBaseClient.prototype.isAbortError = function (error) { | ||
| return error && (error.name === 'AbortError' || error.code === 'ABORT_ERR'); | ||
| } | ||
| module.exports = BceBaseClient; | ||
+72
-4
@@ -43,2 +43,6 @@ /** | ||
| /** | ||
| * @typedef {import('./bos_client.js').HTTPRequestConfig} HTTPRequestConfig | ||
| */ | ||
| /** | ||
| * 签名计算函数 | ||
@@ -83,3 +87,3 @@ * | ||
| * @constructor | ||
| * @param {BceConfig} config The http client configuration. | ||
| * @param {HTTPRequestConfig} config The http client configuration. | ||
| */ | ||
@@ -135,4 +139,3 @@ function HttpClient(config) { | ||
| * @param {string} path The http request path. | ||
| * @param {(string|Buffer|stream.Readable)=} body The request body. If `body` is a | ||
| * stream, `Content-Length` must be set explicitly. | ||
| * @param {(string|Buffer|stream.Readable)=} body The request body. If `body` is a stream, `Content-Length` must be set explicitly. | ||
| * @param {Object=} headers The http request headers. | ||
@@ -204,2 +207,6 @@ * @param {Object=} params The querystrings in url. | ||
| if (this.config.signal) { | ||
| options.signal = this.config.signal; | ||
| } | ||
| // 代理服务器配置,仅支持NodeJS环境配置 | ||
@@ -269,2 +276,12 @@ if (isNodeJS && this.config.proxy && u.isObject(this.config.proxy)) { | ||
| /** | ||
| * @typedef {import('url').UrlWithStringQuery} UrlWithStringQuery | ||
| */ | ||
| /** | ||
| * @param {UrlWithStringQuery} options | ||
| * @param {(string|Buffer|stream.Readable)=} body The request body. | ||
| * @param {stream.Writable} outputStream | ||
| * @returns | ||
| */ | ||
| HttpClient.prototype._doRequest = function (options, body, outputStream) { | ||
@@ -274,3 +291,13 @@ var deferred = Q.defer(); | ||
| var client = this; | ||
| var signal = options.signal; | ||
| var isAborted = false; | ||
| if (signal && signal.aborted) { | ||
| var abortError = new Error('Request aborted'); | ||
| abortError.name = 'AbortError'; | ||
| /** 和Node.js中的错误码对齐 */ | ||
| abortError.code = 'ABORT_ERR'; | ||
| return Q.reject(abortError); | ||
| } | ||
| var req = (client._req = api.request(options, function (res) { | ||
@@ -303,2 +330,41 @@ if (client._isValidStatus(res.statusCode) && outputStream && outputStream instanceof stream.Writable) { | ||
| /** 监听abort事件 */ | ||
| if (signal) { | ||
| var onAbort = function () { | ||
| if (isAborted) return; | ||
| isAborted = true; | ||
| /** 浏览器环境:xhr 对象 */ | ||
| if (req.xhr) { | ||
| req.xhr.abort(); | ||
| } else if (typeof req.destroy === 'function') { | ||
| /** Node.js 环境:ClientRequest 对象 */ | ||
| req.destroy(); | ||
| } else if (typeof req.abort === 'function') { | ||
| req.abort(); | ||
| } | ||
| var abortError = new Error('Request aborted'); | ||
| abortError.name = 'AbortError'; | ||
| abortError.code = 'ABORT_ERR'; | ||
| deferred.reject(abortError); | ||
| }; | ||
| // 兼容不同的 signal 实现 | ||
| if (signal.addEventListener) { | ||
| signal.addEventListener('abort', onAbort, {once: true}); | ||
| } else if (signal.on) { | ||
| signal.once('abort', onAbort); | ||
| } | ||
| // 清理监听器 | ||
| deferred.promise.finally(function () { | ||
| if (signal.removeEventListener) { | ||
| signal.removeEventListener('abort', onAbort); | ||
| } else if (signal.off) { | ||
| signal.off('abort', onAbort); | ||
| } | ||
| }); | ||
| } | ||
| if (req.xhr && typeof req.xhr.upload === 'object') { | ||
@@ -318,3 +384,5 @@ u.each(['progress', 'error', 'abort', 'timeout'], function (eventName) { | ||
| req.on('error', function (error) { | ||
| deferred.reject(error); | ||
| if (!isAborted) { | ||
| deferred.reject(error); | ||
| } | ||
| }); | ||
@@ -321,0 +389,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 5 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 5 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
3730283
0.21%75036
0.3%62
5.08%