@restatedev/restate-sdk 1.18.0 → 1.18.2
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.
- package/dist/common_api.d.cts.map +1 -1
- package/dist/common_api.d.ts.map +1 -1
- package/dist/context.d.cts +3 -0
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/context_impl.cjs +8 -3
- package/dist/context_impl.js +8 -3
- package/dist/context_impl.js.map +1 -1
- package/dist/endpoint/connect/env.cjs +208 -0
- package/dist/endpoint/connect/env.js +201 -0
- package/dist/endpoint/connect/env.js.map +1 -0
- package/dist/endpoint/connect/index.cjs +113 -0
- package/dist/endpoint/connect/index.d.cts +41 -0
- package/dist/endpoint/connect/index.d.cts.map +1 -0
- package/dist/endpoint/connect/index.d.ts +41 -0
- package/dist/endpoint/connect/index.d.ts.map +1 -0
- package/dist/endpoint/connect/index.js +114 -0
- package/dist/endpoint/connect/index.js.map +1 -0
- package/dist/endpoint/connect/key.cjs +62 -0
- package/dist/endpoint/connect/key.js +62 -0
- package/dist/endpoint/connect/key.js.map +1 -0
- package/dist/endpoint/tunnel/backoff.cjs +37 -0
- package/dist/endpoint/tunnel/backoff.js +36 -0
- package/dist/endpoint/tunnel/backoff.js.map +1 -0
- package/dist/endpoint/tunnel/connection.cjs +604 -0
- package/dist/endpoint/tunnel/connection.js +600 -0
- package/dist/endpoint/tunnel/connection.js.map +1 -0
- package/dist/endpoint/tunnel/draining.cjs +40 -0
- package/dist/endpoint/tunnel/draining.js +40 -0
- package/dist/endpoint/tunnel/draining.js.map +1 -0
- package/dist/endpoint/tunnel/engine.cjs +264 -0
- package/dist/endpoint/tunnel/engine.d.cts +1 -0
- package/dist/endpoint/tunnel/engine.d.ts +1 -0
- package/dist/endpoint/tunnel/engine.js +265 -0
- package/dist/endpoint/tunnel/engine.js.map +1 -0
- package/dist/endpoint/tunnel/forwarded.cjs +34 -0
- package/dist/endpoint/tunnel/forwarded.js +34 -0
- package/dist/endpoint/tunnel/forwarded.js.map +1 -0
- package/dist/endpoint/tunnel/handshake.cjs +98 -0
- package/dist/endpoint/tunnel/handshake.js +97 -0
- package/dist/endpoint/tunnel/handshake.js.map +1 -0
- package/dist/endpoint/tunnel/index.d.cts +3 -0
- package/dist/endpoint/tunnel/index.d.ts +3 -0
- package/dist/endpoint/tunnel/options.cjs +168 -0
- package/dist/endpoint/tunnel/options.d.cts +2 -0
- package/dist/endpoint/tunnel/options.d.ts +2 -0
- package/dist/endpoint/tunnel/options.js +161 -0
- package/dist/endpoint/tunnel/options.js.map +1 -0
- package/dist/endpoint/tunnel/supervisor.cjs +180 -0
- package/dist/endpoint/tunnel/supervisor.js +181 -0
- package/dist/endpoint/tunnel/supervisor.js.map +1 -0
- package/dist/endpoint/tunnel/targets.cjs +110 -0
- package/dist/endpoint/tunnel/targets.js +107 -0
- package/dist/endpoint/tunnel/targets.js.map +1 -0
- package/dist/endpoint/tunnel/types.d.cts +269 -0
- package/dist/endpoint/tunnel/types.d.cts.map +1 -0
- package/dist/endpoint/tunnel/types.d.ts +269 -0
- package/dist/endpoint/tunnel/types.d.ts.map +1 -0
- package/dist/endpoint/tunnel/util.cjs +67 -0
- package/dist/endpoint/tunnel/util.js +65 -0
- package/dist/endpoint/tunnel/util.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/node.cjs +2 -0
- package/dist/node.d.cts +4 -1
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.ts +4 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -1
- package/dist/node.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/dist/types/rpc.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/endpoint/connect/key.ts
|
|
2
|
+
/** The prefix every Restate Cloud key starts with. */
|
|
3
|
+
const CLOUD_KEY_PREFIX = "rstcloudv1_";
|
|
4
|
+
/** The shape shown in errors. */
|
|
5
|
+
const CLOUD_KEY_SHAPE = `${CLOUD_KEY_PREFIX}<base58>`;
|
|
6
|
+
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
7
|
+
/**
|
|
8
|
+
* Parse a Restate Cloud key (`rstcloudv1_<base58>`) into its query parameters,
|
|
9
|
+
* in order. Throws an `Error` whose message starts with `what` (the variable
|
|
10
|
+
* or option the value came from) when the string does not follow the format;
|
|
11
|
+
* the message says what is wrong, shows the expected shape and links `help`.
|
|
12
|
+
*
|
|
13
|
+
* @param value the key string
|
|
14
|
+
* @param what how to call the value in errors, e.g. `RESTATE_CONNECT_KEY`
|
|
15
|
+
* @param help where to get a fresh key, linked in every error
|
|
16
|
+
*/
|
|
17
|
+
function parseCloudKey(value, what, help) {
|
|
18
|
+
const fail = (reason) => {
|
|
19
|
+
throw new Error(`${what} is not a Restate Cloud key (${reason}); expected ${CLOUD_KEY_SHAPE} — copy it again from ${help}`);
|
|
20
|
+
};
|
|
21
|
+
const trimmed = value.trim();
|
|
22
|
+
if (!trimmed.startsWith(CLOUD_KEY_PREFIX)) return fail(`it does not start with ${CLOUD_KEY_PREFIX}`);
|
|
23
|
+
const encoded = trimmed.slice(11);
|
|
24
|
+
const corrupted = () => fail("it is truncated or corrupted");
|
|
25
|
+
if (encoded === "") return corrupted();
|
|
26
|
+
let query;
|
|
27
|
+
try {
|
|
28
|
+
query = new TextDecoder("utf-8", { fatal: true }).decode(base58Decode(encoded));
|
|
29
|
+
} catch {
|
|
30
|
+
return corrupted();
|
|
31
|
+
}
|
|
32
|
+
if (!/^[\x21-\x7e]+$/.test(query)) return corrupted();
|
|
33
|
+
const params = [...new URLSearchParams(query).entries()];
|
|
34
|
+
if (params.some(([name]) => name === "")) return corrupted();
|
|
35
|
+
return params;
|
|
36
|
+
}
|
|
37
|
+
/** Decode base58 (Bitcoin alphabet); throws on a character outside it. */
|
|
38
|
+
function base58Decode(text) {
|
|
39
|
+
const digits = [];
|
|
40
|
+
for (const char of text) {
|
|
41
|
+
let carry = BASE58_ALPHABET.indexOf(char);
|
|
42
|
+
if (carry < 0) throw new Error(`not base58: ${JSON.stringify(char)}`);
|
|
43
|
+
for (let i = 0; i < digits.length; i++) {
|
|
44
|
+
carry += digits[i] * 58;
|
|
45
|
+
digits[i] = carry & 255;
|
|
46
|
+
carry >>= 8;
|
|
47
|
+
}
|
|
48
|
+
while (carry > 0) {
|
|
49
|
+
digits.push(carry & 255);
|
|
50
|
+
carry >>= 8;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let zeros = 0;
|
|
54
|
+
while (zeros < text.length && text[zeros] === "1") zeros++;
|
|
55
|
+
const out = new Uint8Array(zeros + digits.length);
|
|
56
|
+
for (let i = 0; i < digits.length; i++) out[zeros + i] = digits[digits.length - 1 - i];
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { parseCloudKey };
|
|
62
|
+
//# sourceMappingURL=key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.js","names":["query: string","digits: number[]"],"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// INTERNAL: the Restate Cloud key format. To users the key is opaque: public\n// docs and error messages only ever say \"copy it again from the Cloud UI\";\n// this comment is the one place in restate-sdk that spells the format out\n// (`RESTATE_INGRESS_KEY` in @restatedev/restate-sdk-clients shares it, with\n// its own trimmed parser).\n//\n// rstcloudv1_<base58>\n//\n// The base58 part (Bitcoin alphabet, no padding) encodes a UTF-8 query string\n// (`application/x-www-form-urlencoded`), for a connect key\n//\n// envid=env_201k…&apikey=key_01abc.5Kd…®ion=eu.restate.cloud&signingkey=publickeyv1_…\n//\n// and for an ingress key the same without `signingkey`. Every value is made\n// of unreserved characters, so nothing in it is percent-encoded. One opaque\n// word: a double click selects it, every shell and secret store copies it\n// intact, and expanding it takes one line anywhere\n// (`new URLSearchParams(utf8(base58decode(rest)))`). The caller decides which\n// parameters it knows; the only derivations are the tunnel SRV name\n// (`tunnel.<region>`) and the ingress URL\n// (`https://<envid minus env_>.env.<region>:8080`).\n\n/** The prefix every Restate Cloud key starts with. */\nexport const CLOUD_KEY_PREFIX = \"rstcloudv1_\";\n\n/** The shape shown in errors. */\nexport const CLOUD_KEY_SHAPE = `${CLOUD_KEY_PREFIX}<base58>`;\n\nconst BASE58_ALPHABET =\n \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\n\n/**\n * Parse a Restate Cloud key (`rstcloudv1_<base58>`) into its query parameters,\n * in order. Throws an `Error` whose message starts with `what` (the variable\n * or option the value came from) when the string does not follow the format;\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): Array<[name: string, value: string]> {\n // Reasons never echo parts of the value (the whole thing is a credential)\n // and never describe the encoding: a user only needs to know whether they\n // pasted something else or lost part of the key.\n const fail = (reason: string): never => {\n throw new Error(\n `${what} is not a Restate Cloud key (${reason}); expected ${CLOUD_KEY_SHAPE} — copy it again from ${help}`\n );\n };\n const trimmed = value.trim();\n if (!trimmed.startsWith(CLOUD_KEY_PREFIX)) {\n return fail(`it does not start with ${CLOUD_KEY_PREFIX}`);\n }\n const encoded = trimmed.slice(CLOUD_KEY_PREFIX.length);\n const corrupted = () => fail(\"it is truncated or corrupted\");\n if (encoded === \"\") return corrupted();\n let query: string;\n try {\n query = new TextDecoder(\"utf-8\", { fatal: true }).decode(\n base58Decode(encoded)\n );\n } catch {\n return corrupted();\n }\n // `URLSearchParams` accepts anything; demand the shape we produce: printable\n // ASCII, non-empty, every entry with a name.\n if (!/^[\\x21-\\x7e]+$/.test(query)) return corrupted();\n const params = [...new URLSearchParams(query).entries()];\n if (params.some(([name]) => name === \"\")) return corrupted();\n return params;\n}\n\n/** Decode base58 (Bitcoin alphabet); throws on a character outside it. */\nfunction base58Decode(text: string): Uint8Array {\n // Little-endian base-256 digits, multiplied up one base58 digit at a time.\n const digits: number[] = [];\n for (const char of text) {\n let carry = BASE58_ALPHABET.indexOf(char);\n if (carry < 0) throw new Error(`not base58: ${JSON.stringify(char)}`);\n for (let i = 0; i < digits.length; i++) {\n carry += digits[i]! * 58;\n digits[i] = carry & 0xff;\n carry >>= 8;\n }\n while (carry > 0) {\n digits.push(carry & 0xff);\n carry >>= 8;\n }\n }\n // Each leading `1` is a leading zero byte.\n let zeros = 0;\n while (zeros < text.length && text[zeros] === \"1\") zeros++;\n const out = new Uint8Array(zeros + digits.length);\n for (let i = 0; i < digits.length; i++) {\n out[zeros + i] = digits[digits.length - 1 - i]!;\n }\n return out;\n}\n"],"mappings":";;AAkCA,MAAa,mBAAmB;;AAGhC,MAAa,kBAAkB,GAAG,iBAAiB;AAEnD,MAAM,kBACJ;;;;;;;;;;;AAYF,SAAgB,cACd,OACA,MACA,MACsC;CAItC,MAAM,QAAQ,WAA0B;AACtC,QAAM,IAAI,MACR,GAAG,KAAK,+BAA+B,OAAO,cAAc,gBAAgB,wBAAwB,OACrG;;CAEH,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,CAAC,QAAQ,WAAW,iBAAiB,CACvC,QAAO,KAAK,0BAA0B,mBAAmB;CAE3D,MAAM,UAAU,QAAQ,MAAM,GAAwB;CACtD,MAAM,kBAAkB,KAAK,+BAA+B;AAC5D,KAAI,YAAY,GAAI,QAAO,WAAW;CACtC,IAAIA;AACJ,KAAI;AACF,UAAQ,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM,CAAC,CAAC,OAChD,aAAa,QAAQ,CACtB;SACK;AACN,SAAO,WAAW;;AAIpB,KAAI,CAAC,iBAAiB,KAAK,MAAM,CAAE,QAAO,WAAW;CACrD,MAAM,SAAS,CAAC,GAAG,IAAI,gBAAgB,MAAM,CAAC,SAAS,CAAC;AACxD,KAAI,OAAO,MAAM,CAAC,UAAU,SAAS,GAAG,CAAE,QAAO,WAAW;AAC5D,QAAO;;;AAIT,SAAS,aAAa,MAA0B;CAE9C,MAAMC,SAAmB,EAAE;AAC3B,MAAK,MAAM,QAAQ,MAAM;EACvB,IAAI,QAAQ,gBAAgB,QAAQ,KAAK;AACzC,MAAI,QAAQ,EAAG,OAAM,IAAI,MAAM,eAAe,KAAK,UAAU,KAAK,GAAG;AACrE,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,YAAS,OAAO,KAAM;AACtB,UAAO,KAAK,QAAQ;AACpB,aAAU;;AAEZ,SAAO,QAAQ,GAAG;AAChB,UAAO,KAAK,QAAQ,IAAK;AACzB,aAAU;;;CAId,IAAI,QAAQ;AACZ,QAAO,QAAQ,KAAK,UAAU,KAAK,WAAW,IAAK;CACnD,MAAM,MAAM,IAAI,WAAW,QAAQ,OAAO,OAAO;AACjD,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,KAAI,QAAQ,KAAK,OAAO,OAAO,SAAS,IAAI;AAE9C,QAAO"}
|
|
@@ -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"}
|