@cocreate/crud-server 1.33.0 → 1.34.1
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 +27 -0
- package/package.json +3 -3
- package/src/index.js +66 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
## [1.34.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.34.0...v1.34.1) (2024-01-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* getOrg query ([5a8ebf1](https://github.com/CoCreate-app/CoCreate-crud-server/commit/5a8ebf1cfa47331dbbd28e562af8e046d3a35f24))
|
|
7
|
+
* update to support new query system ([d97a68f](https://github.com/CoCreate-app/CoCreate-crud-server/commit/d97a68ff74831601fb777ab452769ebbf3870b36))
|
|
8
|
+
|
|
9
|
+
# [1.34.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.33.0...v1.34.0) (2024-01-08)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* applied host to define environment/branch ([7a61c24](https://github.com/CoCreate-app/CoCreate-crud-server/commit/7a61c24c1ef879170106ab3aafa365f5078f6cb7))
|
|
15
|
+
* crud defaults defined by host ([b362deb](https://github.com/CoCreate-app/CoCreate-crud-server/commit/b362deb42945bc6326cfe590a61f532ac8206aa7))
|
|
16
|
+
* data.host data.socket.host ([00eb3a0](https://github.com/CoCreate-app/CoCreate-crud-server/commit/00eb3a030219e78617796f6a2f1fd10a2cec012f))
|
|
17
|
+
* getOrganization then get storage from organization returned ([8253876](https://github.com/CoCreate-app/CoCreate-crud-server/commit/8253876601dca41a58566ffad1542e63080e842e))
|
|
18
|
+
* removed host.crud ([ee1743a](https://github.com/CoCreate-app/CoCreate-crud-server/commit/ee1743abd580efe9045cdd7bcdae7d6b8e206744))
|
|
19
|
+
* requesting organization for platform ([edd65c5](https://github.com/CoCreate-app/CoCreate-crud-server/commit/edd65c50ab232cdb24010a7a447cf7924f94ff0b))
|
|
20
|
+
* typo host.length ([b97e059](https://github.com/CoCreate-app/CoCreate-crud-server/commit/b97e0590ee867634415583ae9a89b9462c7fa3b0))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* bumped CoCreate dependencies to their latest versions ([0aad6d7](https://github.com/CoCreate-app/CoCreate-crud-server/commit/0aad6d794b114993abffd58c83042b95838fe036))
|
|
26
|
+
* crud.getHost and crud.getorganization ([4445e27](https://github.com/CoCreate-app/CoCreate-crud-server/commit/4445e27891b65b53647d18031add25f2de16b417))
|
|
27
|
+
|
|
1
28
|
# [1.33.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.32.0...v1.33.0) (2023-11-25)
|
|
2
29
|
|
|
3
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/crud-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.1",
|
|
4
4
|
"description": "CoCreate-crud-server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cocreate-crud",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://cocreate.app/docs/CoCreate-crud-server",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@cocreate/config": "^1.
|
|
44
|
-
"@cocreate/utils": "^1.
|
|
43
|
+
"@cocreate/config": "^1.10.0",
|
|
44
|
+
"@cocreate/utils": "^1.30.0",
|
|
45
45
|
"csvtojson": "^2.0.10",
|
|
46
46
|
"json-2-csv": "^3.10.3"
|
|
47
47
|
}
|
package/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ class CoCreateCrudServer {
|
|
|
9
9
|
this.databases = databases
|
|
10
10
|
this.ObjectId = ObjectId
|
|
11
11
|
this.organizations = {};
|
|
12
|
+
this.hosts = {};
|
|
12
13
|
this.init()
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -61,24 +62,14 @@ class CoCreateCrudServer {
|
|
|
61
62
|
try {
|
|
62
63
|
if (!data.organization_id || !this.config)
|
|
63
64
|
return resolve()
|
|
64
|
-
if (!this.config)
|
|
65
|
-
this.config = await Config({
|
|
66
|
-
'organization_id': { prompt: 'Enter your organization_id: ' },
|
|
67
|
-
'storage': {
|
|
68
|
-
prompt: 'Enter a friendly name for the new storage: ',
|
|
69
|
-
variable: 'name'
|
|
70
|
-
},
|
|
71
|
-
'storage.{{name}}.provider': {
|
|
72
|
-
prompt: 'Enter the storage provider, ex mongodb: '
|
|
73
|
-
},
|
|
74
|
-
'storage.{{name}}.url': {
|
|
75
|
-
prompt: 'Enter the storage providers url: '
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
65
|
|
|
79
|
-
let
|
|
80
|
-
if (
|
|
81
|
-
return resolve(
|
|
66
|
+
let organization = await this.getOrganization(data.organization_id)
|
|
67
|
+
if (organization.error)
|
|
68
|
+
return resolve(organization)
|
|
69
|
+
|
|
70
|
+
let storages = organization.storage
|
|
71
|
+
if (!storages)
|
|
72
|
+
return resolve({ serverStorage: false, error: 'A storage url could not be found' })
|
|
82
73
|
|
|
83
74
|
if (!data['timeStamp'])
|
|
84
75
|
data['timeStamp'] = new Date().toISOString()
|
|
@@ -119,6 +110,26 @@ class CoCreateCrudServer {
|
|
|
119
110
|
}
|
|
120
111
|
}
|
|
121
112
|
|
|
113
|
+
if (organization.host) {
|
|
114
|
+
let host = organization.host
|
|
115
|
+
for (let i = 0; i < host.length; i++) {
|
|
116
|
+
let hostname
|
|
117
|
+
if (data.socket)
|
|
118
|
+
hostname = data.socket.host
|
|
119
|
+
else
|
|
120
|
+
hostname = data.host
|
|
121
|
+
if (host[i].name === hostname) {
|
|
122
|
+
if (host[i].storage)
|
|
123
|
+
data.storage = host[i].storage
|
|
124
|
+
if (host[i].database)
|
|
125
|
+
data.database = host[i].database
|
|
126
|
+
if (host[i].array)
|
|
127
|
+
data.array = host[i].array
|
|
128
|
+
break
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
122
133
|
if (!data.storage || !data.storage.length) {
|
|
123
134
|
data.storage = [Object.keys(storages)[0]]
|
|
124
135
|
} else if (!Array.isArray(data.storage))
|
|
@@ -181,41 +192,57 @@ class CoCreateCrudServer {
|
|
|
181
192
|
});
|
|
182
193
|
}
|
|
183
194
|
|
|
184
|
-
async
|
|
185
|
-
if (this.
|
|
186
|
-
return await this.
|
|
187
|
-
|
|
188
|
-
if (data.organization_id === this.config.organization_id) {
|
|
189
|
-
this.organizations[data.organization_id] = this.config.storage
|
|
190
|
-
return this.config.storage
|
|
195
|
+
async getHost(host) {
|
|
196
|
+
if (this.hosts[host]) {
|
|
197
|
+
return await this.hosts[host]
|
|
191
198
|
} else {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.organizations[data.organization_id] = this.getOrganization(data)
|
|
196
|
-
this.organizations[data.organization_id] = await this.organizations[data.organization_id]
|
|
197
|
-
return this.organizations[data.organization_id]
|
|
198
|
-
}
|
|
199
|
+
this.hosts[host] = this.getOrg(null, host)
|
|
200
|
+
this.hosts[host] = await this.hosts[host]
|
|
201
|
+
return this.hosts[host]
|
|
199
202
|
}
|
|
200
203
|
|
|
201
204
|
}
|
|
202
205
|
|
|
203
|
-
async getOrganization(
|
|
204
|
-
|
|
206
|
+
async getOrganization(organization_id, platform) {
|
|
207
|
+
if (this.organizations[organization_id]) {
|
|
208
|
+
return await this.organizations[organization_id]
|
|
209
|
+
} else {
|
|
210
|
+
this.organizations[organization_id] = this.getOrg(organization_id, null, platform)
|
|
211
|
+
this.organizations[organization_id] = await this.organizations[organization_id]
|
|
212
|
+
return this.organizations[organization_id]
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async getOrg(organization_id, host, platform = true) {
|
|
217
|
+
let data = {
|
|
205
218
|
method: 'object.read',
|
|
219
|
+
host,
|
|
206
220
|
database: this.config.organization_id,
|
|
207
221
|
array: 'organizations',
|
|
208
|
-
object: [{ _id: data.organization_id }],
|
|
209
222
|
organization_id: this.config.organization_id
|
|
210
|
-
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!platform)
|
|
226
|
+
data.database = data.organization_id = organization_id
|
|
227
|
+
|
|
228
|
+
if (organization_id)
|
|
229
|
+
data.object = [{ _id: organization_id }]
|
|
230
|
+
else if (host)
|
|
231
|
+
data.$filter = {
|
|
232
|
+
query: { host: { $elemMatch: { name: { $in: [host] } } } }
|
|
233
|
+
}
|
|
234
|
+
else
|
|
235
|
+
return { serverOrganization: false, error: 'An organization could not be found' }
|
|
236
|
+
|
|
237
|
+
if (data.organization_id === this.config.organization_id)
|
|
238
|
+
this.organizations[organization_id] = this.config
|
|
239
|
+
|
|
240
|
+
let organization = await this.send(data)
|
|
211
241
|
|
|
212
242
|
if (organization
|
|
213
243
|
&& organization.object
|
|
214
244
|
&& organization.object[0]) {
|
|
215
|
-
|
|
216
|
-
return organization.object[0].storage
|
|
217
|
-
} else
|
|
218
|
-
return { serverStorage: false, error: 'A storage url could not be found' }
|
|
245
|
+
return organization.object[0]
|
|
219
246
|
} else {
|
|
220
247
|
return { serverOrganization: false, error: 'An organization could not be found' }
|
|
221
248
|
}
|