hubot-remotestorage-logger
Advanced tools
Comparing version 0.4.0 to 0.5.0
194
index.js
@@ -1,8 +0,192 @@ | ||
require("babel/register")({ | ||
ignore: false, | ||
extensions: [".es6", ".es"] | ||
/* global setInterval */ | ||
/* Description: | ||
* Logs channel messages to a remoteStorage-enabled account | ||
* | ||
* Configuration: | ||
* RS_LOGGER_USER: RemoteStorage user address | ||
* RS_LOGGER_TOKEN: RemoteStorage OAuth bearer token for "chat-messages:rw" scope | ||
* RS_LOGGER_SERVER_NAME: Server ID/shortname to be used with remoteStorage (in URLs and metadata), e.g. "freenode" | ||
* RS_LOGGER_PUBLIC: Store log files in public folder (doesn't log direct messages) | ||
* | ||
* Commands: | ||
* | ||
* Notes: | ||
* Some code translated from hubot-logger | ||
* | ||
* Author: | ||
* Sebastian Kippe <sebastian@kip.pe> | ||
*/ | ||
const hubot = require("hubot"); | ||
// TODO Remove once re-added in rs.js package | ||
global.XMLHttpRequest = require('xhr2'); | ||
const RemoteStorage = require("remotestoragejs"); | ||
const ChatMessages = require("remotestorage-module-chat-messages"); | ||
const remoteStorage = new RemoteStorage({ | ||
modules: [ChatMessages.default] | ||
}); | ||
module.exports = function(robot) { | ||
require("./src/logger")(robot); | ||
module.exports = function (robot) { | ||
// | ||
// SETUP | ||
// | ||
let rsToken, rsUser, hubotAdapter; | ||
let messageCache = {}; | ||
rsUser = process.env.RS_LOGGER_USER; | ||
rsToken = process.env.RS_LOGGER_TOKEN; | ||
hubotAdapter = robot.adapterName; | ||
const log = function(str, logLevel='info') { | ||
robot.logger[logLevel](`[hubot-rs-logger] ${str}`); | ||
}; | ||
if (typeof rsUser === "undefined" || typeof rsToken === "undefined") { | ||
throw new Error('ENV variable for RS user and/or token missing'); | ||
} | ||
log("RemoteStorage credentials set, connecting storage..."); | ||
remoteStorage.access.claim('chat-messages', 'rw'); | ||
// remoteStorage.caching.disable('/'); | ||
remoteStorage.on('ready', function() { | ||
log("remoteStorage ready"); | ||
}); | ||
remoteStorage.on('connected', function() { | ||
log("remoteStorage connected"); | ||
setInterval(flushMessageCache, 2000); | ||
}); | ||
remoteStorage.on('error', function(error) { | ||
log("remoteStorage.js had a problem: " + error); | ||
}); | ||
remoteStorage.connect(rsUser, rsToken); | ||
// | ||
// LOGS | ||
// | ||
var logMessage = function(response) { | ||
let type; | ||
if (response.message instanceof hubot.TextMessage) { | ||
type = 'text'; | ||
} else { | ||
// TODO implement optional join/leave message logging | ||
return; | ||
} | ||
let room = response.message.user.room || 'general'; | ||
let entry = { | ||
from: response.message.user['id'], | ||
timestamp: (+Date.now()), | ||
type: type, | ||
text: response.message.text | ||
}; | ||
logEntry(room, entry); | ||
}; | ||
var logResponse = (room, strings) => { | ||
strings.forEach(function(string) { | ||
string.split('\n').forEach(function(line) { | ||
let entry = { | ||
from: robot.name, | ||
timestamp: (+Date.now()), | ||
type: 'text', | ||
text: line | ||
}; | ||
logEntry(room, entry); | ||
}); | ||
}); | ||
}; | ||
var logEntry = function(room, entry) { | ||
if (!(messageCache[room] instanceof Array)) { messageCache[room] = []; } | ||
messageCache[room].push(entry); | ||
}; | ||
var flushMessageCache = function() { | ||
Object.keys(messageCache).forEach(function(room) { | ||
let messages = messageCache[room]; | ||
if (messages && messages.length > 0) { | ||
log(`Storing ${messages.length} messages for room ${room}`); | ||
messageCache[room] = []; | ||
rsAddMessages(room, messages).then(function(){ | ||
}, function(error) { | ||
messageCache[room] = messages.concat(messageCache[room]); | ||
log(error, 'error'); | ||
}); | ||
} else { | ||
// nothing to flush | ||
} | ||
}); | ||
}; | ||
var rsAddMessages = function(room, messages) { | ||
let archive = { | ||
server: { | ||
type: hubotAdapter, | ||
name: process.env.RS_LOGGER_SERVER_NAME | ||
}, | ||
date: new Date(messages[0].timestamp), | ||
isPublic: process.env.RS_LOGGER_PUBLIC != null | ||
}; | ||
switch (hubotAdapter) { | ||
case 'irc': | ||
archive.channelName = room; | ||
archive.server.ircURI = "irc://" + process.env.HUBOT_IRC_SERVER; | ||
break; | ||
case 'xmpp': | ||
let [roomName, mucHost] = room.split("@"); | ||
archive.channelName = roomName; | ||
archive.server.xmppMUC = mucHost; | ||
break; | ||
} | ||
let rsArchive = new remoteStorage.chatMessages.DailyArchive(archive); | ||
return rsArchive.addMessages(messages); | ||
}; | ||
// | ||
// ROBOT | ||
// | ||
// Add a listener that matches all messages and calls logMessage | ||
// with a Response object | ||
var listener = new hubot.Listener(robot, (function() { | ||
return true; | ||
}), function(res) { | ||
return logMessage(res); | ||
}); | ||
robot.listeners.push(listener); | ||
// Override send methods in the Response prototype so that we can | ||
// log Hubot's replies | ||
var responseOrig = { | ||
send: robot.Response.prototype.send, | ||
reply: robot.Response.prototype.reply | ||
}; | ||
robot.Response.prototype.send = function(...strings) { | ||
logResponse(this.message.user.room, strings); | ||
responseOrig.send.call(this, ...strings); | ||
}; | ||
robot.Response.prototype.reply = function(...strings) { | ||
logResponse(this.message.user.room, strings); | ||
responseOrig.reply.call(this, ...strings); | ||
}; | ||
}; |
{ | ||
"name": "hubot-remotestorage-logger", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Logs channel messages to a remoteStorage account", | ||
@@ -20,5 +20,10 @@ "main": "index.js", | ||
"dependencies": { | ||
"remotestoragejs": "remotestorage/remotestorage.js#eafe8ce4e975479c511c7685b1c9a70fcef0bebe", | ||
"babel": "^5.6.14" | ||
"hubot": "2.x", | ||
"remotestorage-module-chat-messages": "~1.0.1", | ||
"remotestoragejs": "github:remotestorage/remotestorage.js#v1.0.0-rc1", | ||
"xhr2": "^0.1.4" | ||
}, | ||
"peerDependencies": { | ||
"hubot": "2.x" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
157
0
6972
5
4
6
+ Addedhubot@2.x
+ Addedxhr2@^0.1.4
+ Addedaccepts@1.2.131.3.8(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedbase64-url@1.2.1(transitive)
+ Addedbasic-auth@1.0.4(transitive)
+ Addedbasic-auth-connect@1.0.0(transitive)
+ Addedbatch@0.5.3(transitive)
+ Addedbody-parser@1.13.3(transitive)
+ Addedbytes@2.1.02.4.0(transitive)
+ Addedcline@0.8.2(transitive)
+ Addedcoffee-script@1.6.3(transitive)
+ Addedcommander@2.6.0(transitive)
+ Addedcompressible@2.0.18(transitive)
+ Addedcompression@1.5.2(transitive)
+ Addedconnect@2.30.2(transitive)
+ Addedconnect-multiparty@1.2.5(transitive)
+ Addedconnect-timeout@1.6.2(transitive)
+ Addedcontent-disposition@0.5.0(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedcookie@0.1.3(transitive)
+ Addedcookie-parser@1.3.5(transitive)
+ Addedcookie-signature@1.0.6(transitive)
+ Addedcrc@3.3.0(transitive)
+ Addedcsrf@3.0.6(transitive)
+ Addedcsurf@1.8.3(transitive)
+ Addeddebug@2.2.0(transitive)
+ Addeddepd@1.0.11.1.22.0.0(transitive)
+ Addeddestroy@1.0.31.0.4(transitive)
+ Addedee-first@1.1.01.1.1(transitive)
+ Addederrorhandler@1.4.3(transitive)
+ Addedescape-html@1.0.21.0.3(transitive)
+ Addedetag@1.7.0(transitive)
+ Addedexpress@3.21.2(transitive)
+ Addedexpress-session@1.11.3(transitive)
+ Addedfinalhandler@0.4.0(transitive)
+ Addedforwarded@0.1.2(transitive)
+ Addedfresh@0.3.0(transitive)
+ Addedhttp-errors@1.3.1(transitive)
+ Addedhubot@2.19.0(transitive)
+ Addediconv-lite@0.4.110.4.13(transitive)
+ Addedipaddr.js@1.0.5(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedlog@1.4.0(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmerge-descriptors@1.0.0(transitive)
+ Addedmethod-override@2.3.10(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.3.4(transitive)
+ Addedmime-db@1.12.01.52.01.53.0(transitive)
+ Addedmime-types@2.0.142.1.35(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedmkdirp@0.5.1(transitive)
+ Addedmorgan@1.6.1(transitive)
+ Addedms@0.7.10.7.2(transitive)
+ Addedmultiparty@3.3.2(transitive)
+ Addednegotiator@0.5.30.6.3(transitive)
+ Addedon-finished@2.1.12.3.0(transitive)
+ Addedon-headers@1.0.2(transitive)
+ Addedoptparse@1.0.4(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedpause@0.1.0(transitive)
+ Addedproxy-addr@1.0.10(transitive)
+ Addedqs@2.2.54.0.0(transitive)
+ Addedrandom-bytes@1.0.0(transitive)
+ Addedrange-parser@1.0.3(transitive)
+ Addedraw-body@2.1.7(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedremotestorage-module-chat-messages@1.0.1(transitive)
+ Addedresponse-time@2.3.3(transitive)
+ Addedrndm@1.2.0(transitive)
+ Addedscoped-http-client@0.11.0(transitive)
+ Addedsend@0.13.00.13.2(transitive)
+ Addedserve-favicon@2.3.2(transitive)
+ Addedserve-index@1.7.3(transitive)
+ Addedserve-static@1.10.3(transitive)
+ Addedstatuses@1.2.11.5.0(transitive)
+ Addedstream-counter@0.2.0(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedtsscmp@1.0.5(transitive)
+ Addedtype-is@1.5.71.6.18(transitive)
+ Addeduid-safe@2.0.02.1.4(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedutils-merge@1.0.0(transitive)
+ Addedvary@1.0.11.1.2(transitive)
+ Addedvhost@3.0.2(transitive)
+ Addedxhr2@0.1.4(transitive)
- Removedbabel@^5.6.14
- Removedacorn@5.7.4(transitive)
- Removedalign-text@0.1.4(transitive)
- Removedalter@0.2.0(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedanymatch@1.3.2(transitive)
- Removedarr-diff@2.0.04.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedarray-unique@0.2.10.3.2(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedast-traverse@0.1.1(transitive)
- Removedast-types@0.8.120.9.6(transitive)
- Removedasync-each@1.0.6(transitive)
- Removedatob@2.1.2(transitive)
- Removedbabel@5.8.38(transitive)
- Removedbabel-core@5.8.38(transitive)
- Removedbabel-plugin-constant-folding@1.0.1(transitive)
- Removedbabel-plugin-dead-code-elimination@1.0.2(transitive)
- Removedbabel-plugin-eval@1.0.1(transitive)
- Removedbabel-plugin-inline-environment-variables@1.0.1(transitive)
- Removedbabel-plugin-jscript@1.0.4(transitive)
- Removedbabel-plugin-member-expression-literals@1.0.1(transitive)
- Removedbabel-plugin-property-literals@1.0.1(transitive)
- Removedbabel-plugin-proto-to-assign@1.0.4(transitive)
- Removedbabel-plugin-react-constant-elements@1.0.3(transitive)
- Removedbabel-plugin-react-display-name@1.0.3(transitive)
- Removedbabel-plugin-remove-console@1.0.1(transitive)
- Removedbabel-plugin-remove-debugger@1.0.1(transitive)
- Removedbabel-plugin-runtime@1.0.7(transitive)
- Removedbabel-plugin-undeclared-variables-check@1.0.2(transitive)
- Removedbabel-plugin-undefined-to-void@1.1.6(transitive)
- Removedbabylon@5.8.38(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbinary-extensions@1.13.1(transitive)
- Removedbindings@1.5.0(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbraces@1.8.52.3.2(transitive)
- Removedbreakable@1.0.0(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedcamelcase@1.2.1(transitive)
- Removedcenter-align@0.1.3(transitive)
- Removedchokidar@1.7.0(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcliui@2.1.0(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcommoner@0.10.8(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removedcore-js@1.2.7(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@0.2.51.0.02.0.2(transitive)
- Removeddefined@1.0.1(transitive)
- Removeddefs@1.1.1(transitive)
- Removeddetect-indent@3.0.1(transitive)
- Removeddetective@4.7.1(transitive)
- Removedesprima@2.7.33.1.3(transitive)
- Removedesprima-fb@15001.1001.0-dev-harmony-fb(transitive)
- Removedesutils@2.0.3(transitive)
- Removedexpand-brackets@0.1.52.1.4(transitive)
- Removedexpand-range@1.8.2(transitive)
- Removedextend-shallow@2.0.13.0.2(transitive)
- Removedextglob@0.3.22.0.4(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedfilename-regex@2.0.1(transitive)
- Removedfill-range@2.2.44.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedfs-readdir-recursive@0.1.2(transitive)
- Removedfsevents@1.2.13(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedget-value@2.0.6(transitive)
- Removedglob@5.0.15(transitive)
- Removedglob-base@0.3.0(transitive)
- Removedglob-parent@2.0.0(transitive)
- Removedglobals@6.4.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhome-or-tmp@1.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-binary-path@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-dotfile@1.0.3(transitive)
- Removedis-equal-shallow@0.1.3(transitive)
- Removedis-extendable@0.1.11.0.1(transitive)
- Removedis-extglob@1.0.0(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-glob@2.0.1(transitive)
- Removedis-integer@1.0.7(transitive)
- Removedis-number@2.1.03.0.04.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-posix-bracket@0.1.1(transitive)
- Removedis-primitive@2.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedjs-tokens@1.0.1(transitive)
- Removedjsesc@0.5.0(transitive)
- Removedjson5@0.4.0(transitive)
- Removedkind-of@3.2.24.0.06.0.3(transitive)
- Removedlazy-cache@1.0.4(transitive)
- Removedlcid@1.0.0(transitive)
- Removedleven@1.0.2(transitive)
- Removedlodash@3.10.1(transitive)
- Removedlongest@1.0.1(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmath-random@1.0.4(transitive)
- Removedmicromatch@2.3.113.1.10(transitive)
- Removedminimatch@2.0.10(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednan@2.22.0(transitive)
- Removednanomatch@1.2.13(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.omit@2.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedoutput-file-sync@1.1.2(transitive)
- Removedparse-glob@3.0.4(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedpath-exists@1.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedpreserve@0.2.0(transitive)
- Removedprivate@0.1.8(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedq@1.5.1(transitive)
- Removedrandomatic@3.1.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedreaddirp@2.2.1(transitive)
- Removedrecast@0.10.330.11.23(transitive)
- Removedregenerate@1.4.2(transitive)
- Removedregenerator@0.8.40(transitive)
- Removedregex-cache@0.4.4(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedregexpu@1.3.0(transitive)
- Removedregjsgen@0.2.0(transitive)
- Removedregjsparser@0.1.5(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedrepeating@1.1.3(transitive)
- Removedresolve@1.22.8(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedret@0.1.15(transitive)
- Removedright-align@0.1.3(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedset-value@2.0.1(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsimple-fmt@0.1.0(transitive)
- Removedsimple-is@0.2.0(transitive)
- Removedslash@1.0.0(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.1.320.5.7(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-support@0.2.10(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstable@0.1.8(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstringmap@0.2.2(transitive)
- Removedstringset@0.2.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedto-fast-properties@1.0.3(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedtrim-right@1.0.1(transitive)
- Removedtry-resolve@1.0.1(transitive)
- Removedtryor@0.1.2(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
- Removeduser-home@1.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedwordwrap@0.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@3.27.0(transitive)
Updatedremotestoragejs@github:remotestorage/remotestorage.js#v1.0.0-rc1