Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
ab1ac03993 | |||
3ee4a1677e | |||
29bd68f57d | |||
5227cebc98 | |||
4301a0337c | |||
723833d9bb | |||
cb28b55617 | |||
12614ff011 | |||
7274f7859a | |||
068198a02f | |||
62537fffe2 | |||
22239ddbeb |
15249
package-lock.json
generated
15249
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/tink",
|
"name": "@mojoio/tink",
|
||||||
"version": "3.1.0",
|
"version": "3.1.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an unofficial api abstraction for tink.com",
|
"description": "an unofficial api abstraction for tink.com",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -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
generated
Normal file
4353
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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,14 @@ 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.getNormalizedData()));
|
||||||
|
}
|
||||||
await toolsArg.delayFor(10000);
|
await toolsArg.delayFor(10000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@mojoio/tink',
|
name: '@mojoio/tink',
|
||||||
version: '3.1.0',
|
version: '3.1.6',
|
||||||
description: 'an unofficial api abstraction for tink.com'
|
description: 'an unofficial api abstraction for tink.com'
|
||||||
}
|
}
|
||||||
|
1
ts/helpers/index.ts
Normal file
1
ts/helpers/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './tinkmath.js';
|
22
ts/helpers/tinkmath.ts
Normal file
22
ts/helpers/tinkmath.ts
Normal 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 {
|
||||||
|
value: parseInt(scaledArg.value.unscaledValue) * Math.pow(10, -(parseInt(scaledArg.value.scale))),
|
||||||
|
currency: 'EUR'
|
||||||
|
};
|
||||||
|
};
|
@ -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';
|
@ -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';
|
||||||
|
|
||||||
export interface IBankAccountData {
|
import * as tinkHelpers from './helpers/index.js';
|
||||||
"balances": {
|
|
||||||
"booked": {
|
export interface ITinkBankAccountData {
|
||||||
"amount": {
|
balances: {
|
||||||
"currencyCode": string,
|
booked: {
|
||||||
"value": {
|
amount: {
|
||||||
"scale": string,
|
currencyCode: string;
|
||||||
"unscaledValue": string
|
value: {
|
||||||
}
|
scale: string;
|
||||||
}
|
unscaledValue: string;
|
||||||
}
|
};
|
||||||
},
|
};
|
||||||
"customerSegment": string,
|
};
|
||||||
"dates": {
|
available: {
|
||||||
"lastRefreshed": string
|
amount: {
|
||||||
},
|
currencyCode: string;
|
||||||
"financialInstitutionId": string,
|
value: {
|
||||||
"id": string,
|
scale: string;
|
||||||
"identifiers": {
|
unscaledValue: string;
|
||||||
"iban": {
|
};
|
||||||
"bban": string,
|
};
|
||||||
"iban": string,
|
};
|
||||||
},
|
};
|
||||||
"pan": {
|
customerSegment: string;
|
||||||
"masked": string
|
dates: {
|
||||||
}
|
lastRefreshed: string;
|
||||||
},
|
};
|
||||||
"name": string,
|
financialInstitutionId: string;
|
||||||
"type": string,
|
id: string;
|
||||||
|
identifiers: {
|
||||||
|
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,19 +78,46 @@ 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;
|
||||||
data: IBankAccountData;
|
data: ITinkBankAccountData;
|
||||||
constructor(tinkUserRefArg: TinkUser, dataArg: IBankAccountData) {
|
constructor(tinkUserRefArg: TinkUser, dataArg: ITinkBankAccountData) {
|
||||||
this.tinkUserRef = tinkUserRefArg;
|
this.tinkUserRef = tinkUserRefArg;
|
||||||
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 {
|
||||||
|
id: this.data.id,
|
||||||
|
name: this.data.name,
|
||||||
|
accountNumber: this.data.identifiers?.financialInstitution?.accountNumber || null,
|
||||||
|
iban: this.data.identifiers.iban?.iban || 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
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import { BankAccount } from './tink.classes.bankaccount.js';
|
import { BankAccount } from './tink.classes.bankaccount.js';
|
||||||
import * as plugins from './tink.plugins.js';
|
import * as plugins from './tink.plugins.js';
|
||||||
|
|
||||||
export interface IBankTransactiondata {
|
import * as tinkHelpers from './helpers/index.js';
|
||||||
|
|
||||||
|
export interface ITinkBankTransactiondata {
|
||||||
|
id: string;
|
||||||
accountId:string;
|
accountId:string;
|
||||||
amount: {
|
amount: {
|
||||||
currencyCode: string;
|
currencyCode: string;
|
||||||
@ -24,7 +27,6 @@ export interface IBankTransactiondata {
|
|||||||
display: string;
|
display: string;
|
||||||
original: string;
|
original: string;
|
||||||
};
|
};
|
||||||
id: string;
|
|
||||||
identifiers: {
|
identifiers: {
|
||||||
providerTransactionId: string;
|
providerTransactionId: string;
|
||||||
};
|
};
|
||||||
@ -87,10 +89,28 @@ export class BankTransaction {
|
|||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
bankAccountRef: BankAccount;
|
bankAccountRef: BankAccount;
|
||||||
data: IBankTransactiondata;
|
data: ITinkBankTransactiondata;
|
||||||
|
|
||||||
constructor(bankAccountRefArg: BankAccount, dataArg: IBankTransactiondata) {
|
constructor(bankAccountRefArg: BankAccount, dataArg: ITinkBankTransactiondata) {
|
||||||
this.bankAccountRef = bankAccountRefArg;
|
this.bankAccountRef = bankAccountRefArg;
|
||||||
this.data = dataArg;
|
this.data = dataArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets normalized data
|
||||||
|
*/
|
||||||
|
public getNormalizedData() {
|
||||||
|
return {
|
||||||
|
id: this.data.id,
|
||||||
|
date: new Date(this.data.dates.booked).getTime(),
|
||||||
|
amount: tinkHelpers.getNormalizedAmount(this.data.amount),
|
||||||
|
name: this.data.descriptions.display,
|
||||||
|
description: this.data.descriptions.original,
|
||||||
|
originAccountId: this.data.accountId,
|
||||||
|
justForLooks: {
|
||||||
|
originalScaledAmount: this.data.amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user