Skip to content

Commit

Permalink
Merge pull request #785 from davesag/develop
Browse files Browse the repository at this point in the history
[release, 1.1.3] various improvements
  • Loading branch information
davesag authored Jun 4, 2024
2 parents 56b813c + 9d72990 commit d9b7aa7
Show file tree
Hide file tree
Showing 12 changed files with 2,287 additions and 5,876 deletions.
8,052 changes: 2,225 additions & 5,827 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 20 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "ir-api",
"version": "1.1.2",
"version": "1.1.3",
"description": "A Javascript API client for Independent Reserve's API.",
"author": "Dave Sag (https://github.com/davesag)",
"contributors": [
"Oleg Koval (https://github.com/oleg-koval)"
"Oleg Koval (https://github.com/oleg-koval)",
"Nick (https://github.com/omniwolf)"
],
"type": "commonjs",
"license": "MIT",
Expand All @@ -31,7 +32,7 @@
"test": "npm run test:unit",
"test:unit": "NODE_ENV=test mocha ./test/unit/ --require ./test/unitTestHelper.js --recursive",
"test:unit:cov": "NODE_ENV=test nyc mocha ./test/unit/ --require ./test/unitTestHelper.js --recursive",
"snyk-protect": "snyk protect"
"snyk-protect": "snyk-protect"
},
"keywords": [
"independent-reserve",
Expand All @@ -51,28 +52,28 @@
"axios": ">= 0.25.0"
},
"devDependencies": {
"@snyk/protect": "^1.981.0",
"ajv": "^8.11.0",
"axios": "^0.27.2",
"chai": "^4.3.6",
"axios": "^1.6.8",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-fp": "^2.3.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-mocha": "^10.4.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.2.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.5",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"prettier": "^3.3.0",
"proxyquire": "^2.1.3",
"sinon": "^14.0.0",
"sinon-chai": "^3.5.0",
"snyk": "^1.981.0"
"sinon": "^17.0.1",
"sinon-chai": "^3.5.0"
},
"prettier": {
"semi": false,
Expand Down
12 changes: 7 additions & 5 deletions src/api/private/getTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const { getTransport } = require('../../utils/transport')
const { defaultParams } = require('../../defaults')
const { validateFields } = require('../../validation')
const isPositiveNumber = require('../../validation/isPositiveNumber')
const isArrayOf = require('../../validation/isArrayOf')
const isTime = require('../../validation/isTime')
const isOneOf = require('../../validation/isOneOf')

const validation = {
accountGuid: ['isRequired', 'isGuid'],
txTypes: ['isRequired', isArrayOf(['Brokerage', 'Trade'])],
pageIndex: ['isPositiveNumber'],
pageSize: [isPositiveNumber(50)]
pageSize: [isPositiveNumber(5000)],
includeTotals: [isOneOf(['true', 'false'])]
}

// https://www.independentreserve.com/products/api#GetTransactions
Expand All @@ -23,15 +23,17 @@ const getTransactions = (apiKey, apiSecret) => {
toTimestampUtc,
txTypes,
pageIndex = defaultParams.pageIndex,
pageSize = defaultParams.pageSize
pageSize = defaultParams.pageSize,
includeTotals = 'true'
}) => {
const payload = {
accountGuid,
fromTimestampUtc,
toTimestampUtc,
txTypes,
pageIndex,
pageSize
pageSize,
includeTotals
}
// eslint-disable-next-line fp/no-unused-expression
validateFields(payload, {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/fixKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const fixKeys = input =>
? Array.isArray(input)
? input.map(fixKeys)
: typeof input === 'object'
? Object.keys(input).reduce(
(acc, elem) => ({ ...acc, [downcase(elem)]: fixKeys(input[elem]) }),
{}
)
: input
? Object.keys(input).reduce(
(acc, elem) => ({ ...acc, [downcase(elem)]: fixKeys(input[elem]) }),
{}
)
: input
: input

module.exports = fixKeys
4 changes: 2 additions & 2 deletions src/utils/payloadBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const payloadBuilder =
elem === 'signature'
? acc
: Array.isArray(data[elem])
? [...acc, `${elem}=${data[elem].join(',')}`]
: [...acc, `${elem}=${data[elem]}`],
? [...acc, `${elem}=${data[elem].join(',')}`]
: [...acc, `${elem}=${data[elem]}`],
[url]
)
.join(',')
Expand Down
4 changes: 2 additions & 2 deletions src/validation/isArrayOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const isArrayOf =
(allowed.length === 0 || (allowed.length !== 0 && value.every(val => allowed.includes(val)))))
? null
: allowed.length === 0
? 'Expected an array'
: `Expected an array containing ${allowed.join(',')}`
? 'Expected an array'
: `Expected an array containing ${allowed.join(',')}`

module.exports = isArrayOf
4 changes: 2 additions & 2 deletions src/validation/isPositiveNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const isPositiveNumber = max => value =>
(typeof value === 'number' && (isNaN(value) || (value > 0 && (!max || (max && !(value > max))))))
? null
: max
? `Expected a positive number no greater than ${max}`
: 'Expected a positive number'
? `Expected a positive number no greater than ${max}`
: 'Expected a positive number'

module.exports = isPositiveNumber
8 changes: 4 additions & 4 deletions src/validation/isRequired.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const checkRequired = value =>
typeof value === 'number'
? !isNaN(value)
: Array.isArray(value) || typeof value === 'string'
? value.length !== 0
: value === undefined || value === null
? false
: typeof value === 'object' && Object.keys(value).length !== 0
? value.length !== 0
: value === undefined || value === null
? false
: typeof value === 'object' && Object.keys(value).length !== 0

const isRequired = value => (checkRequired(value) ? null : 'Field is required')

Expand Down
4 changes: 2 additions & 2 deletions src/validation/isString.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const isString = max => value =>
!value || (typeof value === 'string' && (!max || (max && !(value.length > max))))
? null
: max
? `Expected a string no longer than ${max} characters`
: 'Expected a string'
? `Expected a string no longer than ${max} characters`
: 'Expected a string'

module.exports = isString
4 changes: 2 additions & 2 deletions test/helpers/privateHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const doTest = ({ handler, params, useDefaults, validation }) => {
}
: params
: useDefaults
? defaultParams
: undefined
? defaultParams
: undefined

let result

Expand Down
20 changes: 15 additions & 5 deletions test/unit/api/private/getTransactions.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const doTest = require('../../../helpers/privateHandlerTest')
const isPositiveNumber = require('../../../../src/validation/isPositiveNumber')
const isArrayOf = require('../../../../src/validation/isArrayOf')
const isTime = require('../../../../src/validation/isTime')
const isOneOf = require('../../../../src/validation/isOneOf')

const fromTimestampUtc = '2014-08-01T08:00:00Z'
const toTimestampUtc = '2016-08-01T08:00:00Z'

const config = {
const config1 = {
handler: 'getTransactions',
params: {
accountGuid: 'dd015a29-8f73-4469-a5fa-ea91544dfcda',
Expand All @@ -19,10 +19,20 @@ const config = {
accountGuid: ['isRequired', 'isGuid'],
fromTimestampUtc: ['isRequired', isTime({ before: toTimestampUtc })],
toTimestampUtc: ['isRequired', isTime({ after: fromTimestampUtc })],
txTypes: ['isRequired', isArrayOf(['Brokerage', 'Trade'])],
pageIndex: ['isPositiveNumber'],
pageSize: [isPositiveNumber(50)]
pageSize: [isPositiveNumber(5000)],
includeTotals: [isOneOf(['true', 'false'])]
}
}

doTest(config)
doTest(config1) // test with missing includeTotals param

const config2 = {
...config1,
params: {
...config1.params,
includeTotals: 'false'
}
}

doTest(config2)
2 changes: 1 addition & 1 deletion test/unit/utils/transport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('utils/transport', () => {
axios.create = stub().returns(axios)

const { getTransport, close } = proxyquire('../../../src/utils/transport', {
axios: axios,
axios,
'./makeTransformError': makeTransformError,
'./transformResponse': transformResponse
})
Expand Down

0 comments on commit d9b7aa7

Please sign in to comment.