asyx 0.0.2 → 0.1.1
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/LICENSE +67 -0
- package/README.md +125 -17
- package/SECURITY.md +40 -0
- package/bin/asyx.js +2 -0
- package/package.json +75 -18
- package/src/commands/.gitkeep +0 -0
- package/src/commands/mqtt-broker.js +56 -0
- package/src/commands/mqtt.js +164 -0
- package/src/commands/setup.js +137 -0
- package/src/commands/sts.js +73 -0
- package/src/commands/tunnel.js +540 -0
- package/src/lib/.gitkeep +0 -0
- package/src/lib/certs.js +25 -0
- package/src/lib/csr.js +185 -0
- package/src/lib/device.js +18 -0
- package/src/lib/fingerprint.js +115 -0
- package/src/lib/ids.js +5 -0
- package/src/lib/logger.js +58 -0
- package/src/lib/pairing.js +15 -0
- package/src/lib/shared-transport.js +15 -0
- package/src/main.js +57 -0
- package/src/mqtt/awaiter-map.js +157 -0
- package/src/mqtt/events/handlers.js +90 -0
- package/src/mqtt/events/index.js +14 -0
- package/src/mqtt/events/schemas.js +58 -0
- package/src/mqtt/ingress.js +172 -0
- package/src/state/assignment.js +156 -0
- package/src/tunnel/http-tunnel.js +1131 -0
- package/src/tunnel/ws-control.js +135 -0
- package/index.js +0 -13
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-REAUTH: WebSocket Control Frame Helper
|
|
3
|
+
* Manages control frame communication with relay for in-band reauth
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Global waiter registry: op -> Set<{ resolve, reject, timer }>
|
|
7
|
+
const controlWaiters = new Map();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CLI-REAUTH: Dispatch incoming control frames to waiting promises
|
|
11
|
+
* Called from WebSocket message handler when a text frame matches control pattern
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} frame - Parsed JSON control frame (must have 'op' field)
|
|
14
|
+
*/
|
|
15
|
+
export function dispatchControlFrame(frame) {
|
|
16
|
+
if (!frame || typeof frame !== 'object' || !frame.op) {
|
|
17
|
+
return false; // Not a control frame
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const waiters = controlWaiters.get(frame.op);
|
|
21
|
+
if (!waiters || waiters.size === 0) {
|
|
22
|
+
return false; // No waiters for this op
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Resolve all waiters for this op and remove them
|
|
26
|
+
const resolvedWaiters = Array.from(waiters);
|
|
27
|
+
controlWaiters.delete(frame.op);
|
|
28
|
+
|
|
29
|
+
for (const waiter of resolvedWaiters) {
|
|
30
|
+
clearTimeout(waiter.timer);
|
|
31
|
+
try {
|
|
32
|
+
waiter.resolve(frame);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
// Ignore resolution errors
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return true; // Frame was dispatched
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* CLI-REAUTH: Cleanup all waiters (call on socket close to prevent leaks)
|
|
43
|
+
* Rejects all pending waiters to ensure promises settle and don't linger in microtask queue
|
|
44
|
+
*/
|
|
45
|
+
export function clearAllWaiters() {
|
|
46
|
+
for (const [, waiters] of controlWaiters) {
|
|
47
|
+
for (const waiter of waiters) {
|
|
48
|
+
clearTimeout(waiter.timer);
|
|
49
|
+
try {
|
|
50
|
+
// Reject the promise - tests should await these to prevent unhandled rejections
|
|
51
|
+
waiter.reject(new Error('WebSocket closed before control frame received'));
|
|
52
|
+
} catch {
|
|
53
|
+
// Ignore rejection errors (promise already settled)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
controlWaiters.clear();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* CLI-REAUTH: Send control frame and wait for acknowledgment
|
|
62
|
+
*
|
|
63
|
+
* @param {WebSocket} ws - WebSocket connection
|
|
64
|
+
* @param {string} payloadJson - Serialized JSON payload to send
|
|
65
|
+
* @param {string} expectedOp - Expected 'op' value in response (e.g., 'reauth_ack')
|
|
66
|
+
* @param {number} timeoutMs - Timeout in milliseconds (default 3000)
|
|
67
|
+
* @returns {Promise<Object>} Resolves with parsed control frame, or {status:'error', error:'timeout'} on timeout
|
|
68
|
+
*/
|
|
69
|
+
export function sendControlAndWaitAck(ws, payloadJson, expectedOp, timeoutMs = 3000) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
// Validate inputs
|
|
72
|
+
if (!ws || ws.readyState !== 1) { // WebSocket.OPEN = 1
|
|
73
|
+
resolve({ status: 'error', error: 'socket_not_open' });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!payloadJson || typeof payloadJson !== 'string') {
|
|
78
|
+
resolve({ status: 'error', error: 'invalid_payload' });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!expectedOp || typeof expectedOp !== 'string') {
|
|
83
|
+
resolve({ status: 'error', error: 'invalid_expected_op' });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Set up timeout
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
// Remove from registry
|
|
90
|
+
const waiters = controlWaiters.get(expectedOp);
|
|
91
|
+
if (waiters) {
|
|
92
|
+
waiters.delete(waiter);
|
|
93
|
+
if (waiters.size === 0) {
|
|
94
|
+
controlWaiters.delete(expectedOp);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
resolve({ status: 'error', error: 'timeout' });
|
|
98
|
+
}, timeoutMs);
|
|
99
|
+
|
|
100
|
+
// Create waiter
|
|
101
|
+
const waiter = {
|
|
102
|
+
resolve: (frame) => {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
resolve(frame);
|
|
105
|
+
},
|
|
106
|
+
reject: (error) => {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
reject(error);
|
|
109
|
+
},
|
|
110
|
+
timer
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Register waiter
|
|
114
|
+
if (!controlWaiters.has(expectedOp)) {
|
|
115
|
+
controlWaiters.set(expectedOp, new Set());
|
|
116
|
+
}
|
|
117
|
+
controlWaiters.get(expectedOp).add(waiter);
|
|
118
|
+
|
|
119
|
+
// Send control frame
|
|
120
|
+
try {
|
|
121
|
+
ws.send(payloadJson);
|
|
122
|
+
} catch (sendError) {
|
|
123
|
+
// Clean up waiter on send failure
|
|
124
|
+
const waiters = controlWaiters.get(expectedOp);
|
|
125
|
+
if (waiters) {
|
|
126
|
+
waiters.delete(waiter);
|
|
127
|
+
if (waiters.size === 0) {
|
|
128
|
+
controlWaiters.delete(expectedOp);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
resolve({ status: 'error', error: 'send_failed', message: sendError.message });
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
package/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Simple CLI placeholder for the Asyx platform
|
|
4
|
-
console.log(`
|
|
5
|
-
🚀 Asyx CLI
|
|
6
|
-
-----------------------
|
|
7
|
-
Secure access for everyone.
|
|
8
|
-
This is a placeholder CLI for the future full fledged client capaibility.
|
|
9
|
-
|
|
10
|
-
Coming soon:
|
|
11
|
-
• asyx tunnel open --port 3000
|
|
12
|
-
• asyx quickpass generate --user email@example.com
|
|
13
|
-
`);
|