@mft/moneyhub-api-client 4.13.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.
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.13.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"
@@ -37,8 +37,8 @@
37
37
  "eslint": "^7.32.0",
38
38
  "express": "^4.17.1",
39
39
  "husky": "^7.0.2",
40
- "mocha": "^9.1.2",
41
- "mocha-junit-reporter": "^2.0.0"
40
+ "mocha": "^9.2.0",
41
+ "mocha-junit-reporter": "^2.0.2"
42
42
  },
43
43
  "husky": {
44
44
  "hooks": {
package/readme.md CHANGED
@@ -1345,6 +1345,57 @@ const regulartransactions = await moneyhub.getRegularTransactions({
1345
1345
  })
1346
1346
  ```
1347
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
+
1348
1399
  ### Financial Connections
1349
1400
 
1350
1401
  #### `listConnections`
@@ -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
+ })
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
 
@@ -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
+ }