diff --git a/package.json b/package.json index 476f7aa4..93a3e9f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bfx-report", - "version": "4.10.6", + "version": "4.10.7", "description": "Reporting tool", "main": "worker.js", "license": "Apache-2.0", diff --git a/test/helpers/helpers.core.js b/test/helpers/helpers.core.js index 9428a074..12348ede 100644 --- a/test/helpers/helpers.core.js +++ b/test/helpers/helpers.core.js @@ -1,47 +1,55 @@ 'use strict' -const { promisify } = require('util') const path = require('path') -const fs = require('fs') -const readdir = promisify(fs.readdir) -const unlink = promisify(fs.unlink) -const mkdir = promisify(fs.mkdir) +const { + readdir, + mkdir, + rm +} = require('node:fs/promises') const rmDB = async ( dir, - exclude = ['.gitkeep'], - isThrownError + exclude = ['.gitkeep'] ) => { try { - const files = await readdir(dir) - const promisesArr = files.map((file) => { - if (exclude.every(exFile => exFile !== file)) { - return unlink(path.join(dir, file)) + const files = await readdir( + dir, + { withFileTypes: true } + ) + + for (const dirent of files) { + const { name } = dirent + + if ( + !dirent.isFile() || + exclude.some((exFile) => exFile === name) + ) { + continue } - return null - }) - - const res = await Promise.all(promisesArr) - - return res - } catch (err) { - if (!isThrownError) { - return + const filePath = path.join(dir, name) + await rm( + filePath, + { + force: true, + maxRetries: 5, + recursive: true, + retryDelay: 200 + } + ) } - - throw err + } catch (err) { + console.log(err) } } const rmAllFiles = async (dir, exclude) => { try { - await rmDB(dir, exclude, true) + await rmDB(dir, exclude) + await mkdir(dir, { recursive: true }) } catch (err) { - if (err.syscall === 'scandir') { - await mkdir(dir) - } + console.log(err) } } diff --git a/workers/api.service.report.wrk.js b/workers/api.service.report.wrk.js index 57d2a906..9ae4ff23 100644 --- a/workers/api.service.report.wrk.js +++ b/workers/api.service.report.wrk.js @@ -73,15 +73,6 @@ class WrkReportServiceApi extends WrkApi { loadDIConfig (cont = container) { const conf = this.conf[this.group] - /** - * @deprecated isAddedUniqueEndingToCsvName - * Keep for back compatibility - */ - conf.isAddedUniqueEndingToReportFileName = ( - conf.isAddedUniqueEndingToReportFileName ?? - conf.isAddedUniqueEndingToCsvName - ) - this.container = cont diConfig(conf, this.ctx.root) diff --git a/workers/loc.api/generate-report-file/index.js b/workers/loc.api/generate-report-file/index.js index b64e9d01..df1a8d6e 100644 --- a/workers/loc.api/generate-report-file/index.js +++ b/workers/loc.api/generate-report-file/index.js @@ -41,13 +41,7 @@ const _getReportFileStoreStatus = async ({ return { isSaveLocaly: true, localReportFolderPath, - remoteReportUrn, - - /** - * @deprecated fields - */ - localCsvFolderPath: localReportFolderPath, - remoteCsvUrn: remoteReportUrn + remoteReportUrn } } diff --git a/workers/loc.api/helpers/api-errors-testers.js b/workers/loc.api/helpers/api-errors-testers.js index 04a8fa78..f6b50a69 100644 --- a/workers/loc.api/helpers/api-errors-testers.js +++ b/workers/loc.api/helpers/api-errors-testers.js @@ -48,7 +48,11 @@ const isEAiAgainError = (err) => { } const isEConnRefusedError = (err) => { - return /ECONNREFUSED/i.test(_getErrorString(err)) + return /(ECONNREFUSED)|(ERR_CONNECTION_REFUSED)/i.test(_getErrorString(err)) +} + +const isEConnClosedError = (err) => { + return /ERR_CONNECTION_CLOSED/i.test(_getErrorString(err)) } const isENotFoundError = (err) => { @@ -71,6 +75,10 @@ const isTempUnavailableError = (err) => { return /temporarily_unavailable/i.test(_getErrorString(err)) } +const isBadGatewayError = (err) => { + return /Bad Gateway/i.test(_getErrorString(err)) +} + const isForbiddenError = (err) => { return /forbidden/i.test(_getErrorString(err)) } @@ -87,11 +95,13 @@ const isENetError = (err) => ( isNodeFetchTimeoutError(err) || isEAiAgainError(err) || isEConnRefusedError(err) || + isEConnClosedError(err) || isENotFoundError(err) || isESocketTimeoutError(err) || isEHostUnreachError(err) || isEProtoError(err) || - isTempUnavailableError(err) + isTempUnavailableError(err) || + isBadGatewayError(err) ) module.exports = { @@ -106,11 +116,13 @@ module.exports = { isNodeFetchTimeoutError, isEAiAgainError, isEConnRefusedError, + isEConnClosedError, isENotFoundError, isESocketTimeoutError, isEHostUnreachError, isEProtoError, isTempUnavailableError, + isBadGatewayError, isENetError, isForbiddenError, isMaintenanceError diff --git a/workers/loc.api/helpers/index.js b/workers/loc.api/helpers/index.js index add351b3..6f55dc03 100644 --- a/workers/loc.api/helpers/index.js +++ b/workers/loc.api/helpers/index.js @@ -34,8 +34,13 @@ const { isNodeFetchTimeoutError, isEAiAgainError, isEConnRefusedError, + isEConnClosedError, isENotFoundError, isESocketTimeoutError, + isEHostUnreachError, + isEProtoError, + isTempUnavailableError, + isBadGatewayError, isENetError, isForbiddenError, isMaintenanceError @@ -81,8 +86,13 @@ module.exports = { isNodeFetchTimeoutError, isEAiAgainError, isEConnRefusedError, + isEConnClosedError, isENotFoundError, isESocketTimeoutError, + isEHostUnreachError, + isEProtoError, + isTempUnavailableError, + isBadGatewayError, isENetError, isForbiddenError, isMaintenanceError, diff --git a/workers/loc.api/service.report.js b/workers/loc.api/service.report.js index 090a7413..78b16b42 100644 --- a/workers/loc.api/service.report.js +++ b/workers/loc.api/service.report.js @@ -678,11 +678,6 @@ class ReportService extends Api { }, 'getWeightedAveragesReport', args, cb) } - /** - * @deprecated - */ - getMultipleCsv (...args) { return this.getMultipleFile(...args) } - getMultipleFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -692,11 +687,6 @@ class ReportService extends Api { }, 'getMultipleFile', args, cb) } - /** - * @deprecated - */ - getTradesCsv (...args) { return this.getTradesFile(...args) } - getTradesFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -706,11 +696,6 @@ class ReportService extends Api { }, 'getTradesFile', args, cb) } - /** - * @deprecated - */ - getFundingTradesCsv (...args) { return this.getFundingTradesFile(...args) } - getFundingTradesFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -720,11 +705,6 @@ class ReportService extends Api { }, 'getFundingTradesFile', args, cb) } - /** - * @deprecated - */ - getTickersHistoryCsv (...args) { return this.getTickersHistoryFile(...args) } - getTickersHistoryFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -734,11 +714,6 @@ class ReportService extends Api { }, 'getTickersHistoryFile', args, cb) } - /** - * @deprecated - */ - getWalletsCsv (...args) { return this.getWalletsFile(...args) } - getWalletsFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -748,11 +723,6 @@ class ReportService extends Api { }, 'getWalletsFile', args, cb) } - /** - * @deprecated - */ - getPositionsHistoryCsv (...args) { return this.getPositionsHistoryFile(...args) } - getPositionsHistoryFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -762,11 +732,6 @@ class ReportService extends Api { }, 'getPositionsHistoryFile', args, cb) } - /** - * @deprecated - */ - getActivePositionsCsv (...args) { return this.getActivePositionsFile(...args) } - getActivePositionsFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -776,11 +741,6 @@ class ReportService extends Api { }, 'getActivePositionsFile', args, cb) } - /** - * @deprecated - */ - getPositionsAuditCsv (...args) { return this.getPositionsAuditFile(...args) } - getPositionsAuditFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -790,11 +750,6 @@ class ReportService extends Api { }, 'getPositionsAuditFile', args, cb) } - /** - * @deprecated - */ - getPublicTradesCsv (...args) { return this.getPublicTradesFile(...args) } - getPublicTradesFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -804,11 +759,6 @@ class ReportService extends Api { }, 'getPublicTradesFile', args, cb) } - /** - * @deprecated - */ - getStatusMessagesCsv (...args) { return this.getStatusMessagesFile(...args) } - getStatusMessagesFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -818,11 +768,6 @@ class ReportService extends Api { }, 'getStatusMessagesFile', args, cb) } - /** - * @deprecated - */ - getCandlesCsv (...args) { return this.getCandlesFile(...args) } - getCandlesFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -832,11 +777,6 @@ class ReportService extends Api { }, 'getCandlesFile', args, cb) } - /** - * @deprecated - */ - getLedgersCsv (...args) { return this.getLedgersFile(...args) } - getLedgersFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -846,11 +786,6 @@ class ReportService extends Api { }, 'getLedgersFile', args, cb) } - /** - * @deprecated - */ - getPayInvoiceListCsv (...args) { return this.getPayInvoiceListFile(...args) } - getPayInvoiceListFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -860,11 +795,6 @@ class ReportService extends Api { }, 'getPayInvoiceListFile', args, cb) } - /** - * @deprecated - */ - getOrderTradesCsv (...args) { return this.getOrderTradesFile(...args) } - getOrderTradesFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -874,11 +804,6 @@ class ReportService extends Api { }, 'getOrderTradesFile', args, cb) } - /** - * @deprecated - */ - getOrdersCsv (...args) { return this.getOrdersFile(...args) } - getOrdersFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -888,11 +813,6 @@ class ReportService extends Api { }, 'getOrdersFile', args, cb) } - /** - * @deprecated - */ - getActiveOrdersCsv (...args) { return this.getActiveOrdersFile(...args) } - getActiveOrdersFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -902,11 +822,6 @@ class ReportService extends Api { }, 'getActiveOrdersFile', args, cb) } - /** - * @deprecated - */ - getMovementsCsv (...args) { return this.getMovementsFile(...args) } - getMovementsFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -916,11 +831,6 @@ class ReportService extends Api { }, 'getMovementsFile', args, cb) } - /** - * @deprecated - */ - getFundingOfferHistoryCsv (...args) { return this.getFundingOfferHistoryFile(...args) } - getFundingOfferHistoryFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -930,11 +840,6 @@ class ReportService extends Api { }, 'getFundingOfferHistoryFile', args, cb) } - /** - * @deprecated - */ - getFundingLoanHistoryCsv (...args) { return this.getFundingLoanHistoryFile(...args) } - getFundingLoanHistoryFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -944,11 +849,6 @@ class ReportService extends Api { }, 'getFundingLoanHistoryFile', args, cb) } - /** - * @deprecated - */ - getFundingCreditHistoryCsv (...args) { return this.getFundingCreditHistoryFile(...args) } - getFundingCreditHistoryFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -958,11 +858,6 @@ class ReportService extends Api { }, 'getFundingCreditHistoryFile', args, cb) } - /** - * @deprecated - */ - getLoginsCsv (...args) { return this.getLoginsFile(...args) } - getLoginsFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -972,11 +867,6 @@ class ReportService extends Api { }, 'getLoginsFile', args, cb) } - /** - * @deprecated - */ - getChangeLogsCsv (...args) { return this.getChangeLogsFile(...args) } - getChangeLogsFile (space, args, cb) { return this._responder(() => { return this._generateReportFile( @@ -986,11 +876,6 @@ class ReportService extends Api { }, 'getChangeLogsFile', args, cb) } - /** - * @deprecated - */ - getWeightedAveragesReportCsv (...args) { return this.getWeightedAveragesReportFile(...args) } - getWeightedAveragesReportFile (space, args, cb) { return this._responder(() => { return this._generateReportFile(