@slack/client
Advanced tools
Comparing version 2.0.4 to 2.0.6
@@ -0,1 +1,15 @@ | ||
### v2.0.6 (2016-03-01) | ||
* Fixes a crash introduce in `2.0.5` if you try and instantiate a `WebClient` without passing in any options | ||
### v2.0.5 (2016-03-01) | ||
* Updates the way that API requests are throttled to: | ||
* avoid a condition where the request queue callback could be called multiple times, causing a crash | ||
* refactor the logic in `_callTransport` into multiple functions to make it easier to follow | ||
* Updates dev dependencies: | ||
* eslint | ||
* nock | ||
* eslint-config-airbnb | ||
### v2.0.4 (2016-02-28) | ||
@@ -2,0 +16,0 @@ |
@@ -9,7 +9,7 @@ var events = require('./lib/clients/events'); | ||
WEB: events.CLIENT_EVENTS.WEB, | ||
RTM: events.CLIENT_EVENTS.RTM, | ||
RTM: events.CLIENT_EVENTS.RTM | ||
}, | ||
RTM_EVENTS: events.RTM_EVENTS, | ||
RTM_MESSAGE_SUBTYPES: events.RTM_MESSAGE_SUBTYPES, | ||
MemoryDataStore: require('./lib/data-store/memory-data-store'), | ||
MemoryDataStore: require('./lib/data-store/memory-data-store') | ||
}; |
@@ -9,9 +9,10 @@ /** | ||
var inherits = require('inherits'); | ||
var partial = require('lodash').partial; | ||
var retry = require('retry'); | ||
var urlJoin = require('url-join'); | ||
var WEB_CLIENT_EVENTS = require('./events/client').WEB; | ||
var getLogger = require('../helpers').getLogger; | ||
var helpers = require('./helpers'); | ||
var requestsTransport = require('./transports/request').requestTransport; | ||
var callTransport = require('./transports/call-transport'); | ||
@@ -29,6 +30,9 @@ | ||
* @param {Number} opts.maxRequestConcurrency The max # of concurrent requests to make to Slack's | ||
* API's, defaults to 5. | ||
* API's, defaults to 3. | ||
* @param {Object} opts.retryConfig The configuration to use for the retry operation, | ||
* {@see https://github.com/SEAPUNK/node-retry} | ||
* @constructor | ||
*/ | ||
function BaseAPIClient(token, opts) { | ||
var clientOpts = opts || {}; | ||
EventEmitter.call(this); | ||
@@ -43,11 +47,19 @@ | ||
/** @type {string} */ | ||
this.slackAPIUrl = opts.slackAPIUrl || 'https://slack.com/api/'; | ||
this.slackAPIUrl = clientOpts.slackAPIUrl || 'https://slack.com/api/'; | ||
/** @type {Function} */ | ||
this.transport = opts.transport || requestsTransport; | ||
this.transport = clientOpts.transport || requestsTransport; | ||
/** @type {string} */ | ||
this.userAgent = opts.userAgent || 'node-slack'; | ||
this.userAgent = clientOpts.userAgent || 'node-slack'; | ||
/** | ||
* Default to attempting 5 retries within 5 minutes, with exponential backoff. | ||
*/ | ||
this.retryConfig = clientOpts.retryConfig || { | ||
retries: 5, | ||
factor: 3.9 | ||
}; | ||
/** | ||
* | ||
@@ -57,5 +69,5 @@ * @type {Object} | ||
*/ | ||
this._requestQueue = async.priorityQueue( | ||
this.requestQueue = async.priorityQueue( | ||
bind(this._callTransport, this), | ||
opts.maxRequestConcurrency | ||
clientOpts.maxRequestConcurrency || 3 | ||
); | ||
@@ -67,3 +79,3 @@ | ||
*/ | ||
this.logger = opts.logger || getLogger(opts.logLevel); | ||
this.logger = clientOpts.logger || getLogger(clientOpts.logLevel); | ||
@@ -109,81 +121,13 @@ this._createFacets(); | ||
BaseAPIClient.prototype._callTransport = function _callTransport(task, queueCb) { | ||
// TODO(leah): Add some logging to this function as it's kind of complex | ||
var args = task.args; | ||
var cb = task.cb; | ||
var _this = this; | ||
var retryOp = retry.operation(this.retryConfig); | ||
var handleTransportResponse = function handleTransportResponse(err, headers, statusCode, body) { | ||
var headerSecs; | ||
var headerMs; | ||
var httpErr; | ||
var jsonResponse; | ||
var jsonParseErr; | ||
if (err) { | ||
if (!retryOp.retry(err)) { | ||
cb(retryOp.mainError(), null); | ||
} else { | ||
return; | ||
} | ||
} | ||
// NOTE: this assumes that non-200 codes simply won't happen, as the Slack API policy is to | ||
// return a 200 with an error property | ||
if (statusCode !== 200) { | ||
// There are only a couple of possible bad cases here: | ||
// - 429: the application is being rate-limited. The client is designed to automatically | ||
// respect this | ||
// - 4xx or 5xx: something bad, but probably recoverable, has happened, so requeue the | ||
// request | ||
if (statusCode === 429) { | ||
_this._requestQueue.pause(); | ||
headerSecs = parseInt(headers['Retry-After'], 10); | ||
headerMs = headerSecs * 1000; | ||
setTimeout(function retryRateLimitedRequest() { | ||
// Don't retry limit requests that were rejected due to retry-after | ||
_this.transport(args, handleTransportResponse); | ||
_this._requestQueue.resume(); | ||
}, headerMs); | ||
_this.emit(WEB_CLIENT_EVENTS.RATE_LIMITED, headerSecs); | ||
} else { | ||
// If this is reached, it means an error outside the normal error logic was received. These | ||
// should be very unusual as standard errors come back with a 200 code and an "error" | ||
// property. | ||
// | ||
// Given that, assume that something really weird happened and retry the request as normal. | ||
httpErr = new Error('Unable to process request, received bad ' + statusCode + ' error'); | ||
if (!retryOp.retry(httpErr)) { | ||
cb(httpErr, null); | ||
} else { | ||
return; | ||
} | ||
} | ||
} else { | ||
try { | ||
jsonResponse = JSON.parse(body); | ||
} catch (parseErr) { | ||
// TODO(leah): Emit an event here? | ||
jsonParseErr = new Error('unable to parse Slack API Response'); | ||
} | ||
try { | ||
cb(jsonParseErr, jsonResponse); | ||
} catch (callbackErr) { | ||
// Never retry requests that fail in the callback | ||
_this.logger('error', callbackErr); | ||
} | ||
} | ||
// This is always an empty callback, even if there's an error, as it's used to signal the | ||
// request queue that a request has completed processing, and nothing else. | ||
queueCb(); | ||
var retryOp = retry.operation(_this.retryConfig); | ||
var retryArgs = { | ||
client: _this, | ||
task: task, | ||
queueCb: queueCb, | ||
retryOp: retryOp | ||
}; | ||
retryOp.attempt(function attemptTransportCall() { | ||
_this.transport(args, handleTransportResponse); | ||
_this.transport(task.args, partial(callTransport.handleTransportResponse, retryArgs)); | ||
}); | ||
@@ -198,3 +142,3 @@ }; | ||
* @param {Object=} optData The data send to the Slack API. | ||
* @param {function} optCb The callback to run on completion. | ||
* @param {function=} optCb The callback to run on completion. | ||
*/ | ||
@@ -208,9 +152,9 @@ BaseAPIClient.prototype.makeAPICall = function makeAPICall(endpoint, optData, optCb) { | ||
headers: { | ||
'User-Agent': this.userAgent, | ||
}, | ||
'User-Agent': this.userAgent | ||
} | ||
}; | ||
this._requestQueue.push({ | ||
this.requestQueue.push({ | ||
args: args, | ||
cb: apiCallArgs.cb, | ||
cb: apiCallArgs.cb | ||
}); | ||
@@ -217,0 +161,0 @@ }; |
@@ -15,3 +15,3 @@ /** | ||
logLevel: 'debug', | ||
dataStore: new MemoryDataStore(), | ||
dataStore: new MemoryDataStore() | ||
}; | ||
@@ -18,0 +18,0 @@ RtmClient.call(this, slackToken, opts); |
@@ -6,3 +6,3 @@ /** | ||
module.exports.WEB = { | ||
RATE_LIMITED: 'rate_limited', | ||
RATE_LIMITED: 'rate_limited' | ||
}; | ||
@@ -41,5 +41,5 @@ | ||
RAW_MESSAGE: 'raw_message', // a message was received from the RTM API. This | ||
RAW_MESSAGE: 'raw_message' // a message was received from the RTM API. This | ||
// will also contain the raw message payload that | ||
// was sent from Slack | ||
}; |
module.exports = { | ||
CLIENT_EVENTS: { | ||
WEB: require('./client').WEB, | ||
RTM: require('./client').RTM, | ||
RTM: require('./client').RTM | ||
}, | ||
RTM_EVENTS: require('./rtm').EVENTS, | ||
RTM_MESSAGE_SUBTYPES: require('./rtm').MESSAGE_SUBTYPES, | ||
RTM_MESSAGE_SUBTYPES: require('./rtm').MESSAGE_SUBTYPES | ||
}; |
@@ -68,3 +68,3 @@ /** | ||
USER_CHANGE: 'user_change', | ||
USER_TYPING: 'user_typing', | ||
USER_TYPING: 'user_typing' | ||
}; | ||
@@ -95,3 +95,3 @@ | ||
MESSAGE_CHANGED: 'message_changed', | ||
MESSAGE_DELETED: 'message_deleted', | ||
MESSAGE_DELETED: 'message_deleted' | ||
}; |
@@ -69,3 +69,3 @@ /** | ||
cb: cb, | ||
data: data, | ||
data: data | ||
}; | ||
@@ -72,0 +72,0 @@ }; |
@@ -16,3 +16,3 @@ /** | ||
RTM_API_EVENTS.HELLO, | ||
RTM_API_EVENTS.TEAM_MIGRATION_STARTED, | ||
RTM_API_EVENTS.TEAM_MIGRATION_STARTED | ||
]; | ||
@@ -22,3 +22,3 @@ var UNRECOVERABLE_RTM_START_ERRS = [ | ||
'invalid_auth', | ||
'account_inactive', | ||
'account_inactive' | ||
]; | ||
@@ -48,3 +48,2 @@ var CLIENT_EVENTS = require('../events/client').RTM; | ||
* parameters. | ||
* @param {SlackDataStore} opts.dataStore | ||
* @constructor | ||
@@ -501,3 +500,3 @@ */ | ||
channel: channelId, | ||
type: RTM_API_EVENTS.MESSAGE, | ||
type: RTM_API_EVENTS.MESSAGE | ||
}, optCb); | ||
@@ -504,0 +503,0 @@ }; |
@@ -28,3 +28,3 @@ /** | ||
url: args.url, | ||
headers: args.headers, | ||
headers: args.headers | ||
}; | ||
@@ -31,0 +31,0 @@ |
@@ -24,10 +24,3 @@ /** | ||
var clientOpts = opts || {}; | ||
BaseAPIClient.call(this, token, clientOpts); | ||
// Attempts 5 retries within 5 minutes, with exponential backoff | ||
this.retryConfig = clientOpts.retryConfig || { | ||
retries: 5, | ||
factor: 3.9, | ||
}; | ||
} | ||
@@ -34,0 +27,0 @@ |
@@ -27,3 +27,3 @@ /** | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -30,0 +30,0 @@ |
@@ -40,3 +40,3 @@ /** | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -56,3 +56,3 @@ | ||
var args = { | ||
name: name, | ||
name: name | ||
}; | ||
@@ -78,3 +78,3 @@ | ||
channel: channel, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -94,3 +94,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -112,3 +112,3 @@ | ||
channel: channel, | ||
user: user, | ||
user: user | ||
}; | ||
@@ -128,3 +128,3 @@ | ||
var args = { | ||
name: name, | ||
name: name | ||
}; | ||
@@ -146,3 +146,3 @@ | ||
channel: channel, | ||
user: user, | ||
user: user | ||
}; | ||
@@ -162,3 +162,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -192,3 +192,3 @@ | ||
channel: channel, | ||
ts: ts, | ||
ts: ts | ||
}; | ||
@@ -210,3 +210,3 @@ | ||
channel: channel, | ||
name: name, | ||
name: name | ||
}; | ||
@@ -228,3 +228,3 @@ | ||
channel: channel, | ||
purpose: purpose, | ||
purpose: purpose | ||
}; | ||
@@ -246,3 +246,3 @@ | ||
channel: channel, | ||
topic: topic, | ||
topic: topic | ||
}; | ||
@@ -262,3 +262,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -265,0 +265,0 @@ |
@@ -29,3 +29,3 @@ /** | ||
ts: ts, | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -59,3 +59,3 @@ | ||
text: text, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -84,3 +84,3 @@ | ||
text: text, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -87,0 +87,0 @@ |
@@ -28,3 +28,3 @@ /** | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -50,3 +50,3 @@ | ||
channel: channel, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -79,3 +79,3 @@ | ||
channel: channel, | ||
ts: ts, | ||
ts: ts | ||
}; | ||
@@ -95,3 +95,3 @@ | ||
var args = { | ||
user: user, | ||
user: user | ||
}; | ||
@@ -98,0 +98,0 @@ |
@@ -28,3 +28,3 @@ /** | ||
var args = { | ||
file: file, | ||
file: file | ||
}; | ||
@@ -44,3 +44,3 @@ | ||
var args = { | ||
file: file, | ||
file: file | ||
}; | ||
@@ -75,3 +75,3 @@ | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -98,3 +98,3 @@ | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -101,0 +101,0 @@ |
@@ -42,3 +42,3 @@ /** | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -58,3 +58,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -74,3 +74,3 @@ | ||
var args = { | ||
name: name, | ||
name: name | ||
}; | ||
@@ -90,3 +90,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -112,3 +112,3 @@ | ||
channel: channel, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -128,3 +128,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -146,3 +146,3 @@ | ||
channel: channel, | ||
user: user, | ||
user: user | ||
}; | ||
@@ -164,3 +164,3 @@ | ||
channel: channel, | ||
user: user, | ||
user: user | ||
}; | ||
@@ -180,3 +180,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -210,3 +210,3 @@ | ||
channel: channel, | ||
ts: ts, | ||
ts: ts | ||
}; | ||
@@ -226,3 +226,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -244,3 +244,3 @@ | ||
channel: channel, | ||
name: name, | ||
name: name | ||
}; | ||
@@ -262,3 +262,3 @@ | ||
channel: channel, | ||
purpose: purpose, | ||
purpose: purpose | ||
}; | ||
@@ -280,3 +280,3 @@ | ||
channel: channel, | ||
topic: topic, | ||
topic: topic | ||
}; | ||
@@ -296,3 +296,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -299,0 +299,0 @@ |
@@ -12,3 +12,3 @@ /** | ||
var ret = { | ||
args: {}, | ||
args: {} | ||
}; | ||
@@ -15,0 +15,0 @@ |
@@ -18,3 +18,3 @@ module.exports = { | ||
TeamFacet: require('./team.js'), | ||
UsersFacet: require('./users.js'), | ||
UsersFacet: require('./users.js') | ||
}; |
@@ -32,3 +32,3 @@ /** | ||
code: code, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -35,0 +35,0 @@ |
@@ -32,3 +32,3 @@ /** | ||
channel: channel, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -48,3 +48,3 @@ | ||
var args = { | ||
channel: channel, | ||
channel: channel | ||
}; | ||
@@ -69,3 +69,3 @@ | ||
channel: channel, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -72,0 +72,0 @@ |
@@ -25,3 +25,3 @@ /** | ||
var args = { | ||
presence: presence, | ||
presence: presence | ||
}; | ||
@@ -28,0 +28,0 @@ |
@@ -34,3 +34,3 @@ /** | ||
name: name, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -55,3 +55,3 @@ | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -73,3 +73,3 @@ | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -95,3 +95,3 @@ | ||
name: name, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -98,0 +98,0 @@ |
@@ -28,3 +28,3 @@ /** | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -31,0 +31,0 @@ |
@@ -32,3 +32,3 @@ /** | ||
query: query, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -53,3 +53,3 @@ | ||
query: query, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -74,3 +74,3 @@ | ||
query: query, | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -77,0 +77,0 @@ |
@@ -34,3 +34,3 @@ /** | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -67,3 +67,3 @@ | ||
var args = { | ||
opts: opts, | ||
opts: opts | ||
}; | ||
@@ -70,0 +70,0 @@ |
@@ -31,3 +31,3 @@ /** | ||
var args = { | ||
user: user, | ||
user: user | ||
}; | ||
@@ -47,3 +47,3 @@ | ||
var args = { | ||
user: user, | ||
user: user | ||
}; | ||
@@ -87,3 +87,3 @@ | ||
var args = { | ||
presence: presence, | ||
presence: presence | ||
}; | ||
@@ -90,0 +90,0 @@ |
@@ -339,11 +339,14 @@ /* eslint no-unused-vars: 0 */ | ||
SlackDataStore.prototype.getChannelGroupOrDMById = function getChannelGroupOrDMById(objId) { | ||
var ret; | ||
var firstChar = objId.substring(0, 1); | ||
if (firstChar === 'C') { | ||
return this.getChannelById(objId); | ||
ret = this.getChannelById(objId); | ||
} else if (firstChar === 'G') { | ||
return this.getGroupById(objId); | ||
ret = this.getGroupById(objId); | ||
} else if (firstChar === 'D') { | ||
return this.getDMById(objId); | ||
ret = this.getDMById(objId); | ||
} | ||
return ret; | ||
}; | ||
@@ -359,3 +362,3 @@ | ||
var channel = this.getChannelByName(name); | ||
return channel ? channel : this.getGroupByName(name); | ||
return channel || this.getGroupByName(name); | ||
}; | ||
@@ -417,4 +420,4 @@ | ||
// the message to the base channel history | ||
handler = handler ? | ||
handler : this._messageHandlers[makeMessageEventWithSubtype('rtm_client_add_message')]; | ||
handler = handler || this._messageHandlers[ | ||
makeMessageEventWithSubtype('rtm_client_add_message')]; | ||
} else { | ||
@@ -421,0 +424,0 @@ handler = this._messageHandlers[messageType]; |
module.exports = { | ||
DataStore: require('./data-store'), | ||
MemoryDataStore: require('./memory-data-store'), | ||
MemoryDataStore: require('./memory-data-store') | ||
}; |
@@ -24,3 +24,3 @@ /** | ||
[RTM_EVENTS.BOT_ADDED, addBot], | ||
[RTM_EVENTS.BOT_CHANGED, changedBot], | ||
[RTM_EVENTS.BOT_CHANGED, changedBot] | ||
]; | ||
@@ -27,0 +27,0 @@ |
@@ -57,3 +57,3 @@ /** | ||
[RTM_EVENTS.CHANNEL_RENAME, baseChannelHandlers.handleRename], | ||
[RTM_EVENTS.CHANNEL_UNARCHIVE, baseChannelHandlers.handleUnarchive], | ||
[RTM_EVENTS.CHANNEL_UNARCHIVE, baseChannelHandlers.handleUnarchive] | ||
]; | ||
@@ -60,0 +60,0 @@ |
@@ -47,3 +47,3 @@ /** | ||
[RTM_EVENTS.IM_CLOSE, handleDMClose], | ||
[RTM_EVENTS.IM_HISTORY_CHANGED, helpers.noopMessage], | ||
[RTM_EVENTS.IM_HISTORY_CHANGED, helpers.noopMessage] | ||
]; | ||
@@ -50,0 +50,0 @@ |
@@ -48,3 +48,3 @@ /** | ||
[RTM_EVENTS.GROUP_RENAME, baseChannelHandlers.handleRename], | ||
[RTM_EVENTS.GROUP_HISTORY_CHANGED, helpers.noopMessage], | ||
[RTM_EVENTS.GROUP_HISTORY_CHANGED, helpers.noopMessage] | ||
]; | ||
@@ -51,0 +51,0 @@ |
@@ -18,3 +18,3 @@ /** | ||
require('./message'), | ||
require('./reactions'), | ||
require('./reactions') | ||
]; | ||
@@ -21,0 +21,0 @@ |
@@ -74,3 +74,3 @@ /** | ||
// Add in a default handler for all other message subtypes | ||
[makeMessageEventWithSubtype('rtm_client_add_message'), addMessageToChannel], | ||
[makeMessageEventWithSubtype('rtm_client_add_message'), addMessageToChannel] | ||
]; | ||
@@ -77,0 +77,0 @@ |
@@ -27,3 +27,3 @@ /** | ||
[RTM_EVENTS.MANUAL_PRESENCE_CHANGE, handleManualPresenceChange], | ||
[RTM_EVENTS.PRESENCE_CHANGE, handlePresenceChange], | ||
[RTM_EVENTS.PRESENCE_CHANGE, handlePresenceChange] | ||
]; | ||
@@ -30,0 +30,0 @@ |
@@ -59,3 +59,3 @@ /** | ||
users: [message.user], | ||
count: 1, | ||
count: 1 | ||
}); | ||
@@ -92,3 +92,3 @@ } | ||
[RTM_EVENTS.REACTION_ADDED, partial(toggleReaction, true)], | ||
[RTM_EVENTS.REACTION_REMOVED, partial(toggleReaction, false)], | ||
[RTM_EVENTS.REACTION_REMOVED, partial(toggleReaction, false)] | ||
]; | ||
@@ -95,0 +95,0 @@ |
@@ -13,3 +13,3 @@ /** | ||
[RTM_EVENTS.STAR_ADDED, helpers.noopMessage], | ||
[RTM_EVENTS.STAR_REMOVED, helpers.noopMessage], | ||
[RTM_EVENTS.STAR_REMOVED, helpers.noopMessage] | ||
]; | ||
@@ -16,0 +16,0 @@ |
@@ -42,3 +42,3 @@ /** | ||
[RTM_EVENTS.TEAM_PREF_CHANGE, handleTeamPrefChange], | ||
[RTM_EVENTS.TEAM_JOIN, helpers.handleNewOrUpdatedUser], | ||
[RTM_EVENTS.TEAM_JOIN, helpers.handleNewOrUpdatedUser] | ||
]; | ||
@@ -45,0 +45,0 @@ |
@@ -35,3 +35,3 @@ /** | ||
[RTM_EVENTS.USER_TYPING, handleUserTyping], | ||
[RTM_EVENTS.USER_CHANGE, helpers.handleNewOrUpdatedUser], | ||
[RTM_EVENTS.USER_CHANGE, helpers.handleNewOrUpdatedUser] | ||
]; | ||
@@ -38,0 +38,0 @@ |
@@ -19,3 +19,3 @@ /** | ||
level: optLogLevel || 'info', | ||
transports: [optTransport || new ConsoleTransport()], | ||
transports: [optTransport || new ConsoleTransport()] | ||
}); | ||
@@ -22,0 +22,0 @@ return bind(logger.log, logger); |
@@ -88,3 +88,5 @@ /** | ||
BaseChannel.prototype.recalcUnreads = function recalcUnreads() { | ||
var continueIterating = true; | ||
this.unreadCount = 0; | ||
forEachRight(this.history, function checkMessageIsUnread(message) { | ||
@@ -94,4 +96,6 @@ if (message.ts > this.lastRead) { | ||
} else { | ||
return false; | ||
continueIterating = false; | ||
} | ||
return continueIterating; | ||
}, this); | ||
@@ -98,0 +102,0 @@ |
@@ -25,28 +25,29 @@ var hasKey = require('lodash').has; | ||
var getModelClass = function getModelClass(obj) { | ||
var modelClass; | ||
var apiTypePrefix = obj.id.substr(0, 1); | ||
switch (apiTypePrefix) { | ||
case 'C': | ||
return require('./channel'); | ||
case 'F': | ||
return require('./file'); | ||
case 'D': | ||
return require('./dm'); | ||
case 'U': | ||
return require('./user'); | ||
case 'S': | ||
return require('./user-group'); | ||
if (apiTypePrefix === 'C') { | ||
modelClass = require('./channel'); | ||
} else if (apiTypePrefix === 'F') { | ||
modelClass = require('./file'); | ||
} else if (apiTypePrefix === 'D') { | ||
modelClass = require('./dm'); | ||
} else if (apiTypePrefix === 'U') { | ||
modelClass = require('./user'); | ||
} else if (apiTypePrefix === 'S') { | ||
modelClass = require('./user-group'); | ||
} else { | ||
// The MPDM and Group classes share the same prefix, so do an extra check here | ||
if (apiTypePrefix === 'G') { | ||
if (obj.is_mpim) { | ||
modelClass = require('./mpdm'); | ||
} | ||
default: | ||
// The MPDM and Group classes share the same prefix, so do an extra check here | ||
if (apiTypePrefix === 'G') { | ||
if (obj.is_mpim) { | ||
return require('./mpdm'); | ||
} | ||
if (obj.is_group) { | ||
return require('./group'); | ||
} | ||
if (obj.is_group) { | ||
modelClass = require('./group'); | ||
} | ||
} | ||
} | ||
return modelClass; | ||
}; | ||
@@ -53,0 +54,0 @@ |
@@ -8,3 +8,3 @@ module.exports = { | ||
User: require('./user'), | ||
UserGroup: require('./user-group'), | ||
UserGroup: require('./user-group') | ||
}; |
var PROPERTY_TYPES = { | ||
SIMPLE: 0, | ||
MODEL: 1, | ||
MODEL_ARRAY: 2, | ||
MODEL_ARRAY: 2 | ||
}; | ||
module.exports = PROPERTY_TYPES; |
{ | ||
"name": "@slack/client", | ||
"version": "2.0.4", | ||
"version": "2.0.6", | ||
"description": "A library for creating a Slack client", | ||
@@ -39,4 +39,4 @@ "main": "./index", | ||
"coveralls": "^2.11.6", | ||
"eslint": "^1.10.3", | ||
"eslint-config-airbnb": "^3.0.1", | ||
"eslint": "^2.2.0", | ||
"eslint-config-airbnb": "^6.0.2", | ||
"istanbul": "^0.4.2", | ||
@@ -46,3 +46,3 @@ "istanbul-coveralls": "^1.0.3", | ||
"mocha-lcov-reporter": "^1.0.0", | ||
"nock": "^2.15.0", | ||
"nock": "^7.2.2", | ||
"sinon": "^1.17.1" | ||
@@ -49,0 +49,0 @@ }, |
@@ -13,4 +13,4 @@ var expect = require('chai').expect; | ||
opts: { | ||
count: 125, | ||
}, | ||
count: 125 | ||
} | ||
}; | ||
@@ -21,3 +21,3 @@ | ||
count: 125, | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -29,3 +29,3 @@ }); | ||
channel: 'slack', | ||
opt_count: undefined, | ||
opt_count: undefined | ||
}; | ||
@@ -35,3 +35,3 @@ | ||
channel: 'slack', | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -44,3 +44,3 @@ }); | ||
expect(helpers.getData(testData, 'test')).to.be.deep.equal({ | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -51,3 +51,3 @@ }); | ||
var testData = { | ||
attachments: [1, 2, 3], | ||
attachments: [1, 2, 3] | ||
}; | ||
@@ -57,3 +57,3 @@ | ||
attachments: '[1,2,3]', | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -64,3 +64,3 @@ }); | ||
var testData = { | ||
attachments: '["a","b","c"]', | ||
attachments: '["a","b","c"]' | ||
}; | ||
@@ -70,3 +70,3 @@ | ||
attachments: '["a","b","c"]', | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -80,3 +80,3 @@ }); | ||
expect(callArgs.data).to.deep.equal({ | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -90,3 +90,3 @@ expect(callArgs.cb).to.deep.equal(lodash.noop); | ||
test: 1, | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -100,3 +100,3 @@ expect(callArgs.cb).to.deep.equal(lodash.noop); | ||
expect(callArgs.data).to.deep.equal({ | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -111,3 +111,3 @@ expect(callArgs.cb).to.deep.equal(testCb); | ||
test: 1, | ||
token: 'test', | ||
token: 'test' | ||
}); | ||
@@ -114,0 +114,0 @@ expect(callArgs.cb).to.deep.equal(testCb); |
@@ -66,3 +66,3 @@ var expect = require('chai').expect; | ||
maxPongInterval: 2, | ||
reconnectionBackoff: 1, | ||
reconnectionBackoff: 1 | ||
}; | ||
@@ -69,0 +69,0 @@ |
@@ -20,3 +20,3 @@ var expect = require('chai').expect; | ||
userAgent: 'test', | ||
transport: lodash.noop, | ||
transport: lodash.noop | ||
}; | ||
@@ -38,3 +38,3 @@ var client = new WebAPIClient('test-token', opts); | ||
statusCode: 200, | ||
body: '{"test": 10}', | ||
body: '{"test": 10}' | ||
}; | ||
@@ -68,4 +68,4 @@ | ||
minTimeout: 0, | ||
maxTimeout: 1, | ||
}, | ||
maxTimeout: 1 | ||
} | ||
}); | ||
@@ -72,0 +72,0 @@ sinon.spy(client, 'transport'); |
@@ -87,3 +87,3 @@ var expect = require('chai').expect; | ||
ts: '1448496776.000003', | ||
team: 'T0CHZBU59', | ||
team: 'T0CHZBU59' | ||
}; | ||
@@ -107,3 +107,3 @@ var channel = dataStore.getChannelById(TEST_CHANNEL_ID); | ||
ts: '1448496754.000002', | ||
team: 'T0CHZBU59', | ||
team: 'T0CHZBU59' | ||
}; | ||
@@ -110,0 +110,0 @@ var channel = dataStore.getChannelById(TEST_CHANNEL_ID); |
Sorry, the diff of this file is not supported yet
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
208305
94
5630
3