- CronJob
- interface and simple impl for Actual
- interface and simple impl for Sparebank1
- Mappings between sparebank1 transactions and actual transactions
- Requires type keyword on type imports
This commit is contained in:
2024-11-17 22:27:29 +01:00
parent 90bcf94f14
commit 01af64349e
6 changed files with 167 additions and 34 deletions

View File

@ -5,6 +5,54 @@ import {
ACTUAL_SERVER_URL,
ACTUAL_SYNC_ID,
} from "../config.ts"
import type { TransactionEntity } from "@actual-app/api/@types/loot-core/types/models"
import { type UUID } from "node:crypto"
export interface Actual {
importTransactions: (
accountId: UUID,
transactions: ReadonlyArray<TransactionEntity>,
) => Promise<ImportTransactionsResponse>
shutdown: () => Promise<void>
}
export interface Message {
message: string
}
export interface ImportTransactionsResponse {
errors?: Message[]
added: number
updated: number
}
export class ActualImpl implements Actual {
private constructor() {}
static async init(): Promise<Actual> {
await actual.init({
// Budget data will be cached locally here, in subdirectories for each file.
dataDir: ACTUAL_DATA_DIR,
// This is the URL of your running server
serverURL: ACTUAL_SERVER_URL,
// This is the password you use to log into the server
password: ACTUAL_PASSWORD,
})
return new ActualImpl()
}
async importTransactions(
accountId: UUID,
transactions: ReadonlyArray<TransactionEntity>,
): Promise<ImportTransactionsResponse> {
return await actual.importTransactions(accountId, transactions)
}
async shutdown() {
return await actual.shutdown()
}
}
export async function init() {
return await actual.init({