@cocreate/users 1.38.6 → 1.39.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 +22 -0
- package/package.json +1 -1
- package/src/client.js +68 -54
- package/src/index.css +9 -9
- package/src/index.js +6 -6
- package/src/server.js +21 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [1.39.1](https://github.com/CoCreate-app/CoCreate-users/compare/v1.39.0...v1.39.1) (2026-04-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* property access for user object in client.js ([94369a5](https://github.com/CoCreate-app/CoCreate-users/commit/94369a56dc78ee5cc3aaa9449e1a88c62ddf2c8d))
|
|
7
|
+
|
|
8
|
+
# [1.39.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.38.6...v1.39.0) (2026-04-04)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* root factory variable Module ([811bfe4](https://github.com/CoCreate-app/CoCreate-users/commit/811bfe4c97da3d619df4ddb577194baac584fff6))
|
|
14
|
+
* root factory variable Module ([4de7567](https://github.com/CoCreate-app/CoCreate-users/commit/4de7567d186b230211c579a311714668a8b3fc1a))
|
|
15
|
+
* signup ([0d9773f](https://github.com/CoCreate-app/CoCreate-users/commit/0d9773ff411dbfb1428bfff5755aae0cc36c1549))
|
|
16
|
+
* Update TODO comment to include a period at the end. ([ce07c87](https://github.com/CoCreate-app/CoCreate-users/commit/ce07c873b38b8b3925ccb048f91b5fabdb591c31))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* update user status to online/offline/idle and corresponding UI changes ([086e970](https://github.com/CoCreate-app/CoCreate-users/commit/086e97008381a7bfc0c73a024d34c537110e0478))
|
|
22
|
+
|
|
1
23
|
## [1.38.6](https://github.com/CoCreate-app/CoCreate-users/compare/v1.38.5...v1.38.6) (2026-02-04)
|
|
2
24
|
|
|
3
25
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -7,7 +7,7 @@ import "@cocreate/element-prototype";
|
|
|
7
7
|
import Observer from "@cocreate/observer";
|
|
8
8
|
import "./index.css";
|
|
9
9
|
|
|
10
|
-
// TODO: Replace with @cocreate/config
|
|
10
|
+
// TODO: Replace with @cocreate/config.
|
|
11
11
|
import localStorage from "@cocreate/local-storage";
|
|
12
12
|
|
|
13
13
|
const CoCreateUser = {
|
|
@@ -28,61 +28,69 @@ const CoCreateUser = {
|
|
|
28
28
|
signUp: async function (action) {
|
|
29
29
|
if (!action.form) return;
|
|
30
30
|
|
|
31
|
-
let data = await Elements.
|
|
31
|
+
let data = await Elements.getData(action.form);
|
|
32
32
|
let user = data[0];
|
|
33
|
-
// data.method = 'object.create'
|
|
34
|
-
// data['array'] = array
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// if (!data.object[0]._id)
|
|
39
|
-
// data.object[0]._id = Crud.ObjectId().toString();
|
|
40
|
-
|
|
41
|
-
// let user = await Crud.send(data)
|
|
42
|
-
// Elements.setTypeValue(formEl, user)
|
|
43
|
-
|
|
44
|
-
// const socket = Crud.socket.getSockets()
|
|
45
|
-
// if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
|
|
46
|
-
|
|
47
|
-
// ToDo: remove roles handling from client and implement a serverside solution similar to lazyloader webooks processOperators
|
|
48
|
-
let key = {
|
|
49
|
-
status: "await",
|
|
34
|
+
let userKey = {
|
|
50
35
|
method: "object.create",
|
|
51
36
|
array: "keys",
|
|
52
37
|
object: {
|
|
53
|
-
_id: user.object[0]
|
|
38
|
+
_id: user.object._id || user.object[0]?._id,
|
|
54
39
|
type: "user",
|
|
55
|
-
key: user.object[0]
|
|
56
|
-
roles: user.object
|
|
57
|
-
email: user.object[0]
|
|
58
|
-
password: user.object
|
|
40
|
+
key: user.object._id || user.object[0]?._id,
|
|
41
|
+
roles: user.object.roles || [user.object["roles[]"]] || user.object[0]?.roles,
|
|
42
|
+
email: user.object.email || user.object[0]?.email,
|
|
43
|
+
password: user.object.password || window.btoa("0000"),
|
|
59
44
|
array: user.array
|
|
60
45
|
}
|
|
61
46
|
};
|
|
62
47
|
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
48
|
+
const socket = await Crud.socket.getSockets();
|
|
49
|
+
if (
|
|
50
|
+
!socket[0] ||
|
|
51
|
+
!socket[0].connected ||
|
|
52
|
+
(window && !window.navigator.onLine) ||
|
|
53
|
+
Crud.socket.serverOrganization == false
|
|
54
|
+
) {
|
|
55
|
+
user.method = "object.create";
|
|
56
|
+
await Crud.send(user);
|
|
57
|
+
let response = await Crud.send(userKey);
|
|
58
|
+
if (response && response.object && response.object[0]) {
|
|
59
|
+
this.signUpResponse(response, action);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
let request = {
|
|
63
|
+
method: "signUp",
|
|
64
|
+
user,
|
|
65
|
+
userKey,
|
|
66
|
+
broadcastBrowser: false
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
Crud.socket.send(request).then((response) => {
|
|
70
|
+
this.signUpResponse(response, action);
|
|
76
71
|
});
|
|
77
|
-
|
|
78
|
-
action.element.dispatchEvent(
|
|
79
|
-
new CustomEvent("signUp", {
|
|
80
|
-
detail: response
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
72
|
}
|
|
84
73
|
},
|
|
85
74
|
|
|
75
|
+
signUpResponse: function (response, action) {
|
|
76
|
+
render({
|
|
77
|
+
selector: "[template*='signUp']",
|
|
78
|
+
data: [
|
|
79
|
+
{
|
|
80
|
+
type: "signUp",
|
|
81
|
+
message: "Succesfully Signed Up",
|
|
82
|
+
success: true
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
action.element.dispatchEvent(
|
|
88
|
+
new CustomEvent("signUp", {
|
|
89
|
+
detail: response
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
},
|
|
93
|
+
|
|
86
94
|
signIn: async function (action) {
|
|
87
95
|
if (!action.form) return;
|
|
88
96
|
let query = {};
|
|
@@ -117,6 +125,7 @@ const CoCreateUser = {
|
|
|
117
125
|
Crud.send(request).then((response) => {
|
|
118
126
|
response["success"] = false;
|
|
119
127
|
response["status"] = "signIn failed";
|
|
128
|
+
response["message"] = "offline";
|
|
120
129
|
if (response.object && response.object[0]) {
|
|
121
130
|
response["success"] = true;
|
|
122
131
|
response["status"] = "success";
|
|
@@ -145,13 +154,9 @@ const CoCreateUser = {
|
|
|
145
154
|
localStorage.setItem("token", token);
|
|
146
155
|
message = "Successful signIn";
|
|
147
156
|
Crud.socket.user_id = user_id;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
detail: {}
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
} else message = "The email or password you entered is incorrect";
|
|
157
|
+
} else if (!message) {
|
|
158
|
+
message = "The email or password you entered is incorrect";
|
|
159
|
+
}
|
|
155
160
|
|
|
156
161
|
render({
|
|
157
162
|
selector: "[template*='signIn']",
|
|
@@ -164,6 +169,13 @@ const CoCreateUser = {
|
|
|
164
169
|
}
|
|
165
170
|
]
|
|
166
171
|
});
|
|
172
|
+
|
|
173
|
+
action.element.dispatchEvent(
|
|
174
|
+
new CustomEvent("signIn", {
|
|
175
|
+
detail: {}
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
|
|
167
179
|
},
|
|
168
180
|
|
|
169
181
|
signOut: (action) => {
|
|
@@ -206,6 +218,8 @@ const CoCreateUser = {
|
|
|
206
218
|
},
|
|
207
219
|
|
|
208
220
|
redirect: (data) => {
|
|
221
|
+
const userStatus = data.userStatus;
|
|
222
|
+
|
|
209
223
|
if (
|
|
210
224
|
(data.user_id && data.user_id !== Crud.socket.user_id) ||
|
|
211
225
|
(data.clientId && data.clientId !== Crud.socket.clientId)
|
|
@@ -213,16 +227,16 @@ const CoCreateUser = {
|
|
|
213
227
|
return;
|
|
214
228
|
|
|
215
229
|
let redirectTag;
|
|
216
|
-
if (
|
|
230
|
+
if (userStatus == "online" || userStatus == "idle") {
|
|
217
231
|
redirectTag = document.querySelector('[session="true"]');
|
|
218
|
-
} else if (
|
|
232
|
+
} else if (userStatus == "offline") {
|
|
219
233
|
redirectTag = document.querySelector('[session="false"]');
|
|
220
234
|
}
|
|
221
235
|
|
|
222
236
|
if (redirectTag) {
|
|
223
237
|
let redirectLink = redirectTag.getAttribute("href");
|
|
224
238
|
if (redirectLink) {
|
|
225
|
-
if (
|
|
239
|
+
if (userStatus == "offline") {
|
|
226
240
|
localStorage.removeItem("user_id");
|
|
227
241
|
localStorage.removeItem("token");
|
|
228
242
|
}
|
|
@@ -243,12 +257,12 @@ const CoCreateUser = {
|
|
|
243
257
|
}
|
|
244
258
|
}
|
|
245
259
|
|
|
246
|
-
if (
|
|
260
|
+
if (userStatus) {
|
|
247
261
|
let sessionElements = document.querySelectorAll(
|
|
248
262
|
'[session]:not([session="true"], [session="false"])'
|
|
249
263
|
);
|
|
250
264
|
for (let i = 0; i < sessionElements.length; i++)
|
|
251
|
-
sessionElements[i].setAttribute("session",
|
|
265
|
+
sessionElements[i].setAttribute("session", userStatus);
|
|
252
266
|
}
|
|
253
267
|
},
|
|
254
268
|
|
package/src/index.css
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
[user-status="
|
|
2
|
-
background-color:yellowgreen;
|
|
3
|
-
}
|
|
4
|
-
[user-status="
|
|
5
|
-
background-color:red;
|
|
6
|
-
}
|
|
7
|
-
[user-status="idle"] {
|
|
8
|
-
background-color:orange;
|
|
9
|
-
}
|
|
1
|
+
[user-status="online"] {
|
|
2
|
+
background-color:yellowgreen;
|
|
3
|
+
}
|
|
4
|
+
[user-status="offline"] {
|
|
5
|
+
background-color:red;
|
|
6
|
+
}
|
|
7
|
+
[user-status="idle"] {
|
|
8
|
+
background-color:orange;
|
|
9
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
(function (root, factory) {
|
|
2
2
|
if (typeof define === 'function' && define.amd) {
|
|
3
|
-
define(["./client"], function (
|
|
4
|
-
return factory(
|
|
3
|
+
define(["./client"], function (Module) {
|
|
4
|
+
return factory(Module)
|
|
5
5
|
});
|
|
6
6
|
} else if (typeof module === 'object' && module.exports) {
|
|
7
|
-
const
|
|
8
|
-
module.exports = factory(
|
|
7
|
+
const Module = require("./server.js")
|
|
8
|
+
module.exports = factory(Module);
|
|
9
9
|
} else {
|
|
10
10
|
root.returnExports = factory(root["./client.js"]);
|
|
11
11
|
}
|
|
12
|
-
}(typeof self !== 'undefined' ? self : this, function (
|
|
13
|
-
return
|
|
12
|
+
}(typeof self !== 'undefined' ? self : this, function (Module) {
|
|
13
|
+
return Module;
|
|
14
14
|
}));
|
package/src/server.js
CHANGED
|
@@ -28,21 +28,32 @@ class CoCreateUser {
|
|
|
28
28
|
|
|
29
29
|
async signUp(data) {
|
|
30
30
|
try {
|
|
31
|
+
let response = {
|
|
32
|
+
socket: data.socket,
|
|
33
|
+
host: data.host,
|
|
34
|
+
method: "signUp",
|
|
35
|
+
success: false,
|
|
36
|
+
message: "signUp failed",
|
|
37
|
+
organization_id: data.organization_id,
|
|
38
|
+
uid: data.uid
|
|
39
|
+
};
|
|
40
|
+
|
|
31
41
|
if (data.user) {
|
|
32
42
|
data.user.method = "object.create";
|
|
33
43
|
data.user.host = data.host;
|
|
34
|
-
|
|
35
|
-
this.wsManager.send(response);
|
|
44
|
+
await this.crud.send(data.user);
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
if (data.userKey) {
|
|
39
48
|
data.userKey.method = "object.create";
|
|
40
49
|
data.userKey.host = data.host;
|
|
41
|
-
|
|
42
|
-
this.wsManager.send(response);
|
|
50
|
+
await this.crud.send(data.userKey);
|
|
43
51
|
}
|
|
44
52
|
|
|
45
|
-
|
|
53
|
+
response.success = true;
|
|
54
|
+
response.message = "signUp successful";
|
|
55
|
+
|
|
56
|
+
this.wsManager.send(response);
|
|
46
57
|
} catch (error) {
|
|
47
58
|
console.log("signup error", error);
|
|
48
59
|
}
|
|
@@ -79,7 +90,7 @@ class CoCreateUser {
|
|
|
79
90
|
method: "signIn",
|
|
80
91
|
success: false,
|
|
81
92
|
message: "signIn failed",
|
|
82
|
-
userStatus: "
|
|
93
|
+
userStatus: "offline",
|
|
83
94
|
organization_id: data.organization_id,
|
|
84
95
|
uid: data.uid
|
|
85
96
|
};
|
|
@@ -103,7 +114,7 @@ class CoCreateUser {
|
|
|
103
114
|
socket.user_id = user_id;
|
|
104
115
|
response.success = true;
|
|
105
116
|
response.message = "signIn successful";
|
|
106
|
-
response.userStatus = "
|
|
117
|
+
response.userStatus = "online";
|
|
107
118
|
response.user_id = user_id;
|
|
108
119
|
response.token = token;
|
|
109
120
|
}
|
|
@@ -124,7 +135,7 @@ class CoCreateUser {
|
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
/**
|
|
127
|
-
* status: '
|
|
138
|
+
* status: 'online/offline/idle'
|
|
128
139
|
*/
|
|
129
140
|
async userStatus(data) {
|
|
130
141
|
const self = this;
|
|
@@ -173,8 +184,8 @@ class CoCreateUser {
|
|
|
173
184
|
try {
|
|
174
185
|
data.method = "updateUserStatus";
|
|
175
186
|
|
|
176
|
-
if (!data.socket.user_id) data.userStatus = "
|
|
177
|
-
else data.userStatus = "
|
|
187
|
+
if (!data.socket.user_id) data.userStatus = "offline";
|
|
188
|
+
else data.userStatus = "online";
|
|
178
189
|
|
|
179
190
|
this.wsManager.send(data);
|
|
180
191
|
} catch (error) {
|