Socket
Socket
Sign inDemoInstall

@slack/client

Package Overview
Dependencies
67
Maintainers
4
Versions
57
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.6 to 2.1.0

lib/clients/errors.js

5

CHANGELOG.md

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

### v2.1.0 (2016-03-05)
* Adds promises to the Slack clients. If no callback is passed to an API call, a promise will be created and returned instead.
* Logs a warning if an API response with a `warning` key is received
### v2.0.6 (2016-03-01)

@@ -2,0 +7,0 @@

36

lib/clients/client.js

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

var EventEmitter = require('eventemitter3');
var Promise = require('bluebird');
var async = require('async');

@@ -14,2 +15,3 @@ var bind = require('lodash').bind;

var SlackAPIError = require('./errors').SlackAPIError;
var getLogger = require('../helpers').getLogger;

@@ -141,5 +143,8 @@ var helpers = require('./helpers');

BaseAPIClient.prototype.makeAPICall = function makeAPICall(endpoint, optData, optCb) {
var promise;
var args;
var _this = this;
var apiCallArgs = helpers.getAPICallArgs(this._token, optData, optCb);
var args = {
args = {
url: urlJoin(this.slackAPIUrl, endpoint),

@@ -152,6 +157,27 @@ data: apiCallArgs.data,

this.requestQueue.push({
args: args,
cb: apiCallArgs.cb
});
if (!apiCallArgs.cb) {
promise = new Promise(function makeAPICallPromiseResolver(resolve, reject) {
_this.requestQueue.push({
args: args,
cb: function makeAPICallPromiseResolverInner(err, res) {
if (err) {
reject(err);
} else {
if (!res.ok) {
reject(new SlackAPIError(res.error));
} else {
resolve(res);
}
}
}
});
});
} else {
this.requestQueue.push({
args: args,
cb: apiCallArgs.cb
});
}
return promise;
};

@@ -158,0 +184,0 @@

6

lib/clients/helpers.js

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

var forEach = require('lodash').forEach;
var noop = require('lodash').noop;

@@ -52,4 +51,2 @@

if (arguments.length === 1) {
// Pass in a no-op function here to avoid adding more conditionals in the _callTransport fn
cb = noop;
data = getData({}, token);

@@ -61,7 +58,6 @@ } else if (arguments.length === 2) {

} else {
cb = noop;
data = getData(optData, token);
}
} else if (arguments.length === 3) {
cb = optCb || noop;
cb = optCb;
data = getData(optData, token);

@@ -68,0 +64,0 @@ }

@@ -98,2 +98,6 @@ // For some reason, I can't turn this off only for functions, so suppress all cases

if (!jsonParseErr && jsonResponse.warning) {
client.logger('warn', jsonResponse.warning);
}
try {

@@ -100,0 +104,0 @@ apiCb(jsonParseErr, jsonResponse);

{
"name": "@slack/client",
"version": "2.0.6",
"version": "2.1.0",
"description": "A library for creating a Slack client",

@@ -26,2 +26,3 @@ "main": "./index",

"async": "^1.5.0",
"bluebird": "^3.3.3",
"eventemitter3": "^1.1.1",

@@ -28,0 +29,0 @@ "https-proxy-agent": "^1.0.0",

var expect = require('chai').expect;
var lodash = require('lodash');

@@ -68,3 +67,3 @@ var helpers = require('../../lib/clients/helpers');

describe('#getAPICallArgs()', function () {
it('returns an empty object and noop fn when called with no data or cb', function () {
it('returns an object with the token when called with no data or cb', function () {
var callArgs = helpers.getAPICallArgs('test');

@@ -74,6 +73,5 @@ expect(callArgs.data).to.deep.equal({

});
expect(callArgs.cb).to.deep.equal(lodash.noop);
});
it('returns the supplied object and noop fn when called with an object and no cb', function () {
it('returns the supplied object when called with a data object and no cb', function () {
var callArgs = helpers.getAPICallArgs('test', { test: 1 });

@@ -84,3 +82,2 @@ expect(callArgs.data).to.deep.equal({

});
expect(callArgs.cb).to.deep.equal(lodash.noop);
});

@@ -87,0 +84,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc