Compare commits

..

36 Commits

Author SHA1 Message Date
5abc4e7976 1.0.22 2020-08-25 12:57:15 +00:00
58f4855cb6 fix(core): update 2020-08-25 12:57:14 +00:00
c34846c82f 1.0.21 2020-08-21 01:37:32 +00:00
2656f1a9a9 fix(core): update 2020-08-21 01:37:31 +00:00
e63d24eb13 1.0.20 2020-08-21 01:33:31 +00:00
f0e27bf7c8 fix(core): update 2020-08-21 01:33:30 +00:00
282d2bdf24 1.0.19 2020-08-21 01:31:49 +00:00
04cb6f042f fix(core): update 2020-08-21 01:31:49 +00:00
423bd22903 1.0.18 2020-08-20 01:20:16 +00:00
5295bf272e fix(core): update 2020-08-20 01:20:15 +00:00
752c585e26 1.0.17 2020-08-20 01:08:06 +00:00
a3bfd49d6e fix(core): update 2020-08-20 01:08:05 +00:00
838de2b8bc 1.0.16 2020-06-20 01:47:53 +00:00
01dbf842e9 fix(core): update 2020-06-20 01:47:53 +00:00
9fbaac20d3 1.0.15 2019-12-15 23:07:47 +00:00
270d1406c5 fix(transactions): enter a starting transaction 2019-12-15 23:07:46 +00:00
3cec57e3e7 1.0.14 2019-12-15 17:21:55 +00:00
cebb8a5555 fix(core): update 2019-12-15 17:21:54 +00:00
c3f60959c4 1.0.13 2019-12-15 17:21:24 +00:00
dc97525de6 fix(core): update 2019-12-15 17:21:23 +00:00
eeb93ef969 1.0.12 2019-10-03 14:44:38 +02:00
9cf02e32ef fix(core): update 2019-10-03 14:44:38 +02:00
d41019d341 1.0.11 2019-10-03 14:04:15 +02:00
27f120b608 fix(core): update 2019-10-03 14:04:15 +02:00
4978a2c272 1.0.10 2019-10-03 00:16:05 +02:00
a36f9634ce fix(core): update 2019-10-03 00:16:05 +02:00
f241956743 1.0.9 2019-10-03 00:04:41 +02:00
c40526c16c fix(core): update 2019-10-03 00:04:40 +02:00
945b69a659 1.0.8 2019-10-02 23:50:45 +02:00
0438e5d792 1.0.7 2019-10-02 23:38:54 +02:00
7e85acd404 1.0.6 2019-10-02 23:38:08 +02:00
ecdf7e46cc fix(core): update 2019-10-02 23:38:07 +02:00
7bd4cb67ae 1.0.5 2019-10-02 23:34:05 +02:00
cf5a462bd0 fix(core): update 2019-10-02 23:34:05 +02:00
328007fd97 1.0.4 2019-09-26 13:59:33 +02:00
def87cc216 fix(core): update 2019-09-26 13:59:33 +02:00
15 changed files with 10657 additions and 784 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
- test - test
- release - release
- metadata - metadata
# ==================== # ====================
# security stage # security stage
@ -18,21 +18,36 @@ stages:
mirror: mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
snyk: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install -g snyk - npmci command npm install --production --ignore-scripts
- npmci command npm install --ignore-scripts - npmci command npm config set registry https://registry.npmjs.org
- npmci command snyk test - npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - docker
- notpriv
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -41,37 +56,36 @@ snyk:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
# ==================== # ====================
# metadata stage # metadata stage
@ -79,35 +93,39 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- docker - lossless
- priv - docker
- priv
trigger: trigger:
stage: metadata stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: only:
@ -115,5 +133,5 @@ pages:
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true allow_failure: true

View File

@ -11,7 +11,13 @@
}, },
"gitzone": { "gitzone": {
"type": "object", "type": "object",
"description": "settings for gitzone" "description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
} }
} }
} }

View File

@ -1,5 +1,6 @@
{ {
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "mojoio", "gitscope": "mojoio",

10871
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,46 @@
{ {
"name": "@mojoio/bunq", "name": "@mojoio/bunq",
"version": "1.0.3", "version": "1.0.22",
"private": false, "private": false,
"description": "a bunq api abstraction package", "description": "a bunq api abstraction package",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)", "build": "(tsbuild --web)",
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/qenv": "^4.0.10",
"@types/node": "^10.11.7", "@pushrocks/tapbundle": "^3.2.9",
"tslint": "^5.11.0", "@types/node": "^14.6.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@bunq-community/bunq-js-client": "^0.42.1" "@bunq-community/bunq-js-client": "^1.1.2",
} "@pushrocks/smartcrypto": "^1.0.9",
"@pushrocks/smartfile": "^8.0.0",
"@pushrocks/smartpromise": "^3.0.6",
"json-store": "^1.0.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
} }

2
qenv.yml Normal file
View File

@ -0,0 +1,2 @@
required:
- BUNQ_APIKEY

39
readme.md Normal file
View File

@ -0,0 +1,39 @@
# @mojoio/bunq
a bunq api abstraction package
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/bunq)
* [gitlab.com (source)](https://gitlab.com/mojoio/bunq)
* [github.com (source mirror)](https://github.com/mojoio/bunq)
* [docs (typedoc)](https://mojoio.gitlab.io/bunq/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/mojoio/bunq/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/mojoio/bunq/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@mojoio/bunq)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/mojoio/bunq)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@mojoio/bunq)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@mojoio/bunq)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@mojoio/bunq)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
Use Typescript for best in class intellisense.
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,8 +1,41 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as bunq from '../ts/index' import { Qenv } from '@pushrocks/qenv';
tap.test('first test', async () => { const testQenv = new Qenv('./', './.nogit/');
console.log(bunq.standardExport)
})
tap.start() import * as bunq from '../ts';
let testBunqAccount: bunq.BunqAccount;
const testBunqOptions: bunq.IBunqConstructorOptions = {
apiKey: testQenv.getEnvVarOnDemand('BUNQ_APIKEY'),
deviceName: 'mojoiobunqpackage',
environment: 'SANDBOX',
};
tap.test('should create a valid bunq account', async () => {
testBunqAccount = new bunq.BunqAccount(testBunqOptions);
expect(testBunqAccount).to.be.instanceOf(bunq.BunqAccount);
});
tap.test('should init the client', async () => {
await testBunqAccount.init();
});
tap.test('should get accounts', async () => {
const accounts = await testBunqAccount.getAccounts();
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);
}
});
tap.test('should stop the instance', async () => {
await testBunqAccount.stop();
});
tap.start();

112
ts/bunq.classes.account.ts Normal file
View File

@ -0,0 +1,112 @@
import * as plugins from './bunq.plugins';
import * as paths from './bunq.paths';
import { BunqMonetaryAccount } from './bunq.classes.monetaryaccount';
export interface IBunqConstructorOptions {
deviceName: string;
apiKey: string;
environment: 'SANDBOX' | 'PRODUCTION';
}
/**
* the main bunq account
*/
export class BunqAccount {
public options: IBunqConstructorOptions;
public bunqJSClient: plugins.bunqCommunityClient.default;
public encryptionKey: string;
public permittedIps = []; // bunq will use the current ip if omitted
/**
* user id is needed for doing stuff like listing accounts;
*/
public userId: number;
constructor(optionsArg: IBunqConstructorOptions) {
this.options = optionsArg;
}
public async init() {
this.encryptionKey = plugins.smartcrypto.nodeForge.util.bytesToHex(
plugins.smartcrypto.nodeForge.random.getBytesSync(16)
);
// lets setup bunq client
await plugins.smartfile.fs.ensureDir(paths.nogitDir);
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(
apiKey,
this.permittedIps,
this.options.environment,
this.encryptionKey
);
// install a new keypair
await this.bunqJSClient.install();
// register this device
await this.bunqJSClient.registerDevice(this.options.deviceName);
// register a new session
await this.bunqJSClient.registerSession();
await this.getUserId();
}
/**
* lists all users
*/
private async getUserId() {
const users = await this.bunqJSClient.api.user.list();
if (users.UserPerson) {
this.userId = users.UserPerson.id;
} else if (users.UserApiKey) {
this.userId = users.UserApiKey.id;
} else if (users.UserCompany) {
this.userId = users.UserCompany.id;
} else {
console.log('could not determine user id');
}
}
public async getAccounts() {
const apiMonetaryAccounts = await this.bunqJSClient.api.monetaryAccount
.list(this.userId, {})
.catch((e) => {
console.log(e);
});
const accountsArray: BunqMonetaryAccount[] = [];
for (const apiAccount of apiMonetaryAccounts) {
accountsArray.push(BunqMonetaryAccount.fromAPIObject(this, apiAccount));
}
return accountsArray;
}
/**
* stops the instance
*/
public async stop() {
if (this.bunqJSClient) {
this.bunqJSClient.setKeepAlive(false);
await this.bunqJSClient.destroyApiSession();
this.bunqJSClient = null;
}
}
}

View File

@ -0,0 +1,114 @@
import * as plugins from './bunq.plugins';
import { BunqAccount } from './bunq.classes.account';
import { BunqTransaction } from './bunq.classes.transaction';
export type TAccountType = 'joint' | 'savings' | 'bank';
/**
* a monetary account
*/
export class BunqMonetaryAccount {
public static fromAPIObject(bunqAccountRef: BunqAccount, apiObject: any) {
const newMonetaryAccount = new this(bunqAccountRef);
let type: TAccountType;
let accessor: 'MonetaryAccountBank' | 'MonetaryAccountJoint' | 'MonetaryAccountSavings';
switch (true) {
case !!apiObject.MonetaryAccountBank:
type = 'bank';
accessor = 'MonetaryAccountBank';
break;
case !!apiObject.MonetaryAccountJoint:
type = 'joint';
accessor = 'MonetaryAccountJoint';
break;
case !!apiObject.MonetaryAccountSavings:
type = 'savings';
accessor = 'MonetaryAccountSavings';
break;
case !!apiObject.default:
console.log(apiObject);
throw new Error('unknown accoun type');
}
Object.assign(newMonetaryAccount, apiObject[accessor], { type });
return newMonetaryAccount;
}
// computed
public type: TAccountType;
// from API
public id: number;
public created: string;
public updated: string;
public alias: any[];
public avatar: {
uuid: string;
image: any[];
anchor_uuid: string;
};
public balance: {
currency: string;
value: string;
};
public country: string;
public currency: string;
public daily_limit: {
currency: string;
value: string;
};
public daily_spent: {
currency: string;
value: string;
};
public description: string;
public public_uuid: string;
public status: string;
public sub_status: string;
public timezone: string;
public user_id: number;
public monetary_account_profile: null;
public notification_filters: any[];
public setting: any[];
public connected_cards: any[];
public overdraft_limit: {
currency: string;
value: string;
};
public reason: string;
public reason_description: string;
public auto_save_id: null;
public all_auto_save_id: any[];
public bunqAccountRef: BunqAccount;
constructor(bunqAccountRefArg: BunqAccount) {
this.bunqAccountRef = bunqAccountRefArg;
}
/**
* gets all transactions no this account
*/
public async getTransactions(startingIdArg: number | false = false) {
const paginationOptions: {
count?: number;
newer_id?: number | false;
older_id?: number | false;
} = {
count: 200,
newer_id: startingIdArg,
};
const apiTransactions = await this.bunqAccountRef.bunqJSClient.api.payment.list(
this.bunqAccountRef.userId,
this.id,
paginationOptions
);
const transactionsArray: BunqTransaction[] = [];
for (const apiTransaction of apiTransactions) {
transactionsArray.push(BunqTransaction.fromApiObject(this, apiTransaction));
}
return transactionsArray;
}
}

View File

@ -0,0 +1,67 @@
import * as plugins from './bunq.plugins';
import { BunqMonetaryAccount } from './bunq.classes.monetaryaccount';
export class BunqTransaction {
public static fromApiObject(monetaryAccountRefArg: BunqMonetaryAccount, apiObjectArg: any) {
const newTransaction = new this(monetaryAccountRefArg);
Object.assign(newTransaction, apiObjectArg.Payment);
return newTransaction;
}
public id: number;
public created: string;
public updated: string;
public monetary_account_id: number;
public amount: {
currency: string;
value: string;
};
public description: string;
public type: 'MASTERCARD' | 'BUNQ';
public merchant_reference: null;
public alias: [Object];
public counterparty_alias: {
iban: string,
is_light: any,
display_name: string,
avatar: {
uuid: string,
image: [
{
attachment_public_uuid: string,
height: number,
width: number,
content_type: string,
},
],
anchor_uuid: null,
},
label_user: {
uuid: null,
display_name: string,
country: string,
avatar: null,
public_nick_name: string,
},
country: string,
};
public attachment: [];
public geolocation: null;
public batch_id: null;
public allow_chat: boolean;
public scheduled_id: null;
public address_billing: null;
public address_shipping: null;
public sub_type: 'PAYMENT';
public request_reference_split_the_bill: [];
public balance_after_mutation: {
currency: string;
value: string;
};
public monetaryAccountRef: BunqMonetaryAccount;
constructor(monetaryAccountRefArg: BunqMonetaryAccount) {
this.monetaryAccountRef = monetaryAccountRefArg;
}
}

7
ts/bunq.paths.ts Normal file
View File

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

View File

@ -1,4 +1,17 @@
const removeme = {}; // node natice
export { import * as path from 'path';
removeme
} export { path };
// @pushrocks scope
import * as smartcrypto from '@pushrocks/smartcrypto';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
export { smartcrypto, smartfile, smartpromise };
// third party
import JSONFileStore from '@bunq-community/bunq-js-client/dist/Stores/JSONFileStore';
import * as bunqCommunityClient from '@bunq-community/bunq-js-client';
export { JSONFileStore, bunqCommunityClient };

View File

@ -1,3 +1,3 @@
import * as plugins from './bunq.plugins'; export * from './bunq.classes.account';
export * from './bunq.classes.monetaryaccount';
export let standardExport = 'Hi there! :) This is an exported string'; export * from './bunq.classes.transaction';