asyx 0.10.0 → 0.11.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.
Files changed (93) hide show
  1. package/AGENTS.md +42 -0
  2. package/bin/asyx.js +1 -1
  3. package/package.json +6 -3
  4. package/src/commands/account.js +80 -71
  5. package/src/commands/app.js +317 -151
  6. package/src/commands/in-use-messages.js +47 -48
  7. package/src/commands/mqtt-broker.js +36 -49
  8. package/src/commands/mqtt.js +111 -149
  9. package/src/commands/name.js +24 -22
  10. package/src/commands/reject-messages.js +123 -123
  11. package/src/commands/setup.js +107 -131
  12. package/src/commands/sts.js +45 -61
  13. package/src/commands/tunnel.js +853 -931
  14. package/src/commands/validate-target-host.js +36 -59
  15. package/src/lib/aws-iot-config.js +30 -0
  16. package/src/lib/certs.js +15 -18
  17. package/src/lib/csr.js +107 -182
  18. package/src/lib/device.js +26 -37
  19. package/src/lib/ids.js +1 -2
  20. package/src/lib/naming.js +74 -68
  21. package/src/lib/pairing.js +10 -11
  22. package/src/lib/shared-transport.js +5 -9
  23. package/src/main.js +63 -53
  24. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.js +25 -287
  25. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.js +0 -72
  26. package/vendor/tunnel-core/dist/control-plane/session.js +0 -20
  27. package/vendor/tunnel-core/dist/errors.js +0 -19
  28. package/vendor/tunnel-core/dist/flows/account.js +1 -6
  29. package/vendor/tunnel-core/dist/flows/goodbye.js +0 -4
  30. package/vendor/tunnel-core/dist/flows/http.js +24 -112
  31. package/vendor/tunnel-core/dist/flows/identity.js +11 -10
  32. package/vendor/tunnel-core/dist/flows/in-use.js +0 -6
  33. package/vendor/tunnel-core/dist/flows/reopen.js +0 -4
  34. package/vendor/tunnel-core/dist/flows/tcp.js +18 -84
  35. package/vendor/tunnel-core/dist/flows/udp.js +15 -52
  36. package/vendor/tunnel-core/dist/lib/fingerprint.js +38 -42
  37. package/vendor/tunnel-core/dist/lib/jwt-verifier.js +14 -67
  38. package/vendor/tunnel-core/dist/lib/logger.js +1 -9
  39. package/vendor/tunnel-core/dist/lib/refresh-helpers.js +1 -22
  40. package/vendor/tunnel-core/dist/lifecycle.js +1 -8
  41. package/vendor/tunnel-core/dist/mqtt/awaiter-map.js +1 -53
  42. package/vendor/tunnel-core/dist/mqtt/events/handlers.js +10 -64
  43. package/vendor/tunnel-core/dist/mqtt/events/index.js +3 -36
  44. package/vendor/tunnel-core/dist/mqtt/events/schemas.js +0 -1
  45. package/vendor/tunnel-core/dist/mqtt/ingress.js +0 -60
  46. package/vendor/tunnel-core/dist/state/assignment.js +6 -122
  47. package/vendor/tunnel-core/dist/state/instance-registry.js +0 -63
  48. package/vendor/tunnel-core/dist/tcp-v1/framing.js +2 -64
  49. package/vendor/tunnel-core/dist/tunnel/http-tunnel.js +64 -331
  50. package/vendor/tunnel-core/dist/tunnel/httpws-constants.js +5 -14
  51. package/vendor/tunnel-core/dist/tunnel/reconnect.js +10 -50
  52. package/vendor/tunnel-core/dist/tunnel/request-sink.js +0 -16
  53. package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.js +32 -195
  54. package/vendor/tunnel-core/dist/tunnel/udp-tunnel.js +28 -153
  55. package/vendor/tunnel-core/dist/tunnel/ws-control.js +4 -39
  56. package/vendor/tunnel-core/dist/types.js +0 -2
  57. package/vendor/tunnel-core/dist/udp-v1/framing.js +2 -64
  58. package/vendor/tunnel-core/package.json +0 -25
  59. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.d.ts +0 -273
  60. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.d.ts +0 -79
  61. package/vendor/tunnel-core/dist/control-plane/session.d.ts +0 -55
  62. package/vendor/tunnel-core/dist/errors.d.ts +0 -49
  63. package/vendor/tunnel-core/dist/flows/account.d.ts +0 -24
  64. package/vendor/tunnel-core/dist/flows/goodbye.d.ts +0 -10
  65. package/vendor/tunnel-core/dist/flows/http.d.ts +0 -61
  66. package/vendor/tunnel-core/dist/flows/identity.d.ts +0 -23
  67. package/vendor/tunnel-core/dist/flows/in-use.d.ts +0 -27
  68. package/vendor/tunnel-core/dist/flows/reopen.d.ts +0 -9
  69. package/vendor/tunnel-core/dist/flows/tcp.d.ts +0 -85
  70. package/vendor/tunnel-core/dist/flows/udp.d.ts +0 -52
  71. package/vendor/tunnel-core/dist/lib/adapt-logger.d.ts +0 -2
  72. package/vendor/tunnel-core/dist/lib/fingerprint.d.ts +0 -145
  73. package/vendor/tunnel-core/dist/lib/jwt-verifier.d.ts +0 -27
  74. package/vendor/tunnel-core/dist/lib/logger.d.ts +0 -9
  75. package/vendor/tunnel-core/dist/lib/refresh-helpers.d.ts +0 -16
  76. package/vendor/tunnel-core/dist/lifecycle.d.ts +0 -24
  77. package/vendor/tunnel-core/dist/mqtt/awaiter-map.d.ts +0 -56
  78. package/vendor/tunnel-core/dist/mqtt/events/handlers.d.ts +0 -60
  79. package/vendor/tunnel-core/dist/mqtt/events/index.d.ts +0 -1
  80. package/vendor/tunnel-core/dist/mqtt/events/schemas.d.ts +0 -498
  81. package/vendor/tunnel-core/dist/mqtt/ingress.d.ts +0 -63
  82. package/vendor/tunnel-core/dist/state/assignment.d.ts +0 -136
  83. package/vendor/tunnel-core/dist/state/instance-registry.d.ts +0 -88
  84. package/vendor/tunnel-core/dist/tcp-v1/framing.d.ts +0 -43
  85. package/vendor/tunnel-core/dist/tunnel/http-tunnel.d.ts +0 -140
  86. package/vendor/tunnel-core/dist/tunnel/httpws-constants.d.ts +0 -13
  87. package/vendor/tunnel-core/dist/tunnel/reconnect.d.ts +0 -76
  88. package/vendor/tunnel-core/dist/tunnel/request-sink.d.ts +0 -40
  89. package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.d.ts +0 -92
  90. package/vendor/tunnel-core/dist/tunnel/udp-tunnel.d.ts +0 -93
  91. package/vendor/tunnel-core/dist/tunnel/ws-control.d.ts +0 -22
  92. package/vendor/tunnel-core/dist/types.d.ts +0 -24
  93. package/vendor/tunnel-core/dist/udp-v1/framing.d.ts +0 -41
@@ -1,136 +0,0 @@
1
- /**
2
- * Set assignment for a specific tunnel instance
3
- * TPB-12: Per-instance assignment storage to prevent cross-wiring
4
- * @param {string} instanceId - Tunnel instance ID (full MQTT clientId)
5
- * @param {Object} assignment - Assignment data
6
- * @param {string} assignment.requestId - Request ID
7
- * @param {string} assignment.relayId - Relay ID
8
- * @param {string} assignment.relayUrl - Relay URL
9
- * @param {string} assignment.jwt - JWT token (stored in memory only)
10
- * @param {number} assignment.leaseMs - Lease duration in milliseconds
11
- * @param {string} assignment.leaseId - Lease ID for JWT refresh (optional)
12
- * @param {string} [assignment.quickpassSlug]
13
- * @param {string} [assignment.tcpAliasFqdn]
14
- * @param {number} [assignment.publicPort]
15
- * @param {string} [assignment.fqdn]
16
- * @param {boolean} [assignment.srvProvisioned]
17
- * @param {string} [assignment.srvFqdn]
18
- * @param {unknown[]} [assignment.warnings]
19
- * @param {string} [assignment.tunnelMode]
20
- * @param {string} [assignment.protocol]
21
- * @param {string} [assignment.assignmentJwt]
22
- * @param {{ port: number, kind: string, from: string, to: string }} [assignment.portMoved] Story 2.11 c3
23
- */
24
- export function setAssignment(instanceId: string, assignment: {
25
- requestId: string;
26
- relayId: string;
27
- relayUrl: string;
28
- jwt: string;
29
- leaseMs: number;
30
- leaseId: string;
31
- quickpassSlug?: string;
32
- tcpAliasFqdn?: string;
33
- publicPort?: number;
34
- fqdn?: string;
35
- srvProvisioned?: boolean;
36
- srvFqdn?: string;
37
- warnings?: unknown[];
38
- tunnelMode?: string;
39
- protocol?: string;
40
- assignmentJwt?: string;
41
- portMoved?: {
42
- port: number;
43
- kind: string;
44
- from: string;
45
- to: string;
46
- };
47
- }): void;
48
- /**
49
- * Get assignment for a specific tunnel instance
50
- * TPB-12: Per-instance assignment retrieval
51
- * @param {string} instanceId - Tunnel instance ID (full MQTT clientId)
52
- * @returns {Object|null} Assignment for the instance or null if none set
53
- */
54
- export function getAssignment(instanceId: string): any | null;
55
- /**
56
- * Resolve instanceId from leaseId
57
- * TPB-12: Helper to route events that only have leaseId
58
- * @param {string} leaseId - Lease ID
59
- * @returns {string|null} Instance ID or null if not found
60
- */
61
- export function resolveInstanceByLease(leaseId: string): string | null;
62
- /**
63
- * Clear assignment for a specific tunnel instance
64
- * TPB-12: Per-instance assignment clearing
65
- * @param {string} instanceId - Tunnel instance ID (full MQTT clientId)
66
- */
67
- export function clearAssignment(instanceId: string): void;
68
- /**
69
- * Drop one instance key without touching a lease mapping that already points elsewhere.
70
- * Does not reject assignment waiters.
71
- * @param {string} instanceId
72
- */
73
- export function forgetInstanceAssignment(instanceId: string): void;
74
- /**
75
- * Copy an assignment onto a new instance id and drop the old key.
76
- * When a tunnel object is passed, its instanceId moves with the assignment.
77
- * @param {{ oldId: string, newId: string, tunnel?: { instanceId?: string } | null }} opts
78
- * @returns {{ moved: boolean, leaseId: string | null, size: number }}
79
- */
80
- export function migrateInstanceAssignment({ oldId, newId, tunnel }?: {
81
- oldId: string;
82
- newId: string;
83
- tunnel?: {
84
- instanceId?: string;
85
- } | null;
86
- }): {
87
- moved: boolean;
88
- leaseId: string | null;
89
- size: number;
90
- };
91
- /**
92
- * Assignment stored for this instance after a refresh ack.
93
- * Throws when the keyed entry is missing or the JWT has no exp.
94
- * @param {string} instanceId
95
- * @returns {{ assignment: Object, expMs: number }}
96
- */
97
- export function readRefreshAssignment(instanceId: string): {
98
- assignment: any;
99
- expMs: number;
100
- };
101
- /**
102
- * Check if an assignment exists for a specific tunnel instance
103
- * TPB-12: Per-instance assignment check
104
- * @param {string} instanceId - Tunnel instance ID (full MQTT clientId)
105
- * @returns {boolean} True if assignment exists for the instance
106
- */
107
- export function hasAssignment(instanceId: string): boolean;
108
- /**
109
- * Wait until an assignment with the specified requestId is available.
110
- * @param {string} requestId - Request ID to wait for
111
- * @param {number} [timeoutMs=10000] - Timeout before rejecting
112
- * @returns {Promise<Object>} resolves with the assignment snapshot
113
- */
114
- export function waitForAssignment(requestId: string, timeoutMs?: number): Promise<any>;
115
- /**
116
- * Story 1.9: fail the open waiting for requestId with `error` (e.g. address_in_use), so the flow can
117
- * decide to wait and ask again instead of timing out. Returns true when someone was waiting.
118
- * @param {string} requestId
119
- * @param {Error} error
120
- */
121
- export function rejectAssignment(requestId: string, error: Error): boolean;
122
- /**
123
- * Get assignment metadata (without JWT for logging)
124
- * TPB-12: Per-instance metadata retrieval
125
- * @param {string} instanceId - Tunnel instance ID (full MQTT clientId)
126
- * @returns {Object|null} Assignment metadata or null
127
- */
128
- export function getAssignmentMetadata(instanceId: string): any | null;
129
- /**
130
- * Record a successful refresh in the assignment cache and return delta ms since last refresh (or since initial assignment if none).
131
- * TPB-12: Per-instance refresh recording
132
- * @param {string} instanceId - Tunnel instance ID (full MQTT clientId)
133
- * @param {number} [nowMs]
134
- * @returns {number} delta milliseconds since last refresh or initial assignment
135
- */
136
- export function recordRefresh(instanceId: string, nowMs?: number): number;
@@ -1,88 +0,0 @@
1
- /**
2
- * Register a tunnel instance
3
- * @param {string} instanceId - Full MQTT clientId (instanceId)
4
- * @param {Object} context - Instance context
5
- * @param {string} context.tunnelType - Tunnel type ('http' | 'tcp' | 'udp')
6
- * @param {Function} context.setAssignment - Per-instance setAssignment callback
7
- * @param {Function} context.getAssignment - Per-instance getAssignment callback
8
- * @param {Object} [context.metadata] - Additional metadata
9
- */
10
- export function registerInstance(instanceId: string, context: {
11
- tunnelType: string;
12
- setAssignment: Function;
13
- getAssignment: Function;
14
- metadata?: any;
15
- }): void;
16
- /**
17
- * Unregister a tunnel instance
18
- * @param {string} instanceId - Full MQTT clientId (instanceId)
19
- */
20
- export function unregisterInstance(instanceId: string): void;
21
- /**
22
- * Get instance context by instanceId
23
- * @param {string} instanceId - Full MQTT clientId (instanceId)
24
- * @returns {InstanceContext|null} Instance context or null if not found
25
- */
26
- export function getInstance(instanceId: string): InstanceContext | null;
27
- /**
28
- * Get all registered instances (for debugging)
29
- * @returns {Array<InstanceContext>} Array of all instance contexts
30
- */
31
- export function getAllInstances(): Array<InstanceContext>;
32
- /**
33
- * Set expected requestId for an instance (for pre-assignment routing)
34
- * TPB-12: Track requestId before assignment exists so open_ack can be routed
35
- *
36
- * Note: This automatically clears any previous requestId for this instance,
37
- * so reconnect/retry flows that use a new requestId are handled correctly.
38
- *
39
- * @param {string} instanceId - Full MQTT clientId (instanceId)
40
- * @param {string} requestId - Expected requestId from cmd/open
41
- */
42
- export function setExpectedRequestId(instanceId: string, requestId: string): void;
43
- /**
44
- * Clear expected requestId for an instance (called after assignment is created)
45
- * TPB-12: Clean up requestId mapping once assignment exists (routing uses leaseId after that)
46
- * @param {string} instanceId - Full MQTT clientId (instanceId)
47
- */
48
- export function clearExpectedRequestId(instanceId: string): void;
49
- /**
50
- * Resolve instanceId from requestId (for pre-assignment routing)
51
- * TPB-12: Route open_ack events by requestId before assignment exists
52
- * @param {string} requestId - Request ID from cmd/open
53
- * @returns {string|null} Instance ID or null if not found
54
- */
55
- export function resolveInstanceByRequestId(requestId: string): string | null;
56
- /**
57
- * Clear all instances (for cleanup/testing)
58
- */
59
- export function clearAll(): void;
60
- /**
61
- * Instance context for a tunnel instance
62
- */
63
- export type InstanceContext = {
64
- /**
65
- * - Full MQTT clientId (instanceId)
66
- */
67
- instanceId: string;
68
- /**
69
- * - Tunnel type ('http' | 'tcp' | 'udp')
70
- */
71
- tunnelType: string;
72
- /**
73
- * - Per-instance setAssignment callback
74
- */
75
- setAssignment: Function;
76
- /**
77
- * - Per-instance getAssignment callback
78
- */
79
- getAssignment: Function;
80
- /**
81
- * - Additional metadata (baseClientId, etc.)
82
- */
83
- metadata?: any;
84
- /**
85
- * - Expected requestId for initial open_ack routing
86
- */
87
- expectedRequestId?: string;
88
- };
@@ -1,43 +0,0 @@
1
- /**
2
- * Encode a frame to binary format
3
- * @param {Object} frame - Frame object with type, streamId, and payload
4
- * @param {number} frame.type - Frame type (FrameType constant)
5
- * @param {number} frame.streamId - Stream ID (24-bit, 0 for PING/PONG)
6
- * @param {Buffer|Uint8Array} frame.payload - Frame payload (max 64 KiB)
7
- * @returns {Buffer} Encoded frame
8
- * @throws {TcpV1FramingError} If frame is invalid
9
- */
10
- export function encodeFrame(frame: {
11
- type: number;
12
- streamId: number;
13
- payload: Buffer | Uint8Array;
14
- }): Buffer;
15
- /**
16
- * Decode a frame from binary format
17
- * @param {Buffer|Uint8Array} data - Binary frame data
18
- * @param {number} [offset=0] - Offset to start reading from
19
- * @returns {Object} Decoded frame object with type, streamId, payload, and consumed bytes
20
- * @throws {TcpV1FramingError} If frame is invalid
21
- */
22
- export function decodeFrame(data: Buffer | Uint8Array, offset?: number): any;
23
- /**
24
- * Validate a frame for protocol violations
25
- * @param {Object} frame - Frame object to validate
26
- * @returns {void}
27
- * @throws {TcpV1FramingError} If frame is invalid
28
- */
29
- export function validateFrame(frame: any): void;
30
- export namespace FrameType {
31
- let STREAM_OPEN: number;
32
- let STREAM_DATA: number;
33
- let STREAM_CLOSE: number;
34
- let STREAM_ERROR: number;
35
- let PING: number;
36
- let PONG: number;
37
- }
38
- export const MAX_FRAME_PAYLOAD: number;
39
- export const FRAME_HEADER_SIZE: 9;
40
- export class TcpV1FramingError extends Error {
41
- constructor(message: any, code: any);
42
- code: any;
43
- }
@@ -1,140 +0,0 @@
1
- export const LOCAL_UNAVAILABLE_PAGE: "<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Service not reachable</title></head><body style=\"font-family:system-ui,sans-serif;max-width:32rem;margin:4rem auto;padding:0 1rem;color:#334155\"><h1 style=\"font-size:1.4rem;color:#0f172a\">This service is not reachable right now</h1><p>The tunnel is up, but the app behind it is not answering. It may be restarting; try again in a moment.</p></body></html>";
2
- export class HttpTunnel {
3
- constructor({ relayUrl, jwt, deviceId, requestId, localPort, log, coordinatorCore, coordinatorIngress, isControlPlaneConnected, waitForControlPlane, getLastMqttError, getForceReconnect, controlPlaneTimeoutMs, secGroupSlug, instanceId, onFatal, onNotice, onLeaseClosed, requestSink, }: {
4
- relayUrl: any;
5
- jwt: any;
6
- deviceId: any;
7
- requestId: any;
8
- localPort: any;
9
- log: any;
10
- coordinatorCore: any;
11
- coordinatorIngress: any;
12
- isControlPlaneConnected?: () => boolean;
13
- waitForControlPlane?: () => Promise<void>;
14
- getLastMqttError?: () => any;
15
- getForceReconnect?: () => any;
16
- controlPlaneTimeoutMs?: number;
17
- secGroupSlug?: any;
18
- instanceId?: any;
19
- onFatal?: any;
20
- onNotice?: any;
21
- onLeaseClosed?: any;
22
- requestSink?: any;
23
- });
24
- requestSink: any;
25
- onFatal: any;
26
- onLeaseClosed: any;
27
- onNotice: any;
28
- relayUrl: any;
29
- jwt: any;
30
- deviceId: any;
31
- requestId: any;
32
- localPort: any;
33
- log: any;
34
- ws: WebSocket;
35
- secGroupSlug: any;
36
- instanceId: any;
37
- coordinatorCore: any;
38
- coordinatorIngress: any;
39
- isControlPlaneConnected: () => boolean;
40
- waitForControlPlane: () => Promise<void>;
41
- getLastMqttError: () => any;
42
- getForceReconnect: () => any;
43
- controlPlaneTimeoutMs: number;
44
- heartbeatTimer: NodeJS.Timeout;
45
- lastActivityMs: number;
46
- shouldReconnect: boolean;
47
- retryCount: number;
48
- maxRetries: number;
49
- reconnectTimer: any;
50
- headers: {
51
- Authorization: string;
52
- 'X-Asyx-DeviceId': any;
53
- 'X-Asyx-RequestId': any;
54
- } | {
55
- Authorization: string;
56
- 'X-Asyx-DeviceId': any;
57
- 'X-Asyx-RequestId': any;
58
- } | {
59
- Authorization: string;
60
- 'X-Asyx-DeviceId': any;
61
- 'X-Asyx-RequestId': any;
62
- } | {
63
- Authorization: string;
64
- 'X-Asyx-DeviceId': any;
65
- 'X-Asyx-RequestId': any;
66
- } | {
67
- Authorization: string;
68
- 'X-Asyx-DeviceId': any;
69
- 'X-Asyx-RequestId': any;
70
- };
71
- refreshState: string;
72
- refreshAttempts: number;
73
- refreshMaxAttempts: number;
74
- refreshRetryTimer: any;
75
- refreshDeadline: number;
76
- refreshRetryCount: number;
77
- refreshRetryMaxDelay: number;
78
- refreshTimer: any;
79
- jwtMeta: {
80
- token: any;
81
- expMs: number;
82
- } | {
83
- token: any;
84
- expMs: number;
85
- };
86
- LEAD_MS: number;
87
- reauthAckTimeoutMs: number;
88
- reauthInFlight: Promise<boolean>;
89
- httpWsVersion: any;
90
- activeV2Responses: Map<any, any>;
91
- _decodeJwtExp(token: any): {
92
- expMs: number;
93
- issuedAtMs: number;
94
- skewMs: number;
95
- };
96
- _extractJti(token: any): any;
97
- scheduleRefresh(token: any, context?: string): void;
98
- reauthInBand(newJwt: any, prevJti: any, trigger?: string): Promise<boolean>;
99
- _checkRefreshLeadWindow(): boolean;
100
- _ensureControlPlane(reason: any, forceWait?: boolean): Promise<boolean>;
101
- _extractMqttReasonFromError(mqttError: any): any;
102
- /** Story 12.1: report a fatal condition (formerly process.exit(1)) to the owner of the tunnel. */
103
- _fatal(code: any, details?: {}): any;
104
- /** Story 12.1: a message for the user (formerly printed here); the caller decides the wording. */
105
- _notice(code: any, details?: {}): void;
106
- _localUnreachable(err: any): void;
107
- localServiceDown: boolean;
108
- _localReachable(): void;
109
- /** Story 3.8: the visitor's answer when the local service cannot be reached. */
110
- sendLocalUnavailable(requestId: any): void;
111
- open(): Promise<any>;
112
- _attemptConnect(): Promise<any>;
113
- _helloAttempts: any;
114
- lastInboundMs: number;
115
- scheduleReconnect(code: any, reason: any): any;
116
- attemptReconnect(): Promise<void>;
117
- _scheduleRefreshRetry(reason: any): any;
118
- _cancelRefreshRetry(): void;
119
- attemptJwtRefresh(): Promise<any>;
120
- _fallbackToFreshTunnel(): Promise<any>;
121
- sendTunnelError(requestId: any, status: any): void;
122
- handleHttpRequest(msg: any): void;
123
- handleHttpRequestBuffer(buffer: any): void;
124
- _sendHello(): void;
125
- _helloTimer: any;
126
- _handleHelloAck(helloAck: any): void;
127
- _canUseV2(): boolean;
128
- _encodeRequestId(requestId: any): Buffer<ArrayBuffer>;
129
- _selectResponseMode(contentLength: any, isChunked: any): "v2" | "v1";
130
- _sendV2Chunk(requestId: any, payload: any): boolean;
131
- _chunkPayload(payload: any): any[];
132
- _handleV2Response(proxyRes: any, requestId: any): void;
133
- _handleV1Response(proxyRes: any, requestId: any): void;
134
- close(): void;
135
- getHeartbeatInterval(): number;
136
- startHeartbeat(): void;
137
- sendHeartbeat(): void;
138
- stopHeartbeat(): void;
139
- }
140
- import WebSocket from 'ws';
@@ -1,13 +0,0 @@
1
- /**
2
- * HTTP-WS v2 Protocol Constants
3
- *
4
- * These constants define the authoritative values for HTTP-WS v2 protocol
5
- * implementation. They must match the values used by the relay server.
6
- *
7
- * @see relay/src/httpws-constants.js
8
- */
9
- export const HTTPWS_V2_TARGET_CHUNK_BYTES: 65536;
10
- export const HTTPWS_V2_MAX_CHUNK_BYTES: 262144;
11
- export const HTTPWS_V2_PROTOCOL_ERROR_CLOSE_CODE: 1002;
12
- export const HTTPWS_V2_PROTOCOL_ERROR_REASON: "httpws_v2_without_negotiation";
13
- export const HTTP_BODY_CHUNK: 32;
@@ -1,76 +0,0 @@
1
- export function reconnectEnabled(env?: NodeJS.ProcessEnv): boolean;
2
- /**
3
- * Decide what an established connection's close means.
4
- * Close code 4000 is the relay's application code: "lease_closed" (the control plane
5
- * ended the lease) and "lease_reconnected" (another connection took the lease over)
6
- * must not be fought; anything else (relay restart, network loss, 1006, 1001, 1011,
7
- * protocol errors) is retried.
8
- */
9
- export function classifyDrop(code: any, reason: any): {
10
- fatal: boolean;
11
- reason: string;
12
- };
13
- /** HTTP status from a ws handshake error ("Unexpected server response: 403"). */
14
- export function httpStatusOf(err: any): any;
15
- /**
16
- * Decide what a failed reconnect attempt means.
17
- * 401/403 and token verification failures are counted as authorization failures
18
- * (the token expired or the lease was closed); a few in a row end the tunnel.
19
- * 409 means the relay still holds the old connection for the lease; retry.
20
- * 400 means the request itself is malformed; retrying cannot help.
21
- */
22
- export function classifyFailure(err: any): {
23
- fatal: boolean;
24
- auth: boolean;
25
- reason: any;
26
- };
27
- /** Seconds-since-epoch exp claim of a JWT, or null. */
28
- export function jwtExp(jwt: any): any;
29
- export const DEFAULT_INITIAL_DELAY_MS: 250;
30
- export const DEFAULT_MAX_DELAY_MS: 5000;
31
- export const DEFAULT_MAX_OUTAGE_MS: number;
32
- export const DEFAULT_MAX_AUTH_FAILURES: 3;
33
- /**
34
- * Runs the reconnect loop for one tunnel.
35
- * connect(): Promise resolving when a new connection is open, rejecting otherwise.
36
- * onGiveUp(reason): called once if the tunnel cannot be reconnected.
37
- * onAuthFailure(): optional (Story 10.9). Called on the first authorization failure of a
38
- * streak; it may fetch a new assignment (for example after the tenant moved to another
39
- * relay, where the old token's relay no longer matches). If it returns true, the streak
40
- * is reset and the next attempt uses the new assignment at once.
41
- */
42
- export class Reconnector {
43
- constructor({ kind, log, connect, onGiveUp, env, initialDelayMs, maxDelayMs, maxOutageMs, maxAuthFailures, onAuthFailure, now, sleep, }: {
44
- kind: any;
45
- log: any;
46
- connect: any;
47
- onGiveUp: any;
48
- env?: NodeJS.ProcessEnv;
49
- initialDelayMs?: number;
50
- maxDelayMs?: any;
51
- maxOutageMs?: any;
52
- maxAuthFailures?: number;
53
- onAuthFailure?: any;
54
- now?: () => number;
55
- sleep?: (ms: any) => Promise<any>;
56
- });
57
- /** @type {string} */ kind: string;
58
- log: any;
59
- /** @type {() => Promise<unknown>} */ connect: () => Promise<unknown>;
60
- /** @type {(reason: string) => void} */ onGiveUp: (reason: string) => void;
61
- /** @type {number} */ initialDelayMs: number;
62
- /** @type {number} */ maxDelayMs: number;
63
- /** @type {number} */ maxOutageMs: number;
64
- /** @type {number} */ maxAuthFailures: number;
65
- /** @type {null | (() => Promise<boolean>)} */ onAuthFailure: null | (() => Promise<boolean>);
66
- /** @type {() => number} */ now: () => number;
67
- /** @type {(ms: number) => Promise<unknown>} */ sleep: (ms: number) => Promise<unknown>;
68
- running: boolean;
69
- stopped: boolean;
70
- reconnects: number;
71
- stop(): void;
72
- delayFor(attempt: any): number;
73
- /** Start reconnecting after a drop. Resolves when connected, given up or stopped. */
74
- run(dropReason: any): Promise<void>;
75
- giveUp(reason: any, extra?: {}): void;
76
- }
@@ -1,40 +0,0 @@
1
- import http from 'node:http';
2
- import type { IncomingHttpHeaders, IncomingMessage, OutgoingHttpHeaders } from 'node:http';
3
- import type { Writable } from 'node:stream';
4
- /** One request the relay sent through the tunnel. */
5
- export interface SinkRequest {
6
- method: string;
7
- path: string;
8
- headers: OutgoingHttpHeaders | IncomingHttpHeaders;
9
- }
10
- /** What the tunnel writes the request body to; http.ClientRequest satisfies it. */
11
- export type SinkRequestHandle = Writable & {
12
- on(event: 'error', listener: (err: NodeJS.ErrnoException) => void): SinkRequestHandle;
13
- destroy(error?: Error): SinkRequestHandle;
14
- };
15
- /** Where an HTTP tunnel sends the requests it receives. */
16
- export interface RequestSink {
17
- request(req: SinkRequest, onResponse: (res: IncomingMessage) => void): SinkRequestHandle;
18
- }
19
- /** The only addresses a local-port sink connects to, in order: IPv4 loopback, then IPv6 loopback. */
20
- export declare const LOOPBACK_ADDRESSES: readonly [{
21
- readonly address: "127.0.0.1";
22
- readonly family: 4;
23
- }, {
24
- readonly address: "::1";
25
- readonly family: 6;
26
- }];
27
- type LookupCallback = (err: NodeJS.ErrnoException | null, address: string | {
28
- address: string;
29
- family: number;
30
- }[], family?: number) => void;
31
- /** dns.lookup replacement for the sink: ignores the name and returns loopback only. */
32
- export declare function loopbackLookup(_hostname: string, options: {
33
- all?: boolean;
34
- } | number | LookupCallback, callback?: LookupCallback): void;
35
- export declare class LocalPortSink implements RequestSink {
36
- readonly port: number;
37
- constructor(port: number);
38
- request({ method, path, headers }: SinkRequest, onResponse: (res: IncomingMessage) => void): http.ClientRequest;
39
- }
40
- export {};
@@ -1,92 +0,0 @@
1
- export class TcpTunnel {
2
- constructor({ relayUrl, jwt, deviceId, requestId, localPort, leaseId, log, coordinatorCore, coordinatorIngress, isControlPlaneConnected, waitForControlPlane, getLastMqttError, getForceReconnect, controlPlaneTimeoutMs, getJwt, reassign, exit, }: {
3
- relayUrl: any;
4
- jwt: any;
5
- deviceId: any;
6
- requestId: any;
7
- localPort: any;
8
- leaseId: any;
9
- log: any;
10
- coordinatorCore: any;
11
- coordinatorIngress: any;
12
- isControlPlaneConnected?: () => boolean;
13
- waitForControlPlane?: () => Promise<void>;
14
- getLastMqttError?: () => any;
15
- getForceReconnect?: () => any;
16
- controlPlaneTimeoutMs?: number;
17
- getJwt?: any;
18
- reassign?: any;
19
- exit?: (code: number) => void;
20
- });
21
- relayUrl: any;
22
- jwt: any;
23
- getJwt: any;
24
- reassign: any;
25
- exit: (code: number) => void;
26
- deviceId: any;
27
- requestId: any;
28
- localPort: any;
29
- leaseId: any;
30
- log: any;
31
- ws: WebSocket;
32
- coordinatorCore: any;
33
- coordinatorIngress: any;
34
- isControlPlaneConnected: () => boolean;
35
- waitForControlPlane: () => Promise<void>;
36
- getLastMqttError: () => any;
37
- getForceReconnect: () => any;
38
- controlPlaneTimeoutMs: number;
39
- heartbeatTimer: any;
40
- lastActivityMs: number;
41
- headers: {
42
- Authorization: string;
43
- 'X-Asyx-DeviceId': any;
44
- 'X-Asyx-RequestId': any;
45
- };
46
- closing: boolean;
47
- everOpened: boolean;
48
- lastInboundMs: number;
49
- reconnectEnabled: boolean;
50
- reconnector: Reconnector;
51
- relayId: any;
52
- activeStreams: Map<any, any>;
53
- nextStreamId: number;
54
- frameBuffer: Buffer<ArrayBuffer>;
55
- protocolViolation: boolean;
56
- idleTimeoutMs: number;
57
- pingIntervalMs: number;
58
- pingTimer: NodeJS.Timeout;
59
- lastPongMs: number;
60
- tcpKeepalive: boolean;
61
- tcpKeepaliveInitialDelay: number;
62
- open(): Promise<void>;
63
- _attemptConnect(): Promise<any>;
64
- _onDropped(code: any, reasonStr: any): void;
65
- handleBinaryFrame(data: any): void;
66
- routeFrame(frame: any): void;
67
- handleProtocolViolation(error: any): void;
68
- handleStreamOpen(frame: any): void;
69
- handleStreamData(frame: any): void;
70
- handleStreamClose(frame: any): void;
71
- handleStreamError(frame: any): void;
72
- handlePing(frame: any): void;
73
- handlePong(frame: any): void;
74
- handleTcpStream(msg: any): void;
75
- handleTcpData(msg: any): void;
76
- startPingKeepalive(): void;
77
- stopPingKeepalive(): void;
78
- sendPing(): void;
79
- handleTcpClose(msg: any): void;
80
- closeStream(streamId: any): void;
81
- closeAllStreams(): void;
82
- close(): void;
83
- getHeartbeatInterval(): number;
84
- startHeartbeat(): void;
85
- sendHeartbeat(): void;
86
- stopHeartbeat(): void;
87
- /** Story 3.13: the coordinator said this lease is closed (at renewal): reopen exactly as on a relay
88
- * close 4000 lease_closed (same port, new lease, then reconnect); resolves false when refused. */
89
- reopenAfterLeaseClosed(): Promise<boolean>;
90
- }
91
- import WebSocket from 'ws';
92
- import { Reconnector } from './reconnect.js';