Socket
Socket
Sign inDemoInstall

gangway

Package Overview
Dependencies
22
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

5

CHANGELOG.md
# Changelog
## 2.1.0
- Upgrade superagent to 1.8.x
- Add `buildQuery` option to define custom query string behavior
## 2.0.0

@@ -4,0 +9,0 @@

3

docs/readme.md
# Gangway Documentation
1. [Guides](#guides)
2. [API](#api)
## Guides

@@ -4,0 +7,0 @@

4

package.json
{
"name": "gangway",
"version": "2.0.0",
"version": "2.1.0",
"description": "A client-side API abstraction layer",

@@ -22,3 +22,3 @@ "engines": {

"dependencies": {
"superagent": "~1.7"
"superagent": "~1.8"
},

@@ -25,0 +25,0 @@ "devDependencies": {

@@ -135,2 +135,3 @@ # Gangway

onError : Run before rejecting a request to preprocessing errors
buildQuery : Run before a query string stringifies.
params : Populate bindings in paths and are sent as request bodies. Defaults to body.

@@ -144,2 +145,16 @@ Promise : The Promise implementation. Defaults to global.Promise.

### Responses
Gangway wraps around superagent, leaning on it to build a response
object. [This object is documented within superagent](https://visionmedia.github.io/superagent/#response-properties),
however the important parts are:
```javascript
{
"text": "...", // The unparsed response body string
"body": {}, // The parsed response body
"status": 200 // The HTTP status code for the request
}
```
***

@@ -146,0 +161,0 @@

@@ -23,3 +23,3 @@ var Mock = require('./mock')

.send(options.body)
.query(options.query)
.query(options.buildQuery(options.query))
.set(options.headers)

@@ -26,0 +26,0 @@ .timeout(options.timeout)

@@ -21,2 +21,3 @@ /**

type : 'application/json',
buildQuery : function(query) { return query },
beforeSend : function(ajax) { return ajax },

@@ -23,0 +24,0 @@ onResponse : function(response) { return response.body },

@@ -191,2 +191,89 @@ var ajax = require('../src/ajax')

})
it ('can configure how query parameters are stringified', function () {
var message = ajax({
baseURL : baseURL,
buildQuery : function (query) {
return 'foo=bar'
}
})
assert.deepEqual(message.qsRaw, [ 'foo=bar' ])
})
describe('Promise decoration', function() {
it ('can chain off of requests', function (done) {
var message = ajax({
baseURL : baseURL,
path : '/base/test/response.json'
})
message.then(function() {
done()
})
})
it ('can catch rejected promises', function (done) {
var message = ajax({
baseURL : baseURL,
path : '/base/test/404.json'
})
message.catch(function (error) {
done()
})
})
it ('supports the done() Promise method', function (done) {
var message = ajax({
baseURL : baseURL,
path : '/base/test/response.json'
})
message.done(function (error) {
done()
})
})
context('when done() raises an error', function() {
beforeEach(function() {
this.originalTimeout = global.setTimeout
})
afterEach(function() {
global.setTimeout = this.originalTimeout
})
it ('done errors bubble out', function (done) {
var message = ajax({
baseURL : baseURL,
path : '/base/test/response.json'
})
message.done(function (error) {
global.setTimeout = function(fn) {
assert.throws(fn, /This should fail/)
done()
}
throw new Error('This should fail')
})
})
it ('done errors bubble out if given no callback', function (done) {
var message = ajax({
baseURL : baseURL,
path : '/base/test/response.json'
})
global.setTimeout = function(fn) {
assert.throws(fn)
done()
}
message.done()
})
})
})
})

@@ -122,2 +122,12 @@ var API = require('../src/api')

context('When given a basePath option', function() {
beforeEach(function() {
this.api = API({ basePath: 'test' })
})
it ('adds that path to the segment', function() {
assert.deepEqual(this.api.segments, [ 'test' ])
})
})
context('when a route is executed', function() {

@@ -124,0 +134,0 @@ var api = API({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc