@socket-mesh/server 17.3.6 → 18.0.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.
package/action.d.ts CHANGED
@@ -5,8 +5,8 @@ import { AuthState, AuthToken, SignedAuthToken } from "@socket-mesh/auth";
5
5
  import { IncomingMessage } from 'http';
6
6
  import { DataPacket } from "@socket-mesh/simple-broker";
7
7
  import { ChannelOptions } from "@socket-mesh/channel";
8
- import { Request } from "@socket-mesh/request";
9
- import { ServerSocket } from "./serversocket";
8
+ import { ServerSocket } from "./serversocket.js";
9
+ import { HandshakeRequest } from "./request.js";
10
10
  export declare enum ActionType {
11
11
  HANDSHAKE_WS = "handshakeWS",
12
12
  HANDSHAKE_SC = "handshakeSC",
@@ -32,11 +32,12 @@ export declare abstract class Action<T, U extends ActionType = ActionType> {
32
32
  private _resolve;
33
33
  private _reject;
34
34
  constructor(type: U);
35
- allow(packet?: ActionResult<T>): void;
36
- block(error: Error): void;
35
+ allow: (packet?: ActionResult<T>) => void;
36
+ block: (error: Error) => void;
37
37
  }
38
- export type MiddlewareAction<T> = ActionTransmit<T> | ActionInvoke<T> | ActionPublishIn<T> | ActionPublishOut<T> | ActionSubscribe<T> | ActionHandshakeSC<T> | ActionHandshakeWS | ActionAuthenticate<T> | ActionMessage<T>;
39
- export type InboundAction<T> = ActionAuthenticate<T> | ActionTransmit<T> | ActionInvoke<T> | ActionPublishIn<T> | ActionSubscribe<T>;
38
+ export type MiddlewareAction = ActionTransmit | ActionInvoke | ActionPublishIn | ActionPublishOut | ActionSubscribe | ActionHandshakeSC | ActionHandshakeWS | ActionAuthenticate | ActionMessage;
39
+ export type InboundAction = ActionAuthenticate | ActionTransmit | ActionInvoke | ActionPublishIn | ActionSubscribe;
40
+ export type HandshakeAction = ActionHandshakeSC | ActionHandshakeWS;
40
41
  export declare class ActionHandshakeWS extends Action<undefined, ActionType.HANDSHAKE_WS> {
41
42
  constructor(request: IncomingMessage);
42
43
  request: IncomingMessage;
@@ -52,58 +53,54 @@ export type AuthInfo = {
52
53
  authToken: AuthToken;
53
54
  authState: AuthState;
54
55
  };
55
- export declare class ActionHandshakeSC<T> extends Action<AuthInfo, ActionType.HANDSHAKE_SC> {
56
- constructor(socket: ServerSocket<T>, request: Request<{
57
- authToken: string;
58
- }>, data: AuthInfo);
59
- request: Request<{
60
- authToken: string;
61
- }>;
62
- socket: ServerSocket<T>;
56
+ export declare class ActionHandshakeSC extends Action<AuthInfo, ActionType.HANDSHAKE_SC> {
57
+ constructor(socket: ServerSocket, request: HandshakeRequest, data: AuthInfo);
58
+ request: HandshakeRequest;
59
+ socket: ServerSocket;
63
60
  data: AuthInfo;
64
61
  }
65
- export declare class ActionMessage<T> extends Action<string | ArrayBuffer | Buffer[], ActionType.MESSAGE> {
66
- constructor(socket: ServerSocket<T>, data: string | ArrayBuffer | Buffer[]);
67
- socket: ServerSocket<T>;
62
+ export declare class ActionMessage extends Action<string | ArrayBuffer | Buffer[], ActionType.MESSAGE> {
63
+ constructor(socket: ServerSocket, data: string | ArrayBuffer | Buffer[]);
64
+ socket: ServerSocket;
68
65
  data: string | ArrayBuffer | Buffer[];
69
66
  }
70
- export declare class ActionTransmit<T> extends Action<T, ActionType.TRANSMIT> {
71
- constructor(socket: ServerSocket<T>, receiver: string, packet: DataPacket<T>);
72
- socket: ServerSocket<T>;
67
+ export declare class ActionTransmit extends Action<any, ActionType.TRANSMIT> {
68
+ constructor(socket: ServerSocket, receiver: string, packet: DataPacket<any>);
69
+ socket: ServerSocket;
73
70
  authTokenExpiredError?: AuthTokenExpiredError;
74
71
  receiver: string;
75
- data?: DataPacket<T>;
72
+ data?: DataPacket<any>;
76
73
  }
77
- export declare class ActionInvoke<T> extends Action<T, ActionType.INVOKE> {
78
- constructor(socket: ServerSocket<T>, procedure: string, packet?: DataPacket<T>);
79
- socket: ServerSocket<T>;
74
+ export declare class ActionInvoke extends Action<any, ActionType.INVOKE> {
75
+ constructor(socket: ServerSocket, procedure: string, packet?: DataPacket<any>);
76
+ socket: ServerSocket;
80
77
  authTokenExpiredError?: AuthTokenExpiredError;
81
78
  procedure: string;
82
- data?: DataPacket<T>;
79
+ data?: DataPacket<any>;
83
80
  }
84
- export declare class ActionSubscribe<T> extends Action<ChannelOptions, ActionType.SUBSCRIBE> {
85
- constructor(socket: ServerSocket<T>, packet?: DataPacket<ChannelOptions>);
86
- socket: ServerSocket<T>;
81
+ export declare class ActionSubscribe extends Action<ChannelOptions, ActionType.SUBSCRIBE> {
82
+ constructor(socket: ServerSocket, packet?: DataPacket<ChannelOptions>);
83
+ socket: ServerSocket;
87
84
  authTokenExpiredError?: AuthTokenExpiredError;
88
- channel?: string;
85
+ channel: string;
89
86
  data?: ChannelOptions;
90
87
  }
91
- export declare class ActionPublishIn<T> extends Action<T, ActionType.PUBLISH_IN> {
92
- constructor(socket: ServerSocket<T>, packet?: Partial<DataPacket<T>>);
93
- socket: ServerSocket<T>;
88
+ export declare class ActionPublishIn extends Action<any, ActionType.PUBLISH_IN> {
89
+ constructor(socket: ServerSocket, packet: Partial<DataPacket<any>>);
90
+ socket: ServerSocket;
94
91
  authTokenExpiredError?: AuthTokenExpiredError;
95
- channel?: string;
96
- data?: T;
92
+ channel: string;
93
+ data?: any;
97
94
  }
98
- export declare class ActionPublishOut<T> extends Action<T, ActionType.PUBLISH_OUT> {
99
- constructor(socket: ServerSocket<T>);
100
- socket: ServerSocket<T>;
95
+ export declare class ActionPublishOut extends Action<any, ActionType.PUBLISH_OUT> {
96
+ constructor(socket: ServerSocket);
97
+ socket: ServerSocket;
101
98
  channel?: string;
102
- data?: T;
99
+ data?: any;
103
100
  }
104
- export declare class ActionAuthenticate<T> extends Action<undefined, ActionType.AUTHENTICATE> {
105
- constructor(socket: ServerSocket<T>, authToken: AuthToken, signedAuthToken: SignedAuthToken);
106
- socket: ServerSocket<T>;
101
+ export declare class ActionAuthenticate extends Action<undefined, ActionType.AUTHENTICATE> {
102
+ constructor(socket: ServerSocket, authToken: AuthToken, signedAuthToken: SignedAuthToken);
103
+ socket: ServerSocket;
107
104
  authToken: AuthToken;
108
105
  signedAuthToken: string;
109
106
  }
package/action.js CHANGED
@@ -13,6 +13,20 @@ export var ActionType;
13
13
  })(ActionType || (ActionType = {}));
14
14
  export class Action {
15
15
  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
+ };
16
30
  this.type = type;
17
31
  this.outcome = null;
18
32
  this.promise = new Promise((resolve, reject) => {
@@ -20,20 +34,6 @@ export class Action {
20
34
  this._reject = reject;
21
35
  });
22
36
  }
23
- allow(packet) {
24
- if (this.outcome) {
25
- throw new InvalidActionError(`Action ${this.type} has already been ${this.outcome}; cannot allow`);
26
- }
27
- this.outcome = 'allowed';
28
- this._resolve(packet);
29
- }
30
- block(error) {
31
- if (this.outcome) {
32
- throw new InvalidActionError(`Action ${this.type} has already been ${this.outcome}; cannot block`);
33
- }
34
- this.outcome = 'blocked';
35
- this._reject(error);
36
- }
37
37
  }
38
38
  export class ActionHandshakeWS extends Action {
39
39
  constructor(request) {
@@ -80,20 +80,16 @@ export class ActionSubscribe extends Action {
80
80
  constructor(socket, packet) {
81
81
  super(ActionType.SUBSCRIBE);
82
82
  this.socket = socket;
83
- if (packet) {
84
- this.channel = packet.channel;
85
- this.data = packet.data;
86
- }
83
+ this.channel = packet.channel;
84
+ this.data = packet.data;
87
85
  }
88
86
  }
89
87
  export class ActionPublishIn extends Action {
90
88
  constructor(socket, packet) {
91
89
  super(ActionType.PUBLISH_IN);
92
90
  this.socket = socket;
93
- if (packet) {
94
- this.channel = packet.channel;
95
- this.data = packet.data;
96
- }
91
+ this.channel = packet.channel;
92
+ this.data = packet.data;
97
93
  }
98
94
  }
99
95
  export class ActionPublishOut extends Action {
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import jwt from 'jsonwebtoken';
3
+ import { ServerSocket } from './serversocket.js';
4
+ export interface AuthTokenOptions extends jwt.SignOptions {
5
+ rejectOnFailedDelivery?: boolean;
6
+ }
7
+ export interface VerifyOptions extends jwt.VerifyOptions {
8
+ socket: ServerSocket;
9
+ }
10
+ export declare class AuthEngine {
11
+ verifyToken(signedToken: string, key: jwt.Secret | jwt.GetPublicKeyOrSecret, options: VerifyOptions): Promise<jwt.JwtPayload>;
12
+ signToken(token: string | object | Buffer, key: jwt.Secret, options: jwt.SignOptions): Promise<string>;
13
+ }
package/auth-engine.js ADDED
@@ -0,0 +1,32 @@
1
+ import jwt from 'jsonwebtoken';
2
+ import { InvalidArgumentsError } from '@socket-mesh/errors';
3
+ export class AuthEngine {
4
+ verifyToken(signedToken, key, options) {
5
+ const jwtOptions = Object.assign({}, options || {});
6
+ if (typeof signedToken === 'string' || signedToken == null) {
7
+ return new Promise((resolve, reject) => {
8
+ const cb = (err, token) => {
9
+ if (err) {
10
+ reject(err);
11
+ return;
12
+ }
13
+ resolve(token);
14
+ };
15
+ jwt.verify(signedToken || '', key, jwtOptions, cb);
16
+ });
17
+ }
18
+ return Promise.reject(new InvalidArgumentsError('Invalid token format - Token must be a string'));
19
+ }
20
+ signToken(token, key, options) {
21
+ const jwtOptions = Object.assign({}, options || {});
22
+ return new Promise((resolve, reject) => {
23
+ jwt.sign(token, key, jwtOptions, (err, signedToken) => {
24
+ if (err) {
25
+ reject(err);
26
+ return;
27
+ }
28
+ resolve(signedToken);
29
+ });
30
+ });
31
+ }
32
+ }
package/events.d.ts CHANGED
@@ -6,16 +6,16 @@ export type RawMessage = {
6
6
  message: string | ArrayBuffer | Buffer[];
7
7
  };
8
8
  export interface AuthStateChanged extends AuthStateChange {
9
- authToken?: AuthToken | null;
9
+ authToken?: AuthToken;
10
10
  }
11
11
  export interface AuthTokenSigned {
12
12
  signedAuthToken: SignedAuthToken;
13
13
  }
14
14
  export interface Authenticated {
15
- authToken?: AuthToken | null;
15
+ authToken: AuthToken;
16
16
  }
17
17
  export interface Deauthenticated {
18
- oldAuthToken?: AuthToken | null;
18
+ oldAuthToken: AuthToken;
19
19
  }
20
20
  export interface BadAuthToken {
21
21
  authError: Error;
@@ -1,7 +1,7 @@
1
1
  import { SignedAuthToken } from "@socket-mesh/auth";
2
2
  import { ChannelOptions } from "@socket-mesh/channel";
3
3
  import { DataPacket } from "@socket-mesh/simple-broker";
4
- export type InboundPacket<T> = InboundHandshakePacket | InboundDataPacket<T> | InboundPublishPacket<T> | InboundSubscribePacket | InboundUnsubscribePacket | InboundAuthenticatePacket | InboundRemoveAuthTokenPacket;
4
+ export type InboundPacket = InboundHandshakePacket | InboundDataPacket | InboundPublishPacket | InboundSubscribePacket | InboundUnsubscribePacket | InboundAuthenticatePacket | InboundRemoveAuthTokenPacket;
5
5
  export interface InboundHandshakePacket {
6
6
  event: '#handshake';
7
7
  cid: number;
@@ -19,10 +19,10 @@ export interface InboundUnsubscribePacket {
19
19
  cid?: number;
20
20
  data: string;
21
21
  }
22
- export interface InboundPublishPacket<T> {
22
+ export interface InboundPublishPacket {
23
23
  event: '#publish';
24
24
  cid?: number;
25
- data?: Partial<DataPacket<T>>;
25
+ data?: Partial<DataPacket<any>>;
26
26
  }
27
27
  export interface InboundAuthenticatePacket {
28
28
  event: '#authenticate';
@@ -33,16 +33,16 @@ export interface InboundRemoveAuthTokenPacket {
33
33
  event: '#removeAuthToken';
34
34
  data: undefined;
35
35
  }
36
- export interface InboundDataPacket<T> {
36
+ export interface InboundDataPacket {
37
37
  event: string | null;
38
38
  rid: number | null;
39
39
  cid?: number | null;
40
- data: DataPacket<T>;
40
+ data: DataPacket<any>;
41
41
  error: any;
42
42
  }
43
- export declare function isHandshakePacket<T>(packet: InboundPacket<T>): packet is InboundHandshakePacket;
44
- export declare function isSubscribePacket<T>(packet: InboundPacket<T>): packet is InboundSubscribePacket;
45
- export declare function isUnsubscribePacket<T>(packet: InboundPacket<T>): packet is InboundUnsubscribePacket;
46
- export declare function isPublishPacket<T>(packet: InboundPacket<T>): packet is InboundPublishPacket<T>;
47
- export declare function isAuthenticatePacket<T>(packet: InboundPacket<T>): packet is InboundAuthenticatePacket;
48
- export declare function isRemoveAuthTokenPacket<T>(packet: InboundPacket<T>): packet is InboundRemoveAuthTokenPacket;
43
+ export declare function isHandshakePacket(packet: InboundPacket): packet is InboundHandshakePacket;
44
+ export declare function isSubscribePacket(packet: InboundPacket): packet is InboundSubscribePacket;
45
+ export declare function isUnsubscribePacket(packet: InboundPacket): packet is InboundUnsubscribePacket;
46
+ export declare function isPublishPacket(packet: InboundPacket): packet is InboundPublishPacket;
47
+ export declare function isAuthenticatePacket(packet: InboundPacket): packet is InboundAuthenticatePacket;
48
+ export declare function isRemoveAuthTokenPacket(packet: InboundPacket): packet is InboundRemoveAuthTokenPacket;
package/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import http from "http";
3
- import { Server } from "./server";
4
- import { ServerOptions } from "./server-options";
5
- export { Server } from "./server";
6
- export { ServerSocket } from "./serversocket";
7
- export { ServerOptions } from "./server-options";
8
- export { MiddlewareType } from "./middleware-type";
3
+ import { Server } from "./server.js";
4
+ import { ServerOptions } from "./server-options.js";
5
+ export { Server } from "./server.js";
6
+ export { ServerSocket } from "./serversocket.js";
7
+ export { ServerOptions } from "./server-options.js";
8
+ export { MiddlewareType } from "./middleware-type.js";
9
9
  /**
10
10
  * Creates an http.Server exclusively used for WS upgrades.
11
11
  *
@@ -15,10 +15,10 @@ export { MiddlewareType } from "./middleware-type";
15
15
  * @return {AGServer} websocket cluster server
16
16
  * @api public
17
17
  */
18
- export declare function listen<T>(): Server<T>;
19
- export declare function listen<T>(port: number, fn: () => void): Server<T>;
20
- export declare function listen<T>(port: number, options: ServerOptions): Server<T>;
21
- export declare function listen<T>(port: number, options: ServerOptions, fn: () => void): Server<T>;
18
+ export declare function listen(): Server;
19
+ export declare function listen(port: number, fn: () => void): Server;
20
+ export declare function listen(port: number, options: ServerOptions): Server;
21
+ export declare function listen(port: number, options: ServerOptions, fn: () => void): Server;
22
22
  /**
23
23
  * Captures upgrade requests for a http.Server.
24
24
  *
@@ -27,4 +27,4 @@ export declare function listen<T>(port: number, options: ServerOptions, fn: () =
27
27
  * @return {AGServer} websocket cluster server
28
28
  * @api public
29
29
  */
30
- export declare function attach<T>(server: http.Server, options?: ServerOptions): Server<T>;
30
+ export declare function attach(server: http.Server, options?: ServerOptions): Server;
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import http from "http";
2
- import { Server } from "./server";
3
- export { Server } from "./server";
4
- export { ServerSocket } from "./serversocket";
5
- export { MiddlewareType } from "./middleware-type";
2
+ import { Server } from "./server.js";
3
+ export { Server } from "./server.js";
4
+ export { ServerSocket } from "./serversocket.js";
5
+ export { MiddlewareType } from "./middleware-type.js";
6
6
  export function listen(port, options, fn) {
7
7
  if (typeof options === 'function') {
8
8
  fn = options;
@@ -1,7 +1,7 @@
1
1
  import { WritableConsumableStream } from "@socket-mesh/writable-consumable-stream";
2
- import { MiddlewareType } from "./middleware-type";
3
- import { Action } from "./action";
4
- export declare class MiddlewareStream<T> extends WritableConsumableStream<Action<T>> {
2
+ import { MiddlewareType } from "./middleware-type.js";
3
+ import { Action, ActionType } from "./action.js";
4
+ export declare class MiddlewareStream<T extends Action<any, ActionType>> extends WritableConsumableStream<T> {
5
5
  readonly type: MiddlewareType;
6
6
  constructor(type: MiddlewareType);
7
7
  }
@@ -1,18 +1,18 @@
1
1
  import { DataPacket } from "@socket-mesh/simple-broker";
2
- export type OutboundPacket<T> = OutboundPublishPacket<T> | OutboundTransmitPacket<T> | OutboundInvokePacket<T>;
3
- export interface OutboundPublishPacket<T> {
2
+ export type OutboundPacket = OutboundPublishPacket | OutboundTransmitPacket | OutboundInvokePacket;
3
+ export interface OutboundPublishPacket {
4
4
  event: '#publish';
5
- data: DataPacket<T>;
5
+ data: DataPacket<any>;
6
6
  options?: OutboundPacketOptions;
7
7
  }
8
- export interface OutboundTransmitPacket<T> {
8
+ export interface OutboundTransmitPacket {
9
9
  event: string;
10
- data: T;
10
+ data: any;
11
11
  options?: OutboundPacketOptions;
12
12
  }
13
- export interface OutboundInvokePacket<T> {
13
+ export interface OutboundInvokePacket {
14
14
  event: string;
15
- data: T;
15
+ data: any;
16
16
  options?: OutboundPacketOptions;
17
17
  resolve: (value: any) => void;
18
18
  reject: (err: Error) => void;
@@ -22,4 +22,4 @@ export interface OutboundPacketOptions {
22
22
  useCache?: boolean;
23
23
  stringifiedData?: string;
24
24
  }
25
- export declare function isPublishOutPacket<T>(packet: OutboundPacket<T>): packet is OutboundPublishPacket<T>;
25
+ export declare function isPublishOutPacket(packet: OutboundPacket): packet is OutboundPublishPacket;
package/package.json CHANGED
@@ -1,60 +1,58 @@
1
1
  {
2
- "name": "@socket-mesh/server",
3
- "version": "17.3.6",
4
- "description": "Server module for SocketMesh",
5
- "main": "index.js",
6
- "type": "module",
7
- "repository": {
8
- "type": "git",
9
- "url": "git://github.com/socket-mesh/server.git"
10
- },
11
- "dependencies": {
12
- "@socket-mesh/async-stream-emitter": "^4.2.4",
13
- "@socket-mesh/consumable-stream": "3.2.0",
14
- "@socket-mesh/auth": "^2.1.5",
15
- "@socket-mesh/errors": "^3.0.4",
16
- "@socket-mesh/formatter": "^4.0.3",
17
- "@socket-mesh/request": "^2.0.3",
18
- "@socket-mesh/server-auth": "^0.0.3",
19
- "@socket-mesh/simple-broker": "^5.1.5",
20
- "@socket-mesh/stream-demux": "^9.0.5",
21
- "@socket-mesh/writable-consumable-stream": "^4.2.0",
22
- "@socket-mesh/channel": "6.0.15",
23
- "base64id": "^2.0.0",
24
- "clone-deep": "^4.0.1",
25
- "jsonwebtoken": "^9.0.0",
26
- "ws": "^8.13.0"
27
- },
28
- "devDependencies": {
29
- "@socket-mesh/local-storage": "^1.0.0",
30
- "@types/base64id": "^2.0.0",
31
- "@types/clone-deep": "^4.0.1",
32
- "@types/jsonwebtoken": "^9.0.1",
33
- "@types/ws": "^8.5.4",
34
- "cross-env": "^7.0.3",
35
- "jest": "^29.5.0",
36
- "ts-jest": "^29.0.5",
37
- "ts-node": "^10.9.1",
38
- "typescript": "^5.0.4"
39
- },
40
- "scripts": {
41
- "build": "node ./scripts/build.mjs && tsc",
42
- "deploy": "cd dist && npm publish --access public",
43
- "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --config ./jest.config.ts"
44
- },
45
- "keywords": [
46
- "websocket",
47
- "realtime",
48
- "socketcluster",
49
- "socketmesh"
50
- ],
51
- "author": "Jonathan Gros-Dubois <grosjona@yahoo.com.au>",
52
- "contributors": [
53
- "Greg Kimmy",
54
- {
55
- "name": "Jonathan Gros-Dubois",
56
- "email": "grosjona@yahoo.com.au"
57
- }
58
- ],
59
- "license": "MIT"
2
+ "name": "@socket-mesh/server",
3
+ "version": "18.0.0",
4
+ "description": "Server module for SocketMesh",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git://github.com/socket-mesh/server.git"
10
+ },
11
+ "dependencies": {
12
+ "@socket-mesh/async-stream-emitter": "^7.0.2",
13
+ "@socket-mesh/consumable-stream": "3.2.1",
14
+ "@socket-mesh/auth": "^2.1.6",
15
+ "@socket-mesh/errors": "^3.0.8",
16
+ "@socket-mesh/formatter": "^4.0.5",
17
+ "@socket-mesh/request": "^2.0.9",
18
+ "@socket-mesh/simple-broker": "^6.0.0",
19
+ "@socket-mesh/stream-demux": "^10.0.1",
20
+ "@socket-mesh/writable-consumable-stream": "^4.2.9",
21
+ "@socket-mesh/channel": "6.0.25",
22
+ "base64id": "^2.0.0",
23
+ "clone-deep": "^4.0.1",
24
+ "jsonwebtoken": "^9.0.2",
25
+ "ws": "^8.14.2"
26
+ },
27
+ "devDependencies": {
28
+ "@socket-mesh/client": "^18.0.3",
29
+ "@socket-mesh/local-storage": "^1.0.2",
30
+ "@types/base64id": "^2.0.1",
31
+ "@types/clone-deep": "^4.0.3",
32
+ "@types/jsonwebtoken": "^9.0.4",
33
+ "@types/ws": "^8.5.8",
34
+ "cross-env": "^7.0.3",
35
+ "ts-node": "^10.9.1",
36
+ "typescript": "^5.2.2"
37
+ },
38
+ "scripts": {
39
+ "build": "node ./scripts/build.mjs && tsc",
40
+ "deploy": "cd dist && npm publish --access public",
41
+ "test": "cross-env node --test --loader ts-node/esm test/test.ts"
42
+ },
43
+ "keywords": [
44
+ "websocket",
45
+ "realtime",
46
+ "socketcluster",
47
+ "socketmesh"
48
+ ],
49
+ "author": "Jonathan Gros-Dubois <grosjona@yahoo.com.au>",
50
+ "contributors": [
51
+ "Greg Kimmy",
52
+ {
53
+ "name": "Jonathan Gros-Dubois",
54
+ "email": "grosjona@yahoo.com.au"
55
+ }
56
+ ],
57
+ "license": "MIT"
60
58
  }
package/request.d.ts CHANGED
@@ -1,26 +1,24 @@
1
- import { Request } from "@socket-mesh/request";
2
- import { RequestSocket } from "@socket-mesh/request/request";
3
- import { Connected } from "./events";
1
+ import { Request, RequestSocket, RequestWithResponse } from "@socket-mesh/request";
2
+ import { Connected } from "./events.js";
4
3
  import { DataPacket } from "@socket-mesh/simple-broker";
5
4
  import { ChannelOptions } from "@socket-mesh/channel";
6
- export type InboundRequest<T> = HandshakeRequest | SubscribeRequest | UnsubscribeRequest | AuthenticateRequest | PublishRequest<T>;
5
+ export type InboundRequest = HandshakeRequest | SubscribeRequest | UnsubscribeRequest | AuthenticateRequest | PublishRequest | InvokeRequest<any, any>;
7
6
  export interface HandshakeData {
8
7
  authToken: string;
9
8
  }
10
- export declare class HandshakeRequest extends Request<HandshakeData, Connected> {
9
+ export declare class HandshakeRequest extends RequestWithResponse<HandshakeData, Connected> {
11
10
  constructor(socket: RequestSocket, id: number, procedureName: '#handshake', data: HandshakeData);
12
11
  }
13
- export type SubscribeRequest = Request<Partial<DataPacket<ChannelOptions>>, void>;
14
- export type PublishRequest<T> = Request<Partial<DataPacket<T>>, void>;
15
- export declare class UnsubscribeRequest extends Request<string, void> {
12
+ export type InvokeRequest<T, U> = RequestWithResponse<T, U>;
13
+ export type SubscribeRequest = Request<Partial<DataPacket<ChannelOptions>>>;
14
+ export type PublishRequest = Request<Partial<DataPacket<any>>>;
15
+ export declare class UnsubscribeRequest extends Request<string> {
16
16
  constructor(socket: RequestSocket, id: number, procedureName: '#unsubscribe', data: string);
17
17
  }
18
18
  export interface AuthenticateData {
19
19
  isAuthenticated: boolean;
20
20
  authError: Error | null;
21
21
  }
22
- export declare class AuthenticateRequest extends Request<string, AuthenticateData> {
22
+ export declare class AuthenticateRequest extends RequestWithResponse<string, AuthenticateData> {
23
23
  constructor(socket: RequestSocket, id: number, procedureName: '#authenticate', data: string);
24
24
  }
25
- export declare function isSubscribeRequest(request: Request<unknown>): request is SubscribeRequest;
26
- export declare function isPublishRequest<T>(request: Request<unknown>): request is PublishRequest<T>;
package/request.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Request } from "@socket-mesh/request";
2
- export class HandshakeRequest extends Request {
1
+ import { Request, RequestWithResponse } from "@socket-mesh/request";
2
+ export class HandshakeRequest extends RequestWithResponse {
3
3
  constructor(socket, id, procedureName, data) {
4
4
  super(socket, id, procedureName, data);
5
5
  }
@@ -9,14 +9,8 @@ export class UnsubscribeRequest extends Request {
9
9
  super(socket, id, procedureName, data);
10
10
  }
11
11
  }
12
- export class AuthenticateRequest extends Request {
12
+ export class AuthenticateRequest extends RequestWithResponse {
13
13
  constructor(socket, id, procedureName, data) {
14
14
  super(socket, id, procedureName, data);
15
15
  }
16
16
  }
17
- export function isSubscribeRequest(request) {
18
- return request.procedure === '#subscribe';
19
- }
20
- export function isPublishRequest(request) {
21
- return request.procedure === '#publish';
22
- }
@@ -3,7 +3,7 @@ import { CodecEngine } from "@socket-mesh/formatter";
3
3
  import ws from "ws";
4
4
  import jwt from "jsonwebtoken";
5
5
  import { Server as HttpServer } from 'http';
6
- import { AuthEngine } from "@socket-mesh/server-auth";
6
+ import { AuthEngine } from "./auth-engine.js";
7
7
  export type ProtocolVersions = 1 | 2;
8
8
  export interface ServerOptions {
9
9
  httpServer?: HttpServer;
@@ -28,7 +28,7 @@ export interface ServerOptions {
28
28
  batchOnHandshake?: boolean;
29
29
  batchOnHandshakeDuration?: number;
30
30
  batchInterval?: number;
31
- socketStreamCleanupMode?: 'kill' | 'close';
31
+ socketStreamCleanupMode?: 'kill' | 'close' | 'none';
32
32
  authVerifyAlgorithms?: jwt.Algorithm[];
33
33
  authEngine?: AuthEngine;
34
34
  codecEngine?: CodecEngine;