@socket-mesh/server 18.0.1 → 18.0.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.
package/action.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import { AuthTokenError, AuthTokenExpiredError } from "@socket-mesh/errors";
4
4
  import { AuthState, AuthToken, SignedAuthToken } from "@socket-mesh/auth";
5
5
  import { IncomingMessage } from 'http';
6
- import { DataPacket } from "@socket-mesh/simple-broker";
6
+ import { DataPacket } from "@socket-mesh/broker";
7
7
  import { ChannelOptions } from "@socket-mesh/channel";
8
8
  import { ServerSocket } from "./serversocket.js";
9
9
  import { HandshakeRequest } from "./request.js";
package/action.js CHANGED
@@ -12,21 +12,12 @@ export var ActionType;
12
12
  ActionType["AUTHENTICATE"] = "authenticate";
13
13
  })(ActionType || (ActionType = {}));
14
14
  export class Action {
15
+ type;
16
+ promise;
17
+ outcome;
18
+ _resolve;
19
+ _reject;
15
20
  constructor(type) {
16
- this.allow = (packet) => {
17
- if (this.outcome) {
18
- throw new InvalidActionError(`Action ${this.type} has already been ${this.outcome}; cannot allow`);
19
- }
20
- this.outcome = 'allowed';
21
- this._resolve(packet);
22
- };
23
- this.block = (error) => {
24
- if (this.outcome) {
25
- throw new InvalidActionError(`Action ${this.type} has already been ${this.outcome}; cannot block`);
26
- }
27
- this.outcome = 'blocked';
28
- this._reject(error);
29
- };
30
21
  this.type = type;
31
22
  this.outcome = null;
32
23
  this.promise = new Promise((resolve, reject) => {
@@ -34,12 +25,27 @@ export class Action {
34
25
  this._reject = reject;
35
26
  });
36
27
  }
28
+ allow = (packet) => {
29
+ if (this.outcome) {
30
+ throw new InvalidActionError(`Action ${this.type} has already been ${this.outcome}; cannot allow`);
31
+ }
32
+ this.outcome = 'allowed';
33
+ this._resolve(packet);
34
+ };
35
+ block = (error) => {
36
+ if (this.outcome) {
37
+ throw new InvalidActionError(`Action ${this.type} has already been ${this.outcome}; cannot block`);
38
+ }
39
+ this.outcome = 'blocked';
40
+ this._reject(error);
41
+ };
37
42
  }
38
43
  export class ActionHandshakeWS extends Action {
39
44
  constructor(request) {
40
45
  super(ActionType.HANDSHAKE_WS);
41
46
  this.request = request;
42
47
  }
48
+ request;
43
49
  }
44
50
  export class ActionHandshakeSC extends Action {
45
51
  constructor(socket, request, data) {
@@ -48,6 +54,9 @@ export class ActionHandshakeSC extends Action {
48
54
  this.request = request;
49
55
  this.data = data;
50
56
  }
57
+ request;
58
+ socket;
59
+ data;
51
60
  }
52
61
  export class ActionMessage extends Action {
53
62
  constructor(socket, data) {
@@ -55,6 +64,8 @@ export class ActionMessage extends Action {
55
64
  this.socket = socket;
56
65
  this.data = data;
57
66
  }
67
+ socket;
68
+ data;
58
69
  }
59
70
  export class ActionTransmit extends Action {
60
71
  constructor(socket, receiver, packet) {
@@ -65,6 +76,10 @@ export class ActionTransmit extends Action {
65
76
  this.data = packet;
66
77
  }
67
78
  }
79
+ socket;
80
+ authTokenExpiredError;
81
+ receiver;
82
+ data;
68
83
  }
69
84
  export class ActionInvoke extends Action {
70
85
  constructor(socket, procedure, packet) {
@@ -75,6 +90,10 @@ export class ActionInvoke extends Action {
75
90
  this.data = packet;
76
91
  }
77
92
  }
93
+ socket;
94
+ authTokenExpiredError;
95
+ procedure;
96
+ data;
78
97
  }
79
98
  export class ActionSubscribe extends Action {
80
99
  constructor(socket, packet) {
@@ -83,6 +102,10 @@ export class ActionSubscribe extends Action {
83
102
  this.channel = packet.channel;
84
103
  this.data = packet.data;
85
104
  }
105
+ socket;
106
+ authTokenExpiredError;
107
+ channel;
108
+ data;
86
109
  }
87
110
  export class ActionPublishIn extends Action {
88
111
  constructor(socket, packet) {
@@ -91,12 +114,19 @@ export class ActionPublishIn extends Action {
91
114
  this.channel = packet.channel;
92
115
  this.data = packet.data;
93
116
  }
117
+ socket;
118
+ authTokenExpiredError;
119
+ channel;
120
+ data;
94
121
  }
95
122
  export class ActionPublishOut extends Action {
96
123
  constructor(socket) {
97
124
  super(ActionType.PUBLISH_OUT);
98
125
  this.socket = socket;
99
126
  }
127
+ socket;
128
+ channel;
129
+ data;
100
130
  }
101
131
  export class ActionAuthenticate extends Action {
102
132
  constructor(socket, authToken, signedAuthToken) {
@@ -105,4 +135,7 @@ export class ActionAuthenticate extends Action {
105
135
  this.authToken = authToken;
106
136
  this.signedAuthToken = signedAuthToken;
107
137
  }
138
+ socket;
139
+ authToken;
140
+ signedAuthToken;
108
141
  }
@@ -1,6 +1,6 @@
1
1
  import { SignedAuthToken } from "@socket-mesh/auth";
2
2
  import { ChannelOptions } from "@socket-mesh/channel";
3
- import { DataPacket } from "@socket-mesh/simple-broker";
3
+ import { DataPacket } from "@socket-mesh/broker";
4
4
  export type InboundPacket = InboundHandshakePacket | InboundDataPacket | InboundPublishPacket | InboundSubscribePacket | InboundUnsubscribePacket | InboundAuthenticatePacket | InboundRemoveAuthTokenPacket;
5
5
  export interface InboundHandshakePacket {
6
6
  event: '#handshake';
package/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Server } from "./server.js";
4
4
  import { ServerOptions } from "./server-options.js";
5
5
  export { Server } from "./server.js";
6
6
  export { ServerSocket } from "./serversocket.js";
7
+ export { SocketState } from "./socket-state.js";
7
8
  export { ServerOptions } from "./server-options.js";
8
9
  export { MiddlewareType } from "./middleware-type.js";
9
10
  export * from "./action.js";
package/index.js CHANGED
@@ -2,6 +2,7 @@ import http from "http";
2
2
  import { Server } from "./server.js";
3
3
  export { Server } from "./server.js";
4
4
  export { ServerSocket } from "./serversocket.js";
5
+ export { SocketState } from "./socket-state.js";
5
6
  export { MiddlewareType } from "./middleware-type.js";
6
7
  export * from "./action.js";
7
8
  export function listen(port, options, fn) {
@@ -1,5 +1,6 @@
1
1
  import { WritableConsumableStream } from "@socket-mesh/writable-consumable-stream";
2
2
  export class MiddlewareStream extends WritableConsumableStream {
3
+ type;
3
4
  constructor(type) {
4
5
  super();
5
6
  this.type = type;
@@ -1,4 +1,4 @@
1
- import { DataPacket } from "@socket-mesh/simple-broker";
1
+ import { DataPacket } from "@socket-mesh/broker";
2
2
  export type OutboundPacket = OutboundPublishPacket | OutboundTransmitPacket | OutboundInvokePacket;
3
3
  export interface OutboundPublishPacket {
4
4
  event: '#publish';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socket-mesh/server",
3
- "version": "18.0.1",
3
+ "version": "18.0.2",
4
4
  "description": "Server module for SocketMesh",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,7 +15,8 @@
15
15
  "@socket-mesh/errors": "^3.0.8",
16
16
  "@socket-mesh/formatter": "^4.0.5",
17
17
  "@socket-mesh/request": "^2.0.9",
18
- "@socket-mesh/simple-broker": "^6.0.0",
18
+ "@socket-mesh/broker": "^1.0.0",
19
+ "@socket-mesh/simple-broker": "^6.0.1",
19
20
  "@socket-mesh/stream-demux": "^10.0.1",
20
21
  "@socket-mesh/writable-consumable-stream": "^4.2.9",
21
22
  "@socket-mesh/channel": "6.0.25",
@@ -25,7 +26,7 @@
25
26
  "ws": "^8.14.2"
26
27
  },
27
28
  "devDependencies": {
28
- "@socket-mesh/client": "^18.0.3",
29
+ "@socket-mesh/client": "^18.0.5",
29
30
  "@socket-mesh/local-storage": "^1.0.2",
30
31
  "@types/base64id": "^2.0.1",
31
32
  "@types/clone-deep": "^4.0.3",
package/request.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Request, RequestSocket, RequestWithResponse } from "@socket-mesh/request";
2
2
  import { Connected } from "./events.js";
3
- import { DataPacket } from "@socket-mesh/simple-broker";
3
+ import { DataPacket } from "@socket-mesh/broker";
4
4
  import { ChannelOptions } from "@socket-mesh/channel";
5
5
  export type InboundRequest = HandshakeRequest | SubscribeRequest | UnsubscribeRequest | AuthenticateRequest | PublishRequest | InvokeRequest<any, any>;
6
6
  export interface HandshakeData {
package/server.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  import { AuthEngine } from "./auth-engine.js";
4
4
  import { CodecEngine } from "@socket-mesh/formatter";
5
- import { Broker, Packet } from "@socket-mesh/simple-broker";
5
+ import { Broker, Packet } from "@socket-mesh/broker";
6
6
  import { AsyncStreamEmitter } from "@socket-mesh/async-stream-emitter";
7
7
  import { MiddlewareType } from "./middleware-type.js";
8
8
  import { MiddlewareStream } from "./middleware-stream.js";
package/server.js CHANGED
@@ -12,52 +12,40 @@ import { ServerSocket } from "./serversocket.js";
12
12
  import url from "url";
13
13
  import crypto from "crypto";
14
14
  export class Server extends AsyncStreamEmitter {
15
+ allowClientPublish;
16
+ auth;
17
+ clientsCount;
18
+ codec;
19
+ defaultVerificationOptions;
20
+ defaultSignatureOptions;
21
+ isReady;
22
+ httpServer;
23
+ middlewareEmitFailures;
24
+ pendingClientsCount;
25
+ ackTimeout;
26
+ handshakeTimeout;
27
+ options;
28
+ path;
29
+ perMessageDeflate;
30
+ pingInterval;
31
+ pingTimeout;
32
+ pingTimeoutDisabled;
33
+ protocolVersion;
34
+ origins;
35
+ signatureKey;
36
+ strictHandshake;
37
+ socketChannelLimit;
38
+ verificationKey;
39
+ clients;
40
+ pendingClients;
41
+ brokerEngine;
42
+ exchange;
43
+ wsServer;
44
+ _allowAllOrigins;
45
+ _path;
46
+ _middleware;
15
47
  constructor(options) {
16
48
  super();
17
- this._verifyHandshake = async function (info, callback) {
18
- let req = info.req;
19
- let origin = info.origin;
20
- if (typeof origin !== 'string' || origin === 'null') {
21
- origin = '*';
22
- }
23
- let ok = false;
24
- if (this._allowAllOrigins) {
25
- ok = true;
26
- }
27
- else {
28
- try {
29
- let parts = url.parse(origin);
30
- parts.port = parts.port || (parts.protocol === 'https:' ? '443' : '80');
31
- ok = !!(~this.origins.indexOf(parts.hostname + ':' + parts.port) ||
32
- ~this.origins.indexOf(parts.hostname + ':*') ||
33
- ~this.origins.indexOf('*:' + parts.port));
34
- }
35
- catch (e) { }
36
- }
37
- const middlewareHandshakeStream = new MiddlewareStream(MiddlewareType.MIDDLEWARE_HANDSHAKE);
38
- req['handshakeStream'] = middlewareHandshakeStream;
39
- const handshakeMiddleware = this._middleware[MiddlewareType.MIDDLEWARE_HANDSHAKE];
40
- if (handshakeMiddleware) {
41
- handshakeMiddleware(middlewareHandshakeStream);
42
- }
43
- const action = new ActionHandshakeWS(req);
44
- try {
45
- await this._processMiddlewareAction(middlewareHandshakeStream, action);
46
- }
47
- catch (error) {
48
- middlewareHandshakeStream.close();
49
- callback(false, 401, typeof error === 'string' ? error : error.message);
50
- return;
51
- }
52
- if (ok) {
53
- callback(true);
54
- return;
55
- }
56
- const error = new ServerProtocolError(`Failed to authorize socket handshake - Invalid origin: ${origin}`);
57
- this.emitWarning(error);
58
- middlewareHandshakeStream.close();
59
- callback(false, 403, error.message);
60
- };
61
49
  let opts = {
62
50
  brokerEngine: new SimpleBroker(),
63
51
  wsEngine: 'ws',
@@ -326,4 +314,48 @@ export class Server extends AsyncStreamEmitter {
326
314
  }
327
315
  return { data: newData, options };
328
316
  }
317
+ _verifyHandshake = async function (info, callback) {
318
+ let req = info.req;
319
+ let origin = info.origin;
320
+ if (typeof origin !== 'string' || origin === 'null') {
321
+ origin = '*';
322
+ }
323
+ let ok = false;
324
+ if (this._allowAllOrigins) {
325
+ ok = true;
326
+ }
327
+ else {
328
+ try {
329
+ let parts = url.parse(origin);
330
+ parts.port = parts.port || (parts.protocol === 'https:' ? '443' : '80');
331
+ ok = !!(~this.origins.indexOf(parts.hostname + ':' + parts.port) ||
332
+ ~this.origins.indexOf(parts.hostname + ':*') ||
333
+ ~this.origins.indexOf('*:' + parts.port));
334
+ }
335
+ catch (e) { }
336
+ }
337
+ const middlewareHandshakeStream = new MiddlewareStream(MiddlewareType.MIDDLEWARE_HANDSHAKE);
338
+ req['handshakeStream'] = middlewareHandshakeStream;
339
+ const handshakeMiddleware = this._middleware[MiddlewareType.MIDDLEWARE_HANDSHAKE];
340
+ if (handshakeMiddleware) {
341
+ handshakeMiddleware(middlewareHandshakeStream);
342
+ }
343
+ const action = new ActionHandshakeWS(req);
344
+ try {
345
+ await this._processMiddlewareAction(middlewareHandshakeStream, action);
346
+ }
347
+ catch (error) {
348
+ middlewareHandshakeStream.close();
349
+ callback(false, 401, typeof error === 'string' ? error : error.message);
350
+ return;
351
+ }
352
+ if (ok) {
353
+ callback(true);
354
+ return;
355
+ }
356
+ const error = new ServerProtocolError(`Failed to authorize socket handshake - Invalid origin: ${origin}`);
357
+ this.emitWarning(error);
358
+ middlewareHandshakeStream.close();
359
+ callback(false, 403, error.message);
360
+ };
329
361
  }
package/serversocket.d.ts CHANGED
@@ -78,7 +78,7 @@ export declare class ServerSocket extends AsyncStreamEmitter<ServerSocketEvents>
78
78
  private readonly _sendPing;
79
79
  constructor(id: string, server: Server, socket: WebSocket, protocolVersion: ProtocolVersions);
80
80
  getBackpressure(): number;
81
- get exchange(): import("@socket-mesh/channel").Client<import("@socket-mesh/simple-broker/packet").Packet<any>>;
81
+ get exchange(): import("@socket-mesh/channel").Client<import("@socket-mesh/broker/packet").Packet<any>>;
82
82
  getInboundBackpressure(): number;
83
83
  getOutboundBackpressure(): number;
84
84
  private _startBatchOnHandshake;
package/serversocket.js CHANGED
@@ -15,6 +15,48 @@ import { AuthenticateRequest, HandshakeRequest, UnsubscribeRequest } from './req
15
15
  import { ServerSocketProcedure } from './serversocket-procedure.js';
16
16
  const HANDSHAKE_REJECTION_STATUS_CODE = 4008;
17
17
  export class ServerSocket extends AsyncStreamEmitter {
18
+ authState;
19
+ authToken;
20
+ batchInterval;
21
+ batchOnHandshake;
22
+ batchOnHandshakeDuration;
23
+ cloneData;
24
+ channelSubscriptionsCount;
25
+ inboundReceivedMessageCount;
26
+ inboundProcessedMessageCount;
27
+ isBatching;
28
+ isBufferingBatch;
29
+ request;
30
+ id;
31
+ socket;
32
+ protocolVersion;
33
+ channelSubscriptions;
34
+ inboundMessageStream;
35
+ outboundPacketStream;
36
+ server;
37
+ middlewareHandshakeStream;
38
+ middlewareInboundRawStream;
39
+ middlewareInboundStream;
40
+ middlewareOutboundStream;
41
+ remoteAddress;
42
+ remoteFamily;
43
+ remotePort;
44
+ outboundPreparedMessageCount;
45
+ outboundSentMessageCount;
46
+ signedAuthToken;
47
+ state;
48
+ receiver;
49
+ procedure;
50
+ _cid;
51
+ _handshakeTimeoutRef;
52
+ _pingIntervalTicker;
53
+ _pingTimeoutTicker;
54
+ _batchBuffer;
55
+ _batchingIntervalId;
56
+ _callbackMap;
57
+ _receiverDemux;
58
+ _procedureDemux;
59
+ _sendPing;
18
60
  constructor(id, server, socket, protocolVersion) {
19
61
  super();
20
62
  this.id = id;