blob: a00552da5cde09e2f3363a66763ee4079d39b2ed (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import { join } from "node:path"
import { homedir } from "node:os"
import { mkdirSync, existsSync, readFileSync, writeFileSync } from "node:fs"
export const CONFIG_DIR = join(homedir(), ".config", "sb1-actual")
export const CONFIG_PATH = join(CONFIG_DIR, "config.json")
export const TOKENS_PATH = join(CONFIG_DIR, "tokens.json")
export type AccountMapping = {
sb1Id: string
actualId: string
label?: string
}
export type Config = {
sb1: {
clientId: string
clientSecret: string
finInst: string
}
actual: {
host: string
password: string
fileId: string
}
mappings: AccountMapping[]
anthropicApiKey?: string
}
export function loadConfig(): Config {
if (!existsSync(CONFIG_PATH)) {
throw new Error(`No config found at ${CONFIG_PATH}\n\nRun \`sb1-actual init\` to create it.`)
}
return JSON.parse(readFileSync(CONFIG_PATH, "utf8"))
}
export function saveConfig(config: Config): void {
mkdirSync(CONFIG_DIR, { recursive: true })
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2))
}
|