@cocreate/crud-server 1.23.1 → 1.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.23.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.23.1...v1.23.2) (2023-06-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * renamed db to storage ([9b1df98](https://github.com/CoCreate-app/CoCreate-crud-server/commit/9b1df98ecae81f2c861757f51d04bf773dd77f2b))
7
+ * renamed hosts to host. the value can be a string or an array of strings ([1cfaade](https://github.com/CoCreate-app/CoCreate-crud-server/commit/1cfaadeeeccd8b899a83ed1a0c1b2d0811829b77))
8
+
1
9
  ## [1.23.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.23.0...v1.23.1) (2023-06-10)
2
10
 
3
11
 
@@ -10,7 +10,7 @@ module.exports = {
10
10
  "name": "index.html",
11
11
  "path": "/docs/crud-server/index.html",
12
12
  "src": "{{./docs/index.html}}",
13
- "hosts": [
13
+ "host": [
14
14
  "*",
15
15
  "general.cocreate.app"
16
16
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.23.1",
3
+ "version": "1.23.2",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
package/src/index.js CHANGED
@@ -8,14 +8,14 @@ class CoCreateCrudServer {
8
8
  this.wsManager = wsManager
9
9
  this.databases = databases
10
10
  this.ObjectId = ObjectId
11
- this.dbUrls = new Map();
11
+ this.storages = new Map();
12
12
  config([
13
13
  {
14
14
  key: 'organization_id',
15
15
  prompt: 'Enter your organization_id: ',
16
16
  },
17
17
  {
18
- key: 'db',
18
+ key: 'storage',
19
19
  prompt: 'Enter your db object as json.string: ',
20
20
  }
21
21
  ])//
@@ -110,14 +110,15 @@ class CoCreateCrudServer {
110
110
  if (!data.organization_id)
111
111
  return resolve()
112
112
 
113
- let dbUrl = this.dbUrls.get(data.organization_id)
114
- if (dbUrl === false)
115
- return resolve({ dbUrl: false, error: 'database url could not be found' })
113
+ let storage = this.storages.get(data.organization_id)
114
+ if (storage === false)
115
+ return resolve({ storage: false, error: 'A storage or database could not be found' })
116
116
 
117
- if (!dbUrl) {
117
+ if (!storage) {
118
118
  if (data.organization_id === process.env.organization_id) {
119
- dbUrl = process.env.db
120
- this.dbUrls.set(data.organization_id, dbUrl)
119
+ storage = process.env.storage
120
+ if (storage)
121
+ this.storages.set(data.organization_id, JSON.parse(storage))
121
122
  } else {
122
123
  let organization = await this.readDocument({
123
124
  database: process.env.organization_id,
@@ -127,13 +128,13 @@ class CoCreateCrudServer {
127
128
  })
128
129
  if (organization && organization.document && organization.document[0])
129
130
  organization = organization.document[0]
130
- if (organization && organization.databases) {
131
- dbUrl = organization.databases
132
- this.dbUrls.set(data.organization_id, dbUrl)
131
+ if (organization && organization.storage) {
132
+ storage = organization.storage
133
+ this.storages.set(data.organization_id, storage)
133
134
  } else {
134
- this.dbUrls.set(data.organization_id, false)
135
+ this.storages.set(data.organization_id, false)
135
136
  if (organization)
136
- return resolve({ dbUrl: false, error: 'database url could not be found' })
137
+ return resolve({ storage: false, error: 'database url could not be found' })
137
138
  else
138
139
  return resolve({ organization: false, error: 'organization could not be found' })
139
140
  }
@@ -154,7 +155,7 @@ class CoCreateCrudServer {
154
155
  if (action === 'updateDocument' && data.organization_id !== process.env.organization_id) {
155
156
  let syncKeys
156
157
  if (data.collection === 'organizations')
157
- syncKeys = ['name', 'logo', 'databases', 'hosts', 'apis']
158
+ syncKeys = ['name', 'logo', 'databases', 'host', 'apis']
158
159
  else if (data.collection === 'users')
159
160
  syncKeys = ['name', 'email', 'password', 'avatar']
160
161
 
@@ -181,14 +182,14 @@ class CoCreateCrudServer {
181
182
 
182
183
  }
183
184
 
184
- if (!data.db || !data.db.length) {
185
- data.db = [Object.keys(dbUrl)[0]]
186
- } else if (!Array.isArray(data.db))
187
- data.db = [data.db]
185
+ if (!data.storage || !data.storage.length) {
186
+ data.storage = [Object.keys(storage)[0]]
187
+ } else if (!Array.isArray(data.storage))
188
+ data.storage = [data.storage]
188
189
 
189
- for (let i = 0; i < data.db.length; i++) {
190
- if (dbUrl && dbUrl[data.db[i]]) {
191
- let db = dbUrl[data.db[i]]
190
+ for (let i = 0; i < data.storage.length; i++) {
191
+ if (storage && storage[data.storage[i]]) {
192
+ let db = storage[data.storage[i]]
192
193
 
193
194
  if (db.provider && this.databases[db.provider]) {
194
195
  if (!Array.isArray(db.url))
@@ -234,7 +235,7 @@ class CoCreateCrudServer {
234
235
 
235
236
  errorHandler(data, error, database, collection) {
236
237
  if (typeof error == 'object')
237
- error['db'] = 'mongodb'
238
+ error['storage'] = 'mongodb'
238
239
  else
239
240
  error = { location: 'crudServer', message: error }
240
241