@cocreate/organizations 1.28.4 → 1.28.5
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 +8 -0
- package/package.json +1 -9
- package/src/server.js +102 -68
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.28.5](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.28.4...v1.28.5) (2025-09-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* improve organization creation logic and error handling ([bfed09d](https://github.com/CoCreate-app/CoCreate-organizations/commit/bfed09df186993dccef4164674ac430fe4aec17b))
|
|
7
|
+
* streamline organization creation validation and error handling ([4e94111](https://github.com/CoCreate-app/CoCreate-organizations/commit/4e94111529c50be01f96424e5428c14b0d0e4b36))
|
|
8
|
+
|
|
1
9
|
## [1.28.4](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.28.3...v1.28.4) (2025-05-01)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/organizations",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.5",
|
|
4
4
|
"description": "A simple organizations component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"organizations",
|
|
7
|
-
"cocreate",
|
|
8
|
-
"low-code-framework",
|
|
9
|
-
"no-code-framework",
|
|
10
|
-
"cocreatejs",
|
|
11
|
-
"cocreatejs-component",
|
|
12
|
-
"cocreate-framework",
|
|
13
|
-
"no-code",
|
|
14
7
|
"low-code",
|
|
15
|
-
"collaborative-framework",
|
|
16
8
|
"realtime",
|
|
17
9
|
"realtime-framework",
|
|
18
10
|
"collaboration",
|
package/src/server.js
CHANGED
|
@@ -1,80 +1,114 @@
|
|
|
1
1
|
class CoCreateOrganization {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
constructor(crud) {
|
|
3
|
+
this.wsManager = crud.wsManager;
|
|
4
|
+
this.crud = crud;
|
|
5
|
+
this.platformSocket = {
|
|
6
|
+
config: {
|
|
7
|
+
organization_id: process.env.organization_id
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
this.init();
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
init() {
|
|
14
|
+
if (this.wsManager) {
|
|
15
|
+
this.wsManager.on("createOrganization", (data) =>
|
|
16
|
+
this.createOrganization(data)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!data.user || !data.user._id || !data.user.email || !data.user.password) return
|
|
21
|
+
async createOrganization(data) {
|
|
22
|
+
try {
|
|
23
|
+
const { organization, user, key } = data;
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
if (
|
|
26
|
+
!organization ||
|
|
27
|
+
!organization._id ||
|
|
28
|
+
!organization.host ||
|
|
29
|
+
!organization.host[0] ||
|
|
30
|
+
!organization.host[0].name
|
|
31
|
+
) {
|
|
32
|
+
this.errorHandler(
|
|
33
|
+
data,
|
|
34
|
+
"invalid_organization: missing required organization fields"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if (!user || !user._id || !user.email || !user.password) {
|
|
39
|
+
this.errorHandler(
|
|
40
|
+
data,
|
|
41
|
+
"invalid_user: missing required user fields"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
user: {
|
|
49
|
-
array: 'users'
|
|
50
|
-
}
|
|
51
|
-
}
|
|
45
|
+
if (!key || !Array.isArray(key) || key.length !== 3) {
|
|
46
|
+
this.errorHandler(
|
|
47
|
+
data,
|
|
48
|
+
"invalid_key: An array of 3 keys is required with type key, user and role."
|
|
49
|
+
);
|
|
50
|
+
}
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Data.organization_id = process.env.organization_id
|
|
52
|
+
// If there are validation errors, include them in the response and send immediately
|
|
53
|
+
if (data.success === false) {
|
|
54
|
+
return this.wsManager.send(data);
|
|
55
|
+
}
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const response = await this.crud.send({ ...Data, array: 'users', object: user })
|
|
65
|
-
this.wsManager.send(this.platformSocket, response);
|
|
66
|
-
}
|
|
57
|
+
const Data = {};
|
|
58
|
+
Data.method = "object.create";
|
|
59
|
+
Data.host = organization.host[0].name;
|
|
60
|
+
Data.database = organization._id;
|
|
61
|
+
Data.organization_id = organization._id;
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
if (organization) {
|
|
64
|
+
const response = await this.crud.send({
|
|
65
|
+
...Data,
|
|
66
|
+
array: "organizations",
|
|
67
|
+
object: organization
|
|
68
|
+
});
|
|
69
|
+
if (response.error) {
|
|
70
|
+
this.errorHandler(data, response.error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (user) {
|
|
74
|
+
const response = await this.crud.send({
|
|
75
|
+
...Data,
|
|
76
|
+
array: "users",
|
|
77
|
+
object: user
|
|
78
|
+
});
|
|
79
|
+
if (response.error) {
|
|
80
|
+
this.errorHandler(data, response.error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
if (key) {
|
|
85
|
+
const response = await this.crud.send({
|
|
86
|
+
...Data,
|
|
87
|
+
array: "keys",
|
|
88
|
+
object: key
|
|
89
|
+
});
|
|
90
|
+
if (response.error) {
|
|
91
|
+
this.errorHandler(data, response.error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (data.success !== false) {
|
|
96
|
+
data.success = true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.wsManager.send(data);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (data.socket) {
|
|
102
|
+
this.errorHandler(data, error);
|
|
103
|
+
this.wsManager.send(data);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
errorHandler(data, error) {
|
|
109
|
+
data.success = false;
|
|
110
|
+
this.crud.errorHandler(data, error);
|
|
111
|
+
}
|
|
78
112
|
}
|
|
79
113
|
|
|
80
|
-
module.exports = CoCreateOrganization;
|
|
114
|
+
module.exports = CoCreateOrganization;
|