@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 +38 -41
- package/action.js +18 -22
- package/auth-engine.d.ts +13 -0
- package/auth-engine.js +32 -0
- package/events.d.ts +3 -3
- package/inbound-packet.d.ts +11 -11
- package/index.d.ts +11 -11
- package/index.js +4 -4
- package/middleware-stream.d.ts +3 -3
- package/outbound-packet.d.ts +8 -8
- package/package.json +56 -58
- package/request.d.ts +9 -11
- package/request.js +3 -9
- package/server-options.d.ts +2 -2
- package/server.d.ts +53 -53
- package/server.js +90 -128
- package/serversocket-procedure.d.ts +13 -0
- package/serversocket-procedure.js +9 -0
- package/serversocket.d.ts +23 -22
- package/serversocket.js +663 -737
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 {
|
|
9
|
-
import {
|
|
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>)
|
|
36
|
-
block(error: Error)
|
|
35
|
+
allow: (packet?: ActionResult<T>) => void;
|
|
36
|
+
block: (error: Error) => void;
|
|
37
37
|
}
|
|
38
|
-
export type MiddlewareAction
|
|
39
|
-
export type InboundAction
|
|
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
|
|
56
|
-
constructor(socket: ServerSocket
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
66
|
-
constructor(socket: ServerSocket
|
|
67
|
-
socket: ServerSocket
|
|
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
|
|
71
|
-
constructor(socket: ServerSocket
|
|
72
|
-
socket: ServerSocket
|
|
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<
|
|
72
|
+
data?: DataPacket<any>;
|
|
76
73
|
}
|
|
77
|
-
export declare class ActionInvoke
|
|
78
|
-
constructor(socket: ServerSocket
|
|
79
|
-
socket: ServerSocket
|
|
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<
|
|
79
|
+
data?: DataPacket<any>;
|
|
83
80
|
}
|
|
84
|
-
export declare class ActionSubscribe
|
|
85
|
-
constructor(socket: ServerSocket
|
|
86
|
-
socket: ServerSocket
|
|
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
|
|
85
|
+
channel: string;
|
|
89
86
|
data?: ChannelOptions;
|
|
90
87
|
}
|
|
91
|
-
export declare class ActionPublishIn
|
|
92
|
-
constructor(socket: ServerSocket
|
|
93
|
-
socket: ServerSocket
|
|
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
|
|
96
|
-
data?:
|
|
92
|
+
channel: string;
|
|
93
|
+
data?: any;
|
|
97
94
|
}
|
|
98
|
-
export declare class ActionPublishOut
|
|
99
|
-
constructor(socket: ServerSocket
|
|
100
|
-
socket: ServerSocket
|
|
95
|
+
export declare class ActionPublishOut extends Action<any, ActionType.PUBLISH_OUT> {
|
|
96
|
+
constructor(socket: ServerSocket);
|
|
97
|
+
socket: ServerSocket;
|
|
101
98
|
channel?: string;
|
|
102
|
-
data?:
|
|
99
|
+
data?: any;
|
|
103
100
|
}
|
|
104
|
-
export declare class ActionAuthenticate
|
|
105
|
-
constructor(socket: ServerSocket
|
|
106
|
-
socket: ServerSocket
|
|
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
|
-
|
|
84
|
-
|
|
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
|
-
|
|
94
|
-
|
|
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 {
|
package/auth-engine.d.ts
ADDED
|
@@ -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
|
|
9
|
+
authToken?: AuthToken;
|
|
10
10
|
}
|
|
11
11
|
export interface AuthTokenSigned {
|
|
12
12
|
signedAuthToken: SignedAuthToken;
|
|
13
13
|
}
|
|
14
14
|
export interface Authenticated {
|
|
15
|
-
authToken
|
|
15
|
+
authToken: AuthToken;
|
|
16
16
|
}
|
|
17
17
|
export interface Deauthenticated {
|
|
18
|
-
oldAuthToken
|
|
18
|
+
oldAuthToken: AuthToken;
|
|
19
19
|
}
|
|
20
20
|
export interface BadAuthToken {
|
|
21
21
|
authError: Error;
|
package/inbound-packet.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
22
|
+
export interface InboundPublishPacket {
|
|
23
23
|
event: '#publish';
|
|
24
24
|
cid?: number;
|
|
25
|
-
data?: Partial<DataPacket<
|
|
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
|
|
36
|
+
export interface InboundDataPacket {
|
|
37
37
|
event: string | null;
|
|
38
38
|
rid: number | null;
|
|
39
39
|
cid?: number | null;
|
|
40
|
-
data: DataPacket<
|
|
40
|
+
data: DataPacket<any>;
|
|
41
41
|
error: any;
|
|
42
42
|
}
|
|
43
|
-
export declare function isHandshakePacket
|
|
44
|
-
export declare function isSubscribePacket
|
|
45
|
-
export declare function isUnsubscribePacket
|
|
46
|
-
export declare function isPublishPacket
|
|
47
|
-
export declare function isAuthenticatePacket
|
|
48
|
-
export declare function isRemoveAuthTokenPacket
|
|
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
|
|
19
|
-
export declare function listen
|
|
20
|
-
export declare function listen
|
|
21
|
-
export declare function listen
|
|
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
|
|
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;
|
package/middleware-stream.d.ts
CHANGED
|
@@ -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
|
|
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
|
}
|
package/outbound-packet.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { DataPacket } from "@socket-mesh/simple-broker";
|
|
2
|
-
export type OutboundPacket
|
|
3
|
-
export interface OutboundPublishPacket
|
|
2
|
+
export type OutboundPacket = OutboundPublishPacket | OutboundTransmitPacket | OutboundInvokePacket;
|
|
3
|
+
export interface OutboundPublishPacket {
|
|
4
4
|
event: '#publish';
|
|
5
|
-
data: DataPacket<
|
|
5
|
+
data: DataPacket<any>;
|
|
6
6
|
options?: OutboundPacketOptions;
|
|
7
7
|
}
|
|
8
|
-
export interface OutboundTransmitPacket
|
|
8
|
+
export interface OutboundTransmitPacket {
|
|
9
9
|
event: string;
|
|
10
|
-
data:
|
|
10
|
+
data: any;
|
|
11
11
|
options?: OutboundPacketOptions;
|
|
12
12
|
}
|
|
13
|
-
export interface OutboundInvokePacket
|
|
13
|
+
export interface OutboundInvokePacket {
|
|
14
14
|
event: string;
|
|
15
|
-
data:
|
|
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
|
|
25
|
+
export declare function isPublishOutPacket(packet: OutboundPacket): packet is OutboundPublishPacket;
|
package/package.json
CHANGED
|
@@ -1,60 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"@socket-mesh/consumable-stream": "3.2.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 {
|
|
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
|
|
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
|
|
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
|
|
14
|
-
export type
|
|
15
|
-
export
|
|
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
|
|
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
|
|
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
|
|
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
|
-
}
|
package/server-options.d.ts
CHANGED
|
@@ -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 "
|
|
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;
|