Initial commit

This commit is contained in:
2024-11-15 22:55:53 +01:00
commit 90bcf94f14
14 changed files with 1134 additions and 0 deletions

32
src/actual.ts Normal file
View File

@ -0,0 +1,32 @@
import * as actual from "@actual-app/api"
import {
ACTUAL_DATA_DIR,
ACTUAL_PASSWORD,
ACTUAL_SERVER_URL,
ACTUAL_SYNC_ID,
} from "../config.ts"
export async function init() {
return 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,
})
}
export async function downloadBudget() {
const something = await actual.downloadBudget(ACTUAL_SYNC_ID)
console.log("downloadBudget", something)
return something
}
export async function getAccounts() {
return await actual.getAccounts()
}
export async function shutdown() {
await actual.shutdown()
}

0
src/cron.ts Normal file
View File

39
src/main.ts Normal file
View File

@ -0,0 +1,39 @@
// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts
import { downloadBudget, getAccounts, init, shutdown } from "@/actual.ts"
import * as actual from "@actual-app/api"
// TODO actual api does not work with Deno or Bun, because of better-sqlite3. Use Node LTS ☹
async function main() {
console.log("Before init")
await init()
console.log("After init")
console.log("Downloading budget")
await downloadBudget()
console.log("Downloaded budget")
await actual.getBudgetMonth("2024-11")
actual
.getTransactions(
"8e54a5d9-2155-47ff-9b5e-3f87415c2d10",
new Date("01-01-2024"),
new Date("12-12-2024"),
)
.then((transactions) => {
console.log("Transactions", transactions)
})
.catch((error) => {
console.error("Error", error)
})
console.log("Getting accounts")
const accounts = await getAccounts()
console.log("Accounts", accounts)
console.log("Before shutdown")
await shutdown()
console.log("After shutdown")
}
void main()

14
src/sparebank1.ts Normal file
View File

@ -0,0 +1,14 @@
import {
SPAREBANK1_OAUTH_CLIENT_ID,
SPAREBANK1_OAUTH_REDIRECT_URI,
SPAREBANK1_OAUTH_STATE,
} from "../config.ts"
async function authorize() {
await fetch(`https://api.sparebank1.no/oauth/authorize?
client_id=${SPAREBANK1_OAUTH_CLIENT_ID}&
state=${SPAREBANK1_OAUTH_STATE}&
redirect_uri=${SPAREBANK1_OAUTH_REDIRECT_URI}&
finInst=fid-smn&
response_type=code`)
}