这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
b1dc63b
Merge pull request #437 from bitfinexcom/staging
tarcisiozf Jun 9, 2025
f2253e9
Update ajv
ZIMkaRU Jun 12, 2025
d5419e7
Add ajv-formats dep
ZIMkaRU Jun 12, 2025
9eac114
Add schema names
ZIMkaRU Jun 12, 2025
336907c
Add schema domain
ZIMkaRU Jun 12, 2025
f83a9d0
Add schema ids
ZIMkaRU Jun 12, 2025
2622e83
Add schema defs
ZIMkaRU Jun 12, 2025
8cddbf7
Add schema entrypoint
ZIMkaRU Jun 12, 2025
a494300
Add data-validator module
ZIMkaRU Jun 12, 2025
97b8af7
Move schema ids getter to helper
ZIMkaRU Jun 12, 2025
1b2d304
Move schema require logic to helper
ZIMkaRU Jun 12, 2025
1cf2b20
Implement validate fn using ajv
ZIMkaRU Jun 13, 2025
af1d3ac
Add DataValidator service type
ZIMkaRU Jun 13, 2025
5b62da8
Add DataValidator to di
ZIMkaRU Jun 13, 2025
a567cb6
Add language to param schema definitions
ZIMkaRU Jun 13, 2025
1af95b2
Add timezone to param schema definitions
ZIMkaRU Jun 16, 2025
47c20d6
Add start to param schema definitions
ZIMkaRU Jun 16, 2025
f5e4b56
Add end to param schema definitions
ZIMkaRU Jun 16, 2025
e29fc9e
Add limit to param schema definitions
ZIMkaRU Jun 16, 2025
16d2ebf
Add symbol to param schema definitions
ZIMkaRU Jun 16, 2025
fff8d8b
Add sort to param schema definitions
ZIMkaRU Jun 16, 2025
8beffc3
Add email to param schema definitions
ZIMkaRU Jun 16, 2025
2c267a1
Add id to param schema definitions
ZIMkaRU Jun 16, 2025
2626a15
Add symbol with min-max to param schema definitions
ZIMkaRU Jun 16, 2025
dc57d84
Add symbol without min-max to param schema definitions
ZIMkaRU Jun 16, 2025
41eb66a
Add isPDFRequired to param schema definitions
ZIMkaRU Jun 16, 2025
aaa1248
Add common-req param schema
ZIMkaRU Jun 16, 2025
ade9b3c
Inject DataValidator into main report service
ZIMkaRU Jun 16, 2025
0acd249
Rename common req param schema
ZIMkaRU Jun 16, 2025
240d67c
Add getWeightedAveragesReport req param schema
ZIMkaRU Jun 17, 2025
adda8c9
Use DataValidator with getWeightedAveragesReport endpoint
ZIMkaRU Jun 17, 2025
c91deb7
Add getPayInvoiceList req param schema
ZIMkaRU Jun 17, 2025
686e91e
Prevent additional properties in params schemas
ZIMkaRU Jun 17, 2025
6c4c6c3
Add getStatusMessages req param schema
ZIMkaRU Jun 17, 2025
7814943
Add notCheckNextPage into param schemas
ZIMkaRU Jun 17, 2025
6a38396
Add notThrowError into param schemas
ZIMkaRU Jun 17, 2025
0732806
Add isSyncRequest into param schemas
ZIMkaRU Jun 17, 2025
2060b8c
Add getPublicTrades req param schema
ZIMkaRU Jun 18, 2025
9be9fcd
Add getPositionsAudit req param schema
ZIMkaRU Jun 18, 2025
2f55d59
Add to getPayInvoiceList req param schema
ZIMkaRU Jun 18, 2025
3679d2e
Add to getPublicTrades req param schema
ZIMkaRU Jun 18, 2025
384fa75
Add to getStatusMessages req param schema
ZIMkaRU Jun 18, 2025
eebf753
Add filter to req param schemas
ZIMkaRU Jun 18, 2025
e2c6e1b
Add getOrderTrades req param schema
ZIMkaRU Jun 18, 2025
3b06a48
Add getCandles req param schema
ZIMkaRU Jun 18, 2025
00c8009
Add getLedgers req param schema
ZIMkaRU Jun 18, 2025
dcb4231
Add getTickersHistory req param schema
ZIMkaRU Jun 18, 2025
1f58e37
Add milliseconds to param schema definitions
ZIMkaRU Jun 19, 2025
398622e
Add isSignatureRequired to param schema definitions
ZIMkaRU Jun 19, 2025
13429b5
Inject DataValidator into PrepareApiResponse service
ZIMkaRU Jun 19, 2025
90d9a02
Add validation-schema-id getter
ZIMkaRU Jun 19, 2025
03d1a3d
Use data validator in PrepareResponse service
ZIMkaRU Jun 19, 2025
c51f9ee
Remove redundant required fields from getTickersHistory endpoint
ZIMkaRU Jun 19, 2025
393ae38
Adjust default params for getStatusMessages
ZIMkaRU Jun 19, 2025
badd150
Adjust limit params for getWeightedAverages
ZIMkaRU Jun 19, 2025
c84d50f
Omit redundant request params for report file gen
ZIMkaRU Jun 19, 2025
9e82c9a
Add getMovementInfo req param schema
ZIMkaRU Jun 20, 2025
1edb1c4
Use DataValidator with getMovementInfo endpoint
ZIMkaRU Jun 20, 2025
67165df
Add getWallets req param schema
ZIMkaRU Jun 20, 2025
70ec922
Use DataValidator with getWallets endpoint
ZIMkaRU Jun 20, 2025
0597af1
Adjust default params for getWallets
ZIMkaRU Jun 20, 2025
99f545f
Omit redundant request params for wallets report file gen
ZIMkaRU Jun 20, 2025
1422ee8
Fix setDefaultParams helper naming
ZIMkaRU Jun 20, 2025
6df5fab
Add method to param schema definitions
ZIMkaRU Jul 8, 2025
ef3f576
Add commonFile req param schema name
ZIMkaRU Jul 8, 2025
5d7c19c
Add commonFile req param schema
ZIMkaRU Jul 8, 2025
a17e853
Use data validator with commonFile req param schema
ZIMkaRU Jul 8, 2025
a3cd648
Omit redundant method field for multi-export
ZIMkaRU Jul 9, 2025
2a745f2
Add getMultipleFile req param schema name
ZIMkaRU Jul 9, 2025
9bd79a1
Add getMultipleFile req param schema
ZIMkaRU Jul 9, 2025
0de8d83
Remove redundant method field from commonFile req param schema
ZIMkaRU Jul 9, 2025
4e421e2
Add shouldParamsFieldBeChecked flag support to data validator
ZIMkaRU Jul 9, 2025
6a6fafe
Use data validator with multi-export
ZIMkaRU Jul 9, 2025
ba8b306
Add email to commonFile req param schema
ZIMkaRU Jul 9, 2025
bf290e1
Add getTickersHistoryFile req param schema name
ZIMkaRU Jul 9, 2025
13a7d57
Add getTickersHistoryFile req param schema
ZIMkaRU Jul 9, 2025
2a75635
Use data validator with getTickersHistoryFile
ZIMkaRU Jul 9, 2025
7ac7b34
Add getMovementsFile req param schema name
ZIMkaRU Jul 10, 2025
f377249
Add getMovementsFile req param schema
ZIMkaRU Jul 10, 2025
45a246e
Use data validator with getMovementsFile
ZIMkaRU Jul 10, 2025
db3950b
Add getLedgersFile req param schema name
ZIMkaRU Jul 10, 2025
0f95f3e
Add getLedgersFile req param schema
ZIMkaRU Jul 10, 2025
7c64174
Use data validator with getLedgersFile
ZIMkaRU Jul 10, 2025
cf17073
Add getWalletsFile req param schema name
ZIMkaRU Jul 10, 2025
d29ef61
Add getWalletsFile req param schema
ZIMkaRU Jul 10, 2025
7184a37
Use data validator with getWalletsFile
ZIMkaRU Jul 10, 2025
875ca13
Add getActivePositionsFile req param schema name
ZIMkaRU Jul 10, 2025
54aa867
Add getActivePositionsFile req param schema
ZIMkaRU Jul 10, 2025
ba7b1f8
Use data validator with getActivePositionsFile
ZIMkaRU Jul 10, 2025
78df59f
Add getPositionsAuditFile req param schema name
ZIMkaRU Jul 11, 2025
0c9b7d0
Add getPositionsAuditFile req param schema
ZIMkaRU Jul 11, 2025
419d065
Use data validator with getPositionsAuditFile
ZIMkaRU Jul 11, 2025
914b52a
Add getPublicTradesFile req param schema name
ZIMkaRU Jul 11, 2025
dc71a26
Add getPublicTradesFile req param schema
ZIMkaRU Jul 11, 2025
df50e96
Use data validator with getPublicTradesFile
ZIMkaRU Jul 11, 2025
9b0a41a
Add required symbol field to getPublicTrades req param schema
ZIMkaRU Jul 11, 2025
2faa744
Add getStatusMessagesFile req param schema name
ZIMkaRU Jul 11, 2025
bef272e
Add getStatusMessagesFile req param schema
ZIMkaRU Jul 11, 2025
367c20f
Use data validator with getStatusMessagesFile
ZIMkaRU Jul 11, 2025
e402b08
Add getCandlesFile req param schema name
ZIMkaRU Jul 11, 2025
40b217b
Add getCandlesFile req param schema
ZIMkaRU Jul 11, 2025
3fce722
Use data validator with getCandlesFile
ZIMkaRU Jul 11, 2025
c7260cc
Add getOrderTradesFile req param schema name
ZIMkaRU Jul 14, 2025
f61c5c1
Add getOrderTradesFile req param schema
ZIMkaRU Jul 14, 2025
8988abc
Use data validator with getOrderTradesFile
ZIMkaRU Jul 14, 2025
cd00db3
Add getWeightedAveragesReportFile req param schema name
ZIMkaRU Jul 14, 2025
41b07e3
Add getWeightedAveragesReportFile req param schema
ZIMkaRU Jul 14, 2025
497b233
Use data validator with getWeightedAveragesReportFile
ZIMkaRU Jul 14, 2025
bf3ceff
Add helper to omit extra param fields
ZIMkaRU Jul 15, 2025
a59a998
Use omitting extra param fields helper
ZIMkaRU Jul 15, 2025
b77c5d7
Add sort to getPublicTrades req param schema
ZIMkaRU Jul 16, 2025
8118c48
Add sort to getPublicTradesFile req param schema
ZIMkaRU Jul 16, 2025
5ba8cc2
Prevent request retry to bfx api if params validation error
ZIMkaRU Jul 18, 2025
ed6def1
Fix limit param passing
ZIMkaRU Jul 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"Ezequiel Wernicke <ezequiel.wernicke@bitfinex.com>"
],
"dependencies": {
"ajv": "8.6.3",
"ajv": "8.17.1",
"ajv-formats": "3.0.1",
"async": "3.2.4",
"better-npm-run": "0.1.1",
"bfx-facs-base": "git+https://github.com:bitfinexcom/bfx-facs-base.git",
Expand Down
36 changes: 36 additions & 0 deletions workers/loc.api/data-validator/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

const path = require('node:path')

const SCHEMA_DOMAIN = require('../schema.domain')

const getSchemaIds = (schemaNames, schemaDomain) => {
const domain = schemaDomain ?? SCHEMA_DOMAIN
const names = Object.entries(schemaNames ?? {})

const schemaIds = {}

for (const [key, name] of names) {
schemaIds[key] = `${domain}/${name}`
}

return schemaIds
}

const requireSchemas = (schemaNames, baseSchemaPath) => {
const schemaPath = baseSchemaPath ?? path.join(__dirname, '../schemas')
const names = Object.values(schemaNames ?? {})

const schemas = {}

for (const name of names) {
schemas[name] = require(path.join(schemaPath, name))
}

return schemas
}

module.exports = {
getSchemaIds,
requireSchemas
}
102 changes: 102 additions & 0 deletions workers/loc.api/data-validator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict'

const Ajv = require('ajv')
const addFormats = require('ajv-formats')
const argv = require('yargs').argv

const isDevEnv = (
argv.env === 'development' ||
process.env.NODE_ENV === 'development'
)

const {
ArgsParamsError,
ParamsValidSchemaFindingError
} = require('../errors')

const SCHEMA_DOMAIN = require('./schema.domain')
const SCHEMA_NAMES = require('./schema.names')
const SCHEMA_IDS = require('./schema.ids')
const schemas = require('./schemas')

const ajv = new Ajv({
// Compile schema on initialization
schemas: Object.values(schemas),

// Strict mode
strict: true,
strictRequired: true,
allowMatchingProperties: true,
allowUnionTypes: true,

$data: true,
ownProperties: true,
allErrors: true,
messages: true,
formats: { reserved: true },
verbose: isDevEnv
})
addFormats(ajv)

const addSchemas = (schemas = []) => {
const _schemas = Array.isArray(schemas)
? schemas
: [schemas]

if (_schemas.length === 0) {
return
}

for (const schema of schemas) {
ajv.addSchema(schema)
}
}

const validate = (args, schemaId, opts) => {
const {
shouldParamsFieldBeChecked
} = opts ?? {}
const params = args?.params

if (
!shouldParamsFieldBeChecked &&
(
typeof params === 'undefined' ||
params === null
)
) {
return true
}

const validate = ajv.getSchema(schemaId)

if (typeof validate !== 'function') {
throw new ParamsValidSchemaFindingError()
}

const res = validate(params)

// It covers a case when schema has `$async: true` keyword
if (res instanceof Promise) {
return res
.then(() => true)
.catch((err) => Promise.reject(
new ArgsParamsError({ data: err.errors })
))
}

if (res) {
return true
}

throw new ArgsParamsError({ data: validate.errors })
}

module.exports = {
SCHEMA_DOMAIN,
SCHEMA_NAMES,
SCHEMA_IDS,

addSchemas,
validate
}
3 changes: 3 additions & 0 deletions workers/loc.api/data-validator/schema.domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

module.exports = 'report.bitfinex.com'
6 changes: 6 additions & 0 deletions workers/loc.api/data-validator/schema.ids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

const SCHEMA_NAMES = require('./schema.names')
const { getSchemaIds } = require('./helpers')

module.exports = getSchemaIds(SCHEMA_NAMES)
32 changes: 32 additions & 0 deletions workers/loc.api/data-validator/schema.names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

module.exports = {
DEFS: 'defs',

COMMON_REQ: 'commonReq',
GET_WEIGHTED_AVERAGES_REPORT_REQ: 'getWeightedAveragesReportReq',
GET_PAY_INVOICE_LIST_REQ: 'getPayInvoiceListReq',
GET_STATUS_MESSAGES_REQ: 'getStatusMessagesReq',
GET_PUBLIC_TRADES_REQ: 'getPublicTradesReq',
GET_POSITIONS_AUDIT_REQ: 'getPositionsAuditReq',
GET_ORDER_TRADES_REQ: 'getOrderTradesReq',
GET_CANDLES_REQ: 'getCandlesReq',
GET_LEDGERS_REQ: 'getLedgersReq',
GET_TICKERS_HISTORY_REQ: 'getTickersHistoryReq',
GET_MOVEMENT_INFO_REQ: 'getMovementInfoReq',
GET_WALLETS_REQ: 'getWalletsReq',

COMMON_FILE_REQ: 'commonFileReq',
GET_MULTIPLE_FILE_REQ: 'getMultipleFileReq',
GET_TICKERS_HISTORY_FILE_REQ: 'getTickersHistoryFileReq',
GET_MOVEMENTS_FILE_REQ: 'getMovementsFileReq',
GET_LEDGERS_FILE_REQ: 'getLedgersFileReq',
GET_WALLETS_FILE_REQ: 'getWalletsFileReq',
GET_ACTIVE_POSITIONS_FILE_REQ: 'getActivePositionsFileReq',
GET_POSITIONS_AUDIT_FILE_REQ: 'getPositionsAuditFileReq',
GET_PUBLIC_TRADES_FILE_REQ: 'getPublicTradesFileReq',
GET_STATUS_MESSAGES_FILE_REQ: 'getStatusMessagesFileReq',
GET_CANDLES_FILE_REQ: 'getCandlesFileReq',
GET_ORDER_TRADES_FILE_REQ: 'getOrderTradesFileReq',
GET_WEIGHTED_AVERAGES_REPORT_FILE_REQ: 'getWeightedAveragesReportFileReq'
}
48 changes: 48 additions & 0 deletions workers/loc.api/data-validator/schemas/commonFileReq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

const SCHEMA_IDS = require('../schema.ids')

module.exports = {
$id: SCHEMA_IDS.COMMON_FILE_REQ,
type: 'object',
additionalProperties: false,
properties: {
start: {
$ref: 'defs#/definitions/start'
},
end: {
$ref: 'defs#/definitions/end'
},
limit: {
$ref: 'defs#/definitions/limit'
},
symbol: {
$ref: 'defs#/definitions/symbolWithMinItem'
},
filter: {
$ref: 'defs#/definitions/filter'
},

email: {
$ref: 'defs#/definitions/email'
},
milliseconds: {
$ref: 'defs#/definitions/milliseconds'
},
dateFormat: {
$ref: 'defs#/definitions/dateFormat'
},
language: {
$ref: 'defs#/definitions/language'
},
timezone: {
$ref: 'defs#/definitions/timezone'
},
isPDFRequired: {
$ref: 'defs#/definitions/isPDFRequired'
},
isSignatureRequired: {
$ref: 'defs#/definitions/isSignatureRequired'
}
}
}
36 changes: 36 additions & 0 deletions workers/loc.api/data-validator/schemas/commonReq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

const SCHEMA_IDS = require('../schema.ids')

module.exports = {
$id: SCHEMA_IDS.COMMON_REQ,
type: 'object',
additionalProperties: false,
properties: {
start: {
$ref: 'defs#/definitions/start'
},
end: {
$ref: 'defs#/definitions/end'
},
limit: {
$ref: 'defs#/definitions/limit'
},
symbol: {
$ref: 'defs#/definitions/symbolWithMinItem'
},
filter: {
$ref: 'defs#/definitions/filter'
},

notCheckNextPage: {
$ref: 'defs#/definitions/notCheckNextPage'
},
notThrowError: {
$ref: 'defs#/definitions/notThrowError'
},
isSyncRequest: {
$ref: 'defs#/definitions/isSyncRequest'
}
}
}
Loading