Skip to content

Commit

Permalink
chore: use native randomUUID instead of uuid4
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Oct 30, 2023
1 parent 5c0c059 commit 2b6e844
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 107 deletions.
14 changes: 1 addition & 13 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@
"moment": "2.29.4",
"mongo-uri-builder": "^4.0.0",
"rc": "1.2.8",
"require-glob": "^4.1.0",
"uuid4": "2.0.3"
"require-glob": "^4.1.0"
},
"optionalDependencies": {
"mysql": "2.18.1"
Expand Down
8 changes: 4 additions & 4 deletions src/domain/participant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const PositionFacade = require('../../models/position/facade')
const Config = require('../../lib/config')
const Kafka = require('@mojaloop/central-services-shared').Util.Kafka
const KafkaProducer = require('@mojaloop/central-services-stream').Util.Producer
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const Enum = require('@mojaloop/central-services-shared').Enum
const Enums = require('../../lib/enumCached')

Expand Down Expand Up @@ -480,7 +480,7 @@ const adjustLimits = async (name, payload) => {

const createLimitAdjustmentMessageProtocol = (payload, action = Enum.Transfers.AdminNotificationActions.LIMIT_ADJUSTMENT, state = '', pp = '') => {
return {
id: Uuid(),
id: randomUUID(),
from: payload.name,
to: Config.HUB_NAME,
type: 'application/json',
Expand All @@ -490,7 +490,7 @@ const createLimitAdjustmentMessageProtocol = (payload, action = Enum.Transfers.A
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
responseTo: '',
type: 'notification',
action,
Expand Down Expand Up @@ -653,7 +653,7 @@ const createRecordFundsMessageProtocol = (payload, action = '', state = '', pp =
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
responseTo: '',
type: 'transfer',
action,
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/positions/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Consumer = require('@mojaloop/central-services-stream').Util.Consumer
const Enum = require('@mojaloop/central-services-shared').Enum
const Metrics = require('@mojaloop/central-services-metrics')
const Config = require('../../lib/config')
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const decodePayload = require('@mojaloop/central-services-shared').Util.StreamingProtocol.decodePayload
const decodeMessages = require('@mojaloop/central-services-shared').Util.StreamingProtocol.decodeMessages
const ErrorHandler = require('@mojaloop/central-services-error-handling')
Expand Down Expand Up @@ -274,7 +274,7 @@ const registerPositionHandler = async () => {
topicName: Kafka.transformGeneralTopicName(Config.KAFKA_CONFIG.TOPIC_TEMPLATES.GENERAL_TOPIC_TEMPLATE.TEMPLATE, Enum.Events.Event.Type.POSITION, Enum.Events.Event.Action.PREPARE),
config: Kafka.getKafkaConfig(Config.KAFKA_CONFIG, Enum.Kafka.Config.CONSUMER, Enum.Events.Event.Type.TRANSFER.toUpperCase(), Enum.Events.Event.Action.POSITION.toUpperCase())
}
positionHandler.config.rdkafkaConf['client.id'] = `${positionHandler.config.rdkafkaConf['client.id']}-${Uuid()}`
positionHandler.config.rdkafkaConf['client.id'] = `${positionHandler.config.rdkafkaConf['client.id']}-${randomUUID()}`
await Consumer.createHandler(positionHandler.topicName, positionHandler.config, positionHandler.command)
return true
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ObjStoreDb = require('@mojaloop/object-store-lib').Db
const Plugins = require('./plugins')
const Config = require('../lib/config')
const RequestLogger = require('../lib/requestLogger')
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const UrlParser = require('../lib/urlParser')
const Logger = require('@mojaloop/central-services-logger')
const RegisterHandlers = require('../handlers/register')
Expand Down Expand Up @@ -115,7 +115,7 @@ const createServer = (port, modules) => {
})
server.ext('onPostAuth', function (request, h) {
const transferId = UrlParser.idFromTransferUri(`${Config.HOSTNAME}${request.path}`)
request.headers.traceid = request.headers.traceid || transferId || Uuid()
request.headers.traceid = request.headers.traceid || transferId || randomUUID()
RequestLogger.logRequest(request)
return h.continue
})
Expand Down
16 changes: 8 additions & 8 deletions test/integration-override/handlers/transfers/handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ optionally within square brackets <email>.
'use strict'

const Test = require('tape')
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const Logger = require('@mojaloop/central-services-logger')
const Config = require('#src/lib/config')
const Time = require('@mojaloop/central-services-shared').Util.Time
Expand Down Expand Up @@ -160,7 +160,7 @@ const prepareTestData = async (dataObj) => {
}

const transferPayload = {
transferId: Uuid(),
transferId: randomUUID(),
payerFsp: payer.participant.name,
payeeFsp: payee.participant.name,
amount: {
Expand Down Expand Up @@ -219,7 +219,7 @@ const prepareTestData = async (dataObj) => {
errorPayload.errorInformation.extensionList = { extension: [{ key: 'errorDetail', value: 'This is an abort extension' }] }

const messageProtocolPrepare = {
id: Uuid(),
id: randomUUID(),
from: transferPayload.payerFsp,
to: transferPayload.payeeFsp,
type: 'application/json',
Expand All @@ -229,7 +229,7 @@ const prepareTestData = async (dataObj) => {
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
type: TransferEventAction.PREPARE,
action: TransferEventType.PREPARE,
createdAt: dataObj.now,
Expand All @@ -242,24 +242,24 @@ const prepareTestData = async (dataObj) => {
}

const messageProtocolFulfil = Util.clone(messageProtocolPrepare)
messageProtocolFulfil.id = Uuid()
messageProtocolFulfil.id = randomUUID()
messageProtocolFulfil.from = transferPayload.payeeFsp
messageProtocolFulfil.to = transferPayload.payerFsp
messageProtocolFulfil.content.headers = fulfilAbortRejectHeaders
messageProtocolFulfil.content.uriParams = { id: transferPayload.transferId }
messageProtocolFulfil.content.payload = fulfilPayload
messageProtocolFulfil.metadata.event.id = Uuid()
messageProtocolFulfil.metadata.event.id = randomUUID()
messageProtocolFulfil.metadata.event.type = TransferEventType.FULFIL
messageProtocolFulfil.metadata.event.action = TransferEventAction.COMMIT

const messageProtocolReject = Util.clone(messageProtocolFulfil)
messageProtocolReject.id = Uuid()
messageProtocolReject.id = randomUUID()
messageProtocolFulfil.content.uriParams = { id: transferPayload.transferId }
messageProtocolReject.content.payload = rejectPayload
messageProtocolReject.metadata.event.action = TransferEventAction.REJECT

const messageProtocolError = Util.clone(messageProtocolFulfil)
messageProtocolError.id = Uuid()
messageProtocolError.id = randomUUID()
messageProtocolFulfil.content.uriParams = { id: transferPayload.transferId }
messageProtocolError.content.payload = errorPayload
messageProtocolError.metadata.event.action = TransferEventAction.ABORT
Expand Down
16 changes: 8 additions & 8 deletions test/integration/handlers/transfers/handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'use strict'

const Test = require('tape')
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const retry = require('async-retry')
const Logger = require('@mojaloop/central-services-logger')
const Config = require('#src/lib/config')
Expand Down Expand Up @@ -189,7 +189,7 @@ const prepareTestData = async (dataObj) => {
}

const transferPayload = {
transferId: Uuid(),
transferId: randomUUID(),
payerFsp: payer.participant.name,
payeeFsp: payee.participant.name,
amount: {
Expand Down Expand Up @@ -248,7 +248,7 @@ const prepareTestData = async (dataObj) => {
errorPayload.errorInformation.extensionList = { extension: [{ key: 'errorDetail', value: 'This is an abort extension' }] }

const messageProtocolPrepare = {
id: Uuid(),
id: randomUUID(),
from: transferPayload.payerFsp,
to: transferPayload.payeeFsp,
type: 'application/json',
Expand All @@ -258,7 +258,7 @@ const prepareTestData = async (dataObj) => {
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
type: TransferEventAction.PREPARE,
action: TransferEventType.PREPARE,
createdAt: dataObj.now,
Expand All @@ -271,24 +271,24 @@ const prepareTestData = async (dataObj) => {
}

const messageProtocolFulfil = Util.clone(messageProtocolPrepare)
messageProtocolFulfil.id = Uuid()
messageProtocolFulfil.id = randomUUID()
messageProtocolFulfil.from = transferPayload.payeeFsp
messageProtocolFulfil.to = transferPayload.payerFsp
messageProtocolFulfil.content.headers = fulfilAbortRejectHeaders
messageProtocolFulfil.content.uriParams = { id: transferPayload.transferId }
messageProtocolFulfil.content.payload = fulfilPayload
messageProtocolFulfil.metadata.event.id = Uuid()
messageProtocolFulfil.metadata.event.id = randomUUID()
messageProtocolFulfil.metadata.event.type = TransferEventType.FULFIL
messageProtocolFulfil.metadata.event.action = TransferEventAction.COMMIT

const messageProtocolReject = Util.clone(messageProtocolFulfil)
messageProtocolReject.id = Uuid()
messageProtocolReject.id = randomUUID()
messageProtocolFulfil.content.uriParams = { id: transferPayload.transferId }
messageProtocolReject.content.payload = rejectPayload
messageProtocolReject.metadata.event.action = TransferEventAction.REJECT

const messageProtocolError = Util.clone(messageProtocolFulfil)
messageProtocolError.id = Uuid()
messageProtocolError.id = randomUUID()
messageProtocolFulfil.content.uriParams = { id: transferPayload.transferId }
messageProtocolError.content.payload = errorPayload
messageProtocolError.metadata.event.action = TransferEventAction.ABORT
Expand Down
4 changes: 2 additions & 2 deletions test/integration/helpers/participantFundsInOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

'use strict'

const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const TransferService = require('../../../src/domain/transfer')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Time = require('@mojaloop/central-services-shared').Util.Time
Expand All @@ -40,7 +40,7 @@ const recordFundsInSampleData = {

exports.recordFundsIn = async (participantName, participantCurrencyId, recordFundsInObj = {}) => {
try {
const transferId = Uuid()
const transferId = randomUUID()
const payload = {
transferId,
externalReference: 'string',
Expand Down
14 changes: 7 additions & 7 deletions test/integration/helpers/testProducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

const Producer = require('@mojaloop/central-services-stream').Util.Producer
const Logger = require('@mojaloop/central-services-logger')
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const Utility = require('@mojaloop/central-services-shared').Util.Kafka
const Enum = require('@mojaloop/central-services-shared').Enum
const Config = require('../../../src/lib/config')
Expand All @@ -42,7 +42,7 @@ const expiration = new Date((new Date()).getTime() + (24 * 60 * 60 * 1000)) // t
const Time = require('@mojaloop/central-services-shared').Util.Time

const transfer = {
transferId: Uuid(),
transferId: randomUUID(),
payerFsp: 'dfsp1',
payeeFsp: 'dfsp2',
amount: {
Expand Down Expand Up @@ -131,7 +131,7 @@ exports.transferReject = async (transferId) => {
}

const requestBodys = (transferId = null) => {
const localTransfer = Object.assign({}, transfer, { transferId: transferId || Uuid() })
const localTransfer = Object.assign({}, transfer, { transferId: transferId || randomUUID() })
const localFulfil = Object.assign({}, fulfil, { completedTimestamp: new Date() })
const localReject = Object.assign({}, fulfil, { transferState: TransferInternalState.ABORTED_REJECTED })

Expand All @@ -148,7 +148,7 @@ const requestBodys = (transferId = null) => {
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
type: 'transfer',
action: 'prepare',
createdAt: new Date(),
Expand All @@ -174,7 +174,7 @@ const requestBodys = (transferId = null) => {
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
type: 'fulfil',
action: 'commit',
createdAt: new Date(),
Expand All @@ -200,7 +200,7 @@ const requestBodys = (transferId = null) => {
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
type: 'fulfil',
action: 'reject',
createdAt: new Date(),
Expand All @@ -226,7 +226,7 @@ const requestBodys = (transferId = null) => {
},
metadata: {
event: {
id: Uuid(),
id: randomUUID(),
type: 'fulfil',
action: TransferEventAction.REJECT,
createdAt: new Date(),
Expand Down
4 changes: 2 additions & 2 deletions test/integration/helpers/transferDuplicateCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const Model = require('../../../src/models/transfer/transferDuplicateCheck')
const ParticipantPreparationModule = require('./participant')
const Time = require('@mojaloop/central-services-shared').Util.Time
const Crypto = require('crypto')
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const ErrorHandler = require('@mojaloop/central-services-error-handling')

exports.prepareData = async () => {
try {
const participantPayerResult = await ParticipantPreparationModule.prepareData('payerFsp')
const participantPayeeResult = await ParticipantPreparationModule.prepareData('payeeFsp')

const transferId = Uuid()
const transferId = randomUUID()
const payload = {
payerFsp: participantPayerResult.name,
payeeFsp: participantPayeeResult.name,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/domain/transfer/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

const Test = require('tapes')(require('tape'))
const Sinon = require('sinon')
const Uuid = require('uuid4')
const { randomUUID } = require('crypto')
const TransformService = require('../../../../src/domain/transfer/transform')
const Util = require('@mojaloop/central-services-shared').Util
const Logger = require('@mojaloop/central-services-logger')
Expand Down Expand Up @@ -193,7 +193,7 @@ Test('Transform Service', transformTest => {

toTransferTest.test('return result for savePayeeTransferResponseExecuted', async (test) => {
try {
const transferId = Uuid()
const transferId = randomUUID()
const executedTransfer = {
transferFulfilmentRecord: {
transferId,
Expand Down
Loading

0 comments on commit 2b6e844

Please sign in to comment.