Compare commits
7 Commits
95ddcbaf13
...
main
Author | SHA1 | Date | |
---|---|---|---|
2e68da2352
|
|||
f68afd0ff7
|
|||
7ea55567da
|
|||
080b65854d
|
|||
a0cefcdfa1
|
|||
a2c6c55430
|
|||
0e83172558
|
@ -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
|
||||
|
@ -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:
|
||||
|
26
package.json
26
package.json
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
2541
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -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...`)
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user