@mft/moneyhub-api-client 4.9.0 → 4.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mft/moneyhub-api-client",
3
- "version": "4.9.0",
3
+ "version": "4.13.0",
4
4
  "description": "Node.JS client for the Moneyhub API",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -34,10 +34,10 @@
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",
39
+ "husky": "^7.0.2",
40
+ "mocha": "^9.1.2",
41
41
  "mocha-junit-reporter": "^2.0.0"
42
42
  },
43
43
  "husky": {
package/readme.md CHANGED
@@ -964,6 +964,32 @@ const categoryGroups = await moneyhub.getCategoryGroups({
964
964
  },
965
965
  })
966
966
  ```
967
+
968
+ #### `getStandardCategories`
969
+
970
+ Get standard categories.
971
+
972
+ ```javascript
973
+
974
+ const categories = await moneyhub.getStandardCategories({
975
+ params: {
976
+ type: "personal" // optional personal|business|all
977
+ },
978
+ })
979
+ ```
980
+
981
+ #### `getStandardCategoryGroups`
982
+
983
+ Get standard categories.
984
+
985
+ ```javascript
986
+
987
+ const categoryGroups = await moneyhub.getStandardCategoryGroups({
988
+ params: {
989
+ type: "personal" // optional personal|business|all
990
+ },
991
+ })
992
+ ```
967
993
  #### `createCustomCategory`
968
994
 
969
995
  Create a custom category. This function uses the scopes `categories:read categories:write`.
@@ -1074,10 +1100,10 @@ This is a helper function that returns an authorize url to authorize a payment t
1074
1100
 
1075
1101
  ```javascript
1076
1102
  const url = await moneyhub.getPaymentAuthorizeUrl({
1077
- bankId: "Bank id to authorise payment from",
1078
- payeeId: "Id of payee",
1103
+ bankId: "Bank id to authorise payment from", // required
1104
+ payeeId: "Id of payee", // required
1079
1105
  payeeType: "Payee type [api-payee|mh-user-account]", // optional - defaults to api-payee
1080
- payerId: "Id of payer", // requird only if payerType is defined
1106
+ payerId: "Id of payer", // required only if payerType is defined
1081
1107
  payerType: "Payer type [mh-user-account]", // required only if payerId is used
1082
1108
  amount: "Amount in pence to authorize payment",
1083
1109
  payeeRef: "Payee reference",
@@ -1087,6 +1113,7 @@ const url = await moneyhub.getPaymentAuthorizeUrl({
1087
1113
  state: "your state value",
1088
1114
  nonce: "your nonce value", // optional
1089
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
1090
1117
  claims: claimsObject, // optional
1091
1118
  })
1092
1119
 
@@ -1126,6 +1153,7 @@ const url = await moneyhub.getReversePaymentAuthorizeUrl({
1126
1153
  bankId: "Bank id to authorise payment from",
1127
1154
  paymentId: "Id of payment to reverse",
1128
1155
  state: "your state value",
1156
+ amount: "reverse payment amount" // optional
1129
1157
  nonce: "your nonce value", // optional
1130
1158
  claims: claimsObject, // optional
1131
1159
  })
@@ -1221,10 +1249,10 @@ This is a helper function that returns an authorize url to authorize a standng o
1221
1249
 
1222
1250
  ```javascript
1223
1251
  const url = await moneyhub.getStandingOrderAuthorizeUrl({
1224
- bankId: "Bank id to authorise payment from",
1225
- payeeId: "Id of payee",
1252
+ bankId: "Bank id to authorise payment from", // required
1253
+ payeeId: "Id of payee", // required
1226
1254
  payeeType: "Payee type [api-payee|mh-user-account]", // optional - defaults to api-payee
1227
- payerId: "Id of payer", // requird only if payerType is defined
1255
+ payerId: "Id of payer", // required only if payerType is defined
1228
1256
  payerType: "Payer type [mh-user-account]", // required only if payerId is used
1229
1257
  reference: "The reference for standing order",
1230
1258
  frequency: {
@@ -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
  })
@@ -13,6 +13,16 @@ describe("Categories", () => {
13
13
  moneyhub = await Moneyhub(config)
14
14
  })
15
15
 
16
+ it("get standard categories", async () => {
17
+ const categories = await moneyhub.getStandardCategories({params: {type: "personal"}})
18
+ expect(categories.data.length).to.be.at.least(50)
19
+ })
20
+
21
+ it("get standard category groups", async () => {
22
+ const categories = await moneyhub.getStandardCategoryGroups({params: {type: "all"}})
23
+ expect(categories.data.length).to.be.at.least(24)
24
+ })
25
+
16
26
  it("get personal categories", async () => {
17
27
  const categories = await moneyhub.getCategories({userId, params: {limit: 100}})
18
28
  expect(categories.data.length).to.be.at.least(50)
@@ -81,8 +81,10 @@ describe("API client", () => {
81
81
  "deleteUserConnection",
82
82
  "deleteUser",
83
83
  "getCategories",
84
+ "getStandardCategories",
84
85
  "getCategory",
85
86
  "getCategoryGroups",
87
+ "getStandardCategoryGroups",
86
88
  "createCustomCategory",
87
89
  "getStandingOrder",
88
90
  "getStandingOrders",
@@ -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
@@ -51,8 +51,6 @@ module.exports = async (apiClientConfig) => {
51
51
  timeout,
52
52
  })
53
53
 
54
- Issuer.defaultHttpOptions = {timeout}
55
-
56
54
  const moneyhubIssuer = await Issuer.discover(identityServiceUrl + "/oidc")
57
55
 
58
56
  const client = new moneyhubIssuer.Client(
@@ -7,6 +7,7 @@ module.exports = ({config, request}) => {
7
7
  redirectUri,
8
8
  payment,
9
9
  reversePayment,
10
+ standingOrder,
10
11
  userId,
11
12
  connectionId,
12
13
  categorisationType,
@@ -22,6 +23,7 @@ module.exports = ({config, request}) => {
22
23
  redirectUri,
23
24
  payment,
24
25
  reversePayment,
26
+ standingOrder,
25
27
  userId,
26
28
  connectionId,
27
29
  scope,
@@ -11,6 +11,11 @@ module.exports = ({config, request}) => {
11
11
  },
12
12
  }),
13
13
 
14
+ getStandardCategories: async ({params = {}}) =>
15
+ request(`${resourceServerUrl}/standard-categories`, {
16
+ searchParams: params,
17
+ }),
18
+
14
19
  getCategory: async ({userId, categoryId, params = {}}) =>
15
20
  request(`${resourceServerUrl}/categories/${categoryId}`, {
16
21
  searchParams: params,
@@ -29,6 +34,11 @@ module.exports = ({config, request}) => {
29
34
  },
30
35
  }),
31
36
 
37
+ getStandardCategoryGroups: async ({params = {}}) =>
38
+ request(`${resourceServerUrl}/standard-category-groups`, {
39
+ searchParams: params,
40
+ }),
41
+
32
42
  createCustomCategory: async ({userId, category: {group, name}}) =>
33
43
  request(`${resourceServerUrl}/categories`, {
34
44
  method: "POST",