@welshman/net 0.0.25 → 0.0.27
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 +6 -16
- package/build/src/Connection.cjs.map +1 -1
- package/build/src/Connection.d.ts +3 -4
- package/build/src/Connection.mjs +7 -17
- package/build/src/Connection.mjs.map +1 -1
- package/build/src/ConnectionAuth.cjs +111 -0
- package/build/src/ConnectionAuth.cjs.map +1 -0
- package/build/src/ConnectionAuth.d.ts +32 -0
- package/build/src/ConnectionAuth.mjs +107 -0
- package/build/src/ConnectionAuth.mjs.map +1 -0
- package/build/src/ConnectionMeta.cjs +10 -36
- package/build/src/ConnectionMeta.cjs.map +1 -1
- package/build/src/ConnectionMeta.d.ts +2 -11
- package/build/src/ConnectionMeta.mjs +9 -35
- package/build/src/ConnectionMeta.mjs.map +1 -1
- package/build/src/Context.cjs +4 -3
- package/build/src/Context.cjs.map +1 -1
- package/build/src/Context.d.ts +8 -7
- package/build/src/Context.mjs +4 -3
- package/build/src/Context.mjs.map +1 -1
- package/build/src/Executor.cjs +0 -2
- package/build/src/Executor.cjs.map +1 -1
- package/build/src/Executor.mjs +0 -2
- package/build/src/Executor.mjs.map +1 -1
- package/build/src/Subscribe.cjs +1 -1
- package/build/src/Subscribe.cjs.map +1 -1
- package/build/src/Subscribe.mjs +1 -1
- package/build/src/Subscribe.mjs.map +1 -1
- package/build/src/Tracker.cjs +22 -17
- package/build/src/Tracker.cjs.map +1 -1
- package/build/src/Tracker.d.ts +5 -3
- package/build/src/Tracker.mjs +23 -18
- package/build/src/Tracker.mjs.map +1 -1
- package/build/src/index.cjs +1 -0
- package/build/src/index.cjs.map +1 -1
- package/build/src/index.d.ts +1 -0
- package/build/src/index.mjs +1 -0
- package/package.json +2 -2
package/build/src/Connection.cjs
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Connection = void 0;
|
|
4
4
|
const lib_1 = require("@welshman/lib");
|
|
5
5
|
const ConnectionMeta_1 = require("./ConnectionMeta.cjs");
|
|
6
|
+
const ConnectionAuth_1 = require("./ConnectionAuth.cjs");
|
|
6
7
|
const Socket_1 = require("./Socket.cjs");
|
|
7
8
|
class Connection extends lib_1.Emitter {
|
|
8
9
|
constructor(url) {
|
|
@@ -26,7 +27,7 @@ class Connection extends lib_1.Emitter {
|
|
|
26
27
|
return false;
|
|
27
28
|
}
|
|
28
29
|
// Only defer for auth if we're not multiplexing
|
|
29
|
-
if ((0, Socket_1.isMessage)(message) && ![
|
|
30
|
+
if ((0, Socket_1.isMessage)(message) && ![ConnectionAuth_1.AuthStatus.None, ConnectionAuth_1.AuthStatus.Ok].includes(this.auth.status)) {
|
|
30
31
|
return true;
|
|
31
32
|
}
|
|
32
33
|
if (verb === 'REQ') {
|
|
@@ -61,7 +62,7 @@ class Connection extends lib_1.Emitter {
|
|
|
61
62
|
this.onReceive = (message) => {
|
|
62
63
|
this.emit('receive', this, message);
|
|
63
64
|
};
|
|
64
|
-
this.ensureConnected = async ({ shouldReconnect = true }) => {
|
|
65
|
+
this.ensureConnected = async ({ shouldReconnect = true } = {}) => {
|
|
65
66
|
const isUnhealthy = this.socket.isClosing() || this.socket.isClosed();
|
|
66
67
|
const noRecentFault = this.meta.lastFault < Date.now() - 60000;
|
|
67
68
|
if (shouldReconnect && isUnhealthy && noRecentFault) {
|
|
@@ -70,20 +71,8 @@ class Connection extends lib_1.Emitter {
|
|
|
70
71
|
if (this.socket.isNew()) {
|
|
71
72
|
await this.socket.connect();
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
await this.ensureConnected({ shouldReconnect: true });
|
|
76
|
-
if (this.meta.authStatus === ConnectionMeta_1.AuthStatus.Pending) {
|
|
77
|
-
await Promise.race([
|
|
78
|
-
(0, lib_1.sleep)(timeout),
|
|
79
|
-
new Promise(resolve => {
|
|
80
|
-
this.on('receive', (cxn, message) => {
|
|
81
|
-
if (message[0] === 'OK' && message[2]) {
|
|
82
|
-
resolve();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
})
|
|
86
|
-
]);
|
|
74
|
+
while (this.socket.isConnecting()) {
|
|
75
|
+
await (0, lib_1.sleep)(100);
|
|
87
76
|
}
|
|
88
77
|
};
|
|
89
78
|
this.url = url;
|
|
@@ -91,6 +80,7 @@ class Connection extends lib_1.Emitter {
|
|
|
91
80
|
this.sender = this.createSender();
|
|
92
81
|
this.receiver = this.createReceiver();
|
|
93
82
|
this.meta = new ConnectionMeta_1.ConnectionMeta(this);
|
|
83
|
+
this.auth = new ConnectionAuth_1.ConnectionAuth(this);
|
|
94
84
|
this.setMaxListeners(100);
|
|
95
85
|
}
|
|
96
86
|
disconnect() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.cjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AACpD,yDAA2D;AAC3D,yCAAqD;AAGrD,MAAa,UAAW,SAAQ,aAAO;
|
|
1
|
+
{"version":3,"file":"Connection.cjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AACpD,yDAA+C;AAC/C,yDAA2D;AAC3D,yCAAqD;AAGrD,MAAa,UAAW,SAAQ,aAAO;IAQrC,YAAY,GAAW;QACrB,KAAK,EAAE,CAAA;QAWT,iBAAY,GAAG,GAAG,EAAE;YAClB,MAAM,MAAM,GAAG,IAAI,YAAM,CAAgB;gBACvC,WAAW,EAAE,CAAC,OAAsB,EAAE,EAAE;oBACtC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE;wBACzB,OAAO,IAAI,CAAA;qBACZ;oBAED,MAAM,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,IAAA,kBAAS,EAAC,OAAO,CAAC,CAAA;oBAE3C,IAAI,IAAI,KAAK,MAAM,EAAE;wBACnB,OAAO,KAAK,CA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@
|
|
|
1
1
|
import { Emitter, Worker } from '@welshman/lib';
|
|
2
2
|
import { ConnectionMeta } from './ConnectionMeta';
|
|
3
|
+
import { ConnectionAuth } from './ConnectionAuth';
|
|
3
4
|
import { Socket } from './Socket';
|
|
4
5
|
import type { SocketMessage } from './Socket';
|
|
5
6
|
export declare class Connection extends Emitter {
|
|
@@ -8,6 +9,7 @@ export declare class Connection extends Emitter {
|
|
|
8
9
|
sender: Worker<SocketMessage>;
|
|
9
10
|
receiver: Worker<SocketMessage>;
|
|
10
11
|
meta: ConnectionMeta;
|
|
12
|
+
auth: ConnectionAuth;
|
|
11
13
|
constructor(url: string);
|
|
12
14
|
createSender: () => Worker<SocketMessage>;
|
|
13
15
|
createReceiver: () => Worker<SocketMessage>;
|
|
@@ -18,12 +20,9 @@ export declare class Connection extends Emitter {
|
|
|
18
20
|
onMessage: (m: SocketMessage) => void;
|
|
19
21
|
onSend: (message: SocketMessage) => void;
|
|
20
22
|
onReceive: (message: SocketMessage) => void;
|
|
21
|
-
ensureConnected: ({ shouldReconnect }
|
|
23
|
+
ensureConnected: ({ shouldReconnect }?: {
|
|
22
24
|
shouldReconnect?: boolean | undefined;
|
|
23
25
|
}) => Promise<void>;
|
|
24
|
-
ensureAuth: ({ timeout }: {
|
|
25
|
-
timeout?: number | undefined;
|
|
26
|
-
}) => Promise<void>;
|
|
27
26
|
disconnect(): void;
|
|
28
27
|
destroy(): void;
|
|
29
28
|
}
|
package/build/src/Connection.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Emitter, Worker, sleep } from '@welshman/lib';
|
|
2
|
-
import {
|
|
2
|
+
import { ConnectionMeta } from "./ConnectionMeta.mjs";
|
|
3
|
+
import { ConnectionAuth, AuthStatus } from "./ConnectionAuth.mjs";
|
|
3
4
|
import { Socket, isMessage, asMessage } from "./Socket.mjs";
|
|
4
5
|
export class Connection extends Emitter {
|
|
5
6
|
constructor(url) {
|
|
@@ -23,7 +24,7 @@ export class Connection extends Emitter {
|
|
|
23
24
|
return false;
|
|
24
25
|
}
|
|
25
26
|
// Only defer for auth if we're not multiplexing
|
|
26
|
-
if (isMessage(message) && ![AuthStatus.
|
|
27
|
+
if (isMessage(message) && ![AuthStatus.None, AuthStatus.Ok].includes(this.auth.status)) {
|
|
27
28
|
return true;
|
|
28
29
|
}
|
|
29
30
|
if (verb === 'REQ') {
|
|
@@ -58,7 +59,7 @@ export class Connection extends Emitter {
|
|
|
58
59
|
this.onReceive = (message) => {
|
|
59
60
|
this.emit('receive', this, message);
|
|
60
61
|
};
|
|
61
|
-
this.ensureConnected = async ({ shouldReconnect = true }) => {
|
|
62
|
+
this.ensureConnected = async ({ shouldReconnect = true } = {}) => {
|
|
62
63
|
const isUnhealthy = this.socket.isClosing() || this.socket.isClosed();
|
|
63
64
|
const noRecentFault = this.meta.lastFault < Date.now() - 60000;
|
|
64
65
|
if (shouldReconnect && isUnhealthy && noRecentFault) {
|
|
@@ -67,20 +68,8 @@ export class Connection extends Emitter {
|
|
|
67
68
|
if (this.socket.isNew()) {
|
|
68
69
|
await this.socket.connect();
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
await this.ensureConnected({ shouldReconnect: true });
|
|
73
|
-
if (this.meta.authStatus === AuthStatus.Pending) {
|
|
74
|
-
await Promise.race([
|
|
75
|
-
sleep(timeout),
|
|
76
|
-
new Promise(resolve => {
|
|
77
|
-
this.on('receive', (cxn, message) => {
|
|
78
|
-
if (message[0] === 'OK' && message[2]) {
|
|
79
|
-
resolve();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
})
|
|
83
|
-
]);
|
|
71
|
+
while (this.socket.isConnecting()) {
|
|
72
|
+
await sleep(100);
|
|
84
73
|
}
|
|
85
74
|
};
|
|
86
75
|
this.url = url;
|
|
@@ -88,6 +77,7 @@ export class Connection extends Emitter {
|
|
|
88
77
|
this.sender = this.createSender();
|
|
89
78
|
this.receiver = this.createReceiver();
|
|
90
79
|
this.meta = new ConnectionMeta(this);
|
|
80
|
+
this.auth = new ConnectionAuth(this);
|
|
91
81
|
this.setMaxListeners(100);
|
|
92
82
|
}
|
|
93
83
|
disconnect() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.mjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAC,MAAM,eAAe;OAC7C,EAAC,
|
|
1
|
+
{"version":3,"file":"Connection.mjs","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAC,MAAM,eAAe;OAC7C,EAAC,cAAc,EAAC;OAChB,EAAC,cAAc,EAAE,UAAU,EAAC;OAC5B,EAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAC;AAGrC,MAAM,OAAO,UAAW,SAAQ,OAAO;IAQrC,YAAY,GAAW;QACrB,KAAK,EAAE,CAAA;QAWT,iBAAY,GAAG,GAAG,EAAE;YAClB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAgB;gBACvC,WAAW,EAAE,CAAC,OAAsB,EAAE,EAAE;oBACtC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE;wBACzB,OAAO,IAAI,CAAA;qBACZ;oBAED,MAAM,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;oBAE3C,IAAI,IAAI,KAAK,MAAM,EAAE;wBACnB,OAAO,KAAK,CAAA;qBACb;oBAED,sCAAsC;oBACtC,IAAI,IAAI,KAAK,OAAO,EAAE;wBACpB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;qBAChD;oBAED,+BAA+B;oBAC/B,IAAI,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,K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MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;aACjB;QACH,CAAC,CAAA;QAnGC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;QACpC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IA8FD,UAAU;QACR,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACnB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,IAAI,CAAC,UAAU,EAAE,CAAA;QACjB,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;QAClB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _ConnectionAuth_onReceive;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ConnectionAuth = exports.AuthStatus = exports.AuthMode = void 0;
|
|
10
|
+
const lib_1 = require("@welshman/lib");
|
|
11
|
+
const util_1 = require("@welshman/util");
|
|
12
|
+
const Socket_1 = require("./Socket.cjs");
|
|
13
|
+
var AuthMode;
|
|
14
|
+
(function (AuthMode) {
|
|
15
|
+
AuthMode["Implicit"] = "implicit";
|
|
16
|
+
AuthMode["Explicit"] = "explicit";
|
|
17
|
+
})(AuthMode || (exports.AuthMode = AuthMode = {}));
|
|
18
|
+
var AuthStatus;
|
|
19
|
+
(function (AuthStatus) {
|
|
20
|
+
AuthStatus["None"] = "none";
|
|
21
|
+
AuthStatus["Requested"] = "requested";
|
|
22
|
+
AuthStatus["PendingSignature"] = "pending_signature";
|
|
23
|
+
AuthStatus["DeniedSignature"] = "denied_signature";
|
|
24
|
+
AuthStatus["PendingResponse"] = "pending_response";
|
|
25
|
+
AuthStatus["Forbidden"] = "forbidden";
|
|
26
|
+
AuthStatus["Ok"] = "ok";
|
|
27
|
+
})(AuthStatus || (exports.AuthStatus = AuthStatus = {}));
|
|
28
|
+
const { None, Requested, PendingSignature, DeniedSignature, PendingResponse, Forbidden, Ok, } = AuthStatus;
|
|
29
|
+
class ConnectionAuth {
|
|
30
|
+
constructor(connection) {
|
|
31
|
+
this.connection = connection;
|
|
32
|
+
this.status = None;
|
|
33
|
+
_ConnectionAuth_onReceive.set(this, (connection, message) => {
|
|
34
|
+
const [verb, ...extra] = (0, Socket_1.asMessage)(message);
|
|
35
|
+
if (verb === 'OK') {
|
|
36
|
+
const [id, ok, message] = extra;
|
|
37
|
+
if (id === this.request) {
|
|
38
|
+
this.challenge = undefined;
|
|
39
|
+
this.request = undefined;
|
|
40
|
+
this.message = message;
|
|
41
|
+
this.status = ok ? Ok : Forbidden;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (verb === 'AUTH' && extra[0] !== this.challenge) {
|
|
45
|
+
this.challenge = extra[0];
|
|
46
|
+
this.request = undefined;
|
|
47
|
+
this.message = undefined;
|
|
48
|
+
this.status = Requested;
|
|
49
|
+
if (lib_1.ctx.net.authMode === AuthMode.Implicit) {
|
|
50
|
+
this.attempt();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this.attempt = async () => {
|
|
55
|
+
if (!this.challenge) {
|
|
56
|
+
throw new Error("Attempted to authenticate with no challenge");
|
|
57
|
+
}
|
|
58
|
+
if (this.status !== Requested) {
|
|
59
|
+
throw new Error(`Attempted to authenticate when auth is already ${this.status}`);
|
|
60
|
+
}
|
|
61
|
+
this.status = PendingSignature;
|
|
62
|
+
const template = (0, util_1.createEvent)(util_1.CLIENT_AUTH, {
|
|
63
|
+
tags: [
|
|
64
|
+
["relay", this.connection.url],
|
|
65
|
+
["challenge", this.challenge],
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
const [event] = await Promise.all([
|
|
69
|
+
lib_1.ctx.net.signEvent(template),
|
|
70
|
+
this.connection.ensureConnected(),
|
|
71
|
+
]);
|
|
72
|
+
if (event) {
|
|
73
|
+
this.request = event.id;
|
|
74
|
+
this.connection.send(['AUTH', event]);
|
|
75
|
+
this.status = PendingResponse;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.status = DeniedSignature;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
this.attemptIfRequested = async () => {
|
|
82
|
+
if (this.status === Requested) {
|
|
83
|
+
await this.attempt();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
this.wait = async ({ timeout = 3000 } = {}) => {
|
|
87
|
+
const deadline = Date.now() + timeout;
|
|
88
|
+
while (Date.now() < deadline) {
|
|
89
|
+
await (0, lib_1.sleep)(100);
|
|
90
|
+
if ([None, Requested].includes(this.status)) {
|
|
91
|
+
throw new Error("Auth flow reset while waiting for auth");
|
|
92
|
+
}
|
|
93
|
+
if ([DeniedSignature, Forbidden, Ok].includes(this.status)) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
this.waitIfPending = async ({ timeout = 3000 } = {}) => {
|
|
99
|
+
if ([PendingSignature, PendingResponse].includes(this.status)) {
|
|
100
|
+
await this.wait({ timeout });
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
this.destroy = () => {
|
|
104
|
+
this.connection.off('recieve', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
105
|
+
};
|
|
106
|
+
this.connection.on('receive', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.ConnectionAuth = ConnectionAuth;
|
|
110
|
+
_ConnectionAuth_onReceive = new WeakMap();
|
|
111
|
+
//# sourceMappingURL=ConnectionAuth.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionAuth.cjs","sourceRoot":"","sources":["../../src/ConnectionAuth.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAwC;AACxC,yCAAuD;AAGvD,yCAAkC;AAElC,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;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I,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;oBAC3C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;iBAC1D;gBAED,IAAI,CAAC,eAAe,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;oBAC1D,MAAK;iBACN;aACF;QACH,CAAC,CAAA;QAED,kBAAa,GAAG,KAAK,EAAE,EAAC,OAAO,GAAG,IAAI,KAAwB,EAAE,EAAE,EAAE;YAClE,IAAI,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;gBAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,EAAC,OAAO,EAAC,CAAC,CAAA;aAC3B;QACH,CAAC,CAAA;QAED,YAAO,GAAG,GAAG,EAAE;YACb,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,uBAAA,IAAI,iCAAW,CAAC,CAAA;QACjD,CAAC,CAAA;QA3FC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,uBAAA,IAAI,iCAAW,CAAC,CAAA;IAChD,CAAC;CA2FF;AAnGD,wCAmGC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Connection } from './Connection';
|
|
2
|
+
export declare enum AuthMode {
|
|
3
|
+
Implicit = "implicit",
|
|
4
|
+
Explicit = "explicit"
|
|
5
|
+
}
|
|
6
|
+
export declare enum AuthStatus {
|
|
7
|
+
None = "none",
|
|
8
|
+
Requested = "requested",
|
|
9
|
+
PendingSignature = "pending_signature",
|
|
10
|
+
DeniedSignature = "denied_signature",
|
|
11
|
+
PendingResponse = "pending_response",
|
|
12
|
+
Forbidden = "forbidden",
|
|
13
|
+
Ok = "ok"
|
|
14
|
+
}
|
|
15
|
+
export declare class ConnectionAuth {
|
|
16
|
+
#private;
|
|
17
|
+
readonly connection: Connection;
|
|
18
|
+
challenge: string | undefined;
|
|
19
|
+
request: string | undefined;
|
|
20
|
+
message: string | undefined;
|
|
21
|
+
status: AuthStatus;
|
|
22
|
+
constructor(connection: Connection);
|
|
23
|
+
attempt: () => Promise<void>;
|
|
24
|
+
attemptIfRequested: () => Promise<void>;
|
|
25
|
+
wait: ({ timeout }?: {
|
|
26
|
+
timeout?: number | undefined;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
waitIfPending: ({ timeout }?: {
|
|
29
|
+
timeout?: number | undefined;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
destroy: () => void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _ConnectionAuth_onReceive;
|
|
7
|
+
import { ctx, sleep } from '@welshman/lib';
|
|
8
|
+
import { CLIENT_AUTH, createEvent } from '@welshman/util';
|
|
9
|
+
import { asMessage } from "./Socket.mjs";
|
|
10
|
+
export var AuthMode;
|
|
11
|
+
(function (AuthMode) {
|
|
12
|
+
AuthMode["Implicit"] = "implicit";
|
|
13
|
+
AuthMode["Explicit"] = "explicit";
|
|
14
|
+
})(AuthMode || (AuthMode = {}));
|
|
15
|
+
export var AuthStatus;
|
|
16
|
+
(function (AuthStatus) {
|
|
17
|
+
AuthStatus["None"] = "none";
|
|
18
|
+
AuthStatus["Requested"] = "requested";
|
|
19
|
+
AuthStatus["PendingSignature"] = "pending_signature";
|
|
20
|
+
AuthStatus["DeniedSignature"] = "denied_signature";
|
|
21
|
+
AuthStatus["PendingResponse"] = "pending_response";
|
|
22
|
+
AuthStatus["Forbidden"] = "forbidden";
|
|
23
|
+
AuthStatus["Ok"] = "ok";
|
|
24
|
+
})(AuthStatus || (AuthStatus = {}));
|
|
25
|
+
const { None, Requested, PendingSignature, DeniedSignature, PendingResponse, Forbidden, Ok, } = AuthStatus;
|
|
26
|
+
export class ConnectionAuth {
|
|
27
|
+
constructor(connection) {
|
|
28
|
+
this.connection = connection;
|
|
29
|
+
this.status = None;
|
|
30
|
+
_ConnectionAuth_onReceive.set(this, (connection, message) => {
|
|
31
|
+
const [verb, ...extra] = asMessage(message);
|
|
32
|
+
if (verb === 'OK') {
|
|
33
|
+
const [id, ok, message] = extra;
|
|
34
|
+
if (id === this.request) {
|
|
35
|
+
this.challenge = undefined;
|
|
36
|
+
this.request = undefined;
|
|
37
|
+
this.message = message;
|
|
38
|
+
this.status = ok ? Ok : Forbidden;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (verb === 'AUTH' && extra[0] !== this.challenge) {
|
|
42
|
+
this.challenge = extra[0];
|
|
43
|
+
this.request = undefined;
|
|
44
|
+
this.message = undefined;
|
|
45
|
+
this.status = Requested;
|
|
46
|
+
if (ctx.net.authMode === AuthMode.Implicit) {
|
|
47
|
+
this.attempt();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
this.attempt = async () => {
|
|
52
|
+
if (!this.challenge) {
|
|
53
|
+
throw new Error("Attempted to authenticate with no challenge");
|
|
54
|
+
}
|
|
55
|
+
if (this.status !== Requested) {
|
|
56
|
+
throw new Error(`Attempted to authenticate when auth is already ${this.status}`);
|
|
57
|
+
}
|
|
58
|
+
this.status = PendingSignature;
|
|
59
|
+
const template = createEvent(CLIENT_AUTH, {
|
|
60
|
+
tags: [
|
|
61
|
+
["relay", this.connection.url],
|
|
62
|
+
["challenge", this.challenge],
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
const [event] = await Promise.all([
|
|
66
|
+
ctx.net.signEvent(template),
|
|
67
|
+
this.connection.ensureConnected(),
|
|
68
|
+
]);
|
|
69
|
+
if (event) {
|
|
70
|
+
this.request = event.id;
|
|
71
|
+
this.connection.send(['AUTH', event]);
|
|
72
|
+
this.status = PendingResponse;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.status = DeniedSignature;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
this.attemptIfRequested = async () => {
|
|
79
|
+
if (this.status === Requested) {
|
|
80
|
+
await this.attempt();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
this.wait = async ({ timeout = 3000 } = {}) => {
|
|
84
|
+
const deadline = Date.now() + timeout;
|
|
85
|
+
while (Date.now() < deadline) {
|
|
86
|
+
await sleep(100);
|
|
87
|
+
if ([None, Requested].includes(this.status)) {
|
|
88
|
+
throw new Error("Auth flow reset while waiting for auth");
|
|
89
|
+
}
|
|
90
|
+
if ([DeniedSignature, Forbidden, Ok].includes(this.status)) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
this.waitIfPending = async ({ timeout = 3000 } = {}) => {
|
|
96
|
+
if ([PendingSignature, PendingResponse].includes(this.status)) {
|
|
97
|
+
await this.wait({ timeout });
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
this.destroy = () => {
|
|
101
|
+
this.connection.off('recieve', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
102
|
+
};
|
|
103
|
+
this.connection.on('receive', __classPrivateFieldGet(this, _ConnectionAuth_onReceive, "f"));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
_ConnectionAuth_onReceive = new WeakMap();
|
|
107
|
+
//# sourceMappingURL=ConnectionAuth.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionAuth.mjs","sourceRoot":"","sources":["../../src/ConnectionAuth.ts"],"names":[],"mappings":";;;;;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AS,EAAE,uBAAA,IAAI,iCAAW,CAAC,CAAA;QACjD,CAAC,CAAA;QA3FC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,uBAAA,IAAI,iCAAW,CAAC,CAAA;IAChD,CAAC;CA2FF"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConnectionMeta = exports.ConnectionStatus =
|
|
4
|
-
var AuthStatus;
|
|
5
|
-
(function (AuthStatus) {
|
|
6
|
-
AuthStatus["Ok"] = "ok";
|
|
7
|
-
AuthStatus["Pending"] = "pending";
|
|
8
|
-
AuthStatus["Unauthorized"] = "unauthorized";
|
|
9
|
-
AuthStatus["Forbidden"] = "forbidden";
|
|
10
|
-
})(AuthStatus || (exports.AuthStatus = AuthStatus = {}));
|
|
3
|
+
exports.ConnectionMeta = exports.ConnectionStatus = void 0;
|
|
11
4
|
var ConnectionStatus;
|
|
12
5
|
(function (ConnectionStatus) {
|
|
13
|
-
ConnectionStatus["Unauthorized"] = "unauthorized";
|
|
14
|
-
ConnectionStatus["Forbidden"] = "forbidden";
|
|
15
6
|
ConnectionStatus["Error"] = "error";
|
|
16
7
|
ConnectionStatus["Closed"] = "closed";
|
|
17
8
|
ConnectionStatus["Slow"] = "slow";
|
|
@@ -20,7 +11,6 @@ var ConnectionStatus;
|
|
|
20
11
|
class ConnectionMeta {
|
|
21
12
|
constructor(cxn) {
|
|
22
13
|
this.cxn = cxn;
|
|
23
|
-
this.authStatus = AuthStatus.Pending;
|
|
24
14
|
this.pendingPublishes = new Map();
|
|
25
15
|
this.pendingRequests = new Map();
|
|
26
16
|
this.publishCount = 0;
|
|
@@ -32,6 +22,7 @@ class ConnectionMeta {
|
|
|
32
22
|
this.lastPublish = 0;
|
|
33
23
|
this.lastRequest = 0;
|
|
34
24
|
this.lastEvent = 0;
|
|
25
|
+
this.lastAuth = 0;
|
|
35
26
|
this.responseCount = 0;
|
|
36
27
|
this.responseTimer = 0;
|
|
37
28
|
this.clearPending = () => {
|
|
@@ -41,30 +32,16 @@ class ConnectionMeta {
|
|
|
41
32
|
this.getSpeed = () => this.responseCount ? this.responseTimer / this.responseCount : 0;
|
|
42
33
|
this.getStatus = () => {
|
|
43
34
|
const socket = this.cxn.socket;
|
|
44
|
-
if (this.authStatus === AuthStatus.Unauthorized)
|
|
45
|
-
return ConnectionStatus.Unauthorized;
|
|
46
|
-
if (this.authStatus === AuthStatus.Forbidden)
|
|
47
|
-
return ConnectionStatus.Forbidden;
|
|
48
35
|
if (socket.isNew())
|
|
49
36
|
return ConnectionStatus.Closed;
|
|
50
37
|
if (this.lastFault && this.lastFault > this.lastOpen)
|
|
51
38
|
return ConnectionStatus.Error;
|
|
52
39
|
if (socket.isClosed() || socket.isClosing())
|
|
53
40
|
return ConnectionStatus.Closed;
|
|
54
|
-
if (this.getSpeed() >
|
|
41
|
+
if (this.getSpeed() > 2000)
|
|
55
42
|
return ConnectionStatus.Slow;
|
|
56
43
|
return ConnectionStatus.Ok;
|
|
57
44
|
};
|
|
58
|
-
this.getDescription = () => {
|
|
59
|
-
switch (this.getStatus()) {
|
|
60
|
-
case ConnectionStatus.Unauthorized: return 'Logging in';
|
|
61
|
-
case ConnectionStatus.Forbidden: return 'Failed to log in';
|
|
62
|
-
case ConnectionStatus.Error: return 'Failed to connect';
|
|
63
|
-
case ConnectionStatus.Closed: return 'Waiting to reconnect';
|
|
64
|
-
case ConnectionStatus.Slow: return 'Slow Connection';
|
|
65
|
-
case ConnectionStatus.Ok: return 'Connected';
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
45
|
cxn.on('open', () => {
|
|
69
46
|
this.lastOpen = Date.now();
|
|
70
47
|
});
|
|
@@ -115,25 +92,22 @@ class ConnectionMeta {
|
|
|
115
92
|
this.pendingPublishes.set(event.id, { sent: Date.now(), event });
|
|
116
93
|
}
|
|
117
94
|
onReceiveOk([verb, eventId, ok, notice]) {
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
this.authStatus = AuthStatus.Ok;
|
|
121
|
-
}
|
|
122
|
-
else if (notice === null || notice === void 0 ? void 0 : notice.startsWith('auth-required:')) {
|
|
123
|
-
// Re-enqueue pending events when auth challenge is received
|
|
95
|
+
// Re-enqueue pending events when auth challenge is received
|
|
96
|
+
if (notice === null || notice === void 0 ? void 0 : notice.startsWith('auth-required:')) {
|
|
124
97
|
const pub = this.pendingPublishes.get(eventId);
|
|
125
98
|
if (pub) {
|
|
126
99
|
this.cxn.send(['EVENT', pub.event]);
|
|
127
100
|
}
|
|
128
101
|
}
|
|
102
|
+
const publish = this.pendingPublishes.get(eventId);
|
|
129
103
|
if (publish) {
|
|
130
104
|
this.responseCount++;
|
|
131
105
|
this.responseTimer += Date.now() - publish.sent;
|
|
132
106
|
this.pendingPublishes.delete(eventId);
|
|
133
107
|
}
|
|
134
108
|
}
|
|
135
|
-
onReceiveAuth(
|
|
136
|
-
this.
|
|
109
|
+
onReceiveAuth(message) {
|
|
110
|
+
this.lastAuth = Date.now();
|
|
137
111
|
}
|
|
138
112
|
onReceiveEvent([verb, event]) {
|
|
139
113
|
this.eventCount++;
|
|
@@ -149,8 +123,8 @@ class ConnectionMeta {
|
|
|
149
123
|
}
|
|
150
124
|
}
|
|
151
125
|
onReceiveClosed([verb, id, notice]) {
|
|
152
|
-
|
|
153
|
-
|
|
126
|
+
// Re-enqueue pending reqs when auth challenge is received
|
|
127
|
+
if (notice === null || notice === void 0 ? void 0 : notice.startsWith('auth-required:')) {
|
|
154
128
|
const req = this.pendingRequests.get(id);
|
|
155
129
|
if (req) {
|
|
156
130
|
this.cxn.send(['REQ', id, ...req.filters]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionMeta.cjs","sourceRoot":"","sources":["../../src/ConnectionMeta.ts"],"names":[],"mappings":";;;AAeA,IAAY,
|
|
1
|
+
{"version":3,"file":"ConnectionMeta.cjs","sourceRoot":"","sources":["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,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;YACpC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAA;YAE3B,IAAI,CAAC,aAAa,EAAE,CAAA;YACpB,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAA;SAChD;IACH,CAAC;IAED,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAU;QACzC,0DAA0D;QAC1D,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAC,gBAAgB,CAAC,EAAE;YACxC,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YAExC,IAAI,GAAG,EAAE;gBACP,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;aAC3C;SACF;IACH,CAAC;IAED,eAAe,CAAC,CAAC,IAAI,EAAE,MAAM,CAAU;QACrC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC9C,CAAC;CAmBF;AAzID,wCAyIC"}
|
|
@@ -10,15 +10,7 @@ export type RequestMeta = {
|
|
|
10
10
|
filters: Filter[];
|
|
11
11
|
eoseReceived: boolean;
|
|
12
12
|
};
|
|
13
|
-
export declare enum AuthStatus {
|
|
14
|
-
Ok = "ok",
|
|
15
|
-
Pending = "pending",
|
|
16
|
-
Unauthorized = "unauthorized",
|
|
17
|
-
Forbidden = "forbidden"
|
|
18
|
-
}
|
|
19
13
|
export declare enum ConnectionStatus {
|
|
20
|
-
Unauthorized = "unauthorized",
|
|
21
|
-
Forbidden = "forbidden",
|
|
22
14
|
Error = "error",
|
|
23
15
|
Closed = "closed",
|
|
24
16
|
Slow = "slow",
|
|
@@ -26,7 +18,6 @@ export declare enum ConnectionStatus {
|
|
|
26
18
|
}
|
|
27
19
|
export declare class ConnectionMeta {
|
|
28
20
|
readonly cxn: Connection;
|
|
29
|
-
authStatus: AuthStatus;
|
|
30
21
|
pendingPublishes: Map<string, PublishMeta>;
|
|
31
22
|
pendingRequests: Map<string, RequestMeta>;
|
|
32
23
|
publishCount: number;
|
|
@@ -38,6 +29,7 @@ export declare class ConnectionMeta {
|
|
|
38
29
|
lastPublish: number;
|
|
39
30
|
lastRequest: number;
|
|
40
31
|
lastEvent: number;
|
|
32
|
+
lastAuth: number;
|
|
41
33
|
responseCount: number;
|
|
42
34
|
responseTimer: number;
|
|
43
35
|
constructor(cxn: Connection);
|
|
@@ -45,7 +37,7 @@ export declare class ConnectionMeta {
|
|
|
45
37
|
onSendClose([verb, subId]: Message): void;
|
|
46
38
|
onSendEvent([verb, event]: Message): void;
|
|
47
39
|
onReceiveOk([verb, eventId, ok, notice]: Message): void;
|
|
48
|
-
onReceiveAuth(
|
|
40
|
+
onReceiveAuth(message: Message): void;
|
|
49
41
|
onReceiveEvent([verb, event]: Message): void;
|
|
50
42
|
onReceiveEose([verb, subId]: Message): void;
|
|
51
43
|
onReceiveClosed([verb, id, notice]: Message): void;
|
|
@@ -53,5 +45,4 @@ export declare class ConnectionMeta {
|
|
|
53
45
|
clearPending: () => void;
|
|
54
46
|
getSpeed: () => number;
|
|
55
47
|
getStatus: () => ConnectionStatus;
|
|
56
|
-
getDescription: () => "Logging in" | "Failed to log in" | "Failed to connect" | "Waiting to reconnect" | "Slow Connection" | "Connected";
|
|
57
48
|
}
|