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

main
ts 48 lines 1.27 KB
Raw
1 import { getEnvRedactedRequired } from "alchemy/Auth/Env";
2 import {
3 makeStoredAuthProvider,
4 storedSecret,
5 type StoredAuthConfig,
6 } from "alchemy/Auth/StoredAuthProvider";
7 import * as Effect from "effect/Effect";
8 import * as Redacted from "effect/Redacted";
9
10 export const NEON_AUTH_PROVIDER_NAME = "Neon";
11
12 export type NeonAuthConfig = StoredAuthConfig;
13
14 export type NeonResolvedCredentials = {
15 type: "apiKey";
16 apiKey: Redacted.Redacted<string>;
17 source: { type: NeonAuthConfig["method"] | "env"; details?: string };
18 };
19
20 const neonAuth = makeStoredAuthProvider<NeonResolvedCredentials>({
21 provider: NEON_AUTH_PROVIDER_NAME,
22 fields: [{ name: "apiKey", label: "Neon API Key", secret: true }],
23 toResolved: (values) => ({
24 type: "apiKey",
25 apiKey: storedSecret(values.apiKey) ?? Redacted.make(""),
26 source: { type: "stored" },
27 }),
28 readEnvironment: getEnvRedactedRequired("NEON_API_KEY").pipe(
29 Effect.map((apiKey) => ({
30 type: "apiKey" as const,
31 apiKey,
32 source: { type: "env" as const },
33 })),
34 ),
35 environment: [
36 {
37 name: "NEON_API_KEY",
38 required: true,
39 secret: true,
40 },
41 ],
42 });
43
44 /**
45 * Layer that registers the Neon {@link AuthProvider} into the
46 * {@link AuthProviders} registry.
47 */
48 export const NeonAuth = neonAuth.layer;