@restatedev/restate-sdk 1.18.0 → 1.18.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.
Files changed (79) hide show
  1. package/dist/common_api.d.cts.map +1 -1
  2. package/dist/common_api.d.ts.map +1 -1
  3. package/dist/context.d.cts +3 -0
  4. package/dist/context.d.cts.map +1 -1
  5. package/dist/context.d.ts +3 -0
  6. package/dist/context.d.ts.map +1 -1
  7. package/dist/context.js.map +1 -1
  8. package/dist/context_impl.cjs +8 -3
  9. package/dist/context_impl.js +8 -3
  10. package/dist/context_impl.js.map +1 -1
  11. package/dist/endpoint/connect/env.cjs +206 -0
  12. package/dist/endpoint/connect/env.js +199 -0
  13. package/dist/endpoint/connect/env.js.map +1 -0
  14. package/dist/endpoint/connect/index.cjs +113 -0
  15. package/dist/endpoint/connect/index.d.cts +41 -0
  16. package/dist/endpoint/connect/index.d.cts.map +1 -0
  17. package/dist/endpoint/connect/index.d.ts +41 -0
  18. package/dist/endpoint/connect/index.d.ts.map +1 -0
  19. package/dist/endpoint/connect/index.js +114 -0
  20. package/dist/endpoint/connect/index.js.map +1 -0
  21. package/dist/endpoint/connect/key.cjs +53 -0
  22. package/dist/endpoint/connect/key.js +53 -0
  23. package/dist/endpoint/connect/key.js.map +1 -0
  24. package/dist/endpoint/tunnel/backoff.cjs +37 -0
  25. package/dist/endpoint/tunnel/backoff.js +36 -0
  26. package/dist/endpoint/tunnel/backoff.js.map +1 -0
  27. package/dist/endpoint/tunnel/connection.cjs +604 -0
  28. package/dist/endpoint/tunnel/connection.js +600 -0
  29. package/dist/endpoint/tunnel/connection.js.map +1 -0
  30. package/dist/endpoint/tunnel/draining.cjs +40 -0
  31. package/dist/endpoint/tunnel/draining.js +40 -0
  32. package/dist/endpoint/tunnel/draining.js.map +1 -0
  33. package/dist/endpoint/tunnel/engine.cjs +264 -0
  34. package/dist/endpoint/tunnel/engine.d.cts +1 -0
  35. package/dist/endpoint/tunnel/engine.d.ts +1 -0
  36. package/dist/endpoint/tunnel/engine.js +265 -0
  37. package/dist/endpoint/tunnel/engine.js.map +1 -0
  38. package/dist/endpoint/tunnel/forwarded.cjs +34 -0
  39. package/dist/endpoint/tunnel/forwarded.js +34 -0
  40. package/dist/endpoint/tunnel/forwarded.js.map +1 -0
  41. package/dist/endpoint/tunnel/handshake.cjs +98 -0
  42. package/dist/endpoint/tunnel/handshake.js +97 -0
  43. package/dist/endpoint/tunnel/handshake.js.map +1 -0
  44. package/dist/endpoint/tunnel/index.d.cts +3 -0
  45. package/dist/endpoint/tunnel/index.d.ts +3 -0
  46. package/dist/endpoint/tunnel/options.cjs +168 -0
  47. package/dist/endpoint/tunnel/options.d.cts +2 -0
  48. package/dist/endpoint/tunnel/options.d.ts +2 -0
  49. package/dist/endpoint/tunnel/options.js +161 -0
  50. package/dist/endpoint/tunnel/options.js.map +1 -0
  51. package/dist/endpoint/tunnel/supervisor.cjs +180 -0
  52. package/dist/endpoint/tunnel/supervisor.js +181 -0
  53. package/dist/endpoint/tunnel/supervisor.js.map +1 -0
  54. package/dist/endpoint/tunnel/targets.cjs +110 -0
  55. package/dist/endpoint/tunnel/targets.js +107 -0
  56. package/dist/endpoint/tunnel/targets.js.map +1 -0
  57. package/dist/endpoint/tunnel/types.d.cts +270 -0
  58. package/dist/endpoint/tunnel/types.d.cts.map +1 -0
  59. package/dist/endpoint/tunnel/types.d.ts +270 -0
  60. package/dist/endpoint/tunnel/types.d.ts.map +1 -0
  61. package/dist/endpoint/tunnel/util.cjs +67 -0
  62. package/dist/endpoint/tunnel/util.js +65 -0
  63. package/dist/endpoint/tunnel/util.js.map +1 -0
  64. package/dist/index.cjs +2 -0
  65. package/dist/index.d.cts +3 -1
  66. package/dist/index.d.ts +3 -1
  67. package/dist/index.js +2 -1
  68. package/dist/node.cjs +2 -0
  69. package/dist/node.d.cts +4 -1
  70. package/dist/node.d.cts.map +1 -1
  71. package/dist/node.d.ts +4 -1
  72. package/dist/node.d.ts.map +1 -1
  73. package/dist/node.js +2 -1
  74. package/dist/node.js.map +1 -1
  75. package/dist/package.cjs +1 -1
  76. package/dist/package.js +1 -1
  77. package/dist/package.js.map +1 -1
  78. package/dist/types/rpc.d.cts.map +1 -1
  79. package/package.json +2 -2
@@ -0,0 +1,270 @@
1
+ import { EndpointOptions } from "../types.cjs";
2
+ import { Duration } from "@restatedev/restate-sdk-core";
3
+
4
+ //#region src/endpoint/tunnel/types.d.ts
5
+
6
+ /**
7
+ * TLS options for the outbound connection.
8
+ *
9
+ * The connection always offers ALPN `h2` and requires TLS peers to negotiate
10
+ * it; omit these options to use the system trust store and SNI for the dialed
11
+ * host. There is no user-facing ALPN option because the protocol requires
12
+ * HTTP/2.
13
+ */
14
+ interface ConnectTlsOptions {
15
+ /**
16
+ * CA certificate(s) (PEM) to trust. Omit to use the system trust store —
17
+ * the right choice for Restate Cloud's public endpoints.
18
+ */
19
+ ca?: string | Buffer | Array<string | Buffer>;
20
+ /** Client certificate (PEM) for mutual TLS. */
21
+ cert?: string | Buffer;
22
+ /** Client key (PEM) for mutual TLS. */
23
+ key?: string | Buffer;
24
+ /**
25
+ * SNI / certificate-verification name. Defaults to the hostname being
26
+ * dialed (for DNS SRV discovery, the SRV target hostname).
27
+ */
28
+ servername?: string;
29
+ /** Verify the server certificate. Default true. */
30
+ rejectUnauthorized?: boolean;
31
+ }
32
+ /**
33
+ * Reconnect retry policy, the same shape as the invocation and client retry
34
+ * policies: a jittered exponential backoff between attempts, reset after a
35
+ * connection stays up long enough to count as stable. Intervals accept a
36
+ * {@link Duration} or a number of milliseconds.
37
+ *
38
+ * Unlike those policies the reconnect loop is unbounded by default — a
39
+ * deployment keeps trying until Restate Cloud is reachable again — so
40
+ * {@link maxAttempts} and {@link maxDuration} default to `false`. A bound is
41
+ * counted per server (and for DNS discovery itself); reaching it stops the
42
+ * deployment only when no other connection is alive, otherwise that server
43
+ * is dropped until discovery brings it back.
44
+ */
45
+ interface ReconnectRetryPolicy {
46
+ /**
47
+ * Max number of attempts (including the initial) in a row without a stable
48
+ * connection, before giving up. Giving up is a non-retryable stop: the
49
+ * connection's `ready`, `close()` and `shutdown()` reject with the reason.
50
+ *
51
+ * Defaults to `false`: no attempt bound.
52
+ */
53
+ maxAttempts?: number | false;
54
+ /**
55
+ * Max total duration without a stable connection, measured from the first
56
+ * failed attempt, before giving up. If a number is provided, it is
57
+ * interpreted as milliseconds.
58
+ *
59
+ * Defaults to `false`: no duration bound.
60
+ */
61
+ maxDuration?: Duration | number | false;
62
+ /**
63
+ * Initial backoff interval. If a number is provided, it is interpreted as
64
+ * milliseconds. Defaults to `10` milliseconds.
65
+ */
66
+ initialInterval?: Duration | number;
67
+ /**
68
+ * Maximum backoff interval. If a number is provided, it is interpreted as
69
+ * milliseconds. Defaults to `120_000` milliseconds.
70
+ */
71
+ maxInterval?: Duration | number;
72
+ /**
73
+ * Exponentiation factor to use when computing the next retry delay.
74
+ * Defaults to `2`.
75
+ */
76
+ exponentiationFactor?: number;
77
+ }
78
+ /**
79
+ * Options for {@link connect}.
80
+ *
81
+ * A usual connect setup requires 3 configuration options:
82
+ *
83
+ * * The `services` to expose
84
+ * * The {@link name} (or env `RESTATE_CONNECT_NAME`) of the deployment, used to identify this version of the code.
85
+ * * The {@link key} (or `RESTATE_CONNECT_KEY`) required to connect to Restate Cloud/BYOC
86
+ */
87
+ interface ConnectOptions extends EndpointOptions {
88
+ /**
89
+ * Required: The deployment name, e.g. `"greeter-v1"`: the identity you register
90
+ * (`restate deployments register connect://<name>`). Restate Cloud/BYOC routes by
91
+ * `<environment>/<name>` and load-balances across every connection under
92
+ * it, so replicas of the same deployment share one name and distinct
93
+ * deployments each have their own. Letters, digits, `.`, `_` and `-`.
94
+ *
95
+ * Also configurable via env `RESTATE_CONNECT_NAME`.
96
+ */
97
+ name?: string;
98
+ /**
99
+ * The connect key from the Cloud UI -> Development → Configure SDK.
100
+ *
101
+ * Also configurable via env `RESTATE_CONNECT_KEY`.
102
+ */
103
+ key?: string;
104
+ /**
105
+ * Advanced connection options.
106
+ */
107
+ connection?: ConnectionOptions;
108
+ }
109
+ /**
110
+ * The {@link ConnectOptions.connection} tuning: server discovery, the worker
111
+ * id, reconnect and drain behaviour, HTTP/2 limits, TLS. Every option has a
112
+ * default that fits Restate Cloud; most deployments set none of them.
113
+ */
114
+ interface ConnectionOptions {
115
+ /**
116
+ * A DNS SRV name to discover the servers to connect to, instead of the one
117
+ * derived from the key (`tunnel.<region domain>`, or its `tunnel-srv`
118
+ * parameter). For environments with a custom domain; the Cloud UI puts it
119
+ * in the key when needed, so this is rarely set by hand. Servers are
120
+ * discovered via a DNS SRV lookup expanded to every resolved address — the
121
+ * engine holds **one connection per resolved server** and re-resolves every
122
+ * {@link resolveIntervalMs}, starting connections to
123
+ * servers that appear and tearing down connections to servers that vanish.
124
+ *
125
+ * At most one of `serversSrv` and `servers` may be set.
126
+ */
127
+ serversSrv?: string;
128
+ /**
129
+ * Explicit server addresses, instead of DNS discovery. Each entry is either
130
+ * `"host:port"` (TLS governed by the `tls` option) or a URL
131
+ * `"https://host:port"` / `"http://host:port"` (scheme selects TLS/plaintext
132
+ * for that server). One connection per entry; the set is fixed (no
133
+ * re-resolution). Private networks and tests.
134
+ *
135
+ * At most one of `serversSrv` and `servers` may be set.
136
+ */
137
+ servers?: string[];
138
+ /**
139
+ * Stable diagnostic identifier for this SDK worker/process. Restate Cloud
140
+ * can include it in routing and failure logs so operators can grep
141
+ * server-side events against SDK-side logs. Defaults to a hostname-based
142
+ * id with a short random suffix that is stable for this process. Advisory
143
+ * only: it is sent in the handshake for diagnostics, not used for
144
+ * authentication.
145
+ */
146
+ workerId?: string;
147
+ /**
148
+ * How often DNS SRV discovery re-resolves the server set. Default 30_000.
149
+ * (The Rust client re-resolves on DNS TTL expiry; Node does not expose
150
+ * record TTLs, so a fixed interval approximates it.) Ignored with explicit
151
+ * server addresses.
152
+ */
153
+ resolveIntervalMs?: number;
154
+ /**
155
+ * How long a draining connection may keep serving its in-flight
156
+ * invocations before being torn down. Default 120_000.
157
+ */
158
+ drainGraceMs?: number;
159
+ /**
160
+ * Automatic graceful shutdown on process signals. **On by default**: the
161
+ * engine installs a one-shot handler for each signal (default `SIGTERM`)
162
+ * that calls `shutdown()`. If multiple connections in the same process
163
+ * register for a signal, the shared process-level handler waits for all of
164
+ * them before calling `process.exit(0)` once draining completes (or the
165
+ * grace elapses) — so an operator-managed deployment gets
166
+ * zero-dropped-invocation rollouts with no wiring. In Kubernetes, set
167
+ * `terminationGracePeriodSeconds` to at least the drain grace plus the
168
+ * handler slack you want to preserve. The handlers are removed when the
169
+ * connection closes.
170
+ *
171
+ * Pass `false` to opt out entirely — e.g. to manage signals and process
172
+ * exit yourself and call `shutdown()` by hand. Pass an object to choose the
173
+ * signals and grace, or `true` for the defaults.
174
+ */
175
+ gracefulShutdown?: boolean | {
176
+ signals?: NodeJS.Signals[];
177
+ graceMs?: number;
178
+ };
179
+ /**
180
+ * Reconnect backoff policy: jittered exponential backoff applied between
181
+ * reconnect attempts (10ms → 120s by default), reset after a stable
182
+ * connection. See {@link ReconnectRetryPolicy}.
183
+ */
184
+ reconnectRetryPolicy?: ReconnectRetryPolicy;
185
+ /**
186
+ * Deadline for establishing the TCP connection and completing the TLS
187
+ * handshake. Default 5_000. Without it, a peer that accepts the connection
188
+ * but never completes TLS would stall reconnection indefinitely.
189
+ */
190
+ connectTimeoutMs?: number;
191
+ /**
192
+ * Deadline for the handshake with Restate Cloud. Default 5_000, mirroring
193
+ * the server's own handshake timeout.
194
+ */
195
+ handshakeTimeoutMs?: number;
196
+ /**
197
+ * Liveness watchdog: send an HTTP/2 PING every this many milliseconds.
198
+ * Default 75_000.
199
+ */
200
+ pingIntervalMs?: number;
201
+ /** Watchdog: how long to wait for a PING ack. Default 10_000. */
202
+ pingTimeoutMs?: number;
203
+ /**
204
+ * Watchdog: consecutive missed PINGs before the connection is declared
205
+ * dead and redialed. Default 2.
206
+ */
207
+ pingMaxMissed?: number;
208
+ /**
209
+ * Maximum concurrent HTTP/2 streams (in-flight invocations) per
210
+ * connection. Default 4096 (Node's default of 100 is far too low for a
211
+ * deployment serving many concurrent invocations).
212
+ */
213
+ maxConcurrentStreams?: number;
214
+ /**
215
+ * Per-connection HTTP/2 flow-control window in bytes. Default 16 MiB
216
+ * (Node's 64 KiB default throttles aggregate throughput).
217
+ */
218
+ connectionWindowSize?: number;
219
+ /**
220
+ * Node http2 per-session memory cap in MiB. Default 256 (Node's 10 MiB
221
+ * default makes the session reject work under load).
222
+ */
223
+ maxSessionMemory?: number;
224
+ /**
225
+ * TLS for the outbound connection. Default `true` (system trust, SNI =
226
+ * dialed host, ALPN `h2`). Pass `false` only for plaintext dev/test setups,
227
+ * or an object for a private CA / mTLS.
228
+ */
229
+ tls?: boolean | ConnectTlsOptions;
230
+ /** Abort to stop reconnecting and close the connection (same as `close()`). */
231
+ signal?: AbortSignal;
232
+ }
233
+ /**
234
+ * Handle returned by {@link connect}: the outbound connection to Restate
235
+ * Cloud serving your services.
236
+ */
237
+ interface Connection {
238
+ /**
239
+ * Resolves when the first handshake succeeds (the deployment is reachable
240
+ * from Restate Cloud and can be registered); rejects if the connection
241
+ * stops on a non-retryable failure before ever connecting. Useful for
242
+ * readiness checks; safe to ignore.
243
+ */
244
+ readonly ready: Promise<void>;
245
+ /** The deployment name, as configured. */
246
+ readonly name: string;
247
+ /**
248
+ * Stop reconnecting, close the current connections, and wait for teardown.
249
+ * Rejects with the fatal error if the connection had already stopped on a
250
+ * non-retryable failure (e.g. Restate Cloud rejected the key or the name).
251
+ */
252
+ close(): Promise<void>;
253
+ /**
254
+ * Gracefully drain, then stop. Proactively sends HTTP/2 GOAWAY so Restate
255
+ * Cloud stops opening new streams, refuses any raced streams with a drain
256
+ * sentinel, lets in-flight invocations finish — bounded by `graceMs`
257
+ * (default {@link ConnectionOptions.drainGraceMs}) — and then closes the
258
+ * session gracefully. If the grace elapses first, the session/socket are
259
+ * force-closed. The default {@link ConnectionOptions.gracefulShutdown}
260
+ * handler wires this to `SIGTERM`; {@link close} is the abrupt alternative.
261
+ * Rejects like {@link close} if the connection had already stopped on a
262
+ * non-retryable failure.
263
+ */
264
+ shutdown(opts?: {
265
+ graceMs?: number;
266
+ }): Promise<void>;
267
+ }
268
+ //#endregion
269
+ export { ConnectOptions, ConnectTlsOptions, Connection, ConnectionOptions, ReconnectRetryPolicy };
270
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../../src/endpoint/tunnel/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAwBA;;;;;;AASuB,UATN,iBAAA,CASM;EAuBN;;;;EA0BO,EAAA,CAAA,EAAA,MAAA,GArDR,MAqDQ,GArDC,KAqDD,CAAA,MAAA,GArDgB,MAqDhB,CAAA;EAiBP;EA4BA,IAAA,CAAA,EAAA,MAAA,GAhGC,MAgGgB;EA6DS;EAMlB,GAAA,CAAA,EAAA,MAAA,GAjKR,MAiKQ;EA6CP;;;AASlB;EAOkB,UAAA,CAAA,EAAA,MAAA;EAQP;EAY8B,kBAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;UA3NxB,oBAAA;;;;;;;;;;;;;;;;gBAgBD;;;;;oBAKI;;;;;gBAKJ;;;;;;;;;;;;;;;;UAiBC,cAAA,SAAuB;;;;;;;;;;;;;;;;;;;;eAoBzB;;;;;;;UAQE,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6D0B,MAAA,CAAO;;;;;;;;yBAMzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6CP;;WAEP;;;;;;UAOM,UAAA;;;;;;;kBAOC;;;;;;;;WAQP;;;;;;;;;;;;;;MAY8B"}
@@ -0,0 +1,270 @@
1
+ import { EndpointOptions } from "../types.js";
2
+ import { Duration } from "@restatedev/restate-sdk-core";
3
+
4
+ //#region src/endpoint/tunnel/types.d.ts
5
+
6
+ /**
7
+ * TLS options for the outbound connection.
8
+ *
9
+ * The connection always offers ALPN `h2` and requires TLS peers to negotiate
10
+ * it; omit these options to use the system trust store and SNI for the dialed
11
+ * host. There is no user-facing ALPN option because the protocol requires
12
+ * HTTP/2.
13
+ */
14
+ interface ConnectTlsOptions {
15
+ /**
16
+ * CA certificate(s) (PEM) to trust. Omit to use the system trust store —
17
+ * the right choice for Restate Cloud's public endpoints.
18
+ */
19
+ ca?: string | Buffer | Array<string | Buffer>;
20
+ /** Client certificate (PEM) for mutual TLS. */
21
+ cert?: string | Buffer;
22
+ /** Client key (PEM) for mutual TLS. */
23
+ key?: string | Buffer;
24
+ /**
25
+ * SNI / certificate-verification name. Defaults to the hostname being
26
+ * dialed (for DNS SRV discovery, the SRV target hostname).
27
+ */
28
+ servername?: string;
29
+ /** Verify the server certificate. Default true. */
30
+ rejectUnauthorized?: boolean;
31
+ }
32
+ /**
33
+ * Reconnect retry policy, the same shape as the invocation and client retry
34
+ * policies: a jittered exponential backoff between attempts, reset after a
35
+ * connection stays up long enough to count as stable. Intervals accept a
36
+ * {@link Duration} or a number of milliseconds.
37
+ *
38
+ * Unlike those policies the reconnect loop is unbounded by default — a
39
+ * deployment keeps trying until Restate Cloud is reachable again — so
40
+ * {@link maxAttempts} and {@link maxDuration} default to `false`. A bound is
41
+ * counted per server (and for DNS discovery itself); reaching it stops the
42
+ * deployment only when no other connection is alive, otherwise that server
43
+ * is dropped until discovery brings it back.
44
+ */
45
+ interface ReconnectRetryPolicy {
46
+ /**
47
+ * Max number of attempts (including the initial) in a row without a stable
48
+ * connection, before giving up. Giving up is a non-retryable stop: the
49
+ * connection's `ready`, `close()` and `shutdown()` reject with the reason.
50
+ *
51
+ * Defaults to `false`: no attempt bound.
52
+ */
53
+ maxAttempts?: number | false;
54
+ /**
55
+ * Max total duration without a stable connection, measured from the first
56
+ * failed attempt, before giving up. If a number is provided, it is
57
+ * interpreted as milliseconds.
58
+ *
59
+ * Defaults to `false`: no duration bound.
60
+ */
61
+ maxDuration?: Duration | number | false;
62
+ /**
63
+ * Initial backoff interval. If a number is provided, it is interpreted as
64
+ * milliseconds. Defaults to `10` milliseconds.
65
+ */
66
+ initialInterval?: Duration | number;
67
+ /**
68
+ * Maximum backoff interval. If a number is provided, it is interpreted as
69
+ * milliseconds. Defaults to `120_000` milliseconds.
70
+ */
71
+ maxInterval?: Duration | number;
72
+ /**
73
+ * Exponentiation factor to use when computing the next retry delay.
74
+ * Defaults to `2`.
75
+ */
76
+ exponentiationFactor?: number;
77
+ }
78
+ /**
79
+ * Options for {@link connect}.
80
+ *
81
+ * A usual connect setup requires 3 configuration options:
82
+ *
83
+ * * The `services` to expose
84
+ * * The {@link name} (or env `RESTATE_CONNECT_NAME`) of the deployment, used to identify this version of the code.
85
+ * * The {@link key} (or `RESTATE_CONNECT_KEY`) required to connect to Restate Cloud/BYOC
86
+ */
87
+ interface ConnectOptions extends EndpointOptions {
88
+ /**
89
+ * Required: The deployment name, e.g. `"greeter-v1"`: the identity you register
90
+ * (`restate deployments register connect://<name>`). Restate Cloud/BYOC routes by
91
+ * `<environment>/<name>` and load-balances across every connection under
92
+ * it, so replicas of the same deployment share one name and distinct
93
+ * deployments each have their own. Letters, digits, `.`, `_` and `-`.
94
+ *
95
+ * Also configurable via env `RESTATE_CONNECT_NAME`.
96
+ */
97
+ name?: string;
98
+ /**
99
+ * The connect key from the Cloud UI -> Development → Configure SDK.
100
+ *
101
+ * Also configurable via env `RESTATE_CONNECT_KEY`.
102
+ */
103
+ key?: string;
104
+ /**
105
+ * Advanced connection options.
106
+ */
107
+ connection?: ConnectionOptions;
108
+ }
109
+ /**
110
+ * The {@link ConnectOptions.connection} tuning: server discovery, the worker
111
+ * id, reconnect and drain behaviour, HTTP/2 limits, TLS. Every option has a
112
+ * default that fits Restate Cloud; most deployments set none of them.
113
+ */
114
+ interface ConnectionOptions {
115
+ /**
116
+ * A DNS SRV name to discover the servers to connect to, instead of the one
117
+ * derived from the key (`tunnel.<region domain>`, or its `tunnel-srv`
118
+ * parameter). For environments with a custom domain; the Cloud UI puts it
119
+ * in the key when needed, so this is rarely set by hand. Servers are
120
+ * discovered via a DNS SRV lookup expanded to every resolved address — the
121
+ * engine holds **one connection per resolved server** and re-resolves every
122
+ * {@link resolveIntervalMs}, starting connections to
123
+ * servers that appear and tearing down connections to servers that vanish.
124
+ *
125
+ * At most one of `serversSrv` and `servers` may be set.
126
+ */
127
+ serversSrv?: string;
128
+ /**
129
+ * Explicit server addresses, instead of DNS discovery. Each entry is either
130
+ * `"host:port"` (TLS governed by the `tls` option) or a URL
131
+ * `"https://host:port"` / `"http://host:port"` (scheme selects TLS/plaintext
132
+ * for that server). One connection per entry; the set is fixed (no
133
+ * re-resolution). Private networks and tests.
134
+ *
135
+ * At most one of `serversSrv` and `servers` may be set.
136
+ */
137
+ servers?: string[];
138
+ /**
139
+ * Stable diagnostic identifier for this SDK worker/process. Restate Cloud
140
+ * can include it in routing and failure logs so operators can grep
141
+ * server-side events against SDK-side logs. Defaults to a hostname-based
142
+ * id with a short random suffix that is stable for this process. Advisory
143
+ * only: it is sent in the handshake for diagnostics, not used for
144
+ * authentication.
145
+ */
146
+ workerId?: string;
147
+ /**
148
+ * How often DNS SRV discovery re-resolves the server set. Default 30_000.
149
+ * (The Rust client re-resolves on DNS TTL expiry; Node does not expose
150
+ * record TTLs, so a fixed interval approximates it.) Ignored with explicit
151
+ * server addresses.
152
+ */
153
+ resolveIntervalMs?: number;
154
+ /**
155
+ * How long a draining connection may keep serving its in-flight
156
+ * invocations before being torn down. Default 120_000.
157
+ */
158
+ drainGraceMs?: number;
159
+ /**
160
+ * Automatic graceful shutdown on process signals. **On by default**: the
161
+ * engine installs a one-shot handler for each signal (default `SIGTERM`)
162
+ * that calls `shutdown()`. If multiple connections in the same process
163
+ * register for a signal, the shared process-level handler waits for all of
164
+ * them before calling `process.exit(0)` once draining completes (or the
165
+ * grace elapses) — so an operator-managed deployment gets
166
+ * zero-dropped-invocation rollouts with no wiring. In Kubernetes, set
167
+ * `terminationGracePeriodSeconds` to at least the drain grace plus the
168
+ * handler slack you want to preserve. The handlers are removed when the
169
+ * connection closes.
170
+ *
171
+ * Pass `false` to opt out entirely — e.g. to manage signals and process
172
+ * exit yourself and call `shutdown()` by hand. Pass an object to choose the
173
+ * signals and grace, or `true` for the defaults.
174
+ */
175
+ gracefulShutdown?: boolean | {
176
+ signals?: NodeJS.Signals[];
177
+ graceMs?: number;
178
+ };
179
+ /**
180
+ * Reconnect backoff policy: jittered exponential backoff applied between
181
+ * reconnect attempts (10ms → 120s by default), reset after a stable
182
+ * connection. See {@link ReconnectRetryPolicy}.
183
+ */
184
+ reconnectRetryPolicy?: ReconnectRetryPolicy;
185
+ /**
186
+ * Deadline for establishing the TCP connection and completing the TLS
187
+ * handshake. Default 5_000. Without it, a peer that accepts the connection
188
+ * but never completes TLS would stall reconnection indefinitely.
189
+ */
190
+ connectTimeoutMs?: number;
191
+ /**
192
+ * Deadline for the handshake with Restate Cloud. Default 5_000, mirroring
193
+ * the server's own handshake timeout.
194
+ */
195
+ handshakeTimeoutMs?: number;
196
+ /**
197
+ * Liveness watchdog: send an HTTP/2 PING every this many milliseconds.
198
+ * Default 75_000.
199
+ */
200
+ pingIntervalMs?: number;
201
+ /** Watchdog: how long to wait for a PING ack. Default 10_000. */
202
+ pingTimeoutMs?: number;
203
+ /**
204
+ * Watchdog: consecutive missed PINGs before the connection is declared
205
+ * dead and redialed. Default 2.
206
+ */
207
+ pingMaxMissed?: number;
208
+ /**
209
+ * Maximum concurrent HTTP/2 streams (in-flight invocations) per
210
+ * connection. Default 4096 (Node's default of 100 is far too low for a
211
+ * deployment serving many concurrent invocations).
212
+ */
213
+ maxConcurrentStreams?: number;
214
+ /**
215
+ * Per-connection HTTP/2 flow-control window in bytes. Default 16 MiB
216
+ * (Node's 64 KiB default throttles aggregate throughput).
217
+ */
218
+ connectionWindowSize?: number;
219
+ /**
220
+ * Node http2 per-session memory cap in MiB. Default 256 (Node's 10 MiB
221
+ * default makes the session reject work under load).
222
+ */
223
+ maxSessionMemory?: number;
224
+ /**
225
+ * TLS for the outbound connection. Default `true` (system trust, SNI =
226
+ * dialed host, ALPN `h2`). Pass `false` only for plaintext dev/test setups,
227
+ * or an object for a private CA / mTLS.
228
+ */
229
+ tls?: boolean | ConnectTlsOptions;
230
+ /** Abort to stop reconnecting and close the connection (same as `close()`). */
231
+ signal?: AbortSignal;
232
+ }
233
+ /**
234
+ * Handle returned by {@link connect}: the outbound connection to Restate
235
+ * Cloud serving your services.
236
+ */
237
+ interface Connection {
238
+ /**
239
+ * Resolves when the first handshake succeeds (the deployment is reachable
240
+ * from Restate Cloud and can be registered); rejects if the connection
241
+ * stops on a non-retryable failure before ever connecting. Useful for
242
+ * readiness checks; safe to ignore.
243
+ */
244
+ readonly ready: Promise<void>;
245
+ /** The deployment name, as configured. */
246
+ readonly name: string;
247
+ /**
248
+ * Stop reconnecting, close the current connections, and wait for teardown.
249
+ * Rejects with the fatal error if the connection had already stopped on a
250
+ * non-retryable failure (e.g. Restate Cloud rejected the key or the name).
251
+ */
252
+ close(): Promise<void>;
253
+ /**
254
+ * Gracefully drain, then stop. Proactively sends HTTP/2 GOAWAY so Restate
255
+ * Cloud stops opening new streams, refuses any raced streams with a drain
256
+ * sentinel, lets in-flight invocations finish — bounded by `graceMs`
257
+ * (default {@link ConnectionOptions.drainGraceMs}) — and then closes the
258
+ * session gracefully. If the grace elapses first, the session/socket are
259
+ * force-closed. The default {@link ConnectionOptions.gracefulShutdown}
260
+ * handler wires this to `SIGTERM`; {@link close} is the abrupt alternative.
261
+ * Rejects like {@link close} if the connection had already stopped on a
262
+ * non-retryable failure.
263
+ */
264
+ shutdown(opts?: {
265
+ graceMs?: number;
266
+ }): Promise<void>;
267
+ }
268
+ //#endregion
269
+ export { ConnectOptions, ConnectTlsOptions, Connection, ConnectionOptions, ReconnectRetryPolicy };
270
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/endpoint/tunnel/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAwBA;;;;;;AASuB,UATN,iBAAA,CASM;EAuBN;;;;EA0BO,EAAA,CAAA,EAAA,MAAA,GArDR,MAqDQ,GArDC,KAqDD,CAAA,MAAA,GArDgB,MAqDhB,CAAA;EAiBP;EA4BA,IAAA,CAAA,EAAA,MAAA,GAhGC,MAgGgB;EA6DS;EAMlB,GAAA,CAAA,EAAA,MAAA,GAjKR,MAiKQ;EA6CP;;;AASlB;EAOkB,UAAA,CAAA,EAAA,MAAA;EAQP;EAY8B,kBAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;UA3NxB,oBAAA;;;;;;;;;;;;;;;;gBAgBD;;;;;oBAKI;;;;;gBAKJ;;;;;;;;;;;;;;;;UAiBC,cAAA,SAAuB;;;;;;;;;;;;;;;;;;;;eAoBzB;;;;;;;UAQE,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6D0B,MAAA,CAAO;;;;;;;;yBAMzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6CP;;WAEP;;;;;;UAOM,UAAA;;;;;;;kBAOC;;;;;;;;WAQP;;;;;;;;;;;;;;MAY8B"}
@@ -0,0 +1,67 @@
1
+
2
+ //#region src/endpoint/tunnel/util.ts
3
+ /** Sleep that wakes early (resolving) when the signal aborts. */
4
+ function delay(ms, signal) {
5
+ return new Promise((resolve) => {
6
+ if (signal.aborted) {
7
+ resolve();
8
+ return;
9
+ }
10
+ const t = setTimeout(() => {
11
+ signal.removeEventListener("abort", onAbort);
12
+ resolve();
13
+ }, ms);
14
+ const onAbort = () => {
15
+ clearTimeout(t);
16
+ resolve();
17
+ };
18
+ signal.addEventListener("abort", onAbort, { once: true });
19
+ });
20
+ }
21
+ /**
22
+ * Race a promise against a signal: resolves `null` the moment the signal
23
+ * aborts, otherwise passes the promise's result through (rejections
24
+ * propagate). The abort listener is removed when the race settles, so
25
+ * repeated calls against a long-lived signal don't accumulate listeners.
26
+ */
27
+ async function raceAbortable(promise, signal) {
28
+ if (signal.aborted) return null;
29
+ let onAbort;
30
+ const aborted = new Promise((resolve) => {
31
+ onAbort = () => resolve(null);
32
+ signal.addEventListener("abort", onAbort, { once: true });
33
+ });
34
+ try {
35
+ return await Promise.race([promise, aborted]);
36
+ } finally {
37
+ signal.removeEventListener("abort", onAbort);
38
+ }
39
+ }
40
+ /** A promise whose resolve/reject are exposed and fire at most once. */
41
+ var Deferred = class {
42
+ settled = false;
43
+ promise;
44
+ resolveFn;
45
+ rejectFn;
46
+ constructor() {
47
+ this.promise = new Promise((resolve, reject) => {
48
+ this.resolveFn = resolve;
49
+ this.rejectFn = reject;
50
+ });
51
+ }
52
+ resolve(value) {
53
+ if (this.settled) return;
54
+ this.settled = true;
55
+ this.resolveFn(value);
56
+ }
57
+ reject(err) {
58
+ if (this.settled) return;
59
+ this.settled = true;
60
+ this.rejectFn(err);
61
+ }
62
+ };
63
+
64
+ //#endregion
65
+ exports.Deferred = Deferred;
66
+ exports.delay = delay;
67
+ exports.raceAbortable = raceAbortable;
@@ -0,0 +1,65 @@
1
+ //#region src/endpoint/tunnel/util.ts
2
+ /** Sleep that wakes early (resolving) when the signal aborts. */
3
+ function delay(ms, signal) {
4
+ return new Promise((resolve) => {
5
+ if (signal.aborted) {
6
+ resolve();
7
+ return;
8
+ }
9
+ const t = setTimeout(() => {
10
+ signal.removeEventListener("abort", onAbort);
11
+ resolve();
12
+ }, ms);
13
+ const onAbort = () => {
14
+ clearTimeout(t);
15
+ resolve();
16
+ };
17
+ signal.addEventListener("abort", onAbort, { once: true });
18
+ });
19
+ }
20
+ /**
21
+ * Race a promise against a signal: resolves `null` the moment the signal
22
+ * aborts, otherwise passes the promise's result through (rejections
23
+ * propagate). The abort listener is removed when the race settles, so
24
+ * repeated calls against a long-lived signal don't accumulate listeners.
25
+ */
26
+ async function raceAbortable(promise, signal) {
27
+ if (signal.aborted) return null;
28
+ let onAbort;
29
+ const aborted = new Promise((resolve) => {
30
+ onAbort = () => resolve(null);
31
+ signal.addEventListener("abort", onAbort, { once: true });
32
+ });
33
+ try {
34
+ return await Promise.race([promise, aborted]);
35
+ } finally {
36
+ signal.removeEventListener("abort", onAbort);
37
+ }
38
+ }
39
+ /** A promise whose resolve/reject are exposed and fire at most once. */
40
+ var Deferred = class {
41
+ settled = false;
42
+ promise;
43
+ resolveFn;
44
+ rejectFn;
45
+ constructor() {
46
+ this.promise = new Promise((resolve, reject) => {
47
+ this.resolveFn = resolve;
48
+ this.rejectFn = reject;
49
+ });
50
+ }
51
+ resolve(value) {
52
+ if (this.settled) return;
53
+ this.settled = true;
54
+ this.resolveFn(value);
55
+ }
56
+ reject(err) {
57
+ if (this.settled) return;
58
+ this.settled = true;
59
+ this.rejectFn(err);
60
+ }
61
+ };
62
+
63
+ //#endregion
64
+ export { Deferred, delay, raceAbortable };
65
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","names":["onAbort!: () => void"],"sources":["../../../src/endpoint/tunnel/util.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2026 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\n// Small abort-aware async utilities shared by the engine.\n\n/** Sleep that wakes early (resolving) when the signal aborts. */\nexport function delay(ms: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve) => {\n if (signal.aborted) {\n resolve();\n return;\n }\n const t = setTimeout(() => {\n signal.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(t);\n resolve();\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\n/**\n * Race a promise against a signal: resolves `null` the moment the signal\n * aborts, otherwise passes the promise's result through (rejections\n * propagate). The abort listener is removed when the race settles, so\n * repeated calls against a long-lived signal don't accumulate listeners.\n */\nexport async function raceAbortable<T>(\n promise: Promise<T>,\n signal: AbortSignal\n): Promise<T | null> {\n if (signal.aborted) return null;\n let onAbort!: () => void;\n const aborted = new Promise<null>((resolve) => {\n onAbort = () => resolve(null);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n try {\n return await Promise.race([promise, aborted]);\n } finally {\n signal.removeEventListener(\"abort\", onAbort);\n }\n}\n\n// TODO replace with Promise.withResolvers\n/** A promise whose resolve/reject are exposed and fire at most once. */\nexport class Deferred<T> {\n private settled = false;\n readonly promise: Promise<T>;\n private resolveFn!: (value: T) => void;\n private rejectFn!: (err: Error) => void;\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this.resolveFn = resolve;\n this.rejectFn = reject;\n });\n }\n\n resolve(value: T): void {\n if (this.settled) return;\n this.settled = true;\n this.resolveFn(value);\n }\n\n reject(err: Error): void {\n if (this.settled) return;\n this.settled = true;\n this.rejectFn(err);\n }\n}\n"],"mappings":";;AAcA,SAAgB,MAAM,IAAY,QAAoC;AACpE,QAAO,IAAI,SAAS,YAAY;AAC9B,MAAI,OAAO,SAAS;AAClB,YAAS;AACT;;EAEF,MAAM,IAAI,iBAAiB;AACzB,UAAO,oBAAoB,SAAS,QAAQ;AAC5C,YAAS;KACR,GAAG;EACN,MAAM,gBAAgB;AACpB,gBAAa,EAAE;AACf,YAAS;;AAEX,SAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;GACzD;;;;;;;;AASJ,eAAsB,cACpB,SACA,QACmB;AACnB,KAAI,OAAO,QAAS,QAAO;CAC3B,IAAIA;CACJ,MAAM,UAAU,IAAI,SAAe,YAAY;AAC7C,kBAAgB,QAAQ,KAAK;AAC7B,SAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;GACzD;AACF,KAAI;AACF,SAAO,MAAM,QAAQ,KAAK,CAAC,SAAS,QAAQ,CAAC;WACrC;AACR,SAAO,oBAAoB,SAAS,QAAQ;;;;AAMhD,IAAa,WAAb,MAAyB;CACvB,AAAQ,UAAU;CAClB,AAAS;CACT,AAAQ;CACR,AAAQ;CAER,cAAc;AACZ,OAAK,UAAU,IAAI,SAAY,SAAS,WAAW;AACjD,QAAK,YAAY;AACjB,QAAK,WAAW;IAChB;;CAGJ,QAAQ,OAAgB;AACtB,MAAI,KAAK,QAAS;AAClB,OAAK,UAAU;AACf,OAAK,UAAU,MAAM;;CAGvB,OAAO,KAAkB;AACvB,MAAI,KAAK,QAAS;AAClB,OAAK,UAAU;AACf,OAAK,SAAS,IAAI"}