@welshman/net 0.0.32 → 0.0.33
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/build/src/Connection.cjs +29 -85
- package/build/src/Connection.cjs.map +1 -1
- package/build/src/Connection.d.ts +19 -21
- package/build/src/Connection.mjs +30 -86
- package/build/src/Connection.mjs.map +1 -1
- package/build/src/ConnectionAuth.cjs +28 -38
- package/build/src/ConnectionAuth.cjs.map +1 -1
- package/build/src/ConnectionAuth.d.ts +7 -11
- package/build/src/ConnectionAuth.mjs +28 -38
- package/build/src/ConnectionAuth.mjs.map +1 -1
- package/build/src/ConnectionEvent.cjs +16 -0
- package/build/src/ConnectionEvent.cjs.map +1 -0
- package/build/src/ConnectionEvent.d.ts +11 -0
- package/build/src/ConnectionEvent.mjs +13 -0
- package/build/src/ConnectionEvent.mjs.map +1 -0
- package/build/src/ConnectionSender.cjs +50 -0
- package/build/src/ConnectionSender.cjs.map +1 -0
- package/build/src/ConnectionSender.d.ts +10 -0
- package/build/src/ConnectionSender.mjs +46 -0
- package/build/src/ConnectionSender.mjs.map +1 -0
- package/build/src/ConnectionState.cjs +68 -0
- package/build/src/ConnectionState.cjs.map +1 -0
- package/build/src/ConnectionState.d.ts +17 -0
- package/build/src/ConnectionState.mjs +64 -0
- package/build/src/ConnectionState.mjs.map +1 -0
- package/build/src/ConnectionStats.cjs +86 -0
- package/build/src/ConnectionStats.cjs.map +1 -0
- package/build/src/ConnectionStats.d.ts +26 -0
- package/build/src/ConnectionStats.mjs +82 -0
- package/build/src/ConnectionStats.mjs.map +1 -0
- package/build/src/Pool.cjs +9 -15
- package/build/src/Pool.cjs.map +1 -1
- package/build/src/Pool.d.ts +1 -4
- package/build/src/Pool.mjs +9 -15
- package/build/src/Pool.mjs.map +1 -1
- package/build/src/Socket.cjs +94 -53
- package/build/src/Socket.cjs.map +1 -1
- package/build/src/Socket.d.ts +21 -28
- package/build/src/Socket.mjs +94 -51
- package/build/src/Socket.mjs.map +1 -1
- package/build/src/Subscribe.cjs +8 -3
- package/build/src/Subscribe.cjs.map +1 -1
- package/build/src/Subscribe.mjs +8 -3
- package/build/src/Subscribe.mjs.map +1 -1
- package/build/src/index.cjs +4 -2
- package/build/src/index.cjs.map +1 -1
- package/build/src/index.d.ts +4 -2
- package/build/src/index.mjs +4 -2
- package/build/src/target/Relay.cjs +3 -2
- package/build/src/target/Relay.cjs.map +1 -1
- package/build/src/target/Relay.mjs +3 -2
- package/build/src/target/Relay.mjs.map +1 -1
- package/build/src/target/Relays.cjs +2 -1
- package/build/src/target/Relays.cjs.map +1 -1
- package/build/src/target/Relays.mjs +2 -1
- package/build/src/target/Relays.mjs.map +1 -1
- package/package.json +1 -1
- package/build/src/ConnectionMeta.cjs +0 -139
- package/build/src/ConnectionMeta.cjs.map +0 -1
- package/build/src/ConnectionMeta.d.ts +0 -48
- package/build/src/ConnectionMeta.mjs +0 -135
- package/build/src/ConnectionMeta.mjs.map +0 -1
- package/build/src/target/Plex.cjs +0 -27
- package/build/src/target/Plex.cjs.map +0 -1
- package/build/src/target/Plex.d.ts +0 -12
- package/build/src/target/Plex.mjs +0 -23
- package/build/src/target/Plex.mjs.map +0 -1
package/build/src/Connection.cjs
CHANGED
|
@@ -1,101 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Connection = void 0;
|
|
3
|
+
exports.Connection = exports.ConnectionStatus = void 0;
|
|
4
4
|
const lib_1 = require("@welshman/lib");
|
|
5
|
-
const util_1 = require("@welshman/util");
|
|
6
|
-
const ConnectionMeta_1 = require("./ConnectionMeta.cjs");
|
|
7
|
-
const ConnectionAuth_1 = require("./ConnectionAuth.cjs");
|
|
8
5
|
const Socket_1 = require("./Socket.cjs");
|
|
6
|
+
const ConnectionState_1 = require("./ConnectionState.cjs");
|
|
7
|
+
const ConnectionStats_1 = require("./ConnectionStats.cjs");
|
|
8
|
+
const ConnectionAuth_1 = require("./ConnectionAuth.cjs");
|
|
9
|
+
const ConnectionSender_1 = require("./ConnectionSender.cjs");
|
|
10
|
+
var ConnectionStatus;
|
|
11
|
+
(function (ConnectionStatus) {
|
|
12
|
+
ConnectionStatus["Ready"] = "ready";
|
|
13
|
+
ConnectionStatus["Closed"] = "Closed";
|
|
14
|
+
ConnectionStatus["Closing"] = "Closing";
|
|
15
|
+
})(ConnectionStatus || (exports.ConnectionStatus = ConnectionStatus = {}));
|
|
16
|
+
const { Ready, Closed, Closing } = ConnectionStatus;
|
|
9
17
|
class Connection extends lib_1.Emitter {
|
|
10
18
|
constructor(url) {
|
|
11
19
|
super();
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const [verb, ...extra] = (0, Socket_1.asMessage)(message);
|
|
19
|
-
if (verb === 'AUTH') {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
// Only close reqs that have been sent
|
|
23
|
-
if (verb === 'CLOSE') {
|
|
24
|
-
return !this.meta.pendingRequests.has(extra[0]);
|
|
25
|
-
}
|
|
26
|
-
// Allow relay requests through
|
|
27
|
-
if (verb === 'EVENT' && extra[0].kind === util_1.AUTH_JOIN) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
// Only defer for auth if we're not multiplexing
|
|
31
|
-
if ((0, Socket_1.isMessage)(message) && ![ConnectionAuth_1.AuthStatus.None, ConnectionAuth_1.AuthStatus.Ok].includes(this.auth.status)) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
if (verb === 'REQ') {
|
|
35
|
-
return this.meta.pendingRequests.size >= 8;
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
worker.addGlobalHandler((message) => {
|
|
41
|
-
// If we ended up handling a CLOSE before we handled the REQ, don't send the REQ
|
|
42
|
-
if (message[0] === 'CLOSE') {
|
|
43
|
-
worker.buffer = worker.buffer.filter(m => !(m[0] === 'REQ' && m[1] === message[1]));
|
|
44
|
-
}
|
|
45
|
-
this.onSend(message);
|
|
46
|
-
});
|
|
47
|
-
return worker;
|
|
48
|
-
};
|
|
49
|
-
this.createReceiver = () => {
|
|
50
|
-
const worker = new lib_1.Worker();
|
|
51
|
-
worker.addGlobalHandler(this.onReceive);
|
|
52
|
-
return worker;
|
|
53
|
-
};
|
|
54
|
-
this.send = (m) => this.sender.push(m);
|
|
55
|
-
this.onOpen = () => this.emit('open', this);
|
|
56
|
-
this.onClose = () => this.emit('close', this);
|
|
57
|
-
this.onFault = () => this.emit('fault', this);
|
|
58
|
-
this.onMessage = (m) => this.receiver.push(m);
|
|
59
|
-
this.onSend = (message) => {
|
|
60
|
-
this.emit('send', this, message);
|
|
61
|
-
this.socket.send(message);
|
|
62
|
-
};
|
|
63
|
-
this.onReceive = (message) => {
|
|
64
|
-
this.emit('receive', this, message);
|
|
65
|
-
};
|
|
66
|
-
this.ensureConnected = async ({ shouldReconnect = true } = {}) => {
|
|
67
|
-
const isUnhealthy = this.socket.isClosing() || this.socket.isClosed();
|
|
68
|
-
const noRecentFault = this.meta.lastFault < Date.now() - 60000;
|
|
69
|
-
if (shouldReconnect && isUnhealthy && noRecentFault) {
|
|
70
|
-
await this.disconnect();
|
|
71
|
-
}
|
|
72
|
-
if (this.socket.isNew()) {
|
|
73
|
-
await this.socket.connect();
|
|
74
|
-
}
|
|
75
|
-
while (this.socket.isConnecting()) {
|
|
76
|
-
await (0, lib_1.sleep)(100);
|
|
20
|
+
this.status = Ready;
|
|
21
|
+
this.emit = (type, ...args) => super.emit(type, this, ...args);
|
|
22
|
+
this.send = async (message) => {
|
|
23
|
+
await this.socket.open();
|
|
24
|
+
if (this.status === Ready) {
|
|
25
|
+
this.sender.push(message);
|
|
77
26
|
}
|
|
78
27
|
};
|
|
28
|
+
this.close = async () => {
|
|
29
|
+
this.status = Closing;
|
|
30
|
+
await this.sender.close();
|
|
31
|
+
await this.socket.close();
|
|
32
|
+
this.status = Closed;
|
|
33
|
+
this.removeAllListeners();
|
|
34
|
+
};
|
|
79
35
|
this.url = url;
|
|
80
|
-
this.socket = new Socket_1.Socket(
|
|
81
|
-
this.sender =
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
36
|
+
this.socket = new Socket_1.Socket(this);
|
|
37
|
+
this.sender = new ConnectionSender_1.ConnectionSender(this);
|
|
38
|
+
this.state = new ConnectionState_1.ConnectionState(this);
|
|
39
|
+
this.stats = new ConnectionStats_1.ConnectionStats(this);
|
|
84
40
|
this.auth = new ConnectionAuth_1.ConnectionAuth(this);
|
|
85
41
|
this.setMaxListeners(100);
|
|
86
42
|
}
|
|
87
|
-
async disconnect() {
|
|
88
|
-
await this.socket.disconnect();
|
|
89
|
-
this.sender.clear();
|
|
90
|
-
this.receiver.clear();
|
|
91
|
-
this.meta.clearPending();
|
|
92
|
-
}
|
|
93
|
-
async destroy() {
|
|
94
|
-
await this.disconnect();
|
|
95
|
-
this.removeAllListeners();
|
|
96
|
-
this.sender.stop();
|
|
97
|
-
this.receiver.stop();
|
|
98
|
-
}
|
|
99
43
|
}
|
|
100
44
|
exports.Connection = Connection;
|
|
101
45
|
//# sourceMappingURL=Connection.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.cjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Connection.cjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AACrC,yCAA+B;AAG/B,2DAAiD;AACjD,2DAAiD;AACjD,yDAA+C;AAC/C,6DAAmD;AAEnD,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,mCAAe,CAAA;IACf,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;AACrB,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B;AAED,MAAM,EAAC,KAAK,EAAE,MAAM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AAA;IAC3B,CAAC;CAqBF;AAxCD,gCAwCC"}
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { Emitter
|
|
2
|
-
import { ConnectionMeta } from './ConnectionMeta';
|
|
3
|
-
import { ConnectionAuth } from './ConnectionAuth';
|
|
1
|
+
import { Emitter } from '@welshman/lib';
|
|
4
2
|
import { Socket } from './Socket';
|
|
5
|
-
import type {
|
|
3
|
+
import type { Message } from './Socket';
|
|
4
|
+
import { ConnectionEvent } from './ConnectionEvent';
|
|
5
|
+
import { ConnectionState } from './ConnectionState';
|
|
6
|
+
import { ConnectionStats } from './ConnectionStats';
|
|
7
|
+
import { ConnectionAuth } from './ConnectionAuth';
|
|
8
|
+
import { ConnectionSender } from './ConnectionSender';
|
|
9
|
+
export declare enum ConnectionStatus {
|
|
10
|
+
Ready = "ready",
|
|
11
|
+
Closed = "Closed",
|
|
12
|
+
Closing = "Closing"
|
|
13
|
+
}
|
|
6
14
|
export declare class Connection extends Emitter {
|
|
7
15
|
url: string;
|
|
8
16
|
socket: Socket;
|
|
9
|
-
sender:
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
sender: ConnectionSender;
|
|
18
|
+
state: ConnectionState;
|
|
19
|
+
stats: ConnectionStats;
|
|
12
20
|
auth: ConnectionAuth;
|
|
21
|
+
status: ConnectionStatus;
|
|
13
22
|
constructor(url: string);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
onOpen: () => boolean;
|
|
18
|
-
onClose: () => boolean;
|
|
19
|
-
onFault: () => boolean;
|
|
20
|
-
onMessage: (m: SocketMessage) => void;
|
|
21
|
-
onSend: (message: SocketMessage) => void;
|
|
22
|
-
onReceive: (message: SocketMessage) => void;
|
|
23
|
-
ensureConnected: ({ shouldReconnect }?: {
|
|
24
|
-
shouldReconnect?: boolean | undefined;
|
|
25
|
-
}) => Promise<void>;
|
|
26
|
-
disconnect(): Promise<void>;
|
|
27
|
-
destroy(): Promise<void>;
|
|
23
|
+
emit: (type: ConnectionEvent, ...args: any[]) => boolean;
|
|
24
|
+
send: (message: Message) => Promise<void>;
|
|
25
|
+
close: () => Promise<void>;
|
|
28
26
|
}
|
package/build/src/Connection.mjs
CHANGED
|
@@ -1,97 +1,41 @@
|
|
|
1
|
-
import { Emitter
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Emitter } from '@welshman/lib';
|
|
2
|
+
import { Socket } from "./Socket.mjs";
|
|
3
|
+
import { ConnectionState } from "./ConnectionState.mjs";
|
|
4
|
+
import { ConnectionStats } from "./ConnectionStats.mjs";
|
|
5
|
+
import { ConnectionAuth } from "./ConnectionAuth.mjs";
|
|
6
|
+
import { ConnectionSender } from "./ConnectionSender.mjs";
|
|
7
|
+
export var ConnectionStatus;
|
|
8
|
+
(function (ConnectionStatus) {
|
|
9
|
+
ConnectionStatus["Ready"] = "ready";
|
|
10
|
+
ConnectionStatus["Closed"] = "Closed";
|
|
11
|
+
ConnectionStatus["Closing"] = "Closing";
|
|
12
|
+
})(ConnectionStatus || (ConnectionStatus = {}));
|
|
13
|
+
const { Ready, Closed, Closing } = ConnectionStatus;
|
|
6
14
|
export class Connection extends Emitter {
|
|
7
15
|
constructor(url) {
|
|
8
16
|
super();
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const [verb, ...extra] = asMessage(message);
|
|
16
|
-
if (verb === 'AUTH') {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
// Only close reqs that have been sent
|
|
20
|
-
if (verb === 'CLOSE') {
|
|
21
|
-
return !this.meta.pendingRequests.has(extra[0]);
|
|
22
|
-
}
|
|
23
|
-
// Allow relay requests through
|
|
24
|
-
if (verb === 'EVENT' && extra[0].kind === AUTH_JOIN) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
// Only defer for auth if we're not multiplexing
|
|
28
|
-
if (isMessage(message) && ![AuthStatus.None, AuthStatus.Ok].includes(this.auth.status)) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
if (verb === 'REQ') {
|
|
32
|
-
return this.meta.pendingRequests.size >= 8;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
worker.addGlobalHandler((message) => {
|
|
38
|
-
// If we ended up handling a CLOSE before we handled the REQ, don't send the REQ
|
|
39
|
-
if (message[0] === 'CLOSE') {
|
|
40
|
-
worker.buffer = worker.buffer.filter(m => !(m[0] === 'REQ' && m[1] === message[1]));
|
|
41
|
-
}
|
|
42
|
-
this.onSend(message);
|
|
43
|
-
});
|
|
44
|
-
return worker;
|
|
45
|
-
};
|
|
46
|
-
this.createReceiver = () => {
|
|
47
|
-
const worker = new Worker();
|
|
48
|
-
worker.addGlobalHandler(this.onReceive);
|
|
49
|
-
return worker;
|
|
50
|
-
};
|
|
51
|
-
this.send = (m) => this.sender.push(m);
|
|
52
|
-
this.onOpen = () => this.emit('open', this);
|
|
53
|
-
this.onClose = () => this.emit('close', this);
|
|
54
|
-
this.onFault = () => this.emit('fault', this);
|
|
55
|
-
this.onMessage = (m) => this.receiver.push(m);
|
|
56
|
-
this.onSend = (message) => {
|
|
57
|
-
this.emit('send', this, message);
|
|
58
|
-
this.socket.send(message);
|
|
59
|
-
};
|
|
60
|
-
this.onReceive = (message) => {
|
|
61
|
-
this.emit('receive', this, message);
|
|
62
|
-
};
|
|
63
|
-
this.ensureConnected = async ({ shouldReconnect = true } = {}) => {
|
|
64
|
-
const isUnhealthy = this.socket.isClosing() || this.socket.isClosed();
|
|
65
|
-
const noRecentFault = this.meta.lastFault < Date.now() - 60000;
|
|
66
|
-
if (shouldReconnect && isUnhealthy && noRecentFault) {
|
|
67
|
-
await this.disconnect();
|
|
68
|
-
}
|
|
69
|
-
if (this.socket.isNew()) {
|
|
70
|
-
await this.socket.connect();
|
|
71
|
-
}
|
|
72
|
-
while (this.socket.isConnecting()) {
|
|
73
|
-
await sleep(100);
|
|
17
|
+
this.status = Ready;
|
|
18
|
+
this.emit = (type, ...args) => super.emit(type, this, ...args);
|
|
19
|
+
this.send = async (message) => {
|
|
20
|
+
await this.socket.open();
|
|
21
|
+
if (this.status === Ready) {
|
|
22
|
+
this.sender.push(message);
|
|
74
23
|
}
|
|
75
24
|
};
|
|
25
|
+
this.close = async () => {
|
|
26
|
+
this.status = Closing;
|
|
27
|
+
await this.sender.close();
|
|
28
|
+
await this.socket.close();
|
|
29
|
+
this.status = Closed;
|
|
30
|
+
this.removeAllListeners();
|
|
31
|
+
};
|
|
76
32
|
this.url = url;
|
|
77
|
-
this.socket = new Socket(
|
|
78
|
-
this.sender = this
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
33
|
+
this.socket = new Socket(this);
|
|
34
|
+
this.sender = new ConnectionSender(this);
|
|
35
|
+
this.state = new ConnectionState(this);
|
|
36
|
+
this.stats = new ConnectionStats(this);
|
|
81
37
|
this.auth = new ConnectionAuth(this);
|
|
82
38
|
this.setMaxListeners(100);
|
|
83
39
|
}
|
|
84
|
-
async disconnect() {
|
|
85
|
-
await this.socket.disconnect();
|
|
86
|
-
this.sender.clear();
|
|
87
|
-
this.receiver.clear();
|
|
88
|
-
this.meta.clearPending();
|
|
89
|
-
}
|
|
90
|
-
async destroy() {
|
|
91
|
-
await this.disconnect();
|
|
92
|
-
this.removeAllListeners();
|
|
93
|
-
this.sender.stop();
|
|
94
|
-
this.receiver.stop();
|
|
95
|
-
}
|
|
96
40
|
}
|
|
97
41
|
//# sourceMappingURL=Connection.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.mjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"Connection.mjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,EAAC,MAAM,eAAe;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AAC,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAA;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAA;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;QACpC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;CAqBF"}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.ConnectionAuth = exports.AuthStatus = exports.AuthMode = void 0;
|
|
10
10
|
const lib_1 = require("@welshman/lib");
|
|
11
11
|
const util_1 = require("@welshman/util");
|
|
12
|
-
const
|
|
12
|
+
const ConnectionEvent_1 = require("./ConnectionEvent.cjs");
|
|
13
13
|
var AuthMode;
|
|
14
14
|
(function (AuthMode) {
|
|
15
15
|
AuthMode["Implicit"] = "implicit";
|
|
@@ -27,11 +27,10 @@ var AuthStatus;
|
|
|
27
27
|
})(AuthStatus || (exports.AuthStatus = AuthStatus = {}));
|
|
28
28
|
const { None, Requested, PendingSignature, DeniedSignature, PendingResponse, Forbidden, Ok, } = AuthStatus;
|
|
29
29
|
class ConnectionAuth {
|
|
30
|
-
constructor(
|
|
31
|
-
this.
|
|
30
|
+
constructor(cxn) {
|
|
31
|
+
this.cxn = cxn;
|
|
32
32
|
this.status = None;
|
|
33
|
-
_ConnectionAuth_onReceive.set(this, (
|
|
34
|
-
const [verb, ...extra] = (0, Socket_1.asMessage)(message);
|
|
33
|
+
_ConnectionAuth_onReceive.set(this, (cxn, [verb, ...extra]) => {
|
|
35
34
|
if (verb === 'OK') {
|
|
36
35
|
const [id, ok, message] = extra;
|
|
37
36
|
if (id === this.request) {
|
|
@@ -45,17 +44,28 @@ class ConnectionAuth {
|
|
|
45
44
|
this.message = undefined;
|
|
46
45
|
this.status = Requested;
|
|
47
46
|
if (lib_1.ctx.net.authMode === AuthMode.Implicit) {
|
|
48
|
-
this.
|
|
47
|
+
this.respond();
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
});
|
|
52
|
-
_ConnectionAuth_onClose.set(this, (
|
|
51
|
+
_ConnectionAuth_onClose.set(this, (cxn) => {
|
|
53
52
|
this.challenge = undefined;
|
|
54
53
|
this.request = undefined;
|
|
55
54
|
this.message = undefined;
|
|
56
55
|
this.status = None;
|
|
57
56
|
});
|
|
58
|
-
this.
|
|
57
|
+
this.waitFor = async (condition, timeout = 300) => {
|
|
58
|
+
const start = Date.now();
|
|
59
|
+
while (Date.now() - timeout <= start) {
|
|
60
|
+
await (0, lib_1.sleep)(100);
|
|
61
|
+
if (condition()) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this.waitForChallenge = async (timeout = 300) => this.waitFor(() => Boolean(this.challenge), timeout);
|
|
67
|
+
this.waitForResolution = async (timeout = 300) => this.waitFor(() => [None, DeniedSignature, Forbidden, Ok].includes(this.status), timeout);
|
|
68
|
+
this.respond = async () => {
|
|
59
69
|
if (!this.challenge) {
|
|
60
70
|
throw new Error("Attempted to authenticate with no challenge");
|
|
61
71
|
}
|
|
@@ -65,53 +75,33 @@ class ConnectionAuth {
|
|
|
65
75
|
this.status = PendingSignature;
|
|
66
76
|
const template = (0, util_1.createEvent)(util_1.CLIENT_AUTH, {
|
|
67
77
|
tags: [
|
|
68
|
-
["relay", this.
|
|
78
|
+
["relay", this.cxn.url],
|
|
69
79
|
["challenge", this.challenge],
|
|
70
80
|
],
|
|
71
81
|
});
|
|
72
82
|
const [event] = await Promise.all([
|
|
73
83
|
lib_1.ctx.net.signEvent(template),
|
|
74
|
-
this.
|
|
84
|
+
this.cxn.socket.open(),
|
|
75
85
|
]);
|
|
76
86
|
if (event) {
|
|
77
87
|
this.request = event.id;
|
|
78
|
-
this.
|
|
88
|
+
this.cxn.send(['AUTH', event]);
|
|
79
89
|
this.status = PendingResponse;
|
|
80
90
|
}
|
|
81
91
|
else {
|
|
82
92
|
this.status = DeniedSignature;
|
|
83
93
|
}
|
|
84
94
|
};
|
|
85
|
-
this.
|
|
95
|
+
this.attempt = async (timeout = 300) => {
|
|
96
|
+
await this.cxn.socket.open();
|
|
97
|
+
await this.waitForChallenge(timeout);
|
|
86
98
|
if (this.status === Requested) {
|
|
87
|
-
await this.
|
|
99
|
+
await this.respond();
|
|
88
100
|
}
|
|
101
|
+
await this.waitForResolution(timeout);
|
|
89
102
|
};
|
|
90
|
-
this.
|
|
91
|
-
|
|
92
|
-
while (Date.now() < deadline) {
|
|
93
|
-
await (0, lib_1.sleep)(100);
|
|
94
|
-
// State got reset while we were waiting
|
|
95
|
-
if ([None, Requested].includes(this.status)) {
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
// We've completed the auth flow
|
|
99
|
-
if ([DeniedSignature, Forbidden, Ok].includes(this.status)) {
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
this.waitIfPending = async ({ timeout = 3000 } = {}) => {
|
|
105
|
-
while ([PendingSignature, PendingResponse].includes(this.status)) {
|
|
106
|
-
await this.wait({ timeout });
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
this.destroy = () => {
|
|
110
|
-
this.connection.off('receive', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
111
|
-
this.connection.off('close', __classPrivateFieldGet(this, _ConnectionAuth_onClose, "f"));
|
|
112
|
-
};
|
|
113
|
-
this.connection.on('receive', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
114
|
-
this.connection.on('close', __classPrivateFieldGet(this, _ConnectionAuth_onClose, "f"));
|
|
103
|
+
this.cxn.on(ConnectionEvent_1.ConnectionEvent.Close, __classPrivateFieldGet(this, _ConnectionAuth_onClose, "f"));
|
|
104
|
+
this.cxn.on(ConnectionEvent_1.ConnectionEvent.Receive, __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
exports.ConnectionAuth = ConnectionAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionAuth.cjs","sourceRoot":"","sources":["../../src/ConnectionAuth.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAwC;AACxC,yCAAuD;
|
|
1
|
+
{"version":3,"file":"ConnectionAuth.cjs","sourceRoot":"","sources":["../../src/ConnectionAuth.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAwC;AACxC,yCAAuD;AACvD,2DAAiD;AAIjD,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;AACvB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAED,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,qCAAuB,CAAA;IACvB,oDAAsC,CAAA;IACtC,kDAAoC,CAAA;IACpC,kDAAoC,CAAA;IACpC,qCAAuB,CAAA;IACvB,uBAAS,CAAA;AACX,CAAC,EARW,UAAU,0BAAV,UAAU,QAQrB;AAED,MAAM,EACJ,IAAI,EACJ,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,SAAS,EACT,EAAE,GACH,GAAG,UAAU,CAAA;AAEd,MAAa,cAAc;IAMzB,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAFpC,WAAM,GAAG,IAAI,CAAA;QAOb,oCAAa,CAAC,GAAe,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAU,EAAE,EAAE;YAC1D,IAAI,IAAI,KAAK,IAAI,EAAE;gBACjB,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,KAAK,CAAA;gBAE/B,IAAI,EAAE,KAAK,IAAI,CAAC,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B;iBAAM;gBACL,IAAI,CAAC,MAAM,GAAG,eAAe,CAAA;aAC9B;QACH,CAAC,CAAA;QAED,YAAO,GAAG,KAAK,EAAE,OAAO,GAAG,GAAG,EAAE,EAAE;YAChC,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;YAC5B,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;YAEpC,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;gBAC7B,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;aACrB;YAED,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;QACvC,CAAC,CAAA;QA5FC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,iCAAe,CAAC,KAAK,EAAE,uBAAA,IAAI,+BAAS,CAAC,CAAA;QACjD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,iCAAe,CAAC,OAAO,EAAE,uBAAA,IAAI,iCAAW,CAAC,CAAA;IACvD,CAAC;CA2FF;AApGD,wCAoGC"}
|
|
@@ -14,19 +14,15 @@ export declare enum AuthStatus {
|
|
|
14
14
|
}
|
|
15
15
|
export declare class ConnectionAuth {
|
|
16
16
|
#private;
|
|
17
|
-
readonly
|
|
17
|
+
readonly cxn: Connection;
|
|
18
18
|
challenge: string | undefined;
|
|
19
19
|
request: string | undefined;
|
|
20
20
|
message: string | undefined;
|
|
21
21
|
status: AuthStatus;
|
|
22
|
-
constructor(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
waitIfPending: ({ timeout }?: {
|
|
29
|
-
timeout?: number | undefined;
|
|
30
|
-
}) => Promise<void>;
|
|
31
|
-
destroy: () => void;
|
|
22
|
+
constructor(cxn: Connection);
|
|
23
|
+
waitFor: (condition: () => boolean, timeout?: number) => Promise<void>;
|
|
24
|
+
waitForChallenge: (timeout?: number) => Promise<void>;
|
|
25
|
+
waitForResolution: (timeout?: number) => Promise<void>;
|
|
26
|
+
respond: () => Promise<void>;
|
|
27
|
+
attempt: (timeout?: number) => Promise<void>;
|
|
32
28
|
}
|
|
@@ -6,7 +6,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
6
6
|
var _ConnectionAuth_onReceive, _ConnectionAuth_onClose;
|
|
7
7
|
import { ctx, sleep } from '@welshman/lib';
|
|
8
8
|
import { CLIENT_AUTH, createEvent } from '@welshman/util';
|
|
9
|
-
import {
|
|
9
|
+
import { ConnectionEvent } from "./ConnectionEvent.mjs";
|
|
10
10
|
export var AuthMode;
|
|
11
11
|
(function (AuthMode) {
|
|
12
12
|
AuthMode["Implicit"] = "implicit";
|
|
@@ -24,11 +24,10 @@ export var AuthStatus;
|
|
|
24
24
|
})(AuthStatus || (AuthStatus = {}));
|
|
25
25
|
const { None, Requested, PendingSignature, DeniedSignature, PendingResponse, Forbidden, Ok, } = AuthStatus;
|
|
26
26
|
export class ConnectionAuth {
|
|
27
|
-
constructor(
|
|
28
|
-
this.
|
|
27
|
+
constructor(cxn) {
|
|
28
|
+
this.cxn = cxn;
|
|
29
29
|
this.status = None;
|
|
30
|
-
_ConnectionAuth_onReceive.set(this, (
|
|
31
|
-
const [verb, ...extra] = asMessage(message);
|
|
30
|
+
_ConnectionAuth_onReceive.set(this, (cxn, [verb, ...extra]) => {
|
|
32
31
|
if (verb === 'OK') {
|
|
33
32
|
const [id, ok, message] = extra;
|
|
34
33
|
if (id === this.request) {
|
|
@@ -42,17 +41,28 @@ export class ConnectionAuth {
|
|
|
42
41
|
this.message = undefined;
|
|
43
42
|
this.status = Requested;
|
|
44
43
|
if (ctx.net.authMode === AuthMode.Implicit) {
|
|
45
|
-
this.
|
|
44
|
+
this.respond();
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
});
|
|
49
|
-
_ConnectionAuth_onClose.set(this, (
|
|
48
|
+
_ConnectionAuth_onClose.set(this, (cxn) => {
|
|
50
49
|
this.challenge = undefined;
|
|
51
50
|
this.request = undefined;
|
|
52
51
|
this.message = undefined;
|
|
53
52
|
this.status = None;
|
|
54
53
|
});
|
|
55
|
-
this.
|
|
54
|
+
this.waitFor = async (condition, timeout = 300) => {
|
|
55
|
+
const start = Date.now();
|
|
56
|
+
while (Date.now() - timeout <= start) {
|
|
57
|
+
await sleep(100);
|
|
58
|
+
if (condition()) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
this.waitForChallenge = async (timeout = 300) => this.waitFor(() => Boolean(this.challenge), timeout);
|
|
64
|
+
this.waitForResolution = async (timeout = 300) => this.waitFor(() => [None, DeniedSignature, Forbidden, Ok].includes(this.status), timeout);
|
|
65
|
+
this.respond = async () => {
|
|
56
66
|
if (!this.challenge) {
|
|
57
67
|
throw new Error("Attempted to authenticate with no challenge");
|
|
58
68
|
}
|
|
@@ -62,53 +72,33 @@ export class ConnectionAuth {
|
|
|
62
72
|
this.status = PendingSignature;
|
|
63
73
|
const template = createEvent(CLIENT_AUTH, {
|
|
64
74
|
tags: [
|
|
65
|
-
["relay", this.
|
|
75
|
+
["relay", this.cxn.url],
|
|
66
76
|
["challenge", this.challenge],
|
|
67
77
|
],
|
|
68
78
|
});
|
|
69
79
|
const [event] = await Promise.all([
|
|
70
80
|
ctx.net.signEvent(template),
|
|
71
|
-
this.
|
|
81
|
+
this.cxn.socket.open(),
|
|
72
82
|
]);
|
|
73
83
|
if (event) {
|
|
74
84
|
this.request = event.id;
|
|
75
|
-
this.
|
|
85
|
+
this.cxn.send(['AUTH', event]);
|
|
76
86
|
this.status = PendingResponse;
|
|
77
87
|
}
|
|
78
88
|
else {
|
|
79
89
|
this.status = DeniedSignature;
|
|
80
90
|
}
|
|
81
91
|
};
|
|
82
|
-
this.
|
|
92
|
+
this.attempt = async (timeout = 300) => {
|
|
93
|
+
await this.cxn.socket.open();
|
|
94
|
+
await this.waitForChallenge(timeout);
|
|
83
95
|
if (this.status === Requested) {
|
|
84
|
-
await this.
|
|
96
|
+
await this.respond();
|
|
85
97
|
}
|
|
98
|
+
await this.waitForResolution(timeout);
|
|
86
99
|
};
|
|
87
|
-
this.
|
|
88
|
-
|
|
89
|
-
while (Date.now() < deadline) {
|
|
90
|
-
await sleep(100);
|
|
91
|
-
// State got reset while we were waiting
|
|
92
|
-
if ([None, Requested].includes(this.status)) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
// We've completed the auth flow
|
|
96
|
-
if ([DeniedSignature, Forbidden, Ok].includes(this.status)) {
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this.waitIfPending = async ({ timeout = 3000 } = {}) => {
|
|
102
|
-
while ([PendingSignature, PendingResponse].includes(this.status)) {
|
|
103
|
-
await this.wait({ timeout });
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
this.destroy = () => {
|
|
107
|
-
this.connection.off('receive', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
108
|
-
this.connection.off('close', __classPrivateFieldGet(this, _ConnectionAuth_onClose, "f"));
|
|
109
|
-
};
|
|
110
|
-
this.connection.on('receive', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
111
|
-
this.connection.on('close', __classPrivateFieldGet(this, _ConnectionAuth_onClose, "f"));
|
|
100
|
+
this.cxn.on(ConnectionEvent.Close, __classPrivateFieldGet(this, _ConnectionAuth_onClose, "f"));
|
|
101
|
+
this.cxn.on(ConnectionEvent.Receive, __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
112
102
|
}
|
|
113
103
|
}
|
|
114
104
|
_ConnectionAuth_onReceive = new WeakMap(), _ConnectionAuth_onClose = new WeakMap();
|