fix(core): update

This commit is contained in:
Philipp Kunz 2022-10-29 16:18:29 +02:00
parent 9b7f25c996
commit 22239ddbeb
10 changed files with 4461 additions and 15290 deletions

15249
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,15 +15,15 @@
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.65", "@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsbundle": "^2.0.7", "@gitzone/tsbundle": "^2.0.7",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.73", "@gitzone/tstest": "^1.0.73",
"@pushrocks/qenv": "^5.0.2", "@pushrocks/qenv": "^5.0.2",
"@pushrocks/tapbundle": "^5.0.4", "@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.7.8", "@types/node": "^18.11.7"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.13", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrequest": "^2.0.10", "@pushrocks/smartrequest": "^2.0.10",
"@pushrocks/smarturl": "^3.0.5" "@pushrocks/smarturl": "^3.0.5"
}, },

4353
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ tap.test('should create a valid request', async (toolsArg) => {
}); });
tap.test('allow tink link to be used', async (toolsArg) => { tap.test('allow tink link to be used', async (toolsArg) => {
await toolsArg.delayFor(60000); await toolsArg.delayFor(30000);
}); });
tap.test('get provider consents', async () => { tap.test('get provider consents', async () => {
@ -43,11 +43,15 @@ tap.test('get provider consents', async () => {
tap.test('get bankaccounts', async (toolsArg) => { tap.test('get bankaccounts', async (toolsArg) => {
const tinkuser: tink.TinkUser = await tinkTestAccount.getTinkUser('user_1234_abc'); const tinkuser: tink.TinkUser = await tinkTestAccount.getTinkUser('user_1234_abc');
const bankAccounts = await tinkuser.getAllBankAccounts(); const bankAccounts = await tinkuser.getAllBankAccounts();
console.log(bankAccounts); console.log(bankAccounts.map(bankAccountArg => bankAccountArg.getNormalizedData()));
for (const bankAccount of bankAccounts) { for (const bankAccount of bankAccounts) {
const transactions = await bankAccount.getTransactions(); const transactions = await bankAccount.getTransactions();
console.log(transactions); for (const transaction of transactions) {
console.log(`=======================`)
console.log(JSON.stringify(transaction));
}
await toolsArg.delayFor(10000); await toolsArg.delayFor(10000);
} }
}); });

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@mojoio/tink', name: '@mojoio/tink',
version: '3.1.0', version: '3.1.1',
description: 'an unofficial api abstraction for tink.com' description: 'an unofficial api abstraction for tink.com'
} }

1
ts/helpers/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './tinkmath.js';

22
ts/helpers/tinkmath.ts Normal file
View File

@ -0,0 +1,22 @@
export interface ITinkScaledAmount {
value: {
unscaledValue: string;
scale: string;
};
currencyCode: string;
}
/**
* returns a normalized amount
* @param scaledArg
* @returns
*/
export const getNormalizedAmount = (scaledArg?: ITinkScaledAmount) => {
if (!scaledArg) {
return null;
}
return {
amount: parseInt(scaledArg.value.unscaledValue) / (10 ^ parseInt(scaledArg.value.scale)),
currency: 'EUR'
};
};

View File

@ -1,3 +1,3 @@
export * from './tink.classes.tinkaccount.js'; export * from './tink.classes.tinkaccount.js';
export * from './tink.classes.tinkuser.js'; export * from './tink.classes.tinkuser.js';
export * from './tink.classes.tinkproviderconsent.js'; export * from './tink.classes.tinkproviderconsent.js';

View File

@ -2,35 +2,47 @@ import { BankTransaction } from './tink.classes.banktransaction.js';
import { TinkUser } from './tink.classes.tinkuser.js'; import { TinkUser } from './tink.classes.tinkuser.js';
import * as plugins from './tink.plugins.js'; import * as plugins from './tink.plugins.js';
import * as tinkHelpers from './helpers/index.js';
export interface IBankAccountData { export interface IBankAccountData {
"balances": { balances: {
"booked": { booked: {
"amount": { amount: {
"currencyCode": string, currencyCode: string;
"value": { value: {
"scale": string, scale: string;
"unscaledValue": string unscaledValue: string;
} };
} };
} };
}, available: {
"customerSegment": string, amount: {
"dates": { currencyCode: string;
"lastRefreshed": string value: {
}, scale: string;
"financialInstitutionId": string, unscaledValue: string;
"id": string, };
"identifiers": { };
"iban": { };
"bban": string, };
"iban": string, customerSegment: string;
}, dates: {
"pan": { lastRefreshed: string;
"masked": string };
} financialInstitutionId: string;
}, id: string;
"name": string, identifiers: {
"type": string, iban?: {
bban: string;
iban: string;
};
pan: {
masked: string;
};
financialInstitution: { accountNumber: string; referenceNumbers: unknown };
};
name: string;
type: string;
} }
export class BankAccount { export class BankAccount {
@ -47,12 +59,12 @@ export class BankAccount {
public static async getBankAccountsForUser(tinkUserArg: TinkUser) { public static async getBankAccountsForUser(tinkUserArg: TinkUser) {
const userAccessToken = await this.getAccountUserAccessToken(tinkUserArg); const userAccessToken = await this.getAccountUserAccessToken(tinkUserArg);
const returnBankAccounts: BankAccount[] = [] const returnBankAccounts: BankAccount[] = [];
const getBankAccountRecursively = async (nextPageToken?: string) => { const getBankAccountRecursively = async (nextPageToken?: string) => {
const searchParams = new URLSearchParams(); const searchParams = new URLSearchParams();
searchParams.set('pageSize', '200'); searchParams.set('pageSize', '200');
if (nextPageToken) { if (nextPageToken) {
searchParams.set('pageToken', nextPageToken) searchParams.set('pageToken', nextPageToken);
} }
const response = await tinkUserArg.tinkAccountRef.request({ const response = await tinkUserArg.tinkAccountRef.request({
urlArg: `/data/v2/accounts?${searchParams.toString()}`, urlArg: `/data/v2/accounts?${searchParams.toString()}`,
@ -66,10 +78,10 @@ export class BankAccount {
if (response.nextPageToken.length > 0) { if (response.nextPageToken.length > 0) {
await getBankAccountRecursively(response.nextPageToken); await getBankAccountRecursively(response.nextPageToken);
} }
} };
await getBankAccountRecursively(); await getBankAccountRecursively();
return returnBankAccounts; return returnBankAccounts;
}; }
// INSTANCE // INSTANCE
tinkUserRef: TinkUser; tinkUserRef: TinkUser;
@ -79,6 +91,34 @@ export class BankAccount {
this.data = dataArg; this.data = dataArg;
} }
/**
* updates the account and tries to get the latest state from bunq
*/
public async update() {
const bankAccounts = await BankAccount.getBankAccountsForUser(this.tinkUserRef);
const matchingAccount = bankAccounts.find(
(bankAccountArg) => bankAccountArg.data.id === this.data.id
);
if (matchingAccount) {
this.data = matchingAccount.data;
}
}
/**
* gets normalized data
*/
public getNormalizedData() {
return {
name: this.data.name,
accountNumber:
this.data.identifiers.iban?.iban ||
this.data.identifiers?.financialInstitution?.accountNumber ||
null,
bookedValue: tinkHelpers.getNormalizedAmount(this.data.balances.booked?.amount),
availableValue: tinkHelpers.getNormalizedAmount(this.data.balances.available?.amount),
};
}
/** /**
* gets the transactions for the bank account * gets the transactions for the bank account
*/ */

View File

@ -119,7 +119,7 @@ export class TinkUser {
customState: string; customState: string;
testProviderBool?: boolean; testProviderBool?: boolean;
} = { } = {
countryId: 'DE', countryId: 'NL',
redirectUrl: 'https://console.tink.com/callback', redirectUrl: 'https://console.tink.com/callback',
customState: "exampleState", customState: "exampleState",
testProviderBool: true testProviderBool: true