@cocreate/socket-server 1.26.0 → 1.27.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,22 @@
1
+ ## [1.27.1](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.27.0...v1.27.1) (2024-01-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handling of host and origin. Updated to support new query system ([61a1c68](https://github.com/CoCreate-app/CoCreate-socket-server/commit/61a1c685a1d3466836b19867558842632c7994a4))
7
+
8
+ # [1.27.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.26.0...v1.27.0) (2024-01-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * applied host to define environment/branch ([fad44e5](https://github.com/CoCreate-app/CoCreate-socket-server/commit/fad44e52babae6dd142c22e88214956e2d3dfd97))
14
+
15
+
16
+ ### Features
17
+
18
+ * bumped CoCreate dependencies to their latest versions ([b043307](https://github.com/CoCreate-app/CoCreate-socket-server/commit/b043307cb515a75a6fafd261ddb6295ceaba0ba9))
19
+
1
20
  # [1.26.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.25.0...v1.26.0) (2024-01-03)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/socket-server",
3
- "version": "1.26.0",
3
+ "version": "1.27.1",
4
4
  "description": "CoCreate-socket-server",
5
5
  "keywords": [
6
6
  "cocreate-socket",
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "homepage": "https://cocreate.app/docs/CoCreate-socket-server",
42
42
  "dependencies": {
43
- "@cocreate/config": "^1.8.0",
44
- "@cocreate/uuid": "^1.9.0",
45
- "@cocreate/utils": "^1.29.0",
43
+ "@cocreate/config": "^1.10.0",
44
+ "@cocreate/uuid": "^1.10.0",
45
+ "@cocreate/utils": "^1.30.0",
46
46
  "ws": "7.5.9"
47
47
  }
48
48
  }
package/src/index.js CHANGED
@@ -25,11 +25,11 @@ class SocketServer extends EventEmitter {
25
25
  socket.destroy();
26
26
  });
27
27
 
28
- server.https.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head))
29
- server.http.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head))
28
+ server.https.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head, 'wss'))
29
+ server.http.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head, 'ws'))
30
30
  }
31
31
 
32
- upgrade(request, socket, head) {
32
+ upgrade(request, socket, head, protocol) {
33
33
  const self = this;
34
34
  let organization_id = request.url.split('/')
35
35
  organization_id = organization_id[organization_id.length - 1]
@@ -53,20 +53,19 @@ class SocketServer extends EventEmitter {
53
53
  socket.id = options.socketId;
54
54
  socket.clientId = options.clientId;
55
55
  socket.pathname = request.url
56
- socket.origin = request.headers.origin || request.headers.host
56
+ socket.origin = request.headers.origin
57
+ socket.host = request.headers.host
57
58
 
58
- if (socket.origin.startsWith('http'))
59
- socket.origin = socket.origin.replace('http', 'ws')
60
-
61
- socket.socketUrl = socket.origin + socket.pathname
62
-
63
- if (socket.origin && socket.origin !== 'null') {
59
+ if (!socket.host && socket.origin && socket.origin !== 'null') {
64
60
  if (socket.origin.includes('://'))
65
61
  socket.host = new URL(socket.origin).host
66
62
  else
67
63
  socket.host = socket.origin;
68
64
  }
69
65
 
66
+ socket.socketUrl = protocol + '://' + socket.host + socket.pathname
67
+
68
+
70
69
  // if (!await server.acme.checkCertificate(socket.host, organization_id))
71
70
  // return socket.send(JSON.stringify({ method: 'Access Denied', error: 'Host not whitelisted' }))
72
71
 
@@ -85,9 +84,10 @@ class SocketServer extends EventEmitter {
85
84
  }
86
85
 
87
86
  if (options.lastSynced)
88
- data.$filter.query = [
89
- { key: '_id', value: options.lastSynced, operator: '$gt' }
90
- ]
87
+ data.$filter.query = {
88
+ _id: { $gt: options.lastSynced }
89
+ }
90
+
91
91
  else
92
92
  data.$filter.limit = 1
93
93
 
@@ -152,6 +152,7 @@ class SocketServer extends EventEmitter {
152
152
 
153
153
  this.emit('object.update', {
154
154
  method: 'object.update',
155
+ host: socket.host,
155
156
  array: 'organizations',
156
157
  object: {
157
158
  _id: organization_id, ['$addToSet.activeHost']: socket.socketUrl // needs socketId
@@ -244,6 +245,7 @@ class SocketServer extends EventEmitter {
244
245
  this.organizations.delete(socket.organization_id);
245
246
  this.emit('object.update', {
246
247
  method: 'object.update',
248
+ host: socket.host,
247
249
  array: 'organizations',
248
250
  object: {
249
251
  _id: organization_id, ['$pull.activeHost']: socket.socketUrl
@@ -358,6 +360,7 @@ class SocketServer extends EventEmitter {
358
360
  }
359
361
 
360
362
  data.socket = socket
363
+ data.host = socket.host
361
364
 
362
365
  const authorized = await this.authorize.check(data, socket.user_id)
363
366
  let errors = {}