@cocreate/crud-server
Advanced tools
Comparing version
@@ -0,1 +1,14 @@ | ||
# [1.19.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.18.0...v1.19.0) (2023-04-11) | ||
### Bug Fixes | ||
* renamed domans to hosts ([312353a](https://github.com/CoCreate-app/CoCreate-crud-server/commit/312353a9ec03d65b05d749675db9c73a1e16e069)) | ||
### Features | ||
* custom dburls stored and fetched from platform db organizations. sync fields from org and user to platform prototype ([183839b](https://github.com/CoCreate-app/CoCreate-crud-server/commit/183839b02655ac4d7edf24375b9012ad80feeee9)) | ||
* if dbUrls not defined query platform db ([05fecfe](https://github.com/CoCreate-app/CoCreate-crud-server/commit/05fecfe999f471541717765e606aa57649398821)) | ||
# [1.18.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.17.29...v1.18.0) (2023-03-19) | ||
@@ -2,0 +15,0 @@ |
@@ -15,3 +15,3 @@ module.exports = { | ||
"src": "{{./docs/index.html}}", | ||
"domains": [ | ||
"hosts": [ | ||
"*", | ||
@@ -18,0 +18,0 @@ "general.cocreate.app" |
{ | ||
"name": "@cocreate/crud-server", | ||
"version": "1.18.0", | ||
"version": "1.19.0", | ||
"description": "CoCreate-crud-server", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
106
src/index.js
@@ -10,2 +10,3 @@ 'use strict'; | ||
this.ObjectId = ObjectId | ||
this.databaseUrls = new Map(); | ||
this.init(); | ||
@@ -99,2 +100,35 @@ } | ||
try { | ||
if (!data.organization_id) | ||
resolve() | ||
let dbUrl = this.databaseUrls.get(data.organization_id) | ||
if (dbUrl == 'false') | ||
resolve() | ||
if (!dbUrl) { | ||
if (data.organization_id === process.env.organization_id) { | ||
dbUrl = {mongodb: [process.env.MONGO_URL]} | ||
console.log('platform dbUrl crud', dbUrl) | ||
this.databaseUrls.set(data.organization_id, dbUrl) | ||
} else { | ||
let organization = await this.databases['mongodb']['readDocument']({ | ||
database: process.env.organization_id, | ||
collection: 'organizations', | ||
document: [{_id: data.organization_id}], | ||
organization_id: process.env.organization_id | ||
}) | ||
if (organization && organization.document && organization.document[0]) | ||
organization = organization.document[0] | ||
if (organization && organization.databases) { | ||
dbUrl = organization.databases | ||
this.databaseUrls.set(data.organization_id, dbUrl) | ||
console.log('organization dbUrl queried from platform') | ||
} else { | ||
this.databaseUrls.set(data.organization_id, 'false') | ||
console.log('organization or dbUrl urls could not be found') | ||
resolve() | ||
} | ||
} | ||
} | ||
if (!data['timeStamp']) | ||
@@ -105,11 +139,7 @@ data['timeStamp'] = new Date().toISOString() | ||
data.upsert = true | ||
// ToDo: support stats from multiple dbs | ||
if (data.collection || action == 'databaseStats') { | ||
if (!data.db) | ||
data['db'] = ['indexeddb', 'mongodb'] | ||
if (!data.database) | ||
data['database'] = data.organization_id || process.env.organization_id | ||
if (!data.organization_id) | ||
data['organization_id'] = process.env.organization_id | ||
data['database'] = data.organization_id | ||
} | ||
@@ -123,27 +153,47 @@ | ||
if (this.databases[data.db[i]]) { | ||
if (socket.dbs && socket.dbs[data.db[i]]) | ||
data['dbs'] = socket.dbs[data.db[i]][0] | ||
this.databases[data.db[i]][action](data).then((data) => { | ||
//ToDo: sorting should take place here in order to return sorted values from multiple dbs | ||
if (!dbsLength) { | ||
if (socket) { | ||
this.wsManager.broadcast(socket, action, data); | ||
process.emit('changed-document', data) | ||
resolve() | ||
} else { | ||
resolve(data) | ||
// ToDo: for loop on each dbUrl | ||
if (dbUrl && dbUrl[data.db[i]]) { | ||
data['dbUrl'] = dbUrl[data.db[i]][0] | ||
data = await this.databases[data.db[i]][action](data) | ||
// ToDo: sync orgdb and platformdb specified keys from collections organizations and users | ||
if (data.collection === 'organization' || data.collection === 'user') { | ||
let syncKeys | ||
if (data.collection === 'organizations') | ||
syncKeys = ['name', 'logo', 'databases', 'hosts', 'apis'] | ||
else if (data.collection === 'users') | ||
syncKeys = ['name', 'email', 'password', 'avatar'] | ||
if (syncKeys && syncKeys.length) { | ||
let platformUpdate = { | ||
dbUrl: process.env.MONGO_URL, | ||
database: process.env.organization_id, | ||
collection: data.collection, | ||
document: [{}], | ||
organization_id: process.env.organization_id | ||
} | ||
let document = data.document[0] || data.document | ||
if (document) { | ||
for (let key of syncKeys) { | ||
if (document[key]) | ||
platformUpdate.document[0][key] = document[key] | ||
} | ||
} | ||
} | ||
this.databases['mongodb'][action]() | ||
} | ||
}) | ||
} else { | ||
if (!dbsLength) { | ||
if (socket) { | ||
this.wsManager.broadcast(socket, action, data); | ||
process.emit('changed-document', data) | ||
resolve() | ||
} else { | ||
resolve(data) | ||
} | ||
//ToDo: sorting should take place here in order to return sorted values from multiple dbs | ||
} | ||
} | ||
if (!dbsLength) { | ||
if (socket) { | ||
this.wsManager.broadcast(socket, action, data); | ||
process.emit('changed-document', data) | ||
resolve() | ||
} else { | ||
resolve(data) | ||
} | ||
} | ||
@@ -150,0 +200,0 @@ } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
92504
2.7%364
13.4%7
250%