| 1 | import os from "node:os"; |
| 2 | import 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 | */ |
| 11 | export const rootDir = () => |
| 12 | process.env.ALCHEMY_HOME ?? path.join(os.homedir(), ".alchemy"); |
| 13 | |
| 14 | export const configFilePath = () => path.join(rootDir(), "profiles.json"); |
| 15 | |
| 16 | /** Directory containing one directory per named profile. */ |
| 17 | export const profilesDirPath = () => path.join(rootDir(), "profiles"); |
| 18 | |
| 19 | /** Directory containing all provider documents for a named profile. */ |
| 20 | export const profileDirPath = (profile: string) => |
| 21 | path.join(profilesDirPath(), profile); |
| 22 | |
| 23 | /** The single persisted document for one provider in one profile. */ |
| 24 | export const profileProviderFilePath = (profile: string, provider: string) => |
| 25 | path.join(profileDirPath(profile), `${provider.toLowerCase()}.json`); |
| 26 | |
| 27 | export const credentialsDirPath = () => path.join(rootDir(), "credentials"); |
| 28 | |
| 29 | export const profileCredentialsDirPath = (profile: string) => |
| 30 | path.join(credentialsDirPath(), profile); |