@cocreate/socket-server 1.33.3 → 1.35.0
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/.github/workflows/automated.yml +22 -20
- package/package.json +3 -3
- package/src/index.js +88 -88
|
@@ -9,33 +9,36 @@ jobs:
|
|
|
9
9
|
about:
|
|
10
10
|
runs-on: ubuntu-latest
|
|
11
11
|
steps:
|
|
12
|
-
- name: Checkout
|
|
13
|
-
uses: actions/checkout@
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
- name: Checkout repository
|
|
13
|
+
uses: actions/checkout@v7
|
|
14
|
+
|
|
15
|
+
- name: Sync package.json description to GitHub About
|
|
16
|
+
env:
|
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB }}
|
|
18
|
+
run: |
|
|
19
|
+
DESC=$(jq -r '.description // empty' package.json)
|
|
20
|
+
if [ -n "$DESC" ]; then
|
|
21
|
+
echo "Updating repository description to: $DESC"
|
|
22
|
+
gh api -X PATCH repos/${{ github.repository }} -f description="$DESC"
|
|
23
|
+
else
|
|
24
|
+
echo "No description found in package.json."
|
|
25
|
+
fi
|
|
23
26
|
|
|
24
27
|
release:
|
|
25
28
|
runs-on: ubuntu-latest
|
|
26
29
|
steps:
|
|
27
|
-
- name: Checkout
|
|
28
|
-
uses: actions/checkout@
|
|
30
|
+
- name: Checkout repository
|
|
31
|
+
uses: actions/checkout@v7
|
|
29
32
|
with:
|
|
30
|
-
fetch-depth: 0
|
|
33
|
+
fetch-depth: 0
|
|
34
|
+
token: ${{ secrets.GITHUB }} # Authenticates git CLI for tag/commit pushes
|
|
31
35
|
|
|
32
36
|
- name: Setup Node.js
|
|
33
|
-
uses: actions/setup-node@
|
|
37
|
+
uses: actions/setup-node@v7
|
|
34
38
|
with:
|
|
35
|
-
node-version:
|
|
39
|
+
node-version: '24'
|
|
36
40
|
|
|
37
41
|
- name: Install Semantic Release & Plugins
|
|
38
|
-
# Installs semantic-release and its plugins on the runner
|
|
39
42
|
run: |
|
|
40
43
|
npm install -g semantic-release \
|
|
41
44
|
@semantic-release/changelog \
|
|
@@ -43,12 +46,11 @@ jobs:
|
|
|
43
46
|
@semantic-release/github \
|
|
44
47
|
@semantic-release/git
|
|
45
48
|
|
|
46
|
-
- name: Run Semantic Release
|
|
49
|
+
- name: Run Semantic Release
|
|
47
50
|
id: semantic
|
|
48
|
-
# This will automatically pick up your export default config file in the repository root
|
|
49
51
|
run: npx semantic-release
|
|
50
52
|
env:
|
|
51
|
-
GITHUB_TOKEN: "${{ secrets.
|
|
53
|
+
GITHUB_TOKEN: "${{ secrets.GITHUB }}"
|
|
52
54
|
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
|
|
53
55
|
|
|
54
56
|
outputs:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/socket-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.0",
|
|
4
4
|
"description": "High-density multi-tenant WebSocket orchestration server for real-time state synchronization and cluster-mesh collaboration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"websocket-server",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://cocreate.app/docs/CoCreate-socket-server",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cocreate/config": "^1.
|
|
37
|
-
"@cocreate/utils": "^1.
|
|
36
|
+
"@cocreate/config": "^1.16.0",
|
|
37
|
+
"@cocreate/utils": "^1.46.0",
|
|
38
38
|
"ws": "^8.21.1"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import { EventEmitter } from 'node:events';
|
|
|
24
24
|
import { WebSocketServer } from 'ws';
|
|
25
25
|
import { URL } from 'node:url';
|
|
26
26
|
import { uuid } from '@cocreate/utils';
|
|
27
|
-
import
|
|
27
|
+
import Config from '@cocreate/config';
|
|
28
28
|
|
|
29
29
|
export class SocketServer extends EventEmitter {
|
|
30
30
|
constructor(server) {
|
|
@@ -47,7 +47,7 @@ export class SocketServer extends EventEmitter {
|
|
|
47
47
|
this.authenticate = server.authenticate;
|
|
48
48
|
this.authorize = server.authorize;
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Config.prompt({ organization_id: { prompt: "Enter your organization_id: " } });
|
|
51
51
|
|
|
52
52
|
this.wss = new WebSocketServer({ noServer: true });
|
|
53
53
|
|
|
@@ -710,107 +710,107 @@ export class SocketServer extends EventEmitter {
|
|
|
710
710
|
|
|
711
711
|
// --- POST-EXECUTION METADATA LOGGING ---
|
|
712
712
|
if (
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
}
|
|
738
|
-
if (skeletonArray.length > 0) logPayload.object = skeletonArray;
|
|
739
|
-
} else if (data.object._id) {
|
|
740
|
-
logPayload.object = { _id: data.object._id };
|
|
713
|
+
!data.error && // Only log successful operations
|
|
714
|
+
data.log !== false &&
|
|
715
|
+
data.log !== "false" &&
|
|
716
|
+
!data.method.endsWith(".read") &&
|
|
717
|
+
data.method !== "updateUserStatus" &&
|
|
718
|
+
data.method !== "userStatus" &&
|
|
719
|
+
data.method !== "crdt" &&
|
|
720
|
+
data.method !== "cursor"
|
|
721
|
+
) {
|
|
722
|
+
let logPayload = {
|
|
723
|
+
method: data.method,
|
|
724
|
+
organization_id: data.organization_id,
|
|
725
|
+
user_id: (socket && socket.user_id) || data.user_id,
|
|
726
|
+
timestamp: new Date().toISOString()
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
if (data.endpoint) logPayload.endpoint = data.endpoint;
|
|
730
|
+
if (data.array) logPayload.array = data.array;
|
|
731
|
+
|
|
732
|
+
if (data.object) {
|
|
733
|
+
if (Array.isArray(data.object)) {
|
|
734
|
+
const skeletonArray = [];
|
|
735
|
+
for (const item of data.object) {
|
|
736
|
+
if (item && item._id) skeletonArray.push({ _id: item._id });
|
|
741
737
|
}
|
|
738
|
+
if (skeletonArray.length > 0) logPayload.object = skeletonArray;
|
|
739
|
+
} else if (data.object._id) {
|
|
740
|
+
logPayload.object = { _id: data.object._id };
|
|
742
741
|
}
|
|
743
|
-
|
|
744
|
-
this.emit("object.create", {
|
|
745
|
-
method: "object.create",
|
|
746
|
-
host: data.host || (socket && socket.host),
|
|
747
|
-
array: "message_log",
|
|
748
|
-
object: logPayload,
|
|
749
|
-
organization_id: data.organization_id
|
|
750
|
-
});
|
|
751
742
|
}
|
|
752
743
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
cleanData.$filter.query._id.$eq === "$user_id"
|
|
762
|
-
) {
|
|
763
|
-
delete cleanData.$filter.query._id;
|
|
764
|
-
}
|
|
744
|
+
this.emit("object.create", {
|
|
745
|
+
method: "object.create",
|
|
746
|
+
host: data.host || (socket && socket.host),
|
|
747
|
+
array: "message_log",
|
|
748
|
+
object: logPayload,
|
|
749
|
+
organization_id: data.organization_id
|
|
750
|
+
});
|
|
751
|
+
}
|
|
765
752
|
|
|
766
|
-
|
|
753
|
+
let sockets = this.get(data);
|
|
754
|
+
let cleanData = { ...data };
|
|
755
|
+
delete cleanData.socket;
|
|
756
|
+
|
|
757
|
+
if (
|
|
758
|
+
cleanData.$filter &&
|
|
759
|
+
cleanData.$filter.query &&
|
|
760
|
+
cleanData.$filter.query._id &&
|
|
761
|
+
cleanData.$filter.query._id.$eq === "$user_id"
|
|
762
|
+
) {
|
|
763
|
+
delete cleanData.$filter.query._id;
|
|
764
|
+
}
|
|
767
765
|
|
|
768
|
-
|
|
769
|
-
if (!recipientSocket) continue;
|
|
766
|
+
const defaultPayloadStr = JSON.stringify(cleanData);
|
|
770
767
|
|
|
771
|
-
|
|
772
|
-
|
|
768
|
+
for (const recipientSocket of sockets) {
|
|
769
|
+
if (!recipientSocket) continue;
|
|
773
770
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
cleanData,
|
|
777
|
-
recipientSocket.user_id
|
|
778
|
-
);
|
|
779
|
-
|
|
780
|
-
if (authResult === false) {
|
|
781
|
-
continue;
|
|
782
|
-
}
|
|
771
|
+
let payloadStr = defaultPayloadStr;
|
|
772
|
+
let finalDataObj = cleanData;
|
|
783
773
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
finalDataObj.$filter.query._id.$eq === "$user_id"
|
|
793
|
-
) {
|
|
794
|
-
delete finalDataObj.$filter.query._id;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
payloadStr = JSON.stringify(finalDataObj);
|
|
798
|
-
}
|
|
774
|
+
if (authorizeService) {
|
|
775
|
+
const authResult = await authorizeService.check(
|
|
776
|
+
cleanData,
|
|
777
|
+
recipientSocket.user_id
|
|
778
|
+
);
|
|
779
|
+
|
|
780
|
+
if (authResult === false) {
|
|
781
|
+
continue;
|
|
799
782
|
}
|
|
800
783
|
|
|
801
|
-
|
|
784
|
+
if (authResult !== true && authResult && authResult.authorized) {
|
|
785
|
+
finalDataObj = { ...authResult.authorized };
|
|
786
|
+
delete finalDataObj.socket;
|
|
802
787
|
|
|
803
|
-
|
|
804
|
-
|
|
788
|
+
if (
|
|
789
|
+
finalDataObj.$filter &&
|
|
790
|
+
finalDataObj.$filter.query &&
|
|
791
|
+
finalDataObj.$filter.query._id &&
|
|
792
|
+
finalDataObj.$filter.query._id.$eq === "$user_id"
|
|
793
|
+
) {
|
|
794
|
+
delete finalDataObj.$filter.query._id;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
payloadStr = JSON.stringify(finalDataObj);
|
|
805
798
|
}
|
|
806
|
-
|
|
807
|
-
this.emit("usage", {
|
|
808
|
-
type: "egress",
|
|
809
|
-
data: finalDataObj,
|
|
810
|
-
organization_id: recipientSocket.organization_id
|
|
811
|
-
});
|
|
812
799
|
}
|
|
813
800
|
|
|
801
|
+
this._safeSend(recipientSocket, payloadStr);
|
|
802
|
+
|
|
803
|
+
if (recipientSocket.clientId) {
|
|
804
|
+
sent.push(recipientSocket.clientId);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
this.emit("usage", {
|
|
808
|
+
type: "egress",
|
|
809
|
+
data: finalDataObj,
|
|
810
|
+
organization_id: recipientSocket.organization_id
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
|
|
814
814
|
// Send data to socketMesh
|
|
815
815
|
if (cleanData.organization_id) {
|
|
816
816
|
this.server.send({
|