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,55 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { MqttControlPlaneClient } from './MqttControlPlaneClient.js';
3
- import type { Logger } from '../types.js';
4
- /** Credentials as values; reading them from disk is the caller's job. */
5
- export interface ControlPlaneCredentials {
6
- endpoint: string;
7
- clientId: string;
8
- ca: Buffer | string;
9
- cert: Buffer | string;
10
- key: Buffer | string;
11
- }
12
- export type TunnelType = 'http' | 'tcp' | 'udp' | 'account' | 'identity';
13
- export interface ControlPlaneSessionOptions {
14
- credentials: ControlPlaneCredentials;
15
- tunnelType: TunnelType;
16
- /** Instance metadata used when re-registering after a client id rotation. */
17
- metadata: Record<string, unknown>;
18
- logger: Logger;
19
- /** Protocol-specific renewal (stays with the caller for now). */
20
- onRefreshLease: () => Promise<number | null>;
21
- /** Story 3.13: reopen after a closed lease; resolves the new lease or throws (ends the tunnel). */
22
- onLeaseClosed?: () => Promise<{
23
- exp: number | null;
24
- leaseId: string;
25
- } | null>;
26
- /** HTTP passes its tunnel when the assignment moves to a new instance id. */
27
- getTunnel?: () => unknown;
28
- /** HTTP and UDP track it; TCP never has. */
29
- trackSubscriptionReady?: boolean;
30
- /** HTTP and UDP report it; TCP has no offline handler. */
31
- reportOffline?: boolean;
32
- /** UDP never logged requestId migration or re-registration. */
33
- verboseRotationLogs?: boolean;
34
- keepaliveSec?: number;
35
- mode?: 'unique' | 'legacy';
36
- instanceIdRef?: {
37
- instanceId: string | null;
38
- };
39
- subscriptionReadyRef?: {
40
- ready: boolean;
41
- };
42
- }
43
- /** Events: 'connected' { clientId }, 'offline' { reason }, 'fatal' { reason, error }. */
44
- export interface ControlPlaneSession {
45
- mqttClient: MqttControlPlaneClient;
46
- events: EventEmitter;
47
- baseClientId: string;
48
- instanceIdRef: {
49
- instanceId: string | null;
50
- };
51
- subscriptionReadyRef: {
52
- ready: boolean;
53
- };
54
- }
55
- export declare function createControlPlaneSession(o: ControlPlaneSessionOptions): ControlPlaneSession;
@@ -1,49 +0,0 @@
1
- export interface TunnelErrorOptions {
2
- /** Whether trying the same operation again may succeed. */
3
- retryable?: boolean;
4
- /** The underlying error, kept for logs. */
5
- cause?: unknown;
6
- /** Structured facts for the caller (e.g. port limits for a refused port, exitCode for the CLI). */
7
- details?: Record<string, unknown>;
8
- }
9
- export declare class TunnelError extends Error {
10
- /** Stable, machine-readable reason. */
11
- readonly code: string;
12
- readonly retryable: boolean;
13
- details?: Record<string, unknown>;
14
- /**
15
- * @param code stable, machine-readable reason
16
- * @param message developer-facing description (never shown to users as-is by the CLI)
17
- */
18
- constructor(code: string, message?: string, { retryable, cause, details }?: TunnelErrorOptions);
19
- }
20
- type SubclassOptions = Omit<TunnelErrorOptions, 'retryable'> & {
21
- retryable?: boolean;
22
- };
23
- /** The machine is not enrolled, or the coordinator wants it to enroll again. */
24
- export declare class SetupRequiredError extends TunnelError {
25
- constructor(code?: string, message?: string, opts?: SubclassOptions);
26
- }
27
- /**
28
- * The coordinator said no. `code` is the coordinator's own reason, passed through unchanged, so a
29
- * new reason on the server needs no client release (e.g. port_out_of_block, invalid_secgroup,
30
- * cap_exceeded, hostname_not_assigned, revoked).
31
- */
32
- export declare class RefusedError extends TunnelError {
33
- constructor(code?: string, message?: string, opts?: SubclassOptions);
34
- }
35
- /** Network or transport failure; usually worth retrying. */
36
- export declare class ConnectionError extends TunnelError {
37
- constructor(code?: string, message?: string, opts?: SubclassOptions);
38
- }
39
- /** Bad local input (arguments, configuration, credentials on disk). */
40
- export declare class ConfigError extends TunnelError {
41
- constructor(code?: string, message?: string, opts?: SubclassOptions);
42
- }
43
- /** A bug or an unexpected state inside the core. */
44
- export declare class InternalError extends TunnelError {
45
- constructor(code?: string, message?: string, opts?: SubclassOptions);
46
- }
47
- /** Wrap anything thrown into a TunnelError without losing it. */
48
- export declare function toTunnelError(e: unknown, fallbackCode?: string): TunnelError;
49
- export {};
@@ -1,24 +0,0 @@
1
- import type { Logger } from '../types.js';
2
- import type { ControlPlaneCredentials } from '../control-plane/session.js';
3
- export type AccountCommand = {
4
- type: 'address_add';
5
- name: string;
6
- } | {
7
- type: 'port_release';
8
- kind: 'tcp' | 'udp';
9
- port: number;
10
- };
11
- export type AccountReply = {
12
- op: string;
13
- ok: boolean;
14
- error?: string;
15
- [k: string]: unknown;
16
- };
17
- export interface AccountCommandOptions {
18
- credentials: ControlPlaneCredentials;
19
- command: AccountCommand;
20
- logger: Logger;
21
- timeoutMs?: number;
22
- }
23
- /** Sends one account command and resolves the coordinator's answer (a refusal is { ok: false, error }). */
24
- export declare function sendAccountCommand(o: AccountCommandOptions): Promise<AccountReply>;
@@ -1,10 +0,0 @@
1
- export interface GoodbyeHandle {
2
- core: any;
3
- assignment: Record<string, any> | null;
4
- opts: {
5
- credentials: {
6
- clientId: string;
7
- };
8
- };
9
- }
10
- export declare function sayGoodbye(h: GoodbyeHandle, timeoutMs?: number): Promise<'sent' | 'skipped' | 'timeout' | 'error'>;
@@ -1,61 +0,0 @@
1
- import { ReopenLimiter } from './reopen.js';
2
- import { LifecycleEmitter } from '../lifecycle.js';
3
- import type { ControlPlaneCredentials } from '../control-plane/session.js';
4
- import type { RequestSink } from '../tunnel/request-sink.js';
5
- import type { Logger } from '../types.js';
6
- export declare function scheduleInitialHttpRefresh(mqttClient: {
7
- scheduleRefresh(expMs: number, leaseId: string): void;
8
- } | null, assignment: Record<string, any>, logger: Logger): void;
9
- export interface HttpTunnelOptions {
10
- credentials: ControlPlaneCredentials;
11
- /** The local web app's port. */
12
- localPort: number;
13
- /** QuickPass security group (QPA-04): only its members can open the URL. */
14
- secGroupSlug?: string | null;
15
- /** Where received requests go (default: LocalPortSink(localPort)). */
16
- requestSink?: RequestSink;
17
- logger: Logger;
18
- /** Called with each observability line when ASYX_DEBUG=1 (the CLI prints them). */
19
- onObserve?: (line: string) => void;
20
- /** Story 1.9: while a live tunnel of this kind serves the address, ask again every 30 s instead of failing. */
21
- waitIfInUse?: boolean;
22
- /** Story 1.9: take over this address's live tunnel of the same kind (the old one is told and stops), like `asyx tunnel --replace`. */
23
- replace?: boolean;
24
- }
25
- /**
26
- * Sent with 'notice': something the user may want to know that does not end the tunnel, e.g.
27
- * control_plane_offline, control_plane_timeout, jwt_expired_offline, quickpass_refresh_delayed.
28
- */
29
- export type HttpNoticeEvent = {
30
- code: string;
31
- [key: string]: unknown;
32
- };
33
- /** What open() resolves to and the 'live' state carries. */
34
- export type HttpTunnelInfo = {
35
- assignment: Record<string, any>;
36
- localPort: number;
37
- relayId: string;
38
- leaseMs?: number;
39
- quickpassSlug?: string;
40
- };
41
- export declare class HttpTunnelHandle extends LifecycleEmitter {
42
- readonly opts: HttpTunnelOptions & {
43
- secGroupSlug: string | null;
44
- };
45
- tunnel: any;
46
- mqttClient: any;
47
- /** Story 1.9: one id for this tunnel across its opens (a re-open is never "another tunnel"). */
48
- readonly tunnelSession: string;
49
- /** Story 3.13: reopens after a closed lease, at most 3 in 10 minutes. */
50
- readonly reopenLimiter: ReopenLimiter;
51
- core: any;
52
- assignment: Record<string, any> | null;
53
- constructor(o: HttpTunnelOptions);
54
- /** Story 3.13: tell the cloud this tunnel stops on purpose (closes its lease at once); waits at most 2 s. */
55
- goodbye(timeoutMs?: number): Promise<'sent' | 'skipped' | 'timeout' | 'error'>;
56
- /** Connect the control plane, get a lease and open the data plane; rejects with a ConnectionError. */
57
- open(): Promise<HttpTunnelInfo>;
58
- /** Ask for a renewal now (SIGUSR2 in the CLI). */
59
- attemptJwtRefresh(): Promise<unknown> | undefined;
60
- }
61
- export declare function createHttpTunnel(opts: HttpTunnelOptions): HttpTunnelHandle;
@@ -1,23 +0,0 @@
1
- import type { Logger } from '../types.js';
2
- import type { ControlPlaneCredentials } from '../control-plane/session.js';
3
- export type AppCreateCommand = {
4
- name: string;
5
- csrPem: string;
6
- hostname?: string;
7
- random?: boolean;
8
- address?: string;
9
- };
10
- export type IdentityReply = {
11
- op: string;
12
- ok: boolean;
13
- error?: string;
14
- [k: string]: unknown;
15
- };
16
- export interface IdentityCommandOptions {
17
- credentials: ControlPlaneCredentials;
18
- command: AppCreateCommand;
19
- logger: Logger;
20
- timeoutMs?: number;
21
- }
22
- /** Sends one app create and resolves the service's answer (a refusal is { ok: false, error }). */
23
- export declare function sendAppCreate(o: IdentityCommandOptions): Promise<IdentityReply>;
@@ -1,27 +0,0 @@
1
- export declare const SAME_COMPUTER_WAIT_MS = 15000;
2
- export declare const SAME_COMPUTER_STEP_MS = 3000;
3
- export declare const WAIT_STEP_MS = 30000;
4
- export type InUseDetails = Record<string, unknown> & {
5
- sameComputer?: boolean;
6
- };
7
- /** How long to wait before asking again, or null to give up (the caller reports the refusal). */
8
- export declare function inUseDelay(details: InUseDetails | undefined, firstAt: number, now: number, waitIfInUse: boolean): number | null;
9
- export interface OpenUntilFreeOptions<T> {
10
- /** publish a cmd/open with this requestId */
11
- send: (requestId: string) => Promise<void>;
12
- /** wait for the assignment of this requestId */
13
- wait: (requestId: string) => Promise<T>;
14
- waitIfInUse?: boolean;
15
- onWaiting?: (info: {
16
- details: InUseDetails;
17
- delayMs: number;
18
- sameComputer: boolean;
19
- attempt: number;
20
- }) => void;
21
- sleep?: (ms: number) => Promise<void>;
22
- now?: () => number;
23
- }
24
- export declare function openUntilFree<T>(o: OpenUntilFreeOptions<T>): Promise<{
25
- assignment: T;
26
- requestId: string;
27
- }>;
@@ -1,9 +0,0 @@
1
- export declare class ReopenLimiter {
2
- private readonly max;
3
- private readonly windowMs;
4
- private times;
5
- constructor(max?: number, windowMs?: number);
6
- allow(now?: number): boolean;
7
- }
8
- /** The open request for a reopen: same address, port and session, never `replace`. */
9
- export declare function reopenPayload(openPayload: Record<string, any>, requestId: string, publicPort: number | null | undefined): Record<string, any>;
@@ -1,85 +0,0 @@
1
- import { ReopenLimiter } from './reopen.js';
2
- import { LifecycleEmitter } from '../lifecycle.js';
3
- import type { ControlPlaneCredentials } from '../control-plane/session.js';
4
- import type { Logger } from '../types.js';
5
- export interface TcpTunnelOptions {
6
- credentials: ControlPlaneCredentials;
7
- localPort: number;
8
- /** "127.0.0.1:<port>" (TCP-S1). */
9
- target: string;
10
- /** Alias requested for the public hostname (e.g. for Minecraft). */
11
- serviceName?: string | null;
12
- /** Service kind, e.g. 'minecraft'. */
13
- kind?: string | null;
14
- /** A public port inside the tenant's block, or null for the coordinator's choice. */
15
- requestedExternalPort?: number | null;
16
- logger: Logger;
17
- /** Called with each observability line when ASYX_DEBUG=1 (the CLI prints them). */
18
- onObserve?: (line: string) => void;
19
- /** Story 1.9: while a live tunnel of this kind serves the address, ask again every 30 s instead of failing. */
20
- waitIfInUse?: boolean;
21
- /** Story 1.9: take over this address's live tunnel of the same kind (the old one is told and stops), like `asyx tunnel --replace`. */
22
- replace?: boolean;
23
- }
24
- /** Sent with 'assigned' when the coordinator's assignment arrives. */
25
- export type TcpAssignedEvent = {
26
- tcpAliasFqdn?: string;
27
- srvProvisioned?: boolean;
28
- srvFqdn?: string;
29
- fqdn?: string;
30
- publicPort?: number;
31
- aliasRequestedButFailed?: boolean;
32
- /** Story 2.11 c3: the named port was labelled for another address and its label moved to this one. */
33
- portMoved?: {
34
- port: number;
35
- kind: string;
36
- from: string;
37
- to: string;
38
- fromHostname?: string | null;
39
- toHostname?: string | null;
40
- /** Story 1.7 r8: what happened to the port's Minecraft record */
41
- minecraft?: {
42
- status: 'moved' | 'nothing' | 'kept_existing' | 'pending' | 'not_updated';
43
- existingPort?: number | null;
44
- } | null;
45
- } | null;
46
- };
47
- /** What open() resolves to and the 'live' state carries. */
48
- export type TcpTunnelInfo = {
49
- assignment: Record<string, any>;
50
- localPort: number;
51
- relayId: string;
52
- publicPort?: number;
53
- fqdn?: string;
54
- leaseMs?: number;
55
- };
56
- export declare class TcpTunnelHandle extends LifecycleEmitter {
57
- readonly opts: TcpTunnelOptions & {
58
- serviceName: string | null;
59
- kind: string | null;
60
- requestedExternalPort: number | null;
61
- };
62
- tunnel: any;
63
- mqttClient: any;
64
- /** Story 1.9: one id for this tunnel across its opens. */
65
- readonly tunnelSession: string;
66
- /** Story 3.13: reopens after a closed lease, at most 3 in 10 minutes. */
67
- readonly reopenLimiter: ReopenLimiter;
68
- core: any;
69
- assignment: Record<string, any> | null;
70
- constructor(o: TcpTunnelOptions);
71
- /** Story 3.13: tell the cloud this tunnel stops on purpose (closes its lease at once); waits at most 2 s. */
72
- goodbye(timeoutMs?: number): Promise<'sent' | 'skipped' | 'timeout' | 'error'>;
73
- /** Connect the control plane, get a lease and open the data plane; rejects with a typed error. */
74
- open(): Promise<TcpTunnelInfo>;
75
- /** Close the data plane, then the control plane. */
76
- close(): Promise<void>;
77
- }
78
- /**
79
- * TPB-17: schedule the first TCP renewal from the assignment token's expiry (moved unchanged from
80
- * connectToRelayTcp; exported so its behaviour can be tested on its own).
81
- */
82
- export declare function scheduleInitialTcpRefresh(mqttClient: {
83
- scheduleRefresh(expMs: number, leaseId: string): void;
84
- } | null, assignment: Record<string, any>, logger: Logger): void;
85
- export declare function createTcpTunnel(opts: TcpTunnelOptions): TcpTunnelHandle;
@@ -1,52 +0,0 @@
1
- import { ReopenLimiter } from './reopen.js';
2
- import { LifecycleEmitter } from '../lifecycle.js';
3
- import type { ControlPlaneCredentials } from '../control-plane/session.js';
4
- import type { Logger } from '../types.js';
5
- export interface UdpTunnelOptions {
6
- credentials: ControlPlaneCredentials;
7
- /** The local app's port (UDP-S13: not a port the CLI binds). */
8
- targetPort: number;
9
- /** Must be loopback; default 127.0.0.1. */
10
- targetHost?: string;
11
- /** A public port inside the tenant's block, or null for the coordinator's choice. */
12
- requestedExternalPort?: number | null;
13
- logger: Logger;
14
- /** Called with each observability line when ASYX_DEBUG=1 (the CLI prints them). */
15
- onObserve?: (line: string) => void;
16
- /** Story 1.9: while a live tunnel of this kind serves the address, ask again every 30 s instead of failing. */
17
- waitIfInUse?: boolean;
18
- /** Story 1.9: take over this address's live tunnel of the same kind (the old one is told and stops), like `asyx tunnel --replace`. */
19
- replace?: boolean;
20
- }
21
- /** What open() resolves to and the 'live' state carries. */
22
- export type UdpTunnelInfo = {
23
- assignment: Record<string, any>;
24
- targetHost: string;
25
- targetPort: number;
26
- relayId: string;
27
- publicPort?: number;
28
- fqdn?: string;
29
- leaseMs?: number;
30
- };
31
- export declare class UdpTunnelHandle extends LifecycleEmitter {
32
- readonly opts: UdpTunnelOptions & {
33
- targetHost: string;
34
- requestedExternalPort: number | null;
35
- };
36
- tunnel: any;
37
- mqttClient: any;
38
- /** Story 1.9: one id for this tunnel across its opens. */
39
- readonly tunnelSession: string;
40
- /** Story 3.13: reopens after a closed lease, at most 3 in 10 minutes. */
41
- readonly reopenLimiter: ReopenLimiter;
42
- core: any;
43
- assignment: Record<string, any> | null;
44
- constructor(o: UdpTunnelOptions);
45
- /** Story 3.13: tell the cloud this tunnel stops on purpose (closes its lease at once); waits at most 2 s. */
46
- goodbye(timeoutMs?: number): Promise<'sent' | 'skipped' | 'timeout' | 'error'>;
47
- /** Connect the control plane, get a lease and open the data plane; rejects with a ConnectionError. */
48
- open(): Promise<UdpTunnelInfo>;
49
- /** Close the data plane, then the control plane. */
50
- close(): Promise<void>;
51
- }
52
- export declare function createUdpTunnel(opts: UdpTunnelOptions): UdpTunnelHandle;
@@ -1,2 +0,0 @@
1
- import type { ClassLogger, Logger } from '../types.js';
2
- export declare function adaptLogger(logger: Logger): ClassLogger;
@@ -1,145 +0,0 @@
1
- export function getFpHash(clientId: any): Promise<{
2
- replace: boolean;
3
- host: string;
4
- to: string;
5
- clientVersion: string;
6
- fpv: string;
7
- fph: string;
8
- alg: string;
9
- lib: string;
10
- } | {
11
- replace?: undefined;
12
- host: string;
13
- to: string;
14
- clientVersion: string;
15
- fpv: string;
16
- fph: string;
17
- alg: string;
18
- lib: string;
19
- } | {
20
- replace: boolean;
21
- host?: undefined;
22
- to: string;
23
- clientVersion: string;
24
- fpv: string;
25
- fph: string;
26
- alg: string;
27
- lib: string;
28
- } | {
29
- replace?: undefined;
30
- host?: undefined;
31
- to: string;
32
- clientVersion: string;
33
- fpv: string;
34
- fph: string;
35
- alg: string;
36
- lib: string;
37
- } | {
38
- replace: boolean;
39
- host: string;
40
- to?: undefined;
41
- clientVersion: string;
42
- fpv: string;
43
- fph: string;
44
- alg: string;
45
- lib: string;
46
- } | {
47
- replace?: undefined;
48
- host: string;
49
- to?: undefined;
50
- clientVersion: string;
51
- fpv: string;
52
- fph: string;
53
- alg: string;
54
- lib: string;
55
- } | {
56
- replace: boolean;
57
- host?: undefined;
58
- to?: undefined;
59
- clientVersion: string;
60
- fpv: string;
61
- fph: string;
62
- alg: string;
63
- lib: string;
64
- } | {
65
- replace?: undefined;
66
- host?: undefined;
67
- to?: undefined;
68
- clientVersion: string;
69
- fpv: string;
70
- fph: string;
71
- alg: string;
72
- lib: string;
73
- } | {
74
- replace: boolean;
75
- host: string;
76
- to: string;
77
- clientVersion?: undefined;
78
- fpv: string;
79
- fph: string;
80
- alg: string;
81
- lib: string;
82
- } | {
83
- replace?: undefined;
84
- host: string;
85
- to: string;
86
- clientVersion?: undefined;
87
- fpv: string;
88
- fph: string;
89
- alg: string;
90
- lib: string;
91
- } | {
92
- replace: boolean;
93
- host?: undefined;
94
- to: string;
95
- clientVersion?: undefined;
96
- fpv: string;
97
- fph: string;
98
- alg: string;
99
- lib: string;
100
- } | {
101
- replace?: undefined;
102
- host?: undefined;
103
- to: string;
104
- clientVersion?: undefined;
105
- fpv: string;
106
- fph: string;
107
- alg: string;
108
- lib: string;
109
- } | {
110
- replace: boolean;
111
- host: string;
112
- to?: undefined;
113
- clientVersion?: undefined;
114
- fpv: string;
115
- fph: string;
116
- alg: string;
117
- lib: string;
118
- } | {
119
- replace?: undefined;
120
- host: string;
121
- to?: undefined;
122
- clientVersion?: undefined;
123
- fpv: string;
124
- fph: string;
125
- alg: string;
126
- lib: string;
127
- } | {
128
- replace: boolean;
129
- host?: undefined;
130
- to?: undefined;
131
- clientVersion?: undefined;
132
- fpv: string;
133
- fph: string;
134
- alg: string;
135
- lib: string;
136
- } | {
137
- replace?: undefined;
138
- host?: undefined;
139
- to?: undefined;
140
- clientVersion?: undefined;
141
- fpv: string;
142
- fph: string;
143
- alg: string;
144
- lib: string;
145
- }>;
@@ -1,27 +0,0 @@
1
- /**
2
- * Verify assignment JWT with JWKS signature verification
3
- * AC1.4/AC5.1: Validates signature, iss, aud, exp, relayId, protocol, tunnelMode, leaseId
4
- * @param {string} token - JWT token to verify
5
- * @param {Object} expectedClaims - Expected claim values
6
- * @param {string} expectedClaims.relayId - Expected relayId
7
- * @param {string} expectedClaims.protocol - Expected protocol ('udp' | 'tcp')
8
- * @param {string} expectedClaims.tunnelMode - Expected tunnelMode ('udpWs-v1' | 'tcpWs-v1')
9
- * @param {string} [expectedClaims.leaseId] - Expected leaseId (optional)
10
- * @returns {Promise<Object>} Verified JWT payload
11
- * @throws {Error} If JWT verification fails (signature, claims, or JWKS unavailable)
12
- */
13
- export function verifyAssignmentJWT(token: string, expectedClaims?: {
14
- relayId: string;
15
- protocol: string;
16
- tunnelMode: string;
17
- leaseId?: string;
18
- }): Promise<any>;
19
- /**
20
- * Check if JWKS is available (for health checks)
21
- * @returns {boolean} True if JWKS is initialized
22
- */
23
- export function isJWKSAvailable(): boolean;
24
- /**
25
- * Reset JWKS cache (for testing or re-initialization)
26
- */
27
- export function resetJWKS(): void;
@@ -1,9 +0,0 @@
1
- export function log(level: any, msg: any, fields?: {}): void;
2
- export namespace logger {
3
- export function debug(msg: any, fields: any): void;
4
- export function info(msg: any, fields: any): void;
5
- export function warn(msg: any, fields: any): void;
6
- export function error(msg: any, fields: any): void;
7
- export { log };
8
- }
9
- export default logger;
@@ -1,16 +0,0 @@
1
- import type { Logger, Publisher } from '../types.js';
2
- /**
3
- * QPA-CLI-09: Publish refresh request with ECONNRESET error handling.
4
- * Catches connection reset errors during publish and returns a sentinel value
5
- * instead of throwing, so the CLI doesn't exit with "Unexpected error".
6
- *
7
- * @param coordinatorCore - MQTT core client with publish method
8
- * @param topic - MQTT topic to publish to
9
- * @param payload - Refresh payload object (will be JSON stringified)
10
- * @param refreshRequestId - Request ID for logging
11
- * @param logger - Logger instance
12
- * @returns Returns true on success, false on ECONNRESET (buffered), throws on other errors
13
- */
14
- export declare function publishRefreshRequestWithErrorHandling(coordinatorCore: Publisher, topic: string, payload: unknown, refreshRequestId: string, logger: Logger): Promise<boolean>;
15
- /** Expiry (seconds since epoch) of a JWT, or null; no signature check. */
16
- export declare function jwtExpOf(jwt: unknown): number | null;
@@ -1,24 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import type { TunnelError } from './errors.js';
3
- export declare const STATES: readonly ["opening", "live", "reconnecting", "renewed", "closed"];
4
- export type TunnelState = (typeof STATES)[number];
5
- /** Extra facts sent with a state change; `error` is set on a 'closed' that was not asked for. */
6
- export interface StateDetail {
7
- error?: TunnelError;
8
- [key: string]: unknown;
9
- }
10
- export interface StateEvent extends StateDetail {
11
- state: TunnelState;
12
- }
13
- export interface WarningEvent {
14
- code: string;
15
- [key: string]: unknown;
16
- }
17
- export declare class LifecycleEmitter extends EventEmitter {
18
- state: TunnelState | null;
19
- emit(name: string | symbol, ...args: unknown[]): boolean;
20
- /** Change state and tell listeners. `detail` may carry `error` (on 'closed'), relay ids, etc. */
21
- setState(state: TunnelState, detail?: StateDetail): void;
22
- /** A non-fatal problem the caller may want to show (the core never prints). */
23
- warn(code: string, detail?: Record<string, unknown>): void;
24
- }