bankson-js-mb 1.0.6 → 2.0.0

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.
Files changed (78) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/eslint.config.js +12 -0
  3. package/lib/baseSubClient.d.ts +6 -0
  4. package/lib/baseSubClient.d.ts.map +1 -0
  5. package/lib/baseSubClient.js +7 -0
  6. package/lib/baseSubClient.js.map +1 -0
  7. package/lib/client.d.ts +58 -0
  8. package/lib/client.d.ts.map +1 -0
  9. package/lib/client.js +146 -0
  10. package/lib/client.js.map +1 -0
  11. package/lib/ext/apikeys.d.ts +7 -0
  12. package/lib/ext/apikeys.d.ts.map +1 -0
  13. package/lib/ext/apikeys.js +13 -0
  14. package/lib/ext/apikeys.js.map +1 -0
  15. package/lib/ext/applications.d.ts +6 -0
  16. package/lib/ext/applications.d.ts.map +1 -0
  17. package/lib/ext/applications.js +10 -0
  18. package/lib/ext/applications.js.map +1 -0
  19. package/lib/ext/bank-account-statements.d.ts +10 -0
  20. package/lib/ext/bank-account-statements.d.ts.map +1 -0
  21. package/lib/ext/bank-account-statements.js +34 -0
  22. package/lib/ext/bank-account-statements.js.map +1 -0
  23. package/lib/ext/bank-accounts.d.ts +16 -0
  24. package/lib/ext/bank-accounts.d.ts.map +1 -0
  25. package/lib/ext/bank-accounts.js +14 -0
  26. package/lib/ext/bank-accounts.js.map +1 -0
  27. package/lib/ext/bank-certificates.d.ts +9 -0
  28. package/lib/ext/bank-certificates.d.ts.map +1 -0
  29. package/lib/ext/bank-certificates.js +23 -0
  30. package/lib/ext/bank-certificates.js.map +1 -0
  31. package/lib/ext/calls.d.ts +6 -0
  32. package/lib/ext/calls.d.ts.map +1 -0
  33. package/lib/ext/calls.js +7 -0
  34. package/lib/ext/calls.js.map +1 -0
  35. package/lib/ext/inbound-payments.d.ts +17 -0
  36. package/lib/ext/inbound-payments.d.ts.map +1 -0
  37. package/lib/ext/inbound-payments.js +14 -0
  38. package/lib/ext/inbound-payments.js.map +1 -0
  39. package/lib/ext/outbound-payments.d.ts +24 -0
  40. package/lib/ext/outbound-payments.d.ts.map +1 -0
  41. package/lib/ext/outbound-payments.js +17 -0
  42. package/lib/ext/outbound-payments.js.map +1 -0
  43. package/lib/ext/webhooks.d.ts +7 -0
  44. package/lib/ext/webhooks.d.ts.map +1 -0
  45. package/lib/ext/webhooks.js +13 -0
  46. package/lib/ext/webhooks.js.map +1 -0
  47. package/lib/index.d.ts +3 -0
  48. package/lib/index.d.ts.map +1 -0
  49. package/lib/index.js +4 -0
  50. package/lib/index.js.map +1 -0
  51. package/lib/tsconfig.tsbuildinfo +1 -0
  52. package/lib/types.d.ts +111 -0
  53. package/lib/types.d.ts.map +1 -0
  54. package/lib/types.js +2 -0
  55. package/lib/types.js.map +1 -0
  56. package/package.json +13 -13
  57. package/src/baseSubClient.ts +8 -0
  58. package/src/client.ts +172 -0
  59. package/src/ext/apikeys.js +2 -16
  60. package/src/ext/applications.js +2 -12
  61. package/src/ext/bank-account-statements.ts +39 -0
  62. package/src/ext/bank-accounts.ts +27 -0
  63. package/src/ext/bank-certificates.js +2 -27
  64. package/src/ext/calls.ts +8 -0
  65. package/src/ext/inbound-payments.ts +27 -0
  66. package/src/ext/outbound-payments.ts +38 -0
  67. package/src/ext/webhooks.js +2 -12
  68. package/src/types.ts +116 -0
  69. package/tsconfig.json +20 -0
  70. package/.eslintrc.cjs +0 -27
  71. package/bankson-js-mb-1.0.6.tgz +0 -0
  72. package/src/client.js +0 -128
  73. package/src/ext/bank-account-statements.js +0 -77
  74. package/src/ext/bank-accounts.js +0 -27
  75. package/src/ext/calls.js +0 -13
  76. package/src/ext/inbound-payments.js +0 -40
  77. package/src/ext/outbound-payments.js +0 -31
  78. /package/src/{index.js → index.ts} +0 -0
package/src/types.ts ADDED
@@ -0,0 +1,116 @@
1
+ export interface BaseResponse <T> {
2
+ total_count: number
3
+ items: T[]
4
+ }
5
+
6
+ export interface BankAccountResponse {
7
+ id: string
8
+ bic: string
9
+ iban: string
10
+ contract_id: string
11
+ customer_information: {
12
+ name: string
13
+ business_id: string | null
14
+ contact_person: string | null
15
+ contact_person_ssn: string | null
16
+ contact_person_email: string | null
17
+ contact_person_phone: string | null
18
+ } | null | undefined
19
+ balance?: number
20
+ balance_date?: string
21
+ }
22
+
23
+ export interface BankAccountStatementResponse {
24
+ id: string
25
+ from: string
26
+ to: string
27
+ legal_sequence_number: string
28
+ entries: {
29
+ entry_reference: number
30
+ archive_id: string
31
+ booking_date: string
32
+ value_date: string
33
+ payment_date: string
34
+ booking_information: string
35
+ amount: number
36
+ receiver: string
37
+ receiver_account: string
38
+ debitor: string
39
+ reference_number: string
40
+ additional_information: string[]
41
+ }[]
42
+ balances: {
43
+ booking_date: string
44
+ amount: number
45
+ available_amount?: number
46
+ }[]
47
+ created_at: string
48
+ updated_at: string
49
+ servicer_name: string
50
+ servicer_bic: string
51
+ account_owner_name: string
52
+ currency: string
53
+ test: boolean
54
+ transaction_summary: {
55
+ entry_count: number
56
+ credit_count: number
57
+ credit_amount: number
58
+ debit_count: number
59
+ debit_amount: number
60
+ }
61
+ bank_account: BankAccountResponse & {
62
+ deleted_at: string | null
63
+ restored_at: string | null
64
+ }
65
+ }
66
+
67
+ export interface OutboundPaymentResponse {
68
+ id: string
69
+ source: string
70
+ recipient_name: string
71
+ recipient_iban: string
72
+ recipient_bic: string
73
+ amount: string
74
+ reference_number: string | null
75
+ message: string | null
76
+ payment_date: string
77
+ vendor_reference: string | null
78
+ status: string | null
79
+ created_at: string
80
+ updated_at: string
81
+ bank_account: BankAccountResponse
82
+ }
83
+
84
+ export interface InboundPaymentResponse {
85
+ id: string
86
+ bank_account_id: string
87
+ debitor_name: string
88
+ amount: number
89
+ reference_number: string | null
90
+ message: string | null
91
+ payment_date: string
92
+ archive_id: string | null
93
+ booking_date: string | null
94
+ created_at: string
95
+ updated_at: string
96
+ bank_account: BankAccountResponse
97
+ }
98
+
99
+ export interface WebhookResponse {
100
+ id: string
101
+ description: string | null
102
+ url: string | null
103
+ test: boolean
104
+ production: boolean
105
+ created_at: string
106
+ updated_at: string
107
+ }
108
+
109
+ export interface CallResponse {
110
+ id: string
111
+ certificate_id: string
112
+ file_type: string
113
+ content: string
114
+ response: string
115
+ created_at: string
116
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["ES2022"],
4
+ "module": "NodeNext",
5
+ "moduleResolution": "nodenext",
6
+ "resolveJsonModule": true,
7
+ //"noImplicitAny": true,
8
+ "noImplicitReturns": true,
9
+ "noImplicitThis": true,
10
+ "sourceMap": true,
11
+ "inlineSources": true,
12
+ "target": "es2022",
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "outDir": "lib",
16
+ "allowJs": true,
17
+ "strictNullChecks": true
18
+ },
19
+ "include": ["src/**/*.ts"]
20
+ }
package/.eslintrc.cjs DELETED
@@ -1,27 +0,0 @@
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
- }
Binary file
package/src/client.js DELETED
@@ -1,128 +0,0 @@
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
- }
@@ -1,77 +0,0 @@
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
- }
@@ -1,27 +0,0 @@
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
- }
package/src/ext/calls.js DELETED
@@ -1,13 +0,0 @@
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
- }
@@ -1,40 +0,0 @@
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
- }
@@ -1,31 +0,0 @@
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
- }
File without changes