New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cocreate/cocreatews

Package Overview
Dependencies
Maintainers
1
Versions
245
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cocreate/cocreatews - npm Package Compare versions

Comparing version 0.7.1 to 0.8.0

src/helpers/archive/utils.1.js

7

CHANGELOG.md

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

# [0.8.0](https://github.com/CoCreate-app/CoCreateWS/compare/v0.7.1...v0.8.0) (2021-05-05)
### Features
* permissions listens to change and updates document in memory ([7f9d07e](https://github.com/CoCreate-app/CoCreateWS/commit/7f9d07ef0202128260af94d4a98140ede17378e4))
## [0.7.1](https://github.com/CoCreate-app/CoCreateWS/compare/v0.7.0...v0.7.1) (2021-04-23)

@@ -2,0 +9,0 @@

@@ -7,3 +7,11 @@ {

"port": 6379
},
"jwttoken": {
"key": "aaIbx6W0366Mm6NXrPQb1k3Hg3sRxd1B",
"options": {
"algorithm": "HS256",
"expiresIn": "2 days",
"issuer": "issuer"
}
}
}

4

package.json
{
"name": "@cocreate/cocreatews",
"version": "0.7.1",
"version": "0.8.0",
"description": "CoCreateWS",

@@ -51,5 +51,7 @@ "keywords": [

"json-2-csv": "^3.7.6",
"mime-types": "^2.1.30",
"mongodb": "^3.5.8",
"node-html-parser": "^3.2.0",
"querystring": "^0.2.0"
}
}

@@ -8,20 +8,17 @@

const CoCreateMetricsServer = require('@cocreate/metrics-server')
const CoCreateAuth = require('@cocreate/auth')
const ServerPermission = require("./permission.js")
module.exports.init = async function(manager) {
try {
let db_client = await MongoClient.connect(config.db_url, { useNewUrlParser: true, poolSize: 10 });
let permission = new ServerPermission(db_client)
let auth = new CoCreateAuth(config.jwttoken)
manager.setPermission(permission)
manager.setAuth(auth)
CoCreateCrudServer.init(manager, db_client)
CoCreateMessageServer.init(manager, db_client);
CoCreateMetricsServer.init(manager, db_client)
let permission = new ServerPermission(db_client)
return {
status: true,
instances: {
crudserver: CoCreateCrudServer,
messageserver: CoCreateMessageServer,
metricsserver: CoCreateMessageServer,
permission: permission
}
}
// return true;

@@ -28,0 +25,0 @@ } catch (error) {

@@ -58,28 +58,5 @@ const connection = require('./dbConnection.js');

try {
const db = await connection(dbName); // obtenemos la conexión
/*console.log(" before")
db.listCollections().toArray(function (err, collectionInfos) {
console.log(collectionInfos);
});*/
/* var myobj = { domains: ["server.cocreate.app","cocreate.app"], route: '/test/twiml', collection: "module_activities", document_id: '5ee3937ce3fc3a5b7493dc37' ,name : 'xml',content_type : 'text/xml'};
db.collection("routes").insertOne(myobj, function(err, res) {
if (err) throw err;
console.log("1 document inserted");
});
*/
//console.log("-- Await ",await db.getCollectionNames())
const collection = db.collection('routes');
//console.log(" collection ",collection)
// db.routes.findOne({domains: { $in: [hostname] } , route : route_uri});
console.log("REturn ---")
return await collection.findOne({domains: { $in: [data["hostname"]] } , route : data["route_uri"]});
const db = await connection(dbName); // obtenemos la conexión
const collection = db.collection('files');
return await collection.findOne({domains: { $in: [data["hostname"]] } , "path" : data["route_uri"]});
//return await collection.findOne({domains: { $in: [data["hostname"]] } , route : data["route_uri"]});

@@ -86,0 +63,0 @@ }catch(e){

@@ -10,2 +10,3 @@ const CoCreatePermission = require('@cocreate/permissions');

this.dbClient = db_client;
this.initEvent()
}

@@ -18,9 +19,21 @@

organization_id,
key: 'collections',
key_value: collection,
type: action
collection,
plugin: 'messages',
type: action,
}
}
async getPermissionObject(key, organization_id) {
initEvent() {
const self = this;
process.on('changed-document', async (data) => {
const {collection, document_id, organization_id, data : permissionData } = data
if (collection === 'permissions' && self.hasPermission(permissionData.key)) {
let new_permission = await self.getPermissionObject(permissionData.key, organization_id, permissionData.type)
self.setPermissionObject(permissionData.key, new_permission)
}
})
}
async getPermissionObject(key, organization_id, type) {

@@ -42,4 +55,4 @@ try {

let permission = await collection.findOne({
apikey: key,
type: 'apikey'
key,
type: type || 'apikey'
});

@@ -68,6 +81,8 @@

}
console.log('WS permission fetch data----', permission)
// console.log('WS permission fetch data----', permission)
return permission;
} catch (error) {
console.log("Error en permission")
return null;

@@ -74,0 +89,0 @@ }

@@ -6,66 +6,92 @@ var express = require('express');

var fs = require('fs');
const mime = require('mime-types')
const render = require('./render');
router.get('/*', async (req, res, next) => {
console.log("GetRoutes by organization")
let hostname = req.hostname;
let url = req.url;
let route_uri = url.split(req.hostname)[0];
let masterDB = '5ae0cfac6fb8c4e656fdaf92'
route_uri = route_uri.indexOf('?') ? route_uri.split('?')[0] : route_uri
/**
* <write a short decription>
*
* 1. with hostname we query a master db in order to find the organization_id...
* with the org id we can now query for the uri in collection "files" and return value for fieldName "src"
* 2. in db we store path as /docs/dnd but need something more flexible so we can respond even if request /docs/dnd/
*
* */
const masterDB = '5ae0cfac6fb8c4e656fdaf92'
router.get('/*', async(req, res, next) => {
let hostname = req.hostname;
let organization = await utils.organizationsfindOne({ domains: hostname }, masterDB)
if (!organization)
return res.send('Organization cannot be found using the domain:' + hostname);
let organization = await utils.organizationsfindOne({domains:hostname},masterDB)
if(organization == null) {
res.send('Organization cannot be found using the domain:'+hostname);
return null;
} else {
let organization_id = organization._id.toString();
route_uri = route_uri.indexOf('/ws') != -1 ? route_uri.substr(3) : route_uri;
let route = await utils.routesfindOne({hostname:hostname , route_uri : route_uri },organization_id);
console.log(organization, hostname, route_uri,route);
if (route != null){
var route_export = await utils.getDocument({
'collection':route['collection'],
'document_id':route['document_id']
}, organization_id);
if (route_export != null) {
let content_type = '';
let is_file = route['is_file'];
let ext = path.extname(route_uri).substr(1);
if (!is_file) {
switch(ext){
case 'css':
content_type = 'text/css'
break;
case 'js':
content_type = 'text/javascript'
break;
case 'xml':
content_type = 'text/xml'
break;
default:
content_type = 'text/html'
}
res.type(content_type);
res.send(route_export[route['name']]);
} else {
// let content_type = route['content_type'] || "image/png";
let file = Buffer.from(route_export[route['name']], 'base64');
// res.set('Content-Type', content_type);
res.send(file);
}
}
else {
res.send('Document provided by routes could not be found in collection: '+route['collection'] + ' document_id: '+route['document_id']);
}
let url = req.url;
if (url.endsWith('/'))
url = url.substring(0, url.length - 1);
url = url.startsWith('/ws') ? url.substr(3) : url; // dev
// console.log('>>>>>>>>>>>>>', url, organization)
let organization_id = organization._id.toString();
let route_files = await utils.routesfindOne({ hostname: hostname, route_uri: url }, organization_id);
if (!route_files)
return res.send(`there is no ${url} in masterDb ${organization_id} `);
let data;
if (route_files['src'])
data = route_files['src'];
else {
let route_export = await utils.getDocument({
collection: route_files['collection'],
document_id: route_files['document_id']
}, organization_id);
data = route_export[route_files['name']];
}
if (!data) {
res.send('Document provided by routes could not be found and has no src ');
}
let content_type = route_files['content_type'] ||
mime.lookup(url) ||
'text/html';
console.log('(>>>>>>>>>>>>>>', content_type, route_files['content_type'], route_files['route'])
if (content_type.startsWith('image/') || content_type.startsWith('audio/') || content_type.startsWith('video/')) {
// let content_type = route['content_type'] || "image/png";
// todo: is there are better alternative or conevention not to process base64
let file = Buffer.from(data, 'base64');
res.set('Content-Type', content_type);
res.send(file);
}
else if (content_type === 'text/html') {
try {
let fullHtml = await render(data, organization_id);
res.type(content_type);
res.send(fullHtml);
}
else {
res.send('Organization could not be found for ['+hostname+'] in masterDb ['+organization_id+'] ');
catch (err) {
if (err.message.startsWith('infinite loop:'))
return res.send('there is a infinite loop');
else
return res.send('something is wrong')
}
}
else {
res.type(content_type);
res.send(data);
}
});
module.exports = router;

@@ -35,7 +35,8 @@ 'use strict';

adapter.init(socketManager).then(({status, instances}) => {
if (status && instances) {
socketManager.setPermission(instances.permission)
}
})
adapter.init(socketManager)
// .then(({status, instances}) => {
// if (status && instances) {
// socketManager.setPermission(instances.permission)
// }
// })

@@ -42,0 +43,0 @@ const server = createServer(app);

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