carpenterd-api-client
Advanced tools
Comparing version 1.4.0 to 2.0.0
31
index.js
'use strict'; | ||
var request = require('hyperquest'), | ||
url = require('url'); | ||
url = require('url'); | ||
@@ -15,6 +15,12 @@ // | ||
* @constructor | ||
* @param {String} base The root URL of the carpenter service | ||
* @api public | ||
* @param {Object|String} opts Options for root URL of carpenter service | ||
* @param {String} opts.url The root URL of the carpenter service | ||
* @param {String} opts.uri The root URL of the carpenter service | ||
* @param {String} opts.href The href for root URL of the carpenter service | ||
* @param {String} opts.protocol Protocol for root URL of the carpenter service | ||
* @param {String} opts.version The carpenter build API version to use (defaults to v2) | ||
* @public | ||
*/ | ||
function Carpenter(opts) { | ||
// eslint-disable-next-line no-new | ||
if (!this) new Carpenter(opts); | ||
@@ -32,2 +38,4 @@ | ||
this.version = (opts.version === '1' || opts.version === 'v1' || opts.version === 1) ? '' : 'v2'; | ||
// | ||
@@ -49,3 +57,4 @@ // Handle all possible cases | ||
* @param {Function} next Completion callback. | ||
* @api private | ||
* @returns {Stream} the request | ||
* @private | ||
*/ | ||
@@ -56,3 +65,6 @@ Carpenter.prototype.build = function build(options, next) { | ||
return this.send('build', options, next); | ||
return this.send([ | ||
this.version, | ||
'build' | ||
].filter(Boolean).join('/'), options, next); | ||
}; | ||
@@ -66,3 +78,4 @@ | ||
* @param {Function} next Completion callback. | ||
* @api private | ||
* @returns {Stream} the request | ||
* @private | ||
*/ | ||
@@ -87,3 +100,3 @@ Carpenter.prototype.cancel = function cancel(options, next) { | ||
* @param {Function} next Completion callback. | ||
* @returns {Hyperquest} | ||
* @returns {Stream} the request | ||
* @api private | ||
@@ -93,4 +106,4 @@ */ | ||
var base = url.parse(this.base), | ||
data = false, | ||
req; | ||
data = false, | ||
req; | ||
@@ -97,0 +110,0 @@ if (typeof pathname === 'object') { |
{ | ||
"name": "carpenterd-api-client", | ||
"version": "1.4.0", | ||
"version": "2.0.0", | ||
"description": "Node.js API client to interact with the carpenter build service.", | ||
"main": "index.js", | ||
"scripts": { | ||
"eslint": "eslint-godaddy -c .eslintrc ./*.js", | ||
"pretest": "npm run eslint", | ||
"test": "mocha test.js" | ||
@@ -11,3 +13,3 @@ }, | ||
"type": "git", | ||
"url": "git@github.com:warehouseai/carpenter-api-client.git" | ||
"url": "git@github.com:warehouseai/carpenterd-api-client.git" | ||
}, | ||
@@ -31,6 +33,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"assume": "~1.4.1", | ||
"mocha": "~2.3.2", | ||
"nock": "~2.11.0" | ||
"assume": "^2.1.0", | ||
"eslint": "^5.12.0", | ||
"eslint-config-godaddy": "^3.0.0", | ||
"eslint-plugin-json": "^1.2.0", | ||
"eslint-plugin-mocha": "^5.2.0", | ||
"mocha": "^5.2.0", | ||
"nock": "^10.0.6" | ||
} | ||
} |
# carpenterd-api-client | ||
The `carpenterd-api-client` is an API client for the []`carpenterd`][carpenterd] build service. | ||
The `carpenterd-api-client` is an API client for the [`carpenterd`][carpenterd] build service. | ||
@@ -5,0 +5,0 @@ ## Install |
116
test.js
describe('carpenter-api-client', function () { | ||
'use strict'; | ||
var assume = require('assume') | ||
, Carpenter = require('./') | ||
, nock = require('nock') | ||
, url = require('url') | ||
, carpenter | ||
, uri; | ||
var assume = require('assume'), | ||
Carpenter = require('./'), | ||
nock = require('nock'), | ||
url = require('url'); | ||
var carpenter, uri; | ||
@@ -57,24 +56,37 @@ beforeEach(function each() { | ||
it('can be configured with an api version', function () { | ||
[1, '1', 'v1'].forEach(function (version) { | ||
carpenter = new Carpenter({ uri, version }); | ||
assume(carpenter.version).equals(''); | ||
}); | ||
}); | ||
it('defaults to the v2 api', function () { | ||
assume(new Carpenter({ uri }).version).equals('v2'); | ||
assume(new Carpenter({ uri, version: 'not one' }).version).equals('v2'); | ||
}); | ||
describe('#build', function () { | ||
var options = { | ||
data: { | ||
name: 'foo-bar' | ||
data: { name: 'foo-bar' }, | ||
promote: true | ||
} | ||
}; | ||
it('sends a request to /build', function (next) { | ||
it('sends a request to /v2/build', function (next) { | ||
next = assume.wait(2, next); | ||
nock(uri) | ||
.post('/build') | ||
.reply(200, function reply(uri, body) { | ||
body = JSON.parse(body); | ||
.post('/v2/build') | ||
.reply(200, function reply(uri, body) { | ||
assume(body.data.name).equals('foo-bar'); | ||
assume(body.promote).equals(true); | ||
nock.cleanAll(); | ||
next(); | ||
assume(body.name).equals('foo-bar'); | ||
nock.cleanAll(); | ||
next(); | ||
return {}; | ||
}); | ||
return {}; | ||
}); | ||
carpenter.build(options, next); | ||
@@ -87,15 +99,37 @@ }); | ||
nock(uri) | ||
.post('/build') | ||
.reply(200, function reply(uri, body) { | ||
body = JSON.parse(body); | ||
.post('/v2/build') | ||
.reply(200, function reply(uri, body) { | ||
assume(body.data.name).equals('foo-bar'); | ||
assume(body.promote).equals(true); | ||
nock.cleanAll(); | ||
next(); | ||
assume(body.name).equals('foo-bar'); | ||
nock.cleanAll(); | ||
next(); | ||
return {}; | ||
}); | ||
return {}; | ||
carpenter.build({ | ||
data: JSON.stringify(options.data) | ||
}, next); | ||
}); | ||
it('sends a request to /build when using v1 API', function (next) { | ||
carpenter = new Carpenter({ | ||
uri, | ||
version: 'v1' | ||
}); | ||
next = assume.wait(2, next); | ||
nock(uri) | ||
.post('/build') | ||
.reply(200, function reply(uri, body) { | ||
assume(body.name).equals('foo-bar'); | ||
nock.cleanAll(); | ||
next(); | ||
return {}; | ||
}); | ||
carpenter.build({ | ||
data: JSON.stringify(options.data) | ||
data: { name: 'foo-bar' } | ||
}, next); | ||
@@ -116,11 +150,11 @@ }); | ||
nock(uri) | ||
.get('/cancel/foo-bar/1.0.0/prod') | ||
.reply(200, function reply(uri, body) { | ||
assume(uri).equals('/cancel/foo-bar/1.0.0/prod'); | ||
assume(body).to.be.falsey(); | ||
nock.cleanAll(); | ||
next(); | ||
.get('/cancel/foo-bar/1.0.0/prod') | ||
.reply(200, function reply(uri, body) { | ||
assume(uri).equals('/cancel/foo-bar/1.0.0/prod'); | ||
assume(body).to.be.falsey(); | ||
nock.cleanAll(); | ||
next(); | ||
return {}; | ||
}); | ||
return {}; | ||
}); | ||
@@ -136,11 +170,11 @@ carpenter.cancel(options, next); | ||
nock(uri) | ||
.get('/cancel/foo-bar/1.0.0') | ||
.reply(200, function reply(uri, body) { | ||
assume(uri).equals('/cancel/foo-bar/1.0.0'); | ||
assume(body).to.be.falsey(); | ||
nock.cleanAll(); | ||
next(); | ||
.get('/cancel/foo-bar/1.0.0') | ||
.reply(200, function reply(uri, body) { | ||
assume(uri).equals('/cancel/foo-bar/1.0.0'); | ||
assume(body).to.be.falsey(); | ||
nock.cleanAll(); | ||
next(); | ||
return {}; | ||
}); | ||
return {}; | ||
}); | ||
@@ -147,0 +181,0 @@ carpenter.cancel(options, next); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance 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
11637
271
7
3