@cocreate/socket-server 1.9.0 → 1.10.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.10.1](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.10.0...v1.10.1) (2023-05-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Update dependencies versions ([d3cad89](https://github.com/CoCreate-app/CoCreate-socket-server/commit/d3cad89ad28f8b90c89b9fd3f30acab59496a623))
7
+
8
+ # [1.10.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.9.0...v1.10.0) (2023-05-25)
9
+
10
+
11
+ ### Features
12
+
13
+ * Simplify WebSocketServer Class, Replace Permission and Auth Instance with Single functions. ([4ec6eb3](https://github.com/CoCreate-app/CoCreate-socket-server/commit/4ec6eb35e034a119c3f4e24a054a7708f04e8ac4))
14
+
1
15
  # [1.9.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.8.2...v1.9.0) (2023-05-24)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/socket-server",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "description": "CoCreate-socket-server",
5
5
  "keywords": [
6
6
  "cocreate-socket",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "homepage": "https://cocreate.app/docs/CoCreate-socket-server",
42
42
  "dependencies": {
43
- "@cocreate/docs": "^1.7.11",
44
- "@cocreate/uuid": "^1.4.10"
43
+ "@cocreate/docs": "^1.7.13",
44
+ "@cocreate/uuid": "^1.4.11"
45
45
  },
46
46
  "devDependencies": {
47
47
  "express": "^4.17.1",
package/src/index.js CHANGED
@@ -15,16 +15,6 @@ class SocketServer extends EventEmitter {
15
15
 
16
16
  //. websocket server
17
17
  this.wss = new WebSocket.Server({ noServer: true });
18
- this.permissionInstance = null;
19
- this.authInstance = null;
20
- }
21
-
22
- setPermission(instance) {
23
- this.permissionInstance = instance;
24
- }
25
-
26
- setAuth(instance) {
27
- this.authInstance = instance
28
18
  }
29
19
 
30
20
  handleUpgrade(req, socket, head) {
@@ -138,17 +128,17 @@ class SocketServer extends EventEmitter {
138
128
  organization_id
139
129
  });
140
130
  let user_id = null;
141
- if (this.authInstance)
142
- user_id = await this.authInstance.getUserId(req);
131
+ if (this.authenticate)
132
+ user_id = await this.authenticate.getUserId(req);
143
133
 
144
- if (this.permissionInstance) {
134
+ if (this.authorize) {
145
135
  data.host = this.getHost(req)
146
- const permission = await this.permissionInstance.check(action, data, user_id)
136
+ const permission = await this.authorize.check(action, data, user_id)
147
137
  if (permission.dbUrl === false) {
148
138
  data.database = process.env.organization_id
149
139
  data.organization_id = process.env.organization_id
150
140
 
151
- const permission2 = await this.permissionInstance.check(action, data, req, user_id)
141
+ const permission2 = await this.authorize.check(action, data, req, user_id)
152
142
  if (!permission2 || permission2.error) {
153
143
  return this.send(socket, 'Access Denied', { action, permission2, ...data })
154
144
  }
@@ -258,7 +248,7 @@ class SocketServer extends EventEmitter {
258
248
  if (isAsync) {
259
249
  asyncData.push({ socket, message: JSON.stringify({ action, data }) })
260
250
  } else {
261
- const permission = await this.permissionInstance.check(action, data, socket.config.user_id)
251
+ const permission = await this.authorize.check(action, data, socket.config.user_id)
262
252
  if (permission && permission.authorized)
263
253
  data = permission.authorized
264
254