@cocreate/socket-server 1.20.2 → 1.21.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 +15 -0
- package/package.json +1 -1
- package/src/index.js +38 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.21.1](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.21.0...v1.21.1) (2023-10-24)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* allow organization to connect if serverOrganization false ([b91a1b5](https://github.com/CoCreate-app/CoCreate-socket-server/commit/b91a1b574ecb14604245930bd8ebf563f9e9f445))
|
|
7
|
+
* return access denied ([bb9a929](https://github.com/CoCreate-app/CoCreate-socket-server/commit/bb9a929481fc34fc2ead377577100cf6908c4707))
|
|
8
|
+
|
|
9
|
+
# [1.21.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.20.2...v1.21.0) (2023-10-22)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* ObjectId() returns an object containg the parts iof the _id along with a toString() function ([d0fffc7](https://github.com/CoCreate-app/CoCreate-socket-server/commit/d0fffc777f099b242a0dccfe5ed6b8008d54dda2))
|
|
15
|
+
|
|
1
16
|
## [1.20.2](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.20.1...v1.20.2) (2023-10-21)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,7 +2,6 @@ const WebSocket = require('ws');
|
|
|
2
2
|
const { URL } = require("url");
|
|
3
3
|
const EventEmitter = require("events").EventEmitter;
|
|
4
4
|
const uid = require('@cocreate/uuid')
|
|
5
|
-
// const { ObjectId } = require('@cocreate/utils')
|
|
6
5
|
const config = require('@cocreate/config')
|
|
7
6
|
|
|
8
7
|
class SocketServer extends EventEmitter {
|
|
@@ -62,45 +61,48 @@ class SocketServer extends EventEmitter {
|
|
|
62
61
|
socket.host = url.host || socket.origin;
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
if (organization && organization.status !== false) {
|
|
65
|
+
let data = {
|
|
66
|
+
socket,
|
|
67
|
+
method: 'read.object',
|
|
68
|
+
array: 'message_log',
|
|
69
|
+
$filter: {
|
|
70
|
+
sort: [
|
|
71
|
+
{ key: '_id', direction: 'desc' }
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
sync: true,
|
|
75
|
+
organization_id
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (options.lastSynced)
|
|
79
|
+
data.$filter.query = [
|
|
80
|
+
{ key: '_id', value: options.lastSynced, operator: '$gt' }
|
|
72
81
|
]
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
else
|
|
83
|
+
data.$filter.limit = 1
|
|
84
|
+
|
|
85
|
+
self.emit('read.object', data);
|
|
86
|
+
|
|
87
|
+
if (self.authenticate) {
|
|
88
|
+
const { user_id, expires } = self.authenticate.decodeToken(options.token)
|
|
89
|
+
const userStatus = { socket, method: 'userStatus', user_id: options.user_id, userStatus: 'off', organization_id }
|
|
90
|
+
if (user_id) {
|
|
91
|
+
options.user_id = user_id
|
|
92
|
+
socket.user_id = user_id;
|
|
93
|
+
socket.expires = expires;
|
|
94
|
+
userStatus.userStatus = 'on'
|
|
95
|
+
self.emit("notification.user", socket)
|
|
96
|
+
}
|
|
77
97
|
|
|
78
|
-
|
|
79
|
-
data.$filter.query = [
|
|
80
|
-
{ key: '_id', value: options.lastSynced, operator: '$gt' }
|
|
81
|
-
]
|
|
82
|
-
else
|
|
83
|
-
data.$filter.limit = 1
|
|
84
|
-
|
|
85
|
-
self.emit('read.object', data);
|
|
86
|
-
|
|
87
|
-
if (self.authenticate) {
|
|
88
|
-
const { user_id, expires } = self.authenticate.decodeToken(options.token)
|
|
89
|
-
const userStatus = { socket, method: 'userStatus', user_id: options.user_id, userStatus: 'off', organization_id }
|
|
90
|
-
if (user_id) {
|
|
91
|
-
options.user_id = user_id
|
|
92
|
-
socket.user_id = user_id;
|
|
93
|
-
socket.expires = expires;
|
|
94
|
-
userStatus.userStatus = 'on'
|
|
95
|
-
self.emit("notification.user", socket)
|
|
96
|
-
}
|
|
98
|
+
self.emit('userStatus', userStatus);
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
self.onWebSocket(socket);
|
|
99
101
|
|
|
100
|
-
|
|
102
|
+
} else
|
|
103
|
+
self.onWebSocket(socket);
|
|
104
|
+
}
|
|
101
105
|
|
|
102
|
-
} else
|
|
103
|
-
self.onWebSocket(socket);
|
|
104
106
|
} else {
|
|
105
107
|
socket.send(JSON.stringify({ method: 'Access Denied', error: 'An organization_id is required' }))
|
|
106
108
|
}
|
|
@@ -421,7 +423,7 @@ class SocketServer extends EventEmitter {
|
|
|
421
423
|
if (authorized && authorized.authorized)
|
|
422
424
|
data = authorized.authorized
|
|
423
425
|
|
|
424
|
-
if (!data.method.startsWith('read.') && data.method !== 'updateUserStatus' && data.method !== 'userStatus' && data.method !== 'signIn' && data.method !== 'signUp') {
|
|
426
|
+
if (data.log !== false && data.log !== 'false' && !data.method.startsWith('read.') && data.method !== 'updateUserStatus' && data.method !== 'userStatus' && data.method !== 'signIn' && data.method !== 'signUp') {
|
|
425
427
|
let object = { url: socket.socketUrl, data }
|
|
426
428
|
delete object.socket
|
|
427
429
|
this.emit('create.object', {
|