From 68d7c2f5b6bb199bbd3088c48d50347c80f31eb9 Mon Sep 17 00:00:00 2001 From: Emil Styrke Date: Sat, 4 May 2024 23:10:03 +0200 Subject: [PATCH] feat: use 180 day agreements --- lib/nordigen.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/nordigen.ts b/lib/nordigen.ts index 7da2fe6..d6a62d4 100644 --- a/lib/nordigen.ts +++ b/lib/nordigen.ts @@ -49,7 +49,7 @@ const makeRequest = async ( }); if (!res.ok) { - console.log(`problem with request: ${res.status}: ${res.text()}`); + console.log(`problem with request: ${res.status}: ${await res.text()}`); throw new Error(res.statusText); } @@ -89,6 +89,16 @@ export const refreshTokens = async (tokens: Tokens): Promise => { })); }; +export type AgreementData = { + id: string; + created: string; + max_historical_days: number; + access_valid_for_days: number; + access_scope: string[]; + accepted: string; + institution_id: string; +}; + export type RequisitionData = { id: string; created: string; @@ -171,15 +181,28 @@ export type CreateRequisitionOptions = { export const createRequisition = async ( { redirectUrl, institutionId }: CreateRequisitionOptions, session: Session -) => - post( +) => { + const agreement = post( + "/api/v2/agreements/enduser/", + { + institution_id: institutionId, + max_historical_days: 180, + access_valid_for_days: 180, + access_scope: ["balances", "details", "transactions"], + }, + session + ); + + return post( "/api/v2/requisitions/", { redirect: redirectUrl, institution_id: institutionId, + agreement: (await agreement).id, }, session ); +}; export const deleteRequisition = async (id: string, session: Session) => makeRequest(