Martin Berg Alstad 2e73baf98b
✏ README, fix start-once bug and refactor
- Added some configuration and running to README
- Refactored some code
- Fixed exception when stopping a start-once script
- Only allow running with pnpm
- Moved transactions into sparebank1Api.ts
- Formatted
2025-01-25 22:30:52 +01:00

39 lines
1.2 KiB
TypeScript

import assert from "node:assert"
import dotenv from "dotenv"
dotenv.config()
// Actual
export const ACTUAL_SYNC_ID = getOrThrow("ACTUAL_SYNC_ID")
export const ACTUAL_SERVER_URL = getOrThrow("ACTUAL_SERVER_URL")
export const ACTUAL_PASSWORD = getOrThrow("ACTUAL_PASSWORD")
export const ACTUAL_ACCOUNT_IDS = getArrayOrThrow("ACTUAL_ACCOUNT_IDS")
export const ACTUAL_DATA_DIR = getOrDefault("ACTUAL_DATA_DIR", ".cache")
// Bank
export const BANK_INITIAL_REFRESH_TOKEN = getOrThrow(
"BANK_INITIAL_REFRESH_TOKEN",
)
export const BANK_OAUTH_CLIENT_ID = getOrThrow("BANK_OAUTH_CLIENT_ID")
export const BANK_OAUTH_CLIENT_SECRET = getOrThrow("BANK_OAUTH_CLIENT_SECRET")
export const BANK_ACCOUNT_IDS = getArrayOrThrow("BANK_ACCOUNT_IDS")
// Configuration
export const DB_FILENAME = getOrDefault("DB_FILENAME", "default")
export const LOG_LEVEL = getOrDefault("LOG_LEVEL", "info")
// Utility functions
function getOrDefault(key: string, def: string): string {
return process.env[key] || def
}
function getOrThrow(key: string): string {
const value = process.env[key]
assert(value, `Missing environment variable: ${key}`)
return value
}
function getArrayOrThrow(key: string): ReadonlyArray<string> {
return getOrThrow(key).split(",")
}