Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@baiducloud/sdk

Package Overview
Dependencies
Maintainers
7
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@baiducloud/sdk - npm Package Compare versions

Comparing version
1.0.8-beta.2
to
1.0.8-beta.3
+7
-0
CHANGELOG.md
# 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;

@@ -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