@restatedev/restate-sdk-tunnel 0.0.0-dev → 1.15.0-rc.3

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.
@@ -0,0 +1,288 @@
1
+ import { EndpointOptions } from "@restatedev/restate-sdk";
2
+
3
+ //#region src/types.d.ts
4
+
5
+ /**
6
+ * The services to expose over the tunnel — the same shape `restate.serve`
7
+ * and `createEndpointHandler` accept (services, virtual objects, workflows).
8
+ */
9
+ type Services = EndpointOptions["services"];
10
+ /**
11
+ * TLS options for the outbound tunnel connection.
12
+ *
13
+ * Note: unlike a regular HTTP/2 client, the tunnel deliberately negotiates
14
+ * NO ALPN protocol ("tunnel is not normal h2" — the server clears its ALPN
15
+ * list); both sides speak HTTP/2 with prior knowledge after the TLS
16
+ * handshake. There is therefore no ALPN field here, and the package never
17
+ * sets one.
18
+ */
19
+ interface TunnelTlsOptions {
20
+ /**
21
+ * CA certificate(s) (PEM) to trust. Omit to use the system trust store —
22
+ * the right choice for Restate Cloud's public endpoints.
23
+ */
24
+ ca?: string | Buffer | Array<string | Buffer>;
25
+ /** Client certificate (PEM) for mutual TLS. */
26
+ cert?: string | Buffer;
27
+ /** Client key (PEM) for mutual TLS. */
28
+ key?: string | Buffer;
29
+ /**
30
+ * SNI / certificate-verification name. Defaults to the hostname being
31
+ * dialed (for region/SRV discovery, the SRV target hostname).
32
+ */
33
+ servername?: string;
34
+ /** Verify the server certificate. Default true. */
35
+ rejectUnauthorized?: boolean;
36
+ }
37
+ /**
38
+ * Options for {@link connectTunnel}.
39
+ *
40
+ * The identity and discovery options fall back to `RESTATE_INPROC_*`
41
+ * environment variables when not given (option > environment > throw):
42
+ * `tunnelName` ← `RESTATE_INPROC_TUNNEL_NAME`, `environmentId` ←
43
+ * `RESTATE_INPROC_ENVIRONMENT_ID`, `region` ← `RESTATE_INPROC_CLOUD_REGION`,
44
+ * `signingPublicKey` ← `RESTATE_INPROC_SIGNING_PUBLIC_KEY`, and `authToken`
45
+ * ← the file named by `RESTATE_INPROC_AUTH_TOKEN_FILE` (re-read on every
46
+ * reconnect, so rotations are picked up). The
47
+ * [restate-operator](https://github.com/restatedev/restate-operator)
48
+ * injects the first four into the pods of a `tunnelMode: in-process`
49
+ * RestateDeployment and registers the matching URL — there,
50
+ * `connectTunnel({ services })` plus a token-file Secret mount (named by
51
+ * `RESTATE_INPROC_AUTH_TOKEN_FILE`) is a complete configuration.
52
+ */
53
+ interface ConnectTunnelOptions {
54
+ /**
55
+ * Restate Cloud region (e.g. `"us"`, `"eu"`). Tunnel servers are
56
+ * discovered via a DNS SRV lookup of `tunnel.<region>.restate.cloud`,
57
+ * expanded to every resolved address — the engine holds **one tunnel
58
+ * connection per resolved tunnel server** (like the standalone client),
59
+ * and re-resolves every {@link resolveIntervalMs}, starting connections
60
+ * to servers that appear and tearing down connections to servers that
61
+ * vanish.
62
+ *
63
+ * Exactly one of `region`, `tunnelServersSrv` or `tunnelServers` must be
64
+ * set. When none is, `region` falls back to the
65
+ * `RESTATE_INPROC_CLOUD_REGION` environment variable.
66
+ */
67
+ region?: string;
68
+ /**
69
+ * A DNS SRV name to discover tunnel servers from, for environments whose
70
+ * SRV name doesn't follow the `tunnel.<region>.restate.cloud` template
71
+ * (the standalone client's `RESTATE_TUNNEL_SERVERS_SRV`). Same expansion
72
+ * and reconciliation semantics as `region`.
73
+ *
74
+ * Exactly one of `region`, `tunnelServersSrv` or `tunnelServers` must be
75
+ * set.
76
+ */
77
+ tunnelServersSrv?: string;
78
+ /**
79
+ * Explicit tunnel server addresses, instead of region-based discovery.
80
+ * Each entry is either `"host:port"` (TLS governed by the `tls` option)
81
+ * or a URL `"https://host:port"` / `"http://host:port"` (scheme selects
82
+ * TLS/plaintext for that server). The engine holds one tunnel connection
83
+ * per entry; the set is fixed (no re-resolution).
84
+ *
85
+ * Exactly one of `region`, `tunnelServersSrv` or `tunnelServers` must be
86
+ * set.
87
+ */
88
+ tunnelServers?: string[];
89
+ /**
90
+ * How often region-based discovery re-resolves the tunnel-server set.
91
+ * Default 30_000. (The Rust client re-resolves on DNS TTL expiry; Node
92
+ * does not expose record TTLs, so a fixed interval approximates it.)
93
+ * Ignored with explicit `tunnelServers`.
94
+ */
95
+ resolveIntervalMs?: number;
96
+ /**
97
+ * The Restate Cloud environment ID to tunnel to, including the `env_`
98
+ * prefix (e.g. `"env_201k0yd4rz8yftmd4awh1bajg4v"`).
99
+ *
100
+ * Falls back to the `RESTATE_INPROC_ENVIRONMENT_ID` environment variable.
101
+ */
102
+ environmentId?: string;
103
+ /**
104
+ * A Restate Cloud API key with the `Full` role (`key_...`), or a user
105
+ * JWT. Presented as `authorization: Bearer <token>` during the tunnel
106
+ * handshake; validated server-side.
107
+ *
108
+ * Falls back to the contents of the file named by the
109
+ * `RESTATE_INPROC_AUTH_TOKEN_FILE` environment variable — the right shape
110
+ * for a mounted Kubernetes Secret: the file is re-read on every reconnect,
111
+ * so a rotated token is picked up without a restart.
112
+ */
113
+ authToken?: string;
114
+ /**
115
+ * The environment's request-identity public key
116
+ * (`publickeyv1_<base58>`). Passed to the SDK's request-identity
117
+ * verification so every forwarded request is checked to genuinely come
118
+ * from your environment. Shown by Restate Cloud for your environment.
119
+ *
120
+ * Falls back to the `RESTATE_INPROC_SIGNING_PUBLIC_KEY` environment
121
+ * variable.
122
+ */
123
+ signingPublicKey?: string;
124
+ /**
125
+ * The deployment's identity: the rendezvous key both ends use to route.
126
+ * The tunnel server keys connections by `<environment>/<tunnelName>` and
127
+ * load-balances each proxied invocation across every connection
128
+ * registered under that key — so replicas of the *same* deployment must
129
+ * share one `tunnelName`, and distinct deployments must each have their
130
+ * own. It appears in the deployment registration URL, so it should be
131
+ * stable across restarts (e.g. `"greeter-v1"`).
132
+ *
133
+ * Falls back to the `RESTATE_INPROC_TUNNEL_NAME` environment variable
134
+ * (the restate-operator injects a per-revision name there).
135
+ */
136
+ tunnelName?: string;
137
+ /** The services to serve over the tunnel. */
138
+ services: Services;
139
+ /**
140
+ * Protocol mode for the SDK handler. Default `true` (`BIDI_STREAM`) —
141
+ * the tunnel is always HTTP/2, so full-duplex streaming is available.
142
+ */
143
+ bidirectional?: boolean;
144
+ /**
145
+ * Advertise graceful-drain support (`supports-drain: true`) in the
146
+ * handshake. Default `true`. When Restate Cloud rolls a tunnel node it
147
+ * sends `/_/drain-tunnel` to drain-capable connections: the engine then
148
+ * immediately opens a replacement connection while the old one keeps
149
+ * serving its in-flight invocations (bounded by {@link drainGraceMs}) —
150
+ * zero dropped requests across cloud rollovers. With `false`, the cloud
151
+ * simply closes the connection and in-flight invocations are retried by
152
+ * the Restate runtime after the redial.
153
+ */
154
+ supportsDrain?: boolean;
155
+ /**
156
+ * How long a draining connection may keep serving its in-flight
157
+ * invocations before being torn down. Default 120_000 (mirrors the
158
+ * standalone tunnel client).
159
+ */
160
+ drainGraceMs?: number;
161
+ /**
162
+ * Reconnect backoff: initial delay in milliseconds. Default 10.
163
+ * The delay grows by `reconnectFactor` per failed attempt (with jitter)
164
+ * up to `reconnectMaxMs`, and resets after a successful handshake.
165
+ */
166
+ reconnectInitialMs?: number;
167
+ /** Reconnect backoff: maximum delay in milliseconds. Default 120_000. */
168
+ reconnectMaxMs?: number;
169
+ /** Reconnect backoff: growth factor. Default 2. */
170
+ reconnectFactor?: number;
171
+ /**
172
+ * Deadline for establishing the TCP connection and completing the TLS
173
+ * handshake. Default 5_000 (mirrors the standalone tunnel client's
174
+ * connect timeout). Without it, a peer that accepts the connection but
175
+ * never completes TLS would stall reconnection indefinitely.
176
+ */
177
+ connectTimeoutMs?: number;
178
+ /**
179
+ * Deadline for the tunnel handshake (the server opening
180
+ * `/_/start-tunnel` and completing it with trailers). Default 5_000,
181
+ * mirroring the tunnel server's own handshake timeout.
182
+ */
183
+ handshakeTimeoutMs?: number;
184
+ /**
185
+ * Liveness watchdog: send an HTTP/2 PING every this many milliseconds.
186
+ * Default 75_000 (the tunnel protocol's keepalive cadence).
187
+ */
188
+ pingIntervalMs?: number;
189
+ /** Watchdog: how long to wait for a PING ack. Default 10_000. */
190
+ pingTimeoutMs?: number;
191
+ /**
192
+ * Watchdog: consecutive missed PINGs before the connection is declared
193
+ * dead and redialed. Default 2.
194
+ */
195
+ pingMaxMissed?: number;
196
+ /**
197
+ * Maximum concurrent HTTP/2 streams (in-flight invocations) per
198
+ * connection. Default 4096 (Node's default of 100 is far too low for a
199
+ * deployment serving many concurrent invocations).
200
+ */
201
+ maxConcurrentStreams?: number;
202
+ /**
203
+ * Per-connection HTTP/2 flow-control window in bytes. Default 16 MiB
204
+ * (Node's 64 KiB default throttles aggregate throughput).
205
+ */
206
+ connectionWindowSize?: number;
207
+ /**
208
+ * Node http2 per-session memory cap in MiB. Default 256 (Node's 10 MiB
209
+ * default makes the session reject work under load).
210
+ */
211
+ maxSessionMemory?: number;
212
+ /**
213
+ * TLS for the outbound connection. Default `true` (system trust, SNI =
214
+ * dialed host, and — deliberately — NO ALPN). Pass `false` only for
215
+ * plaintext dev/test setups, or an object for a private CA / mTLS.
216
+ */
217
+ tls?: boolean | TunnelTlsOptions;
218
+ /** Abort to stop reconnecting and close the tunnel (same as `close()`). */
219
+ signal?: AbortSignal;
220
+ /** Diagnostic logger. Default: silent. */
221
+ logger?: (message: string) => void;
222
+ }
223
+ /**
224
+ * Handle returned by {@link connectTunnel}.
225
+ */
226
+ interface TunnelConnection {
227
+ /** Stop reconnecting, close the current connection, and wait for teardown. */
228
+ close(): Promise<void>;
229
+ /** Number of successful tunnel handshakes since `connectTunnel` was called. */
230
+ readonly connectionCount: number;
231
+ /**
232
+ * The tunnel name confirmed by the server in the most recent successful
233
+ * handshake. `undefined` until the first handshake completes.
234
+ */
235
+ readonly tunnelName: string | undefined;
236
+ /**
237
+ * The public proxy **base** URL for this tunnel
238
+ * (`<proxy-host>/<env-id>/<tunnel-name>`), learned from the most recent
239
+ * successful handshake. The deployment registration URL is this base plus
240
+ * a `/<scheme>/<host>/<port>` destination segment — for an in-process
241
+ * deployment the destination is vestigial, e.g.
242
+ * `${proxyUrl}/http/in-process/9080`. Registering the bare base URL will
243
+ * not route.
244
+ */
245
+ readonly proxyUrl: string | undefined;
246
+ /** The tunnel server URL, learned from the most recent successful handshake. */
247
+ readonly tunnelUrl: string | undefined;
248
+ /**
249
+ * The full deployment registration URL:
250
+ * `<proxyUrl>/http/in-process/9080/` — register this with
251
+ * `restate dep register <url>` (or the UI) once the tunnel is
252
+ * {@link ready}. `undefined` until the first successful handshake.
253
+ *
254
+ * The `/http/in-process/9080/` destination segment is a constant: an
255
+ * in-process tunnel terminates at this very process, so the destination
256
+ * is never dialed and plays no routing role — the deployment's identity
257
+ * is the `tunnelName` earlier in the path.
258
+ *
259
+ * Built from the handshake-advertised proxy URL; on BYOC clusters where
260
+ * Restate reaches the proxy via a cluster-internal address instead,
261
+ * substitute that base and keep the path.
262
+ */
263
+ readonly deploymentUrl: string | undefined;
264
+ /**
265
+ * Set when the tunnel stopped on a non-retryable failure (e.g. the server
266
+ * answered `unauthorized` or `bad-tunnel-name`). Once set, the tunnel no
267
+ * longer reconnects.
268
+ */
269
+ readonly error: Error | undefined;
270
+ /**
271
+ * Resolves when the first tunnel handshake succeeds; rejects if the
272
+ * tunnel stops on a non-retryable failure before ever connecting.
273
+ * Useful for readiness checks; safe to ignore.
274
+ */
275
+ readonly ready: Promise<void>;
276
+ }
277
+ //#endregion
278
+ //#region src/connect.d.ts
279
+ /**
280
+ * Connect this deployment to a Restate Cloud tunnel and serve `services`
281
+ * over it. Returns immediately; connection management runs in the
282
+ * background until `close()` (or the `signal`) stops it. See
283
+ * {@link TunnelConnection.ready} to await the first successful handshake.
284
+ */
285
+ declare function connectTunnel(options: ConnectTunnelOptions): TunnelConnection;
286
+ //#endregion
287
+ export { type ConnectTunnelOptions, type Services, type TunnelConnection, type TunnelTlsOptions, connectTunnel };
288
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/connect.ts"],"sourcesContent":[],"mappings":";;;;;;AAmBA;AAWA;AAKgB,KAhBJ,QAAA,GAAW,eAgBP,CAAA,UAAA,CAAA;;;;;;AA8BhB;;;;AAsKsB,UAzML,gBAAA,CAyMK;EAQL;;;;EAiDQ,EAAA,CAAA,EAAA,MAAA,GA7PT,MA6PS,GA7PA,KA6PA,CAAA,MAAA,GA7Pe,MA6Pf,CAAA;;kBA3PP;;ECgCF,GAAA,CAAA,EAAA,MAAA,GD9BC,MC8BY;;;;;;;;;;;;;;;;;;;;;;;;;UDJZ,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqFL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA+EM;;WAEP;;;;;;;UAQM,gBAAA;;WAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAyCO;;;;;;kBAMA;;;;;;AA7QlB;AAWA;;;AAKyB,iBCkCT,aAAA,CDlCS,OAAA,ECkCc,oBDlCd,CAAA,ECkCqC,gBDlCrC"}
@@ -0,0 +1,288 @@
1
+ import { EndpointOptions } from "@restatedev/restate-sdk";
2
+
3
+ //#region src/types.d.ts
4
+
5
+ /**
6
+ * The services to expose over the tunnel — the same shape `restate.serve`
7
+ * and `createEndpointHandler` accept (services, virtual objects, workflows).
8
+ */
9
+ type Services = EndpointOptions["services"];
10
+ /**
11
+ * TLS options for the outbound tunnel connection.
12
+ *
13
+ * Note: unlike a regular HTTP/2 client, the tunnel deliberately negotiates
14
+ * NO ALPN protocol ("tunnel is not normal h2" — the server clears its ALPN
15
+ * list); both sides speak HTTP/2 with prior knowledge after the TLS
16
+ * handshake. There is therefore no ALPN field here, and the package never
17
+ * sets one.
18
+ */
19
+ interface TunnelTlsOptions {
20
+ /**
21
+ * CA certificate(s) (PEM) to trust. Omit to use the system trust store —
22
+ * the right choice for Restate Cloud's public endpoints.
23
+ */
24
+ ca?: string | Buffer | Array<string | Buffer>;
25
+ /** Client certificate (PEM) for mutual TLS. */
26
+ cert?: string | Buffer;
27
+ /** Client key (PEM) for mutual TLS. */
28
+ key?: string | Buffer;
29
+ /**
30
+ * SNI / certificate-verification name. Defaults to the hostname being
31
+ * dialed (for region/SRV discovery, the SRV target hostname).
32
+ */
33
+ servername?: string;
34
+ /** Verify the server certificate. Default true. */
35
+ rejectUnauthorized?: boolean;
36
+ }
37
+ /**
38
+ * Options for {@link connectTunnel}.
39
+ *
40
+ * The identity and discovery options fall back to `RESTATE_INPROC_*`
41
+ * environment variables when not given (option > environment > throw):
42
+ * `tunnelName` ← `RESTATE_INPROC_TUNNEL_NAME`, `environmentId` ←
43
+ * `RESTATE_INPROC_ENVIRONMENT_ID`, `region` ← `RESTATE_INPROC_CLOUD_REGION`,
44
+ * `signingPublicKey` ← `RESTATE_INPROC_SIGNING_PUBLIC_KEY`, and `authToken`
45
+ * ← the file named by `RESTATE_INPROC_AUTH_TOKEN_FILE` (re-read on every
46
+ * reconnect, so rotations are picked up). The
47
+ * [restate-operator](https://github.com/restatedev/restate-operator)
48
+ * injects the first four into the pods of a `tunnelMode: in-process`
49
+ * RestateDeployment and registers the matching URL — there,
50
+ * `connectTunnel({ services })` plus a token-file Secret mount (named by
51
+ * `RESTATE_INPROC_AUTH_TOKEN_FILE`) is a complete configuration.
52
+ */
53
+ interface ConnectTunnelOptions {
54
+ /**
55
+ * Restate Cloud region (e.g. `"us"`, `"eu"`). Tunnel servers are
56
+ * discovered via a DNS SRV lookup of `tunnel.<region>.restate.cloud`,
57
+ * expanded to every resolved address — the engine holds **one tunnel
58
+ * connection per resolved tunnel server** (like the standalone client),
59
+ * and re-resolves every {@link resolveIntervalMs}, starting connections
60
+ * to servers that appear and tearing down connections to servers that
61
+ * vanish.
62
+ *
63
+ * Exactly one of `region`, `tunnelServersSrv` or `tunnelServers` must be
64
+ * set. When none is, `region` falls back to the
65
+ * `RESTATE_INPROC_CLOUD_REGION` environment variable.
66
+ */
67
+ region?: string;
68
+ /**
69
+ * A DNS SRV name to discover tunnel servers from, for environments whose
70
+ * SRV name doesn't follow the `tunnel.<region>.restate.cloud` template
71
+ * (the standalone client's `RESTATE_TUNNEL_SERVERS_SRV`). Same expansion
72
+ * and reconciliation semantics as `region`.
73
+ *
74
+ * Exactly one of `region`, `tunnelServersSrv` or `tunnelServers` must be
75
+ * set.
76
+ */
77
+ tunnelServersSrv?: string;
78
+ /**
79
+ * Explicit tunnel server addresses, instead of region-based discovery.
80
+ * Each entry is either `"host:port"` (TLS governed by the `tls` option)
81
+ * or a URL `"https://host:port"` / `"http://host:port"` (scheme selects
82
+ * TLS/plaintext for that server). The engine holds one tunnel connection
83
+ * per entry; the set is fixed (no re-resolution).
84
+ *
85
+ * Exactly one of `region`, `tunnelServersSrv` or `tunnelServers` must be
86
+ * set.
87
+ */
88
+ tunnelServers?: string[];
89
+ /**
90
+ * How often region-based discovery re-resolves the tunnel-server set.
91
+ * Default 30_000. (The Rust client re-resolves on DNS TTL expiry; Node
92
+ * does not expose record TTLs, so a fixed interval approximates it.)
93
+ * Ignored with explicit `tunnelServers`.
94
+ */
95
+ resolveIntervalMs?: number;
96
+ /**
97
+ * The Restate Cloud environment ID to tunnel to, including the `env_`
98
+ * prefix (e.g. `"env_201k0yd4rz8yftmd4awh1bajg4v"`).
99
+ *
100
+ * Falls back to the `RESTATE_INPROC_ENVIRONMENT_ID` environment variable.
101
+ */
102
+ environmentId?: string;
103
+ /**
104
+ * A Restate Cloud API key with the `Full` role (`key_...`), or a user
105
+ * JWT. Presented as `authorization: Bearer <token>` during the tunnel
106
+ * handshake; validated server-side.
107
+ *
108
+ * Falls back to the contents of the file named by the
109
+ * `RESTATE_INPROC_AUTH_TOKEN_FILE` environment variable — the right shape
110
+ * for a mounted Kubernetes Secret: the file is re-read on every reconnect,
111
+ * so a rotated token is picked up without a restart.
112
+ */
113
+ authToken?: string;
114
+ /**
115
+ * The environment's request-identity public key
116
+ * (`publickeyv1_<base58>`). Passed to the SDK's request-identity
117
+ * verification so every forwarded request is checked to genuinely come
118
+ * from your environment. Shown by Restate Cloud for your environment.
119
+ *
120
+ * Falls back to the `RESTATE_INPROC_SIGNING_PUBLIC_KEY` environment
121
+ * variable.
122
+ */
123
+ signingPublicKey?: string;
124
+ /**
125
+ * The deployment's identity: the rendezvous key both ends use to route.
126
+ * The tunnel server keys connections by `<environment>/<tunnelName>` and
127
+ * load-balances each proxied invocation across every connection
128
+ * registered under that key — so replicas of the *same* deployment must
129
+ * share one `tunnelName`, and distinct deployments must each have their
130
+ * own. It appears in the deployment registration URL, so it should be
131
+ * stable across restarts (e.g. `"greeter-v1"`).
132
+ *
133
+ * Falls back to the `RESTATE_INPROC_TUNNEL_NAME` environment variable
134
+ * (the restate-operator injects a per-revision name there).
135
+ */
136
+ tunnelName?: string;
137
+ /** The services to serve over the tunnel. */
138
+ services: Services;
139
+ /**
140
+ * Protocol mode for the SDK handler. Default `true` (`BIDI_STREAM`) —
141
+ * the tunnel is always HTTP/2, so full-duplex streaming is available.
142
+ */
143
+ bidirectional?: boolean;
144
+ /**
145
+ * Advertise graceful-drain support (`supports-drain: true`) in the
146
+ * handshake. Default `true`. When Restate Cloud rolls a tunnel node it
147
+ * sends `/_/drain-tunnel` to drain-capable connections: the engine then
148
+ * immediately opens a replacement connection while the old one keeps
149
+ * serving its in-flight invocations (bounded by {@link drainGraceMs}) —
150
+ * zero dropped requests across cloud rollovers. With `false`, the cloud
151
+ * simply closes the connection and in-flight invocations are retried by
152
+ * the Restate runtime after the redial.
153
+ */
154
+ supportsDrain?: boolean;
155
+ /**
156
+ * How long a draining connection may keep serving its in-flight
157
+ * invocations before being torn down. Default 120_000 (mirrors the
158
+ * standalone tunnel client).
159
+ */
160
+ drainGraceMs?: number;
161
+ /**
162
+ * Reconnect backoff: initial delay in milliseconds. Default 10.
163
+ * The delay grows by `reconnectFactor` per failed attempt (with jitter)
164
+ * up to `reconnectMaxMs`, and resets after a successful handshake.
165
+ */
166
+ reconnectInitialMs?: number;
167
+ /** Reconnect backoff: maximum delay in milliseconds. Default 120_000. */
168
+ reconnectMaxMs?: number;
169
+ /** Reconnect backoff: growth factor. Default 2. */
170
+ reconnectFactor?: number;
171
+ /**
172
+ * Deadline for establishing the TCP connection and completing the TLS
173
+ * handshake. Default 5_000 (mirrors the standalone tunnel client's
174
+ * connect timeout). Without it, a peer that accepts the connection but
175
+ * never completes TLS would stall reconnection indefinitely.
176
+ */
177
+ connectTimeoutMs?: number;
178
+ /**
179
+ * Deadline for the tunnel handshake (the server opening
180
+ * `/_/start-tunnel` and completing it with trailers). Default 5_000,
181
+ * mirroring the tunnel server's own handshake timeout.
182
+ */
183
+ handshakeTimeoutMs?: number;
184
+ /**
185
+ * Liveness watchdog: send an HTTP/2 PING every this many milliseconds.
186
+ * Default 75_000 (the tunnel protocol's keepalive cadence).
187
+ */
188
+ pingIntervalMs?: number;
189
+ /** Watchdog: how long to wait for a PING ack. Default 10_000. */
190
+ pingTimeoutMs?: number;
191
+ /**
192
+ * Watchdog: consecutive missed PINGs before the connection is declared
193
+ * dead and redialed. Default 2.
194
+ */
195
+ pingMaxMissed?: number;
196
+ /**
197
+ * Maximum concurrent HTTP/2 streams (in-flight invocations) per
198
+ * connection. Default 4096 (Node's default of 100 is far too low for a
199
+ * deployment serving many concurrent invocations).
200
+ */
201
+ maxConcurrentStreams?: number;
202
+ /**
203
+ * Per-connection HTTP/2 flow-control window in bytes. Default 16 MiB
204
+ * (Node's 64 KiB default throttles aggregate throughput).
205
+ */
206
+ connectionWindowSize?: number;
207
+ /**
208
+ * Node http2 per-session memory cap in MiB. Default 256 (Node's 10 MiB
209
+ * default makes the session reject work under load).
210
+ */
211
+ maxSessionMemory?: number;
212
+ /**
213
+ * TLS for the outbound connection. Default `true` (system trust, SNI =
214
+ * dialed host, and — deliberately — NO ALPN). Pass `false` only for
215
+ * plaintext dev/test setups, or an object for a private CA / mTLS.
216
+ */
217
+ tls?: boolean | TunnelTlsOptions;
218
+ /** Abort to stop reconnecting and close the tunnel (same as `close()`). */
219
+ signal?: AbortSignal;
220
+ /** Diagnostic logger. Default: silent. */
221
+ logger?: (message: string) => void;
222
+ }
223
+ /**
224
+ * Handle returned by {@link connectTunnel}.
225
+ */
226
+ interface TunnelConnection {
227
+ /** Stop reconnecting, close the current connection, and wait for teardown. */
228
+ close(): Promise<void>;
229
+ /** Number of successful tunnel handshakes since `connectTunnel` was called. */
230
+ readonly connectionCount: number;
231
+ /**
232
+ * The tunnel name confirmed by the server in the most recent successful
233
+ * handshake. `undefined` until the first handshake completes.
234
+ */
235
+ readonly tunnelName: string | undefined;
236
+ /**
237
+ * The public proxy **base** URL for this tunnel
238
+ * (`<proxy-host>/<env-id>/<tunnel-name>`), learned from the most recent
239
+ * successful handshake. The deployment registration URL is this base plus
240
+ * a `/<scheme>/<host>/<port>` destination segment — for an in-process
241
+ * deployment the destination is vestigial, e.g.
242
+ * `${proxyUrl}/http/in-process/9080`. Registering the bare base URL will
243
+ * not route.
244
+ */
245
+ readonly proxyUrl: string | undefined;
246
+ /** The tunnel server URL, learned from the most recent successful handshake. */
247
+ readonly tunnelUrl: string | undefined;
248
+ /**
249
+ * The full deployment registration URL:
250
+ * `<proxyUrl>/http/in-process/9080/` — register this with
251
+ * `restate dep register <url>` (or the UI) once the tunnel is
252
+ * {@link ready}. `undefined` until the first successful handshake.
253
+ *
254
+ * The `/http/in-process/9080/` destination segment is a constant: an
255
+ * in-process tunnel terminates at this very process, so the destination
256
+ * is never dialed and plays no routing role — the deployment's identity
257
+ * is the `tunnelName` earlier in the path.
258
+ *
259
+ * Built from the handshake-advertised proxy URL; on BYOC clusters where
260
+ * Restate reaches the proxy via a cluster-internal address instead,
261
+ * substitute that base and keep the path.
262
+ */
263
+ readonly deploymentUrl: string | undefined;
264
+ /**
265
+ * Set when the tunnel stopped on a non-retryable failure (e.g. the server
266
+ * answered `unauthorized` or `bad-tunnel-name`). Once set, the tunnel no
267
+ * longer reconnects.
268
+ */
269
+ readonly error: Error | undefined;
270
+ /**
271
+ * Resolves when the first tunnel handshake succeeds; rejects if the
272
+ * tunnel stops on a non-retryable failure before ever connecting.
273
+ * Useful for readiness checks; safe to ignore.
274
+ */
275
+ readonly ready: Promise<void>;
276
+ }
277
+ //#endregion
278
+ //#region src/connect.d.ts
279
+ /**
280
+ * Connect this deployment to a Restate Cloud tunnel and serve `services`
281
+ * over it. Returns immediately; connection management runs in the
282
+ * background until `close()` (or the `signal`) stops it. See
283
+ * {@link TunnelConnection.ready} to await the first successful handshake.
284
+ */
285
+ declare function connectTunnel(options: ConnectTunnelOptions): TunnelConnection;
286
+ //#endregion
287
+ export { type ConnectTunnelOptions, type Services, type TunnelConnection, type TunnelTlsOptions, connectTunnel };
288
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/connect.ts"],"sourcesContent":[],"mappings":";;;;;;AAmBA;AAWA;AAKgB,KAhBJ,QAAA,GAAW,eAgBP,CAAA,UAAA,CAAA;;;;;;AA8BhB;;;;AAsKsB,UAzML,gBAAA,CAyMK;EAQL;;;;EAiDQ,EAAA,CAAA,EAAA,MAAA,GA7PT,MA6PS,GA7PA,KA6PA,CAAA,MAAA,GA7Pe,MA6Pf,CAAA;;kBA3PP;;ECgCF,GAAA,CAAA,EAAA,MAAA,GD9BC,MC8BY;;;;;;;;;;;;;;;;;;;;;;;;;UDJZ,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqFL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA+EM;;WAEP;;;;;;;UAQM,gBAAA;;WAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAyCO;;;;;;kBAMA;;;;;;AA7QlB;AAWA;;;AAKyB,iBCkCT,aAAA,CDlCS,OAAA,ECkCc,oBDlCd,CAAA,ECkCqC,gBDlCrC"}