@restatedev/restate-sdk 1.17.4 → 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.
- package/dist/common_api.d.cts +1 -1
- package/dist/common_api.d.cts.map +1 -1
- package/dist/common_api.d.ts +1 -1
- package/dist/common_api.d.ts.map +1 -1
- package/dist/common_api.js.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/components.cjs +28 -6
- package/dist/endpoint/components.js +28 -6
- package/dist/endpoint/components.js.map +1 -1
- package/dist/endpoint/connect/env.cjs +206 -0
- package/dist/endpoint/connect/env.js +199 -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 +53 -0
- package/dist/endpoint/connect/key.js +53 -0
- package/dist/endpoint/connect/key.js.map +1 -0
- package/dist/endpoint/handlers/discovery.cjs +12 -2
- package/dist/endpoint/handlers/discovery.js +12 -2
- package/dist/endpoint/handlers/discovery.js.map +1 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.cjs +1 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +1 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
- 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 +270 -0
- package/dist/endpoint/tunnel/types.d.cts.map +1 -0
- package/dist/endpoint/tunnel/types.d.ts +270 -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/fetch.d.cts +2 -2
- package/dist/fetch.d.ts +2 -2
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/lambda.d.cts +2 -2
- package/dist/lambda.d.ts +2 -2
- package/dist/node.cjs +2 -0
- package/dist/node.d.cts +5 -2
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.ts +5 -2
- 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/errors.cjs +4 -2
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +4 -2
- package/dist/types/errors.js.map +1 -1
- package/dist/types/rpc.d.cts +42 -17
- package/dist/types/rpc.d.cts.map +1 -1
- package/dist/types/rpc.d.ts +42 -17
- package/dist/types/rpc.d.ts.map +1 -1
- package/dist/types/rpc.js.map +1 -1
- package/package.json +2 -2
- package/dist/context_impl.d.ts.map +0 -1
- package/dist/endpoint/components.d.ts.map +0 -1
- package/dist/endpoint/discovery.d.ts +0 -184
- package/dist/endpoint/discovery.d.ts.map +0 -1
- package/dist/endpoint/discovery.js +0 -7
- package/dist/endpoint/discovery.js.map +0 -1
- package/dist/endpoint/endpoint.d.ts.map +0 -1
- package/dist/endpoint/handlers/core_logging.d.ts +0 -14
- package/dist/endpoint/handlers/core_logging.d.ts.map +0 -1
- package/dist/endpoint/handlers/discovery.d.ts +0 -5
- package/dist/endpoint/handlers/discovery.d.ts.map +0 -1
- package/dist/endpoint/handlers/fetch.d.ts +0 -5
- package/dist/endpoint/handlers/fetch.d.ts.map +0 -1
- package/dist/endpoint/handlers/generic.d.ts +0 -5
- package/dist/endpoint/handlers/generic.d.ts.map +0 -1
- package/dist/endpoint/handlers/lambda.d.ts +0 -10
- package/dist/endpoint/handlers/lambda.d.ts.map +0 -1
- package/dist/endpoint/handlers/preview.d.ts +0 -5
- package/dist/endpoint/handlers/preview.d.ts.map +0 -1
- package/dist/endpoint/handlers/types.d.ts.map +0 -1
- package/dist/endpoint/handlers/types.js +0 -2
- package/dist/endpoint/handlers/types.js.map +0 -1
- package/dist/endpoint/handlers/utils.d.ts +0 -23
- package/dist/endpoint/handlers/utils.d.ts.map +0 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +0 -454
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +0 -1
- package/dist/endpoint/node_endpoint.d.ts +0 -28
- package/dist/endpoint/node_endpoint.d.ts.map +0 -1
- package/dist/endpoint/types.js +0 -2
- package/dist/endpoint/types.js.map +0 -1
- package/dist/endpoint/withOptions.d.ts +0 -4
- package/dist/endpoint/withOptions.d.ts.map +0 -1
- package/dist/endpoint.js +0 -12
- package/dist/endpoint.js.map +0 -1
- package/dist/error_sanitization.d.ts +0 -13
- package/dist/error_sanitization.d.ts.map +0 -1
- package/dist/hooks.js +0 -2
- package/dist/hooks.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/io.d.ts.map +0 -1
- package/dist/logging/console_logger_transport.d.ts +0 -5
- package/dist/logging/console_logger_transport.d.ts.map +0 -1
- package/dist/logging/logger.d.ts.map +0 -1
- package/dist/user_agent.d.ts +0 -2
- package/dist/user_agent.d.ts.map +0 -1
- package/dist/utils/external_progress_channel.d.ts +0 -19
- package/dist/utils/external_progress_channel.d.ts.map +0 -1
- package/dist/utils/rand.d.ts +0 -13
- package/dist/utils/rand.d.ts.map +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { LogSource } from "../../logging/logger_transport.js";
|
|
2
|
+
import { defaultLoggerTransport } from "../../logging/console_logger_transport.js";
|
|
3
|
+
import { createLogger } from "../../logging/logger.js";
|
|
4
|
+
import { startEngine } from "../tunnel/engine.js";
|
|
5
|
+
import { CONNECT_KEY_ENV, CONNECT_KEY_URL, CONNECT_NAME_ENVS, registrationDeepLink, registrationIdentifier, resolveCoordinates, resolveName } from "./env.js";
|
|
6
|
+
|
|
7
|
+
//#region src/endpoint/connect/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Connect your services to Restate Cloud and serve them over the connection.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import * as restate from "@restatedev/restate-sdk";
|
|
13
|
+
*
|
|
14
|
+
* restate.connect({ services: [greeter], name: "greeter-v1" });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* The connection needs two things:
|
|
18
|
+
*
|
|
19
|
+
* - a **name** for the deployment (`name` option, or `RESTATE_CONNECT_NAME`):
|
|
20
|
+
* the identity you register, shared by replicas of the same deployment;
|
|
21
|
+
* - a **connect key** (`RESTATE_CONNECT_KEY`): one string you can obtain from
|
|
22
|
+
* Cloud UI -> Development → Configure SDK.
|
|
23
|
+
*
|
|
24
|
+
* Both are read from the process environment; the SDK never reads a file.
|
|
25
|
+
*
|
|
26
|
+
* Once connected, the SDK logs how to register the deployment, once:
|
|
27
|
+
*
|
|
28
|
+
* ```
|
|
29
|
+
* Connecting to Restate Cloud environment env_201k… (eu.restate.cloud)
|
|
30
|
+
* Connected as "greeter-v1"
|
|
31
|
+
* Register it once:
|
|
32
|
+
* restate deployments register connect://greeter-v1
|
|
33
|
+
* or open https://cloud.restate.dev/to/overview?register-deployment=connect://greeter-v1
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* The returned {@link Connection} reconnects in the background until closed.
|
|
37
|
+
*
|
|
38
|
+
* @param options the services, the name and the tuning, see {@link ConnectOptions}
|
|
39
|
+
* @returns the connection handle
|
|
40
|
+
*/
|
|
41
|
+
function connect(options) {
|
|
42
|
+
const handle = connectEngine(options);
|
|
43
|
+
const settled = async (done) => {
|
|
44
|
+
await done;
|
|
45
|
+
if (handle.error !== void 0) throw handle.error;
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
ready: handle.ready,
|
|
49
|
+
name: handle.name,
|
|
50
|
+
close: () => settled(handle.close()),
|
|
51
|
+
shutdown: (opts) => settled(handle.shutdown(opts))
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `connect()` without the projection: the engine handle, with the connection
|
|
56
|
+
* count and the fatal error. Internal (tests).
|
|
57
|
+
*/
|
|
58
|
+
function connectEngine(options) {
|
|
59
|
+
const { name: nameOption, key, identityKeys, connection = {},...endpointOptions } = options;
|
|
60
|
+
const { serversSrv, servers,...tuning } = connection;
|
|
61
|
+
const rlog = createLogger(options.logger ?? defaultLoggerTransport, LogSource.SYSTEM);
|
|
62
|
+
const name = resolveName(nameOption);
|
|
63
|
+
const coordinates = resolveCoordinates({
|
|
64
|
+
key,
|
|
65
|
+
identityKeys,
|
|
66
|
+
serversSrv,
|
|
67
|
+
servers
|
|
68
|
+
}, (message) => rlog.warn(message));
|
|
69
|
+
return start({
|
|
70
|
+
...endpointOptions,
|
|
71
|
+
...tuning
|
|
72
|
+
}, name, coordinates, rlog);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Start the engine with the resolved identity and log the banner on ready.
|
|
76
|
+
*/
|
|
77
|
+
function start(rest, name, coordinates, rlog) {
|
|
78
|
+
const { regionLabel,...engineCoordinates } = coordinates;
|
|
79
|
+
const connection = startEngine({
|
|
80
|
+
...rest,
|
|
81
|
+
name,
|
|
82
|
+
...engineCoordinates,
|
|
83
|
+
onFatal: (error) => {
|
|
84
|
+
for (const line of explainFatal(error, name, coordinates.environmentId)) rlog.error(line);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
rlog.info(`Connecting to Restate Cloud environment ${coordinates.environmentId} (${regionLabel})`);
|
|
88
|
+
connection.ready.then(() => {
|
|
89
|
+
rlog.debug(`Deployment URL: ${connection.deploymentUrl ?? "?"}`);
|
|
90
|
+
rlog.info(`Connected as "${name}"`);
|
|
91
|
+
rlog.info("Register it once:");
|
|
92
|
+
rlog.info(` restate deployments register ${registrationIdentifier(name)}`);
|
|
93
|
+
rlog.info(` or open ${registrationDeepLink(name)}`);
|
|
94
|
+
}, () => {});
|
|
95
|
+
return connection;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A non-retryable stop, in plain words: what Restate Cloud said, what it
|
|
99
|
+
* means, what to do. The engine's own `tunnel: FATAL — …` line stays at debug.
|
|
100
|
+
*/
|
|
101
|
+
function explainFatal(error, name, environmentId) {
|
|
102
|
+
const reason = error.message.replace(/^tunnel: /, "");
|
|
103
|
+
const lines = [];
|
|
104
|
+
if (reason.includes("tunnel-status: unauthorized")) lines.push(`Restate Cloud rejected the connect key for environment ${environmentId}: it is invalid, revoked, or for another environment.`, `Create a new key at ${CONNECT_KEY_URL} and set ${CONNECT_KEY_ENV}.`);
|
|
105
|
+
else if (reason.includes("tunnel-status: bad-tunnel-name") || reason.startsWith("tunnel-name mismatch")) lines.push(`Restate Cloud rejected the deployment name "${name}" (${reason}).`, `Use letters, digits, '.', '_' or '-' — ${CONNECT_NAME_ENVS[0]} or the name option.`);
|
|
106
|
+
else if (reason.startsWith("gave up reconnecting")) lines.push(`Could not reach Restate Cloud for environment ${environmentId}: ${reason}.`, `Check the network, and that the key's region is right (${CONNECT_KEY_ENV}).`);
|
|
107
|
+
else lines.push(`The connection to Restate Cloud stopped: ${reason}`);
|
|
108
|
+
lines.push("Not retrying. Fix the configuration and restart.");
|
|
109
|
+
return lines;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { connect };
|
|
114
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["lines: string[]"],"sources":["../../../src/endpoint/connect/index.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\nimport { startEngine } from \"../tunnel/engine.js\";\nimport type {\n Connection,\n ConnectOptions,\n EngineHandle,\n EngineOptions,\n} from \"../tunnel/types.js\";\nimport {\n CONNECT_KEY_ENV,\n CONNECT_KEY_URL,\n CONNECT_NAME_ENVS,\n type Coordinates,\n registrationDeepLink,\n registrationIdentifier,\n resolveCoordinates,\n resolveName,\n} from \"./env.js\";\nimport { createLogger, type Logger } from \"../../logging/logger.js\";\nimport { LogSource } from \"../../logging/logger_transport.js\";\nimport { defaultLoggerTransport } from \"../../logging/console_logger_transport.js\";\n\n/**\n * Connect your services to Restate Cloud and serve them over the connection.\n *\n * ```ts\n * import * as restate from \"@restatedev/restate-sdk\";\n *\n * restate.connect({ services: [greeter], name: \"greeter-v1\" });\n * ```\n *\n * The connection needs two things:\n *\n * - a **name** for the deployment (`name` option, or `RESTATE_CONNECT_NAME`):\n * the identity you register, shared by replicas of the same deployment;\n * - a **connect key** (`RESTATE_CONNECT_KEY`): one string you can obtain from\n * Cloud UI -> Development → Configure SDK.\n *\n * Both are read from the process environment; the SDK never reads a file.\n *\n * Once connected, the SDK logs how to register the deployment, once:\n *\n * ```\n * Connecting to Restate Cloud environment env_201k… (eu.restate.cloud)\n * Connected as \"greeter-v1\"\n * Register it once:\n * restate deployments register connect://greeter-v1\n * or open https://cloud.restate.dev/to/overview?register-deployment=connect://greeter-v1\n * ```\n *\n * The returned {@link Connection} reconnects in the background until closed.\n *\n * @param options the services, the name and the tuning, see {@link ConnectOptions}\n * @returns the connection handle\n */\nexport function connect(options: ConnectOptions): Connection {\n const handle = connectEngine(options);\n // The fatal error is on the handle; surface it where the caller waits.\n const settled = async (done: Promise<void>): Promise<void> => {\n await done;\n if (handle.error !== undefined) throw handle.error;\n };\n return {\n ready: handle.ready,\n name: handle.name,\n close: () => settled(handle.close()),\n shutdown: (opts) => settled(handle.shutdown(opts)),\n };\n}\n\n/**\n * `connect()` without the projection: the engine handle, with the connection\n * count and the fatal error. Internal (tests).\n */\nexport function connectEngine(options: ConnectOptions): EngineHandle {\n const {\n name: nameOption,\n key,\n identityKeys,\n connection = {},\n ...endpointOptions\n } = options;\n const { serversSrv, servers, ...tuning } = connection;\n const rlog = createLogger(\n options.logger ?? defaultLoggerTransport,\n LogSource.SYSTEM\n );\n const name = resolveName(nameOption);\n const coordinates = resolveCoordinates(\n { key, identityKeys, serversSrv, servers },\n (message) => rlog.warn(message)\n );\n return start({ ...endpointOptions, ...tuning }, name, coordinates, rlog);\n}\n\n/**\n * Start the engine with the resolved identity and log the banner on ready.\n */\nfunction start(\n rest: Omit<\n EngineOptions,\n \"name\" | \"environmentId\" | \"authToken\" | \"identityKeys\" | \"discovery\"\n >,\n name: string,\n coordinates: Coordinates,\n rlog: Logger\n): EngineHandle {\n const { regionLabel, ...engineCoordinates } = coordinates;\n // startEngine validates the tuning synchronously; log only once it did.\n const connection = startEngine({\n ...rest,\n name,\n ...engineCoordinates,\n onFatal: (error) => {\n for (const line of explainFatal(error, name, coordinates.environmentId)) {\n rlog.error(line);\n }\n },\n });\n rlog.info(\n `Connecting to Restate Cloud environment ${coordinates.environmentId} (${regionLabel})`\n );\n connection.ready.then(\n () => {\n rlog.debug(`Deployment URL: ${connection.deploymentUrl ?? \"?\"}`);\n rlog.info(`Connected as \"${name}\"`);\n rlog.info(\"Register it once:\");\n rlog.info(\n ` restate deployments register ${registrationIdentifier(name)}`\n );\n rlog.info(` or open ${registrationDeepLink(name)}`);\n },\n () => {\n // Explained by onFatal above (or a plain close() before the first handshake).\n }\n );\n return connection;\n}\n\n/**\n * A non-retryable stop, in plain words: what Restate Cloud said, what it\n * means, what to do. The engine's own `tunnel: FATAL — …` line stays at debug.\n */\nfunction explainFatal(\n error: Error,\n name: string,\n environmentId: string\n): string[] {\n const reason = error.message.replace(/^tunnel: /, \"\");\n const lines: string[] = [];\n if (reason.includes(\"tunnel-status: unauthorized\")) {\n lines.push(\n `Restate Cloud rejected the connect key for environment ${environmentId}: it is invalid, revoked, or for another environment.`,\n `Create a new key at ${CONNECT_KEY_URL} and set ${CONNECT_KEY_ENV}.`\n );\n } else if (\n reason.includes(\"tunnel-status: bad-tunnel-name\") ||\n reason.startsWith(\"tunnel-name mismatch\")\n ) {\n lines.push(\n `Restate Cloud rejected the deployment name \"${name}\" (${reason}).`,\n `Use letters, digits, '.', '_' or '-' — ${CONNECT_NAME_ENVS[0]} or the name option.`\n );\n } else if (reason.startsWith(\"gave up reconnecting\")) {\n lines.push(\n `Could not reach Restate Cloud for environment ${environmentId}: ${reason}.`,\n `Check the network, and that the key's region is right (${CONNECT_KEY_ENV}).`\n );\n } else {\n lines.push(`The connection to Restate Cloud stopped: ${reason}`);\n }\n lines.push(\"Not retrying. Fix the configuration and restart.\");\n return lines;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,QAAQ,SAAqC;CAC3D,MAAM,SAAS,cAAc,QAAQ;CAErC,MAAM,UAAU,OAAO,SAAuC;AAC5D,QAAM;AACN,MAAI,OAAO,UAAU,OAAW,OAAM,OAAO;;AAE/C,QAAO;EACL,OAAO,OAAO;EACd,MAAM,OAAO;EACb,aAAa,QAAQ,OAAO,OAAO,CAAC;EACpC,WAAW,SAAS,QAAQ,OAAO,SAAS,KAAK,CAAC;EACnD;;;;;;AAOH,SAAgB,cAAc,SAAuC;CACnE,MAAM,EACJ,MAAM,YACN,KACA,cACA,aAAa,EAAE,CACf,GAAG,oBACD;CACJ,MAAM,EAAE,YAAY,QAAS,GAAG,WAAW;CAC3C,MAAM,OAAO,aACX,QAAQ,UAAU,wBAClB,UAAU,OACX;CACD,MAAM,OAAO,YAAY,WAAW;CACpC,MAAM,cAAc,mBAClB;EAAE;EAAK;EAAc;EAAY;EAAS,GACzC,YAAY,KAAK,KAAK,QAAQ,CAChC;AACD,QAAO,MAAM;EAAE,GAAG;EAAiB,GAAG;EAAQ,EAAE,MAAM,aAAa,KAAK;;;;;AAM1E,SAAS,MACP,MAIA,MACA,aACA,MACc;CACd,MAAM,EAAE,YAAa,GAAG,sBAAsB;CAE9C,MAAM,aAAa,YAAY;EAC7B,GAAG;EACH;EACA,GAAG;EACH,UAAU,UAAU;AAClB,QAAK,MAAM,QAAQ,aAAa,OAAO,MAAM,YAAY,cAAc,CACrE,MAAK,MAAM,KAAK;;EAGrB,CAAC;AACF,MAAK,KACH,2CAA2C,YAAY,cAAc,IAAI,YAAY,GACtF;AACD,YAAW,MAAM,WACT;AACJ,OAAK,MAAM,mBAAmB,WAAW,iBAAiB,MAAM;AAChE,OAAK,KAAK,iBAAiB,KAAK,GAAG;AACnC,OAAK,KAAK,oBAAoB;AAC9B,OAAK,KACH,kCAAkC,uBAAuB,KAAK,GAC/D;AACD,OAAK,KAAK,aAAa,qBAAqB,KAAK,GAAG;UAEhD,GAGP;AACD,QAAO;;;;;;AAOT,SAAS,aACP,OACA,MACA,eACU;CACV,MAAM,SAAS,MAAM,QAAQ,QAAQ,aAAa,GAAG;CACrD,MAAMA,QAAkB,EAAE;AAC1B,KAAI,OAAO,SAAS,8BAA8B,CAChD,OAAM,KACJ,0DAA0D,cAAc,wDACxE,uBAAuB,gBAAgB,WAAW,gBAAgB,GACnE;UAED,OAAO,SAAS,iCAAiC,IACjD,OAAO,WAAW,uBAAuB,CAEzC,OAAM,KACJ,+CAA+C,KAAK,KAAK,OAAO,KAChE,0CAA0C,kBAAkB,GAAG,sBAChE;UACQ,OAAO,WAAW,uBAAuB,CAClD,OAAM,KACJ,iDAAiD,cAAc,IAAI,OAAO,IAC1E,0DAA0D,gBAAgB,IAC3E;KAED,OAAM,KAAK,4CAA4C,SAAS;AAElE,OAAM,KAAK,mDAAmD;AAC9D,QAAO"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/endpoint/connect/key.ts
|
|
3
|
+
const BARE_ENVIRONMENT_ID = /^[A-Za-z0-9_-]+$/;
|
|
4
|
+
const DOMAIN = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
|
|
5
|
+
/**
|
|
6
|
+
* Parse a Restate Cloud key (`restate://<api key>@<environment id>.env.<region
|
|
7
|
+
* domain>/?…`). Throws an `Error` whose message starts with `what` (the variable
|
|
8
|
+
* or option the value came from) when the string does not follow the grammar;
|
|
9
|
+
* the message says what is wrong, shows the expected shape and links `help`.
|
|
10
|
+
*
|
|
11
|
+
* @param value the key string
|
|
12
|
+
* @param what how to call the value in errors, e.g. `RESTATE_CONNECT_KEY`
|
|
13
|
+
* @param help where to get a fresh key, linked in every error
|
|
14
|
+
*/
|
|
15
|
+
function parseCloudKey(value, what, help) {
|
|
16
|
+
const fail = (reason) => {
|
|
17
|
+
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}`);
|
|
18
|
+
};
|
|
19
|
+
let url;
|
|
20
|
+
try {
|
|
21
|
+
url = new URL(value.trim());
|
|
22
|
+
} catch {
|
|
23
|
+
return fail("not a URL");
|
|
24
|
+
}
|
|
25
|
+
if (url.protocol !== "restate:") return fail(`the scheme is ${JSON.stringify(url.protocol.replace(/:$/, ""))}, not restate`);
|
|
26
|
+
if (url.port !== "") return fail("the host must not carry a port");
|
|
27
|
+
if (url.pathname !== "" && url.pathname !== "/") return fail("the path must be empty");
|
|
28
|
+
if (url.hash !== "") return fail("a fragment is not allowed");
|
|
29
|
+
const host = url.hostname.toLowerCase();
|
|
30
|
+
const marker = host.indexOf(".env.");
|
|
31
|
+
const bareEnvironmentId = marker > 0 ? host.slice(0, marker) : "";
|
|
32
|
+
const regionDomain = marker > 0 ? host.slice(marker + 5) : "";
|
|
33
|
+
if (!BARE_ENVIRONMENT_ID.test(bareEnvironmentId) || bareEnvironmentId.startsWith("env_") || !DOMAIN.test(regionDomain)) return fail("the host must be <environment id>.env.<region domain>");
|
|
34
|
+
let apiKey;
|
|
35
|
+
if (url.username !== "" || url.password !== "") {
|
|
36
|
+
const raw = url.password === "" ? url.username : `${url.username}:${url.password}`;
|
|
37
|
+
try {
|
|
38
|
+
apiKey = decodeURIComponent(raw);
|
|
39
|
+
} catch {
|
|
40
|
+
return fail("the API key is not valid percent-encoding");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
apiKey,
|
|
45
|
+
host,
|
|
46
|
+
environmentId: `env_${bareEnvironmentId}`,
|
|
47
|
+
regionDomain,
|
|
48
|
+
params: [...url.searchParams.entries()]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.parseCloudKey = parseCloudKey;
|
|
@@ -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"}
|
|
@@ -5,6 +5,7 @@ const require_utils = require('./utils.cjs');
|
|
|
5
5
|
const ENDPOINT_MANIFEST_V2 = "application/vnd.restate.endpointmanifest.v2+json";
|
|
6
6
|
const ENDPOINT_MANIFEST_V3 = "application/vnd.restate.endpointmanifest.v3+json";
|
|
7
7
|
const ENDPOINT_MANIFEST_V4 = "application/vnd.restate.endpointmanifest.v4+json";
|
|
8
|
+
const ENDPOINT_MANIFEST_V5 = "application/vnd.restate.endpointmanifest.v5+json";
|
|
8
9
|
function handleDiscovery(endpoint, protocolMode, additionalDiscoveryFields, acceptVersionsString) {
|
|
9
10
|
if (typeof acceptVersionsString !== "string") {
|
|
10
11
|
const errorMessage = "Missing accept header";
|
|
@@ -12,7 +13,8 @@ function handleDiscovery(endpoint, protocolMode, additionalDiscoveryFields, acce
|
|
|
12
13
|
return require_utils.errorResponse(415, errorMessage);
|
|
13
14
|
}
|
|
14
15
|
let manifestVersion;
|
|
15
|
-
if (acceptVersionsString.includes(
|
|
16
|
+
if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V5)) manifestVersion = 5;
|
|
17
|
+
else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V4)) manifestVersion = 4;
|
|
16
18
|
else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V3)) manifestVersion = 3;
|
|
17
19
|
else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V2)) manifestVersion = 2;
|
|
18
20
|
else {
|
|
@@ -47,9 +49,17 @@ function handleDiscovery(endpoint, protocolMode, additionalDiscoveryFields, acce
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
}
|
|
52
|
+
if (manifestVersion < 5) for (const service of discovery.services) {
|
|
53
|
+
const error = checkUnsupportedFeature(service, "eagerStateKeysWhitelist");
|
|
54
|
+
if (error !== void 0) return error;
|
|
55
|
+
for (const handler of service.handlers) {
|
|
56
|
+
const error$1 = checkUnsupportedFeature(handler, "eagerStateKeysWhitelist");
|
|
57
|
+
if (error$1 !== void 0) return error$1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
50
60
|
const body = JSON.stringify(discovery);
|
|
51
61
|
return require_utils.simpleResponse(200, {
|
|
52
|
-
"content-type": manifestVersion === 2 ? ENDPOINT_MANIFEST_V2 : manifestVersion === 3 ? ENDPOINT_MANIFEST_V3 : ENDPOINT_MANIFEST_V4,
|
|
62
|
+
"content-type": manifestVersion === 2 ? ENDPOINT_MANIFEST_V2 : manifestVersion === 3 ? ENDPOINT_MANIFEST_V3 : manifestVersion === 4 ? ENDPOINT_MANIFEST_V4 : ENDPOINT_MANIFEST_V5,
|
|
53
63
|
"x-restate-server": require_user_agent.X_RESTATE_SERVER
|
|
54
64
|
}, new TextEncoder().encode(body));
|
|
55
65
|
}
|
|
@@ -5,6 +5,7 @@ import { errorResponse, simpleResponse } from "./utils.js";
|
|
|
5
5
|
const ENDPOINT_MANIFEST_V2 = "application/vnd.restate.endpointmanifest.v2+json";
|
|
6
6
|
const ENDPOINT_MANIFEST_V3 = "application/vnd.restate.endpointmanifest.v3+json";
|
|
7
7
|
const ENDPOINT_MANIFEST_V4 = "application/vnd.restate.endpointmanifest.v4+json";
|
|
8
|
+
const ENDPOINT_MANIFEST_V5 = "application/vnd.restate.endpointmanifest.v5+json";
|
|
8
9
|
function handleDiscovery(endpoint, protocolMode, additionalDiscoveryFields, acceptVersionsString) {
|
|
9
10
|
if (typeof acceptVersionsString !== "string") {
|
|
10
11
|
const errorMessage = "Missing accept header";
|
|
@@ -12,7 +13,8 @@ function handleDiscovery(endpoint, protocolMode, additionalDiscoveryFields, acce
|
|
|
12
13
|
return errorResponse(415, errorMessage);
|
|
13
14
|
}
|
|
14
15
|
let manifestVersion;
|
|
15
|
-
if (acceptVersionsString.includes(
|
|
16
|
+
if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V5)) manifestVersion = 5;
|
|
17
|
+
else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V4)) manifestVersion = 4;
|
|
16
18
|
else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V3)) manifestVersion = 3;
|
|
17
19
|
else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V2)) manifestVersion = 2;
|
|
18
20
|
else {
|
|
@@ -47,9 +49,17 @@ function handleDiscovery(endpoint, protocolMode, additionalDiscoveryFields, acce
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
}
|
|
52
|
+
if (manifestVersion < 5) for (const service of discovery.services) {
|
|
53
|
+
const error = checkUnsupportedFeature(service, "eagerStateKeysWhitelist");
|
|
54
|
+
if (error !== void 0) return error;
|
|
55
|
+
for (const handler of service.handlers) {
|
|
56
|
+
const error$1 = checkUnsupportedFeature(handler, "eagerStateKeysWhitelist");
|
|
57
|
+
if (error$1 !== void 0) return error$1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
50
60
|
const body = JSON.stringify(discovery);
|
|
51
61
|
return simpleResponse(200, {
|
|
52
|
-
"content-type": manifestVersion === 2 ? ENDPOINT_MANIFEST_V2 : manifestVersion === 3 ? ENDPOINT_MANIFEST_V3 : ENDPOINT_MANIFEST_V4,
|
|
62
|
+
"content-type": manifestVersion === 2 ? ENDPOINT_MANIFEST_V2 : manifestVersion === 3 ? ENDPOINT_MANIFEST_V3 : manifestVersion === 4 ? ENDPOINT_MANIFEST_V4 : ENDPOINT_MANIFEST_V5,
|
|
53
63
|
"x-restate-server": X_RESTATE_SERVER
|
|
54
64
|
}, new TextEncoder().encode(body));
|
|
55
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.js","names":["error"],"sources":["../../../src/endpoint/handlers/discovery.ts"],"sourcesContent":["import type { RestateResponse } from \"./types.js\";\nimport type { Endpoint } from \"../endpoint.js\";\nimport type {\n Endpoint as EndpointManifest,\n ProtocolMode,\n} from \"../discovery.js\";\nimport { X_RESTATE_SERVER } from \"../../user_agent.js\";\nimport { errorResponse, simpleResponse } from \"./utils.js\";\n\nconst ENDPOINT_MANIFEST_V2 = \"application/vnd.restate.endpointmanifest.v2+json\";\nconst ENDPOINT_MANIFEST_V3 = \"application/vnd.restate.endpointmanifest.v3+json\";\nconst ENDPOINT_MANIFEST_V4 = \"application/vnd.restate.endpointmanifest.v4+json\";\n\nexport function handleDiscovery(\n endpoint: Endpoint,\n protocolMode: ProtocolMode,\n additionalDiscoveryFields: Partial<EndpointManifest>,\n acceptVersionsString: string | string[] | undefined\n): RestateResponse {\n if (typeof acceptVersionsString !== \"string\") {\n const errorMessage = \"Missing accept header\";\n endpoint.rlog.warn(errorMessage);\n return errorResponse(415, errorMessage);\n }\n\n // Negotiate version to use\n let manifestVersion;\n if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V4)) {\n manifestVersion = 4;\n } else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V3)) {\n manifestVersion = 3;\n } else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V2)) {\n manifestVersion = 2;\n } else {\n const errorMessage = `Unsupported service discovery protocol version '${acceptVersionsString}'`;\n endpoint.rlog.warn(errorMessage);\n return errorResponse(415, errorMessage);\n }\n\n const discovery = {\n ...endpoint.discoveryMetadata,\n ...additionalDiscoveryFields,\n protocolMode: protocolMode,\n };\n\n const checkUnsupportedFeature = <T extends object>(\n obj: T,\n ...fields: Array<keyof T>\n ) => {\n for (const field of fields) {\n if (field in obj && obj[field] !== undefined) {\n return errorResponse(\n 500,\n `The code uses the new discovery feature '${String(\n field\n )}' but the runtime doesn't support it yet (discovery protocol negotiated version ${manifestVersion}). Either remove the usage of this feature, or upgrade the runtime.`\n );\n }\n }\n return;\n };\n\n // Verify none of the manifest v3 configuration options are used.\n if (manifestVersion < 3) {\n for (const service of discovery.services) {\n const error = checkUnsupportedFeature(\n service,\n \"journalRetention\",\n \"idempotencyRetention\",\n \"inactivityTimeout\",\n \"abortTimeout\",\n \"enableLazyState\",\n \"ingressPrivate\"\n );\n if (error !== undefined) {\n return error;\n }\n for (const handler of service.handlers) {\n const error = checkUnsupportedFeature(\n handler,\n \"journalRetention\",\n \"idempotencyRetention\",\n \"workflowCompletionRetention\",\n \"inactivityTimeout\",\n \"abortTimeout\",\n \"enableLazyState\",\n \"ingressPrivate\"\n );\n if (error !== undefined) {\n return error;\n }\n }\n }\n }\n\n if (manifestVersion < 4) {\n // Blank the lambda compression field. No need to fail in this case.\n discovery.lambdaCompression = undefined;\n for (const service of discovery.services) {\n const error = checkUnsupportedFeature(\n service,\n \"retryPolicyExponentiationFactor\",\n \"retryPolicyInitialInterval\",\n \"retryPolicyMaxAttempts\",\n \"retryPolicyMaxInterval\",\n \"retryPolicyOnMaxAttempts\"\n );\n if (error !== undefined) {\n return error;\n }\n for (const handler of service.handlers) {\n const error = checkUnsupportedFeature(\n handler,\n \"retryPolicyExponentiationFactor\",\n \"retryPolicyInitialInterval\",\n \"retryPolicyMaxAttempts\",\n \"retryPolicyMaxInterval\",\n \"retryPolicyOnMaxAttempts\"\n );\n if (error !== undefined) {\n return error;\n }\n }\n }\n }\n\n const body = JSON.stringify(discovery);\n return simpleResponse(\n 200,\n {\n \"content-type\":\n manifestVersion === 2\n ? ENDPOINT_MANIFEST_V2\n : manifestVersion === 3\n ? ENDPOINT_MANIFEST_V3\n : ENDPOINT_MANIFEST_V4,\n \"x-restate-server\": X_RESTATE_SERVER,\n },\n new TextEncoder().encode(body)\n );\n}\n"],"mappings":";;;;AASA,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAE7B,SAAgB,gBACd,UACA,cACA,2BACA,sBACiB;AACjB,KAAI,OAAO,yBAAyB,UAAU;EAC5C,MAAM,eAAe;AACrB,WAAS,KAAK,KAAK,aAAa;AAChC,SAAO,cAAc,KAAK,aAAa;;CAIzC,IAAI;AACJ,KAAI,qBAAqB,SAAS,qBAAqB,CACrD,mBAAkB;UACT,qBAAqB,SAAS,qBAAqB,CAC5D,mBAAkB;UACT,qBAAqB,SAAS,qBAAqB,CAC5D,mBAAkB;MACb;EACL,MAAM,eAAe,mDAAmD,qBAAqB;AAC7F,WAAS,KAAK,KAAK,aAAa;AAChC,SAAO,cAAc,KAAK,aAAa;;CAGzC,MAAM,YAAY;EAChB,GAAG,SAAS;EACZ,GAAG;EACW;EACf;CAED,MAAM,2BACJ,KACA,GAAG,WACA;AACH,OAAK,MAAM,SAAS,OAClB,KAAI,SAAS,OAAO,IAAI,WAAW,OACjC,QAAO,cACL,KACA,4CAA4C,OAC1C,MACD,CAAC,kFAAkF,gBAAgB,qEACrG;;AAOP,KAAI,kBAAkB,EACpB,MAAK,MAAM,WAAW,UAAU,UAAU;EACxC,MAAM,QAAQ,wBACZ,SACA,oBACA,wBACA,qBACA,gBACA,mBACA,iBACD;AACD,MAAI,UAAU,OACZ,QAAO;AAET,OAAK,MAAM,WAAW,QAAQ,UAAU;GACtC,MAAMA,UAAQ,wBACZ,SACA,oBACA,wBACA,+BACA,qBACA,gBACA,mBACA,iBACD;AACD,OAAIA,YAAU,OACZ,QAAOA;;;AAMf,KAAI,kBAAkB,GAAG;AAEvB,YAAU,oBAAoB;AAC9B,OAAK,MAAM,WAAW,UAAU,UAAU;GACxC,MAAM,QAAQ,wBACZ,SACA,mCACA,8BACA,0BACA,0BACA,2BACD;AACD,OAAI,UAAU,OACZ,QAAO;AAET,QAAK,MAAM,WAAW,QAAQ,UAAU;IACtC,MAAMA,UAAQ,wBACZ,SACA,mCACA,8BACA,0BACA,0BACA,2BACD;AACD,QAAIA,YAAU,OACZ,QAAOA;;;;CAMf,MAAM,OAAO,KAAK,UAAU,UAAU;AACtC,QAAO,eACL,KACA;EACE,gBACE,oBAAoB,IAChB,uBACA,oBAAoB,IAClB,uBACA;
|
|
1
|
+
{"version":3,"file":"discovery.js","names":["error"],"sources":["../../../src/endpoint/handlers/discovery.ts"],"sourcesContent":["import type { RestateResponse } from \"./types.js\";\nimport type { Endpoint } from \"../endpoint.js\";\nimport type {\n Endpoint as EndpointManifest,\n ProtocolMode,\n} from \"../discovery.js\";\nimport { X_RESTATE_SERVER } from \"../../user_agent.js\";\nimport { errorResponse, simpleResponse } from \"./utils.js\";\n\nconst ENDPOINT_MANIFEST_V2 = \"application/vnd.restate.endpointmanifest.v2+json\";\nconst ENDPOINT_MANIFEST_V3 = \"application/vnd.restate.endpointmanifest.v3+json\";\nconst ENDPOINT_MANIFEST_V4 = \"application/vnd.restate.endpointmanifest.v4+json\";\nconst ENDPOINT_MANIFEST_V5 = \"application/vnd.restate.endpointmanifest.v5+json\";\n\nexport function handleDiscovery(\n endpoint: Endpoint,\n protocolMode: ProtocolMode,\n additionalDiscoveryFields: Partial<EndpointManifest>,\n acceptVersionsString: string | string[] | undefined\n): RestateResponse {\n if (typeof acceptVersionsString !== \"string\") {\n const errorMessage = \"Missing accept header\";\n endpoint.rlog.warn(errorMessage);\n return errorResponse(415, errorMessage);\n }\n\n // Negotiate version to use\n let manifestVersion;\n if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V5)) {\n manifestVersion = 5;\n } else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V4)) {\n manifestVersion = 4;\n } else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V3)) {\n manifestVersion = 3;\n } else if (acceptVersionsString.includes(ENDPOINT_MANIFEST_V2)) {\n manifestVersion = 2;\n } else {\n const errorMessage = `Unsupported service discovery protocol version '${acceptVersionsString}'`;\n endpoint.rlog.warn(errorMessage);\n return errorResponse(415, errorMessage);\n }\n\n const discovery = {\n ...endpoint.discoveryMetadata,\n ...additionalDiscoveryFields,\n protocolMode: protocolMode,\n };\n\n const checkUnsupportedFeature = <T extends object>(\n obj: T,\n ...fields: Array<keyof T>\n ) => {\n for (const field of fields) {\n if (field in obj && obj[field] !== undefined) {\n return errorResponse(\n 500,\n `The code uses the new discovery feature '${String(\n field\n )}' but the runtime doesn't support it yet (discovery protocol negotiated version ${manifestVersion}). Either remove the usage of this feature, or upgrade the runtime.`\n );\n }\n }\n return;\n };\n\n // Verify none of the manifest v3 configuration options are used.\n if (manifestVersion < 3) {\n for (const service of discovery.services) {\n const error = checkUnsupportedFeature(\n service,\n \"journalRetention\",\n \"idempotencyRetention\",\n \"inactivityTimeout\",\n \"abortTimeout\",\n \"enableLazyState\",\n \"ingressPrivate\"\n );\n if (error !== undefined) {\n return error;\n }\n for (const handler of service.handlers) {\n const error = checkUnsupportedFeature(\n handler,\n \"journalRetention\",\n \"idempotencyRetention\",\n \"workflowCompletionRetention\",\n \"inactivityTimeout\",\n \"abortTimeout\",\n \"enableLazyState\",\n \"ingressPrivate\"\n );\n if (error !== undefined) {\n return error;\n }\n }\n }\n }\n\n if (manifestVersion < 4) {\n // Blank the lambda compression field. No need to fail in this case.\n discovery.lambdaCompression = undefined;\n for (const service of discovery.services) {\n const error = checkUnsupportedFeature(\n service,\n \"retryPolicyExponentiationFactor\",\n \"retryPolicyInitialInterval\",\n \"retryPolicyMaxAttempts\",\n \"retryPolicyMaxInterval\",\n \"retryPolicyOnMaxAttempts\"\n );\n if (error !== undefined) {\n return error;\n }\n for (const handler of service.handlers) {\n const error = checkUnsupportedFeature(\n handler,\n \"retryPolicyExponentiationFactor\",\n \"retryPolicyInitialInterval\",\n \"retryPolicyMaxAttempts\",\n \"retryPolicyMaxInterval\",\n \"retryPolicyOnMaxAttempts\"\n );\n if (error !== undefined) {\n return error;\n }\n }\n }\n }\n\n // Verify none of the manifest v5 configuration options are used.\n // Note: `enableLazyState` itself is already available since v3; only the\n // eager-state whitelist (selective preloading) requires v5.\n if (manifestVersion < 5) {\n for (const service of discovery.services) {\n const error = checkUnsupportedFeature(service, \"eagerStateKeysWhitelist\");\n if (error !== undefined) {\n return error;\n }\n for (const handler of service.handlers) {\n const error = checkUnsupportedFeature(\n handler,\n \"eagerStateKeysWhitelist\"\n );\n if (error !== undefined) {\n return error;\n }\n }\n }\n }\n\n const body = JSON.stringify(discovery);\n return simpleResponse(\n 200,\n {\n \"content-type\":\n manifestVersion === 2\n ? ENDPOINT_MANIFEST_V2\n : manifestVersion === 3\n ? ENDPOINT_MANIFEST_V3\n : manifestVersion === 4\n ? ENDPOINT_MANIFEST_V4\n : ENDPOINT_MANIFEST_V5,\n \"x-restate-server\": X_RESTATE_SERVER,\n },\n new TextEncoder().encode(body)\n );\n}\n"],"mappings":";;;;AASA,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAE7B,SAAgB,gBACd,UACA,cACA,2BACA,sBACiB;AACjB,KAAI,OAAO,yBAAyB,UAAU;EAC5C,MAAM,eAAe;AACrB,WAAS,KAAK,KAAK,aAAa;AAChC,SAAO,cAAc,KAAK,aAAa;;CAIzC,IAAI;AACJ,KAAI,qBAAqB,SAAS,qBAAqB,CACrD,mBAAkB;UACT,qBAAqB,SAAS,qBAAqB,CAC5D,mBAAkB;UACT,qBAAqB,SAAS,qBAAqB,CAC5D,mBAAkB;UACT,qBAAqB,SAAS,qBAAqB,CAC5D,mBAAkB;MACb;EACL,MAAM,eAAe,mDAAmD,qBAAqB;AAC7F,WAAS,KAAK,KAAK,aAAa;AAChC,SAAO,cAAc,KAAK,aAAa;;CAGzC,MAAM,YAAY;EAChB,GAAG,SAAS;EACZ,GAAG;EACW;EACf;CAED,MAAM,2BACJ,KACA,GAAG,WACA;AACH,OAAK,MAAM,SAAS,OAClB,KAAI,SAAS,OAAO,IAAI,WAAW,OACjC,QAAO,cACL,KACA,4CAA4C,OAC1C,MACD,CAAC,kFAAkF,gBAAgB,qEACrG;;AAOP,KAAI,kBAAkB,EACpB,MAAK,MAAM,WAAW,UAAU,UAAU;EACxC,MAAM,QAAQ,wBACZ,SACA,oBACA,wBACA,qBACA,gBACA,mBACA,iBACD;AACD,MAAI,UAAU,OACZ,QAAO;AAET,OAAK,MAAM,WAAW,QAAQ,UAAU;GACtC,MAAMA,UAAQ,wBACZ,SACA,oBACA,wBACA,+BACA,qBACA,gBACA,mBACA,iBACD;AACD,OAAIA,YAAU,OACZ,QAAOA;;;AAMf,KAAI,kBAAkB,GAAG;AAEvB,YAAU,oBAAoB;AAC9B,OAAK,MAAM,WAAW,UAAU,UAAU;GACxC,MAAM,QAAQ,wBACZ,SACA,mCACA,8BACA,0BACA,0BACA,2BACD;AACD,OAAI,UAAU,OACZ,QAAO;AAET,QAAK,MAAM,WAAW,QAAQ,UAAU;IACtC,MAAMA,UAAQ,wBACZ,SACA,mCACA,8BACA,0BACA,0BACA,2BACD;AACD,QAAIA,YAAU,OACZ,QAAOA;;;;AASf,KAAI,kBAAkB,EACpB,MAAK,MAAM,WAAW,UAAU,UAAU;EACxC,MAAM,QAAQ,wBAAwB,SAAS,0BAA0B;AACzE,MAAI,UAAU,OACZ,QAAO;AAET,OAAK,MAAM,WAAW,QAAQ,UAAU;GACtC,MAAMA,UAAQ,wBACZ,SACA,0BACD;AACD,OAAIA,YAAU,OACZ,QAAOA;;;CAMf,MAAM,OAAO,KAAK,UAAU,UAAU;AACtC,QAAO,eACL,KACA;EACE,gBACE,oBAAoB,IAChB,uBACA,oBAAoB,IAClB,uBACA,oBAAoB,IAClB,uBACA;EACV,oBAAoB;EACrB,EACD,IAAI,aAAa,CAAC,OAAO,KAAK,CAC/B"}
|