diff --git a/package-lock.json b/package-lock.json index e9184e85..83680f04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "4.12.4", "license": "Apache-2.0", "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", @@ -501,21 +502,38 @@ "license": "MIT" }, "node_modules/ajv": { - "version": "8.6.3", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.6.3.tgz", - "integrity": "sha512-SMJOdDP6LqTkD0Uq8qLi+gMwSt0imXLSV080qFVwJCpH9U6Mb+SUGHAXM0KNbcBPguytWyvFxcHgMLe2D2XSpw==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "license": "MIT", "dependencies": { - "fast-deep-equal": "^3.1.1", + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" + "require-from-string": "^2.0.2" }, "funding": { "type": "github", "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -3316,6 +3334,22 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-uri": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.6.tgz", + "integrity": "sha512-Atfo14OibSv5wAp4VWNsFYE1AchQRTv9cBGWET4pZWHzYshFSS9NQI6I57rdKn9croWVMbYFbLhJ+yJvmZIIHw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/fastq": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.19.1.tgz", @@ -6314,6 +6348,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -7702,6 +7737,7 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, "license": "BSD-2-Clause", "dependencies": { "punycode": "^2.1.0" diff --git a/package.json b/package.json index 277edfd2..20870f1f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "Ezequiel Wernicke " ], "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", diff --git a/workers/loc.api/data-validator/helpers/index.js b/workers/loc.api/data-validator/helpers/index.js new file mode 100644 index 00000000..207aad00 --- /dev/null +++ b/workers/loc.api/data-validator/helpers/index.js @@ -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 +} diff --git a/workers/loc.api/data-validator/index.js b/workers/loc.api/data-validator/index.js new file mode 100644 index 00000000..0793445c --- /dev/null +++ b/workers/loc.api/data-validator/index.js @@ -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 +} diff --git a/workers/loc.api/data-validator/schema.domain.js b/workers/loc.api/data-validator/schema.domain.js new file mode 100644 index 00000000..55204c4f --- /dev/null +++ b/workers/loc.api/data-validator/schema.domain.js @@ -0,0 +1,3 @@ +'use strict' + +module.exports = 'report.bitfinex.com' diff --git a/workers/loc.api/data-validator/schema.ids.js b/workers/loc.api/data-validator/schema.ids.js new file mode 100644 index 00000000..9c797d80 --- /dev/null +++ b/workers/loc.api/data-validator/schema.ids.js @@ -0,0 +1,6 @@ +'use strict' + +const SCHEMA_NAMES = require('./schema.names') +const { getSchemaIds } = require('./helpers') + +module.exports = getSchemaIds(SCHEMA_NAMES) diff --git a/workers/loc.api/data-validator/schema.names.js b/workers/loc.api/data-validator/schema.names.js new file mode 100644 index 00000000..9bc39edd --- /dev/null +++ b/workers/loc.api/data-validator/schema.names.js @@ -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' +} diff --git a/workers/loc.api/data-validator/schemas/commonFileReq.js b/workers/loc.api/data-validator/schemas/commonFileReq.js new file mode 100644 index 00000000..a5eeb011 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/commonFileReq.js @@ -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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/commonReq.js b/workers/loc.api/data-validator/schemas/commonReq.js new file mode 100644 index 00000000..cce7c66c --- /dev/null +++ b/workers/loc.api/data-validator/schemas/commonReq.js @@ -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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/defs.js b/workers/loc.api/data-validator/schemas/defs.js new file mode 100644 index 00000000..4d9b4539 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/defs.js @@ -0,0 +1,156 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.DEFS, + definitions: { + milliseconds: { + type: 'boolean' + }, + dateFormat: { + type: 'string', + enum: [ + 'DD-MM-YY', + 'DD-MM-YYYY', + 'MM-DD-YY', + 'MM-DD-YYYY', + 'YY-MM-DD', + 'YYYY-MM-DD' + ] + }, + language: { + type: 'string', + minLength: 2 + }, + timezone: { + type: ['number', 'string'] + }, + start: { + type: 'integer', + minimum: 0 + }, + end: { + type: 'integer', + exclusiveMinimum: { $data: '1/start' }, + minimum: Date.UTC(2013) + }, + limit: { + type: 'integer', + minimum: 1 + }, + strSymbol: { + type: 'string', + minLength: 3 + }, + symbol: { + type: ['string', 'array'], + if: { + type: 'array' + }, + then: { + uniqueItems: true, + items: { + $ref: '#/definitions/strSymbol' + } + }, + else: { + $ref: '#/definitions/strSymbol' + } + }, + symbolWithMinItem: { + type: ['string', 'array'], + if: { + type: 'array' + }, + then: { + uniqueItems: true, + minItems: 1, + items: { + $ref: '#/definitions/strSymbol' + } + }, + else: { + $ref: '#/definitions/strSymbol' + } + }, + symbolWithMaxItem: { + type: ['string', 'array'], + if: { + type: 'array' + }, + then: { + uniqueItems: true, + maxItems: 1, + items: { + $ref: '#/definitions/strSymbol' + } + }, + else: { + $ref: '#/definitions/strSymbol' + } + }, + symbolWithMinMaxItem: { + type: ['string', 'array'], + if: { + type: 'array' + }, + then: { + uniqueItems: true, + minItems: 1, + maxItems: 1, + items: { + $ref: '#/definitions/strSymbol' + } + }, + else: { + $ref: '#/definitions/strSymbol' + } + }, + sort: { + type: 'integer', + enum: [1, -1] + }, + email: { + type: 'string', + format: 'email' + }, + strId: { + type: 'string', + minLength: 1 + }, + intId: { + type: 'integer', + minimum: 0 + }, + arrId: { + type: 'array', + uniqueItems: true, + minItems: 1, + items: { + $ref: '#/definitions/intId' + } + }, + filter: { + type: 'object' + }, + notCheckNextPage: { + type: 'boolean' + }, + notThrowError: { + type: 'boolean' + }, + isSyncRequest: { + type: 'boolean' + }, + isPDFRequired: { + type: 'boolean' + }, + isSignatureRequired: { + type: 'boolean' + }, + method: { + type: 'string' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getActivePositionsFileReq.js b/workers/loc.api/data-validator/schemas/getActivePositionsFileReq.js new file mode 100644 index 00000000..8bbb83cb --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getActivePositionsFileReq.js @@ -0,0 +1,32 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_ACTIVE_POSITIONS_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getCandlesFileReq.js b/workers/loc.api/data-validator/schemas/getCandlesFileReq.js new file mode 100644 index 00000000..c1552202 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getCandlesFileReq.js @@ -0,0 +1,60 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_CANDLES_FILE_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMaxItem' + }, + sort: { + $ref: 'defs#/definitions/sort' + }, + timeframe: { + type: 'string', + minLength: 2 + }, + section: { + type: 'string', + enum: ['last', 'hist'] + }, + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getCandlesReq.js b/workers/loc.api/data-validator/schemas/getCandlesReq.js new file mode 100644 index 00000000..c79ccf8f --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getCandlesReq.js @@ -0,0 +1,48 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_CANDLES_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMaxItem' + }, + sort: { + $ref: 'defs#/definitions/sort' + }, + timeframe: { + type: 'string', + minLength: 2 + }, + section: { + type: 'string', + enum: ['last', 'hist'] + }, + filter: { + $ref: 'defs#/definitions/filter' + }, + + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + }, + isSyncRequest: { + $ref: 'defs#/definitions/isSyncRequest' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getLedgersFileReq.js b/workers/loc.api/data-validator/schemas/getLedgersFileReq.js new file mode 100644 index 00000000..ef916779 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getLedgersFileReq.js @@ -0,0 +1,70 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_LEDGERS_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' + }, + category: { + type: ['string', 'integer'], + if: { + type: 'string' + }, + then: { + minLength: 1, + pattern: '(^[1-9]\\d*$)|(^[0]$)' + }, + else: { + minimum: 0 + } + }, + isMarginFundingPayment: { + type: 'boolean' + }, + isAffiliateRebate: { + type: 'boolean' + }, + isStakingPayments: { + type: 'boolean' + }, + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getLedgersReq.js b/workers/loc.api/data-validator/schemas/getLedgersReq.js new file mode 100644 index 00000000..cdf049e6 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getLedgersReq.js @@ -0,0 +1,58 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_LEDGERS_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' + }, + category: { + type: ['string', 'integer'], + if: { + type: 'string' + }, + then: { + minLength: 1, + pattern: '(^[1-9]\\d*$)|(^[0]$)' + }, + else: { + minimum: 0 + } + }, + isMarginFundingPayment: { + type: 'boolean' + }, + isAffiliateRebate: { + type: 'boolean' + }, + isStakingPayments: { + type: 'boolean' + }, + filter: { + $ref: 'defs#/definitions/filter' + }, + + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + }, + isSyncRequest: { + $ref: 'defs#/definitions/isSyncRequest' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getMovementInfoReq.js b/workers/loc.api/data-validator/schemas/getMovementInfoReq.js new file mode 100644 index 00000000..55945b7e --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getMovementInfoReq.js @@ -0,0 +1,15 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_MOVEMENT_INFO_REQ, + type: 'object', + additionalProperties: false, + required: ['id'], + properties: { + id: { + $ref: 'defs#/definitions/intId' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getMovementsFileReq.js b/workers/loc.api/data-validator/schemas/getMovementsFileReq.js new file mode 100644 index 00000000..91499afb --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getMovementsFileReq.js @@ -0,0 +1,54 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_MOVEMENTS_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' + }, + isDeposits: { + type: 'boolean' + }, + isWithdrawals: { + type: 'boolean' + }, + + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getMultipleFileReq.js b/workers/loc.api/data-validator/schemas/getMultipleFileReq.js new file mode 100644 index 00000000..173e4c5f --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getMultipleFileReq.js @@ -0,0 +1,39 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_MULTIPLE_FILE_REQ, + type: 'object', + additionalProperties: false, + required: ['multiExport'], + properties: { + email: { + $ref: 'defs#/definitions/email' + }, + language: { + $ref: 'defs#/definitions/language' + }, + isPDFRequired: { + $ref: 'defs#/definitions/isPDFRequired' + }, + isSignatureRequired: { + $ref: 'defs#/definitions/isSignatureRequired' + }, + + multiExport: { + type: 'array', + minItems: 1, + items: { + type: 'object', + additionalProperties: true, + required: ['method'], + properties: { + method: { + $ref: 'defs#/definitions/method' + } + } + } + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getOrderTradesFileReq.js b/workers/loc.api/data-validator/schemas/getOrderTradesFileReq.js new file mode 100644 index 00000000..3f6ea679 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getOrderTradesFileReq.js @@ -0,0 +1,52 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_ORDER_TRADES_FILE_REQ, + type: 'object', + additionalProperties: false, + required: ['id', 'symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMinMaxItem' + }, + id: { + $ref: 'defs#/definitions/intId' + }, + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getOrderTradesReq.js b/workers/loc.api/data-validator/schemas/getOrderTradesReq.js new file mode 100644 index 00000000..06ed4cc2 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getOrderTradesReq.js @@ -0,0 +1,40 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_ORDER_TRADES_REQ, + type: 'object', + additionalProperties: false, + required: ['id', 'symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMinMaxItem' + }, + id: { + $ref: 'defs#/definitions/intId' + }, + filter: { + $ref: 'defs#/definitions/filter' + }, + + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + }, + isSyncRequest: { + $ref: 'defs#/definitions/isSyncRequest' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getPayInvoiceListReq.js b/workers/loc.api/data-validator/schemas/getPayInvoiceListReq.js new file mode 100644 index 00000000..00eedecf --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPayInvoiceListReq.js @@ -0,0 +1,39 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_PAY_INVOICE_LIST_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' + }, + id: { + $ref: 'defs#/definitions/strId' + }, + filter: { + $ref: 'defs#/definitions/filter' + }, + + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + }, + isSyncRequest: { + $ref: 'defs#/definitions/isSyncRequest' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getPositionsAuditFileReq.js b/workers/loc.api/data-validator/schemas/getPositionsAuditFileReq.js new file mode 100644 index 00000000..a4aa98f9 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPositionsAuditFileReq.js @@ -0,0 +1,52 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_POSITIONS_AUDIT_FILE_REQ, + type: 'object', + additionalProperties: false, + required: ['id'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMinItem' + }, + id: { + $ref: 'defs#/definitions/arrId' + }, + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getPositionsAuditReq.js b/workers/loc.api/data-validator/schemas/getPositionsAuditReq.js new file mode 100644 index 00000000..d0ddd340 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPositionsAuditReq.js @@ -0,0 +1,40 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_POSITIONS_AUDIT_REQ, + type: 'object', + additionalProperties: false, + required: ['id'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMinItem' + }, + id: { + $ref: 'defs#/definitions/arrId' + }, + filter: { + $ref: 'defs#/definitions/filter' + }, + + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + }, + isSyncRequest: { + $ref: 'defs#/definitions/isSyncRequest' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getPublicTradesFileReq.js b/workers/loc.api/data-validator/schemas/getPublicTradesFileReq.js new file mode 100644 index 00000000..66398c3b --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPublicTradesFileReq.js @@ -0,0 +1,52 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_PUBLIC_TRADES_FILE_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMaxItem' + }, + sort: { + $ref: 'defs#/definitions/sort' + }, + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getPublicTradesReq.js b/workers/loc.api/data-validator/schemas/getPublicTradesReq.js new file mode 100644 index 00000000..58002e18 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPublicTradesReq.js @@ -0,0 +1,40 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_PUBLIC_TRADES_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + limit: { + $ref: 'defs#/definitions/limit' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMaxItem' + }, + sort: { + $ref: 'defs#/definitions/sort' + }, + filter: { + $ref: 'defs#/definitions/filter' + }, + + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + }, + isSyncRequest: { + $ref: 'defs#/definitions/isSyncRequest' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getStatusMessagesFileReq.js b/workers/loc.api/data-validator/schemas/getStatusMessagesFileReq.js new file mode 100644 index 00000000..a96adf89 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getStatusMessagesFileReq.js @@ -0,0 +1,42 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_STATUS_MESSAGES_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + symbol: { + $ref: 'defs#/definitions/symbolWithMinItem' + }, + type: { + type: 'string' + }, + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getStatusMessagesReq.js b/workers/loc.api/data-validator/schemas/getStatusMessagesReq.js new file mode 100644 index 00000000..3932d2f6 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getStatusMessagesReq.js @@ -0,0 +1,30 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_STATUS_MESSAGES_REQ, + type: 'object', + additionalProperties: false, + properties: { + symbol: { + $ref: 'defs#/definitions/symbolWithMinItem' + }, + type: { + type: 'string' + }, + filter: { + $ref: 'defs#/definitions/filter' + }, + + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + }, + isSyncRequest: { + $ref: 'defs#/definitions/isSyncRequest' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getTickersHistoryFileReq.js b/workers/loc.api/data-validator/schemas/getTickersHistoryFileReq.js new file mode 100644 index 00000000..97e8132b --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTickersHistoryFileReq.js @@ -0,0 +1,49 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TICKERS_HISTORY_FILE_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getTickersHistoryReq.js b/workers/loc.api/data-validator/schemas/getTickersHistoryReq.js new file mode 100644 index 00000000..3bc8d82e --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTickersHistoryReq.js @@ -0,0 +1,37 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TICKERS_HISTORY_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getWalletsFileReq.js b/workers/loc.api/data-validator/schemas/getWalletsFileReq.js new file mode 100644 index 00000000..7c7f7ee5 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWalletsFileReq.js @@ -0,0 +1,36 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WALLETS_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + end: { + $ref: 'defs#/definitions/end' + }, + + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getWalletsReq.js b/workers/loc.api/data-validator/schemas/getWalletsReq.js new file mode 100644 index 00000000..1d5be5c2 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWalletsReq.js @@ -0,0 +1,14 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WALLETS_REQ, + type: 'object', + additionalProperties: false, + properties: { + end: { + $ref: 'defs#/definitions/end' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getWeightedAveragesReportFileReq.js b/workers/loc.api/data-validator/schemas/getWeightedAveragesReportFileReq.js new file mode 100644 index 00000000..f8da6041 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWeightedAveragesReportFileReq.js @@ -0,0 +1,43 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WEIGHTED_AVERAGES_REPORT_FILE_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMaxItem' + }, + + 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' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getWeightedAveragesReportReq.js b/workers/loc.api/data-validator/schemas/getWeightedAveragesReportReq.js new file mode 100644 index 00000000..3132a577 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWeightedAveragesReportReq.js @@ -0,0 +1,27 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WEIGHTED_AVERAGES_REPORT_REQ, + type: 'object', + additionalProperties: false, + required: ['symbol'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + symbol: { + $ref: 'defs#/definitions/symbolWithMaxItem' + }, + notCheckNextPage: { + $ref: 'defs#/definitions/notCheckNextPage' + }, + notThrowError: { + $ref: 'defs#/definitions/notThrowError' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/index.js b/workers/loc.api/data-validator/schemas/index.js new file mode 100644 index 00000000..cc2e619f --- /dev/null +++ b/workers/loc.api/data-validator/schemas/index.js @@ -0,0 +1,6 @@ +'use strict' + +const SCHEMA_NAMES = require('../schema.names') +const { requireSchemas } = require('../helpers') + +module.exports = requireSchemas(SCHEMA_NAMES) diff --git a/workers/loc.api/di/app.deps.js b/workers/loc.api/di/app.deps.js index 4a57dd8c..eed0ba6d 100644 --- a/workers/loc.api/di/app.deps.js +++ b/workers/loc.api/di/app.deps.js @@ -55,7 +55,8 @@ module.exports = ({ ['_generateReportFile', TYPES.GenerateReportFile], ['_hasGrcService', TYPES.HasGrcService], ['_weightedAveragesReport', TYPES.WeightedAveragesReport], - ['_i18next', TYPES.I18next] + ['_i18next', TYPES.I18next], + ['_dataValidator', TYPES.DataValidator] ]) bind(TYPES.RServiceDepsSchemaAliase) .toDynamicValue((ctx) => { @@ -105,7 +106,10 @@ module.exports = ({ bind(TYPES.PrepareApiResponse).toConstantValue( bindDepsToFn( prepareApiResponse, - [TYPES.GetREST] + [ + TYPES.GetREST, + TYPES.DataValidator + ] ) ) bind(TYPES.FOREX_SYMBS).toConstantValue(FOREX_SYMBS) diff --git a/workers/loc.api/di/core.deps.js b/workers/loc.api/di/core.deps.js index ad4a406d..db01e483 100644 --- a/workers/loc.api/di/core.deps.js +++ b/workers/loc.api/di/core.deps.js @@ -6,6 +6,7 @@ const TYPES = require('./types') const { bindDepsToFn } = require('./helpers') const loggerFactory = require('../logger') +const dataValidator = require('../data-validator') module.exports = () => { return new ContainerModule((bind) => { @@ -16,5 +17,6 @@ module.exports = () => { [TYPES.CONF] ) }).inSingletonScope() + bind(TYPES.DataValidator).toConstantValue(dataValidator) }) } diff --git a/workers/loc.api/di/types.js b/workers/loc.api/di/types.js index 09b5b67a..74be5ae9 100644 --- a/workers/loc.api/di/types.js +++ b/workers/loc.api/di/types.js @@ -8,6 +8,7 @@ module.exports = { Container: Symbol.for('Container'), LoggerFactory: Symbol.for('LoggerFactory'), Logger: Symbol.for('Logger'), + DataValidator: Symbol.for('DataValidator'), I18next: Symbol.for('I18next'), RService: Symbol.for('RService'), DeflateFac: Symbol.for('DeflateFac'), diff --git a/workers/loc.api/generate-report-file/csv-writer/weighted-averages-report-csv-writer.js b/workers/loc.api/generate-report-file/csv-writer/weighted-averages-report-csv-writer.js index 99288db6..f5411b4c 100644 --- a/workers/loc.api/generate-report-file/csv-writer/weighted-averages-report-csv-writer.js +++ b/workers/loc.api/generate-report-file/csv-writer/weighted-averages-report-csv-writer.js @@ -3,7 +3,9 @@ const { write } = require('../../queue/write-data-to-stream/helpers') - +const { + omitExtraParamFieldsForReportExport +} = require('../helpers') const { streamWriter } = require('./helpers') module.exports = ( @@ -40,7 +42,10 @@ module.exports = ( const { res } = await getDataFromApi({ getData: rService[name].bind(rService), - args, + args: { + ...args, + params: omitExtraParamFieldsForReportExport(params) + }, callerName: 'CSV_WRITER', shouldNotInterrupt: true }) diff --git a/workers/loc.api/generate-report-file/helpers/index.js b/workers/loc.api/generate-report-file/helpers/index.js new file mode 100644 index 00000000..0e86f1b7 --- /dev/null +++ b/workers/loc.api/generate-report-file/helpers/index.js @@ -0,0 +1,9 @@ +'use strict' + +const omitExtraParamFieldsForReportExport = require( + './omit-extra-param-fields-for-report-export' +) + +module.exports = { + omitExtraParamFieldsForReportExport +} diff --git a/workers/loc.api/generate-report-file/helpers/omit-extra-param-fields-for-report-export.js b/workers/loc.api/generate-report-file/helpers/omit-extra-param-fields-for-report-export.js new file mode 100644 index 00000000..a33be354 --- /dev/null +++ b/workers/loc.api/generate-report-file/helpers/omit-extra-param-fields-for-report-export.js @@ -0,0 +1,20 @@ +'use strict' + +const { omit } = require('lib-js-util-base') + +module.exports = (params) => { + return omit(params ?? {}, [ + 'dateFormat', + 'milliseconds', + 'language', + 'isPDFRequired', + 'method', + 'timezone', + 'email', + 'isSignatureRequired', + 'isDeposits', + 'isWithdrawals', + 'isTradingPair', + 'isBaseNameInName' + ]) +} diff --git a/workers/loc.api/generate-report-file/report.file.job.data.js b/workers/loc.api/generate-report-file/report.file.job.data.js index 8037c02f..466cfd5f 100644 --- a/workers/loc.api/generate-report-file/report.file.job.data.js +++ b/workers/loc.api/generate-report-file/report.file.job.data.js @@ -1,9 +1,10 @@ 'use strict' +const { omit } = require('lib-js-util-base') + const { decorateInjectable } = require('../di/utils') const { - checkParams, getReportFileArgs, checkTimeLimit, checkJobAndGetUserData, @@ -16,14 +17,17 @@ const { const depsTypes = (TYPES) => [ TYPES.RService, + TYPES.DataValidator, TYPES.WeightedAveragesReportCsvWriter ] class ReportFileJobData { constructor ( rService, + dataValidator, weightedAveragesReportCsvWriter ) { this.rService = rService + this.dataValidator = dataValidator this.weightedAveragesReportCsvWriter = weightedAveragesReportCsvWriter } @@ -32,7 +36,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -76,7 +83,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -119,7 +129,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForFile', ['symbol']) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_TICKERS_HISTORY_FILE_REQ + ) const { userId, @@ -180,7 +193,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForWalletsFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_WALLETS_FILE_REQ + ) const { userId, @@ -218,7 +234,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -265,7 +284,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForActivePositionsFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_ACTIVE_POSITIONS_FILE_REQ + ) const { userId, @@ -316,7 +338,10 @@ class ReportFileJobData { uInfo ) { const _args = parsePositionsAuditId(args) - checkParams(_args, 'paramsSchemaForPositionsAuditFile', ['id']) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_POSITIONS_AUDIT_FILE_REQ + ) const { userId, @@ -365,7 +390,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForPublicTradesFile', ['symbol']) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_PUBLIC_TRADES_FILE_REQ + ) checkTimeLimit(args) const { @@ -420,7 +448,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForStatusMessagesFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_STATUS_MESSAGES_FILE_REQ + ) const { userId, @@ -460,7 +491,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForCandlesFile', ['symbol']) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_CANDLES_FILE_REQ + ) checkTimeLimit(args) const { @@ -501,7 +535,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_LEDGERS_FILE_REQ + ) const { userId, @@ -546,7 +583,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -589,7 +629,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForOrderTradesFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_ORDER_TRADES_FILE_REQ + ) const { userId, @@ -632,7 +675,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -681,7 +727,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -727,7 +776,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_MOVEMENTS_FILE_REQ + ) const { userId, @@ -770,7 +822,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -816,7 +871,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -864,7 +922,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -913,7 +974,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -950,7 +1014,10 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.COMMON_FILE_REQ + ) const { userId, @@ -988,7 +1055,11 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForMultipleFile', false, true) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_MULTIPLE_FILE_REQ, + { shouldParamsFieldBeChecked: true } + ) const { userId, @@ -1022,7 +1093,7 @@ class ReportFileJobData { { ...args, params: { - ...params, + ...omit(params, ['method']), ...(language && typeof language === 'string' ? { language } : {}), @@ -1052,7 +1123,11 @@ class ReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForWeightedAveragesReportFile', ['symbol']) + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_WEIGHTED_AVERAGES_REPORT_FILE_REQ, + { shouldParamsFieldBeChecked: true } + ) const { userId, @@ -1063,7 +1138,7 @@ class ReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs(args, 'getWeightedAverages') const jobData = { userInfo, diff --git a/workers/loc.api/helpers/get-data-from-api/index.js b/workers/loc.api/helpers/get-data-from-api/index.js index 61ce7c87..d75a2539 100644 --- a/workers/loc.api/helpers/get-data-from-api/index.js +++ b/workers/loc.api/helpers/get-data-from-api/index.js @@ -10,6 +10,9 @@ const { isENetError, isAuthError } = require('../api-errors-testers') +const { + ArgsParamsError +} = require('../../errors') const { calcBackOffAndJitteredDelay, isInterrupted: _isInterrupted, @@ -76,6 +79,10 @@ module.exports = ( break } catch (err) { + if (err instanceof ArgsParamsError) { + throw err + } + if (isUserIsNotMerchantError(err)) { return getEmptyArrRes() } diff --git a/workers/loc.api/helpers/limit-param.helpers.js b/workers/loc.api/helpers/limit-param.helpers.js index 642cf1bd..a540b9b5 100644 --- a/workers/loc.api/helpers/limit-param.helpers.js +++ b/workers/loc.api/helpers/limit-param.helpers.js @@ -65,11 +65,16 @@ const getReportFileArgs = (args, method, extraParams = {}) => { ...args, params: { ...args.params, - ...extraParams, - limit: getMethodLimit({ isMax: true }, method) + ...extraParams } } + if (method === 'getWeightedAverages') { + return reportFileArgs + } + + reportFileArgs.params.limit = getMethodLimit({ isMax: true }, method) + return reportFileArgs } diff --git a/workers/loc.api/helpers/prepare-response/helpers/get-validation-schema-id.js b/workers/loc.api/helpers/prepare-response/helpers/get-validation-schema-id.js new file mode 100644 index 00000000..7d2012f0 --- /dev/null +++ b/workers/loc.api/helpers/prepare-response/helpers/get-validation-schema-id.js @@ -0,0 +1,23 @@ +'use strict' + +const { SCHEMA_IDS } = require('../../../data-validator') + +const PARAMS_SCHEMAS_MAP = { + default: SCHEMA_IDS.COMMON_REQ, + + payInvoiceList: SCHEMA_IDS.GET_PAY_INVOICE_LIST_REQ, + statusMessages: SCHEMA_IDS.GET_STATUS_MESSAGES_REQ, + publicTrades: SCHEMA_IDS.GET_PUBLIC_TRADES_REQ, + positionsAudit: SCHEMA_IDS.GET_POSITIONS_AUDIT_REQ, + orderTrades: SCHEMA_IDS.GET_ORDER_TRADES_REQ, + candles: SCHEMA_IDS.GET_CANDLES_REQ, + ledgers: SCHEMA_IDS.GET_LEDGERS_REQ, + tickersHistory: SCHEMA_IDS.GET_TICKERS_HISTORY_REQ +} + +module.exports = ( + method, + map = PARAMS_SCHEMAS_MAP +) => { + return map?.[method] ?? map.default +} diff --git a/workers/loc.api/helpers/prepare-response/helpers/index.js b/workers/loc.api/helpers/prepare-response/helpers/index.js index 3ec2d445..0b2b812a 100644 --- a/workers/loc.api/helpers/prepare-response/helpers/index.js +++ b/workers/loc.api/helpers/prepare-response/helpers/index.js @@ -2,6 +2,7 @@ const getParamsMap = require('./get-params-map') const getParamsSchemaName = require('./get-params-schema-name') +const getValidationSchemaId = require('./get-validation-schema-id') const omitPrivateModelFields = require('./omit-private-model-fields') const getBfxApiMethodName = require('./get-bfx-api-method-name') const getSymbolsForFiltering = require('./get-symbols-for-filtering') @@ -12,6 +13,7 @@ const isNotContainedSameMts = require('./is-not-contained-same-mts') module.exports = { getParamsMap, getParamsSchemaName, + getValidationSchemaId, omitPrivateModelFields, getBfxApiMethodName, getSymbolsForFiltering, diff --git a/workers/loc.api/helpers/prepare-response/index.js b/workers/loc.api/helpers/prepare-response/index.js index a3817bee..d2dae441 100644 --- a/workers/loc.api/helpers/prepare-response/index.js +++ b/workers/loc.api/helpers/prepare-response/index.js @@ -3,14 +3,13 @@ const { MinLimitParamError } = require('../../errors') const filterResponse = require('../filter-response') -const checkParams = require('../check-params') const checkFilterParams = require('../check-filter-params') const normalizeFilterParams = require('../normalize-filter-params') const prepareSymbolResponse = require('./prepare-symbol-response') const { - getParamsSchemaName, + getValidationSchemaId, omitPrivateModelFields, getBfxApiMethodName, getSymbolsForFiltering, @@ -128,7 +127,8 @@ const prepareResponse = ( } const prepareApiResponse = ( - getREST + getREST, + dataValidator ) => async ( reqArgs, apiMethodName, @@ -137,13 +137,12 @@ const prepareApiResponse = ( const { datePropName, symbPropName, - requireFields, parseFieldsFn, isNotMoreThanInnerMax: _isNotMoreThanInnerMax } = params ?? {} - const schemaName = getParamsSchemaName(apiMethodName) + const schemaId = getValidationSchemaId(apiMethodName) - checkParams(reqArgs, schemaName, requireFields) + await dataValidator.validate(reqArgs, schemaId) const args = normalizeFilterParams(apiMethodName, reqArgs) checkFilterParams(apiMethodName, args) diff --git a/workers/loc.api/queue/write-data-to-stream/helpers.js b/workers/loc.api/queue/write-data-to-stream/helpers.js index 26fdb643..218e1527 100644 --- a/workers/loc.api/queue/write-data-to-stream/helpers.js +++ b/workers/loc.api/queue/write-data-to-stream/helpers.js @@ -169,8 +169,21 @@ const writeMessageToStream = ( processorQueue.emit('progress', 100) } -const setDefaultPrams = (args) => { +const setDefaultParams = (args, method) => { + if (method === 'getWallets') { + args.params.end = args.params.end + ? Math.min(args.params.end, Date.now()) + : Date.now() + + return + } + args.params.notThrowError = true + + if (method === 'getStatusMessages') { + return + } + args.params.end = args.params.end ? Math.min(args.params.end, Date.now()) : Date.now() @@ -213,7 +226,7 @@ const progress = ( module.exports = { writeMessageToStream, - setDefaultPrams, + setDefaultParams, filterMovementsByAmount, write, progress diff --git a/workers/loc.api/queue/write-data-to-stream/index.js b/workers/loc.api/queue/write-data-to-stream/index.js index 1f9bd2e8..252c84c1 100644 --- a/workers/loc.api/queue/write-data-to-stream/index.js +++ b/workers/loc.api/queue/write-data-to-stream/index.js @@ -2,9 +2,12 @@ const { cloneDeep } = require('lib-js-util-base') +const { + omitExtraParamFieldsForReportExport +} = require('../../generate-report-file/helpers') const { writeMessageToStream, - setDefaultPrams, + setDefaultParams, filterMovementsByAmount, write, progress @@ -33,9 +36,12 @@ module.exports = ( const propName = jobData.propNameForPagination const formatSettings = jobData.formatSettings - const _args = cloneDeep(jobData.args) + const _args = { + auth: { ...jobData?.args?.auth }, + params: omitExtraParamFieldsForReportExport(jobData?.args?.params) + } - setDefaultPrams(_args) + setDefaultParams(_args, method) const currIterationArgs = cloneDeep(_args) const getData = rService[method].bind(rService) diff --git a/workers/loc.api/service.report.js b/workers/loc.api/service.report.js index d6171020..5ac9aae9 100644 --- a/workers/loc.api/service.report.js +++ b/workers/loc.api/service.report.js @@ -3,7 +3,6 @@ const { Api } = require('bfx-wrk-api') const { - checkParams, parseFields, parseLoginsExtraDataFields, accountCache, @@ -312,7 +311,6 @@ class ReportService extends Api { 'tickersHistory', { datePropName: 'mtsUpdate', - requireFields: ['symbol'], isNotMoreThanInnerMax } ) @@ -364,7 +362,10 @@ class ReportService extends Api { getWallets (space, args, cb) { return this._responder(async () => { - checkParams(args, 'paramsSchemaForWallets') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_WALLETS_REQ + ) const rest = this._getREST(args.auth, { interrupter: args?.interrupter @@ -564,7 +565,10 @@ class ReportService extends Api { getMovementInfo (space, args, cb) { return this._responder(async () => { - checkParams(args, 'paramsSchemaForMovementInfo', ['id']) + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_MOVEMENT_INFO_REQ + ) const { auth, params, interrupter } = args ?? {} const rest = this._getREST(auth, { interrupter }) @@ -673,7 +677,10 @@ class ReportService extends Api { getWeightedAveragesReport (space, args, cb) { return this._responder(async () => { - checkParams(args, 'paramsSchemaForWeightedAveragesReportApi', ['symbol']) + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_WEIGHTED_AVERAGES_REPORT_REQ + ) return this._weightedAveragesReport .getWeightedAveragesReport(args)