fix(core): update
This commit is contained in:
		
							
								
								
									
										15249
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										15249
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -15,15 +15,15 @@ | ||||
|   "devDependencies": { | ||||
|     "@gitzone/tsbuild": "^2.1.65", | ||||
|     "@gitzone/tsbundle": "^2.0.7", | ||||
|     "@gitzone/tsrun": "^1.2.39", | ||||
|     "@gitzone/tstest": "^1.0.73", | ||||
|     "@pushrocks/qenv": "^5.0.2", | ||||
|     "@pushrocks/tapbundle": "^5.0.4", | ||||
|     "@types/node": "^18.7.8", | ||||
|     "tslint": "^6.1.3", | ||||
|     "tslint-config-prettier": "^1.15.0" | ||||
|     "@types/node": "^18.11.7" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@pushrocks/smartdelay": "^2.0.13", | ||||
|     "@pushrocks/smartpromise": "^3.1.7", | ||||
|     "@pushrocks/smartrequest": "^2.0.10", | ||||
|     "@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) => { | ||||
|   await toolsArg.delayFor(60000); | ||||
|   await toolsArg.delayFor(30000); | ||||
| }); | ||||
|  | ||||
| tap.test('get provider consents', async () => { | ||||
| @@ -43,11 +43,15 @@ tap.test('get provider consents', async () => { | ||||
| tap.test('get bankaccounts', async (toolsArg) => { | ||||
|   const tinkuser: tink.TinkUser = await tinkTestAccount.getTinkUser('user_1234_abc'); | ||||
|   const bankAccounts = await tinkuser.getAllBankAccounts(); | ||||
|   console.log(bankAccounts); | ||||
|   console.log(bankAccounts.map(bankAccountArg => bankAccountArg.getNormalizedData())); | ||||
|  | ||||
|   for (const bankAccount of bankAccounts) { | ||||
|     const transactions = await bankAccount.getTransactions(); | ||||
|     console.log(transactions); | ||||
|     for (const transaction of transactions) { | ||||
|       console.log(`=======================`) | ||||
|       console.log(JSON.stringify(transaction)); | ||||
|  | ||||
|     } | ||||
|     await toolsArg.delayFor(10000); | ||||
|   }  | ||||
| }); | ||||
|   | ||||
| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@mojoio/tink', | ||||
|   version: '3.1.0', | ||||
|   version: '3.1.1', | ||||
|   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 { | ||||
|     amount: parseInt(scaledArg.value.unscaledValue) / (10 ^ parseInt(scaledArg.value.scale)), | ||||
|     currency: 'EUR' | ||||
|   }; | ||||
| }; | ||||
| @@ -1,3 +1,3 @@ | ||||
| export * from './tink.classes.tinkaccount.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 * as plugins from './tink.plugins.js'; | ||||
|  | ||||
| import * as tinkHelpers from './helpers/index.js'; | ||||
|  | ||||
| export interface IBankAccountData { | ||||
|   "balances": { | ||||
|     "booked": { | ||||
|       "amount": { | ||||
|         "currencyCode": string, | ||||
|         "value": { | ||||
|           "scale": string, | ||||
|           "unscaledValue": string | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   }, | ||||
|   "customerSegment": string, | ||||
|   "dates": { | ||||
|     "lastRefreshed": string | ||||
|   }, | ||||
|   "financialInstitutionId": string, | ||||
|   "id": string, | ||||
|   "identifiers": { | ||||
|     "iban": { | ||||
|       "bban": string, | ||||
|       "iban": string, | ||||
|     }, | ||||
|     "pan": { | ||||
|       "masked": string | ||||
|     } | ||||
|   }, | ||||
|   "name": string, | ||||
|   "type": string, | ||||
|   balances: { | ||||
|     booked: { | ||||
|       amount: { | ||||
|         currencyCode: string; | ||||
|         value: { | ||||
|           scale: string; | ||||
|           unscaledValue: string; | ||||
|         }; | ||||
|       }; | ||||
|     }; | ||||
|     available: { | ||||
|       amount: { | ||||
|         currencyCode: string; | ||||
|         value: { | ||||
|           scale: string; | ||||
|           unscaledValue: string; | ||||
|         }; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
|   customerSegment: string; | ||||
|   dates: { | ||||
|     lastRefreshed: string; | ||||
|   }; | ||||
|   financialInstitutionId: string; | ||||
|   id: string; | ||||
|   identifiers: { | ||||
|     iban?: { | ||||
|       bban: string; | ||||
|       iban: string; | ||||
|     }; | ||||
|     pan: { | ||||
|       masked: string; | ||||
|     }; | ||||
|     financialInstitution: { accountNumber: string; referenceNumbers: unknown }; | ||||
|   }; | ||||
|   name: string; | ||||
|   type: string; | ||||
| } | ||||
|  | ||||
| export class BankAccount { | ||||
| @@ -47,12 +59,12 @@ export class BankAccount { | ||||
|  | ||||
|   public static async getBankAccountsForUser(tinkUserArg: TinkUser) { | ||||
|     const userAccessToken = await this.getAccountUserAccessToken(tinkUserArg); | ||||
|     const returnBankAccounts: BankAccount[] = [] | ||||
|     const returnBankAccounts: BankAccount[] = []; | ||||
|     const getBankAccountRecursively = async (nextPageToken?: string) => { | ||||
|       const searchParams = new URLSearchParams(); | ||||
|       searchParams.set('pageSize', '200'); | ||||
|       if (nextPageToken) { | ||||
|         searchParams.set('pageToken', nextPageToken) | ||||
|         searchParams.set('pageToken', nextPageToken); | ||||
|       } | ||||
|       const response = await tinkUserArg.tinkAccountRef.request({ | ||||
|         urlArg: `/data/v2/accounts?${searchParams.toString()}`, | ||||
| @@ -66,10 +78,10 @@ export class BankAccount { | ||||
|       if (response.nextPageToken.length > 0) { | ||||
|         await getBankAccountRecursively(response.nextPageToken); | ||||
|       } | ||||
|     } | ||||
|     }; | ||||
|     await getBankAccountRecursively(); | ||||
|     return returnBankAccounts; | ||||
|   }; | ||||
|   } | ||||
|  | ||||
|   // INSTANCE | ||||
|   tinkUserRef: TinkUser; | ||||
| @@ -79,6 +91,34 @@ export class BankAccount { | ||||
|     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 | ||||
|    */ | ||||
|   | ||||
| @@ -119,7 +119,7 @@ export class TinkUser { | ||||
|     customState: string; | ||||
|     testProviderBool?: boolean; | ||||
|   } = { | ||||
|     countryId: 'DE', | ||||
|     countryId: 'NL', | ||||
|     redirectUrl: 'https://console.tink.com/callback', | ||||
|     customState: "exampleState", | ||||
|     testProviderBool: true | ||||
|   | ||||
		Reference in New Issue
	
	Block a user