@bbc/http-transport
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -5,2 +5,3 @@ 'use strict'; | ||
const CallbackDecorator = require('./callbacks/decorator'); | ||
const HttpTransportClient = require('./client'); | ||
@@ -15,6 +16,7 @@ | ||
/** | ||
* Configures HttpTransport client | ||
* @param {Transport} transport - Transport instance. | ||
*/ | ||
* Configures HttpTransport client | ||
* @param {Transport} transport - Transport instance. | ||
*/ | ||
constructor(transport) { | ||
this._callback = false; | ||
this._transport = transport; | ||
@@ -93,2 +95,15 @@ this._defaults = { | ||
/** | ||
* Callbackify the client | ||
* | ||
* @return a HttpTransport instance supporting callbacks | ||
* @example | ||
* | ||
* const client = httpTransport.asCallback().createClient(); | ||
*/ | ||
asCallback() { | ||
this._callback = true; | ||
return this; | ||
} | ||
/** | ||
* Instantiates a HttpTransport | ||
@@ -103,3 +118,7 @@ * | ||
createClient() { | ||
return new HttpTransportClient(this._transport, this._defaults); | ||
const transportClient = new HttpTransportClient(this._transport, this._defaults); | ||
if (this._callback) { | ||
return new CallbackDecorator(transportClient); | ||
} | ||
return transportClient; | ||
} | ||
@@ -106,0 +125,0 @@ } |
@@ -12,6 +12,6 @@ 'use strict'; | ||
/** | ||
* Create a HttpTransport. | ||
* @param {Transport} transport - Transport instance. | ||
* @param {object} defaults - default configutation | ||
*/ | ||
* Create a HttpTransport. | ||
* @param {Transport} transport - Transport instance. | ||
* @param {object} defaults - default configutation | ||
*/ | ||
constructor(transport, defaults) { | ||
@@ -18,0 +18,0 @@ this._transport = transport; |
{ | ||
"name": "@bbc/http-transport", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "A flexible, modular REST client built for ease-of-use and resilience.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,3 +14,3 @@ 'use strict'; | ||
const packageInfo = require('../package'); | ||
const toError = require('./toError'); | ||
const sandbox = sinon.sandbox.create(); | ||
@@ -59,15 +59,2 @@ | ||
function toError() { | ||
return async (ctx, next) => { | ||
await next(); | ||
if (ctx.res.statusCode >= 400) { | ||
const err = new Error('something bad happend.'); | ||
err.statusCode = ctx.res.statusCode; | ||
err.headers = ctx.res.headers; | ||
throw err; | ||
} | ||
}; | ||
} | ||
describe('HttpTransportClient', () => { | ||
@@ -74,0 +61,0 @@ beforeEach(() => { |
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
374970
88
6769
0