@cocreate/organizations 1.29.0 → 1.30.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 +7 -0
- package/package.json +1 -1
- package/src/client.js +36 -0
- package/src/server.js +98 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.30.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.29.0...v1.30.0) (2025-09-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add createEnvironment function and enhance createEnvironments handling ([d8e28f9](https://github.com/CoCreate-app/CoCreate-organizations/commit/d8e28f9ef032783f73e31a1a811643cb49a3c32e))
|
|
7
|
+
|
|
1
8
|
# [1.29.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.28.5...v1.29.0) (2025-09-07)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -285,6 +285,35 @@ async function create(action) {
|
|
|
285
285
|
);
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
async function createEnvironment(action) {
|
|
289
|
+
let form = action.form;
|
|
290
|
+
if (!form) return;
|
|
291
|
+
|
|
292
|
+
let organization = form.querySelector("#organization");
|
|
293
|
+
if (organization) {
|
|
294
|
+
organization = organization.value;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let hostname = form.querySelector("#hostname");
|
|
298
|
+
if (hostname) {
|
|
299
|
+
hostname = hostname.value;
|
|
300
|
+
hostname = ["dev." + hostname, "test." + hostname];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let response = await Crud.socket.send({
|
|
304
|
+
method: "createEnvironments",
|
|
305
|
+
organization,
|
|
306
|
+
hostname,
|
|
307
|
+
broadcastBrowser: false
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
action.element.dispatchEvent(
|
|
311
|
+
new CustomEvent("createdEnvironments", {
|
|
312
|
+
detail: response
|
|
313
|
+
})
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
288
317
|
Action.init({
|
|
289
318
|
name: "createOrganization",
|
|
290
319
|
endEvent: "createdOrganization",
|
|
@@ -292,5 +321,12 @@ Action.init({
|
|
|
292
321
|
create(action);
|
|
293
322
|
}
|
|
294
323
|
});
|
|
324
|
+
Action.init({
|
|
325
|
+
name: "createEnvironments",
|
|
326
|
+
endEvent: "createdEnvironments",
|
|
327
|
+
callback: (action) => {
|
|
328
|
+
createEnvironment(action);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
295
331
|
|
|
296
332
|
export default { generateDB, create, get };
|
package/src/server.js
CHANGED
|
@@ -15,6 +15,9 @@ class CoCreateOrganization {
|
|
|
15
15
|
this.wsManager.on("createOrganization", (data) =>
|
|
16
16
|
this.createOrganization(data)
|
|
17
17
|
);
|
|
18
|
+
this.wsManager.on("createEnvironments", (data) =>
|
|
19
|
+
this.createEnvironments(data)
|
|
20
|
+
);
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -42,10 +45,10 @@ class CoCreateOrganization {
|
|
|
42
45
|
);
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
if (!key || !Array.isArray(key) || key.length
|
|
48
|
+
if (!key || !Array.isArray(key) || key.length < 4) {
|
|
46
49
|
this.errorHandler(
|
|
47
50
|
data,
|
|
48
|
-
"invalid_key: An array of
|
|
51
|
+
"invalid_key: An array of 4 keys is required with type key, user and role."
|
|
49
52
|
);
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -55,12 +58,13 @@ class CoCreateOrganization {
|
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
const Data = {};
|
|
58
|
-
Data.method = "object.
|
|
61
|
+
Data.method = "object.update";
|
|
59
62
|
Data.host = organization.host[0].name;
|
|
60
|
-
Data.database = [organization._id
|
|
63
|
+
Data.database = [organization._id];
|
|
61
64
|
Data.organization_id = organization._id;
|
|
62
|
-
|
|
65
|
+
Data.upsert = true;
|
|
63
66
|
if (organization) {
|
|
67
|
+
organization.organization_id = organization._id;
|
|
64
68
|
const response = await this.crud.send({
|
|
65
69
|
...Data,
|
|
66
70
|
array: "organizations",
|
|
@@ -71,6 +75,7 @@ class CoCreateOrganization {
|
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
if (user) {
|
|
78
|
+
user.organization_id = organization._id;
|
|
74
79
|
const response = await this.crud.send({
|
|
75
80
|
...Data,
|
|
76
81
|
array: "users",
|
|
@@ -82,6 +87,9 @@ class CoCreateOrganization {
|
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
if (key) {
|
|
90
|
+
key.forEach(k => {
|
|
91
|
+
k.organization_id = organization._id;
|
|
92
|
+
});
|
|
85
93
|
const response = await this.crud.send({
|
|
86
94
|
...Data,
|
|
87
95
|
array: "keys",
|
|
@@ -105,6 +113,91 @@ class CoCreateOrganization {
|
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
|
|
116
|
+
async createEnvironments(data) {
|
|
117
|
+
try {
|
|
118
|
+
let { organization, hostname } = data;
|
|
119
|
+
|
|
120
|
+
if (!organization) {
|
|
121
|
+
this.errorHandler(
|
|
122
|
+
data,
|
|
123
|
+
"Missing required field: 'organization'. Please provide the organization object to create an organization."
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (!hostname) {
|
|
127
|
+
this.errorHandler(
|
|
128
|
+
data,
|
|
129
|
+
"Missing required field: 'hostname'. Please provide the hostname to create an organization."
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// If there are validation errors, include them in the response and send immediately
|
|
134
|
+
if (data.success === false) {
|
|
135
|
+
return this.wsManager.send(data);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const Data = {};
|
|
139
|
+
Data.method = "object.read";
|
|
140
|
+
Data.host = hostname;
|
|
141
|
+
Data.organization_id = organization;
|
|
142
|
+
Data.$filter = { limit: 0 };
|
|
143
|
+
|
|
144
|
+
let organizations = await this.crud.send({
|
|
145
|
+
...Data,
|
|
146
|
+
array: "organizations",
|
|
147
|
+
object: []
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (organizations.error) {
|
|
151
|
+
this.errorHandler(data, organizations.error);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let users = await this.crud.send({
|
|
155
|
+
...Data,
|
|
156
|
+
array: "users",
|
|
157
|
+
object: []
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
if (users.error) {
|
|
161
|
+
this.errorHandler(data, users.error);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let keys = await this.crud.send({
|
|
165
|
+
...Data,
|
|
166
|
+
array: "keys",
|
|
167
|
+
object: []
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (keys.error) {
|
|
171
|
+
this.errorHandler(data, keys.error);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (let host of hostname) {
|
|
175
|
+
organizations.method = "object.create";
|
|
176
|
+
organizations.host = host;
|
|
177
|
+
organizations = await this.crud.send(organizations);
|
|
178
|
+
|
|
179
|
+
users.method = "object.create";
|
|
180
|
+
users.host = host;
|
|
181
|
+
users = await this.crud.send(users);
|
|
182
|
+
|
|
183
|
+
keys.method = "object.create";
|
|
184
|
+
keys.host = host;
|
|
185
|
+
keys = await this.crud.send(keys);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (data.success !== false) {
|
|
189
|
+
data.success = true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.wsManager.send(data);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (data.socket) {
|
|
195
|
+
this.errorHandler(data, error);
|
|
196
|
+
this.wsManager.send(data);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
108
201
|
errorHandler(data, error) {
|
|
109
202
|
data.success = false;
|
|
110
203
|
this.crud.errorHandler(data, error);
|