Comparing version 7.0.10 to 7.0.11
@@ -1,39 +0,29 @@ | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.S3Error = exports.InvalidXMLError = exports.IncorrectSizeError = exports.InvalidBucketPolicyError = exports.InvalidPrefixError = exports.InvalidDateError = exports.ExpiresParamError = exports.SecretKeyRequiredError = exports.AccessKeyRequiredError = exports.InvalidObjectNameError = exports.InvalidBucketNameError = exports.InvalidEndpointError = exports.InvalidPortError = exports.InvalidArgumentError = exports.AnonymousRequestError = void 0; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _es6Error = _interopRequireDefault(require("es6-error")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
var _es6Error = require('es6-error'); | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var _es6Error2 = _interopRequireDefault(_es6Error); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
// AnonymousRequestError is generated for anonymous keys on specific | ||
// APIs. NOTE: PresignedURL generation always requires access keys. | ||
var AnonymousRequestError = (function (_ExtendableError) { | ||
var AnonymousRequestError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError) { | ||
_inherits(AnonymousRequestError, _ExtendableError); | ||
@@ -44,12 +34,14 @@ | ||
_get(Object.getPrototypeOf(AnonymousRequestError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(AnonymousRequestError).call(this, message)); | ||
} | ||
// InvalidArgumentError is generated for all invalid arguments. | ||
return AnonymousRequestError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidArgumentError is generated for all invalid arguments. | ||
exports.AnonymousRequestError = AnonymousRequestError; | ||
var InvalidArgumentError = (function (_ExtendableError2) { | ||
var InvalidArgumentError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError2) { | ||
_inherits(InvalidArgumentError, _ExtendableError2); | ||
@@ -60,13 +52,15 @@ | ||
_get(Object.getPrototypeOf(InvalidArgumentError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidArgumentError).call(this, message)); | ||
} | ||
// InvalidPortError is generated when a non integer value is provided | ||
// for ports. | ||
return InvalidArgumentError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidPortError is generated when a non integer value is provided | ||
// for ports. | ||
exports.InvalidArgumentError = InvalidArgumentError; | ||
var InvalidPortError = (function (_ExtendableError3) { | ||
var InvalidPortError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError3) { | ||
_inherits(InvalidPortError, _ExtendableError3); | ||
@@ -77,13 +71,15 @@ | ||
_get(Object.getPrototypeOf(InvalidPortError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidPortError).call(this, message)); | ||
} | ||
// InvalidEndpointError is generated when an invalid end point value is | ||
// provided which does not follow domain standards. | ||
return InvalidPortError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidEndpointError is generated when an invalid end point value is | ||
// provided which does not follow domain standards. | ||
exports.InvalidPortError = InvalidPortError; | ||
var InvalidEndpointError = (function (_ExtendableError4) { | ||
var InvalidEndpointError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError4) { | ||
_inherits(InvalidEndpointError, _ExtendableError4); | ||
@@ -94,14 +90,16 @@ | ||
_get(Object.getPrototypeOf(InvalidEndpointError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidEndpointError).call(this, message)); | ||
} | ||
// InvalidBucketNameError is generated when an invalid bucket name is | ||
// provided which does not follow AWS S3 specifications. | ||
// http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html | ||
return InvalidEndpointError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidBucketNameError is generated when an invalid bucket name is | ||
// provided which does not follow AWS S3 specifications. | ||
// http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html | ||
exports.InvalidEndpointError = InvalidEndpointError; | ||
var InvalidBucketNameError = (function (_ExtendableError5) { | ||
var InvalidBucketNameError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError5) { | ||
_inherits(InvalidBucketNameError, _ExtendableError5); | ||
@@ -112,14 +110,16 @@ | ||
_get(Object.getPrototypeOf(InvalidBucketNameError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidBucketNameError).call(this, message)); | ||
} | ||
// InvalidObjectNameError is generated when an invalid object name is | ||
// provided which does not follow AWS S3 specifications. | ||
// http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html | ||
return InvalidBucketNameError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidObjectNameError is generated when an invalid object name is | ||
// provided which does not follow AWS S3 specifications. | ||
// http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html | ||
exports.InvalidBucketNameError = InvalidBucketNameError; | ||
var InvalidObjectNameError = (function (_ExtendableError6) { | ||
var InvalidObjectNameError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError6) { | ||
_inherits(InvalidObjectNameError, _ExtendableError6); | ||
@@ -130,13 +130,15 @@ | ||
_get(Object.getPrototypeOf(InvalidObjectNameError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidObjectNameError).call(this, message)); | ||
} | ||
// AccessKeyRequiredError generated by signature methods when access | ||
// key is not found. | ||
return InvalidObjectNameError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // AccessKeyRequiredError generated by signature methods when access | ||
// key is not found. | ||
exports.InvalidObjectNameError = InvalidObjectNameError; | ||
var AccessKeyRequiredError = (function (_ExtendableError7) { | ||
var AccessKeyRequiredError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError7) { | ||
_inherits(AccessKeyRequiredError, _ExtendableError7); | ||
@@ -147,13 +149,15 @@ | ||
_get(Object.getPrototypeOf(AccessKeyRequiredError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(AccessKeyRequiredError).call(this, message)); | ||
} | ||
// SecretKeyRequiredError generated by signature methods when secret | ||
// key is not found. | ||
return AccessKeyRequiredError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // SecretKeyRequiredError generated by signature methods when secret | ||
// key is not found. | ||
exports.AccessKeyRequiredError = AccessKeyRequiredError; | ||
var SecretKeyRequiredError = (function (_ExtendableError8) { | ||
var SecretKeyRequiredError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError8) { | ||
_inherits(SecretKeyRequiredError, _ExtendableError8); | ||
@@ -164,13 +168,15 @@ | ||
_get(Object.getPrototypeOf(SecretKeyRequiredError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(SecretKeyRequiredError).call(this, message)); | ||
} | ||
// ExpiresParamError generated when expires parameter value is not | ||
// well within stipulated limits. | ||
return SecretKeyRequiredError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // ExpiresParamError generated when expires parameter value is not | ||
// well within stipulated limits. | ||
exports.SecretKeyRequiredError = SecretKeyRequiredError; | ||
var ExpiresParamError = (function (_ExtendableError9) { | ||
var ExpiresParamError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError9) { | ||
_inherits(ExpiresParamError, _ExtendableError9); | ||
@@ -181,12 +187,14 @@ | ||
_get(Object.getPrototypeOf(ExpiresParamError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ExpiresParamError).call(this, message)); | ||
} | ||
// InvalidDateError generated when invalid date is found. | ||
return ExpiresParamError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidDateError generated when invalid date is found. | ||
exports.ExpiresParamError = ExpiresParamError; | ||
var InvalidDateError = (function (_ExtendableError10) { | ||
var InvalidDateError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError10) { | ||
_inherits(InvalidDateError, _ExtendableError10); | ||
@@ -197,13 +205,15 @@ | ||
_get(Object.getPrototypeOf(InvalidDateError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidDateError).call(this, message)); | ||
} | ||
// InvalidPrefixError generated when object prefix provided is invalid | ||
// or does not conform to AWS S3 object key restrictions. | ||
return InvalidDateError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidPrefixError generated when object prefix provided is invalid | ||
// or does not conform to AWS S3 object key restrictions. | ||
exports.InvalidDateError = InvalidDateError; | ||
var InvalidPrefixError = (function (_ExtendableError11) { | ||
var InvalidPrefixError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError11) { | ||
_inherits(InvalidPrefixError, _ExtendableError11); | ||
@@ -214,12 +224,14 @@ | ||
_get(Object.getPrototypeOf(InvalidPrefixError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidPrefixError).call(this, message)); | ||
} | ||
// InvalidBucketPolicyError generated when the given bucket policy is invalid. | ||
return InvalidPrefixError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidBucketPolicyError generated when the given bucket policy is invalid. | ||
exports.InvalidPrefixError = InvalidPrefixError; | ||
var InvalidBucketPolicyError = (function (_ExtendableError12) { | ||
var InvalidBucketPolicyError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError12) { | ||
_inherits(InvalidBucketPolicyError, _ExtendableError12); | ||
@@ -230,13 +242,15 @@ | ||
_get(Object.getPrototypeOf(InvalidBucketPolicyError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidBucketPolicyError).call(this, message)); | ||
} | ||
// IncorrectSizeError generated when total data read mismatches with | ||
// the input size. | ||
return InvalidBucketPolicyError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // IncorrectSizeError generated when total data read mismatches with | ||
// the input size. | ||
exports.InvalidBucketPolicyError = InvalidBucketPolicyError; | ||
var IncorrectSizeError = (function (_ExtendableError13) { | ||
var IncorrectSizeError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError13) { | ||
_inherits(IncorrectSizeError, _ExtendableError13); | ||
@@ -247,12 +261,14 @@ | ||
_get(Object.getPrototypeOf(IncorrectSizeError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(IncorrectSizeError).call(this, message)); | ||
} | ||
// InvalidXMLError generated when an unknown XML is found. | ||
return IncorrectSizeError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // InvalidXMLError generated when an unknown XML is found. | ||
exports.IncorrectSizeError = IncorrectSizeError; | ||
var InvalidXMLError = (function (_ExtendableError14) { | ||
var InvalidXMLError = | ||
/*#__PURE__*/ | ||
function (_ExtendableError14) { | ||
_inherits(InvalidXMLError, _ExtendableError14); | ||
@@ -263,13 +279,15 @@ | ||
_get(Object.getPrototypeOf(InvalidXMLError.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(InvalidXMLError).call(this, message)); | ||
} | ||
// S3Error is generated for errors returned from S3 server. | ||
// see getErrorTransformer for details | ||
return InvalidXMLError; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); // S3Error is generated for errors returned from S3 server. | ||
// see getErrorTransformer for details | ||
exports.InvalidXMLError = InvalidXMLError; | ||
var S3Error = (function (_ExtendableError15) { | ||
var S3Error = | ||
/*#__PURE__*/ | ||
function (_ExtendableError15) { | ||
_inherits(S3Error, _ExtendableError15); | ||
@@ -280,9 +298,9 @@ | ||
_get(Object.getPrototypeOf(S3Error.prototype), 'constructor', this).call(this, message); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(S3Error).call(this, message)); | ||
} | ||
return S3Error; | ||
})(_es6Error2['default']); | ||
}(_es6Error.default); | ||
exports.S3Error = S3Error; | ||
//# sourceMappingURL=errors.js.map |
@@ -1,23 +0,6 @@ | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _slice = Array.prototype.slice; | ||
exports.promisify = promisify; | ||
@@ -56,15 +39,25 @@ exports.uriEscape = uriEscape; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _stream = _interopRequireDefault(require("stream")); | ||
var _stream = require('stream'); | ||
var _mimeTypes = _interopRequireDefault(require("mime-types")); | ||
var _stream2 = _interopRequireDefault(_stream); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _mimeTypes = require('mime-types'); | ||
var _mimeTypes2 = _interopRequireDefault(_mimeTypes); | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// Returns a wrapper function that will promisify a given callback function. | ||
// It will preserve 'this'. | ||
function promisify(fn) { | ||
@@ -75,11 +68,8 @@ return function () { | ||
// If the last argument is a function, assume its the callback. | ||
var callback = arguments[arguments.length - 1]; | ||
var callback = arguments[arguments.length - 1]; // If the callback is given, don't promisify, just pass straight in. | ||
// If the callback is given, don't promisify, just pass straight in. | ||
if (typeof callback === 'function') return fn.apply(this, arguments); | ||
// Otherwise, create a new set of arguments, and wrap | ||
if (typeof callback === 'function') return fn.apply(this, arguments); // Otherwise, create a new set of arguments, and wrap | ||
// it in a promise. | ||
var args = [].concat(_slice.call(arguments)); | ||
var args = Array.prototype.slice.call(arguments); | ||
return new Promise(function (resolve, reject) { | ||
@@ -89,19 +79,17 @@ // Add the callback function. | ||
if (err) return reject(err); | ||
resolve(value); | ||
}); | ||
}); // Call the function with our special adaptor callback added. | ||
// Call the function with our special adaptor callback added. | ||
fn.apply(_this, args); | ||
}); | ||
}; | ||
} | ||
// All characters in string which are NOT unreserved should be percent encoded. | ||
} // All characters in string which are NOT unreserved should be percent encoded. | ||
// Unreserved characers are : ALPHA / DIGIT / "-" / "." / "_" / "~" | ||
// Reference https://tools.ietf.org/html/rfc3986#section-2.2 | ||
function uriEscape(string) { | ||
return string.split('').reduce(function (acc, elem) { | ||
var buf = new Buffer(elem); | ||
var buf = Buffer.from(elem); | ||
if (buf.length === 1) { | ||
@@ -115,8 +103,10 @@ // length 1 indicates that elem is not a unicode character. | ||
} | ||
} | ||
// elem needs encoding - i.e elem should be encoded if it's not unreserved | ||
} // elem needs encoding - i.e elem should be encoded if it's not unreserved | ||
// character or if it's a unicode character. | ||
for (var i = 0; i < buf.length; i++) { | ||
acc = acc + "%" + buf[i].toString(16).toUpperCase(); | ||
} | ||
return acc; | ||
@@ -131,12 +121,9 @@ }, ''); | ||
function getScope(region, date) { | ||
return makeDateShort(date) + '/' + region + '/s3/aws4_request'; | ||
} | ||
return `${makeDateShort(date)}/${region}/s3/aws4_request`; | ||
} // isAmazonEndpoint - true if endpoint is 's3.amazonaws.com' or 's3.cn-north-1.amazonaws.com.cn' | ||
// isAmazonEndpoint - true if endpoint is 's3.amazonaws.com' or 's3.cn-north-1.amazonaws.com.cn' | ||
function isAmazonEndpoint(endpoint) { | ||
return endpoint === 's3.amazonaws.com' || endpoint === 's3.cn-north-1.amazonaws.com.cn'; | ||
} | ||
// isVirtualHostStyle - verify if bucket name is support with virtual | ||
} // isVirtualHostStyle - verify if bucket name is support with virtual | ||
// hosts. bucketNames with periods should be always treated as path | ||
@@ -147,2 +134,3 @@ // style if the protocol is 'https:', this is due to SSL wildcard | ||
function isVirtualHostStyle(endpoint, protocol, bucket) { | ||
@@ -152,2 +140,3 @@ if (protocol === 'https:' && bucket.indexOf('.') > -1) { | ||
} | ||
return isAmazonEndpoint(endpoint); | ||
@@ -160,5 +149,4 @@ } | ||
return ipv4Regex.test(ip); | ||
} | ||
} // isValidEndpoint - true if endpoint is valid domain. | ||
// isValidEndpoint - true if endpoint is valid domain. | ||
@@ -168,29 +156,33 @@ function isValidEndpoint(endpoint) { | ||
return false; | ||
} | ||
// Return true. | ||
} // Return true. | ||
return true; | ||
} | ||
} // isValidDomain - true if input host is a valid domain. | ||
// isValidDomain - true if input host is a valid domain. | ||
function isValidDomain(host) { | ||
if (!isString(host)) return false; | ||
// See RFC 1035, RFC 3696. | ||
if (!isString(host)) return false; // See RFC 1035, RFC 3696. | ||
if (host.length === 0 || host.length > 255) { | ||
return false; | ||
} | ||
// Host cannot start or end with a '-' | ||
} // Host cannot start or end with a '-' | ||
if (host[0] === '-' || host.substr(-1) === '-') { | ||
return false; | ||
} | ||
// Host cannot start or end with a '_' | ||
} // Host cannot start or end with a '_' | ||
if (host[0] === '_' || host.substr(-1) === '_') { | ||
return false; | ||
} | ||
// Host cannot start or end with a '.' | ||
} // Host cannot start or end with a '.' | ||
if (host[0] === '.' || host.substr(-1) === '.') { | ||
return false; | ||
} | ||
var alphaNumerics = '`~!@#$%^&*()+={}[]|\\"\';:><?/'.split(''); | ||
// All non alphanumeric characters are invalid. | ||
var alphaNumerics = '`~!@#$%^&*()+={}[]|\\"\';:><?/'.split(''); // All non alphanumeric characters are invalid. | ||
for (var i in alphaNumerics) { | ||
@@ -200,31 +192,32 @@ if (host.indexOf(alphaNumerics[i]) > -1) { | ||
} | ||
} | ||
// No need to regexp match, since the list is non-exhaustive. | ||
} // No need to regexp match, since the list is non-exhaustive. | ||
// We let it be valid and fail later. | ||
return true; | ||
} | ||
// Probes contentType using file extensions. | ||
} // Probes contentType using file extensions. | ||
// For example: probeContentType('file.png') returns 'image/png'. | ||
function probeContentType(path) { | ||
var contentType = _mimeTypes2['default'].lookup(path); | ||
var contentType = _mimeTypes.default.lookup(path); | ||
if (!contentType) { | ||
contentType = 'application/octet-stream'; | ||
} | ||
return contentType; | ||
} | ||
} // isValidPort - is input port valid. | ||
// isValidPort - is input port valid. | ||
function isValidPort(port) { | ||
// verify if port is a number. | ||
if (!isNumber(port)) return false; | ||
// port cannot be negative. | ||
if (port < 0) return false; | ||
// port '0' is valid and special case return true. | ||
if (!isNumber(port)) return false; // port cannot be negative. | ||
if (port < 0) return false; // port '0' is valid and special case return true. | ||
if (port === 0) return true; | ||
var min_port = 1; | ||
var max_port = 65535; | ||
// Verify if port is in range. | ||
var max_port = 65535; // Verify if port is in range. | ||
return port >= min_port && port <= max_port; | ||
@@ -234,26 +227,28 @@ } | ||
function isValidBucketName(bucket) { | ||
if (!isString(bucket)) return false; | ||
if (!isString(bucket)) return false; // bucket length should be less than and no more than 63 | ||
// characters long. | ||
// bucket length should be less than and no more than 63 | ||
// characters long. | ||
if (bucket.length < 3 || bucket.length > 63) { | ||
return false; | ||
} | ||
// bucket with successive periods is invalid. | ||
} // bucket with successive periods is invalid. | ||
if (bucket.indexOf('..') > -1) { | ||
return false; | ||
} | ||
// bucket cannot have ip address style. | ||
} // bucket cannot have ip address style. | ||
if (bucket.match(/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/)) { | ||
return false; | ||
} | ||
// bucket should begin with alphabet/number and end with alphabet/number, | ||
} // bucket should begin with alphabet/number and end with alphabet/number, | ||
// with alphabet/number/.- in the middle. | ||
if (bucket.match(/^[a-z0-9][a-z0-9.-]+[a-z0-9]$/)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} // check if objectName is a valid object name | ||
// check if objectName is a valid object name | ||
@@ -264,5 +259,4 @@ function isValidObjectName(objectName) { | ||
return true; | ||
} | ||
} // check if prefix is valid | ||
// check if prefix is valid | ||
@@ -273,82 +267,67 @@ function isValidPrefix(prefix) { | ||
return true; | ||
} | ||
} // check if typeof arg number | ||
// check if typeof arg number | ||
function isNumber(arg) { | ||
return typeof arg === 'number'; | ||
} | ||
} // check if typeof arg function | ||
// check if typeof arg function | ||
function isFunction(arg) { | ||
return typeof arg === 'function'; | ||
} | ||
} // check if typeof arg string | ||
// check if typeof arg string | ||
function isString(arg) { | ||
return typeof arg === 'string'; | ||
} | ||
} // check if typeof arg object | ||
// check if typeof arg object | ||
function isObject(arg) { | ||
return typeof arg === 'object' && arg !== null; | ||
} | ||
} // check if object is readable stream | ||
// check if object is readable stream | ||
function isReadableStream(arg) { | ||
return isObject(arg) && isFunction(arg._read); | ||
} | ||
} // check if arg is boolean | ||
// check if arg is boolean | ||
function isBoolean(arg) { | ||
return typeof arg === 'boolean'; | ||
} | ||
} // check if arg is array | ||
// check if arg is array | ||
function isArray(arg) { | ||
return Array.isArray(arg); | ||
} | ||
} // check if arg is a valid date | ||
// check if arg is a valid date | ||
function isValidDate(arg) { | ||
return arg instanceof Date && !isNaN(arg); | ||
} | ||
// Create a Date string with format: | ||
} // Create a Date string with format: | ||
// 'YYYYMMDDTHHmmss' + Z | ||
function makeDateLong(date) { | ||
date = date || new Date(); | ||
date = date || new Date(); // Gives format like: '2017-08-07T16:28:59.889Z' | ||
// Gives format like: '2017-08-07T16:28:59.889Z' | ||
date = date.toISOString(); | ||
return date.substr(0, 4) + date.substr(5, 2) + date.substr(8, 5) + date.substr(14, 2) + date.substr(17, 2) + 'Z'; | ||
} | ||
// Create a Date string with format: | ||
} // Create a Date string with format: | ||
// 'YYYYMMDD' | ||
function makeDateShort(date) { | ||
date = date || new Date(); | ||
date = date || new Date(); // Gives format like: '2017-08-07T16:28:59.889Z' | ||
// Gives format like: '2017-08-07T16:28:59.889Z' | ||
date = date.toISOString(); | ||
return date.substr(0, 4) + date.substr(5, 2) + date.substr(8, 2); | ||
} | ||
// pipesetup sets up pipe() from left to right os streams array | ||
} // pipesetup sets up pipe() from left to right os streams array | ||
// pipesetup will also make sure that error emitted at any of the upstream Stream | ||
// will be emitted at the last stream. This makes error handling simple | ||
function pipesetup() { | ||
for (var _len = arguments.length, streams = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) { | ||
streams[_key] = arguments[_key]; | ||
@@ -363,15 +342,15 @@ } | ||
}); | ||
} | ||
} // return a Readable stream that emits data | ||
// return a Readable stream that emits data | ||
function readableStream(data) { | ||
var s = new _stream2['default'].Readable(); | ||
var s = new _stream.default.Readable(); | ||
s._read = function () {}; | ||
s.push(data); | ||
s.push(null); | ||
return s; | ||
} | ||
} // Process metadata to insert appropriate value to `content-type` attribute | ||
// Process metadata to insert appropriate value to `content-type` attribute | ||
@@ -384,13 +363,14 @@ function insertContentType(metaData, filePath) { | ||
} | ||
} | ||
// if `content-type` attribute is not present in metadata, | ||
} // if `content-type` attribute is not present in metadata, | ||
// then infer it from the extension in filePath | ||
metaData['content-type'] = probeContentType(filePath); | ||
return metaData; | ||
} | ||
} // Function prepends metadata with the appropriate prefix if it is not already on | ||
// Function prepends metadata with the appropriate prefix if it is not already on | ||
function prependXAMZMeta(metaData) { | ||
var newMetadata = Object.assign({}, metaData); | ||
for (var key in metaData) { | ||
@@ -402,6 +382,6 @@ if (!isAmzHeader(key) && !isSupportedHeader(key) && !isStorageclassHeader(key)) { | ||
} | ||
return newMetadata; | ||
} | ||
} // Checks if it is a valid header according to the AmazonS3 API | ||
// Checks if it is a valid header according to the AmazonS3 API | ||
@@ -411,5 +391,4 @@ function isAmzHeader(key) { | ||
return temp.startsWith("x-amz-meta-") || temp === "x-amz-acl" || temp.startsWith("x-amz-server-side-encryption-") || temp === "x-amz-server-side-encryption"; | ||
} | ||
} //Checks if it is a supported Header | ||
//Checks if it is a supported Header | ||
@@ -419,5 +398,4 @@ function isSupportedHeader(key) { | ||
return supported_headers.indexOf(key.toLowerCase()) > -1; | ||
} | ||
} //Checks if it is a storage header | ||
//Checks if it is a storage header | ||
@@ -430,2 +408,3 @@ function isStorageclassHeader(key) { | ||
var newMetadata = {}; | ||
for (var key in metaData) { | ||
@@ -440,4 +419,5 @@ if (isSupportedHeader(key) || isStorageclassHeader(key) || isAmzHeader(key)) { | ||
} | ||
return newMetadata; | ||
} | ||
//# sourceMappingURL=helpers.js.map |
@@ -1,41 +0,32 @@ | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2016 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.NotificationPoller = exports.ObjectReducedRedundancyLostObject = exports.ObjectRemovedDeleteMarkerCreated = exports.ObjectRemovedDelete = exports.ObjectRemovedAll = exports.ObjectCreatedCompleteMultipartUpload = exports.ObjectCreatedCopy = exports.ObjectCreatedPost = exports.ObjectCreatedPut = exports.ObjectCreatedAll = exports.buildARN = exports.CloudFunctionConfig = exports.QueueConfig = exports.TopicConfig = exports.NotificationConfig = void 0; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _events = require("events"); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var transformers = _interopRequireWildcard(require("./transformers")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _helpers = require("./helpers"); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
var _events = require('events'); | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var _transformers = require('./transformers'); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var transformers = _interopRequireWildcard(_transformers); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
var _helpers = require('./helpers'); | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
// Notification config - array of target configs. | ||
@@ -46,4 +37,5 @@ // Target configs can be | ||
// 3. CloudFront (lambda function) | ||
var NotificationConfig = (function () { | ||
var NotificationConfig = | ||
/*#__PURE__*/ | ||
function () { | ||
function NotificationConfig() { | ||
@@ -53,17 +45,19 @@ _classCallCheck(this, NotificationConfig); | ||
// Base class for three supported configs. | ||
_createClass(NotificationConfig, [{ | ||
key: 'add', | ||
key: "add", | ||
value: function add(target) { | ||
var instance = ''; | ||
if (target instanceof TopicConfig) { | ||
instance = 'TopicConfiguration'; | ||
} | ||
if (target instanceof QueueConfig) { | ||
instance = 'QueueConfiguration'; | ||
} | ||
if (target instanceof CloudFunctionConfig) { | ||
instance = 'CloudFunctionConfiguration'; | ||
} | ||
if (!this[instance]) this[instance] = []; | ||
@@ -75,7 +69,10 @@ this[instance].push(target); | ||
return NotificationConfig; | ||
})(); | ||
}(); // Base class for three supported configs. | ||
exports.NotificationConfig = NotificationConfig; | ||
var TargetConfig = (function () { | ||
var TargetConfig = | ||
/*#__PURE__*/ | ||
function () { | ||
function TargetConfig() { | ||
@@ -85,6 +82,4 @@ _classCallCheck(this, TargetConfig); | ||
// 1. Topic (simple notification service) | ||
_createClass(TargetConfig, [{ | ||
key: 'setId', | ||
key: "setId", | ||
value: function setId(id) { | ||
@@ -94,3 +89,3 @@ this.Id = id; | ||
}, { | ||
key: 'addEvent', | ||
key: "addEvent", | ||
value: function addEvent(newevent) { | ||
@@ -101,12 +96,26 @@ if (!this.Event) this.Event = []; | ||
}, { | ||
key: 'addFilterSuffix', | ||
key: "addFilterSuffix", | ||
value: function addFilterSuffix(suffix) { | ||
if (!this.Filter) this.Filter = { S3Key: { FilterRule: [] } }; | ||
this.Filter.S3Key.FilterRule.push({ Name: "suffix", Value: suffix }); | ||
if (!this.Filter) this.Filter = { | ||
S3Key: { | ||
FilterRule: [] | ||
} | ||
}; | ||
this.Filter.S3Key.FilterRule.push({ | ||
Name: "suffix", | ||
Value: suffix | ||
}); | ||
} | ||
}, { | ||
key: 'addFilterPrefix', | ||
key: "addFilterPrefix", | ||
value: function addFilterPrefix(prefix) { | ||
if (!this.Filter) this.Filter = { S3Key: { FilterRule: [] } }; | ||
this.Filter.S3Key.FilterRule.push({ Name: "prefix", Value: prefix }); | ||
if (!this.Filter) this.Filter = { | ||
S3Key: { | ||
FilterRule: [] | ||
} | ||
}; | ||
this.Filter.S3Key.FilterRule.push({ | ||
Name: "prefix", | ||
Value: prefix | ||
}); | ||
} | ||
@@ -116,50 +125,67 @@ }]); | ||
return TargetConfig; | ||
})(); | ||
}(); // 1. Topic (simple notification service) | ||
var TopicConfig = (function (_TargetConfig) { | ||
var TopicConfig = | ||
/*#__PURE__*/ | ||
function (_TargetConfig) { | ||
_inherits(TopicConfig, _TargetConfig); | ||
function TopicConfig(arn) { | ||
var _this; | ||
_classCallCheck(this, TopicConfig); | ||
_get(Object.getPrototypeOf(TopicConfig.prototype), 'constructor', this).call(this); | ||
this.Topic = arn; | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(TopicConfig).call(this)); | ||
_this.Topic = arn; | ||
return _this; | ||
} | ||
// 2. Queue (simple queue service) | ||
return TopicConfig; | ||
})(TargetConfig); | ||
}(TargetConfig); // 2. Queue (simple queue service) | ||
exports.TopicConfig = TopicConfig; | ||
var QueueConfig = (function (_TargetConfig2) { | ||
var QueueConfig = | ||
/*#__PURE__*/ | ||
function (_TargetConfig2) { | ||
_inherits(QueueConfig, _TargetConfig2); | ||
function QueueConfig(arn) { | ||
var _this2; | ||
_classCallCheck(this, QueueConfig); | ||
_get(Object.getPrototypeOf(QueueConfig.prototype), 'constructor', this).call(this); | ||
this.Queue = arn; | ||
_this2 = _possibleConstructorReturn(this, _getPrototypeOf(QueueConfig).call(this)); | ||
_this2.Queue = arn; | ||
return _this2; | ||
} | ||
// 3. CloudFront (lambda function) | ||
return QueueConfig; | ||
})(TargetConfig); | ||
}(TargetConfig); // 3. CloudFront (lambda function) | ||
exports.QueueConfig = QueueConfig; | ||
var CloudFunctionConfig = (function (_TargetConfig3) { | ||
var CloudFunctionConfig = | ||
/*#__PURE__*/ | ||
function (_TargetConfig3) { | ||
_inherits(CloudFunctionConfig, _TargetConfig3); | ||
function CloudFunctionConfig(arn) { | ||
var _this3; | ||
_classCallCheck(this, CloudFunctionConfig); | ||
_get(Object.getPrototypeOf(CloudFunctionConfig.prototype), 'constructor', this).call(this); | ||
this.CloudFunction = arn; | ||
_this3 = _possibleConstructorReturn(this, _getPrototypeOf(CloudFunctionConfig).call(this)); | ||
_this3.CloudFunction = arn; | ||
return _this3; | ||
} | ||
return CloudFunctionConfig; | ||
})(TargetConfig); | ||
}(TargetConfig); | ||
exports.CloudFunctionConfig = CloudFunctionConfig; | ||
var buildARN = function buildARN(partition, service, region, accountId, resource) { | ||
@@ -186,43 +212,42 @@ return "arn:" + partition + ":" + service + ":" + region + ":" + accountId + ":" + resource; | ||
exports.ObjectRemovedDeleteMarkerCreated = ObjectRemovedDeleteMarkerCreated; | ||
var ObjectReducedRedundancyLostObject = "s3:ReducedRedundancyLostObject"; | ||
exports.ObjectReducedRedundancyLostObject = ObjectReducedRedundancyLostObject; | ||
// Poll for notifications, used in #listenBucketNotification. | ||
var ObjectReducedRedundancyLostObject = "s3:ReducedRedundancyLostObject"; // Poll for notifications, used in #listenBucketNotification. | ||
// Listening constitutes repeatedly requesting s3 whether or not any | ||
// changes have occurred. | ||
var NotificationPoller = (function (_EventEmitter) { | ||
exports.ObjectReducedRedundancyLostObject = ObjectReducedRedundancyLostObject; | ||
var NotificationPoller = | ||
/*#__PURE__*/ | ||
function (_EventEmitter) { | ||
_inherits(NotificationPoller, _EventEmitter); | ||
function NotificationPoller(client, bucketName, prefix, suffix, events) { | ||
var _this4; | ||
_classCallCheck(this, NotificationPoller); | ||
_get(Object.getPrototypeOf(NotificationPoller.prototype), 'constructor', this).call(this); | ||
_this4 = _possibleConstructorReturn(this, _getPrototypeOf(NotificationPoller).call(this)); | ||
_this4.client = client; | ||
_this4.bucketName = bucketName; | ||
_this4.prefix = prefix; | ||
_this4.suffix = suffix; | ||
_this4.events = events; | ||
_this4.ending = false; | ||
return _this4; | ||
} // Starts the polling. | ||
this.client = client; | ||
this.bucketName = bucketName; | ||
this.prefix = prefix; | ||
this.suffix = suffix; | ||
this.events = events; | ||
this.ending = false; | ||
} | ||
// Starts the polling. | ||
_createClass(NotificationPoller, [{ | ||
key: 'start', | ||
key: "start", | ||
value: function start() { | ||
var _this = this; | ||
var _this5 = this; | ||
this.ending = false; | ||
process.nextTick(function () { | ||
_this.checkForChanges(); | ||
_this5.checkForChanges(); | ||
}); | ||
} | ||
} // Stops the polling. | ||
// Stops the polling. | ||
}, { | ||
key: 'stop', | ||
key: "stop", | ||
value: function stop() { | ||
@@ -232,19 +257,21 @@ this.ending = true; | ||
}, { | ||
key: 'checkForChanges', | ||
key: "checkForChanges", | ||
value: function checkForChanges() { | ||
var _this2 = this; | ||
var _this6 = this; | ||
// Don't continue if we're looping again but are cancelled. | ||
if (this.ending) return; | ||
var method = 'GET'; | ||
var queries = []; | ||
if (this.prefix) { | ||
var prefix = (0, _helpers.uriEscape)(this.prefix); | ||
queries.push('prefix=' + prefix); | ||
queries.push(`prefix=${prefix}`); | ||
} | ||
if (this.suffix) { | ||
var suffix = (0, _helpers.uriEscape)(this.suffix); | ||
queries.push('suffix=' + suffix); | ||
queries.push(`suffix=${suffix}`); | ||
} | ||
if (this.events) { | ||
@@ -255,11 +282,16 @@ this.events.forEach(function (s3event) { | ||
} | ||
queries.sort(); | ||
var query = ''; | ||
var query = ''; | ||
if (queries.length > 0) { | ||
query = '' + queries.join('&'); | ||
query = `${queries.join('&')}`; | ||
} | ||
this.client.makeRequest({ method: method, bucketName: this.bucketName, query: query }, '', 200, '', true, function (e, response) { | ||
if (e) return _this2.emit('error', e); | ||
this.client.makeRequest({ | ||
method, | ||
bucketName: this.bucketName, | ||
query | ||
}, '', 200, '', true, function (e, response) { | ||
if (e) return _this6.emit('error', e); | ||
var transformer = transformers.getNotificationTransformer(); | ||
@@ -269,19 +301,17 @@ (0, _helpers.pipesetup)(response, transformer).on('data', function (result) { | ||
// handle it after flushing from the JSON parser. | ||
var records = result.Records; | ||
// If null (= no records), change to an empty array. | ||
if (!records) records = []; | ||
var records = result.Records; // If null (= no records), change to an empty array. | ||
// Iterate over the notifications and emit them individually. | ||
if (!records) records = []; // Iterate over the notifications and emit them individually. | ||
records.forEach(function (record) { | ||
_this2.emit('notification', record); | ||
}); | ||
_this6.emit('notification', record); | ||
}); // If we're done, stop. | ||
// If we're done, stop. | ||
if (_this2.ending) response.destroy(); | ||
if (_this6.ending) response.destroy(); | ||
}).on('error', function (e) { | ||
return _this2.emit('error', e); | ||
return _this6.emit('error', e); | ||
}).on('end', function () { | ||
// Do it again, if we haven't cancelled yet. | ||
process.nextTick(function () { | ||
_this2.checkForChanges(); | ||
_this6.checkForChanges(); | ||
}); | ||
@@ -294,5 +324,5 @@ }); | ||
return NotificationPoller; | ||
})(_events.EventEmitter); | ||
}(_events.EventEmitter); | ||
exports.NotificationPoller = NotificationPoller; | ||
//# sourceMappingURL=notification.js.map |
@@ -1,111 +0,102 @@ | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2016 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _stream = require("stream"); | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _crypto = _interopRequireDefault(require("crypto")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var querystring = _interopRequireWildcard(require("querystring")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _stream = require('stream'); | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
var _crypto = require('crypto'); | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
var _querystring = require('querystring'); | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var querystring = _interopRequireWildcard(_querystring); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
// We extend Transform because Writable does not implement ._flush(). | ||
var ObjectUploader = (function (_Transform) { | ||
var ObjectUploader = | ||
/*#__PURE__*/ | ||
function (_Transform) { | ||
_inherits(ObjectUploader, _Transform); | ||
function ObjectUploader(client, bucketName, objectName, partSize, metaData, callback) { | ||
var _this; | ||
_classCallCheck(this, ObjectUploader); | ||
_get(Object.getPrototypeOf(ObjectUploader.prototype), 'constructor', this).call(this); | ||
this.emptyStream = true; | ||
this.client = client; | ||
this.bucketName = bucketName; | ||
this.objectName = objectName; | ||
// The size of each multipart, chunked by BlockStream2. | ||
this.partSize = partSize; | ||
// This is the metadata for the object. | ||
this.metaData = metaData; | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(ObjectUploader).call(this)); | ||
_this.emptyStream = true; | ||
_this.client = client; | ||
_this.bucketName = bucketName; | ||
_this.objectName = objectName; // The size of each multipart, chunked by BlockStream2. | ||
// Call like: callback(error, etag). | ||
this.callback = callback; | ||
_this.partSize = partSize; // This is the metadata for the object. | ||
// We need to keep track of what number chunk/part we're on. This increments | ||
_this.metaData = metaData; // Call like: callback(error, etag). | ||
_this.callback = callback; // We need to keep track of what number chunk/part we're on. This increments | ||
// each time _write() is called. Starts with 1, not 0. | ||
this.partNumber = 1; | ||
// A list of the previously uploaded chunks, for resuming a file upload. This | ||
_this.partNumber = 1; // A list of the previously uploaded chunks, for resuming a file upload. This | ||
// will be null if we aren't resuming an upload. | ||
this.oldParts = null; | ||
// Keep track of the etags for aggregating the chunks together later. Each | ||
_this.oldParts = null; // Keep track of the etags for aggregating the chunks together later. Each | ||
// etag represents a single chunk of the file. | ||
this.etags = []; | ||
// This is for the multipart upload request — if null, we're either not initiated | ||
_this.etags = []; // This is for the multipart upload request — if null, we're either not initiated | ||
// yet or we're flushing in one packet. | ||
this.id = null; | ||
// Handle errors. | ||
this.on('error', function (err) { | ||
_this.id = null; // Handle errors. | ||
_this.on('error', function (err) { | ||
callback(err); | ||
}); | ||
return _this; | ||
} | ||
_createClass(ObjectUploader, [{ | ||
key: '_transform', | ||
key: "_transform", | ||
value: function _transform(chunk, encoding, callback) { | ||
var _this = this; | ||
var _this2 = this; | ||
this.emptyStream = false; | ||
var method = 'PUT'; | ||
var headers = Object.assign({}, this.metaData, { 'Content-Length': chunk.length }); | ||
var md5digest = ''; | ||
var headers = Object.assign({}, this.metaData, { | ||
'Content-Length': chunk.length | ||
}); | ||
var md5digest = ''; // Calculate and set Content-MD5 header if SHA256 is not set. | ||
// This will happen only when there is a secure connection to the s3 server. | ||
// Calculate and set Content-MD5 header if SHA256 is not set. | ||
// This will happen only when there is a secure connection to the s3 server. | ||
if (!this.client.enableSHA256) { | ||
md5digest = _crypto2['default'].createHash('md5').update(chunk).digest(); | ||
md5digest = _crypto.default.createHash('md5').update(chunk).digest(); | ||
headers['Content-MD5'] = md5digest.toString('base64'); | ||
} | ||
// We can flush the object in one packet if it fits in one chunk. This is true | ||
} // We can flush the object in one packet if it fits in one chunk. This is true | ||
// if the chunk size is smaller than the part size, signifying the end of the | ||
// stream. | ||
if (this.partNumber == 1 && chunk.length < this.partSize) { | ||
// PUT the chunk in a single request — use an empty query. | ||
var _options = { | ||
method: method, headers: headers, | ||
method, | ||
headers, | ||
query: '', | ||
@@ -115,48 +106,39 @@ bucketName: this.bucketName, | ||
}; | ||
this.client.makeRequest(_options, chunk, 200, '', true, function (err, response) { | ||
if (err) return callback(err); | ||
var etag = response.headers.etag; | ||
var etag = response.headers.etag; | ||
if (etag) { | ||
etag = etag.replace(/^"/, '').replace(/"$/, ''); | ||
} | ||
} // Ignore the 'data' event so that the stream closes. (nodejs stream requirement) | ||
// Ignore the 'data' event so that the stream closes. (nodejs stream requirement) | ||
response.on('data', function () {}); | ||
// Give the etag back, we're done! | ||
response.on('data', function () {}); // Give the etag back, we're done! | ||
process.nextTick(function () { | ||
_this.callback(null, etag); | ||
}); | ||
_this2.callback(null, etag); | ||
}); // Because we're sure the stream has ended, allow it to flush and end. | ||
// Because we're sure the stream has ended, allow it to flush and end. | ||
callback(); | ||
}); | ||
return; | ||
} | ||
// If we aren't flushing in one packet, we need to initiate the multipart upload, | ||
} // If we aren't flushing in one packet, we need to initiate the multipart upload, | ||
// if it hasn't already been done. The write will be buffered until the upload has been | ||
// initiated. | ||
if (this.id === null) { | ||
this.once('ready', function () { | ||
_this._transform(chunk, encoding, callback); | ||
}); | ||
_this2._transform(chunk, encoding, callback); | ||
}); // Check for an incomplete previous upload. | ||
// Check for an incomplete previous upload. | ||
this.client.findUploadId(this.bucketName, this.objectName, function (err, id) { | ||
if (err) return _this.emit('error', err); | ||
if (err) return _this2.emit('error', err); // If no upload ID exists, initiate a new one. | ||
// If no upload ID exists, initiate a new one. | ||
if (!id) { | ||
_this.client.initiateNewMultipartUpload(_this.bucketName, _this.objectName, _this.metaData, function (err, id) { | ||
_this2.client.initiateNewMultipartUpload(_this2.bucketName, _this2.objectName, _this2.metaData, function (err, id) { | ||
if (err) return callback(err); | ||
_this2.id = id; // We are now ready to accept new chunks — this will flush the buffered chunk. | ||
_this.id = id; | ||
// We are now ready to accept new chunks — this will flush the buffered chunk. | ||
_this.emit('ready'); | ||
_this2.emit('ready'); | ||
}); | ||
@@ -167,37 +149,32 @@ | ||
_this.id = id; | ||
_this2.id = id; // Retrieve the pre-uploaded parts, if we need to resume the upload. | ||
// Retrieve the pre-uploaded parts, if we need to resume the upload. | ||
_this.client.listParts(_this.bucketName, _this.objectName, id, function (err, etags) { | ||
if (err) return _this.emit('error', err); | ||
_this2.client.listParts(_this2.bucketName, _this2.objectName, id, function (err, etags) { | ||
if (err) return _this2.emit('error', err); // It is possible for no parts to be already uploaded. | ||
// It is possible for no parts to be already uploaded. | ||
if (!etags) etags = []; | ||
if (!etags) etags = []; // oldParts will become an object, allowing oldParts[partNumber].etag | ||
// oldParts will become an object, allowing oldParts[partNumber].etag | ||
_this.oldParts = etags.reduce(function (prev, item) { | ||
_this2.oldParts = etags.reduce(function (prev, item) { | ||
if (!prev[item.part]) { | ||
prev[item.part] = item; | ||
} | ||
return prev; | ||
}, {}); | ||
_this.emit('ready'); | ||
_this2.emit('ready'); | ||
}); | ||
}); | ||
return; | ||
} | ||
} // Continue uploading various parts if we have initiated multipart upload. | ||
// Continue uploading various parts if we have initiated multipart upload. | ||
var partNumber = this.partNumber++; | ||
// Check to see if we've already uploaded this chunk. If the hash sums match, | ||
var partNumber = this.partNumber++; // Check to see if we've already uploaded this chunk. If the hash sums match, | ||
// we can skip to the next chunk. | ||
if (this.oldParts) { | ||
var oldPart = this.oldParts[partNumber]; | ||
var oldPart = this.oldParts[partNumber]; //Calulcate the md5 hash, if it has not already been calculated. | ||
//Calulcate the md5 hash, if it has not already been calculated. | ||
if (!md5digest) { | ||
md5digest = _crypto2['default'].createHash('md5').update(chunk).digest(); | ||
md5digest = _crypto.default.createHash('md5').update(chunk).digest(); | ||
} | ||
@@ -207,10 +184,12 @@ | ||
// The md5 matches, the chunk has already been uploaded. | ||
this.etags.push({ part: partNumber, etag: oldPart.etag }); | ||
this.etags.push({ | ||
part: partNumber, | ||
etag: oldPart.etag | ||
}); | ||
callback(); | ||
return; | ||
} | ||
} | ||
} // Write the chunk with an uploader. | ||
// Write the chunk with an uploader. | ||
var query = querystring.stringify({ | ||
@@ -220,19 +199,21 @@ partNumber: partNumber, | ||
}); | ||
var options = { | ||
method: method, query: query, headers: headers, | ||
method, | ||
query, | ||
headers, | ||
bucketName: this.bucketName, | ||
objectName: this.objectName | ||
}; | ||
this.client.makeRequest(options, chunk, 200, '', true, function (err, response) { | ||
if (err) return callback(err); | ||
if (err) return callback(err); // In order to aggregate the parts together, we need to collect the etags. | ||
// In order to aggregate the parts together, we need to collect the etags. | ||
var etag = response.headers.etag; | ||
if (etag) etag = etag.replace(/^"/, '').replace(/"$/, ''); | ||
_this.etags.push({ part: partNumber, etag: etag }); | ||
_this2.etags.push({ | ||
part: partNumber, | ||
etag | ||
}); // We're ready for the next chunk. | ||
// We're ready for the next chunk. | ||
callback(); | ||
@@ -242,11 +223,14 @@ }); | ||
}, { | ||
key: '_flush', | ||
key: "_flush", | ||
value: function _flush(callback) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
if (this.emptyStream) { | ||
var method = 'PUT'; | ||
var headers = Object.assign({}, this.metaData, { 'Content-Length': 0 }); | ||
var headers = Object.assign({}, this.metaData, { | ||
'Content-Length': 0 | ||
}); | ||
var options = { | ||
method: method, headers: headers, | ||
method, | ||
headers, | ||
query: '', | ||
@@ -256,41 +240,36 @@ bucketName: this.bucketName, | ||
}; | ||
this.client.makeRequest(options, '', 200, '', true, function (err, response) { | ||
if (err) return callback(err); | ||
var etag = response.headers.etag; | ||
var etag = response.headers.etag; | ||
if (etag) { | ||
etag = etag.replace(/^"/, '').replace(/"$/, ''); | ||
} | ||
} // Ignore the 'data' event so that the stream closes. (nodejs stream requirement) | ||
// Ignore the 'data' event so that the stream closes. (nodejs stream requirement) | ||
response.on('data', function () {}); | ||
// Give the etag back, we're done! | ||
response.on('data', function () {}); // Give the etag back, we're done! | ||
process.nextTick(function () { | ||
_this2.callback(null, etag); | ||
}); | ||
_this3.callback(null, etag); | ||
}); // Because we're sure the stream has ended, allow it to flush and end. | ||
// Because we're sure the stream has ended, allow it to flush and end. | ||
callback(); | ||
}); | ||
return; | ||
} // If it has been uploaded in a single packet, we don't have to do anything. | ||
return; | ||
} | ||
// If it has been uploaded in a single packet, we don't have to do anything. | ||
if (this.id === null) { | ||
return; | ||
} | ||
} // This is called when all of the chunks uploaded successfully, thus | ||
// completing the multipart upload. | ||
// This is called when all of the chunks uploaded successfully, thus | ||
// completing the multipart upload. | ||
this.client.completeMultipartUpload(this.bucketName, this.objectName, this.id, this.etags, function (err, etag) { | ||
if (err) return callback(err); | ||
if (err) return callback(err); // Call our callback on the next tick to allow the streams infrastructure | ||
// to finish what its doing before we continue. | ||
// Call our callback on the next tick to allow the streams infrastructure | ||
// to finish what its doing before we continue. | ||
process.nextTick(function () { | ||
_this2.callback(null, etag); | ||
_this3.callback(null, etag); | ||
}); | ||
callback(); | ||
@@ -302,6 +281,5 @@ }); | ||
return ObjectUploader; | ||
})(_stream.Transform); | ||
}(_stream.Transform); | ||
exports['default'] = ObjectUploader; | ||
module.exports = exports['default']; | ||
exports.default = ObjectUploader; | ||
//# sourceMappingURL=object-uploader.js.map |
@@ -0,1 +1,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getS3Endpoint = getS3Endpoint; | ||
var _helpers = require("./helpers.js"); | ||
/* | ||
@@ -16,12 +25,2 @@ * MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015, 2016 MinIO, Inc. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.getS3Endpoint = getS3Endpoint; | ||
var _helpersJs = require('./helpers.js'); | ||
// List of currently supported endpoints. | ||
@@ -42,18 +41,20 @@ var awsS3Endpoint = { | ||
'ap-northeast-1': 's3-ap-northeast-1.amazonaws.com', | ||
'cn-north-1': 's3.cn-north-1.amazonaws.com.cn' | ||
// Add new endpoints here. | ||
'cn-north-1': 's3.cn-north-1.amazonaws.com.cn' // Add new endpoints here. | ||
// getS3Endpoint get relevant endpoint for the region. | ||
}; | ||
// getS3Endpoint get relevant endpoint for the region. | ||
function getS3Endpoint(region) { | ||
if (!(0, _helpersJs.isString)(region)) { | ||
throw new TypeError('Invalid region: ' + region); | ||
if (!(0, _helpers.isString)(region)) { | ||
throw new TypeError(`Invalid region: ${region}`); | ||
} | ||
var endpoint = awsS3Endpoint[region]; | ||
if (endpoint) { | ||
return endpoint; | ||
} | ||
return 's3.amazonaws.com'; | ||
} | ||
//# sourceMappingURL=s3-endpoints.js.map |
@@ -0,1 +1,22 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.postPresignSignatureV4 = postPresignSignatureV4; | ||
exports.signV4 = signV4; | ||
exports.presignSignatureV4 = presignSignatureV4; | ||
var _crypto = _interopRequireDefault(require("crypto")); | ||
var _lodash = _interopRequireDefault(require("lodash")); | ||
var _helpers = require("./helpers.js"); | ||
var errors = _interopRequireWildcard(require("./errors.js")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* | ||
@@ -16,33 +37,3 @@ * MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2016 MinIO, Inc. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.postPresignSignatureV4 = postPresignSignatureV4; | ||
exports.signV4 = signV4; | ||
exports.presignSignatureV4 = presignSignatureV4; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _crypto = require('crypto'); | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
var _lodash = require('lodash'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _helpersJs = require('./helpers.js'); | ||
var _errorsJs = require('./errors.js'); | ||
var errors = _interopRequireWildcard(_errorsJs); | ||
var signV4Algorithm = 'AWS4-HMAC-SHA256'; | ||
// getCanonicalRequest generate a canonical request of style. | ||
var signV4Algorithm = 'AWS4-HMAC-SHA256'; // getCanonicalRequest generate a canonical request of style. | ||
// | ||
@@ -57,23 +48,28 @@ // canonicalRequest = | ||
// | ||
function getCanonicalRequest(method, path, headers, signedHeaders, hashedPayload) { | ||
if (!(0, _helpersJs.isString)(method)) { | ||
if (!(0, _helpers.isString)(method)) { | ||
throw new TypeError('method should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(path)) { | ||
if (!(0, _helpers.isString)(path)) { | ||
throw new TypeError('path should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isObject)(headers)) { | ||
if (!(0, _helpers.isObject)(headers)) { | ||
throw new TypeError('headers should be of type "object"'); | ||
} | ||
if (!(0, _helpersJs.isArray)(signedHeaders)) { | ||
if (!(0, _helpers.isArray)(signedHeaders)) { | ||
throw new TypeError('signedHeaders should be of type "array"'); | ||
} | ||
if (!(0, _helpersJs.isString)(hashedPayload)) { | ||
if (!(0, _helpers.isString)(hashedPayload)) { | ||
throw new TypeError('hashedPayload should be of type "string"'); | ||
} | ||
var headersArray = signedHeaders.reduce(function (acc, i) { | ||
acc.push(i.toLowerCase() + ':' + headers[i]); | ||
acc.push(`${i.toLowerCase()}:${headers[i]}`); | ||
return acc; | ||
}, []); | ||
var requestResource = path.split('?')[0]; | ||
@@ -97,24 +93,26 @@ var requestQuery = path.split('?')[1]; | ||
return canonical.join('\n'); | ||
} | ||
} // generate a credential string | ||
// generate a credential string | ||
function getCredential(accessKey, region, requestDate) { | ||
if (!(0, _helpersJs.isString)(accessKey)) { | ||
if (!(0, _helpers.isString)(accessKey)) { | ||
throw new TypeError('accessKey should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(region)) { | ||
if (!(0, _helpers.isString)(region)) { | ||
throw new TypeError('region should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isObject)(requestDate)) { | ||
if (!(0, _helpers.isObject)(requestDate)) { | ||
throw new TypeError('requestDate should be of type "object"'); | ||
} | ||
return accessKey + '/' + (0, _helpersJs.getScope)(region, requestDate); | ||
} | ||
// Returns signed headers array - alphabetically sorted | ||
return `${accessKey}/${(0, _helpers.getScope)(region, requestDate)}`; | ||
} // Returns signed headers array - alphabetically sorted | ||
function getSignedHeaders(headers) { | ||
if (!(0, _helpersJs.isObject)(headers)) { | ||
if (!(0, _helpers.isObject)(headers)) { | ||
throw new TypeError('request should be of type "object"'); | ||
} | ||
// Excerpts from @lsegal - https://github.com/aws/aws-sdk-js/issues/659#issuecomment-120477258 | ||
} // Excerpts from @lsegal - https://github.com/aws/aws-sdk-js/issues/659#issuecomment-120477258 | ||
// | ||
@@ -146,4 +144,5 @@ // User-Agent: | ||
var ignoredHeaders = ['authorization', 'content-length', 'content-type', 'user-agent']; | ||
return _lodash2['default'].map(headers, function (v, header) { | ||
return _lodash.default.map(headers, function (v, header) { | ||
return header; | ||
@@ -153,75 +152,88 @@ }).filter(function (header) { | ||
}).sort(); | ||
} | ||
} // returns the key used for calculating signature | ||
// returns the key used for calculating signature | ||
function getSigningKey(date, region, secretKey) { | ||
if (!(0, _helpersJs.isObject)(date)) { | ||
if (!(0, _helpers.isObject)(date)) { | ||
throw new TypeError('date should be of type "object"'); | ||
} | ||
if (!(0, _helpersJs.isString)(region)) { | ||
if (!(0, _helpers.isString)(region)) { | ||
throw new TypeError('region should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(secretKey)) { | ||
if (!(0, _helpers.isString)(secretKey)) { | ||
throw new TypeError('secretKey should be of type "string"'); | ||
} | ||
var dateLine = (0, _helpersJs.makeDateShort)(date), | ||
hmac1 = _crypto2['default'].createHmac('sha256', 'AWS4' + secretKey).update(dateLine).digest(), | ||
hmac2 = _crypto2['default'].createHmac('sha256', hmac1).update(region).digest(), | ||
hmac3 = _crypto2['default'].createHmac('sha256', hmac2).update('s3').digest(); | ||
return _crypto2['default'].createHmac('sha256', hmac3).update('aws4_request').digest(); | ||
} | ||
// returns the string that needs to be signed | ||
var dateLine = (0, _helpers.makeDateShort)(date), | ||
hmac1 = _crypto.default.createHmac('sha256', 'AWS4' + secretKey).update(dateLine).digest(), | ||
hmac2 = _crypto.default.createHmac('sha256', hmac1).update(region).digest(), | ||
hmac3 = _crypto.default.createHmac('sha256', hmac2).update('s3').digest(); | ||
return _crypto.default.createHmac('sha256', hmac3).update('aws4_request').digest(); | ||
} // returns the string that needs to be signed | ||
function getStringToSign(canonicalRequest, requestDate, region) { | ||
if (!(0, _helpersJs.isString)(canonicalRequest)) { | ||
if (!(0, _helpers.isString)(canonicalRequest)) { | ||
throw new TypeError('canonicalRequest should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isObject)(requestDate)) { | ||
if (!(0, _helpers.isObject)(requestDate)) { | ||
throw new TypeError('requestDate should be of type "object"'); | ||
} | ||
if (!(0, _helpersJs.isString)(region)) { | ||
if (!(0, _helpers.isString)(region)) { | ||
throw new TypeError('region should be of type "string"'); | ||
} | ||
var hash = _crypto2['default'].createHash('sha256').update(canonicalRequest).digest('hex'); | ||
var scope = (0, _helpersJs.getScope)(region, requestDate); | ||
var hash = _crypto.default.createHash('sha256').update(canonicalRequest).digest('hex'); | ||
var scope = (0, _helpers.getScope)(region, requestDate); | ||
var stringToSign = []; | ||
stringToSign.push(signV4Algorithm); | ||
stringToSign.push((0, _helpersJs.makeDateLong)(requestDate)); | ||
stringToSign.push((0, _helpers.makeDateLong)(requestDate)); | ||
stringToSign.push(scope); | ||
stringToSign.push(hash); | ||
return stringToSign.join('\n'); | ||
} | ||
} // calculate the signature of the POST policy | ||
// calculate the signature of the POST policy | ||
function postPresignSignatureV4(region, date, secretKey, policyBase64) { | ||
if (!(0, _helpersJs.isString)(region)) { | ||
if (!(0, _helpers.isString)(region)) { | ||
throw new TypeError('region should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isObject)(date)) { | ||
if (!(0, _helpers.isObject)(date)) { | ||
throw new TypeError('date should be of type "object"'); | ||
} | ||
if (!(0, _helpersJs.isString)(secretKey)) { | ||
if (!(0, _helpers.isString)(secretKey)) { | ||
throw new TypeError('secretKey should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(policyBase64)) { | ||
if (!(0, _helpers.isString)(policyBase64)) { | ||
throw new TypeError('policyBase64 should be of type "string"'); | ||
} | ||
var signingKey = getSigningKey(date, region, secretKey); | ||
return _crypto2['default'].createHmac('sha256', signingKey).update(policyBase64).digest('hex').toLowerCase(); | ||
} | ||
return _crypto.default.createHmac('sha256', signingKey).update(policyBase64).digest('hex').toLowerCase(); | ||
} // Returns the authorization header | ||
// Returns the authorization header | ||
function signV4(request, accessKey, secretKey, region, requestDate) { | ||
if (!(0, _helpersJs.isObject)(request)) { | ||
if (!(0, _helpers.isObject)(request)) { | ||
throw new TypeError('request should be of type "object"'); | ||
} | ||
if (!(0, _helpersJs.isString)(accessKey)) { | ||
if (!(0, _helpers.isString)(accessKey)) { | ||
throw new TypeError('accessKey should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(secretKey)) { | ||
if (!(0, _helpers.isString)(secretKey)) { | ||
throw new TypeError('secretKey should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(region)) { | ||
if (!(0, _helpers.isString)(region)) { | ||
throw new TypeError('region should be of type "string"'); | ||
@@ -233,2 +245,3 @@ } | ||
} | ||
if (!secretKey) { | ||
@@ -239,3 +252,2 @@ throw new errors.SecretKeyRequiredError('secretKey is required for signing'); | ||
var sha256sum = request.headers['x-amz-content-sha256']; | ||
var signedHeaders = getSignedHeaders(request.headers); | ||
@@ -246,20 +258,23 @@ var canonicalRequest = getCanonicalRequest(request.method, request.path, request.headers, signedHeaders, sha256sum); | ||
var credential = getCredential(accessKey, region, requestDate); | ||
var signature = _crypto2['default'].createHmac('sha256', signingKey).update(stringToSign).digest('hex').toLowerCase(); | ||
return signV4Algorithm + ' Credential=' + credential + ', SignedHeaders=' + signedHeaders.join(';').toLowerCase() + ', Signature=' + signature; | ||
} | ||
var signature = _crypto.default.createHmac('sha256', signingKey).update(stringToSign).digest('hex').toLowerCase(); | ||
// returns a presigned URL string | ||
return `${signV4Algorithm} Credential=${credential}, SignedHeaders=${signedHeaders.join(';').toLowerCase()}, Signature=${signature}`; | ||
} // returns a presigned URL string | ||
function presignSignatureV4(request, accessKey, secretKey, region, requestDate, expires) { | ||
if (!(0, _helpersJs.isObject)(request)) { | ||
if (!(0, _helpers.isObject)(request)) { | ||
throw new TypeError('request should be of type "object"'); | ||
} | ||
if (!(0, _helpersJs.isString)(accessKey)) { | ||
if (!(0, _helpers.isString)(accessKey)) { | ||
throw new TypeError('accessKey should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(secretKey)) { | ||
if (!(0, _helpers.isString)(secretKey)) { | ||
throw new TypeError('secretKey should be of type "string"'); | ||
} | ||
if (!(0, _helpersJs.isString)(region)) { | ||
if (!(0, _helpers.isString)(region)) { | ||
throw new TypeError('region should be of type "string"'); | ||
@@ -271,2 +286,3 @@ } | ||
} | ||
if (!secretKey) { | ||
@@ -276,8 +292,10 @@ throw new errors.SecretKeyRequiredError('secretKey is required for presigning'); | ||
if (!(0, _helpersJs.isNumber)(expires)) { | ||
if (!(0, _helpers.isNumber)(expires)) { | ||
throw new TypeError('expires should be of type "number"'); | ||
} | ||
if (expires < 1) { | ||
throw new errors.ExpiresParamError('expires param cannot be less than 1 seconds'); | ||
} | ||
if (expires > 604800) { | ||
@@ -287,16 +305,15 @@ throw new errors.ExpiresParamError('expires param cannot be greater than 7 days'); | ||
var iso8601Date = (0, _helpersJs.makeDateLong)(requestDate); | ||
var iso8601Date = (0, _helpers.makeDateLong)(requestDate); | ||
var signedHeaders = getSignedHeaders(request.headers); | ||
var credential = getCredential(accessKey, region, requestDate); | ||
var hashedPayload = 'UNSIGNED-PAYLOAD'; | ||
var requestQuery = []; | ||
requestQuery.push('X-Amz-Algorithm=' + signV4Algorithm); | ||
requestQuery.push('X-Amz-Credential=' + (0, _helpersJs.uriEscape)(credential)); | ||
requestQuery.push('X-Amz-Date=' + iso8601Date); | ||
requestQuery.push('X-Amz-Expires=' + expires); | ||
requestQuery.push('X-Amz-SignedHeaders=' + (0, _helpersJs.uriEscape)(signedHeaders.join(';').toLowerCase())); | ||
requestQuery.push(`X-Amz-Algorithm=${signV4Algorithm}`); | ||
requestQuery.push(`X-Amz-Credential=${(0, _helpers.uriEscape)(credential)}`); | ||
requestQuery.push(`X-Amz-Date=${iso8601Date}`); | ||
requestQuery.push(`X-Amz-Expires=${expires}`); | ||
requestQuery.push(`X-Amz-SignedHeaders=${(0, _helpers.uriEscape)(signedHeaders.join(';').toLowerCase())}`); | ||
var resource = request.path.split('?')[0]; | ||
var query = request.path.split('?')[1]; | ||
if (query) { | ||
@@ -309,11 +326,11 @@ query = query + '&' + requestQuery.join('&'); | ||
var path = resource + '?' + query; | ||
var canonicalRequest = getCanonicalRequest(request.method, path, request.headers, signedHeaders, hashedPayload); | ||
var stringToSign = getStringToSign(canonicalRequest, requestDate, region); | ||
var signingKey = getSigningKey(requestDate, region, secretKey); | ||
var signature = _crypto2['default'].createHmac('sha256', signingKey).update(stringToSign).digest('hex').toLowerCase(); | ||
var presignedUrl = request.protocol + '//' + request.headers.host + path + ('&X-Amz-Signature=' + signature); | ||
var signature = _crypto.default.createHmac('sha256', signingKey).update(stringToSign).digest('hex').toLowerCase(); | ||
var presignedUrl = request.protocol + '//' + request.headers.host + path + `&X-Amz-Signature=${signature}`; | ||
return presignedUrl; | ||
} | ||
//# sourceMappingURL=signing.js.map |
@@ -1,20 +0,4 @@ | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015, 2016 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
@@ -37,32 +21,35 @@ }); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var xmlParsers = _interopRequireWildcard(require("./xml-parsers.js")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _ = _interopRequireWildcard(require("lodash")); | ||
var _xmlParsersJs = require('./xml-parsers.js'); | ||
var _through = _interopRequireDefault(require("through2")); | ||
var xmlParsers = _interopRequireWildcard(_xmlParsersJs); | ||
var _crypto = _interopRequireDefault(require("crypto")); | ||
var _lodash = require('lodash'); | ||
var _jsonStream = _interopRequireDefault(require("json-stream")); | ||
var _ = _interopRequireWildcard(_lodash); | ||
var _helpers = require("./helpers.js"); | ||
var _through2 = require('through2'); | ||
var errors = _interopRequireWildcard(require("./errors.js")); | ||
var _through22 = _interopRequireDefault(_through2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _crypto = require('crypto'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
var _jsonStream = require('json-stream'); | ||
var _jsonStream2 = _interopRequireDefault(_jsonStream); | ||
var _helpersJs = require('./helpers.js'); | ||
var _errorsJs = require('./errors.js'); | ||
var errors = _interopRequireWildcard(_errorsJs); | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015, 2016 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// getConcater returns a stream that concatenates the input and emits | ||
@@ -72,3 +59,2 @@ // the concatenated output when 'end' has reached. If an optional | ||
// `parser(concatenated_data)` will be emitted. | ||
function getConcater(parser, emitError) { | ||
@@ -78,3 +64,3 @@ var objectMode = false; | ||
if (parser && !(0, _helpersJs.isFunction)(parser)) { | ||
if (parser && !(0, _helpers.isFunction)(parser)) { | ||
throw new TypeError('parser should be of type "function"'); | ||
@@ -87,3 +73,5 @@ } | ||
return (0, _through22['default'])({ objectMode: objectMode }, function (chunk, enc, cb) { | ||
return (0, _through.default)({ | ||
objectMode | ||
}, function (chunk, enc, cb) { | ||
bufs.push(chunk); | ||
@@ -93,7 +81,8 @@ cb(); | ||
if (emitError) { | ||
cb(parser(Buffer.concat(bufs).toString())); | ||
// cb(e) would mean we have to emit 'end' by explicitly calling this.push(null) | ||
cb(parser(Buffer.concat(bufs).toString())); // cb(e) would mean we have to emit 'end' by explicitly calling this.push(null) | ||
this.push(null); | ||
return; | ||
} | ||
if (bufs.length) { | ||
@@ -106,7 +95,7 @@ if (parser) { | ||
} | ||
cb(); | ||
}); | ||
} | ||
} // Generates an Error object depending on http statusCode and XML body | ||
// Generates an Error object depending on http statusCode and XML body | ||
@@ -116,2 +105,3 @@ function getErrorTransformer(response) { | ||
var code, message; | ||
if (statusCode === 301) { | ||
@@ -137,30 +127,34 @@ code = 'MovedPermanently'; | ||
code = 'UnknownError'; | ||
message = '' + statusCode; | ||
message = `${statusCode}`; | ||
} | ||
var headerInfo = {}; | ||
// A value created by S3 compatible server that uniquely identifies | ||
var headerInfo = {}; // A value created by S3 compatible server that uniquely identifies | ||
// the request. | ||
headerInfo.amzRequestid = response.headersSent ? response.getHeader('x-amz-request-id') : null; | ||
// A special token that helps troubleshoot API replies and issues. | ||
headerInfo.amzId2 = response.headersSent ? response.getHeader('x-amz-id-2') : null; | ||
// Region where the bucket is located. This header is returned only | ||
headerInfo.amzRequestid = response.headersSent ? response.getHeader('x-amz-request-id') : null; // A special token that helps troubleshoot API replies and issues. | ||
headerInfo.amzId2 = response.headersSent ? response.getHeader('x-amz-id-2') : null; // Region where the bucket is located. This header is returned only | ||
// in HEAD bucket and ListObjects response. | ||
headerInfo.amzBucketRegion = response.headersSent ? response.getHeader('x-amz-bucket-region') : null; | ||
return getConcater(function (xmlString) { | ||
var getError = function getError() { | ||
// Message should be instantiated for each S3Errors. | ||
var e = new errors.S3Error(message); | ||
// S3 Error code. | ||
var e = new errors.S3Error(message); // S3 Error code. | ||
e.code = code; | ||
_.each(headerInfo, function (value, key) { | ||
e[key] = value; | ||
}); | ||
return e; | ||
}; | ||
if (!xmlString) { | ||
return getError(); | ||
} | ||
var e = undefined; | ||
var e; | ||
try { | ||
@@ -171,14 +165,14 @@ e = xmlParsers.parseError(xmlString, headerInfo); | ||
} | ||
return e; | ||
}, true); | ||
} | ||
} // A through stream that calculates md5sum and sha256sum | ||
// A through stream that calculates md5sum and sha256sum | ||
function getHashSummer(enableSHA256) { | ||
var md5 = _crypto2['default'].createHash('md5'); | ||
var sha256 = _crypto2['default'].createHash('sha256'); | ||
var md5 = _crypto.default.createHash('md5'); | ||
return _through22['default'].obj(function (chunk, enc, cb) { | ||
var sha256 = _crypto.default.createHash('sha256'); | ||
return _through.default.obj(function (chunk, enc, cb) { | ||
if (enableSHA256) { | ||
@@ -189,2 +183,3 @@ sha256.update(chunk); | ||
} | ||
cb(); | ||
@@ -194,2 +189,3 @@ }, function (cb) { | ||
var sha256sum = ''; | ||
if (enableSHA256) { | ||
@@ -200,3 +196,7 @@ sha256sum = sha256.digest('hex'); | ||
} | ||
var hashData = { md5sum: md5sum, sha256sum: sha256sum }; | ||
var hashData = { | ||
md5sum, | ||
sha256sum | ||
}; | ||
this.push(hashData); | ||
@@ -206,73 +206,61 @@ this.push(null); | ||
}); | ||
} | ||
// Following functions return a stream object that parses XML | ||
} // Following functions return a stream object that parses XML | ||
// and emits suitable Javascript objects. | ||
// Parses CopyObject response. | ||
function getCopyObjectTransformer() { | ||
return getConcater(xmlParsers.parseCopyObject); | ||
} | ||
} // Parses listBuckets response. | ||
// Parses listBuckets response. | ||
function getListBucketTransformer() { | ||
return getConcater(xmlParsers.parseListBucket); | ||
} | ||
} // Parses listMultipartUploads response. | ||
// Parses listMultipartUploads response. | ||
function getListMultipartTransformer() { | ||
return getConcater(xmlParsers.parseListMultipart); | ||
} | ||
} // Parses listParts response. | ||
// Parses listParts response. | ||
function getListPartsTransformer() { | ||
return getConcater(xmlParsers.parseListParts); | ||
} | ||
} // Parses initMultipartUpload response. | ||
// Parses initMultipartUpload response. | ||
function getInitiateMultipartTransformer() { | ||
return getConcater(xmlParsers.parseInitiateMultipart); | ||
} | ||
} // Parses listObjects response. | ||
// Parses listObjects response. | ||
function getListObjectsTransformer() { | ||
return getConcater(xmlParsers.parseListObjects); | ||
} | ||
} // Parses listObjects response. | ||
// Parses listObjects response. | ||
function getListObjectsV2Transformer() { | ||
return getConcater(xmlParsers.parseListObjectsV2); | ||
} | ||
} // Parses completeMultipartUpload response. | ||
// Parses completeMultipartUpload response. | ||
function getCompleteMultipartTransformer() { | ||
return getConcater(xmlParsers.parseCompleteMultipart); | ||
} | ||
} // Parses getBucketLocation response. | ||
// Parses getBucketLocation response. | ||
function getBucketRegionTransformer() { | ||
return getConcater(xmlParsers.parseBucketRegion); | ||
} | ||
} // Parses GET/SET BucketNotification response | ||
// Parses GET/SET BucketNotification response | ||
function getBucketNotificationTransformer() { | ||
return getConcater(xmlParsers.parseBucketNotification); | ||
} | ||
} // Parses a notification. | ||
// Parses a notification. | ||
function getNotificationTransformer() { | ||
// This will parse and return each object. | ||
return new _jsonStream2['default'](); | ||
return new _jsonStream.default(); | ||
} | ||
//# sourceMappingURL=transformers.js.map |
@@ -1,20 +0,4 @@ | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
@@ -34,28 +18,39 @@ }); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _xml2js = _interopRequireDefault(require("xml2js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _lodash = _interopRequireDefault(require("lodash")); | ||
var _xml2js = require('xml2js'); | ||
var errors = _interopRequireWildcard(require("./errors.js")); | ||
var _xml2js2 = _interopRequireDefault(_xml2js); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
var _lodash = require('lodash'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
/* | ||
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var options = { | ||
// options passed to xml2js parser | ||
explicitRoot: false, | ||
// return the root node in the resulting object? | ||
ignoreAttrs: true // ignore attributes, only create text nodes | ||
var _errorsJs = require('./errors.js'); | ||
}; | ||
var errors = _interopRequireWildcard(_errorsJs); | ||
var options = { // options passed to xml2js parser | ||
explicitRoot: false, // return the root node in the resulting object? | ||
ignoreAttrs: true }; | ||
// ignore attributes, only create text nodes | ||
var parseXml = function parseXml(xml) { | ||
var result = null; | ||
var error = null; | ||
var parser = new _xml2js2['default'].Parser(options); | ||
var parser = new _xml2js.default.Parser(options); | ||
parser.parseString(xml, function (e, r) { | ||
@@ -69,9 +64,8 @@ error = e; | ||
} | ||
return result; | ||
}; | ||
}; // Parse XML and return information as Javascript types | ||
// parse error XML response | ||
// Parse XML and return information as Javascript types | ||
// parse error XML response | ||
function parseError(xml, headerInfo) { | ||
@@ -81,3 +75,4 @@ var xmlError = {}; | ||
var message; | ||
_lodash2['default'].each(xmlobj, function (n, key) { | ||
_lodash.default.each(xmlobj, function (n, key) { | ||
if (key === 'Message') { | ||
@@ -87,15 +82,19 @@ message = xmlobj[key][0]; | ||
} | ||
xmlError[key.toLowerCase()] = xmlobj[key][0]; | ||
}); | ||
var e = new errors.S3Error(message); | ||
_lodash2['default'].each(xmlError, function (value, key) { | ||
_lodash.default.each(xmlError, function (value, key) { | ||
e[key] = value; | ||
}); | ||
_lodash2['default'].each(headerInfo, function (value, key) { | ||
_lodash.default.each(headerInfo, function (value, key) { | ||
e[key] = value; | ||
}); | ||
return e; | ||
} | ||
} // parse XML response for copy object | ||
// parse XML response for copy object | ||
@@ -110,7 +109,5 @@ function parseCopyObject(xml) { | ||
if (xmlobj.LastModified) result.lastModified = new Date(xmlobj.LastModified[0]); | ||
return result; | ||
} | ||
} // parse XML response for listing in-progress multipart uploads | ||
// parse XML response for listing in-progress multipart uploads | ||
@@ -128,3 +125,5 @@ function parseListMultipart(xml) { | ||
if (xmlobj.CommonPrefixes) xmlobj.CommonPrefixes.forEach(function (prefix) { | ||
result.prefixes.push({ prefix: prefix[0] }); | ||
result.prefixes.push({ | ||
prefix: prefix[0] | ||
}); | ||
}); | ||
@@ -139,5 +138,4 @@ if (xmlobj.Upload) xmlobj.Upload.forEach(function (upload) { | ||
return result; | ||
} | ||
} // parse XML response to list all the owned buckets | ||
// parse XML response to list all the owned buckets | ||
@@ -147,2 +145,3 @@ function parseListBucket(xml) { | ||
var xmlobj = parseXml(xml); | ||
if (xmlobj.Buckets) { | ||
@@ -153,10 +152,13 @@ if (xmlobj.Buckets[0].Bucket) { | ||
var creationDate = new Date(bucket.CreationDate[0]); | ||
result.push({ name: name, creationDate: creationDate }); | ||
result.push({ | ||
name, | ||
creationDate | ||
}); | ||
}); | ||
} | ||
} | ||
return result; | ||
} | ||
} // parse XML response for bucket notification | ||
// parse XML response for bucket notification | ||
@@ -167,7 +169,9 @@ function parseBucketNotification(xml) { | ||
QueueConfiguration: [], | ||
CloudFunctionConfiguration: [] | ||
CloudFunctionConfiguration: [] // Parse the events list | ||
}; | ||
// Parse the events list | ||
var genEvents = function genEvents(events) { | ||
var result = []; | ||
if (events) { | ||
@@ -178,7 +182,10 @@ events.forEach(function (s3event) { | ||
} | ||
return result; | ||
}; | ||
// Parse all filter rules | ||
}; // Parse all filter rules | ||
var genFilterRules = function genFilterRules(filters) { | ||
var result = []; | ||
if (filters && filters[0].S3Key && filters[0].S3Key[0].FilterRule) { | ||
@@ -188,11 +195,14 @@ filters[0].S3Key[0].FilterRule.forEach(function (rule) { | ||
var Value = rule.Value[0]; | ||
result.push({ Name: Name, Value: Value }); | ||
result.push({ | ||
Name, | ||
Value | ||
}); | ||
}); | ||
} | ||
return result; | ||
}; | ||
var xmlobj = parseXml(xml); | ||
var xmlobj = parseXml(xml); // Parse all topic configurations in the xml | ||
// Parse all topic configurations in the xml | ||
if (xmlobj.TopicConfiguration) { | ||
@@ -204,6 +214,12 @@ xmlobj.TopicConfiguration.forEach(function (config) { | ||
var Filter = genFilterRules(config.Filter); | ||
result.TopicConfiguration.push({ Id: Id, Topic: Topic, Event: Event, Filter: Filter }); | ||
result.TopicConfiguration.push({ | ||
Id, | ||
Topic, | ||
Event, | ||
Filter | ||
}); | ||
}); | ||
} | ||
// Parse all topic configurations in the xml | ||
} // Parse all topic configurations in the xml | ||
if (xmlobj.QueueConfiguration) { | ||
@@ -215,6 +231,12 @@ xmlobj.QueueConfiguration.forEach(function (config) { | ||
var Filter = genFilterRules(config.Filter); | ||
result.QueueConfiguration.push({ Id: Id, Queue: Queue, Event: Event, Filter: Filter }); | ||
result.QueueConfiguration.push({ | ||
Id, | ||
Queue, | ||
Event, | ||
Filter | ||
}); | ||
}); | ||
} | ||
// Parse all QueueConfiguration arrays | ||
} // Parse all QueueConfiguration arrays | ||
if (xmlobj.CloudFunctionConfiguration) { | ||
@@ -226,3 +248,8 @@ xmlobj.CloudFunctionConfiguration.forEach(function (config) { | ||
var Filter = genFilterRules(config.Filter); | ||
result.CloudFunctionConfiguration.push({ Id: Id, CloudFunction: CloudFunction, Event: Event, Filter: Filter }); | ||
result.CloudFunctionConfiguration.push({ | ||
Id, | ||
CloudFunction, | ||
Event, | ||
Filter | ||
}); | ||
}); | ||
@@ -232,11 +259,9 @@ } | ||
return result; | ||
} | ||
} // parse XML response for bucket region | ||
// parse XML response for bucket region | ||
function parseBucketRegion(xml) { | ||
return parseXml(xml); | ||
} | ||
} // parse XML response for list parts of an in progress multipart upload | ||
// parse XML response for list parts of an in progress multipart upload | ||
@@ -252,2 +277,3 @@ function parseListParts(xml) { | ||
if (xmlobj.NextPartNumberMarker) result.marker = +xmlobj.NextPartNumberMarker[0]; | ||
if (xmlobj.Part) { | ||
@@ -258,9 +284,13 @@ xmlobj.Part.forEach(function (p) { | ||
var etag = p.ETag[0].replace(/^"/g, '').replace(/"$/g, '').replace(/^"/g, '').replace(/"$/g, '').replace(/^"/g, '').replace(/^"$/g, ''); | ||
result.parts.push({ part: part, lastModified: lastModified, etag: etag }); | ||
result.parts.push({ | ||
part, | ||
lastModified, | ||
etag | ||
}); | ||
}); | ||
} | ||
return result; | ||
} | ||
} // parse XML response when a new multipart upload is initiated | ||
// parse XML response when a new multipart upload is initiated | ||
@@ -271,8 +301,8 @@ function parseInitiateMultipart(xml) { | ||
throw new errors.InvalidXMLError('UploadId missing in XML'); | ||
} | ||
} // parse XML response when a multipart upload is completed | ||
// parse XML response when a multipart upload is completed | ||
function parseCompleteMultipart(xml) { | ||
var xmlobj = parseXml(xml); | ||
if (xmlobj.Location) { | ||
@@ -283,14 +313,21 @@ var location = xmlobj.Location[0]; | ||
var etag = xmlobj.ETag[0].replace(/^"/g, '').replace(/"$/g, '').replace(/^"/g, '').replace(/"$/g, '').replace(/^"/g, '').replace(/^"$/g, ''); | ||
return { | ||
location, | ||
bucket, | ||
key, | ||
etag | ||
}; | ||
} // Complete Multipart can return XML Error after a 200 OK response | ||
return { location: location, bucket: bucket, key: key, etag: etag }; | ||
} | ||
// Complete Multipart can return XML Error after a 200 OK response | ||
if (xmlobj.Code && xmlobj.Message) { | ||
var errCode = xmlobj.Code[0]; | ||
var errMessage = xmlobj.Message[0]; | ||
return { errCode: errCode, errMessage: errMessage }; | ||
return { | ||
errCode, | ||
errMessage | ||
}; | ||
} | ||
} | ||
} // parse XML response for list objects in a bucket | ||
// parse XML response for list objects in a bucket | ||
@@ -305,2 +342,3 @@ function parseListObjects(xml) { | ||
if (xmlobj.IsTruncated && xmlobj.IsTruncated[0] === 'true') result.isTruncated = true; | ||
if (xmlobj.Contents) { | ||
@@ -312,6 +350,12 @@ xmlobj.Contents.forEach(function (content) { | ||
var size = +content.Size[0]; | ||
result.objects.push({ name: name, lastModified: lastModified, etag: etag, size: size }); | ||
result.objects.push({ | ||
name, | ||
lastModified, | ||
etag, | ||
size | ||
}); | ||
nextMarker = name; | ||
}); | ||
} | ||
if (xmlobj.CommonPrefixes) { | ||
@@ -321,12 +365,16 @@ xmlobj.CommonPrefixes.forEach(function (commonPrefix) { | ||
var size = 0; | ||
result.objects.push({ prefix: prefix, size: size }); | ||
result.objects.push({ | ||
prefix, | ||
size | ||
}); | ||
}); | ||
} | ||
if (result.isTruncated) { | ||
result.nextMarker = xmlobj.NextMarker ? xmlobj.NextMarker[0] : nextMarker; | ||
} | ||
return result; | ||
} | ||
} // parse XML response for list objects v2 in a bucket | ||
// parse XML response for list objects v2 in a bucket | ||
@@ -348,5 +396,11 @@ function parseListObjectsV2(xml) { | ||
var size = +content.Size[0]; | ||
result.objects.push({ name: name, lastModified: lastModified, etag: etag, size: size }); | ||
result.objects.push({ | ||
name, | ||
lastModified, | ||
etag, | ||
size | ||
}); | ||
}); | ||
} | ||
if (xmlobj.CommonPrefixes) { | ||
@@ -356,7 +410,11 @@ xmlobj.CommonPrefixes.forEach(function (commonPrefix) { | ||
var size = 0; | ||
result.objects.push({ prefix: prefix, size: size }); | ||
result.objects.push({ | ||
prefix, | ||
size | ||
}); | ||
}); | ||
} | ||
return result; | ||
} | ||
//# sourceMappingURL=xml-parsers.js.map |
{ | ||
"name": "minio", | ||
"version": "7.0.10", | ||
"version": "7.0.11", | ||
"description": "S3 Compatible Cloud Storage client", | ||
@@ -9,4 +9,5 @@ "main": "./dist/main/minio.js", | ||
"test": "gulp test", | ||
"prepublish": "gulp test", | ||
"functional": "gulp functional-test", | ||
"lint": "gulp lint", | ||
"prepublishOnly": "gulp test", | ||
"functional": "gulp functionalTest", | ||
"browserify": "gulp browserify", | ||
@@ -25,3 +26,3 @@ "prepare": "npm run compile" | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
"node": ">= 4" | ||
}, | ||
@@ -35,6 +36,5 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"async": "^1.5.2", | ||
"block-stream2": "^1.0.0", | ||
"concat-stream": "^1.4.8", | ||
"es6-error": "^2.0.2", | ||
"async": "^3.1.0", | ||
"block-stream2": "^2.0.0", | ||
"es6-error": "^4.1.1", | ||
"json-stream": "^1.0.0", | ||
@@ -45,4 +45,3 @@ "lodash": "^4.14.2", | ||
"querystring": "0.2.0", | ||
"through2": "^0.6.5", | ||
"uuid": "^3.1.0", | ||
"through2": "^3.0.1", | ||
"xml": "^1.0.0", | ||
@@ -52,17 +51,19 @@ "xml2js": "^0.4.15" | ||
"devDependencies": { | ||
"browserify": "^12.0.1", | ||
"chai": "^3.5.0", | ||
"eslint": "^4.1.1", | ||
"gulp": "^3.9.0", | ||
"gulp-babel": "^5.2.1", | ||
"gulp-eslint": "^4.0.0", | ||
"gulp-mocha": "^2.1.0", | ||
"gulp-notify": "^2.2.0", | ||
"gulp-sourcemaps": "^1.5.2", | ||
"mocha": "^2.3.2", | ||
"@babel/core": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"babelify": "^10.0.0", | ||
"browserify": "^16.3.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.1.0", | ||
"gulp": "^4.0.2", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-eslint": "^6.0.0", | ||
"gulp-mocha": "^6.0.0", | ||
"gulp-sourcemaps": "^2.6.5", | ||
"mocha": "^6.2.0", | ||
"mocha-steps": "^1.1.0", | ||
"nock": "^2.12.0", | ||
"rewire": "^2.3.3", | ||
"source-map-support": "^0.4.12", | ||
"superagent": "^3.7.0" | ||
"nock": "^10.0.6", | ||
"source-map-support": "^0.5.13", | ||
"superagent": "^5.1.0", | ||
"uuid": "^3.3.2" | ||
}, | ||
@@ -69,0 +70,0 @@ "keywords": [ |
@@ -43,3 +43,3 @@ # 适用于Amazon S3兼容云存储的Minio JavaScript Library [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) | ||
var minioClient = new Minio.Client({ | ||
endPoint: 'play.minio.io', | ||
endPoint: 'play.min.io', | ||
port: 9000, | ||
@@ -56,3 +56,3 @@ useSSL: true, | ||
我们在本示例中使用运行在 [https://play.min.io:9000](https://play.min.io:9000) 上的Minio服务,你可以用这个服务来开发和测试。示例中的访问凭据是公开的。 | ||
我们在本示例中使用运行在 [https://play.min.io](https://play.min.io) 上的Minio服务,你可以用这个服务来开发和测试。示例中的访问凭据是公开的。 | ||
@@ -67,3 +67,3 @@ #### file-uploader.js | ||
var minioClient = new Minio.Client({ | ||
endPoint: 'play.minio.io', | ||
endPoint: 'play.min.io', | ||
port: 9000, | ||
@@ -70,0 +70,0 @@ useSSL: true, |
@@ -51,3 +51,3 @@ # MinIO JavaScript Library for Amazon S3 Compatible Cloud Storage [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) | ||
var minioClient = new Minio.Client({ | ||
endPoint: 'play.minio.io', | ||
endPoint: 'play.min.io', | ||
port: 9000, | ||
@@ -64,3 +64,3 @@ useSSL: true, | ||
We will use the MinIO server running at [https://play.min.io:9000](https://play.min.io:9000) in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public. | ||
We will use the MinIO server running at [https://play.min.io](https://play.min.io) in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public. | ||
@@ -75,3 +75,3 @@ #### file-uploader.js | ||
var minioClient = new Minio.Client({ | ||
endPoint: 'play.minio.io', | ||
endPoint: 'play.min.io', | ||
port: 9000, | ||
@@ -78,0 +78,0 @@ useSSL: true, |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
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
11
1
206867
17
14
4045
+ Addedasync@3.2.6(transitive)
+ Addedblock-stream2@2.1.0(transitive)
+ Addedes6-error@4.1.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedthrough2@3.0.2(transitive)
- Removedconcat-stream@^1.4.8
- Removeduuid@^3.1.0
- Removedasync@1.5.2(transitive)
- Removedblock-stream2@1.1.0(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddefined@1.0.1(transitive)
- Removedes6-error@2.1.1(transitive)
- Removedisarray@0.0.11.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@1.0.342.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@0.10.311.1.1(transitive)
- Removedthrough2@0.6.5(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removeduuid@3.4.0(transitive)
- Removedxtend@4.0.2(transitive)
Updatedasync@^3.1.0
Updatedblock-stream2@^2.0.0
Updatedes6-error@^4.1.1
Updatedthrough2@^3.0.1