@mft/moneyhub-api-client 4.15.0 → 4.17.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.
- package/package.json +11 -11
- package/readme.md +11 -2
- package/src/__tests__/transaction-splits.js +1 -1
- package/src/get-auth-urls.js +31 -2
- package/src/request.js +24 -0
- package/src/requests/unauthenticated.js +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mft/moneyhub-api-client",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.17.0",
|
|
4
4
|
"description": "Node.JS client for the Moneyhub API",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,23 +21,23 @@
|
|
|
21
21
|
"repository": "moneyhub/moneyhub-api-client",
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"form-data": "^3.0.
|
|
24
|
+
"form-data": "^3.0.1",
|
|
25
25
|
"got": "^11.8.3",
|
|
26
26
|
"jose": "^2.0.5",
|
|
27
|
-
"openid-client": "^4.
|
|
28
|
-
"ramda": "^0.27.
|
|
27
|
+
"openid-client": "^4.9.1",
|
|
28
|
+
"ramda": "^0.27.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@mft/eslint-config-momentumft": "^4.0.0",
|
|
32
|
-
"body-parser": "^1.19.
|
|
33
|
-
"chai": "^4.
|
|
34
|
-
"command-line-args": "^5.
|
|
32
|
+
"body-parser": "^1.19.2",
|
|
33
|
+
"chai": "^4.3.6",
|
|
34
|
+
"command-line-args": "^5.2.1",
|
|
35
35
|
"command-line-usage": "^6.1.1",
|
|
36
|
-
"config": "^3.3.
|
|
36
|
+
"config": "^3.3.7",
|
|
37
37
|
"eslint": "^7.32.0",
|
|
38
|
-
"express": "^4.17.
|
|
39
|
-
"husky": "^7.0.
|
|
40
|
-
"mocha": "^9.2.
|
|
38
|
+
"express": "^4.17.3",
|
|
39
|
+
"husky": "^7.0.4",
|
|
40
|
+
"mocha": "^9.2.2",
|
|
41
41
|
"mocha-junit-reporter": "^2.0.2"
|
|
42
42
|
},
|
|
43
43
|
"husky": {
|
package/readme.md
CHANGED
|
@@ -89,10 +89,16 @@ const moneyhub = await Moneyhub({
|
|
|
89
89
|
Once the api client has been initialised it provides a simple promise based interface with the following methods:
|
|
90
90
|
|
|
91
91
|
### Auth API
|
|
92
|
+
The options below can be set on the following URL generating methods:
|
|
93
|
+
- `getAuthorizeUrl`
|
|
94
|
+
- `getAuthorizeUrlForCreatedUser`
|
|
95
|
+
- `getReauthAuthorizeUrlForCreatedUser`
|
|
96
|
+
- `getRefreshAuthorizeUrlForCreatedUser`
|
|
92
97
|
|
|
98
|
+
The `expirationDateTime` and `transactionFromDateTime` options can be set according to the [AIS Consents documentation](https://docs.moneyhubenterprise.com/docs/ais-consents)
|
|
93
99
|
#### `getAuthorizeUrl`
|
|
94
100
|
|
|
95
|
-
This method returns an authorize url for your API client. You can redirect a user to this url, after which they will be redirected back to your `redirect_uri`.
|
|
101
|
+
This method returns an authorize url for your API client. You can redirect a user to this url, after which they will be redirected back to your `redirect_uri`.
|
|
96
102
|
|
|
97
103
|
[Financial institutions](https://docs.moneyhubenterprise.com/docs/bank-connections)
|
|
98
104
|
|
|
@@ -100,13 +106,16 @@ This method returns an authorize url for your API client. You can redirect a use
|
|
|
100
106
|
|
|
101
107
|
[Claims](https://docs.moneyhubenterprise.com/docs/claims)
|
|
102
108
|
|
|
109
|
+
|
|
103
110
|
```javascript
|
|
104
111
|
const url = await moneyhub.getAuthorizeUrl({
|
|
105
112
|
scope: "openid bank-id-scope other-data-scopes",
|
|
106
113
|
state: " your state value", // optional
|
|
107
114
|
nonce: "your nonce value", //optional
|
|
108
115
|
claims: claimsObject, // optional
|
|
109
|
-
permissions: ["ReadBeneficiariesDetail"] // optional - set of extra permissions to set for auth URL
|
|
116
|
+
permissions: ["ReadBeneficiariesDetail"], // optional - set of extra permissions to set for auth URL
|
|
117
|
+
expirationDateTime: "2022-09-01T00:00:00.000Z", // optional
|
|
118
|
+
transactionFromDateTime: "2020-09-01T00:00:00.000Z", // optional,
|
|
110
119
|
})
|
|
111
120
|
|
|
112
121
|
// Default claims if none are provided
|
|
@@ -67,7 +67,7 @@ describe("Transaction Splits", () => {
|
|
|
67
67
|
transactionId,
|
|
68
68
|
})
|
|
69
69
|
expect(splits).to.have.length(2)
|
|
70
|
-
expect(R.path([0, "amount"], splits)).to.be.oneOf([-1500, -800])
|
|
70
|
+
expect(R.path([0, "amount", "value"], splits)).to.be.oneOf([-1500, -800])
|
|
71
71
|
expect(R.path([0, "description"], splits)).to.be.oneOf(["Split 1", "Split 2"])
|
|
72
72
|
})
|
|
73
73
|
|
package/src/get-auth-urls.js
CHANGED
|
@@ -30,7 +30,15 @@ module.exports = ({client, config}) => {
|
|
|
30
30
|
return claims
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const getAuthorizeUrl = ({
|
|
33
|
+
const getAuthorizeUrl = ({
|
|
34
|
+
state,
|
|
35
|
+
scope,
|
|
36
|
+
nonce,
|
|
37
|
+
claims = {},
|
|
38
|
+
permissions,
|
|
39
|
+
expirationDateTime,
|
|
40
|
+
transactionFromDateTime,
|
|
41
|
+
}) => {
|
|
34
42
|
const defaultClaims = {
|
|
35
43
|
id_token: {
|
|
36
44
|
sub: {
|
|
@@ -39,6 +47,15 @@ module.exports = ({client, config}) => {
|
|
|
39
47
|
"mh:con_id": {
|
|
40
48
|
essential: true,
|
|
41
49
|
},
|
|
50
|
+
...(expirationDateTime || transactionFromDateTime) && {
|
|
51
|
+
"mh:consent": {
|
|
52
|
+
"essential": true,
|
|
53
|
+
"value": {
|
|
54
|
+
...expirationDateTime && {expirationDateTime},
|
|
55
|
+
...transactionFromDateTime && {transactionFromDateTime},
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
42
59
|
},
|
|
43
60
|
}
|
|
44
61
|
|
|
@@ -116,7 +133,9 @@ module.exports = ({client, config}) => {
|
|
|
116
133
|
nonce,
|
|
117
134
|
userId,
|
|
118
135
|
claims = {},
|
|
119
|
-
permissions
|
|
136
|
+
permissions,
|
|
137
|
+
expirationDateTime,
|
|
138
|
+
transactionFromDateTime,
|
|
120
139
|
}) => {
|
|
121
140
|
const scope = `id:${bankId} openid`
|
|
122
141
|
const defaultClaims = {
|
|
@@ -140,6 +159,8 @@ module.exports = ({client, config}) => {
|
|
|
140
159
|
nonce,
|
|
141
160
|
scope,
|
|
142
161
|
claims: _claims,
|
|
162
|
+
expirationDateTime,
|
|
163
|
+
transactionFromDateTime,
|
|
143
164
|
})
|
|
144
165
|
return url
|
|
145
166
|
},
|
|
@@ -150,6 +171,8 @@ module.exports = ({client, config}) => {
|
|
|
150
171
|
state,
|
|
151
172
|
nonce,
|
|
152
173
|
claims = {},
|
|
174
|
+
expirationDateTime,
|
|
175
|
+
transactionFromDateTime,
|
|
153
176
|
}) => {
|
|
154
177
|
const scope = "openid reauth"
|
|
155
178
|
const defaultClaims = {
|
|
@@ -171,6 +194,8 @@ module.exports = ({client, config}) => {
|
|
|
171
194
|
nonce,
|
|
172
195
|
scope,
|
|
173
196
|
claims: _claims,
|
|
197
|
+
expirationDateTime,
|
|
198
|
+
transactionFromDateTime,
|
|
174
199
|
})
|
|
175
200
|
return url
|
|
176
201
|
},
|
|
@@ -181,6 +206,8 @@ module.exports = ({client, config}) => {
|
|
|
181
206
|
state,
|
|
182
207
|
nonce,
|
|
183
208
|
claims = {},
|
|
209
|
+
expirationDateTime,
|
|
210
|
+
transactionFromDateTime,
|
|
184
211
|
}) => {
|
|
185
212
|
const scope = "openid refresh"
|
|
186
213
|
const defaultClaims = {
|
|
@@ -202,6 +229,8 @@ module.exports = ({client, config}) => {
|
|
|
202
229
|
scope,
|
|
203
230
|
nonce,
|
|
204
231
|
claims: _claims,
|
|
232
|
+
expirationDateTime,
|
|
233
|
+
transactionFromDateTime,
|
|
205
234
|
})
|
|
206
235
|
return url
|
|
207
236
|
},
|
package/src/request.js
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
const got = require("got")
|
|
2
|
+
const R = require("ramda")
|
|
3
|
+
|
|
4
|
+
const getResponseBody = err => {
|
|
5
|
+
let body = {}
|
|
6
|
+
try {
|
|
7
|
+
const {code, message, details} = JSON.parse(R.pathOr("{}", ["response", "body"], err))
|
|
8
|
+
body = {code, message, details: typeof details === "object" ? JSON.stringify(details) : details}
|
|
9
|
+
// eslint-disable-next-line no-empty
|
|
10
|
+
} catch (e) {
|
|
11
|
+
body = {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return body
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const attachErrorDetails = err => {
|
|
18
|
+
const {code, message, details} = getResponseBody(err)
|
|
19
|
+
err.error = code
|
|
20
|
+
err.error_description = message
|
|
21
|
+
err.error_details = details
|
|
22
|
+
throw err
|
|
23
|
+
}
|
|
2
24
|
|
|
3
25
|
module.exports = ({client, options: {timeout}}) => async (url, opts = {}) => {
|
|
4
26
|
const gotOpts = {
|
|
@@ -28,7 +50,9 @@ module.exports = ({client, options: {timeout}}) => async (url, opts = {}) => {
|
|
|
28
50
|
const req = got(url, gotOpts)
|
|
29
51
|
if (opts.returnStatus) {
|
|
30
52
|
return req.then(res => res.statusCode)
|
|
53
|
+
.catch(attachErrorDetails)
|
|
31
54
|
}
|
|
32
55
|
|
|
33
56
|
return req.json()
|
|
57
|
+
.catch(attachErrorDetails)
|
|
34
58
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
module.exports = ({config, request}) => {
|
|
2
2
|
const {resourceServerUrl, identityServiceUrl} = config
|
|
3
3
|
return {
|
|
4
|
-
getGlobalCounterparties: () =>
|
|
5
|
-
request(resourceServerUrl + "/global-counterparties"
|
|
4
|
+
getGlobalCounterparties: (params = {}) =>
|
|
5
|
+
request(resourceServerUrl + "/global-counterparties", {
|
|
6
|
+
searchParams: params,
|
|
7
|
+
}),
|
|
6
8
|
listConnections: () =>
|
|
7
9
|
request(identityServiceUrl + "/oidc/.well-known/all-connections"),
|
|
8
10
|
listAPIConnections: () =>
|