Compare commits

..

7 Commits

Author SHA1 Message Date
2e68da2352 📦 Update dependencies
All checks were successful
Deploy application / deploy (push) Successful in 3s
2025-07-03 20:00:06 +02:00
f68afd0ff7 ⬆️ Updated dependencies
All checks were successful
Deploy application / deploy (push) Successful in 19s
2025-05-15 18:00:05 +02:00
7ea55567da ⬆️ Update actual api to 25.3, cron to 4
All checks were successful
Deploy application / deploy (push) Successful in 18s
2025-03-02 08:37:38 +01:00
080b65854d 🐛 Do not upload transactions that are not booked
All checks were successful
Deploy application / deploy (push) Successful in 8s
2025-02-16 18:22:10 +01:00
a0cefcdfa1 ️ Return early if no transactions were fetched 2025-02-16 18:07:48 +01:00
a2c6c55430 🐛 Fix relative dates are wrong
All checks were successful
Deploy application / deploy (push) Successful in 9s
2025-02-15 12:53:50 +01:00
0e83172558 🔪🐛 Fix docker volume in wrong directory
All checks were successful
Deploy application / deploy (push) Successful in 3s
2025-02-14 17:08:10 +01:00
9 changed files with 1811 additions and 813 deletions

View File

@ -25,8 +25,8 @@ jobs:
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
DB_DIRECTORY: ${{ vars.DB_DIRECTORY }}
DB_FILENAME: ${{ vars.DB_FILENAME }}
TRANSACTION_RELATIVE_FROM_DATE: ${{ vars.TRANSACTION_RELATIVE_FROM_DATE }}
TRANSACTION_RELATIVE_TO_DATE: ${{ vars.TRANSACTION_RELATIVE_TO_DATE }}
TRANSACTION_RELATIVE_FROM_DATE: ${{ vars.TRANSACTION_RELATIVE_FROM_DATE || 'N/A' }}
TRANSACTION_RELATIVE_TO_DATE: ${{ vars.TRANSACTION_RELATIVE_TO_DATE || 'N/A' }}
steps:
- name: Check out repository code

View File

@ -21,8 +21,8 @@ services:
- TRANSACTION_RELATIVE_FROM_DATE
- TRANSACTION_RELATIVE_TO_DATE
volumes:
- cache:/${ACTUAL_DATA_DIR:-.cache}
- data:/${DB_DIRECTORY:-data}
- cache:/app/${ACTUAL_DATA_DIR:-.cache}
- data:/app/${DB_DIRECTORY:-data}
# TODO change volume name from hostexecutor-*
volumes:

View File

@ -14,24 +14,24 @@
"author": "",
"license": "ISC",
"dependencies": {
"@actual-app/api": "^25.2.1",
"@dotenvx/dotenvx": "^1.35.0",
"better-sqlite3": "^11.8.1",
"cron": "^3.5.0",
"@actual-app/api": "^25.7.1",
"@dotenvx/dotenvx": "^1.45.2",
"better-sqlite3": "^12.2.0",
"cron": "^4.3.1",
"dayjs": "^1.11.13",
"dotenv": "^16.4.7",
"prettier": "^3.5.0",
"tsx": "^4.19.2"
"dotenv": "^17.0.1",
"prettier": "^3.6.2",
"tsx": "^4.20.3"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/better-sqlite3": "^7.6.12",
"@types/jest": "^29.5.14",
"@types/node": "^22.13.1",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"@types/better-sqlite3": "^7.6.13",
"@types/jest": "^30.0.0",
"@types/node": "^24.0.10",
"jest": "^30.0.4",
"ts-jest": "^29.4.0",
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
"typescript": "^5.8.3"
},
"prettier": {
"semi": false,

View File

@ -1,6 +1,6 @@
import type { Dayjs } from "dayjs"
import type { UUID } from "node:crypto"
import type { TransactionEntity } from "@actual-app/api/@types/loot-core/types/models"
import { TransactionEntity } from "@actual-app/api/@types/loot-core/src/types/models"
/**
* Defines how to interact with the bank

View File

@ -1,10 +1,10 @@
import type { UUID } from "node:crypto"
import dayjs from "dayjs"
import { ACTUAL_ACCOUNT_IDS, BANK_ACCOUNT_IDS } from "@/config.ts"
import logger from "@common/logger.ts"
import { toISODateString } from "@common/date.ts"
import type { SB1Transaction } from "@sb1/types.ts"
import dayjs from "dayjs"
import type { ActualTransaction } from "@common/types.ts"
import type { SB1Transaction } from "@sb1/types.ts"
import type { UUID } from "node:crypto"
export function bankTransactionIntoActualTransaction(
transaction: SB1Transaction,
@ -18,7 +18,6 @@ export function bankTransactionIntoActualTransaction(
amount: Math.floor(transaction.amount * 100),
date: toISODateString(dayjs(transaction.date)),
payee_name: transaction.cleanedDescription,
// TODO if not cleared or nonUniqueId is 0, rerun later
cleared: isCleared(transaction),
}
}
@ -38,9 +37,7 @@ function getActualAccountId(transcation: SB1Transaction): UUID {
return ACTUAL_ACCOUNT_IDS[i] as UUID
}
}
const error = new Error(
throw new Error(
"Failed to find ActualAccountId, length of BANK_ACCOUNT_IDS and ACTUAL_ACCOUNT_IDS must match",
)
logger.error(error)
throw error
}

View File

@ -1,3 +1,5 @@
import * as Transactions from "@sb1/transactions.ts"
import * as Oauth from "@sb1/oauth.ts"
import {
BANK_INITIAL_REFRESH_TOKEN,
BANK_OAUTH_CLIENT_ID,
@ -5,22 +7,21 @@ import {
DB_DIRECTORY,
DB_FILENAME,
} from "@/config.ts"
import logger from "@common/logger.ts"
import dayjs from "dayjs"
import type { Database } from "better-sqlite3"
import {
clearTokens,
createDb,
fetchToken,
insertTokens,
} from "@sb1impl/db/queries.ts"
import * as Oauth from "@sb1/oauth.ts"
import * as Transactions from "@sb1/transactions.ts"
import { bankTransactionIntoActualTransaction } from "./mappings.ts"
import type { OAuthTokenResponse } from "@sb1/types.ts"
import { createDirIfMissing } from "@/fs.ts"
import logger from "@common/logger.ts"
import dayjs from "dayjs"
import type { ActualTransaction, Bank, Interval } from "@common/types.ts"
import type { TokenResponse } from "@sb1impl/db/types.ts"
import { createDirIfMissing } from "@/fs.ts"
import type { OAuthTokenResponse } from "@sb1/types.ts"
import type { Database } from "better-sqlite3"
export class Sparebank1Impl implements Bank {
private readonly db: Database
@ -31,6 +32,7 @@ export class Sparebank1Impl implements Bank {
this.db = createDb(databaseFilePath)
}
// TODO if not cleared rerun later
async fetchTransactions(
interval: Interval,
...accountKeys: ReadonlyArray<string>
@ -40,8 +42,15 @@ export class Sparebank1Impl implements Bank {
accountKeys,
interval,
)
const sparebankTransactions = response.transactions
return sparebankTransactions.map(bankTransactionIntoActualTransaction)
return response.transactions
.map((transaction) => {
const actualTransaction =
bankTransactionIntoActualTransaction(transaction)
return actualTransaction.cleared === true ? actualTransaction : null
})
.filter((transaction) => transaction !== null)
}
shutdown(): void {

2541
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
import * as fs from "node:fs"
import logger from "@common/logger"
// TODO move to common
export function createDirIfMissing(directory: string): void {
if (!fs.existsSync(directory)) {
logger.info(`Missing '${directory}', creating...`)

View File

@ -15,7 +15,6 @@ import { Sparebank1Impl } from "@sb1impl/sparebank1.ts"
// TODO move tsx to devDependency. Requires ts support for Node with support for @ alias
// TODO verbatimSyntax in tsconfig, conflicts with jest
// TODO store last fetched date in db, and refetch from that date, if app has been offline for some time
// TODO do not fetch if saturday or sunday
async function main(): Promise<void> {
logger.info("Starting application")
@ -38,6 +37,11 @@ export async function moveTransactions(
)
logger.info(`Fetched ${actualTransactions.length} transactions`)
if (actualTransactions.length === 0) {
logger.debug("No transactions to import, skipping")
return
}
const transactionsByAccount = Object.groupBy(
actualTransactions,
(transaction) => transaction.account,