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-alpha-3 to 2.0.0-rc

src/promise-decorator.js

7

CHANGELOG.md

@@ -5,4 +5,6 @@ # Changelog

- The promise returned from endpoints now exposes a `request`
reference point to the original superagent request
- Endpoint invocations now return a promise-like interface with
`then`, `catch`, and `done` methods. `then` and `catch` return true
promises. The intention is to allow for access to the underlying
superagent request while still exposing promise functionality.
- Promises are not included by default. If not polyfilled,

@@ -14,2 +16,3 @@ use the `Promise` option to provide the Promise implementation to

base path.
- Added a request timeout option. This option defaults to 15 seconds.

@@ -16,0 +19,0 @@ ### Upgrading

{
"name": "gangway",
"version": "2.0.0-alpha-3",
"version": "2.0.0-rc",
"description": "A client-side API abstraction layer",

@@ -5,0 +5,0 @@ "engines": {

@@ -16,7 +16,9 @@ # Gangway

All request methods return Promises. This means you'll need to include
your own polyfill for Promise (depending on your environment). We
recommend [`then/promise`](https://github.com/then/promise) as it
includes additional methods like `.done()` and `.nodeify()` that
improve interoperability and debugging:
The returned value of all endpoints follow the Promise
interface. Invocations of that interface return real Promises. This
means you'll need to include your own polyfill for Promise (depending
on your environment). We recommend
[`then/promise`](https://github.com/then/promise) as it includes
additional methods like `.done()` and `.nodeify()` that improve
interoperability and debugging:

@@ -139,2 +141,3 @@ ```

query : An object of query parameters. Gangway will automatically stringify this into the URL.
timeout : Request timeout in milliseconds. Defaults to 15 seconds.
```

@@ -141,0 +144,0 @@

@@ -1,5 +0,6 @@

var Mock = require('./mock')
var Mock = require('./mock')
var Request = require('superagent')
var prepare = require('./prepare')
var url = require('./url')
var promiseDecorator = require('./promise-decorator')
var url = require('./url')

@@ -14,3 +15,3 @@ module.exports = function AJAX (options) {

if ('mock' in options) {
return options.Promise.resolve(Mock(options))
return Mock(options)
}

@@ -25,14 +26,7 @@

.set(options.headers)
.timeout(options.timeout)
options.beforeSend(message)
var promise = new options.Promise(function(resolve, reject) {
message.end(function(err, response) {
return err ? reject(options.onError(err)) : resolve(options.onResponse(response))
})
})
promise.request = message
return promise
return promiseDecorator(message, options)
}

@@ -15,3 +15,3 @@ var ajax = require('./ajax')

this.config = prepare(config)
this.segments = []
this.segments = this.config.basePath ? [ this.config.basePath ] : []

@@ -18,0 +18,0 @@ this.route(routes)

module.exports = function (options) {
return typeof options.mock === 'function' ? options.mock(options) : options.mock
var answer = typeof options.mock === 'function' ? options.mock(options) : options.mock
return options.Promise.resolve(answer)
}

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

query : {},
timeout : 15000,
type : 'application/json',

@@ -21,0 +22,0 @@ beforeSend : function(ajax) { return ajax },

@@ -27,3 +27,3 @@ var ajax = require('../src/ajax')

it ('can send requests', function(done) {
ajax({
var promise = ajax({
baseURL : baseURL,

@@ -87,3 +87,3 @@ path : '/base/test/response.json'

path : '/asdf'
}).then(null, function(error) {
}).then(null, function (error) {
assert.equal(error.status, 404)

@@ -187,3 +187,3 @@ done()

message.request.abort()
message.abort()

@@ -190,0 +190,0 @@ setTimeout(function() {

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