2024-11-17 22:27:29 +01:00
|
|
|
// TODO move types
|
|
|
|
export interface OAuthTokenResponse {
|
|
|
|
access_token: string
|
|
|
|
expires_in: number
|
|
|
|
refresh_token_expires_in: number
|
|
|
|
refresh_token_absolute_expires_in: number
|
|
|
|
token_type: "Bearer"
|
|
|
|
refresh_token: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Transaction {
|
|
|
|
id: string
|
|
|
|
date: string
|
|
|
|
amount: number
|
|
|
|
description: string
|
|
|
|
cleanedDescription: string
|
|
|
|
remoteAccountName: string
|
|
|
|
|
|
|
|
[key: string]: string | number | boolean | unknown
|
|
|
|
}
|
|
|
|
|
|
|
|
export type Bank = Sparebank1
|
|
|
|
|
|
|
|
export interface Sparebank1 {
|
|
|
|
accessToken: () => Promise<OAuthTokenResponse>
|
|
|
|
refreshToken: (refreshToken: string) => Promise<OAuthTokenResponse>
|
|
|
|
|
|
|
|
transactionsPastDay: (
|
|
|
|
accountKeys: ReadonlyArray<string> | string,
|
|
|
|
accessToken: string,
|
|
|
|
) => Promise<ReadonlyArray<Transaction>>
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Sparebank1Impl implements Sparebank1 {
|
|
|
|
private baseUrl = "https://api.sparebank1.no"
|
|
|
|
|
2024-12-01 19:35:45 +01:00
|
|
|
// TODO remove?
|
2024-11-17 22:27:29 +01:00
|
|
|
async accessToken(): Promise<OAuthTokenResponse> {
|
2024-12-01 19:35:45 +01:00
|
|
|
throw new Error("Not implemented")
|
2024-11-17 22:27:29 +01:00
|
|
|
|
2024-12-01 19:35:45 +01:00
|
|
|
// if (response.ok) {
|
|
|
|
// return await response.json()
|
|
|
|
// }
|
|
|
|
// throw new Error(`Failed to get access token. ${response.statusText}`)
|
2024-11-17 22:27:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async refreshToken(refreshToken: string): Promise<OAuthTokenResponse> {
|
|
|
|
throw new Error("Not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
async transactionsPastDay(
|
|
|
|
accountKeys: ReadonlyArray<string> | string,
|
|
|
|
accessToken: string,
|
|
|
|
): Promise<ReadonlyArray<Transaction>> {
|
|
|
|
throw new Error("Not implemented")
|
|
|
|
}
|
2024-11-15 22:55:53 +01:00
|
|
|
}
|