@cocreate/users 1.40.1 → 1.40.3

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.
@@ -3,7 +3,7 @@ name: Automated Workflow
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
6
+ - main
7
7
 
8
8
  jobs:
9
9
  about:
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.40.2](https://github.com/CoCreate-app/CoCreate-users/compare/v1.40.1...v1.40.2) (2026-07-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * set default branch to main ([353f036](https://github.com/CoCreate-app/CoCreate-users/commit/353f036c667b3e7a7550be16e7b19cbd7d91da53))
7
+
1
8
  ## [1.40.1](https://github.com/CoCreate-app/CoCreate-users/compare/v1.40.0...v1.40.1) (2026-07-17)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/users",
3
- "version": "1.40.1",
3
+ "version": "1.40.3",
4
4
  "description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "users",
@@ -72,7 +72,6 @@
72
72
  "@cocreate/render@1.46.1": true,
73
73
  "@cocreate/socket-client@1.40.5": true,
74
74
  "@cocreate/utils@1.42.2": true,
75
- "@cocreate/uuid@1.12.4": true,
76
75
  "@cocreate/webpack@1.4.3": true
77
76
  }
78
77
  }
package/release.config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  dryRun: false,
3
- branches: ["master"],
3
+ branches: ["main"],
4
4
  plugins: [
5
5
  "@semantic-release/commit-analyzer",
6
6
  "@semantic-release/release-notes-generator",
package/src/client.js CHANGED
@@ -5,518 +5,516 @@ import Elements from "@cocreate/elements";
5
5
  import { render } from "@cocreate/render";
6
6
  import "@cocreate/element-prototype";
7
7
  import Observer from "@cocreate/observer";
8
- import "./index.css";
9
-
10
- // TODO: Replace with @cocreate/config.
11
- import localStorage from "@cocreate/local-storage";
12
8
  import Config from "@cocreate/config";
9
+ import "./index.css";
13
10
 
14
11
  const CoCreateUser = {
15
- organization_id: async () => {
16
- return await Crud.socket.organization_id();
17
- },
18
-
19
- init: function () {
20
- this.initSocket();
21
- this.initSession();
22
- },
23
-
24
- initSocket: function () {
25
- const self = this;
26
- Crud.listen("updateUserStatus", (data) => self.updateUserStatus(data));
27
- },
28
-
29
- signUp: async function (action) {
30
- if (!action.form) return;
31
-
32
- let data = await Elements.getData(action.form);
33
- let user = data[0];
34
-
35
- let userKey = {
36
- method: "object.create",
37
- array: "keys",
38
- object: {
39
- type: "user",
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"),
44
- array: user.array
45
- }
46
- };
47
-
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);
71
- });
72
- }
73
- },
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
-
94
- signIn: async function (action) {
95
- if (!action.form) return;
96
- let query = {};
97
-
98
- const inputs = action.form.querySelectorAll(
99
- 'input[key="email"], input[key="password"], input[key="username"]'
100
- );
101
- for (let i = 0; i < inputs.length; i++) {
102
- const key = inputs[i].getAttribute("key");
103
- if (key === "password" && inputs[i].type === "text") {
104
- inputs[i].type = "password"
105
- }
106
- const value = await inputs[i].getValue();
107
- query[key] = value;
108
- }
109
-
110
- let request = {
111
- method: "object.read",
112
- array: "keys",
113
- $filter: {
114
- query
115
- }
116
- };
117
-
118
- const socket = await Crud.socket.getSockets();
119
- if (
120
- !socket[0] ||
121
- !socket[0].connected ||
122
- (window && !window.navigator.onLine) ||
123
- Crud.socket.serverOrganization == false
124
- ) {
125
- Crud.send(request).then((response) => {
126
- response["success"] = false;
127
- response["status"] = "signIn failed";
128
- response["message"] = "offline";
129
- if (response.object && response.object[0]) {
130
- response["success"] = true;
131
- response["status"] = "success";
132
- response["user_id"] = response.object[0].key;
133
- }
134
- this.signInResponse(response, action);
135
- });
136
- } else {
137
- request.method = "signIn";
138
- request.broadcastBrowser = false;
139
- delete request.storage;
140
- Crud.socket.send(request).then((response) => {
141
- this.signInResponse(response, action);
142
- });
143
- }
144
- },
145
-
146
- signInResponse: function (data, action) {
147
- let { success, status, message, organization_id, user_id, token } =
148
- data;
149
- if (success) {
150
- localStorage.setItem("organization_id", organization_id);
151
- localStorage.setItem("key", Crud.socket.key);
152
- localStorage.setItem("host", Crud.socket.host);
153
- localStorage.setItem("user_id", user_id);
154
- localStorage.setItem("token", token);
155
- message = "Successful signIn";
156
- Crud.socket.user_id = user_id;
157
- } else if (!message) {
158
- message = "The email or password you entered is incorrect";
159
- }
160
-
161
- render({
162
- selector: "[template*='signIn']",
163
- data: [
164
- {
165
- type: "signIn",
166
- status,
167
- message,
168
- success
169
- }
170
- ]
171
- });
172
-
173
- action.element.dispatchEvent(
174
- new CustomEvent("signIn", {
175
- detail: {}
176
- })
177
- );
178
-
179
- },
180
-
181
- signOut: function (action) {
182
- // Remove user_id via Config to clear cookies and CoCreateConfig
183
- Config.remove("user_id");
184
- // token can remain in localStorage removal
185
- localStorage.removeItem("token");
186
- if (Crud && Crud.socket) {
187
- Crud.socket.user_id = null;
188
- if (Crud.socket.token) Crud.socket.token = null;
189
- }
190
-
191
- render({
192
- selector: "[template*='signOut']",
193
- data: [
194
- {
195
- type: "signOut",
196
- message: "Succesfully logged out",
197
- success: true
198
- }
199
- ]
200
- });
201
-
202
- action.element.dispatchEvent(new CustomEvent("signOut"));
203
- },
204
-
205
- updateUserStatus: function (data) {
206
- this.redirect(data);
207
- let statusEls;
208
- if (data.user_id) {
209
- if (data.user_id === Crud.socket.user_id)
210
- statusEls = document.querySelectorAll(
211
- `[user-status][object='${data["user_id"]}'], [user-status][object='$user_id']`
212
- );
213
- else
214
- statusEls = document.querySelectorAll(
215
- `[user-status][object='${data["user_id"]}']`
216
- );
217
-
218
- statusEls.forEach((el) => {
219
- el.setAttribute("user-status", data["userStatus"]);
220
- });
221
- }
222
- },
223
-
224
- redirect: (data) => {
225
- const userStatus = data.userStatus;
226
-
227
- if (
228
- (data.user_id && data.user_id !== Crud.socket.user_id) ||
229
- (data.clientId && data.clientId !== Crud.socket.clientId)
230
- )
231
- return;
232
-
233
- let redirectTag;
234
- if (userStatus == "online" || userStatus == "idle") {
235
- redirectTag = document.querySelector('[session="true"]');
236
- } else if (userStatus == "offline") {
237
- redirectTag = document.querySelector('[session="false"]');
238
- }
239
-
240
- if (redirectTag) {
241
- let redirectLink = redirectTag.getAttribute("href");
242
- if (redirectLink) {
243
- if (userStatus == "offline") {
244
- Config.removeItem("user_id");
245
- localStorage.removeItem("token");
246
- if (Crud && Crud.socket) Crud.socket.user_id = null;
247
- }
248
-
249
- // Normalize both URLs to compare paths in a uniform way
250
- const currentPath = new URL(location.href).pathname.replace(
251
- "/index.html",
252
- "/"
253
- );
254
- const targetPath = new URL(
255
- redirectLink,
256
- location.href
257
- ).pathname.replace("/index.html", "/");
258
-
259
- if (currentPath !== targetPath) {
260
- location.href = redirectLink;
261
- }
262
- }
263
- }
264
-
265
- if (userStatus) {
266
- let sessionElements = document.querySelectorAll(
267
- '[session]:not([session="true"], [session="false"])'
268
- );
269
- for (let i = 0; i < sessionElements.length; i++)
270
- sessionElements[i].setAttribute("session", userStatus);
271
- }
272
- },
273
-
274
- initSession: () => {
275
- let redirectTag = document.querySelector("[session]");
276
-
277
- if (redirectTag) {
278
- Crud.socket.send({
279
- method: "checkSession",
280
- broadcast: false,
281
- broadcastSender: false,
282
- broadcastBrowser: false
283
- });
284
- }
285
- },
286
-
287
- inviteUser: async function (action) {
288
- let email = action.form.querySelector('input[key="email"]');
289
- if (!email) return;
290
- else email = await email.getValue();
291
-
292
- let name = action.form.querySelector('input[key="name"]');
293
- if (name) name = await name.getValue();
294
-
295
- let from = action.form.querySelector('input[key="from"]');
296
- if (from) from = await from.getValue();
297
-
298
- let origin = action.form.querySelector('input[key="origin"]');
299
- if (origin)
300
- origin = (await origin.getValue()) || window.location.origin;
301
-
302
- let hostname = action.form.querySelector('input[key="hostname"]');
303
- if (hostname)
304
- hostname = (await hostname.getValue()) || window.location.hostname;
305
-
306
- let path = action.form.querySelector('input[key="path"]');
307
- if (path) path = await path.getValue();
308
-
309
- let request = {
310
- method: "inviteUser",
311
- name,
312
- email,
313
- from,
314
- origin,
315
- hostname,
316
- path
317
- };
318
-
319
- Crud.socket.send(request).then((response) => {
320
- if (response.success)
321
- action.element.dispatchEvent(new CustomEvent("inviteUser"));
322
-
323
- render({
324
- selector: "[template*='inviteUser']",
325
- data: [
326
- {
327
- type: "inviteUser",
328
- message: response.message,
329
- success: response.success
330
- }
331
- ]
332
- });
333
- });
334
- },
335
-
336
- acceptInvite: async function (action) {
337
- let data = {
338
- method: "acceptInvite",
339
- success: false
340
- };
341
-
342
- let token = action.form.querySelector('input[key="token"]');
343
- if (token) data.token = await token.getValue();
344
- let user_id = action.form.querySelector('input[key="_id"]');
345
- if (user_id) data.user_id = await user_id.getValue();
346
- let email = action.form.querySelector('input[key="email"]');
347
- if (email) data.email = await email.getValue();
348
-
349
- if (data.token && data.user_id) {
350
- data = await Crud.socket.send(data);
351
- } else {
352
- data.message = "Invitation failed";
353
- }
354
-
355
- if (data.success)
356
- action.element.dispatchEvent(new CustomEvent("acceptInvite"));
357
- render({
358
- selector: "[template*='acceptInvite']",
359
- data: [
360
- {
361
- type: "acceptInvite",
362
- message: data.message,
363
- success: data.success
364
- }
365
- ]
366
- });
367
- },
368
-
369
- forgotPassword: async function (action) {
370
- let email = action.form.querySelector('input[key="email"]');
371
- if (!email) return;
372
- else email = await email.getValue();
373
-
374
- let from = action.form.querySelector('input[key="from"]');
375
- if (from) from = await from.getValue();
376
-
377
- let origin = action.form.querySelector('input[key="origin"]');
378
- if (origin)
379
- origin = (await origin.getValue()) || window.location.origin;
380
-
381
- let hostname = action.form.querySelector('input[key="hostname"]');
382
- if (hostname)
383
- hostname = (await hostname.getValue()) || window.location.hostname;
384
-
385
- let path = action.form.querySelector('input[key="path"]');
386
- if (path) path = await path.getValue();
387
-
388
- let request = {
389
- method: "forgotPassword",
390
- email,
391
- from,
392
- origin,
393
- hostname,
394
- path
395
- };
396
-
397
- Crud.socket.send(request).then((response) => {
398
- if (response.success)
399
- action.element.dispatchEvent(new CustomEvent("forgotPassword"));
400
- render({
401
- selector: "[template*='forgotPassword']",
402
- data: [
403
- {
404
- type: "forgotPassword",
405
- message: response.message,
406
- success: response.success
407
- }
408
- ]
409
- });
410
- });
411
- },
412
-
413
- resetPassword: async function (action) {
414
- let data = {
415
- method: "resetPassword"
416
- };
417
- let email = action.form.querySelector('input[key="email"]');
418
- if (email) data.email = await email.getValue();
419
- else return;
420
-
421
- let password = action.form.querySelector('input[key="password"]');
422
- if (password) data.password = await password.getValue();
423
- else return;
424
-
425
- let token = action.form.querySelector('input[key="token"]');
426
- if (token) data.token = await token.getValue();
427
- else return;
428
-
429
- Crud.socket.send(data).then((data) => {
430
- if (data.success)
431
- action.element.dispatchEvent(new CustomEvent("resetPassword"));
432
- else
433
- render({
434
- selector: "[template*='resetPassword']",
435
- data: [
436
- {
437
- type: "resetPassword",
438
- message: data.message,
439
- success: data.success
440
- }
441
- ]
442
- });
443
- });
444
- }
12
+ organization_id: async () => {
13
+ return await Crud.socket.organization_id();
14
+ },
15
+
16
+ init: function () {
17
+ this.initSocket();
18
+ this.initSession();
19
+ },
20
+
21
+ initSocket: function () {
22
+ const self = this;
23
+ Crud.listen("updateUserStatus", (data) => self.updateUserStatus(data));
24
+ },
25
+
26
+ signUp: async function (action) {
27
+ if (!action.form) return;
28
+
29
+ let data = await Elements.getData(action.form);
30
+ let user = data[0];
31
+
32
+ let userKey = {
33
+ method: "object.create",
34
+ array: "keys",
35
+ object: {
36
+ type: "user",
37
+ key: user.object._id || user.object[0]?._id,
38
+ roles: user.object.roles || [user.object["roles[]"]] || user.object[0]?.roles,
39
+ email: user.object.email || user.object[0]?.email,
40
+ password: user.object.password || window.btoa("0000"),
41
+ array: user.array
42
+ }
43
+ };
44
+
45
+ const socket = await Crud.socket.getSockets();
46
+ if (
47
+ !socket[0] ||
48
+ !socket[0].connected ||
49
+ (window && !window.navigator.onLine) ||
50
+ Crud.socket.serverOrganization == false
51
+ ) {
52
+ user.method = "object.create";
53
+ await Crud.send(user);
54
+ let response = await Crud.send(userKey);
55
+ if (response && response.object && response.object[0]) {
56
+ this.signUpResponse(response, action);
57
+ }
58
+ } else {
59
+ let request = {
60
+ method: "signUp",
61
+ user,
62
+ userKey,
63
+ broadcastBrowser: false
64
+ };
65
+
66
+ Crud.socket.send(request).then((response) => {
67
+ this.signUpResponse(response, action);
68
+ });
69
+ }
70
+ },
71
+
72
+ signUpResponse: function (response, action) {
73
+ render({
74
+ selector: "[template*='signUp']",
75
+ data: [
76
+ {
77
+ type: "signUp",
78
+ message: "Succesfully Signed Up",
79
+ success: true
80
+ }
81
+ ]
82
+ });
83
+
84
+ action.element.dispatchEvent(
85
+ new CustomEvent("signUp", {
86
+ detail: response
87
+ })
88
+ );
89
+ },
90
+
91
+ signIn: async function (action) {
92
+ if (!action.form) return;
93
+ let query = {};
94
+
95
+ const inputs = action.form.querySelectorAll(
96
+ 'input[key="email"], input[key="password"], input[key="username"]'
97
+ );
98
+ for (let i = 0; i < inputs.length; i++) {
99
+ const key = inputs[i].getAttribute("key");
100
+ if (key === "password" && inputs[i].type === "text") {
101
+ inputs[i].type = "password"
102
+ }
103
+ const value = await inputs[i].getValue();
104
+ query[key] = value;
105
+ }
106
+
107
+ let request = {
108
+ method: "object.read",
109
+ array: "keys",
110
+ $filter: {
111
+ query
112
+ }
113
+ };
114
+
115
+ const socket = await Crud.socket.getSockets();
116
+ if (
117
+ !socket[0] ||
118
+ !socket[0].connected ||
119
+ (window && !window.navigator.onLine) ||
120
+ Crud.socket.serverOrganization == false
121
+ ) {
122
+ Crud.send(request).then((response) => {
123
+ response["success"] = false;
124
+ response["status"] = "signIn failed";
125
+ response["message"] = "offline";
126
+ if (response.object && response.object[0]) {
127
+ response["success"] = true;
128
+ response["status"] = "success";
129
+ response["user_id"] = response.object[0].key;
130
+ }
131
+ this.signInResponse(response, action);
132
+ });
133
+ } else {
134
+ request.method = "signIn";
135
+ request.broadcastBrowser = false;
136
+ delete request.storage;
137
+ Crud.socket.send(request).then((response) => {
138
+ this.signInResponse(response, action);
139
+ });
140
+ }
141
+ },
142
+
143
+ signInResponse: function (data, action) {
144
+ let { success, status, message, organization_id, user_id, token } =
145
+ data;
146
+ if (success) {
147
+ // Updated to synchronize values isomorphic-safely via our configuration manager API
148
+ Config.set("organization_id", organization_id);
149
+ Config.set("key", Crud.socket.key);
150
+ Config.set("host", Crud.socket.host);
151
+ Config.set("user_id", user_id);
152
+ Config.set("token", token);
153
+ message = "Successful signIn";
154
+ Crud.socket.user_id = user_id;
155
+ } else if (!message) {
156
+ message = "The email or password you entered is incorrect";
157
+ }
158
+
159
+ render({
160
+ selector: "[template*='signIn']",
161
+ data: [
162
+ {
163
+ type: "signIn",
164
+ status,
165
+ message,
166
+ success
167
+ }
168
+ ]
169
+ });
170
+
171
+ action.element.dispatchEvent(
172
+ new CustomEvent("signIn", {
173
+ detail: {}
174
+ })
175
+ );
176
+ },
177
+
178
+ signOut: function (action) {
179
+ // Synchronously evict user configuration metadata
180
+ Config.remove("user_id");
181
+ Config.remove("token");
182
+
183
+ if (Crud && Crud.socket) {
184
+ Crud.socket.user_id = null;
185
+ if (Crud.socket.token) Crud.socket.token = null;
186
+ }
187
+
188
+ render({
189
+ selector: "[template*='signOut']",
190
+ data: [
191
+ {
192
+ type: "signOut",
193
+ message: "Succesfully logged out",
194
+ success: true
195
+ }
196
+ ]
197
+ });
198
+
199
+ action.element.dispatchEvent(new CustomEvent("signOut"));
200
+ },
201
+
202
+ updateUserStatus: function (data) {
203
+ this.redirect(data);
204
+ let statusEls;
205
+ if (data.user_id) {
206
+ if (data.user_id === Crud.socket.user_id)
207
+ statusEls = document.querySelectorAll(
208
+ `[user-status][object='${data["user_id"]}'], [user-status][object='$user_id']`
209
+ );
210
+ else
211
+ statusEls = document.querySelectorAll(
212
+ `[user-status][object='${data["user_id"]}']`
213
+ );
214
+
215
+ statusEls.forEach((el) => {
216
+ el.setAttribute("user-status", data["userStatus"]);
217
+ });
218
+ }
219
+ },
220
+
221
+ redirect: (data) => {
222
+ const userStatus = data.userStatus;
223
+
224
+ if (
225
+ (data.user_id && data.user_id !== Crud.socket.user_id) ||
226
+ (data.clientId && data.clientId !== Crud.socket.clientId)
227
+ )
228
+ return;
229
+
230
+ let redirectTag;
231
+ if (userStatus == "online" || userStatus == "idle") {
232
+ redirectTag = document.querySelector('[session="true"]');
233
+ } else if (userStatus == "offline") {
234
+ redirectTag = document.querySelector('[session="false"]');
235
+ }
236
+
237
+ if (redirectTag) {
238
+ let redirectLink = redirectTag.getAttribute("href");
239
+ if (redirectLink) {
240
+ if (userStatus == "offline") {
241
+ // Corrected bug: Changed legacy or non-existent .removeItem() to standard .remove()
242
+ Config.remove("user_id");
243
+ Config.remove("token");
244
+ if (Crud && Crud.socket) Crud.socket.user_id = null;
245
+ }
246
+
247
+ // Normalize both URLs to compare paths in a uniform way
248
+ const currentPath = new URL(location.href).pathname.replace(
249
+ "/index.html",
250
+ "/"
251
+ );
252
+ const targetPath = new URL(
253
+ redirectLink,
254
+ location.href
255
+ ).pathname.replace("/index.html", "/");
256
+
257
+ if (currentPath !== targetPath) {
258
+ location.href = redirectLink;
259
+ }
260
+ }
261
+ }
262
+
263
+ if (userStatus) {
264
+ let sessionElements = document.querySelectorAll(
265
+ '[session]:not([session="true"], [session="false"])'
266
+ );
267
+ for (let i = 0; i < sessionElements.length; i++)
268
+ sessionElements[i].setAttribute("session", userStatus);
269
+ }
270
+ },
271
+
272
+ initSession: () => {
273
+ let redirectTag = document.querySelector("[session]");
274
+
275
+ if (redirectTag) {
276
+ Crud.socket.send({
277
+ method: "checkSession",
278
+ broadcast: false,
279
+ broadcastSender: false,
280
+ broadcastBrowser: false
281
+ });
282
+ }
283
+ },
284
+
285
+ inviteUser: async function (action) {
286
+ let email = action.form.querySelector('input[key="email"]');
287
+ if (!email) return;
288
+ else email = await email.getValue();
289
+
290
+ let name = action.form.querySelector('input[key="name"]');
291
+ if (name) name = await name.getValue();
292
+
293
+ let from = action.form.querySelector('input[key="from"]');
294
+ if (from) from = await from.getValue();
295
+
296
+ let origin = action.form.querySelector('input[key="origin"]');
297
+ if (origin)
298
+ origin = (await origin.getValue()) || window.location.origin;
299
+
300
+ let hostname = action.form.querySelector('input[key="hostname"]');
301
+ if (hostname)
302
+ hostname = (await hostname.getValue()) || window.location.hostname;
303
+
304
+ let path = action.form.querySelector('input[key="path"]');
305
+ if (path) path = await path.getValue();
306
+
307
+ let request = {
308
+ method: "inviteUser",
309
+ name,
310
+ email,
311
+ from,
312
+ origin,
313
+ hostname,
314
+ path
315
+ };
316
+
317
+ Crud.socket.send(request).then((response) => {
318
+ if (response.success)
319
+ action.element.dispatchEvent(new CustomEvent("inviteUser"));
320
+
321
+ render({
322
+ selector: "[template*='inviteUser']",
323
+ data: [
324
+ {
325
+ type: "inviteUser",
326
+ message: response.message,
327
+ success: response.success
328
+ }
329
+ ]
330
+ });
331
+ });
332
+ },
333
+
334
+ acceptInvite: async function (action) {
335
+ let data = {
336
+ method: "acceptInvite",
337
+ success: false
338
+ };
339
+
340
+ let token = action.form.querySelector('input[key="token"]');
341
+ if (token) data.token = await token.getValue();
342
+ let user_id = action.form.querySelector('input[key="_id"]');
343
+ if (user_id) data.user_id = await user_id.getValue();
344
+ let email = action.form.querySelector('input[key="email"]');
345
+ if (email) data.email = await email.getValue();
346
+
347
+ if (data.token && data.user_id) {
348
+ data = await Crud.socket.send(data);
349
+ } else {
350
+ data.message = "Invitation failed";
351
+ }
352
+
353
+ if (data.success)
354
+ action.element.dispatchEvent(new CustomEvent("acceptInvite"));
355
+ render({
356
+ selector: "[template*='acceptInvite']",
357
+ data: [
358
+ {
359
+ type: "acceptInvite",
360
+ message: data.message,
361
+ success: data.success
362
+ }
363
+ ]
364
+ });
365
+ },
366
+
367
+ forgotPassword: async function (action) {
368
+ let email = action.form.querySelector('input[key="email"]');
369
+ if (!email) return;
370
+ else email = await email.getValue();
371
+
372
+ let from = action.form.querySelector('input[key="from"]');
373
+ if (from) from = await from.getValue();
374
+
375
+ let origin = action.form.querySelector('input[key="origin"]');
376
+ if (origin)
377
+ origin = (await origin.getValue()) || window.location.origin;
378
+
379
+ let hostname = action.form.querySelector('input[key="hostname"]');
380
+ if (hostname)
381
+ hostname = (await hostname.getValue()) || window.location.hostname;
382
+
383
+ let path = action.form.querySelector('input[key="path"]');
384
+ if (path) path = await path.getValue();
385
+
386
+ let request = {
387
+ method: "forgotPassword",
388
+ email,
389
+ from,
390
+ origin,
391
+ hostname,
392
+ path
393
+ };
394
+
395
+ Crud.socket.send(request).then((response) => {
396
+ if (response.success)
397
+ action.element.dispatchEvent(new CustomEvent("forgotPassword"));
398
+ render({
399
+ selector: "[template*='forgotPassword']",
400
+ data: [
401
+ {
402
+ type: "forgotPassword",
403
+ message: response.message,
404
+ success: response.success
405
+ }
406
+ ]
407
+ });
408
+ });
409
+ },
410
+
411
+ resetPassword: async function (action) {
412
+ let data = {
413
+ method: "resetPassword"
414
+ };
415
+ let email = action.form.querySelector('input[key="email"]');
416
+ if (email) data.email = await email.getValue();
417
+ else return;
418
+
419
+ let password = action.form.querySelector('input[key="password"]');
420
+ if (password) data.password = await password.getValue();
421
+ else return;
422
+
423
+ let token = action.form.querySelector('input[key="token"]');
424
+ if (token) data.token = await token.getValue();
425
+ else return;
426
+
427
+ Crud.socket.send(data).then((data) => {
428
+ if (data.success)
429
+ action.element.dispatchEvent(new CustomEvent("resetPassword"));
430
+ else
431
+ render({
432
+ selector: "[template*='resetPassword']",
433
+ data: [
434
+ {
435
+ type: "resetPassword",
436
+ message: data.message,
437
+ success: data.success
438
+ }
439
+ ]
440
+ });
441
+ });
442
+ }
445
443
  };
446
444
 
447
445
  Actions.init([
448
- {
449
- name: "signUp",
450
- endEvent: "signUp",
451
- callback: (action) => {
452
- CoCreateUser.signUp(action);
453
- }
454
- },
455
- {
456
- name: "signIn",
457
- endEvent: "signIn",
458
- callback: (action) => {
459
- CoCreateUser.signIn(action);
460
- }
461
- },
462
- {
463
- name: "signOut",
464
- endEvent: "signOut",
465
- callback: (action) => {
466
- CoCreateUser.signOut(action);
467
- }
468
- },
469
- {
470
- name: "inviteUser",
471
- endEvent: "inviteUser",
472
- callback: (action) => {
473
- CoCreateUser.inviteUser(action);
474
- }
475
- },
476
- {
477
- name: "acceptInvite",
478
- endEvent: "acceptInvite",
479
- callback: (action) => {
480
- CoCreateUser.acceptInvite(action);
481
- }
482
- },
483
- {
484
- name: "forgotPassword",
485
- endEvent: "forgotPassword",
486
- callback: (action) => {
487
- CoCreateUser.forgotPassword(action);
488
- }
489
- },
490
- {
491
- name: "resetPassword",
492
- endEvent: "resetPassword",
493
- callback: (action) => {
494
- CoCreateUser.resetPassword(action);
495
- }
496
- }
446
+ {
447
+ name: "signUp",
448
+ endEvent: "signUp",
449
+ callback: (action) => {
450
+ CoCreateUser.signUp(action);
451
+ }
452
+ },
453
+ {
454
+ name: "signIn",
455
+ endEvent: "signIn",
456
+ callback: (action) => {
457
+ CoCreateUser.signIn(action);
458
+ }
459
+ },
460
+ {
461
+ name: "signOut",
462
+ endEvent: "signOut",
463
+ callback: (action) => {
464
+ CoCreateUser.signOut(action);
465
+ }
466
+ },
467
+ {
468
+ name: "inviteUser",
469
+ endEvent: "inviteUser",
470
+ callback: (action) => {
471
+ CoCreateUser.inviteUser(action);
472
+ }
473
+ },
474
+ {
475
+ name: "acceptInvite",
476
+ endEvent: "acceptInvite",
477
+ callback: (action) => {
478
+ CoCreateUser.acceptInvite(action);
479
+ }
480
+ },
481
+ {
482
+ name: "forgotPassword",
483
+ endEvent: "forgotPassword",
484
+ callback: (action) => {
485
+ CoCreateUser.forgotPassword(action);
486
+ }
487
+ },
488
+ {
489
+ name: "resetPassword",
490
+ endEvent: "resetPassword",
491
+ callback: (action) => {
492
+ CoCreateUser.resetPassword(action);
493
+ }
494
+ }
497
495
  ]);
498
496
 
499
497
  let checkSessionTimeout;
500
498
  function checkSession() {
501
- clearTimeout(checkSessionTimeout);
502
- checkSessionTimeout = setTimeout(function () {
503
- Crud.socket.send({
504
- method: "checkSession",
505
- broadcast: false,
506
- broadcastBrowser: false
507
- });
508
- }, 500);
499
+ clearTimeout(checkSessionTimeout);
500
+ checkSessionTimeout = setTimeout(function () {
501
+ Crud.socket.send({
502
+ method: "checkSession",
503
+ broadcast: false,
504
+ broadcastBrowser: false
505
+ });
506
+ }, 500);
509
507
  }
510
508
 
511
509
  Observer.init({
512
- name: "CoCreateUserSessionAddedNodes",
513
- types: ["addedNodes"],
514
- selector: "[session]",
515
- callback: () => {
516
- checkSession();
517
- }
510
+ name: "CoCreateUserSessionAddedNodes",
511
+ types: ["addedNodes"],
512
+ selector: "[session]",
513
+ callback: () => {
514
+ checkSession();
515
+ }
518
516
  });
519
517
 
520
518
  CoCreateUser.init();
521
519
 
522
- export default CoCreateUser;
520
+ export default CoCreateUser;
package/src/server.js CHANGED
@@ -36,7 +36,7 @@ async function signUp(data) {
36
36
  success: false,
37
37
  message: "signUp failed",
38
38
  organization_id: data.organization_id,
39
- uid: data.uid
39
+ uuid: data.uuid
40
40
  };
41
41
 
42
42
  const targetEmail = data.user?.object?.email;
@@ -152,7 +152,7 @@ async function signIn(data) {
152
152
  message: "signIn failed",
153
153
  userStatus: "offline",
154
154
  organization_id: result.organization_id,
155
- uid: result.uid
155
+ uuid: result.uuid
156
156
  };
157
157
 
158
158
  if (
@@ -285,8 +285,8 @@ async function inviteUser(data) {
285
285
  if (!server || !server.crud) return;
286
286
 
287
287
  const inviteId = server.crud.ObjectId().toString();
288
- let uid = data.uid;
289
- delete data.uid;
288
+ let uuid = data.uuid;
289
+ delete data.uuid;
290
290
 
291
291
  let targetArray = "users"; // default fallback
292
292
  let keyData = await server.crud.send({
@@ -385,7 +385,7 @@ async function inviteUser(data) {
385
385
  success: true,
386
386
  message: "Successfully sent invite",
387
387
  organization_id: updatedData.organization_id,
388
- uid
388
+ uuid
389
389
  };
390
390
 
391
391
  if (server.wsManager) {
@@ -410,8 +410,8 @@ async function acceptInvite(data) {
410
410
  return;
411
411
  }
412
412
 
413
- let uid = data.uid;
414
- delete data.uid;
413
+ let uuid = data.uuid;
414
+ delete data.uuid;
415
415
 
416
416
  data.method = "object.update";
417
417
  data.array = "users";
@@ -439,7 +439,7 @@ async function acceptInvite(data) {
439
439
  message:
440
440
  "The token is invalid or has expired. However, you can still access your account. Please request a new invite to proceed, and feel free to explore the available features while you wait.",
441
441
  organization_id: updatedData.organization_id,
442
- uid
442
+ uuid
443
443
  };
444
444
 
445
445
  for (let object of updatedData.object) {
@@ -502,7 +502,7 @@ async function forgotPassword(data) {
502
502
  success: false,
503
503
  message: "Email does not exist",
504
504
  organization_id: result.organization_id,
505
- uid: result.uid
505
+ uuid: result.uuid
506
506
  };
507
507
 
508
508
  for (let object of result.object) {
@@ -588,7 +588,7 @@ async function resetPassword(data) {
588
588
  success: false,
589
589
  message: "Token is invalid or has expired",
590
590
  organization_id: result.organization_id,
591
- uid: result.uid
591
+ uuid: result.uuid
592
592
  };
593
593
 
594
594
  for (let object of result.object) {