🔪🐛 Fixed pnpm in Dockerfile, moved config to src
All checks were successful
Deploy application / deploy (push) Successful in 10s
All checks were successful
Deploy application / deploy (push) Successful in 10s
This commit is contained in:
55
src/config.ts
Normal file
55
src/config.ts
Normal file
@ -0,0 +1,55 @@
|
||||
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_DIRECTORY = getOrDefault("DB_DIRECTORY", "data")
|
||||
export const DB_FILENAME = getOrDefault("DB_FILENAME", "default")
|
||||
export const LOG_LEVEL = getOrDefault("LOG_LEVEL", "info")
|
||||
// TODO default to fetch 1 day
|
||||
// Relative number of days in the past to start fetching transactions from
|
||||
export const TRANSACTION_RELATIVE_FROM_DATE = getNumberOrDefault(
|
||||
"TRANSACTION_RELATIVE_FROM_DATE",
|
||||
4,
|
||||
)
|
||||
// Relative number of days in the past to end fetching transactions from
|
||||
export const TRANSACTION_RELATIVE_TO_DATE = getNumberOrDefault(
|
||||
"TRANSACTION_RELATIVE_TO_DATE",
|
||||
3,
|
||||
)
|
||||
|
||||
// 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(",")
|
||||
}
|
||||
|
||||
function getNumberOrDefault(key: string, def: number): number {
|
||||
const num = Number(process.env[key])
|
||||
return Number.isNaN(num) ? def : num
|
||||
}
|
Reference in New Issue
Block a user