@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 34 lines 1.19 KB
Raw
1 import { makeRandom } from "alchemy/Random";
2
3 /** Env var on the RPC host. Callers send it as {@link RPC_TOKEN_HEADER}. */
4 export const RPC_TOKEN_ENV = "ALCHEMY_RPC_TOKEN";
5
6 /** Request header the caller must send. Never accepted from the public edge. */
7 export const RPC_TOKEN_HEADER = "x-alchemy-rpc-token";
8
9 export const PRIVATE_HOST_SUFFIX = ".railway.internal";
10
11 export const DEFAULT_RPC_PORT = 3000;
12
13 /** Same prefix as `alchemy/Rpc` so Function canvas code does not import Rpc.ts. */
14 export const RPC_PATH_PREFIX = "/__rpc__/";
15
16 /** Same envelope tag as `alchemy/Rpc.ErrorTag`. */
17 export const RPC_ERROR_TAG = "~alchemy/rpc/error";
18
19 export const RPC_TOKEN_ATTR = "rpcToken";
20
21 const envKey = (logicalId: string, suffix: string) =>
22 `RAILWAY_RPC_${logicalId.replaceAll(/[^a-zA-Z0-9]/g, "_").toUpperCase()}_${suffix}`;
23
24 export const rpcEnvKeys = (logicalId: string) => ({
25 host: envKey(logicalId, "HOST"),
26 port: envKey(logicalId, "PORT"),
27 token: envKey(logicalId, "TOKEN"),
28 });
29
30 /**
31 * Child {@link makeRandom} for a Function/Service logical id. Generated
32 * once, persisted in alchemy state, reused on later deploys.
33 */
34 export const mintRpcToken = (logicalId: string) => makeRandom(`${logicalId}RpcToken`);