underpost 3.1.3 → 3.2.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 (87) hide show
  1. package/.env.example +0 -2
  2. package/.github/workflows/ghpkg.ci.yml +4 -4
  3. package/.github/workflows/npmpkg.ci.yml +28 -11
  4. package/.github/workflows/pwa-microservices-template-page.cd.yml +3 -4
  5. package/.github/workflows/pwa-microservices-template-test.ci.yml +3 -3
  6. package/.github/workflows/release.cd.yml +4 -4
  7. package/CHANGELOG.md +324 -1
  8. package/CLI-HELP.md +49 -3
  9. package/README.md +3 -2
  10. package/bin/build.js +18 -12
  11. package/bin/deploy.js +177 -124
  12. package/bin/file.js +3 -0
  13. package/conf.js +3 -2
  14. package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +1 -1
  15. package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +1 -1
  16. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  17. package/manifests/deployment/dd-test-development/deployment.yaml +72 -50
  18. package/manifests/deployment/dd-test-development/proxy.yaml +13 -4
  19. package/manifests/deployment/playwright/deployment.yaml +1 -1
  20. package/nodemon.json +1 -1
  21. package/package.json +22 -15
  22. package/scripts/rhel-grpc-setup.sh +56 -0
  23. package/src/api/file/file.ref.json +18 -0
  24. package/src/api/user/user.service.js +8 -7
  25. package/src/cli/cluster.js +7 -7
  26. package/src/cli/db.js +76 -242
  27. package/src/cli/deploy.js +104 -65
  28. package/src/cli/env.js +1 -0
  29. package/src/cli/fs.js +2 -1
  30. package/src/cli/index.js +42 -1
  31. package/src/cli/kubectl.js +211 -0
  32. package/src/cli/release.js +284 -0
  33. package/src/cli/repository.js +291 -75
  34. package/src/cli/run.js +188 -33
  35. package/src/cli/test.js +3 -3
  36. package/src/client/Default.index.js +3 -4
  37. package/src/client/components/core/AppStore.js +69 -0
  38. package/src/client/components/core/CalendarCore.js +2 -2
  39. package/src/client/components/core/DropDown.js +129 -17
  40. package/src/client/components/core/Keyboard.js +2 -2
  41. package/src/client/components/core/LogIn.js +2 -2
  42. package/src/client/components/core/LogOut.js +2 -2
  43. package/src/client/components/core/Modal.js +0 -1
  44. package/src/client/components/core/Panel.js +0 -1
  45. package/src/client/components/core/PanelForm.js +19 -19
  46. package/src/client/components/core/SocketIo.js +82 -29
  47. package/src/client/components/core/SocketIoHandler.js +75 -0
  48. package/src/client/components/core/Stream.js +143 -95
  49. package/src/client/components/core/Webhook.js +40 -7
  50. package/src/client/components/default/AppStoreDefault.js +5 -0
  51. package/src/client/components/default/LogInDefault.js +3 -3
  52. package/src/client/components/default/LogOutDefault.js +2 -2
  53. package/src/client/components/default/MenuDefault.js +5 -5
  54. package/src/client/components/default/SocketIoDefault.js +3 -51
  55. package/src/client/services/core/core.service.js +20 -8
  56. package/src/client/services/user/user.management.js +2 -2
  57. package/src/index.js +24 -1
  58. package/src/runtime/express/Express.js +18 -1
  59. package/src/runtime/lampp/Dockerfile +9 -2
  60. package/src/runtime/lampp/Lampp.js +4 -3
  61. package/src/runtime/wp/Dockerfile +64 -0
  62. package/src/runtime/wp/Wp.js +497 -0
  63. package/src/server/auth.js +24 -1
  64. package/src/server/backup.js +19 -1
  65. package/src/server/client-build-docs.js +9 -2
  66. package/src/server/client-build.js +31 -31
  67. package/src/server/client-formatted.js +109 -57
  68. package/src/server/ipfs-client.js +24 -1
  69. package/src/server/peer.js +8 -0
  70. package/src/server/runtime.js +25 -1
  71. package/src/server/start.js +6 -0
  72. package/src/ws/IoInterface.js +1 -10
  73. package/src/ws/IoServer.js +14 -33
  74. package/src/ws/core/channels/core.ws.chat.js +65 -20
  75. package/src/ws/core/channels/core.ws.mailer.js +113 -32
  76. package/src/ws/core/channels/core.ws.stream.js +90 -31
  77. package/src/ws/core/core.ws.connection.js +12 -33
  78. package/src/ws/core/core.ws.emit.js +10 -26
  79. package/src/ws/core/core.ws.server.js +25 -58
  80. package/src/ws/default/channels/default.ws.main.js +53 -12
  81. package/src/ws/default/default.ws.connection.js +26 -13
  82. package/src/ws/default/default.ws.server.js +30 -12
  83. package/src/client/components/default/ElementsDefault.js +0 -38
  84. package/src/ws/core/management/core.ws.chat.js +0 -8
  85. package/src/ws/core/management/core.ws.mailer.js +0 -16
  86. package/src/ws/core/management/core.ws.stream.js +0 -8
  87. package/src/ws/default/management/default.ws.main.js +0 -8
@@ -1,23 +1,68 @@
1
- import { loggerFactory } from '../../../server/logger.js';
2
- import { IoCreateChannel } from '../../IoInterface.js';
3
- import { CoreWsEmit } from '../core.ws.emit.js';
4
-
5
- const channel = 'chat';
6
- const logger = loggerFactory(import.meta);
7
-
8
- const CoreWsChatController = {
9
- channel,
10
- controller: function (socket, client, payload, wsManagementId) {
11
- for (const socketId of Object.keys(client)) {
12
- if (socketId !== socket.id) {
13
- CoreWsEmit(channel, client[socketId], { id: socket.id, ...payload });
1
+ /**
2
+ * Chat WebSocket channel — broadcasts messages to all connected sockets except the sender.
3
+ * @module ws/core/channels/core.ws.chat
4
+ */
5
+
6
+ import { IoChannel } from '../../IoInterface.js';
7
+ import { CoreWsEmitter } from '../core.ws.emit.js';
8
+
9
+ /**
10
+ * @class CoreWsChatChannel
11
+ * @classdesc Manages the chat WebSocket channel with per-instance state.
12
+ * Broadcasts incoming messages to all other connected sockets.
13
+ */
14
+ class CoreWsChatChannel {
15
+ /** @type {Object.<string, Object>} Per-instance state keyed by wsManagementId. */
16
+ static #state = {};
17
+
18
+ /** @type {IoChannel} */
19
+ static #io = new IoChannel({
20
+ channel: 'chat',
21
+ controller(socket, client, payload, wsManagementId) {
22
+ for (const socketId of Object.keys(client)) {
23
+ if (socketId !== socket.id) {
24
+ CoreWsEmitter.emit('chat', client[socketId], { id: socket.id, ...payload });
25
+ }
14
26
  }
15
- }
16
- },
17
- connection: function (socket, client, wsManagementId) {},
18
- disconnect: function (socket, client, reason, wsManagementId) {},
19
- };
27
+ },
28
+ });
29
+
30
+ /** @returns {Object.<string, import('socket.io').Socket>} Connected sockets map. */
31
+ static get client() {
32
+ return this.#io.client;
33
+ }
34
+
35
+ /** @returns {string} Channel name. */
36
+ static get channel() {
37
+ return this.#io.channel;
38
+ }
39
+
40
+ /**
41
+ * Initializes state for a server instance.
42
+ * @param {string} wsManagementId - Unique server context ID.
43
+ */
44
+ static init(wsManagementId) {
45
+ this.#state[wsManagementId] = {};
46
+ }
47
+
48
+ /**
49
+ * Registers a socket connection.
50
+ * @param {import('socket.io').Socket} socket
51
+ * @param {string} wsManagementId
52
+ */
53
+ static connection(socket, wsManagementId) {
54
+ return this.#io.connection(socket, wsManagementId);
55
+ }
20
56
 
21
- const CoreWsChatChannel = IoCreateChannel(CoreWsChatController);
57
+ /**
58
+ * Handles socket disconnection.
59
+ * @param {import('socket.io').Socket} socket
60
+ * @param {string} reason
61
+ * @param {string} wsManagementId
62
+ */
63
+ static disconnect(socket, reason, wsManagementId) {
64
+ return this.#io.disconnect(socket, reason, wsManagementId);
65
+ }
66
+ }
22
67
 
23
- export { CoreWsChatChannel, CoreWsChatController };
68
+ export { CoreWsChatChannel };
@@ -1,35 +1,116 @@
1
- import { loggerFactory } from '../../../server/logger.js';
2
- import { IoCreateChannel } from '../../IoInterface.js';
3
- import { CoreWsMailerManagement } from '../management/core.ws.mailer.js';
4
-
5
- const channel = 'mailer';
6
- const logger = loggerFactory(import.meta);
7
-
8
- const CoreWsMailerController = {
9
- channel,
10
- controller: function (socket, client, payload, wsManagementId) {
11
- switch (payload.status) {
12
- case 'register-user':
13
- CoreWsMailerManagement.element[wsManagementId][socket.id] = {
14
- model: {
15
- user: payload.user,
16
- },
17
- };
18
- break;
19
- case 'unregister-user':
20
- delete CoreWsMailerManagement.element[wsManagementId][socket.id];
21
- break;
22
-
23
- default:
24
- break;
1
+ /**
2
+ * Mailer WebSocket channel — manages user↔socket bidirectional mapping
3
+ * for targeted real-time pushes (e.g. email confirmation notifications).
4
+ * @module ws/core/channels/core.ws.mailer
5
+ */
6
+
7
+ import { IoChannel } from '../../IoInterface.js';
8
+
9
+ /**
10
+ * @class CoreWsMailerChannel
11
+ * @classdesc Manages the mailer WebSocket channel with O(1) user↔socket lookup.
12
+ * Handles register/unregister messages and cleanup on disconnect.
13
+ */
14
+ class CoreWsMailerChannel {
15
+ /** @type {Object.<string, Object.<string, { model: { user: Object } }>>} Socket data keyed by `[wsManagementId][socketId]`. */
16
+ static #data = {};
17
+
18
+ /** @type {Object.<string, Object.<string, string>>} Reverse index: `[wsManagementId][userId]` → socketId. */
19
+ static #userIndex = {};
20
+
21
+ /** @type {IoChannel} */
22
+ static #io = new IoChannel({
23
+ channel: 'mailer',
24
+ controller(socket, client, payload, wsManagementId) {
25
+ switch (payload.status) {
26
+ case 'register-user':
27
+ CoreWsMailerChannel.setUser(wsManagementId, socket.id, payload.user);
28
+ break;
29
+ case 'unregister-user':
30
+ CoreWsMailerChannel.removeSocket(wsManagementId, socket.id);
31
+ break;
32
+ default:
33
+ break;
34
+ }
35
+ },
36
+ disconnect(socket, client, reason, wsManagementId) {
37
+ CoreWsMailerChannel.removeSocket(wsManagementId, socket.id);
38
+ },
39
+ });
40
+
41
+ /** @returns {Object.<string, import('socket.io').Socket>} Connected sockets map. */
42
+ static get client() {
43
+ return this.#io.client;
44
+ }
45
+
46
+ /** @returns {string} Channel name. */
47
+ static get channel() {
48
+ return this.#io.channel;
49
+ }
50
+
51
+ /**
52
+ * Initializes state for a server instance.
53
+ * @param {string} wsManagementId - Unique server context ID (`${host}${path}`).
54
+ */
55
+ static init(wsManagementId) {
56
+ this.#data[wsManagementId] = {};
57
+ this.#userIndex[wsManagementId] = {};
58
+ }
59
+
60
+ /**
61
+ * Registers a socket connection.
62
+ * @param {import('socket.io').Socket} socket
63
+ * @param {string} wsManagementId
64
+ */
65
+ static connection(socket, wsManagementId) {
66
+ return this.#io.connection(socket, wsManagementId);
67
+ }
68
+
69
+ /**
70
+ * Handles socket disconnection.
71
+ * @param {import('socket.io').Socket} socket
72
+ * @param {string} reason
73
+ * @param {string} wsManagementId
74
+ */
75
+ static disconnect(socket, reason, wsManagementId) {
76
+ return this.#io.disconnect(socket, reason, wsManagementId);
77
+ }
78
+
79
+ /**
80
+ * Registers a user↔socket mapping.
81
+ * @param {string} wsManagementId
82
+ * @param {string} socketId
83
+ * @param {Object} user - User data with `_id` property.
84
+ */
85
+ static setUser(wsManagementId, socketId, user) {
86
+ this.#data[wsManagementId][socketId] = { model: { user } };
87
+ if (user?._id) {
88
+ this.#userIndex[wsManagementId][user._id.toString()] = socketId;
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Removes a socket entry and its reverse user index.
94
+ * @param {string} wsManagementId
95
+ * @param {string} socketId
96
+ */
97
+ static removeSocket(wsManagementId, socketId) {
98
+ const entry = this.#data[wsManagementId]?.[socketId];
99
+ if (entry?.model?.user?._id) {
100
+ delete this.#userIndex[wsManagementId][entry.model.user._id.toString()];
25
101
  }
26
- },
27
- connection: function (socket, client, wsManagementId) {},
28
- disconnect: function (socket, client, reason, wsManagementId) {
29
- delete CoreWsMailerManagement.element[wsManagementId][socket.id];
30
- },
31
- };
102
+ delete this.#data[wsManagementId]?.[socketId];
103
+ }
32
104
 
33
- const CoreWsMailerChannel = IoCreateChannel(CoreWsMailerController);
105
+ /**
106
+ * Finds the socket ID for a user (O(1) reverse index lookup).
107
+ * @param {string} wsManagementId
108
+ * @param {string} userId - The user `_id`.
109
+ * @returns {string|undefined} Socket ID, or `undefined` if not connected.
110
+ */
111
+ static getUserWsId(wsManagementId, userId) {
112
+ return this.#userIndex[wsManagementId]?.[userId];
113
+ }
114
+ }
34
115
 
35
- export { CoreWsMailerChannel, CoreWsMailerController };
116
+ export { CoreWsMailerChannel };
@@ -1,31 +1,90 @@
1
- import { loggerFactory } from '../../../server/logger.js';
2
- import { IoCreateChannel } from '../../IoInterface.js';
3
- import { CoreWsStreamManagement } from '../management/core.ws.stream.js';
4
-
5
- const channel = 'stream';
6
- const logger = loggerFactory(import.meta);
7
-
8
- const CoreWsStreamController = {
9
- channel,
10
- stream: true,
11
- controller: function (socket, client, payload, wsManagementId, args) {
12
- const [roomId, userId] = args;
13
- CoreWsStreamManagement.element[wsManagementId][socket.id] = args;
14
-
15
- socket.join(roomId); // Join the room
16
- socket.broadcast.emit(`${channel}-user-connected`, userId); // Tell everyone else in the room that we joined
17
- },
18
- connection: function (socket, client, wsManagementId) {
19
- CoreWsStreamManagement.element[wsManagementId][socket.id] = [];
20
- },
21
- disconnect: function (socket, client, reason, wsManagementId) {
22
- // Communicate the disconnection
23
- const [roomId, userId] = CoreWsStreamManagement.element[wsManagementId][socket.id];
24
- socket.broadcast.emit(`${channel}-user-disconnected`, userId);
25
- delete CoreWsStreamManagement.element[wsManagementId][socket.id];
26
- },
27
- };
28
-
29
- const CoreWsStreamChannel = IoCreateChannel(CoreWsStreamController);
30
-
31
- export { CoreWsStreamChannel, CoreWsStreamController };
1
+ /**
2
+ * Stream WebSocket channel — manages per-socket room membership and user tracking.
3
+ * @module ws/core/channels/core.ws.stream
4
+ */
5
+
6
+ import { IoChannel } from '../../IoInterface.js';
7
+
8
+ /**
9
+ * @class CoreWsStreamChannel
10
+ * @classdesc Manages the stream WebSocket channel. Each socket can join a room
11
+ * and broadcast connection/disconnection events to other room members.
12
+ */
13
+ class CoreWsStreamChannel {
14
+ /** @type {Object.<string, Object.<string, Array>>} Per-socket room/user args keyed by `[wsManagementId][socketId]`. */
15
+ static #state = {};
16
+
17
+ /** @type {IoChannel} */
18
+ static #io = new IoChannel({
19
+ channel: 'stream',
20
+ stream: true,
21
+ controller(socket, client, payload, wsManagementId, args) {
22
+ const [roomId, userId] = args;
23
+
24
+ // Collect existing users in the room before registering the new one
25
+ const existingUsers = [];
26
+ for (const entry of Object.values(CoreWsStreamChannel.#state[wsManagementId])) {
27
+ if (entry[0] === roomId && entry[1]) existingUsers.push(entry[1]);
28
+ }
29
+
30
+ CoreWsStreamChannel.#state[wsManagementId][socket.id] = args;
31
+ socket.join(roomId);
32
+ socket.to(roomId).emit('stream-user-connected', userId);
33
+
34
+ // Tell the joining user about everyone already in the room
35
+ if (existingUsers.length > 0) socket.emit('stream-existing-users', existingUsers);
36
+ },
37
+ connection(socket, client, wsManagementId) {
38
+ CoreWsStreamChannel.#state[wsManagementId][socket.id] = [];
39
+ },
40
+ disconnect(socket, client, reason, wsManagementId) {
41
+ const entry = CoreWsStreamChannel.#state[wsManagementId]?.[socket.id];
42
+ if (!entry || entry.length === 0) {
43
+ if (CoreWsStreamChannel.#state[wsManagementId]) delete CoreWsStreamChannel.#state[wsManagementId][socket.id];
44
+ return;
45
+ }
46
+ const [roomId, userId] = entry;
47
+ socket.to(roomId).emit('stream-user-disconnected', userId);
48
+ delete CoreWsStreamChannel.#state[wsManagementId][socket.id];
49
+ },
50
+ });
51
+
52
+ /** @returns {Object.<string, import('socket.io').Socket>} Connected sockets map. */
53
+ static get client() {
54
+ return this.#io.client;
55
+ }
56
+
57
+ /** @returns {string} Channel name. */
58
+ static get channel() {
59
+ return this.#io.channel;
60
+ }
61
+
62
+ /**
63
+ * Initializes state for a server instance.
64
+ * @param {string} wsManagementId - Unique server context ID (`${host}${path}`).
65
+ */
66
+ static init(wsManagementId) {
67
+ this.#state[wsManagementId] = {};
68
+ }
69
+
70
+ /**
71
+ * Registers a socket connection.
72
+ * @param {import('socket.io').Socket} socket
73
+ * @param {string} wsManagementId
74
+ */
75
+ static connection(socket, wsManagementId) {
76
+ return this.#io.connection(socket, wsManagementId);
77
+ }
78
+
79
+ /**
80
+ * Handles socket disconnection.
81
+ * @param {import('socket.io').Socket} socket
82
+ * @param {string} reason
83
+ * @param {string} wsManagementId
84
+ */
85
+ static disconnect(socket, reason, wsManagementId) {
86
+ return this.#io.disconnect(socket, reason, wsManagementId);
87
+ }
88
+ }
89
+
90
+ export { CoreWsStreamChannel };
@@ -1,47 +1,36 @@
1
1
  /**
2
- * Module for handling new WebSocket connections and setting up channel listeners.
3
- * @module ws/core.ws.connection
4
- * @namespace CoreWsConnection
2
+ * Core WebSocket connection handler wires sockets to all channels.
3
+ * @module ws/core/core.ws.connection
5
4
  */
6
5
 
7
6
  import { loggerFactory } from '../../server/logger.js';
8
7
  import { CoreWsChatChannel } from './channels/core.ws.chat.js';
9
8
  import { CoreWsMailerChannel } from './channels/core.ws.mailer.js';
10
9
  import { CoreWsStreamChannel } from './channels/core.ws.stream.js';
11
- import { Socket } from 'socket.io'; // Added for JSDoc type hinting
12
10
 
13
11
  const logger = loggerFactory(import.meta);
14
12
 
15
13
  /**
16
- * @class CoreWsConnectionManager
17
- * @alias CoreWsConnectionManager
18
- * @memberof CoreWsConnection
19
- * @classdesc Manages the lifecycle of a new WebSocket connection, setting up listeners for
20
- * all registered channels (Chat, Mailer, Stream) and handling disconnection by delegating to channel handlers.
14
+ * @class CoreWsConnectionHandler
15
+ * @classdesc Subscribes a new socket to all core channels (chat, mailer, stream)
16
+ * and delegates disconnect events to each channel.
21
17
  */
22
- class CoreWsConnectionManager {
18
+ class CoreWsConnectionHandler {
23
19
  /**
24
- * Handles a new WebSocket connection by subscribing it to all active channels
25
- * and setting up the disconnect listener.
26
- *
27
- * @static
28
- * @param {Socket} socket - The Socket.IO socket object representing the client connection.
29
- * @param {string} wsManagementId - Unique identifier for the WebSocket management context.
30
- * @returns {void}
20
+ * Handles a new WebSocket connection.
21
+ * @param {import('socket.io').Socket} socket
22
+ * @param {string} wsManagementId
31
23
  */
32
- static handleConnection(socket, wsManagementId) {
24
+ static handle(socket, wsManagementId) {
33
25
  logger.info(`New connection established. Socket ID: ${socket.id}`);
34
26
 
35
- // Subscribe socket to all channel connection handlers (assuming these channels are IoChannel instances)
36
27
  CoreWsChatChannel.connection(socket, wsManagementId);
37
28
  CoreWsMailerChannel.connection(socket, wsManagementId);
38
29
  CoreWsStreamChannel.connection(socket, wsManagementId);
39
30
 
40
- // Set up the disconnect listener
41
31
  socket.on('disconnect', (reason) => {
42
- logger.info(`Connection disconnected. Socket ID: ${socket.id} due to reason: ${reason}`);
32
+ logger.info(`Connection disconnected. Socket ID: ${socket.id}, reason: ${reason}`);
43
33
 
44
- // Notify all channels of the disconnection
45
34
  CoreWsChatChannel.disconnect(socket, reason, wsManagementId);
46
35
  CoreWsMailerChannel.disconnect(socket, reason, wsManagementId);
47
36
  CoreWsStreamChannel.disconnect(socket, reason, wsManagementId);
@@ -49,14 +38,4 @@ class CoreWsConnectionManager {
49
38
  }
50
39
  }
51
40
 
52
- /**
53
- * Backward compatibility export for the connection handler function.
54
- * @memberof CoreWsConnection
55
- * @function CoreWsConnection
56
- * @param {Socket} socket - The Socket.IO socket object.
57
- * @param {string} wsManagementId - Unique identifier for the WebSocket management context.
58
- * @returns {void}
59
- */
60
- const CoreWsConnection = CoreWsConnectionManager.handleConnection;
61
-
62
- export { CoreWsConnectionManager, CoreWsConnection };
41
+ export { CoreWsConnectionHandler };
@@ -1,29 +1,24 @@
1
1
  /**
2
- * Module for standardized WebSocket message emission (sending).
3
- * @module ws/core.ws.emit
4
- * @namespace CoreWsEmitter
2
+ * Standardized WebSocket message emission.
3
+ * @module ws/core/core.ws.emit
5
4
  */
6
5
 
7
6
  import { loggerFactory } from '../../server/logger.js';
8
- import { Socket } from 'socket.io';
9
7
 
10
8
  const logger = loggerFactory(import.meta);
11
9
 
12
10
  /**
13
11
  * @class CoreWsEmitter
14
- * @alias CoreWsEmitter
15
- * @memberof CoreWsEmitter
16
- * @classdesc Provides a static utility method for safely emitting messages over a WebSocket connection.
12
+ * @classdesc Provides a static utility for safely emitting JSON-serialized messages over Socket.IO.
17
13
  */
18
14
  class CoreWsEmitter {
19
15
  /**
20
- * Emits a payload to a specific client over a given channel.
21
- * The payload is automatically JSON stringified.
16
+ * Emits a JSON-stringified payload to a client on a given channel.
22
17
  *
23
18
  * @static
24
- * @param {string} [channel=''] - The name of the channel/event to emit on.
25
- * @param {Socket | Object} [client={}] - The Socket.IO client/socket object. Must have an `emit` method.
26
- * @param {Object} [payload={}] - The data object to send.
19
+ * @param {string} channel - The channel/event name to emit on.
20
+ * @param {import('socket.io').Socket} client - The Socket.IO socket to emit to.
21
+ * @param {Object} payload - The data object to send.
27
22
  * @returns {void}
28
23
  */
29
24
  static emit(channel = '', client = {}, payload = {}) {
@@ -31,23 +26,12 @@ class CoreWsEmitter {
31
26
  if (client && typeof client.emit === 'function') {
32
27
  client.emit(channel, JSON.stringify(payload));
33
28
  } else {
34
- logger.error('Invalid client: Cannot emit message.', { channel, client, payload });
29
+ logger.error('Invalid client: Cannot emit message.', { channel, payload });
35
30
  }
36
31
  } catch (error) {
37
- logger.error(error, { channel, client, payload, stack: error.stack });
32
+ logger.error(error, { channel, payload, stack: error.stack });
38
33
  }
39
34
  }
40
35
  }
41
36
 
42
- /**
43
- * Backward compatibility export for the `emit` function.
44
- * @memberof CoreWsEmitter
45
- * @function CoreWsEmit
46
- * @param {string} [channel=''] - The name of the channel/event to emit on.
47
- * @param {Socket | Object} [client={}] - The Socket.IO client/socket object.
48
- * @param {Object} [payload={}] - The data object to send.
49
- * @returns {void}
50
- */
51
- const CoreWsEmit = CoreWsEmitter.emit;
52
-
53
- export { CoreWsEmitter, CoreWsEmit };
37
+ export { CoreWsEmitter };
@@ -1,76 +1,43 @@
1
1
  /**
2
- * Module for creating and initializing the main WebSocket server instance.
3
- * @module ws/core.ws.server
4
- * @namespace CoreWsServer
2
+ * Core WebSocket server factory — initializes channels and creates the Socket.IO server.
3
+ * @module ws/core/core.ws.server
5
4
  */
6
5
 
7
6
  'use strict';
8
7
 
9
- import { IoServerClass } from '../IoServer.js';
10
- import { CoreWsConnection } from './core.ws.connection.js';
11
- import { CoreWsChatManagement } from './management/core.ws.chat.js';
12
- import { CoreWsMailerManagement } from './management/core.ws.mailer.js';
13
- import { CoreWsStreamManagement } from './management/core.ws.stream.js';
14
- import http from 'http'; // Added for JSDoc type hinting
15
-
16
- // https://socket.io/docs/v3/
8
+ import { IoServer } from '../IoServer.js';
9
+ import { CoreWsConnectionHandler } from './core.ws.connection.js';
10
+ import { CoreWsChatChannel } from './channels/core.ws.chat.js';
11
+ import { CoreWsMailerChannel } from './channels/core.ws.mailer.js';
12
+ import { CoreWsStreamChannel } from './channels/core.ws.stream.js';
17
13
 
18
14
  /**
19
- * @class CoreWsServerClass
20
- * @alias CoreWsServerClass
21
- * @memberof CoreWsServer
22
- * @classdesc Manages the creation and initialization of the main WebSocket server,
23
- * including setting up the management instances for all channels.
15
+ * @class CoreWsServer
16
+ * @classdesc Creates the core WebSocket server, initializing all channel state
17
+ * before attaching the connection handler.
24
18
  */
25
- class CoreWsServerClass {
19
+ class CoreWsServer {
26
20
  /**
27
- * Initializes channel management instances and creates the Socket.IO server.
28
- *
29
- * @static
30
- * @async
31
- * @param {http.Server} httpServer - The HTTP server instance to attach the WebSocket server to.
32
- * @param {Object} options - Configuration options for the WebSocket server.
33
- * @param {string} options.host - The host address.
34
- * @param {string} options.path - The base path for the API.
35
- * @returns {Promise<Object>} The result object from IoServer creation.
21
+ * Initializes channel state and creates the Socket.IO server.
22
+ * @param {import('http').Server} httpServer
23
+ * @param {Object} options
24
+ * @param {string} options.host
25
+ * @param {string} options.path
26
+ * @returns {{ options: import('socket.io').ServerOptions, ioServer: import('socket.io').Server, meta: ImportMeta }}
36
27
  */
37
- static async create(httpServer, options) {
28
+ static create(httpServer, options) {
38
29
  const { host, path } = options;
39
- if (!host || !path) {
40
- throw new Error('Host and path must be provided in server options.');
41
- }
42
-
43
- // Create a unique identifier for this server instance's management context
44
30
  const wsManagementId = `${host}${path}`;
45
31
 
46
- // Initialize/Retrieve singleton management instances for all channels
47
- CoreWsChatManagement.instance(wsManagementId);
48
- CoreWsMailerManagement.instance(wsManagementId);
49
- CoreWsStreamManagement.instance(wsManagementId);
32
+ CoreWsChatChannel.init(wsManagementId);
33
+ CoreWsMailerChannel.init(wsManagementId);
34
+ CoreWsStreamChannel.init(wsManagementId);
50
35
 
51
- // Use the IoServerClass factory to create the server, passing the connection handler
52
- return IoServerClass.create(httpServer, options, (socket) => CoreWsConnection(socket, wsManagementId));
36
+ return IoServer.create(httpServer, options, (socket) => CoreWsConnectionHandler.handle(socket, wsManagementId));
53
37
  }
54
38
  }
55
39
 
56
- /**
57
- * Backward compatibility export for the server creation function.
58
- * @memberof CoreWsServer
59
- * @function createIoServer
60
- * @param {http.Server} httpServer - The HTTP server instance.
61
- * @param {Object} options - Configuration options.
62
- * @returns {Promise<Object>} The server creation result.
63
- */
64
- const createIoServer = CoreWsServerClass.create;
65
-
66
- /**
67
- * Backward compatibility alias.
68
- * @memberof CoreWsServer
69
- * @function CoreWsServer
70
- * @param {import('http').Server} httpServer - The HTTP server instance.
71
- * @param {Object} options - Configuration options.
72
- * @returns {Promise<Object>} The server creation result.
73
- */
74
- const CoreWsServer = createIoServer;
40
+ /** Required by Express.js dynamic import: `const { createIoServer } = await import(...)` */
41
+ const createIoServer = CoreWsServer.create.bind(CoreWsServer);
75
42
 
76
- export { CoreWsServerClass, createIoServer, CoreWsServer };
43
+ export { CoreWsServer, createIoServer };