Skip to content

Commit

Permalink
feat: use 180 day agreements
Browse files Browse the repository at this point in the history
  • Loading branch information
estyrke committed May 4, 2024
1 parent 529cf71 commit 68d7c2f
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/nordigen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const makeRequest = async <Res>(
});

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);
}

Expand Down Expand Up @@ -89,6 +89,16 @@ export const refreshTokens = async (tokens: Tokens): Promise<Tokens> => {
}));
};

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;
Expand Down Expand Up @@ -171,15 +181,28 @@ export type CreateRequisitionOptions = {
export const createRequisition = async (
{ redirectUrl, institutionId }: CreateRequisitionOptions,
session: Session
) =>
post<RequisitionData>(
) => {
const agreement = post<AgreementData>(
"/api/v2/agreements/enduser/",
{
institution_id: institutionId,
max_historical_days: 180,
access_valid_for_days: 180,
access_scope: ["balances", "details", "transactions"],
},
session
);

return post<RequisitionData>(
"/api/v2/requisitions/",
{
redirect: redirectUrl,
institution_id: institutionId,
agreement: (await agreement).id,
},
session
);
};

export const deleteRequisition = async (id: string, session: Session) =>
makeRequest<void>(
Expand Down

0 comments on commit 68d7c2f

Please sign in to comment.