@cocreate/crud-server 1.32.0 → 1.34.0

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,34 @@
1
+ # [1.34.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.33.0...v1.34.0) (2024-01-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * applied host to define environment/branch ([7a61c24](https://github.com/CoCreate-app/CoCreate-crud-server/commit/7a61c24c1ef879170106ab3aafa365f5078f6cb7))
7
+ * crud defaults defined by host ([b362deb](https://github.com/CoCreate-app/CoCreate-crud-server/commit/b362deb42945bc6326cfe590a61f532ac8206aa7))
8
+ * data.host data.socket.host ([00eb3a0](https://github.com/CoCreate-app/CoCreate-crud-server/commit/00eb3a030219e78617796f6a2f1fd10a2cec012f))
9
+ * getOrganization then get storage from organization returned ([8253876](https://github.com/CoCreate-app/CoCreate-crud-server/commit/8253876601dca41a58566ffad1542e63080e842e))
10
+ * removed host.crud ([ee1743a](https://github.com/CoCreate-app/CoCreate-crud-server/commit/ee1743abd580efe9045cdd7bcdae7d6b8e206744))
11
+ * requesting organization for platform ([edd65c5](https://github.com/CoCreate-app/CoCreate-crud-server/commit/edd65c50ab232cdb24010a7a447cf7924f94ff0b))
12
+ * typo host.length ([b97e059](https://github.com/CoCreate-app/CoCreate-crud-server/commit/b97e0590ee867634415583ae9a89b9462c7fa3b0))
13
+
14
+
15
+ ### Features
16
+
17
+ * bumped CoCreate dependencies to their latest versions ([0aad6d7](https://github.com/CoCreate-app/CoCreate-crud-server/commit/0aad6d794b114993abffd58c83042b95838fe036))
18
+ * crud.getHost and crud.getorganization ([4445e27](https://github.com/CoCreate-app/CoCreate-crud-server/commit/4445e27891b65b53647d18031add25f2de16b417))
19
+
20
+ # [1.33.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.32.0...v1.33.0) (2023-11-25)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * update licensing details ([466a74f](https://github.com/CoCreate-app/CoCreate-crud-server/commit/466a74f43836bd1ec5610dfaf309dbb3d566ec8c))
26
+
27
+
28
+ ### Features
29
+
30
+ * upgrade dependencies for latest features and fixes ([5c185ca](https://github.com/CoCreate-app/CoCreate-crud-server/commit/5c185ca0c9364ffb99ff65049387054b31c33dbe))
31
+
1
32
  # [1.32.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.31.0...v1.32.0) (2023-11-25)
2
33
 
3
34
 
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # CoCreate-crud-server
2
+
2
3
  A simple boilerplate component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API. Take it for a spin in our [playground!](https://cocreate.app/docs/boilerplate)
3
4
 
4
5
  ![GitHub latest release](https://img.shields.io/github/v/release/CoCreate-app/CoCreate-crud-server?style=flat-square)
@@ -16,25 +17,27 @@ We appreciate your continued support, thank you!
16
17
 
17
18
  # Table of Contents
18
19
 
19
- - [Table of Contents](#table-of-contents)
20
- - [Announcements](#announcements)
21
- - [Roadmap](#roadmap)
22
- - [How to Contribute](#how-to-contribute)
23
- - [About](#about)
24
- - [License](#license)
20
+ - [Table of Contents](#table-of-contents)
21
+ - [Announcements](#announcements)
22
+ - [Roadmap](#roadmap)
23
+ - [How to Contribute](#how-to-contribute)
24
+ - [About](#about)
25
+ - [License](#license)
25
26
 
26
27
  <a name="announcements"></a>
28
+
27
29
  # Announcements
28
30
 
29
- All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreate-app/CoCreate-crud-server/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreate-app/CoCreate-crud-server/releases). You may also subscribe to email for releases and breaking changes.
31
+ All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreate-app/CoCreate-crud-server/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreate-app/CoCreate-crud-server/releases). You may also subscribe to email for releases and breaking changes.
30
32
 
31
33
  <a name="roadmap"></a>
34
+
32
35
  # Roadmap
33
36
 
34
37
  If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreate-app/CoCreate-crud-server/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-crud-server/pulls). We would love to hear your feedback.
35
38
 
36
-
37
39
  <a name="about"></a>
40
+
38
41
  # About
39
42
 
40
43
  CoCreate-crud-server is guided and supported by the CoCreate Developer Experience Team.
@@ -44,23 +47,19 @@ Please Email the Developer Experience Team [here](mailto:develop@cocreate.app) i
44
47
  CoCreate-crud-server is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.
45
48
 
46
49
  <a name="contribute"></a>
50
+
47
51
  # How to Contribute
48
52
 
49
53
  We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreate-app/CoCreate-crud-server/blob/master/CONTRIBUTING.md) guide for details.
50
54
 
51
55
  <a name="license"></a>
52
- # Dual License
53
- ## Open Source
54
- [Server Side Public License (SSPL)](https://github.com/CoCreate-app/CoCreate-crud-server/blob/master/LICENSE)
55
-
56
- ## Commercial
57
- For-profit companies and individuals intending to use CoCreate-crud-server for
58
- commercial use must purchase a commercial license. This license allows
59
- source code modifications, but does not permit redistribution of
60
- modifications.
61
-
62
- The commercial license is designed for you to use CoCreate-crud-server in commercial
63
- products and applications, without the provisions of the SSPL. With the
64
- commercial license, your code is kept propietary, to yourself. If you
65
- want to use CoCreate-crud-server to develop commercial sites, themes, projects, and
66
- applications, the commercial license is the appropriate license.
56
+
57
+ # License
58
+
59
+ This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license.
60
+
61
+ - **Open Source Use**: For open-source projects and non-commercial use, this software is available under the AGPLv3. The AGPLv3 allows you to freely use, modify, and distribute this software, provided that all modifications and derivative works are also licensed under the AGPLv3. For the full license text, see the [LICENSE file](https://github.com/CoCreate-app/CoCreate-crud-server/blob/master/LICENSE).
62
+
63
+ - **Commercial Use**: For-profit companies and individuals intending to use this software for commercial purposes must obtain a commercial license. The commercial license is available when you sign up for an API key on our [website](https://cocreate.app). This license permits proprietary use and modification of the software without the copyleft requirements of the AGPLv3. It is ideal for integrating this software into proprietary commercial products and applications.
64
+
65
+ If you have not purchased a commercial license and intend to use this software for commercial purposes, you are required to sign up for an API key on our website.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.32.0",
3
+ "version": "1.34.0",
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.7.0",
44
- "@cocreate/utils": "^1.28.0",
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 storages = await this.getStorage(data)
80
- if (storages.error)
81
- return resolve(storages)
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,59 @@ class CoCreateCrudServer {
181
192
  });
182
193
  }
183
194
 
184
- async getStorage(data) {
185
- if (this.organizations[data.organization_id])
186
- return await this.organizations[data.organization_id]
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
- if (this.organizations[data.organization_id]) {
193
- return await this.organizations[data.organization_id]
194
- } else {
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(data) {
204
- let organization = await this.send({
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: [
233
+ { key: "host", value: [host], operator: "$elemMatch" }
234
+ ]
235
+ }
236
+ else
237
+ return { serverOrganization: false, error: 'An organization could not be found' }
238
+
239
+ if (data.organization_id === this.config.organization_id)
240
+ this.organizations[organization_id] = this.config
241
+
242
+ let organization = await this.send(data)
211
243
 
212
244
  if (organization
213
245
  && organization.object
214
246
  && organization.object[0]) {
215
- if (organization.object[0].storage) {
216
- return organization.object[0].storage
217
- } else
218
- return { serverStorage: false, error: 'A storage url could not be found' }
247
+ return organization.object[0]
219
248
  } else {
220
249
  return { serverOrganization: false, error: 'An organization could not be found' }
221
250
  }