@cocreate/socket-server 1.33.3 → 1.34.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +88 -88
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/socket-server",
3
- "version": "1.33.3",
3
+ "version": "1.34.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.13.4",
37
- "@cocreate/utils": "^1.42.2",
36
+ "@cocreate/config": "^1.14.3",
37
+ "@cocreate/utils": "^1.44.3",
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 config from '@cocreate/config';
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
- config.request({ organization_id: { prompt: "Enter your organization_id: " } });
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
- !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 });
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
- 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
- }
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
- const defaultPayloadStr = JSON.stringify(cleanData);
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
- for (const recipientSocket of sockets) {
769
- if (!recipientSocket) continue;
766
+ const defaultPayloadStr = JSON.stringify(cleanData);
770
767
 
771
- let payloadStr = defaultPayloadStr;
772
- let finalDataObj = cleanData;
768
+ for (const recipientSocket of sockets) {
769
+ if (!recipientSocket) continue;
773
770
 
774
- if (authorizeService) {
775
- const authResult = await authorizeService.check(
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
- if (authResult !== true && authResult && authResult.authorized) {
785
- finalDataObj = { ...authResult.authorized };
786
- delete finalDataObj.socket;
787
-
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);
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
- this._safeSend(recipientSocket, payloadStr);
784
+ if (authResult !== true && authResult && authResult.authorized) {
785
+ finalDataObj = { ...authResult.authorized };
786
+ delete finalDataObj.socket;
802
787
 
803
- if (recipientSocket.clientId) {
804
- sent.push(recipientSocket.clientId);
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({