@cocreate/users 1.21.3 → 1.21.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +8 -8
  3. package/src/server.js +140 -138
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.21.5](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.4...v1.21.5) (2023-05-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Simplify CoCreateUser class by adding async/await and removing unnecessary commented code. ([bd22d42](https://github.com/CoCreate-app/CoCreate-users/commit/bd22d42c6e73be130c6d208bb8010b1056e0da0a))
7
+
8
+ ## [1.21.4](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.3...v1.21.4) (2023-05-19)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update packages to latest version. This commit updates various packages in the dependencies section of the package.json file to their latest published versions, thereby fixing multiple bugs and improving overall performance. ([57377f1](https://github.com/CoCreate-app/CoCreate-users/commit/57377f19ca386d3d1db4fd22b4a4d7a5ec4eb710))
14
+
1
15
  ## [1.21.3](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.2...v1.21.3) (2023-05-18)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/users",
3
- "version": "1.21.3",
3
+ "version": "1.21.5",
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",
@@ -59,12 +59,12 @@
59
59
  "webpack-log": "^3.0.1"
60
60
  },
61
61
  "dependencies": {
62
- "@cocreate/actions": "^1.8.8",
63
- "@cocreate/crud-client": "^1.20.4",
64
- "@cocreate/docs": "^1.7.8",
65
- "@cocreate/element-prototype": "^1.8.7",
66
- "@cocreate/form": "^1.14.6",
67
- "@cocreate/local-storage": "^1.6.8",
68
- "@cocreate/render": "^1.24.8"
62
+ "@cocreate/actions": "^1.8.11",
63
+ "@cocreate/crud-client": "^1.21.2",
64
+ "@cocreate/docs": "^1.7.11",
65
+ "@cocreate/element-prototype": "^1.8.11",
66
+ "@cocreate/form": "^1.14.11",
67
+ "@cocreate/local-storage": "^1.7.2",
68
+ "@cocreate/render": "^1.24.11"
69
69
  }
70
70
  }
package/src/server.js CHANGED
@@ -1,142 +1,144 @@
1
1
  class CoCreateUser {
2
- constructor(crud) {
3
- this.wsManager = crud.wsManager
4
- this.crud = crud
5
- this.init()
6
- }
7
-
8
- init() {
9
- if (this.wsManager) {
10
- this.wsManager.on('signUp', (socket, data) => this.signUp(socket, data));
11
- this.wsManager.on('signIn', (socket, data) => this.signIn(socket, data))
12
- this.wsManager.on('userStatus', (socket, data) => this.userStatus(socket, data))
13
- }
14
- }
15
-
16
- async signUp(socket, data) {
17
- const self = this;
18
- if (!data.document) return;
19
-
20
- try {
21
- // Create new user in config db users collection
22
- this.crud.createDocument(data).then((data) => {
23
- if (data.document[0] && data.document[0]._id) {
24
- // const orgDB = data.orgDB;
25
-
26
- // if new orgDb Create new user in new org db users collection
27
- // if (orgDB && orgDB != data.organization_id) {
28
- // let Data = {...data, organization_id: orgDB}
29
- // self.crud.createDocument(Data)
30
- // }
31
-
32
- self.wsManager.broadcast(socket, 'updateDocument', data);
33
- self.wsManager.send(socket, 'signUp', data);
34
-
35
-
36
- // add new user to platformDB
37
- if (data.organization_id != process.env.organization_id) {
38
- let Data = {...data, organization_id: process.env.organization_id}
39
- self.crud.createDocument(Data)
40
- }
41
- }
42
-
43
- // self.wsManager.broadcast(socket, 'updateUserStatus', data)
44
- })
45
- } catch(error) {
46
- console.log('createDocument error', error);
47
- }
48
- }
49
-
50
-
51
- /**
52
- data = {
53
- namespace: string,
54
- collection: string,
55
- data: object,
56
- eId: string,
57
- key: string,
58
- organization_id: string
59
- }
60
- **/
61
- async signIn(socket, data) {
62
- const self = this;
63
- try {
64
- this.crud.updateDocument(data).then(async (data) => {
65
- let response = {
66
- ...data,
67
- success: false,
68
- message: "signIn failed",
69
- status: "failed",
70
- userStatus: 'off'
71
- }
72
-
73
- if (data.document[0] && data.document[0]._id) {
74
- let token = null;
75
- if (self.wsManager.authInstance) {
76
- token = await self.wsManager.authInstance.generateToken({user_id: data.document[0]._id});
77
- }
78
-
79
- if (token && token != 'null')
80
- response = { ...response,
81
- success: true,
82
- message: "signIn successful",
83
- status: "success",
84
- userStatus: 'on',
85
- token
86
- };
87
-
88
-
89
- if (data.organization_id != process.env.organization_id) {
90
- let Data = {organization_id: process.env.organization_id}
91
- Data.document['_id'] = data.document[0]._id
92
- Data.document['lastsignIn'] = data.document[0].lastsignIn
93
- Data.document['organization_id'] = process.env.organization_id
94
- crud.updateDocument(Data)
95
- }
96
-
97
- }
98
- self.wsManager.send(socket, 'signIn', response)
99
- self.wsManager.broadcast(socket, 'updateUserStatus', {
100
- user_id: response.user_id,
101
- userStatus: response.userStatus,
102
- organization_id: response.organization_id
103
- })
104
- })
105
-
106
- } catch (error) {
107
- console.log('signIn failed', error);
108
- }
109
- }
110
-
111
-
112
- /**
113
- * status: 'on/off/idle'
114
- */
115
- async userStatus(socket, data) {
116
- const self = this;
117
- try {
118
- if (!data.user_id || !data.userStatus)
119
- return
120
- data.collection = 'users'
121
- data['document'] = {
122
- _id: data.user_id,
123
- userStatus: data.userStatus
124
- }
125
-
126
- this.crud.updateDocument(data).then((data) => {
127
- // self.wsManager.broadcast(socket, 'updateUserStatus', data)
128
- self.wsManager.broadcast(socket, 'updateUserStatus', {
129
- user_id: data.user_id,
130
- userStatus: data.userStatus,
131
- organization_id: data.organization_id || socket.config.organization_id
132
- })
133
-
134
- })
135
-
136
- } catch (error) {
137
- console.log('userStatus error')
138
- }
139
- }
2
+ constructor(crud) {
3
+ this.wsManager = crud.wsManager
4
+ this.crud = crud
5
+ this.init()
6
+ }
7
+
8
+ init() {
9
+ if (this.wsManager) {
10
+ this.wsManager.on('signUp', (socket, data) => this.signUp(socket, data));
11
+ this.wsManager.on('signIn', (socket, data) => this.signIn(socket, data))
12
+ this.wsManager.on('userStatus', (socket, data) => this.userStatus(socket, data))
13
+ }
14
+ }
15
+
16
+ async signUp(socket, data) {
17
+ const self = this;
18
+ if (!data.document) return;
19
+
20
+ try {
21
+ // Create new user in config db users collection
22
+ this.crud.createDocument(data).then((data) => {
23
+ if (data.document[0] && data.document[0]._id) {
24
+ // const orgDB = data.orgDB;
25
+
26
+ // if new orgDb Create new user in new org db users collection
27
+ // if (orgDB && orgDB != data.organization_id) {
28
+ // let Data = {...data, organization_id: orgDB}
29
+ // self.crud.createDocument(Data)
30
+ // }
31
+
32
+ self.wsManager.broadcast(socket, 'updateDocument', data);
33
+ self.wsManager.send(socket, 'signUp', data);
34
+
35
+
36
+ // add new user to platformDB
37
+ if (data.organization_id != process.env.organization_id) {
38
+ let Data = { ...data, organization_id: process.env.organization_id }
39
+ self.crud.createDocument(Data)
40
+ }
41
+ }
42
+
43
+ // self.wsManager.broadcast(socket, 'updateUserStatus', data)
44
+ })
45
+ } catch (error) {
46
+ console.log('createDocument error', error);
47
+ }
48
+ }
49
+
50
+
51
+ /**
52
+ data = {
53
+ namespace: string,
54
+ collection: string,
55
+ data: object,
56
+ eId: string,
57
+ key: string,
58
+ organization_id: string
59
+ }
60
+ **/
61
+ async signIn(socket, data) {
62
+ const self = this;
63
+ try {
64
+ data.collection = 'keys'
65
+ this.crud.updateDocument(data).then(async (data) => {
66
+ let response = {
67
+ ...data,
68
+ success: false,
69
+ message: "signIn failed",
70
+ status: "failed",
71
+ userStatus: 'off'
72
+ }
73
+
74
+ if (data.document[0] && data.document[0]._id) {
75
+ let token = null;
76
+ if (self.wsManager.authInstance) {
77
+ token = await self.wsManager.authInstance.generateToken({ user_id: data.document[0]._id });
78
+ }
79
+
80
+ if (token && token != 'null')
81
+ response = {
82
+ ...response,
83
+ success: true,
84
+ message: "signIn successful",
85
+ status: "success",
86
+ userStatus: 'on',
87
+ token
88
+ };
89
+
90
+
91
+ if (data.organization_id != process.env.organization_id) {
92
+ let Data = { organization_id: process.env.organization_id }
93
+ Data.document['_id'] = data.document[0]._id
94
+ Data.document['lastsignIn'] = data.document[0].lastsignIn
95
+ Data.document['organization_id'] = process.env.organization_id
96
+ crud.updateDocument(Data)
97
+ }
98
+
99
+ }
100
+ self.wsManager.send(socket, 'signIn', response)
101
+ self.wsManager.broadcast(socket, 'updateUserStatus', {
102
+ user_id: response.user_id,
103
+ userStatus: response.userStatus,
104
+ organization_id: response.organization_id
105
+ })
106
+ })
107
+
108
+ } catch (error) {
109
+ console.log('signIn failed', error);
110
+ }
111
+ }
112
+
113
+
114
+ /**
115
+ * status: 'on/off/idle'
116
+ */
117
+ async userStatus(socket, data) {
118
+ const self = this;
119
+ try {
120
+ if (!data.user_id || !data.userStatus)
121
+ return
122
+ data.collection = 'users'
123
+ data['document'] = {
124
+ _id: data.user_id,
125
+ userStatus: data.userStatus
126
+ }
127
+
128
+ this.crud.updateDocument(data).then((data) => {
129
+ // self.wsManager.broadcast(socket, 'updateUserStatus', data)
130
+ self.wsManager.broadcast(socket, 'updateUserStatus', {
131
+ user_id: data.user_id,
132
+ userStatus: data.userStatus,
133
+ organization_id: data.organization_id || socket.config.organization_id
134
+ })
135
+
136
+ })
137
+
138
+ } catch (error) {
139
+ console.log('userStatus error')
140
+ }
141
+ }
140
142
  }
141
143
 
142
144
  module.exports = CoCreateUser;