@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,53 @@
1
+ //#region src/endpoint/connect/key.ts
2
+ const BARE_ENVIRONMENT_ID = /^[A-Za-z0-9_-]+$/;
3
+ const DOMAIN = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
4
+ /**
5
+ * Parse a Restate Cloud key (`restate://<api key>@<environment id>.env.<region
6
+ * domain>/?…`). Throws an `Error` whose message starts with `what` (the variable
7
+ * or option the value came from) when the string does not follow the grammar;
8
+ * the message says what is wrong, shows the expected shape and links `help`.
9
+ *
10
+ * @param value the key string
11
+ * @param what how to call the value in errors, e.g. `RESTATE_CONNECT_KEY`
12
+ * @param help where to get a fresh key, linked in every error
13
+ */
14
+ function parseCloudKey(value, what, help) {
15
+ const fail = (reason) => {
16
+ throw new Error(`${what} is not a Restate Cloud key (${reason}); expected restate://<api key>@<environment id>.env.<region domain>/ — copy it again from ${help}`);
17
+ };
18
+ let url;
19
+ try {
20
+ url = new URL(value.trim());
21
+ } catch {
22
+ return fail("not a URL");
23
+ }
24
+ if (url.protocol !== "restate:") return fail(`the scheme is ${JSON.stringify(url.protocol.replace(/:$/, ""))}, not restate`);
25
+ if (url.port !== "") return fail("the host must not carry a port");
26
+ if (url.pathname !== "" && url.pathname !== "/") return fail("the path must be empty");
27
+ if (url.hash !== "") return fail("a fragment is not allowed");
28
+ const host = url.hostname.toLowerCase();
29
+ const marker = host.indexOf(".env.");
30
+ const bareEnvironmentId = marker > 0 ? host.slice(0, marker) : "";
31
+ const regionDomain = marker > 0 ? host.slice(marker + 5) : "";
32
+ if (!BARE_ENVIRONMENT_ID.test(bareEnvironmentId) || bareEnvironmentId.startsWith("env_") || !DOMAIN.test(regionDomain)) return fail("the host must be <environment id>.env.<region domain>");
33
+ let apiKey;
34
+ if (url.username !== "" || url.password !== "") {
35
+ const raw = url.password === "" ? url.username : `${url.username}:${url.password}`;
36
+ try {
37
+ apiKey = decodeURIComponent(raw);
38
+ } catch {
39
+ return fail("the API key is not valid percent-encoding");
40
+ }
41
+ }
42
+ return {
43
+ apiKey,
44
+ host,
45
+ environmentId: `env_${bareEnvironmentId}`,
46
+ regionDomain,
47
+ params: [...url.searchParams.entries()]
48
+ };
49
+ }
50
+
51
+ //#endregion
52
+ export { parseCloudKey };
53
+ //# sourceMappingURL=key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.js","names":["url: URL","apiKey: string | undefined"],"sources":["../../../src/endpoint/connect/key.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// The Restate Cloud key grammar (`RESTATE_CONNECT_KEY`; `RESTATE_INGRESS_KEY`\n// in @restatedev/restate-sdk-clients shares it, with its own trimmed parser):\n//\n// restate://<api key>@<bare environment id>.env.<region domain>/?<params>\n//\n// URL-shaped on purpose: standard-library parsers everywhere, the secret in\n// the userinfo slot that log redactors already mask, and query parameters for\n// forward-compatible extras. The host is the environment's own hostname, so\n// the environment id (`env_` + first label), the region domain (after\n// `.env.`) and the ingress URL (`https://<host>:8080`) all derive from it.\n\n/** A parsed Restate Cloud key, see {@link parseCloudKey}. */\nexport interface CloudKey {\n /** The API key from the userinfo slot, `undefined` when the key has none. */\n apiKey: string | undefined;\n /** `<bare environment id>.env.<region domain>`: the environment's hostname. */\n host: string;\n /** The environment id, `env_` + the host's first label. */\n environmentId: string;\n /** The part of the host after `.env.` (e.g. `eu.restate.cloud`). */\n regionDomain: string;\n /** The query parameters, in order; the caller decides which ones it knows. */\n params: Array<[name: string, value: string]>;\n}\n\nconst BARE_ENVIRONMENT_ID = /^[A-Za-z0-9_-]+$/;\nconst DOMAIN = /^[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/;\n\n/**\n * Parse a Restate Cloud key (`restate://<api key>@<environment id>.env.<region\n * domain>/?…`). Throws an `Error` whose message starts with `what` (the variable\n * or option the value came from) when the string does not follow the grammar;\n * the message says what is wrong, shows the expected shape and links `help`.\n *\n * @param value the key string\n * @param what how to call the value in errors, e.g. `RESTATE_CONNECT_KEY`\n * @param help where to get a fresh key, linked in every error\n */\nexport function parseCloudKey(\n value: string,\n what: string,\n help: string\n): CloudKey {\n // Reasons never echo parts of the value: a key pasted with a lost `@` or a\n // stray `/` would otherwise put the credential in the error message.\n const fail = (reason: string): never => {\n throw new Error(\n `${what} is not a Restate Cloud key (${reason}); expected restate://<api key>@<environment id>.env.<region domain>/ — copy it again from ${help}`\n );\n };\n let url: URL;\n try {\n url = new URL(value.trim());\n } catch {\n return fail(\"not a URL\");\n }\n if (url.protocol !== \"restate:\") {\n return fail(\n `the scheme is ${JSON.stringify(url.protocol.replace(/:$/, \"\"))}, not restate`\n );\n }\n if (url.port !== \"\") return fail(\"the host must not carry a port\");\n // The path is not echoed: a key pasted with a stray `/` would put part of\n // the credential in the error message.\n if (url.pathname !== \"\" && url.pathname !== \"/\") {\n return fail(\"the path must be empty\");\n }\n if (url.hash !== \"\") return fail(\"a fragment is not allowed\");\n\n // Hosts are case-insensitive; a non-special scheme keeps the pasted case.\n const host = url.hostname.toLowerCase();\n const marker = host.indexOf(\".env.\");\n const bareEnvironmentId = marker > 0 ? host.slice(0, marker) : \"\";\n const regionDomain = marker > 0 ? host.slice(marker + \".env.\".length) : \"\";\n if (\n !BARE_ENVIRONMENT_ID.test(bareEnvironmentId) ||\n bareEnvironmentId.startsWith(\"env_\") ||\n !DOMAIN.test(regionDomain)\n ) {\n return fail(\"the host must be <environment id>.env.<region domain>\");\n }\n\n // The userinfo slot: `username[:password]`, percent-decoded. API keys carry\n // no `:` today, but a key is opaque to us, so a password part is re-joined.\n let apiKey: string | undefined;\n if (url.username !== \"\" || url.password !== \"\") {\n const raw =\n url.password === \"\" ? url.username : `${url.username}:${url.password}`;\n try {\n apiKey = decodeURIComponent(raw);\n } catch {\n return fail(\"the API key is not valid percent-encoding\");\n }\n }\n\n return {\n apiKey,\n host,\n environmentId: `env_${bareEnvironmentId}`,\n regionDomain,\n params: [...url.searchParams.entries()],\n };\n}\n"],"mappings":";AAoCA,MAAM,sBAAsB;AAC5B,MAAM,SAAS;;;;;;;;;;;AAYf,SAAgB,cACd,OACA,MACA,MACU;CAGV,MAAM,QAAQ,WAA0B;AACtC,QAAM,IAAI,MACR,GAAG,KAAK,+BAA+B,OAAO,6FAA6F,OAC5I;;CAEH,IAAIA;AACJ,KAAI;AACF,QAAM,IAAI,IAAI,MAAM,MAAM,CAAC;SACrB;AACN,SAAO,KAAK,YAAY;;AAE1B,KAAI,IAAI,aAAa,WACnB,QAAO,KACL,iBAAiB,KAAK,UAAU,IAAI,SAAS,QAAQ,MAAM,GAAG,CAAC,CAAC,eACjE;AAEH,KAAI,IAAI,SAAS,GAAI,QAAO,KAAK,iCAAiC;AAGlE,KAAI,IAAI,aAAa,MAAM,IAAI,aAAa,IAC1C,QAAO,KAAK,yBAAyB;AAEvC,KAAI,IAAI,SAAS,GAAI,QAAO,KAAK,4BAA4B;CAG7D,MAAM,OAAO,IAAI,SAAS,aAAa;CACvC,MAAM,SAAS,KAAK,QAAQ,QAAQ;CACpC,MAAM,oBAAoB,SAAS,IAAI,KAAK,MAAM,GAAG,OAAO,GAAG;CAC/D,MAAM,eAAe,SAAS,IAAI,KAAK,MAAM,SAAS,EAAe,GAAG;AACxE,KACE,CAAC,oBAAoB,KAAK,kBAAkB,IAC5C,kBAAkB,WAAW,OAAO,IACpC,CAAC,OAAO,KAAK,aAAa,CAE1B,QAAO,KAAK,wDAAwD;CAKtE,IAAIC;AACJ,KAAI,IAAI,aAAa,MAAM,IAAI,aAAa,IAAI;EAC9C,MAAM,MACJ,IAAI,aAAa,KAAK,IAAI,WAAW,GAAG,IAAI,SAAS,GAAG,IAAI;AAC9D,MAAI;AACF,YAAS,mBAAmB,IAAI;UAC1B;AACN,UAAO,KAAK,4CAA4C;;;AAI5D,QAAO;EACL;EACA;EACA,eAAe,OAAO;EACtB;EACA,QAAQ,CAAC,GAAG,IAAI,aAAa,SAAS,CAAC;EACxC"}
@@ -0,0 +1,37 @@
1
+
2
+ //#region src/endpoint/tunnel/backoff.ts
3
+ /**
4
+ * Backoff resets only when a served connection stayed up at least this long
5
+ * (mirrors the Rust client's 5s "opened" guard). Without it, a server that
6
+ * authorizes the handshake but immediately drops the connection would be
7
+ * redialed at the backoff floor forever — a full TLS+h2+auth round trip
8
+ * every ~10ms.
9
+ */
10
+ const MIN_UPTIME_FOR_BACKOFF_RESET_MS = 5e3;
11
+ /**
12
+ * Jittered exponential backoff: each `next()` returns the current delay
13
+ * with ±50% jitter and advances the schedule toward `maxMs`; `reset()`
14
+ * returns to the floor. Jitter keeps multi-homed slots from redialing in
15
+ * lockstep after a fleet-wide blip (thundering herd).
16
+ */
17
+ var Backoff = class {
18
+ currentMs;
19
+ constructor(initialMs, factor, maxMs) {
20
+ this.initialMs = initialMs;
21
+ this.factor = factor;
22
+ this.maxMs = maxMs;
23
+ this.currentMs = initialMs;
24
+ }
25
+ next() {
26
+ const d = this.currentMs;
27
+ this.currentMs = Math.min(this.currentMs * this.factor, this.maxMs);
28
+ return d * (.5 + Math.random());
29
+ }
30
+ reset() {
31
+ this.currentMs = this.initialMs;
32
+ }
33
+ };
34
+
35
+ //#endregion
36
+ exports.Backoff = Backoff;
37
+ exports.MIN_UPTIME_FOR_BACKOFF_RESET_MS = MIN_UPTIME_FOR_BACKOFF_RESET_MS;
@@ -0,0 +1,36 @@
1
+ //#region src/endpoint/tunnel/backoff.ts
2
+ /**
3
+ * Backoff resets only when a served connection stayed up at least this long
4
+ * (mirrors the Rust client's 5s "opened" guard). Without it, a server that
5
+ * authorizes the handshake but immediately drops the connection would be
6
+ * redialed at the backoff floor forever — a full TLS+h2+auth round trip
7
+ * every ~10ms.
8
+ */
9
+ const MIN_UPTIME_FOR_BACKOFF_RESET_MS = 5e3;
10
+ /**
11
+ * Jittered exponential backoff: each `next()` returns the current delay
12
+ * with ±50% jitter and advances the schedule toward `maxMs`; `reset()`
13
+ * returns to the floor. Jitter keeps multi-homed slots from redialing in
14
+ * lockstep after a fleet-wide blip (thundering herd).
15
+ */
16
+ var Backoff = class {
17
+ currentMs;
18
+ constructor(initialMs, factor, maxMs) {
19
+ this.initialMs = initialMs;
20
+ this.factor = factor;
21
+ this.maxMs = maxMs;
22
+ this.currentMs = initialMs;
23
+ }
24
+ next() {
25
+ const d = this.currentMs;
26
+ this.currentMs = Math.min(this.currentMs * this.factor, this.maxMs);
27
+ return d * (.5 + Math.random());
28
+ }
29
+ reset() {
30
+ this.currentMs = this.initialMs;
31
+ }
32
+ };
33
+
34
+ //#endregion
35
+ export { Backoff, MIN_UPTIME_FOR_BACKOFF_RESET_MS };
36
+ //# sourceMappingURL=backoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.js","names":["initialMs: number","factor: number","maxMs: number"],"sources":["../../../src/endpoint/tunnel/backoff.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// Reconnect backoff policy.\n\n/**\n * Backoff resets only when a served connection stayed up at least this long\n * (mirrors the Rust client's 5s \"opened\" guard). Without it, a server that\n * authorizes the handshake but immediately drops the connection would be\n * redialed at the backoff floor forever — a full TLS+h2+auth round trip\n * every ~10ms.\n */\nexport const MIN_UPTIME_FOR_BACKOFF_RESET_MS = 5_000;\n\n/**\n * Jittered exponential backoff: each `next()` returns the current delay\n * with ±50% jitter and advances the schedule toward `maxMs`; `reset()`\n * returns to the floor. Jitter keeps multi-homed slots from redialing in\n * lockstep after a fleet-wide blip (thundering herd).\n */\nexport class Backoff {\n private currentMs: number;\n\n constructor(\n private readonly initialMs: number,\n private readonly factor: number,\n private readonly maxMs: number\n ) {\n this.currentMs = initialMs;\n }\n\n next(): number {\n const d = this.currentMs;\n this.currentMs = Math.min(this.currentMs * this.factor, this.maxMs);\n return d * (0.5 + Math.random());\n }\n\n reset(): void {\n this.currentMs = this.initialMs;\n }\n}\n"],"mappings":";;;;;;;;AAoBA,MAAa,kCAAkC;;;;;;;AAQ/C,IAAa,UAAb,MAAqB;CACnB,AAAQ;CAER,YACE,AAAiBA,WACjB,AAAiBC,QACjB,AAAiBC,OACjB;EAHiB;EACA;EACA;AAEjB,OAAK,YAAY;;CAGnB,OAAe;EACb,MAAM,IAAI,KAAK;AACf,OAAK,YAAY,KAAK,IAAI,KAAK,YAAY,KAAK,QAAQ,KAAK,MAAM;AACnE,SAAO,KAAK,KAAM,KAAK,QAAQ;;CAGjC,QAAc;AACZ,OAAK,YAAY,KAAK"}