fix(core): update

This commit is contained in:
Philipp Kunz 2019-10-03 14:04:15 +02:00
parent 4978a2c272
commit 27f120b608
5 changed files with 31 additions and 8 deletions

View File

@ -27,15 +27,19 @@ tap.test('should init the client', async () => {
tap.test('should get accounts', async () => {
const accounts = await testBunqAccount.getAccounts();
console.log(accounts[2].alias);
console.log(accounts);
});
tap.test('should get transactions', async () => {
const accounts = await testBunqAccount.getAccounts();
for (const account of accounts) {
const transactions = await account.getTransactions();
// console.log(transactions);
console.log(transactions);
}
});
tap.test('should stop the instance', async () => {
await testBunqAccount.stop();
})
tap.start();

View File

@ -34,13 +34,22 @@ export class BunqAccount {
// lets setup bunq client
await plugins.smartfile.fs.ensureDir(paths.nogitDir);
await plugins.smartfile.fs.ensureFile(paths.bunqJsonFile, '{}');
const storageInstance = plugins.JSONFileStore(paths.bunqJsonFile);
this.bunqJSClient = new plugins.bunqCommunityClient.default(storageInstance);
await plugins.smartfile.fs.ensureFile(paths.bunqJsonProductionFile, '{}');
await plugins.smartfile.fs.ensureFile(paths.bunqJsonSandboxFile, '{}');
let apiKey: string;
if (this.options.environment === 'SANDBOX') {
this.bunqJSClient = new plugins.bunqCommunityClient.default(plugins.JSONFileStore(paths.bunqJsonSandboxFile));
apiKey = await this.bunqJSClient.api.sandboxUser.post();
console.log(apiKey);
} else {
this.bunqJSClient = new plugins.bunqCommunityClient.default(plugins.JSONFileStore(paths.bunqJsonProductionFile));
apiKey = this.options.apiKey;
}
// run the bunq application with our API key
await this.bunqJSClient.run(
this.options.apiKey,
apiKey,
this.permittedIps,
this.options.environment,
this.encryptionKey
@ -79,4 +88,12 @@ export class BunqAccount {
}
return accountsArray;
}
public async stop() {
if (this.bunqJSClient) {
this.bunqJSClient.setKeepAlive(false);
this.bunqJSClient.destroyApiSession();
this.bunqJSClient = null;
}
}
}

View File

@ -97,5 +97,6 @@ export class MonetaryAccount {
for (const apiTransaction of apiTransactions) {
transactionsArray.push(Transaction.fromApiObject(this, apiTransaction));
}
return transactionsArray;
}
}

View File

@ -3,4 +3,5 @@ import * as plugins from './bunq.plugins';
export const packageDir = plugins.path.join(__dirname, '../');
export const nogitDir = plugins.path.join(packageDir, './.nogit/');
export const bunqJsonFile = plugins.path.join(nogitDir, 'bunq.json');
export const bunqJsonProductionFile = plugins.path.join(nogitDir, 'bunqproduction.json');
export const bunqJsonSandboxFile = plugins.path.join(nogitDir, 'bunqsandbox.json');