New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ali-oss

Package Overview
Dependencies
Maintainers
7
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ali-oss - npm Package Compare versions

Comparing version 6.15.2 to 6.16.0

lib/common/utils/isFunction.d.ts

16

lib/browser/client.js

@@ -17,2 +17,3 @@ const debug = require('debug')('ali-oss');

const { retry } = require('../common/utils/retry');
const { isFunction } = require('../common/utils/isFunction');

@@ -218,2 +219,5 @@ const globalHttpAgent = new AgentKeepalive();

async function request(params) {
if (this.options.stsToken && isFunction(this.options.refreshSTSToken)) {
await setSTSToken.call(this);
}
const reqParams = createRequest.call(this, params);

@@ -246,12 +250,2 @@ if (!this.options.useFetch) {

if (err) {
if (err.status === 403 && err.code === 'InvalidAccessKeyId' &&
this.options.accessKeyId.startsWith('STS.') &&
typeof this.options.refreshSTSToken === 'function') {
// prevent infinite loop, only trigger once within 10 seconds
if (!this._setOptions || Date.now() - this._setOptions > 10000) {
this._setOptions = Date.now();
await setSTSToken.call(this);
return this.request(params);
}
}
throw err;

@@ -265,3 +259,3 @@ }

return result;
};
}

@@ -268,0 +262,0 @@ proto._getResource = function _getResource(params) {

@@ -1,1 +0,1 @@

exports.version="6.15.1"
exports.version="6.16.0"

@@ -20,2 +20,3 @@

const { retry } = require('./common/utils/retry');
const { isFunction } = require('./common/utils/isFunction');

@@ -190,2 +191,5 @@ const globalHttpAgent = new AgentKeepalive();

async function request(params) {
if (this.options.stsToken && isFunction(this.options.refreshSTSToken)) {
await setSTSToken.call(this);
}
const reqParams = createRequest.call(this, params);

@@ -214,15 +218,2 @@ let result;

if (err.status === 403 && err.code === 'InvalidAccessKeyId' &&
this.options.accessKeyId.startsWith('STS.') &&
typeof this.options.refreshSTSToken === 'function') {
// prevent infinite loop, only trigger once within 10 seconds
if (!this._setOptions || Date.now() - this._setOptions > 10000) {
this._setOptions = Date.now();
await setSTSToken.call(this);
if (!params.stream) {
return this.request(params);
}
}
}
if (err.name === 'ResponseTimeoutError') {

@@ -229,0 +220,0 @@ err.message = `${err.message.split(',')[0]}, please increase the timeout or use multipartDownload.`;

@@ -26,5 +26,6 @@ const ms = require('humanize-ms');

}
if (options.stsToken && !options.refreshSTSToken) {
if (options.stsToken && !options.refreshSTSToken && !options.refreshSTSTokenInterval) {
console.warn(
"It's recommended to set `refreshSTSToken` to refresh stsToken、accessKeyId、accessKeySecret automatically when sts info expires"
"It's recommended to set 'refreshSTSToken' and 'refreshSTSTokenInterval' to refresh" +
' stsToken、accessKeyId、accessKeySecret automatically when sts token has expired'
);

@@ -48,2 +49,3 @@ }

refreshSTSToken: null,
refreshSTSTokenInterval: 60000 * 5,
retryMax: 0

@@ -50,0 +52,0 @@ },

@@ -1,2 +0,2 @@

const { isArray } = require("./utils/isArray");
const { isArray } = require('./utils/isArray');

@@ -3,0 +3,0 @@ const proto = exports;

@@ -1,1 +0,1 @@

export declare function setSTSToken(this: any): Promise<void>;
export declare function setSTSToken(this: any): Promise<null>;

@@ -8,9 +8,19 @@ "use strict";

this.options = {};
let credentials = await this.options.refreshSTSToken();
credentials = formatObjKey_1.formatObjKey(credentials, 'firstLowerCase');
if (credentials.securityToken) {
credentials.stsToken = credentials.securityToken;
const now = new Date();
if (this.stsTokenFreshTime) {
if (+now - this.stsTokenFreshTime >= this.options.refreshSTSTokenInterval) {
this.stsTokenFreshTime = now;
let credentials = await this.options.refreshSTSToken();
credentials = formatObjKey_1.formatObjKey(credentials, 'firstLowerCase');
if (credentials.securityToken) {
credentials.stsToken = credentials.securityToken;
}
checkCredentials(credentials);
Object.assign(this.options, credentials);
}
}
checkCredentials(credentials);
Object.assign(this.options, credentials);
else {
this.stsTokenFreshTime = now;
}
return null;
}

@@ -17,0 +27,0 @@ exports.setSTSToken = setSTSToken;

@@ -5,9 +5,19 @@ import { formatObjKey } from './formatObjKey';

if (!this.options) this.options = {};
let credentials = await this.options.refreshSTSToken();
credentials = formatObjKey(credentials, 'firstLowerCase');
if (credentials.securityToken) {
credentials.stsToken = credentials.securityToken;
const now = new Date();
if (this.stsTokenFreshTime) {
if (+now - this.stsTokenFreshTime >= this.options.refreshSTSTokenInterval) {
this.stsTokenFreshTime = now;
let credentials = await this.options.refreshSTSToken();
credentials = formatObjKey(credentials, 'firstLowerCase');
if (credentials.securityToken) {
credentials.stsToken = credentials.securityToken;
}
checkCredentials(credentials);
Object.assign(this.options, credentials);
}
} else {
this.stsTokenFreshTime = now;
}
checkCredentials(credentials);
Object.assign(this.options, credentials);
return null;
}

@@ -14,0 +24,0 @@

@@ -110,2 +110,3 @@ const fs = require('fs');

proto._resumeMultipart = async function _resumeMultipart(checkpoint, options) {
const that = this;
if (this.isCancel()) {

@@ -211,3 +212,8 @@ throw this._makeCancelEvent();

// upload in parallel
const jobErr = await this._parallelNode(todo, parallel, uploadPartJob);
const jobErr = await this._parallel(todo, parallel,
value => new Promise((resolve, reject) => {
uploadPartJob(that, value).then(() => {
resolve();
}).catch(reject);
}));

@@ -214,0 +220,0 @@ const abortEvent = jobErr.find(err => err.name === 'abort');

{
"name": "ali-oss",
"version": "6.15.2",
"version": "6.16.0",
"description": "aliyun oss(object storage service) node client",

@@ -24,4 +24,4 @@ "main": "lib/client.js",

"build-change-log": "standard-version",
"test": "mocha -t 60000 -r thunk-mocha -r should -r dotenv/config test/node/*.test.js test/node/**/*.test.js",
"test-cov": "nyc --reporter=lcov node_modules/.bin/_mocha -t 60000 -r thunk-mocha -r should test/node/*.test.js test/node/**/*.test.js",
"test": "npm run tsc && mocha -t 60000 -r thunk-mocha -r should -r dotenv/config test/node/*.test.js test/node/**/*.test.js",
"test-cov": "npm run tsc && nyc --reporter=lcov node_modules/.bin/_mocha -t 60000 -r thunk-mocha -r should test/node/*.test.js test/node/**/*.test.js",
"jshint": "jshint .",

@@ -115,3 +115,3 @@ "autod": "autod",

"sinon": "^1.17.7",
"snyk": "^1.520.0",
"snyk": "1.454.0",
"standard-version": "^8.0.1",

@@ -118,0 +118,0 @@ "stream-equal": "^1.1.0",

'use strict';
const util = require('util');
const urlutil = require('url');
const http = require('http');
const https = require('https');
const debug = require('debug')('urllib');
const ms = require('humanize-ms');
let REQUEST_ID = 0;
const MAX_VALUE = Math.pow(2, 31) - 10;
const PROTO_RE = /^https?:\/\//i;
var util = require('util');
var urlutil = require('url');
var http = require('http');
var https = require('https');
var debug = require('debug')('urllib');
var ms = require('humanize-ms');
var _Promise;
var REQUEST_ID = 0;
var MAX_VALUE = Math.pow(2, 31) - 10;
var PROTO_RE = /^https?:\/\//i;
function getAgent(agent, defaultAgent) {

@@ -20,2 +16,10 @@ return agent === undefined ? defaultAgent : agent;

function parseContentType(str) {
if (!str) {
return '';
}
return str.split(';')[0].trim().toLowerCase();
}
function makeCallback(resolve, reject) {

@@ -38,3 +42,3 @@ return function (err, data, res) {

var TEXT_DATA_TYPES = [
const TEXT_DATA_TYPES = [
'json',

@@ -61,5 +65,5 @@ 'text'

exports.requestWithCallback = function requestWithCallback(url, args, callback) {
// requestWithCallback(url, callback)
if (!url || (typeof url !== 'string' && typeof url !== 'object')) {
var msg = util.format('expect request url to be a string or a http request options, but got %j', url);
const msg = util.format('expect request url to be a string or a http request options, but got' +
' %j', url);
throw new Error(msg);

@@ -77,7 +81,7 @@ }

}
var reqId = ++REQUEST_ID;
const reqId = ++REQUEST_ID;
args.requestUrls = args.requestUrls || [];
var reqMeta = {
const reqMeta = {
requestId: reqId,

@@ -95,4 +99,4 @@ url: url,

args.streaming = args.streaming || args.customResponse;
var requestStartTime = Date.now();
var parsedUrl;
const requestStartTime = Date.now();
let parsedUrl;

@@ -102,3 +106,3 @@ if (typeof url === 'string') {

// Support `request('www.server.com')`
url = 'http://' + url;
url = 'https://' + url;
}

@@ -110,7 +114,7 @@ parsedUrl = urlutil.parse(url);

var method = (args.type || args.method || parsedUrl.method || 'GET').toUpperCase();
var port = parsedUrl.port || 80;
var httplib = http;
var agent = getAgent(args.agent, exports.agent);
var fixJSONCtlChars = args.fixJSONCtlChars;
const method = (args.type || args.method || parsedUrl.method || 'GET').toUpperCase();
let port = parsedUrl.port || 80;
let httplib = http;
let agent = getAgent(args.agent, exports.agent);
const fixJSONCtlChars = args.fixJSONCtlChars;

@@ -132,3 +136,3 @@ if (parsedUrl.protocol === 'https:') {

var options = {
const options = {
host: parsedUrl.hostname || parsedUrl.host || 'localhost',

@@ -153,26 +157,26 @@ path: parsedUrl.path || '/',

var sslNames = [
'pfx',
'key',
'passphrase',
'cert',
'ca',
'ciphers',
'rejectUnauthorized',
'secureProtocol',
'secureOptions',
];
for (var i = 0; i < sslNames.length; i++) {
var name = sslNames[i];
if (args.hasOwnProperty(name)) {
options[name] = args[name];
}
}
// const sslNames = [
// 'pfx',
// 'key',
// 'passphrase',
// 'cert',
// 'ca',
// 'ciphers',
// 'rejectUnauthorized',
// 'secureProtocol',
// 'secureOptions',
// ];
// for (let i = 0; i < sslNames.length; i++) {
// const name = sslNames[i];
// if (args.hasOwnProperty(name)) {
// options[name] = args[name];
// }
// }
// don't check ssl
if (options.rejectUnauthorized === false && !options.hasOwnProperty('secureOptions')) {
options.secureOptions = require('constants').SSL_OP_NO_TLSv1_2;
}
// if (options.rejectUnauthorized === false && !options.hasOwnProperty('secureOptions')) {
// options.secureOptions = require('constants').SSL_OP_NO_TLSv1_2;
// }
var auth = args.auth || parsedUrl.auth;
const auth = args.auth || parsedUrl.auth;
if (auth) {

@@ -182,4 +186,5 @@ options.auth = auth;

var body = args.content || args.data;
var dataAsQueryString = method === 'GET' || method === 'HEAD' || args.dataAsQueryString;
// content undefined data 有值
let body = args.content || args.data;
const dataAsQueryString = method === 'GET' || method === 'HEAD' || args.dataAsQueryString;
if (!args.content) {

@@ -191,3 +196,3 @@ if (body && !(typeof body === 'string' || Buffer.isBuffer(body))) {

} else {
var contentType = options.headers['Content-Type'] || options.headers['content-type'];
let contentType = options.headers['Content-Type'] || options.headers['content-type'];
// auto add application/x-www-form-urlencoded when using urlencode form request

@@ -203,3 +208,3 @@ if (!contentType) {

if (parseContentType(contentType).type === 'application/json') {
if (parseContentType(contentType) === 'application/json') {
body = JSON.stringify(body);

@@ -220,5 +225,5 @@ } else {

var requestSize = 0;
let requestSize = 0;
if (body) {
var length = body.length;
let length = body.length;
if (!Buffer.isBuffer(body)) {

@@ -238,13 +243,13 @@ length = Buffer.byteLength(body);

}
var connectTimer = null;
var responseTimer = null;
var __err = null;
var connected = false; // socket connected or not
var keepAliveSocket = false; // request with keepalive socket
var responseSize = 0;
var statusCode = -1;
var responseAborted = false;
var remoteAddress = '';
var remotePort = '';
var timing = null;
let connectTimer = null;
let responseTimer = null;
let __err = null;
let connected = false; // socket connected or not
let keepAliveSocket = false; // request with keepalive socket
let responseSize = 0;
let statusCode = -1;
let responseAborted = false;
let remoteAddress = '';
let remotePort = '';
let timing = null;
if (args.timing) {

@@ -291,5 +296,5 @@ timing = {

}
var cb = callback;
const cb = callback;
callback = null;
var headers = {};
let headers = {};
if (res) {

@@ -301,18 +306,18 @@ statusCode = res.statusCode;

// handle digest auth
if (statusCode === 401 && headers['www-authenticate']
&& (!args.headers || !args.headers.Authorization) && args.digestAuth) {
var authenticate = headers['www-authenticate'];
if (authenticate.indexOf('Digest ') >= 0) {
debug('Request#%d %s: got digest auth header WWW-Authenticate: %s', reqId, url, authenticate);
args.headers = args.headers || {};
args.headers.Authorization = digestAuthHeader(options.method, options.path, authenticate, args.digestAuth);
debug('Request#%d %s: auth with digest header: %s', reqId, url, args.headers.Authorization);
if (res.headers['set-cookie']) {
args.headers.Cookie = res.headers['set-cookie'].join(';');
}
return exports.requestWithCallback(url, args, cb);
}
}
// if (statusCode === 401 && headers['www-authenticate']
// && (!args.headers || !args.headers.Authorization) && args.digestAuth) {
// const authenticate = headers['www-authenticate'];
// if (authenticate.indexOf('Digest ') >= 0) {
// debug('Request#%d %s: got digest auth header WWW-Authenticate: %s', reqId, url, authenticate);
// args.headers = args.headers || {};
// args.headers.Authorization = digestAuthHeader(options.method, options.path, authenticate, args.digestAuth);
// debug('Request#%d %s: auth with digest header: %s', reqId, url, args.headers.Authorization);
// if (res.headers['set-cookie']) {
// args.headers.Cookie = res.headers['set-cookie'].join(';');
// }
// return exports.requestWithCallback(url, args, cb);
// }
// }
var requestUseTime = Date.now() - requestStartTime;
const requestUseTime = Date.now() - requestStartTime;
if (timing) {

@@ -326,3 +331,3 @@ timing.contentDownload = requestUseTime;

var response = {
const response = {
status: statusCode,

@@ -343,3 +348,3 @@ statusCode: statusCode,

if (err) {
var agentStatus = '';
let agentStatus = '';
if (agent && typeof agent.getCurrentStatus === 'function') {

@@ -379,6 +384,6 @@ // add current agent status to error message for logging and debug

function handleRedirect(res) {
var err = null;
let err = null;
if (args.followRedirect && statuses.redirect[res.statusCode]) { // handle redirect
args._followRedirectCount = (args._followRedirectCount || 0) + 1;
var location = res.headers.location;
const location = res.headers.location;
if (!location) {

@@ -391,3 +396,3 @@ err = new Error('Got statusCode ' + res.statusCode + ' but cannot resolve next location from headers');

} else {
var newUrl = args.formatRedirectUrl ? args.formatRedirectUrl(url, location) : urlutil.resolve(url, location);
const newUrl = args.formatRedirectUrl ? args.formatRedirectUrl(url, location) : urlutil.resolve(url, location);
debug('Request#%d %s: `redirected` from %s to %s', reqId, options.path, url, newUrl);

@@ -401,3 +406,3 @@ // make sure timer stop

// avoid done will be execute in the future change.
var cb = callback;
const cb = callback;
callback = null;

@@ -425,3 +430,3 @@ exports.requestWithCallback(newUrl, args, cb);

function decodeContent(res, body, cb) {
var encoding = res.headers['content-encoding'];
const encoding = res.headers['content-encoding'];
// if (body.length === 0) {

@@ -439,3 +444,3 @@ // return cb(null, body, encoding);

var writeStream = args.writeStream;
const writeStream = args.writeStream;

@@ -455,3 +460,3 @@ debug('Request#%d %s %s with headers %j, options.path: %s',

if (args.streaming) {
var result = handleRedirect(res);
const result = handleRedirect(res);
if (result.redirect) {

@@ -502,3 +507,3 @@ res.resume();

// - http://nodejs.org/api/stream.html#stream_event_close_1
var result = handleRedirect(res);
const result = handleRedirect(res);
if (result.redirect) {

@@ -519,10 +524,12 @@ res.resume();

// node 0.10, 0.12: only emit res aborted, writeStream close not fired
if (isNode010 || isNode012) {
first([
[ writeStream, 'close' ],
[ res, 'aborted' ],
], function(_, stream, event) {
debug('Request#%d %s: writeStream or res %s event emitted', reqId, url, event);
done(__err || null, null, res);
});
// if (isNode010 || isNode012) {
// first([
// [ writeStream, 'close' ],
// [ res, 'aborted' ],
// ], function(_, stream, event) {
// debug('Request#%d %s: writeStream or res %s event emitted', reqId, url, event);
// done(__err || null, null, res);
// });
if (false) {
} else {

@@ -551,3 +558,3 @@ writeStream.on('close', function() {

var chunks = [];
const chunks = [];

@@ -561,3 +568,3 @@ res.on('data', function (chunk) {

res.on('end', function () {
var body = Buffer.concat(chunks, responseSize);
const body = Buffer.concat(chunks, responseSize);
debug('Request#%d %s: `res end` event emit, total size %d, _dumped: %s',

@@ -571,3 +578,3 @@ reqId, url, responseSize, res._dumped);

var result = handleRedirect(res);
const result = handleRedirect(res);
if (result.error) {

@@ -599,3 +606,3 @@ return done(result.error, body, res);

} else {
var r = parseJSON(data, fixJSONCtlChars);
const r = parseJSON(data, fixJSONCtlChars);
if (r.error) {

@@ -621,3 +628,3 @@ err = r.error;

var connectTimeout, responseTimeout;
let connectTimeout, responseTimeout;
if (Array.isArray(args.timeout)) {

@@ -638,4 +645,4 @@ connectTimeout = ms(args.timeout[0]);

}
var msg = 'Connect timeout for ' + connectTimeout + 'ms';
var errorName = 'ConnectionTimeoutError';
let msg = 'Connect timeout for ' + connectTimeout + 'ms';
let errorName = 'ConnectionTimeoutError';
if (!req.socket) {

@@ -657,4 +664,4 @@ errorName = 'SocketAssignTimeoutError';

responseTimer = null;
var msg = 'Response timeout for ' + responseTimeout + 'ms';
var errorName = 'ResponseTimeoutError';
const msg = 'Response timeout for ' + responseTimeout + 'ms';
const errorName = 'ResponseTimeoutError';
__err = new Error(msg);

@@ -668,3 +675,3 @@ __err.name = errorName;

var req;
let req;
// request headers checker will throw error

@@ -687,4 +694,4 @@ options.mode = args.mode ? args.mode : '';

}
var msg = 'Connect timeout for ' + connectTimeout + 'ms';
var errorName = 'ConnectionTimeoutError';
const msg = 'Connect timeout for ' + connectTimeout + 'ms';
const errorName = 'ConnectionTimeoutError';
__err = new Error(msg);

@@ -723,7 +730,7 @@ __err.name = errorName;

// should use socket.socket on 0.10.x
if (isNode010 && socket.socket) {
socket = socket.socket;
}
// if (isNode010 && socket.socket) {
// socket = socket.socket;
// }
var readyState = socket.readyState;
const readyState = socket.readyState;
if (readyState === 'opening') {

@@ -805,2 +812,2 @@ socket.once('lookup', function(err, ip, addressType) {

return req;
};
};

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc