1import os from "node:os";
2import path from "pathe";
3
4/**
5 * Root of alchemy's user-level auth state (`~/.alchemy`). Overridable with
6 * `ALCHEMY_HOME`, which relocates profiles, credential files,
7 * and cross-process locks together — used by tests to isolate a temp home
8 * and available to users who keep dotfiles elsewhere. Resolved lazily so an
9 * override set after module load (e.g. in a test) still takes effect.
10 */
11export const rootDir = () =>
12 process.env.ALCHEMY_HOME ?? path.join(os.homedir(), ".alchemy");
13
14export const configFilePath = () => path.join(rootDir(), "profiles.json");
15
16/** Directory containing one directory per named profile. */
17export const profilesDirPath = () => path.join(rootDir(), "profiles");
18
19/** Directory containing all provider documents for a named profile. */
20export const profileDirPath = (profile: string) =>
21 path.join(profilesDirPath(), profile);
22
23/** The single persisted document for one provider in one profile. */
24export const profileProviderFilePath = (profile: string, provider: string) =>
25 path.join(profileDirPath(profile), `${provider.toLowerCase()}.json`);
26
27export const credentialsDirPath = () => path.join(rootDir(), "credentials");
28
29export const profileCredentialsDirPath = (profile: string) =>
30 path.join(credentialsDirPath(), profile);