🌟 Refactor

- Moved mappings into Sb1 impl
- Moved Actual types to @common
- Moved createDirIfMissing to respective functions
- Refactored main into multiple functions
- Moved create db into Sb1impl and close
- Log requests on info
This commit is contained in:
2025-02-13 21:07:30 +01:00
parent 06cc89f762
commit 4367c24fb0
13 changed files with 178 additions and 118 deletions

View File

@ -1,4 +1,4 @@
import { OAuthTokenResponse, Result } from "./types"
import type { OAuthTokenResponse, Result } from "./types"
import * as querystring from "node:querystring"
import { baseUrl, failure, success } from "./common"
import logger from "@common/logger"

View File

@ -1,8 +1,9 @@
import type { Interval, TransactionResponse } from "./types"
import type { TransactionResponse } from "./types"
import * as querystring from "node:querystring"
import { toISODateString } from "@common/date"
import logger from "@common/logger"
import { baseUrl } from "./common"
import type { Interval } from "@common/types.ts"
export async function list(
accessToken: string,
@ -18,7 +19,7 @@ export async function list(
})
const url = `${baseUrl}/personal/banking/transactions?${queryString}`
logger.debug(`Sending GET request to '${url}'`)
logger.info(`GET '${url}'`)
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${accessToken}`,

View File

@ -1,14 +1,7 @@
import type { Dayjs } from "dayjs"
export type Success<T> = { status: "success"; data: T }
export type Failure<T> = { status: "failure"; data: T }
export type Result<OK, Err> = Success<OK> | Failure<Err>
export interface Interval {
fromDate: Dayjs
toDate: Dayjs
}
export interface OAuthTokenResponse {
access_token: string
expires_in: number
@ -20,6 +13,10 @@ export interface OAuthTokenResponse {
export type BookingStatus = "PENDING" | "BOOKED"
/**
* 18-character unique ID used to identify a transaction
* The value is "000000000000000000" until the transaction is booked, and might be set a few days later
*/
export type NonUniqueId = "000000000000000000" | `${number}`
export interface SB1Transaction {