underpost 2.8.884 → 2.8.885

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 (43) hide show
  1. package/README.md +4 -120
  2. package/bin/deploy.js +9 -10
  3. package/bin/file.js +4 -6
  4. package/cli.md +15 -11
  5. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  6. package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
  7. package/package.json +1 -1
  8. package/src/cli/cluster.js +21 -0
  9. package/src/cli/cron.js +8 -0
  10. package/src/cli/db.js +63 -1
  11. package/src/cli/deploy.js +156 -3
  12. package/src/cli/env.js +43 -0
  13. package/src/cli/fs.js +94 -0
  14. package/src/cli/image.js +8 -0
  15. package/src/cli/index.js +17 -4
  16. package/src/cli/monitor.js +0 -1
  17. package/src/cli/repository.js +95 -2
  18. package/src/client/components/core/Css.js +16 -0
  19. package/src/client/components/core/Docs.js +5 -13
  20. package/src/client/components/core/Modal.js +48 -29
  21. package/src/client/components/core/Router.js +6 -3
  22. package/src/client/components/core/Worker.js +205 -118
  23. package/src/client/components/default/MenuDefault.js +1 -0
  24. package/src/client.dev.js +6 -3
  25. package/src/db/DataBaseProvider.js +65 -12
  26. package/src/db/mariadb/MariaDB.js +39 -6
  27. package/src/db/mongo/MongooseDB.js +51 -133
  28. package/src/index.js +1 -1
  29. package/src/mailer/EmailRender.js +58 -9
  30. package/src/mailer/MailerProvider.js +98 -25
  31. package/src/runtime/express/Express.js +20 -34
  32. package/src/server/auth.js +9 -28
  33. package/src/server/client-build-live.js +14 -5
  34. package/src/server/client-dev-server.js +21 -8
  35. package/src/server/conf.js +78 -25
  36. package/src/server/peer.js +2 -2
  37. package/src/server/runtime.js +0 -5
  38. package/src/server/start.js +39 -0
  39. package/src/ws/IoInterface.js +132 -39
  40. package/src/ws/IoServer.js +79 -31
  41. package/src/ws/core/core.ws.connection.js +50 -16
  42. package/src/ws/core/core.ws.emit.js +47 -8
  43. package/src/ws/core/core.ws.server.js +62 -10
@@ -1,39 +1,87 @@
1
+ /**
2
+ * Module for creating and managing WebSocket servers.
3
+ * @module src/ws/IoServer
4
+ * @namespace SocketIoServer
5
+ */
6
+
1
7
  'use strict';
2
8
 
3
9
  import { Server } from 'socket.io';
4
10
  import { loggerFactory } from '../server/logger.js';
11
+ import UnderpostStartUp from '../server/start.js';
5
12
 
6
- // https://socket.io/docs/v3/
13
+ import http from 'http';
7
14
 
8
15
  const logger = loggerFactory(import.meta);
9
16
 
10
- const IoServer = (httpServer, options = {}, Connection = () => {}) => {
11
- const wsOptions = {
12
- cors: {
13
- // origin: `http://localhost:${options.port}`,
14
- origins: options.origins,
15
- methods: ['GET', 'POST', 'DELETE', 'PUT'],
16
- allowedHeaders: [
17
- 'Access-Control-Allow-Headers',
18
- 'Access-Control-Allow-Origin',
19
- 'X-Requested-With',
20
- 'X-Access-Token',
21
- 'Content-Type',
22
- 'Host',
23
- 'Accept',
24
- 'Connection',
25
- 'Cache-Control',
26
- 'Authorization',
27
- ],
28
- credentials: true,
29
- },
30
- path: options.path !== '/' ? `${options.path}/socket.io/` : '/socket.io',
31
- };
32
- return {
33
- options: wsOptions,
34
- meta: import.meta,
35
- ioServer: new Server(httpServer, wsOptions).on('connection', Connection),
36
- };
37
- };
38
-
39
- export { IoServer };
17
+ /**
18
+ * @class
19
+ * @alias IoServerClass
20
+ * @memberof SocketIoServer
21
+ * @classdesc Provides a static factory method to create and configure a Socket.IO server,
22
+ * encapsulating WebSocket server initialization logic and CORS configuration.
23
+ */
24
+ class IoServerClass {
25
+ /**
26
+ * Creates a new WebSocket server instance attached to an HTTP server.
27
+ *
28
+ * @static
29
+ * @param {http.Server} httpServer - The HTTP server instance to attach the WebSocket server to.
30
+ * @param {Object} options - Configuration options for the WebSocket server.
31
+ * @param {string[]} options.origins - List of allowed origins for Cross-Origin Resource Sharing (CORS).
32
+ * @param {string} options.path - The base path for the API. The WebSocket path ('/socket.io') will be appended to this.
33
+ * @param {function(import('socket.io').Socket): void} ConnectionHandler - The connection handler function to be executed on a new connection.
34
+ * @returns {Object} An object containing the final options and the server instance.
35
+ * @returns {import('socket.io').ServerOptions} return.options - The final options object used to create the WebSocket server.
36
+ * @returns {import('socket.io').Server} return.ioServer - The created and listening WebSocket server instance.
37
+ * @returns {object} return.meta - The module's import meta object (`import.meta`).
38
+ */
39
+ static create(httpServer, options = {}, ConnectionHandler = () => {}) {
40
+ const wsOptions = {
41
+ cors: {
42
+ origins: options.origins,
43
+ methods: ['GET', 'POST', 'DELETE', 'PUT'],
44
+ allowedHeaders: [
45
+ 'Access-Control-Allow-Headers',
46
+ 'Access-Control-Allow-Origin',
47
+ 'X-Requested-With',
48
+ 'X-Access-Token',
49
+ 'Content-Type',
50
+ 'Host',
51
+ 'Accept',
52
+ 'Connection',
53
+ 'Cache-Control',
54
+ 'Authorization',
55
+ ],
56
+ credentials: true,
57
+ },
58
+ // Ensure the path ends correctly, appending '/socket.io/'
59
+ path: options.path !== '/' ? `${options.path}/socket.io/` : '/socket.io/',
60
+ };
61
+
62
+ const ioServerInstance = UnderpostStartUp.API.listenServerFactory(() =>
63
+ new Server(httpServer, wsOptions).on('connection', ConnectionHandler),
64
+ );
65
+
66
+ logger.info('Socket.IO Server created and listening', { path: wsOptions.path });
67
+
68
+ return {
69
+ options: wsOptions,
70
+ meta: import.meta,
71
+ ioServer: ioServerInstance,
72
+ };
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Backward compatibility export for the server creation function.
78
+ * @memberof SocketIoServer
79
+ * @function IoServer
80
+ * @param {http.Server} httpServer - The HTTP server instance.
81
+ * @param {Object} options - Configuration options.
82
+ * @param {function(import('socket.io').Socket): void} ConnectionHandler - The connection handler function.
83
+ * @returns {Object} The server configuration object.
84
+ */
85
+ const IoServer = IoServerClass.create;
86
+
87
+ export { IoServerClass, IoServer };
@@ -1,28 +1,62 @@
1
+ /**
2
+ * Module for handling new WebSocket connections and setting up channel listeners.
3
+ * @module ws/core.ws.connection
4
+ * @namespace CoreWsConnection
5
+ */
6
+
1
7
  import { loggerFactory } from '../../server/logger.js';
2
8
  import { CoreWsChatChannel } from './channels/core.ws.chat.js';
3
9
  import { CoreWsMailerChannel } from './channels/core.ws.mailer.js';
4
10
  import { CoreWsStreamChannel } from './channels/core.ws.stream.js';
11
+ import { Socket } from 'socket.io'; // Added for JSDoc type hinting
5
12
 
6
13
  const logger = loggerFactory(import.meta);
7
14
 
8
- const CoreWsConnection = function (socket, wsManagementId) {
9
- // const headers = socket.handshake.headers;
10
- // const ip = socket.handshake.address;
11
- // const { query, auth } = socket.handshake;
15
+ /**
16
+ * @class
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.
21
+ */
22
+ class CoreWsConnectionManager {
23
+ /**
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}
31
+ */
32
+ static handleConnection(socket, wsManagementId) {
33
+ logger.info(`New connection established. Socket ID: ${socket.id}`);
12
34
 
13
- logger.info(`CoreWsConnection ${socket.id}`);
35
+ // Subscribe socket to all channel connection handlers (assuming these channels are IoChannel instances)
36
+ CoreWsChatChannel.connection(socket, wsManagementId);
37
+ CoreWsMailerChannel.connection(socket, wsManagementId);
38
+ CoreWsStreamChannel.connection(socket, wsManagementId);
14
39
 
15
- CoreWsChatChannel.connection(socket, wsManagementId);
16
- CoreWsMailerChannel.connection(socket, wsManagementId);
17
- CoreWsStreamChannel.connection(socket, wsManagementId);
40
+ // Set up the disconnect listener
41
+ socket.on('disconnect', (reason) => {
42
+ logger.info(`Connection disconnected. Socket ID: ${socket.id} due to reason: ${reason}`);
18
43
 
19
- socket.on('disconnect', (reason) => {
20
- logger.info(`CoreWsConnection ${socket.id} due to reason: ${reason}`);
44
+ // Notify all channels of the disconnection
45
+ CoreWsChatChannel.disconnect(socket, reason, wsManagementId);
46
+ CoreWsMailerChannel.disconnect(socket, reason, wsManagementId);
47
+ CoreWsStreamChannel.disconnect(socket, reason, wsManagementId);
48
+ });
49
+ }
50
+ }
21
51
 
22
- CoreWsChatChannel.disconnect(socket, reason, wsManagementId);
23
- CoreWsMailerChannel.disconnect(socket, reason, wsManagementId);
24
- CoreWsStreamChannel.disconnect(socket, reason, wsManagementId);
25
- });
26
- };
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;
27
61
 
28
- export { CoreWsConnection };
62
+ export { CoreWsConnectionManager, CoreWsConnection };
@@ -1,14 +1,53 @@
1
+ /**
2
+ * Module for standardized WebSocket message emission (sending).
3
+ * @module ws/core.ws.emit
4
+ * @namespace CoreWsEmitter
5
+ */
6
+
1
7
  import { loggerFactory } from '../../server/logger.js';
8
+ import { Socket } from 'socket.io';
2
9
 
3
10
  const logger = loggerFactory(import.meta);
4
11
 
5
- const CoreWsEmit = (channel = '', client = {}, payload = {}) => {
6
- try {
7
- if (client && client.emit) client.emit(channel, JSON.stringify(payload));
8
- else logger.error('Invalid client', { channel, client, payload });
9
- } catch (error) {
10
- logger.error(error, { channel, client, payload, stack: error.stack });
12
+ /**
13
+ * @class
14
+ * @alias CoreWsEmitter
15
+ * @memberof CoreWsEmitter
16
+ * @classdesc Provides a static utility method for safely emitting messages over a WebSocket connection.
17
+ */
18
+ class CoreWsEmitter {
19
+ /**
20
+ * Emits a payload to a specific client over a given channel.
21
+ * The payload is automatically JSON stringified.
22
+ *
23
+ * @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.
27
+ * @returns {void}
28
+ */
29
+ static emit(channel = '', client = {}, payload = {}) {
30
+ try {
31
+ if (client && typeof client.emit === 'function') {
32
+ client.emit(channel, JSON.stringify(payload));
33
+ } else {
34
+ logger.error('Invalid client: Cannot emit message.', { channel, client, payload });
35
+ }
36
+ } catch (error) {
37
+ logger.error(error, { channel, client, payload, stack: error.stack });
38
+ }
11
39
  }
12
- };
40
+ }
41
+
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;
13
52
 
14
- export { CoreWsEmit };
53
+ export { CoreWsEmitter, CoreWsEmit };
@@ -1,24 +1,76 @@
1
+ /**
2
+ * Module for creating and initializing the main WebSocket server instance.
3
+ * @module ws/core.ws.server
4
+ * @namespace CoreWsServer
5
+ */
6
+
1
7
  'use strict';
2
8
 
3
- import { IoServer } from '../IoServer.js';
9
+ import { IoServerClass } from '../IoServer.js';
4
10
  import { CoreWsConnection } from './core.ws.connection.js';
5
11
  import { CoreWsChatManagement } from './management/core.ws.chat.js';
6
12
  import { CoreWsMailerManagement } from './management/core.ws.mailer.js';
7
13
  import { CoreWsStreamManagement } from './management/core.ws.stream.js';
14
+ import http from 'http'; // Added for JSDoc type hinting
8
15
 
9
16
  // https://socket.io/docs/v3/
10
17
 
11
- const createIoServer = async (httpServer, options) => {
12
- const { host, path } = options;
13
- const wsManagementId = `${host}${path}`;
18
+ /**
19
+ * @class
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.
24
+ */
25
+ class CoreWsServerClass {
26
+ /**
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.
36
+ */
37
+ static async create(httpServer, options) {
38
+ 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
+ const wsManagementId = `${host}${path}`;
45
+
46
+ // Initialize/Retrieve singleton management instances for all channels
47
+ CoreWsChatManagement.instance(wsManagementId);
48
+ CoreWsMailerManagement.instance(wsManagementId);
49
+ CoreWsStreamManagement.instance(wsManagementId);
14
50
 
15
- CoreWsChatManagement.instance(wsManagementId);
16
- CoreWsMailerManagement.instance(wsManagementId);
17
- CoreWsStreamManagement.instance(wsManagementId);
51
+ // Use the IoServerClass factory to create the server, passing the connection handler
52
+ return IoServerClass.create(httpServer, options, (socket) => CoreWsConnection(socket, wsManagementId));
53
+ }
54
+ }
18
55
 
19
- return IoServer(httpServer, options, (socket) => CoreWsConnection(socket, wsManagementId));
20
- };
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;
21
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
+ */
22
74
  const CoreWsServer = createIoServer;
23
75
 
24
- export { createIoServer, CoreWsServer };
76
+ export { CoreWsServerClass, createIoServer, CoreWsServer };