@elliemae/pui-cli 8.23.0 → 8.25.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.
@@ -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": "8.23.0",
3
+ "version": "8.25.0",
4
4
  "description": "ICE MT UI Platform CLI",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -75,7 +75,7 @@
75
75
  "sonar56x": true
76
76
  },
77
77
  "dependencies": {
78
- "@axe-core/react": "~4.8.0",
78
+ "@axe-core/react": "~4.8.1",
79
79
  "@babel/cli": "~7.23.0",
80
80
  "@babel/core": "~7.23.2",
81
81
  "@babel/eslint-parser": "~7.22.15",
@@ -93,8 +93,8 @@
93
93
  "@babel/preset-react": "~7.22.15",
94
94
  "@babel/preset-typescript": "~7.23.2",
95
95
  "@babel/runtime": "~7.23.2",
96
- "@commitlint/cli": "~17.7.2",
97
- "@commitlint/config-conventional": "~17.7.0",
96
+ "@commitlint/cli": "~17.8.1",
97
+ "@commitlint/config-conventional": "~17.8.1",
98
98
  "@elliemae/browserslist-config-elliemae-latest-browsers": "~1.8.0",
99
99
  "@faker-js/faker": "~7.6.0",
100
100
  "@nrwl/cli": "~15.9.7",
@@ -118,29 +118,29 @@
118
118
  "@stylelint/postcss-css-in-js": "~0.38.0",
119
119
  "@svgr/webpack": "~7.0.0",
120
120
  "@swc/cli": "~0.1.62",
121
- "@swc/core": "~1.3.92",
121
+ "@swc/core": "~1.3.95",
122
122
  "@swc/jest": "~0.2.29",
123
123
  "@testing-library/jest-dom": "~5.17.0",
124
124
  "@testing-library/react": "~14.0.0",
125
125
  "@testing-library/react-hooks": "~8.0.1",
126
126
  "@testing-library/user-event": "~14.5.1",
127
- "@types/circular-dependency-plugin": "~5.0.6",
128
- "@types/compression": "~1.7.3",
129
- "@types/cors": "~2.8.14",
130
- "@types/duplicate-package-checker-webpack-plugin": "~2.1.3",
131
- "@types/ip": "~1.1.1",
132
- "@types/jest": "~29.5.5",
133
- "@types/jest-axe": "~3.5.6",
134
- "@types/moment-locales-webpack-plugin": "~1.2.4",
135
- "@types/node": "~18.18.5",
136
- "@types/normalize-path": "~3.0.0",
127
+ "@types/circular-dependency-plugin": "~5.0.7",
128
+ "@types/compression": "~1.7.4",
129
+ "@types/cors": "~2.8.15",
130
+ "@types/duplicate-package-checker-webpack-plugin": "~2.1.4",
131
+ "@types/ip": "~1.1.2",
132
+ "@types/jest": "~29.5.7",
133
+ "@types/jest-axe": "~3.5.7",
134
+ "@types/moment-locales-webpack-plugin": "~1.2.5",
135
+ "@types/node": "~18.18.8",
136
+ "@types/normalize-path": "~3.0.1",
137
137
  "@types/postcss-preset-env": "~7.7.0",
138
138
  "@types/rimraf": "~3.0.2",
139
- "@types/speed-measure-webpack-plugin": "~1.3.4",
140
- "@types/supertest": "~2.0.14",
139
+ "@types/speed-measure-webpack-plugin": "~1.3.5",
140
+ "@types/supertest": "~2.0.15",
141
141
  "@types/testing-library__jest-dom": "~5.14.9",
142
- "@types/uuid": "~9.0.5",
143
- "@types/webpack-bundle-analyzer": "~4.6.1",
142
+ "@types/uuid": "~9.0.6",
143
+ "@types/webpack-bundle-analyzer": "~4.6.2",
144
144
  "@typescript-eslint/eslint-plugin": "~5.62.0",
145
145
  "@typescript-eslint/parser": "~5.62.0",
146
146
  "@vitejs/plugin-react": "~4.1.0",
@@ -170,16 +170,16 @@
170
170
  "cross-env": "~7.0.3",
171
171
  "css-loader": "~6.8.1",
172
172
  "css-minimizer-webpack-plugin": "~5.0.1",
173
- "depcheck": "~1.4.6",
173
+ "depcheck": "~1.4.7",
174
174
  "docdash": "~2.0.2",
175
175
  "dotenv": "~16.3.1",
176
176
  "dotenv-webpack": "~8.0.1",
177
177
  "duplicate-package-checker-webpack-plugin": "~3.0.0",
178
178
  "enhanced-resolve": "5.15.0",
179
- "esbuild": "~0.19.4",
179
+ "esbuild": "~0.19.5",
180
180
  "esbuild-loader": "~3.2.0",
181
181
  "esbuild-plugin-svgr": "~1.1.0",
182
- "eslint": "~8.51.0",
182
+ "eslint": "~8.52.0",
183
183
  "eslint-config-airbnb": "~19.0.4",
184
184
  "eslint-config-airbnb-base": "~15.0.0",
185
185
  "eslint-config-airbnb-typescript": "~17.1.0",
@@ -187,11 +187,11 @@
187
187
  "eslint-config-react-app": "~7.0.1",
188
188
  "eslint-import-resolver-babel-module": "~5.3.2",
189
189
  "eslint-import-resolver-typescript": "~3.6.1",
190
- "eslint-import-resolver-webpack": "~0.13.7",
190
+ "eslint-import-resolver-webpack": "~0.13.8",
191
191
  "eslint-plugin-compat": "~4.2.0",
192
192
  "eslint-plugin-eslint-comments": "~3.2.0",
193
- "eslint-plugin-import": "~2.28.1",
194
- "eslint-plugin-jest": "~27.4.2",
193
+ "eslint-plugin-import": "~2.29.0",
194
+ "eslint-plugin-jest": "~27.6.0",
195
195
  "eslint-plugin-jsdoc": "~43.2.0",
196
196
  "eslint-plugin-jsx-a11y": "~6.7.1",
197
197
  "eslint-plugin-mdx": "~2.2.0",
@@ -201,7 +201,7 @@
201
201
  "eslint-plugin-redux-saga": "~1.3.2",
202
202
  "eslint-plugin-storybook": "~0.6.15",
203
203
  "eslint-plugin-testing-library": "~5.11.1",
204
- "eslint-plugin-wdio": "~8.8.7",
204
+ "eslint-plugin-wdio": "~8.20.0",
205
205
  "execa": "~7.2.0",
206
206
  "express": "~4.18.2",
207
207
  "express-static-gzip": "~2.1.7",
@@ -210,7 +210,7 @@
210
210
  "favicons-webpack-plugin": "~6.0.1",
211
211
  "find-up": "~6.3.0",
212
212
  "find-up-cli": "~5.0.0",
213
- "happy-dom": "~12.9.1",
213
+ "happy-dom": "~12.10.3",
214
214
  "helmet-csp": "~3.4.0",
215
215
  "html-loader": "~4.2.0",
216
216
  "html-webpack-plugin": "~5.5.3",
@@ -225,7 +225,7 @@
225
225
  "jest-sonar-reporter": "~2.0.0",
226
226
  "jest-styled-components": "~7.2.0",
227
227
  "jest-watch-typeahead": "~2.2.2",
228
- "jscodeshift": "~0.15.0",
228
+ "jscodeshift": "~0.15.1",
229
229
  "jsdoc": "~4.0.2",
230
230
  "lerna": "~6.6.2",
231
231
  "lint-staged": "~13.3.0",
@@ -234,14 +234,14 @@
234
234
  "moment": "~2.29.4",
235
235
  "moment-locales-webpack-plugin": "~1.2.0",
236
236
  "msw": "~1.3.2",
237
- "node-gyp": "~9.4.0",
237
+ "node-gyp": "~9.4.1",
238
238
  "node-plop": "~0.32.0",
239
239
  "nodemon": "~2.0.22",
240
240
  "normalize-path": "~3.0.0",
241
241
  "npm-check-updates": "16.14.6",
242
242
  "npm-run-all": "~4.1.5",
243
- "pino": "~8.16.0",
244
- "pino-http": "~8.5.0",
243
+ "pino": "~8.16.1",
244
+ "pino-http": "~8.5.1",
245
245
  "pino-pretty": "~10.2.3",
246
246
  "plop": "~3.1.2",
247
247
  "postcss": "~8.4.31",
@@ -249,7 +249,7 @@
249
249
  "postcss-jsx": "~0.36.4",
250
250
  "postcss-loader": "~7.3.3",
251
251
  "postcss-markdown": "~1.2.0",
252
- "postcss-preset-env": "9.2.0",
252
+ "postcss-preset-env": "9.3.0",
253
253
  "postcss-syntax": "~0.36.2",
254
254
  "prettier": "~2.8.8",
255
255
  "prisma": "~4.16.2",
@@ -268,7 +268,7 @@
268
268
  "storybook-addon-turbo-build": "~1.1.0",
269
269
  "storybook-react-router": "~1.0.8",
270
270
  "style-loader": "~3.3.3",
271
- "stylelint": "~15.10.3",
271
+ "stylelint": "~15.11.0",
272
272
  "stylelint-config-recommended": "~12.0.0",
273
273
  "stylelint-config-styled-components": "~0.1.1",
274
274
  "supertest": "~6.3.3",
@@ -277,22 +277,23 @@
277
277
  "ts-node": "~10.9.1",
278
278
  "tsc-alias": "~1.8.8",
279
279
  "tsx": "~3.13.0",
280
- "typedoc": "~0.25.2",
280
+ "typedoc": "~0.25.3",
281
281
  "typescript": "~5.2.2",
282
282
  "update-notifier": "~6.0.2",
283
283
  "url-loader": "~4.1.1",
284
284
  "uuid": "~9.0.1",
285
- "vite": "~4.4.11",
285
+ "vite": "~4.5.0",
286
286
  "vite-tsconfig-paths": "~4.2.1",
287
- "vitest": "~1.0.0-beta.1",
288
- "webpack": "~5.88.2",
287
+ "vitest": "~1.0.0-beta.3",
288
+ "webpack": "~5.89.0",
289
289
  "webpack-bundle-analyzer": "~4.9.1",
290
290
  "webpack-cli": "~5.1.4",
291
291
  "webpack-dev-server": "~4.15.1",
292
292
  "webpack-manifest-plugin": "~5.0.0",
293
- "webpack-merge": "~5.9.0",
293
+ "webpack-merge": "~5.10.0",
294
294
  "whatwg-fetch": "~3.6.19",
295
295
  "workbox-webpack-plugin": "~6.6.0",
296
+ "ws": "~8.14.2",
296
297
  "yargs": "~17.7.2"
297
298
  },
298
299
  "devDependencies": {