diff --git a/bfx-report-ui b/bfx-report-ui index 43b135762..081912542 160000 --- a/bfx-report-ui +++ b/bfx-report-ui @@ -1 +1 @@ -Subproject commit 43b135762afa0ef020c65f23dde8793b757ee380 +Subproject commit 08191254267cbe608a35b8ec160edab4cd8fe4ea diff --git a/package-lock.json b/package-lock.json index e99f8f285..91bce0a31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bfx-reports-framework", - "version": "4.22.4", + "version": "4.22.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bfx-reports-framework", - "version": "4.22.4", + "version": "4.22.5", "license": "Apache-2.0", "dependencies": { "better-npm-run": "0.1.1", @@ -1395,8 +1395,8 @@ } }, "node_modules/bfx-report": { - "version": "4.12.5", - "resolved": "git+ssh://git@github.com/bitfinexcom/bfx-report.git#f77372272c87681e3d6e73182c4b2a9fb2d3f5ff", + "version": "4.12.6", + "resolved": "git+ssh://git@github.com/bitfinexcom/bfx-report.git#19609fc1681730017c6d1b96f5b044d08a82c5bd", "license": "Apache-2.0", "dependencies": { "ajv": "8.17.1", diff --git a/package.json b/package.json index 80a69c432..76fcedcef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bfx-reports-framework", - "version": "4.22.4", + "version": "4.22.5", "description": "Bitfinex reports framework", "main": "worker.js", "license": "Apache-2.0", diff --git a/workers/api.framework.report.wrk.js b/workers/api.framework.report.wrk.js index d6a05eaab..0d6272125 100644 --- a/workers/api.framework.report.wrk.js +++ b/workers/api.framework.report.wrk.js @@ -41,8 +41,21 @@ const { const appDeps = require('./loc.api/di/app.deps') const TYPES = require('./loc.api/di/types') +const fwDataValidator = require('./loc.api/data-validator') class WrkReportFrameWorkApi extends WrkReportServiceApi { + loadCoreDeps (...args) { + super.loadCoreDeps(...args) + + this.container + .get(TYPES.DataValidator) + .reinit({ + schemaNames: fwDataValidator.SCHEMA_NAMES, + schemaIds: fwDataValidator.SCHEMA_IDS, + schemas: fwDataValidator.schemas + }) + } + loadAppDeps (...args) { super.loadAppDeps(...args) diff --git a/workers/loc.api/data-validator/index.js b/workers/loc.api/data-validator/index.js new file mode 100644 index 000000000..e78004d22 --- /dev/null +++ b/workers/loc.api/data-validator/index.js @@ -0,0 +1,12 @@ +'use strict' + +const SCHEMA_NAMES = require('./schema.names') +const SCHEMA_IDS = require('./schema.ids') +const schemas = require('./schemas') + +module.exports = { + SCHEMA_NAMES, + SCHEMA_IDS, + + schemas +} 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 000000000..5a7bef1de --- /dev/null +++ b/workers/loc.api/data-validator/schema.ids.js @@ -0,0 +1,8 @@ +'use strict' + +const SCHEMA_NAMES = require('./schema.names') +const { + getSchemaIds +} = require('bfx-report/workers/loc.api/data-validator/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 000000000..fc393432b --- /dev/null +++ b/workers/loc.api/data-validator/schema.names.js @@ -0,0 +1,35 @@ +'use strict' + +module.exports = { + FW_DEFS: 'fwDefs', + + CREATE_SUB_ACCOUNT_REQ: 'createSubAccountReq', + UPDATE_SUB_ACCOUNT_REQ: 'updateSubAccountReq', + INTERRUPT_OPERATIONS_REQ: 'interruptOperationsReq', + EDIT_ALL_PUBLIC_COLLS_CONFS_REQ: 'editAllPublicCollsConfsReq', + + FW_GET_CANDLES_REQ: 'fwGetCandlesReq', + GET_BALANCE_HISTORY_REQ: 'getBalanceHistoryReq', + GET_WIN_LOSS_REQ: 'getWinLossReq', + GET_POSITIONS_SNAPSHOT_REQ: 'getPositionsSnapshotReq', + GET_FULL_SNAPSHOT_REPORT_REQ: 'getFullSnapshotReportReq', + GET_FULL_TAX_REPORT_REQ: 'getFullTaxReportReq', + GET_TRANSACTION_TAX_REPORT_REQ: 'getTransactionTaxReportReq', + GET_TRADED_VOLUME_REQ: 'getTradedVolumeReq', + GET_TOTAL_FEES_REPORT_REQ: 'getTotalFeesReportReq', + GET_PERFORMING_LOAN_REQ: 'getPerformingLoanReq', + GET_WIN_LOSS_VS_ACCOUNT_BALANCE_REQ: 'getWinLossVSAccountBalanceReq', + GET_SUMMARY_BY_ASSET_REQ: 'getSummaryByAssetReq', + + FW_GET_CANDLES_FILE_REQ: 'fwGetCandlesFileReq', + GET_BALANCE_HISTORY_FILE_REQ: 'getBalanceHistoryFileReq', + GET_WIN_LOSS_FILE_REQ: 'getWinLossFileReq', + GET_POSITIONS_SNAPSHOT_FILE_REQ: 'getPositionsSnapshotFileReq', + GET_FULL_SNAPSHOT_REPORT_FILE_REQ: 'getFullSnapshotReportFileReq', + GET_FULL_TAX_REPORT_FILE_REQ: 'getFullTaxReportFileReq', + GET_TRANSACTION_TAX_REPORT_FILE_REQ: 'getTransactionTaxReportFileReq', + GET_TRADED_VOLUME_FILE_REQ: 'getTradedVolumeFileReq', + GET_TOTAL_FEES_REPORT_FILE_REQ: 'getTotalFeesReportFileReq', + GET_PERFORMING_LOAN_FILE_REQ: 'getPerformingLoanFileReq', + GET_WIN_LOSS_VS_ACCOUNT_BALANCE_FILE_REQ: 'getWinLossVSAccountBalanceFileReq' +} diff --git a/workers/loc.api/data-validator/schemas/createSubAccountReq.js b/workers/loc.api/data-validator/schemas/createSubAccountReq.js new file mode 100644 index 000000000..8d86e5f48 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/createSubAccountReq.js @@ -0,0 +1,21 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.CREATE_SUB_ACCOUNT_REQ, + type: 'object', + additionalProperties: false, + required: ['subAccountApiKeys'], + properties: { + subAccountApiKeys: { + $ref: 'fwDefs#/definitions/subAccountApiKeys' + }, + subAccountPassword: { + $ref: 'fwDefs#/definitions/password' + }, + localUsername: { + type: 'string' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/editAllPublicCollsConfsReq.js b/workers/loc.api/data-validator/schemas/editAllPublicCollsConfsReq.js new file mode 100644 index 000000000..ab699695b --- /dev/null +++ b/workers/loc.api/data-validator/schemas/editAllPublicCollsConfsReq.js @@ -0,0 +1,78 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.EDIT_ALL_PUBLIC_COLLS_CONFS_REQ, + type: 'object', + additionalProperties: false, + properties: { + candlesConf: { + type: 'array', + items: { + type: 'object', + additionalProperties: false, + required: ['symbol', 'start', 'timeframe'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + symbol: { + $ref: 'defs#/definitions/strSymbol' + }, + timeframe: { + $ref: 'defs#/definitions/candleTimeframe' + } + } + } + }, + statusMessagesConf: { + type: 'array', + items: { + type: 'object', + additionalProperties: false, + required: ['symbol', 'start'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + symbol: { + $ref: 'defs#/definitions/strSymbol' + } + } + } + }, + tickersHistoryConf: { + type: 'array', + items: { + type: 'object', + additionalProperties: false, + required: ['symbol', 'start'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + symbol: { + $ref: 'defs#/definitions/strSymbol' + } + } + } + }, + publicTradesConf: { + type: 'array', + items: { + type: 'object', + additionalProperties: false, + required: ['symbol', 'start'], + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + symbol: { + $ref: 'defs#/definitions/strSymbol' + } + } + } + } + } +} diff --git a/workers/loc.api/data-validator/schemas/fwDefs.js b/workers/loc.api/data-validator/schemas/fwDefs.js new file mode 100644 index 000000000..86978adfe --- /dev/null +++ b/workers/loc.api/data-validator/schemas/fwDefs.js @@ -0,0 +1,92 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.FW_DEFS, + definitions: { + timeframe: { + type: 'string', + enum: [ + 'day', + 'week', + 'month', + 'year' + ] + }, + isUnrealizedProfitExcluded: { + type: 'boolean' + }, + isVSPrevDayBalance: { + type: 'boolean' + }, + apiKey: { + type: 'string' + }, + apiSecret: { + type: 'string' + }, + token: { + type: 'string' + }, + password: { + type: 'string' + }, + subAccountApiKeys: { + type: 'array', + minItems: 1, + maxItems: 20, + items: { + type: 'object', + oneOf: [ + { + additionalProperties: false, + properties: { + apiKey: { + $ref: '#/definitions/apiKey' + }, + apiSecret: { + $ref: '#/definitions/apiSecret' + } + } + }, + { + additionalProperties: false, + properties: { + token: { + $ref: '#/definitions/token' + } + } + }, + { + additionalProperties: false, + properties: { + email: { + $ref: 'defs#/definitions/email' + }, + password: { + $ref: '#/definitions/password' + } + } + } + ] + } + }, + strategy: { + type: 'string', + enum: [ + 'FIFO', + 'LIFO' + ] + }, + shouldFeesBeDeducted: { + type: 'boolean' + }, + isTradingFees: { + type: 'boolean' + }, + isFundingFees: { + type: 'boolean' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/fwGetCandlesFileReq.js b/workers/loc.api/data-validator/schemas/fwGetCandlesFileReq.js new file mode 100644 index 000000000..8af9ab222 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/fwGetCandlesFileReq.js @@ -0,0 +1,59 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.FW_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: { + $ref: 'defs#/definitions/candleTimeframe' + }, + section: { + type: 'string', + enum: ['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/fwGetCandlesReq.js b/workers/loc.api/data-validator/schemas/fwGetCandlesReq.js new file mode 100644 index 000000000..cec0ff58c --- /dev/null +++ b/workers/loc.api/data-validator/schemas/fwGetCandlesReq.js @@ -0,0 +1,47 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.FW_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: { + $ref: 'defs#/definitions/candleTimeframe' + }, + section: { + type: 'string', + enum: ['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/getBalanceHistoryFileReq.js b/workers/loc.api/data-validator/schemas/getBalanceHistoryFileReq.js new file mode 100644 index 000000000..1f2f2fb08 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getBalanceHistoryFileReq.js @@ -0,0 +1,45 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_BALANCE_HISTORY_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + isUnrealizedProfitExcluded: { + $ref: 'fwDefs#/definitions/isUnrealizedProfitExcluded' + }, + + 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/getBalanceHistoryReq.js b/workers/loc.api/data-validator/schemas/getBalanceHistoryReq.js new file mode 100644 index 000000000..4b50d89db --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getBalanceHistoryReq.js @@ -0,0 +1,23 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_BALANCE_HISTORY_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + isUnrealizedProfitExcluded: { + $ref: 'fwDefs#/definitions/isUnrealizedProfitExcluded' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getFullSnapshotReportFileReq.js b/workers/loc.api/data-validator/schemas/getFullSnapshotReportFileReq.js new file mode 100644 index 000000000..0af70a377 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getFullSnapshotReportFileReq.js @@ -0,0 +1,42 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_FULL_SNAPSHOT_REPORT_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + end: { + $ref: 'defs#/definitions/end' + }, + isStartSnapshot: { + type: 'boolean' + }, + isEndSnapshot: { + 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/getFullSnapshotReportReq.js b/workers/loc.api/data-validator/schemas/getFullSnapshotReportReq.js new file mode 100644 index 000000000..39a2c057a --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getFullSnapshotReportReq.js @@ -0,0 +1,14 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_FULL_SNAPSHOT_REPORT_REQ, + type: 'object', + additionalProperties: false, + properties: { + end: { + $ref: 'defs#/definitions/end' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getFullTaxReportFileReq.js b/workers/loc.api/data-validator/schemas/getFullTaxReportFileReq.js new file mode 100644 index 000000000..97f2938f6 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getFullTaxReportFileReq.js @@ -0,0 +1,45 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_FULL_TAX_REPORT_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + isStartSnapshot: { + type: 'boolean' + }, + isEndSnapshot: { + 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/getFullTaxReportReq.js b/workers/loc.api/data-validator/schemas/getFullTaxReportReq.js new file mode 100644 index 000000000..2d48c7005 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getFullTaxReportReq.js @@ -0,0 +1,17 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_FULL_TAX_REPORT_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getPerformingLoanFileReq.js b/workers/loc.api/data-validator/schemas/getPerformingLoanFileReq.js new file mode 100644 index 000000000..07a981a09 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPerformingLoanFileReq.js @@ -0,0 +1,45 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_PERFORMING_LOAN_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + symbol: { + $ref: 'defs#/definitions/symbol' + }, + + 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/getPerformingLoanReq.js b/workers/loc.api/data-validator/schemas/getPerformingLoanReq.js new file mode 100644 index 000000000..a6f625386 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPerformingLoanReq.js @@ -0,0 +1,23 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_PERFORMING_LOAN_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + symbol: { + $ref: 'defs#/definitions/symbol' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getPositionsSnapshotFileReq.js b/workers/loc.api/data-validator/schemas/getPositionsSnapshotFileReq.js new file mode 100644 index 000000000..da85d4a9b --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPositionsSnapshotFileReq.js @@ -0,0 +1,36 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_POSITIONS_SNAPSHOT_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/getPositionsSnapshotReq.js b/workers/loc.api/data-validator/schemas/getPositionsSnapshotReq.js new file mode 100644 index 000000000..9f55e7066 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getPositionsSnapshotReq.js @@ -0,0 +1,14 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_POSITIONS_SNAPSHOT_REQ, + type: 'object', + additionalProperties: false, + properties: { + end: { + $ref: 'defs#/definitions/end' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getSummaryByAssetReq.js b/workers/loc.api/data-validator/schemas/getSummaryByAssetReq.js new file mode 100644 index 000000000..fbb0b21d1 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getSummaryByAssetReq.js @@ -0,0 +1,17 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_SUMMARY_BY_ASSET_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getTotalFeesReportFileReq.js b/workers/loc.api/data-validator/schemas/getTotalFeesReportFileReq.js new file mode 100644 index 000000000..374b2ceab --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTotalFeesReportFileReq.js @@ -0,0 +1,51 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TOTAL_FEES_REPORT_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + symbol: { + $ref: 'defs#/definitions/symbol' + }, + isTradingFees: { + $ref: 'fwDefs#/definitions/isTradingFees' + }, + isFundingFees: { + $ref: 'fwDefs#/definitions/isFundingFees' + }, + + 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/getTotalFeesReportReq.js b/workers/loc.api/data-validator/schemas/getTotalFeesReportReq.js new file mode 100644 index 000000000..42e829940 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTotalFeesReportReq.js @@ -0,0 +1,29 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TOTAL_FEES_REPORT_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + symbol: { + $ref: 'defs#/definitions/symbol' + }, + isTradingFees: { + $ref: 'fwDefs#/definitions/isTradingFees' + }, + isFundingFees: { + $ref: 'fwDefs#/definitions/isFundingFees' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getTradedVolumeFileReq.js b/workers/loc.api/data-validator/schemas/getTradedVolumeFileReq.js new file mode 100644 index 000000000..9726fddd7 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTradedVolumeFileReq.js @@ -0,0 +1,45 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TRADED_VOLUME_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + symbol: { + $ref: 'defs#/definitions/symbol' + }, + + 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/getTradedVolumeReq.js b/workers/loc.api/data-validator/schemas/getTradedVolumeReq.js new file mode 100644 index 000000000..b06edd1ba --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTradedVolumeReq.js @@ -0,0 +1,23 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TRADED_VOLUME_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + symbol: { + $ref: 'defs#/definitions/symbol' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getTransactionTaxReportFileReq.js b/workers/loc.api/data-validator/schemas/getTransactionTaxReportFileReq.js new file mode 100644 index 000000000..31d8db87d --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTransactionTaxReportFileReq.js @@ -0,0 +1,45 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TRANSACTION_TAX_REPORT_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + strategy: { + $ref: 'fwDefs#/definitions/strategy' + }, + shouldFeesBeDeducted: { + $ref: 'fwDefs#/definitions/shouldFeesBeDeducted' + }, + + 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/getTransactionTaxReportReq.js b/workers/loc.api/data-validator/schemas/getTransactionTaxReportReq.js new file mode 100644 index 000000000..db2a638fe --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getTransactionTaxReportReq.js @@ -0,0 +1,23 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_TRANSACTION_TAX_REPORT_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + strategy: { + $ref: 'fwDefs#/definitions/strategy' + }, + shouldFeesBeDeducted: { + $ref: 'fwDefs#/definitions/shouldFeesBeDeducted' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getWinLossFileReq.js b/workers/loc.api/data-validator/schemas/getWinLossFileReq.js new file mode 100644 index 000000000..84fb0a12a --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWinLossFileReq.js @@ -0,0 +1,45 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WIN_LOSS_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + isUnrealizedProfitExcluded: { + $ref: 'fwDefs#/definitions/isUnrealizedProfitExcluded' + }, + + 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/getWinLossReq.js b/workers/loc.api/data-validator/schemas/getWinLossReq.js new file mode 100644 index 000000000..e80cec81b --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWinLossReq.js @@ -0,0 +1,23 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WIN_LOSS_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + isUnrealizedProfitExcluded: { + $ref: 'fwDefs#/definitions/isUnrealizedProfitExcluded' + } + } +} diff --git a/workers/loc.api/data-validator/schemas/getWinLossVSAccountBalanceFileReq.js b/workers/loc.api/data-validator/schemas/getWinLossVSAccountBalanceFileReq.js new file mode 100644 index 000000000..fd0262c82 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWinLossVSAccountBalanceFileReq.js @@ -0,0 +1,48 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WIN_LOSS_VS_ACCOUNT_BALANCE_FILE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + isUnrealizedProfitExcluded: { + $ref: 'fwDefs#/definitions/isUnrealizedProfitExcluded' + }, + isVSPrevDayBalance: { + $ref: 'fwDefs#/definitions/isVSPrevDayBalance' + }, + + 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/getWinLossVSAccountBalanceReq.js b/workers/loc.api/data-validator/schemas/getWinLossVSAccountBalanceReq.js new file mode 100644 index 000000000..a9a7783a0 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/getWinLossVSAccountBalanceReq.js @@ -0,0 +1,26 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.GET_WIN_LOSS_VS_ACCOUNT_BALANCE_REQ, + type: 'object', + additionalProperties: false, + properties: { + start: { + $ref: 'defs#/definitions/start' + }, + end: { + $ref: 'defs#/definitions/end' + }, + timeframe: { + $ref: 'fwDefs#/definitions/timeframe' + }, + isUnrealizedProfitExcluded: { + $ref: 'fwDefs#/definitions/isUnrealizedProfitExcluded' + }, + isVSPrevDayBalance: { + $ref: 'fwDefs#/definitions/isVSPrevDayBalance' + } + } +} 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 000000000..33226d395 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/index.js @@ -0,0 +1,11 @@ +'use strict' + +const SCHEMA_NAMES = require('../schema.names') +const { + requireSchemas +} = require('bfx-report/workers/loc.api/data-validator/helpers') + +module.exports = requireSchemas( + SCHEMA_NAMES, + __dirname +) diff --git a/workers/loc.api/data-validator/schemas/interruptOperationsReq.js b/workers/loc.api/data-validator/schemas/interruptOperationsReq.js new file mode 100644 index 000000000..fda3f8d10 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/interruptOperationsReq.js @@ -0,0 +1,22 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.INTERRUPT_OPERATIONS_REQ, + type: 'object', + additionalProperties: false, + required: ['names'], + properties: { + names: { + type: 'array', + minItems: 1, + items: { + type: 'string', + enum: [ + 'TRX_TAX_REPORT_INTERRUPTER' + ] + } + } + } +} diff --git a/workers/loc.api/data-validator/schemas/updateSubAccountReq.js b/workers/loc.api/data-validator/schemas/updateSubAccountReq.js new file mode 100644 index 000000000..e5edd4b46 --- /dev/null +++ b/workers/loc.api/data-validator/schemas/updateSubAccountReq.js @@ -0,0 +1,28 @@ +'use strict' + +const SCHEMA_IDS = require('../schema.ids') + +module.exports = { + $id: SCHEMA_IDS.UPDATE_SUB_ACCOUNT_REQ, + type: 'object', + additionalProperties: false, + properties: { + addingSubUsers: { + $ref: 'fwDefs#/definitions/subAccountApiKeys' + }, + removingSubUsersByEmails: { + type: 'array', + minItems: 1, + maxItems: 20, + items: { + type: 'object', + additionalProperties: false, + properties: { + email: { + $ref: 'defs#/definitions/email' + } + } + } + } + } +} diff --git a/workers/loc.api/generate-report-file/csv-writer/full-snapshot-report-csv-writer.js b/workers/loc.api/generate-report-file/csv-writer/full-snapshot-report-csv-writer.js index 9bc1fc10a..2df1bd816 100644 --- a/workers/loc.api/generate-report-file/csv-writer/full-snapshot-report-csv-writer.js +++ b/workers/loc.api/generate-report-file/csv-writer/full-snapshot-report-csv-writer.js @@ -6,6 +6,9 @@ const { const { streamWriter } = require('bfx-report/workers/loc.api/generate-report-file/csv-writer/helpers') +const { + omitExtraParamFieldsForReportExport +} = require('bfx-report/workers/loc.api/generate-report-file/helpers') module.exports = ( rService, @@ -16,17 +19,15 @@ module.exports = ( ) => { const queue = rService.ctx.lokue_aggregator.q const { - args: _args, + args, columnsCsv, formatSettings, name - } = { ...jobData } - const { params: _params } = { ..._args } + } = jobData ?? {} const params = { end: Date.now(), - ..._params + ...args?.params } - const args = { ..._args, params } queue.emit('progress', 0) @@ -46,7 +47,10 @@ module.exports = ( const res = await getDataFromApi({ getData: rService[name].bind(rService), - args, + args: { + ...args, + params: omitExtraParamFieldsForReportExport(params) + }, callerName: 'REPORT_FILE_WRITER', shouldNotInterrupt: true }) diff --git a/workers/loc.api/generate-report-file/csv-writer/full-tax-report-csv-writer.js b/workers/loc.api/generate-report-file/csv-writer/full-tax-report-csv-writer.js index 15578c0e5..0d242ece8 100644 --- a/workers/loc.api/generate-report-file/csv-writer/full-tax-report-csv-writer.js +++ b/workers/loc.api/generate-report-file/csv-writer/full-tax-report-csv-writer.js @@ -6,6 +6,9 @@ const { const { streamWriter } = require('bfx-report/workers/loc.api/generate-report-file/csv-writer/helpers') +const { + omitExtraParamFieldsForReportExport +} = require('bfx-report/workers/loc.api/generate-report-file/helpers') module.exports = ( rService, @@ -16,18 +19,16 @@ module.exports = ( ) => { const queue = rService.ctx.lokue_aggregator.q const { - args: _args, + args, columnsCsv, formatSettings, name } = { ...jobData } - const { params: _params } = { ..._args } const params = { start: 0, end: Date.now(), - ..._params + ...args?.params } - const args = { ..._args, params } queue.emit('progress', 0) @@ -47,7 +48,10 @@ module.exports = ( const res = await getDataFromApi({ getData: rService[name].bind(rService), - args, + args: { + ...args, + params: omitExtraParamFieldsForReportExport(params) + }, callerName: 'REPORT_FILE_WRITER', shouldNotInterrupt: true }) diff --git a/workers/loc.api/generate-report-file/csv-writer/transaction-tax-report-csv-writer.js b/workers/loc.api/generate-report-file/csv-writer/transaction-tax-report-csv-writer.js index b97671b50..cd6fbdf50 100644 --- a/workers/loc.api/generate-report-file/csv-writer/transaction-tax-report-csv-writer.js +++ b/workers/loc.api/generate-report-file/csv-writer/transaction-tax-report-csv-writer.js @@ -9,6 +9,9 @@ const { const TRANSLATION_NAMESPACES = require( 'bfx-report/workers/loc.api/i18next/translation.namespaces' ) +const { + omitExtraParamFieldsForReportExport +} = require('bfx-report/workers/loc.api/generate-report-file/helpers') module.exports = ( rService, @@ -20,18 +23,16 @@ module.exports = ( ) => { const queue = rService.ctx.lokue_aggregator.q const { - args: _args, + args, columnsCsv, formatSettings, name } = { ...jobData } - const { params: _params } = { ..._args } const params = { start: 0, end: Date.now(), - ..._params + ...args?.params } - const args = { ..._args, params } const { language } = params ?? queue.emit('progress', 0) @@ -52,7 +53,10 @@ module.exports = ( const res = await getDataFromApi({ getData: rService[name].bind(rService), - args, + args: { + ...args, + params: omitExtraParamFieldsForReportExport(params) + }, callerName: 'REPORT_FILE_WRITER', shouldNotInterrupt: true }) 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 74332f3b7..0fcdb77df 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 @@ -11,7 +11,6 @@ const { } = require('bfx-report/workers/loc.api/helpers') const { - checkParams, getDateString } = require('../helpers') const TEMPLATE_FILE_NAMES = require('./pdf-writer/template-file-names') @@ -138,7 +137,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForBalanceHistoryFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_BALANCE_HISTORY_FILE_REQ + ) const { userId, @@ -149,7 +151,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const jobData = { userInfo, @@ -175,7 +180,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForWinLossFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_WIN_LOSS_FILE_REQ + ) const { userId, @@ -186,7 +194,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const jobData = { userInfo, @@ -212,7 +223,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForPositionsSnapshotFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_POSITIONS_SNAPSHOT_FILE_REQ + ) const { userId, @@ -223,7 +237,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const jobData = { userInfo, @@ -263,7 +280,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo, opts ) { - checkParams(args, 'paramsSchemaForFullSnapshotReportFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_FULL_SNAPSHOT_REPORT_FILE_REQ + ) const { userId, @@ -307,9 +327,14 @@ class ReportFileJobData extends BaseReportFileJobData { : `${uName}full-snapshot-report_TO_${endDate}` const reportFileArgs = getReportFileArgs( - args, - null, - { isBaseNameInName: true } + { + ...args, + params: omit(params, ['isStartSnapshot', 'isEndSnapshot']) + }, + { + isLimitUnused: true, + extraParams: { isBaseNameInName: true } + } ) const jobData = { @@ -432,7 +457,10 @@ class ReportFileJobData extends BaseReportFileJobData { ) } - checkParams(args, 'paramsSchemaForFullTaxReportFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_FULL_TAX_REPORT_FILE_REQ + ) const { userId, @@ -444,9 +472,14 @@ class ReportFileJobData extends BaseReportFileJobData { ) const reportFileArgs = getReportFileArgs( - args, - null, - { isBaseNameInName: true } + { + ...args, + params: omit(params, ['isStartSnapshot', 'isEndSnapshot']) + }, + { + isLimitUnused: true, + extraParams: { isBaseNameInName: true } + } ) const jobData = { @@ -538,7 +571,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForTransactionTaxReportFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_TRANSACTION_TAX_REPORT_FILE_REQ + ) const { userId, @@ -549,7 +585,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const jobData = { userInfo, @@ -590,7 +629,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForTradedVolumeFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_TRADED_VOLUME_FILE_REQ + ) const { userId, @@ -601,7 +643,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const jobData = { userInfo, @@ -627,7 +672,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForTotalFeesReportFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_TOTAL_FEES_REPORT_FILE_REQ + ) const { userId, @@ -638,7 +686,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const jobData = { userInfo, @@ -665,7 +716,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForPerformingLoanFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_PERFORMING_LOAN_FILE_REQ + ) const { userId, @@ -676,7 +730,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const jobData = { userInfo, @@ -704,7 +761,10 @@ class ReportFileJobData extends BaseReportFileJobData { uId, uInfo ) { - checkParams(args, 'paramsSchemaForWinLossVSAccountBalanceFile') + this.dataValidator.validate( + args, + this.dataValidator.SCHEMA_IDS.GET_WIN_LOSS_VS_ACCOUNT_BALANCE_FILE_REQ + ) const { userId, @@ -715,7 +775,10 @@ class ReportFileJobData extends BaseReportFileJobData { uInfo ) - const reportFileArgs = getReportFileArgs(args) + const reportFileArgs = getReportFileArgs( + args, + { isLimitUnused: true } + ) const suffix = args?.params?.isVSPrevDayBalance ? 'balance' : 'deposits' diff --git a/workers/loc.api/helpers/check-params.js b/workers/loc.api/helpers/check-params.js deleted file mode 100644 index c90ddf5dc..000000000 --- a/workers/loc.api/helpers/check-params.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict' - -const { - checkParams: checkParamsBase -} = require('bfx-report/workers/loc.api/helpers') - -const schema = require('./schema') - -module.exports = ( - args, - schemaName = 'paramsSchemaForFile', - requireFields = [], - checkParamsField = false -) => { - checkParamsBase( - args, - schemaName, - requireFields, - checkParamsField, - schema - ) -} diff --git a/workers/loc.api/helpers/index.js b/workers/loc.api/helpers/index.js index 528f54f6f..299f6680d 100644 --- a/workers/loc.api/helpers/index.js +++ b/workers/loc.api/helpers/index.js @@ -1,6 +1,5 @@ 'use strict' -const checkParams = require('./check-params') const { checkParamsAuth, tryParseJSON, @@ -21,7 +20,6 @@ const { } = require('./sub-account-auth') module.exports = { - checkParams, checkParamsAuth, tryParseJSON, collObjToArr, diff --git a/workers/loc.api/helpers/schema.js b/workers/loc.api/helpers/schema.js deleted file mode 100644 index 53083659a..000000000 --- a/workers/loc.api/helpers/schema.js +++ /dev/null @@ -1,474 +0,0 @@ -'use strict' - -const { cloneDeep } = require('lib-js-util-base') - -const { - paramsSchemaForFile, - paramsSchemaForCandlesApi: baseParamsSchemaForCandlesApi -} = require('bfx-report/workers/loc.api/helpers/schema') - -const subAccountApiKeys = { - type: 'array', - minItems: 1, - maxItems: 300, - items: { - type: 'object', - properties: { - apiKey: { type: 'string' }, - apiSecret: { type: 'string' }, - token: { type: 'string' }, - email: { type: 'string' } - } - } -} - -const paramsSchemaForCreateSubAccount = { - type: 'object', - required: ['subAccountApiKeys'], - properties: { - subAccountApiKeys, - subAccountPassword: { type: 'string' } - } -} - -const paramsSchemaForUpdateSubAccount = { - type: 'object', - properties: { - addingSubUsers: subAccountApiKeys, - removingSubUsersByEmails: { - type: 'array', - minItems: 1, - maxItems: 300, - items: { - type: 'object', - properties: { - email: { type: 'string' } - } - } - } - } -} - -const paramsSchemaForInterruptOperations = { - type: 'object', - properties: { - names: { - type: 'array', - minItems: 1, - items: { - type: 'string', - enum: [ - 'TRX_TAX_REPORT_INTERRUPTER' - ] - } - } - } -} - -const paramsSchemaForCandlesApi = { - ...cloneDeep(baseParamsSchemaForCandlesApi), - properties: { - ...cloneDeep(baseParamsSchemaForCandlesApi.properties), - section: { - type: 'string', - enum: ['hist'] - } - } -} - -const paramsSchemaForEditAllPublicCollsConfs = { - type: 'object', - properties: { - candlesConf: { - type: 'array', - items: { - type: 'object', - required: ['symbol', 'start', 'timeframe'], - properties: { - start: { type: 'integer' }, - symbol: { type: 'string' }, - timeframe: { type: 'string' } - } - } - }, - statusMessagesConf: { - type: 'array', - items: { - type: 'object', - required: ['symbol', 'start'], - properties: { - start: { type: 'integer' }, - symbol: { type: 'string' } - } - } - }, - tickersHistoryConf: { - type: 'array', - items: { - type: 'object', - required: ['symbol', 'start'], - properties: { - start: { type: 'integer' }, - symbol: { type: 'string' } - } - } - }, - publicTradesConf: { - type: 'array', - items: { - type: 'object', - required: ['symbol', 'start'], - properties: { - start: { type: 'integer' }, - symbol: { type: 'string' } - } - } - } - } -} - -const paramsSchemaForBalanceHistoryApi = { - type: 'object', - properties: { - timeframe: { - type: 'string', - enum: [ - 'day', - 'week', - 'month', - 'year' - ] - }, - start: { - type: 'integer' - }, - end: { - type: 'integer' - } - } -} - -const paramsSchemaForPositionsSnapshotApi = { - type: 'object', - properties: { - end: { - type: 'integer' - } - } -} - -const paramsSchemaForFullSnapshotReportApi = { - type: 'object', - properties: { - end: { - type: 'integer' - } - } -} - -const paramsSchemaForFullTaxReportApi = { - type: 'object', - properties: { - end: { - type: 'integer' - }, - start: { - type: 'integer' - } - } -} - -const paramsSchemaForTransactionTaxReportApi = { - type: 'object', - properties: { - end: { - type: 'integer' - }, - start: { - type: 'integer' - }, - strategy: { - type: 'string', - enum: [ - 'FIFO', - 'LIFO' - ] - }, - shouldFeesBeDeducted: { - type: 'boolean' - } - } -} - -const paramsSchemaForWinLossApi = { - type: 'object', - properties: { - timeframe: { - type: 'string', - enum: [ - 'day', - 'week', - 'month', - 'year' - ] - }, - start: { - type: 'integer' - }, - end: { - type: 'integer' - }, - isUnrealizedProfitExcluded: { - type: 'boolean' - } - } -} - -const paramsSchemaForWinLossVSAccountBalanceApi = { - type: 'object', - properties: { - timeframe: { - type: 'string', - enum: [ - 'day', - 'week', - 'month', - 'year' - ] - }, - start: { - type: 'integer' - }, - end: { - type: 'integer' - } - } -} - -const paramsSchemaForTradedVolumeApi = { - type: 'object', - properties: { - timeframe: { - type: 'string', - enum: [ - 'day', - 'week', - 'month', - 'year' - ] - }, - start: { - type: 'integer' - }, - end: { - type: 'integer' - }, - symbol: { - type: ['string', 'array'] - } - } -} - -const paramsSchemaForTotalFeesReportApi = { - type: 'object', - properties: { - timeframe: { - type: 'string', - enum: [ - 'day', - 'week', - 'month', - 'year' - ] - }, - start: { - type: 'integer' - }, - end: { - type: 'integer' - }, - symbol: { - type: ['string', 'array'] - }, - isTradingFees: { - type: 'boolean' - }, - isFundingFees: { - type: 'boolean' - } - } -} - -const paramsSchemaForPerformingLoanApi = { - type: 'object', - properties: { - timeframe: { - type: 'string', - enum: [ - 'day', - 'week', - 'month', - 'year' - ] - }, - start: { - type: 'integer' - }, - end: { - type: 'integer' - }, - symbol: { - type: ['string', 'array'] - } - } -} - -const paramsSchemaForSummaryByAssetApi = { - type: 'object', - properties: { - start: { - type: 'integer' - }, - end: { - type: 'integer' - } - } -} - -const { - timezone, - dateFormat -} = { ...paramsSchemaForFile.properties } - -const paramsSchemaForBalanceHistoryFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForBalanceHistoryApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForWinLossFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForWinLossApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForWinLossVSAccountBalanceFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForWinLossVSAccountBalanceApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForPositionsSnapshotFile = { - type: 'object', - properties: { - end: { - type: 'integer' - }, - timezone, - dateFormat - } -} - -const paramsSchemaForFullSnapshotReportFile = { - type: 'object', - properties: { - end: { - type: 'integer' - }, - timezone, - dateFormat - } -} - -const paramsSchemaForFullTaxReportFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForFullTaxReportApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForTransactionTaxReportFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForTransactionTaxReportApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForTradedVolumeFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForTradedVolumeApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForTotalFeesReportFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForTotalFeesReportApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForPerformingLoanFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForPerformingLoanApi.properties), - timezone, - dateFormat - } -} - -const paramsSchemaForCandlesFile = { - type: 'object', - properties: { - ...cloneDeep(paramsSchemaForCandlesApi.properties), - timezone, - dateFormat - } -} - -module.exports = { - paramsSchemaForEditAllPublicCollsConfs, - paramsSchemaForCreateSubAccount, - paramsSchemaForUpdateSubAccount, - paramsSchemaForInterruptOperations, - paramsSchemaForBalanceHistoryApi, - paramsSchemaForWinLossApi, - paramsSchemaForWinLossVSAccountBalanceApi, - paramsSchemaForPositionsSnapshotApi, - paramsSchemaForFullSnapshotReportApi, - paramsSchemaForFullTaxReportApi, - paramsSchemaForTransactionTaxReportApi, - paramsSchemaForTradedVolumeApi, - paramsSchemaForTotalFeesReportApi, - paramsSchemaForPerformingLoanApi, - paramsSchemaForCandlesApi, - paramsSchemaForSummaryByAssetApi, - paramsSchemaForBalanceHistoryFile, - paramsSchemaForWinLossFile, - paramsSchemaForWinLossVSAccountBalanceFile, - paramsSchemaForPositionsSnapshotFile, - paramsSchemaForFullSnapshotReportFile, - paramsSchemaForFullTaxReportFile, - paramsSchemaForTransactionTaxReportFile, - paramsSchemaForTradedVolumeFile, - paramsSchemaForTotalFeesReportFile, - paramsSchemaForPerformingLoanFile, - paramsSchemaForCandlesFile -} diff --git a/workers/loc.api/service.report.framework.js b/workers/loc.api/service.report.framework.js index b572c7da1..f353d84e1 100644 --- a/workers/loc.api/service.report.framework.js +++ b/workers/loc.api/service.report.framework.js @@ -19,7 +19,6 @@ const { ServerAvailabilityError } = require('./errors') const { - checkParams, checkParamsAuth, isNotSyncRequired, collObjToArr, @@ -254,7 +253,10 @@ class FrameworkReportService extends ReportService { createSubAccount (space, args, cb) { return this._responder(() => { - checkParams(args, 'paramsSchemaForCreateSubAccount') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.CREATE_SUB_ACCOUNT_REQ + ) return this._subAccount .createSubAccount(args) @@ -263,7 +265,10 @@ class FrameworkReportService extends ReportService { updateSubAccount (space, args, cb) { return this._responder(() => { - checkParams(args, 'paramsSchemaForUpdateSubAccount') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.UPDATE_SUB_ACCOUNT_REQ + ) return this._subAccount .updateSubAccount(args) @@ -483,7 +488,10 @@ class FrameworkReportService extends ReportService { interruptOperations (space, args = {}, cb) { return this._privResponder(() => { - checkParams(args, 'paramsSchemaForInterruptOperations', ['names']) + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.INTERRUPT_OPERATIONS_REQ + ) return this._authenticator.interruptOperations(args) }, 'interruptOperations', args, cb) @@ -491,7 +499,10 @@ class FrameworkReportService extends ReportService { editAllPublicCollsConfs (space, args = {}, cb) { return this._privResponder(async () => { - checkParams(args, 'paramsSchemaForEditAllPublicCollsConfs') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.EDIT_ALL_PUBLIC_COLLS_CONFS_REQ + ) const syncedColls = await this._publicCollsConfAccessors .editAllPublicCollsConfs(args) @@ -544,8 +555,6 @@ class FrameworkReportService extends ReportService { return super.getSymbols(space, args) } - checkParams(args, 'paramsSchemaForApi') - const methods = [ this._SYNC_API_METHODS.SYMBOLS, this._SYNC_API_METHODS.FUTURES, @@ -614,12 +623,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.POSITIONS_HISTORY, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getPositionsHistory', args, cb) } @@ -680,8 +687,9 @@ class FrameworkReportService extends ReportService { }), args, { - checkParamsFn: (args) => checkParams( - args, 'paramsSchemaForPositionsAudit' + checkParamsFn: (args) => this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_POSITIONS_AUDIT_REQ ) } ) @@ -702,12 +710,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.LEDGERS, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getLedgers', args, cb) } @@ -726,12 +732,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForPayInvoiceList') - return this._dao.findInCollBy( this._SYNC_API_METHODS.PAY_INVOICE_LIST, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getPayInvoiceList', args, cb) } @@ -750,12 +754,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.TRADES, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getTrades', args, cb) } @@ -774,12 +776,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.FUNDING_TRADES, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getFundingTrades', args, cb) } @@ -793,8 +793,6 @@ class FrameworkReportService extends ReportService { return super.getTickersHistory(space, args) } - checkParams(args, 'paramsSchemaForApi', ['symbol']) - return this._publicCollsConfAccessors .getPublicData( (args) => super.getTickersHistory(space, args), @@ -817,8 +815,6 @@ class FrameworkReportService extends ReportService { return super.getPublicTrades(space, args) } - checkParams(args, 'paramsSchemaForPublicTrades', ['symbol']) - return this._publicCollsConfAccessors .getPublicData( (args) => super.getPublicTrades(space, args), @@ -841,8 +837,6 @@ class FrameworkReportService extends ReportService { return super.getStatusMessages(space, args) } - checkParams(args, 'paramsSchemaForStatusMessagesApi') - const { params } = { ...args } const { type = 'deriv', @@ -887,13 +881,16 @@ class FrameworkReportService extends ReportService { return super.getCandles(space, args) } - checkParams(args, 'paramsSchemaForCandlesApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.FW_GET_CANDLES_REQ + ) - const { params } = { ...args } + const { params } = args ?? {} const { section = 'hist', timeframe = '1D' - } = { ...params } + } = params ?? {} const argsWithParamsByDefault = { ...args, params: { @@ -925,8 +922,9 @@ class FrameworkReportService extends ReportService { (args) => super.getOrderTrades(space, args), args, { - checkParamsFn: (args) => checkParams( - args, 'paramsSchemaForOrderTradesApi' + checkParamsFn: (args) => this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_ORDER_TRADES_REQ ) } ) @@ -947,12 +945,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.ORDERS, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getOrders', args, cb) } @@ -988,12 +984,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.MOVEMENTS, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getMovements', args, cb) } @@ -1033,12 +1027,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.FUNDING_OFFER_HISTORY, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getFundingOfferHistory', args, cb) } @@ -1057,12 +1049,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.FUNDING_LOAN_HISTORY, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getFundingLoanHistory', args, cb) } @@ -1081,12 +1071,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.FUNDING_CREDIT_HISTORY, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getFundingCreditHistory', args, cb) } @@ -1105,12 +1093,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.LOGINS, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getLogins', args, cb) } @@ -1129,12 +1115,10 @@ class FrameworkReportService extends ReportService { ) } - checkParams(args, 'paramsSchemaForApi') - return this._dao.findInCollBy( this._SYNC_API_METHODS.CHANGE_LOGS, args, - { isPrepareResponse: true } + { isPrepareResponse: true, shouldParamsBeVerified: true } ) }, 'getChangeLogs', args, cb) } @@ -1264,7 +1248,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.WALLETS, args) - checkParams(args, 'paramsSchemaForWallets') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_WALLETS_REQ + ) return this._wallets.getWallets(args) }, 'getWallets', args, cb) @@ -1275,7 +1262,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.BALANCE_HISTORY, args) - checkParams(args, 'paramsSchemaForBalanceHistoryApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_BALANCE_HISTORY_REQ + ) return this._balanceHistory.getBalanceHistory(args) }, 'getBalanceHistory', args, cb) @@ -1286,7 +1276,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.WIN_LOSS, args) - checkParams(args, 'paramsSchemaForWinLossApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_WIN_LOSS_REQ + ) return this._winLoss.getWinLoss(args) }, 'getWinLoss', args, cb) @@ -1297,7 +1290,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.POSITIONS_SNAPSHOT, args) - checkParams(args, 'paramsSchemaForPositionsSnapshotApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_POSITIONS_SNAPSHOT_REQ + ) return this._positionsSnapshot.getPositionsSnapshot(args) }, 'getPositionsSnapshot', args, cb) @@ -1308,7 +1304,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.FULL_SNAPSHOT_REPORT, args) - checkParams(args, 'paramsSchemaForFullSnapshotReportApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_FULL_SNAPSHOT_REPORT_REQ + ) return this._fullSnapshotReport.getFullSnapshotReport(args) }, 'getFullSnapshotReport', args, cb) @@ -1319,7 +1318,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.FULL_TAX_REPORT, args) - checkParams(args, 'paramsSchemaForFullTaxReportApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_FULL_TAX_REPORT_REQ + ) return this._fullTaxReport.getFullTaxReport(args) }, 'getFullTaxReport', args, cb) @@ -1330,7 +1332,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.TRANSACTION_TAX_REPORT, args) - checkParams(args, 'paramsSchemaForTransactionTaxReportApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_TRANSACTION_TAX_REPORT_REQ + ) return this._transactionTaxReport.getTransactionTaxReport(args) }, 'getTransactionTaxReport', args, cb) @@ -1341,7 +1346,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.TRANSACTION_TAX_REPORT, args) - checkParams(args, 'paramsSchemaForTransactionTaxReportApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_TRANSACTION_TAX_REPORT_REQ + ) return this._transactionTaxReport.makeTrxTaxReportInBackground(args) }, 'makeTrxTaxReportInBackground', args, cb) @@ -1352,7 +1360,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.TRADED_VOLUME, args) - checkParams(args, 'paramsSchemaForTradedVolumeApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_TRADED_VOLUME_REQ + ) return this._tradedVolume.getTradedVolume(args) }, 'getTradedVolume', args, cb) @@ -1363,7 +1374,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.TOTAL_FEES_REPORT, args) - checkParams(args, 'paramsSchemaForTotalFeesReportApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_TOTAL_FEES_REPORT_REQ + ) return this._totalFeesReport.getTotalFeesReport(args) }, 'getTotalFeesReport', args, cb) @@ -1374,7 +1388,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.PERFORMING_LOAN, args) - checkParams(args, 'paramsSchemaForPerformingLoanApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_PERFORMING_LOAN_REQ + ) return this._performingLoan.getPerformingLoan(args) }, 'getPerformingLoan', args, cb) @@ -1385,7 +1402,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.WIN_LOSS, args) - checkParams(args, 'paramsSchemaForWinLossVSAccountBalanceApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_WIN_LOSS_VS_ACCOUNT_BALANCE_REQ + ) return this._winLossVSAccountBalance .getWinLossVSAccountBalance(args) @@ -1397,7 +1417,10 @@ class FrameworkReportService extends ReportService { await this._dataConsistencyChecker .check(this._CHECKER_NAMES.SUMMARY_BY_ASSET, args) - checkParams(args, 'paramsSchemaForSummaryByAssetApi') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.GET_SUMMARY_BY_ASSET_REQ + ) return this._summaryByAsset.getSummaryByAsset(args) }, 'getSummaryByAsset', args, cb) @@ -1502,7 +1525,10 @@ class FrameworkReportService extends ReportService { return super.getCandlesFile(space, args) } - checkParams(args, 'paramsSchemaForCandlesFile') + this._dataValidator.validate( + args, + this._dataValidator.SCHEMA_IDS.FW_GET_CANDLES_FILE_REQ + ) return super.getCandlesFile(space, args) }, 'getCandlesFile', args, cb) diff --git a/workers/loc.api/sync/colls.accessors/public.colls.conf.accessors.js b/workers/loc.api/sync/colls.accessors/public.colls.conf.accessors.js index 17c0e28b2..7958dcd37 100644 --- a/workers/loc.api/sync/colls.accessors/public.colls.conf.accessors.js +++ b/workers/loc.api/sync/colls.accessors/public.colls.conf.accessors.js @@ -51,6 +51,10 @@ class PublicCollsConfAccessors { return confName === this.PUBLIC_COLLS_CONF_NAMES.CANDLES_CONF } + isStatusMessagesConfs (confName) { + return confName === this.PUBLIC_COLLS_CONF_NAMES.STATUS_MESSAGES_CONF + } + isUniqueConf (confName, confs, currConf) { return confs.every((conf) => ( conf.symbol !== currConf.symbol || @@ -295,26 +299,52 @@ class PublicCollsConfAccessors { return confsTimeframe } - getArgs (confs, args) { - const { params } = { ...args } + getArgs (confName, confs, args) { + const { params } = args ?? {} const symbol = this.getSymbol( confs ) + + if (this.isStatusMessagesConfs(confName)) { + return { + ...args, + auth: null, + params: { + ...params, + symbol + } + } + } + const start = this.getStart( confs, params.start ) - const timeframe = this.getTimeframe( - confs - ) - const timeframeParam = ( - Array.isArray(timeframe) && - timeframe.length > 0 - ) - ? { timeframe } - : {} + if (this.isCandlesConfs(confName)) { + const timeframe = this.getTimeframe( + confs + ) + + const timeframeParam = ( + Array.isArray(timeframe) && + timeframe.length > 0 + ) + ? { timeframe: timeframe[0] } + : {} + + return { + ...args, + auth: null, + params: { + ...params, + symbol, + start, + ...timeframeParam + } + } + } return { ...args, @@ -322,8 +352,7 @@ class PublicCollsConfAccessors { params: { ...params, symbol, - start, - timeframeParam + start } } } @@ -434,14 +463,15 @@ class PublicCollsConfAccessors { return method(args) } - const _args = this.getArgs(confs, args) + const _args = this.getArgs(confName, confs, args) const dbRes = await this.dao.findInCollBy( collName, _args, { isPrepareResponse: false, - isPublic: true + isPublic: true, + shouldParamsBeVerified: true } ) const _dbRes = Array.isArray(dbRes) diff --git a/workers/loc.api/sync/dao/dao.better.sqlite.js b/workers/loc.api/sync/dao/dao.better.sqlite.js index 962c9e568..e5bf46bc7 100644 --- a/workers/loc.api/sync/dao/dao.better.sqlite.js +++ b/workers/loc.api/sync/dao/dao.better.sqlite.js @@ -6,9 +6,12 @@ const MAIN_DB_WORKER_ACTIONS = require( 'bfx-facs-db-better-sqlite/worker/db-worker-actions/db-worker-actions.const' ) const { - checkFilterParams, normalizeFilterParams } = require('bfx-report/workers/loc.api/helpers') +const { + getValidationSchemaId, + getFilterValidationSchemaId +} = require('bfx-report/workers/loc.api/helpers/prepare-response/helpers') const { AuthError } = require('bfx-report/workers/loc.api/errors') @@ -67,7 +70,8 @@ const depsTypes = (TYPES) => [ TYPES.TABLES_NAMES, TYPES.SyncSchema, TYPES.DbMigratorFactory, - TYPES.ProcessMessageManagerFactory + TYPES.ProcessMessageManagerFactory, + TYPES.DataValidator ] class BetterSqliteDAO extends DAO { constructor (...args) { @@ -914,9 +918,9 @@ class BetterSqliteDAO extends DAO { ) { const { schema = {}, - isNotDataConverted = false + isNotDataConverted = false, + shouldParamsBeVerified = false } = { ...opts } - const filterModelName = filterModelNameMap.get(method) const methodColl = ( schema && typeof schema === 'object' @@ -927,8 +931,20 @@ class BetterSqliteDAO extends DAO { .setDataStructure(schema) : this._getMethodCollMap().get(method) - const args = normalizeFilterParams(method, reqArgs) - checkFilterParams(filterModelName, args) + const apiMethodName = filterModelNameMap.get(method) ?? {} + const args = normalizeFilterParams(apiMethodName, reqArgs) + + if (shouldParamsBeVerified) { + const schemaId = getValidationSchemaId(apiMethodName) + const filterSchemaId = getFilterValidationSchemaId(apiMethodName) + + await this.dataValidator.validate(reqArgs, schemaId) + await this.dataValidator.validate( + { params: args?.params?.filter }, + filterSchemaId + ) + } + const _args = getArgs(args, methodColl) const { sql, sqlParams } = getQuery( diff --git a/workers/loc.api/sync/dao/dao.js b/workers/loc.api/sync/dao/dao.js index 38237bd60..fee38c095 100644 --- a/workers/loc.api/sync/dao/dao.js +++ b/workers/loc.api/sync/dao/dao.js @@ -16,13 +16,15 @@ class DAO { TABLES_NAMES, syncSchema, dbMigratorFactory, - processMessageManagerFactory + processMessageManagerFactory, + dataValidator ) { this.db = db this.TABLES_NAMES = TABLES_NAMES this.syncSchema = syncSchema this.dbMigratorFactory = dbMigratorFactory this.processMessageManagerFactory = processMessageManagerFactory + this.dataValidator = dataValidator } _getModelsMap () { diff --git a/workers/loc.api/sync/dao/helpers/filter-model-name-map.js b/workers/loc.api/sync/dao/helpers/filter-model-name-map.js index b9163fead..a51cc9d88 100644 --- a/workers/loc.api/sync/dao/helpers/filter-model-name-map.js +++ b/workers/loc.api/sync/dao/helpers/filter-model-name-map.js @@ -1,10 +1,10 @@ 'use strict' const { - FILTER_MODELS_NAMES + FILTER_API_METHOD_NAMES } = require('bfx-report/workers/loc.api/helpers') -module.exports = Object.values(FILTER_MODELS_NAMES) +module.exports = Object.values(FILTER_API_METHOD_NAMES) .reduce((map, name) => { const baseName = `${name[0].toUpperCase()}${name.slice(1)}` const key = `_get${baseName}`