remotestorage-module-chat-messages
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -1,1 +0,2 @@ | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var s=n[r]={exports:{},id:r,loaded:!1};return t[r].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e){"use strict";function n(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}Object.defineProperty(e,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=function(t,e){var s={type:"object",properties:{"@context":{type:"string",default:"https://kosmos.org/ns/v1",enum:["https://kosmos.org/ns/v1"]},"@id":{type:"string",required:!0},"@type":{type:"string",default:"ChatChannel",enum:["ChatChannel"]},name:{type:"string",required:!0},ircURI:{type:"string",format:"uri"},xmppURI:{type:"string",format:"uri"},today:{type:"object",properties:{"@id":{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$",required:!0},"@type":{type:"string",default:"ChatLog",pattern:"^ChatLog$"},messageType:{type:"string",default:"InstantMessage",pattern:"^InstantMessage$"},previous:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},next:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},messages:{type:"array",required:!0,items:{type:"object",properties:{date:{type:"string",format:"date-time"},user:{type:"string"},text:{type:"string"},type:"string",default:"text",enum:["text","join","leave","action"]}}}}}},required:[]};t.declareType("daily-archive","https://kosmos.org/ns/v1",s),e.declareType("daily-archive","https://kosmos.org/ns/v1",s);var i=function(n){if(n.isPublic=n.isPublic||!1,"object"!==("undefined"==typeof n?"undefined":r(n)))throw"options must be an object";if("object"!==r(n.server)||"string"!=typeof n.server.type||"string"!=typeof n.server.name)throw'server must be an object containing at least server "type" and "name"';if("string"!=typeof n.channelName)throw"channelName must be a string";if(!(n.date instanceof Date))throw"date must be a date object";if("boolean"!=typeof n.isPublic)throw"isPublic must be a boolean value";switch(this.server=n.server,this.channelName=n.channelName,this.date=n.date,this.isPublic=n.isPublic,this.parsedDate=o(this.date),this.dateId=this.parsedDate.year+"/"+this.parsedDate.month+"/"+this.parsedDate.day,this.server.type){case"irc":if(this.channelName.match(/^#/)){var s=this.channelName.replace(/^#/,"");this.path=this.server.name+"/channels/"+s+"/"+this.dateId}else this.path=this.server.name+"/users/"+this.channelName+"/"+this.dateId;break;default:this.path=this.server.name+"/"+this.channelName+"/"+this.dateId}this.client=this.isPublic?e:t,this.previous=n.previous,this.next=n.next};i.prototype={addMessage:function(t){var e=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(t.type=t.type||"text",this.client.getObject(this.path).then(function(n){return"object"===("undefined"==typeof n?"undefined":r(n))?e._updateDocument(n,t):e._createDocument(t)}))},addMessages:function(t,e){var n=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(e=e||!1,t.forEach(function(t){t.type=t.type||"text"}),e?this._createDocument(t):this.client.getObject(this.path).then(function(e){return"object"===("undefined"==typeof e?"undefined":r(e))?n._updateDocument(e,t):n._createDocument(t)}))},remove:function(){return this.client.remove(this.path)},_updateDocument:function(t,e){return console.debug("[chat-messages] Updating archive document",t),Array.isArray(e)?e.forEach(function(e){t.today.messages.push(e)}):t.today.messages.push(e),this._sync(t)},_createDocument:function(t){var e=this;console.debug("[chat-messages] Creating new archive document");var n=this._buildArchiveObject();return Array.isArray(t)?t.forEach(function(t){n.today.messages.push(t)}):n.today.messages.push(t),this.previous||this.next?(this.previous&&(n.today.previous=this.previous),this.next&&(n.today.next=this.next),this._sync(n)):this._updatePreviousArchive().then(function(t){return"object"===("undefined"==typeof t?"undefined":r(t))&&(n.today.previous=t.today["@id"]),e._sync(n)})},_buildArchiveObject:function(){var t=this.channelName.replace(/#/,""),e={"@id":"chat-messages/"+this.server.name+"/channels/"+t+"/","@type":"ChatChannel",name:this.channelName,today:{"@id":this.dateId,"@type":"ChatLog",messageType:"InstantMessage",messages:[]}};switch(this.server.type){case"irc":this.channelName.match(/^#/)||(e["@id"]="chat-messages/"+this.server.name+"/users/"+this.channelName+"/"),e.ircURI=this.server.ircURI+"/"+t;break;case"xmpp":e.xmppURI="xmpp:"+this.channelName+"@"+this.server.xmppMUC}return e},_updatePreviousArchive:function(){var t=this;return this._findPreviousArchive().then(function(e){if("object"===("undefined"==typeof e?"undefined":r(e))&&e.today){e.today.next=t.dateId;var n=t.path.substring(0,t.path.length-t.dateId.length)+e.today["@id"];return t.client.storeObject("daily-archive",n,e).then(function(){return console.debug("[chat-messages] Previous archive written to remote storage",n,e),e})}return console.debug("[chat-messages] Previous archive not found"),!1})},_findPreviousArchive:function(){var t=this,e=this.path.substring(0,this.path.length-2),r=this.path.substring(0,this.path.length-5),s=this.path.substring(0,this.path.length-10);return this.client.getListing(e).then(function(i){var o=Object.keys(i).map(function(t){return parseInt(t)}).map(function(e){return e<parseInt(t.parsedDate.day)?e:null}).filter(function(t){return null!=t});if(o.length>0){var u=a(Math.max.apply(Math,n(o)).toString());return t.client.getObject(e+u)}return t.client.getListing(r).then(function(e){var i=Object.keys(e).map(function(t){return parseInt(t.substr(0,2))}).map(function(e){return e<parseInt(t.parsedDate.month)?e:null}).filter(function(t){return null!=t});if(i.length>0){var o=a(Math.max.apply(Math,n(i)).toString());return t.client.getListing(r+o+"/").then(function(e){var s=Object.keys(e).map(function(t){return parseInt(t)}),i=a(Math.max.apply(Math,n(s)).toString());return t.client.getObject(r+o+"/"+i)})}return t.client.getListing(s).then(function(e){var r=Object.keys(e).map(function(t){return parseInt(t.substr(0,4))}).map(function(e){return e<parseInt(t.parsedDate.year)?e:null}).filter(function(t){return null!=t});if(r.length>0){var i=Math.max.apply(Math,n(r)).toString();return t.client.getListing(s+i+"/").then(function(e){var r=Object.keys(e).map(function(t){return parseInt(t.substr(0,2))}),o=a(Math.max.apply(Math,n(r)).toString());return t.client.getListing(s+i+"/"+o+"/").then(function(e){var r=Object.keys(e).map(function(t){return parseInt(t)}),u=a(Math.max.apply(Math,n(r)).toString());return t.client.getObject(s+i+"/"+o+"/"+u)})})}return!1})})})},_sync:function(t){return console.debug("[chat-messages] Writing archive object",t),this.client.storeObject("daily-archive",this.path,t).then(function(){return console.debug("[chat-messages] Archive written to remote storage"),!0},function(t){return console.warn("[chat-messages] Error trying to store object",t),t})}};var a=function(t){return t=String(t),1===t.length&&(t="0"+t),t},o=function(t){return{year:t.getUTCFullYear(),month:a(t.getUTCMonth()+1),day:a(t.getUTCDate())}},u={DailyArchive:i,privateClient:t,publicClient:e};return{exports:u}};e.default={name:"chat-messages",builder:s}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("ChatMessages",[],e):"object"==typeof exports?exports.ChatMessages=e():t.ChatMessages=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function n(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function s(t){return 1===(t=String(t)).length&&(t="0"+t),t}t.d(e,{default:()=>o});const o={name:"chat-messages",builder:function(t,e){var r={type:"object",properties:{"@context":{type:"string",default:"https://kosmos.org/ns/v2",enum:["https://kosmos.org/ns/v2"]},"@id":{type:"string",required:!0},"@type":{type:"string",default:"ChatChannel",enum:["ChatChannel"]},service:{type:"object",properties:{domain:{type:"string",required:!0},protocol:{type:"string",required:!0}}},name:{type:"string",required:!0},type:{type:"string",required:!0,enum:["room","person"]},today:{type:"object",properties:{"@id":{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$",required:!0},"@type":{type:"string",default:"ChatLog",pattern:"^ChatLog$"},messageType:{type:"string",default:"InstantMessage",pattern:"^InstantMessage$"},previous:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},next:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},messages:{type:"array",required:!0,items:{type:"object",properties:{date:{type:"string",format:"date-time"},user:{type:"string"},text:{type:"string"},type:"string",default:"text",enum:["text","join","leave","action"]}}}}}},required:[]};return t.declareType("daily-archive","https://kosmos.org/ns/v2",r),e.declareType("daily-archive","https://kosmos.org/ns/v2",r),{exports:{DailyArchive:function(){function r(n){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),n.isPublic=n.isPublic||!1,n.channelType=n.channelType||"room","object"!==a(n))throw"options must be an object";if("object"!==a(n.service)||"string"!=typeof n.service.protocol||"string"!=typeof n.service.domain)throw'service must be an object containing at least service "protocol" and "domain"';if("string"!=typeof n.channelName)throw"channelName must be a string";if(!(n.date instanceof Date))throw"date must be a date object";if("boolean"!=typeof n.isPublic)throw"isPublic must be a boolean value";var i;if(this.service=n.service,this.channelName=n.channelName,this.channelType=n.channelType,this.date=n.date,this.isPublic=n.isPublic||!1,this.parsedDate={year:(i=this.date).getUTCFullYear(),month:s(i.getUTCMonth()+1),day:s(i.getUTCDate())},this.dateId=this.parsedDate.year+"/"+this.parsedDate.month+"/"+this.parsedDate.day,"room"===this.channelType){var o=this.channelName.replace(/#/,"");this.path="".concat(this.service.domain,"/channels/").concat(o,"/").concat(this.dateId)}else this.path="".concat(this.service.domain,"/users/").concat(this.channelName,"/").concat(this.dateId);this.client=this.isPublic?e:t,this.previous=n.previous,this.next=n.next}var o,c;return o=r,(c=[{key:"addMessage",value:function(t){var e=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(t.type=t.type||"text",this.client.getObject(this.path).then((function(n){return"object"===a(n)?e._updateDocument(n,t):e._createDocument(t)})))}},{key:"addMessages",value:function(t,e){var n=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(e=e||!1,t.forEach((function(t){t.type=t.type||"text"})),e?this._createDocument(t):this.client.getObject(this.path).then((function(e){return"object"===a(e)?n._updateDocument(e,t):n._createDocument(t)})))}},{key:"remove",value:function(){return this.client.remove(this.path)}},{key:"_updateDocument",value:function(t,e){return console.debug("[chat-messages] Updating archive document"),Array.isArray(e)?e.forEach((function(e){t.today.messages.push(e)})):t.today.messages.push(e),this._sync(t)}},{key:"_createDocument",value:function(t){var e=this;console.debug("[chat-messages] Creating new archive document");var n=this._buildArchiveObject();return Array.isArray(t)?t.forEach((function(t){n.today.messages.push(t)})):n.today.messages.push(t),this.previous||this.next?(this.previous&&(n.today.previous=this.previous),this.next&&(n.today.next=this.next),this._sync(n)):this._updatePreviousArchive().then((function(t){return"object"===a(t)&&(n.today.previous=t.today["@id"]),e._sync(n)}))}},{key:"_buildArchiveObject",value:function(){var t=this.channelName.replace(/#/,""),e={"@id":"chat-messages/"+this.service.domain+"/channels/"+t+"/","@type":"ChatChannel",service:this.service,name:this.channelName,type:this.channelType,today:{"@id":this.dateId,"@type":"ChatLog",messageType:"InstantMessage",messages:[]}};switch(this.service.protocol){case"IRC":this.channelName.match(/^#/)||(e["@id"]="chat-messages/"+this.service.domain+"/users/"+this.channelName+"/")}return e}},{key:"_updatePreviousArchive",value:function(){var t=this;return this._findPreviousArchive().then((function(e){if("object"===a(e)&&e.today){e.today.next=t.dateId;var n=t.path.substring(0,t.path.length-t.dateId.length)+e.today["@id"];return t.client.storeObject("daily-archive",n,e).then((function(){return console.debug("[chat-messages] Previous archive written to remote storage",n,e),e}))}return console.debug("[chat-messages] Previous archive not found"),!1}))}},{key:"_findPreviousArchive",value:function(){var t=this,e=this.path.substring(0,this.path.length-2),r=this.path.substring(0,this.path.length-5),a=this.path.substring(0,this.path.length-10);return this.client.getListing(e).then((function(i){var o=Object.keys(i).map((function(t){return parseInt(t)})).map((function(e){return e<parseInt(t.parsedDate.day)?e:null})).filter((function(t){return null!=t}));if(o.length>0){var c=s(Math.max.apply(Math,n(o)).toString());return t.client.getObject(e+c)}return t.client.getListing(r).then((function(e){var i=Object.keys(e).map((function(t){return parseInt(t.substr(0,2))})).map((function(e){return e<parseInt(t.parsedDate.month)?e:null})).filter((function(t){return null!=t}));if(i.length>0){var o=s(Math.max.apply(Math,n(i)).toString());return t.client.getListing(r+o+"/").then((function(e){var a=Object.keys(e).map((function(t){return parseInt(t)})),i=s(Math.max.apply(Math,n(a)).toString());return t.client.getObject(r+o+"/"+i)}))}return t.client.getListing(a).then((function(e){var r=Object.keys(e).map((function(t){return parseInt(t.substr(0,4))})).map((function(e){return e<parseInt(t.parsedDate.year)?e:null})).filter((function(t){return null!=t}));if(r.length>0){var i=Math.max.apply(Math,n(r)).toString();return t.client.getListing(a+i+"/").then((function(e){var r=Object.keys(e).map((function(t){return parseInt(t.substr(0,2))})),o=s(Math.max.apply(Math,n(r)).toString());return t.client.getListing(a+i+"/"+o+"/").then((function(e){var r=Object.keys(e).map((function(t){return parseInt(t)})),c=s(Math.max.apply(Math,n(r)).toString());return t.client.getObject(a+i+"/"+o+"/"+c)}))}))}return!1}))}))}))}},{key:"_sync",value:function(t){return console.debug("[chat-messages] Writing archive object with ".concat(t.today.messages.length," messages")),this.client.storeObject("daily-archive",this.path,t).then((function(){return console.debug("[chat-messages] Archive written to remote storage"),!0}),(function(t){return console.warn("[chat-messages] Error trying to store object",t),t}))}}])&&i(o.prototype,c),r}(),privateClient:t,publicClient:e}}}};return e.default})()})); | ||
//# sourceMappingURL=build.js.map |
{ | ||
"name": "remotestorage-module-chat-messages", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Stores chat messages in daily archive files", | ||
"main": "./dist/build.js", | ||
"scripts": { | ||
"build": "NODE_ENV=production webpack", | ||
"dev": "webpack -w", | ||
"start": "npm run dev", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"dev": "webpack -w", | ||
"build": "NODE_ENV=production webpack -p", | ||
"version": "npm run build && git add dist/" | ||
}, | ||
"author": "Kosmos Developers <mail@kosmos.org> (https://kosmos.org)", | ||
"contributors": [ | ||
"Sebastian Kippe <sebastian@kip.pe>" | ||
], | ||
"author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)", | ||
"license": "MIT", | ||
"homepage": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/67P/remotestorage-module-chat-messages.git" | ||
"url": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages.git" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.18.2", | ||
"babel-loader": "^6.2.7", | ||
"babel-preset-es2015": "^6.18.0", | ||
"webpack": "^1.13.2" | ||
"@babel/core": "^7.14.8", | ||
"@babel/preset-env": "^7.14.9", | ||
"babel-loader": "^8.2.2", | ||
"webpack": "^5.48.0", | ||
"webpack-cli": "^4.8.0" | ||
} | ||
} |
@@ -7,17 +7,35 @@ [![Release](https://img.shields.io/npm/v/remotestorage-module-chat-messages.svg?style=flat)](https://github.com/67P/remotestorage-module-chat-messages/releases) | ||
Please feel free to open GitHub issues for questions, feature requests, | ||
protocol proposals, and whatever else you like. | ||
## Usage | ||
## Protocols | ||
Open a daily archive and write messages to it: | ||
### Currently supported | ||
```js | ||
const RemoteStorage = require("remotestoragejs"); | ||
const ChatMessages = require("remotestorage-module-chat-messages"); | ||
const remoteStorage = new RemoteStorage({ modules: [ ChatMessages ] }); | ||
* IRC | ||
* XMPP | ||
const archive = new remoteStorage.chatMessages.DailyArchive({ | ||
service: { | ||
protocol: 'IRC', | ||
domain: 'irc.libera.chat' | ||
}, | ||
channelName: '#kosmos', | ||
date: new Date(), | ||
isPublic: true // Channel logs will be written to public folder | ||
}); | ||
### Planned | ||
const messages = [ | ||
{ "date": "2015-06-05T17:35:28.454Z", "user": "jimmy", "text": "knock knock" }, | ||
{ "date": "2015-06-05T17:36:05.123Z", "user": "walter", "text": "who's there?" } | ||
]; | ||
* Mattermost | ||
* Matrix | ||
* Slack | ||
* ... | ||
archive.addMessages(messages); | ||
``` | ||
See the inline source code documentation (JSDoc) for usage details and function | ||
arguments. For a real-world integration example, see | ||
[hubot-remotestorage-logger](https://github.com/67P/hubot-remotestorage-logger/). | ||
## Support, bugs, feedback, questions | ||
Come and chat with us: https://wiki.kosmos.org/Main_Page#Chat |
@@ -1,24 +0,33 @@ | ||
var webpack = require('webpack'); | ||
var isProd = (process.env.NODE_ENV === 'production'); | ||
/* global __dirname */ | ||
const isProd = (process.env.NODE_ENV === 'production'); | ||
const path = require('path'); | ||
// minimize only in production | ||
var plugins = isProd ? [new webpack.optimize.UglifyJsPlugin({minimize: true })] : [] | ||
module.exports = { | ||
entry: './index.js', | ||
// source map not in production | ||
devtool: !isProd && 'source-map', | ||
entry: ['./src/chat-messages.js'], | ||
output: { | ||
filename: __dirname + '/dist/build.js', | ||
libraryTarget: 'umd' | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: 'build.js', | ||
library: 'ChatMessages', | ||
libraryTarget: 'umd', | ||
libraryExport: 'default', | ||
umdNamedDefine: true, | ||
globalObject: 'this' | ||
}, | ||
mode: isProd ? 'production' : 'development', | ||
devtool: isProd ? 'source-map' : 'eval-source-map', | ||
module: { | ||
loaders: [ | ||
{ test: /\.js$/, exclude: '/node_modules|dist/', loader: 'babel?presets[]=es2015' }, | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: ['@babel/preset-env'] | ||
} | ||
} | ||
}, | ||
] | ||
}, | ||
resolve: { | ||
extensions: ['', '.js'] | ||
}, | ||
plugins: plugins | ||
// plugins: plugins | ||
}; |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance 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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
585
1
41
57163
5
1