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 }}
|
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
|
||||||
DB_DIRECTORY: ${{ vars.DB_DIRECTORY }}
|
DB_DIRECTORY: ${{ vars.DB_DIRECTORY }}
|
||||||
DB_FILENAME: ${{ vars.DB_FILENAME }}
|
DB_FILENAME: ${{ vars.DB_FILENAME }}
|
||||||
TRANSACTION_RELATIVE_FROM_DATE: ${{ vars.TRANSACTION_RELATIVE_FROM_DATE }}
|
TRANSACTION_RELATIVE_FROM_DATE: ${{ vars.TRANSACTION_RELATIVE_FROM_DATE || 'N/A' }}
|
||||||
TRANSACTION_RELATIVE_TO_DATE: ${{ vars.TRANSACTION_RELATIVE_TO_DATE }}
|
TRANSACTION_RELATIVE_TO_DATE: ${{ vars.TRANSACTION_RELATIVE_TO_DATE || 'N/A' }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
|
@ -21,8 +21,8 @@ services:
|
|||||||
- TRANSACTION_RELATIVE_FROM_DATE
|
- TRANSACTION_RELATIVE_FROM_DATE
|
||||||
- TRANSACTION_RELATIVE_TO_DATE
|
- TRANSACTION_RELATIVE_TO_DATE
|
||||||
volumes:
|
volumes:
|
||||||
- cache:/${ACTUAL_DATA_DIR:-.cache}
|
- cache:/app/${ACTUAL_DATA_DIR:-.cache}
|
||||||
- data:/${DB_DIRECTORY:-data}
|
- data:/app/${DB_DIRECTORY:-data}
|
||||||
|
|
||||||
# TODO change volume name from hostexecutor-*
|
# TODO change volume name from hostexecutor-*
|
||||||
volumes:
|
volumes:
|
||||||
|
26
package.json
26
package.json
@ -14,24 +14,24 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actual-app/api": "^25.2.1",
|
"@actual-app/api": "^25.7.1",
|
||||||
"@dotenvx/dotenvx": "^1.35.0",
|
"@dotenvx/dotenvx": "^1.45.2",
|
||||||
"better-sqlite3": "^11.8.1",
|
"better-sqlite3": "^12.2.0",
|
||||||
"cron": "^3.5.0",
|
"cron": "^4.3.1",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^17.0.1",
|
||||||
"prettier": "^3.5.0",
|
"prettier": "^3.6.2",
|
||||||
"tsx": "^4.19.2"
|
"tsx": "^4.20.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@jest/globals": "^29.7.0",
|
"@jest/globals": "^29.7.0",
|
||||||
"@types/better-sqlite3": "^7.6.12",
|
"@types/better-sqlite3": "^7.6.13",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/node": "^22.13.1",
|
"@types/node": "^24.0.10",
|
||||||
"jest": "^29.7.0",
|
"jest": "^30.0.4",
|
||||||
"ts-jest": "^29.2.5",
|
"ts-jest": "^29.4.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.8.3"
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"semi": false,
|
"semi": false,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { Dayjs } from "dayjs"
|
import type { Dayjs } from "dayjs"
|
||||||
import type { UUID } from "node:crypto"
|
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
|
* 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 { ACTUAL_ACCOUNT_IDS, BANK_ACCOUNT_IDS } from "@/config.ts"
|
||||||
import logger from "@common/logger.ts"
|
|
||||||
import { toISODateString } from "@common/date.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 { ActualTransaction } from "@common/types.ts"
|
||||||
|
import type { SB1Transaction } from "@sb1/types.ts"
|
||||||
|
import type { UUID } from "node:crypto"
|
||||||
|
|
||||||
export function bankTransactionIntoActualTransaction(
|
export function bankTransactionIntoActualTransaction(
|
||||||
transaction: SB1Transaction,
|
transaction: SB1Transaction,
|
||||||
@ -18,7 +18,6 @@ export function bankTransactionIntoActualTransaction(
|
|||||||
amount: Math.floor(transaction.amount * 100),
|
amount: Math.floor(transaction.amount * 100),
|
||||||
date: toISODateString(dayjs(transaction.date)),
|
date: toISODateString(dayjs(transaction.date)),
|
||||||
payee_name: transaction.cleanedDescription,
|
payee_name: transaction.cleanedDescription,
|
||||||
// TODO if not cleared or nonUniqueId is 0, rerun later
|
|
||||||
cleared: isCleared(transaction),
|
cleared: isCleared(transaction),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,9 +37,7 @@ function getActualAccountId(transcation: SB1Transaction): UUID {
|
|||||||
return ACTUAL_ACCOUNT_IDS[i] as 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",
|
"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 {
|
import {
|
||||||
BANK_INITIAL_REFRESH_TOKEN,
|
BANK_INITIAL_REFRESH_TOKEN,
|
||||||
BANK_OAUTH_CLIENT_ID,
|
BANK_OAUTH_CLIENT_ID,
|
||||||
@ -5,22 +7,21 @@ import {
|
|||||||
DB_DIRECTORY,
|
DB_DIRECTORY,
|
||||||
DB_FILENAME,
|
DB_FILENAME,
|
||||||
} from "@/config.ts"
|
} from "@/config.ts"
|
||||||
import logger from "@common/logger.ts"
|
|
||||||
import dayjs from "dayjs"
|
|
||||||
import type { Database } from "better-sqlite3"
|
|
||||||
import {
|
import {
|
||||||
clearTokens,
|
clearTokens,
|
||||||
createDb,
|
createDb,
|
||||||
fetchToken,
|
fetchToken,
|
||||||
insertTokens,
|
insertTokens,
|
||||||
} from "@sb1impl/db/queries.ts"
|
} 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 { 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 { ActualTransaction, Bank, Interval } from "@common/types.ts"
|
||||||
import type { TokenResponse } from "@sb1impl/db/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 {
|
export class Sparebank1Impl implements Bank {
|
||||||
private readonly db: Database
|
private readonly db: Database
|
||||||
@ -31,6 +32,7 @@ export class Sparebank1Impl implements Bank {
|
|||||||
this.db = createDb(databaseFilePath)
|
this.db = createDb(databaseFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO if not cleared rerun later
|
||||||
async fetchTransactions(
|
async fetchTransactions(
|
||||||
interval: Interval,
|
interval: Interval,
|
||||||
...accountKeys: ReadonlyArray<string>
|
...accountKeys: ReadonlyArray<string>
|
||||||
@ -40,8 +42,15 @@ export class Sparebank1Impl implements Bank {
|
|||||||
accountKeys,
|
accountKeys,
|
||||||
interval,
|
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 {
|
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 * as fs from "node:fs"
|
||||||
import logger from "@common/logger"
|
import logger from "@common/logger"
|
||||||
|
|
||||||
|
// TODO move to common
|
||||||
export function createDirIfMissing(directory: string): void {
|
export function createDirIfMissing(directory: string): void {
|
||||||
if (!fs.existsSync(directory)) {
|
if (!fs.existsSync(directory)) {
|
||||||
logger.info(`Missing '${directory}', creating...`)
|
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 move tsx to devDependency. Requires ts support for Node with support for @ alias
|
||||||
// TODO verbatimSyntax in tsconfig, conflicts with jest
|
// 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 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> {
|
async function main(): Promise<void> {
|
||||||
logger.info("Starting application")
|
logger.info("Starting application")
|
||||||
@ -38,6 +37,11 @@ export async function moveTransactions(
|
|||||||
)
|
)
|
||||||
logger.info(`Fetched ${actualTransactions.length} transactions`)
|
logger.info(`Fetched ${actualTransactions.length} transactions`)
|
||||||
|
|
||||||
|
if (actualTransactions.length === 0) {
|
||||||
|
logger.debug("No transactions to import, skipping")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const transactionsByAccount = Object.groupBy(
|
const transactionsByAccount = Object.groupBy(
|
||||||
actualTransactions,
|
actualTransactions,
|
||||||
(transaction) => transaction.account,
|
(transaction) => transaction.account,
|
||||||
|
Reference in New Issue
Block a user