Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remotestorage-module-chat-messages

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remotestorage-module-chat-messages - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

dist/build.js

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

!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 i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.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},i=function(t,e){var i={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",i),e.declareType("daily-archive","https://kosmos.org/ns/v1",i);var s=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 i=this.channelName.replace(/^#/,"");this.path=this.server.name+"/channels/"+i+"/"+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};s.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 RemoteStorage.log("[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;RemoteStorage.log("[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 RemoteStorage.log("[chat-messages] Previous archive written to remote storage",n,e),e})}return RemoteStorage.log("[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),i=this.path.substring(0,this.path.length-10);return this.client.getListing(e).then(function(s){var o=Object.keys(s).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 h=a(Math.max.apply(Math,n(o)).toString());return t.client.getObject(e+h)}return t.client.getListing(r).then(function(e){var s=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(s.length>0){var o=a(Math.max.apply(Math,n(s)).toString());return t.client.getListing(r+o+"/").then(function(e){var i=Object.keys(e).map(function(t){return parseInt(t)}),s=a(Math.max.apply(Math,n(i)).toString());return t.client.getObject(r+o+"/"+s)})}return t.client.getListing(i).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 s=Math.max.apply(Math,n(r)).toString();return t.client.getListing(i+s+"/").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(i+s+"/"+o+"/").then(function(e){var r=Object.keys(e).map(function(t){return parseInt(t)}),h=a(Math.max.apply(Math,n(r)).toString());return t.client.getObject(i+s+"/"+o+"/"+h)})})}return!1})})})},_sync:function(t){return RemoteStorage.log("[chat-messages] Writing archive object",t),this.client.storeObject("daily-archive",this.path,t).then(function(){return RemoteStorage.log("[chat-messages] Archive written to remote storage"),!0},function(t){return console.log("[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())}},h={DailyArchive:s,privateClient:t,publicClient:e};return{exports:h}};e.default={name:"chat-messages",builder:i}}])});
!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}}])});

@@ -363,3 +363,3 @@ var ChatMessages = function (privateClient, publicClient) {

_updateDocument: function(archive, messages) {
RemoteStorage.log('[chat-messages] Updating archive document', archive);
console.debug('[chat-messages] Updating archive document', archive);

@@ -383,3 +383,3 @@ if (Array.isArray(messages)) {

_createDocument: function(messages) {
RemoteStorage.log('[chat-messages] Creating new archive document');
console.debug('[chat-messages] Creating new archive document');
let archive = this._buildArchiveObject();

@@ -459,7 +459,7 @@

return this.client.storeObject('daily-archive', path, archive).then(() => {
RemoteStorage.log('[chat-messages] Previous archive written to remote storage', path, archive);
console.debug('[chat-messages] Previous archive written to remote storage', path, archive);
return archive;
});
} else {
RemoteStorage.log('[chat-messages] Previous archive not found');
console.debug('[chat-messages] Previous archive not found');
return false;

@@ -540,9 +540,9 @@ }

_sync: function(obj) {
RemoteStorage.log('[chat-messages] Writing archive object', obj);
console.debug('[chat-messages] Writing archive object', obj);
return this.client.storeObject('daily-archive', this.path, obj).then(function(){
RemoteStorage.log('[chat-messages] Archive written to remote storage');
console.debug('[chat-messages] Archive written to remote storage');
return true;
},function(error){
console.log('[chat-messages] Error trying to store object', error);
console.warn('[chat-messages] Error trying to store object', error);
return error;

@@ -549,0 +549,0 @@ });

{
"name": "remotestorage-module-chat-messages",
"version": "1.0.0",
"version": "1.0.1",
"description": "Stores chat messages in daily archive files",

@@ -5,0 +5,0 @@ "main": "./dist/build.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc