happychat-service
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -32,11 +32,13 @@ 'use strict'; | ||
// change a lib/customer message to what an agent client expects | ||
var formatAgentMessage = function formatAgentMessage(author_type, author_id, context, _ref) { | ||
var formatAgentMessage = function formatAgentMessage(author_type, author_id, session_id, _ref) { | ||
var id = _ref.id; | ||
var timestamp = _ref.timestamp; | ||
var text = _ref.text; | ||
var meta = _ref.meta; | ||
return { | ||
id: id, timestamp: timestamp, text: text, | ||
context: context, | ||
session_id: session_id, | ||
author_id: author_id, | ||
author_type: author_type | ||
author_type: author_type, | ||
meta: meta | ||
}; | ||
@@ -70,6 +72,2 @@ }; | ||
var isPromise = function isPromise(obj) { | ||
return obj && obj.constructor === Promise; | ||
}; | ||
exports.default = function (_ref2) { | ||
@@ -91,7 +89,8 @@ var customers = _ref2.customers; | ||
var message = _ref3.message; | ||
return new Promise(function (resolve, reject) { | ||
return new Promise(function (middlewareComplete) { | ||
if ((0, _isEmpty2.default)(middlewares)) { | ||
return resolve(message); | ||
debug('no middlewares registered'); | ||
return middlewareComplete(message); | ||
} | ||
// copy the middlewar | ||
// copy the middleware | ||
var context = middlewares.slice(); | ||
@@ -109,17 +108,17 @@ debug('running middleware', context.length); | ||
if (!head) { | ||
return resolve(data.message); | ||
debug('middleware complete', chat.id, user); | ||
return middlewareComplete(data.message); | ||
} | ||
var result = void 0; | ||
try { | ||
result = head(data); | ||
} catch (e) { | ||
debug('middlware exception', e); | ||
run(data, rest); | ||
} | ||
var promise = isPromise(result) ? result : Promise.resolve(result); | ||
promise.then(function (nextMessage) { | ||
debug('middleware complete', rest.length); | ||
// Wrapping call to middleware in Promise in case of exception | ||
new Promise(function (resolve) { | ||
return resolve(head(data)); | ||
}) | ||
// continue running with remaining middleware | ||
.then(function (nextMessage) { | ||
return run((0, _assign2.default)({}, data, { message: nextMessage }), rest); | ||
}).catch(function (e) { | ||
debug('failure', e); | ||
}) | ||
// if middleware fails, log the error and continue processing | ||
.catch(function (e) { | ||
debug('middleware failed to run', e); | ||
debug(e.stack); | ||
@@ -129,2 +128,3 @@ run(data, rest); | ||
}; | ||
// kick off the middleware processing | ||
run({ origin: origin, destination: destination, chat: chat, user: user, message: message }, context); | ||
@@ -204,3 +204,3 @@ }); | ||
agents.on('message', function (message) { | ||
var chat = { id: message.context }; | ||
var chat = { id: message.session_id }; | ||
var format = function format(m) { | ||
@@ -207,0 +207,0 @@ return (0, _assign2.default)({}, { author_type: 'agent' }, m); |
@@ -13,2 +13,3 @@ 'use strict'; | ||
// limit the information for the user | ||
var identityForUser = function identityForUser(_ref) { | ||
@@ -36,3 +37,3 @@ var id = _ref.id; | ||
return function () { | ||
var socketIdentifier = { id: user.id, socket_id: socket.id }; | ||
var socketIdentifier = { id: user.id, socket_id: socket.id, session_id: user.session_id }; | ||
debug('user joined room', user.id); | ||
@@ -43,6 +44,5 @@ | ||
var id = _ref3.id; | ||
var meta = _ref3.meta; | ||
var meta = {}; | ||
var userIdentity = identityForUser(user); | ||
var message = { context: user.id, id: id, text: text, timestamp: (0, _util.timestamp)(), user: userIdentity, meta: meta }; | ||
var message = { session_id: user.session_id, id: id, text: text, timestamp: (0, _util.timestamp)(), user: identityForUser(user), meta: meta }; | ||
// all customer connections for this user receive the message | ||
@@ -49,0 +49,0 @@ // io.to( user.id ).emit( 'message', message ) |
{ | ||
"name": "happychat-service", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Socket.IO based chat server for happychat.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
51027
12
1
45
0