@mft/moneyhub-api-client 4.11.0 → 4.14.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.
@@ -0,0 +1,24 @@
1
+ name: npm audit
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ schedule:
8
+ - cron: '0 10 * * *'
9
+
10
+ jobs:
11
+ scan:
12
+ name: npm audit
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: install dependencies
17
+ run: npm ci
18
+ - uses: oke-py/npm-audit-action@v1.8.4
19
+ with:
20
+ audit_level: moderate
21
+ github_token: ${{ secrets.GITHUB_TOKEN }}
22
+ issue_assignees: oke-py
23
+ issue_labels: vulnerability,test
24
+ dedupe_issues: true
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ 4.13.0 / 2022-01-05
2
+ ==================
3
+
4
+ **Features**
5
+
6
+ * Add getRentalRecords
7
+ * Add createRentalRecord
8
+ * Add deleteRentalRecord
1
9
 
2
10
  4.0.0 / 2021-01-11
3
11
  ==================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mft/moneyhub-api-client",
3
- "version": "4.11.0",
3
+ "version": "4.14.0",
4
4
  "description": "Node.JS client for the Moneyhub API",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "license": "ISC",
23
23
  "dependencies": {
24
24
  "form-data": "^3.0.0",
25
- "got": "^11.8.1",
25
+ "got": "^11.8.3",
26
26
  "jose": "^2.0.5",
27
27
  "openid-client": "^4.2.2",
28
28
  "ramda": "^0.27.1"
@@ -34,11 +34,11 @@
34
34
  "command-line-args": "^5.1.1",
35
35
  "command-line-usage": "^6.1.1",
36
36
  "config": "^3.3.6",
37
- "eslint": "^6.8.0",
37
+ "eslint": "^7.32.0",
38
38
  "express": "^4.17.1",
39
- "husky": "^4.3.6",
40
- "mocha": "^8.2.1",
41
- "mocha-junit-reporter": "^2.0.0"
39
+ "husky": "^7.0.2",
40
+ "mocha": "^9.2.0",
41
+ "mocha-junit-reporter": "^2.0.2"
42
42
  },
43
43
  "husky": {
44
44
  "hooks": {
package/readme.md CHANGED
@@ -1100,10 +1100,10 @@ This is a helper function that returns an authorize url to authorize a payment t
1100
1100
 
1101
1101
  ```javascript
1102
1102
  const url = await moneyhub.getPaymentAuthorizeUrl({
1103
- bankId: "Bank id to authorise payment from",
1104
- payeeId: "Id of payee",
1103
+ bankId: "Bank id to authorise payment from", // required
1104
+ payeeId: "Id of payee", // required
1105
1105
  payeeType: "Payee type [api-payee|mh-user-account]", // optional - defaults to api-payee
1106
- payerId: "Id of payer", // requird only if payerType is defined
1106
+ payerId: "Id of payer", // required only if payerType is defined
1107
1107
  payerType: "Payer type [mh-user-account]", // required only if payerId is used
1108
1108
  amount: "Amount in pence to authorize payment",
1109
1109
  payeeRef: "Payee reference",
@@ -1113,6 +1113,7 @@ const url = await moneyhub.getPaymentAuthorizeUrl({
1113
1113
  state: "your state value",
1114
1114
  nonce: "your nonce value", // optional
1115
1115
  context: "Payment context [Other,BillPayment,PartyToParty]", // optional - defaults to PartyToParty
1116
+ userId: "Moneyhub API User ID you wish to attach to the payment" // optional
1116
1117
  claims: claimsObject, // optional
1117
1118
  })
1118
1119
 
@@ -1152,6 +1153,7 @@ const url = await moneyhub.getReversePaymentAuthorizeUrl({
1152
1153
  bankId: "Bank id to authorise payment from",
1153
1154
  paymentId: "Id of payment to reverse",
1154
1155
  state: "your state value",
1156
+ amount: "reverse payment amount" // optional
1155
1157
  nonce: "your nonce value", // optional
1156
1158
  claims: claimsObject, // optional
1157
1159
  })
@@ -1247,10 +1249,10 @@ This is a helper function that returns an authorize url to authorize a standng o
1247
1249
 
1248
1250
  ```javascript
1249
1251
  const url = await moneyhub.getStandingOrderAuthorizeUrl({
1250
- bankId: "Bank id to authorise payment from",
1251
- payeeId: "Id of payee",
1252
+ bankId: "Bank id to authorise payment from", // required
1253
+ payeeId: "Id of payee", // required
1252
1254
  payeeType: "Payee type [api-payee|mh-user-account]", // optional - defaults to api-payee
1253
- payerId: "Id of payer", // requird only if payerType is defined
1255
+ payerId: "Id of payer", // required only if payerType is defined
1254
1256
  payerType: "Payer type [mh-user-account]", // required only if payerId is used
1255
1257
  reference: "The reference for standing order",
1256
1258
  frequency: {
@@ -1343,6 +1345,57 @@ const regulartransactions = await moneyhub.getRegularTransactions({
1343
1345
  })
1344
1346
  ```
1345
1347
 
1348
+ ### Rental records
1349
+
1350
+ #### `getRentalRecords`
1351
+
1352
+ This method will return the rental record for the user. Requires the scope `rental_records:read`.
1353
+
1354
+ ```javascript
1355
+ const getRentalRecordResponse = await moneyhub.getRentalRecords({
1356
+ userId: "user-id"
1357
+ })
1358
+ const rentalRecord = getRentalRecordResponse.data[0]
1359
+ ```
1360
+
1361
+ #### `createRentalRecord`
1362
+
1363
+ This method will create a rental record for the user. Requires the scope `rental_records:write`. Please note only one rental record can exist for a user.
1364
+
1365
+ ```javascript
1366
+ const createRentalRecordResponse = await moneyhub.createRentalRecord({
1367
+ userId: "user-id",
1368
+ rentalData: {
1369
+ title: "Title",
1370
+ firstName: "firstName",
1371
+ lastName: "lastName",
1372
+ birthdate: "2000-11-19",
1373
+ addressLine1: "First address line",
1374
+ addressLine2: "Second address line", // optional
1375
+ addressLine3: "Third address line", // optional
1376
+ addressLine4: "Fourth address line", // optional
1377
+ postalCode: "CA12345",
1378
+ tenancyStartDate: "2020-11-19",
1379
+ rentalAmount: {
1380
+ value: 10000
1381
+ },
1382
+ rentalFrequency: "monthly",
1383
+ }
1384
+ })
1385
+ const createdRentalRecord = createRentalRecordResponse.data
1386
+ ```
1387
+
1388
+ #### `deleteRentalRecord`
1389
+
1390
+ This method deletes the rental record for a user.
1391
+
1392
+ ```javascript
1393
+ await moneyhub.deleteRentalRecord({
1394
+ userId: "user-id",
1395
+ rentalId: "rental-id"
1396
+ })
1397
+ ```
1398
+
1346
1399
  ### Financial Connections
1347
1400
 
1348
1401
  #### `listConnections`
@@ -4,10 +4,8 @@ const config = require("../../test/test-client-config")
4
4
  const {expect} = require("chai")
5
5
 
6
6
  describe("Accounts", () => {
7
- let moneyhub
8
- let accountId
9
- let pensionId
10
- const userId = config.testUserId
7
+ let manualAccountId, moneyhub
8
+ const {testUserId: userId, testAccountId: accountId, testPensionId: pensionId} = config
11
9
 
12
10
  before(async () => {
13
11
  moneyhub = await Moneyhub(config)
@@ -15,9 +13,12 @@ describe("Accounts", () => {
15
13
 
16
14
  it("get accounts", async () => {
17
15
  const accounts = await moneyhub.getAccounts({userId})
18
- expect(accounts.data.length).to.eql(11)
19
- accountId = accounts.data.find(a => a.type === "cash:current").id
20
- pensionId = accounts.data.find(a => a.type === "pension").id
16
+ expect(accounts.data.length).to.be.at.least(11)
17
+ const cashAccount = accounts.data.find(a => a.type === "cash:current")
18
+ const pension = accounts.data.find(a => a.type === "pension")
19
+
20
+ expect(cashAccount).to.not.be.undefined
21
+ expect(pension).to.not.be.undefined
21
22
  })
22
23
 
23
24
  it("get account", async () => {
@@ -64,12 +65,12 @@ describe("Accounts", () => {
64
65
  }
65
66
 
66
67
  const {data: {id}} = await moneyhub.createAccount({userId, account})
67
- accountId = id
68
+ manualAccountId = id
68
69
  expect(id).to.not.be.undefined
69
70
  })
70
71
 
71
72
  it("deletes manual account", async () => {
72
- const status = await moneyhub.deleteAccount({userId, accountId})
73
+ const status = await moneyhub.deleteAccount({userId, accountId: manualAccountId})
73
74
  expect(status).to.eql(204)
74
75
  })
75
76
  })
@@ -89,6 +89,9 @@ describe("API client", () => {
89
89
  "getStandingOrder",
90
90
  "getStandingOrders",
91
91
  "getRegularTransactions",
92
+ "getRentalRecords",
93
+ "createRentalRecord",
94
+ "deleteRentalRecord",
92
95
  "getAuthorizeUrl",
93
96
  "getAuthorizeUrlFromRequestUri",
94
97
  "requestObject",
@@ -0,0 +1,90 @@
1
+ /* eslint-disable max-nested-callbacks */
2
+ const Moneyhub = require("..")
3
+ const config = require("../../test/test-client-config")
4
+ const {expect, assert} = require("chai")
5
+
6
+ const testRentalData = {
7
+ title: "Title",
8
+ firstName: "firstName",
9
+ lastName: "lastName",
10
+ birthdate: "2000-11-19",
11
+ addressLine1: "First address line",
12
+ addressLine2: "Second address line",
13
+ addressLine3: "Third address line",
14
+ addressLine4: "Fourth address line",
15
+ postalCode: "CA12345",
16
+ tenancyStartDate: "2020-11-19",
17
+ rentalAmount: {
18
+ value: 10000
19
+ },
20
+ rentalFrequency: "monthly",
21
+ }
22
+
23
+ describe("Rental records", () => {
24
+ let moneyhub
25
+ let seriesId
26
+ let rentalId
27
+ const userId = config.testUserIdWithconnection
28
+
29
+ before(async () => {
30
+ moneyhub = await Moneyhub(config)
31
+ const {data: regularTransactions} = await moneyhub.getRegularTransactions({userId})
32
+ seriesId = regularTransactions[0].seriesId
33
+ const {data: rentals} = await moneyhub.getRentalRecords({userId})
34
+ if (rentals.length) {
35
+ const existingRentalId = rentals[0].id
36
+ await moneyhub.deleteRentalRecord({userId, rentalId: existingRentalId})
37
+ }
38
+ })
39
+
40
+ beforeEach(async () => {
41
+ const {data} = await moneyhub.createRentalRecord({rentalData: {...testRentalData, seriesId}, userId})
42
+ rentalId = data.id
43
+ })
44
+
45
+ afterEach(async () => {
46
+ try {
47
+ await moneyhub.deleteRentalRecord({userId, rentalId})
48
+ } catch (e) {
49
+ if (!e.message.includes("404")) {
50
+ throw e
51
+ }
52
+ }
53
+
54
+ })
55
+
56
+ it("get rental record", async () => {
57
+ const {data} = await moneyhub.getRentalRecords({userId})
58
+ expect(data.length).to.be.above(0)
59
+ expect(data[0]).to.have.property("seriesId")
60
+ })
61
+
62
+ it("create rental record", async () => {
63
+ const {data} = await moneyhub.getRentalRecords({userId})
64
+ expect(data.length).to.be.above(0)
65
+ assert.containsAllKeys(data[0], {
66
+ title: "Title",
67
+ firstName: "firstName",
68
+ lastName: "lastName",
69
+ birthdate: "2000-11-19",
70
+ addressLine1: "First address line",
71
+ addressLine2: "Second address line",
72
+ addressLine3: "Third address line",
73
+ addressLine4: "Fourth address line",
74
+ postalCode: "CA12345",
75
+ tenancyStartDate: "2020-11-19",
76
+ rentalAmount: {
77
+ value: 10000,
78
+ currency: "GBP"
79
+ },
80
+ rentalFrequency: "monthly",
81
+ })
82
+ })
83
+
84
+ it("delete rental record", async () => {
85
+ await moneyhub.deleteRentalRecord({userId, rentalId})
86
+ const {data} = await moneyhub.getRentalRecords({userId})
87
+ expect(data.length).to.eql(0)
88
+ })
89
+
90
+ })
@@ -2,40 +2,61 @@
2
2
  const Moneyhub = require("..")
3
3
  const config = require("../../test/test-client-config")
4
4
  const {expect} = require("chai")
5
- const userId = config.testUserId
5
+ const {testUserId: userId, testAccountId: accountId} = config
6
6
  const R = require("ramda")
7
+
7
8
  describe("Transaction Splits", () => {
8
9
  let moneyhub
9
- let transaction
10
10
  let transactionId
11
11
  let splitId
12
+
13
+ const splitTestBaseInput = {
14
+ userId,
15
+ splits: [
16
+ {
17
+ categoryId: "std:39577c49-350f-45a4-8ec3-48ce205585fb",
18
+ amount: -1500,
19
+ description: "Split 1"
20
+ },
21
+ {
22
+ categoryId: "std:7daf3d79-98dd-4c85-b3cc-6d7ffd83fce9",
23
+ amount: -800,
24
+ description: "Split 2"
25
+ }
26
+ ]
27
+ }
28
+
12
29
  before(async () => {
13
30
  moneyhub = await Moneyhub(config)
14
- const {data} = await moneyhub.getTransactions({
15
- userId,
16
- params: {limit: 1},
17
- })
18
- transaction = R.head(data)
19
- transactionId = transaction.id
31
+ const transaction = {
32
+ accountId,
33
+ "amount": {
34
+ "value": -2300
35
+ },
36
+ "categoryId": "std:4b0255f0-0309-4509-9e05-4b4e386f9b0d",
37
+ "categoryIdConfirmed": true,
38
+ "longDescription": "New transaction",
39
+ "shortDescription": "transaction",
40
+ "notes": "notes",
41
+ "status": "posted",
42
+ "date": "2018-07-10T12:00:00+00:00"
43
+ }
44
+
45
+ const {data} = await moneyhub.addTransaction({userId, transaction})
46
+ transactionId = data.id
47
+ })
48
+
49
+ beforeEach(async () => {
50
+ const {data} = await moneyhub.splitTransaction({...splitTestBaseInput, transactionId})
51
+ splitId = data[0].id
52
+ })
53
+
54
+ after(async () => {
55
+ await moneyhub.deleteTransaction({userId, transactionId})
20
56
  })
21
57
 
22
58
  it("can split a transaction", async () => {
23
- const {data: splits} = await moneyhub.splitTransaction({
24
- userId,
25
- transactionId,
26
- splits: [
27
- {
28
- categoryId: "std:39577c49-350f-45a4-8ec3-48ce205585fb",
29
- amount: transaction.amount.value / 2,
30
- description: "Split 1"
31
- },
32
- {
33
- categoryId: "std:7daf3d79-98dd-4c85-b3cc-6d7ffd83fce9",
34
- amount: transaction.amount.value / 2,
35
- description: "Split 2"
36
- }
37
- ]
38
- })
59
+ const {data: splits} = await moneyhub.splitTransaction({...splitTestBaseInput, transactionId})
39
60
 
40
61
  expect(splits).to.have.length(2)
41
62
  })
@@ -45,8 +66,9 @@ describe("Transaction Splits", () => {
45
66
  userId,
46
67
  transactionId,
47
68
  })
48
- splitId = R.path([0, "id"], splits)
49
69
  expect(splits).to.have.length(2)
70
+ expect(R.path([0, "amount"], splits)).to.be.oneOf([-1500, -800])
71
+ expect(R.path([0, "description"], splits)).to.be.oneOf(["Split 1", "Split 2"])
50
72
  })
51
73
 
52
74
  it("can update a transactions splits", async () => {
@@ -58,7 +80,6 @@ describe("Transaction Splits", () => {
58
80
  description: "New Description"
59
81
  }
60
82
  })
61
-
62
83
  expect(splits).to.have.length(2)
63
84
  expect(R.path([0, "description"], splits)).to.equal("New Description")
64
85
  })
@@ -219,6 +219,7 @@ module.exports = ({client, config}) => {
219
219
  nonce,
220
220
  context,
221
221
  readRefundAccount,
222
+ userId,
222
223
  claims = {},
223
224
  }) => {
224
225
  if (!state) {
@@ -251,6 +252,11 @@ module.exports = ({client, config}) => {
251
252
  readRefundAccount,
252
253
  },
253
254
  },
255
+ ...userId && {
256
+ sub: {
257
+ value: userId
258
+ }
259
+ }
254
260
  },
255
261
  }
256
262
 
@@ -275,6 +281,7 @@ module.exports = ({client, config}) => {
275
281
  paymentId,
276
282
  state,
277
283
  nonce,
284
+ amount,
278
285
  claims = {},
279
286
  }) => {
280
287
  if (!state) {
@@ -297,6 +304,7 @@ module.exports = ({client, config}) => {
297
304
  essential: true,
298
305
  value: {
299
306
  paymentId,
307
+ amount,
300
308
  },
301
309
  },
302
310
  "mh:payment": {
package/src/index.js CHANGED
@@ -20,6 +20,7 @@ const requestFactories = [
20
20
  require("./requests/categories"),
21
21
  require("./requests/standing-orders"),
22
22
  require("./requests/regular-transactions"),
23
+ require("./requests/rental-records")
23
24
  ]
24
25
  const DEFAULT_TIMEOUT = 60000
25
26
 
@@ -51,8 +52,6 @@ module.exports = async (apiClientConfig) => {
51
52
  timeout,
52
53
  })
53
54
 
54
- Issuer.defaultHttpOptions = {timeout}
55
-
56
55
  const moneyhubIssuer = await Issuer.discover(identityServiceUrl + "/oidc")
57
56
 
58
57
  const client = new moneyhubIssuer.Client(
@@ -0,0 +1,41 @@
1
+ module.exports = ({config, request}) => {
2
+ const {resourceServerUrl} = config
3
+
4
+ return {
5
+ getRentalRecords: async ({userId}) =>
6
+ request(
7
+ `${resourceServerUrl}/rental-records`,
8
+ {
9
+ cc: {
10
+ scope: "rental_records:read",
11
+ sub: userId,
12
+ },
13
+ },
14
+ ),
15
+ createRentalRecord: async ({userId, rentalData}) => {
16
+ return await request(
17
+ `${resourceServerUrl}/rental-records`,
18
+ {
19
+ method: "POST",
20
+ cc: {
21
+ scope: "rental_records:write",
22
+ sub: userId,
23
+ },
24
+ body: rentalData,
25
+ },
26
+ )
27
+ },
28
+ deleteRentalRecord: async ({userId, rentalId}) => {
29
+ return await request(
30
+ `${resourceServerUrl}/rental-records/${rentalId}`,
31
+ {
32
+ method: "DELETE",
33
+ cc: {
34
+ scope: "rental_records:write",
35
+ sub: userId,
36
+ },
37
+ },
38
+ )
39
+ },
40
+ }
41
+ }