Skip to content

Commit

Permalink
Merge pull request #8 from erikdesjardins/update
Browse files Browse the repository at this point in the history
Update deps, tested node versions
  • Loading branch information
erikdesjardins committed Feb 13, 2017
2 parents 12d5dc9 + c9f803f commit 7412daf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "5"
- "4"
- "0.12"
- 7
- 6
- 4
branches:
only:
- master
Expand All @@ -18,4 +18,4 @@ deploy:
secure: gtuRmfAX4KGvusBEG/M+UiwBnuAYENPuxobPUEYVCWIYur3Qmn4mKMJSqSdJlrOZ+C55bv3ijTi5ATlxXypuuXSyckhLWs3HGvTe+meml7GfWhOdFxSUo/y8ZdSYt7oKDh0Bys/7o90VPN0ZBkFCqhJlr8MfB8KUmGyXf4E8Y8x8cEIrOH83rzQx6T+132XLlJT75I8LLjLeufEuNQ2dMh5L2Mw1jUqlGsV7bodwE+LVJ0gXAn8gJb7T9XH3a70svdwadgX2Ov9c0+GMvnEAnOB1UU8RSO2xTQjoxXTG3G+t2wMHGGXZvy5WpPhTNo19lB5QY2ZjZVSPA5gsBIZiknnXnuZiP9tBx3P5A0IjXi2RdbflT9l6RzN5t//szAwXkCYqscAbd3SgWQGV9yKHbCM+WIUKYf548qaY70HS0fE2FpkSphKgXqnmEgCpPVwUf8yS0qc9qRtPFpFQoffhbaLtqvNaTWX85GCiVcDNTi0k5d+ADzrXkCZC8t++EPXCSHyHNmE+RbTRu2oybpU4P+Wk7SakB0fz2130B91jsjr7DXu5EFcgQTCJy2dxLLPTlg4crMzFHw+k3p57rO2yRPaFGqBALGzkViL8bi85Zr+x2HpxrDgRoU3WPRiwoMzwYrtC/f0efe07Dq9ePWzi+weYeOLUogzzQbpI8x9y90g=
on:
tags: true
node: 5
node: 7
72 changes: 32 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,45 @@ var jwt = require('jsonwebtoken');
var REQUIRED_FIELDS = ['issuer', 'secret', 'id', 'version', 'src'];

module.exports = function deploy(options) {
var fieldError = REQUIRED_FIELDS.reduce(function(err, field) {
if (err) return err;
if (!options[field]) {
return 'Missing required field: ' + field;
}
}, null);

if (fieldError) {
return Promise.reject(new Error(fieldError));
}

var jwtIssuer = options.issuer;
var jwtSecret = options.secret;
var extensionId = options.id;
var extensionVersion = options.version;
var srcFile = options.src;

var issuedAt = Math.floor(Date.now() / 1000);
var payload = {
iss: jwtIssuer,
jti: Math.random().toString(),
iat: issuedAt,
exp: issuedAt + 60
};
var token = jwt.sign(payload, jwtSecret, { algorithm: 'HS256' });

// SuperAgent's "promise" support doesn't provide a way to get the status of a failed request
return new Promise(function(resolve, reject) {
request
.put('https://addons.mozilla.org/api/v3/addons/' + extensionId + '/versions/' + extensionVersion + '/')
.set('Authorization', 'JWT ' + token)
.field('upload', srcFile)
.end(function(err, response) {
if (err) {
var msg;
switch (response.status) {
return Promise.resolve()
// options validation
.then(function() {
REQUIRED_FIELDS.forEach(function(field) {
if (!options[field]) {
throw new Error('Missing required field: ' + field);
}
});
})
// submit the addon
.then(function() {
var issuedAt = Math.floor(Date.now() / 1000);
var payload = {
iss: jwtIssuer,
jti: Math.random().toString(),
iat: issuedAt,
exp: issuedAt + 60
};
var token = jwt.sign(payload, jwtSecret, { algorithm: 'HS256' });

return request
.put('https://addons.mozilla.org/api/v3/addons/' + extensionId + '/versions/' + extensionVersion + '/')
.set('Authorization', 'JWT ' + token)
.field('upload', srcFile)
.then(function() {
// success
}, function(err) {
switch (err.response.status) {
case 401:
msg = '401 Unauthorized: ' + response.body.detail;
break;
throw new Error('401 Unauthorized: ' + err.response.body.detail);
default:
msg = 'Status ' + response.status + ': ' + response.body.error;
break;
throw new Error('Status ' + err.response.status + ': ' + err.response.body.error);
}
reject(new Error(msg));
} else {
resolve();
}
});
});
});
});
};
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firefox-extension-deploy",
"version": "0.0.2",
"version": "1.0.0",
"description": "Deploy Firefox extensions to AMO.",
"main": "index.js",
"scripts": {
Expand All @@ -17,13 +17,13 @@
},
"homepage": "https://github.com/erikdesjardins/firefox-extension-deploy#readme",
"devDependencies": {
"ava": "^0.13.0",
"coveralls": "^2.11.8",
"nyc": "^6.0.0",
"superagent-mock": "^1.10.0"
"ava": "^0.18.1",
"coveralls": "^2.11.16",
"nyc": "^10.1.2",
"superagent-mock": "^3.2.0"
},
"dependencies": {
"jsonwebtoken": "^7.1.6",
"superagent": "^1.8.0"
"superagent": "^3.4.2"
}
}
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.beforeEach(t => {
fixtures(match, params, headers) {
t.context.requests.push({ match, params, headers });
if (t.context.publishFail) {
throw { message: t.context.publishFail };
throw { response: { status: t.context.publishFail, body: {} } };
}
return t.context.publishResponse;
},
Expand Down

0 comments on commit 7412daf

Please sign in to comment.