Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return true
} else {
// TODO: handle use case when no individual transfer has been accepted:
// Switch to finilize bulk state and notify payer with PUT /bulkTransfers/{id}
// const payerBulkResponse = Object.assign({}, { messageId: message.value.id, headers }, getBulkTransferByIdResult.payerBulkTransfer)
Logger.info(Util.breadcrumb(location, `noTransfers--${actionLetter}1`))
Logger.error(Util.breadcrumb(location, 'notImplemented'))
return true
}
} else if (eventType === Enum.Events.Event.Type.BULK_PROCESSING && [Enum.Events.Event.Action.BULK_COMMIT, Enum.Events.Event.Action.BULK_TIMEOUT_RECEIVED, Enum.Events.Event.Action.BULK_TIMEOUT_RESERVED].includes(action)) {
Logger.info(Util.breadcrumb(location, `bulkFulfil--${actionLetter}3`))
const participants = await BulkTransferService.getParticipantsById(bulkTransferInfo.bulkTransferId)
const normalizedKeys = Object.keys(headers).reduce((keys, k) => { keys[k.toLowerCase()] = k; return keys }, {})
const payeeBulkResponseHeaders = Util.Headers.transformHeaders(headers, { httpMethod: headers[normalizedKeys[Enum.Http.Headers.FSPIOP.HTTP_METHOD]], sourceFsp: Enum.Http.Headers.FSPIOP.SWITCH.value, destinationFsp: participants.payeeFsp })
delete payeeBulkResponseHeaders[normalizedKeys[Enum.Http.Headers.FSPIOP.SIGNATURE]]
const payerBulkResponse = Object.assign({}, { messageId: message.value.id, headers: Util.clone(headers) }, getBulkTransferByIdResult.payerBulkTransfer)
const payeeBulkResponse = Object.assign({}, { messageId: message.value.id, headers: payeeBulkResponseHeaders }, getBulkTransferByIdResult.payeeBulkTransfer)
const BulkTransferResultModel = BulkTransferModels.getBulkTransferResultModel()
await (new BulkTransferResultModel(payerBulkResponse)).save()
await (new BulkTransferResultModel(payeeBulkResponse)).save()
const payerParams = Util.clone(params)
const payeeParams = Util.clone(params)
const payerPayload = Util.omitNil({
bulkTransferId: payerBulkResponse.bulkTransferId,
bulkTransferState: payerBulkResponse.bulkTransferState,
completedTimestamp: payerBulkResponse.completedTimestamp,
extensionList: payerBulkResponse.extensionList
})
const payerMetadata = Util.StreamingProtocol.createMetadataWithCorrelatedEvent(params.message.value.metadata.event.id, payerParams.message.value.metadata.type, payerParams.message.value.metadata.action, Enum.Events.EventStatus.SUCCESS)
payerParams.message.value = Util.StreamingProtocol.createMessage(params.message.value.id, participants.payerFsp, payerBulkResponse.headers[normalizedKeys[Enum.Http.Headers.FSPIOP.SOURCE]], payerMetadata, payerBulkResponse.headers, payerPayload)
const payeePayload = Util.omitNil({
).startTimer()
if (error) {
histTimerEnd({ success: false, fspId: Config.INSTRUMENTATION_METRICS_LABELS.fspId })
throw ErrorHandler.Factory.reformatFSPIOPError(error)
}
let message = {}
let prepareBatch = []
let contextFromMessage
let span
try {
if (Array.isArray(messages)) {
prepareBatch = Array.from(messages)
message = Object.assign(message, Utility.clone(prepareBatch[0]))
} else {
prepareBatch = [Object.assign({}, Utility.clone(messages))]
message = Object.assign({}, messages)
}
contextFromMessage = EventSdk.Tracer.extractContextFromMessage(message.value)
span = EventSdk.Tracer.createChildSpanFromContext('cl_transfer_position', contextFromMessage)
await span.audit(message, EventSdk.AuditEventAction.start)
const payload = decodePayload(message.value.content.payload)
const eventType = message.value.metadata.event.type
const action = message.value.metadata.event.action
const transferId = payload.transferId || (message.value.content.uriParams && message.value.content.uriParams.id)
if (!transferId) {
const fspiopError = ErrorHandler.Factory.createInternalServerFSPIOPError('transferId is null or undefined')
Logger.error(fspiopError)
throw fspiopError
}
const kafkaTopic = message.topic
Logger.info(Utility.breadcrumb(location, { method: 'positions' }))
'Consume a prepare transfer message from the kafka topic and process it accordingly',
['success', 'fspId']
).startTimer()
if (error) {
histTimerEnd({ success: false, fspId: Config.INSTRUMENTATION_METRICS_LABELS.fspId })
throw ErrorHandler.Factory.reformatFSPIOPError(error)
}
let message = {}
let prepareBatch = []
let contextFromMessage
let span
try {
if (Array.isArray(messages)) {
prepareBatch = Array.from(messages)
message = Object.assign(message, Utility.clone(prepareBatch[0]))
} else {
prepareBatch = [Object.assign({}, Utility.clone(messages))]
message = Object.assign({}, messages)
}
contextFromMessage = EventSdk.Tracer.extractContextFromMessage(message.value)
span = EventSdk.Tracer.createChildSpanFromContext('cl_transfer_position', contextFromMessage)
await span.audit(message, EventSdk.AuditEventAction.start)
const payload = decodePayload(message.value.content.payload)
const eventType = message.value.metadata.event.type
const action = message.value.metadata.event.action
const transferId = payload.transferId || (message.value.content.uriParams && message.value.content.uriParams.id)
if (!transferId) {
const fspiopError = ErrorHandler.Factory.createInternalServerFSPIOPError('transferId is null or undefined')
Logger.error(fspiopError)
throw fspiopError
}
Logger.info(Util.breadcrumb(location, `noTransfers--${actionLetter}1`))
Logger.error(Util.breadcrumb(location, 'notImplemented'))
return true
}
} else if (eventType === Enum.Events.Event.Type.BULK_PROCESSING && [Enum.Events.Event.Action.BULK_COMMIT, Enum.Events.Event.Action.BULK_TIMEOUT_RECEIVED, Enum.Events.Event.Action.BULK_TIMEOUT_RESERVED].includes(action)) {
Logger.info(Util.breadcrumb(location, `bulkFulfil--${actionLetter}3`))
const participants = await BulkTransferService.getParticipantsById(bulkTransferInfo.bulkTransferId)
const normalizedKeys = Object.keys(headers).reduce((keys, k) => { keys[k.toLowerCase()] = k; return keys }, {})
const payeeBulkResponseHeaders = Util.Headers.transformHeaders(headers, { httpMethod: headers[normalizedKeys[Enum.Http.Headers.FSPIOP.HTTP_METHOD]], sourceFsp: Enum.Http.Headers.FSPIOP.SWITCH.value, destinationFsp: participants.payeeFsp })
delete payeeBulkResponseHeaders[normalizedKeys[Enum.Http.Headers.FSPIOP.SIGNATURE]]
const payerBulkResponse = Object.assign({}, { messageId: message.value.id, headers: Util.clone(headers) }, getBulkTransferByIdResult.payerBulkTransfer)
const payeeBulkResponse = Object.assign({}, { messageId: message.value.id, headers: payeeBulkResponseHeaders }, getBulkTransferByIdResult.payeeBulkTransfer)
const BulkTransferResultModel = BulkTransferModels.getBulkTransferResultModel()
await (new BulkTransferResultModel(payerBulkResponse)).save()
await (new BulkTransferResultModel(payeeBulkResponse)).save()
const payerParams = Util.clone(params)
const payeeParams = Util.clone(params)
const payerPayload = Util.omitNil({
bulkTransferId: payerBulkResponse.bulkTransferId,
bulkTransferState: payerBulkResponse.bulkTransferState,
completedTimestamp: payerBulkResponse.completedTimestamp,
extensionList: payerBulkResponse.extensionList
})
const payerMetadata = Util.StreamingProtocol.createMetadataWithCorrelatedEvent(params.message.value.metadata.event.id, payerParams.message.value.metadata.type, payerParams.message.value.metadata.action, Enum.Events.EventStatus.SUCCESS)
payerParams.message.value = Util.StreamingProtocol.createMessage(params.message.value.id, participants.payerFsp, payerBulkResponse.headers[normalizedKeys[Enum.Http.Headers.FSPIOP.SOURCE]], payerMetadata, payerBulkResponse.headers, payerPayload)
const payeePayload = Util.omitNil({
bulkTransferId: payeeBulkResponse.bulkTransferId,
bulkTransferState: payeeBulkResponse.bulkTransferState,
completedTimestamp: payeeBulkResponse.completedTimestamp,
extensionList: payeeBulkResponse.extensionList
})
Logger.error(Util.breadcrumb(location, 'notImplemented'))
return true
}
} else if (eventType === Enum.Events.Event.Type.BULK_PROCESSING && [Enum.Events.Event.Action.BULK_COMMIT, Enum.Events.Event.Action.BULK_TIMEOUT_RECEIVED, Enum.Events.Event.Action.BULK_TIMEOUT_RESERVED].includes(action)) {
Logger.info(Util.breadcrumb(location, `bulkFulfil--${actionLetter}3`))
const participants = await BulkTransferService.getParticipantsById(bulkTransferInfo.bulkTransferId)
const normalizedKeys = Object.keys(headers).reduce((keys, k) => { keys[k.toLowerCase()] = k; return keys }, {})
const payeeBulkResponseHeaders = Util.Headers.transformHeaders(headers, { httpMethod: headers[normalizedKeys[Enum.Http.Headers.FSPIOP.HTTP_METHOD]], sourceFsp: Enum.Http.Headers.FSPIOP.SWITCH.value, destinationFsp: participants.payeeFsp })
delete payeeBulkResponseHeaders[normalizedKeys[Enum.Http.Headers.FSPIOP.SIGNATURE]]
const payerBulkResponse = Object.assign({}, { messageId: message.value.id, headers: Util.clone(headers) }, getBulkTransferByIdResult.payerBulkTransfer)
const payeeBulkResponse = Object.assign({}, { messageId: message.value.id, headers: payeeBulkResponseHeaders }, getBulkTransferByIdResult.payeeBulkTransfer)
const BulkTransferResultModel = BulkTransferModels.getBulkTransferResultModel()
await (new BulkTransferResultModel(payerBulkResponse)).save()
await (new BulkTransferResultModel(payeeBulkResponse)).save()
const payerParams = Util.clone(params)
const payeeParams = Util.clone(params)
const payerPayload = Util.omitNil({
bulkTransferId: payerBulkResponse.bulkTransferId,
bulkTransferState: payerBulkResponse.bulkTransferState,
completedTimestamp: payerBulkResponse.completedTimestamp,
extensionList: payerBulkResponse.extensionList
})
const payerMetadata = Util.StreamingProtocol.createMetadataWithCorrelatedEvent(params.message.value.metadata.event.id, payerParams.message.value.metadata.type, payerParams.message.value.metadata.action, Enum.Events.EventStatus.SUCCESS)
payerParams.message.value = Util.StreamingProtocol.createMessage(params.message.value.id, participants.payerFsp, payerBulkResponse.headers[normalizedKeys[Enum.Http.Headers.FSPIOP.SOURCE]], payerMetadata, payerBulkResponse.headers, payerPayload)
const payeePayload = Util.omitNil({
bulkTransferId: payeeBulkResponse.bulkTransferId,
bulkTransferState: payeeBulkResponse.bulkTransferState,
completedTimestamp: payeeBulkResponse.completedTimestamp,
extensionList: payeeBulkResponse.extensionList
})
const payeeMetadata = Util.StreamingProtocol.createMetadataWithCorrelatedEvent(params.message.value.metadata.event.id, payeeParams.message.value.metadata.type, payeeParams.message.value.metadata.action, Enum.Events.EventStatus.SUCCESS)