bankson-js-mb 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.cjs ADDED
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ plugins: [
3
+ 'simple-import-sort',
4
+ 'unicorn'
5
+ ],
6
+ extends: [
7
+ 'madbooster-node-app'
8
+ ],
9
+ rules: {
10
+ 'n/no-missing-import': 2,
11
+ 'n/no-extraneous-import': 2,
12
+ 'n/file-extension-in-import': 2,
13
+
14
+ 'import/no-unresolved': 2,
15
+ 'import/no-useless-path-segments': 2,
16
+ 'import/no-extraneous-dependencies': 2,
17
+ 'import/no-commonjs': [2, { allowRequire: true }],
18
+ 'import/extensions': [2, 'ignorePackages'],
19
+ 'simple-import-sort/imports': 2,
20
+ 'sort-imports': 0, // import sort plugin needs this
21
+ 'import/order': 0,
22
+ 'import/newline-after-import': 2,
23
+ 'unicorn/prefer-module': 2,
24
+ 'unicorn/prefer-node-protocol': 2,
25
+ 'lodash/prefer-lodash-typecheck': 0
26
+ }
27
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 banksonfi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Bankson.fi Node.JS client
2
+
3
+ API documentation: [Official bankson.fi documentation](http://docs.bankson.fi)
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm install --save bankson-js
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import Client from 'bankson-js';
15
+ var client = new Client({
16
+ bearerToken: bearerTokenObtainedWithOAuth2
17
+ });
18
+
19
+ client.me().then(resp => {
20
+ console.log('Current user', resp.user);
21
+ });
22
+
23
+ ```
24
+
25
+ ## Dynamic bearer token
26
+
27
+ Because of the expiring nature of bearer tokens you can validate and refresh them before every request by providing a `beforeRequest` function that returns
28
+ a promise:
29
+
30
+ ```js
31
+ import Client from 'bankson-js';
32
+ var client = new Client({
33
+ beforeRequest: () => {
34
+ return refreshMyToken().then(token => {
35
+ return {
36
+ bearerToken: token
37
+ };
38
+ });
39
+ }
40
+ });
41
+ ```
42
+
43
+ ## Test mode
44
+
45
+ To support API requests in test mode, you can either specify `test: true` in the constructor options or return `test: true` in the promised value in `beforeRequest`.
46
+
47
+ ## License
48
+
49
+ MIT License
Binary file
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "bankson-js-mb",
3
+ "version": "1.0.6",
4
+ "description": "Bankson.fi Node client, Mad Booster fork",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=18.0.0"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "build": "babel src --out-dir lib",
13
+ "dev": "babel -w src --out-dir lib",
14
+ "lint": "eslint src"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/MadBooster/bankson-js.git"
19
+ },
20
+ "keywords": [
21
+ "bankson",
22
+ "camt",
23
+ "pain",
24
+ "corporatefileservice"
25
+ ],
26
+ "author": "Bankson authors",
27
+ "license": "MIT",
28
+ "bugs": {
29
+ "url": "https://github.com/MadBooster/bankson-js/issues"
30
+ },
31
+ "homepage": "https://github.com/MadBooster/bankson-js#readme",
32
+ "devDependencies": {
33
+ "eslint": "^8.57.1",
34
+ "eslint-config-madbooster-node-app": "^11.0.0",
35
+ "eslint-plugin-simple-import-sort": "^12.1.0"
36
+ },
37
+ "dependencies": {
38
+ "form-data": "^4.0.2",
39
+ "node-rsa": "^1.1.1",
40
+ "qs": "^6.14.0"
41
+ },
42
+ "overrides": {
43
+ "eslint-plugin-n": "^17.7.0",
44
+ "eslint-plugin-promise": "^7.1.0"
45
+ }
46
+ }
package/src/client.js ADDED
@@ -0,0 +1,128 @@
1
+ import NodeRSA from 'node-rsa'
2
+
3
+ import ApiKeys from './ext/apikeys.js'
4
+ import Applications from './ext/applications.js'
5
+ import BankAccountStatements from './ext/bank-account-statements.js'
6
+ import BankAccounts from './ext/bank-accounts.js'
7
+ import Certificates from './ext/bank-certificates.js'
8
+ import Calls from './ext/calls.js'
9
+ import InboundPayments from './ext/inbound-payments.js'
10
+ import Payments from './ext/outbound-payments.js'
11
+ import Webhooks from './ext/webhooks.js'
12
+
13
+ export default class Client {
14
+ constructor(opts = {}) {
15
+ this.applications = new Applications(this)
16
+ this.webhooks = new Webhooks(this)
17
+ this.certificates = new Certificates(this)
18
+ this.calls = new Calls(this)
19
+ this.bankAccounts = new BankAccounts(this)
20
+ this.bankAccountStatements = new BankAccountStatements(this)
21
+ this.outboundPayments = new Payments(this)
22
+ this.apikeys = new ApiKeys(this)
23
+ this.inboundPayments = new InboundPayments(this)
24
+ this.beforeRequest = opts.beforeRequest || (() => Promise.resolve())
25
+ this.bearerToken = opts.bearerToken || '-'
26
+ this.baseUrl = opts.baseUrl || 'https://api.bankson.fi'
27
+ this.testMode = typeof opts.test !== 'undefined' ? opts.test : false
28
+ if(opts.privateKey && opts.apiKey) {
29
+ // ApiKey authentication
30
+ this.bearerToken = false
31
+ this.privateKey = new NodeRSA()
32
+ this.privateKey.importKey(opts.privateKey, 'private')
33
+ if(!this.privateKey.isPrivate()) throw new Error('Invalid private key')
34
+ this.apiKey = opts.apiKey
35
+ }
36
+ }
37
+
38
+ me() {
39
+ return this.get('/me')
40
+ }
41
+
42
+ meV2() {
43
+ return this.get('/v2/me')
44
+ }
45
+
46
+ authorizationHeader(bearerToken) {
47
+ if(this.bearerToken) return 'Bearer ' + bearerToken
48
+ const timestamp = Date.now()
49
+ const str = this.apiKey + timestamp
50
+ const signature = this.privateKey.sign(str, 'base64')
51
+ return 'BanksonRSA ' + [
52
+ 'ApiKey=' + this.apiKey,
53
+ 'Timestamp=' + timestamp,
54
+ 'Signature=' + signature
55
+ ].join(', ')
56
+ }
57
+
58
+ headers(additionalHeaders = {}) {
59
+ return this.beforeRequest().then(result => {
60
+ const bearerToken = result?.bearerToken || this.bearerToken
61
+ const banksonTest = result && typeof result.test !== 'undefined' ? result.test : this.testMode
62
+ const headers = new Headers()
63
+ headers.append('Accept', additionalHeaders.Accept || 'application/json')
64
+ headers.append('Authorization', this.authorizationHeader(bearerToken))
65
+ if(banksonTest) headers.append('X-Bankson-Environment', 'Test')
66
+ return headers
67
+ })
68
+ }
69
+
70
+ get(path, options = {}) {
71
+ return this.headers(options.headers).then(headers => fetch(`${this.baseUrl}${path}`, { headers }).then(resp => this.handleResponse(resp, options)))
72
+ }
73
+
74
+ post(path, data) {
75
+ return this.request('POST', path, data)
76
+ }
77
+
78
+ put(path, data) {
79
+ return this.request('PUT', path, data)
80
+ }
81
+
82
+ request(method, path, data) {
83
+ return this.headers().then(headers => {
84
+ const isFormData = data instanceof FormData
85
+ if(!isFormData) {
86
+ headers.append('Content-Type', 'application/json')
87
+ }
88
+ return fetch(`${this.baseUrl}${path}`, {
89
+ method,
90
+ body: isFormData ? data : JSON.stringify(data),
91
+ headers
92
+ }).then(this.handleResponse)
93
+ })
94
+ }
95
+
96
+ delete(path) {
97
+ return this.headers().then(headers => fetch(`${this.baseUrl}${path}`, {
98
+ method: 'DELETE',
99
+ headers
100
+ })).then(this.handleResponse)
101
+ }
102
+
103
+ handleResponse(resp, options = {}) {
104
+ if(!resp.ok) {
105
+ if(resp.status >= 500 || resp.status < 400) {
106
+ const err = new Error(`Internal error (${resp.status}): ${resp.statusText}`)
107
+ err.status = resp.status
108
+ err.statusText = resp.statusText
109
+ throw err
110
+ }
111
+ return getBody(resp).then(json => {
112
+ const err = new Error('Request unsuccessfull')
113
+ err.status = resp.status
114
+ err.body = json
115
+ throw err
116
+ })
117
+ }
118
+ return getBody(resp)
119
+
120
+ function getBody(resp) {
121
+ if(!/application\/json/.test(resp.headers.get('Content-Type'))) {
122
+ if(options.responseType === 'arraybuffer') return resp.arrayBuffer()
123
+ return resp.text()
124
+ }
125
+ return resp.json()
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,29 @@
1
+ export default class ApiKeys {
2
+ constructor(base) {
3
+ this.base = base
4
+ }
5
+
6
+ fetch() {
7
+ return this.base.get('/apikeys')
8
+ }
9
+
10
+ create(data) {
11
+ return this.base.post('/apikeys', data)
12
+ }
13
+
14
+ remove(id) {
15
+ return this.base.delete(`/apikeys/${id}`)
16
+ }
17
+
18
+ fetchV2() {
19
+ return this.base.get('/v2/apikeys')
20
+ }
21
+
22
+ createV2(data) {
23
+ return this.base.post('/v2/apikeys', data)
24
+ }
25
+
26
+ removeV2(id) {
27
+ return this.base.delete(`/v2/apikeys/${id}`)
28
+ }
29
+ }
@@ -0,0 +1,21 @@
1
+ export default class Applications {
2
+ constructor(base) {
3
+ this.base = base
4
+ }
5
+
6
+ fetch() {
7
+ return this.base.get('/applications')
8
+ }
9
+
10
+ create(data) {
11
+ return this.base.post('/applications', data)
12
+ }
13
+
14
+ fetchV2() {
15
+ return this.base.get('/v2/applications')
16
+ }
17
+
18
+ createV2(data) {
19
+ return this.base.post('/v2/applications', data)
20
+ }
21
+ }
@@ -0,0 +1,77 @@
1
+ export default class BankAccountStatements {
2
+ constructor(base) {
3
+ this.base = base
4
+ }
5
+
6
+ fetch() {
7
+ return this.base.get('/bankaccountstatements')
8
+ }
9
+
10
+ statementHtml(id) {
11
+ return this.base.get(`/bankaccountstatements/${id}`, {
12
+ headers: {
13
+ Accept: 'text/html'
14
+ },
15
+ responseType: 'arraybuffer'
16
+ })
17
+ }
18
+
19
+ statementXml(id) {
20
+ return this.base.get(`/bankaccountstatements/${id}`, {
21
+ headers: {
22
+ Accept: 'application/xml'
23
+ },
24
+ responseType: 'arraybuffer'
25
+ })
26
+ }
27
+
28
+ statementText(id) {
29
+ return this.base.get(`/bankaccountstatements/${id}`, {
30
+ headers: {
31
+ Accept: 'text/plain'
32
+ },
33
+ responseType: 'arraybuffer'
34
+ })
35
+ }
36
+
37
+ refresh(id) {
38
+ return this.base.post('/bankaccountstatements', {
39
+ certificate_id: id
40
+ })
41
+ }
42
+
43
+ fetchV2() {
44
+ return this.base.get('/v2/bankaccountstatements')
45
+ }
46
+
47
+ statementHtmlV2(id) {
48
+ return this.base.get(`/v2/bankaccountstatements/${id}`, {
49
+ headers: {
50
+ Accept: 'text/html'
51
+ },
52
+ responseType: 'arraybuffer'
53
+ })
54
+ }
55
+
56
+ statementXmlV2(id) {
57
+ return this.base.get(`/v2/bankaccountstatements/${id}`, {
58
+ headers: {
59
+ Accept: 'application/xml'
60
+ },
61
+ responseType: 'arraybuffer'
62
+ })
63
+ }
64
+
65
+ statementTextV2(id) {
66
+ return this.base.get(`/v2/bankaccountstatements/${id}`, {
67
+ headers: {
68
+ Accept: 'text/plain'
69
+ },
70
+ responseType: 'arraybuffer'
71
+ })
72
+ }
73
+
74
+ refreshV2(id) {
75
+ throw new Error('Not implemented')
76
+ }
77
+ }
@@ -0,0 +1,27 @@
1
+ import Qs from 'qs'
2
+
3
+ export default class BankAccounts {
4
+ constructor(base) {
5
+ this.base = base
6
+ }
7
+
8
+ fetch() {
9
+ return this.base.get('/bankaccounts')
10
+ }
11
+
12
+ create(data) {
13
+ return this.base.post('/bankaccounts', data)
14
+ }
15
+
16
+ fetchV2(opts) {
17
+ return this.base.get('/v2/bank-accounts?' + Qs.stringify(opts))
18
+ }
19
+
20
+ createV2(data) {
21
+ return this.base.post('/v2/bank-accounts', data)
22
+ }
23
+
24
+ updateV2(id, data) {
25
+ return this.base.put(`/v2/bank-accounts/${id}`, data)
26
+ }
27
+ }
@@ -0,0 +1,53 @@
1
+ import FormData from 'form-data'
2
+
3
+ export default class Certificates {
4
+ constructor(base) {
5
+ this.base = base
6
+ }
7
+
8
+ fetch() {
9
+ return this.base.get('/certificates')
10
+ }
11
+
12
+ upload(file, params) {
13
+ const data = new FormData()
14
+ Object.keys(params).forEach(k => data.append(k, params[k]))
15
+ data.append('certificate', file)
16
+ return this.base.post('/certificates/upload', data)
17
+ }
18
+
19
+ request(data) {
20
+ return this.base.post('/certificates/request', data)
21
+ }
22
+
23
+ remove(id) {
24
+ return this.base.delete(`/certificates/${id}`)
25
+ }
26
+
27
+ renew(id, data = {}) {
28
+ return this.base.post(`/certificates/${id}/renew`, data)
29
+ }
30
+
31
+ fetchV2() {
32
+ return this.base.get('/v2/bank-certificates')
33
+ }
34
+
35
+ uploadV2(file, params) {
36
+ const data = new FormData()
37
+ Object.keys(params).forEach(k => data.append(k, params[k]))
38
+ data.append('certificate', file)
39
+ return this.base.post('/v2/bank-certificates/upload', data)
40
+ }
41
+
42
+ requestV2(data) {
43
+ return this.base.post('/v2/bank-certificates/request', data)
44
+ }
45
+
46
+ removeV2(id) {
47
+ return this.base.delete(`/v2/bank-certificates/${id}`)
48
+ }
49
+
50
+ renewV2(id, data = {}) {
51
+ return this.base.post(`/v2/bank-certificates/${id}/renew`, data)
52
+ }
53
+ }
@@ -0,0 +1,13 @@
1
+ export default class Calls {
2
+ constructor(base) {
3
+ this.base = base
4
+ }
5
+
6
+ fetch() {
7
+ return this.base.get('/calls')
8
+ }
9
+
10
+ fetchV2() {
11
+ return this.base.get('/v2/calls')
12
+ }
13
+ }
@@ -0,0 +1,40 @@
1
+ import Qs from 'qs'
2
+
3
+ export default class InboundPayments {
4
+ constructor(base) {
5
+ this.base = base
6
+ }
7
+
8
+ fetch(opts) {
9
+ return this.base.get('/inboundpayments?' + Qs.stringify(opts))
10
+ }
11
+
12
+ refresh(certificateId) {
13
+ return this.base.post('/inboundpayments', { certificate_id: certificateId })
14
+ }
15
+
16
+ batch(batchId, type = 'json') {
17
+ let opts
18
+ if(type !== 'json') {
19
+ opts = {
20
+ headers: {
21
+ Accept: type === 'xml' ? 'application/xml' : 'text/plain'
22
+ },
23
+ responseType: 'arraybuffer'
24
+ }
25
+ }
26
+ return this.base.get(`/inboundpayments/batches/${batchId}`, opts)
27
+ }
28
+
29
+ fetchV2(opts) {
30
+ return this.base.get('/v2/inbound-payments?' + Qs.stringify(opts))
31
+ }
32
+
33
+ refreshV2(certificateId) {
34
+ throw new Error('Not implemented')
35
+ }
36
+
37
+ batchV2(batchId, type = 'json') {
38
+ throw new Error('Not implemented')
39
+ }
40
+ }
@@ -0,0 +1,31 @@
1
+ import Qs from 'qs'
2
+
3
+ export default class Payments {
4
+ constructor(base) {
5
+ this.base = base
6
+ }
7
+
8
+ fetch() {
9
+ return this.base.get('/payments')
10
+ }
11
+
12
+ fetchFeedback() {
13
+ return this.base.post('/payments/feedback', {})
14
+ }
15
+
16
+ fetchV2(opts) {
17
+ return this.base.get('/v2/outbound-payments?' + Qs.stringify(opts))
18
+ }
19
+
20
+ addV2(data) {
21
+ return this.base.post('/v2/outbound-payments', data)
22
+ }
23
+
24
+ removeV2(id) {
25
+ return this.base.delete(`/v2/outbound-payments/${id}`)
26
+ }
27
+
28
+ fetchFeedbackV2() {
29
+ throw new Error('Not implemented')
30
+ }
31
+ }
@@ -0,0 +1,25 @@
1
+ export default class Webhooks {
2
+ constructor(base) {
3
+ this.base = base
4
+ }
5
+
6
+ fetch() {
7
+ return this.base.get('/webhooks')
8
+ }
9
+
10
+ create(data) {
11
+ return this.base.post('/webhooks', data)
12
+ }
13
+
14
+ fetchV2() {
15
+ return this.base.get('/v2/webhooks')
16
+ }
17
+
18
+ createV2(data) {
19
+ return this.base.post('/v2/webhooks', data)
20
+ }
21
+
22
+ updateV2(id, data) {
23
+ return this.base.put(`/v2/webhooks/${id}`, data)
24
+ }
25
+ }
package/src/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import Client from './client.js'
2
+
3
+ // Export for commonjs modules
4
+ export default Client