@arcblock/ws 1.32.0 → 1.32.2

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.
@@ -52,6 +52,7 @@ interface WsServerOptions {
52
52
  trustedProxies?: string[];
53
53
  trustedIpHeader?: string;
54
54
  sanitizeErrors?: boolean;
55
+ env?: Record<string, string | undefined>;
55
56
  }
56
57
  interface BroadcastOptions {
57
58
  enableLog?: boolean;
@@ -215,13 +215,14 @@ var WsServer = class extends EventEmitter {
215
215
  this.heartbeatTimeout = opts.heartbeatTimeout || HEARTBEAT_TIMEOUT;
216
216
  this.heartbeatInterval = opts.heartbeatInterval ?? DEFAULT_HEARTBEAT_INTERVAL;
217
217
  this.maxTopicsPerSocket = opts.maxTopicsPerSocket ?? MAX_TOPICS_PER_SOCKET;
218
- this.maxConnections = opts.maxConnections ?? parseEnvNonNegativeInt(process.env.WS_MAX_CONNECTIONS, MAX_CONNECTIONS);
219
- this.maxConnectionsPerIp = opts.maxConnectionsPerIp ?? parseEnvNonNegativeInt(process.env.WS_MAX_CONNECTIONS_PER_IP, MAX_CONNECTIONS_PER_IP);
220
- this.trustProxy = typeof opts.trustProxy === "number" ? opts.trustProxy > 0 : opts.trustProxy ?? parseEnvBoolean(process.env.WS_TRUST_PROXY) ?? parseEnvBoolean(process.env.TRUST_PROXY) ?? false;
221
- this.trustProxyHops = opts.trustProxyHops ?? (typeof opts.trustProxy === "number" && opts.trustProxy > 0 ? Math.floor(opts.trustProxy) : parseEnvPositiveInt(process.env.WS_TRUST_PROXY_HOPS, 1));
222
- const envTrustedProxies = process.env.WS_TRUSTED_PROXIES?.split(",").map((s) => s.trim()).filter(Boolean);
218
+ const wsEnv = opts.env ?? process.env;
219
+ this.maxConnections = opts.maxConnections ?? parseEnvNonNegativeInt(wsEnv.WS_MAX_CONNECTIONS, MAX_CONNECTIONS);
220
+ this.maxConnectionsPerIp = opts.maxConnectionsPerIp ?? parseEnvNonNegativeInt(wsEnv.WS_MAX_CONNECTIONS_PER_IP, MAX_CONNECTIONS_PER_IP);
221
+ this.trustProxy = typeof opts.trustProxy === "number" ? opts.trustProxy > 0 : opts.trustProxy ?? parseEnvBoolean(wsEnv.WS_TRUST_PROXY) ?? parseEnvBoolean(wsEnv.TRUST_PROXY) ?? false;
222
+ this.trustProxyHops = opts.trustProxyHops ?? (typeof opts.trustProxy === "number" && opts.trustProxy > 0 ? Math.floor(opts.trustProxy) : parseEnvPositiveInt(wsEnv.WS_TRUST_PROXY_HOPS, 1));
223
+ const envTrustedProxies = wsEnv.WS_TRUSTED_PROXIES?.split(",").map((s) => s.trim()).filter(Boolean);
223
224
  this.trustedProxies = opts.trustedProxies ?? (envTrustedProxies && envTrustedProxies.length > 0 ? envTrustedProxies : DEFAULT_TRUSTED_PROXIES);
224
- this.trustedIpHeader = opts.trustedIpHeader ?? (process.env.WS_TRUSTED_IP_HEADER?.trim() || void 0);
225
+ this.trustedIpHeader = opts.trustedIpHeader ?? (wsEnv.WS_TRUSTED_IP_HEADER?.trim() || void 0);
225
226
  this.sanitizeErrors = opts.sanitizeErrors ?? false;
226
227
  this.wss = new WebSocketServer({
227
228
  noServer: true,
@@ -220,13 +220,14 @@ var WsServer = class extends node_events.default {
220
220
  this.heartbeatTimeout = opts.heartbeatTimeout || HEARTBEAT_TIMEOUT;
221
221
  this.heartbeatInterval = opts.heartbeatInterval ?? DEFAULT_HEARTBEAT_INTERVAL;
222
222
  this.maxTopicsPerSocket = opts.maxTopicsPerSocket ?? MAX_TOPICS_PER_SOCKET;
223
- this.maxConnections = opts.maxConnections ?? parseEnvNonNegativeInt(process.env.WS_MAX_CONNECTIONS, MAX_CONNECTIONS);
224
- this.maxConnectionsPerIp = opts.maxConnectionsPerIp ?? parseEnvNonNegativeInt(process.env.WS_MAX_CONNECTIONS_PER_IP, MAX_CONNECTIONS_PER_IP);
225
- this.trustProxy = typeof opts.trustProxy === "number" ? opts.trustProxy > 0 : opts.trustProxy ?? parseEnvBoolean(process.env.WS_TRUST_PROXY) ?? parseEnvBoolean(process.env.TRUST_PROXY) ?? false;
226
- this.trustProxyHops = opts.trustProxyHops ?? (typeof opts.trustProxy === "number" && opts.trustProxy > 0 ? Math.floor(opts.trustProxy) : parseEnvPositiveInt(process.env.WS_TRUST_PROXY_HOPS, 1));
227
- const envTrustedProxies = process.env.WS_TRUSTED_PROXIES?.split(",").map((s) => s.trim()).filter(Boolean);
223
+ const wsEnv = opts.env ?? process.env;
224
+ this.maxConnections = opts.maxConnections ?? parseEnvNonNegativeInt(wsEnv.WS_MAX_CONNECTIONS, MAX_CONNECTIONS);
225
+ this.maxConnectionsPerIp = opts.maxConnectionsPerIp ?? parseEnvNonNegativeInt(wsEnv.WS_MAX_CONNECTIONS_PER_IP, MAX_CONNECTIONS_PER_IP);
226
+ this.trustProxy = typeof opts.trustProxy === "number" ? opts.trustProxy > 0 : opts.trustProxy ?? parseEnvBoolean(wsEnv.WS_TRUST_PROXY) ?? parseEnvBoolean(wsEnv.TRUST_PROXY) ?? false;
227
+ this.trustProxyHops = opts.trustProxyHops ?? (typeof opts.trustProxy === "number" && opts.trustProxy > 0 ? Math.floor(opts.trustProxy) : parseEnvPositiveInt(wsEnv.WS_TRUST_PROXY_HOPS, 1));
228
+ const envTrustedProxies = wsEnv.WS_TRUSTED_PROXIES?.split(",").map((s) => s.trim()).filter(Boolean);
228
229
  this.trustedProxies = opts.trustedProxies ?? (envTrustedProxies && envTrustedProxies.length > 0 ? envTrustedProxies : DEFAULT_TRUSTED_PROXIES);
229
- this.trustedIpHeader = opts.trustedIpHeader ?? (process.env.WS_TRUSTED_IP_HEADER?.trim() || void 0);
230
+ this.trustedIpHeader = opts.trustedIpHeader ?? (wsEnv.WS_TRUSTED_IP_HEADER?.trim() || void 0);
230
231
  this.sanitizeErrors = opts.sanitizeErrors ?? false;
231
232
  this.wss = new ws.WebSocketServer({
232
233
  noServer: true,
@@ -52,6 +52,7 @@ interface WsServerOptions {
52
52
  trustedProxies?: string[];
53
53
  trustedIpHeader?: string;
54
54
  sanitizeErrors?: boolean;
55
+ env?: Record<string, string | undefined>;
55
56
  }
56
57
  interface BroadcastOptions {
57
58
  enableLog?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ws",
3
- "version": "1.32.0",
3
+ "version": "1.32.2",
4
4
  "description": "OCAP Chain websocket server and client",
5
5
  "keywords": [
6
6
  "websocket"
@@ -75,7 +75,7 @@
75
75
  "url": "https://github.com/ArcBlock/blockchain/issues"
76
76
  },
77
77
  "dependencies": {
78
- "@arcblock/event-hub": "1.32.0",
78
+ "@arcblock/event-hub": "1.32.2",
79
79
  "debug": "^4.4.3",
80
80
  "eventemitter3": "^4.0.7",
81
81
  "lodash": "^4.17.23",