Comparing version 1.0.0 to 2.0.0
140
API.md
@@ -22,4 +22,2 @@ ## API Documentation | ||
* [`removeBucket`](#removeBucket) | ||
* [`getBucketACL`](#getBucketACL) | ||
* [`setBucketACL`](#setBucketACL) | ||
* [`listObjects`](#listObjects) | ||
@@ -48,3 +46,3 @@ * [`listIncompleteUploads`](#listIncompleteUploads) | ||
<a name="makeBucket"> | ||
#### makeBucket(bucketName, callback) | ||
#### makeBucket(bucketName, 'us-east-1', callback) | ||
Create a new bucket. | ||
@@ -54,3 +52,2 @@ | ||
* `bucketName` _string_ - Name of the bucket. | ||
* `acl` _string_ - cannedACL valid values are _private_, _public-read_, _public-read-write_, _authenticated-read_. | ||
* `region` _string_ - region valid values are _us-west-1_, _us-west-2_, _eu-west-1_, _eu-central-1_, _ap-southeast-1_, _ap-northeast-1_, _ap-southeast-2_, _sa-east-1_ | ||
@@ -61,3 +58,3 @@ * `callback(err)` _function_ - callback function with `err` as the error argument. `err` is null if the bucket is successfully created. | ||
```js | ||
s3Client.makeBucket('mybucket', 'public-read', 'us-west-1', function(err) { | ||
s3Client.makeBucket('mybucket', 'us-west-1', function(err) { | ||
if (err) return console.log('Error creating bucket.') | ||
@@ -76,4 +73,4 @@ console.log('Bucket created successfully in "us-west-1".') | ||
`bucketStream` emits Object with the format: | ||
* `obj.name` _string_ : bucket name | ||
* `obj.creationDate` _Date_: date when bucket was created | ||
* `bucket.name` _string_ : bucket name | ||
* `bucket.creationDate` _Date_: date when bucket was created | ||
@@ -131,40 +128,2 @@ __Example__ | ||
--------------------------------------- | ||
<a name="getBucketACL"> | ||
#### getBucketACL(bucketName, callback) | ||
Get ACL of a bucket. | ||
__Arguments__ | ||
* `bucketName` _string_ : name of the bucket | ||
* `callback(err, acl)` _function_ : `err` is not `null` in case of error. `acl` _string_ is the cannedACL which can have the values _private_, _public-read_, _public-read-write_. | ||
__Example__ | ||
```js | ||
s3Client.getBucketACL('mybucket', function(e, acl) { | ||
if (e) { | ||
return console.log(e) | ||
} | ||
console.log('acl is', acl) | ||
}) | ||
``` | ||
--------------------------------------- | ||
<a name="setBucketACL"> | ||
#### setBucketACL(bucketname, acl, callback) | ||
Set ACL on an existing bucket. | ||
__Arguments__ | ||
* `bucketName` _string_: name of the bucket | ||
* `acl` _string_: acl can be _private_, _public-read_, _public-read-write_ | ||
* `callback(err)` _function_: callback is called with error or `null` | ||
__Example__ | ||
```js | ||
s3Client.setBucketACL('mybucket', 'public-read-write', function(e) { | ||
if (e) { | ||
return console.log(e) | ||
} | ||
console.log('Successfully updated acl.') | ||
}) | ||
``` | ||
--------------------------------------- | ||
<a name="listObjects"> | ||
@@ -181,6 +140,6 @@ #### listObjects(bucketName, prefix, recursive) | ||
* `stream` _Stream_: stream emitting the objects in the bucket, the object is of the format: | ||
* `stat.key` _string_: name of the object | ||
* `stat.size` _number_: size of the object | ||
* `stat.etag` _string_: etag of the object | ||
* `stat.lastModified` _Date_: modified time stamp | ||
* `obj.key` _string_: name of the object | ||
* `obj.size` _number_: size of the object | ||
* `obj.etag` _string_: etag of the object | ||
* `obj.lastModified` _Date_: modified time stamp | ||
@@ -206,5 +165,5 @@ __Example__ | ||
* `stream` _Stream_ : emits objects of the format: | ||
* `object.key` _string_: name of the object | ||
* `object.uploadId` _string_: upload ID of the object | ||
* `object.size` _Integer_: size of the partially uploaded object | ||
* `part.key` _string_: name of the object | ||
* `part.uploadId` _string_: upload ID of the object | ||
* `part.size` _Integer_: size of the partially uploaded object | ||
@@ -287,3 +246,3 @@ __Example__ | ||
<a name="fGetObject"> | ||
#### fGetObject(bucketName, objectName, callback) | ||
#### fGetObject(bucketName, objectName, filePath, callback) | ||
Callback is called with `error` in case of error or `null` in case of success | ||
@@ -345,4 +304,4 @@ | ||
```js | ||
var file = '/tmp/40mbfile' | ||
s3Client.putObject('mybucket', '40mbfile', file, 'application/octet-stream', function(e, etag) { | ||
var buffer = 'Hello World' | ||
s3Client.putObject('mybucket', 'hello-file', buffer, 'application/octet-stream', function(e, etag) { | ||
return console.log(e, etag) // e should be null | ||
@@ -436,3 +395,3 @@ }) | ||
<a name="presignedGetObject"> | ||
#### presignedGetObject(bucketName, objectName, expiry) | ||
#### presignedGetObject(bucketName, objectName, expiry, cb) | ||
Generate a presigned URL for GET. | ||
@@ -444,2 +403,3 @@ | ||
* `expiry` _number_: expiry in seconds. | ||
* `callback(err, presignedUrl)` _function_: callback function is called with non `null` value in case of error. `presignedUrl` will be the URL using which the object can be downloaded using GET request. | ||
@@ -449,3 +409,7 @@ __Example__ | ||
// expires in a day | ||
var presignedUrl = s3Client.presignedGetObject('mybucket', 'photo.jpg', 24*60*60) | ||
var presignedUrl = s3Client.presignedGetObject('mybucket', 'photo.jpg', 24*60*60, function(err, presignedUrl) { | ||
if (err) return console.log(err) | ||
console.log(presignedUrl) | ||
}) | ||
``` | ||
@@ -455,3 +419,3 @@ | ||
<a name="presignedPutObject"> | ||
#### presignedPutObject(bucketName, objectName, expiry) | ||
#### presignedPutObject(bucketName, objectName, expiry, cb) | ||
Generate a presigned URL for PUT. | ||
@@ -466,2 +430,3 @@ <blockquote> | ||
* `expiry` _number_: expiry in seconds | ||
* `callback(err, presignedUrl)` _function_: callback function is called with non `null` value in case of error. `presignedUrl` will be the URL using which the object can be uploaded using PUT request. | ||
@@ -471,3 +436,6 @@ __Example__ | ||
// expires in a day | ||
var presignedUrl = s3Client.presignedPutObject('mybucket', 'photo.jpg', 24*60*60) | ||
var presignedUrl = s3Client.presignedPutObject('mybucket', 'photo.jpg', 24*60*60, function(err, presignedUrl) { | ||
if (err) return console.log(err) | ||
console.log(presignedUrl) | ||
}) | ||
``` | ||
@@ -478,6 +446,9 @@ | ||
#### presignedPostPolicy | ||
presignedPostPolicy we can provide security policy specifying conditions restricting | ||
what you want to allow in the request, such as bucket name where objects can be | ||
uploaded, key name prefixes that you want to allow for the object being created and more. | ||
presignedPostPolicy is used for uploading objects using POST request but it gives more control than presigned-PUT on | ||
what can be uploaded by the clients in the POST request. | ||
We can provide policies specifying conditions restricting what you want to allow in a POST request | ||
such as bucket name where objects can be uploaded, key name prefixes that you want to allow for the | ||
object being created and more, etc. | ||
We need to create our policy first: | ||
@@ -489,5 +460,13 @@ ```js | ||
```js | ||
policy.setBucket('bucketname') | ||
policy.setKey('photo.png') or policy.setKeyStartsWith('keyPrefix') | ||
// Policy restricted only for bucket 'bucketName'. | ||
policy.setBucket('bucketName') | ||
// Policy restricted only for photo.png object. | ||
policy.setKey('photo.png') | ||
or | ||
// Policy restricted for incoming objects with keyPrefix. | ||
policy.setKeyStartsWith('keyPrefix') | ||
var expires = new Date | ||
@@ -502,25 +481,24 @@ expires.setSeconds(24 * 60 * 60 * 10) | ||
// Only allow content size in range 1KB to 1MB. | ||
policy.setContentLength(1024, 1024*1024) | ||
policy.setContentLengthRange(1024, 1024*1024) | ||
``` | ||
Get the POST form key/value object: | ||
Upload using POST. | ||
```js | ||
formData = s3Client.presignedPostPolicy(policy) | ||
``` | ||
s3Client.presignedPostPolicy(policy, function(err, postURL, formData) { | ||
if (err) return console.log(err) | ||
POST your content from the browser using `superagent`: | ||
```js | ||
var req = superagent.post('https://<your-s3-endpoint>/bucketname') | ||
_.each(formData, function(value, key) { | ||
req.field(key, value) | ||
}) | ||
var req = superagent.post(postURL) | ||
_.each(formData, function(value, key) { | ||
req.field(key, value) | ||
}) | ||
// file contents | ||
req.attach('file', '/path/to/photo.jpg', 'photo.jpg') | ||
// file contents | ||
req.attach('file', '/path/to/photo.jpg', 'photo.jpg') | ||
req.end(function(err, res) { | ||
if (err) { | ||
return console.log(err.toString()) | ||
} | ||
console.log('Upload successful.') | ||
req.end(function(err, res) { | ||
if (err) { | ||
return console.log(err.toString()) | ||
} | ||
console.log('Upload successful.') | ||
}) | ||
}) | ||
``` |
@@ -17,28 +17,22 @@ /* | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
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 _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); } } }; | ||
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 ExtendableError = (function (_Error) { | ||
_inherits(ExtendableError, _Error); | ||
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 ExtendableError(message) { | ||
_classCallCheck(this, ExtendableError); | ||
var _es6Error = require('es6-error'); | ||
_get(Object.getPrototypeOf(ExtendableError.prototype), "constructor", this).call(this, message); | ||
this.name = this.constructor.name; | ||
this.message = message; | ||
Error.captureStackTrace(this, this.constructor.name); | ||
} | ||
var _es6Error2 = _interopRequireDefault(_es6Error); | ||
return ExtendableError; | ||
})(Error); | ||
// AnonymousRequestError is generated for anonymous keys on specific | ||
// APIs. NOTE: PresignedURL generation always requires access keys. | ||
@@ -51,7 +45,8 @@ var AnonymousRequestError = (function (_ExtendableError) { | ||
_get(Object.getPrototypeOf(AnonymousRequestError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(AnonymousRequestError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// InvalidArgumentError is generated for all invalid arguments. | ||
return AnonymousRequestError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
@@ -66,7 +61,9 @@ exports.AnonymousRequestError = AnonymousRequestError; | ||
_get(Object.getPrototypeOf(InvalidArgumentError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidArgumentError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// InvalidPortError is generated when a non integer value is provided | ||
// for ports. | ||
return InvalidArgumentError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
@@ -81,23 +78,28 @@ exports.InvalidArgumentError = InvalidArgumentError; | ||
_get(Object.getPrototypeOf(InvalidPortError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidPortError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// InvalidEndpointError is generated when an invalid end point value is | ||
// provided which does not follow domain standards. | ||
return InvalidPortError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.InvalidPortError = InvalidPortError; | ||
var InvalidEndPointError = (function (_ExtendableError4) { | ||
_inherits(InvalidEndPointError, _ExtendableError4); | ||
var InvalidEndpointError = (function (_ExtendableError4) { | ||
_inherits(InvalidEndpointError, _ExtendableError4); | ||
function InvalidEndPointError(message) { | ||
_classCallCheck(this, InvalidEndPointError); | ||
function InvalidEndpointError(message) { | ||
_classCallCheck(this, InvalidEndpointError); | ||
_get(Object.getPrototypeOf(InvalidEndPointError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidEndpointError.prototype), 'constructor', this).call(this, message); | ||
} | ||
return InvalidEndPointError; | ||
})(ExtendableError); | ||
// 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']); | ||
exports.InvalidEndPointError = InvalidEndPointError; | ||
exports.InvalidEndpointError = InvalidEndpointError; | ||
@@ -110,7 +112,10 @@ var InvalidBucketNameError = (function (_ExtendableError5) { | ||
_get(Object.getPrototypeOf(InvalidBucketNameError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidBucketNameError.prototype), 'constructor', this).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; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
@@ -125,7 +130,9 @@ exports.InvalidBucketNameError = InvalidBucketNameError; | ||
_get(Object.getPrototypeOf(InvalidObjectNameError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidObjectNameError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// AccessKeyRequiredError generated by signature methods when access | ||
// key is not found. | ||
return InvalidObjectNameError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
@@ -140,7 +147,9 @@ exports.InvalidObjectNameError = InvalidObjectNameError; | ||
_get(Object.getPrototypeOf(AccessKeyRequiredError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(AccessKeyRequiredError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// SecretKeyRequiredError generated by signature methods when secret | ||
// key is not found. | ||
return AccessKeyRequiredError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
@@ -155,69 +164,45 @@ exports.AccessKeyRequiredError = AccessKeyRequiredError; | ||
_get(Object.getPrototypeOf(SecretKeyRequiredError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(SecretKeyRequiredError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// if neither http not https | ||
// ExpiresParamError generated when expires parameter value is not | ||
// well within stipulated limits. | ||
return SecretKeyRequiredError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.SecretKeyRequiredError = SecretKeyRequiredError; | ||
var InvalidProtocolError = (function (_ExtendableError9) { | ||
_inherits(InvalidProtocolError, _ExtendableError9); | ||
var ExpiresParamError = (function (_ExtendableError9) { | ||
_inherits(ExpiresParamError, _ExtendableError9); | ||
function InvalidProtocolError(message) { | ||
_classCallCheck(this, InvalidProtocolError); | ||
_get(Object.getPrototypeOf(InvalidProtocolError.prototype), "constructor", this).call(this, message); | ||
} | ||
return InvalidProtocolError; | ||
})(ExtendableError); | ||
exports.InvalidProtocolError = InvalidProtocolError; | ||
var ExpiresParamError = (function (_ExtendableError10) { | ||
_inherits(ExpiresParamError, _ExtendableError10); | ||
function ExpiresParamError(message) { | ||
_classCallCheck(this, ExpiresParamError); | ||
_get(Object.getPrototypeOf(ExpiresParamError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(ExpiresParamError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// InvalidDateError generated when invalid date is found. | ||
return ExpiresParamError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.ExpiresParamError = ExpiresParamError; | ||
var InvalidACLError = (function (_ExtendableError11) { | ||
_inherits(InvalidACLError, _ExtendableError11); | ||
var InvalidDateError = (function (_ExtendableError10) { | ||
_inherits(InvalidDateError, _ExtendableError10); | ||
function InvalidACLError(message) { | ||
_classCallCheck(this, InvalidACLError); | ||
_get(Object.getPrototypeOf(InvalidACLError.prototype), "constructor", this).call(this, message); | ||
} | ||
return InvalidACLError; | ||
})(ExtendableError); | ||
exports.InvalidACLError = InvalidACLError; | ||
var InvalidDateError = (function (_ExtendableError12) { | ||
_inherits(InvalidDateError, _ExtendableError12); | ||
function InvalidDateError(message) { | ||
_classCallCheck(this, InvalidDateError); | ||
_get(Object.getPrototypeOf(InvalidDateError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidDateError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// InvalidPrefixError generated when object prefix provided is invalid | ||
// or does not conform to AWS S3 object key restrictions. | ||
return InvalidDateError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.InvalidDateError = InvalidDateError; | ||
var InvalidPrefixError = (function (_ExtendableError13) { | ||
_inherits(InvalidPrefixError, _ExtendableError13); | ||
var InvalidPrefixError = (function (_ExtendableError11) { | ||
_inherits(InvalidPrefixError, _ExtendableError11); | ||
@@ -227,12 +212,14 @@ function InvalidPrefixError(message) { | ||
_get(Object.getPrototypeOf(InvalidPrefixError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidPrefixError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// IncorrectSizeError generated when total data read mismatches with | ||
// the input size. | ||
return InvalidPrefixError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.InvalidPrefixError = InvalidPrefixError; | ||
var IncorrectSizeError = (function (_ExtendableError14) { | ||
_inherits(IncorrectSizeError, _ExtendableError14); | ||
var IncorrectSizeError = (function (_ExtendableError12) { | ||
_inherits(IncorrectSizeError, _ExtendableError12); | ||
@@ -242,12 +229,13 @@ function IncorrectSizeError(message) { | ||
_get(Object.getPrototypeOf(IncorrectSizeError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(IncorrectSizeError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// InvalidXMLError generated when an unknown XML is found. | ||
return IncorrectSizeError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.IncorrectSizeError = IncorrectSizeError; | ||
var InvalidXMLError = (function (_ExtendableError15) { | ||
_inherits(InvalidXMLError, _ExtendableError15); | ||
var InvalidXMLError = (function (_ExtendableError13) { | ||
_inherits(InvalidXMLError, _ExtendableError13); | ||
@@ -257,14 +245,14 @@ function InvalidXMLError(message) { | ||
_get(Object.getPrototypeOf(InvalidXMLError.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(InvalidXMLError.prototype), 'constructor', this).call(this, message); | ||
} | ||
// we throw S3Error instance for errors returned from S3 server | ||
// S3Error is generated for errors returned from S3 server. | ||
// see getErrorTransformer for details | ||
return InvalidXMLError; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.InvalidXMLError = InvalidXMLError; | ||
var S3Error = (function (_ExtendableError16) { | ||
_inherits(S3Error, _ExtendableError16); | ||
var S3Error = (function (_ExtendableError14) { | ||
_inherits(S3Error, _ExtendableError14); | ||
@@ -274,9 +262,9 @@ function S3Error(message) { | ||
_get(Object.getPrototypeOf(S3Error.prototype), "constructor", this).call(this, message); | ||
_get(Object.getPrototypeOf(S3Error.prototype), 'constructor', this).call(this, message); | ||
} | ||
return S3Error; | ||
})(ExtendableError); | ||
})(_es6Error2['default']); | ||
exports.S3Error = S3Error; | ||
//# sourceMappingURL=errors.js.map |
@@ -33,3 +33,2 @@ /* | ||
exports.isValidPrefix = isValidPrefix; | ||
exports.isValidACL = isValidACL; | ||
exports.isNumber = isNumber; | ||
@@ -73,3 +72,3 @@ exports.isFunction = isFunction; | ||
output = output.replace(/[^A-Za-z0-9_.~\-%]+/g, encodeURIComponent); | ||
output = output.replace('%2F', '/'); | ||
output = output.replace(/%2F/g, '/'); | ||
@@ -205,8 +204,2 @@ return output; | ||
// check for allowed ACLs | ||
function isValidACL(acl) { | ||
return acl === 'private' || acl === 'public-read' || acl === 'public-read-write' || acl === 'authenticated-read'; | ||
} | ||
// check if typeof arg number | ||
@@ -213,0 +206,0 @@ |
/* | ||
* Minio Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015 Minio, Inc. | ||
* Minio Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2015, 2016 Minio, Inc. | ||
* | ||
@@ -23,2 +23,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
exports.getS3Endpoint = getS3Endpoint; | ||
var _helpersJs = require('./helpers.js'); | ||
// List of currently supported endpoints. | ||
var awsS3Endpoint = { | ||
@@ -34,5 +38,11 @@ 'us-east-1': 's3.amazonaws.com', | ||
'ap-northeast-1': 's3-ap-northeast-1.amazonaws.com' | ||
// Add new endpoints here. | ||
}; | ||
// getS3Endpoint get relevant endpoint for the region. | ||
function getS3Endpoint(region) { | ||
if (!(0, _helpersJs.isString)(region)) { | ||
throw new TypeError('Invalid region: ' + region); | ||
} | ||
var endpoint = awsS3Endpoint[region]; | ||
@@ -39,0 +49,0 @@ if (endpoint) { |
@@ -0,1 +1,17 @@ | ||
/* | ||
* 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'; | ||
@@ -7,5 +23,4 @@ | ||
exports.getConcater = getConcater; | ||
exports.getDummyTransformer = getDummyTransformer; | ||
exports.getErrorTransformer = getErrorTransformer; | ||
exports.getSizeVerifierTransformer = getSizeVerifierTransformer; | ||
exports.getSizeLimiter = getSizeLimiter; | ||
exports.getHashSummer = getHashSummer; | ||
@@ -15,3 +30,2 @@ exports.getListBucketTransformer = getListBucketTransformer; | ||
exports.getListPartsTransformer = getListPartsTransformer; | ||
exports.getAclTransformer = getAclTransformer; | ||
exports.getInitiateMultipartTransformer = getInitiateMultipartTransformer; | ||
@@ -48,7 +62,6 @@ exports.getListObjectsTransformer = getListObjectsTransformer; | ||
// returns a stream that concatenates the input and emits the | ||
// concatenated output when 'End' is reached. | ||
// If an optional parser function is passed, on reaching the | ||
// 'End' of the stream, parser(concatenated_data) will be | ||
// emitted | ||
// getConcater returns a stream that concatenates the input and emits | ||
// the concatenated output when 'end' has reached. If an optional | ||
// parser function is passed upon reaching the 'end' of the stream, | ||
// `parser(concatenated_data)` will be emitted. | ||
@@ -73,3 +86,3 @@ function getConcater(parser, emitError) { | ||
cb(parser(Buffer.concat(bufs).toString())); | ||
// cb(e) would mean we have to emit 'End' by explicitly calling this.push(null) | ||
// cb(e) would mean we have to emit 'end' by explicitly calling this.push(null) | ||
this.push(null); | ||
@@ -89,59 +102,62 @@ return; | ||
// dummy through stream | ||
// Generates an Error object depending on http statusCode and XML body | ||
function getDummyTransformer() { | ||
return _through22['default'].obj(function (chunk, enc, cb) { | ||
return cb(null, chunk); | ||
}); | ||
} | ||
// generates an Error object depending on statusCode and XML body | ||
function getErrorTransformer(response) { | ||
var e = new errors.S3Error(); | ||
var statusCode = response.statusCode; | ||
// A value created by S3 compatible server that uniquely identifies | ||
// the request. | ||
e.amzRequestId = response.headersSent ? response.getHeader('x-amz-request-id') : null; | ||
// A special token that helps troubleshoot API replies and issues. | ||
e.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. | ||
e.amzBucketRegion = response.headersSent ? response.getHeader('x-amz-bucket-region') : null; | ||
var code, message; | ||
if (statusCode === 301) { | ||
e.name = 'MovedPermanently'; | ||
e.message = 'Moved Permanently'; | ||
code = 'MovedPermanently'; | ||
message = 'Moved Permanently'; | ||
} else if (statusCode === 307) { | ||
e.name = 'TemporaryRedirect'; | ||
e.message = 'Are you using the correct endpoint URL?'; | ||
code = 'TemporaryRedirect'; | ||
message = 'Are you using the correct endpoint URL?'; | ||
} else if (statusCode === 403) { | ||
e.name = 'AccessDenied'; | ||
e.message = 'Valid and authorized credentials required'; | ||
code = 'AccessDenied'; | ||
message = 'Valid and authorized credentials required'; | ||
} else if (statusCode === 404) { | ||
e.name = 'NotFound'; | ||
e.message = 'Not Found'; | ||
code = 'NotFound'; | ||
message = 'Not Found'; | ||
} else if (statusCode === 405) { | ||
e.name = 'MethodNotAllowed'; | ||
e.message = 'Method Not Allowed'; | ||
code = 'MethodNotAllowed'; | ||
message = 'Method Not Allowed'; | ||
} else if (statusCode === 501) { | ||
e.name = 'MethodNotAllowed'; | ||
e.message = 'Method Not Allowed'; | ||
code = 'MethodNotAllowed'; | ||
message = 'Method Not Allowed'; | ||
} else { | ||
e.name = 'UnknownError'; | ||
e.message = '' + statusCode; | ||
code = 'UnknownError'; | ||
message = '' + statusCode; | ||
} | ||
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 | ||
// in HEAD bucket and ListObjects response. | ||
headerInfo.amzBucketRegion = response.headersSent ? response.getHeader('x-amz-bucket-region') : null; | ||
return getConcater(function (xmlString) { | ||
if (!xmlString) return e; | ||
return _.merge(e, xmlParsers.parseError(xmlString)); | ||
if (!xmlString) { | ||
// Message should be instantiated for each S3Errors. | ||
var e = new errors.S3Error(message); | ||
// S3 Error code. | ||
e.code = code; | ||
_.each(headerInfo, function (value, key) { | ||
e[key] = value; | ||
}); | ||
return e; | ||
} | ||
return xmlParsers.parseError(xmlString, headerInfo); | ||
}, true); | ||
} | ||
// makes sure that only size number of bytes go through this stream | ||
// Makes sure that only size number of bytes go through this stream | ||
function getSizeVerifierTransformer(size, stream, chunker) { | ||
function getSizeLimiter(size, stream, chunker) { | ||
var sizeRemaining = size; | ||
return _through22['default'].obj(function (chunk, enc, cb) { | ||
var length = Math.min(chunk.length, sizeRemaining); | ||
// we should read only till 'size' | ||
// We should read only till 'size' | ||
if (length < chunk.length) chunk = chunk.slice(0, length); | ||
@@ -151,3 +167,3 @@ this.push(chunk); | ||
if (sizeRemaining === 0) { | ||
// unpipe so that the streams do not send us more data | ||
// Unpipe so that the streams do not send us more data | ||
stream.unpipe(); | ||
@@ -160,3 +176,3 @@ chunker.unpipe(); | ||
if (sizeRemaining !== 0) { | ||
return cb(new errors.IncorrectSizeError('size of the input stream is not equal to the expected size(${size})')); | ||
return cb(new errors.IncorrectSizeError('size of the input stream is not equal to the expected size(' + size + ')')); | ||
} | ||
@@ -168,3 +184,3 @@ this.push(null); | ||
// a through stream that calculates md5sum and sha256sum | ||
// A through stream that calculates md5sum and sha256sum | ||
@@ -188,5 +204,7 @@ function getHashSummer(anonymous) { | ||
// following functions return a stream object that parses XML | ||
// and emits suitable Javascript objects | ||
// Following functions return a stream object that parses XML | ||
// and emits suitable Javascript objects. | ||
// Parses listBuckets response. | ||
function getListBucketTransformer() { | ||
@@ -196,2 +214,4 @@ return getConcater(xmlParsers.parseListBucket); | ||
// Parses listMultipartUploads response. | ||
function getListMultipartTransformer() { | ||
@@ -201,2 +221,4 @@ return getConcater(xmlParsers.parseListMultipart); | ||
// Parses listParts response. | ||
function getListPartsTransformer() { | ||
@@ -206,5 +228,3 @@ return getConcater(xmlParsers.parseListParts); | ||
function getAclTransformer() { | ||
return getConcater(xmlParsers.parseAcl); | ||
} | ||
// Parses initMultipartUpload response. | ||
@@ -215,2 +235,4 @@ function getInitiateMultipartTransformer() { | ||
// Parses listObjects response. | ||
function getListObjectsTransformer() { | ||
@@ -220,2 +242,4 @@ return getConcater(xmlParsers.parseListObjects); | ||
// Parses completeMultipartUpload response. | ||
function getCompleteMultipartTransformer() { | ||
@@ -225,2 +249,4 @@ return getConcater(xmlParsers.parseCompleteMultipart); | ||
// Parses getBucketLocation response. | ||
function getBucketRegionTransformer() { | ||
@@ -227,0 +253,0 @@ return getConcater(xmlParsers.parseBucketRegion); |
@@ -25,3 +25,2 @@ /* | ||
exports.parseListBucket = parseListBucket; | ||
exports.parseAcl = parseAcl; | ||
exports.parseBucketRegion = parseBucketRegion; | ||
@@ -82,16 +81,20 @@ exports.parseListParts = parseListParts; | ||
function parseError(xml) { | ||
var e = {}; | ||
function parseError(xml, headerInfo) { | ||
var xmlError = {}; | ||
var xmlobj = parseXml(xml); | ||
var message; | ||
_lodash2['default'].each(xmlobj, function (n, key) { | ||
if (key === 'Code') { | ||
e.name = xmlobj[key][0]; | ||
return; | ||
} | ||
if (key === 'Message') { | ||
e.message = xmlobj[key][0]; | ||
message = xmlobj[key][0]; | ||
return; | ||
} | ||
e[key] = xmlobj[key][0]; | ||
xmlError[key.toLowerCase()] = xmlobj[key][0]; | ||
}); | ||
var e = new errors.S3Error(message); | ||
_lodash2['default'].each(xmlError, function (value, key) { | ||
e[key] = value; | ||
}); | ||
_lodash2['default'].each(headerInfo, function (value, key) { | ||
e[key] = value; | ||
}); | ||
return e; | ||
@@ -142,41 +145,2 @@ } | ||
// parse XML response for bucket ACL | ||
function parseAcl(xml) { | ||
var result = { | ||
owner: undefined, | ||
acl: [] | ||
}; | ||
var xmlobj = parseXml(xml); | ||
if (xmlobj.Owner) { | ||
var ownerObj = {}; | ||
if (xmlobj.Owner[0].ID) ownerObj.id = xmlobj.Owner[0].ID[0]; | ||
if (xmlobj.Owner[0].DisplayName) ownerObj.displayName = xmlobj.Owner[0].DisplayName[0]; | ||
result.owner = ownerObj; | ||
} | ||
if (xmlobj.AccessControlList) { | ||
if (xmlobj.AccessControlList[0].Grant) { | ||
xmlobj.AccessControlList[0].Grant.forEach(function (grant) { | ||
var grantObj = {}; | ||
if (grant.Grantee) { | ||
var granteeObj = {}; | ||
if (grant.Grantee[0].ID) granteeObj.id = grant.Grantee[0].ID[0]; | ||
if (grant.Grantee[0].DisplayName) granteeObj.displayName = grant.Grantee[0].DisplayName[0]; | ||
if (grant.Grantee[0].URI) granteeObj.uri = grant.Grantee[0].URI[0]; | ||
grantObj.grantee = granteeObj; | ||
if (grant.Permission) grantObj.permission = grant.Permission[0]; | ||
if (!granteeObj.uri && !granteeObj.id) { | ||
throw new errors.InvalidXMLError('Grantee should have either ID or URI'); | ||
} | ||
if (!grantObj.permission) { | ||
throw new errors.InvalidXMLError('Grant permission not set'); | ||
} | ||
} | ||
result.acl.push(grantObj); | ||
}); | ||
} | ||
} | ||
return result; | ||
} | ||
// parse XML response for bucket region | ||
@@ -258,3 +222,3 @@ | ||
if (result.isTruncated) { | ||
result.nextMarker = xmlobj.NextMarker ? res.ListBucketResult.NextMarker[0] : nextMarker; | ||
result.nextMarker = xmlobj.NextMarker ? xmlobj.NextMarker[0] : nextMarker; | ||
} | ||
@@ -261,0 +225,0 @@ return result; |
@@ -28,3 +28,3 @@ /* | ||
// Create a bucket name my-bucketname. | ||
s3Client.makeBucket('my-bucketname', 'public-read', 'us-west-1', function(e) { | ||
s3Client.makeBucket('my-bucketname', 'us-west-1', function(e) { | ||
if (e) { | ||
@@ -31,0 +31,0 @@ return console.log(e) |
@@ -26,5 +26,6 @@ /* | ||
secretKey: 'YOUR-SECRETACCESSKEY', | ||
insecure: false // Default is false. | ||
secure: true // Default is true. | ||
}) | ||
// Presigned get object URL for object name my-bucketname, it expires in 7 days by default. | ||
// Presigned get object URL for my-objectname at my-bucketname, it expires in 7 days by default. | ||
var presignedUrl = s3Client.presignedGetObject('my-bucketname', 'my-objectname', 1000, function(e, presignedUrl) { | ||
@@ -31,0 +32,0 @@ if (e) return console.log(e) |
@@ -26,3 +26,3 @@ /* | ||
secretKey: 'YOUR-SECRETACCESSKEY', | ||
insecure: false // Default is false. | ||
secure: true // Default is true. | ||
}) | ||
@@ -41,8 +41,8 @@ | ||
policy.setContentLength(1024, 1024*1024) // Min upload length is 1KB Max upload size is 1MB | ||
policy.setContentLengthRange(1024, 1024*1024) // Min upload length is 1KB Max upload size is 1MB | ||
s3Client.presignedPostPolicy(policy, function(e, formData) { | ||
s3Client.presignedPostPolicy(policy, function(e, urlStr, formData) { | ||
if (e) return console.log(e) | ||
var curl = [] | ||
curl.push('curl https://s3.amazonaws.com/my-bucketname') | ||
curl.push(`curl ${urlStr}`) | ||
for (var key in formData) { | ||
@@ -49,0 +49,0 @@ if (formData.hasOwnProperty(key)) { |
@@ -26,3 +26,3 @@ /* | ||
secretKey: 'YOUR-SECRETACCESSKEY', | ||
insecure: false // Default is false. | ||
secure: true // Default is true. | ||
}) | ||
@@ -29,0 +29,0 @@ |
{ | ||
"name": "minio", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "S3 Compatible Cloud Storage client", | ||
@@ -33,2 +33,3 @@ "main": "./dist/main/minio.js", | ||
"concat-stream": "^1.4.8", | ||
"es6-error": "^2.0.2", | ||
"lodash": "^3.10.1", | ||
@@ -35,0 +36,0 @@ "mkdirp": "^0.5.1", |
@@ -1,2 +0,2 @@ | ||
# Minio Javascript Library for Amazon S3 Compatible Cloud Storage [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
# Minio JavaScript Library for Amazon S3 Compatible Cloud Storage [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -27,3 +27,3 @@ [![NPM](https://nodei.co/npm/minio.png)](https://nodei.co/npm/minio/) | ||
var s3client = new Minio({ | ||
var s3Client = new Minio({ | ||
endPoint: 's3.amazonaws.com', | ||
@@ -34,3 +34,3 @@ accessKey: 'YOUR-ACCESSKEYID', | ||
s3client.listBuckets(function(e, bucketStream) { | ||
s3Client.listBuckets(function(e, bucketStream) { | ||
if (e) { | ||
@@ -82,3 +82,3 @@ console.log(e) | ||
[API](API.md) | ||
[API documentation](API.md) | ||
@@ -89,3 +89,3 @@ ## Examples | ||
[makeBucket(bucket, acl, region, cb)](examples/make-bucket.js) | ||
[makeBucket(bucket, region, cb)](examples/make-bucket.js) | ||
@@ -98,6 +98,2 @@ [listBuckets() : Stream](examples/list-buckets.js) | ||
[getBucketACL(bucket, cb)](examples/get-bucket-acl.js) | ||
[setBucketACL(bucket, acl, cb)](examples/set-bucket-acl.js) | ||
[listObjects(bucket, prefix, recursive) : Stream](examples/list-objects.js) | ||
@@ -126,7 +122,7 @@ | ||
[presignedGetObject(bucket, object, expires) : String](examples/presigned-getobject.js) | ||
[presignedGetObject(bucket, object, expires, cb)](examples/presigned-getobject.js) | ||
[presignedPutObject(bucket, object, expires) : String](examples/presigned-putobject.js) | ||
[presignedPutObject(bucket, object, expires, cb](examples/presigned-putobject.js) | ||
[presignedPostPolicy(postPolicy) : Object](examples/presigned-postpolicy.js) | ||
[presignedPostPolicy(postPolicy, cb)](examples/presigned-postpolicy.js) | ||
@@ -133,0 +129,0 @@ ## Contribute |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2307315
47
55837
11
129
5
5
+ Addedes6-error@^2.0.2
+ Addedes6-error@2.1.1(transitive)