Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "s3proxy", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Front AWS S3 with a web server that you control", | ||
"main": "s3proxy.js", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"aws-sdk": "^2.118.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^4.7.0", | ||
"eslint-config-airbnb-base": "^12.0.0", | ||
"eslint-plugin-import": "^2.7.0", | ||
"mocha": "^3.5.3", | ||
@@ -13,7 +18,7 @@ "sinon": "^3.2.1" | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "make -j test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/gmoon/s3front.git" | ||
"url": "git+https://github.com/gmoon/s3proxy.git" | ||
}, | ||
@@ -31,5 +36,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/gmoon/s3front/issues" | ||
"url": "https://github.com/gmoon/s3proxy/issues" | ||
}, | ||
"homepage": "https://github.com/gmoon/s3front#readme" | ||
"homepage": "https://github.com/gmoon/s3proxy#readme" | ||
} |
@@ -1,14 +0,60 @@ | ||
'use strict'; | ||
/* jslint node: true, esversion: 6 */ | ||
const EventEmitter = require('events'); | ||
const AWS = require('aws-sdk'); | ||
module.exports = class s3front extends EventEmitter { | ||
constructor() { | ||
super(); | ||
}; | ||
init() { | ||
this.emit('init'); | ||
} | ||
class UserException extends Error { | ||
constructor(code, message) { | ||
super(message); | ||
this.code = code; | ||
} | ||
} | ||
module.exports = class s3proxy extends EventEmitter { | ||
constructor(p) { | ||
super(); | ||
if (!p) { | ||
throw new UserException('InvalidParameterList', 'constructor parameters are required'); | ||
} | ||
if (!p.bucket) { | ||
throw new UserException('InvalidParameterList', 'bucket parameter is required'); | ||
} | ||
this.bucket = p.bucket; | ||
} | ||
init(done) { | ||
const params = {}; | ||
params.apiVersion = '2006-03-01'; | ||
this.credentials = new AWS.SharedIniFileCredentials(); | ||
AWS.config.credentials = this.credentials; | ||
this.s3 = new AWS.S3(params); | ||
this.s3.headBucket({ Bucket: this.bucket }, (error, data) => { | ||
if (error) { | ||
if (typeof done === 'undefined') { | ||
this.emit('error', error); | ||
} | ||
} else { | ||
this.emit('init', data); | ||
} | ||
if (typeof done === 'function') { done(error, data); } | ||
}); | ||
} | ||
createReadStream(key) { | ||
this.isInitialized(); | ||
const params = { Bucket: this.bucket, Key: s3proxy.stripLeadingSlash(key) }; | ||
const s3request = this.s3.getObject(params); | ||
const s3stream = s3request.createReadStream(); | ||
s3request.on('httpHeaders', (statusCode, headers) => { | ||
s3stream.emit('httpHeaders', statusCode, headers); | ||
}); | ||
return s3stream; | ||
} | ||
isInitialized() { | ||
if (!this.s3) { | ||
const error = new UserException('UninitializedError', 'S3Proxy is uninitialized (call s3proxy.init)'); | ||
throw error; | ||
} | ||
} | ||
static stripLeadingSlash(str) { | ||
return str.replace(/^\/+/, ''); | ||
} | ||
}; | ||
103
test.js
@@ -1,22 +0,89 @@ | ||
var expect = require('chai').expect | ||
, s3proxy = require('./s3proxy.js') | ||
, proxy = new s3proxy(); | ||
/* eslint-env mocha, node, es6 */ | ||
describe('s3front', function() { | ||
describe('constructor', function() { | ||
it('should be an object', function() { | ||
expect(proxy).to.be.an('object'); | ||
const chai = require('chai'); | ||
const S3Proxy = require('./s3proxy.js'); | ||
const { expect } = chai; | ||
describe('s3proxy', () => { | ||
describe('constructor', () => { | ||
it('should return an object', () => { | ||
const proxy = new S3Proxy({ bucket: 'codeassist-repo' }); | ||
expect(proxy).to.be.an('object'); | ||
}); | ||
}); | ||
describe('initialization', () => { | ||
const proxy = new S3Proxy({ bucket: 'codeassist-repo' }); | ||
it('should throw an exception if it is not initialized', (done) => { | ||
try { | ||
proxy.isInitialized(); | ||
} catch (e) { | ||
expect(e.code).to.equal('UninitializedError'); | ||
done(); | ||
} | ||
}); | ||
it("should emit an 'init' event", (done) => { | ||
proxy.on('init', () => { | ||
done(); | ||
}); | ||
}); | ||
describe('initialization', function() { | ||
it("should emit an 'init' event", function(done) { | ||
proxy.on('init', () => { | ||
done(); | ||
}); | ||
proxy.init(); | ||
proxy.init(); | ||
}); | ||
}); | ||
describe('invalid bucket', () => { | ||
let proxy; | ||
beforeEach(() => { | ||
proxy = new S3Proxy({ bucket: '.Bucket.name.cannot.start.with.a.period' }); | ||
}); | ||
it('should return NotFound error via callback', (done) => { | ||
proxy.init((error) => { | ||
expect(error.code).to.equal('NotFound'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should return NotFound error via event emitter', (done) => { | ||
proxy.on('error', (error) => { | ||
expect(error.code).to.equal('NotFound'); | ||
done(); | ||
}); | ||
proxy.init(); | ||
}); | ||
}); | ||
describe('createReadStream error codes', () => { | ||
const proxy = new S3Proxy({ bucket: 'codeassist-repo' }); | ||
before((done) => { | ||
proxy.init(done); | ||
}); | ||
it('should return error code NoSuchKey for nonexistent key', (done) => { | ||
const stream = proxy.createReadStream('small.txt'); | ||
stream.on('error', (error) => { | ||
expect(error.code).to.equal('NoSuchKey'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('createReadStream', () => { | ||
const proxy = new S3Proxy({ bucket: 'codeassist-repo' }); | ||
const page = {}; | ||
before((done) => { | ||
proxy.init(); | ||
const stream = proxy.createReadStream('index.html'); | ||
page.length = 0; | ||
stream.on('data', (chunk) => { | ||
page.length += chunk.length; | ||
}); | ||
stream.on('httpHeaders', (statusCode, headers) => { | ||
page.headers = headers; | ||
page.statusCode = statusCode; | ||
}); | ||
stream.on('end', () => { | ||
done(); | ||
}); | ||
}); | ||
it('should have headers', () => { | ||
expect(page.headers).to.have.keys(['accept-ranges', 'content-length', 'content-type', 'date', 'etag', 'last-modified', 'server', 'x-amz-id-2', 'x-amz-request-id']); | ||
}); | ||
it('should have length of 58', () => { | ||
expect(page.length).to.equal(58); | ||
}); | ||
}); | ||
}); | ||
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
143
7795
1
6
6
2
0
+ Addedaws-sdk@^2.118.0
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedaws-sdk@2.1692.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@4.9.2(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedevents@1.1.1(transitive)
+ Addedfor-each@0.3.5(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedieee754@1.1.13(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.1.0(transitive)
+ Addedis-regex@1.2.1(transitive)
+ Addedis-typed-array@1.1.15(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjmespath@0.16.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedpossible-typed-array-names@1.1.0(transitive)
+ Addedpunycode@1.3.2(transitive)
+ Addedquerystring@0.2.0(transitive)
+ Addedsafe-regex-test@1.1.0(transitive)
+ Addedsax@1.2.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedurl@0.10.3(transitive)
+ Addedutil@0.12.5(transitive)
+ Addeduuid@8.0.0(transitive)
+ Addedwhich-typed-array@1.1.18(transitive)
+ Addedxml2js@0.6.2(transitive)
+ Addedxmlbuilder@11.0.1(transitive)