@elliemae/pui-cli 9.0.0-next.25 → 9.0.0-next.26

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.
@@ -26,6 +26,7 @@ var import_logger = require("./logger.js");
26
26
  var import_middlewares = require("./middlewares.js");
27
27
  var import_utils = require("./utils.js");
28
28
  var import_appRoutes = require("./appRoutes.js");
29
+ var import_wsServer = require("./wsServer.js");
29
30
  (async function startServer() {
30
31
  const app = (0, import_express.default)();
31
32
  (0, import_middlewares.setupDefaultMiddlewares)(app);
@@ -37,4 +38,8 @@ var import_appRoutes = require("./appRoutes.js");
37
38
  import_logger.logger.error(err);
38
39
  process.exit(1);
39
40
  });
41
+ const { wsServer } = await (0, import_wsServer.createWSServer)({
42
+ port: import_utils.wsPort
43
+ });
44
+ app.locals.wsServer = wsServer;
40
45
  })();
@@ -30,14 +30,21 @@ var utils_exports = {};
30
30
  __export(utils_exports, {
31
31
  getCWD: () => getCWD,
32
32
  host: () => host,
33
- port: () => port
33
+ port: () => port,
34
+ wsPort: () => wsPort
34
35
  });
35
36
  module.exports = __toCommonJS(utils_exports);
36
37
  var import_minimist = __toESM(require("minimist"), 1);
37
- const argv = (0, import_minimist.default)(process.argv.slice(2));
38
+ const argv = (0, import_minimist.default)(
39
+ process.argv.slice(2)
40
+ );
38
41
  const getCWD = () => process.cwd();
39
42
  const port = parseInt(
40
43
  argv.port ?? process.env.port ?? process.env.PORT ?? "3000",
41
44
  10
42
45
  );
43
46
  const host = argv.host ?? process.env.HOST ?? "localhost";
47
+ const wsPort = parseInt(
48
+ argv.wsport ?? process.env.wsport ?? process.env.WSPORT ?? "5000",
49
+ 10
50
+ );
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var wsServer_exports = {};
30
+ __export(wsServer_exports, {
31
+ createWSServer: () => createWSServer
32
+ });
33
+ module.exports = __toCommonJS(wsServer_exports);
34
+ var import_node_http = __toESM(require("node:http"), 1);
35
+ var import_ws = require("ws");
36
+ const PING_INTERVAL = 3e4;
37
+ const DEFAULT_PORT = 5001;
38
+ const onSocketError = (err) => {
39
+ console.error(err);
40
+ };
41
+ const authenticate = (token, cb) => {
42
+ if (!token)
43
+ cb(4401);
44
+ else
45
+ cb();
46
+ };
47
+ const getAuthToken = (protocols) => {
48
+ const authProtocol = protocols.find(
49
+ (protocol) => protocol.startsWith("auth--")
50
+ );
51
+ if (!authProtocol)
52
+ return "";
53
+ return authProtocol.split("--")[1]?.trim?.();
54
+ };
55
+ const createWSServer = ({
56
+ port = DEFAULT_PORT,
57
+ pingInterval = PING_INTERVAL,
58
+ onOpen
59
+ }) => {
60
+ let isAlive = false;
61
+ const heartbeat = () => {
62
+ isAlive = true;
63
+ };
64
+ const httpServer = import_node_http.default.createServer();
65
+ const wsServer = new import_ws.Server({ noServer: true });
66
+ httpServer.on("upgrade", (req, socket, head) => {
67
+ socket.on("error", onSocketError);
68
+ wsServer.handleUpgrade(req, socket, head, (ws) => {
69
+ const protocols = req.headers["sec-websocket-protocol"]?.split(",");
70
+ if (!protocols) {
71
+ console.error("no protocols");
72
+ ws.close(4401, "unauthorized");
73
+ socket.destroy();
74
+ socket.removeListener("error", onSocketError);
75
+ return;
76
+ }
77
+ authenticate(getAuthToken(protocols) || "", (errCode) => {
78
+ if (errCode) {
79
+ switch (errCode) {
80
+ case 4401:
81
+ ws.close(errCode, "unauthorized");
82
+ break;
83
+ default:
84
+ ws.close(4400, "Unknown error");
85
+ break;
86
+ }
87
+ socket.destroy();
88
+ socket.removeListener("error", onSocketError);
89
+ } else {
90
+ socket.removeListener("error", onSocketError);
91
+ wsServer.emit("connection", ws, req);
92
+ setTimeout(() => {
93
+ ws.send('{ "name": "vinoth" }');
94
+ }, 3e3);
95
+ }
96
+ });
97
+ });
98
+ });
99
+ wsServer.on("connection", (ws) => {
100
+ isAlive = true;
101
+ ws.on("error", console.error);
102
+ ws.on("pong", () => {
103
+ heartbeat();
104
+ });
105
+ ws.on("message", (message) => {
106
+ console.log(
107
+ "message from client:",
108
+ JSON.parse(message)
109
+ );
110
+ ws.send(JSON.stringify(JSON.parse(message)));
111
+ });
112
+ console.log("client connected");
113
+ onOpen?.(ws);
114
+ });
115
+ const interval = setInterval(() => {
116
+ wsServer.clients.forEach((ws) => {
117
+ if (isAlive === false)
118
+ ws.terminate();
119
+ isAlive = false;
120
+ ws.ping();
121
+ });
122
+ }, pingInterval);
123
+ wsServer.on("close", function close() {
124
+ clearInterval(interval);
125
+ });
126
+ return new Promise((resolve) => {
127
+ httpServer.listen(port, () => {
128
+ console.log(`Websocket server listening on port ${port}`);
129
+ return resolve({ httpServer, wsServer });
130
+ });
131
+ });
132
+ };
@@ -4,8 +4,9 @@ import {
4
4
  setupDefaultMiddlewares,
5
5
  setupAdditionalMiddlewars
6
6
  } from "./middlewares.js";
7
- import { port, host } from "./utils.js";
7
+ import { port, wsPort, host } from "./utils.js";
8
8
  import { loadRoutes } from "./appRoutes.js";
9
+ import { createWSServer } from "./wsServer.js";
9
10
  (async function startServer() {
10
11
  const app = express();
11
12
  setupDefaultMiddlewares(app);
@@ -17,4 +18,8 @@ import { loadRoutes } from "./appRoutes.js";
17
18
  logger.error(err);
18
19
  process.exit(1);
19
20
  });
21
+ const { wsServer } = await createWSServer({
22
+ port: wsPort
23
+ });
24
+ app.locals.wsServer = wsServer;
20
25
  })();
@@ -1,13 +1,20 @@
1
1
  import minimist from "minimist";
2
- const argv = minimist(process.argv.slice(2));
2
+ const argv = minimist(
3
+ process.argv.slice(2)
4
+ );
3
5
  const getCWD = () => process.cwd();
4
6
  const port = parseInt(
5
7
  argv.port ?? process.env.port ?? process.env.PORT ?? "3000",
6
8
  10
7
9
  );
8
10
  const host = argv.host ?? process.env.HOST ?? "localhost";
11
+ const wsPort = parseInt(
12
+ argv.wsport ?? process.env.wsport ?? process.env.WSPORT ?? "5000",
13
+ 10
14
+ );
9
15
  export {
10
16
  getCWD,
11
17
  host,
12
- port
18
+ port,
19
+ wsPort
13
20
  };
@@ -0,0 +1,102 @@
1
+ import http from "node:http";
2
+ import { Server } from "ws";
3
+ const PING_INTERVAL = 3e4;
4
+ const DEFAULT_PORT = 5001;
5
+ const onSocketError = (err) => {
6
+ console.error(err);
7
+ };
8
+ const authenticate = (token, cb) => {
9
+ if (!token)
10
+ cb(4401);
11
+ else
12
+ cb();
13
+ };
14
+ const getAuthToken = (protocols) => {
15
+ const authProtocol = protocols.find(
16
+ (protocol) => protocol.startsWith("auth--")
17
+ );
18
+ if (!authProtocol)
19
+ return "";
20
+ return authProtocol.split("--")[1]?.trim?.();
21
+ };
22
+ const createWSServer = ({
23
+ port = DEFAULT_PORT,
24
+ pingInterval = PING_INTERVAL,
25
+ onOpen
26
+ }) => {
27
+ let isAlive = false;
28
+ const heartbeat = () => {
29
+ isAlive = true;
30
+ };
31
+ const httpServer = http.createServer();
32
+ const wsServer = new Server({ noServer: true });
33
+ httpServer.on("upgrade", (req, socket, head) => {
34
+ socket.on("error", onSocketError);
35
+ wsServer.handleUpgrade(req, socket, head, (ws) => {
36
+ const protocols = req.headers["sec-websocket-protocol"]?.split(",");
37
+ if (!protocols) {
38
+ console.error("no protocols");
39
+ ws.close(4401, "unauthorized");
40
+ socket.destroy();
41
+ socket.removeListener("error", onSocketError);
42
+ return;
43
+ }
44
+ authenticate(getAuthToken(protocols) || "", (errCode) => {
45
+ if (errCode) {
46
+ switch (errCode) {
47
+ case 4401:
48
+ ws.close(errCode, "unauthorized");
49
+ break;
50
+ default:
51
+ ws.close(4400, "Unknown error");
52
+ break;
53
+ }
54
+ socket.destroy();
55
+ socket.removeListener("error", onSocketError);
56
+ } else {
57
+ socket.removeListener("error", onSocketError);
58
+ wsServer.emit("connection", ws, req);
59
+ setTimeout(() => {
60
+ ws.send('{ "name": "vinoth" }');
61
+ }, 3e3);
62
+ }
63
+ });
64
+ });
65
+ });
66
+ wsServer.on("connection", (ws) => {
67
+ isAlive = true;
68
+ ws.on("error", console.error);
69
+ ws.on("pong", () => {
70
+ heartbeat();
71
+ });
72
+ ws.on("message", (message) => {
73
+ console.log(
74
+ "message from client:",
75
+ JSON.parse(message)
76
+ );
77
+ ws.send(JSON.stringify(JSON.parse(message)));
78
+ });
79
+ console.log("client connected");
80
+ onOpen?.(ws);
81
+ });
82
+ const interval = setInterval(() => {
83
+ wsServer.clients.forEach((ws) => {
84
+ if (isAlive === false)
85
+ ws.terminate();
86
+ isAlive = false;
87
+ ws.ping();
88
+ });
89
+ }, pingInterval);
90
+ wsServer.on("close", function close() {
91
+ clearInterval(interval);
92
+ });
93
+ return new Promise((resolve) => {
94
+ httpServer.listen(port, () => {
95
+ console.log(`Websocket server listening on port ${port}`);
96
+ return resolve({ httpServer, wsServer });
97
+ });
98
+ });
99
+ };
100
+ export {
101
+ createWSServer
102
+ };
@@ -1,3 +1,4 @@
1
1
  export declare const getCWD: () => string;
2
2
  export declare const port: number;
3
3
  export declare const host: string;
4
+ export declare const wsPort: number;
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import http from 'node:http';
3
+ import { Server, WebSocket } from 'ws';
4
+ export interface Servers {
5
+ httpServer: http.Server;
6
+ wsServer: Server;
7
+ }
8
+ export interface WSServerOptions {
9
+ port?: number;
10
+ pingInterval?: number;
11
+ onOpen?: (webSocket: WebSocket) => void;
12
+ }
13
+ export declare const createWSServer: ({ port, pingInterval, onOpen, }: WSServerOptions) => Promise<Servers>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/pui-cli",
3
- "version": "9.0.0-next.25",
3
+ "version": "9.0.0-next.26",
4
4
  "description": "ICE MT UI Platform CLI",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -106,22 +106,22 @@
106
106
  "@semantic-release/changelog": "~6.0.3",
107
107
  "@semantic-release/exec": "~6.0.3",
108
108
  "@semantic-release/git": "~10.0.1",
109
- "@storybook/addon-a11y": "~7.5.1",
110
- "@storybook/addon-essentials": "~7.5.1",
109
+ "@storybook/addon-a11y": "~7.5.2",
110
+ "@storybook/addon-essentials": "~7.5.2",
111
111
  "@storybook/addon-events": "~6.2.9",
112
- "@storybook/addon-interactions": "~7.5.1",
113
- "@storybook/addon-links": "~7.5.1",
114
- "@storybook/addon-storysource": "~7.5.1",
115
- "@storybook/blocks": "~7.5.1",
116
- "@storybook/builder-vite": "~7.5.1",
117
- "@storybook/builder-webpack5": "~7.5.1",
112
+ "@storybook/addon-interactions": "~7.5.2",
113
+ "@storybook/addon-links": "~7.5.2",
114
+ "@storybook/addon-storysource": "~7.5.2",
115
+ "@storybook/blocks": "~7.5.2",
116
+ "@storybook/builder-vite": "~7.5.2",
117
+ "@storybook/builder-webpack5": "~7.5.2",
118
118
  "@storybook/jest": "~0.2.3",
119
119
  "@storybook/manager-webpack5": "~6.5.16",
120
- "@storybook/react": "~7.5.1",
121
- "@storybook/react-vite": "~7.5.1",
122
- "@storybook/react-webpack5": "~7.5.1",
120
+ "@storybook/react": "~7.5.2",
121
+ "@storybook/react-vite": "~7.5.2",
122
+ "@storybook/react-webpack5": "~7.5.2",
123
123
  "@storybook/testing-library": "~0.2.2",
124
- "@storybook/theming": "~7.5.1",
124
+ "@storybook/theming": "~7.5.2",
125
125
  "@stylelint/postcss-css-in-js": "~0.38.0",
126
126
  "@svgr/webpack": "~8.1.0",
127
127
  "@swc/cli": "~0.1.62",
@@ -136,10 +136,10 @@
136
136
  "@types/cors": "~2.8.15",
137
137
  "@types/duplicate-package-checker-webpack-plugin": "~2.1.4",
138
138
  "@types/ip": "~1.1.2",
139
- "@types/jest": "~29.5.6",
139
+ "@types/jest": "~29.5.7",
140
140
  "@types/jest-axe": "~3.5.7",
141
141
  "@types/moment-locales-webpack-plugin": "~1.2.5",
142
- "@types/node": "~20.8.9",
142
+ "@types/node": "~20.8.10",
143
143
  "@types/normalize-path": "~3.0.1",
144
144
  "@types/postcss-preset-env": "~8.0.0",
145
145
  "@types/rimraf": "~4.0.5",
@@ -148,8 +148,8 @@
148
148
  "@types/uuid": "~9.0.6",
149
149
  "@types/testing-library__jest-dom": "~5.14.9",
150
150
  "@types/webpack-bundle-analyzer": "~4.6.2",
151
- "@typescript-eslint/eslint-plugin": "~6.9.0",
152
- "@typescript-eslint/parser": "~6.9.0",
151
+ "@typescript-eslint/eslint-plugin": "~6.9.1",
152
+ "@typescript-eslint/parser": "~6.9.1",
153
153
  "@vitejs/plugin-react": "~4.1.0",
154
154
  "@vitest/coverage-c8": "~0.33.0",
155
155
  "autoprefixer": "~10.4.16",
@@ -217,7 +217,7 @@
217
217
  "fast-glob": "~3.3.1",
218
218
  "find-up": "~6.3.0",
219
219
  "find-up-cli": "~5.0.0",
220
- "happy-dom": "~12.10.2",
220
+ "happy-dom": "~12.10.3",
221
221
  "helmet-csp": "~3.4.0",
222
222
  "html-loader": "~4.2.0",
223
223
  "html-webpack-plugin": "~5.5.3",
@@ -232,24 +232,24 @@
232
232
  "jest-sonar-reporter": "~2.0.0",
233
233
  "jest-styled-components": "~7.2.0",
234
234
  "jest-watch-typeahead": "~2.2.2",
235
- "jscodeshift": "~0.15.0",
235
+ "jscodeshift": "~0.15.1",
236
236
  "jsdoc": "~4.0.2",
237
- "lerna": "~7.4.1",
237
+ "lerna": "~7.4.2",
238
238
  "lint-staged": "~15.0.2",
239
239
  "mini-css-extract-plugin": "~2.7.6",
240
240
  "minimist": "~1.2.8",
241
241
  "moment": "~2.29.4",
242
242
  "moment-locales-webpack-plugin": "~1.2.0",
243
- "msw": "~2.0.0",
243
+ "msw": "~2.0.1",
244
244
  "npm-run-all": "~4.1.5",
245
- "node-gyp": "~9.4.1",
245
+ "node-gyp": "~10.0.0",
246
246
  "node-plop": "~0.32.0",
247
247
  "nodemon": "~3.0.1",
248
248
  "normalize-path": "~3.0.0",
249
249
  "npm-check-updates": "16.14.6",
250
250
  "nx": "~17.0.2",
251
251
  "pino": "~8.16.1",
252
- "pino-http": "~8.5.0",
252
+ "pino-http": "~8.5.1",
253
253
  "pino-pretty": "~10.2.3",
254
254
  "plop": "~4.0.0",
255
255
  "postcss": "~8.4.31",
@@ -257,7 +257,7 @@
257
257
  "postcss-jsx": "~0.36.4",
258
258
  "postcss-loader": "~7.3.3",
259
259
  "postcss-markdown": "~1.2.0",
260
- "postcss-preset-env": "~9.2.0",
260
+ "postcss-preset-env": "~9.3.0",
261
261
  "postcss-syntax": "~0.36.2",
262
262
  "prettier": "~3.0.3",
263
263
  "prisma": "~5.5.2",
@@ -270,10 +270,10 @@
270
270
  "resize-observer-polyfill": "~1.5.1",
271
271
  "resolve-typescript-plugin": "~2.0.1",
272
272
  "rimraf": "5.0.1",
273
- "semantic-release": "~22.0.5",
273
+ "semantic-release": "~22.0.6",
274
274
  "slackify-markdown": "~4.4.0",
275
275
  "speed-measure-webpack-plugin": "~1.5.0",
276
- "storybook": "~7.5.1",
276
+ "storybook": "~7.5.2",
277
277
  "storybook-addon-turbo-build": "~2.0.1",
278
278
  "storybook-react-router": "~1.0.8",
279
279
  "style-loader": "~3.3.3",
@@ -286,7 +286,7 @@
286
286
  "ts-node": "~10.9.1",
287
287
  "tsc-alias": "~1.8.8",
288
288
  "tsx": "~3.13.0",
289
- "typedoc": "~0.25.2",
289
+ "typedoc": "~0.25.3",
290
290
  "typescript": "~5.2.2",
291
291
  "update-notifier": "~7.0.0",
292
292
  "url-loader": "~4.1.1",
@@ -302,6 +302,7 @@
302
302
  "webpack-merge": "~5.10.0",
303
303
  "whatwg-fetch": "~3.6.19",
304
304
  "workbox-webpack-plugin": "~7.0.0",
305
+ "ws": "~8.14.2",
305
306
  "yargs": "~17.7.2"
306
307
  },
307
308
  "devDependencies": {